command-line-parser
Advanced tools
Comparing version
@@ -48,4 +48,4 @@ // Converts an array of arguments into a key value object | ||
const isArgGroupKey = allowKeyGrouping && arg.length > 2 && arg[0] === '-' && arg[1] !== '-'; | ||
let trimmedKey = arg // trim leading dashes and convert any embedded dashes or spaces to camelCase | ||
.replace( /^-*/g, ' ' ) | ||
let trimmedKey = arg // remove leading dashes, trim space, and convert any embedded dashes or spaces to camelCase | ||
.replace( /^-*/g, '' ) | ||
.trim() | ||
@@ -52,0 +52,0 @@ .replace(/(-+|\s+)\w/g, function (g) { return g[g.length - 1].toUpperCase(); }); |
{ | ||
"name": "command-line-parser", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Simple lightweight function takes an array of command-line arguments and returns a parsed object", | ||
@@ -5,0 +5,0 @@ "main": "command-line-parser.js", |
# command-line-parser | ||
This code: | ||
This statement: | ||
``` | ||
const argsObj = require('command-line-parser')(); | ||
``` | ||
invoked with: | ||
``` | ||
node ./myscript.js myfile1 -v -debug -host there.com -port 8081 myfile2 | ||
``` | ||
returns this ```argsObj``` object: | ||
@@ -20,2 +16,6 @@ ``` | ||
``` | ||
when invoked with: | ||
``` | ||
node ./myscript.js myfile1 -v -debug -host there.com -port 8081 myfile2 | ||
``` | ||
This simple lightweight module exports a default function that takes an array of command-line arguments and returns a parsed object (a bit simpler than the venerable ```minimist``` or ```commander```). | ||
@@ -67,4 +67,10 @@ | ||
``` | ||
const { v, debug = false, host = 'default.com', port = '80', _args: files = [] } = argsObj ; | ||
const { | ||
v, | ||
debug = false, | ||
host = 'default.com', | ||
port = '80', | ||
_args: files = [] | ||
} = argsObj ; | ||
``` | ||
will assign the locally scoped constant variables ```v```, ```debug```, ```host```, ```port```, and ```files```. |
10759
0.27%75
8.7%