Socket
Socket
Sign inDemoInstall

args-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    args-parser

Straight-forward node.js arguments parser


Version published
Maintainers
1
Install size
14.7 kB
Created

Readme

Source

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
}

Keywords

FAQs

Last updated on 08 Jul 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc