mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 12:27:49 +00:00
Merge branch 'betterIsX' of https://github.com/michaelficarra/underscore
This commit is contained in:
@@ -435,14 +435,15 @@ $(document).ready(function() {
|
|||||||
ok(!_.isNumber(arguments), 'the arguments object is not a number');
|
ok(!_.isNumber(arguments), 'the arguments object is not a number');
|
||||||
ok(!_.isNumber(undefined), 'undefined is not a number');
|
ok(!_.isNumber(undefined), 'undefined is not a number');
|
||||||
ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are');
|
ok(_.isNumber(3 * 4 - 7 / 10), 'but numbers are');
|
||||||
ok(!_.isNumber(NaN), 'NaN is not a number');
|
ok(_.isNumber(NaN), 'NaN *is* a number');
|
||||||
ok(_.isNumber(Infinity), 'Infinity is a number');
|
ok(_.isNumber(Infinity), 'Infinity is a number');
|
||||||
ok(_.isNumber(iNumber), 'even from another frame');
|
ok(_.isNumber(iNumber), 'even from another frame');
|
||||||
|
ok(!_.isNumber('1'), 'numeric strings are not numbers');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("objects: isBoolean", function() {
|
test("objects: isBoolean", function() {
|
||||||
ok(!_.isBoolean(2), 'a number is not a boolean');
|
ok(!_.isBoolean(2), 'a number is not a boolean');
|
||||||
ok(!_.isBoolean("string"), 'a string is not a boolean');
|
ok(!_.isBoolean("string"), 'a string is not a boolean');
|
||||||
ok(!_.isBoolean("false"), 'the string "false" is not a boolean');
|
ok(!_.isBoolean("false"), 'the string "false" is not a boolean');
|
||||||
ok(!_.isBoolean("true"), 'the string "true" is not a boolean');
|
ok(!_.isBoolean("true"), 'the string "true" is not a boolean');
|
||||||
ok(!_.isBoolean(arguments), 'the arguments object is not a boolean');
|
ok(!_.isBoolean(arguments), 'the arguments object is not a boolean');
|
||||||
|
|||||||
@@ -733,7 +733,8 @@
|
|||||||
return eq(a, b, []);
|
return eq(a, b, []);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Is a given array or object empty?
|
// Is a given array, string, or object empty?
|
||||||
|
// An "empty" object has no enumerable own-properties.
|
||||||
_.isEmpty = function(obj) {
|
_.isEmpty = function(obj) {
|
||||||
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
|
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
|
||||||
for (var key in obj) if (hasOwnProperty.call(obj, key)) return false;
|
for (var key in obj) if (hasOwnProperty.call(obj, key)) return false;
|
||||||
@@ -748,7 +749,7 @@
|
|||||||
// Is a given value an array?
|
// Is a given value an array?
|
||||||
// Delegates to ECMA5's native Array.isArray
|
// Delegates to ECMA5's native Array.isArray
|
||||||
_.isArray = nativeIsArray || function(obj) {
|
_.isArray = nativeIsArray || function(obj) {
|
||||||
return toString.call(obj) === '[object Array]';
|
return toString.call(obj) == '[object Array]';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Is a given variable an object?
|
// Is a given variable an object?
|
||||||
@@ -757,23 +758,30 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Is a given variable an arguments object?
|
// Is a given variable an arguments object?
|
||||||
_.isArguments = function(obj) {
|
_.isArguments = toString.call(arguments) == '[object Arguments]'
|
||||||
return !!(obj && hasOwnProperty.call(obj, 'callee'));
|
? function(obj) {
|
||||||
};
|
return toString.call(obj) == '[object Arguments]';
|
||||||
|
}
|
||||||
|
: function(obj) {
|
||||||
|
return obj
|
||||||
|
? hasOwnProperty.call(obj, 'callee')
|
||||||
|
&& hasOwnProperty.call(obj, 'length')
|
||||||
|
: false;
|
||||||
|
};
|
||||||
|
|
||||||
// Is a given value a function?
|
// Is a given value a function?
|
||||||
_.isFunction = function(obj) {
|
_.isFunction = function(obj) {
|
||||||
return !!(obj && obj.constructor && obj.call && obj.apply);
|
return toString.call(obj) == '[object Function]';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Is a given value a string?
|
// Is a given value a string?
|
||||||
_.isString = function(obj) {
|
_.isString = function(obj) {
|
||||||
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
|
return toString.call(obj) == '[object String]';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Is a given value a number?
|
// Is a given value a number?
|
||||||
_.isNumber = function(obj) {
|
_.isNumber = function(obj) {
|
||||||
return !!(obj === 0 || (obj && obj.toExponential && obj.toFixed));
|
return toString.call(obj) == '[object Number]';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Is the given value `NaN`?
|
// Is the given value `NaN`?
|
||||||
@@ -789,12 +797,12 @@
|
|||||||
|
|
||||||
// Is a given value a date?
|
// Is a given value a date?
|
||||||
_.isDate = function(obj) {
|
_.isDate = function(obj) {
|
||||||
return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear);
|
return toString.call(obj) == '[object Date]';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Is the given value a regular expression?
|
// Is the given value a regular expression?
|
||||||
_.isRegExp = function(obj) {
|
_.isRegExp = function(obj) {
|
||||||
return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false));
|
return toString.call(obj) == '[object RegExp]';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Is a given value equal to null?
|
// Is a given value equal to null?
|
||||||
|
|||||||
Reference in New Issue
Block a user