UNPKG

771 BMarkdownView Raw
1# args-parser
2Straight-forward node.js arguments parser.
3
4## Get the module
5
6```bash
7$ npm install args-parser
8```
9
10## How to use it?
11
12### args(arguments)
13
14Simply call the module passing it an `arguments` array such as `process.argv`:
15
16```javascript
17const args = require("args-parser")(process.argv)
18
19console.info(args)
20```
21
22The returned value is an `Object` having a key for each argument given, and eventually a value if it's found an `=` sign.
23
24Considering that simple command:
25
26```bash
27$ node ./script.js careful -dangerous --tomatoes=3 --tonight
28```
29
30Will return:
31
32```json
33{
34 "careful": true,
35 "dangerous": true,
36 "tomatoes": 3,
37 "tonight": true
38}
39```
40
41So then you can easily check what you need:
42
43```javascript
44if (args.careful) {
45 // Do something
46}
47```