5 This module is the guts of optimist's argument parser without all the
11 var argv = require('minimist')(process.argv.slice(2));
16 $ node example/parse.js -a beep -b boop
17 { _: [], a: 'beep', b: 'boop' }
21 $ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
22 { _: [ 'foo', 'bar', 'baz' ],
34 Previous versions had a prototype pollution bug that could cause privilege
35 escalation in some circumstances when handling untrusted user input.
37 Please use version 1.2.3 or later: https://snyk.io/vuln/SNYK-JS-MINIMIST-559764
42 var parseArgs = require('minimist')
45 ## var argv = parseArgs(args, opts={})
47 Return an argument object `argv` populated with the array arguments from `args`.
49 `argv._` contains all the arguments that didn't have an option associated with
52 Numeric-looking arguments will be returned as numbers unless `opts.string` or
53 `opts.boolean` is set for that argument name.
55 Any arguments after `'--'` will not be parsed and will end up in `argv._`.
59 * `opts.string` - a string or array of strings argument names to always treat as
61 * `opts.boolean` - a boolean, string or array of strings to always treat as
62 booleans. if `true` will treat all double hyphenated arguments without equal signs
63 as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`)
64 * `opts.alias` - an object mapping string names to strings or arrays of string
65 argument names to use as aliases
66 * `opts.default` - an object mapping string argument names to default values
67 * `opts.stopEarly` - when true, populate `argv._` with everything after the
69 * `opts['--']` - when true, populate `argv._` with everything before the `--`
70 and `argv['--']` with everything after the `--`. Here's an example:
73 > require('./')('one two three -- four five --six'.split(' '), { '--': true })
74 { _: [ 'one', 'two', 'three' ],
75 '--': [ 'four', 'five', '--six' ] }
78 Note that with `opts['--']` set, parsing for arguments still stops after the
81 * `opts.unknown` - a function which is invoked with a command line parameter not
82 defined in the `opts` configuration object. If the function returns `false`, the
83 unknown option is not added to `argv`.
87 With [npm](https://npmjs.org) do: