Comparing version 5.1.0 to 6.0.0
38
index.js
'use strict'; | ||
const match = (arr, val) => arr.some(x => x instanceof RegExp ? x.test(val) : x === val); | ||
const match = (array, value) => array.some(x => x instanceof RegExp ? x.test(value) : x === value); | ||
@@ -8,2 +8,3 @@ module.exports = (input, opts) => { | ||
let extraArgs = []; | ||
let separatedArgs = []; | ||
@@ -36,4 +37,4 @@ opts = Object.assign({ | ||
// TODO: use for-of loop and Object.entries when targeting Node.js 6 | ||
Object.keys(input).forEach(key => { | ||
// TODO: Use Object.entries() when targeting Node.js 8 | ||
for (let key of Object.keys(input)) { | ||
const val = input[key]; | ||
@@ -43,7 +44,7 @@ let pushArg = makeArg; | ||
if (Array.isArray(opts.excludes) && match(opts.excludes, key)) { | ||
return; | ||
continue; | ||
} | ||
if (Array.isArray(opts.includes) && !match(opts.includes, key)) { | ||
return; | ||
continue; | ||
} | ||
@@ -56,2 +57,11 @@ | ||
if (key === '--') { | ||
if (!Array.isArray(val)) { | ||
throw new TypeError(`Expected key \`--\` to be Array, got ${typeof val}`); | ||
} | ||
separatedArgs = val; | ||
continue; | ||
} | ||
if (key === '_') { | ||
@@ -63,3 +73,3 @@ if (!Array.isArray(val)) { | ||
extraArgs = val; | ||
return; | ||
continue; | ||
} | ||
@@ -84,7 +94,7 @@ | ||
if (Array.isArray(val)) { | ||
val.forEach(arrVal => { | ||
pushArg(key, arrVal); | ||
}); | ||
for (const arrayValue of val) { | ||
pushArg(key, arrayValue); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -95,3 +105,11 @@ for (const x of extraArgs) { | ||
if (separatedArgs.length > 0) { | ||
args.push('--'); | ||
} | ||
for (const x of separatedArgs) { | ||
args.push(String(x)); | ||
} | ||
return args; | ||
}; |
{ | ||
"name": "dargs", | ||
"version": "5.1.0", | ||
"description": "Reverse minimist. Convert an object of options into an array of command-line arguments.", | ||
"license": "MIT", | ||
"repository": "sindresorhus/dargs", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"reverse", | ||
"minimist", | ||
"options", | ||
"arguments", | ||
"args", | ||
"flags", | ||
"cli", | ||
"nopt", | ||
"commander", | ||
"bin", | ||
"binary", | ||
"command", | ||
"cmd", | ||
"inverse", | ||
"opposite", | ||
"invert", | ||
"switch", | ||
"construct", | ||
"parse", | ||
"parser", | ||
"argv" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "dargs", | ||
"version": "6.0.0", | ||
"description": "Reverse minimist. Convert an object of options into an array of command-line arguments.", | ||
"license": "MIT", | ||
"repository": "sindresorhus/dargs", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"reverse", | ||
"minimist", | ||
"options", | ||
"arguments", | ||
"args", | ||
"flags", | ||
"cli", | ||
"nopt", | ||
"commander", | ||
"bin", | ||
"binary", | ||
"command", | ||
"cmd", | ||
"inverse", | ||
"opposite", | ||
"invert", | ||
"switch", | ||
"construct", | ||
"parse", | ||
"parser", | ||
"argv" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -11,3 +11,3 @@ # dargs [![Build Status](https://travis-ci.org/sindresorhus/dargs.svg?branch=master)](https://travis-ci.org/sindresorhus/dargs) | ||
``` | ||
$ npm install --save dargs | ||
$ npm install dargs | ||
``` | ||
@@ -22,8 +22,8 @@ | ||
const input = { | ||
_: ['some', 'option'], // values in '_' will be appended to the end of the generated argument list | ||
_: ['some', 'option'], // Values in '_' will be appended to the end of the generated argument list | ||
foo: 'bar', | ||
hello: true, // results in only the key being used | ||
cake: false, // prepends `no-` before the key | ||
camelCase: 5, // camelCase is slugged to `camel-case` | ||
multiple: ['value', 'value2'], // converted to multiple arguments | ||
hello: true, // Results in only the key being used | ||
cake: false, // Prepends `no-` before the key | ||
camelCase: 5, // CamelCase is slugged to `camel-case` | ||
multiple: ['value', 'value2'], // Converted to multiple arguments | ||
pieKind: 'cherry', | ||
@@ -33,3 +33,3 @@ sad: ':(' | ||
const excludes = ['sad', /.*Kind$/]; // excludes and includes accept regular expressions | ||
const excludes = ['sad', /.*Kind$/]; // Excludes and includes accept regular expressions | ||
const includes = ['camelCase', 'multiple', 'sad', /^pie.*/]; | ||
@@ -36,0 +36,0 @@ const aliases = {file: 'f'}; |
Sorry, the diff of this file is not supported yet
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
6974
83