[Pkg-javascript-commits] [node-dargs] 49/54: Add `allowCamelCase` option (#34)

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:41:06 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 96fdf065f7bc0a81d613bbf073640bf7a456a775
Author: Jarid Margolin <jaridmargolin at gmail.com>
Date:   Thu Sep 22 10:02:32 2016 -0700

    Add `allowCamelCase` option (#34)
---
 index.js  |  2 +-
 readme.md | 14 ++++++++++++++
 test.js   | 18 ++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index d3aa2c5..ab16539 100644
--- a/index.js
+++ b/index.js
@@ -11,7 +11,7 @@ module.exports = (input, opts) => {
 	}, opts);
 
 	const makeArg = (key, val) => {
-		key = '--' + key.replace(/[A-Z]/g, '-$&').toLowerCase(); // eslint-disable-line prefer-template
+		key = '--' + (opts.allowCamelCase ? key : key.replace(/[A-Z]/g, '-$&').toLowerCase()); // eslint-disable-line prefer-template
 
 		if (opts.useEquals) {
 			args.push(key + (val ? `=${val}` : ''));
diff --git a/readme.md b/readme.md
index 192af30..a8bb011 100644
--- a/readme.md
+++ b/readme.md
@@ -138,6 +138,20 @@ Default: `false`
 
 Exclude `false` values. Can be useful when dealing with strict argument parsers that throw on unknown arguments like `--no-foo`.
 
+##### allowCamelCase
+
+Type: `boolean`<br>
+Default: `false`
+
+By default dargs will convert camelcase arguments to hyphenated arguments. Setting this to true will bypass the conversion process. For example:
+
+```
+console.log(dargs({fooBar: 'baz'}));
+//=> ['--foo-bar', 'baz']
+
+console.log(dargs({fooBar: 'baz'}, {allowCamelCase: true}));
+//=> ['--fooBar', 'baz']
+```
 
 ## License
 
diff --git a/test.js b/test.js
index 1b5eefc..27bd1c0 100644
--- a/test.js
+++ b/test.js
@@ -113,3 +113,21 @@ test('includes and aliases options', t => {
 		'--camel-case-camel'
 	]);
 });
+
+test('camelCase option', t => {
+	t.deepEqual(m(fixture, {
+		allowCamelCase: true
+	}), [
+		'--a=foo',
+		'--b',
+		'--no-c',
+		'--d=5',
+		'--e=foo',
+		'--e=bar',
+		'--h=with a space',
+		'--i=let\'s try quotes',
+		'--camelCaseCamel',
+		'some',
+		'option'
+	]);
+});

-- 
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