Comparing version 2.0.0 to 2.0.1
28
index.js
'use strict'; | ||
var escape = function (value) { | ||
return value.replace(/'/g, "'\''"); | ||
}; | ||
var constructOption = function (name, value) { | ||
name = name.replace(/[A-Z]/g, '-$&').toLowerCase(); | ||
return '--' + name + (value ? "='" + escape(value) + "'": ''); | ||
}; | ||
module.exports = function (options, excludes) { | ||
var args = []; | ||
Object.keys(options).forEach(function (key) { | ||
var flag; | ||
var val = options[key]; | ||
Object.keys(options).forEach(function (name) { | ||
var val = options[name]; | ||
if (Array.isArray(excludes) && excludes.indexOf(key) !== -1) { | ||
if (Array.isArray(excludes) && excludes.indexOf(name) !== -1) { | ||
return; | ||
} | ||
flag = key.replace(/[A-Z]/g, '-$&').toLowerCase(); | ||
if (val === true) { | ||
args.push('--' + flag); | ||
args.push(constructOption(name)); | ||
} | ||
if (typeof val === 'string') { | ||
args.push('--' + flag + '=' + val); | ||
args.push(constructOption(name, val)); | ||
} | ||
if (typeof val === 'number' && isNaN(val) === false) { | ||
args.push('--' + flag + '=' + ('' + val)); | ||
args.push(constructOption(name, '' + val)); | ||
} | ||
@@ -29,3 +37,3 @@ | ||
val.forEach(function (arrVal) { | ||
args.push('--' + flag + '=' + arrVal); | ||
args.push(constructOption(name, arrVal)); | ||
}); | ||
@@ -32,0 +40,0 @@ } |
{ | ||
"name": "dargs", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Converts an object of options into an array of command-line arguments", | ||
@@ -11,3 +11,5 @@ "repository": "sindresorhus/dargs", | ||
"flags", | ||
"cli" | ||
"cli", | ||
"nopt", | ||
"minimist" | ||
], | ||
@@ -14,0 +16,0 @@ "author": { |
@@ -35,7 +35,7 @@ # dargs [![Build Status](https://travis-ci.org/sindresorhus/dargs.svg?branch=master)](https://travis-ci.org/sindresorhus/dargs) | ||
[ | ||
'--foo=bar', | ||
'--hello', | ||
'--camel-case=5', | ||
'--multiple=value', | ||
'--multiple=value2' | ||
"--foo='bar'", | ||
"--hello", | ||
"--camel-case='5'", | ||
"--multiple='value'", | ||
"--multiple='value2'" | ||
] | ||
@@ -42,0 +42,0 @@ */ |
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
2580
32