[Pkg-javascript-commits] [node-optimist] 11/33: Imported Upstream version 0.5.2
Sebastiaan Couwenberg
sebastic at moszumanska.debian.org
Fri Feb 27 23:21:47 UTC 2015
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository node-optimist.
commit dd780d93105738129e05b39ae75efec61e584033
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Fri Feb 27 20:00:32 2015 +0100
Imported Upstream version 0.5.2
---
index.js | 18 ++++++++++++------
package.json | 2 +-
test/whitespace.js | 8 ++++++++
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/index.js b/index.js
index 67e17d8..5f3d53a 100644
--- a/index.js
+++ b/index.js
@@ -310,10 +310,9 @@ function Argv (args, cwd) {
});
function setArg (key, val) {
- var num = Number(val);
- var value = typeof val !== 'string' || isNaN(num) ? val : num;
- if (flags.strings[key]) value = val;
-
+ var value = !flags.strings[key] && isNumber(val)
+ ? Number(val) : val
+ ;
setKey(argv, key.split('.'), value);
(aliases[key] || []).forEach(function (x) {
@@ -403,8 +402,9 @@ function Argv (args, cwd) {
}
}
else {
- var n = Number(arg);
- argv._.push(flags.strings['_'] || isNaN(n) ? arg : n);
+ argv._.push(
+ flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)
+ );
}
}
@@ -490,3 +490,9 @@ function setKey (obj, keys, value) {
o[key] = [ o[key], value ];
}
}
+
+function isNumber (x) {
+ if (typeof x === 'number') return true;
+ if (/^0x[0-9a-f]+$/i.test(x)) return true;
+ return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
+}
diff --git a/package.json b/package.json
index a5eb246..2a370fe 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name" : "optimist",
- "version" : "0.5.1",
+ "version" : "0.5.2",
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
"main" : "./index.js",
"dependencies" : {
diff --git a/test/whitespace.js b/test/whitespace.js
new file mode 100644
index 0000000..90b9075
--- /dev/null
+++ b/test/whitespace.js
@@ -0,0 +1,8 @@
+var optimist = require('../');
+var test = require('tap').test;
+
+test('whitespace should be whitespace' , function (t) {
+ t.plan(1);
+ var x = optimist.parse([ '-x', '\t' ]).x;
+ t.equal(x, '\t');
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/node-optimist.git
More information about the Pkg-javascript-commits
mailing list