Skip to content

Commit

Permalink
check that they type of a value is a boolean, not just that it is cur…
Browse files Browse the repository at this point in the history
…rently set to a boolean
  • Loading branch information
dominictarr committed Mar 10, 2015
1 parent 8c444fe commit 6863198
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
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];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6863198

Please sign in to comment.