mri is a compact and high-performance library designed for quickly parsing command-line interface (CLI) flags and arguments in Node.js environments. It serves as a lightweight and significantly faster alternative to more feature-rich parsers like `minimist` and `yargs-parser`, often achieving 5x to 40x speed improvements respectively. The current stable version is 1.2.0. The project maintains an active release cadence, frequently publishing patch and minor versions that focus on performance optimizations, bug fixes, and minor feature additions. A key differentiator is its minimalist API, intentionally omitting complex features found in other parsers for raw speed, while still providing essential functionalities like aliasing, boolean and string type coercions, and default values. As of v1.2.0, TypeScript definitions are included directly within the package.
npm install mriVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic parsing of CLI arguments, including boolean flags and aliases.
Explicitly define types using `options.boolean` or `options.string` for critical flags, or ensure your code handles the potentially cast types. For example, `mri(['--foo', 'bar'], { default: { foo:true } })` will parse `foo` as `true` and `'bar'` into `_` because the default for `foo` is boolean.Adjust your CLI parsing logic to expect individual boolean flags for short groups. For example, `mri(['-abc', 'hello'])` will result in `{ _:[], a:true, b:true, c:'hello' }`, whereas `minimist` might interpret it differently.Ensure both `options.unknown` and `options.alias` are supplied if you intend to catch unknown flags. Design your CLI to handle this early termination behavior for unknown flags.
If you need a numerical value to remain a string (e.g., '007'), you must explicitly include its key in `options.string`. Otherwise, be prepared to handle `Number` types for values that appear to be numerical.
To force a specific type, add the flag to `options.boolean` or `options.string`. If `options.default` is causing issues, consider removing it or matching its type precisely to your expected input.
Ensure you provide an `options.alias` object (e.g., `{ alias: {} }`) in addition to `options.unknown`. Remember that parsing will stop immediately after the first unknown flag.Adjust your expectation and logic to `mri`'s behavior: `-abc value` will result in `a:true, b:true, c:'value'`. If this is not desired, consider using long flags or separating short flags (e.g., `-a -b -c`).
No dependency data recorded yet.