3 * Lodash (Custom Build) <https://lodash.com/>
4 * Build: `lodash core -o ./dist/lodash.core.js`
5 * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
6 * Released under MIT license <https://lodash.com/license>
7 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
8 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
15 /** Used as the semantic version number. */
16 var VERSION = '4.17.20';
18 /** Error message constants. */
19 var FUNC_ERROR_TEXT = 'Expected a function';
21 /** Used to compose bitmasks for value comparisons. */
22 var COMPARE_PARTIAL_FLAG = 1,
23 COMPARE_UNORDERED_FLAG = 2;
25 /** Used to compose bitmasks for function metadata. */
26 var WRAP_BIND_FLAG = 1,
27 WRAP_PARTIAL_FLAG = 32;
29 /** Used as references for various `Number` constants. */
31 MAX_SAFE_INTEGER = 9007199254740991;
33 /** `Object#toString` result references. */
34 var argsTag = '[object Arguments]',
35 arrayTag = '[object Array]',
36 asyncTag = '[object AsyncFunction]',
37 boolTag = '[object Boolean]',
38 dateTag = '[object Date]',
39 errorTag = '[object Error]',
40 funcTag = '[object Function]',
41 genTag = '[object GeneratorFunction]',
42 numberTag = '[object Number]',
43 objectTag = '[object Object]',
44 proxyTag = '[object Proxy]',
45 regexpTag = '[object RegExp]',
46 stringTag = '[object String]';
48 /** Used to match HTML entities and HTML characters. */
49 var reUnescapedHtml = /[&<>"']/g,
50 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
52 /** Used to detect unsigned integer values. */
53 var reIsUint = /^(?:0|[1-9]\d*)$/;
55 /** Used to map characters to HTML entities. */
64 /** Detect free variable `global` from Node.js. */
65 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
67 /** Detect free variable `self`. */
68 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
70 /** Used as a reference to the global object. */
71 var root = freeGlobal || freeSelf || Function('return this')();
73 /** Detect free variable `exports`. */
74 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
76 /** Detect free variable `module`. */
77 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
79 /*--------------------------------------------------------------------------*/
82 * Appends the elements of `values` to `array`.
85 * @param {Array} array The array to modify.
86 * @param {Array} values The values to append.
87 * @returns {Array} Returns `array`.
89 function arrayPush(array, values) {
90 array.push.apply(array, values);
95 * The base implementation of `_.findIndex` and `_.findLastIndex` without
96 * support for iteratee shorthands.
99 * @param {Array} array The array to inspect.
100 * @param {Function} predicate The function invoked per iteration.
101 * @param {number} fromIndex The index to search from.
102 * @param {boolean} [fromRight] Specify iterating from right to left.
103 * @returns {number} Returns the index of the matched value, else `-1`.
105 function baseFindIndex(array, predicate, fromIndex, fromRight) {
106 var length = array.length,
107 index = fromIndex + (fromRight ? 1 : -1);
109 while ((fromRight ? index-- : ++index < length)) {
110 if (predicate(array[index], index, array)) {
118 * The base implementation of `_.property` without support for deep paths.
121 * @param {string} key The key of the property to get.
122 * @returns {Function} Returns the new accessor function.
124 function baseProperty(key) {
125 return function(object) {
126 return object == null ? undefined : object[key];
131 * The base implementation of `_.propertyOf` without support for deep paths.
134 * @param {Object} object The object to query.
135 * @returns {Function} Returns the new accessor function.
137 function basePropertyOf(object) {
138 return function(key) {
139 return object == null ? undefined : object[key];
144 * The base implementation of `_.reduce` and `_.reduceRight`, without support
145 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
148 * @param {Array|Object} collection The collection to iterate over.
149 * @param {Function} iteratee The function invoked per iteration.
150 * @param {*} accumulator The initial value.
151 * @param {boolean} initAccum Specify using the first or last element of
152 * `collection` as the initial value.
153 * @param {Function} eachFunc The function to iterate over `collection`.
154 * @returns {*} Returns the accumulated value.
156 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
157 eachFunc(collection, function(value, index, collection) {
158 accumulator = initAccum
159 ? (initAccum = false, value)
160 : iteratee(accumulator, value, index, collection);
166 * The base implementation of `_.values` and `_.valuesIn` which creates an
167 * array of `object` property values corresponding to the property names
171 * @param {Object} object The object to query.
172 * @param {Array} props The property names to get values for.
173 * @returns {Object} Returns the array of property values.
175 function baseValues(object, props) {
176 return baseMap(props, function(key) {
182 * Used by `_.escape` to convert characters to HTML entities.
185 * @param {string} chr The matched character to escape.
186 * @returns {string} Returns the escaped character.
188 var escapeHtmlChar = basePropertyOf(htmlEscapes);
191 * Creates a unary function that invokes `func` with its argument transformed.
194 * @param {Function} func The function to wrap.
195 * @param {Function} transform The argument transform.
196 * @returns {Function} Returns the new function.
198 function overArg(func, transform) {
199 return function(arg) {
200 return func(transform(arg));
204 /*--------------------------------------------------------------------------*/
206 /** Used for built-in method references. */
207 var arrayProto = Array.prototype,
208 objectProto = Object.prototype;
210 /** Used to check objects for own properties. */
211 var hasOwnProperty = objectProto.hasOwnProperty;
213 /** Used to generate unique IDs. */
217 * Used to resolve the
218 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
221 var nativeObjectToString = objectProto.toString;
223 /** Used to restore the original `_` reference in `_.noConflict`. */
224 var oldDash = root._;
226 /** Built-in value references. */
227 var objectCreate = Object.create,
228 propertyIsEnumerable = objectProto.propertyIsEnumerable;
230 /* Built-in method references for those with the same name as other `lodash` methods. */
231 var nativeIsFinite = root.isFinite,
232 nativeKeys = overArg(Object.keys, Object),
233 nativeMax = Math.max;
235 /*------------------------------------------------------------------------*/
238 * Creates a `lodash` object which wraps `value` to enable implicit method
239 * chain sequences. Methods that operate on and return arrays, collections,
240 * and functions can be chained together. Methods that retrieve a single value
241 * or may return a primitive value will automatically end the chain sequence
242 * and return the unwrapped value. Otherwise, the value must be unwrapped
245 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
246 * enabled using `_.chain`.
248 * The execution of chained methods is lazy, that is, it's deferred until
249 * `_#value` is implicitly or explicitly called.
251 * Lazy evaluation allows several methods to support shortcut fusion.
252 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
253 * the creation of intermediate arrays and can greatly reduce the number of
254 * iteratee executions. Sections of a chain sequence qualify for shortcut
255 * fusion if the section is applied to an array and iteratees accept only
256 * one argument. The heuristic for whether a section qualifies for shortcut
257 * fusion is subject to change.
259 * Chaining is supported in custom builds as long as the `_#value` method is
260 * directly or indirectly included in the build.
262 * In addition to lodash methods, wrappers have `Array` and `String` methods.
264 * The wrapper `Array` methods are:
265 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
267 * The wrapper `String` methods are:
268 * `replace` and `split`
270 * The wrapper methods that support shortcut fusion are:
271 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
272 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
273 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
275 * The chainable wrapper methods are:
276 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
277 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
278 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
279 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
280 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
281 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
282 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
283 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
284 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
285 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
286 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
287 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
288 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
289 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
290 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
291 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
292 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
293 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
294 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
295 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
296 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
297 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
298 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
299 * `zipObject`, `zipObjectDeep`, and `zipWith`
301 * The wrapper methods that are **not** chainable by default are:
302 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
303 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
304 * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
305 * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
306 * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
307 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
308 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
309 * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
310 * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
311 * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
312 * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
313 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
314 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
315 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
316 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
317 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
318 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
319 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
320 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
321 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
322 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
323 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
324 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
325 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
326 * `upperFirst`, `value`, and `words`
331 * @param {*} value The value to wrap in a `lodash` instance.
332 * @returns {Object} Returns the new `lodash` wrapper instance.
335 * function square(n) {
339 * var wrapped = _([1, 2, 3]);
341 * // Returns an unwrapped value.
342 * wrapped.reduce(_.add);
345 * // Returns a wrapped value.
346 * var squares = wrapped.map(square);
348 * _.isArray(squares);
351 * _.isArray(squares.value());
354 function lodash(value) {
355 return value instanceof LodashWrapper
357 : new LodashWrapper(value);
361 * The base implementation of `_.create` without support for assigning
362 * properties to the created object.
365 * @param {Object} proto The object to inherit from.
366 * @returns {Object} Returns the new object.
368 var baseCreate = (function() {
370 return function(proto) {
371 if (!isObject(proto)) {
375 return objectCreate(proto);
377 object.prototype = proto;
378 var result = new object;
379 object.prototype = undefined;
385 * The base constructor for creating `lodash` wrapper objects.
388 * @param {*} value The value to wrap.
389 * @param {boolean} [chainAll] Enable explicit method chain sequences.
391 function LodashWrapper(value, chainAll) {
392 this.__wrapped__ = value;
393 this.__actions__ = [];
394 this.__chain__ = !!chainAll;
397 LodashWrapper.prototype = baseCreate(lodash.prototype);
398 LodashWrapper.prototype.constructor = LodashWrapper;
400 /*------------------------------------------------------------------------*/
403 * Assigns `value` to `key` of `object` if the existing value is not equivalent
404 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
405 * for equality comparisons.
408 * @param {Object} object The object to modify.
409 * @param {string} key The key of the property to assign.
410 * @param {*} value The value to assign.
412 function assignValue(object, key, value) {
413 var objValue = object[key];
414 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
415 (value === undefined && !(key in object))) {
416 baseAssignValue(object, key, value);
421 * The base implementation of `assignValue` and `assignMergeValue` without
425 * @param {Object} object The object to modify.
426 * @param {string} key The key of the property to assign.
427 * @param {*} value The value to assign.
429 function baseAssignValue(object, key, value) {
434 * The base implementation of `_.delay` and `_.defer` which accepts `args`
435 * to provide to `func`.
438 * @param {Function} func The function to delay.
439 * @param {number} wait The number of milliseconds to delay invocation.
440 * @param {Array} args The arguments to provide to `func`.
441 * @returns {number|Object} Returns the timer id or timeout object.
443 function baseDelay(func, wait, args) {
444 if (typeof func != 'function') {
445 throw new TypeError(FUNC_ERROR_TEXT);
447 return setTimeout(function() { func.apply(undefined, args); }, wait);
451 * The base implementation of `_.forEach` without support for iteratee shorthands.
454 * @param {Array|Object} collection The collection to iterate over.
455 * @param {Function} iteratee The function invoked per iteration.
456 * @returns {Array|Object} Returns `collection`.
458 var baseEach = createBaseEach(baseForOwn);
461 * The base implementation of `_.every` without support for iteratee shorthands.
464 * @param {Array|Object} collection The collection to iterate over.
465 * @param {Function} predicate The function invoked per iteration.
466 * @returns {boolean} Returns `true` if all elements pass the predicate check,
469 function baseEvery(collection, predicate) {
471 baseEach(collection, function(value, index, collection) {
472 result = !!predicate(value, index, collection);
479 * The base implementation of methods like `_.max` and `_.min` which accepts a
480 * `comparator` to determine the extremum value.
483 * @param {Array} array The array to iterate over.
484 * @param {Function} iteratee The iteratee invoked per iteration.
485 * @param {Function} comparator The comparator used to compare values.
486 * @returns {*} Returns the extremum value.
488 function baseExtremum(array, iteratee, comparator) {
490 length = array.length;
492 while (++index < length) {
493 var value = array[index],
494 current = iteratee(value);
496 if (current != null && (computed === undefined
497 ? (current === current && !false)
498 : comparator(current, computed)
500 var computed = current,
508 * The base implementation of `_.filter` without support for iteratee shorthands.
511 * @param {Array|Object} collection The collection to iterate over.
512 * @param {Function} predicate The function invoked per iteration.
513 * @returns {Array} Returns the new filtered array.
515 function baseFilter(collection, predicate) {
517 baseEach(collection, function(value, index, collection) {
518 if (predicate(value, index, collection)) {
526 * The base implementation of `_.flatten` with support for restricting flattening.
529 * @param {Array} array The array to flatten.
530 * @param {number} depth The maximum recursion depth.
531 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
532 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
533 * @param {Array} [result=[]] The initial result value.
534 * @returns {Array} Returns the new flattened array.
536 function baseFlatten(array, depth, predicate, isStrict, result) {
538 length = array.length;
540 predicate || (predicate = isFlattenable);
541 result || (result = []);
543 while (++index < length) {
544 var value = array[index];
545 if (depth > 0 && predicate(value)) {
547 // Recursively flatten arrays (susceptible to call stack limits).
548 baseFlatten(value, depth - 1, predicate, isStrict, result);
550 arrayPush(result, value);
552 } else if (!isStrict) {
553 result[result.length] = value;
560 * The base implementation of `baseForOwn` which iterates over `object`
561 * properties returned by `keysFunc` and invokes `iteratee` for each property.
562 * Iteratee functions may exit iteration early by explicitly returning `false`.
565 * @param {Object} object The object to iterate over.
566 * @param {Function} iteratee The function invoked per iteration.
567 * @param {Function} keysFunc The function to get the keys of `object`.
568 * @returns {Object} Returns `object`.
570 var baseFor = createBaseFor();
573 * The base implementation of `_.forOwn` without support for iteratee shorthands.
576 * @param {Object} object The object to iterate over.
577 * @param {Function} iteratee The function invoked per iteration.
578 * @returns {Object} Returns `object`.
580 function baseForOwn(object, iteratee) {
581 return object && baseFor(object, iteratee, keys);
585 * The base implementation of `_.functions` which creates an array of
586 * `object` function property names filtered from `props`.
589 * @param {Object} object The object to inspect.
590 * @param {Array} props The property names to filter.
591 * @returns {Array} Returns the function names.
593 function baseFunctions(object, props) {
594 return baseFilter(props, function(key) {
595 return isFunction(object[key]);
600 * The base implementation of `getTag` without fallbacks for buggy environments.
603 * @param {*} value The value to query.
604 * @returns {string} Returns the `toStringTag`.
606 function baseGetTag(value) {
607 return objectToString(value);
611 * The base implementation of `_.gt` which doesn't coerce arguments.
614 * @param {*} value The value to compare.
615 * @param {*} other The other value to compare.
616 * @returns {boolean} Returns `true` if `value` is greater than `other`,
619 function baseGt(value, other) {
620 return value > other;
624 * The base implementation of `_.isArguments`.
627 * @param {*} value The value to check.
628 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
630 var baseIsArguments = noop;
633 * The base implementation of `_.isDate` without Node.js optimizations.
636 * @param {*} value The value to check.
637 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
639 function baseIsDate(value) {
640 return isObjectLike(value) && baseGetTag(value) == dateTag;
644 * The base implementation of `_.isEqual` which supports partial comparisons
645 * and tracks traversed objects.
648 * @param {*} value The value to compare.
649 * @param {*} other The other value to compare.
650 * @param {boolean} bitmask The bitmask flags.
651 * 1 - Unordered comparison
652 * 2 - Partial comparison
653 * @param {Function} [customizer] The function to customize comparisons.
654 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
655 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
657 function baseIsEqual(value, other, bitmask, customizer, stack) {
658 if (value === other) {
661 if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
662 return value !== value && other !== other;
664 return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
668 * A specialized version of `baseIsEqual` for arrays and objects which performs
669 * deep comparisons and tracks traversed objects enabling objects with circular
670 * references to be compared.
673 * @param {Object} object The object to compare.
674 * @param {Object} other The other object to compare.
675 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
676 * @param {Function} customizer The function to customize comparisons.
677 * @param {Function} equalFunc The function to determine equivalents of values.
678 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
679 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
681 function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
682 var objIsArr = isArray(object),
683 othIsArr = isArray(other),
684 objTag = objIsArr ? arrayTag : baseGetTag(object),
685 othTag = othIsArr ? arrayTag : baseGetTag(other);
687 objTag = objTag == argsTag ? objectTag : objTag;
688 othTag = othTag == argsTag ? objectTag : othTag;
690 var objIsObj = objTag == objectTag,
691 othIsObj = othTag == objectTag,
692 isSameTag = objTag == othTag;
694 stack || (stack = []);
695 var objStack = find(stack, function(entry) {
696 return entry[0] == object;
698 var othStack = find(stack, function(entry) {
699 return entry[0] == other;
701 if (objStack && othStack) {
702 return objStack[1] == other;
704 stack.push([object, other]);
705 stack.push([other, object]);
706 if (isSameTag && !objIsObj) {
707 var result = (objIsArr)
708 ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
709 : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
713 if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
714 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
715 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
717 if (objIsWrapped || othIsWrapped) {
718 var objUnwrapped = objIsWrapped ? object.value() : object,
719 othUnwrapped = othIsWrapped ? other.value() : other;
721 var result = equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
729 var result = equalObjects(object, other, bitmask, customizer, equalFunc, stack);
735 * The base implementation of `_.isRegExp` without Node.js optimizations.
738 * @param {*} value The value to check.
739 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
741 function baseIsRegExp(value) {
742 return isObjectLike(value) && baseGetTag(value) == regexpTag;
746 * The base implementation of `_.iteratee`.
749 * @param {*} [value=_.identity] The value to convert to an iteratee.
750 * @returns {Function} Returns the iteratee.
752 function baseIteratee(func) {
753 if (typeof func == 'function') {
759 return (typeof func == 'object' ? baseMatches : baseProperty)(func);
763 * The base implementation of `_.lt` which doesn't coerce arguments.
766 * @param {*} value The value to compare.
767 * @param {*} other The other value to compare.
768 * @returns {boolean} Returns `true` if `value` is less than `other`,
771 function baseLt(value, other) {
772 return value < other;
776 * The base implementation of `_.map` without support for iteratee shorthands.
779 * @param {Array|Object} collection The collection to iterate over.
780 * @param {Function} iteratee The function invoked per iteration.
781 * @returns {Array} Returns the new mapped array.
783 function baseMap(collection, iteratee) {
785 result = isArrayLike(collection) ? Array(collection.length) : [];
787 baseEach(collection, function(value, key, collection) {
788 result[++index] = iteratee(value, key, collection);
794 * The base implementation of `_.matches` which doesn't clone `source`.
797 * @param {Object} source The object of property values to match.
798 * @returns {Function} Returns the new spec function.
800 function baseMatches(source) {
801 var props = nativeKeys(source);
802 return function(object) {
803 var length = props.length;
804 if (object == null) {
807 object = Object(object);
809 var key = props[length];
810 if (!(key in object &&
811 baseIsEqual(source[key], object[key], COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG)
821 * The base implementation of `_.pick` without support for individual
822 * property identifiers.
825 * @param {Object} object The source object.
826 * @param {string[]} paths The property paths to pick.
827 * @returns {Object} Returns the new object.
829 function basePick(object, props) {
830 object = Object(object);
831 return reduce(props, function(result, key) {
833 result[key] = object[key];
840 * The base implementation of `_.rest` which doesn't validate or coerce arguments.
843 * @param {Function} func The function to apply a rest parameter to.
844 * @param {number} [start=func.length-1] The start position of the rest parameter.
845 * @returns {Function} Returns the new function.
847 function baseRest(func, start) {
848 return setToString(overRest(func, start, identity), func + '');
852 * The base implementation of `_.slice` without an iteratee call guard.
855 * @param {Array} array The array to slice.
856 * @param {number} [start=0] The start position.
857 * @param {number} [end=array.length] The end position.
858 * @returns {Array} Returns the slice of `array`.
860 function baseSlice(array, start, end) {
862 length = array.length;
865 start = -start > length ? 0 : (length + start);
867 end = end > length ? length : end;
871 length = start > end ? 0 : ((end - start) >>> 0);
874 var result = Array(length);
875 while (++index < length) {
876 result[index] = array[index + start];
882 * Copies the values of `source` to `array`.
885 * @param {Array} source The array to copy values from.
886 * @param {Array} [array=[]] The array to copy values to.
887 * @returns {Array} Returns `array`.
889 function copyArray(source) {
890 return baseSlice(source, 0, source.length);
894 * The base implementation of `_.some` without support for iteratee shorthands.
897 * @param {Array|Object} collection The collection to iterate over.
898 * @param {Function} predicate The function invoked per iteration.
899 * @returns {boolean} Returns `true` if any element passes the predicate check,
902 function baseSome(collection, predicate) {
905 baseEach(collection, function(value, index, collection) {
906 result = predicate(value, index, collection);
913 * The base implementation of `wrapperValue` which returns the result of
914 * performing a sequence of actions on the unwrapped `value`, where each
915 * successive action is supplied the return value of the previous.
918 * @param {*} value The unwrapped value.
919 * @param {Array} actions Actions to perform to resolve the unwrapped value.
920 * @returns {*} Returns the resolved value.
922 function baseWrapperValue(value, actions) {
924 return reduce(actions, function(result, action) {
925 return action.func.apply(action.thisArg, arrayPush([result], action.args));
930 * Compares values to sort them in ascending order.
933 * @param {*} value The value to compare.
934 * @param {*} other The other value to compare.
935 * @returns {number} Returns the sort order indicator for `value`.
937 function compareAscending(value, other) {
938 if (value !== other) {
939 var valIsDefined = value !== undefined,
940 valIsNull = value === null,
941 valIsReflexive = value === value,
944 var othIsDefined = other !== undefined,
945 othIsNull = other === null,
946 othIsReflexive = other === other,
949 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
950 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
951 (valIsNull && othIsDefined && othIsReflexive) ||
952 (!valIsDefined && othIsReflexive) ||
956 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
957 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
958 (othIsNull && valIsDefined && valIsReflexive) ||
959 (!othIsDefined && valIsReflexive) ||
968 * Copies properties of `source` to `object`.
971 * @param {Object} source The object to copy properties from.
972 * @param {Array} props The property identifiers to copy.
973 * @param {Object} [object={}] The object to copy properties to.
974 * @param {Function} [customizer] The function to customize copied values.
975 * @returns {Object} Returns `object`.
977 function copyObject(source, props, object, customizer) {
979 object || (object = {});
982 length = props.length;
984 while (++index < length) {
985 var key = props[index];
987 var newValue = customizer
988 ? customizer(object[key], source[key], key, object, source)
991 if (newValue === undefined) {
992 newValue = source[key];
995 baseAssignValue(object, key, newValue);
997 assignValue(object, key, newValue);
1004 * Creates a function like `_.assign`.
1007 * @param {Function} assigner The function to assign values.
1008 * @returns {Function} Returns the new assigner function.
1010 function createAssigner(assigner) {
1011 return baseRest(function(object, sources) {
1013 length = sources.length,
1014 customizer = length > 1 ? sources[length - 1] : undefined;
1016 customizer = (assigner.length > 3 && typeof customizer == 'function')
1017 ? (length--, customizer)
1020 object = Object(object);
1021 while (++index < length) {
1022 var source = sources[index];
1024 assigner(object, source, index, customizer);
1032 * Creates a `baseEach` or `baseEachRight` function.
1035 * @param {Function} eachFunc The function to iterate over a collection.
1036 * @param {boolean} [fromRight] Specify iterating from right to left.
1037 * @returns {Function} Returns the new base function.
1039 function createBaseEach(eachFunc, fromRight) {
1040 return function(collection, iteratee) {
1041 if (collection == null) {
1044 if (!isArrayLike(collection)) {
1045 return eachFunc(collection, iteratee);
1047 var length = collection.length,
1048 index = fromRight ? length : -1,
1049 iterable = Object(collection);
1051 while ((fromRight ? index-- : ++index < length)) {
1052 if (iteratee(iterable[index], index, iterable) === false) {
1061 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
1064 * @param {boolean} [fromRight] Specify iterating from right to left.
1065 * @returns {Function} Returns the new base function.
1067 function createBaseFor(fromRight) {
1068 return function(object, iteratee, keysFunc) {
1070 iterable = Object(object),
1071 props = keysFunc(object),
1072 length = props.length;
1075 var key = props[fromRight ? length : ++index];
1076 if (iteratee(iterable[key], key, iterable) === false) {
1085 * Creates a function that produces an instance of `Ctor` regardless of
1086 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
1089 * @param {Function} Ctor The constructor to wrap.
1090 * @returns {Function} Returns the new wrapped function.
1092 function createCtor(Ctor) {
1094 // Use a `switch` statement to work with class constructors. See
1095 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1096 // for more details.
1097 var args = arguments;
1098 var thisBinding = baseCreate(Ctor.prototype),
1099 result = Ctor.apply(thisBinding, args);
1101 // Mimic the constructor's `return` behavior.
1102 // See https://es5.github.io/#x13.2.2 for more details.
1103 return isObject(result) ? result : thisBinding;
1108 * Creates a `_.find` or `_.findLast` function.
1111 * @param {Function} findIndexFunc The function to find the collection index.
1112 * @returns {Function} Returns the new find function.
1114 function createFind(findIndexFunc) {
1115 return function(collection, predicate, fromIndex) {
1116 var iterable = Object(collection);
1117 if (!isArrayLike(collection)) {
1118 var iteratee = baseIteratee(predicate, 3);
1119 collection = keys(collection);
1120 predicate = function(key) { return iteratee(iterable[key], key, iterable); };
1122 var index = findIndexFunc(collection, predicate, fromIndex);
1123 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
1128 * Creates a function that wraps `func` to invoke it with the `this` binding
1129 * of `thisArg` and `partials` prepended to the arguments it receives.
1132 * @param {Function} func The function to wrap.
1133 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
1134 * @param {*} thisArg The `this` binding of `func`.
1135 * @param {Array} partials The arguments to prepend to those provided to
1137 * @returns {Function} Returns the new wrapped function.
1139 function createPartial(func, bitmask, thisArg, partials) {
1140 if (typeof func != 'function') {
1141 throw new TypeError(FUNC_ERROR_TEXT);
1143 var isBind = bitmask & WRAP_BIND_FLAG,
1144 Ctor = createCtor(func);
1146 function wrapper() {
1148 argsLength = arguments.length,
1150 leftLength = partials.length,
1151 args = Array(leftLength + argsLength),
1152 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
1154 while (++leftIndex < leftLength) {
1155 args[leftIndex] = partials[leftIndex];
1157 while (argsLength--) {
1158 args[leftIndex++] = arguments[++argsIndex];
1160 return fn.apply(isBind ? thisArg : this, args);
1166 * A specialized version of `baseIsEqualDeep` for arrays with support for
1167 * partial deep comparisons.
1170 * @param {Array} array The array to compare.
1171 * @param {Array} other The other array to compare.
1172 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1173 * @param {Function} customizer The function to customize comparisons.
1174 * @param {Function} equalFunc The function to determine equivalents of values.
1175 * @param {Object} stack Tracks traversed `array` and `other` objects.
1176 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1178 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
1179 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
1180 arrLength = array.length,
1181 othLength = other.length;
1183 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1186 // Check that cyclic values are equal.
1187 var arrStacked = stack.get(array);
1188 var othStacked = stack.get(other);
1189 if (arrStacked && othStacked) {
1190 return arrStacked == other && othStacked == array;
1194 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? [] : undefined;
1196 // Ignore non-index properties.
1197 while (++index < arrLength) {
1198 var arrValue = array[index],
1199 othValue = other[index];
1202 if (compared !== undefined) {
1209 // Recursively compare arrays (susceptible to call stack limits).
1211 if (!baseSome(other, function(othValue, othIndex) {
1212 if (!indexOf(seen, othIndex) &&
1213 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
1214 return seen.push(othIndex);
1221 arrValue === othValue ||
1222 equalFunc(arrValue, othValue, bitmask, customizer, stack)
1232 * A specialized version of `baseIsEqualDeep` for comparing objects of
1233 * the same `toStringTag`.
1235 * **Note:** This function only supports comparing values with tags of
1236 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1239 * @param {Object} object The object to compare.
1240 * @param {Object} other The other object to compare.
1241 * @param {string} tag The `toStringTag` of the objects to compare.
1242 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1243 * @param {Function} customizer The function to customize comparisons.
1244 * @param {Function} equalFunc The function to determine equivalents of values.
1245 * @param {Object} stack Tracks traversed `object` and `other` objects.
1246 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1248 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
1254 // Coerce booleans to `1` or `0` and dates to milliseconds.
1255 // Invalid dates are coerced to `NaN`.
1256 return eq(+object, +other);
1259 return object.name == other.name && object.message == other.message;
1263 // Coerce regexes to strings and treat strings, primitives and objects,
1264 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
1265 // for more details.
1266 return object == (other + '');
1273 * A specialized version of `baseIsEqualDeep` for objects with support for
1274 * partial deep comparisons.
1277 * @param {Object} object The object to compare.
1278 * @param {Object} other The other object to compare.
1279 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1280 * @param {Function} customizer The function to customize comparisons.
1281 * @param {Function} equalFunc The function to determine equivalents of values.
1282 * @param {Object} stack Tracks traversed `object` and `other` objects.
1283 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1285 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
1286 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
1287 objProps = keys(object),
1288 objLength = objProps.length,
1289 othProps = keys(other),
1290 othLength = othProps.length;
1292 if (objLength != othLength && !isPartial) {
1295 var index = objLength;
1297 var key = objProps[index];
1298 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1302 // Check that cyclic values are equal.
1303 var objStacked = stack.get(object);
1304 var othStacked = stack.get(other);
1305 if (objStacked && othStacked) {
1306 return objStacked == other && othStacked == object;
1310 var skipCtor = isPartial;
1311 while (++index < objLength) {
1312 key = objProps[index];
1313 var objValue = object[key],
1314 othValue = other[key];
1317 // Recursively compare objects (susceptible to call stack limits).
1318 if (!(compared === undefined
1319 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
1325 skipCtor || (skipCtor = key == 'constructor');
1327 if (result && !skipCtor) {
1328 var objCtor = object.constructor,
1329 othCtor = other.constructor;
1331 // Non `Object` object instances with different constructors are not equal.
1332 if (objCtor != othCtor &&
1333 ('constructor' in object && 'constructor' in other) &&
1334 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1335 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1343 * A specialized version of `baseRest` which flattens the rest array.
1346 * @param {Function} func The function to apply a rest parameter to.
1347 * @returns {Function} Returns the new function.
1349 function flatRest(func) {
1350 return setToString(overRest(func, undefined, flatten), func + '');
1354 * Checks if `value` is a flattenable `arguments` object or array.
1357 * @param {*} value The value to check.
1358 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
1360 function isFlattenable(value) {
1361 return isArray(value) || isArguments(value);
1365 * Checks if `value` is a valid array-like index.
1368 * @param {*} value The value to check.
1369 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1370 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1372 function isIndex(value, length) {
1373 var type = typeof value;
1374 length = length == null ? MAX_SAFE_INTEGER : length;
1377 (type == 'number' ||
1378 (type != 'symbol' && reIsUint.test(value))) &&
1379 (value > -1 && value % 1 == 0 && value < length);
1383 * Checks if the given arguments are from an iteratee call.
1386 * @param {*} value The potential iteratee value argument.
1387 * @param {*} index The potential iteratee index or key argument.
1388 * @param {*} object The potential iteratee object argument.
1389 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
1392 function isIterateeCall(value, index, object) {
1393 if (!isObject(object)) {
1396 var type = typeof index;
1397 if (type == 'number'
1398 ? (isArrayLike(object) && isIndex(index, object.length))
1399 : (type == 'string' && index in object)
1401 return eq(object[index], value);
1407 * This function is like
1408 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1409 * except that it includes inherited enumerable properties.
1412 * @param {Object} object The object to query.
1413 * @returns {Array} Returns the array of property names.
1415 function nativeKeysIn(object) {
1417 if (object != null) {
1418 for (var key in Object(object)) {
1426 * Converts `value` to a string using `Object.prototype.toString`.
1429 * @param {*} value The value to convert.
1430 * @returns {string} Returns the converted string.
1432 function objectToString(value) {
1433 return nativeObjectToString.call(value);
1437 * A specialized version of `baseRest` which transforms the rest array.
1440 * @param {Function} func The function to apply a rest parameter to.
1441 * @param {number} [start=func.length-1] The start position of the rest parameter.
1442 * @param {Function} transform The rest array transform.
1443 * @returns {Function} Returns the new function.
1445 function overRest(func, start, transform) {
1446 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
1448 var args = arguments,
1450 length = nativeMax(args.length - start, 0),
1451 array = Array(length);
1453 while (++index < length) {
1454 array[index] = args[start + index];
1457 var otherArgs = Array(start + 1);
1458 while (++index < start) {
1459 otherArgs[index] = args[index];
1461 otherArgs[start] = transform(array);
1462 return func.apply(this, otherArgs);
1467 * Sets the `toString` method of `func` to return `string`.
1470 * @param {Function} func The function to modify.
1471 * @param {Function} string The `toString` result.
1472 * @returns {Function} Returns `func`.
1474 var setToString = identity;
1476 /*------------------------------------------------------------------------*/
1479 * Creates an array with all falsey values removed. The values `false`, `null`,
1480 * `0`, `""`, `undefined`, and `NaN` are falsey.
1486 * @param {Array} array The array to compact.
1487 * @returns {Array} Returns the new array of filtered values.
1490 * _.compact([0, 1, false, 2, '', 3]);
1493 function compact(array) {
1494 return baseFilter(array, Boolean);
1498 * Creates a new array concatenating `array` with any additional arrays
1505 * @param {Array} array The array to concatenate.
1506 * @param {...*} [values] The values to concatenate.
1507 * @returns {Array} Returns the new concatenated array.
1511 * var other = _.concat(array, 2, [3], [[4]]);
1513 * console.log(other);
1514 * // => [1, 2, 3, [4]]
1516 * console.log(array);
1520 var length = arguments.length;
1524 var args = Array(length - 1),
1525 array = arguments[0],
1529 args[index - 1] = arguments[index];
1531 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
1535 * This method is like `_.find` except that it returns the index of the first
1536 * element `predicate` returns truthy for instead of the element itself.
1542 * @param {Array} array The array to inspect.
1543 * @param {Function} [predicate=_.identity] The function invoked per iteration.
1544 * @param {number} [fromIndex=0] The index to search from.
1545 * @returns {number} Returns the index of the found element, else `-1`.
1549 * { 'user': 'barney', 'active': false },
1550 * { 'user': 'fred', 'active': false },
1551 * { 'user': 'pebbles', 'active': true }
1554 * _.findIndex(users, function(o) { return o.user == 'barney'; });
1557 * // The `_.matches` iteratee shorthand.
1558 * _.findIndex(users, { 'user': 'fred', 'active': false });
1561 * // The `_.matchesProperty` iteratee shorthand.
1562 * _.findIndex(users, ['active', false]);
1565 * // The `_.property` iteratee shorthand.
1566 * _.findIndex(users, 'active');
1569 function findIndex(array, predicate, fromIndex) {
1570 var length = array == null ? 0 : array.length;
1574 var index = fromIndex == null ? 0 : toInteger(fromIndex);
1576 index = nativeMax(length + index, 0);
1578 return baseFindIndex(array, baseIteratee(predicate, 3), index);
1582 * Flattens `array` a single level deep.
1588 * @param {Array} array The array to flatten.
1589 * @returns {Array} Returns the new flattened array.
1592 * _.flatten([1, [2, [3, [4]], 5]]);
1593 * // => [1, 2, [3, [4]], 5]
1595 function flatten(array) {
1596 var length = array == null ? 0 : array.length;
1597 return length ? baseFlatten(array, 1) : [];
1601 * Recursively flattens `array`.
1607 * @param {Array} array The array to flatten.
1608 * @returns {Array} Returns the new flattened array.
1611 * _.flattenDeep([1, [2, [3, [4]], 5]]);
1612 * // => [1, 2, 3, 4, 5]
1614 function flattenDeep(array) {
1615 var length = array == null ? 0 : array.length;
1616 return length ? baseFlatten(array, INFINITY) : [];
1620 * Gets the first element of `array`.
1627 * @param {Array} array The array to query.
1628 * @returns {*} Returns the first element of `array`.
1631 * _.head([1, 2, 3]);
1637 function head(array) {
1638 return (array && array.length) ? array[0] : undefined;
1642 * Gets the index at which the first occurrence of `value` is found in `array`
1643 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1644 * for equality comparisons. If `fromIndex` is negative, it's used as the
1645 * offset from the end of `array`.
1651 * @param {Array} array The array to inspect.
1652 * @param {*} value The value to search for.
1653 * @param {number} [fromIndex=0] The index to search from.
1654 * @returns {number} Returns the index of the matched value, else `-1`.
1657 * _.indexOf([1, 2, 1, 2], 2);
1660 * // Search from the `fromIndex`.
1661 * _.indexOf([1, 2, 1, 2], 2, 2);
1664 function indexOf(array, value, fromIndex) {
1665 var length = array == null ? 0 : array.length;
1666 if (typeof fromIndex == 'number') {
1667 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1671 var index = (fromIndex || 0) - 1,
1672 isReflexive = value === value;
1674 while (++index < length) {
1675 var other = array[index];
1676 if ((isReflexive ? other === value : other !== other)) {
1684 * Gets the last element of `array`.
1690 * @param {Array} array The array to query.
1691 * @returns {*} Returns the last element of `array`.
1694 * _.last([1, 2, 3]);
1697 function last(array) {
1698 var length = array == null ? 0 : array.length;
1699 return length ? array[length - 1] : undefined;
1703 * Creates a slice of `array` from `start` up to, but not including, `end`.
1705 * **Note:** This method is used instead of
1706 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
1713 * @param {Array} array The array to slice.
1714 * @param {number} [start=0] The start position.
1715 * @param {number} [end=array.length] The end position.
1716 * @returns {Array} Returns the slice of `array`.
1718 function slice(array, start, end) {
1719 var length = array == null ? 0 : array.length;
1720 start = start == null ? 0 : +start;
1721 end = end === undefined ? length : +end;
1722 return length ? baseSlice(array, start, end) : [];
1725 /*------------------------------------------------------------------------*/
1728 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
1729 * chain sequences enabled. The result of such sequences must be unwrapped
1736 * @param {*} value The value to wrap.
1737 * @returns {Object} Returns the new `lodash` wrapper instance.
1741 * { 'user': 'barney', 'age': 36 },
1742 * { 'user': 'fred', 'age': 40 },
1743 * { 'user': 'pebbles', 'age': 1 }
1749 * .map(function(o) {
1750 * return o.user + ' is ' + o.age;
1754 * // => 'pebbles is 1'
1756 function chain(value) {
1757 var result = lodash(value);
1758 result.__chain__ = true;
1763 * This method invokes `interceptor` and returns `value`. The interceptor
1764 * is invoked with one argument; (value). The purpose of this method is to
1765 * "tap into" a method chain sequence in order to modify intermediate results.
1771 * @param {*} value The value to provide to `interceptor`.
1772 * @param {Function} interceptor The function to invoke.
1773 * @returns {*} Returns `value`.
1777 * .tap(function(array) {
1778 * // Mutate input array.
1785 function tap(value, interceptor) {
1791 * This method is like `_.tap` except that it returns the result of `interceptor`.
1792 * The purpose of this method is to "pass thru" values replacing intermediate
1793 * results in a method chain sequence.
1799 * @param {*} value The value to provide to `interceptor`.
1800 * @param {Function} interceptor The function to invoke.
1801 * @returns {*} Returns the result of `interceptor`.
1807 * .thru(function(value) {
1813 function thru(value, interceptor) {
1814 return interceptor(value);
1818 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
1824 * @returns {Object} Returns the new `lodash` wrapper instance.
1828 * { 'user': 'barney', 'age': 36 },
1829 * { 'user': 'fred', 'age': 40 }
1832 * // A sequence without explicit chaining.
1834 * // => { 'user': 'barney', 'age': 36 }
1836 * // A sequence with explicit chaining.
1842 * // => { 'user': 'barney' }
1844 function wrapperChain() {
1849 * Executes the chain sequence to resolve the unwrapped value.
1854 * @alias toJSON, valueOf
1856 * @returns {*} Returns the resolved unwrapped value.
1859 * _([1, 2, 3]).value();
1862 function wrapperValue() {
1863 return baseWrapperValue(this.__wrapped__, this.__actions__);
1866 /*------------------------------------------------------------------------*/
1869 * Checks if `predicate` returns truthy for **all** elements of `collection`.
1870 * Iteration is stopped once `predicate` returns falsey. The predicate is
1871 * invoked with three arguments: (value, index|key, collection).
1873 * **Note:** This method returns `true` for
1874 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
1875 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
1876 * elements of empty collections.
1881 * @category Collection
1882 * @param {Array|Object} collection The collection to iterate over.
1883 * @param {Function} [predicate=_.identity] The function invoked per iteration.
1884 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
1885 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1889 * _.every([true, 1, null, 'yes'], Boolean);
1893 * { 'user': 'barney', 'age': 36, 'active': false },
1894 * { 'user': 'fred', 'age': 40, 'active': false }
1897 * // The `_.matches` iteratee shorthand.
1898 * _.every(users, { 'user': 'barney', 'active': false });
1901 * // The `_.matchesProperty` iteratee shorthand.
1902 * _.every(users, ['active', false]);
1905 * // The `_.property` iteratee shorthand.
1906 * _.every(users, 'active');
1909 function every(collection, predicate, guard) {
1910 predicate = guard ? undefined : predicate;
1911 return baseEvery(collection, baseIteratee(predicate));
1915 * Iterates over elements of `collection`, returning an array of all elements
1916 * `predicate` returns truthy for. The predicate is invoked with three
1917 * arguments: (value, index|key, collection).
1919 * **Note:** Unlike `_.remove`, this method returns a new array.
1924 * @category Collection
1925 * @param {Array|Object} collection The collection to iterate over.
1926 * @param {Function} [predicate=_.identity] The function invoked per iteration.
1927 * @returns {Array} Returns the new filtered array.
1932 * { 'user': 'barney', 'age': 36, 'active': true },
1933 * { 'user': 'fred', 'age': 40, 'active': false }
1936 * _.filter(users, function(o) { return !o.active; });
1937 * // => objects for ['fred']
1939 * // The `_.matches` iteratee shorthand.
1940 * _.filter(users, { 'age': 36, 'active': true });
1941 * // => objects for ['barney']
1943 * // The `_.matchesProperty` iteratee shorthand.
1944 * _.filter(users, ['active', false]);
1945 * // => objects for ['fred']
1947 * // The `_.property` iteratee shorthand.
1948 * _.filter(users, 'active');
1949 * // => objects for ['barney']
1951 * // Combining several predicates using `_.overEvery` or `_.overSome`.
1952 * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
1953 * // => objects for ['fred', 'barney']
1955 function filter(collection, predicate) {
1956 return baseFilter(collection, baseIteratee(predicate));
1960 * Iterates over elements of `collection`, returning the first element
1961 * `predicate` returns truthy for. The predicate is invoked with three
1962 * arguments: (value, index|key, collection).
1967 * @category Collection
1968 * @param {Array|Object} collection The collection to inspect.
1969 * @param {Function} [predicate=_.identity] The function invoked per iteration.
1970 * @param {number} [fromIndex=0] The index to search from.
1971 * @returns {*} Returns the matched element, else `undefined`.
1975 * { 'user': 'barney', 'age': 36, 'active': true },
1976 * { 'user': 'fred', 'age': 40, 'active': false },
1977 * { 'user': 'pebbles', 'age': 1, 'active': true }
1980 * _.find(users, function(o) { return o.age < 40; });
1981 * // => object for 'barney'
1983 * // The `_.matches` iteratee shorthand.
1984 * _.find(users, { 'age': 1, 'active': true });
1985 * // => object for 'pebbles'
1987 * // The `_.matchesProperty` iteratee shorthand.
1988 * _.find(users, ['active', false]);
1989 * // => object for 'fred'
1991 * // The `_.property` iteratee shorthand.
1992 * _.find(users, 'active');
1993 * // => object for 'barney'
1995 var find = createFind(findIndex);
1998 * Iterates over elements of `collection` and invokes `iteratee` for each element.
1999 * The iteratee is invoked with three arguments: (value, index|key, collection).
2000 * Iteratee functions may exit iteration early by explicitly returning `false`.
2002 * **Note:** As with other "Collections" methods, objects with a "length"
2003 * property are iterated like arrays. To avoid this behavior use `_.forIn`
2004 * or `_.forOwn` for object iteration.
2010 * @category Collection
2011 * @param {Array|Object} collection The collection to iterate over.
2012 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
2013 * @returns {Array|Object} Returns `collection`.
2014 * @see _.forEachRight
2017 * _.forEach([1, 2], function(value) {
2018 * console.log(value);
2020 * // => Logs `1` then `2`.
2022 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
2025 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
2027 function forEach(collection, iteratee) {
2028 return baseEach(collection, baseIteratee(iteratee));
2032 * Creates an array of values by running each element in `collection` thru
2033 * `iteratee`. The iteratee is invoked with three arguments:
2034 * (value, index|key, collection).
2036 * Many lodash methods are guarded to work as iteratees for methods like
2037 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
2039 * The guarded methods are:
2040 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
2041 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
2042 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
2043 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
2048 * @category Collection
2049 * @param {Array|Object} collection The collection to iterate over.
2050 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
2051 * @returns {Array} Returns the new mapped array.
2054 * function square(n) {
2058 * _.map([4, 8], square);
2061 * _.map({ 'a': 4, 'b': 8 }, square);
2062 * // => [16, 64] (iteration order is not guaranteed)
2065 * { 'user': 'barney' },
2066 * { 'user': 'fred' }
2069 * // The `_.property` iteratee shorthand.
2070 * _.map(users, 'user');
2071 * // => ['barney', 'fred']
2073 function map(collection, iteratee) {
2074 return baseMap(collection, baseIteratee(iteratee));
2078 * Reduces `collection` to a value which is the accumulated result of running
2079 * each element in `collection` thru `iteratee`, where each successive
2080 * invocation is supplied the return value of the previous. If `accumulator`
2081 * is not given, the first element of `collection` is used as the initial
2082 * value. The iteratee is invoked with four arguments:
2083 * (accumulator, value, index|key, collection).
2085 * Many lodash methods are guarded to work as iteratees for methods like
2086 * `_.reduce`, `_.reduceRight`, and `_.transform`.
2088 * The guarded methods are:
2089 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
2095 * @category Collection
2096 * @param {Array|Object} collection The collection to iterate over.
2097 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
2098 * @param {*} [accumulator] The initial value.
2099 * @returns {*} Returns the accumulated value.
2100 * @see _.reduceRight
2103 * _.reduce([1, 2], function(sum, n) {
2108 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
2109 * (result[value] || (result[value] = [])).push(key);
2112 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
2114 function reduce(collection, iteratee, accumulator) {
2115 return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
2119 * Gets the size of `collection` by returning its length for array-like
2120 * values or the number of own enumerable string keyed properties for objects.
2125 * @category Collection
2126 * @param {Array|Object|string} collection The collection to inspect.
2127 * @returns {number} Returns the collection size.
2130 * _.size([1, 2, 3]);
2133 * _.size({ 'a': 1, 'b': 2 });
2136 * _.size('pebbles');
2139 function size(collection) {
2140 if (collection == null) {
2143 collection = isArrayLike(collection) ? collection : nativeKeys(collection);
2144 return collection.length;
2148 * Checks if `predicate` returns truthy for **any** element of `collection`.
2149 * Iteration is stopped once `predicate` returns truthy. The predicate is
2150 * invoked with three arguments: (value, index|key, collection).
2155 * @category Collection
2156 * @param {Array|Object} collection The collection to iterate over.
2157 * @param {Function} [predicate=_.identity] The function invoked per iteration.
2158 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
2159 * @returns {boolean} Returns `true` if any element passes the predicate check,
2163 * _.some([null, 0, 'yes', false], Boolean);
2167 * { 'user': 'barney', 'active': true },
2168 * { 'user': 'fred', 'active': false }
2171 * // The `_.matches` iteratee shorthand.
2172 * _.some(users, { 'user': 'barney', 'active': false });
2175 * // The `_.matchesProperty` iteratee shorthand.
2176 * _.some(users, ['active', false]);
2179 * // The `_.property` iteratee shorthand.
2180 * _.some(users, 'active');
2183 function some(collection, predicate, guard) {
2184 predicate = guard ? undefined : predicate;
2185 return baseSome(collection, baseIteratee(predicate));
2189 * Creates an array of elements, sorted in ascending order by the results of
2190 * running each element in a collection thru each iteratee. This method
2191 * performs a stable sort, that is, it preserves the original sort order of
2192 * equal elements. The iteratees are invoked with one argument: (value).
2197 * @category Collection
2198 * @param {Array|Object} collection The collection to iterate over.
2199 * @param {...(Function|Function[])} [iteratees=[_.identity]]
2200 * The iteratees to sort by.
2201 * @returns {Array} Returns the new sorted array.
2205 * { 'user': 'fred', 'age': 48 },
2206 * { 'user': 'barney', 'age': 36 },
2207 * { 'user': 'fred', 'age': 30 },
2208 * { 'user': 'barney', 'age': 34 }
2211 * _.sortBy(users, [function(o) { return o.user; }]);
2212 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
2214 * _.sortBy(users, ['user', 'age']);
2215 * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
2217 function sortBy(collection, iteratee) {
2219 iteratee = baseIteratee(iteratee);
2221 return baseMap(baseMap(collection, function(value, key, collection) {
2222 return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2223 }).sort(function(object, other) {
2224 return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2225 }), baseProperty('value'));
2228 /*------------------------------------------------------------------------*/
2231 * Creates a function that invokes `func`, with the `this` binding and arguments
2232 * of the created function, while it's called less than `n` times. Subsequent
2233 * calls to the created function return the result of the last `func` invocation.
2238 * @category Function
2239 * @param {number} n The number of calls at which `func` is no longer invoked.
2240 * @param {Function} func The function to restrict.
2241 * @returns {Function} Returns the new restricted function.
2244 * jQuery(element).on('click', _.before(5, addContactToList));
2245 * // => Allows adding up to 4 contacts to the list.
2247 function before(n, func) {
2249 if (typeof func != 'function') {
2250 throw new TypeError(FUNC_ERROR_TEXT);
2255 result = func.apply(this, arguments);
2265 * Creates a function that invokes `func` with the `this` binding of `thisArg`
2266 * and `partials` prepended to the arguments it receives.
2268 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2269 * may be used as a placeholder for partially applied arguments.
2271 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
2272 * property of bound functions.
2277 * @category Function
2278 * @param {Function} func The function to bind.
2279 * @param {*} thisArg The `this` binding of `func`.
2280 * @param {...*} [partials] The arguments to be partially applied.
2281 * @returns {Function} Returns the new bound function.
2284 * function greet(greeting, punctuation) {
2285 * return greeting + ' ' + this.user + punctuation;
2288 * var object = { 'user': 'fred' };
2290 * var bound = _.bind(greet, object, 'hi');
2294 * // Bound with placeholders.
2295 * var bound = _.bind(greet, object, _, '!');
2299 var bind = baseRest(function(func, thisArg, partials) {
2300 return createPartial(func, WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG, thisArg, partials);
2304 * Defers invoking the `func` until the current call stack has cleared. Any
2305 * additional arguments are provided to `func` when it's invoked.
2310 * @category Function
2311 * @param {Function} func The function to defer.
2312 * @param {...*} [args] The arguments to invoke `func` with.
2313 * @returns {number} Returns the timer id.
2316 * _.defer(function(text) {
2317 * console.log(text);
2319 * // => Logs 'deferred' after one millisecond.
2321 var defer = baseRest(function(func, args) {
2322 return baseDelay(func, 1, args);
2326 * Invokes `func` after `wait` milliseconds. Any additional arguments are
2327 * provided to `func` when it's invoked.
2332 * @category Function
2333 * @param {Function} func The function to delay.
2334 * @param {number} wait The number of milliseconds to delay invocation.
2335 * @param {...*} [args] The arguments to invoke `func` with.
2336 * @returns {number} Returns the timer id.
2339 * _.delay(function(text) {
2340 * console.log(text);
2341 * }, 1000, 'later');
2342 * // => Logs 'later' after one second.
2344 var delay = baseRest(function(func, wait, args) {
2345 return baseDelay(func, toNumber(wait) || 0, args);
2349 * Creates a function that negates the result of the predicate `func`. The
2350 * `func` predicate is invoked with the `this` binding and arguments of the
2356 * @category Function
2357 * @param {Function} predicate The predicate to negate.
2358 * @returns {Function} Returns the new negated function.
2361 * function isEven(n) {
2362 * return n % 2 == 0;
2365 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2368 function negate(predicate) {
2369 if (typeof predicate != 'function') {
2370 throw new TypeError(FUNC_ERROR_TEXT);
2373 var args = arguments;
2374 return !predicate.apply(this, args);
2379 * Creates a function that is restricted to invoking `func` once. Repeat calls
2380 * to the function return the value of the first invocation. The `func` is
2381 * invoked with the `this` binding and arguments of the created function.
2386 * @category Function
2387 * @param {Function} func The function to restrict.
2388 * @returns {Function} Returns the new restricted function.
2391 * var initialize = _.once(createApplication);
2394 * // => `createApplication` is invoked once
2396 function once(func) {
2397 return before(2, func);
2400 /*------------------------------------------------------------------------*/
2403 * Creates a shallow clone of `value`.
2405 * **Note:** This method is loosely based on the
2406 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2407 * and supports cloning arrays, array buffers, booleans, date objects, maps,
2408 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2409 * arrays. The own enumerable properties of `arguments` objects are cloned
2410 * as plain objects. An empty object is returned for uncloneable values such
2411 * as error objects, functions, DOM nodes, and WeakMaps.
2417 * @param {*} value The value to clone.
2418 * @returns {*} Returns the cloned value.
2422 * var objects = [{ 'a': 1 }, { 'b': 2 }];
2424 * var shallow = _.clone(objects);
2425 * console.log(shallow[0] === objects[0]);
2428 function clone(value) {
2429 if (!isObject(value)) {
2432 return isArray(value) ? copyArray(value) : copyObject(value, nativeKeys(value));
2437 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
2438 * comparison between two values to determine if they are equivalent.
2444 * @param {*} value The value to compare.
2445 * @param {*} other The other value to compare.
2446 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2449 * var object = { 'a': 1 };
2450 * var other = { 'a': 1 };
2452 * _.eq(object, object);
2455 * _.eq(object, other);
2461 * _.eq('a', Object('a'));
2467 function eq(value, other) {
2468 return value === other || (value !== value && other !== other);
2472 * Checks if `value` is likely an `arguments` object.
2478 * @param {*} value The value to check.
2479 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
2483 * _.isArguments(function() { return arguments; }());
2486 * _.isArguments([1, 2, 3]);
2489 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
2490 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
2491 !propertyIsEnumerable.call(value, 'callee');
2495 * Checks if `value` is classified as an `Array` object.
2501 * @param {*} value The value to check.
2502 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
2505 * _.isArray([1, 2, 3]);
2508 * _.isArray(document.body.children);
2514 * _.isArray(_.noop);
2517 var isArray = Array.isArray;
2520 * Checks if `value` is array-like. A value is considered array-like if it's
2521 * not a function and has a `value.length` that's an integer greater than or
2522 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2528 * @param {*} value The value to check.
2529 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2532 * _.isArrayLike([1, 2, 3]);
2535 * _.isArrayLike(document.body.children);
2538 * _.isArrayLike('abc');
2541 * _.isArrayLike(_.noop);
2544 function isArrayLike(value) {
2545 return value != null && isLength(value.length) && !isFunction(value);
2549 * Checks if `value` is classified as a boolean primitive or object.
2555 * @param {*} value The value to check.
2556 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
2559 * _.isBoolean(false);
2562 * _.isBoolean(null);
2565 function isBoolean(value) {
2566 return value === true || value === false ||
2567 (isObjectLike(value) && baseGetTag(value) == boolTag);
2571 * Checks if `value` is classified as a `Date` object.
2577 * @param {*} value The value to check.
2578 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
2581 * _.isDate(new Date);
2584 * _.isDate('Mon April 23 2012');
2587 var isDate = baseIsDate;
2590 * Checks if `value` is an empty object, collection, map, or set.
2592 * Objects are considered empty if they have no own enumerable string keyed
2595 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
2596 * jQuery-like collections are considered empty if they have a `length` of `0`.
2597 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
2603 * @param {*} value The value to check.
2604 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2616 * _.isEmpty([1, 2, 3]);
2619 * _.isEmpty({ 'a': 1 });
2622 function isEmpty(value) {
2623 if (isArrayLike(value) &&
2624 (isArray(value) || isString(value) ||
2625 isFunction(value.splice) || isArguments(value))) {
2626 return !value.length;
2628 return !nativeKeys(value).length;
2632 * Performs a deep comparison between two values to determine if they are
2635 * **Note:** This method supports comparing arrays, array buffers, booleans,
2636 * date objects, error objects, maps, numbers, `Object` objects, regexes,
2637 * sets, strings, symbols, and typed arrays. `Object` objects are compared
2638 * by their own, not inherited, enumerable properties. Functions and DOM
2639 * nodes are compared by strict equality, i.e. `===`.
2645 * @param {*} value The value to compare.
2646 * @param {*} other The other value to compare.
2647 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2650 * var object = { 'a': 1 };
2651 * var other = { 'a': 1 };
2653 * _.isEqual(object, other);
2659 function isEqual(value, other) {
2660 return baseIsEqual(value, other);
2664 * Checks if `value` is a finite primitive number.
2666 * **Note:** This method is based on
2667 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
2673 * @param {*} value The value to check.
2674 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
2680 * _.isFinite(Number.MIN_VALUE);
2683 * _.isFinite(Infinity);
2689 function isFinite(value) {
2690 return typeof value == 'number' && nativeIsFinite(value);
2694 * Checks if `value` is classified as a `Function` object.
2700 * @param {*} value The value to check.
2701 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
2707 * _.isFunction(/abc/);
2710 function isFunction(value) {
2711 if (!isObject(value)) {
2714 // The use of `Object#toString` avoids issues with the `typeof` operator
2715 // in Safari 9 which returns 'object' for typed arrays and other constructors.
2716 var tag = baseGetTag(value);
2717 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
2721 * Checks if `value` is a valid array-like length.
2723 * **Note:** This method is loosely based on
2724 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
2730 * @param {*} value The value to check.
2731 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
2737 * _.isLength(Number.MIN_VALUE);
2740 * _.isLength(Infinity);
2746 function isLength(value) {
2747 return typeof value == 'number' &&
2748 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2752 * Checks if `value` is the
2753 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
2754 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2760 * @param {*} value The value to check.
2761 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2767 * _.isObject([1, 2, 3]);
2770 * _.isObject(_.noop);
2776 function isObject(value) {
2777 var type = typeof value;
2778 return value != null && (type == 'object' || type == 'function');
2782 * Checks if `value` is object-like. A value is object-like if it's not `null`
2783 * and has a `typeof` result of "object".
2789 * @param {*} value The value to check.
2790 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2793 * _.isObjectLike({});
2796 * _.isObjectLike([1, 2, 3]);
2799 * _.isObjectLike(_.noop);
2802 * _.isObjectLike(null);
2805 function isObjectLike(value) {
2806 return value != null && typeof value == 'object';
2810 * Checks if `value` is `NaN`.
2812 * **Note:** This method is based on
2813 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
2814 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
2815 * `undefined` and other non-number values.
2821 * @param {*} value The value to check.
2822 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2828 * _.isNaN(new Number(NaN));
2834 * _.isNaN(undefined);
2837 function isNaN(value) {
2838 // An `NaN` primitive is the only value that is not equal to itself.
2839 // Perform the `toStringTag` check first to avoid errors with some
2840 // ActiveX objects in IE.
2841 return isNumber(value) && value != +value;
2845 * Checks if `value` is `null`.
2851 * @param {*} value The value to check.
2852 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2861 function isNull(value) {
2862 return value === null;
2866 * Checks if `value` is classified as a `Number` primitive or object.
2868 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
2869 * classified as numbers, use the `_.isFinite` method.
2875 * @param {*} value The value to check.
2876 * @returns {boolean} Returns `true` if `value` is a number, else `false`.
2882 * _.isNumber(Number.MIN_VALUE);
2885 * _.isNumber(Infinity);
2891 function isNumber(value) {
2892 return typeof value == 'number' ||
2893 (isObjectLike(value) && baseGetTag(value) == numberTag);
2897 * Checks if `value` is classified as a `RegExp` object.
2903 * @param {*} value The value to check.
2904 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
2907 * _.isRegExp(/abc/);
2910 * _.isRegExp('/abc/');
2913 var isRegExp = baseIsRegExp;
2916 * Checks if `value` is classified as a `String` primitive or object.
2922 * @param {*} value The value to check.
2923 * @returns {boolean} Returns `true` if `value` is a string, else `false`.
2926 * _.isString('abc');
2932 function isString(value) {
2933 return typeof value == 'string' ||
2934 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
2938 * Checks if `value` is `undefined`.
2944 * @param {*} value The value to check.
2945 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
2948 * _.isUndefined(void 0);
2951 * _.isUndefined(null);
2954 function isUndefined(value) {
2955 return value === undefined;
2959 * Converts `value` to an array.
2965 * @param {*} value The value to convert.
2966 * @returns {Array} Returns the converted array.
2969 * _.toArray({ 'a': 1, 'b': 2 });
2973 * // => ['a', 'b', 'c']
2981 function toArray(value) {
2982 if (!isArrayLike(value)) {
2983 return values(value);
2985 return value.length ? copyArray(value) : [];
2989 * Converts `value` to an integer.
2991 * **Note:** This method is loosely based on
2992 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
2998 * @param {*} value The value to convert.
2999 * @returns {number} Returns the converted integer.
3005 * _.toInteger(Number.MIN_VALUE);
3008 * _.toInteger(Infinity);
3009 * // => 1.7976931348623157e+308
3011 * _.toInteger('3.2');
3014 var toInteger = Number;
3017 * Converts `value` to a number.
3023 * @param {*} value The value to process.
3024 * @returns {number} Returns the number.
3030 * _.toNumber(Number.MIN_VALUE);
3033 * _.toNumber(Infinity);
3036 * _.toNumber('3.2');
3039 var toNumber = Number;
3042 * Converts `value` to a string. An empty string is returned for `null`
3043 * and `undefined` values. The sign of `-0` is preserved.
3049 * @param {*} value The value to convert.
3050 * @returns {string} Returns the converted string.
3059 * _.toString([1, 2, 3]);
3062 function toString(value) {
3063 if (typeof value == 'string') {
3066 return value == null ? '' : (value + '');
3069 /*------------------------------------------------------------------------*/
3072 * Assigns own enumerable string keyed properties of source objects to the
3073 * destination object. Source objects are applied from left to right.
3074 * Subsequent sources overwrite property assignments of previous sources.
3076 * **Note:** This method mutates `object` and is loosely based on
3077 * [`Object.assign`](https://mdn.io/Object/assign).
3083 * @param {Object} object The destination object.
3084 * @param {...Object} [sources] The source objects.
3085 * @returns {Object} Returns `object`.
3097 * Foo.prototype.b = 2;
3098 * Bar.prototype.d = 4;
3100 * _.assign({ 'a': 0 }, new Foo, new Bar);
3101 * // => { 'a': 1, 'c': 3 }
3103 var assign = createAssigner(function(object, source) {
3104 copyObject(source, nativeKeys(source), object);
3108 * This method is like `_.assign` except that it iterates over own and
3109 * inherited source properties.
3111 * **Note:** This method mutates `object`.
3118 * @param {Object} object The destination object.
3119 * @param {...Object} [sources] The source objects.
3120 * @returns {Object} Returns `object`.
3132 * Foo.prototype.b = 2;
3133 * Bar.prototype.d = 4;
3135 * _.assignIn({ 'a': 0 }, new Foo, new Bar);
3136 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
3138 var assignIn = createAssigner(function(object, source) {
3139 copyObject(source, nativeKeysIn(source), object);
3143 * Creates an object that inherits from the `prototype` object. If a
3144 * `properties` object is given, its own enumerable string keyed properties
3145 * are assigned to the created object.
3151 * @param {Object} prototype The object to inherit from.
3152 * @param {Object} [properties] The properties to assign to the object.
3153 * @returns {Object} Returns the new object.
3156 * function Shape() {
3161 * function Circle() {
3165 * Circle.prototype = _.create(Shape.prototype, {
3166 * 'constructor': Circle
3169 * var circle = new Circle;
3170 * circle instanceof Circle;
3173 * circle instanceof Shape;
3176 function create(prototype, properties) {
3177 var result = baseCreate(prototype);
3178 return properties == null ? result : assign(result, properties);
3182 * Assigns own and inherited enumerable string keyed properties of source
3183 * objects to the destination object for all destination properties that
3184 * resolve to `undefined`. Source objects are applied from left to right.
3185 * Once a property is set, additional values of the same property are ignored.
3187 * **Note:** This method mutates `object`.
3193 * @param {Object} object The destination object.
3194 * @param {...Object} [sources] The source objects.
3195 * @returns {Object} Returns `object`.
3196 * @see _.defaultsDeep
3199 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3200 * // => { 'a': 1, 'b': 2 }
3202 var defaults = baseRest(function(object, sources) {
3203 object = Object(object);
3206 var length = sources.length;
3207 var guard = length > 2 ? sources[2] : undefined;
3209 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
3213 while (++index < length) {
3214 var source = sources[index];
3215 var props = keysIn(source);
3216 var propsIndex = -1;
3217 var propsLength = props.length;
3219 while (++propsIndex < propsLength) {
3220 var key = props[propsIndex];
3221 var value = object[key];
3223 if (value === undefined ||
3224 (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
3225 object[key] = source[key];
3234 * Checks if `path` is a direct property of `object`.
3240 * @param {Object} object The object to query.
3241 * @param {Array|string} path The path to check.
3242 * @returns {boolean} Returns `true` if `path` exists, else `false`.
3245 * var object = { 'a': { 'b': 2 } };
3246 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
3248 * _.has(object, 'a');
3251 * _.has(object, 'a.b');
3254 * _.has(object, ['a', 'b']);
3257 * _.has(other, 'a');
3260 function has(object, path) {
3261 return object != null && hasOwnProperty.call(object, path);
3265 * Creates an array of the own enumerable property names of `object`.
3267 * **Note:** Non-object values are coerced to objects. See the
3268 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
3275 * @param {Object} object The object to query.
3276 * @returns {Array} Returns the array of property names.
3284 * Foo.prototype.c = 3;
3287 * // => ['a', 'b'] (iteration order is not guaranteed)
3292 var keys = nativeKeys;
3295 * Creates an array of the own and inherited enumerable property names of `object`.
3297 * **Note:** Non-object values are coerced to objects.
3303 * @param {Object} object The object to query.
3304 * @returns {Array} Returns the array of property names.
3312 * Foo.prototype.c = 3;
3314 * _.keysIn(new Foo);
3315 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3317 var keysIn = nativeKeysIn;
3320 * Creates an object composed of the picked `object` properties.
3326 * @param {Object} object The source object.
3327 * @param {...(string|string[])} [paths] The property paths to pick.
3328 * @returns {Object} Returns the new object.
3331 * var object = { 'a': 1, 'b': '2', 'c': 3 };
3333 * _.pick(object, ['a', 'c']);
3334 * // => { 'a': 1, 'c': 3 }
3336 var pick = flatRest(function(object, paths) {
3337 return object == null ? {} : basePick(object, paths);
3341 * This method is like `_.get` except that if the resolved value is a
3342 * function it's invoked with the `this` binding of its parent object and
3343 * its result is returned.
3349 * @param {Object} object The object to query.
3350 * @param {Array|string} path The path of the property to resolve.
3351 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
3352 * @returns {*} Returns the resolved value.
3355 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3357 * _.result(object, 'a[0].b.c1');
3360 * _.result(object, 'a[0].b.c2');
3363 * _.result(object, 'a[0].b.c3', 'default');
3366 * _.result(object, 'a[0].b.c3', _.constant('default'));
3369 function result(object, path, defaultValue) {
3370 var value = object == null ? undefined : object[path];
3371 if (value === undefined) {
3372 value = defaultValue;
3374 return isFunction(value) ? value.call(object) : value;
3378 * Creates an array of the own enumerable string keyed property values of `object`.
3380 * **Note:** Non-object values are coerced to objects.
3386 * @param {Object} object The object to query.
3387 * @returns {Array} Returns the array of property values.
3395 * Foo.prototype.c = 3;
3397 * _.values(new Foo);
3398 * // => [1, 2] (iteration order is not guaranteed)
3403 function values(object) {
3404 return object == null ? [] : baseValues(object, keys(object));
3407 /*------------------------------------------------------------------------*/
3410 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
3411 * corresponding HTML entities.
3413 * **Note:** No other characters are escaped. To escape additional
3414 * characters use a third-party library like [_he_](https://mths.be/he).
3416 * Though the ">" character is escaped for symmetry, characters like
3417 * ">" and "/" don't need escaping in HTML and have no special meaning
3418 * unless they're part of a tag or unquoted attribute value. See
3419 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3420 * (under "semi-related fun fact") for more details.
3422 * When working with HTML you should always
3423 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
3430 * @param {string} [string=''] The string to escape.
3431 * @returns {string} Returns the escaped string.
3434 * _.escape('fred, barney, & pebbles');
3435 * // => 'fred, barney, & pebbles'
3437 function escape(string) {
3438 string = toString(string);
3439 return (string && reHasUnescapedHtml.test(string))
3440 ? string.replace(reUnescapedHtml, escapeHtmlChar)
3444 /*------------------------------------------------------------------------*/
3447 * This method returns the first argument it receives.
3453 * @param {*} value Any value.
3454 * @returns {*} Returns `value`.
3457 * var object = { 'a': 1 };
3459 * console.log(_.identity(object) === object);
3462 function identity(value) {
3467 * Creates a function that invokes `func` with the arguments of the created
3468 * function. If `func` is a property name, the created function returns the
3469 * property value for a given element. If `func` is an array or object, the
3470 * created function returns `true` for elements that contain the equivalent
3471 * source properties, otherwise it returns `false`.
3477 * @param {*} [func=_.identity] The value to convert to a callback.
3478 * @returns {Function} Returns the callback.
3482 * { 'user': 'barney', 'age': 36, 'active': true },
3483 * { 'user': 'fred', 'age': 40, 'active': false }
3486 * // The `_.matches` iteratee shorthand.
3487 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
3488 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
3490 * // The `_.matchesProperty` iteratee shorthand.
3491 * _.filter(users, _.iteratee(['user', 'fred']));
3492 * // => [{ 'user': 'fred', 'age': 40 }]
3494 * // The `_.property` iteratee shorthand.
3495 * _.map(users, _.iteratee('user'));
3496 * // => ['barney', 'fred']
3498 * // Create custom iteratee shorthands.
3499 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
3500 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
3501 * return func.test(string);
3505 * _.filter(['abc', 'def'], /ef/);
3508 var iteratee = baseIteratee;
3511 * Creates a function that performs a partial deep comparison between a given
3512 * object and `source`, returning `true` if the given object has equivalent
3513 * property values, else `false`.
3515 * **Note:** The created function is equivalent to `_.isMatch` with `source`
3516 * partially applied.
3518 * Partial comparisons will match empty array and empty object `source`
3519 * values against any array or object value, respectively. See `_.isEqual`
3520 * for a list of supported value comparisons.
3522 * **Note:** Multiple values can be checked by combining several matchers
3523 * using `_.overSome`
3529 * @param {Object} source The object of property values to match.
3530 * @returns {Function} Returns the new spec function.
3534 * { 'a': 1, 'b': 2, 'c': 3 },
3535 * { 'a': 4, 'b': 5, 'c': 6 }
3538 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
3539 * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
3541 * // Checking for several possible values
3542 * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
3543 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
3545 function matches(source) {
3546 return baseMatches(assign({}, source));
3550 * Adds all own enumerable string keyed function properties of a source
3551 * object to the destination object. If `object` is a function, then methods
3552 * are added to its prototype as well.
3554 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3555 * avoid conflicts caused by modifying the original.
3561 * @param {Function|Object} [object=lodash] The destination object.
3562 * @param {Object} source The object of functions to add.
3563 * @param {Object} [options={}] The options object.
3564 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
3565 * @returns {Function|Object} Returns `object`.
3568 * function vowels(string) {
3569 * return _.filter(string, function(v) {
3570 * return /[aeiou]/i.test(v);
3574 * _.mixin({ 'vowels': vowels });
3578 * _('fred').vowels().value();
3581 * _.mixin({ 'vowels': vowels }, { 'chain': false });
3582 * _('fred').vowels();
3585 function mixin(object, source, options) {
3586 var props = keys(source),
3587 methodNames = baseFunctions(source, props);
3589 if (options == null &&
3590 !(isObject(source) && (methodNames.length || !props.length))) {
3594 methodNames = baseFunctions(source, keys(source));
3596 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
3597 isFunc = isFunction(object);
3599 baseEach(methodNames, function(methodName) {
3600 var func = source[methodName];
3601 object[methodName] = func;
3603 object.prototype[methodName] = function() {
3604 var chainAll = this.__chain__;
3605 if (chain || chainAll) {
3606 var result = object(this.__wrapped__),
3607 actions = result.__actions__ = copyArray(this.__actions__);
3609 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3610 result.__chain__ = chainAll;
3613 return func.apply(object, arrayPush([this.value()], arguments));
3622 * Reverts the `_` variable to its previous value and returns a reference to
3623 * the `lodash` function.
3629 * @returns {Function} Returns the `lodash` function.
3632 * var lodash = _.noConflict();
3634 function noConflict() {
3635 if (root._ === this) {
3642 * This method returns `undefined`.
3650 * _.times(2, _.noop);
3651 * // => [undefined, undefined]
3654 // No operation performed.
3658 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
3664 * @param {string} [prefix=''] The value to prefix the ID with.
3665 * @returns {string} Returns the unique ID.
3668 * _.uniqueId('contact_');
3669 * // => 'contact_104'
3674 function uniqueId(prefix) {
3675 var id = ++idCounter;
3676 return toString(prefix) + id;
3679 /*------------------------------------------------------------------------*/
3682 * Computes the maximum value of `array`. If `array` is empty or falsey,
3683 * `undefined` is returned.
3689 * @param {Array} array The array to iterate over.
3690 * @returns {*} Returns the maximum value.
3693 * _.max([4, 2, 8, 6]);
3699 function max(array) {
3700 return (array && array.length)
3701 ? baseExtremum(array, identity, baseGt)
3706 * Computes the minimum value of `array`. If `array` is empty or falsey,
3707 * `undefined` is returned.
3713 * @param {Array} array The array to iterate over.
3714 * @returns {*} Returns the minimum value.
3717 * _.min([4, 2, 8, 6]);
3723 function min(array) {
3724 return (array && array.length)
3725 ? baseExtremum(array, identity, baseLt)
3729 /*------------------------------------------------------------------------*/
3731 // Add methods that return wrapped values in chain sequences.
3732 lodash.assignIn = assignIn;
3733 lodash.before = before;
3735 lodash.chain = chain;
3736 lodash.compact = compact;
3737 lodash.concat = concat;
3738 lodash.create = create;
3739 lodash.defaults = defaults;
3740 lodash.defer = defer;
3741 lodash.delay = delay;
3742 lodash.filter = filter;
3743 lodash.flatten = flatten;
3744 lodash.flattenDeep = flattenDeep;
3745 lodash.iteratee = iteratee;
3748 lodash.matches = matches;
3749 lodash.mixin = mixin;
3750 lodash.negate = negate;
3753 lodash.slice = slice;
3754 lodash.sortBy = sortBy;
3757 lodash.toArray = toArray;
3758 lodash.values = values;
3761 lodash.extend = assignIn;
3763 // Add methods to `lodash.prototype`.
3764 mixin(lodash, lodash);
3766 /*------------------------------------------------------------------------*/
3768 // Add methods that return unwrapped values in chain sequences.
3769 lodash.clone = clone;
3770 lodash.escape = escape;
3771 lodash.every = every;
3773 lodash.forEach = forEach;
3776 lodash.identity = identity;
3777 lodash.indexOf = indexOf;
3778 lodash.isArguments = isArguments;
3779 lodash.isArray = isArray;
3780 lodash.isBoolean = isBoolean;
3781 lodash.isDate = isDate;
3782 lodash.isEmpty = isEmpty;
3783 lodash.isEqual = isEqual;
3784 lodash.isFinite = isFinite;
3785 lodash.isFunction = isFunction;
3786 lodash.isNaN = isNaN;
3787 lodash.isNull = isNull;
3788 lodash.isNumber = isNumber;
3789 lodash.isObject = isObject;
3790 lodash.isRegExp = isRegExp;
3791 lodash.isString = isString;
3792 lodash.isUndefined = isUndefined;
3796 lodash.noConflict = noConflict;
3798 lodash.reduce = reduce;
3799 lodash.result = result;
3802 lodash.uniqueId = uniqueId;
3805 lodash.each = forEach;
3806 lodash.first = head;
3808 mixin(lodash, (function() {
3810 baseForOwn(lodash, function(func, methodName) {
3811 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3812 source[methodName] = func;
3816 }()), { 'chain': false });
3818 /*------------------------------------------------------------------------*/
3821 * The semantic version number.
3827 lodash.VERSION = VERSION;
3829 // Add `Array` methods to `lodash.prototype`.
3830 baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3831 var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3832 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3833 retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3835 lodash.prototype[methodName] = function() {
3836 var args = arguments;
3837 if (retUnwrapped && !this.__chain__) {
3838 var value = this.value();
3839 return func.apply(isArray(value) ? value : [], args);
3841 return this[chainName](function(value) {
3842 return func.apply(isArray(value) ? value : [], args);
3847 // Add chain sequence methods to the `lodash` wrapper.
3848 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3850 /*--------------------------------------------------------------------------*/
3852 // Some AMD build optimizers, like r.js, check for condition patterns like:
3853 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3854 // Expose Lodash on the global object to prevent errors when Lodash is
3855 // loaded by a script tag in the presence of an AMD loader.
3856 // See http://requirejs.org/docs/errors.html#mismatch for more details.
3857 // Use `_.noConflict` to remove Lodash from the global object.
3860 // Define as an anonymous module so, through path mapping, it can be
3861 // referenced as the "underscore" module.
3866 // Check for `exports` after `define` in case a build optimizer adds it.
3867 else if (freeModule) {
3868 // Export for Node.js.
3869 (freeModule.exports = lodash)._ = lodash;
3870 // Export for CommonJS support.
3871 freeExports._ = lodash;
3874 // Export to the global object.