{"name":"mri","version":"1.1.6","description":"Quickly scan for CLI flags and arguments","repository":{"type":"git","url":"git+https://github.com/lukeed/mri.git"},"module":"lib/index.mjs","main":"lib/index.js","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"engines":{"node":">=4"},"scripts":{"build":"bundt","bench":"node bench","pretest":"npm run build","test":"tape test/*.js | tap-spec"},"keywords":["argv","arguments","cli","minimist","options","optimist","parser","args"],"devDependencies":{"bundt":"1.0.2","tap-spec":"4.1.2","tape":"4.13.3"},"gitHead":"52f722e07216412424abf1ec1c01477b0760a29f","bugs":{"url":"https://github.com/lukeed/mri/issues"},"homepage":"https://github.com/lukeed/mri#readme","_id":"mri@1.1.6","_nodeVersion":"12.18.2","_npmVersion":"6.14.5","dist":{"integrity":"sha512-oi1b3MfbyGa7FJMP9GmLTttni5JoICpYBRlq+x5V16fZbLsnL9N3wFqqIm/nIG43FjUFkFh9Epzp/kzUGUnJxQ==","shasum":"49952e1044db21dbf90f6cd92bc9c9a777d415a6","tarball":"http://registry-npm.ywwl.com/mri/download/mri-1.1.6.tgz","fileCount":5,"unpackedSize":12616,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfDjImCRA9TVsSAnZWagAAHFgP/A84+0z7oVN5/0yby2k/\nTHoSdJJ6/i7JYfrMuVW5uyGWFS22gUYA9i77Vyu6RoVS4cT3lXE8OFyWLCso\nJp6FaoY2xh/zoK/WfU9n/kOJFiBwCUrslotGRSfLBrcH8JJiCqOVyYV1qyUt\ncEWoT/wBB5UoH6Ce81F4NCJ6WL7XDguETTVIC5d9buKm3hQIQ633Qhldc2SD\nU6sj9xnDuHaxV6S/okTFuv9uIb6fzofuxR8PF5Wk5aP+OEvaO64R0vjLyYrD\nOv5I6d9PXIfgU34swhyjy+Z679UP0h5dup2EZAjrsBWxNoY5AKX42EKnIVpp\nLWfZstXTL9ogCvYayU9MfaGzM8rjNLAaw8I4Ar9ImCi6WpvJSdZ+qiOdpSBo\nLIq/H90DaY+JUWisiWANVjNE0zbWmiumO2sZgDf4QmVI+Un384JcWeWDjucT\nsPu/CvvGna7EuhWdZZMusrGQJIzuhZ6jaAjtl91qIrva2ULx7pQTmC4US7gG\nGitYgOVHBu9l8GlsmQ0kEC7+XJbExGr4NCqCJQM+1yH03X7MVKQmJ/oYsoZy\nnwh5cUMbMs1GFqXRxQy8k5pVA89BZ3DyhuKuIEz24OdSL6QCBvYJ4m5B+SZe\nSwAF3ezfREIc8VY/w6bBbCW8xz77Ph+MFNAQGNockcSYmFBn41WIRLGXjDqH\n/k7A\r\n=Arad\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC64bttODKsO48UjdjnTzan5+dNRYLoSONcppmP/lmHawIgX+gpB0sKnsyNEt2uIRw8kfDiOOsVQfKaEkJbgadMceU="}],"size":4171,"noattachment":false,"key":"/mri/-/mri-1.1.6.tgz"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mri_1.1.6_1594765862079_0.27244387719891305"},"_hasShrinkwrap":false,"readme":"# mri [![CI](https://github.com/lukeed/mri/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/lukeed/mri/actions)\n\n> Quickly scan for CLI flags and arguments\n\nThis is a [fast](#benchmarks) and lightweight alternative to [`minimist`](https://github.com/substack/minimist) and [`yargs-parser`](https://github.com/yargs/yargs-parser).\n\nIt only exists because I find that I usually don't need most of what `minimist` and `yargs-parser` have to offer. However, `mri` is similar _enough_ that it might function as a \"drop-in replacement\" for you, too!\n\nSee [Comparisons](#comparisons) for more info.\n\n## Install\n\n```sh\n$ npm install --save mri\n```\n\n## Usage\n\n```sh\n$ demo-cli --foo --bar=baz -mtv -- hello world\n```\n\n```js\nconst mri = require('mri');\n\nconst argv = process.argv.slice(2);\n\nmri(argv);\n//=> { _: ['hello', 'world'], foo:true, bar:'baz', m:true, t:true, v:true }\n\nmri(argv, { boolean:['bar'] });\n//=> { _: ['baz', 'hello', 'world'], foo:true, bar:true, m:true, t:true, v:true }\n\nmri(argv, {\n  alias: {\n    b: 'bar',\n    foo: ['f', 'fuz']\n  }\n});\n//=> { _: ['hello', 'world'], foo:true, f:true, fuz:true, b:'baz', bar:'baz', m:true, t:true, v:true }\n```\n\n## API\n\n### mri(args, options)\nReturn: `Object`\n\n#### args\nType: `Array`<br>\nDefault: `[]`\n\nAn array of arguments to parse. For CLI usage, send `process.argv.slice(2)`. See [`process.argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) for info.\n\n#### options.alias\nType: `Object`<br>\nDefault: `{}`\n\nAn object of keys whose values are `String`s or `Array<String>` of aliases. These will be added to the parsed output with matching values.\n\n#### options.boolean\nType: `Array|String`<br>\nDefault: `[]`\n\nA single key (or array of keys) that should be parsed as `Boolean`s.\n\n#### options.default\nType: `Object`<br>\nDefault: `{}`\n\nAn `key:value` object of defaults. If a default is provided for a key, its type (`typeof`) will be used to cast parsed arguments.\n\n```js\nmri(['--foo', 'bar']);\n//=> { _:[], foo:'bar' }\n\nmri(['--foo', 'bar'], {\n  default: { foo:true, baz:'hello', bat:42 }\n});\n//=> { _:['bar'], foo:true, baz:'hello', bat:42 }\n```\n\n> **Note:** Because `--foo` has a default of `true`, its output is cast to a Boolean. This means that `foo=true`, making `'bar'` an extra argument (`_` key).\n\n#### options.string\nType: `Array|String`<br>\nDefault: `[]`\n\nA single key (or array of keys) that should be parsed as `String`s.\n\n#### options.unknown\nType: `Function`<br>\nDefault: `undefined`\n\nCallback that is run when a parsed flag has not been defined as a known key or alias. Its only parameter is the unknown flag itself; eg `--foobar` or `-f`.\n\nOnce an unknown flag is encountered, parsing will terminate, regardless of your return value.\n\n> **Note:** `mri` _only_ checks for unknown flags if `options.unknown` **and** `options.alias` are populated. Otherwise, everything will be accepted.\n\n\n## Comparisons\n\n#### minimist\n\n- `mri` is 5x faster (see [benchmarks](#benchmarks))\n- Numerical values are cast as `Number`s when possible\n  - A key (and its aliases) will always honor `opts.boolean` or `opts.string`\n- Short flag groups are treated as `Boolean`s by default:\n    ```js\n    minimist(['-abc', 'hello']);\n    //=> { _:[], a:'', b:'', c:'hello' }\n\n    mri(['-abc', 'hello']);\n    //=> { _:[], a:true, b:true, c:'hello' }\n    ```\n- The `opts.unknown` behaves differently:\n  - Unlike `minimist`, `mri` will not continue continue parsing after encountering an unknown flag\n- Missing `options`:\n  - `opts.stopEarly`\n  - `opts['--']`\n- Ignores newlines (`\\n`) within args (see [test](https://github.com/substack/minimist/blob/master/test/parse.js#L69-L80))\n- Ignores slashBreaks within args (see [test](https://github.com/substack/minimist/blob/master/test/parse.js#L147-L157))\n- Ignores dot-nested flags (see [test](https://github.com/substack/minimist/blob/master/test/parse.js#L180-L197))\n\n#### yargs-parser\n\n- `mri` is 40x faster (see [benchmarks](#benchmarks))\n- Numerical values are cast as `Number`s when possible\n  - A key (and its aliases) will always honor `opts.boolean` or `opts.string`\n- Missing `options`:\n  - `opts.array`\n  - `opts.config`\n  - `opts.coerce`\n  - `opts.count`\n  - `opts.envPrefix`\n  - `opts.narg`\n  - `opts.normalize`\n  - `opts.configuration`\n  - `opts.number`\n  - `opts['--']`\n- Missing [`parser.detailed()`](https://github.com/yargs/yargs-parser#requireyargs-parserdetailedargs-opts) method\n- No [additional configuration](https://github.com/yargs/yargs-parser#configuration) object\n- Added [`options.unknown`](#optionsunknown) feature\n\n\n## Benchmarks\n\n> Running Node.js v10.13.0\n\n```\nLoad Times:\n  nopt          3.179ms\n  yargs-parser  2.137ms\n  minimist      0.746ms\n  mri           0.517ms\n\nBenchmark:\n  minimist      x    328,747 ops/sec ±1.09% (89 runs sampled)\n  mri           x  1,622,801 ops/sec ±0.94% (92 runs sampled)\n  nopt          x    888,223 ops/sec ±0.22% (92 runs sampled)\n  yargs-parser  x     30,538 ops/sec ±0.81% (91 runs sampled)\n```\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","publish_time":1594765862214,"_cnpm_publish_time":1594765862214,"dist-tags":{"latest":"1.2.0"}}