exports.isArray = isArray;
function isBoolean(arg) {
- return typeof arg === 'boolean';
+ return typeof arg === 'boolean' || objectToString(arg) === '[object Boolean]';
}
exports.isBoolean = isBoolean;
exports.isNullOrUndefined = isNullOrUndefined;
function isNumber(arg) {
- return typeof arg === 'number';
+ return typeof arg === 'number' || objectToString(arg) === '[object Number]';
}
exports.isNumber = isNumber;
function isString(arg) {
- return typeof arg === 'string';
+ return typeof arg === 'string' || objectToString(arg) === '[object String]';
}
exports.isString = isString;
[{e: extendedFunction}, 'e=', {'e': ''}],
[{d: new Date()}, 'd=', {'d': ''}],
[{d: Date}, 'd=', {'d': ''}],
- [{f: new Boolean(false), t: new Boolean(true)}, 'f=&t=', {'f': '', 't': ''}],
+ [{
+ f: new Boolean(false),
+ t: new Boolean(true)},
+ 'f=false&t=true',
+ {'f': 'false', 't': 'true'}
+ ],
[{f: false, t: true}, 'f=false&t=true', {'f': 'false', 't': 'true'}],
[{n: null}, 'n=', {'n': ''}],
[{nan: NaN}, 'nan=', {'nan': ''}],
var util = require('util');
var context = require('vm').runInNewContext;
+// isBoolean
+assert.equal(true, util.isBoolean(true));
+assert.equal(true, util.isBoolean(false));
+assert.equal(true, util.isBoolean(Boolean()));
+assert.equal(true, util.isBoolean(new Boolean()));
+assert.equal(true, util.isBoolean(new Boolean(true)));
+assert.equal(true, util.isBoolean(context('Boolean')()));
+assert.equal(false, util.isBoolean({}));
+assert.equal(false, util.isBoolean(/regexp/));
+
+// isNumber
+assert.equal(true, util.isNumber(0));
+assert.equal(true, util.isNumber(NaN));
+assert.equal(true, util.isNumber(Number()));
+assert.equal(true, util.isNumber(new Number()));
+assert.equal(true, util.isNumber(new Number(10)));
+assert.equal(true, util.isNumber(context('Number')()));
+assert.equal(false, util.isNumber({}));
+assert.equal(false, util.isNumber(/regexp/));
+
+// isString
+assert.equal(true, util.isString('string'));
+assert.equal(true, util.isString(String()));
+assert.equal(true, util.isString(new String()));
+assert.equal(true, util.isString(new String(10)));
+assert.equal(true, util.isString(context('String')()));
+assert.equal(false, util.isString({}));
+assert.equal(false, util.isString(/regexp/));
+
// isArray
assert.equal(true, util.isArray([]));
assert.equal(true, util.isArray(Array()));