1# minimist 2 3parse argument options 4 5This module is the guts of optimist's argument parser without all the 6fanciful decoration. 7 8# example 9 10``` js 11var argv = require('minimist')(process.argv.slice(2)); 12console.log(argv); 13``` 14 15``` 16$ node example/parse.js -a beep -b boop 17{ _: [], a: 'beep', b: 'boop' } 18``` 19 20``` 21$ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz 22{ _: [ 'foo', 'bar', 'baz' ], 23 x: 3, 24 y: 4, 25 n: 5, 26 a: true, 27 b: true, 28 c: true, 29 beep: 'boop' } 30``` 31 32# security 33 34Previous versions had a prototype pollution bug that could cause privilege 35escalation in some circumstances when handling untrusted user input. 36 37Please use version 1.2.6 or later: 38 39* https://security.snyk.io/vuln/SNYK-JS-MINIMIST-2429795 (version <=1.2.5) 40* https://snyk.io/vuln/SNYK-JS-MINIMIST-559764 (version <=1.2.3) 41 42# methods 43 44``` js 45var parseArgs = require('minimist') 46``` 47 48## var argv = parseArgs(args, opts={}) 49 50Return an argument object `argv` populated with the array arguments from `args`. 51 52`argv._` contains all the arguments that didn't have an option associated with 53them. 54 55Numeric-looking arguments will be returned as numbers unless `opts.string` or 56`opts.boolean` is set for that argument name. 57 58Any arguments after `'--'` will not be parsed and will end up in `argv._`. 59 60options can be: 61 62* `opts.string` - a string or array of strings argument names to always treat as 63strings 64* `opts.boolean` - a boolean, string or array of strings to always treat as 65booleans. if `true` will treat all double hyphenated arguments without equal signs 66as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`) 67* `opts.alias` - an object mapping string names to strings or arrays of string 68argument names to use as aliases 69* `opts.default` - an object mapping string argument names to default values 70* `opts.stopEarly` - when true, populate `argv._` with everything after the 71first non-option 72* `opts['--']` - when true, populate `argv._` with everything before the `--` 73and `argv['--']` with everything after the `--`. Here's an example: 74 75 ``` 76 > require('./')('one two three -- four five --six'.split(' '), { '--': true }) 77 { _: [ 'one', 'two', 'three' ], 78 '--': [ 'four', 'five', '--six' ] } 79 ``` 80 81 Note that with `opts['--']` set, parsing for arguments still stops after the 82 `--`. 83 84* `opts.unknown` - a function which is invoked with a command line parameter not 85defined in the `opts` configuration object. If the function returns `false`, the 86unknown option is not added to `argv`. 87 88# install 89 90With [npm](https://npmjs.org) do: 91 92``` 93npm install minimist 94``` 95 96# license 97 98MIT 99