租房小程序前端代码
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.

121 lines
3.5 KiB

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