expand-args
Advanced tools
Comparing version 0.2.1 to 0.2.2
68
index.js
@@ -10,3 +10,3 @@ /*! | ||
var expand = require('expand-object'); | ||
var utils = require('./utils'); | ||
@@ -22,7 +22,46 @@ function expandArgs(argv) { | ||
var orig = argv[key]; | ||
if (typeof orig === 'string') { | ||
orig = orig.split('/').join('__SLASH__'); | ||
} | ||
if (utils.typeOf(orig) === 'object') { | ||
res[key] = expandArgs(orig); | ||
continue; | ||
} | ||
var val = orig.toString(); | ||
if ((/[\\\/]/.test(val) || /\/\./.test(val))) { | ||
if (/:/.test(val)) { | ||
res[key] = emit(val).split('|').reduce(function (acc, ele) { | ||
var o = {}; | ||
var segs = ele.split(':'); | ||
var v = segs[1].split('\\.').join('.'); | ||
if (/,/.test(v)) { | ||
v = v.split(','); | ||
} | ||
utils.set(o, segs[0], v); | ||
extend(acc, o); | ||
return acc; | ||
}, {}); | ||
continue; | ||
} | ||
if (/,/.test(val)) { | ||
res[key] = emit(val).split('|').reduce(function (acc, ele) { | ||
var arr = ele.split('\\.').join('.').split(','); | ||
return acc.concat(arr); | ||
}, []); | ||
continue; | ||
} | ||
if (val.indexOf('./') === 0) { | ||
res[key] = emit(val); | ||
continue; | ||
} | ||
} | ||
if (~key.indexOf(':') && val === 'true') { | ||
var parts = key.split(':'); | ||
res[parts[0]] = parts[1]; | ||
res[parts[0]] = emit(parts[1]); | ||
continue; | ||
@@ -40,6 +79,6 @@ } | ||
if (/\W/.test(ele)) { | ||
extend(res, expand(ele)); | ||
extend(res, utils.expand(ele)); | ||
} else { | ||
res._ = res._ || []; | ||
res._.push(ele); | ||
res._.push(emit(ele)); | ||
} | ||
@@ -57,7 +96,7 @@ } | ||
if (typeof orig === 'string' && /\W/.test(orig)) { | ||
res[key] = expand(orig, {toBoolean: true}); | ||
res[key] = utils.expand(emit(orig), {toBoolean: true}); | ||
continue; | ||
} | ||
res[key] = orig; | ||
res[key] = emit(orig); | ||
} | ||
@@ -68,13 +107,24 @@ return res; | ||
function extend(a, b) { | ||
for (var key in b) a[key] = b[key]; | ||
for (var key in b) { | ||
a[key] = b[key]; | ||
} | ||
return a; | ||
}; | ||
} | ||
function expandEach(arr) { | ||
return arr.map(function (ele) { | ||
ele = emit(ele); | ||
if (!/\W/.test(ele)) return ele; | ||
return expand(ele, {toBoolean: true}); | ||
return utils.expand(ele, { | ||
toBoolean: true | ||
}); | ||
}); | ||
} | ||
function emit(str) { | ||
str = str.split('__SLASH__').join('/'); | ||
return str; | ||
} | ||
/** | ||
@@ -81,0 +131,0 @@ * Expose an instance of `expandArgs` plugin |
{ | ||
"name": "expand-args", | ||
"description": "Expand parsed command line arguments using expand-object.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/jonschlinkert/expand-args", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"repository": "jonschlinkert/expand-args", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/expand-args/issues" | ||
}, | ||
"bugs": "https://github.com/jonschlinkert/expand-args/issues", | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"utils.js" | ||
], | ||
@@ -23,3 +22,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"expand-object": "^0.3.8" | ||
"expand-object": "^0.3.8", | ||
"extend-shallow": "^2.0.1", | ||
"kind-of": "^2.0.1", | ||
"lazy-cache": "^0.2.4", | ||
"set-value": "^0.3.0" | ||
}, | ||
@@ -42,3 +45,8 @@ "devDependencies": { | ||
"object" | ||
] | ||
], | ||
"verb": { | ||
"related": { | ||
"list": ["expand-object"] | ||
} | ||
} | ||
} |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
7699
5
141
5
2
2
+ Addedextend-shallow@^2.0.1
+ Addedkind-of@^2.0.1
+ Addedlazy-cache@^0.2.4
+ Addedset-value@^0.3.0
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.0(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedmath-intrinsics@1.0.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-value@0.3.3(transitive)
+ Addedto-object-path@0.2.0(transitive)