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.15';
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)) {
1188 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? [] : undefined;
1190 // Ignore non-index properties.
1191 while (++index < arrLength) {
1192 var arrValue = array[index],
1193 othValue = other[index];
1196 if (compared !== undefined) {
1203 // Recursively compare arrays (susceptible to call stack limits).
1205 if (!baseSome(other, function(othValue, othIndex) {
1206 if (!indexOf(seen, othIndex) &&
1207 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
1208 return seen.push(othIndex);
1215 arrValue === othValue ||
1216 equalFunc(arrValue, othValue, bitmask, customizer, stack)
1226 * A specialized version of `baseIsEqualDeep` for comparing objects of
1227 * the same `toStringTag`.
1229 * **Note:** This function only supports comparing values with tags of
1230 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1233 * @param {Object} object The object to compare.
1234 * @param {Object} other The other object to compare.
1235 * @param {string} tag The `toStringTag` of the objects to compare.
1236 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1237 * @param {Function} customizer The function to customize comparisons.
1238 * @param {Function} equalFunc The function to determine equivalents of values.
1239 * @param {Object} stack Tracks traversed `object` and `other` objects.
1240 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1242 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
1248 // Coerce booleans to `1` or `0` and dates to milliseconds.
1249 // Invalid dates are coerced to `NaN`.
1250 return eq(+object, +other);
1253 return object.name == other.name && object.message == other.message;
1257 // Coerce regexes to strings and treat strings, primitives and objects,
1258 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
1259 // for more details.
1260 return object == (other + '');
1267 * A specialized version of `baseIsEqualDeep` for objects with support for
1268 * partial deep comparisons.
1271 * @param {Object} object The object to compare.
1272 * @param {Object} other The other object to compare.
1273 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1274 * @param {Function} customizer The function to customize comparisons.
1275 * @param {Function} equalFunc The function to determine equivalents of values.
1276 * @param {Object} stack Tracks traversed `object` and `other` objects.
1277 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1279 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
1280 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
1281 objProps = keys(object),
1282 objLength = objProps.length,
1283 othProps = keys(other),
1284 othLength = othProps.length;
1286 if (objLength != othLength && !isPartial) {
1289 var index = objLength;
1291 var key = objProps[index];
1292 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1298 var skipCtor = isPartial;
1299 while (++index < objLength) {
1300 key = objProps[index];
1301 var objValue = object[key],
1302 othValue = other[key];
1305 // Recursively compare objects (susceptible to call stack limits).
1306 if (!(compared === undefined
1307 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
1313 skipCtor || (skipCtor = key == 'constructor');
1315 if (result && !skipCtor) {
1316 var objCtor = object.constructor,
1317 othCtor = other.constructor;
1319 // Non `Object` object instances with different constructors are not equal.
1320 if (objCtor != othCtor &&
1321 ('constructor' in object && 'constructor' in other) &&
1322 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1323 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1331 * A specialized version of `baseRest` which flattens the rest array.
1334 * @param {Function} func The function to apply a rest parameter to.
1335 * @returns {Function} Returns the new function.
1337 function flatRest(func) {
1338 return setToString(overRest(func, undefined, flatten), func + '');
1342 * Checks if `value` is a flattenable `arguments` object or array.
1345 * @param {*} value The value to check.
1346 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
1348 function isFlattenable(value) {
1349 return isArray(value) || isArguments(value);
1353 * Checks if `value` is a valid array-like index.
1356 * @param {*} value The value to check.
1357 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1358 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1360 function isIndex(value, length) {
1361 var type = typeof value;
1362 length = length == null ? MAX_SAFE_INTEGER : length;
1365 (type == 'number' ||
1366 (type != 'symbol' && reIsUint.test(value))) &&
1367 (value > -1 && value % 1 == 0 && value < length);
1371 * Checks if the given arguments are from an iteratee call.
1374 * @param {*} value The potential iteratee value argument.
1375 * @param {*} index The potential iteratee index or key argument.
1376 * @param {*} object The potential iteratee object argument.
1377 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
1380 function isIterateeCall(value, index, object) {
1381 if (!isObject(object)) {
1384 var type = typeof index;
1385 if (type == 'number'
1386 ? (isArrayLike(object) && isIndex(index, object.length))
1387 : (type == 'string' && index in object)
1389 return eq(object[index], value);
1395 * This function is like
1396 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1397 * except that it includes inherited enumerable properties.
1400 * @param {Object} object The object to query.
1401 * @returns {Array} Returns the array of property names.
1403 function nativeKeysIn(object) {
1405 if (object != null) {
1406 for (var key in Object(object)) {
1414 * Converts `value` to a string using `Object.prototype.toString`.
1417 * @param {*} value The value to convert.
1418 * @returns {string} Returns the converted string.
1420 function objectToString(value) {
1421 return nativeObjectToString.call(value);
1425 * A specialized version of `baseRest` which transforms the rest array.
1428 * @param {Function} func The function to apply a rest parameter to.
1429 * @param {number} [start=func.length-1] The start position of the rest parameter.
1430 * @param {Function} transform The rest array transform.
1431 * @returns {Function} Returns the new function.
1433 function overRest(func, start, transform) {
1434 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
1436 var args = arguments,
1438 length = nativeMax(args.length - start, 0),
1439 array = Array(length);
1441 while (++index < length) {
1442 array[index] = args[start + index];
1445 var otherArgs = Array(start + 1);
1446 while (++index < start) {
1447 otherArgs[index] = args[index];
1449 otherArgs[start] = transform(array);
1450 return func.apply(this, otherArgs);
1455 * Sets the `toString` method of `func` to return `string`.
1458 * @param {Function} func The function to modify.
1459 * @param {Function} string The `toString` result.
1460 * @returns {Function} Returns `func`.
1462 var setToString = identity;
1464 /*------------------------------------------------------------------------*/
1467 * Creates an array with all falsey values removed. The values `false`, `null`,
1468 * `0`, `""`, `undefined`, and `NaN` are falsey.
1474 * @param {Array} array The array to compact.
1475 * @returns {Array} Returns the new array of filtered values.
1478 * _.compact([0, 1, false, 2, '', 3]);
1481 function compact(array) {
1482 return baseFilter(array, Boolean);
1486 * Creates a new array concatenating `array` with any additional arrays
1493 * @param {Array} array The array to concatenate.
1494 * @param {...*} [values] The values to concatenate.
1495 * @returns {Array} Returns the new concatenated array.
1499 * var other = _.concat(array, 2, [3], [[4]]);
1501 * console.log(other);
1502 * // => [1, 2, 3, [4]]
1504 * console.log(array);
1508 var length = arguments.length;
1512 var args = Array(length - 1),
1513 array = arguments[0],
1517 args[index - 1] = arguments[index];
1519 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
1523 * This method is like `_.find` except that it returns the index of the first
1524 * element `predicate` returns truthy for instead of the element itself.
1530 * @param {Array} array The array to inspect.
1531 * @param {Function} [predicate=_.identity] The function invoked per iteration.
1532 * @param {number} [fromIndex=0] The index to search from.
1533 * @returns {number} Returns the index of the found element, else `-1`.
1537 * { 'user': 'barney', 'active': false },
1538 * { 'user': 'fred', 'active': false },
1539 * { 'user': 'pebbles', 'active': true }
1542 * _.findIndex(users, function(o) { return o.user == 'barney'; });
1545 * // The `_.matches` iteratee shorthand.
1546 * _.findIndex(users, { 'user': 'fred', 'active': false });
1549 * // The `_.matchesProperty` iteratee shorthand.
1550 * _.findIndex(users, ['active', false]);
1553 * // The `_.property` iteratee shorthand.
1554 * _.findIndex(users, 'active');
1557 function findIndex(array, predicate, fromIndex) {
1558 var length = array == null ? 0 : array.length;
1562 var index = fromIndex == null ? 0 : toInteger(fromIndex);
1564 index = nativeMax(length + index, 0);
1566 return baseFindIndex(array, baseIteratee(predicate, 3), index);
1570 * Flattens `array` a single level deep.
1576 * @param {Array} array The array to flatten.
1577 * @returns {Array} Returns the new flattened array.
1580 * _.flatten([1, [2, [3, [4]], 5]]);
1581 * // => [1, 2, [3, [4]], 5]
1583 function flatten(array) {
1584 var length = array == null ? 0 : array.length;
1585 return length ? baseFlatten(array, 1) : [];
1589 * Recursively flattens `array`.
1595 * @param {Array} array The array to flatten.
1596 * @returns {Array} Returns the new flattened array.
1599 * _.flattenDeep([1, [2, [3, [4]], 5]]);
1600 * // => [1, 2, 3, 4, 5]
1602 function flattenDeep(array) {
1603 var length = array == null ? 0 : array.length;
1604 return length ? baseFlatten(array, INFINITY) : [];
1608 * Gets the first element of `array`.
1615 * @param {Array} array The array to query.
1616 * @returns {*} Returns the first element of `array`.
1619 * _.head([1, 2, 3]);
1625 function head(array) {
1626 return (array && array.length) ? array[0] : undefined;
1630 * Gets the index at which the first occurrence of `value` is found in `array`
1631 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1632 * for equality comparisons. If `fromIndex` is negative, it's used as the
1633 * offset from the end of `array`.
1639 * @param {Array} array The array to inspect.
1640 * @param {*} value The value to search for.
1641 * @param {number} [fromIndex=0] The index to search from.
1642 * @returns {number} Returns the index of the matched value, else `-1`.
1645 * _.indexOf([1, 2, 1, 2], 2);
1648 * // Search from the `fromIndex`.
1649 * _.indexOf([1, 2, 1, 2], 2, 2);
1652 function indexOf(array, value, fromIndex) {
1653 var length = array == null ? 0 : array.length;
1654 if (typeof fromIndex == 'number') {
1655 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1659 var index = (fromIndex || 0) - 1,
1660 isReflexive = value === value;
1662 while (++index < length) {
1663 var other = array[index];
1664 if ((isReflexive ? other === value : other !== other)) {
1672 * Gets the last element of `array`.
1678 * @param {Array} array The array to query.
1679 * @returns {*} Returns the last element of `array`.
1682 * _.last([1, 2, 3]);
1685 function last(array) {
1686 var length = array == null ? 0 : array.length;
1687 return length ? array[length - 1] : undefined;
1691 * Creates a slice of `array` from `start` up to, but not including, `end`.
1693 * **Note:** This method is used instead of
1694 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
1701 * @param {Array} array The array to slice.
1702 * @param {number} [start=0] The start position.
1703 * @param {number} [end=array.length] The end position.
1704 * @returns {Array} Returns the slice of `array`.
1706 function slice(array, start, end) {
1707 var length = array == null ? 0 : array.length;
1708 start = start == null ? 0 : +start;
1709 end = end === undefined ? length : +end;
1710 return length ? baseSlice(array, start, end) : [];
1713 /*------------------------------------------------------------------------*/
1716 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
1717 * chain sequences enabled. The result of such sequences must be unwrapped
1724 * @param {*} value The value to wrap.
1725 * @returns {Object} Returns the new `lodash` wrapper instance.
1729 * { 'user': 'barney', 'age': 36 },
1730 * { 'user': 'fred', 'age': 40 },
1731 * { 'user': 'pebbles', 'age': 1 }
1737 * .map(function(o) {
1738 * return o.user + ' is ' + o.age;
1742 * // => 'pebbles is 1'
1744 function chain(value) {
1745 var result = lodash(value);
1746 result.__chain__ = true;
1751 * This method invokes `interceptor` and returns `value`. The interceptor
1752 * is invoked with one argument; (value). The purpose of this method is to
1753 * "tap into" a method chain sequence in order to modify intermediate results.
1759 * @param {*} value The value to provide to `interceptor`.
1760 * @param {Function} interceptor The function to invoke.
1761 * @returns {*} Returns `value`.
1765 * .tap(function(array) {
1766 * // Mutate input array.
1773 function tap(value, interceptor) {
1779 * This method is like `_.tap` except that it returns the result of `interceptor`.
1780 * The purpose of this method is to "pass thru" values replacing intermediate
1781 * results in a method chain sequence.
1787 * @param {*} value The value to provide to `interceptor`.
1788 * @param {Function} interceptor The function to invoke.
1789 * @returns {*} Returns the result of `interceptor`.
1795 * .thru(function(value) {
1801 function thru(value, interceptor) {
1802 return interceptor(value);
1806 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
1812 * @returns {Object} Returns the new `lodash` wrapper instance.
1816 * { 'user': 'barney', 'age': 36 },
1817 * { 'user': 'fred', 'age': 40 }
1820 * // A sequence without explicit chaining.
1822 * // => { 'user': 'barney', 'age': 36 }
1824 * // A sequence with explicit chaining.
1830 * // => { 'user': 'barney' }
1832 function wrapperChain() {
1837 * Executes the chain sequence to resolve the unwrapped value.
1842 * @alias toJSON, valueOf
1844 * @returns {*} Returns the resolved unwrapped value.
1847 * _([1, 2, 3]).value();
1850 function wrapperValue() {
1851 return baseWrapperValue(this.__wrapped__, this.__actions__);
1854 /*------------------------------------------------------------------------*/
1857 * Checks if `predicate` returns truthy for **all** elements of `collection`.
1858 * Iteration is stopped once `predicate` returns falsey. The predicate is
1859 * invoked with three arguments: (value, index|key, collection).
1861 * **Note:** This method returns `true` for
1862 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
1863 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
1864 * elements of empty collections.
1869 * @category Collection
1870 * @param {Array|Object} collection The collection to iterate over.
1871 * @param {Function} [predicate=_.identity] The function invoked per iteration.
1872 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
1873 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1877 * _.every([true, 1, null, 'yes'], Boolean);
1881 * { 'user': 'barney', 'age': 36, 'active': false },
1882 * { 'user': 'fred', 'age': 40, 'active': false }
1885 * // The `_.matches` iteratee shorthand.
1886 * _.every(users, { 'user': 'barney', 'active': false });
1889 * // The `_.matchesProperty` iteratee shorthand.
1890 * _.every(users, ['active', false]);
1893 * // The `_.property` iteratee shorthand.
1894 * _.every(users, 'active');
1897 function every(collection, predicate, guard) {
1898 predicate = guard ? undefined : predicate;
1899 return baseEvery(collection, baseIteratee(predicate));
1903 * Iterates over elements of `collection`, returning an array of all elements
1904 * `predicate` returns truthy for. The predicate is invoked with three
1905 * arguments: (value, index|key, collection).
1907 * **Note:** Unlike `_.remove`, this method returns a new array.
1912 * @category Collection
1913 * @param {Array|Object} collection The collection to iterate over.
1914 * @param {Function} [predicate=_.identity] The function invoked per iteration.
1915 * @returns {Array} Returns the new filtered array.
1920 * { 'user': 'barney', 'age': 36, 'active': true },
1921 * { 'user': 'fred', 'age': 40, 'active': false }
1924 * _.filter(users, function(o) { return !o.active; });
1925 * // => objects for ['fred']
1927 * // The `_.matches` iteratee shorthand.
1928 * _.filter(users, { 'age': 36, 'active': true });
1929 * // => objects for ['barney']
1931 * // The `_.matchesProperty` iteratee shorthand.
1932 * _.filter(users, ['active', false]);
1933 * // => objects for ['fred']
1935 * // The `_.property` iteratee shorthand.
1936 * _.filter(users, 'active');
1937 * // => objects for ['barney']
1939 function filter(collection, predicate) {
1940 return baseFilter(collection, baseIteratee(predicate));
1944 * Iterates over elements of `collection`, returning the first element
1945 * `predicate` returns truthy for. The predicate is invoked with three
1946 * arguments: (value, index|key, collection).
1951 * @category Collection
1952 * @param {Array|Object} collection The collection to inspect.
1953 * @param {Function} [predicate=_.identity] The function invoked per iteration.
1954 * @param {number} [fromIndex=0] The index to search from.
1955 * @returns {*} Returns the matched element, else `undefined`.
1959 * { 'user': 'barney', 'age': 36, 'active': true },
1960 * { 'user': 'fred', 'age': 40, 'active': false },
1961 * { 'user': 'pebbles', 'age': 1, 'active': true }
1964 * _.find(users, function(o) { return o.age < 40; });
1965 * // => object for 'barney'
1967 * // The `_.matches` iteratee shorthand.
1968 * _.find(users, { 'age': 1, 'active': true });
1969 * // => object for 'pebbles'
1971 * // The `_.matchesProperty` iteratee shorthand.
1972 * _.find(users, ['active', false]);
1973 * // => object for 'fred'
1975 * // The `_.property` iteratee shorthand.
1976 * _.find(users, 'active');
1977 * // => object for 'barney'
1979 var find = createFind(findIndex);
1982 * Iterates over elements of `collection` and invokes `iteratee` for each element.
1983 * The iteratee is invoked with three arguments: (value, index|key, collection).
1984 * Iteratee functions may exit iteration early by explicitly returning `false`.
1986 * **Note:** As with other "Collections" methods, objects with a "length"
1987 * property are iterated like arrays. To avoid this behavior use `_.forIn`
1988 * or `_.forOwn` for object iteration.
1994 * @category Collection
1995 * @param {Array|Object} collection The collection to iterate over.
1996 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1997 * @returns {Array|Object} Returns `collection`.
1998 * @see _.forEachRight
2001 * _.forEach([1, 2], function(value) {
2002 * console.log(value);
2004 * // => Logs `1` then `2`.
2006 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
2009 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
2011 function forEach(collection, iteratee) {
2012 return baseEach(collection, baseIteratee(iteratee));
2016 * Creates an array of values by running each element in `collection` thru
2017 * `iteratee`. The iteratee is invoked with three arguments:
2018 * (value, index|key, collection).
2020 * Many lodash methods are guarded to work as iteratees for methods like
2021 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
2023 * The guarded methods are:
2024 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
2025 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
2026 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
2027 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
2032 * @category Collection
2033 * @param {Array|Object} collection The collection to iterate over.
2034 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
2035 * @returns {Array} Returns the new mapped array.
2038 * function square(n) {
2042 * _.map([4, 8], square);
2045 * _.map({ 'a': 4, 'b': 8 }, square);
2046 * // => [16, 64] (iteration order is not guaranteed)
2049 * { 'user': 'barney' },
2050 * { 'user': 'fred' }
2053 * // The `_.property` iteratee shorthand.
2054 * _.map(users, 'user');
2055 * // => ['barney', 'fred']
2057 function map(collection, iteratee) {
2058 return baseMap(collection, baseIteratee(iteratee));
2062 * Reduces `collection` to a value which is the accumulated result of running
2063 * each element in `collection` thru `iteratee`, where each successive
2064 * invocation is supplied the return value of the previous. If `accumulator`
2065 * is not given, the first element of `collection` is used as the initial
2066 * value. The iteratee is invoked with four arguments:
2067 * (accumulator, value, index|key, collection).
2069 * Many lodash methods are guarded to work as iteratees for methods like
2070 * `_.reduce`, `_.reduceRight`, and `_.transform`.
2072 * The guarded methods are:
2073 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
2079 * @category Collection
2080 * @param {Array|Object} collection The collection to iterate over.
2081 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
2082 * @param {*} [accumulator] The initial value.
2083 * @returns {*} Returns the accumulated value.
2084 * @see _.reduceRight
2087 * _.reduce([1, 2], function(sum, n) {
2092 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
2093 * (result[value] || (result[value] = [])).push(key);
2096 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
2098 function reduce(collection, iteratee, accumulator) {
2099 return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
2103 * Gets the size of `collection` by returning its length for array-like
2104 * values or the number of own enumerable string keyed properties for objects.
2109 * @category Collection
2110 * @param {Array|Object|string} collection The collection to inspect.
2111 * @returns {number} Returns the collection size.
2114 * _.size([1, 2, 3]);
2117 * _.size({ 'a': 1, 'b': 2 });
2120 * _.size('pebbles');
2123 function size(collection) {
2124 if (collection == null) {
2127 collection = isArrayLike(collection) ? collection : nativeKeys(collection);
2128 return collection.length;
2132 * Checks if `predicate` returns truthy for **any** element of `collection`.
2133 * Iteration is stopped once `predicate` returns truthy. The predicate is
2134 * invoked with three arguments: (value, index|key, collection).
2139 * @category Collection
2140 * @param {Array|Object} collection The collection to iterate over.
2141 * @param {Function} [predicate=_.identity] The function invoked per iteration.
2142 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
2143 * @returns {boolean} Returns `true` if any element passes the predicate check,
2147 * _.some([null, 0, 'yes', false], Boolean);
2151 * { 'user': 'barney', 'active': true },
2152 * { 'user': 'fred', 'active': false }
2155 * // The `_.matches` iteratee shorthand.
2156 * _.some(users, { 'user': 'barney', 'active': false });
2159 * // The `_.matchesProperty` iteratee shorthand.
2160 * _.some(users, ['active', false]);
2163 * // The `_.property` iteratee shorthand.
2164 * _.some(users, 'active');
2167 function some(collection, predicate, guard) {
2168 predicate = guard ? undefined : predicate;
2169 return baseSome(collection, baseIteratee(predicate));
2173 * Creates an array of elements, sorted in ascending order by the results of
2174 * running each element in a collection thru each iteratee. This method
2175 * performs a stable sort, that is, it preserves the original sort order of
2176 * equal elements. The iteratees are invoked with one argument: (value).
2181 * @category Collection
2182 * @param {Array|Object} collection The collection to iterate over.
2183 * @param {...(Function|Function[])} [iteratees=[_.identity]]
2184 * The iteratees to sort by.
2185 * @returns {Array} Returns the new sorted array.
2189 * { 'user': 'fred', 'age': 48 },
2190 * { 'user': 'barney', 'age': 36 },
2191 * { 'user': 'fred', 'age': 40 },
2192 * { 'user': 'barney', 'age': 34 }
2195 * _.sortBy(users, [function(o) { return o.user; }]);
2196 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
2198 * _.sortBy(users, ['user', 'age']);
2199 * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
2201 function sortBy(collection, iteratee) {
2203 iteratee = baseIteratee(iteratee);
2205 return baseMap(baseMap(collection, function(value, key, collection) {
2206 return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2207 }).sort(function(object, other) {
2208 return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2209 }), baseProperty('value'));
2212 /*------------------------------------------------------------------------*/
2215 * Creates a function that invokes `func`, with the `this` binding and arguments
2216 * of the created function, while it's called less than `n` times. Subsequent
2217 * calls to the created function return the result of the last `func` invocation.
2222 * @category Function
2223 * @param {number} n The number of calls at which `func` is no longer invoked.
2224 * @param {Function} func The function to restrict.
2225 * @returns {Function} Returns the new restricted function.
2228 * jQuery(element).on('click', _.before(5, addContactToList));
2229 * // => Allows adding up to 4 contacts to the list.
2231 function before(n, func) {
2233 if (typeof func != 'function') {
2234 throw new TypeError(FUNC_ERROR_TEXT);
2239 result = func.apply(this, arguments);
2249 * Creates a function that invokes `func` with the `this` binding of `thisArg`
2250 * and `partials` prepended to the arguments it receives.
2252 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2253 * may be used as a placeholder for partially applied arguments.
2255 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
2256 * property of bound functions.
2261 * @category Function
2262 * @param {Function} func The function to bind.
2263 * @param {*} thisArg The `this` binding of `func`.
2264 * @param {...*} [partials] The arguments to be partially applied.
2265 * @returns {Function} Returns the new bound function.
2268 * function greet(greeting, punctuation) {
2269 * return greeting + ' ' + this.user + punctuation;
2272 * var object = { 'user': 'fred' };
2274 * var bound = _.bind(greet, object, 'hi');
2278 * // Bound with placeholders.
2279 * var bound = _.bind(greet, object, _, '!');
2283 var bind = baseRest(function(func, thisArg, partials) {
2284 return createPartial(func, WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG, thisArg, partials);
2288 * Defers invoking the `func` until the current call stack has cleared. Any
2289 * additional arguments are provided to `func` when it's invoked.
2294 * @category Function
2295 * @param {Function} func The function to defer.
2296 * @param {...*} [args] The arguments to invoke `func` with.
2297 * @returns {number} Returns the timer id.
2300 * _.defer(function(text) {
2301 * console.log(text);
2303 * // => Logs 'deferred' after one millisecond.
2305 var defer = baseRest(function(func, args) {
2306 return baseDelay(func, 1, args);
2310 * Invokes `func` after `wait` milliseconds. Any additional arguments are
2311 * provided to `func` when it's invoked.
2316 * @category Function
2317 * @param {Function} func The function to delay.
2318 * @param {number} wait The number of milliseconds to delay invocation.
2319 * @param {...*} [args] The arguments to invoke `func` with.
2320 * @returns {number} Returns the timer id.
2323 * _.delay(function(text) {
2324 * console.log(text);
2325 * }, 1000, 'later');
2326 * // => Logs 'later' after one second.
2328 var delay = baseRest(function(func, wait, args) {
2329 return baseDelay(func, toNumber(wait) || 0, args);
2333 * Creates a function that negates the result of the predicate `func`. The
2334 * `func` predicate is invoked with the `this` binding and arguments of the
2340 * @category Function
2341 * @param {Function} predicate The predicate to negate.
2342 * @returns {Function} Returns the new negated function.
2345 * function isEven(n) {
2346 * return n % 2 == 0;
2349 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2352 function negate(predicate) {
2353 if (typeof predicate != 'function') {
2354 throw new TypeError(FUNC_ERROR_TEXT);
2357 var args = arguments;
2358 return !predicate.apply(this, args);
2363 * Creates a function that is restricted to invoking `func` once. Repeat calls
2364 * to the function return the value of the first invocation. The `func` is
2365 * invoked with the `this` binding and arguments of the created function.
2370 * @category Function
2371 * @param {Function} func The function to restrict.
2372 * @returns {Function} Returns the new restricted function.
2375 * var initialize = _.once(createApplication);
2378 * // => `createApplication` is invoked once
2380 function once(func) {
2381 return before(2, func);
2384 /*------------------------------------------------------------------------*/
2387 * Creates a shallow clone of `value`.
2389 * **Note:** This method is loosely based on the
2390 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2391 * and supports cloning arrays, array buffers, booleans, date objects, maps,
2392 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2393 * arrays. The own enumerable properties of `arguments` objects are cloned
2394 * as plain objects. An empty object is returned for uncloneable values such
2395 * as error objects, functions, DOM nodes, and WeakMaps.
2401 * @param {*} value The value to clone.
2402 * @returns {*} Returns the cloned value.
2406 * var objects = [{ 'a': 1 }, { 'b': 2 }];
2408 * var shallow = _.clone(objects);
2409 * console.log(shallow[0] === objects[0]);
2412 function clone(value) {
2413 if (!isObject(value)) {
2416 return isArray(value) ? copyArray(value) : copyObject(value, nativeKeys(value));
2421 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
2422 * comparison between two values to determine if they are equivalent.
2428 * @param {*} value The value to compare.
2429 * @param {*} other The other value to compare.
2430 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2433 * var object = { 'a': 1 };
2434 * var other = { 'a': 1 };
2436 * _.eq(object, object);
2439 * _.eq(object, other);
2445 * _.eq('a', Object('a'));
2451 function eq(value, other) {
2452 return value === other || (value !== value && other !== other);
2456 * Checks if `value` is likely an `arguments` object.
2462 * @param {*} value The value to check.
2463 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
2467 * _.isArguments(function() { return arguments; }());
2470 * _.isArguments([1, 2, 3]);
2473 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
2474 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
2475 !propertyIsEnumerable.call(value, 'callee');
2479 * Checks if `value` is classified as an `Array` object.
2485 * @param {*} value The value to check.
2486 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
2489 * _.isArray([1, 2, 3]);
2492 * _.isArray(document.body.children);
2498 * _.isArray(_.noop);
2501 var isArray = Array.isArray;
2504 * Checks if `value` is array-like. A value is considered array-like if it's
2505 * not a function and has a `value.length` that's an integer greater than or
2506 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2512 * @param {*} value The value to check.
2513 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2516 * _.isArrayLike([1, 2, 3]);
2519 * _.isArrayLike(document.body.children);
2522 * _.isArrayLike('abc');
2525 * _.isArrayLike(_.noop);
2528 function isArrayLike(value) {
2529 return value != null && isLength(value.length) && !isFunction(value);
2533 * Checks if `value` is classified as a boolean primitive or object.
2539 * @param {*} value The value to check.
2540 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
2543 * _.isBoolean(false);
2546 * _.isBoolean(null);
2549 function isBoolean(value) {
2550 return value === true || value === false ||
2551 (isObjectLike(value) && baseGetTag(value) == boolTag);
2555 * Checks if `value` is classified as a `Date` object.
2561 * @param {*} value The value to check.
2562 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
2565 * _.isDate(new Date);
2568 * _.isDate('Mon April 23 2012');
2571 var isDate = baseIsDate;
2574 * Checks if `value` is an empty object, collection, map, or set.
2576 * Objects are considered empty if they have no own enumerable string keyed
2579 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
2580 * jQuery-like collections are considered empty if they have a `length` of `0`.
2581 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
2587 * @param {*} value The value to check.
2588 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2600 * _.isEmpty([1, 2, 3]);
2603 * _.isEmpty({ 'a': 1 });
2606 function isEmpty(value) {
2607 if (isArrayLike(value) &&
2608 (isArray(value) || isString(value) ||
2609 isFunction(value.splice) || isArguments(value))) {
2610 return !value.length;
2612 return !nativeKeys(value).length;
2616 * Performs a deep comparison between two values to determine if they are
2619 * **Note:** This method supports comparing arrays, array buffers, booleans,
2620 * date objects, error objects, maps, numbers, `Object` objects, regexes,
2621 * sets, strings, symbols, and typed arrays. `Object` objects are compared
2622 * by their own, not inherited, enumerable properties. Functions and DOM
2623 * nodes are compared by strict equality, i.e. `===`.
2629 * @param {*} value The value to compare.
2630 * @param {*} other The other value to compare.
2631 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2634 * var object = { 'a': 1 };
2635 * var other = { 'a': 1 };
2637 * _.isEqual(object, other);
2643 function isEqual(value, other) {
2644 return baseIsEqual(value, other);
2648 * Checks if `value` is a finite primitive number.
2650 * **Note:** This method is based on
2651 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
2657 * @param {*} value The value to check.
2658 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
2664 * _.isFinite(Number.MIN_VALUE);
2667 * _.isFinite(Infinity);
2673 function isFinite(value) {
2674 return typeof value == 'number' && nativeIsFinite(value);
2678 * Checks if `value` is classified as a `Function` object.
2684 * @param {*} value The value to check.
2685 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
2691 * _.isFunction(/abc/);
2694 function isFunction(value) {
2695 if (!isObject(value)) {
2698 // The use of `Object#toString` avoids issues with the `typeof` operator
2699 // in Safari 9 which returns 'object' for typed arrays and other constructors.
2700 var tag = baseGetTag(value);
2701 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
2705 * Checks if `value` is a valid array-like length.
2707 * **Note:** This method is loosely based on
2708 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
2714 * @param {*} value The value to check.
2715 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
2721 * _.isLength(Number.MIN_VALUE);
2724 * _.isLength(Infinity);
2730 function isLength(value) {
2731 return typeof value == 'number' &&
2732 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2736 * Checks if `value` is the
2737 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
2738 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2744 * @param {*} value The value to check.
2745 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2751 * _.isObject([1, 2, 3]);
2754 * _.isObject(_.noop);
2760 function isObject(value) {
2761 var type = typeof value;
2762 return value != null && (type == 'object' || type == 'function');
2766 * Checks if `value` is object-like. A value is object-like if it's not `null`
2767 * and has a `typeof` result of "object".
2773 * @param {*} value The value to check.
2774 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2777 * _.isObjectLike({});
2780 * _.isObjectLike([1, 2, 3]);
2783 * _.isObjectLike(_.noop);
2786 * _.isObjectLike(null);
2789 function isObjectLike(value) {
2790 return value != null && typeof value == 'object';
2794 * Checks if `value` is `NaN`.
2796 * **Note:** This method is based on
2797 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
2798 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
2799 * `undefined` and other non-number values.
2805 * @param {*} value The value to check.
2806 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2812 * _.isNaN(new Number(NaN));
2818 * _.isNaN(undefined);
2821 function isNaN(value) {
2822 // An `NaN` primitive is the only value that is not equal to itself.
2823 // Perform the `toStringTag` check first to avoid errors with some
2824 // ActiveX objects in IE.
2825 return isNumber(value) && value != +value;
2829 * Checks if `value` is `null`.
2835 * @param {*} value The value to check.
2836 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2845 function isNull(value) {
2846 return value === null;
2850 * Checks if `value` is classified as a `Number` primitive or object.
2852 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
2853 * classified as numbers, use the `_.isFinite` method.
2859 * @param {*} value The value to check.
2860 * @returns {boolean} Returns `true` if `value` is a number, else `false`.
2866 * _.isNumber(Number.MIN_VALUE);
2869 * _.isNumber(Infinity);
2875 function isNumber(value) {
2876 return typeof value == 'number' ||
2877 (isObjectLike(value) && baseGetTag(value) == numberTag);
2881 * Checks if `value` is classified as a `RegExp` object.
2887 * @param {*} value The value to check.
2888 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
2891 * _.isRegExp(/abc/);
2894 * _.isRegExp('/abc/');
2897 var isRegExp = baseIsRegExp;
2900 * Checks if `value` is classified as a `String` primitive or object.
2906 * @param {*} value The value to check.
2907 * @returns {boolean} Returns `true` if `value` is a string, else `false`.
2910 * _.isString('abc');
2916 function isString(value) {
2917 return typeof value == 'string' ||
2918 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
2922 * Checks if `value` is `undefined`.
2928 * @param {*} value The value to check.
2929 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
2932 * _.isUndefined(void 0);
2935 * _.isUndefined(null);
2938 function isUndefined(value) {
2939 return value === undefined;
2943 * Converts `value` to an array.
2949 * @param {*} value The value to convert.
2950 * @returns {Array} Returns the converted array.
2953 * _.toArray({ 'a': 1, 'b': 2 });
2957 * // => ['a', 'b', 'c']
2965 function toArray(value) {
2966 if (!isArrayLike(value)) {
2967 return values(value);
2969 return value.length ? copyArray(value) : [];
2973 * Converts `value` to an integer.
2975 * **Note:** This method is loosely based on
2976 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
2982 * @param {*} value The value to convert.
2983 * @returns {number} Returns the converted integer.
2989 * _.toInteger(Number.MIN_VALUE);
2992 * _.toInteger(Infinity);
2993 * // => 1.7976931348623157e+308
2995 * _.toInteger('3.2');
2998 var toInteger = Number;
3001 * Converts `value` to a number.
3007 * @param {*} value The value to process.
3008 * @returns {number} Returns the number.
3014 * _.toNumber(Number.MIN_VALUE);
3017 * _.toNumber(Infinity);
3020 * _.toNumber('3.2');
3023 var toNumber = Number;
3026 * Converts `value` to a string. An empty string is returned for `null`
3027 * and `undefined` values. The sign of `-0` is preserved.
3033 * @param {*} value The value to convert.
3034 * @returns {string} Returns the converted string.
3043 * _.toString([1, 2, 3]);
3046 function toString(value) {
3047 if (typeof value == 'string') {
3050 return value == null ? '' : (value + '');
3053 /*------------------------------------------------------------------------*/
3056 * Assigns own enumerable string keyed properties of source objects to the
3057 * destination object. Source objects are applied from left to right.
3058 * Subsequent sources overwrite property assignments of previous sources.
3060 * **Note:** This method mutates `object` and is loosely based on
3061 * [`Object.assign`](https://mdn.io/Object/assign).
3067 * @param {Object} object The destination object.
3068 * @param {...Object} [sources] The source objects.
3069 * @returns {Object} Returns `object`.
3081 * Foo.prototype.b = 2;
3082 * Bar.prototype.d = 4;
3084 * _.assign({ 'a': 0 }, new Foo, new Bar);
3085 * // => { 'a': 1, 'c': 3 }
3087 var assign = createAssigner(function(object, source) {
3088 copyObject(source, nativeKeys(source), object);
3092 * This method is like `_.assign` except that it iterates over own and
3093 * inherited source properties.
3095 * **Note:** This method mutates `object`.
3102 * @param {Object} object The destination object.
3103 * @param {...Object} [sources] The source objects.
3104 * @returns {Object} Returns `object`.
3116 * Foo.prototype.b = 2;
3117 * Bar.prototype.d = 4;
3119 * _.assignIn({ 'a': 0 }, new Foo, new Bar);
3120 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
3122 var assignIn = createAssigner(function(object, source) {
3123 copyObject(source, nativeKeysIn(source), object);
3127 * Creates an object that inherits from the `prototype` object. If a
3128 * `properties` object is given, its own enumerable string keyed properties
3129 * are assigned to the created object.
3135 * @param {Object} prototype The object to inherit from.
3136 * @param {Object} [properties] The properties to assign to the object.
3137 * @returns {Object} Returns the new object.
3140 * function Shape() {
3145 * function Circle() {
3149 * Circle.prototype = _.create(Shape.prototype, {
3150 * 'constructor': Circle
3153 * var circle = new Circle;
3154 * circle instanceof Circle;
3157 * circle instanceof Shape;
3160 function create(prototype, properties) {
3161 var result = baseCreate(prototype);
3162 return properties == null ? result : assign(result, properties);
3166 * Assigns own and inherited enumerable string keyed properties of source
3167 * objects to the destination object for all destination properties that
3168 * resolve to `undefined`. Source objects are applied from left to right.
3169 * Once a property is set, additional values of the same property are ignored.
3171 * **Note:** This method mutates `object`.
3177 * @param {Object} object The destination object.
3178 * @param {...Object} [sources] The source objects.
3179 * @returns {Object} Returns `object`.
3180 * @see _.defaultsDeep
3183 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3184 * // => { 'a': 1, 'b': 2 }
3186 var defaults = baseRest(function(object, sources) {
3187 object = Object(object);
3190 var length = sources.length;
3191 var guard = length > 2 ? sources[2] : undefined;
3193 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
3197 while (++index < length) {
3198 var source = sources[index];
3199 var props = keysIn(source);
3200 var propsIndex = -1;
3201 var propsLength = props.length;
3203 while (++propsIndex < propsLength) {
3204 var key = props[propsIndex];
3205 var value = object[key];
3207 if (value === undefined ||
3208 (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
3209 object[key] = source[key];
3218 * Checks if `path` is a direct property of `object`.
3224 * @param {Object} object The object to query.
3225 * @param {Array|string} path The path to check.
3226 * @returns {boolean} Returns `true` if `path` exists, else `false`.
3229 * var object = { 'a': { 'b': 2 } };
3230 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
3232 * _.has(object, 'a');
3235 * _.has(object, 'a.b');
3238 * _.has(object, ['a', 'b']);
3241 * _.has(other, 'a');
3244 function has(object, path) {
3245 return object != null && hasOwnProperty.call(object, path);
3249 * Creates an array of the own enumerable property names of `object`.
3251 * **Note:** Non-object values are coerced to objects. See the
3252 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
3259 * @param {Object} object The object to query.
3260 * @returns {Array} Returns the array of property names.
3268 * Foo.prototype.c = 3;
3271 * // => ['a', 'b'] (iteration order is not guaranteed)
3276 var keys = nativeKeys;
3279 * Creates an array of the own and inherited enumerable property names of `object`.
3281 * **Note:** Non-object values are coerced to objects.
3287 * @param {Object} object The object to query.
3288 * @returns {Array} Returns the array of property names.
3296 * Foo.prototype.c = 3;
3298 * _.keysIn(new Foo);
3299 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3301 var keysIn = nativeKeysIn;
3304 * Creates an object composed of the picked `object` properties.
3310 * @param {Object} object The source object.
3311 * @param {...(string|string[])} [paths] The property paths to pick.
3312 * @returns {Object} Returns the new object.
3315 * var object = { 'a': 1, 'b': '2', 'c': 3 };
3317 * _.pick(object, ['a', 'c']);
3318 * // => { 'a': 1, 'c': 3 }
3320 var pick = flatRest(function(object, paths) {
3321 return object == null ? {} : basePick(object, paths);
3325 * This method is like `_.get` except that if the resolved value is a
3326 * function it's invoked with the `this` binding of its parent object and
3327 * its result is returned.
3333 * @param {Object} object The object to query.
3334 * @param {Array|string} path The path of the property to resolve.
3335 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
3336 * @returns {*} Returns the resolved value.
3339 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3341 * _.result(object, 'a[0].b.c1');
3344 * _.result(object, 'a[0].b.c2');
3347 * _.result(object, 'a[0].b.c3', 'default');
3350 * _.result(object, 'a[0].b.c3', _.constant('default'));
3353 function result(object, path, defaultValue) {
3354 var value = object == null ? undefined : object[path];
3355 if (value === undefined) {
3356 value = defaultValue;
3358 return isFunction(value) ? value.call(object) : value;
3362 * Creates an array of the own enumerable string keyed property values of `object`.
3364 * **Note:** Non-object values are coerced to objects.
3370 * @param {Object} object The object to query.
3371 * @returns {Array} Returns the array of property values.
3379 * Foo.prototype.c = 3;
3381 * _.values(new Foo);
3382 * // => [1, 2] (iteration order is not guaranteed)
3387 function values(object) {
3388 return object == null ? [] : baseValues(object, keys(object));
3391 /*------------------------------------------------------------------------*/
3394 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
3395 * corresponding HTML entities.
3397 * **Note:** No other characters are escaped. To escape additional
3398 * characters use a third-party library like [_he_](https://mths.be/he).
3400 * Though the ">" character is escaped for symmetry, characters like
3401 * ">" and "/" don't need escaping in HTML and have no special meaning
3402 * unless they're part of a tag or unquoted attribute value. See
3403 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3404 * (under "semi-related fun fact") for more details.
3406 * When working with HTML you should always
3407 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
3414 * @param {string} [string=''] The string to escape.
3415 * @returns {string} Returns the escaped string.
3418 * _.escape('fred, barney, & pebbles');
3419 * // => 'fred, barney, & pebbles'
3421 function escape(string) {
3422 string = toString(string);
3423 return (string && reHasUnescapedHtml.test(string))
3424 ? string.replace(reUnescapedHtml, escapeHtmlChar)
3428 /*------------------------------------------------------------------------*/
3431 * This method returns the first argument it receives.
3437 * @param {*} value Any value.
3438 * @returns {*} Returns `value`.
3441 * var object = { 'a': 1 };
3443 * console.log(_.identity(object) === object);
3446 function identity(value) {
3451 * Creates a function that invokes `func` with the arguments of the created
3452 * function. If `func` is a property name, the created function returns the
3453 * property value for a given element. If `func` is an array or object, the
3454 * created function returns `true` for elements that contain the equivalent
3455 * source properties, otherwise it returns `false`.
3461 * @param {*} [func=_.identity] The value to convert to a callback.
3462 * @returns {Function} Returns the callback.
3466 * { 'user': 'barney', 'age': 36, 'active': true },
3467 * { 'user': 'fred', 'age': 40, 'active': false }
3470 * // The `_.matches` iteratee shorthand.
3471 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
3472 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
3474 * // The `_.matchesProperty` iteratee shorthand.
3475 * _.filter(users, _.iteratee(['user', 'fred']));
3476 * // => [{ 'user': 'fred', 'age': 40 }]
3478 * // The `_.property` iteratee shorthand.
3479 * _.map(users, _.iteratee('user'));
3480 * // => ['barney', 'fred']
3482 * // Create custom iteratee shorthands.
3483 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
3484 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
3485 * return func.test(string);
3489 * _.filter(['abc', 'def'], /ef/);
3492 var iteratee = baseIteratee;
3495 * Creates a function that performs a partial deep comparison between a given
3496 * object and `source`, returning `true` if the given object has equivalent
3497 * property values, else `false`.
3499 * **Note:** The created function is equivalent to `_.isMatch` with `source`
3500 * partially applied.
3502 * Partial comparisons will match empty array and empty object `source`
3503 * values against any array or object value, respectively. See `_.isEqual`
3504 * for a list of supported value comparisons.
3510 * @param {Object} source The object of property values to match.
3511 * @returns {Function} Returns the new spec function.
3515 * { 'a': 1, 'b': 2, 'c': 3 },
3516 * { 'a': 4, 'b': 5, 'c': 6 }
3519 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
3520 * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
3522 function matches(source) {
3523 return baseMatches(assign({}, source));
3527 * Adds all own enumerable string keyed function properties of a source
3528 * object to the destination object. If `object` is a function, then methods
3529 * are added to its prototype as well.
3531 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3532 * avoid conflicts caused by modifying the original.
3538 * @param {Function|Object} [object=lodash] The destination object.
3539 * @param {Object} source The object of functions to add.
3540 * @param {Object} [options={}] The options object.
3541 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
3542 * @returns {Function|Object} Returns `object`.
3545 * function vowels(string) {
3546 * return _.filter(string, function(v) {
3547 * return /[aeiou]/i.test(v);
3551 * _.mixin({ 'vowels': vowels });
3555 * _('fred').vowels().value();
3558 * _.mixin({ 'vowels': vowels }, { 'chain': false });
3559 * _('fred').vowels();
3562 function mixin(object, source, options) {
3563 var props = keys(source),
3564 methodNames = baseFunctions(source, props);
3566 if (options == null &&
3567 !(isObject(source) && (methodNames.length || !props.length))) {
3571 methodNames = baseFunctions(source, keys(source));
3573 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
3574 isFunc = isFunction(object);
3576 baseEach(methodNames, function(methodName) {
3577 var func = source[methodName];
3578 object[methodName] = func;
3580 object.prototype[methodName] = function() {
3581 var chainAll = this.__chain__;
3582 if (chain || chainAll) {
3583 var result = object(this.__wrapped__),
3584 actions = result.__actions__ = copyArray(this.__actions__);
3586 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3587 result.__chain__ = chainAll;
3590 return func.apply(object, arrayPush([this.value()], arguments));
3599 * Reverts the `_` variable to its previous value and returns a reference to
3600 * the `lodash` function.
3606 * @returns {Function} Returns the `lodash` function.
3609 * var lodash = _.noConflict();
3611 function noConflict() {
3612 if (root._ === this) {
3619 * This method returns `undefined`.
3627 * _.times(2, _.noop);
3628 * // => [undefined, undefined]
3631 // No operation performed.
3635 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
3641 * @param {string} [prefix=''] The value to prefix the ID with.
3642 * @returns {string} Returns the unique ID.
3645 * _.uniqueId('contact_');
3646 * // => 'contact_104'
3651 function uniqueId(prefix) {
3652 var id = ++idCounter;
3653 return toString(prefix) + id;
3656 /*------------------------------------------------------------------------*/
3659 * Computes the maximum value of `array`. If `array` is empty or falsey,
3660 * `undefined` is returned.
3666 * @param {Array} array The array to iterate over.
3667 * @returns {*} Returns the maximum value.
3670 * _.max([4, 2, 8, 6]);
3676 function max(array) {
3677 return (array && array.length)
3678 ? baseExtremum(array, identity, baseGt)
3683 * Computes the minimum value of `array`. If `array` is empty or falsey,
3684 * `undefined` is returned.
3690 * @param {Array} array The array to iterate over.
3691 * @returns {*} Returns the minimum value.
3694 * _.min([4, 2, 8, 6]);
3700 function min(array) {
3701 return (array && array.length)
3702 ? baseExtremum(array, identity, baseLt)
3706 /*------------------------------------------------------------------------*/
3708 // Add methods that return wrapped values in chain sequences.
3709 lodash.assignIn = assignIn;
3710 lodash.before = before;
3712 lodash.chain = chain;
3713 lodash.compact = compact;
3714 lodash.concat = concat;
3715 lodash.create = create;
3716 lodash.defaults = defaults;
3717 lodash.defer = defer;
3718 lodash.delay = delay;
3719 lodash.filter = filter;
3720 lodash.flatten = flatten;
3721 lodash.flattenDeep = flattenDeep;
3722 lodash.iteratee = iteratee;
3725 lodash.matches = matches;
3726 lodash.mixin = mixin;
3727 lodash.negate = negate;
3730 lodash.slice = slice;
3731 lodash.sortBy = sortBy;
3734 lodash.toArray = toArray;
3735 lodash.values = values;
3738 lodash.extend = assignIn;
3740 // Add methods to `lodash.prototype`.
3741 mixin(lodash, lodash);
3743 /*------------------------------------------------------------------------*/
3745 // Add methods that return unwrapped values in chain sequences.
3746 lodash.clone = clone;
3747 lodash.escape = escape;
3748 lodash.every = every;
3750 lodash.forEach = forEach;
3753 lodash.identity = identity;
3754 lodash.indexOf = indexOf;
3755 lodash.isArguments = isArguments;
3756 lodash.isArray = isArray;
3757 lodash.isBoolean = isBoolean;
3758 lodash.isDate = isDate;
3759 lodash.isEmpty = isEmpty;
3760 lodash.isEqual = isEqual;
3761 lodash.isFinite = isFinite;
3762 lodash.isFunction = isFunction;
3763 lodash.isNaN = isNaN;
3764 lodash.isNull = isNull;
3765 lodash.isNumber = isNumber;
3766 lodash.isObject = isObject;
3767 lodash.isRegExp = isRegExp;
3768 lodash.isString = isString;
3769 lodash.isUndefined = isUndefined;
3773 lodash.noConflict = noConflict;
3775 lodash.reduce = reduce;
3776 lodash.result = result;
3779 lodash.uniqueId = uniqueId;
3782 lodash.each = forEach;
3783 lodash.first = head;
3785 mixin(lodash, (function() {
3787 baseForOwn(lodash, function(func, methodName) {
3788 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3789 source[methodName] = func;
3793 }()), { 'chain': false });
3795 /*------------------------------------------------------------------------*/
3798 * The semantic version number.
3804 lodash.VERSION = VERSION;
3806 // Add `Array` methods to `lodash.prototype`.
3807 baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3808 var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3809 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3810 retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3812 lodash.prototype[methodName] = function() {
3813 var args = arguments;
3814 if (retUnwrapped && !this.__chain__) {
3815 var value = this.value();
3816 return func.apply(isArray(value) ? value : [], args);
3818 return this[chainName](function(value) {
3819 return func.apply(isArray(value) ? value : [], args);
3824 // Add chain sequence methods to the `lodash` wrapper.
3825 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3827 /*--------------------------------------------------------------------------*/
3829 // Some AMD build optimizers, like r.js, check for condition patterns like:
3830 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3831 // Expose Lodash on the global object to prevent errors when Lodash is
3832 // loaded by a script tag in the presence of an AMD loader.
3833 // See http://requirejs.org/docs/errors.html#mismatch for more details.
3834 // Use `_.noConflict` to remove Lodash from the global object.
3837 // Define as an anonymous module so, through path mapping, it can be
3838 // referenced as the "underscore" module.
3843 // Check for `exports` after `define` in case a build optimizer adds it.
3844 else if (freeModule) {
3845 // Export for Node.js.
3846 (freeModule.exports = lodash)._ = lodash;
3847 // Export for CommonJS support.
3848 freeExports._ = lodash;
3851 // Export to the global object.