args-parser
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,1 +0,1 @@ | ||
"use strict";const ARGUMENT_SEPARATION_REGEX=/([^=\s]+)=?([^\s]*)/;function Parse(s){s=s.slice(2);const e={};let t,c;return s.forEach(function(s){(s=s.match(ARGUMENT_SEPARATION_REGEX)).splice(0,1),0===(t=s[0]).indexOf("-")&&(t=t.slice(t.slice(0,2).lastIndexOf("-")+1)),c=""===s[1]||(parseFloat(s[1]).toString()===s[1]?+s[1]:s[1]),e[t]=c}),e}module.exports=Parse; | ||
"use strict";const ARGUMENT_SEPARATION_REGEX=/([^=\s]+)=?\s*(.*)/;function Parse(s){s=s.slice(2);const e={};let t,c;return s.forEach(function(s){(s=s.match(ARGUMENT_SEPARATION_REGEX)).splice(0,1),0===(t=s[0]).indexOf("-")&&(t=t.slice(t.slice(0,2).lastIndexOf("-")+1)),c=""===s[1]||(parseFloat(s[1]).toString()===s[1]?+s[1]:s[1]),e[t]=c}),e}module.exports=Parse; |
{ | ||
"name": "args-parser", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Straight-forward node.js arguments parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/parse.min.js", |
@@ -9,3 +9,3 @@ 'use strict'; | ||
const ARGUMENT_SEPARATION_REGEX = /([^=\s]+)=?([^\s]*)/; | ||
const ARGUMENT_SEPARATION_REGEX = /([^=\s]+)=?\s*(.*)/; | ||
@@ -12,0 +12,0 @@ function Parse(argv) { |
# args-parser | ||
Straight-forward node.js arguments parser. | ||
## Get the module | ||
```bash | ||
$ node ./script.js careful -dangerous --tomatoes=3 --tonight --key=ek== | ||
```bash | ||
$ npm install args-parser | ||
{ | ||
"careful": true, | ||
"dangerous": true, | ||
"tomatoes": 3, | ||
"tonight": true, | ||
"key": "ek==" | ||
} | ||
``` | ||
@@ -12,3 +19,5 @@ | ||
### args(arguments) | ||
```bash | ||
$ npm install args-parser | ||
``` | ||
@@ -18,13 +27,12 @@ Simply call the module passing it an `arguments` array such as `process.argv`: | ||
```javascript | ||
const args = require("args-parser")(process.argv) | ||
console.info(args) | ||
const args = require('args-parser')(process.argv); | ||
console.info(args); | ||
``` | ||
The returned value is an `Object` having a key for each argument given, and eventually a value if it's found an `=` sign. | ||
The returned value is an `Object` having a key for each given argument and a value if it's found an `=` sign (`true` otherwise). | ||
Considering that simple command: | ||
Consider this command: | ||
```bash | ||
$ node ./script.js careful -dangerous --tomatoes=3 --tonight | ||
$ node ./script.js careful -dangerous --tomatoes=3 --tonight --key=ek== | ||
``` | ||
@@ -36,6 +44,7 @@ | ||
{ | ||
"careful": true, | ||
"dangerous": true, | ||
"tomatoes": 3, | ||
"tonight": true | ||
"careful": true, | ||
"dangerous": true, | ||
"tomatoes": 3, | ||
"tonight": true, | ||
"key": "ek==" | ||
} | ||
@@ -48,4 +57,4 @@ ``` | ||
if (args.careful) { | ||
// Do something | ||
// Do something | ||
} | ||
``` |
14122
57