From d6883a077a154936e98a7cfecdad3531d49a1872 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 2 Sep 2014 01:43:31 -0700 Subject: [PATCH] Add `Lang` category. --- lodash.js | 1128 +++++++++++++++++++++++++++-------------------------- 1 file changed, 565 insertions(+), 563 deletions(-) diff --git a/lodash.js b/lodash.js index 74dcf150b..febb65d40 100644 --- a/lodash.js +++ b/lodash.js @@ -765,7 +765,7 @@ } }); - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * Creates a `lodash` object which wraps the given value to enable intuitive @@ -1084,7 +1084,7 @@ } }; - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * A specialized version of `_.forEach` for arrays without support for @@ -3167,7 +3167,7 @@ return isObject(value) ? value : Object(value); } - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * Creates an array of elements split into groups the length of `size`. @@ -4438,7 +4438,7 @@ return result; } - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * Creates a `lodash` object that wraps `value` with explicit method @@ -4559,7 +4559,7 @@ return this.__wrapped__; } - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * Creates an array of elements corresponding to the specified keys, or indexes, @@ -5704,7 +5704,7 @@ return filter(collection, matches(source)); } - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * The opposite of `_.before`; this method creates a function that invokes @@ -6529,37 +6529,7 @@ return basePartial(wrapper, PARTIAL_FLAG, [value], []); } - /*--------------------------------------------------------------------------*/ - - /** - * Assigns own enumerable properties of source object(s) to the destination - * object. Subsequent sources overwrite property assignments of previous sources. - * If `customizer` is provided it is invoked to produce the assigned values. - * The `customizer` is bound to `thisArg` and invoked with five arguments; - * (objectValue, sourceValue, key, object, source). - * - * @static - * @memberOf _ - * @alias extend - * @category Object - * @param {Object} object The destination object. - * @param {...Object} [sources] The source objects. - * @param {Function} [customizer] The function to customize assigning values. - * @param {*} [thisArg] The `this` binding of `customizer`. - * @returns {Object} Returns the destination object. - * @example - * - * _.assign({ 'name': 'fred' }, { 'age': 40 }, { 'employer': 'slate' }); - * // => { 'name': 'fred', 'age': 40, 'employer': 'slate' } - * - * var defaults = _.partialRight(_.assign, function(value, other) { - * return typeof value == 'undefined' ? other : value; - * }); - * - * defaults({ 'name': 'barney' }, { 'age': 36 }, { 'name': 'fred', 'employer': 'slate' }); - * // => { 'name': 'barney', 'age': 36, 'employer': 'slate' } - */ - var assign = createAssigner(baseAssign); + /*------------------------------------------------------------------------*/ /** * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned, @@ -6576,7 +6546,7 @@ * * @static * @memberOf _ - * @category Object + * @category Lang * @param {*} value The value to clone. * @param {boolean} [isDeep=false] Specify a deep clone. * @param {Function} [customizer] The function to customize cloning values. @@ -6639,7 +6609,7 @@ * * @static * @memberOf _ - * @category Object + * @category Lang * @param {*} value The value to deep clone. * @param {Function} [customizer] The function to customize cloning values. * @param {*} [thisArg] The `this` binding of `customizer`. @@ -6672,6 +6642,556 @@ return baseClone(value, true, customizer); } + /** + * Checks if `value` is classified as an `arguments` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, else `false`. + * @example + * + * (function() { return _.isArguments(arguments); })(); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ + function isArguments(value) { + var length = (value && typeof value == 'object') ? value.length : undefined; + return (typeof length == 'number' && length > -1 && length <= MAX_SAFE_INTEGER && + toString.call(value) == argsClass) || false; + } + // fallback for environments without a `[[Class]]` for `arguments` objects + if (!support.argsClass) { + isArguments = function(value) { + var length = (value && typeof value == 'object') ? value.length : undefined; + return (typeof length == 'number' && length > -1 && length <= MAX_SAFE_INTEGER && + hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee')) || false; + }; + } + + /** + * Checks if `value` is classified as an `Array` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isArray([1, 2, 3]); + * // => true + * + * (function() { return _.isArray(arguments); })(); + * // => false + */ + var isArray = nativeIsArray || function(value) { + return (value && typeof value == 'object' && typeof value.length == 'number' && + toString.call(value) == arrayClass) || false; + }; + + /** + * Checks if `value` is classified as a boolean primitive or object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isBoolean(false); + * // => true + * + * _.isBoolean(null); + * // => false + */ + function isBoolean(value) { + return (value === true || value === false || + value && typeof value == 'object' && toString.call(value) == boolClass) || false; + } + + /** + * Checks if `value` is classified as a `Date` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isDate(new Date); + * // => true + * + * _.isDate('Mon April 23 2012'); + * // => false + */ + function isDate(value) { + return (value && typeof value == 'object' && toString.call(value) == dateClass) || false; + } + + /** + * Checks if `value` is a DOM element. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. + * @example + * + * _.isElement(document.body); + * // => true + * + * _.isElement(''); + * // => false + */ + function isElement(value) { + return (value && typeof value == 'object' && value.nodeType === 1 && + (support.nodeClass ? toString.call(value).indexOf('Element') > -1 : isHostObject(value))) || false; + } + // fallback for environments without DOM support + if (!support.dom) { + isElement = function(value) { + return (value && typeof value == 'object' && value.nodeType === 1 && + !isPlainObject(value)) || false; + }; + } + + /** + * Checks if a collection is empty. A value is considered empty unless it is + * an array-like value with a length greater than `0` or an object with own + * enumerable properties. + * + * @static + * @memberOf _ + * @category Lang + * @param {Array|Object|string} value The value to inspect. + * @returns {boolean} Returns `true` if `value` is empty, else `false`. + * @example + * + * _.isEmpty(null); + * // => true + * + * _.isEmpty(true); + * // => true + * + * _.isEmpty(1); + * // => true + * + * _.isEmpty([1, 2, 3]); + * // => false + * + * _.isEmpty({ 'a': 1 }); + * // => false + */ + function isEmpty(value) { + if (value == null) { + return true; + } + var length = value.length; + if ((typeof length == 'number' && length > -1 && length <= MAX_SAFE_INTEGER) && + (isArray(value) || isString(value) || isArguments(value) || + (typeof value == 'object' && isFunction(value.splice)))) { + return !length; + } + return !keys(value).length; + } + + /** + * Performs a deep comparison between two values to determine if they are + * equivalent. If `customizer` is provided it is invoked to compare values. + * If `customizer` returns `undefined` comparisons are handled by the method + * instead. The `customizer` is bound to `thisArg` and invoked with three + * arguments; (value, other, key). + * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Functions and DOM nodes + * are **not** supported. Provide a customizer function to extend support + * for comparing other values. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to compare to `other`. + * @param {*} other The value to compare to `value`. + * @param {Function} [customizer] The function to customize comparing values. + * @param {*} [thisArg] The `this` binding of `customizer`. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * var object = { 'name': 'fred' }; + * var other = { 'name': 'fred' }; + * + * object == other; + * // => false + * + * _.isEqual(object, other); + * // => true + * + * var words = ['hello', 'goodbye']; + * var otherWords = ['hi', 'goodbye']; + * + * _.isEqual(words, otherWords, function() { + * return _.every(arguments, _.bind(RegExp.prototype.test, /^h(?:i|ello)$/)) || undefined; + * }); + * // => true + */ + function isEqual(value, other, customizer, thisArg) { + customizer = typeof customizer == 'function' && baseCallback(customizer, thisArg, 3); + return (!customizer && isStrictComparable(value) && isStrictComparable(other)) + ? value === other + : baseIsEqual(value, other, customizer); + } + + /** + * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, + * `SyntaxError`, `TypeError`, or `URIError` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an error object, else `false`. + * @example + * + * _.isError(new Error); + * // => true + * + * _.isError(Error); + * // => false + */ + function isError(value) { + return (value && typeof value == 'object' && toString.call(value) == errorClass) || false; + } + + /** + * Checks if `value` is a finite primitive number. + * + * **Note:** This method is based on ES6 `Number.isFinite`. See the + * [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite) + * for more details. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. + * @example + * + * _.isFinite(10); + * // => true + * + * _.isFinite('10'); + * // => false + * + * _.isFinite(true); + * // => false + * + * _.isFinite(Object(10)); + * // => false + * + * _.isFinite(Infinity); + * // => false + */ + var isFinite = nativeNumIsFinite || function(value) { + return typeof value == 'number' && nativeIsFinite(value); + }; + + /** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ + function isFunction(value) { + // avoid a Chakra bug in IE 11 + // https://github.com/jashkenas/underscore/issues/1621 + return typeof value == 'function' || false; + } + // fallback for older versions of Chrome and Safari + if (isFunction(/x/)) { + isFunction = function(value) { + return typeof value == 'function' && toString.call(value) == funcClass; + }; + } + + /** + * Checks if `value` is the language type of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * **Note:** See the [ES5 spec](http://es5.github.io/#x8) for more details. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ + function isObject(value) { + // avoid a V8 bug in Chrome 19-20 + // https://code.google.com/p/v8/issues/detail?id=2291 + var type = typeof value; + return type == 'function' || (value && type == 'object') || false; + } + + /** + * Checks if `value` is `NaN`. + * + * **Note:** This method is not the same as native `isNaN` which returns `true` + * for `undefined` and other non-numeric values. See the [ES5 spec](http://es5.github.io/#x15.1.2.4) + * for more details. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + * @example + * + * _.isNaN(NaN); + * // => true + * + * _.isNaN(new Number(NaN)); + * // => true + * + * isNaN(undefined); + * // => true + * + * _.isNaN(undefined); + * // => false + */ + function isNaN(value) { + // `NaN` as a primitive is the only value that is not equal to itself + // (perform the `[[Class]]` check first to avoid errors with some host objects in IE) + return isNumber(value) && value != +value; + } + + /** + * Checks if `value` is a native function. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, else `false`. + */ + function isNative(value) { + if (isFunction(value)) { + return reNative.test(fnToString.call(value)); + } + return (value && typeof value == 'object' && + (isHostObject(value) ? reNative : reHostCtor).test(value)) || false; + } + + /** + * Checks if `value` is `null`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `null`, else `false`. + * @example + * + * _.isNull(null); + * // => true + * + * _.isNull(void 0); + * // => false + */ + function isNull(value) { + return value === null; + } + + /** + * Checks if `value` is classified as a `Number` primitive or object. + * + * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified + * as numbers, use the `_.isFinite` method. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isNumber(8.4); + * // => true + * + * _.isNumber(NaN); + * // => true + * + * _.isNumber('8.4'); + * // => false + */ + function isNumber(value) { + var type = typeof value; + return type == 'number' || + (value && type == 'object' && toString.call(value) == numberClass) || false; + } + + /** + * Checks if `value` is an object created by the `Object` constructor or has + * a `[[Prototype]]` of `null`. + * + * **Note:** This method assumes objects created by the `Object` constructor + * have no inherited enumerable properties. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + * @example + * + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * _.isPlainObject(new Shape); + * // => false + * + * _.isPlainObject([1, 2, 3]); + * // => false + * + * _.isPlainObject({ 'x': 0, 'y': 0 }); + * // => true + * + * _.isPlainObject(Object.create(null)); + * // => true + */ + var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) { + if (!(value && toString.call(value) == objectClass) || (!support.argsClass && isArguments(value))) { + return false; + } + var valueOf = value.valueOf, + objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); + + return objProto + ? (value == objProto || getPrototypeOf(value) == objProto) + : shimIsPlainObject(value); + }; + + /** + * Checks if `value` is classified as a `RegExp` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isRegExp(/abc/); + * // => true + * + * _.isRegExp('/abc/'); + * // => false + */ + function isRegExp(value) { + return (isObject(value) && toString.call(value) == regexpClass) || false; + } + + /** + * Checks if `value` is classified as a `String` primitive or object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isString('abc'); + * // => true + * + * _.isString(1); + * // => false + */ + function isString(value) { + return typeof value == 'string' || + (value && typeof value == 'object' && toString.call(value) == stringClass) || false; + } + + /** + * Checks if `value` is `undefined`. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. + * @example + * + * _.isUndefined(void 0); + * // => true + * + * _.isUndefined(null); + * // => false + */ + function isUndefined(value) { + return typeof value == 'undefined'; + } + + /*------------------------------------------------------------------------*/ + + /** + * Assigns own enumerable properties of source object(s) to the destination + * object. Subsequent sources overwrite property assignments of previous sources. + * If `customizer` is provided it is invoked to produce the assigned values. + * The `customizer` is bound to `thisArg` and invoked with five arguments; + * (objectValue, sourceValue, key, object, source). + * + * @static + * @memberOf _ + * @alias extend + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @param {Function} [customizer] The function to customize assigning values. + * @param {*} [thisArg] The `this` binding of `customizer`. + * @returns {Object} Returns the destination object. + * @example + * + * _.assign({ 'name': 'fred' }, { 'age': 40 }, { 'employer': 'slate' }); + * // => { 'name': 'fred', 'age': 40, 'employer': 'slate' } + * + * var defaults = _.partialRight(_.assign, function(value, other) { + * return typeof value == 'undefined' ? other : value; + * }); + * + * defaults({ 'name': 'barney' }, { 'age': 36 }, { 'name': 'fred', 'employer': 'slate' }); + * // => { 'name': 'barney', 'age': 36, 'employer': 'slate' } + */ + var assign = createAssigner(baseAssign); + /** * Creates an object that inherits from the given `prototype` object. If a * `properties` object is provided its own enumerable properties are assigned @@ -7029,524 +7549,6 @@ return result; } - /** - * Checks if `value` is classified as an `arguments` object. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an `arguments` object, else `false`. - * @example - * - * (function() { return _.isArguments(arguments); })(); - * // => true - * - * _.isArguments([1, 2, 3]); - * // => false - */ - function isArguments(value) { - var length = (value && typeof value == 'object') ? value.length : undefined; - return (typeof length == 'number' && length > -1 && length <= MAX_SAFE_INTEGER && - toString.call(value) == argsClass) || false; - } - // fallback for environments without a `[[Class]]` for `arguments` objects - if (!support.argsClass) { - isArguments = function(value) { - var length = (value && typeof value == 'object') ? value.length : undefined; - return (typeof length == 'number' && length > -1 && length <= MAX_SAFE_INTEGER && - hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee')) || false; - }; - } - - /** - * Checks if `value` is classified as an `Array` object. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. - * @example - * - * _.isArray([1, 2, 3]); - * // => true - * - * (function() { return _.isArray(arguments); })(); - * // => false - */ - var isArray = nativeIsArray || function(value) { - return (value && typeof value == 'object' && typeof value.length == 'number' && - toString.call(value) == arrayClass) || false; - }; - - /** - * Checks if `value` is classified as a boolean primitive or object. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. - * @example - * - * _.isBoolean(false); - * // => true - * - * _.isBoolean(null); - * // => false - */ - function isBoolean(value) { - return (value === true || value === false || - value && typeof value == 'object' && toString.call(value) == boolClass) || false; - } - - /** - * Checks if `value` is classified as a `Date` object. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. - * @example - * - * _.isDate(new Date); - * // => true - * - * _.isDate('Mon April 23 2012'); - * // => false - */ - function isDate(value) { - return (value && typeof value == 'object' && toString.call(value) == dateClass) || false; - } - - /** - * Checks if `value` is a DOM element. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. - * @example - * - * _.isElement(document.body); - * // => true - * - * _.isElement(''); - * // => false - */ - function isElement(value) { - return (value && typeof value == 'object' && value.nodeType === 1 && - (support.nodeClass ? toString.call(value).indexOf('Element') > -1 : isHostObject(value))) || false; - } - // fallback for environments without DOM support - if (!support.dom) { - isElement = function(value) { - return (value && typeof value == 'object' && value.nodeType === 1 && - !isPlainObject(value)) || false; - }; - } - - /** - * Checks if a collection is empty. A value is considered empty unless it is - * an array-like value with a length greater than `0` or an object with own - * enumerable properties. - * - * @static - * @memberOf _ - * @category Object - * @param {Array|Object|string} value The value to inspect. - * @returns {boolean} Returns `true` if `value` is empty, else `false`. - * @example - * - * _.isEmpty(null); - * // => true - * - * _.isEmpty(true); - * // => true - * - * _.isEmpty(1); - * // => true - * - * _.isEmpty([1, 2, 3]); - * // => false - * - * _.isEmpty({ 'a': 1 }); - * // => false - */ - function isEmpty(value) { - if (value == null) { - return true; - } - var length = value.length; - if ((typeof length == 'number' && length > -1 && length <= MAX_SAFE_INTEGER) && - (isArray(value) || isString(value) || isArguments(value) || - (typeof value == 'object' && isFunction(value.splice)))) { - return !length; - } - return !keys(value).length; - } - - /** - * Performs a deep comparison between two values to determine if they are - * equivalent. If `customizer` is provided it is invoked to compare values. - * If `customizer` returns `undefined` comparisons are handled by the method - * instead. The `customizer` is bound to `thisArg` and invoked with three - * arguments; (value, other, key). - * - * **Note:** This method supports comparing arrays, booleans, `Date` objects, - * numbers, `Object` objects, regexes, and strings. Functions and DOM nodes - * are **not** supported. Provide a customizer function to extend support - * for comparing other values. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to compare to `other`. - * @param {*} other The value to compare to `value`. - * @param {Function} [customizer] The function to customize comparing values. - * @param {*} [thisArg] The `this` binding of `customizer`. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - * @example - * - * var object = { 'name': 'fred' }; - * var other = { 'name': 'fred' }; - * - * object == other; - * // => false - * - * _.isEqual(object, other); - * // => true - * - * var words = ['hello', 'goodbye']; - * var otherWords = ['hi', 'goodbye']; - * - * _.isEqual(words, otherWords, function() { - * return _.every(arguments, _.bind(RegExp.prototype.test, /^h(?:i|ello)$/)) || undefined; - * }); - * // => true - */ - function isEqual(value, other, customizer, thisArg) { - customizer = typeof customizer == 'function' && baseCallback(customizer, thisArg, 3); - return (!customizer && isStrictComparable(value) && isStrictComparable(other)) - ? value === other - : baseIsEqual(value, other, customizer); - } - - /** - * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, - * `SyntaxError`, `TypeError`, or `URIError` object. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an error object, else `false`. - * @example - * - * _.isError(new Error); - * // => true - * - * _.isError(Error); - * // => false - */ - function isError(value) { - return (value && typeof value == 'object' && toString.call(value) == errorClass) || false; - } - - /** - * Checks if `value` is a finite primitive number. - * - * **Note:** This method is based on ES6 `Number.isFinite`. See the - * [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite) - * for more details. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. - * @example - * - * _.isFinite(10); - * // => true - * - * _.isFinite('10'); - * // => false - * - * _.isFinite(true); - * // => false - * - * _.isFinite(Object(10)); - * // => false - * - * _.isFinite(Infinity); - * // => false - */ - var isFinite = nativeNumIsFinite || function(value) { - return typeof value == 'number' && nativeIsFinite(value); - }; - - /** - * Checks if `value` is classified as a `Function` object. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. - * @example - * - * _.isFunction(_); - * // => true - * - * _.isFunction(/abc/); - * // => false - */ - function isFunction(value) { - // avoid a Chakra bug in IE 11 - // https://github.com/jashkenas/underscore/issues/1621 - return typeof value == 'function' || false; - } - // fallback for older versions of Chrome and Safari - if (isFunction(/x/)) { - isFunction = function(value) { - return typeof value == 'function' && toString.call(value) == funcClass; - }; - } - - /** - * Checks if `value` is the language type of `Object`. - * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) - * - * **Note:** See the [ES5 spec](http://es5.github.io/#x8) for more details. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an object, else `false`. - * @example - * - * _.isObject({}); - * // => true - * - * _.isObject([1, 2, 3]); - * // => true - * - * _.isObject(1); - * // => false - */ - function isObject(value) { - // avoid a V8 bug in Chrome 19-20 - // https://code.google.com/p/v8/issues/detail?id=2291 - var type = typeof value; - return type == 'function' || (value && type == 'object') || false; - } - - /** - * Checks if `value` is `NaN`. - * - * **Note:** This method is not the same as native `isNaN` which returns `true` - * for `undefined` and other non-numeric values. See the [ES5 spec](http://es5.github.io/#x15.1.2.4) - * for more details. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. - * @example - * - * _.isNaN(NaN); - * // => true - * - * _.isNaN(new Number(NaN)); - * // => true - * - * isNaN(undefined); - * // => true - * - * _.isNaN(undefined); - * // => false - */ - function isNaN(value) { - // `NaN` as a primitive is the only value that is not equal to itself - // (perform the `[[Class]]` check first to avoid errors with some host objects in IE) - return isNumber(value) && value != +value; - } - - /** - * Checks if `value` is a native function. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, else `false`. - */ - function isNative(value) { - if (isFunction(value)) { - return reNative.test(fnToString.call(value)); - } - return (value && typeof value == 'object' && - (isHostObject(value) ? reNative : reHostCtor).test(value)) || false; - } - - /** - * Checks if `value` is `null`. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is `null`, else `false`. - * @example - * - * _.isNull(null); - * // => true - * - * _.isNull(void 0); - * // => false - */ - function isNull(value) { - return value === null; - } - - /** - * Checks if `value` is classified as a `Number` primitive or object. - * - * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified - * as numbers, use the `_.isFinite` method. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. - * @example - * - * _.isNumber(8.4); - * // => true - * - * _.isNumber(NaN); - * // => true - * - * _.isNumber('8.4'); - * // => false - */ - function isNumber(value) { - var type = typeof value; - return type == 'number' || - (value && type == 'object' && toString.call(value) == numberClass) || false; - } - - /** - * Checks if `value` is an object created by the `Object` constructor or has - * a `[[Prototype]]` of `null`. - * - * **Note:** This method assumes objects created by the `Object` constructor - * have no inherited enumerable properties. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. - * @example - * - * function Shape() { - * this.x = 0; - * this.y = 0; - * } - * - * _.isPlainObject(new Shape); - * // => false - * - * _.isPlainObject([1, 2, 3]); - * // => false - * - * _.isPlainObject({ 'x': 0, 'y': 0 }); - * // => true - * - * _.isPlainObject(Object.create(null)); - * // => true - */ - var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) { - if (!(value && toString.call(value) == objectClass) || (!support.argsClass && isArguments(value))) { - return false; - } - var valueOf = value.valueOf, - objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); - - return objProto - ? (value == objProto || getPrototypeOf(value) == objProto) - : shimIsPlainObject(value); - }; - - /** - * Checks if `value` is classified as a `RegExp` object. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. - * @example - * - * _.isRegExp(/abc/); - * // => true - * - * _.isRegExp('/abc/'); - * // => false - */ - function isRegExp(value) { - return (isObject(value) && toString.call(value) == regexpClass) || false; - } - - /** - * Checks if `value` is classified as a `String` primitive or object. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. - * @example - * - * _.isString('abc'); - * // => true - * - * _.isString(1); - * // => false - */ - function isString(value) { - return typeof value == 'string' || - (value && typeof value == 'object' && toString.call(value) == stringClass) || false; - } - - /** - * Checks if `value` is `undefined`. - * - * @static - * @memberOf _ - * @category Object - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. - * @example - * - * _.isUndefined(void 0); - * // => true - * - * _.isUndefined(null); - * // => false - */ - function isUndefined(value) { - return typeof value == 'undefined'; - } - /** * Creates an array of the own enumerable property names of `object`. * @@ -7963,7 +7965,7 @@ return baseValues(object, keysIn); } - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * Converts `string` to camel case. @@ -8697,7 +8699,7 @@ : string; } - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * Attempts to invoke `func`, returning either the result or the caught @@ -9302,7 +9304,7 @@ return String(prefix == null ? '' : prefix) + id; } - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ // add functions that return wrapped values when chaining lodash.after = after; @@ -9413,7 +9415,7 @@ // add functions to `lodash.prototype` mixin(lodash, baseAssign({}, lodash)); - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ // add functions that return unwrapped values when chaining lodash.attempt = attempt; @@ -9508,7 +9510,7 @@ return source; }()), false); - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ // add functions capable of returning wrapped and unwrapped values when chaining lodash.sample = sample; @@ -9527,7 +9529,7 @@ } }); - /*--------------------------------------------------------------------------*/ + /*------------------------------------------------------------------------*/ /** * The semantic version number.