[Pkg-javascript-commits] [node-minimist] 01/04: Imported Upstream version 1.1.1
Sebastiaan Couwenberg
sebastic at moszumanska.debian.org
Fri Mar 13 12:27:16 UTC 2015
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository node-minimist.
commit c8be86f006a6556320bd0e93be5126ddd107f689
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Fri Mar 13 13:13:03 2015 +0100
Imported Upstream version 1.1.1
---
index.js | 38 +++++++++++++++++++-------------------
package.json | 21 ++++++++++++---------
test/all_bool.js | 2 +-
test/default_bool.js | 15 +++++++++++++++
test/parse_modified.js | 2 +-
5 files changed, 48 insertions(+), 30 deletions(-)
diff --git a/index.js b/index.js
index cb0afc2..185a045 100644
--- a/index.js
+++ b/index.js
@@ -65,6 +65,25 @@ module.exports = function (args, opts) {
setKey(argv, x.split('.'), value);
});
}
+
+ function setKey (obj, keys, value) {
+ var o = obj;
+ keys.slice(0,-1).forEach(function (key) {
+ if (o[key] === undefined) o[key] = {};
+ o = o[key];
+ });
+
+ var key = keys[keys.length - 1];
+ if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
+ o[key] = value;
+ }
+ else if (Array.isArray(o[key])) {
+ o[key].push(value);
+ }
+ else {
+ o[key] = [ o[key], value ];
+ }
+ }
for (var i = 0; i < args.length; i++) {
var arg = args[i];
@@ -192,25 +211,6 @@ function hasKey (obj, keys) {
return key in o;
}
-function setKey (obj, keys, value) {
- var o = obj;
- keys.slice(0,-1).forEach(function (key) {
- if (o[key] === undefined) o[key] = {};
- o = o[key];
- });
-
- var key = keys[keys.length - 1];
- if (o[key] === undefined || typeof o[key] === 'boolean') {
- o[key] = value;
- }
- else if (Array.isArray(o[key])) {
- o[key].push(value);
- }
- else {
- o[key] = [ o[key], value ];
- }
-}
-
function isNumber (x) {
if (typeof x === 'number') return true;
if (/^0x[0-9a-f]+$/i.test(x)) return true;
diff --git a/package.json b/package.json
index 739179e..4247f4d 100644
--- a/package.json
+++ b/package.json
@@ -1,24 +1,27 @@
{
"name": "minimist",
- "version": "1.1.0",
+ "version": "1.1.1",
"description": "parse argument options",
"main": "index.js",
"devDependencies": {
- "tape": "~1.0.4",
+ "covert": "^1.0.0",
"tap": "~0.4.0",
- "covert": "^1.0.0"
+ "tape": "^3.5.0"
},
"scripts": {
"test": "tap test/*.js",
"coverage": "covert test/*.js"
},
- "testling" : {
- "files" : "test/*.js",
- "browsers" : [
+ "testling": {
+ "files": "test/*.js",
+ "browsers": [
"ie/6..latest",
- "ff/5", "firefox/latest",
- "chrome/10", "chrome/latest",
- "safari/5.1", "safari/latest",
+ "ff/5",
+ "firefox/latest",
+ "chrome/10",
+ "chrome/latest",
+ "safari/5.1",
+ "safari/latest",
"opera/12"
]
},
diff --git a/test/all_bool.js b/test/all_bool.js
index 4575ec0..ac83548 100644
--- a/test/all_bool.js
+++ b/test/all_bool.js
@@ -23,7 +23,7 @@ test('flag boolean true only affects double hyphen arguments without equals sign
t.deepEqual(argv, {
honk: true,
tacos: 'good',
- p: '55',
+ p: 55,
_: ['moo', 'cow']
});
diff --git a/test/default_bool.js b/test/default_bool.js
index f0041ee..780a311 100644
--- a/test/default_bool.js
+++ b/test/default_bool.js
@@ -18,3 +18,18 @@ test('boolean default false', function (t) {
t.equal(argv.somefalse, false);
t.end();
});
+
+test('boolean default to null', function (t) {
+ var argv = parse([], {
+ boolean: 'maybe',
+ default: { maybe: null }
+ });
+ t.equal(argv.maybe, null);
+ var argv = parse(['--maybe'], {
+ boolean: 'maybe',
+ default: { maybe: null }
+ });
+ t.equal(argv.maybe, true);
+ t.end();
+
+})
diff --git a/test/parse_modified.js b/test/parse_modified.js
index 21851b0..ab620dc 100644
--- a/test/parse_modified.js
+++ b/test/parse_modified.js
@@ -5,5 +5,5 @@ test('parse with modifier functions' , function (t) {
t.plan(1);
var argv = parse([ '-b', '123' ], { boolean: 'b' });
- t.deepEqual(argv, { b: true, _: ['123'] });
+ t.deepEqual(argv, { b: true, _: [123] });
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-minimist.git
More information about the Pkg-javascript-commits
mailing list