Skip to content

Commit

Permalink
fixed the whitespace bug without breaking anything else
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 31, 2013
1 parent 5a3dd1a commit 4497ca5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
);
}
}

Expand Down Expand Up @@ -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);
}

0 comments on commit 4497ca5

Please sign in to comment.