UNPKG

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