You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.5 KiB

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