[Pkg-javascript-commits] [node-dargs] 01/54: init

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:41:01 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 bc5894b71229a187b99412a76fda914e8dbd8836
Author: Sindre Sorhus <sindresorhus at gmail.com>
Date:   Fri Apr 19 00:50:18 2013 +0200

    init
---
 .editorconfig  | 12 ++++++++++++
 .gitattributes |  1 +
 .jshintrc      | 21 +++++++++++++++++++++
 .travis.yml    |  4 ++++
 dargs.js       | 36 ++++++++++++++++++++++++++++++++++++
 package.json   | 39 +++++++++++++++++++++++++++++++++++++++
 readme.md      | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test.js        | 41 +++++++++++++++++++++++++++++++++++++++++
 8 files changed, 211 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..b0d7fd9
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+# editorconfig.org
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..19efbf5
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,21 @@
+{
+	"node": true,
+	"es5": true,
+	"esnext": true,
+	"bitwise": true,
+	"camelcase": true,
+	"curly": true,
+	"eqeqeq": true,
+	"immed": true,
+	"indent": 4,
+	"latedef": true,
+	"newcap": true,
+	"noarg": true,
+	"quotmark": "single",
+	"regexp": true,
+	"undef": true,
+	"unused": true,
+	"strict": true,
+	"trailing": true,
+	"smarttabs": true
+}
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..2cdacaf
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - '0.10'
+  - '0.8'
diff --git a/dargs.js b/dargs.js
new file mode 100644
index 0000000..507c9e4
--- /dev/null
+++ b/dargs.js
@@ -0,0 +1,36 @@
+'use strict';
+
+module.exports = function (options, excludes) {
+	var args = [];
+
+	Object.keys(options).forEach(function (key) {
+		var flag;
+		var val = options[key];
+
+		if (Array.isArray(excludes) && excludes.indexOf(key) !== -1) {
+			return;
+		}
+
+		flag = key.replace(/[A-Z]/g, '-$&').toLowerCase();
+
+		if (val === true) {
+			args.push('--' + flag);
+		}
+
+		if (typeof val === 'string') {
+			args.push('--' + flag, val);
+		}
+
+		if (typeof val === 'number' && isNaN(val) === false) {
+			args.push('--' + flag, '' + val);
+		}
+
+		if (Array.isArray(val)) {
+			val.forEach(function (arrVal) {
+				args.push('--' + flag, arrVal);
+			});
+		}
+	});
+
+	return args;
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..7c6dfba
--- /dev/null
+++ b/package.json
@@ -0,0 +1,39 @@
+{
+  "name": "dargs",
+  "version": "0.0.0",
+  "description": "Converts an object of options into an array of command-line arguments. Useful when calling command-line tools.",
+  "keywords": [
+    "options",
+    "arguments",
+    "args",
+    "flags",
+    "cli"
+  ],
+  "homepage": "https://github.com/sindresorhus/dargs",
+  "bugs": "https://github.com/sindresorhus/dargs/issues",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at gmail.com",
+    "url": "http://sindresorhus.com"
+  },
+  "main": "dargs.js",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/sindresorhus/dargs.git"
+  },
+  "scripts": {
+    "test": "mocha"
+  },
+  "devDependencies": {
+    "mocha": "~1.9.0"
+  },
+  "engines": {
+    "node": ">=0.8.0"
+  },
+  "licenses": [
+    {
+      "type": "MIT"
+    }
+  ],
+  "files": ["dargs.js"]
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..e9df5ed
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,57 @@
+# dargs [![Build Status](https://secure.travis-ci.org/sindresorhus/dargs.png?branch=master)](http://travis-ci.org/sindresorhus/dargs)
+
+> Converts an object of options into an array of command-line arguments
+
+
+## Getting started
+
+Install: `npm install --save dargs`
+
+
+#### Example
+
+```js
+var dargs = require('dargs');
+
+var options = {
+	foo: 'bar',
+	hello: true,                    // results in only the key being used
+	cake: false,                    // ignored
+	camelCase: 5,                   // camelCase is slugged to `camel-case`
+	multiple: ['value', 'value2'],  // converted to multiple arguments
+	sad: ':('
+};
+
+var excludes = ['sad'];
+
+console.log(dargs(options, excludes));
+
+/*
+[
+	'--foo', 'bar',
+	'--hello',
+	'--camel-case', '5',
+	'--multiple', 'value',
+	'--multiple', 'value2'
+]
+*/
+```
+
+
+## Documentation
+
+
+### options
+
+Object of options to convert to command-line arguments.
+
+
+### excludes
+
+Array of keys to exclude.
+
+
+
+## License
+
+MIT License • © [Sindre Sorhus](http://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..5cb423c
--- /dev/null
+++ b/test.js
@@ -0,0 +1,41 @@
+/*global describe, it */
+'use strict';
+var assert = require('assert');
+var dargs = require('./dargs');
+
+
+var fixture = {
+	a: 'foo',
+	b: true,
+	c: false,
+	d: 5,
+	e: ['foo', 'bar'],
+	f: null,
+	g: undefined,
+	camelCaseCamel: true
+};
+
+describe('dargs()', function () {
+	it('convert options to cli flags', function () {
+		var actual = dargs(fixture);
+		var expected = [
+			'--a', 'foo',
+			'--b',
+			'--d', '5',
+			'--e', 'foo',
+			'--e', 'bar',
+			'--camel-case-camel'
+		];
+		assert.deepEqual(actual, expected);
+	});
+
+	it('exclude options', function () {
+		var actual = dargs(fixture, ['b', 'e']);
+		var expected = [
+			'--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