mri

1.2.0 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic parsing of CLI arguments, including boolean flags and aliases.

const mri = require('mri');

// Simulate process.argv for demonstration
const argv = ['--foo', '--bar=baz', '-mtv', '--', 'hello', 'world'];

console.log('Default parsing:');
console.log(mri(argv));
// Expected: { _: ['hello', 'world'], foo:true, bar:'baz', m:true, t:true, v:true }

console.log('\nParsing with boolean options:');
console.log(mri(argv, { boolean:['bar'] }));
// Expected: { _: ['baz', 'hello', 'world'], foo:true, bar:true, m:true, t:true, v:true }

console.log('\nParsing with aliases:');
console.log(mri(argv, {
  alias: {
    b: 'bar',
    foo: ['f', 'fuz']
  }
}));
// Expected: { _: ['hello', 'world'], foo:true, f:true, fuz:true, b:'baz', bar:'baz', m:true, t:true, v:true }

view raw JSON →