minargs is a JavaScript argument parser designed for minimal configuration and assumptions. Currently at version 2.1.0, it provides a barebones approach to parsing command-line arguments without built-in usage messages, validation, type coercion, or strictness. Its core philosophy is to 'Bring Your Own Usage™️' and 'Bring Your Own Validation™️', making it highly flexible but requiring more boilerplate for complex applications. It maintains zero runtime dependencies and aims for consistent results, returning a structured object containing `args`, `positionals`, `remainder`, and `argv` for fine-grained control over parsed input. This library is suitable for projects where developers prefer explicit control over argument processing rather than relying on opinionated, feature-rich parsers, and requires Node.js versions `^12.13.0 || ^14.15.0 || >=16`.
npm install minargsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic argument parsing using `minargs`, showing how it separates named arguments, positional values, and a 'remainder' array after a bare `--` delimiter.
Implement custom validation (e.g., using `Object.keys(args).filter(...)`) and type conversion (e.g., `Number(args.port[0])`) after parsing the arguments.
If you expect bare flag definitions to consume the next token as their value, pass `{ positionalValues: true }` in the options object to `minargs()`.Ensure that `alias` keys intended for short flag parsing are single characters. For multi-character aliases, treat them as full arguments or implement custom alias mapping.
Set `recursive: true` in the options if you wish `minargs` to continue parsing arguments after a `--` marker. Otherwise, manually process the `remainder` array if you need to pass them to another process or parser.
Always check for existence and handle the array. Example: `const fooValue = args.foo ? args.foo[0] : undefined;` or `const count = Number(args.count?.[0] || '0');`.
Explicitly convert parsed string values to the desired types. Example: `const port = Number(args.port?.[0]);` or `const verbose = args.verbose?.includes('') ?? false;`.Implement custom validation logic against the `args` and `positionals` objects after parsing. Maintain a list of known arguments and check for their presence and format manually or with an external validation library.
No dependency data recorded yet.