Comparing version 2.0.0 to 2.1.0
@@ -10,3 +10,7 @@ #!/usr/bin/env node | ||
, "bool-list": [Boolean, Array] | ||
, str: String } | ||
, str: String | ||
, clear: Boolean | ||
, config: Boolean | ||
, length: Number | ||
} | ||
, shorthands = { s: [ "--str", "astring" ] | ||
@@ -19,3 +23,6 @@ , b: [ "--bool" ] | ||
, H: ["--help"] | ||
, n: [ "--num", "125" ] } | ||
, n: [ "--num", "125" ] | ||
, c: ["--config"] | ||
, l: ["--length"] | ||
} | ||
, parsed = nopt( types | ||
@@ -22,0 +29,0 @@ , shorthands |
@@ -53,3 +53,3 @@ // info about each config option. | ||
var remove = {} | ||
, typeDefault = [false, true, null, String, Number] | ||
, typeDefault = [false, true, null, String, Number, Array] | ||
@@ -248,2 +248,3 @@ Object.keys(data).forEach(function (k) { | ||
} | ||
// see if it's a shorthand | ||
@@ -273,2 +274,9 @@ // if so, splice and back up to re-parse it. | ||
// allow unknown things to be arrays if specified multiple times. | ||
if (!types.hasOwnProperty(arg) && data.hasOwnProperty(arg)) { | ||
if (!Array.isArray(data[arg])) | ||
data[arg] = [data[arg]] | ||
isArray = true | ||
} | ||
var val | ||
@@ -347,28 +355,39 @@ , la = args[i + 1] | ||
arg = arg.replace(/^-+/, '') | ||
if (abbrevs[arg] && !shorthands[arg]) { | ||
// first check to see if this arg is a set of single-char shorthands | ||
var singles = shorthands.___singles | ||
if (!singles) { | ||
singles = Object.keys(shorthands).filter(function (s) { | ||
return s.length === 1 | ||
}).reduce(function (l,r) { | ||
l[r] = true | ||
return l | ||
}, {}) | ||
shorthands.___singles = singles | ||
debug('shorthand singles', singles) | ||
} | ||
var chrs = arg.split("").filter(function (c) { | ||
return singles[c] | ||
}) | ||
if (chrs.join("") === arg) return chrs.map(function (c) { | ||
return shorthands[c] | ||
}).reduce(function (l, r) { | ||
return l.concat(r) | ||
}, []) | ||
// if it's an arg abbrev, and not a literal shorthand, then prefer the arg | ||
if (abbrevs[arg] && !shorthands[arg]) | ||
return null | ||
} | ||
if (shortAbbr[arg]) { | ||
// if it's an abbr for a shorthand, then use that | ||
if (shortAbbr[arg]) | ||
arg = shortAbbr[arg] | ||
} else { | ||
var singles = shorthands.___singles | ||
if (!singles) { | ||
singles = Object.keys(shorthands).filter(function (s) { | ||
return s.length === 1 | ||
}).reduce(function (l,r) { l[r] = true ; return l }, {}) | ||
shorthands.___singles = singles | ||
} | ||
var chrs = arg.split("").filter(function (c) { | ||
return singles[c] | ||
}) | ||
if (chrs.join("") === arg) return chrs.map(function (c) { | ||
return shorthands[c] | ||
}).reduce(function (l, r) { | ||
return l.concat(r) | ||
}, []) | ||
} | ||
if (shorthands[arg] && !Array.isArray(shorthands[arg])) { | ||
// make it an array, if it's a list of words | ||
if (shorthands[arg] && !Array.isArray(shorthands[arg])) | ||
shorthands[arg] = shorthands[arg].split(/\s+/) | ||
} | ||
return shorthands[arg] | ||
@@ -540,2 +559,7 @@ } | ||
,[]] | ||
,["-cl 1" | ||
,{config: true, length: 1} | ||
,[] | ||
,{config: Boolean, length: Number, clear: Boolean} | ||
,{c: "--config", l: "--length"}] | ||
].forEach(function (test) { | ||
@@ -545,3 +569,3 @@ var argv = test[0].split(/\s+/) | ||
, rem = test[2] | ||
, actual = nopt(types, shorthands, argv, 0) | ||
, actual = nopt(test[3] || types, test[4] || shorthands, argv, 0) | ||
, parsed = actual.argv | ||
@@ -548,0 +572,0 @@ delete actual.argv |
{ | ||
"name": "nopt", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.", | ||
@@ -5,0 +5,0 @@ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
27880
596
0