[Pkg-javascript-commits] [node-dargs] 18/54: add param, allowing an 'includes' array

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 b870ff3e5717dde1a40510d7d87380360adb351c
Author: joseph bartels <joebartels at hotmail.com>
Date:   Sat Oct 25 23:58:51 2014 -0400

    add param, allowing an 'includes' array
    
    update readme.md with api for includes
---
 index.js  |  6 +++++-
 readme.md | 31 +++++++++++++++++++++++++++++--
 test.js   | 22 ++++++++++++++++++++++
 3 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index c547c1d..fca680d 100644
--- a/index.js
+++ b/index.js
@@ -5,7 +5,7 @@ function createArg(key, val) {
 	return '--' + key + (val ? '=' + val : '');
 };
 
-module.exports = function (opts, excludes) {
+module.exports = function (opts, excludes, includes) {
 	var args = [];
 
 	Object.keys(opts).forEach(function (key) {
@@ -15,6 +15,10 @@ module.exports = function (opts, excludes) {
 			return;
 		}
 
+		if (Array.isArray(includes) && includes.indexOf(key) === -1) {
+			return;
+		}
+
 		if (val === true) {
 			args.push(createArg(key));
 		}
diff --git a/readme.md b/readme.md
index d600efe..34ea222 100644
--- a/readme.md
+++ b/readme.md
@@ -27,6 +27,7 @@ var options = {
 };
 
 var excludes = ['sad'];
+var includes = ['camelCase', 'multiple', 'sad'];
 
 console.log(dargs(options, excludes));
 
@@ -39,12 +40,33 @@ console.log(dargs(options, excludes));
 	"--multiple=value2"
 ]
 */
-```
 
+console.log(dargs(options, excludes, includes));
+
+/*
+[
+	"--camel-case=5",
+	"--multiple=value",
+	"--multiple=value2"
+]
+*/
+
+
+console.log(dargs(options, [], includes));
+
+/*
+[
+	"--camel-case=5",
+	"--multiple=value",
+	"--multiple=value2",
+	"--sad=:("
+]
+*/
+```
 
 ## API
 
-### dargs(options, excludes)
+### dargs(options, excludes, includes)
 
 #### options
 
@@ -58,6 +80,11 @@ Type: `array`
 
 Keys to exclude.
 
+#### includes
+
+Type: `array`
+
+Keys to include. (if a key is in both `excludes` and `includes`, it will be excluded)
 
 ## License
 
diff --git a/test.js b/test.js
index 281fafa..fd2dd08 100644
--- a/test.js
+++ b/test.js
@@ -39,3 +39,25 @@ it('exclude options', function () {
 	];
 	assert.deepEqual(actual, expected);
 });
+
+it('includes options', function() {
+	var actual = dargs(fixture, [], ['a', 'c', 'd', 'e', 'camelCaseCamel']);
+	var expected = [
+		"--a=foo",
+		"--d=5",
+		"--e=foo",
+		"--e=bar",
+		"--camel-case-camel"
+	];
+	assert.deepEqual(actual, expected);
+});
+
+it('excludes and includes options', function() {
+	var actual = dargs(fixture, ['a', 'd'], ['a', 'c', 'd', 'e', 'camelCaseCamel']);
+	var expected = [
+		"--e=foo",
+		"--e=bar",
+		"--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