Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

minimist

minimistjs286.5mMIT1.2.8TypeScript support: definitely-typed

parse argument options

argv, getopt, parser, optimist

readme

minimist Version Badge

github actions coverage License Downloads

npm badge

parse argument options

This module is the guts of optimist's argument parser without all the fanciful decoration.

example

var argv = require('minimist')(process.argv.slice(2));
console.log(argv);
$ node example/parse.js -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }
$ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
{
    _: ['foo', 'bar', 'baz'],
    x: 3,
    y: 4,
    n: 5,
    a: true,
    b: true,
    c: true,
    beep: 'boop'
}

security

Previous versions had a prototype pollution bug that could cause privilege escalation in some circumstances when handling untrusted user input.

Please use version 1.2.6 or later:

methods

var parseArgs = require('minimist')

var argv = parseArgs(args, opts={})

Return an argument object argv populated with the array arguments from args.

argv._ contains all the arguments that didn't have an option associated with them.

Numeric-looking arguments will be returned as numbers unless opts.string or opts.boolean is set for that argument name.

Any arguments after '--' will not be parsed and will end up in argv._.

options can be:

  • opts.string - a string or array of strings argument names to always treat as strings
  • opts.boolean - a boolean, string or array of strings to always treat as booleans. if true will treat all double hyphenated arguments without equal signs as boolean (e.g. affects --foo, not -f or --foo=bar)
  • opts.alias - an object mapping string names to strings or arrays of string argument names to use as aliases
  • opts.default - an object mapping string argument names to default values
  • opts.stopEarly - when true, populate argv._ with everything after the first non-option
  • opts['--'] - when true, populate argv._ with everything before the -- and argv['--'] with everything after the --. Here's an example:

    > require('./')('one two three -- four five --six'.split(' '), { '--': true })
    {
      _: ['one', 'two', 'three'],
      '--': ['four', 'five', '--six']
    }

    Note that with opts['--'] set, parsing for arguments still stops after the --.

  • opts.unknown - a function which is invoked with a command line parameter not defined in the opts configuration object. If the function returns false, the unknown option is not added to argv.

install

With npm do:

npm install minimist

license

MIT

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.2.8 - 2023-02-09

Merged

  • [Fix] Fix long option followed by single dash #17
  • [Tests] Remove duplicate test #12
  • [Fix] opt.string works with multiple aliases #10

Fixed

  • [Fix] Fix long option followed by single dash (#17) #15
  • [Tests] Remove duplicate test (#12) #8
  • [Fix] Fix long option followed by single dash #15
  • [Fix] opt.string works with multiple aliases (#10) #9
  • [Fix] Fix handling of short option with non-trivial equals #5
  • [Tests] Remove duplicate test #8
  • [Fix] opt.string works with multiple aliases #9

Commits

  • Merge tag 'v0.2.3' a026794
  • [eslint] fix indentation and whitespace 5368ca4
  • [eslint] fix indentation and whitespace e5f5067
  • [eslint] more cleanup 62fde7d
  • [eslint] more cleanup 36ac5d0
  • [meta] add auto-changelog 73923d2
  • [actions] add reusable workflows d80727d
  • [eslint] add eslint; rules to enable later are warnings 48bc06a
  • [eslint] fix indentation 34b0f1c
  • [readme] rename and add badges 5df0fe4
  • [Dev Deps] switch from covert to nyc a48b128
  • [Dev Deps] update covert, tape; remove unnecessary tap f0fb958
  • [meta] create FUNDING.yml; add funding in package.json 3639e0c
  • [meta] use npmignore to autogenerate an npmignore file be2e038
  • Only apps should have lockfiles 282b570
  • isConstructorOrProto adapted from PR ef9153f
  • [Dev Deps] update @ljharb/eslint-config, aud 098873c
  • [Dev Deps] update @ljharb/eslint-config, aud 3124ed3
  • [meta] add safe-publish-latest 4b927de
  • [Tests] add aud in posttest b32d9bd
  • [meta] update repo URLs f9fdfc0
  • [actions] Avoid 0.6 tests due to build failures ba92fe6
  • [Dev Deps] update tape 950eaa7
  • [Dev Deps] add missing npmignore dev dep 3226afa
  • Merge tag 'v0.2.2' 980d7ac

v1.2.7 - 2022-10-10

Commits

  • [meta] add auto-changelog 0ebf4eb
  • [actions] add reusable workflows e115b63
  • [eslint] add eslint; rules to enable later are warnings f58745b
  • [Dev Deps] switch from covert to nyc ab03356
  • [readme] rename and add badges 236f4a0
  • [meta] create FUNDING.yml; add funding in package.json 783a49b
  • [meta] use npmignore to autogenerate an npmignore file f81ece6
  • Only apps should have lockfiles 56cad44
  • [Dev Deps] update covert, tape; remove unnecessary tap 49c5f9f
  • [Tests] add aud in posttest 228ae93
  • [meta] add safe-publish-latest 01fc23f
  • [meta] update repo URLs 6b164c7

v1.2.6 - 2022-03-21

Commits

  • test from prototype pollution PR bc8ecee
  • isConstructorOrProto adapted from PR c2b9819
  • security notice for additional prototype pollution issue ef88b93

v1.2.5 - 2020-03-12

v1.2.4 - 2020-03-11

Commits

  • security notice 4cf1354
  • additional test for constructor prototype pollution 1043d21

v1.2.3 - 2020-03-10

Commits

  • more failing proto pollution tests 13c01a5
  • even more aggressive checks for protocol pollution 38a4d1c

v1.2.2 - 2020-03-10

Commits

v1.2.1 - 2020-03-10

Merged

  • move the opts['--'] example back where it belongs #63

Commits

v1.2.0 - 2015-08-24

Commits

v1.1.3 - 2015-08-06

Commits

  • add failing test - boolean alias array 0fa3c5b
  • fix boolean values with multiple aliases 9c0a6e7

v1.1.2 - 2015-07-22

Commits

  • Convert boolean arguments to boolean values 8f3dc27
  • use non-ancient npm, node 0.12 and iojs 61ed1d0
  • an older npm for 0.8 25cf778

v1.1.1 - 2015-03-10

Commits

  • check that they type of a value is a boolean, not just that it is currently set to a boolean 6863198
  • upgrade tape, fix type issues from old tape version 806712d
  • test for setting a boolean to a null default 8c444fe
  • if the previous value was a boolean, without an default (or with an alias) don't make an array either e5f419a

v1.1.0 - 2014-08-10

Commits

  • add support for handling "unknown" options not registered with the parser. 6f3cc5d
  • reformat package.json 02ed371
  • coverage script e5531ba
  • extra fn to get 100% coverage again a6972da

v1.0.0 - 2014-08-10

Commits

v0.2.3 - 2023-02-09

Merged

  • [Fix] Fix long option followed by single dash #17
  • [Tests] Remove duplicate test #12
  • [Fix] opt.string works with multiple aliases #10

Fixed

  • [Fix] Fix long option followed by single dash (#17) #15
  • [Tests] Remove duplicate test (#12) #8
  • [Fix] opt.string works with multiple aliases (#10) #9

Commits

  • [eslint] fix indentation and whitespace e5f5067
  • [eslint] more cleanup 36ac5d0
  • [eslint] fix indentation 34b0f1c
  • isConstructorOrProto adapted from PR ef9153f
  • [Dev Deps] update @ljharb/eslint-config, aud 098873c
  • [Dev Deps] add missing npmignore dev dep 3226afa

v0.2.2 - 2022-10-10

Commits

  • [meta] add auto-changelog 73923d2
  • [actions] add reusable workflows d80727d
  • [eslint] add eslint; rules to enable later are warnings 48bc06a
  • [readme] rename and add badges 5df0fe4
  • [Dev Deps] switch from covert to nyc a48b128
  • [Dev Deps] update covert, tape; remove unnecessary tap f0fb958
  • [meta] create FUNDING.yml; add funding in package.json 3639e0c
  • [meta] use npmignore to autogenerate an npmignore file be2e038
  • Only apps should have lockfiles 282b570
  • [meta] add safe-publish-latest 4b927de
  • [Tests] add aud in posttest b32d9bd
  • [meta] update repo URLs f9fdfc0

v0.2.1 - 2020-03-12

v0.2.0 - 2014-06-19

Commits

v0.1.0 - 2014-05-12

Commits

  • Provide a mechanism to segregate -- arguments ce4a1e6
  • documented argv['--'] 14db0e6
  • Adding a test-case for notFlags segregation 715c1e3

v0.0.10 - 2014-05-11

Commits

  • dedicated boolean test 46e448f
  • dedicated num test 9bf2d36
  • aliased values treated as strings 1ab743b
  • cover the case of already numbers, at 100% coverage b2bb044
  • another test for higher coverage 3662624

v0.0.9 - 2014-05-08

Commits

v0.0.8 - 2014-02-20

Commits

  • return '' if flag is string and empty fa63ed4
  • handle joined single letters 66c248f

v0.0.7 - 2014-02-08

Commits

  • another swap of .test for .match d1da408

v0.0.6 - 2014-02-08

Commits

  • use .test() instead of .match() to not crash on non-string values in the arguments array 7e0d1ad

v0.0.5 - 2013-09-18

Commits

v0.0.4 - 2013-09-17

v0.0.3 - 2013-09-12

Commits

  • failing test for single dash preceeding a double dash b465514
  • fix for the dot test 6a095f1

v0.0.2 - 2013-08-28

Commits

  • allow dotted aliases & defaults 321c33e
  • use a better version of ff e40f611

v0.0.1 - 2013-06-25

Commits

v0.0.0 - 2013-06-25

Commits

  • half of the parse test ported 3079326
  • stripped down code and a passing test from optimist 7cced88
  • ported parse tests completely over 9448754
  • docs, package.json a5bf46a
  • move more short tests into short.js 503edb5
  • default bool test was wrong, not the code 1b9f5db
  • passing long tests ripped out of parse.js 7972c4a
  • badges 84c0370
  • all the tests now ported, some failures 64239ed
  • failing short test f8a5341
  • fixed the numeric test 6b034f3