command-line-parser
Advanced tools
Comparing version
@@ -19,2 +19,3 @@ // Converts an array of arguments into a key value object | ||
} = {} ) { | ||
return args.reduce( ( argsObjInReduction, arg, index, args ) => { | ||
@@ -52,3 +53,3 @@ const isArgKey = arg.length > 0 && arg[0] === '-'; | ||
.trim() | ||
.replace(/(-+|\s+)\w/g, function (g) { return g[g.length - 1].toUpperCase(); }); | ||
.replace(/(-+|\s+)\w/g, g => g[g.length - 1].toUpperCase() ); | ||
let value ; | ||
@@ -76,3 +77,3 @@ const embeddedValueObject = allowEmbeddedValues && getEmbeddedKeyValue( trimmedKey ); | ||
return argsObjInReduction ; | ||
}, {} ); | ||
}, { _args: [] } ); | ||
}; |
{ | ||
"name": "command-line-parser", | ||
"version": "0.1.10", | ||
"version": "0.2.10", | ||
"description": "Simple lightweight function takes an array of command-line arguments and returns a parsed object", | ||
"main": "command-line-parser.js", | ||
"main": "index.js", | ||
"scripts": { | ||
@@ -7,0 +7,0 @@ "test": "./node_modules/.bin/mocha --reporter spec" |
@@ -30,3 +30,5 @@ # command-line-parser | ||
``` | ||
const argsObj = require('command-line-parser')({ booleanKeys: [ 'foo' ] }); | ||
const argsObj = require('command-line-parser')({ | ||
booleanKeys: [ 'foo' ] | ||
}); | ||
``` | ||
@@ -39,2 +41,7 @@ A key with multiple leading dashes such as ```--debug``` will be the same as ```-debug``` (with the exception of overriding the optional argument ```allowKeyGrouping``` described below). | ||
To avoid any arguments intended for ```_args``` from becoming the unintentional value of a preceding boolean key, either specify that boolean key in ```booleanKeys``` of config, or follow that boolean key with a placeholder argument such as a single ```-``` or double dash ```--``` on the command line. | ||
``` | ||
node ./myscript.js -d -- foo1 foo2 foo3 | ||
``` | ||
### Embedding numerical values within keys | ||
@@ -51,3 +58,5 @@ Instead of having to separate a numerical argument from its key: | ||
``` | ||
const argsObj = require('command-line-parser')({ allowEmbeddedValues: true }); | ||
const argsObj = require('command-line-parser')({ | ||
allowEmbeddedValues: true | ||
}); | ||
``` | ||
@@ -67,3 +76,5 @@ to give the result | ||
``` | ||
const argsObj = require('command-line-parser')({ allowKeyGrouping: true }); | ||
const argsObj = require('command-line-parser')({ | ||
allowKeyGrouping: true | ||
}); | ||
``` | ||
@@ -70,0 +81,0 @@ gives the result |
@@ -8,4 +8,4 @@ const should = require('chai').should(); | ||
const argsObj = commandLineParser( { args: [] } ); | ||
argsObj.should.be.empty; | ||
argsObj.should.be.an('object'); | ||
argsObj.should.deep.equal( { _args: [] } ); // nearly should.be.empty | ||
}); | ||
@@ -15,4 +15,4 @@ | ||
const argsObj = commandLineParser( { args: [ '-', '--', '---' ] } ); | ||
argsObj.should.be.empty; | ||
argsObj.should.be.an('object'); | ||
argsObj.should.deep.equal( { _args: [] } ); // nearly should.be.empty | ||
}); | ||
@@ -19,0 +19,0 @@ |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
123
9.82%11696
-56.57%4
-33.33%