node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey »



Minimistish argument parsing.

I have used minimist as my argument-parsing library, but two minor things always bothered me:

  • Checking for flags is not that good. -a becomes { a: true }. The correct way to check if the a flag was provided is if (args.a === true). If you simply do if (args.a) you could be mistakingly interpreting -a some-other-thing.

  • process.argv.slice(2) isn't really classy. There is a reason for that, but I use it only with node so I don't care.


// example.js 
const argv = require('minimisty')
$ node example.js -a beep -b boop
{ _: [], _flags: {}, a: 'beep', b: 'boop' }
$ node example.js -3 -4 -n5 -abc --beep=boop foo bar baz
{ _: [ 'foo', 'bar', 'baz' ],
  _flags: { '5': true, n: true, a: true, b: true, c: true },
  x: '3',
  y: '4',
  beep: 'boop' }