[Pkg-javascript-commits] [node-dargs] 13/54: only quote multi word values

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:41:02 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-dargs.

commit aefc2d1a838c3d9f61e3a2bc8354eea08b47b5a1
Author: Sindre Sorhus <sindresorhus at gmail.com>
Date:   Wed Aug 27 15:21:30 2014 +0200

    only quote multi word values
    
    fixes #8
    fixes #9
    fixes gruntjs/grunt-contrib-sass#150
    fixes gruntjs/grunt-contrib-sass#151
    fixes gruntjs/grunt-contrib-sass#152
---
 index.js  |  3 ++-
 readme.md | 10 ++++++----
 test.js   | 12 ++++++------
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/index.js b/index.js
index 0bb67c2..cf83f60 100644
--- a/index.js
+++ b/index.js
@@ -6,8 +6,9 @@ var escape = function (value) {
 
 var constructOption = function (name, value) {
 	name = name.replace(/[A-Z]/g, '-$&').toLowerCase();
+	var quotedVal = /\W/.test(value) ? ("'" + escape(value) + "'") : value;
 
-	return '--' + name + (value ? "='" + escape(value) + "'": '');
+	return '--' + name + (value ? "=" + quotedVal : '');
 };
 
 module.exports = function (options, excludes) {
diff --git a/readme.md b/readme.md
index da486e2..2ca8929 100644
--- a/readme.md
+++ b/readme.md
@@ -19,6 +19,7 @@ var dargs = require('dargs');
 
 var options = {
 	foo: 'bar',
+	unicorn: 'rainbows and ponies', // quoted when more than just a word
 	hello: true,                    // results in only the key being used
 	cake: false,                    // ignored
 	camelCase: 5,                   // camelCase is slugged to `camel-case`
@@ -32,11 +33,12 @@ console.log(dargs(options, excludes));
 
 /*
 [
-	"--foo='bar'",
+	"--foo=bar",
+	"--unicorn='rainbows and ponies'"
 	"--hello",
-	"--camel-case='5'",
-	"--multiple='value'",
-	"--multiple='value2'"
+	"--camel-case=5",
+	"--multiple=value",
+	"--multiple=value2"
 ]
 */
 ```
diff --git a/test.js b/test.js
index e3b6207..b910aad 100644
--- a/test.js
+++ b/test.js
@@ -19,11 +19,11 @@ describe('dargs()', function () {
 	it('convert options to cli flags', function () {
 		var actual = dargs(fixture);
 		var expected = [
-			"--a='foo'",
+			"--a=foo",
 			"--b",
-			"--d='5'",
-			"--e='foo'",
-			"--e='bar'",
+			"--d=5",
+			"--e=foo",
+			"--e=bar",
 			"--h='with a space'",
 			"--i='let'\''s try quotes'",
 			"--camel-case-camel"
@@ -34,8 +34,8 @@ describe('dargs()', function () {
 	it('exclude options', function () {
 		var actual = dargs(fixture, ['b', 'e', 'h', 'i']);
 		var expected = [
-			"--a='foo'",
-			"--d='5'",
+			"--a=foo",
+			"--d=5",
 			"--camel-case-camel"
 		];
 		assert.deepEqual(actual, expected);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-dargs.git



More information about the Pkg-javascript-commits mailing list