args-parser

Straight-forward node.js arguments parser

Stats

StarsIssuesVersionUpdatedCreatedSize
args-parser
1001.3.06 months ago6 years agoMinified + gzip package size for args-parser in KB

Readme

args-parser

Straight-forward node.js arguments parser.

$ node ./script.js careful -dangerous --tomatoes=3 --tonight --key=ek==

{
  "careful": true,
  "dangerous": true,
  "tomatoes": 3,
  "tonight": true,
  "key": "ek=="
}

How to use it?

$ npm install args-parser

Simply call the module passing it an arguments array such as process.argv:

const args = require('args-parser')(process.argv);
console.info(args);

The returned value is an Object having a key for each given argument and a value if it's found an = sign (true otherwise).

Consider this command:

$ node ./script.js careful -dangerous --tomatoes=3 --tonight --key=ek==

Will return:

{
  "careful": true,
  "dangerous": true,
  "tomatoes": 3,
  "tonight": true,
  "key": "ek=="
}

So then you can easily check what you need:

if (args.careful) {
  // Do something
}

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.