mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Bump to v3.0.0.
This commit is contained in:
65
lang/clone.js
Normal file
65
lang/clone.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import baseClone from '../internal/baseClone';
|
||||
import bindCallback from '../internal/bindCallback';
|
||||
import isIterateeCall from '../internal/isIterateeCall';
|
||||
|
||||
/**
|
||||
* Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
|
||||
* otherwise they are assigned by reference. If `customizer` is provided it is
|
||||
* invoked to produce the cloned values. If `customizer` returns `undefined`
|
||||
* cloning is handled by the method instead. The `customizer` is bound to
|
||||
* `thisArg` and invoked with two argument; (value [, index|key, object]).
|
||||
*
|
||||
* **Note:** This method is loosely based on the structured clone algorithm.
|
||||
* The enumerable properties of `arguments` objects and objects created by
|
||||
* constructors other than `Object` are cloned to plain `Object` objects. An
|
||||
* empty object is returned for uncloneable values such as functions, DOM nodes,
|
||||
* Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
|
||||
* for more details.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {*} value The value to clone.
|
||||
* @param {boolean} [isDeep] Specify a deep clone.
|
||||
* @param {Function} [customizer] The function to customize cloning values.
|
||||
* @param {*} [thisArg] The `this` binding of `customizer`.
|
||||
* @returns {*} Returns the cloned value.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney' },
|
||||
* { 'user': 'fred' }
|
||||
* ];
|
||||
*
|
||||
* var shallow = _.clone(users);
|
||||
* shallow[0] === users[0];
|
||||
* // => true
|
||||
*
|
||||
* var deep = _.clone(users, true);
|
||||
* deep[0] === users[0];
|
||||
* // => false
|
||||
*
|
||||
* // using a customizer callback
|
||||
* var body = _.clone(document.body, function(value) {
|
||||
* return _.isElement(value) ? value.cloneNode(false) : undefined;
|
||||
* });
|
||||
*
|
||||
* body === document.body
|
||||
* // => false
|
||||
* body.nodeName
|
||||
* // => BODY
|
||||
* body.childNodes.length;
|
||||
* // => 0
|
||||
*/
|
||||
function clone(value, isDeep, customizer, thisArg) {
|
||||
// Juggle arguments.
|
||||
if (typeof isDeep != 'boolean' && isDeep != null) {
|
||||
thisArg = customizer;
|
||||
customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep;
|
||||
isDeep = false;
|
||||
}
|
||||
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
|
||||
return baseClone(value, isDeep, customizer);
|
||||
}
|
||||
|
||||
export default clone;
|
||||
52
lang/cloneDeep.js
Normal file
52
lang/cloneDeep.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import baseClone from '../internal/baseClone';
|
||||
import bindCallback from '../internal/bindCallback';
|
||||
|
||||
/**
|
||||
* Creates a deep clone of `value`. If `customizer` is provided it is invoked
|
||||
* to produce the cloned values. If `customizer` returns `undefined` cloning
|
||||
* is handled by the method instead. The `customizer` is bound to `thisArg`
|
||||
* and invoked with two argument; (value [, index|key, object]).
|
||||
*
|
||||
* **Note:** This method is loosely based on the structured clone algorithm.
|
||||
* The enumerable properties of `arguments` objects and objects created by
|
||||
* constructors other than `Object` are cloned to plain `Object` objects. An
|
||||
* empty object is returned for uncloneable values such as functions, DOM nodes,
|
||||
* Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
|
||||
* for more details.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @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`.
|
||||
* @returns {*} Returns the deep cloned value.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney' },
|
||||
* { 'user': 'fred' }
|
||||
* ];
|
||||
*
|
||||
* var deep = _.cloneDeep(users);
|
||||
* deep[0] === users[0];
|
||||
* // => false
|
||||
*
|
||||
* // using a customizer callback
|
||||
* var el = _.cloneDeep(document.body, function(value) {
|
||||
* return _.isElement(value) ? value.cloneNode(true) : undefined;
|
||||
* });
|
||||
*
|
||||
* body === document.body
|
||||
* // => false
|
||||
* body.nodeName
|
||||
* // => BODY
|
||||
* body.childNodes.length;
|
||||
* // => 20
|
||||
*/
|
||||
function cloneDeep(value, customizer, thisArg) {
|
||||
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
|
||||
return baseClone(value, true, customizer);
|
||||
}
|
||||
|
||||
export default cloneDeep;
|
||||
38
lang/isArguments.js
Normal file
38
lang/isArguments.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import isLength from '../internal/isLength';
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var argsTag = '[object Arguments]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* 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 correctly classified, else `false`.
|
||||
* @example
|
||||
*
|
||||
* (function() { return _.isArguments(arguments); })();
|
||||
* // => true
|
||||
*
|
||||
* _.isArguments([1, 2, 3]);
|
||||
* // => false
|
||||
*/
|
||||
function isArguments(value) {
|
||||
var length = isObjectLike(value) ? value.length : undefined;
|
||||
return (isLength(length) && objToString.call(value) == argsTag) || false;
|
||||
}
|
||||
|
||||
export default isArguments;
|
||||
41
lang/isArray.js
Normal file
41
lang/isArray.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import isLength from '../internal/isLength';
|
||||
import isNative from './isNative';
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var arrayTag = '[object Array]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray;
|
||||
|
||||
/**
|
||||
* 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 (isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag) || false;
|
||||
};
|
||||
|
||||
export default isArray;
|
||||
36
lang/isBoolean.js
Normal file
36
lang/isBoolean.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var boolTag = '[object Boolean]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* 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 || isObjectLike(value) && objToString.call(value) == boolTag) || false;
|
||||
}
|
||||
|
||||
export default isBoolean;
|
||||
36
lang/isDate.js
Normal file
36
lang/isDate.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var dateTag = '[object Date]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* 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 (isObjectLike(value) && objToString.call(value) == dateTag) || false;
|
||||
}
|
||||
|
||||
export default isDate;
|
||||
42
lang/isElement.js
Normal file
42
lang/isElement.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
import isPlainObject from './isPlainObject';
|
||||
import support from '../support';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* 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('<body>');
|
||||
* // => false
|
||||
*/
|
||||
function isElement(value) {
|
||||
return (value && value.nodeType === 1 && isObjectLike(value) &&
|
||||
objToString.call(value).indexOf('Element') > -1) || false;
|
||||
}
|
||||
// Fallback for environments without DOM support.
|
||||
if (!support.dom) {
|
||||
isElement = function(value) {
|
||||
return (value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value)) || false;
|
||||
};
|
||||
}
|
||||
|
||||
export default isElement;
|
||||
48
lang/isEmpty.js
Normal file
48
lang/isEmpty.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import isArguments from './isArguments';
|
||||
import isArray from './isArray';
|
||||
import isFunction from './isFunction';
|
||||
import isLength from '../internal/isLength';
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
import isString from './isString';
|
||||
import keys from '../object/keys';
|
||||
|
||||
/**
|
||||
* Checks if a value is empty. A value is considered empty unless it is an
|
||||
* `arguments` object, array, string, or jQuery-like collection 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 (isLength(length) && (isArray(value) || isString(value) || isArguments(value) ||
|
||||
(isObjectLike(value) && isFunction(value.splice)))) {
|
||||
return !length;
|
||||
}
|
||||
return !keys(value).length;
|
||||
}
|
||||
|
||||
export default isEmpty;
|
||||
54
lang/isEqual.js
Normal file
54
lang/isEqual.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import baseIsEqual from '../internal/baseIsEqual';
|
||||
import bindCallback from '../internal/bindCallback';
|
||||
import isStrictComparable from '../internal/isStrictComparable';
|
||||
|
||||
/**
|
||||
* 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 [, index|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.
|
||||
* @param {*} other The other value to compare.
|
||||
* @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 = { 'user': 'fred' };
|
||||
* var other = { 'user': 'fred' };
|
||||
*
|
||||
* object == other;
|
||||
* // => false
|
||||
*
|
||||
* _.isEqual(object, other);
|
||||
* // => true
|
||||
*
|
||||
* // using a customizer callback
|
||||
* var array = ['hello', 'goodbye'];
|
||||
* var other = ['hi', 'goodbye'];
|
||||
*
|
||||
* _.isEqual(array, other, function(value, other) {
|
||||
* return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
|
||||
* });
|
||||
* // => true
|
||||
*/
|
||||
function isEqual(value, other, customizer, thisArg) {
|
||||
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
|
||||
if (!customizer && isStrictComparable(value) && isStrictComparable(other)) {
|
||||
return value === other;
|
||||
}
|
||||
var result = customizer ? customizer(value, other) : undefined;
|
||||
return typeof result == 'undefined' ? baseIsEqual(value, other, customizer) : !!result;
|
||||
}
|
||||
|
||||
export default isEqual;
|
||||
37
lang/isError.js
Normal file
37
lang/isError.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var errorTag = '[object Error]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* 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 (isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag) || false;
|
||||
}
|
||||
|
||||
export default isError;
|
||||
41
lang/isFinite.js
Normal file
41
lang/isFinite.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import isNative from './isNative';
|
||||
import root from '../internal/root';
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeIsFinite = root.isFinite,
|
||||
nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite;
|
||||
|
||||
/**
|
||||
* Checks if `value` is a finite primitive number.
|
||||
*
|
||||
* **Note:** This method is based on ES `Number.isFinite`. See the
|
||||
* [ES spec](https://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);
|
||||
};
|
||||
|
||||
export default isFinite;
|
||||
51
lang/isFunction.js
Normal file
51
lang/isFunction.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import isNative from './isNative';
|
||||
import root from '../internal/root';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var funcTag = '[object Function]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/** Native method references. */
|
||||
var Uint8Array = isNative(Uint8Array = root.Uint8Array) && Uint8Array;
|
||||
|
||||
/**
|
||||
* 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 JIT bug in compatibility modes of IE 11.
|
||||
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
|
||||
return typeof value == 'function' || false;
|
||||
}
|
||||
// Fallback for environments that return incorrect `typeof` operator results.
|
||||
if (isFunction(/x/) || (Uint8Array && !isFunction(Uint8Array))) {
|
||||
isFunction = function(value) {
|
||||
// The use of `Object#toString` avoids issues with the `typeof` operator
|
||||
// in older versions of Chrome and Safari which return 'function' for regexes
|
||||
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
||||
return objToString.call(value) == funcTag;
|
||||
};
|
||||
}
|
||||
|
||||
export default isFunction;
|
||||
74
lang/isMatch.js
Normal file
74
lang/isMatch.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import baseIsMatch from '../internal/baseIsMatch';
|
||||
import bindCallback from '../internal/bindCallback';
|
||||
import isStrictComparable from '../internal/isStrictComparable';
|
||||
import keys from '../object/keys';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Performs a deep comparison between `object` and `source` to determine if
|
||||
* `object` contains equivalent property values. 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, index|key).
|
||||
*
|
||||
* **Note:** This method supports comparing properties of 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 {Object} source The object to inspect.
|
||||
* @param {Object} source The object of property values to match.
|
||||
* @param {Function} [customizer] The function to customize comparing values.
|
||||
* @param {*} [thisArg] The `this` binding of `customizer`.
|
||||
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'user': 'fred', 'age': 40 };
|
||||
*
|
||||
* _.isMatch(object, { 'age': 40 });
|
||||
* // => true
|
||||
*
|
||||
* _.isMatch(object, { 'age': 36 });
|
||||
* // => false
|
||||
*
|
||||
* // using a customizer callback
|
||||
* var object = { 'greeting': 'hello' };
|
||||
* var source = { 'greeting': 'hi' };
|
||||
*
|
||||
* _.isMatch(object, source, function(value, other) {
|
||||
* return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
|
||||
* });
|
||||
* // => true
|
||||
*/
|
||||
function isMatch(object, source, customizer, thisArg) {
|
||||
var props = keys(source),
|
||||
length = props.length;
|
||||
|
||||
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
|
||||
if (!customizer && length == 1) {
|
||||
var key = props[0],
|
||||
value = source[key];
|
||||
|
||||
if (isStrictComparable(value)) {
|
||||
return object != null && value === object[key] && hasOwnProperty.call(object, key);
|
||||
}
|
||||
}
|
||||
var values = Array(length),
|
||||
strictCompareFlags = Array(length);
|
||||
|
||||
while (length--) {
|
||||
value = values[length] = source[props[length]];
|
||||
strictCompareFlags[length] = isStrictComparable(value);
|
||||
}
|
||||
return baseIsMatch(object, props, values, strictCompareFlags, customizer);
|
||||
}
|
||||
|
||||
export default isMatch;
|
||||
35
lang/isNaN.js
Normal file
35
lang/isNaN.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import isNumber from './isNumber';
|
||||
|
||||
/**
|
||||
* 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](https://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) {
|
||||
// An `NaN` primitive is the only value that is not equal to itself.
|
||||
// Perform the `toStringTag` check first to avoid errors with some host objects in IE.
|
||||
return isNumber(value) && value != +value;
|
||||
}
|
||||
|
||||
export default isNaN;
|
||||
55
lang/isNative.js
Normal file
55
lang/isNative.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import escapeRegExp from '../string/escapeRegExp';
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var funcTag = '[object Function]';
|
||||
|
||||
/** Used to detect host constructors (Safari > 5). */
|
||||
var reHostCtor = /^\[object .+?Constructor\]$/;
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to resolve the decompiled source of functions. */
|
||||
var fnToString = Function.prototype.toString;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/** Used to detect if a method is native. */
|
||||
var reNative = RegExp('^' +
|
||||
escapeRegExp(objToString)
|
||||
.replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
||||
);
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
* @example
|
||||
*
|
||||
* _.isNative(Array.prototype.push);
|
||||
* // => true
|
||||
*
|
||||
* _.isNative(_);
|
||||
* // => false
|
||||
*/
|
||||
function isNative(value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
if (objToString.call(value) == funcTag) {
|
||||
return reNative.test(fnToString.call(value));
|
||||
}
|
||||
return (isObjectLike(value) && reHostCtor.test(value)) || false;
|
||||
}
|
||||
|
||||
export default isNative;
|
||||
21
lang/isNull.js
Normal file
21
lang/isNull.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default isNull;
|
||||
42
lang/isNumber.js
Normal file
42
lang/isNumber.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var numberTag = '[object Number]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag) || false;
|
||||
}
|
||||
|
||||
export default isNumber;
|
||||
30
lang/isObject.js
Normal file
30
lang/isObject.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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](https://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 JIT bug in Chrome 19-20.
|
||||
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
||||
var type = typeof value;
|
||||
return type == 'function' || (value && type == 'object') || false;
|
||||
}
|
||||
|
||||
export default isObject;
|
||||
62
lang/isPlainObject.js
Normal file
62
lang/isPlainObject.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import isNative from './isNative';
|
||||
import shimIsPlainObject from '../internal/shimIsPlainObject';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var objectTag = '[object Object]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/** Native method references. */
|
||||
var getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf;
|
||||
|
||||
/**
|
||||
* Checks if `value` is a plain object, that is, an object created by the
|
||||
* `Object` constructor or one with 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 Foo() {
|
||||
* this.a = 1;
|
||||
* }
|
||||
*
|
||||
* _.isPlainObject(new Foo);
|
||||
* // => 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 && objToString.call(value) == objectTag)) {
|
||||
return false;
|
||||
}
|
||||
var valueOf = value.valueOf,
|
||||
objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
||||
|
||||
return objProto
|
||||
? (value == objProto || getPrototypeOf(value) == objProto)
|
||||
: shimIsPlainObject(value);
|
||||
};
|
||||
|
||||
export default isPlainObject;
|
||||
36
lang/isRegExp.js
Normal file
36
lang/isRegExp.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var regexpTag = '[object RegExp]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* 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 (isObjectLike(value) && objToString.call(value) == regexpTag) || false;
|
||||
}
|
||||
|
||||
export default isRegExp;
|
||||
36
lang/isString.js
Normal file
36
lang/isString.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var stringTag = '[object String]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* 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' || (isObjectLike(value) && objToString.call(value) == stringTag) || false;
|
||||
}
|
||||
|
||||
export default isString;
|
||||
75
lang/isTypedArray.js
Normal file
75
lang/isTypedArray.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import isLength from '../internal/isLength';
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var argsTag = '[object Arguments]',
|
||||
arrayTag = '[object Array]',
|
||||
boolTag = '[object Boolean]',
|
||||
dateTag = '[object Date]',
|
||||
errorTag = '[object Error]',
|
||||
funcTag = '[object Function]',
|
||||
mapTag = '[object Map]',
|
||||
numberTag = '[object Number]',
|
||||
objectTag = '[object Object]',
|
||||
regexpTag = '[object RegExp]',
|
||||
setTag = '[object Set]',
|
||||
stringTag = '[object String]',
|
||||
weakMapTag = '[object WeakMap]';
|
||||
|
||||
var arrayBufferTag = '[object ArrayBuffer]',
|
||||
float32Tag = '[object Float32Array]',
|
||||
float64Tag = '[object Float64Array]',
|
||||
int8Tag = '[object Int8Array]',
|
||||
int16Tag = '[object Int16Array]',
|
||||
int32Tag = '[object Int32Array]',
|
||||
uint8Tag = '[object Uint8Array]',
|
||||
uint8ClampedTag = '[object Uint8ClampedArray]',
|
||||
uint16Tag = '[object Uint16Array]',
|
||||
uint32Tag = '[object Uint32Array]';
|
||||
|
||||
/** Used to identify `toStringTag` values of typed arrays. */
|
||||
var typedArrayTags = {};
|
||||
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
||||
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
||||
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
||||
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
||||
typedArrayTags[uint32Tag] = true;
|
||||
typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
||||
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
||||
typedArrayTags[dateTag] = typedArrayTags[errorTag] =
|
||||
typedArrayTags[funcTag] = typedArrayTags[mapTag] =
|
||||
typedArrayTags[numberTag] = typedArrayTags[objectTag] =
|
||||
typedArrayTags[regexpTag] = typedArrayTags[setTag] =
|
||||
typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* Checks if `value` is classified as a typed array.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.isTypedArray(new Uint8Array);
|
||||
* // => true
|
||||
*
|
||||
* _.isTypedArray([]);
|
||||
* // => false
|
||||
*/
|
||||
function isTypedArray(value) {
|
||||
return (isObjectLike(value) && isLength(value.length) && typedArrayTags[objToString.call(value)]) || false;
|
||||
}
|
||||
|
||||
export default isTypedArray;
|
||||
21
lang/isUndefined.js
Normal file
21
lang/isUndefined.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
|
||||
export default isUndefined;
|
||||
29
lang/toArray.js
Normal file
29
lang/toArray.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import arrayCopy from '../internal/arrayCopy';
|
||||
import isLength from '../internal/isLength';
|
||||
import values from '../object/values';
|
||||
|
||||
/**
|
||||
* Converts `value` to an array.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {*} value The value to convert.
|
||||
* @returns {Array} Returns the converted array.
|
||||
* @example
|
||||
*
|
||||
* (function() { return _.toArray(arguments).slice(1); })(1, 2, 3);
|
||||
* // => [2, 3]
|
||||
*/
|
||||
function toArray(value) {
|
||||
var length = value ? value.length : 0;
|
||||
if (!isLength(length)) {
|
||||
return values(value);
|
||||
}
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
return arrayCopy(value);
|
||||
}
|
||||
|
||||
export default toArray;
|
||||
31
lang/toPlainObject.js
Normal file
31
lang/toPlainObject.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import baseCopy from '../internal/baseCopy';
|
||||
import keysIn from '../object/keysIn';
|
||||
|
||||
/**
|
||||
* Converts `value` to a plain object flattening inherited enumerable
|
||||
* properties of `value` to own properties of the plain object.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {*} value The value to convert.
|
||||
* @returns {Object} Returns the converted plain object.
|
||||
* @example
|
||||
*
|
||||
* function Foo() {
|
||||
* this.b = 2;
|
||||
* }
|
||||
*
|
||||
* Foo.prototype.c = 3;
|
||||
*
|
||||
* _.assign({ 'a': 1 }, new Foo);
|
||||
* // => { 'a': 1, 'b': 2 }
|
||||
*
|
||||
* _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
|
||||
* // => { 'a': 1, 'b': 2, 'c': 3 }
|
||||
*/
|
||||
function toPlainObject(value) {
|
||||
return baseCopy(value, keysIn(value));
|
||||
}
|
||||
|
||||
export default toPlainObject;
|
||||
Reference in New Issue
Block a user