lodash.core.js (lodash-4.0.0) | : | lodash.core.js (lodash-4.17.21) | ||
---|---|---|---|---|
/** | /** | |||
* @license | * @license | |||
* lodash 4.0.0 (Custom Build) <https://lodash.com/> | * Lodash (Custom Build) <https://lodash.com/> | |||
* Build: `lodash core -o ./dist/lodash.core.js` | * Build: `lodash core -o ./dist/lodash.core.js` | |||
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/> | * Copyright OpenJS Foundation and other contributors <https://openjsf.org/> | |||
* Released under MIT license <https://lodash.com/license> | ||||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | |||
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporter | * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editor | |||
s & Editors | s | |||
* Available under MIT license <https://lodash.com/license> | ||||
*/ | */ | |||
;(function() { | ;(function() { | |||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */ | /** Used as a safe reference for `undefined` in pre-ES5 environments. */ | |||
var undefined; | var undefined; | |||
/** Used as the semantic version number. */ | /** Used as the semantic version number. */ | |||
var VERSION = '4.0.0'; | var VERSION = '4.17.21'; | |||
/** Used to compose bitmasks for wrapper metadata. */ | /** Error message constants. */ | |||
var BIND_FLAG = 1, | ||||
PARTIAL_FLAG = 32; | ||||
/** Used to compose bitmasks for comparison styles. */ | ||||
var UNORDERED_COMPARE_FLAG = 1, | ||||
PARTIAL_COMPARE_FLAG = 2; | ||||
/** Used as the `TypeError` message for "Functions" methods. */ | ||||
var FUNC_ERROR_TEXT = 'Expected a function'; | var FUNC_ERROR_TEXT = 'Expected a function'; | |||
/** Used to compose bitmasks for value comparisons. */ | ||||
var COMPARE_PARTIAL_FLAG = 1, | ||||
COMPARE_UNORDERED_FLAG = 2; | ||||
/** Used to compose bitmasks for function metadata. */ | ||||
var WRAP_BIND_FLAG = 1, | ||||
WRAP_PARTIAL_FLAG = 32; | ||||
/** Used as references for various `Number` constants. */ | /** Used as references for various `Number` constants. */ | |||
var MAX_SAFE_INTEGER = 9007199254740991; | var INFINITY = 1 / 0, | |||
MAX_SAFE_INTEGER = 9007199254740991; | ||||
/** `Object#toString` result references. */ | /** `Object#toString` result references. */ | |||
var argsTag = '[object Arguments]', | var argsTag = '[object Arguments]', | |||
arrayTag = '[object Array]', | arrayTag = '[object Array]', | |||
asyncTag = '[object AsyncFunction]', | ||||
boolTag = '[object Boolean]', | boolTag = '[object Boolean]', | |||
dateTag = '[object Date]', | dateTag = '[object Date]', | |||
errorTag = '[object Error]', | errorTag = '[object Error]', | |||
funcTag = '[object Function]', | funcTag = '[object Function]', | |||
genTag = '[object GeneratorFunction]', | genTag = '[object GeneratorFunction]', | |||
numberTag = '[object Number]', | numberTag = '[object Number]', | |||
objectTag = '[object Object]', | objectTag = '[object Object]', | |||
proxyTag = '[object Proxy]', | ||||
regexpTag = '[object RegExp]', | regexpTag = '[object RegExp]', | |||
stringTag = '[object String]'; | stringTag = '[object String]'; | |||
/** Used to match HTML entities and HTML characters. */ | /** Used to match HTML entities and HTML characters. */ | |||
var reUnescapedHtml = /[&<>"'`]/g, | var reUnescapedHtml = /[&<>"']/g, | |||
reHasUnescapedHtml = RegExp(reUnescapedHtml.source); | reHasUnescapedHtml = RegExp(reUnescapedHtml.source); | |||
/** Used to detect unsigned integer values. */ | /** Used to detect unsigned integer values. */ | |||
var reIsUint = /^(?:0|[1-9]\d*)$/; | var reIsUint = /^(?:0|[1-9]\d*)$/; | |||
/** Used to map characters to HTML entities. */ | /** Used to map characters to HTML entities. */ | |||
var htmlEscapes = { | var htmlEscapes = { | |||
'&': '&', | '&': '&', | |||
'<': '<', | '<': '<', | |||
'>': '>', | '>': '>', | |||
'"': '"', | '"': '"', | |||
"'": ''', | "'": ''' | |||
'`': '`' | ||||
}; | }; | |||
/** Used to determine if values are of the language type `Object`. */ | ||||
var objectTypes = { | ||||
'function': true, | ||||
'object': true | ||||
}; | ||||
/** Detect free variable `exports`. */ | ||||
var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType | ||||
) ? exports : null; | ||||
/** Detect free variable `module`. */ | ||||
var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? | ||||
module : null; | ||||
/** Detect free variable `global` from Node.js. */ | /** Detect free variable `global` from Node.js. */ | |||
var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'ob ject' && global); | var freeGlobal = typeof global == 'object' && global && global.Object === Obje ct && global; | |||
/** Detect free variable `self`. */ | /** Detect free variable `self`. */ | |||
var freeSelf = checkGlobal(objectTypes[typeof self] && self); | var freeSelf = typeof self == 'object' && self && self.Object === Object && se lf; | |||
/** Detect free variable `window`. */ | /** Used as a reference to the global object. */ | |||
var freeWindow = checkGlobal(objectTypes[typeof window] && window); | var root = freeGlobal || freeSelf || Function('return this')(); | |||
/** Detect the popular CommonJS extension `module.exports`. */ | /** Detect free variable `exports`. */ | |||
var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeE | var freeExports = typeof exports == 'object' && exports && !exports.nodeType & | |||
xports : null; | & exports; | |||
/** Detect `this` as the global object. */ | ||||
var thisGlobal = checkGlobal(objectTypes[typeof this] && this); | ||||
/** | /** Detect free variable `module`. */ | |||
* Used as a reference to the global object. | var freeModule = freeExports && typeof module == 'object' && module && !module | |||
* | .nodeType && module; | |||
* The `this` value is used if it's the global object to avoid Greasemonkey's | ||||
* restricted `window` object, otherwise the `window` object is used. | ||||
*/ | ||||
var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) & | ||||
& freeWindow) || freeSelf || thisGlobal || Function('return this')(); | ||||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Creates a new array concatenating `array` with `other`. | ||||
* | ||||
* @private | ||||
* @param {Array} array The first array to concatenate. | ||||
* @param {Array} other The second array to concatenate. | ||||
* @returns {Array} Returns the new concatenated array. | ||||
*/ | ||||
function arrayConcat(array, other) { | ||||
return arrayPush(copyArray(array), values); | ||||
} | ||||
/** | ||||
* Appends the elements of `values` to `array`. | * Appends the elements of `values` to `array`. | |||
* | * | |||
* @private | * @private | |||
* @param {Array} array The array to modify. | * @param {Array} array The array to modify. | |||
* @param {Array} values The values to append. | * @param {Array} values The values to append. | |||
* @returns {Array} Returns `array`. | * @returns {Array} Returns `array`. | |||
*/ | */ | |||
function arrayPush(array, values) { | function arrayPush(array, values) { | |||
var index = -1, | array.push.apply(array, values); | |||
length = values.length, | ||||
offset = array.length; | ||||
while (++index < length) { | ||||
array[offset + index] = values[index]; | ||||
} | ||||
return array; | return array; | |||
} | } | |||
/** | /** | |||
* The base implementation of methods like `_.max` and `_.min` which accepts a | * The base implementation of `_.findIndex` and `_.findLastIndex` without | |||
* `comparator` to determine the extremum value. | * support for iteratee shorthands. | |||
* | * | |||
* @private | * @private | |||
* @param {Array} array The array to iterate over. | * @param {Array} array The array to inspect. | |||
* @param {Function} iteratee The iteratee invoked per iteration. | * @param {Function} predicate The function invoked per iteration. | |||
* @param {Function} comparator The comparator used to compare values. | * @param {number} fromIndex The index to search from. | |||
* @returns {*} Returns the extremum value. | * @param {boolean} [fromRight] Specify iterating from right to left. | |||
* @returns {number} Returns the index of the matched value, else `-1`. | ||||
*/ | */ | |||
function baseExtremum(array, iteratee, comparator) { | function baseFindIndex(array, predicate, fromIndex, fromRight) { | |||
var index = -1, | var length = array.length, | |||
length = array.length; | index = fromIndex + (fromRight ? 1 : -1); | |||
while (++index < length) { | ||||
var value = array[index], | ||||
current = iteratee(value); | ||||
if (current != null && (computed === undefined | while ((fromRight ? index-- : ++index < length)) { | |||
? current === current | if (predicate(array[index], index, array)) { | |||
: comparator(current, computed) | return index; | |||
)) { | ||||
var computed = current, | ||||
result = value; | ||||
} | } | |||
} | } | |||
return result; | return -1; | |||
} | } | |||
/** | /** | |||
* The base implementation of methods like `_.find` and `_.findKey`, without | * The base implementation of `_.property` without support for deep paths. | |||
* support for iteratee shorthands, which iterates over `collection` using | ||||
* the provided `eachFunc`. | ||||
* | * | |||
* @private | * @private | |||
* @param {Array|Object} collection The collection to search. | * @param {string} key The key of the property to get. | |||
* @param {Function} predicate The function invoked per iteration. | * @returns {Function} Returns the new accessor function. | |||
* @param {Function} eachFunc The function to iterate over `collection`. | ||||
* @param {boolean} [retKey] Specify returning the key of the found element in | ||||
stead of the element itself. | ||||
* @returns {*} Returns the found element or its key, else `undefined`. | ||||
*/ | */ | |||
function baseFind(collection, predicate, eachFunc, retKey) { | function baseProperty(key) { | |||
var result; | return function(object) { | |||
eachFunc(collection, function(value, key, collection) { | return object == null ? undefined : object[key]; | |||
if (predicate(value, key, collection)) { | }; | |||
result = retKey ? key : value; | } | |||
return false; | ||||
} | /** | |||
}); | * The base implementation of `_.propertyOf` without support for deep paths. | |||
return result; | * | |||
* @private | ||||
* @param {Object} object The object to query. | ||||
* @returns {Function} Returns the new accessor function. | ||||
*/ | ||||
function basePropertyOf(object) { | ||||
return function(key) { | ||||
return object == null ? undefined : object[key]; | ||||
}; | ||||
} | } | |||
/** | /** | |||
* The base implementation of `_.reduce` and `_.reduceRight`, without support | * The base implementation of `_.reduce` and `_.reduceRight`, without support | |||
* for iteratee shorthands, which iterates over `collection` using the provide | * for iteratee shorthands, which iterates over `collection` using `eachFunc`. | |||
d | ||||
* `eachFunc`. | ||||
* | * | |||
* @private | * @private | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function} iteratee The function invoked per iteration. | * @param {Function} iteratee The function invoked per iteration. | |||
* @param {*} accumulator The initial value. | * @param {*} accumulator The initial value. | |||
* @param {boolean} initFromCollection Specify using the first or last element | * @param {boolean} initAccum Specify using the first or last element of | |||
of `collection` as the initial value. | * `collection` as the initial value. | |||
* @param {Function} eachFunc The function to iterate over `collection`. | * @param {Function} eachFunc The function to iterate over `collection`. | |||
* @returns {*} Returns the accumulated value. | * @returns {*} Returns the accumulated value. | |||
*/ | */ | |||
function baseReduce(collection, iteratee, accumulator, initFromCollection, eac hFunc) { | function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { | |||
eachFunc(collection, function(value, index, collection) { | eachFunc(collection, function(value, index, collection) { | |||
accumulator = initFromCollection | accumulator = initAccum | |||
? (initFromCollection = false, value) | ? (initAccum = false, value) | |||
: iteratee(accumulator, value, index, collection); | : iteratee(accumulator, value, index, collection); | |||
}); | }); | |||
return accumulator; | return accumulator; | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.times` without support for iteratee shorthand | ||||
s | ||||
* or max array length checks. | ||||
* | ||||
* @private | ||||
* @param {number} n The number of times to invoke `iteratee`. | ||||
* @param {Function} iteratee The function invoked per iteration. | ||||
* @returns {Array} Returns the array of results. | ||||
*/ | ||||
function baseTimes(n, iteratee) { | ||||
var index = -1, | ||||
result = Array(n); | ||||
while (++index < n) { | ||||
result[index] = iteratee(index); | ||||
} | ||||
return result; | ||||
} | ||||
/** | ||||
* The base implementation of `_.values` and `_.valuesIn` which creates an | * The base implementation of `_.values` and `_.valuesIn` which creates an | |||
* array of `object` property values corresponding to the property names | * array of `object` property values corresponding to the property names | |||
* of `props`. | * of `props`. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to query. | * @param {Object} object The object to query. | |||
* @param {Array} props The property names to get values for. | * @param {Array} props The property names to get values for. | |||
* @returns {Object} Returns the array of property values. | * @returns {Object} Returns the array of property values. | |||
*/ | */ | |||
function baseValues(object, props) { | function baseValues(object, props) { | |||
return baseMap(props, function(key) { | return baseMap(props, function(key) { | |||
return object[key]; | return object[key]; | |||
}); | }); | |||
} | } | |||
/** | /** | |||
* Checks if `value` is a global object. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to check. | ||||
* @returns {null|Object} Returns `value` if it's a global object, else `null` | ||||
. | ||||
*/ | ||||
function checkGlobal(value) { | ||||
return (value && value.Object === Object) ? value : null; | ||||
} | ||||
/** | ||||
* Compares values to sort them in ascending order. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to compare. | ||||
* @param {*} other The other value to compare. | ||||
* @returns {number} Returns the sort order indicator for `value`. | ||||
*/ | ||||
function compareAscending(value, other) { | ||||
if (value !== other) { | ||||
var valIsNull = value === null, | ||||
valIsUndef = value === undefined, | ||||
valIsReflexive = value === value; | ||||
var othIsNull = other === null, | ||||
othIsUndef = other === undefined, | ||||
othIsReflexive = other === other; | ||||
if ((value > other && !othIsNull) || !valIsReflexive || | ||||
(valIsNull && !othIsUndef && othIsReflexive) || | ||||
(valIsUndef && othIsReflexive)) { | ||||
return 1; | ||||
} | ||||
if ((value < other && !valIsNull) || !othIsReflexive || | ||||
(othIsNull && !valIsUndef && valIsReflexive) || | ||||
(othIsUndef && valIsReflexive)) { | ||||
return -1; | ||||
} | ||||
} | ||||
return 0; | ||||
} | ||||
/** | ||||
* Used by `_.escape` to convert characters to HTML entities. | * Used by `_.escape` to convert characters to HTML entities. | |||
* | * | |||
* @private | * @private | |||
* @param {string} chr The matched character to escape. | * @param {string} chr The matched character to escape. | |||
* @returns {string} Returns the escaped character. | * @returns {string} Returns the escaped character. | |||
*/ | */ | |||
function escapeHtmlChar(chr) { | var escapeHtmlChar = basePropertyOf(htmlEscapes); | |||
return htmlEscapes[chr]; | ||||
} | ||||
/** | ||||
* Checks if `value` is a host object in IE < 9. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to check. | ||||
* @returns {boolean} Returns `true` if `value` is a host object, else `false` | ||||
. | ||||
*/ | ||||
function isHostObject(value) { | ||||
// Many host objects are `Object` objects that can coerce to strings | ||||
// despite having improperly defined `toString` methods. | ||||
var result = false; | ||||
if (value != null && typeof value.toString != 'function') { | ||||
try { | ||||
result = !!(value + ''); | ||||
} catch (e) {} | ||||
} | ||||
return result; | ||||
} | ||||
/** | ||||
* Checks if `value` is a valid array-like index. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to check. | ||||
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index | ||||
. | ||||
* @returns {boolean} Returns `true` if `value` is a valid index, else `false` | ||||
. | ||||
*/ | ||||
function isIndex(value, length) { | ||||
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1; | ||||
length = length == null ? MAX_SAFE_INTEGER : length; | ||||
return value > -1 && value % 1 == 0 && value < length; | ||||
} | ||||
/** | /** | |||
* Converts `iterator` to an array. | * Creates a unary function that invokes `func` with its argument transformed. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} iterator The iterator to convert. | * @param {Function} func The function to wrap. | |||
* @returns {Array} Returns the converted array. | * @param {Function} transform The argument transform. | |||
* @returns {Function} Returns the new function. | ||||
*/ | */ | |||
function iteratorToArray(iterator) { | function overArg(func, transform) { | |||
var data, | return function(arg) { | |||
result = []; | return func(transform(arg)); | |||
}; | ||||
while (!(data = iterator.next()).done) { | ||||
result.push(data.value); | ||||
} | ||||
return result; | ||||
} | } | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
/** Used for built-in method references. */ | /** Used for built-in method references. */ | |||
var arrayProto = Array.prototype, | var arrayProto = Array.prototype, | |||
objectProto = Object.prototype; | objectProto = Object.prototype; | |||
/** Used to check objects for own properties. */ | /** Used to check objects for own properties. */ | |||
var hasOwnProperty = objectProto.hasOwnProperty; | var hasOwnProperty = objectProto.hasOwnProperty; | |||
/** Used to generate unique IDs. */ | /** Used to generate unique IDs. */ | |||
var idCounter = 0; | var idCounter = 0; | |||
/** | /** | |||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/ | * Used to resolve the | |||
6.0/#sec-object.prototype.tostring) | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prot | |||
otype.tostring) | ||||
* of values. | * of values. | |||
*/ | */ | |||
var objectToString = objectProto.toString; | var nativeObjectToString = objectProto.toString; | |||
/** Used to restore the original `_` reference in `_.noConflict`. */ | /** Used to restore the original `_` reference in `_.noConflict`. */ | |||
var oldDash = root._; | var oldDash = root._; | |||
/** Built-in value references. */ | /** Built-in value references. */ | |||
var _Symbol = root.Symbol, | var objectCreate = Object.create, | |||
Reflect = root.Reflect, | ||||
Uint8Array = root.Uint8Array, | ||||
enumerate = Reflect ? Reflect.enumerate : undefined, | ||||
propertyIsEnumerable = objectProto.propertyIsEnumerable; | propertyIsEnumerable = objectProto.propertyIsEnumerable; | |||
/* Built-in method references for those with the same name as other `lodash` m ethods. */ | /* Built-in method references for those with the same name as other `lodash` m ethods. */ | |||
var nativeIsFinite = root.isFinite, | var nativeIsFinite = root.isFinite, | |||
nativeKeys = Object.keys, | nativeKeys = overArg(Object.keys, Object), | |||
nativeMax = Math.max; | nativeMax = Math.max; | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Creates a `lodash` object which wraps `value` to enable implicit method | * Creates a `lodash` object which wraps `value` to enable implicit method | |||
* chaining. Methods that operate on and return arrays, collections, and | * chain sequences. Methods that operate on and return arrays, collections, | |||
* functions can be chained together. Methods that retrieve a single value or | * and functions can be chained together. Methods that retrieve a single value | |||
* may return a primitive value will automatically end the chain sequence and | * or may return a primitive value will automatically end the chain sequence | |||
* return the unwrapped value. Otherwise, the value must be unwrapped with | * and return the unwrapped value. Otherwise, the value must be unwrapped | |||
* `_#value`. | * with `_#value`. | |||
* | * | |||
* Explicit chaining, which must be unwrapped with `_#value` in all cases, | * Explicit chain sequences, which must be unwrapped with `_#value`, may be | |||
* may be enabled using `_.chain`. | * enabled using `_.chain`. | |||
* | * | |||
* The execution of chained methods is lazy, that is, it's deferred until | * The execution of chained methods is lazy, that is, it's deferred until | |||
* `_#value` is implicitly or explicitly called. | * `_#value` is implicitly or explicitly called. | |||
* | * | |||
* Lazy evaluation allows several methods to support shortcut fusion. Shortcut | * Lazy evaluation allows several methods to support shortcut fusion. | |||
* fusion is an optimization to merge iteratee calls; this avoids the creation | * Shortcut fusion is an optimization to merge iteratee calls; this avoids | |||
* of intermediate arrays and can greatly reduce the number of iteratee execut | * the creation of intermediate arrays and can greatly reduce the number of | |||
ions. | * iteratee executions. Sections of a chain sequence qualify for shortcut | |||
* Sections of a chain sequence qualify for shortcut fusion if the section is | * fusion if the section is applied to an array and iteratees accept only | |||
* applied to an array of at least two hundred elements and any iteratees | * one argument. The heuristic for whether a section qualifies for shortcut | |||
* accept only one argument. The heuristic for whether a section qualifies | * fusion is subject to change. | |||
* for shortcut fusion is subject to change. | ||||
* | * | |||
* Chaining is supported in custom builds as long as the `_#value` method is | * Chaining is supported in custom builds as long as the `_#value` method is | |||
* directly or indirectly included in the build. | * directly or indirectly included in the build. | |||
* | * | |||
* In addition to lodash methods, wrappers have `Array` and `String` methods. | * In addition to lodash methods, wrappers have `Array` and `String` methods. | |||
* | * | |||
* The wrapper `Array` methods are: | * The wrapper `Array` methods are: | |||
* `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift` | * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift` | |||
* | * | |||
* The wrapper `String` methods are: | * The wrapper `String` methods are: | |||
* `replace` and `split` | * `replace` and `split` | |||
* | * | |||
* The wrapper methods that support shortcut fusion are: | * The wrapper methods that support shortcut fusion are: | |||
* `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`, | * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`, | |||
* `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`, | * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`, | |||
* `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` | * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` | |||
* | * | |||
* The chainable wrapper methods are: | * The chainable wrapper methods are: | |||
* `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, | * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, | |||
* `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`, | * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, | |||
* `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`, | * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, | |||
* `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`, | * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, | |||
* `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`, | * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`, | |||
* `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`, | * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`, | |||
* `flowRight`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, | * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`, | |||
* `forOwnRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial | * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, | |||
`, | * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`, | |||
* `intersection`, `intersectionBy`, `intersectionWith`, invert`, `invokeMap`, | * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, | |||
* `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, | * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesPropert | |||
* `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`, | y`, | |||
* `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy | * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, | |||
`, | * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, | |||
* `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`, | * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`, | |||
* `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`, | * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy` | |||
* `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, | , | |||
* `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, | * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`, | |||
* `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, | * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, | |||
* `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, | * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`, | |||
* `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, | * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, | |||
* `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, | * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`, | |||
* `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`, | * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, | |||
* `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith` | * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`, | |||
* `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, | ||||
* `zipObject`, `zipObjectDeep`, and `zipWith` | ||||
* | * | |||
* The wrapper methods that are **not** chainable by default are: | * The wrapper methods that are **not** chainable by default are: | |||
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, | * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, | |||
* `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`, | * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`, | |||
* `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, | * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`, | |||
* `findLast`, `findLastIndex`, `findLastKey`, `floor`, `get`, `gt`, `gte`, | * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, | |||
* `has`, `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, | * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight` | |||
* `invoke`, `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`, | , | |||
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, | * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, | |||
* `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`, | * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, | |||
* `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, | * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObjec | |||
* `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`, | t`, | |||
* `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`, `last`, | * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, | |||
* `lastIndexOf`, `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, | * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength` | |||
* `mean`, `min`, `minBy`, `noConflict`, `noop`, `now`, `pad`, `padEnd`, | , | |||
* `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`, | * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, | |||
* `result`, `round`, `runInContext`, `sample`, `shift`, `size`, `snakeCase`, | * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, | |||
* `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndex | * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`, | |||
By`, | * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`, | |||
* `startCase`, `startsWith`, `subtract`, `sum`, sumBy`, `template`, `times`, | * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, | |||
* `toLower`, `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, toString`, | * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`, | |||
* `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueI | * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, | |||
d`, | * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`, | |||
* `upperCase`, `upperFirst`, `value`, and `words` | * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, | |||
* `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`, | ||||
* `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`, | ||||
* `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`, | ||||
* `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, | ||||
* `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, | ||||
* `upperFirst`, `value`, and `words` | ||||
* | * | |||
* @name _ | * @name _ | |||
* @constructor | * @constructor | |||
* @category Seq | * @category Seq | |||
* @param {*} value The value to wrap in a `lodash` instance. | * @param {*} value The value to wrap in a `lodash` instance. | |||
* @returns {Object} Returns the new `lodash` wrapper instance. | * @returns {Object} Returns the new `lodash` wrapper instance. | |||
* @example | * @example | |||
* | * | |||
* function square(n) { | * function square(n) { | |||
* return n * n; | * return n * n; | |||
* } | * } | |||
* | * | |||
* var wrapped = _([1, 2, 3]); | * var wrapped = _([1, 2, 3]); | |||
* | * | |||
* // returns an unwrapped value | * // Returns an unwrapped value. | |||
* wrapped.reduce(_.add); | * wrapped.reduce(_.add); | |||
* // => 6 | * // => 6 | |||
* | * | |||
* // returns a wrapped value | * // Returns a wrapped value. | |||
* var squares = wrapped.map(square); | * var squares = wrapped.map(square); | |||
* | * | |||
* _.isArray(squares); | * _.isArray(squares); | |||
* // => false | * // => false | |||
* | * | |||
* _.isArray(squares.value()); | * _.isArray(squares.value()); | |||
* // => true | * // => true | |||
*/ | */ | |||
function lodash(value) { | function lodash(value) { | |||
if (isObjectLike(value) && !isArray(value)) { | return value instanceof LodashWrapper | |||
if (value instanceof LodashWrapper) { | ? value | |||
return value; | : new LodashWrapper(value); | |||
} | ||||
if (hasOwnProperty.call(value, '__wrapped__')) { | ||||
return wrapperClone(value); | ||||
} | ||||
} | ||||
return new LodashWrapper(value); | ||||
} | } | |||
/** | /** | |||
* The base implementation of `_.create` without support for assigning | ||||
* properties to the created object. | ||||
* | ||||
* @private | ||||
* @param {Object} proto The object to inherit from. | ||||
* @returns {Object} Returns the new object. | ||||
*/ | ||||
var baseCreate = (function() { | ||||
function object() {} | ||||
return function(proto) { | ||||
if (!isObject(proto)) { | ||||
return {}; | ||||
} | ||||
if (objectCreate) { | ||||
return objectCreate(proto); | ||||
} | ||||
object.prototype = proto; | ||||
var result = new object; | ||||
object.prototype = undefined; | ||||
return result; | ||||
}; | ||||
}()); | ||||
/** | ||||
* The base constructor for creating `lodash` wrapper objects. | * The base constructor for creating `lodash` wrapper objects. | |||
* | * | |||
* @private | * @private | |||
* @param {*} value The value to wrap. | * @param {*} value The value to wrap. | |||
* @param {boolean} [chainAll] Enable chaining for all wrapper methods. | * @param {boolean} [chainAll] Enable explicit method chain sequences. | |||
*/ | */ | |||
function LodashWrapper(value, chainAll) { | function LodashWrapper(value, chainAll) { | |||
this.__wrapped__ = value; | this.__wrapped__ = value; | |||
this.__actions__ = []; | this.__actions__ = []; | |||
this.__chain__ = !!chainAll; | this.__chain__ = !!chainAll; | |||
} | } | |||
/*------------------------------------------------------------------------*/ | LodashWrapper.prototype = baseCreate(lodash.prototype); | |||
LodashWrapper.prototype.constructor = LodashWrapper; | ||||
/** | /*------------------------------------------------------------------------*/ | |||
* Used by `_.defaults` to customize its `_.assignIn` use. | ||||
* | ||||
* @private | ||||
* @param {*} objValue The destination value. | ||||
* @param {*} srcValue The source value. | ||||
* @param {string} key The key of the property to assign. | ||||
* @param {Object} object The parent object of `objValue`. | ||||
* @returns {*} Returns the value to assign. | ||||
*/ | ||||
function assignInDefaults(objValue, srcValue, key, object) { | ||||
if (objValue === undefined || | ||||
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { | ||||
return srcValue; | ||||
} | ||||
return objValue; | ||||
} | ||||
/** | /** | |||
* Assigns `value` to `key` of `object` if the existing value is not equivalen t | * Assigns `value` to `key` of `object` if the existing value is not equivalen t | |||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-sam evaluezero) | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-sam evaluezero) | |||
* for equality comparisons. | * for equality comparisons. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to modify. | * @param {Object} object The object to modify. | |||
* @param {string} key The key of the property to assign. | * @param {string} key The key of the property to assign. | |||
* @param {*} value The value to assign. | * @param {*} value The value to assign. | |||
*/ | */ | |||
function assignValue(object, key, value) { | function assignValue(object, key, value) { | |||
var objValue = object[key]; | var objValue = object[key]; | |||
if ((!eq(objValue, value) || | if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || | |||
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) | ||||
|| | ||||
(value === undefined && !(key in object))) { | (value === undefined && !(key in object))) { | |||
object[key] = value; | baseAssignValue(object, key, value); | |||
} | } | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.create` without support for assigning | * The base implementation of `assignValue` and `assignMergeValue` without | |||
* properties to the created object. | * value checks. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} prototype The object to inherit from. | * @param {Object} object The object to modify. | |||
* @returns {Object} Returns the new object. | * @param {string} key The key of the property to assign. | |||
* @param {*} value The value to assign. | ||||
*/ | */ | |||
var baseCreate = (function() { | function baseAssignValue(object, key, value) { | |||
function object() {} | object[key] = value; | |||
return function(prototype) { | } | |||
if (isObject(prototype)) { | ||||
object.prototype = prototype; | ||||
var result = new object; | ||||
object.prototype = undefined; | ||||
} | ||||
return result || {}; | ||||
}; | ||||
}()); | ||||
/** | /** | |||
* The base implementation of `_.delay` and `_.defer` which accepts an array | * The base implementation of `_.delay` and `_.defer` which accepts `args` | |||
* of `func` arguments. | * to provide to `func`. | |||
* | * | |||
* @private | * @private | |||
* @param {Function} func The function to delay. | * @param {Function} func The function to delay. | |||
* @param {number} wait The number of milliseconds to delay invocation. | * @param {number} wait The number of milliseconds to delay invocation. | |||
* @param {Object} args The arguments provide to `func`. | * @param {Array} args The arguments to provide to `func`. | |||
* @returns {number} Returns the timer id. | * @returns {number|Object} Returns the timer id or timeout object. | |||
*/ | */ | |||
function baseDelay(func, wait, args) { | function baseDelay(func, wait, args) { | |||
if (typeof func != 'function') { | if (typeof func != 'function') { | |||
throw new TypeError(FUNC_ERROR_TEXT); | throw new TypeError(FUNC_ERROR_TEXT); | |||
} | } | |||
return setTimeout(function() { func.apply(undefined, args); }, wait); | return setTimeout(function() { func.apply(undefined, args); }, wait); | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.forEach` without support for iteratee shortha nds. | * The base implementation of `_.forEach` without support for iteratee shortha nds. | |||
skipping to change at line 605 | skipping to change at line 466 | |||
* @returns {Array|Object} Returns `collection`. | * @returns {Array|Object} Returns `collection`. | |||
*/ | */ | |||
var baseEach = createBaseEach(baseForOwn); | var baseEach = createBaseEach(baseForOwn); | |||
/** | /** | |||
* The base implementation of `_.every` without support for iteratee shorthand s. | * The base implementation of `_.every` without support for iteratee shorthand s. | |||
* | * | |||
* @private | * @private | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function} predicate The function invoked per iteration. | * @param {Function} predicate The function invoked per iteration. | |||
* @returns {boolean} Returns `true` if all elements pass the predicate check, | * @returns {boolean} Returns `true` if all elements pass the predicate check, | |||
else `false` | * else `false` | |||
*/ | */ | |||
function baseEvery(collection, predicate) { | function baseEvery(collection, predicate) { | |||
var result = true; | var result = true; | |||
baseEach(collection, function(value, index, collection) { | baseEach(collection, function(value, index, collection) { | |||
result = !!predicate(value, index, collection); | result = !!predicate(value, index, collection); | |||
return result; | return result; | |||
}); | }); | |||
return result; | return result; | |||
} | } | |||
/** | /** | |||
* The base implementation of methods like `_.max` and `_.min` which accepts a | ||||
* `comparator` to determine the extremum value. | ||||
* | ||||
* @private | ||||
* @param {Array} array The array to iterate over. | ||||
* @param {Function} iteratee The iteratee invoked per iteration. | ||||
* @param {Function} comparator The comparator used to compare values. | ||||
* @returns {*} Returns the extremum value. | ||||
*/ | ||||
function baseExtremum(array, iteratee, comparator) { | ||||
var index = -1, | ||||
length = array.length; | ||||
while (++index < length) { | ||||
var value = array[index], | ||||
current = iteratee(value); | ||||
if (current != null && (computed === undefined | ||||
? (current === current && !false) | ||||
: comparator(current, computed) | ||||
)) { | ||||
var computed = current, | ||||
result = value; | ||||
} | ||||
} | ||||
return result; | ||||
} | ||||
/** | ||||
* The base implementation of `_.filter` without support for iteratee shorthan ds. | * The base implementation of `_.filter` without support for iteratee shorthan ds. | |||
* | * | |||
* @private | * @private | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function} predicate The function invoked per iteration. | * @param {Function} predicate The function invoked per iteration. | |||
* @returns {Array} Returns the new filtered array. | * @returns {Array} Returns the new filtered array. | |||
*/ | */ | |||
function baseFilter(collection, predicate) { | function baseFilter(collection, predicate) { | |||
var result = []; | var result = []; | |||
baseEach(collection, function(value, index, collection) { | baseEach(collection, function(value, index, collection) { | |||
skipping to change at line 639 | skipping to change at line 530 | |||
} | } | |||
}); | }); | |||
return result; | return result; | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.flatten` with support for restricting flatten ing. | * The base implementation of `_.flatten` with support for restricting flatten ing. | |||
* | * | |||
* @private | * @private | |||
* @param {Array} array The array to flatten. | * @param {Array} array The array to flatten. | |||
* @param {boolean} [isDeep] Specify a deep flatten. | * @param {number} depth The maximum recursion depth. | |||
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects. | * @param {boolean} [predicate=isFlattenable] The function invoked per iterati | |||
on. | ||||
* @param {boolean} [isStrict] Restrict to values that pass `predicate` checks | ||||
. | ||||
* @param {Array} [result=[]] The initial result value. | * @param {Array} [result=[]] The initial result value. | |||
* @returns {Array} Returns the new flattened array. | * @returns {Array} Returns the new flattened array. | |||
*/ | */ | |||
function baseFlatten(array, isDeep, isStrict, result) { | function baseFlatten(array, depth, predicate, isStrict, result) { | |||
result || (result = []); | ||||
var index = -1, | var index = -1, | |||
length = array.length; | length = array.length; | |||
predicate || (predicate = isFlattenable); | ||||
result || (result = []); | ||||
while (++index < length) { | while (++index < length) { | |||
var value = array[index]; | var value = array[index]; | |||
if (isArrayLikeObject(value) && | if (depth > 0 && predicate(value)) { | |||
(isStrict || isArray(value) || isArguments(value))) { | if (depth > 1) { | |||
if (isDeep) { | ||||
// Recursively flatten arrays (susceptible to call stack limits). | // Recursively flatten arrays (susceptible to call stack limits). | |||
baseFlatten(value, isDeep, isStrict, result); | baseFlatten(value, depth - 1, predicate, isStrict, result); | |||
} else { | } else { | |||
arrayPush(result, value); | arrayPush(result, value); | |||
} | } | |||
} else if (!isStrict) { | } else if (!isStrict) { | |||
result[result.length] = value; | result[result.length] = value; | |||
} | } | |||
} | } | |||
return result; | return result; | |||
} | } | |||
/** | /** | |||
* The base implementation of `baseForIn` and `baseForOwn` which iterates | * The base implementation of `baseForOwn` which iterates over `object` | |||
* over `object` properties returned by `keysFunc` invoking `iteratee` for | * properties returned by `keysFunc` and invokes `iteratee` for each property. | |||
* each property. Iteratee functions may exit iteration early by explicitly | * Iteratee functions may exit iteration early by explicitly returning `false` | |||
* returning `false`. | . | |||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to iterate over. | * @param {Object} object The object to iterate over. | |||
* @param {Function} iteratee The function invoked per iteration. | * @param {Function} iteratee The function invoked per iteration. | |||
* @param {Function} keysFunc The function to get the keys of `object`. | * @param {Function} keysFunc The function to get the keys of `object`. | |||
* @returns {Object} Returns `object`. | * @returns {Object} Returns `object`. | |||
*/ | */ | |||
var baseFor = createBaseFor(); | var baseFor = createBaseFor(); | |||
/** | /** | |||
skipping to change at line 695 | skipping to change at line 586 | |||
* @param {Object} object The object to iterate over. | * @param {Object} object The object to iterate over. | |||
* @param {Function} iteratee The function invoked per iteration. | * @param {Function} iteratee The function invoked per iteration. | |||
* @returns {Object} Returns `object`. | * @returns {Object} Returns `object`. | |||
*/ | */ | |||
function baseForOwn(object, iteratee) { | function baseForOwn(object, iteratee) { | |||
return object && baseFor(object, iteratee, keys); | return object && baseFor(object, iteratee, keys); | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.functions` which creates an array of | * The base implementation of `_.functions` which creates an array of | |||
* `object` function property names filtered from those provided. | * `object` function property names filtered from `props`. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to inspect. | * @param {Object} object The object to inspect. | |||
* @param {Array} props The property names to filter. | * @param {Array} props The property names to filter. | |||
* @returns {Array} Returns the new array of filtered property names. | * @returns {Array} Returns the function names. | |||
*/ | */ | |||
function baseFunctions(object, props) { | function baseFunctions(object, props) { | |||
return baseFilter(props, function(key) { | return baseFilter(props, function(key) { | |||
return isFunction(object[key]); | return isFunction(object[key]); | |||
}); | }); | |||
} | } | |||
/** | /** | |||
* The base implementation of `getTag` without fallbacks for buggy environment | ||||
s. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to query. | ||||
* @returns {string} Returns the `toStringTag`. | ||||
*/ | ||||
function baseGetTag(value) { | ||||
return objectToString(value); | ||||
} | ||||
/** | ||||
* The base implementation of `_.gt` which doesn't coerce arguments. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to compare. | ||||
* @param {*} other The other value to compare. | ||||
* @returns {boolean} Returns `true` if `value` is greater than `other`, | ||||
* else `false`. | ||||
*/ | ||||
function baseGt(value, other) { | ||||
return value > other; | ||||
} | ||||
/** | ||||
* The base implementation of `_.isArguments`. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to check. | ||||
* @returns {boolean} Returns `true` if `value` is an `arguments` object, | ||||
*/ | ||||
var baseIsArguments = noop; | ||||
/** | ||||
* The base implementation of `_.isDate` without Node.js optimizations. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to check. | ||||
* @returns {boolean} Returns `true` if `value` is a date object, else `false` | ||||
. | ||||
*/ | ||||
function baseIsDate(value) { | ||||
return isObjectLike(value) && baseGetTag(value) == dateTag; | ||||
} | ||||
/** | ||||
* The base implementation of `_.isEqual` which supports partial comparisons | * The base implementation of `_.isEqual` which supports partial comparisons | |||
* and tracks traversed objects. | * and tracks traversed objects. | |||
* | * | |||
* @private | * @private | |||
* @param {*} value The value to compare. | * @param {*} value The value to compare. | |||
* @param {*} other The other value to compare. | * @param {*} other The other value to compare. | |||
* @param {boolean} bitmask The bitmask flags. | ||||
* 1 - Unordered comparison | ||||
* 2 - Partial comparison | ||||
* @param {Function} [customizer] The function to customize comparisons. | * @param {Function} [customizer] The function to customize comparisons. | |||
* @param {boolean} [bitmask] The bitmask of comparison flags. | ||||
* The bitmask may be composed of the following flags: | ||||
* 1 - Unordered comparison | ||||
* 2 - Partial comparison | ||||
* @param {Object} [stack] Tracks traversed `value` and `other` objects. | * @param {Object} [stack] Tracks traversed `value` and `other` objects. | |||
* @returns {boolean} Returns `true` if the values are equivalent, else `false `. | * @returns {boolean} Returns `true` if the values are equivalent, else `false `. | |||
*/ | */ | |||
function baseIsEqual(value, other, customizer, bitmask, stack) { | function baseIsEqual(value, other, bitmask, customizer, stack) { | |||
if (value === other) { | if (value === other) { | |||
return true; | return true; | |||
} | } | |||
if (value == null || other == null || (!isObject(value) && !isObjectLike(oth er))) { | if (value == null || other == null || (!isObjectLike(value) && !isObjectLike (other))) { | |||
return value !== value && other !== other; | return value !== value && other !== other; | |||
} | } | |||
return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack ); | return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack ); | |||
} | } | |||
/** | /** | |||
* A specialized version of `baseIsEqual` for arrays and objects which perform s | * A specialized version of `baseIsEqual` for arrays and objects which perform s | |||
* deep comparisons and tracks traversed objects enabling objects with circula r | * deep comparisons and tracks traversed objects enabling objects with circula r | |||
* references to be compared. | * references to be compared. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to compare. | * @param {Object} object The object to compare. | |||
* @param {Object} other The other object to compare. | * @param {Object} other The other object to compare. | |||
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more detai | ||||
ls. | ||||
* @param {Function} customizer The function to customize comparisons. | ||||
* @param {Function} equalFunc The function to determine equivalents of values . | * @param {Function} equalFunc The function to determine equivalents of values . | |||
* @param {Function} [customizer] The function to customize comparisons. | ||||
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual | ||||
` for more details. | ||||
* @param {Object} [stack] Tracks traversed `object` and `other` objects. | * @param {Object} [stack] Tracks traversed `object` and `other` objects. | |||
* @returns {boolean} Returns `true` if the objects are equivalent, else `fals e`. | * @returns {boolean} Returns `true` if the objects are equivalent, else `fals e`. | |||
*/ | */ | |||
function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) { | function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { | |||
var objIsArr = isArray(object), | var objIsArr = isArray(object), | |||
othIsArr = isArray(other), | othIsArr = isArray(other), | |||
objTag = arrayTag, | objTag = objIsArr ? arrayTag : baseGetTag(object), | |||
othTag = arrayTag; | othTag = othIsArr ? arrayTag : baseGetTag(other); | |||
if (!objIsArr) { | objTag = objTag == argsTag ? objectTag : objTag; | |||
objTag = objectToString.call(object); | othTag = othTag == argsTag ? objectTag : othTag; | |||
if (objTag == argsTag) { | ||||
objTag = objectTag; | var objIsObj = objTag == objectTag, | |||
} | othIsObj = othTag == objectTag, | |||
} | ||||
if (!othIsArr) { | ||||
othTag = objectToString.call(other); | ||||
if (othTag == argsTag) { | ||||
othTag = objectTag; | ||||
} | ||||
} | ||||
var objIsObj = objTag == objectTag && !isHostObject(object), | ||||
othIsObj = othTag == objectTag && !isHostObject(other), | ||||
isSameTag = objTag == othTag; | isSameTag = objTag == othTag; | |||
if (isSameTag && !(objIsArr || objIsObj)) { | stack || (stack = []); | |||
return equalByTag(object, other, objTag, equalFunc, customizer, bitmask); | var objStack = find(stack, function(entry) { | |||
return entry[0] == object; | ||||
}); | ||||
var othStack = find(stack, function(entry) { | ||||
return entry[0] == other; | ||||
}); | ||||
if (objStack && othStack) { | ||||
return objStack[1] == other; | ||||
} | } | |||
var isPartial = bitmask & PARTIAL_COMPARE_FLAG; | stack.push([object, other]); | |||
if (!isPartial) { | stack.push([other, object]); | |||
if (isSameTag && !objIsObj) { | ||||
var result = (objIsArr) | ||||
? equalArrays(object, other, bitmask, customizer, equalFunc, stack) | ||||
: equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stac | ||||
k); | ||||
stack.pop(); | ||||
return result; | ||||
} | ||||
if (!(bitmask & COMPARE_PARTIAL_FLAG)) { | ||||
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), | var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), | |||
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); | othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); | |||
if (objIsWrapped || othIsWrapped) { | if (objIsWrapped || othIsWrapped) { | |||
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? | var objUnwrapped = objIsWrapped ? object.value() : object, | |||
other.value() : other, customizer, bitmask, stack); | othUnwrapped = othIsWrapped ? other.value() : other; | |||
var result = equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, | ||||
stack); | ||||
stack.pop(); | ||||
return result; | ||||
} | } | |||
} | } | |||
if (!isSameTag) { | if (!isSameTag) { | |||
return false; | return false; | |||
} | } | |||
stack || (stack = []); | var result = equalObjects(object, other, bitmask, customizer, equalFunc, sta | |||
var stacked = find(stack, function(entry) { | ck); | |||
return entry[0] === object; | ||||
}); | ||||
if (stacked && stacked[1]) { | ||||
return stacked[1] == other; | ||||
} | ||||
stack.push([object, other]); | ||||
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFu | ||||
nc, customizer, bitmask, stack); | ||||
stack.pop(); | stack.pop(); | |||
return result; | return result; | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.iteratee`. | * The base implementation of `_.isRegExp` without Node.js optimizations. | |||
* | * | |||
* @private | * @private | |||
* @param {*} [value=_.identity] The value to convert to an iteratee. | * @param {*} value The value to check. | |||
* @returns {Function} Returns the iteratee. | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. | |||
*/ | */ | |||
function baseIteratee(func) { | function baseIsRegExp(value) { | |||
var type = typeof func; | return isObjectLike(value) && baseGetTag(value) == regexpTag; | |||
if (type == 'function') { | ||||
return func; | ||||
} | ||||
return func == null | ||||
? identity | ||||
: (type == 'object' ? baseMatches : baseProperty)(func); | ||||
} | } | |||
/** | /** | |||
* The base implementation of `_.keys` which doesn't skip the constructor | * The base implementation of `_.iteratee`. | |||
* property of prototypes or treat sparse arrays as dense. | ||||
* | * | |||
* @private | * @private | |||
* @type Function | * @param {*} [value=_.identity] The value to convert to an iteratee. | |||
* @param {Object} object The object to query. | * @returns {Function} Returns the iteratee. | |||
* @returns {Array} Returns the array of property names. | ||||
*/ | */ | |||
function baseKeys(object) { | function baseIteratee(func) { | |||
return nativeKeys(Object(object)); | if (typeof func == 'function') { | |||
return func; | ||||
} | ||||
if (func == null) { | ||||
return identity; | ||||
} | ||||
return (typeof func == 'object' ? baseMatches : baseProperty)(func); | ||||
} | } | |||
/** | /** | |||
* The base implementation of `_.keysIn` which doesn't skip the constructor | * The base implementation of `_.lt` which doesn't coerce arguments. | |||
* property of prototypes or treat sparse arrays as dense. | ||||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to query. | * @param {*} value The value to compare. | |||
* @returns {Array} Returns the array of property names. | * @param {*} other The other value to compare. | |||
* @returns {boolean} Returns `true` if `value` is less than `other`, | ||||
* else `false`. | ||||
*/ | */ | |||
function baseKeysIn(object) { | function baseLt(value, other) { | |||
object = object == null ? object : Object(object); | return value < other; | |||
var result = []; | ||||
for (var key in object) { | ||||
result.push(key); | ||||
} | ||||
return result; | ||||
} | ||||
// Fallback for IE < 9 with es6-shim. | ||||
if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) { | ||||
baseKeysIn = function(object) { | ||||
return iteratorToArray(enumerate(object)); | ||||
}; | ||||
} | } | |||
/** | /** | |||
* The base implementation of `_.map` without support for iteratee shorthands. | * The base implementation of `_.map` without support for iteratee shorthands. | |||
* | * | |||
* @private | * @private | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function} iteratee The function invoked per iteration. | * @param {Function} iteratee The function invoked per iteration. | |||
* @returns {Array} Returns the new mapped array. | * @returns {Array} Returns the new mapped array. | |||
*/ | */ | |||
skipping to change at line 875 | skipping to change at line 798 | |||
result[++index] = iteratee(value, key, collection); | result[++index] = iteratee(value, key, collection); | |||
}); | }); | |||
return result; | return result; | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.matches` which doesn't clone `source`. | * The base implementation of `_.matches` which doesn't clone `source`. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} source The object of property values to match. | * @param {Object} source The object of property values to match. | |||
* @returns {Function} Returns the new function. | * @returns {Function} Returns the new spec function. | |||
*/ | */ | |||
function baseMatches(source) { | function baseMatches(source) { | |||
var props = keys(source), | var props = nativeKeys(source); | |||
length = props.length; | ||||
return function(object) { | return function(object) { | |||
var length = props.length; | ||||
if (object == null) { | if (object == null) { | |||
return !length; | return !length; | |||
} | } | |||
object = Object(object); | object = Object(object); | |||
while (length--) { | while (length--) { | |||
var key = props[length]; | var key = props[length]; | |||
if (!(key in object && baseIsEqual(source[key], object[key], undefined, | if (!(key in object && | |||
true))) { | baseIsEqual(source[key], object[key], COMPARE_PARTIAL_FLAG | COMPA | |||
RE_UNORDERED_FLAG) | ||||
)) { | ||||
return false; | return false; | |||
} | } | |||
} | } | |||
return true; | return true; | |||
}; | }; | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.pick` without support for individual | * The base implementation of `_.pick` without support for individual | |||
* property names. | * property identifiers. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} object The source object. | * @param {Object} object The source object. | |||
* @param {string[]} props The property names to pick. | * @param {string[]} paths The property paths to pick. | |||
* @returns {Object} Returns the new object. | * @returns {Object} Returns the new object. | |||
*/ | */ | |||
function basePick(object, props) { | function basePick(object, props) { | |||
object = Object(object); | object = Object(object); | |||
return reduce(props, function(result, key) { | return reduce(props, function(result, key) { | |||
if (key in object) { | if (key in object) { | |||
result[key] = object[key]; | result[key] = object[key]; | |||
} | } | |||
return result; | return result; | |||
}, {}); | }, {}); | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.property` without support for deep paths. | * The base implementation of `_.rest` which doesn't validate or coerce argume nts. | |||
* | * | |||
* @private | * @private | |||
* @param {string} key The key of the property to get. | * @param {Function} func The function to apply a rest parameter to. | |||
* @param {number} [start=func.length-1] The start position of the rest parame | ||||
ter. | ||||
* @returns {Function} Returns the new function. | * @returns {Function} Returns the new function. | |||
*/ | */ | |||
function baseProperty(key) { | function baseRest(func, start) { | |||
return function(object) { | return setToString(overRest(func, start, identity), func + ''); | |||
return object == null ? undefined : object[key]; | ||||
}; | ||||
} | } | |||
/** | /** | |||
* The base implementation of `_.slice` without an iteratee call guard. | * The base implementation of `_.slice` without an iteratee call guard. | |||
* | * | |||
* @private | * @private | |||
* @param {Array} array The array to slice. | * @param {Array} array The array to slice. | |||
* @param {number} [start=0] The start position. | * @param {number} [start=0] The start position. | |||
* @param {number} [end=array.length] The end position. | * @param {number} [end=array.length] The end position. | |||
* @returns {Array} Returns the slice of `array`. | * @returns {Array} Returns the slice of `array`. | |||
skipping to change at line 976 | skipping to change at line 899 | |||
function copyArray(source) { | function copyArray(source) { | |||
return baseSlice(source, 0, source.length); | return baseSlice(source, 0, source.length); | |||
} | } | |||
/** | /** | |||
* The base implementation of `_.some` without support for iteratee shorthands . | * The base implementation of `_.some` without support for iteratee shorthands . | |||
* | * | |||
* @private | * @private | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function} predicate The function invoked per iteration. | * @param {Function} predicate The function invoked per iteration. | |||
* @returns {boolean} Returns `true` if any element passes the predicate check | * @returns {boolean} Returns `true` if any element passes the predicate check | |||
, else `false`. | , | |||
* else `false`. | ||||
*/ | */ | |||
function baseSome(collection, predicate) { | function baseSome(collection, predicate) { | |||
var result; | var result; | |||
baseEach(collection, function(value, index, collection) { | baseEach(collection, function(value, index, collection) { | |||
result = predicate(value, index, collection); | result = predicate(value, index, collection); | |||
return !result; | return !result; | |||
}); | }); | |||
return !!result; | return !!result; | |||
} | } | |||
skipping to change at line 1006 | skipping to change at line 930 | |||
* @returns {*} Returns the resolved value. | * @returns {*} Returns the resolved value. | |||
*/ | */ | |||
function baseWrapperValue(value, actions) { | function baseWrapperValue(value, actions) { | |||
var result = value; | var result = value; | |||
return reduce(actions, function(result, action) { | return reduce(actions, function(result, action) { | |||
return action.func.apply(action.thisArg, arrayPush([result], action.args)) ; | return action.func.apply(action.thisArg, arrayPush([result], action.args)) ; | |||
}, result); | }, result); | |||
} | } | |||
/** | /** | |||
* Copies properties of `source` to `object`. | * Compares values to sort them in ascending order. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} source The object to copy properties from. | * @param {*} value The value to compare. | |||
* @param {Array} props The property names to copy. | * @param {*} other The other value to compare. | |||
* @param {Object} [object={}] The object to copy properties to. | * @returns {number} Returns the sort order indicator for `value`. | |||
* @returns {Object} Returns `object`. | ||||
*/ | */ | |||
var copyObject = copyObjectWith; | function compareAscending(value, other) { | |||
if (value !== other) { | ||||
var valIsDefined = value !== undefined, | ||||
valIsNull = value === null, | ||||
valIsReflexive = value === value, | ||||
valIsSymbol = false; | ||||
var othIsDefined = other !== undefined, | ||||
othIsNull = other === null, | ||||
othIsReflexive = other === other, | ||||
othIsSymbol = false; | ||||
if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || | ||||
(valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIs | ||||
Symbol) || | ||||
(valIsNull && othIsDefined && othIsReflexive) || | ||||
(!valIsDefined && othIsReflexive) || | ||||
!valIsReflexive) { | ||||
return 1; | ||||
} | ||||
if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || | ||||
(othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIs | ||||
Symbol) || | ||||
(othIsNull && valIsDefined && valIsReflexive) || | ||||
(!othIsDefined && valIsReflexive) || | ||||
!othIsReflexive) { | ||||
return -1; | ||||
} | ||||
} | ||||
return 0; | ||||
} | ||||
/** | /** | |||
* This function is like `copyObject` except that it accepts a function to | * Copies properties of `source` to `object`. | |||
* customize copied values. | ||||
* | * | |||
* @private | * @private | |||
* @param {Object} source The object to copy properties from. | * @param {Object} source The object to copy properties from. | |||
* @param {Array} props The property names to copy. | * @param {Array} props The property identifiers to copy. | |||
* @param {Object} [object={}] The object to copy properties to. | * @param {Object} [object={}] The object to copy properties to. | |||
* @param {Function} [customizer] The function to customize copied values. | * @param {Function} [customizer] The function to customize copied values. | |||
* @returns {Object} Returns `object`. | * @returns {Object} Returns `object`. | |||
*/ | */ | |||
function copyObjectWith(source, props, object, customizer) { | function copyObject(source, props, object, customizer) { | |||
var isNew = !object; | ||||
object || (object = {}); | object || (object = {}); | |||
var index = -1, | var index = -1, | |||
length = props.length; | length = props.length; | |||
while (++index < length) { | while (++index < length) { | |||
var key = props[index], | var key = props[index]; | |||
newValue = customizer ? customizer(object[key], source[key], key, obje | ||||
ct, source) : source[key]; | ||||
assignValue(object, key, newValue); | var newValue = customizer | |||
? customizer(object[key], source[key], key, object, source) | ||||
: undefined; | ||||
if (newValue === undefined) { | ||||
newValue = source[key]; | ||||
} | ||||
if (isNew) { | ||||
baseAssignValue(object, key, newValue); | ||||
} else { | ||||
assignValue(object, key, newValue); | ||||
} | ||||
} | } | |||
return object; | return object; | |||
} | } | |||
/** | /** | |||
* Creates a function like `_.assign`. | * Creates a function like `_.assign`. | |||
* | * | |||
* @private | * @private | |||
* @param {Function} assigner The function to assign values. | * @param {Function} assigner The function to assign values. | |||
* @returns {Function} Returns the new assigner function. | * @returns {Function} Returns the new assigner function. | |||
*/ | */ | |||
function createAssigner(assigner) { | function createAssigner(assigner) { | |||
return rest(function(object, sources) { | return baseRest(function(object, sources) { | |||
var index = -1, | var index = -1, | |||
length = sources.length, | length = sources.length, | |||
customizer = length > 1 ? sources[length - 1] : undefined; | customizer = length > 1 ? sources[length - 1] : undefined; | |||
customizer = typeof customizer == 'function' ? (length--, customizer) : un | customizer = (assigner.length > 3 && typeof customizer == 'function') | |||
defined; | ? (length--, customizer) | |||
: undefined; | ||||
object = Object(object); | object = Object(object); | |||
while (++index < length) { | while (++index < length) { | |||
var source = sources[index]; | var source = sources[index]; | |||
if (source) { | if (source) { | |||
assigner(object, source, customizer); | assigner(object, source, index, customizer); | |||
} | } | |||
} | } | |||
return object; | return object; | |||
}); | }); | |||
} | } | |||
/** | /** | |||
* Creates a `baseEach` or `baseEachRight` function. | * Creates a `baseEach` or `baseEachRight` function. | |||
* | * | |||
* @private | * @private | |||
skipping to change at line 1097 | skipping to change at line 1061 | |||
while ((fromRight ? index-- : ++index < length)) { | while ((fromRight ? index-- : ++index < length)) { | |||
if (iteratee(iterable[index], index, iterable) === false) { | if (iteratee(iterable[index], index, iterable) === false) { | |||
break; | break; | |||
} | } | |||
} | } | |||
return collection; | return collection; | |||
}; | }; | |||
} | } | |||
/** | /** | |||
* Creates a base function for methods like `_.forIn`. | * Creates a base function for methods like `_.forIn` and `_.forOwn`. | |||
* | * | |||
* @private | * @private | |||
* @param {boolean} [fromRight] Specify iterating from right to left. | * @param {boolean} [fromRight] Specify iterating from right to left. | |||
* @returns {Function} Returns the new base function. | * @returns {Function} Returns the new base function. | |||
*/ | */ | |||
function createBaseFor(fromRight) { | function createBaseFor(fromRight) { | |||
return function(object, iteratee, keysFunc) { | return function(object, iteratee, keysFunc) { | |||
var index = -1, | var index = -1, | |||
iterable = Object(object), | iterable = Object(object), | |||
props = keysFunc(object), | props = keysFunc(object), | |||
skipping to change at line 1128 | skipping to change at line 1092 | |||
} | } | |||
/** | /** | |||
* Creates a function that produces an instance of `Ctor` regardless of | * Creates a function that produces an instance of `Ctor` regardless of | |||
* whether it was invoked as part of a `new` expression or by `call` or `apply `. | * whether it was invoked as part of a `new` expression or by `call` or `apply `. | |||
* | * | |||
* @private | * @private | |||
* @param {Function} Ctor The constructor to wrap. | * @param {Function} Ctor The constructor to wrap. | |||
* @returns {Function} Returns the new wrapped function. | * @returns {Function} Returns the new wrapped function. | |||
*/ | */ | |||
function createCtorWrapper(Ctor) { | function createCtor(Ctor) { | |||
return function() { | return function() { | |||
// Use a `switch` statement to work with class constructors. | // Use a `switch` statement to work with class constructors. See | |||
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function | // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-obj | |||
-objects-call-thisargument-argumentslist | ects-call-thisargument-argumentslist | |||
// for more details. | // for more details. | |||
var args = arguments; | var args = arguments; | |||
var thisBinding = baseCreate(Ctor.prototype), | var thisBinding = baseCreate(Ctor.prototype), | |||
result = Ctor.apply(thisBinding, args); | result = Ctor.apply(thisBinding, args); | |||
// Mimic the constructor's `return` behavior. | // Mimic the constructor's `return` behavior. | |||
// See https://es5.github.io/#x13.2.2 for more details. | // See https://es5.github.io/#x13.2.2 for more details. | |||
return isObject(result) ? result : thisBinding; | return isObject(result) ? result : thisBinding; | |||
}; | }; | |||
} | } | |||
/** | /** | |||
* Creates a function that wraps `func` to invoke it with the optional `this` | * Creates a `_.find` or `_.findLast` function. | |||
* binding of `thisArg` and the `partials` prepended to those provided to | * | |||
* the wrapper. | * @private | |||
* @param {Function} findIndexFunc The function to find the collection index. | ||||
* @returns {Function} Returns the new find function. | ||||
*/ | ||||
function createFind(findIndexFunc) { | ||||
return function(collection, predicate, fromIndex) { | ||||
var iterable = Object(collection); | ||||
if (!isArrayLike(collection)) { | ||||
var iteratee = baseIteratee(predicate, 3); | ||||
collection = keys(collection); | ||||
predicate = function(key) { return iteratee(iterable[key], key, iterable | ||||
); }; | ||||
} | ||||
var index = findIndexFunc(collection, predicate, fromIndex); | ||||
return index > -1 ? iterable[iteratee ? collection[index] : index] : undef | ||||
ined; | ||||
}; | ||||
} | ||||
/** | ||||
* Creates a function that wraps `func` to invoke it with the `this` binding | ||||
* of `thisArg` and `partials` prepended to the arguments it receives. | ||||
* | * | |||
* @private | * @private | |||
* @param {Function} func The function to wrap. | * @param {Function} func The function to wrap. | |||
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` f or more details. | * @param {number} bitmask The bitmask flags. See `createWrap` for more detail s. | |||
* @param {*} thisArg The `this` binding of `func`. | * @param {*} thisArg The `this` binding of `func`. | |||
* @param {Array} partials The arguments to prepend to those provided to the n | * @param {Array} partials The arguments to prepend to those provided to | |||
ew function. | * the new function. | |||
* @returns {Function} Returns the new wrapped function. | * @returns {Function} Returns the new wrapped function. | |||
*/ | */ | |||
function createPartialWrapper(func, bitmask, thisArg, partials) { | function createPartial(func, bitmask, thisArg, partials) { | |||
if (typeof func != 'function') { | if (typeof func != 'function') { | |||
throw new TypeError(FUNC_ERROR_TEXT); | throw new TypeError(FUNC_ERROR_TEXT); | |||
} | } | |||
var isBind = bitmask & BIND_FLAG, | var isBind = bitmask & WRAP_BIND_FLAG, | |||
Ctor = createCtorWrapper(func); | Ctor = createCtor(func); | |||
function wrapper() { | function wrapper() { | |||
var argsIndex = -1, | var argsIndex = -1, | |||
argsLength = arguments.length, | argsLength = arguments.length, | |||
leftIndex = -1, | leftIndex = -1, | |||
leftLength = partials.length, | leftLength = partials.length, | |||
args = Array(leftLength + argsLength), | args = Array(leftLength + argsLength), | |||
fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; | fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; | |||
while (++leftIndex < leftLength) { | while (++leftIndex < leftLength) { | |||
skipping to change at line 1188 | skipping to change at line 1172 | |||
return wrapper; | return wrapper; | |||
} | } | |||
/** | /** | |||
* A specialized version of `baseIsEqualDeep` for arrays with support for | * A specialized version of `baseIsEqualDeep` for arrays with support for | |||
* partial deep comparisons. | * partial deep comparisons. | |||
* | * | |||
* @private | * @private | |||
* @param {Array} array The array to compare. | * @param {Array} array The array to compare. | |||
* @param {Array} other The other array to compare. | * @param {Array} other The other array to compare. | |||
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more detai | ||||
ls. | ||||
* @param {Function} customizer The function to customize comparisons. | ||||
* @param {Function} equalFunc The function to determine equivalents of values . | * @param {Function} equalFunc The function to determine equivalents of values . | |||
* @param {Function} [customizer] The function to customize comparisons. | * @param {Object} stack Tracks traversed `array` and `other` objects. | |||
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual | ||||
` for more details. | ||||
* @param {Object} [stack] Tracks traversed `array` and `other` objects. | ||||
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false `. | * @returns {boolean} Returns `true` if the arrays are equivalent, else `false `. | |||
*/ | */ | |||
function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { | |||
var index = -1, | var isPartial = bitmask & COMPARE_PARTIAL_FLAG, | |||
isPartial = bitmask & PARTIAL_COMPARE_FLAG, | ||||
isUnordered = bitmask & UNORDERED_COMPARE_FLAG, | ||||
arrLength = array.length, | arrLength = array.length, | |||
othLength = other.length; | othLength = other.length; | |||
if (arrLength != othLength && !(isPartial && othLength > arrLength)) { | if (arrLength != othLength && !(isPartial && othLength > arrLength)) { | |||
return false; | return false; | |||
} | } | |||
var result = true; | // Check that cyclic values are equal. | |||
var arrStacked = stack.get(array); | ||||
var othStacked = stack.get(other); | ||||
if (arrStacked && othStacked) { | ||||
return arrStacked == other && othStacked == array; | ||||
} | ||||
var index = -1, | ||||
result = true, | ||||
seen = (bitmask & COMPARE_UNORDERED_FLAG) ? [] : undefined; | ||||
// Ignore non-index properties. | // Ignore non-index properties. | |||
while (++index < arrLength) { | while (++index < arrLength) { | |||
var arrValue = array[index], | var arrValue = array[index], | |||
othValue = other[index]; | othValue = other[index]; | |||
var compared; | var compared; | |||
if (compared !== undefined) { | if (compared !== undefined) { | |||
if (compared) { | if (compared) { | |||
continue; | continue; | |||
} | } | |||
result = false; | result = false; | |||
break; | break; | |||
} | } | |||
// Recursively compare arrays (susceptible to call stack limits). | // Recursively compare arrays (susceptible to call stack limits). | |||
if (isUnordered) { | if (seen) { | |||
if (!baseSome(other, function(othValue) { | if (!baseSome(other, function(othValue, othIndex) { | |||
return arrValue === othValue || equalFunc(arrValue, othValue, cust | if (!indexOf(seen, othIndex) && | |||
omizer, bitmask, stack); | (arrValue === othValue || equalFunc(arrValue, othValue, bitmas | |||
k, customizer, stack))) { | ||||
return seen.push(othIndex); | ||||
} | ||||
})) { | })) { | |||
result = false; | result = false; | |||
break; | break; | |||
} | } | |||
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, custom | } else if (!( | |||
izer, bitmask, stack))) { | arrValue === othValue || | |||
equalFunc(arrValue, othValue, bitmask, customizer, stack) | ||||
)) { | ||||
result = false; | result = false; | |||
break; | break; | |||
} | } | |||
} | } | |||
return result; | return result; | |||
} | } | |||
/** | /** | |||
* A specialized version of `baseIsEqualDeep` for comparing objects of | * A specialized version of `baseIsEqualDeep` for comparing objects of | |||
* the same `toStringTag`. | * the same `toStringTag`. | |||
* | * | |||
* **Note:** This function only supports comparing values with tags of | * **Note:** This function only supports comparing values with tags of | |||
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. | * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to compare. | * @param {Object} object The object to compare. | |||
* @param {Object} other The other object to compare. | * @param {Object} other The other object to compare. | |||
* @param {string} tag The `toStringTag` of the objects to compare. | * @param {string} tag The `toStringTag` of the objects to compare. | |||
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more detai | ||||
ls. | ||||
* @param {Function} customizer The function to customize comparisons. | ||||
* @param {Function} equalFunc The function to determine equivalents of values . | * @param {Function} equalFunc The function to determine equivalents of values . | |||
* @param {Function} [customizer] The function to customize comparisons. | * @param {Object} stack Tracks traversed `object` and `other` objects. | |||
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual | ||||
` for more details. | ||||
* @returns {boolean} Returns `true` if the objects are equivalent, else `fals e`. | * @returns {boolean} Returns `true` if the objects are equivalent, else `fals e`. | |||
*/ | */ | |||
function equalByTag(object, other, tag, equalFunc, customizer, bitmask) { | function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { | |||
switch (tag) { | switch (tag) { | |||
case boolTag: | case boolTag: | |||
case dateTag: | case dateTag: | |||
// Coerce dates and booleans to numbers, dates to milliseconds and boole | case numberTag: | |||
ans | // Coerce booleans to `1` or `0` and dates to milliseconds. | |||
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal. | // Invalid dates are coerced to `NaN`. | |||
return +object == +other; | return eq(+object, +other); | |||
case errorTag: | case errorTag: | |||
return object.name == other.name && object.message == other.message; | return object.name == other.name && object.message == other.message; | |||
case numberTag: | ||||
// Treat `NaN` vs. `NaN` as equal. | ||||
return (object != +object) ? other != +other : object == +other; | ||||
case regexpTag: | case regexpTag: | |||
case stringTag: | case stringTag: | |||
// Coerce regexes to strings and treat strings primitives and string | // Coerce regexes to strings and treat strings, primitives and objects, | |||
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more deta | // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-reg | |||
ils. | exp.prototype.tostring | |||
// for more details. | ||||
return object == (other + ''); | return object == (other + ''); | |||
} | } | |||
return false; | return false; | |||
} | } | |||
/** | /** | |||
* A specialized version of `baseIsEqualDeep` for objects with support for | * A specialized version of `baseIsEqualDeep` for objects with support for | |||
* partial deep comparisons. | * partial deep comparisons. | |||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to compare. | * @param {Object} object The object to compare. | |||
* @param {Object} other The other object to compare. | * @param {Object} other The other object to compare. | |||
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more detai | ||||
ls. | ||||
* @param {Function} customizer The function to customize comparisons. | ||||
* @param {Function} equalFunc The function to determine equivalents of values . | * @param {Function} equalFunc The function to determine equivalents of values . | |||
* @param {Function} [customizer] The function to customize comparisons. | * @param {Object} stack Tracks traversed `object` and `other` objects. | |||
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual | ||||
` for more details. | ||||
* @param {Object} [stack] Tracks traversed `object` and `other` objects. | ||||
* @returns {boolean} Returns `true` if the objects are equivalent, else `fals e`. | * @returns {boolean} Returns `true` if the objects are equivalent, else `fals e`. | |||
*/ | */ | |||
function equalObjects(object, other, equalFunc, customizer, bitmask, stack) { | function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { | |||
var isPartial = bitmask & PARTIAL_COMPARE_FLAG, | var isPartial = bitmask & COMPARE_PARTIAL_FLAG, | |||
isUnordered = bitmask & UNORDERED_COMPARE_FLAG, | ||||
objProps = keys(object), | objProps = keys(object), | |||
objLength = objProps.length, | objLength = objProps.length, | |||
othProps = keys(other), | othProps = keys(other), | |||
othLength = othProps.length; | othLength = othProps.length; | |||
if (objLength != othLength && !isPartial) { | if (objLength != othLength && !isPartial) { | |||
return false; | return false; | |||
} | } | |||
var index = objLength; | var index = objLength; | |||
while (index--) { | while (index--) { | |||
var key = objProps[index]; | var key = objProps[index]; | |||
if (!(isPartial ? key in other : hasOwnProperty.call(other, key)) || | if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { | |||
!(isUnordered || key == othProps[index])) { | ||||
return false; | return false; | |||
} | } | |||
} | } | |||
// Check that cyclic values are equal. | ||||
var objStacked = stack.get(object); | ||||
var othStacked = stack.get(other); | ||||
if (objStacked && othStacked) { | ||||
return objStacked == other && othStacked == object; | ||||
} | ||||
var result = true; | var result = true; | |||
var skipCtor = isPartial; | var skipCtor = isPartial; | |||
while (++index < objLength) { | while (++index < objLength) { | |||
key = objProps[index]; | key = objProps[index]; | |||
var objValue = object[key], | var objValue = object[key], | |||
othValue = other[key]; | othValue = other[key]; | |||
var compared; | var compared; | |||
// Recursively compare objects (susceptible to call stack limits). | // Recursively compare objects (susceptible to call stack limits). | |||
if (!(compared === undefined | if (!(compared === undefined | |||
? (objValue === othValue || equalFunc(objValue, othValue, customizer , bitmask, stack)) | ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, c ustomizer, stack)) | |||
: compared | : compared | |||
)) { | )) { | |||
result = false; | result = false; | |||
break; | break; | |||
} | } | |||
skipCtor || (skipCtor = key == 'constructor'); | skipCtor || (skipCtor = key == 'constructor'); | |||
} | } | |||
if (result && !skipCtor) { | if (result && !skipCtor) { | |||
var objCtor = object.constructor, | var objCtor = object.constructor, | |||
othCtor = other.constructor; | othCtor = other.constructor; | |||
skipping to change at line 1344 | skipping to change at line 1343 | |||
('constructor' in object && 'constructor' in other) && | ('constructor' in object && 'constructor' in other) && | |||
!(typeof objCtor == 'function' && objCtor instanceof objCtor && | !(typeof objCtor == 'function' && objCtor instanceof objCtor && | |||
typeof othCtor == 'function' && othCtor instanceof othCtor)) { | typeof othCtor == 'function' && othCtor instanceof othCtor)) { | |||
result = false; | result = false; | |||
} | } | |||
} | } | |||
return result; | return result; | |||
} | } | |||
/** | /** | |||
* Gets the "length" property value of `object`. | * A specialized version of `baseRest` which flattens the rest array. | |||
* | ||||
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.or | ||||
g/show_bug.cgi?id=142792) | ||||
* that affects Safari on at least iOS 8.1-8.3 ARM64. | ||||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to query. | * @param {Function} func The function to apply a rest parameter to. | |||
* @returns {*} Returns the "length" value. | * @returns {Function} Returns the new function. | |||
*/ | */ | |||
var getLength = baseProperty('length'); | function flatRest(func) { | |||
return setToString(overRest(func, undefined, flatten), func + ''); | ||||
} | ||||
/** | /** | |||
* Creates an array of index keys for `object` values of arrays, | * Checks if `value` is a flattenable `arguments` object or array. | |||
* `arguments` objects, and strings, otherwise `null` is returned. | ||||
* | * | |||
* @private | * @private | |||
* @param {Object} object The object to query. | * @param {*} value The value to check. | |||
* @returns {Array|null} Returns index keys, else `null`. | * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. | |||
*/ | */ | |||
function indexKeys(object) { | function isFlattenable(value) { | |||
var length = object ? object.length : undefined; | return isArray(value) || isArguments(value); | |||
return (isLength(length) && (isArray(object) || isString(object) || isArgume | ||||
nts(object))) | ||||
? baseTimes(length, String) | ||||
: null; | ||||
} | } | |||
/** | /** | |||
* Checks if `value` is likely a prototype object. | * Checks if `value` is a valid array-like index. | |||
* | * | |||
* @private | * @private | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`. | * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index | |||
. | ||||
* @returns {boolean} Returns `true` if `value` is a valid index, else `false` | ||||
. | ||||
*/ | */ | |||
function isPrototype(value) { | function isIndex(value, length) { | |||
var Ctor = value && value.constructor, | var type = typeof value; | |||
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; | length = length == null ? MAX_SAFE_INTEGER : length; | |||
return value === proto; | return !!length && | |||
(type == 'number' || | ||||
(type != 'symbol' && reIsUint.test(value))) && | ||||
(value > -1 && value % 1 == 0 && value < length); | ||||
} | } | |||
/** | /** | |||
* Converts `value` to a function if it's not one. | * Checks if the given arguments are from an iteratee call. | |||
* | * | |||
* @private | * @private | |||
* @param {*} value The value to process. | * @param {*} value The potential iteratee value argument. | |||
* @returns {Function} Returns the function. | * @param {*} index The potential iteratee index or key argument. | |||
* @param {*} object The potential iteratee object argument. | ||||
* @returns {boolean} Returns `true` if the arguments are from an iteratee cal | ||||
l, | ||||
* else `false`. | ||||
*/ | */ | |||
function toFunction(value) { | function isIterateeCall(value, index, object) { | |||
return typeof value == 'function' ? value : identity; | if (!isObject(object)) { | |||
return false; | ||||
} | ||||
var type = typeof index; | ||||
if (type == 'number' | ||||
? (isArrayLike(object) && isIndex(index, object.length)) | ||||
: (type == 'string' && index in object) | ||||
) { | ||||
return eq(object[index], value); | ||||
} | ||||
return false; | ||||
} | } | |||
/** | /** | |||
* Creates a clone of `wrapper`. | * This function is like | |||
* [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys | ||||
) | ||||
* except that it includes inherited enumerable properties. | ||||
* | * | |||
* @private | * @private | |||
* @param {Object} wrapper The wrapper to clone. | * @param {Object} object The object to query. | |||
* @returns {Object} Returns the cloned wrapper. | * @returns {Array} Returns the array of property names. | |||
*/ | */ | |||
function wrapperClone(wrapper) { | function nativeKeysIn(object) { | |||
var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); | var result = []; | |||
result.__actions__ = copyArray(wrapper.__actions__); | if (object != null) { | |||
for (var key in Object(object)) { | ||||
result.push(key); | ||||
} | ||||
} | ||||
return result; | return result; | |||
} | } | |||
/** | ||||
* Converts `value` to a string using `Object.prototype.toString`. | ||||
* | ||||
* @private | ||||
* @param {*} value The value to convert. | ||||
* @returns {string} Returns the converted string. | ||||
*/ | ||||
function objectToString(value) { | ||||
return nativeObjectToString.call(value); | ||||
} | ||||
/** | ||||
* A specialized version of `baseRest` which transforms the rest array. | ||||
* | ||||
* @private | ||||
* @param {Function} func The function to apply a rest parameter to. | ||||
* @param {number} [start=func.length-1] The start position of the rest parame | ||||
ter. | ||||
* @param {Function} transform The rest array transform. | ||||
* @returns {Function} Returns the new function. | ||||
*/ | ||||
function overRest(func, start, transform) { | ||||
start = nativeMax(start === undefined ? (func.length - 1) : start, 0); | ||||
return function() { | ||||
var args = arguments, | ||||
index = -1, | ||||
length = nativeMax(args.length - start, 0), | ||||
array = Array(length); | ||||
while (++index < length) { | ||||
array[index] = args[start + index]; | ||||
} | ||||
index = -1; | ||||
var otherArgs = Array(start + 1); | ||||
while (++index < start) { | ||||
otherArgs[index] = args[index]; | ||||
} | ||||
otherArgs[start] = transform(array); | ||||
return func.apply(this, otherArgs); | ||||
}; | ||||
} | ||||
/** | ||||
* Sets the `toString` method of `func` to return `string`. | ||||
* | ||||
* @private | ||||
* @param {Function} func The function to modify. | ||||
* @param {Function} string The `toString` result. | ||||
* @returns {Function} Returns `func`. | ||||
*/ | ||||
var setToString = identity; | ||||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Creates an array with all falsey values removed. The values `false`, `null` , | * Creates an array with all falsey values removed. The values `false`, `null` , | |||
* `0`, `""`, `undefined`, and `NaN` are falsey. | * `0`, `""`, `undefined`, and `NaN` are falsey. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Array | * @category Array | |||
* @param {Array} array The array to compact. | * @param {Array} array The array to compact. | |||
* @returns {Array} Returns the new array of filtered values. | * @returns {Array} Returns the new array of filtered values. | |||
* @example | * @example | |||
* | * | |||
* _.compact([0, 1, false, 2, '', 3]); | * _.compact([0, 1, false, 2, '', 3]); | |||
* // => [1, 2, 3] | * // => [1, 2, 3] | |||
*/ | */ | |||
function compact(array) { | function compact(array) { | |||
return baseFilter(array, Boolean); | return baseFilter(array, Boolean); | |||
} | } | |||
/** | /** | |||
* Creates a new array concatenating `array` with any additional arrays | * Creates a new array concatenating `array` with any additional arrays | |||
* and/or values. | * and/or values. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 4.0.0 | ||||
* @category Array | * @category Array | |||
* @param {Array} array The array to concatenate. | * @param {Array} array The array to concatenate. | |||
* @param {...*} [values] The values to concatenate. | * @param {...*} [values] The values to concatenate. | |||
* @returns {Array} Returns the new concatenated array. | * @returns {Array} Returns the new concatenated array. | |||
* @example | * @example | |||
* | * | |||
* var array = [1]; | * var array = [1]; | |||
* var other = _.concat(array, 2, [3], [[4]]); | * var other = _.concat(array, 2, [3], [[4]]); | |||
* | * | |||
* console.log(other); | * console.log(other); | |||
* // => [1, 2, 3, [4]] | * // => [1, 2, 3, [4]] | |||
* | * | |||
* console.log(array); | * console.log(array); | |||
* // => [1] | * // => [1] | |||
*/ | */ | |||
var concat = rest(function(array, values) { | function concat() { | |||
values = baseFlatten(values); | var length = arguments.length; | |||
return arrayConcat(isArray(array) ? array : [Object(array)], values); | if (!length) { | |||
}); | return []; | |||
} | ||||
var args = Array(length - 1), | ||||
array = arguments[0], | ||||
index = length; | ||||
while (index--) { | ||||
args[index - 1] = arguments[index]; | ||||
} | ||||
return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(ar | ||||
gs, 1)); | ||||
} | ||||
/** | ||||
* This method is like `_.find` except that it returns the index of the first | ||||
* element `predicate` returns truthy for instead of the element itself. | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @since 1.1.0 | ||||
* @category Array | ||||
* @param {Array} array The array to inspect. | ||||
* @param {Function} [predicate=_.identity] The function invoked per iteration | ||||
. | ||||
* @param {number} [fromIndex=0] The index to search from. | ||||
* @returns {number} Returns the index of the found element, else `-1`. | ||||
* @example | ||||
* | ||||
* var users = [ | ||||
* { 'user': 'barney', 'active': false }, | ||||
* { 'user': 'fred', 'active': false }, | ||||
* { 'user': 'pebbles', 'active': true } | ||||
* ]; | ||||
* | ||||
* _.findIndex(users, function(o) { return o.user == 'barney'; }); | ||||
* // => 0 | ||||
* | ||||
* // The `_.matches` iteratee shorthand. | ||||
* _.findIndex(users, { 'user': 'fred', 'active': false }); | ||||
* // => 1 | ||||
* | ||||
* // The `_.matchesProperty` iteratee shorthand. | ||||
* _.findIndex(users, ['active', false]); | ||||
* // => 0 | ||||
* | ||||
* // The `_.property` iteratee shorthand. | ||||
* _.findIndex(users, 'active'); | ||||
* // => 2 | ||||
*/ | ||||
function findIndex(array, predicate, fromIndex) { | ||||
var length = array == null ? 0 : array.length; | ||||
if (!length) { | ||||
return -1; | ||||
} | ||||
var index = fromIndex == null ? 0 : toInteger(fromIndex); | ||||
if (index < 0) { | ||||
index = nativeMax(length + index, 0); | ||||
} | ||||
return baseFindIndex(array, baseIteratee(predicate, 3), index); | ||||
} | ||||
/** | /** | |||
* Flattens `array` a single level. | * Flattens `array` a single level deep. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Array | * @category Array | |||
* @param {Array} array The array to flatten. | * @param {Array} array The array to flatten. | |||
* @returns {Array} Returns the new flattened array. | * @returns {Array} Returns the new flattened array. | |||
* @example | * @example | |||
* | * | |||
* _.flatten([1, [2, 3, [4]]]); | * _.flatten([1, [2, [3, [4]], 5]]); | |||
* // => [1, 2, 3, [4]] | * // => [1, 2, [3, [4]], 5] | |||
*/ | */ | |||
function flatten(array) { | function flatten(array) { | |||
var length = array ? array.length : 0; | var length = array == null ? 0 : array.length; | |||
return length ? baseFlatten(array) : []; | return length ? baseFlatten(array, 1) : []; | |||
} | } | |||
/** | /** | |||
* This method is like `_.flatten` except that it recursively flattens `array` . | * Recursively flattens `array`. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 3.0.0 | ||||
* @category Array | * @category Array | |||
* @param {Array} array The array to recursively flatten. | * @param {Array} array The array to flatten. | |||
* @returns {Array} Returns the new flattened array. | * @returns {Array} Returns the new flattened array. | |||
* @example | * @example | |||
* | * | |||
* _.flattenDeep([1, [2, 3, [4]]]); | * _.flattenDeep([1, [2, [3, [4]], 5]]); | |||
* // => [1, 2, 3, 4] | * // => [1, 2, 3, 4, 5] | |||
*/ | */ | |||
function flattenDeep(array) { | function flattenDeep(array) { | |||
var length = array ? array.length : 0; | var length = array == null ? 0 : array.length; | |||
return length ? baseFlatten(array, true) : []; | return length ? baseFlatten(array, INFINITY) : []; | |||
} | } | |||
/** | /** | |||
* Gets the first element of `array`. | * Gets the first element of `array`. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @alias first | * @alias first | |||
* @category Array | * @category Array | |||
* @param {Array} array The array to query. | * @param {Array} array The array to query. | |||
* @returns {*} Returns the first element of `array`. | * @returns {*} Returns the first element of `array`. | |||
* @example | * @example | |||
* | * | |||
* _.head([1, 2, 3]); | * _.head([1, 2, 3]); | |||
* // => 1 | * // => 1 | |||
* | * | |||
* _.head([]); | * _.head([]); | |||
* // => undefined | * // => undefined | |||
*/ | */ | |||
function head(array) { | function head(array) { | |||
return array ? array[0] : undefined; | return (array && array.length) ? array[0] : undefined; | |||
} | } | |||
/** | /** | |||
* Gets the index at which the first occurrence of `value` is found in `array` | * Gets the index at which the first occurrence of `value` is found in `array` | |||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-sam | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-sam | |||
evaluezero) | evaluezero) | |||
* for equality comparisons. If `fromIndex` is negative, it's used as the offs | * for equality comparisons. If `fromIndex` is negative, it's used as the | |||
et | * offset from the end of `array`. | |||
* from the end of `array`. If `array` is sorted providing `true` for `fromInd | ||||
ex` | ||||
* performs a faster binary search. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Array | * @category Array | |||
* @param {Array} array The array to search. | * @param {Array} array The array to inspect. | |||
* @param {*} value The value to search for. | * @param {*} value The value to search for. | |||
* @param {number} [fromIndex=0] The index to search from. | * @param {number} [fromIndex=0] The index to search from. | |||
* @returns {number} Returns the index of the matched value, else `-1`. | * @returns {number} Returns the index of the matched value, else `-1`. | |||
* @example | * @example | |||
* | * | |||
* _.indexOf([1, 2, 1, 2], 2); | * _.indexOf([1, 2, 1, 2], 2); | |||
* // => 1 | * // => 1 | |||
* | * | |||
* // using `fromIndex` | * // Search from the `fromIndex`. | |||
* _.indexOf([1, 2, 1, 2], 2, 2); | * _.indexOf([1, 2, 1, 2], 2, 2); | |||
* // => 3 | * // => 3 | |||
*/ | */ | |||
function indexOf(array, value, fromIndex) { | function indexOf(array, value, fromIndex) { | |||
var length = array ? array.length : 0; | var length = array == null ? 0 : array.length; | |||
if (typeof fromIndex == 'number') { | if (typeof fromIndex == 'number') { | |||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex; | fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex; | |||
} else { | } else { | |||
fromIndex = 0; | fromIndex = 0; | |||
} | } | |||
var index = (fromIndex || 0) - 1, | var index = (fromIndex || 0) - 1, | |||
isReflexive = value === value; | isReflexive = value === value; | |||
while (++index < length) { | while (++index < length) { | |||
var other = array[index]; | var other = array[index]; | |||
skipping to change at line 1558 | skipping to change at line 1688 | |||
} | } | |||
} | } | |||
return -1; | return -1; | |||
} | } | |||
/** | /** | |||
* Gets the last element of `array`. | * Gets the last element of `array`. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Array | * @category Array | |||
* @param {Array} array The array to query. | * @param {Array} array The array to query. | |||
* @returns {*} Returns the last element of `array`. | * @returns {*} Returns the last element of `array`. | |||
* @example | * @example | |||
* | * | |||
* _.last([1, 2, 3]); | * _.last([1, 2, 3]); | |||
* // => 3 | * // => 3 | |||
*/ | */ | |||
function last(array) { | function last(array) { | |||
var length = array ? array.length : 0; | var length = array == null ? 0 : array.length; | |||
return length ? array[length - 1] : undefined; | return length ? array[length - 1] : undefined; | |||
} | } | |||
/** | /** | |||
* Creates a slice of `array` from `start` up to, but not including, `end`. | * Creates a slice of `array` from `start` up to, but not including, `end`. | |||
* | * | |||
* **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Arr | * **Note:** This method is used instead of | |||
ay/slice) | * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are | |||
* to ensure dense arrays are returned. | * returned. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 3.0.0 | ||||
* @category Array | * @category Array | |||
* @param {Array} array The array to slice. | * @param {Array} array The array to slice. | |||
* @param {number} [start=0] The start position. | * @param {number} [start=0] The start position. | |||
* @param {number} [end=array.length] The end position. | * @param {number} [end=array.length] The end position. | |||
* @returns {Array} Returns the slice of `array`. | * @returns {Array} Returns the slice of `array`. | |||
*/ | */ | |||
function slice(array, start, end) { | function slice(array, start, end) { | |||
var length = array ? array.length : 0; | var length = array == null ? 0 : array.length; | |||
start = start == null ? 0 : +start; | ||||
end = end === undefined ? length : +end; | ||||
return length ? baseSlice(array, start, end) : []; | return length ? baseSlice(array, start, end) : []; | |||
} | } | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Creates a `lodash` object that wraps `value` with explicit method chaining | * Creates a `lodash` wrapper instance that wraps `value` with explicit method | |||
enabled. | * chain sequences enabled. The result of such sequences must be unwrapped | |||
* The result of such method chaining must be unwrapped with `_#value`. | * with `_#value`. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 1.3.0 | ||||
* @category Seq | * @category Seq | |||
* @param {*} value The value to wrap. | * @param {*} value The value to wrap. | |||
* @returns {Object} Returns the new `lodash` wrapper instance. | * @returns {Object} Returns the new `lodash` wrapper instance. | |||
* @example | * @example | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'barney', 'age': 36 }, | * { 'user': 'barney', 'age': 36 }, | |||
* { 'user': 'fred', 'age': 40 }, | * { 'user': 'fred', 'age': 40 }, | |||
* { 'user': 'pebbles', 'age': 1 } | * { 'user': 'pebbles', 'age': 1 } | |||
* ]; | * ]; | |||
skipping to change at line 1626 | skipping to change at line 1763 | |||
* .value(); | * .value(); | |||
* // => 'pebbles is 1' | * // => 'pebbles is 1' | |||
*/ | */ | |||
function chain(value) { | function chain(value) { | |||
var result = lodash(value); | var result = lodash(value); | |||
result.__chain__ = true; | result.__chain__ = true; | |||
return result; | return result; | |||
} | } | |||
/** | /** | |||
* This method invokes `interceptor` and returns `value`. The interceptor is | * This method invokes `interceptor` and returns `value`. The interceptor | |||
* invoked with one argument; (value). The purpose of this method is to "tap i | * is invoked with one argument; (value). The purpose of this method is to | |||
nto" | * "tap into" a method chain sequence in order to modify intermediate results. | |||
* a method chain in order to perform operations on intermediate results withi | ||||
n | ||||
* the chain. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Seq | * @category Seq | |||
* @param {*} value The value to provide to `interceptor`. | * @param {*} value The value to provide to `interceptor`. | |||
* @param {Function} interceptor The function to invoke. | * @param {Function} interceptor The function to invoke. | |||
* @returns {*} Returns `value`. | * @returns {*} Returns `value`. | |||
* @example | * @example | |||
* | * | |||
* _([1, 2, 3]) | * _([1, 2, 3]) | |||
* .tap(function(array) { | * .tap(function(array) { | |||
* // Mutate input array. | ||||
* array.pop(); | * array.pop(); | |||
* }) | * }) | |||
* .reverse() | * .reverse() | |||
* .value(); | * .value(); | |||
* // => [2, 1] | * // => [2, 1] | |||
*/ | */ | |||
function tap(value, interceptor) { | function tap(value, interceptor) { | |||
interceptor(value); | interceptor(value); | |||
return value; | return value; | |||
} | } | |||
/** | /** | |||
* This method is like `_.tap` except that it returns the result of `intercept or`. | * This method is like `_.tap` except that it returns the result of `intercept or`. | |||
* The purpose of this method is to "pass thru" values replacing intermediate | ||||
* results in a method chain sequence. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 3.0.0 | ||||
* @category Seq | * @category Seq | |||
* @param {*} value The value to provide to `interceptor`. | * @param {*} value The value to provide to `interceptor`. | |||
* @param {Function} interceptor The function to invoke. | * @param {Function} interceptor The function to invoke. | |||
* @returns {*} Returns the result of `interceptor`. | * @returns {*} Returns the result of `interceptor`. | |||
* @example | * @example | |||
* | * | |||
* _(' abc ') | * _(' abc ') | |||
* .chain() | * .chain() | |||
* .trim() | * .trim() | |||
* .thru(function(value) { | * .thru(function(value) { | |||
* return [value]; | * return [value]; | |||
* }) | * }) | |||
* .value(); | * .value(); | |||
* // => ['abc'] | * // => ['abc'] | |||
*/ | */ | |||
function thru(value, interceptor) { | function thru(value, interceptor) { | |||
return interceptor(value); | return interceptor(value); | |||
} | } | |||
/** | /** | |||
* Enables explicit method chaining on the wrapper object. | * Creates a `lodash` wrapper instance with explicit method chain sequences en abled. | |||
* | * | |||
* @name chain | * @name chain | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Seq | * @category Seq | |||
* @returns {Object} Returns the new `lodash` wrapper instance. | * @returns {Object} Returns the new `lodash` wrapper instance. | |||
* @example | * @example | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'barney', 'age': 36 }, | * { 'user': 'barney', 'age': 36 }, | |||
* { 'user': 'fred', 'age': 40 } | * { 'user': 'fred', 'age': 40 } | |||
* ]; | * ]; | |||
* | * | |||
* // without explicit chaining | * // A sequence without explicit chaining. | |||
* _(users).head(); | * _(users).head(); | |||
* // => { 'user': 'barney', 'age': 36 } | * // => { 'user': 'barney', 'age': 36 } | |||
* | * | |||
* // with explicit chaining | * // A sequence with explicit chaining. | |||
* _(users) | * _(users) | |||
* .chain() | * .chain() | |||
* .head() | * .head() | |||
* .pick('user') | * .pick('user') | |||
* .value(); | * .value(); | |||
* // => { 'user': 'barney' } | * // => { 'user': 'barney' } | |||
*/ | */ | |||
function wrapperChain() { | function wrapperChain() { | |||
return chain(this); | return chain(this); | |||
} | } | |||
/** | /** | |||
* Executes the chained sequence to extract the unwrapped value. | * Executes the chain sequence to resolve the unwrapped value. | |||
* | * | |||
* @name value | * @name value | |||
* @memberOf _ | * @memberOf _ | |||
* @alias run, toJSON, valueOf | * @since 0.1.0 | |||
* @alias toJSON, valueOf | ||||
* @category Seq | * @category Seq | |||
* @returns {*} Returns the resolved unwrapped value. | * @returns {*} Returns the resolved unwrapped value. | |||
* @example | * @example | |||
* | * | |||
* _([1, 2, 3]).value(); | * _([1, 2, 3]).value(); | |||
* // => [1, 2, 3] | * // => [1, 2, 3] | |||
*/ | */ | |||
function wrapperValue() { | function wrapperValue() { | |||
return baseWrapperValue(this.__wrapped__, this.__actions__); | return baseWrapperValue(this.__wrapped__, this.__actions__); | |||
} | } | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Checks if `predicate` returns truthy for **all** elements of `collection`. | * Checks if `predicate` returns truthy for **all** elements of `collection`. | |||
* Iteration is stopped once `predicate` returns falsey. The predicate is | * Iteration is stopped once `predicate` returns falsey. The predicate is | |||
* invoked with three arguments: (value, index|key, collection). | * invoked with three arguments: (value, index|key, collection). | |||
* | * | |||
* **Note:** This method returns `true` for | ||||
* [empty collections](https://en.wikipedia.org/wiki/Empty_set) because | ||||
* [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of | ||||
* elements of empty collections. | ||||
* | ||||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function|Object|string} [predicate=_.identity] The function invoked | * @param {Function} [predicate=_.identity] The function invoked per iteration | |||
per iteration. | . | |||
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.m | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map | |||
ap`. | `. | |||
* @returns {boolean} Returns `true` if all elements pass the predicate check, | * @returns {boolean} Returns `true` if all elements pass the predicate check, | |||
else `false`. | * else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.every([true, 1, null, 'yes'], Boolean); | * _.every([true, 1, null, 'yes'], Boolean); | |||
* // => false | * // => false | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'barney', 'active': false }, | * { 'user': 'barney', 'age': 36, 'active': false }, | |||
* { 'user': 'fred', 'active': false } | * { 'user': 'fred', 'age': 40, 'active': false } | |||
* ]; | * ]; | |||
* | * | |||
* // using the `_.matches` iteratee shorthand | * // The `_.matches` iteratee shorthand. | |||
* _.every(users, { 'user': 'barney', 'active': false }); | * _.every(users, { 'user': 'barney', 'active': false }); | |||
* // => false | * // => false | |||
* | * | |||
* // using the `_.matchesProperty` iteratee shorthand | * // The `_.matchesProperty` iteratee shorthand. | |||
* _.every(users, ['active', false]); | * _.every(users, ['active', false]); | |||
* // => true | * // => true | |||
* | * | |||
* // using the `_.property` iteratee shorthand | * // The `_.property` iteratee shorthand. | |||
* _.every(users, 'active'); | * _.every(users, 'active'); | |||
* // => false | * // => false | |||
*/ | */ | |||
function every(collection, predicate, guard) { | function every(collection, predicate, guard) { | |||
predicate = guard ? undefined : predicate; | predicate = guard ? undefined : predicate; | |||
return baseEvery(collection, baseIteratee(predicate)); | return baseEvery(collection, baseIteratee(predicate)); | |||
} | } | |||
/** | /** | |||
* Iterates over elements of `collection`, returning an array of all elements | * Iterates over elements of `collection`, returning an array of all elements | |||
* `predicate` returns truthy for. The predicate is invoked with three argumen | * `predicate` returns truthy for. The predicate is invoked with three | |||
ts: | * arguments: (value, index|key, collection). | |||
* (value, index|key, collection). | * | |||
* **Note:** Unlike `_.remove`, this method returns a new array. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration. | * @param {Function} [predicate=_.identity] The function invoked per iteration . | |||
* @returns {Array} Returns the new filtered array. | * @returns {Array} Returns the new filtered array. | |||
* @see _.reject | ||||
* @example | * @example | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'barney', 'age': 36, 'active': true }, | * { 'user': 'barney', 'age': 36, 'active': true }, | |||
* { 'user': 'fred', 'age': 40, 'active': false } | * { 'user': 'fred', 'age': 40, 'active': false } | |||
* ]; | * ]; | |||
* | * | |||
* _.filter(users, function(o) { return !o.active; }); | * _.filter(users, function(o) { return !o.active; }); | |||
* // => objects for ['fred'] | * // => objects for ['fred'] | |||
* | * | |||
* // using the `_.matches` iteratee shorthand | * // The `_.matches` iteratee shorthand. | |||
* _.filter(users, { 'age': 36, 'active': true }); | * _.filter(users, { 'age': 36, 'active': true }); | |||
* // => objects for ['barney'] | * // => objects for ['barney'] | |||
* | * | |||
* // using the `_.matchesProperty` iteratee shorthand | * // The `_.matchesProperty` iteratee shorthand. | |||
* _.filter(users, ['active', false]); | * _.filter(users, ['active', false]); | |||
* // => objects for ['fred'] | * // => objects for ['fred'] | |||
* | * | |||
* // using the `_.property` iteratee shorthand | * // The `_.property` iteratee shorthand. | |||
* _.filter(users, 'active'); | * _.filter(users, 'active'); | |||
* // => objects for ['barney'] | * // => objects for ['barney'] | |||
* | ||||
* // Combining several predicates using `_.overEvery` or `_.overSome`. | ||||
* _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]])); | ||||
* // => objects for ['fred', 'barney'] | ||||
*/ | */ | |||
function filter(collection, predicate) { | function filter(collection, predicate) { | |||
return baseFilter(collection, baseIteratee(predicate)); | return baseFilter(collection, baseIteratee(predicate)); | |||
} | } | |||
/** | /** | |||
* Iterates over elements of `collection`, returning the first element | * Iterates over elements of `collection`, returning the first element | |||
* `predicate` returns truthy for. The predicate is invoked with three argumen | * `predicate` returns truthy for. The predicate is invoked with three | |||
ts: | * arguments: (value, index|key, collection). | |||
* (value, index|key, collection). | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to search. | * @param {Array|Object} collection The collection to inspect. | |||
* @param {Function|Object|string} [predicate=_.identity] The function invoked | * @param {Function} [predicate=_.identity] The function invoked per iteration | |||
per iteration. | . | |||
* @param {number} [fromIndex=0] The index to search from. | ||||
* @returns {*} Returns the matched element, else `undefined`. | * @returns {*} Returns the matched element, else `undefined`. | |||
* @example | * @example | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'barney', 'age': 36, 'active': true }, | * { 'user': 'barney', 'age': 36, 'active': true }, | |||
* { 'user': 'fred', 'age': 40, 'active': false }, | * { 'user': 'fred', 'age': 40, 'active': false }, | |||
* { 'user': 'pebbles', 'age': 1, 'active': true } | * { 'user': 'pebbles', 'age': 1, 'active': true } | |||
* ]; | * ]; | |||
* | * | |||
* _.find(users, function(o) { return o.age < 40; }); | * _.find(users, function(o) { return o.age < 40; }); | |||
* // => object for 'barney' | * // => object for 'barney' | |||
* | * | |||
* // using the `_.matches` iteratee shorthand | * // The `_.matches` iteratee shorthand. | |||
* _.find(users, { 'age': 1, 'active': true }); | * _.find(users, { 'age': 1, 'active': true }); | |||
* // => object for 'pebbles' | * // => object for 'pebbles' | |||
* | * | |||
* // using the `_.matchesProperty` iteratee shorthand | * // The `_.matchesProperty` iteratee shorthand. | |||
* _.find(users, ['active', false]); | * _.find(users, ['active', false]); | |||
* // => object for 'fred' | * // => object for 'fred' | |||
* | * | |||
* // using the `_.property` iteratee shorthand | * // The `_.property` iteratee shorthand. | |||
* _.find(users, 'active'); | * _.find(users, 'active'); | |||
* // => object for 'barney' | * // => object for 'barney' | |||
*/ | */ | |||
function find(collection, predicate) { | var find = createFind(findIndex); | |||
return baseFind(collection, baseIteratee(predicate), baseEach); | ||||
} | ||||
/** | /** | |||
* Iterates over elements of `collection` invoking `iteratee` for each element . | * Iterates over elements of `collection` and invokes `iteratee` for each elem ent. | |||
* The iteratee is invoked with three arguments: (value, index|key, collection ). | * The iteratee is invoked with three arguments: (value, index|key, collection ). | |||
* Iteratee functions may exit iteration early by explicitly returning `false` . | * Iteratee functions may exit iteration early by explicitly returning `false` . | |||
* | * | |||
* **Note:** As with other "Collections" methods, objects with a "length" prop | * **Note:** As with other "Collections" methods, objects with a "length" | |||
erty | * property are iterated like arrays. To avoid this behavior use `_.forIn` | |||
* are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn | * or `_.forOwn` for object iteration. | |||
` | ||||
* for object iteration. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @alias each | * @alias each | |||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function} [iteratee=_.identity] The function invoked per iteration. | * @param {Function} [iteratee=_.identity] The function invoked per iteration. | |||
* @returns {Array|Object} Returns `collection`. | * @returns {Array|Object} Returns `collection`. | |||
* @see _.forEachRight | ||||
* @example | * @example | |||
* | * | |||
* _([1, 2]).forEach(function(value) { | * _.forEach([1, 2], function(value) { | |||
* console.log(value); | * console.log(value); | |||
* }); | * }); | |||
* // => logs `1` then `2` | * // => Logs `1` then `2`. | |||
* | * | |||
* _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { | * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { | |||
* console.log(key); | * console.log(key); | |||
* }); | * }); | |||
* // => logs 'a' then 'b' (iteration order is not guaranteed) | * // => Logs 'a' then 'b' (iteration order is not guaranteed). | |||
*/ | */ | |||
function forEach(collection, iteratee) { | function forEach(collection, iteratee) { | |||
return baseEach(collection, toFunction(iteratee)); | return baseEach(collection, baseIteratee(iteratee)); | |||
} | } | |||
/** | /** | |||
* Invokes the method at `path` of each element in `collection`, returning | * Creates an array of values by running each element in `collection` thru | |||
* an array of the results of each invoked method. Any additional arguments | ||||
* are provided to each invoked method. If `methodName` is a function it's | ||||
* invoked for, and `this` bound to, each element in `collection`. | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @category Collection | ||||
* @param {Array|Object} collection The collection to iterate over. | ||||
* @param {Array|Function|string} path The path of the method to invoke or | ||||
* the function invoked per iteration. | ||||
* @param {...*} [args] The arguments to invoke each method with. | ||||
* @returns {Array} Returns the array of results. | ||||
* @example | ||||
* | ||||
* _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); | ||||
* // => [[1, 5, 7], [1, 2, 3]] | ||||
* | ||||
* _.invokeMap([123, 456], String.prototype.split, ''); | ||||
* // => [['1', '2', '3'], ['4', '5', '6']] | ||||
*/ | ||||
var invokeMap = rest(function(collection, path, args) { | ||||
var isFunc = typeof path == 'function'; | ||||
return baseMap(collection, function(value) { | ||||
var func = isFunc ? path : value[path]; | ||||
return func == null ? func : func.apply(value, args); | ||||
}); | ||||
}); | ||||
/** | ||||
* Creates an array of values by running each element in `collection` through | ||||
* `iteratee`. The iteratee is invoked with three arguments: | * `iteratee`. The iteratee is invoked with three arguments: | |||
* (value, index|key, collection). | * (value, index|key, collection). | |||
* | * | |||
* Many lodash methods are guarded to work as iteratees for methods like | * Many lodash methods are guarded to work as iteratees for methods like | |||
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. | * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. | |||
* | * | |||
* The guarded methods are: | * The guarded methods are: | |||
* `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`, | * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, | |||
* `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`, | * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, | |||
* `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`, | * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`, | |||
* and `words` | * `template`, `trim`, `trimEnd`, `trimStart`, and `words` | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration. | * @param {Function} [iteratee=_.identity] The function invoked per iteration. | |||
* @returns {Array} Returns the new mapped array. | * @returns {Array} Returns the new mapped array. | |||
* @example | * @example | |||
* | * | |||
* function square(n) { | * function square(n) { | |||
* return n * n; | * return n * n; | |||
* } | * } | |||
* | * | |||
* _.map([1, 2], square); | * _.map([4, 8], square); | |||
* // => [3, 6] | * // => [16, 64] | |||
* | * | |||
* _.map({ 'a': 1, 'b': 2 }, square); | * _.map({ 'a': 4, 'b': 8 }, square); | |||
* // => [3, 6] (iteration order is not guaranteed) | * // => [16, 64] (iteration order is not guaranteed) | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'barney' }, | * { 'user': 'barney' }, | |||
* { 'user': 'fred' } | * { 'user': 'fred' } | |||
* ]; | * ]; | |||
* | * | |||
* // using the `_.property` iteratee shorthand | * // The `_.property` iteratee shorthand. | |||
* _.map(users, 'user'); | * _.map(users, 'user'); | |||
* // => ['barney', 'fred'] | * // => ['barney', 'fred'] | |||
*/ | */ | |||
function map(collection, iteratee) { | function map(collection, iteratee) { | |||
return baseMap(collection, baseIteratee(iteratee)); | return baseMap(collection, baseIteratee(iteratee)); | |||
} | } | |||
/** | /** | |||
* Reduces `collection` to a value which is the accumulated result of running | * Reduces `collection` to a value which is the accumulated result of running | |||
* each element in `collection` through `iteratee`, where each successive | * each element in `collection` thru `iteratee`, where each successive | |||
* invocation is supplied the return value of the previous. If `accumulator` | * invocation is supplied the return value of the previous. If `accumulator` | |||
* is not provided the first element of `collection` is used as the initial | * is not given, the first element of `collection` is used as the initial | |||
* value. The iteratee is invoked with four arguments: | * value. The iteratee is invoked with four arguments: | |||
* (accumulator, value, index|key, collection). | * (accumulator, value, index|key, collection). | |||
* | * | |||
* Many lodash methods are guarded to work as iteratees for methods like | * Many lodash methods are guarded to work as iteratees for methods like | |||
* `_.reduce`, `_.reduceRight`, and `_.transform`. | * `_.reduce`, `_.reduceRight`, and `_.transform`. | |||
* | * | |||
* The guarded methods are: | * The guarded methods are: | |||
* `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, | * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, | |||
* and `sortBy` | * and `sortBy` | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function} [iteratee=_.identity] The function invoked per iteration. | * @param {Function} [iteratee=_.identity] The function invoked per iteration. | |||
* @param {*} [accumulator] The initial value. | * @param {*} [accumulator] The initial value. | |||
* @returns {*} Returns the accumulated value. | * @returns {*} Returns the accumulated value. | |||
* @see _.reduceRight | ||||
* @example | * @example | |||
* | * | |||
* _.reduce([1, 2], function(sum, n) { | * _.reduce([1, 2], function(sum, n) { | |||
* return sum + n; | * return sum + n; | |||
* }); | * }, 0); | |||
* // => 3 | * // => 3 | |||
* | * | |||
* _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { | * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { | |||
* (result[value] || (result[value] = [])).push(key); | * (result[value] || (result[value] = [])).push(key); | |||
* return result; | * return result; | |||
* }, {}); | * }, {}); | |||
* // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) | * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) | |||
*/ | */ | |||
function reduce(collection, iteratee, accumulator) { | function reduce(collection, iteratee, accumulator) { | |||
return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments .length < 3, baseEach); | return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments .length < 3, baseEach); | |||
} | } | |||
/** | /** | |||
* Gets the size of `collection` by returning its length for array-like | * Gets the size of `collection` by returning its length for array-like | |||
* values or the number of own enumerable properties for objects. | * values or the number of own enumerable string keyed properties for objects. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to inspect. | * @param {Array|Object|string} collection The collection to inspect. | |||
* @returns {number} Returns the collection size. | * @returns {number} Returns the collection size. | |||
* @example | * @example | |||
* | * | |||
* _.size([1, 2, 3]); | * _.size([1, 2, 3]); | |||
* // => 3 | * // => 3 | |||
* | * | |||
* _.size({ 'a': 1, 'b': 2 }); | * _.size({ 'a': 1, 'b': 2 }); | |||
* // => 2 | * // => 2 | |||
* | * | |||
* _.size('pebbles'); | * _.size('pebbles'); | |||
* // => 7 | * // => 7 | |||
*/ | */ | |||
function size(collection) { | function size(collection) { | |||
if (collection == null) { | if (collection == null) { | |||
return 0; | return 0; | |||
} | } | |||
collection = isArrayLike(collection) ? collection : keys(collection); | collection = isArrayLike(collection) ? collection : nativeKeys(collection); | |||
return collection.length; | return collection.length; | |||
} | } | |||
/** | /** | |||
* Checks if `predicate` returns truthy for **any** element of `collection`. | * Checks if `predicate` returns truthy for **any** element of `collection`. | |||
* Iteration is stopped once `predicate` returns truthy. The predicate is | * Iteration is stopped once `predicate` returns truthy. The predicate is | |||
* invoked with three arguments: (value, index|key, collection). | * invoked with three arguments: (value, index|key, collection). | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {Function|Object|string} [predicate=_.identity] The function invoked | * @param {Function} [predicate=_.identity] The function invoked per iteration | |||
per iteration. | . | |||
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.m | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map | |||
ap`. | `. | |||
* @returns {boolean} Returns `true` if any element passes the predicate check | * @returns {boolean} Returns `true` if any element passes the predicate check | |||
, else `false`. | , | |||
* else `false`. | ||||
* @example | * @example | |||
* | * | |||
* _.some([null, 0, 'yes', false], Boolean); | * _.some([null, 0, 'yes', false], Boolean); | |||
* // => true | * // => true | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'barney', 'active': true }, | * { 'user': 'barney', 'active': true }, | |||
* { 'user': 'fred', 'active': false } | * { 'user': 'fred', 'active': false } | |||
* ]; | * ]; | |||
* | * | |||
* // using the `_.matches` iteratee shorthand | * // The `_.matches` iteratee shorthand. | |||
* _.some(users, { 'user': 'barney', 'active': false }); | * _.some(users, { 'user': 'barney', 'active': false }); | |||
* // => false | * // => false | |||
* | * | |||
* // using the `_.matchesProperty` iteratee shorthand | * // The `_.matchesProperty` iteratee shorthand. | |||
* _.some(users, ['active', false]); | * _.some(users, ['active', false]); | |||
* // => true | * // => true | |||
* | * | |||
* // using the `_.property` iteratee shorthand | * // The `_.property` iteratee shorthand. | |||
* _.some(users, 'active'); | * _.some(users, 'active'); | |||
* // => true | * // => true | |||
*/ | */ | |||
function some(collection, predicate, guard) { | function some(collection, predicate, guard) { | |||
predicate = guard ? undefined : predicate; | predicate = guard ? undefined : predicate; | |||
return baseSome(collection, baseIteratee(predicate)); | return baseSome(collection, baseIteratee(predicate)); | |||
} | } | |||
/** | /** | |||
* Creates an array of elements, sorted in ascending order by the results of | * Creates an array of elements, sorted in ascending order by the results of | |||
* running each element in a collection through each iteratee. This method | * running each element in a collection thru each iteratee. This method | |||
* performs a stable sort, that is, it preserves the original sort order of | * performs a stable sort, that is, it preserves the original sort order of | |||
* equal elements. The iteratees are invoked with one argument: (value). | * equal elements. The iteratees are invoked with one argument: (value). | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Collection | * @category Collection | |||
* @param {Array|Object} collection The collection to iterate over. | * @param {Array|Object} collection The collection to iterate over. | |||
* @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratee | * @param {...(Function|Function[])} [iteratees=[_.identity]] | |||
s=[_.identity]] | * The iteratees to sort by. | |||
* The iteratees to sort by, specified individually or in arrays. | ||||
* @returns {Array} Returns the new sorted array. | * @returns {Array} Returns the new sorted array. | |||
* @example | * @example | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'fred', 'age': 48 }, | * { 'user': 'fred', 'age': 48 }, | |||
* { 'user': 'barney', 'age': 36 }, | * { 'user': 'barney', 'age': 36 }, | |||
* { 'user': 'fred', 'age': 42 }, | * { 'user': 'fred', 'age': 30 }, | |||
* { 'user': 'barney', 'age': 34 } | * { 'user': 'barney', 'age': 34 } | |||
* ]; | * ]; | |||
* | * | |||
* _.sortBy(users, function(o) { return o.user; }); | * _.sortBy(users, [function(o) { return o.user; }]); | |||
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 4 | * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 3 | |||
2]] | 0]] | |||
* | * | |||
* _.sortBy(users, ['user', 'age']); | * _.sortBy(users, ['user', 'age']); | |||
* // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 4 | * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 4 | |||
8]] | 8]] | |||
* | ||||
* _.sortBy(users, 'user', function(o) { | ||||
* return Math.floor(o.age / 10); | ||||
* }); | ||||
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 4 | ||||
2]] | ||||
*/ | */ | |||
function sortBy(collection, iteratee) { | function sortBy(collection, iteratee) { | |||
var index = 0; | var index = 0; | |||
iteratee = baseIteratee(iteratee); | iteratee = baseIteratee(iteratee); | |||
return baseMap(baseMap(collection, function(value, key, collection) { | return baseMap(baseMap(collection, function(value, key, collection) { | |||
return { 'value': value, 'index': index++, 'criteria': iteratee(value, key , collection) }; | return { 'value': value, 'index': index++, 'criteria': iteratee(value, key , collection) }; | |||
}).sort(function(object, other) { | }).sort(function(object, other) { | |||
return compareAscending(object.criteria, other.criteria) || (object.index - other.index); | return compareAscending(object.criteria, other.criteria) || (object.index - other.index); | |||
}), baseProperty('value')); | }), baseProperty('value')); | |||
} | } | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Gets the timestamp of the number of milliseconds that have elapsed since | ||||
* the Unix epoch (1 January 1970 00:00:00 UTC). | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @type Function | ||||
* @category Date | ||||
* @returns {number} Returns the timestamp. | ||||
* @example | ||||
* | ||||
* _.defer(function(stamp) { | ||||
* console.log(_.now() - stamp); | ||||
* }, _.now()); | ||||
* // => logs the number of milliseconds it took for the deferred function to | ||||
be invoked | ||||
*/ | ||||
var now = Date.now; | ||||
/*------------------------------------------------------------------------*/ | ||||
/** | ||||
* Creates a function that invokes `func`, with the `this` binding and argumen ts | * Creates a function that invokes `func`, with the `this` binding and argumen ts | |||
* of the created function, while it's called less than `n` times. Subsequent | * of the created function, while it's called less than `n` times. Subsequent | |||
* calls to the created function return the result of the last `func` invocati on. | * calls to the created function return the result of the last `func` invocati on. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 3.0.0 | ||||
* @category Function | * @category Function | |||
* @param {number} n The number of calls at which `func` is no longer invoked. | * @param {number} n The number of calls at which `func` is no longer invoked. | |||
* @param {Function} func The function to restrict. | * @param {Function} func The function to restrict. | |||
* @returns {Function} Returns the new restricted function. | * @returns {Function} Returns the new restricted function. | |||
* @example | * @example | |||
* | * | |||
* jQuery(element).on('click', _.before(5, addContactToList)); | * jQuery(element).on('click', _.before(5, addContactToList)); | |||
* // => allows adding up to 4 contacts to the list | * // => Allows adding up to 4 contacts to the list. | |||
*/ | */ | |||
function before(n, func) { | function before(n, func) { | |||
var result; | var result; | |||
if (typeof func != 'function') { | if (typeof func != 'function') { | |||
throw new TypeError(FUNC_ERROR_TEXT); | throw new TypeError(FUNC_ERROR_TEXT); | |||
} | } | |||
n = toInteger(n); | n = toInteger(n); | |||
return function() { | return function() { | |||
if (--n > 0) { | if (--n > 0) { | |||
result = func.apply(this, arguments); | result = func.apply(this, arguments); | |||
} | } | |||
if (n <= 1) { | if (n <= 1) { | |||
func = undefined; | func = undefined; | |||
} | } | |||
return result; | return result; | |||
}; | }; | |||
} | } | |||
/** | /** | |||
* Creates a function that invokes `func` with the `this` binding of `thisArg` | * Creates a function that invokes `func` with the `this` binding of `thisArg` | |||
* and prepends any additional `_.bind` arguments to those provided to the | * and `partials` prepended to the arguments it receives. | |||
* bound function. | ||||
* | * | |||
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, | * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, | |||
* may be used as a placeholder for partially applied arguments. | * may be used as a placeholder for partially applied arguments. | |||
* | * | |||
* **Note:** Unlike native `Function#bind` this method doesn't set the "length " | * **Note:** Unlike native `Function#bind`, this method doesn't set the "lengt h" | |||
* property of bound functions. | * property of bound functions. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Function | * @category Function | |||
* @param {Function} func The function to bind. | * @param {Function} func The function to bind. | |||
* @param {*} thisArg The `this` binding of `func`. | * @param {*} thisArg The `this` binding of `func`. | |||
* @param {...*} [partials] The arguments to be partially applied. | * @param {...*} [partials] The arguments to be partially applied. | |||
* @returns {Function} Returns the new bound function. | * @returns {Function} Returns the new bound function. | |||
* @example | * @example | |||
* | * | |||
* var greet = function(greeting, punctuation) { | * function greet(greeting, punctuation) { | |||
* return greeting + ' ' + this.user + punctuation; | * return greeting + ' ' + this.user + punctuation; | |||
* }; | * } | |||
* | * | |||
* var object = { 'user': 'fred' }; | * var object = { 'user': 'fred' }; | |||
* | * | |||
* var bound = _.bind(greet, object, 'hi'); | * var bound = _.bind(greet, object, 'hi'); | |||
* bound('!'); | * bound('!'); | |||
* // => 'hi fred!' | * // => 'hi fred!' | |||
* | * | |||
* // using placeholders | * // Bound with placeholders. | |||
* var bound = _.bind(greet, object, _, '!'); | * var bound = _.bind(greet, object, _, '!'); | |||
* bound('hi'); | * bound('hi'); | |||
* // => 'hi fred!' | * // => 'hi fred!' | |||
*/ | */ | |||
var bind = rest(function(func, thisArg, partials) { | var bind = baseRest(function(func, thisArg, partials) { | |||
return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partial | return createPartial(func, WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG, thisArg, part | |||
s); | ials); | |||
}); | }); | |||
/** | /** | |||
* Defers invoking the `func` until the current call stack has cleared. Any | * Defers invoking the `func` until the current call stack has cleared. Any | |||
* additional arguments are provided to `func` when it's invoked. | * additional arguments are provided to `func` when it's invoked. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Function | * @category Function | |||
* @param {Function} func The function to defer. | * @param {Function} func The function to defer. | |||
* @param {...*} [args] The arguments to invoke `func` with. | * @param {...*} [args] The arguments to invoke `func` with. | |||
* @returns {number} Returns the timer id. | * @returns {number} Returns the timer id. | |||
* @example | * @example | |||
* | * | |||
* _.defer(function(text) { | * _.defer(function(text) { | |||
* console.log(text); | * console.log(text); | |||
* }, 'deferred'); | * }, 'deferred'); | |||
* // logs 'deferred' after one or more milliseconds | * // => Logs 'deferred' after one millisecond. | |||
*/ | */ | |||
var defer = rest(function(func, args) { | var defer = baseRest(function(func, args) { | |||
return baseDelay(func, 1, args); | return baseDelay(func, 1, args); | |||
}); | }); | |||
/** | /** | |||
* Invokes `func` after `wait` milliseconds. Any additional arguments are | * Invokes `func` after `wait` milliseconds. Any additional arguments are | |||
* provided to `func` when it's invoked. | * provided to `func` when it's invoked. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Function | * @category Function | |||
* @param {Function} func The function to delay. | * @param {Function} func The function to delay. | |||
* @param {number} wait The number of milliseconds to delay invocation. | * @param {number} wait The number of milliseconds to delay invocation. | |||
* @param {...*} [args] The arguments to invoke `func` with. | * @param {...*} [args] The arguments to invoke `func` with. | |||
* @returns {number} Returns the timer id. | * @returns {number} Returns the timer id. | |||
* @example | * @example | |||
* | * | |||
* _.delay(function(text) { | * _.delay(function(text) { | |||
* console.log(text); | * console.log(text); | |||
* }, 1000, 'later'); | * }, 1000, 'later'); | |||
* // => logs 'later' after one second | * // => Logs 'later' after one second. | |||
*/ | */ | |||
var delay = rest(function(func, wait, args) { | var delay = baseRest(function(func, wait, args) { | |||
return baseDelay(func, toNumber(wait) || 0, args); | return baseDelay(func, toNumber(wait) || 0, args); | |||
}); | }); | |||
/** | /** | |||
* Creates a function that negates the result of the predicate `func`. The | * Creates a function that negates the result of the predicate `func`. The | |||
* `func` predicate is invoked with the `this` binding and arguments of the | * `func` predicate is invoked with the `this` binding and arguments of the | |||
* created function. | * created function. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 3.0.0 | ||||
* @category Function | * @category Function | |||
* @param {Function} predicate The predicate to negate. | * @param {Function} predicate The predicate to negate. | |||
* @returns {Function} Returns the new function. | * @returns {Function} Returns the new negated function. | |||
* @example | * @example | |||
* | * | |||
* function isEven(n) { | * function isEven(n) { | |||
* return n % 2 == 0; | * return n % 2 == 0; | |||
* } | * } | |||
* | * | |||
* _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); | * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); | |||
* // => [1, 3, 5] | * // => [1, 3, 5] | |||
*/ | */ | |||
function negate(predicate) { | function negate(predicate) { | |||
if (typeof predicate != 'function') { | if (typeof predicate != 'function') { | |||
throw new TypeError(FUNC_ERROR_TEXT); | throw new TypeError(FUNC_ERROR_TEXT); | |||
} | } | |||
return function() { | return function() { | |||
return !predicate.apply(this, arguments); | var args = arguments; | |||
return !predicate.apply(this, args); | ||||
}; | }; | |||
} | } | |||
/** | /** | |||
* Creates a function that is restricted to invoking `func` once. Repeat calls | * Creates a function that is restricted to invoking `func` once. Repeat calls | |||
* to the function return the value of the first invocation. The `func` is | * to the function return the value of the first invocation. The `func` is | |||
* invoked with the `this` binding and arguments of the created function. | * invoked with the `this` binding and arguments of the created function. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Function | * @category Function | |||
* @param {Function} func The function to restrict. | * @param {Function} func The function to restrict. | |||
* @returns {Function} Returns the new restricted function. | * @returns {Function} Returns the new restricted function. | |||
* @example | * @example | |||
* | * | |||
* var initialize = _.once(createApplication); | * var initialize = _.once(createApplication); | |||
* initialize(); | * initialize(); | |||
* initialize(); | * initialize(); | |||
* // `initialize` invokes `createApplication` once | * // => `createApplication` is invoked once | |||
*/ | */ | |||
function once(func) { | function once(func) { | |||
return before(2, func); | return before(2, func); | |||
} | } | |||
/** | ||||
* Creates a function that invokes `func` with the `this` binding of the | ||||
* created function and arguments from `start` and beyond provided as an array | ||||
. | ||||
* | ||||
* **Note:** This method is based on the [rest parameter](https://mdn.io/rest_ | ||||
parameters). | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @category Function | ||||
* @param {Function} func The function to apply a rest parameter to. | ||||
* @param {number} [start=func.length-1] The start position of the rest parame | ||||
ter. | ||||
* @returns {Function} Returns the new function. | ||||
* @example | ||||
* | ||||
* var say = _.rest(function(what, names) { | ||||
* return what + ' ' + _.initial(names).join(', ') + | ||||
* (_.size(names) > 1 ? ', & ' : '') + _.last(names); | ||||
* }); | ||||
* | ||||
* say('hello', 'fred', 'barney', 'pebbles'); | ||||
* // => 'hello fred, barney, & pebbles' | ||||
*/ | ||||
function rest(func, start) { | ||||
if (typeof func != 'function') { | ||||
throw new TypeError(FUNC_ERROR_TEXT); | ||||
} | ||||
start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start) | ||||
, 0); | ||||
return function() { | ||||
var args = arguments, | ||||
index = -1, | ||||
length = nativeMax(args.length - start, 0), | ||||
array = Array(length); | ||||
while (++index < length) { | ||||
array[index] = args[start + index]; | ||||
} | ||||
var otherArgs = Array(start + 1); | ||||
index = -1; | ||||
while (++index < start) { | ||||
otherArgs[index] = args[index]; | ||||
} | ||||
otherArgs[start] = array; | ||||
return func.apply(this, otherArgs); | ||||
}; | ||||
} | ||||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Creates a shallow clone of `value`. | * Creates a shallow clone of `value`. | |||
* | * | |||
* **Note:** This method is loosely based on the | * **Note:** This method is loosely based on the | |||
* [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) | * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) | |||
* and supports cloning arrays, array buffers, booleans, date objects, maps, | * and supports cloning arrays, array buffers, booleans, date objects, maps, | |||
* numbers, `Object` objects, regexes, sets, strings, symbols, and typed | * numbers, `Object` objects, regexes, sets, strings, symbols, and typed | |||
* arrays. The own enumerable properties of `arguments` objects are cloned | * arrays. The own enumerable properties of `arguments` objects are cloned | |||
* as plain objects. An empty object is returned for uncloneable values such | * as plain objects. An empty object is returned for uncloneable values such | |||
* as error objects, functions, DOM nodes, and WeakMaps. | * as error objects, functions, DOM nodes, and WeakMaps. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to clone. | * @param {*} value The value to clone. | |||
* @returns {*} Returns the cloned value. | * @returns {*} Returns the cloned value. | |||
* @see _.cloneDeep | ||||
* @example | * @example | |||
* | * | |||
* var objects = [{ 'a': 1 }, { 'b': 2 }]; | * var objects = [{ 'a': 1 }, { 'b': 2 }]; | |||
* | * | |||
* var shallow = _.clone(objects); | * var shallow = _.clone(objects); | |||
* console.log(shallow[0] === objects[0]); | * console.log(shallow[0] === objects[0]); | |||
* // => true | * // => true | |||
*/ | */ | |||
function clone(value) { | function clone(value) { | |||
if (!isObject(value)) { | if (!isObject(value)) { | |||
return value; | return value; | |||
} | } | |||
return isArray(value) ? copyArray(value) : copyObject(value, keys(value)); | return isArray(value) ? copyArray(value) : copyObject(value, nativeKeys(valu e)); | |||
} | } | |||
/** | /** | |||
* Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#se | * Performs a | |||
c-samevaluezero) | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevalue | |||
zero) | ||||
* comparison between two values to determine if they are equivalent. | * comparison between two values to determine if they are equivalent. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 4.0.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to compare. | * @param {*} value The value to compare. | |||
* @param {*} other The other value to compare. | * @param {*} other The other value to compare. | |||
* @returns {boolean} Returns `true` if the values are equivalent, else `false `. | * @returns {boolean} Returns `true` if the values are equivalent, else `false `. | |||
* @example | * @example | |||
* | * | |||
* var object = { 'user': 'fred' }; | * var object = { 'a': 1 }; | |||
* var other = { 'user': 'fred' }; | * var other = { 'a': 1 }; | |||
* | * | |||
* _.eq(object, object); | * _.eq(object, object); | |||
* // => true | * // => true | |||
* | * | |||
* _.eq(object, other); | * _.eq(object, other); | |||
* // => false | * // => false | |||
* | * | |||
* _.eq('a', 'a'); | * _.eq('a', 'a'); | |||
* // => true | * // => true | |||
* | * | |||
skipping to change at line 2396 | skipping to change at line 2472 | |||
* // => false | * // => false | |||
* | * | |||
* _.eq(NaN, NaN); | * _.eq(NaN, NaN); | |||
* // => true | * // => true | |||
*/ | */ | |||
function eq(value, other) { | function eq(value, other) { | |||
return value === other || (value !== value && other !== other); | return value === other || (value !== value && other !== other); | |||
} | } | |||
/** | /** | |||
* Checks if `value` is greater than `other`. | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @category Lang | ||||
* @param {*} value The value to compare. | ||||
* @param {*} other The other value to compare. | ||||
* @returns {boolean} Returns `true` if `value` is greater than `other`, else | ||||
`false`. | ||||
* @example | ||||
* | ||||
* _.gt(3, 1); | ||||
* // => true | ||||
* | ||||
* _.gt(3, 3); | ||||
* // => false | ||||
* | ||||
* _.gt(1, 3); | ||||
* // => false | ||||
*/ | ||||
function gt(value, other) { | ||||
return value > other; | ||||
} | ||||
/** | ||||
* Checks if `value` is likely an `arguments` object. | * Checks if `value` is likely an `arguments` object. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is correctly classified, else | * @returns {boolean} Returns `true` if `value` is an `arguments` object, | |||
`false`. | * else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isArguments(function() { return arguments; }()); | * _.isArguments(function() { return arguments; }()); | |||
* // => true | * // => true | |||
* | * | |||
* _.isArguments([1, 2, 3]); | * _.isArguments([1, 2, 3]); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isArguments(value) { | var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIs | |||
// Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode | Arguments : function(value) { | |||
. | return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && | |||
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && | !propertyIsEnumerable.call(value, 'callee'); | |||
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) | }; | |||
== argsTag); | ||||
} | ||||
/** | /** | |||
* Checks if `value` is classified as an `Array` object. | * Checks if `value` is classified as an `Array` object. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @type Function | * @since 0.1.0 | |||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | * @returns {boolean} Returns `true` if `value` is an array, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isArray([1, 2, 3]); | * _.isArray([1, 2, 3]); | |||
* // => true | * // => true | |||
* | * | |||
* _.isArray(document.body.children); | * _.isArray(document.body.children); | |||
* // => false | * // => false | |||
* | * | |||
* _.isArray('abc'); | * _.isArray('abc'); | |||
* // => false | * // => false | |||
skipping to change at line 2473 | skipping to change at line 2526 | |||
*/ | */ | |||
var isArray = Array.isArray; | var isArray = Array.isArray; | |||
/** | /** | |||
* Checks if `value` is array-like. A value is considered array-like if it's | * Checks if `value` is array-like. A value is considered array-like if it's | |||
* not a function and has a `value.length` that's an integer greater than or | * not a function and has a `value.length` that's an integer greater than or | |||
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @type Function | * @since 4.0.0 | |||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. | * @returns {boolean} Returns `true` if `value` is array-like, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isArrayLike([1, 2, 3]); | * _.isArrayLike([1, 2, 3]); | |||
* // => true | * // => true | |||
* | * | |||
* _.isArrayLike(document.body.children); | * _.isArrayLike(document.body.children); | |||
* // => true | * // => true | |||
* | * | |||
* _.isArrayLike('abc'); | * _.isArrayLike('abc'); | |||
* // => true | * // => true | |||
* | * | |||
* _.isArrayLike(_.noop); | * _.isArrayLike(_.noop); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isArrayLike(value) { | function isArrayLike(value) { | |||
return value != null && | return value != null && isLength(value.length) && !isFunction(value); | |||
!(typeof value == 'function' && isFunction(value)) && isLength(getLength(v | ||||
alue)); | ||||
} | ||||
/** | ||||
* This method is like `_.isArrayLike` except that it also checks if `value` | ||||
* is an object. | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @type Function | ||||
* @category Lang | ||||
* @param {*} value The value to check. | ||||
* @returns {boolean} Returns `true` if `value` is an array-like object, else | ||||
`false`. | ||||
* @example | ||||
* | ||||
* _.isArrayLikeObject([1, 2, 3]); | ||||
* // => true | ||||
* | ||||
* _.isArrayLikeObject(document.body.children); | ||||
* // => true | ||||
* | ||||
* _.isArrayLikeObject('abc'); | ||||
* // => false | ||||
* | ||||
* _.isArrayLikeObject(_.noop); | ||||
* // => false | ||||
*/ | ||||
function isArrayLikeObject(value) { | ||||
return isObjectLike(value) && isArrayLike(value); | ||||
} | } | |||
/** | /** | |||
* Checks if `value` is classified as a boolean primitive or object. | * Checks if `value` is classified as a boolean primitive or object. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isBoolean(false); | * _.isBoolean(false); | |||
* // => true | * // => true | |||
* | * | |||
* _.isBoolean(null); | * _.isBoolean(null); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isBoolean(value) { | function isBoolean(value) { | |||
return value === true || value === false || | return value === true || value === false || | |||
(isObjectLike(value) && objectToString.call(value) == boolTag); | (isObjectLike(value) && baseGetTag(value) == boolTag); | |||
} | } | |||
/** | /** | |||
* Checks if `value` is classified as a `Date` object. | * Checks if `value` is classified as a `Date` object. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | * @returns {boolean} Returns `true` if `value` is a date object, else `false` . | |||
* @example | * @example | |||
* | * | |||
* _.isDate(new Date); | * _.isDate(new Date); | |||
* // => true | * // => true | |||
* | * | |||
* _.isDate('Mon April 23 2012'); | * _.isDate('Mon April 23 2012'); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isDate(value) { | var isDate = baseIsDate; | |||
return isObjectLike(value) && objectToString.call(value) == dateTag; | ||||
} | ||||
/** | /** | |||
* Checks if `value` is empty. A value is considered empty unless it's an | * Checks if `value` is an empty object, collection, map, or set. | |||
* `arguments` object, array, string, or jQuery-like collection with a length | * | |||
* greater than `0` or an object with own enumerable properties. | * Objects are considered empty if they have no own enumerable string keyed | |||
* properties. | ||||
* | ||||
* Array-like values such as `arguments` objects, arrays, buffers, strings, or | ||||
* jQuery-like collections are considered empty if they have a `length` of `0` | ||||
. | ||||
* Similarly, maps and sets are considered empty if they have a `size` of `0`. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {Array|Object|string} value The value to inspect. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is empty, else `false`. | * @returns {boolean} Returns `true` if `value` is empty, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isEmpty(null); | * _.isEmpty(null); | |||
* // => true | * // => true | |||
* | * | |||
* _.isEmpty(true); | * _.isEmpty(true); | |||
* // => true | * // => true | |||
* | * | |||
* _.isEmpty(1); | * _.isEmpty(1); | |||
* // => true | * // => true | |||
* | * | |||
* _.isEmpty([1, 2, 3]); | * _.isEmpty([1, 2, 3]); | |||
* // => false | * // => false | |||
* | * | |||
* _.isEmpty({ 'a': 1 }); | * _.isEmpty({ 'a': 1 }); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isEmpty(value) { | function isEmpty(value) { | |||
return (!isObjectLike(value) || isFunction(value.splice)) | if (isArrayLike(value) && | |||
? !size(value) | (isArray(value) || isString(value) || | |||
: !keys(value).length; | isFunction(value.splice) || isArguments(value))) { | |||
return !value.length; | ||||
} | ||||
return !nativeKeys(value).length; | ||||
} | } | |||
/** | /** | |||
* Performs a deep comparison between two values to determine if they are | * Performs a deep comparison between two values to determine if they are | |||
* equivalent. | * equivalent. | |||
* | * | |||
* **Note:** This method supports comparing arrays, array buffers, booleans, | * **Note:** This method supports comparing arrays, array buffers, booleans, | |||
* date objects, error objects, maps, numbers, `Object` objects, regexes, | * date objects, error objects, maps, numbers, `Object` objects, regexes, | |||
* sets, strings, symbols, and typed arrays. `Object` objects are compared | * sets, strings, symbols, and typed arrays. `Object` objects are compared | |||
* by their own, not inherited, enumerable properties. Functions and DOM | * by their own, not inherited, enumerable properties. Functions and DOM | |||
* nodes are **not** supported. | * nodes are compared by strict equality, i.e. `===`. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to compare. | * @param {*} value The value to compare. | |||
* @param {*} other The other value to compare. | * @param {*} other The other value to compare. | |||
* @returns {boolean} Returns `true` if the values are equivalent, else `false `. | * @returns {boolean} Returns `true` if the values are equivalent, else `false `. | |||
* @example | * @example | |||
* | * | |||
* var object = { 'user': 'fred' }; | * var object = { 'a': 1 }; | |||
* var other = { 'user': 'fred' }; | * var other = { 'a': 1 }; | |||
* | * | |||
* _.isEqual(object, other); | * _.isEqual(object, other); | |||
* // => true | * // => true | |||
* | * | |||
* object === other; | * object === other; | |||
* // => false | * // => false | |||
*/ | */ | |||
function isEqual(value, other) { | function isEqual(value, other) { | |||
return baseIsEqual(value, other); | return baseIsEqual(value, other); | |||
} | } | |||
/** | /** | |||
* Checks if `value` is a finite primitive number. | * Checks if `value` is a finite primitive number. | |||
* | * | |||
* **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number | * **Note:** This method is based on | |||
/isFinite). | * [`Number.isFinite`](https://mdn.io/Number/isFinite). | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is a finite number, else `fals e`. | * @returns {boolean} Returns `true` if `value` is a finite number, else `fals e`. | |||
* @example | * @example | |||
* | * | |||
* _.isFinite(3); | * _.isFinite(3); | |||
* // => true | * // => true | |||
* | * | |||
* _.isFinite(Number.MAX_VALUE); | * _.isFinite(Number.MIN_VALUE); | |||
* // => true | ||||
* | ||||
* _.isFinite(3.14); | ||||
* // => true | * // => true | |||
* | * | |||
* _.isFinite(Infinity); | * _.isFinite(Infinity); | |||
* // => false | * // => false | |||
* | ||||
* _.isFinite('3'); | ||||
* // => false | ||||
*/ | */ | |||
function isFinite(value) { | function isFinite(value) { | |||
return typeof value == 'number' && nativeIsFinite(value); | return typeof value == 'number' && nativeIsFinite(value); | |||
} | } | |||
/** | /** | |||
* Checks if `value` is classified as a `Function` object. | * Checks if `value` is classified as a `Function` object. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | * @returns {boolean} Returns `true` if `value` is a function, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isFunction(_); | * _.isFunction(_); | |||
* // => true | * // => true | |||
* | * | |||
* _.isFunction(/abc/); | * _.isFunction(/abc/); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isFunction(value) { | function isFunction(value) { | |||
if (!isObject(value)) { | ||||
return false; | ||||
} | ||||
// The use of `Object#toString` avoids issues with the `typeof` operator | // The use of `Object#toString` avoids issues with the `typeof` operator | |||
// in Safari 8 which returns 'object' for typed array constructors, and | // in Safari 9 which returns 'object' for typed arrays and other constructor | |||
// PhantomJS 1.9 which returns 'function' for `NodeList` instances. | s. | |||
var tag = isObject(value) ? objectToString.call(value) : ''; | var tag = baseGetTag(value); | |||
return tag == funcTag || tag == genTag; | return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag | |||
; | ||||
} | } | |||
/** | /** | |||
* Checks if `value` is a valid array-like length. | * Checks if `value` is a valid array-like length. | |||
* | * | |||
* **Note:** This function is loosely based on [`ToLength`](http://ecma-intern | * **Note:** This method is loosely based on | |||
ational.org/ecma-262/6.0/#sec-tolength). | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 4.0.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false `. | * @returns {boolean} Returns `true` if `value` is a valid length, else `false `. | |||
* @example | * @example | |||
* | * | |||
* _.isLength(3); | * _.isLength(3); | |||
* // => true | * // => true | |||
* | * | |||
* _.isLength(Number.MIN_VALUE); | * _.isLength(Number.MIN_VALUE); | |||
* // => false | * // => false | |||
* | * | |||
* _.isLength(Infinity); | * _.isLength(Infinity); | |||
* // => false | * // => false | |||
* | * | |||
* _.isLength('3'); | * _.isLength('3'); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isLength(value) { | function isLength(value) { | |||
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= | return typeof value == 'number' && | |||
MAX_SAFE_INTEGER; | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; | |||
} | } | |||
/** | /** | |||
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Obj | * Checks if `value` is the | |||
ect`. | * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascr | |||
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String | ipt-language-types) | |||
('')`) | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, an | |||
d `new String('')`) | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | * @returns {boolean} Returns `true` if `value` is an object, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isObject({}); | * _.isObject({}); | |||
* // => true | * // => true | |||
* | * | |||
* _.isObject([1, 2, 3]); | * _.isObject([1, 2, 3]); | |||
* // => true | * // => true | |||
* | * | |||
* _.isObject(_.noop); | * _.isObject(_.noop); | |||
* // => true | * // => true | |||
* | * | |||
* _.isObject(null); | * _.isObject(null); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isObject(value) { | 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; | var type = typeof value; | |||
return !!value && (type == 'object' || type == 'function'); | return value != null && (type == 'object' || type == 'function'); | |||
} | } | |||
/** | /** | |||
* Checks if `value` is object-like. A value is object-like if it's not `null` | * Checks if `value` is object-like. A value is object-like if it's not `null` | |||
* and has a `typeof` result of "object". | * and has a `typeof` result of "object". | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 4.0.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | * @returns {boolean} Returns `true` if `value` is object-like, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isObjectLike({}); | * _.isObjectLike({}); | |||
* // => true | * // => true | |||
* | * | |||
* _.isObjectLike([1, 2, 3]); | * _.isObjectLike([1, 2, 3]); | |||
* // => true | * // => true | |||
* | * | |||
* _.isObjectLike(_.noop); | * _.isObjectLike(_.noop); | |||
* // => false | * // => false | |||
* | * | |||
* _.isObjectLike(null); | * _.isObjectLike(null); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isObjectLike(value) { | function isObjectLike(value) { | |||
return !!value && typeof value == 'object'; | return value != null && typeof value == 'object'; | |||
} | } | |||
/** | /** | |||
* Checks if `value` is `NaN`. | * Checks if `value` is `NaN`. | |||
* | * | |||
* **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x | * **Note:** This method is based on | |||
15.1.2.4) | * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as | |||
* which returns `true` for `undefined` and other non-numeric values. | * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for | |||
* `undefined` and other non-number values. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isNaN(NaN); | * _.isNaN(NaN); | |||
* // => true | * // => true | |||
* | * | |||
* _.isNaN(new Number(NaN)); | * _.isNaN(new Number(NaN)); | |||
* // => true | * // => true | |||
* | * | |||
* isNaN(undefined); | * isNaN(undefined); | |||
* // => true | * // => true | |||
* | * | |||
* _.isNaN(undefined); | * _.isNaN(undefined); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isNaN(value) { | function isNaN(value) { | |||
// An `NaN` primitive is the only value that is not equal to itself. | // An `NaN` primitive is the only value that is not equal to itself. | |||
// Perform the `toStringTag` check first to avoid errors with some ActiveX o | // Perform the `toStringTag` check first to avoid errors with some | |||
bjects in IE. | // ActiveX objects in IE. | |||
return isNumber(value) && value != +value; | return isNumber(value) && value != +value; | |||
} | } | |||
/** | /** | |||
* Checks if `value` is `null`. | * Checks if `value` is `null`. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is `null`, else `false`. | * @returns {boolean} Returns `true` if `value` is `null`, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isNull(null); | * _.isNull(null); | |||
* // => true | * // => true | |||
* | * | |||
* _.isNull(void 0); | * _.isNull(void 0); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isNull(value) { | function isNull(value) { | |||
return value === null; | return value === null; | |||
} | } | |||
/** | /** | |||
* Checks if `value` is classified as a `Number` primitive or object. | * Checks if `value` is classified as a `Number` primitive or object. | |||
* | * | |||
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classifi | * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are | |||
ed | * classified as numbers, use the `_.isFinite` method. | |||
* as numbers, use the `_.isFinite` method. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | * @returns {boolean} Returns `true` if `value` is a number, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isNumber(3); | * _.isNumber(3); | |||
* // => true | * // => true | |||
* | * | |||
* _.isNumber(Number.MIN_VALUE); | * _.isNumber(Number.MIN_VALUE); | |||
* // => true | * // => true | |||
* | * | |||
* _.isNumber(Infinity); | * _.isNumber(Infinity); | |||
* // => true | * // => true | |||
* | * | |||
* _.isNumber('3'); | * _.isNumber('3'); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isNumber(value) { | function isNumber(value) { | |||
return typeof value == 'number' || | return typeof value == 'number' || | |||
(isObjectLike(value) && objectToString.call(value) == numberTag); | (isObjectLike(value) && baseGetTag(value) == numberTag); | |||
} | } | |||
/** | /** | |||
* Checks if `value` is classified as a `RegExp` object. | * Checks if `value` is classified as a `RegExp` object. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.1.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isRegExp(/abc/); | * _.isRegExp(/abc/); | |||
* // => true | * // => true | |||
* | * | |||
* _.isRegExp('/abc/'); | * _.isRegExp('/abc/'); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isRegExp(value) { | var isRegExp = baseIsRegExp; | |||
return isObject(value) && objectToString.call(value) == regexpTag; | ||||
} | ||||
/** | /** | |||
* Checks if `value` is classified as a `String` primitive or object. | * Checks if `value` is classified as a `String` primitive or object. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | * @returns {boolean} Returns `true` if `value` is a string, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isString('abc'); | * _.isString('abc'); | |||
* // => true | * // => true | |||
* | * | |||
* _.isString(1); | * _.isString(1); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isString(value) { | function isString(value) { | |||
return typeof value == 'string' || | return typeof value == 'string' || | |||
(!isArray(value) && isObjectLike(value) && objectToString.call(value) == s tringTag); | (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag) ; | |||
} | } | |||
/** | /** | |||
* Checks if `value` is `undefined`. | * Checks if `value` is `undefined`. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Lang | * @category Lang | |||
* @param {*} value The value to check. | * @param {*} value The value to check. | |||
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. | * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. | |||
* @example | * @example | |||
* | * | |||
* _.isUndefined(void 0); | * _.isUndefined(void 0); | |||
* // => true | * // => true | |||
* | * | |||
* _.isUndefined(null); | * _.isUndefined(null); | |||
* // => false | * // => false | |||
*/ | */ | |||
function isUndefined(value) { | function isUndefined(value) { | |||
return value === undefined; | return value === undefined; | |||
} | } | |||
/** | /** | |||
* Checks if `value` is less than `other`. | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @category Lang | ||||
* @param {*} value The value to compare. | ||||
* @param {*} other The other value to compare. | ||||
* @returns {boolean} Returns `true` if `value` is less than `other`, else `fa | ||||
lse`. | ||||
* @example | ||||
* | ||||
* _.lt(1, 3); | ||||
* // => true | ||||
* | ||||
* _.lt(3, 3); | ||||
* // => false | ||||
* | ||||
* _.lt(3, 1); | ||||
* // => false | ||||
*/ | ||||
function lt(value, other) { | ||||
return value < other; | ||||
} | ||||
/** | ||||
* Converts `value` to an array. | * Converts `value` to an array. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Lang | * @category Lang | |||
* @param {*} value The value to convert. | * @param {*} value The value to convert. | |||
* @returns {Array} Returns the converted array. | * @returns {Array} Returns the converted array. | |||
* @example | * @example | |||
* | * | |||
* _.toArray({ 'a': 1, 'b': 2 }); | * _.toArray({ 'a': 1, 'b': 2 }); | |||
* // => [1, 2] | * // => [1, 2] | |||
* | * | |||
* _.toArray('abc'); | * _.toArray('abc'); | |||
skipping to change at line 2964 | skipping to change at line 2991 | |||
function toArray(value) { | function toArray(value) { | |||
if (!isArrayLike(value)) { | if (!isArrayLike(value)) { | |||
return values(value); | return values(value); | |||
} | } | |||
return value.length ? copyArray(value) : []; | return value.length ? copyArray(value) : []; | |||
} | } | |||
/** | /** | |||
* Converts `value` to an integer. | * Converts `value` to an integer. | |||
* | * | |||
* **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-i | * **Note:** This method is loosely based on | |||
nternational.org/ecma-262/6.0/#sec-tointeger). | * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger | |||
). | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 4.0.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to convert. | * @param {*} value The value to convert. | |||
* @returns {number} Returns the converted integer. | * @returns {number} Returns the converted integer. | |||
* @example | * @example | |||
* | * | |||
* _.toInteger(3); | * _.toInteger(3.2); | |||
* // => 3 | * // => 3 | |||
* | * | |||
* _.toInteger(Number.MIN_VALUE); | * _.toInteger(Number.MIN_VALUE); | |||
* // => 0 | * // => 0 | |||
* | * | |||
* _.toInteger(Infinity); | * _.toInteger(Infinity); | |||
* // => 1.7976931348623157e+308 | * // => 1.7976931348623157e+308 | |||
* | * | |||
* _.toInteger('3'); | * _.toInteger('3.2'); | |||
* // => 3 | * // => 3 | |||
*/ | */ | |||
var toInteger = Number; | var toInteger = Number; | |||
/** | /** | |||
* Converts `value` to a number. | * Converts `value` to a number. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 4.0.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to process. | * @param {*} value The value to process. | |||
* @returns {number} Returns the number. | * @returns {number} Returns the number. | |||
* @example | * @example | |||
* | * | |||
* _.toNumber(3); | * _.toNumber(3.2); | |||
* // => 3 | * // => 3.2 | |||
* | * | |||
* _.toNumber(Number.MIN_VALUE); | * _.toNumber(Number.MIN_VALUE); | |||
* // => 5e-324 | * // => 5e-324 | |||
* | * | |||
* _.toNumber(Infinity); | * _.toNumber(Infinity); | |||
* // => Infinity | * // => Infinity | |||
* | * | |||
* _.toNumber('3'); | * _.toNumber('3.2'); | |||
* // => 3 | * // => 3.2 | |||
*/ | */ | |||
var toNumber = Number; | var toNumber = Number; | |||
/** | /** | |||
* Converts `value` to a string if it's not one. An empty string is returned | * Converts `value` to a string. An empty string is returned for `null` | |||
* for `null` and `undefined` values. The sign of `-0` is preserved. | * and `undefined` values. The sign of `-0` is preserved. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 4.0.0 | ||||
* @category Lang | * @category Lang | |||
* @param {*} value The value to process. | * @param {*} value The value to convert. | |||
* @returns {string} Returns the string. | * @returns {string} Returns the converted string. | |||
* @example | * @example | |||
* | * | |||
* _.toString(null); | * _.toString(null); | |||
* // => '' | * // => '' | |||
* | * | |||
* _.toString(-0); | * _.toString(-0); | |||
* // => '-0' | * // => '-0' | |||
* | * | |||
* _.toString([1, 2, 3]); | * _.toString([1, 2, 3]); | |||
* // => '1,2,3' | * // => '1,2,3' | |||
skipping to change at line 3041 | skipping to change at line 3072 | |||
function toString(value) { | function toString(value) { | |||
if (typeof value == 'string') { | if (typeof value == 'string') { | |||
return value; | return value; | |||
} | } | |||
return value == null ? '' : (value + ''); | return value == null ? '' : (value + ''); | |||
} | } | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Assigns own enumerable properties of source objects to the destination | * Assigns own enumerable string keyed properties of source objects to the | |||
* object. Source objects are applied from left to right. Subsequent sources | * destination object. Source objects are applied from left to right. | |||
* overwrite property assignments of previous sources. | * Subsequent sources overwrite property assignments of previous sources. | |||
* | * | |||
* **Note:** This method mutates `object` and is loosely based on | * **Note:** This method mutates `object` and is loosely based on | |||
* [`Object.assign`](https://mdn.io/Object/assign). | * [`Object.assign`](https://mdn.io/Object/assign). | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 0.10.0 | ||||
* @category Object | * @category Object | |||
* @param {Object} object The destination object. | * @param {Object} object The destination object. | |||
* @param {...Object} [sources] The source objects. | * @param {...Object} [sources] The source objects. | |||
* @returns {Object} Returns `object`. | * @returns {Object} Returns `object`. | |||
* @see _.assignIn | ||||
* @example | * @example | |||
* | * | |||
* function Foo() { | * function Foo() { | |||
* this.c = 3; | * this.a = 1; | |||
* } | * } | |||
* | * | |||
* function Bar() { | * function Bar() { | |||
* this.e = 5; | * this.c = 3; | |||
* } | * } | |||
* | * | |||
* Foo.prototype.d = 4; | * Foo.prototype.b = 2; | |||
* Bar.prototype.f = 6; | * Bar.prototype.d = 4; | |||
* | * | |||
* _.assign({ 'a': 1 }, new Foo, new Bar); | * _.assign({ 'a': 0 }, new Foo, new Bar); | |||
* // => { 'a': 1, 'c': 3, 'e': 5 } | * // => { 'a': 1, 'c': 3 } | |||
*/ | */ | |||
var assign = createAssigner(function(object, source) { | var assign = createAssigner(function(object, source) { | |||
copyObject(source, keys(source), object); | copyObject(source, nativeKeys(source), object); | |||
}); | }); | |||
/** | /** | |||
* This method is like `_.assign` except that it iterates over own and | * This method is like `_.assign` except that it iterates over own and | |||
* inherited source properties. | * inherited source properties. | |||
* | * | |||
* **Note:** This method mutates `object`. | * **Note:** This method mutates `object`. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 4.0.0 | ||||
* @alias extend | * @alias extend | |||
* @category Object | * @category Object | |||
* @param {Object} object The destination object. | * @param {Object} object The destination object. | |||
* @param {...Object} [sources] The source objects. | * @param {...Object} [sources] The source objects. | |||
* @returns {Object} Returns `object`. | * @returns {Object} Returns `object`. | |||
* @see _.assign | ||||
* @example | * @example | |||
* | * | |||
* function Foo() { | * function Foo() { | |||
* this.b = 2; | * this.a = 1; | |||
* } | * } | |||
* | * | |||
* function Bar() { | * function Bar() { | |||
* this.d = 4; | * this.c = 3; | |||
* } | * } | |||
* | * | |||
* Foo.prototype.c = 3; | * Foo.prototype.b = 2; | |||
* Bar.prototype.e = 5; | * Bar.prototype.d = 4; | |||
* | * | |||
* _.assignIn({ 'a': 1 }, new Foo, new Bar); | * _.assignIn({ 'a': 0 }, new Foo, new Bar); | |||
* // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 } | * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } | |||
*/ | */ | |||
var assignIn = createAssigner(function(object, source) { | var assignIn = createAssigner(function(object, source) { | |||
copyObject(source, keysIn(source), object); | copyObject(source, nativeKeysIn(source), object); | |||
}); | ||||
/** | ||||
* This method is like `_.assignIn` except that it accepts `customizer` which | ||||
* is invoked to produce the assigned values. If `customizer` returns `undefin | ||||
ed` | ||||
* assignment is handled by the method instead. The `customizer` is invoked | ||||
* with five arguments: (objValue, srcValue, key, object, source). | ||||
* | ||||
* **Note:** This method mutates `object`. | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @alias extendWith | ||||
* @category Object | ||||
* @param {Object} object The destination object. | ||||
* @param {...Object} sources The source objects. | ||||
* @param {Function} [customizer] The function to customize assigned values. | ||||
* @returns {Object} Returns `object`. | ||||
* @example | ||||
* | ||||
* function customizer(objValue, srcValue) { | ||||
* return _.isUndefined(objValue) ? srcValue : objValue; | ||||
* } | ||||
* | ||||
* var defaults = _.partialRight(_.assignInWith, customizer); | ||||
* | ||||
* defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); | ||||
* // => { 'a': 1, 'b': 2 } | ||||
*/ | ||||
var assignInWith = createAssigner(function(object, source, customizer) { | ||||
copyObjectWith(source, keysIn(source), object, customizer); | ||||
}); | }); | |||
/** | /** | |||
* Creates an object that inherits from the `prototype` object. If a `properti | * Creates an object that inherits from the `prototype` object. If a | |||
es` | * `properties` object is given, its own enumerable string keyed properties | |||
* object is provided its own enumerable properties are assigned to the create | * are assigned to the created object. | |||
d object. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 2.3.0 | ||||
* @category Object | * @category Object | |||
* @param {Object} prototype The object to inherit from. | * @param {Object} prototype The object to inherit from. | |||
* @param {Object} [properties] The properties to assign to the object. | * @param {Object} [properties] The properties to assign to the object. | |||
* @returns {Object} Returns the new object. | * @returns {Object} Returns the new object. | |||
* @example | * @example | |||
* | * | |||
* function Shape() { | * function Shape() { | |||
* this.x = 0; | * this.x = 0; | |||
* this.y = 0; | * this.y = 0; | |||
* } | * } | |||
skipping to change at line 3172 | skipping to change at line 3178 | |||
* | * | |||
* var circle = new Circle; | * var circle = new Circle; | |||
* circle instanceof Circle; | * circle instanceof Circle; | |||
* // => true | * // => true | |||
* | * | |||
* circle instanceof Shape; | * circle instanceof Shape; | |||
* // => true | * // => true | |||
*/ | */ | |||
function create(prototype, properties) { | function create(prototype, properties) { | |||
var result = baseCreate(prototype); | var result = baseCreate(prototype); | |||
return properties ? assign(result, properties) : result; | return properties == null ? result : assign(result, properties); | |||
} | } | |||
/** | /** | |||
* Assigns own and inherited enumerable properties of source objects to the | * Assigns own and inherited enumerable string keyed properties of source | |||
* destination object for all destination properties that resolve to `undefine | * objects to the destination object for all destination properties that | |||
d`. | * resolve to `undefined`. Source objects are applied from left to right. | |||
* Source objects are applied from left to right. Once a property is set, | * Once a property is set, additional values of the same property are ignored. | |||
* additional values of the same property are ignored. | ||||
* | * | |||
* **Note:** This method mutates `object`. | * **Note:** This method mutates `object`. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Object | * @category Object | |||
* @param {Object} object The destination object. | * @param {Object} object The destination object. | |||
* @param {...Object} [sources] The source objects. | * @param {...Object} [sources] The source objects. | |||
* @returns {Object} Returns `object`. | * @returns {Object} Returns `object`. | |||
* @see _.defaultsDeep | ||||
* @example | * @example | |||
* | * | |||
* _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); | * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); | |||
* // => { 'user': 'barney', 'age': 36 } | * // => { 'a': 1, 'b': 2 } | |||
*/ | */ | |||
var defaults = rest(function(args) { | var defaults = baseRest(function(object, sources) { | |||
args.push(undefined, assignInDefaults); | object = Object(object); | |||
return assignInWith.apply(undefined, args); | ||||
var index = -1; | ||||
var length = sources.length; | ||||
var guard = length > 2 ? sources[2] : undefined; | ||||
if (guard && isIterateeCall(sources[0], sources[1], guard)) { | ||||
length = 1; | ||||
} | ||||
while (++index < length) { | ||||
var source = sources[index]; | ||||
var props = keysIn(source); | ||||
var propsIndex = -1; | ||||
var propsLength = props.length; | ||||
while (++propsIndex < propsLength) { | ||||
var key = props[propsIndex]; | ||||
var value = object[key]; | ||||
if (value === undefined || | ||||
(eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) | ||||
{ | ||||
object[key] = source[key]; | ||||
} | ||||
} | ||||
} | ||||
return object; | ||||
}); | }); | |||
/** | /** | |||
* Checks if `path` is a direct property of `object`. | * Checks if `path` is a direct property of `object`. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Object | * @category Object | |||
* @param {Object} object The object to query. | * @param {Object} object The object to query. | |||
* @param {Array|string} path The path to check. | * @param {Array|string} path The path to check. | |||
* @returns {boolean} Returns `true` if `path` exists, else `false`. | * @returns {boolean} Returns `true` if `path` exists, else `false`. | |||
* @example | * @example | |||
* | * | |||
* var object = { 'a': { 'b': { 'c': 3 } } }; | * var object = { 'a': { 'b': 2 } }; | |||
* var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) }); | * var other = _.create({ 'a': _.create({ 'b': 2 }) }); | |||
* | * | |||
* _.has(object, 'a'); | * _.has(object, 'a'); | |||
* // => true | * // => true | |||
* | * | |||
* _.has(object, 'a.b.c'); | * _.has(object, 'a.b'); | |||
* // => true | * // => true | |||
* | * | |||
* _.has(object, ['a', 'b', 'c']); | * _.has(object, ['a', 'b']); | |||
* // => true | * // => true | |||
* | * | |||
* _.has(other, 'a'); | * _.has(other, 'a'); | |||
* // => false | * // => false | |||
*/ | */ | |||
function has(object, path) { | function has(object, path) { | |||
return object != null && hasOwnProperty.call(object, path); | return object != null && hasOwnProperty.call(object, path); | |||
} | } | |||
/** | /** | |||
* Creates an array of the own enumerable property names of `object`. | * Creates an array of the own enumerable property names of `object`. | |||
* | * | |||
* **Note:** Non-object values are coerced to objects. See the | * **Note:** Non-object values are coerced to objects. See the | |||
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys) | * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) | |||
* for more details. | * for more details. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Object | * @category Object | |||
* @param {Object} object The object to query. | * @param {Object} object The object to query. | |||
* @returns {Array} Returns the array of property names. | * @returns {Array} Returns the array of property names. | |||
* @example | * @example | |||
* | * | |||
* function Foo() { | * function Foo() { | |||
* this.a = 1; | * this.a = 1; | |||
* this.b = 2; | * this.b = 2; | |||
* } | * } | |||
* | * | |||
* Foo.prototype.c = 3; | * Foo.prototype.c = 3; | |||
* | * | |||
* _.keys(new Foo); | * _.keys(new Foo); | |||
* // => ['a', 'b'] (iteration order is not guaranteed) | * // => ['a', 'b'] (iteration order is not guaranteed) | |||
* | * | |||
* _.keys('hi'); | * _.keys('hi'); | |||
* // => ['0', '1'] | * // => ['0', '1'] | |||
*/ | */ | |||
function keys(object) { | var keys = nativeKeys; | |||
var isProto = isPrototype(object); | ||||
if (!(isProto || isArrayLike(object))) { | ||||
return baseKeys(object); | ||||
} | ||||
var indexes = indexKeys(object), | ||||
skipIndexes = !!indexes, | ||||
result = indexes || [], | ||||
length = result.length; | ||||
for (var key in object) { | ||||
if (hasOwnProperty.call(object, key) && | ||||
!(skipIndexes && (key == 'length' || isIndex(key, length))) && | ||||
!(isProto && key == 'constructor')) { | ||||
result.push(key); | ||||
} | ||||
} | ||||
return result; | ||||
} | ||||
/** | /** | |||
* Creates an array of the own and inherited enumerable property names of `obj ect`. | * Creates an array of the own and inherited enumerable property names of `obj ect`. | |||
* | * | |||
* **Note:** Non-object values are coerced to objects. | * **Note:** Non-object values are coerced to objects. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 3.0.0 | ||||
* @category Object | * @category Object | |||
* @param {Object} object The object to query. | * @param {Object} object The object to query. | |||
* @returns {Array} Returns the array of property names. | * @returns {Array} Returns the array of property names. | |||
* @example | * @example | |||
* | * | |||
* function Foo() { | * function Foo() { | |||
* this.a = 1; | * this.a = 1; | |||
* this.b = 2; | * this.b = 2; | |||
* } | * } | |||
* | * | |||
* Foo.prototype.c = 3; | * Foo.prototype.c = 3; | |||
* | * | |||
* _.keysIn(new Foo); | * _.keysIn(new Foo); | |||
* // => ['a', 'b', 'c'] (iteration order is not guaranteed) | * // => ['a', 'b', 'c'] (iteration order is not guaranteed) | |||
*/ | */ | |||
function keysIn(object) { | var keysIn = nativeKeysIn; | |||
var index = -1, | ||||
isProto = isPrototype(object), | ||||
props = baseKeysIn(object), | ||||
propsLength = props.length, | ||||
indexes = indexKeys(object), | ||||
skipIndexes = !!indexes, | ||||
result = indexes || [], | ||||
length = result.length; | ||||
while (++index < propsLength) { | ||||
var key = props[index]; | ||||
if (!(skipIndexes && (key == 'length' || isIndex(key, length))) && | ||||
!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key | ||||
)))) { | ||||
result.push(key); | ||||
} | ||||
} | ||||
return result; | ||||
} | ||||
/** | /** | |||
* Creates an object composed of the picked `object` properties. | * Creates an object composed of the picked `object` properties. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Object | * @category Object | |||
* @param {Object} object The source object. | * @param {Object} object The source object. | |||
* @param {...(string|string[])} [props] The property names to pick, specified | * @param {...(string|string[])} [paths] The property paths to pick. | |||
* individually or in arrays. | ||||
* @returns {Object} Returns the new object. | * @returns {Object} Returns the new object. | |||
* @example | * @example | |||
* | * | |||
* var object = { 'a': 1, 'b': '2', 'c': 3 }; | * var object = { 'a': 1, 'b': '2', 'c': 3 }; | |||
* | * | |||
* _.pick(object, ['a', 'c']); | * _.pick(object, ['a', 'c']); | |||
* // => { 'a': 1, 'c': 3 } | * // => { 'a': 1, 'c': 3 } | |||
*/ | */ | |||
var pick = rest(function(object, props) { | var pick = flatRest(function(object, paths) { | |||
return object == null ? {} : basePick(object, baseFlatten(props)); | return object == null ? {} : basePick(object, paths); | |||
}); | }); | |||
/** | /** | |||
* This method is like `_.get` except that if the resolved value is a function | * This method is like `_.get` except that if the resolved value is a | |||
* it's invoked with the `this` binding of its parent object and its result | * function it's invoked with the `this` binding of its parent object and | |||
* is returned. | * its result is returned. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Object | * @category Object | |||
* @param {Object} object The object to query. | * @param {Object} object The object to query. | |||
* @param {Array|string} path The path of the property to resolve. | * @param {Array|string} path The path of the property to resolve. | |||
* @param {*} [defaultValue] The value returned if the resolved value is `unde fined`. | * @param {*} [defaultValue] The value returned for `undefined` resolved value s. | |||
* @returns {*} Returns the resolved value. | * @returns {*} Returns the resolved value. | |||
* @example | * @example | |||
* | * | |||
* var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; | * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; | |||
* | * | |||
* _.result(object, 'a[0].b.c1'); | * _.result(object, 'a[0].b.c1'); | |||
* // => 3 | * // => 3 | |||
* | * | |||
* _.result(object, 'a[0].b.c2'); | * _.result(object, 'a[0].b.c2'); | |||
* // => 4 | * // => 4 | |||
skipping to change at line 3376 | skipping to change at line 3378 | |||
*/ | */ | |||
function result(object, path, defaultValue) { | function result(object, path, defaultValue) { | |||
var value = object == null ? undefined : object[path]; | var value = object == null ? undefined : object[path]; | |||
if (value === undefined) { | if (value === undefined) { | |||
value = defaultValue; | value = defaultValue; | |||
} | } | |||
return isFunction(value) ? value.call(object) : value; | return isFunction(value) ? value.call(object) : value; | |||
} | } | |||
/** | /** | |||
* Creates an array of the own enumerable property values of `object`. | * Creates an array of the own enumerable string keyed property values of `obj ect`. | |||
* | * | |||
* **Note:** Non-object values are coerced to objects. | * **Note:** Non-object values are coerced to objects. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Object | * @category Object | |||
* @param {Object} object The object to query. | * @param {Object} object The object to query. | |||
* @returns {Array} Returns the array of property values. | * @returns {Array} Returns the array of property values. | |||
* @example | * @example | |||
* | * | |||
* function Foo() { | * function Foo() { | |||
* this.a = 1; | * this.a = 1; | |||
* this.b = 2; | * this.b = 2; | |||
* } | * } | |||
* | * | |||
* Foo.prototype.c = 3; | * Foo.prototype.c = 3; | |||
* | * | |||
* _.values(new Foo); | * _.values(new Foo); | |||
* // => [1, 2] (iteration order is not guaranteed) | * // => [1, 2] (iteration order is not guaranteed) | |||
* | * | |||
* _.values('hi'); | * _.values('hi'); | |||
* // => ['h', 'i'] | * // => ['h', 'i'] | |||
*/ | */ | |||
function values(object) { | function values(object) { | |||
return object ? baseValues(object, keys(object)) : []; | return object == null ? [] : baseValues(object, keys(object)); | |||
} | } | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to | * Converts the characters "&", "<", ">", '"', and "'" in `string` to their | |||
* their corresponding HTML entities. | * corresponding HTML entities. | |||
* | * | |||
* **Note:** No other characters are escaped. To escape additional | * **Note:** No other characters are escaped. To escape additional | |||
* characters use a third-party library like [_he_](https://mths.be/he). | * characters use a third-party library like [_he_](https://mths.be/he). | |||
* | * | |||
* Though the ">" character is escaped for symmetry, characters like | * Though the ">" character is escaped for symmetry, characters like | |||
* ">" and "/" don't need escaping in HTML and have no special meaning | * ">" and "/" don't need escaping in HTML and have no special meaning | |||
* unless they're part of a tag or unquoted attribute value. | * unless they're part of a tag or unquoted attribute value. See | |||
* See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-amp | * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersa | |||
ersands) | nds) | |||
* (under "semi-related fun fact") for more details. | * (under "semi-related fun fact") for more details. | |||
* | * | |||
* Backticks are escaped because in IE < 9, they can break out of | * When working with HTML you should always | |||
* attribute values or HTML comments. See [#59](https://html5sec.org/#59), | * [quote attribute values](http://wonko.com/post/html-escaping) to reduce | |||
* [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and | * XSS vectors. | |||
* [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https: | ||||
//html5sec.org/) | ||||
* for more details. | ||||
* | ||||
* When working with HTML you should always [quote attribute values](http://wo | ||||
nko.com/post/html-escaping) | ||||
* to reduce XSS vectors. | ||||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category String | * @category String | |||
* @param {string} [string=''] The string to escape. | * @param {string} [string=''] The string to escape. | |||
* @returns {string} Returns the escaped string. | * @returns {string} Returns the escaped string. | |||
* @example | * @example | |||
* | * | |||
* _.escape('fred, barney, & pebbles'); | * _.escape('fred, barney, & pebbles'); | |||
* // => 'fred, barney, & pebbles' | * // => 'fred, barney, & pebbles' | |||
*/ | */ | |||
function escape(string) { | function escape(string) { | |||
string = toString(string); | string = toString(string); | |||
return (string && reHasUnescapedHtml.test(string)) | return (string && reHasUnescapedHtml.test(string)) | |||
? string.replace(reUnescapedHtml, escapeHtmlChar) | ? string.replace(reUnescapedHtml, escapeHtmlChar) | |||
: string; | : string; | |||
} | } | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* This method returns the first argument provided to it. | * This method returns the first argument it receives. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Util | * @category Util | |||
* @param {*} value Any value. | * @param {*} value Any value. | |||
* @returns {*} Returns `value`. | * @returns {*} Returns `value`. | |||
* @example | * @example | |||
* | * | |||
* var object = { 'user': 'fred' }; | * var object = { 'a': 1 }; | |||
* | * | |||
* _.identity(object) === object; | * console.log(_.identity(object) === object); | |||
* // => true | * // => true | |||
*/ | */ | |||
function identity(value) { | function identity(value) { | |||
return value; | return value; | |||
} | } | |||
/** | /** | |||
* Creates a function that invokes `func` with the arguments of the created | * Creates a function that invokes `func` with the arguments of the created | |||
* function. If `func` is a property name the created callback returns the | * function. If `func` is a property name, the created function returns the | |||
* property value for a given element. If `func` is an object the created | * property value for a given element. If `func` is an array or object, the | |||
* callback returns `true` for elements that contain the equivalent object pro | * created function returns `true` for elements that contain the equivalent | |||
perties, otherwise it returns `false`. | * source properties, otherwise it returns `false`. | |||
* | * | |||
* @static | * @static | |||
* @since 4.0.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Util | * @category Util | |||
* @param {*} [func=_.identity] The value to convert to a callback. | * @param {*} [func=_.identity] The value to convert to a callback. | |||
* @returns {Function} Returns the callback. | * @returns {Function} Returns the callback. | |||
* @example | * @example | |||
* | * | |||
* var users = [ | * var users = [ | |||
* { 'user': 'barney', 'age': 36 }, | * { 'user': 'barney', 'age': 36, 'active': true }, | |||
* { 'user': 'fred', 'age': 40 } | * { 'user': 'fred', 'age': 40, 'active': false } | |||
* ]; | * ]; | |||
* | * | |||
* // create custom iteratee shorthands | * // The `_.matches` iteratee shorthand. | |||
* _.iteratee = _.wrap(_.iteratee, function(callback, func) { | * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true })); | |||
* var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func); | * // => [{ 'user': 'barney', 'age': 36, 'active': true }] | |||
* return !p ? callback(func) : function(object) { | * | |||
* return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]); | * // The `_.matchesProperty` iteratee shorthand. | |||
* _.filter(users, _.iteratee(['user', 'fred'])); | ||||
* // => [{ 'user': 'fred', 'age': 40 }] | ||||
* | ||||
* // The `_.property` iteratee shorthand. | ||||
* _.map(users, _.iteratee('user')); | ||||
* // => ['barney', 'fred'] | ||||
* | ||||
* // Create custom iteratee shorthands. | ||||
* _.iteratee = _.wrap(_.iteratee, function(iteratee, func) { | ||||
* return !_.isRegExp(func) ? iteratee(func) : function(string) { | ||||
* return func.test(string); | ||||
* }; | * }; | |||
* }); | * }); | |||
* | * | |||
* _.filter(users, 'age > 36'); | * _.filter(['abc', 'def'], /ef/); | |||
* // => [{ 'user': 'fred', 'age': 40 }] | * // => ['def'] | |||
*/ | */ | |||
var iteratee = baseIteratee; | var iteratee = baseIteratee; | |||
/** | /** | |||
* Adds all own enumerable function properties of a source object to the | * Creates a function that performs a partial deep comparison between a given | |||
* destination object. If `object` is a function then methods are added to | * object and `source`, returning `true` if the given object has equivalent | |||
* its prototype as well. | * property values, else `false`. | |||
* | ||||
* **Note:** The created function is equivalent to `_.isMatch` with `source` | ||||
* partially applied. | ||||
* | ||||
* Partial comparisons will match empty array and empty object `source` | ||||
* values against any array or object value, respectively. See `_.isEqual` | ||||
* for a list of supported value comparisons. | ||||
* | ||||
* **Note:** Multiple values can be checked by combining several matchers | ||||
* using `_.overSome` | ||||
* | ||||
* @static | ||||
* @memberOf _ | ||||
* @since 3.0.0 | ||||
* @category Util | ||||
* @param {Object} source The object of property values to match. | ||||
* @returns {Function} Returns the new spec function. | ||||
* @example | ||||
* | ||||
* var objects = [ | ||||
* { 'a': 1, 'b': 2, 'c': 3 }, | ||||
* { 'a': 4, 'b': 5, 'c': 6 } | ||||
* ]; | ||||
* | ||||
* _.filter(objects, _.matches({ 'a': 4, 'c': 6 })); | ||||
* // => [{ 'a': 4, 'b': 5, 'c': 6 }] | ||||
* | ||||
* // Checking for several possible values | ||||
* _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })] | ||||
)); | ||||
* // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }] | ||||
*/ | ||||
function matches(source) { | ||||
return baseMatches(assign({}, source)); | ||||
} | ||||
/** | ||||
* Adds all own enumerable string keyed function properties of a source | ||||
* object to the destination object. If `object` is a function, then methods | ||||
* are added to its prototype as well. | ||||
* | * | |||
* **Note:** Use `_.runInContext` to create a pristine `lodash` function to | * **Note:** Use `_.runInContext` to create a pristine `lodash` function to | |||
* avoid conflicts caused by modifying the original. | * avoid conflicts caused by modifying the original. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Util | * @category Util | |||
* @param {Function|Object} [object=lodash] The destination object. | * @param {Function|Object} [object=lodash] The destination object. | |||
* @param {Object} source The object of functions to add. | * @param {Object} source The object of functions to add. | |||
* @param {Object} [options] The options object. | * @param {Object} [options={}] The options object. | |||
* @param {boolean} [options.chain=true] Specify whether the functions added | * @param {boolean} [options.chain=true] Specify whether mixins are chainable. | |||
* are chainable. | ||||
* @returns {Function|Object} Returns `object`. | * @returns {Function|Object} Returns `object`. | |||
* @example | * @example | |||
* | * | |||
* function vowels(string) { | * function vowels(string) { | |||
* return _.filter(string, function(v) { | * return _.filter(string, function(v) { | |||
* return /[aeiou]/i.test(v); | * return /[aeiou]/i.test(v); | |||
* }); | * }); | |||
* } | * } | |||
* | * | |||
* _.mixin({ 'vowels': vowels }); | * _.mixin({ 'vowels': vowels }); | |||
skipping to change at line 3544 | skipping to change at line 3596 | |||
var props = keys(source), | var props = keys(source), | |||
methodNames = baseFunctions(source, props); | methodNames = baseFunctions(source, props); | |||
if (options == null && | if (options == null && | |||
!(isObject(source) && (methodNames.length || !props.length))) { | !(isObject(source) && (methodNames.length || !props.length))) { | |||
options = source; | options = source; | |||
source = object; | source = object; | |||
object = this; | object = this; | |||
methodNames = baseFunctions(source, keys(source)); | methodNames = baseFunctions(source, keys(source)); | |||
} | } | |||
var chain = (isObject(options) && 'chain' in options) ? options.chain : true , | var chain = !(isObject(options) && 'chain' in options) || !!options.chain, | |||
isFunc = isFunction(object); | isFunc = isFunction(object); | |||
baseEach(methodNames, function(methodName) { | baseEach(methodNames, function(methodName) { | |||
var func = source[methodName]; | var func = source[methodName]; | |||
object[methodName] = func; | object[methodName] = func; | |||
if (isFunc) { | if (isFunc) { | |||
object.prototype[methodName] = function() { | object.prototype[methodName] = function() { | |||
var chainAll = this.__chain__; | var chainAll = this.__chain__; | |||
if (chain || chainAll) { | if (chain || chainAll) { | |||
var result = object(this.__wrapped__), | var result = object(this.__wrapped__), | |||
skipping to change at line 3574 | skipping to change at line 3626 | |||
}); | }); | |||
return object; | return object; | |||
} | } | |||
/** | /** | |||
* Reverts the `_` variable to its previous value and returns a reference to | * Reverts the `_` variable to its previous value and returns a reference to | |||
* the `lodash` function. | * the `lodash` function. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Util | * @category Util | |||
* @returns {Function} Returns the `lodash` function. | * @returns {Function} Returns the `lodash` function. | |||
* @example | * @example | |||
* | * | |||
* var lodash = _.noConflict(); | * var lodash = _.noConflict(); | |||
*/ | */ | |||
function noConflict() { | function noConflict() { | |||
root._ = oldDash; | if (root._ === this) { | |||
root._ = oldDash; | ||||
} | ||||
return this; | return this; | |||
} | } | |||
/** | /** | |||
* A no-operation function that returns `undefined` regardless of the | * This method returns `undefined`. | |||
* arguments it receives. | ||||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @since 2.3.0 | ||||
* @category Util | * @category Util | |||
* @example | * @example | |||
* | * | |||
* var object = { 'user': 'fred' }; | * _.times(2, _.noop); | |||
* | * // => [undefined, undefined] | |||
* _.noop(object) === undefined; | ||||
* // => true | ||||
*/ | */ | |||
function noop() { | function noop() { | |||
// No operation performed. | // No operation performed. | |||
} | } | |||
/** | /** | |||
* Generates a unique ID. If `prefix` is provided the ID is appended to it. | * Generates a unique ID. If `prefix` is given, the ID is appended to it. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Util | * @category Util | |||
* @param {string} [prefix] The value to prefix the ID with. | * @param {string} [prefix=''] The value to prefix the ID with. | |||
* @returns {string} Returns the unique ID. | * @returns {string} Returns the unique ID. | |||
* @example | * @example | |||
* | * | |||
* _.uniqueId('contact_'); | * _.uniqueId('contact_'); | |||
* // => 'contact_104' | * // => 'contact_104' | |||
* | * | |||
* _.uniqueId(); | * _.uniqueId(); | |||
* // => '105' | * // => '105' | |||
*/ | */ | |||
function uniqueId(prefix) { | function uniqueId(prefix) { | |||
var id = ++idCounter; | var id = ++idCounter; | |||
return toString(prefix) + id; | return toString(prefix) + id; | |||
} | } | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Computes the maximum value of `array`. If `array` is empty or falsey | * Computes the maximum value of `array`. If `array` is empty or falsey, | |||
* `undefined` is returned. | * `undefined` is returned. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Math | * @category Math | |||
* @param {Array} array The array to iterate over. | * @param {Array} array The array to iterate over. | |||
* @returns {*} Returns the maximum value. | * @returns {*} Returns the maximum value. | |||
* @example | * @example | |||
* | * | |||
* _.max([4, 2, 8, 6]); | * _.max([4, 2, 8, 6]); | |||
* // => 8 | * // => 8 | |||
* | * | |||
* _.max([]); | * _.max([]); | |||
* // => undefined | * // => undefined | |||
*/ | */ | |||
function max(array) { | function max(array) { | |||
return (array && array.length) | return (array && array.length) | |||
? baseExtremum(array, identity, gt) | ? baseExtremum(array, identity, baseGt) | |||
: undefined; | : undefined; | |||
} | } | |||
/** | /** | |||
* Computes the minimum value of `array`. If `array` is empty or falsey | * Computes the minimum value of `array`. If `array` is empty or falsey, | |||
* `undefined` is returned. | * `undefined` is returned. | |||
* | * | |||
* @static | * @static | |||
* @since 0.1.0 | ||||
* @memberOf _ | * @memberOf _ | |||
* @category Math | * @category Math | |||
* @param {Array} array The array to iterate over. | * @param {Array} array The array to iterate over. | |||
* @returns {*} Returns the minimum value. | * @returns {*} Returns the minimum value. | |||
* @example | * @example | |||
* | * | |||
* _.min([4, 2, 8, 6]); | * _.min([4, 2, 8, 6]); | |||
* // => 2 | * // => 2 | |||
* | * | |||
* _.min([]); | * _.min([]); | |||
* // => undefined | * // => undefined | |||
*/ | */ | |||
function min(array) { | function min(array) { | |||
return (array && array.length) | return (array && array.length) | |||
? baseExtremum(array, identity, lt) | ? baseExtremum(array, identity, baseLt) | |||
: undefined; | : undefined; | |||
} | } | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
LodashWrapper.prototype = baseCreate(lodash.prototype); | // Add methods that return wrapped values in chain sequences. | |||
LodashWrapper.prototype.constructor = LodashWrapper; | ||||
// Add functions that return wrapped values when chaining. | ||||
lodash.assignIn = assignIn; | lodash.assignIn = assignIn; | |||
lodash.before = before; | lodash.before = before; | |||
lodash.bind = bind; | lodash.bind = bind; | |||
lodash.chain = chain; | lodash.chain = chain; | |||
lodash.compact = compact; | lodash.compact = compact; | |||
lodash.concat = concat; | lodash.concat = concat; | |||
lodash.create = create; | lodash.create = create; | |||
lodash.defaults = defaults; | lodash.defaults = defaults; | |||
lodash.defer = defer; | lodash.defer = defer; | |||
lodash.delay = delay; | lodash.delay = delay; | |||
lodash.filter = filter; | lodash.filter = filter; | |||
lodash.flatten = flatten; | lodash.flatten = flatten; | |||
lodash.flattenDeep = flattenDeep; | lodash.flattenDeep = flattenDeep; | |||
lodash.invokeMap = invokeMap; | ||||
lodash.iteratee = iteratee; | lodash.iteratee = iteratee; | |||
lodash.keys = keys; | lodash.keys = keys; | |||
lodash.map = map; | lodash.map = map; | |||
lodash.matches = matches; | ||||
lodash.mixin = mixin; | lodash.mixin = mixin; | |||
lodash.negate = negate; | lodash.negate = negate; | |||
lodash.once = once; | lodash.once = once; | |||
lodash.pick = pick; | lodash.pick = pick; | |||
lodash.slice = slice; | lodash.slice = slice; | |||
lodash.sortBy = sortBy; | lodash.sortBy = sortBy; | |||
lodash.tap = tap; | lodash.tap = tap; | |||
lodash.thru = thru; | lodash.thru = thru; | |||
lodash.toArray = toArray; | lodash.toArray = toArray; | |||
lodash.values = values; | lodash.values = values; | |||
// Add aliases. | // Add aliases. | |||
lodash.each = forEach; | ||||
lodash.extend = assignIn; | lodash.extend = assignIn; | |||
// Add functions to `lodash.prototype`. | // Add methods to `lodash.prototype`. | |||
mixin(lodash, lodash); | mixin(lodash, lodash); | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
// Add functions that return unwrapped values when chaining. | // Add methods that return unwrapped values in chain sequences. | |||
lodash.clone = clone; | lodash.clone = clone; | |||
lodash.escape = escape; | lodash.escape = escape; | |||
lodash.every = every; | lodash.every = every; | |||
lodash.find = find; | lodash.find = find; | |||
lodash.forEach = forEach; | lodash.forEach = forEach; | |||
lodash.has = has; | lodash.has = has; | |||
lodash.head = head; | lodash.head = head; | |||
lodash.identity = identity; | lodash.identity = identity; | |||
lodash.indexOf = indexOf; | lodash.indexOf = indexOf; | |||
lodash.isArguments = isArguments; | lodash.isArguments = isArguments; | |||
skipping to change at line 3746 | skipping to change at line 3798 | |||
lodash.isNumber = isNumber; | lodash.isNumber = isNumber; | |||
lodash.isObject = isObject; | lodash.isObject = isObject; | |||
lodash.isRegExp = isRegExp; | lodash.isRegExp = isRegExp; | |||
lodash.isString = isString; | lodash.isString = isString; | |||
lodash.isUndefined = isUndefined; | lodash.isUndefined = isUndefined; | |||
lodash.last = last; | lodash.last = last; | |||
lodash.max = max; | lodash.max = max; | |||
lodash.min = min; | lodash.min = min; | |||
lodash.noConflict = noConflict; | lodash.noConflict = noConflict; | |||
lodash.noop = noop; | lodash.noop = noop; | |||
lodash.now = now; | ||||
lodash.reduce = reduce; | lodash.reduce = reduce; | |||
lodash.result = result; | lodash.result = result; | |||
lodash.size = size; | lodash.size = size; | |||
lodash.some = some; | lodash.some = some; | |||
lodash.uniqueId = uniqueId; | lodash.uniqueId = uniqueId; | |||
// Add aliases. | // Add aliases. | |||
lodash.each = forEach; | ||||
lodash.first = head; | lodash.first = head; | |||
mixin(lodash, (function() { | mixin(lodash, (function() { | |||
var source = {}; | var source = {}; | |||
baseForOwn(lodash, function(func, methodName) { | baseForOwn(lodash, function(func, methodName) { | |||
if (!hasOwnProperty.call(lodash.prototype, methodName)) { | if (!hasOwnProperty.call(lodash.prototype, methodName)) { | |||
source[methodName] = func; | source[methodName] = func; | |||
} | } | |||
}); | }); | |||
return source; | return source; | |||
}()), { 'chain': false }); | }()), { 'chain': false }); | |||
/*------------------------------------------------------------------------*/ | /*------------------------------------------------------------------------*/ | |||
/** | /** | |||
* The semantic version number. | * The semantic version number. | |||
* | * | |||
* @static | * @static | |||
* @memberOf _ | * @memberOf _ | |||
* @type string | * @type {string} | |||
*/ | */ | |||
lodash.VERSION = VERSION; | lodash.VERSION = VERSION; | |||
// Add `Array` and `String` methods to `lodash.prototype`. | // Add `Array` methods to `lodash.prototype`. | |||
baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort ', 'splice', 'unshift'], function(methodName) { | baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort ', 'splice', 'unshift'], function(methodName) { | |||
var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arra yProto)[methodName], | var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arra yProto)[methodName], | |||
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', | chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', | |||
retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName); | retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName); | |||
lodash.prototype[methodName] = function() { | lodash.prototype[methodName] = function() { | |||
var args = arguments; | var args = arguments; | |||
if (retUnwrapped && !this.__chain__) { | if (retUnwrapped && !this.__chain__) { | |||
return func.apply(this.value(), args); | var value = this.value(); | |||
return func.apply(isArray(value) ? value : [], args); | ||||
} | } | |||
return this[chainName](function(value) { | return this[chainName](function(value) { | |||
return func.apply(value, args); | return func.apply(isArray(value) ? value : [], args); | |||
}); | }); | |||
}; | }; | |||
}); | }); | |||
// Add chaining functions to the `lodash` wrapper. | // Add chain sequence methods to the `lodash` wrapper. | |||
lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; | lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
// Expose lodash on the free variable `window` or `self` when available. This | // Some AMD build optimizers, like r.js, check for condition patterns like: | |||
// prevents errors in cases where lodash is loaded by a script tag in the pres | ||||
ence | ||||
// of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for mo | ||||
re details. | ||||
(freeWindow || freeSelf || {})._ = lodash; | ||||
// Some AMD build optimizers like r.js check for condition patterns like the f | ||||
ollowing: | ||||
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd ) { | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd ) { | |||
// Expose Lodash on the global object to prevent errors when Lodash is | ||||
// loaded by a script tag in the presence of an AMD loader. | ||||
// See http://requirejs.org/docs/errors.html#mismatch for more details. | ||||
// Use `_.noConflict` to remove Lodash from the global object. | ||||
root._ = lodash; | ||||
// Define as an anonymous module so, through path mapping, it can be | // Define as an anonymous module so, through path mapping, it can be | |||
// referenced as the "underscore" module. | // referenced as the "underscore" module. | |||
define(function() { | define(function() { | |||
return lodash; | return lodash; | |||
}); | }); | |||
} | } | |||
// Check for `exports` after `define` in case a build optimizer adds an `expor | // Check for `exports` after `define` in case a build optimizer adds it. | |||
ts` object. | else if (freeModule) { | |||
else if (freeExports && freeModule) { | ||||
// Export for Node.js. | // Export for Node.js. | |||
if (moduleExports) { | (freeModule.exports = lodash)._ = lodash; | |||
(freeModule.exports = lodash)._ = lodash; | ||||
} | ||||
// Export for CommonJS support. | // Export for CommonJS support. | |||
freeExports._ = lodash; | freeExports._ = lodash; | |||
} | } | |||
else { | else { | |||
// Export to the global object. | // Export to the global object. | |||
root._ = lodash; | root._ = lodash; | |||
} | } | |||
}.call(this)); | }.call(this)); | |||
End of changes. 435 change blocks. | ||||
1181 lines changed or deleted | 1195 lines changed or added |