https://github.com/eveningkid/args-parser
Straight-forward node.js arguments parser
https://github.com/eveningkid/args-parser
Last synced: 6 months ago
JSON representation
Straight-forward node.js arguments parser
- Host: GitHub
- URL: https://github.com/eveningkid/args-parser
- Owner: eveningkid
- License: apache-2.0
- Created: 2016-02-06T18:37:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-09T22:46:46.000Z (over 2 years ago)
- Last Synced: 2025-03-30T10:33:59.877Z (6 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 17
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# args-parser
Straight-forward node.js arguments parser.
```bash
$ node ./script.js careful -dangerous --tomatoes=3 --tonight --key=ek=={
"careful": true,
"dangerous": true,
"tomatoes": 3,
"tonight": true,
"key": "ek=="
}
```## How to use it?
```bash
$ npm install args-parser
```Simply call the module passing it an `arguments` array such as `process.argv`:
```javascript
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:
```bash
$ node ./script.js careful -dangerous --tomatoes=3 --tonight --key=ek==
```Will return:
```json
{
"careful": true,
"dangerous": true,
"tomatoes": 3,
"tonight": true,
"key": "ek=="
}
```So then you can easily check what you need:
```javascript
if (args.careful) {
// Do something
}
```