3 * lodash (Custom Build) <https://lodash.com/>
4 * Build: `lodash core -o ./dist/lodash.core.js`
5 * Copyright jQuery Foundation and other contributors <https://jquery.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.13.1';
18 /** Used as the `TypeError` message for "Functions" methods. */
19 var FUNC_ERROR_TEXT = 'Expected a function';
21 /** Used to compose bitmasks for wrapper metadata. */
25 /** Used to compose bitmasks for comparison styles. */
26 var UNORDERED_COMPARE_FLAG = 1,
27 PARTIAL_COMPARE_FLAG = 2;
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 boolTag = '[object Boolean]',
37 dateTag = '[object Date]',
38 errorTag = '[object Error]',
39 funcTag = '[object Function]',
40 genTag = '[object GeneratorFunction]',
41 numberTag = '[object Number]',
42 objectTag = '[object Object]',
43 regexpTag = '[object RegExp]',
44 stringTag = '[object String]';
46 /** Used to match HTML entities and HTML characters. */
47 var reUnescapedHtml = /[&<>"'`]/g,
48 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
50 /** Used to map characters to HTML entities. */
60 /** Detect free variable `exports`. */
61 var freeExports = typeof exports == 'object' && exports;
63 /** Detect free variable `module`. */
64 var freeModule = freeExports && typeof module == 'object' && module;
66 /** Detect free variable `global` from Node.js. */
67 var freeGlobal = checkGlobal(typeof global == 'object' && global);
69 /** Detect free variable `self`. */
70 var freeSelf = checkGlobal(typeof self == 'object' && self);
72 /** Detect `this` as the global object. */
73 var thisGlobal = checkGlobal(typeof this == 'object' && this);
75 /** Used as a reference to the global object. */
76 var root = freeGlobal || freeSelf || thisGlobal || Function('return this')();
78 /*--------------------------------------------------------------------------*/
81 * Appends the elements of `values` to `array`.
84 * @param {Array} array The array to modify.
85 * @param {Array} values The values to append.
86 * @returns {Array} Returns `array`.
88 function arrayPush(array, values) {
89 array.push.apply(array, values);
94 * The base implementation of `_.findIndex` and `_.findLastIndex` without
95 * support for iteratee shorthands.
98 * @param {Array} array The array to search.
99 * @param {Function} predicate The function invoked per iteration.
100 * @param {number} fromIndex The index to search from.
101 * @param {boolean} [fromRight] Specify iterating from right to left.
102 * @returns {number} Returns the index of the matched value, else `-1`.
104 function baseFindIndex(array, predicate, fromIndex, fromRight) {
105 var length = array.length,
106 index = fromIndex + (fromRight ? 1 : -1);
108 while ((fromRight ? index-- : ++index < length)) {
109 if (predicate(array[index], index, array)) {
117 * The base implementation of `_.reduce` and `_.reduceRight`, without support
118 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
121 * @param {Array|Object} collection The collection to iterate over.
122 * @param {Function} iteratee The function invoked per iteration.
123 * @param {*} accumulator The initial value.
124 * @param {boolean} initAccum Specify using the first or last element of
125 * `collection` as the initial value.
126 * @param {Function} eachFunc The function to iterate over `collection`.
127 * @returns {*} Returns the accumulated value.
129 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
130 eachFunc(collection, function(value, index, collection) {
131 accumulator = initAccum
132 ? (initAccum = false, value)
133 : iteratee(accumulator, value, index, collection);
139 * The base implementation of `_.values` and `_.valuesIn` which creates an
140 * array of `object` property values corresponding to the property names
144 * @param {Object} object The object to query.
145 * @param {Array} props The property names to get values for.
146 * @returns {Object} Returns the array of property values.
148 function baseValues(object, props) {
149 return baseMap(props, function(key) {
155 * Checks if `value` is a global object.
158 * @param {*} value The value to check.
159 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
161 function checkGlobal(value) {
162 return (value && value.Object === Object) ? value : null;
166 * Used by `_.escape` to convert characters to HTML entities.
169 * @param {string} chr The matched character to escape.
170 * @returns {string} Returns the escaped character.
172 function escapeHtmlChar(chr) {
173 return htmlEscapes[chr];
177 * Checks if `value` is a host object in IE < 9.
180 * @param {*} value The value to check.
181 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
183 function isHostObject() {
187 /*--------------------------------------------------------------------------*/
189 /** Used for built-in method references. */
190 var arrayProto = Array.prototype,
191 objectProto = Object.prototype;
193 /** Used to check objects for own properties. */
194 var hasOwnProperty = objectProto.hasOwnProperty;
196 /** Used to generate unique IDs. */
200 * Used to resolve the
201 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
204 var objectToString = objectProto.toString;
206 /** Used to restore the original `_` reference in `_.noConflict`. */
207 var oldDash = root._;
209 /** Built-in value references. */
210 var objectCreate = Object.create,
211 propertyIsEnumerable = objectProto.propertyIsEnumerable;
213 /* Built-in method references for those with the same name as other `lodash` methods. */
214 var nativeIsFinite = root.isFinite,
215 nativeKeys = Object.keys,
216 nativeMax = Math.max;
218 /*------------------------------------------------------------------------*/
221 * Creates a `lodash` object which wraps `value` to enable implicit method
222 * chain sequences. Methods that operate on and return arrays, collections,
223 * and functions can be chained together. Methods that retrieve a single value
224 * or may return a primitive value will automatically end the chain sequence
225 * and return the unwrapped value. Otherwise, the value must be unwrapped
228 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
229 * enabled using `_.chain`.
231 * The execution of chained methods is lazy, that is, it's deferred until
232 * `_#value` is implicitly or explicitly called.
234 * Lazy evaluation allows several methods to support shortcut fusion.
235 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
236 * the creation of intermediate arrays and can greatly reduce the number of
237 * iteratee executions. Sections of a chain sequence qualify for shortcut
238 * fusion if the section is applied to an array of at least `200` elements
239 * and any iteratees accept only one argument. The heuristic for whether a
240 * section qualifies for shortcut fusion is subject to change.
242 * Chaining is supported in custom builds as long as the `_#value` method is
243 * directly or indirectly included in the build.
245 * In addition to lodash methods, wrappers have `Array` and `String` methods.
247 * The wrapper `Array` methods are:
248 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
250 * The wrapper `String` methods are:
251 * `replace` and `split`
253 * The wrapper methods that support shortcut fusion are:
254 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
255 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
256 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
258 * The chainable wrapper methods are:
259 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
260 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
261 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
262 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
263 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
264 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
265 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
266 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
267 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
268 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
269 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
270 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
271 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
272 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
273 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
274 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
275 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
276 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
277 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
278 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
279 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
280 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
281 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
282 * `zipObject`, `zipObjectDeep`, and `zipWith`
284 * The wrapper methods that are **not** chainable by default are:
285 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
286 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`,
287 * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`,
288 * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`,
289 * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
290 * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`,
291 * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`,
292 * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
293 * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
294 * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`,
295 * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
296 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
297 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
298 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
299 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
300 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
301 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
302 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
303 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
304 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
305 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
306 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
307 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
308 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
309 * `upperFirst`, `value`, and `words`
314 * @param {*} value The value to wrap in a `lodash` instance.
315 * @returns {Object} Returns the new `lodash` wrapper instance.
318 * function square(n) {
322 * var wrapped = _([1, 2, 3]);
324 * // Returns an unwrapped value.
325 * wrapped.reduce(_.add);
328 * // Returns a wrapped value.
329 * var squares = wrapped.map(square);
331 * _.isArray(squares);
334 * _.isArray(squares.value());
337 function lodash(value) {
338 return value instanceof LodashWrapper
340 : new LodashWrapper(value);
344 * The base constructor for creating `lodash` wrapper objects.
347 * @param {*} value The value to wrap.
348 * @param {boolean} [chainAll] Enable explicit method chain sequences.
350 function LodashWrapper(value, chainAll) {
351 this.__wrapped__ = value;
352 this.__actions__ = [];
353 this.__chain__ = !!chainAll;
356 LodashWrapper.prototype = baseCreate(lodash.prototype);
357 LodashWrapper.prototype.constructor = LodashWrapper;
359 /*------------------------------------------------------------------------*/
362 * Used by `_.defaults` to customize its `_.assignIn` use.
365 * @param {*} objValue The destination value.
366 * @param {*} srcValue The source value.
367 * @param {string} key The key of the property to assign.
368 * @param {Object} object The parent object of `objValue`.
369 * @returns {*} Returns the value to assign.
371 function assignInDefaults(objValue, srcValue, key, object) {
372 if (objValue === undefined ||
373 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
380 * Assigns `value` to `key` of `object` if the existing value is not equivalent
381 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
382 * for equality comparisons.
385 * @param {Object} object The object to modify.
386 * @param {string} key The key of the property to assign.
387 * @param {*} value The value to assign.
389 function assignValue(object, key, value) {
390 var objValue = object[key];
391 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
392 (value === undefined && !(key in object))) {
398 * The base implementation of `_.create` without support for assigning
399 * properties to the created object.
402 * @param {Object} prototype The object to inherit from.
403 * @returns {Object} Returns the new object.
405 function baseCreate(proto) {
406 return isObject(proto) ? objectCreate(proto) : {};
410 * The base implementation of `_.delay` and `_.defer` which accepts an array
411 * of `func` arguments.
414 * @param {Function} func The function to delay.
415 * @param {number} wait The number of milliseconds to delay invocation.
416 * @param {Object} args The arguments to provide to `func`.
417 * @returns {number} Returns the timer id.
419 function baseDelay(func, wait, args) {
420 if (typeof func != 'function') {
421 throw new TypeError(FUNC_ERROR_TEXT);
423 return setTimeout(function() { func.apply(undefined, args); }, wait);
427 * The base implementation of `_.forEach` without support for iteratee shorthands.
430 * @param {Array|Object} collection The collection to iterate over.
431 * @param {Function} iteratee The function invoked per iteration.
432 * @returns {Array|Object} Returns `collection`.
434 var baseEach = createBaseEach(baseForOwn);
437 * The base implementation of `_.every` without support for iteratee shorthands.
440 * @param {Array|Object} collection The collection to iterate over.
441 * @param {Function} predicate The function invoked per iteration.
442 * @returns {boolean} Returns `true` if all elements pass the predicate check,
445 function baseEvery(collection, predicate) {
447 baseEach(collection, function(value, index, collection) {
448 result = !!predicate(value, index, collection);
455 * The base implementation of methods like `_.max` and `_.min` which accepts a
456 * `comparator` to determine the extremum value.
459 * @param {Array} array The array to iterate over.
460 * @param {Function} iteratee The iteratee invoked per iteration.
461 * @param {Function} comparator The comparator used to compare values.
462 * @returns {*} Returns the extremum value.
464 function baseExtremum(array, iteratee, comparator) {
466 length = array.length;
468 while (++index < length) {
469 var value = array[index],
470 current = iteratee(value);
472 if (current != null && (computed === undefined
473 ? (current === current && !false)
474 : comparator(current, computed)
476 var computed = current,
484 * The base implementation of `_.filter` without support for iteratee shorthands.
487 * @param {Array|Object} collection The collection to iterate over.
488 * @param {Function} predicate The function invoked per iteration.
489 * @returns {Array} Returns the new filtered array.
491 function baseFilter(collection, predicate) {
493 baseEach(collection, function(value, index, collection) {
494 if (predicate(value, index, collection)) {
502 * The base implementation of `_.flatten` with support for restricting flattening.
505 * @param {Array} array The array to flatten.
506 * @param {number} depth The maximum recursion depth.
507 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
508 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
509 * @param {Array} [result=[]] The initial result value.
510 * @returns {Array} Returns the new flattened array.
512 function baseFlatten(array, depth, predicate, isStrict, result) {
514 length = array.length;
516 predicate || (predicate = isFlattenable);
517 result || (result = []);
519 while (++index < length) {
520 var value = array[index];
521 if (depth > 0 && predicate(value)) {
523 // Recursively flatten arrays (susceptible to call stack limits).
524 baseFlatten(value, depth - 1, predicate, isStrict, result);
526 arrayPush(result, value);
528 } else if (!isStrict) {
529 result[result.length] = value;
536 * The base implementation of `baseForOwn` which iterates over `object`
537 * properties returned by `keysFunc` and invokes `iteratee` for each property.
538 * Iteratee functions may exit iteration early by explicitly returning `false`.
541 * @param {Object} object The object to iterate over.
542 * @param {Function} iteratee The function invoked per iteration.
543 * @param {Function} keysFunc The function to get the keys of `object`.
544 * @returns {Object} Returns `object`.
546 var baseFor = createBaseFor();
549 * The base implementation of `_.forOwn` without support for iteratee shorthands.
552 * @param {Object} object The object to iterate over.
553 * @param {Function} iteratee The function invoked per iteration.
554 * @returns {Object} Returns `object`.
556 function baseForOwn(object, iteratee) {
557 return object && baseFor(object, iteratee, keys);
561 * The base implementation of `_.functions` which creates an array of
562 * `object` function property names filtered from `props`.
565 * @param {Object} object The object to inspect.
566 * @param {Array} props The property names to filter.
567 * @returns {Array} Returns the function names.
569 function baseFunctions(object, props) {
570 return baseFilter(props, function(key) {
571 return isFunction(object[key]);
576 * The base implementation of `_.gt` which doesn't coerce arguments to numbers.
579 * @param {*} value The value to compare.
580 * @param {*} other The other value to compare.
581 * @returns {boolean} Returns `true` if `value` is greater than `other`,
584 function baseGt(value, other) {
585 return value > other;
589 * The base implementation of `_.isEqual` which supports partial comparisons
590 * and tracks traversed objects.
593 * @param {*} value The value to compare.
594 * @param {*} other The other value to compare.
595 * @param {Function} [customizer] The function to customize comparisons.
596 * @param {boolean} [bitmask] The bitmask of comparison flags.
597 * The bitmask may be composed of the following flags:
598 * 1 - Unordered comparison
599 * 2 - Partial comparison
600 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
601 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
603 function baseIsEqual(value, other, customizer, bitmask, stack) {
604 if (value === other) {
607 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
608 return value !== value && other !== other;
610 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
614 * A specialized version of `baseIsEqual` for arrays and objects which performs
615 * deep comparisons and tracks traversed objects enabling objects with circular
616 * references to be compared.
619 * @param {Object} object The object to compare.
620 * @param {Object} other The other object to compare.
621 * @param {Function} equalFunc The function to determine equivalents of values.
622 * @param {Function} [customizer] The function to customize comparisons.
623 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
625 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
626 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
628 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
629 var objIsArr = isArray(object),
630 othIsArr = isArray(other),
635 objTag = objectToString.call(object);
636 objTag = objTag == argsTag ? objectTag : objTag;
639 othTag = objectToString.call(other);
640 othTag = othTag == argsTag ? objectTag : othTag;
642 var objIsObj = objTag == objectTag && !isHostObject(object),
643 othIsObj = othTag == objectTag && !isHostObject(other),
644 isSameTag = objTag == othTag;
646 stack || (stack = []);
647 var stacked = find(stack, function(entry) {
648 return entry[0] === object;
650 if (stacked && stacked[1]) {
651 return stacked[1] == other;
653 stack.push([object, other]);
654 if (isSameTag && !objIsObj) {
655 var result = (objIsArr)
656 ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
657 : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
661 if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
662 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
663 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
665 if (objIsWrapped || othIsWrapped) {
666 var objUnwrapped = objIsWrapped ? object.value() : object,
667 othUnwrapped = othIsWrapped ? other.value() : other;
669 var result = equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
677 var result = equalObjects(object, other, equalFunc, customizer, bitmask, stack);
683 * The base implementation of `_.iteratee`.
686 * @param {*} [value=_.identity] The value to convert to an iteratee.
687 * @returns {Function} Returns the iteratee.
689 function baseIteratee(func) {
690 if (typeof func == 'function') {
696 return (typeof func == 'object' ? baseMatches : baseProperty)(func);
700 * The base implementation of `_.keys` which doesn't skip the constructor
701 * property of prototypes or treat sparse arrays as dense.
704 * @param {Object} object The object to query.
705 * @returns {Array} Returns the array of property names.
707 function baseKeys(object) {
708 return nativeKeys(Object(object));
712 * The base implementation of `_.keysIn` which doesn't skip the constructor
713 * property of prototypes or treat sparse arrays as dense.
716 * @param {Object} object The object to query.
717 * @returns {Array} Returns the array of property names.
719 function baseKeysIn(object) {
720 object = object == null ? object : Object(object);
723 for (var key in object) {
730 * The base implementation of `_.lt` which doesn't coerce arguments to numbers.
733 * @param {*} value The value to compare.
734 * @param {*} other The other value to compare.
735 * @returns {boolean} Returns `true` if `value` is less than `other`,
738 function baseLt(value, other) {
739 return value < other;
743 * The base implementation of `_.map` without support for iteratee shorthands.
746 * @param {Array|Object} collection The collection to iterate over.
747 * @param {Function} iteratee The function invoked per iteration.
748 * @returns {Array} Returns the new mapped array.
750 function baseMap(collection, iteratee) {
752 result = isArrayLike(collection) ? Array(collection.length) : [];
754 baseEach(collection, function(value, key, collection) {
755 result[++index] = iteratee(value, key, collection);
761 * The base implementation of `_.matches` which doesn't clone `source`.
764 * @param {Object} source The object of property values to match.
765 * @returns {Function} Returns the new spec function.
767 function baseMatches(source) {
768 var props = keys(source);
769 return function(object) {
770 var length = props.length;
771 if (object == null) {
774 object = Object(object);
776 var key = props[length];
777 if (!(key in object &&
778 baseIsEqual(source[key], object[key], undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG)
788 * The base implementation of `_.pick` without support for individual
789 * property identifiers.
792 * @param {Object} object The source object.
793 * @param {string[]} props The property identifiers to pick.
794 * @returns {Object} Returns the new object.
796 function basePick(object, props) {
797 object = Object(object);
798 return reduce(props, function(result, key) {
800 result[key] = object[key];
807 * The base implementation of `_.property` without support for deep paths.
810 * @param {string} key The key of the property to get.
811 * @returns {Function} Returns the new accessor function.
813 function baseProperty(key) {
814 return function(object) {
815 return object == null ? undefined : object[key];
820 * The base implementation of `_.slice` without an iteratee call guard.
823 * @param {Array} array The array to slice.
824 * @param {number} [start=0] The start position.
825 * @param {number} [end=array.length] The end position.
826 * @returns {Array} Returns the slice of `array`.
828 function baseSlice(array, start, end) {
830 length = array.length;
833 start = -start > length ? 0 : (length + start);
835 end = end > length ? length : end;
839 length = start > end ? 0 : ((end - start) >>> 0);
842 var result = Array(length);
843 while (++index < length) {
844 result[index] = array[index + start];
850 * Copies the values of `source` to `array`.
853 * @param {Array} source The array to copy values from.
854 * @param {Array} [array=[]] The array to copy values to.
855 * @returns {Array} Returns `array`.
857 function copyArray(source) {
858 return baseSlice(source, 0, source.length);
862 * The base implementation of `_.some` without support for iteratee shorthands.
865 * @param {Array|Object} collection The collection to iterate over.
866 * @param {Function} predicate The function invoked per iteration.
867 * @returns {boolean} Returns `true` if any element passes the predicate check,
870 function baseSome(collection, predicate) {
873 baseEach(collection, function(value, index, collection) {
874 result = predicate(value, index, collection);
881 * The base implementation of `wrapperValue` which returns the result of
882 * performing a sequence of actions on the unwrapped `value`, where each
883 * successive action is supplied the return value of the previous.
886 * @param {*} value The unwrapped value.
887 * @param {Array} actions Actions to perform to resolve the unwrapped value.
888 * @returns {*} Returns the resolved value.
890 function baseWrapperValue(value, actions) {
892 return reduce(actions, function(result, action) {
893 return action.func.apply(action.thisArg, arrayPush([result], action.args));
898 * Compares values to sort them in ascending order.
901 * @param {*} value The value to compare.
902 * @param {*} other The other value to compare.
903 * @returns {number} Returns the sort order indicator for `value`.
905 function compareAscending(value, other) {
906 if (value !== other) {
907 var valIsDefined = value !== undefined,
908 valIsNull = value === null,
909 valIsReflexive = value === value,
912 var othIsDefined = other !== undefined,
913 othIsNull = other === null,
914 othIsReflexive = other === other,
917 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
918 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
919 (valIsNull && othIsDefined && othIsReflexive) ||
920 (!valIsDefined && othIsReflexive) ||
924 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
925 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
926 (othIsNull && valIsDefined && valIsReflexive) ||
927 (!othIsDefined && valIsReflexive) ||
936 * Copies properties of `source` to `object`.
939 * @param {Object} source The object to copy properties from.
940 * @param {Array} props The property identifiers to copy.
941 * @param {Object} [object={}] The object to copy properties to.
942 * @param {Function} [customizer] The function to customize copied values.
943 * @returns {Object} Returns `object`.
945 function copyObject(source, props, object, customizer) {
946 object || (object = {});
949 length = props.length;
951 while (++index < length) {
952 var key = props[index];
954 var newValue = customizer
955 ? customizer(object[key], source[key], key, object, source)
958 assignValue(object, key, newValue);
964 * Creates a function like `_.assign`.
967 * @param {Function} assigner The function to assign values.
968 * @returns {Function} Returns the new assigner function.
970 function createAssigner(assigner) {
971 return rest(function(object, sources) {
973 length = sources.length,
974 customizer = length > 1 ? sources[length - 1] : undefined;
976 customizer = (assigner.length > 3 && typeof customizer == 'function')
977 ? (length--, customizer)
980 object = Object(object);
981 while (++index < length) {
982 var source = sources[index];
984 assigner(object, source, index, customizer);
992 * Creates a `baseEach` or `baseEachRight` function.
995 * @param {Function} eachFunc The function to iterate over a collection.
996 * @param {boolean} [fromRight] Specify iterating from right to left.
997 * @returns {Function} Returns the new base function.
999 function createBaseEach(eachFunc, fromRight) {
1000 return function(collection, iteratee) {
1001 if (collection == null) {
1004 if (!isArrayLike(collection)) {
1005 return eachFunc(collection, iteratee);
1007 var length = collection.length,
1008 index = fromRight ? length : -1,
1009 iterable = Object(collection);
1011 while ((fromRight ? index-- : ++index < length)) {
1012 if (iteratee(iterable[index], index, iterable) === false) {
1021 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
1024 * @param {boolean} [fromRight] Specify iterating from right to left.
1025 * @returns {Function} Returns the new base function.
1027 function createBaseFor(fromRight) {
1028 return function(object, iteratee, keysFunc) {
1030 iterable = Object(object),
1031 props = keysFunc(object),
1032 length = props.length;
1035 var key = props[fromRight ? length : ++index];
1036 if (iteratee(iterable[key], key, iterable) === false) {
1045 * Creates a function that produces an instance of `Ctor` regardless of
1046 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
1049 * @param {Function} Ctor The constructor to wrap.
1050 * @returns {Function} Returns the new wrapped function.
1052 function createCtorWrapper(Ctor) {
1054 // Use a `switch` statement to work with class constructors. See
1055 // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1056 // for more details.
1057 var args = arguments;
1058 var thisBinding = baseCreate(Ctor.prototype),
1059 result = Ctor.apply(thisBinding, args);
1061 // Mimic the constructor's `return` behavior.
1062 // See https://es5.github.io/#x13.2.2 for more details.
1063 return isObject(result) ? result : thisBinding;
1068 * Creates a `_.find` or `_.findLast` function.
1071 * @param {Function} findIndexFunc The function to find the collection index.
1072 * @returns {Function} Returns the new find function.
1074 function createFind(findIndexFunc) {
1075 return function(collection, predicate, fromIndex) {
1076 var iterable = Object(collection);
1077 predicate = baseIteratee(predicate, 3);
1078 if (!isArrayLike(collection)) {
1079 var props = keys(collection);
1081 var index = findIndexFunc(props || collection, function(value, key) {
1084 value = iterable[key];
1086 return predicate(value, key, iterable);
1088 return index > -1 ? collection[props ? props[index] : index] : undefined;
1093 * Creates a function that wraps `func` to invoke it with the `this` binding
1094 * of `thisArg` and `partials` prepended to the arguments it receives.
1097 * @param {Function} func The function to wrap.
1098 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
1100 * @param {*} thisArg The `this` binding of `func`.
1101 * @param {Array} partials The arguments to prepend to those provided to
1103 * @returns {Function} Returns the new wrapped function.
1105 function createPartialWrapper(func, bitmask, thisArg, partials) {
1106 if (typeof func != 'function') {
1107 throw new TypeError(FUNC_ERROR_TEXT);
1109 var isBind = bitmask & BIND_FLAG,
1110 Ctor = createCtorWrapper(func);
1112 function wrapper() {
1114 argsLength = arguments.length,
1116 leftLength = partials.length,
1117 args = Array(leftLength + argsLength),
1118 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
1120 while (++leftIndex < leftLength) {
1121 args[leftIndex] = partials[leftIndex];
1123 while (argsLength--) {
1124 args[leftIndex++] = arguments[++argsIndex];
1126 return fn.apply(isBind ? thisArg : this, args);
1132 * A specialized version of `baseIsEqualDeep` for arrays with support for
1133 * partial deep comparisons.
1136 * @param {Array} array The array to compare.
1137 * @param {Array} other The other array to compare.
1138 * @param {Function} equalFunc The function to determine equivalents of values.
1139 * @param {Function} customizer The function to customize comparisons.
1140 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
1142 * @param {Object} stack Tracks traversed `array` and `other` objects.
1143 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1145 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
1146 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1147 arrLength = array.length,
1148 othLength = other.length;
1150 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1155 seen = (bitmask & UNORDERED_COMPARE_FLAG) ? [] : undefined;
1157 // Ignore non-index properties.
1158 while (++index < arrLength) {
1159 var arrValue = array[index],
1160 othValue = other[index];
1163 if (compared !== undefined) {
1170 // Recursively compare arrays (susceptible to call stack limits).
1172 if (!baseSome(other, function(othValue, othIndex) {
1173 if (!indexOf(seen, othIndex) &&
1174 (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
1175 return seen.push(othIndex);
1182 arrValue === othValue ||
1183 equalFunc(arrValue, othValue, customizer, bitmask, stack)
1193 * A specialized version of `baseIsEqualDeep` for comparing objects of
1194 * the same `toStringTag`.
1196 * **Note:** This function only supports comparing values with tags of
1197 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1200 * @param {Object} object The object to compare.
1201 * @param {Object} other The other object to compare.
1202 * @param {string} tag The `toStringTag` of the objects to compare.
1203 * @param {Function} equalFunc The function to determine equivalents of values.
1204 * @param {Function} customizer The function to customize comparisons.
1205 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
1207 * @param {Object} stack Tracks traversed `object` and `other` objects.
1208 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1210 function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
1215 // Coerce dates and booleans to numbers, dates to milliseconds and
1216 // booleans to `1` or `0` treating invalid dates coerced to `NaN` as
1218 return +object == +other;
1221 return object.name == other.name && object.message == other.message;
1224 // Treat `NaN` vs. `NaN` as equal.
1225 return (object != +object) ? other != +other : object == +other;
1229 // Coerce regexes to strings and treat strings, primitives and objects,
1230 // as equal. See http://www.ecma-international.org/ecma-262/6.0/#sec-regexp.prototype.tostring
1231 // for more details.
1232 return object == (other + '');
1239 * A specialized version of `baseIsEqualDeep` for objects with support for
1240 * partial deep comparisons.
1243 * @param {Object} object The object to compare.
1244 * @param {Object} other The other object to compare.
1245 * @param {Function} equalFunc The function to determine equivalents of values.
1246 * @param {Function} customizer The function to customize comparisons.
1247 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
1249 * @param {Object} stack Tracks traversed `object` and `other` objects.
1250 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1252 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
1253 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1254 objProps = keys(object),
1255 objLength = objProps.length,
1256 othProps = keys(other),
1257 othLength = othProps.length;
1259 if (objLength != othLength && !isPartial) {
1262 var index = objLength;
1264 var key = objProps[index];
1265 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1271 var skipCtor = isPartial;
1272 while (++index < objLength) {
1273 key = objProps[index];
1274 var objValue = object[key],
1275 othValue = other[key];
1278 // Recursively compare objects (susceptible to call stack limits).
1279 if (!(compared === undefined
1280 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
1286 skipCtor || (skipCtor = key == 'constructor');
1288 if (result && !skipCtor) {
1289 var objCtor = object.constructor,
1290 othCtor = other.constructor;
1292 // Non `Object` object instances with different constructors are not equal.
1293 if (objCtor != othCtor &&
1294 ('constructor' in object && 'constructor' in other) &&
1295 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1296 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1304 * Gets the "length" property value of `object`.
1306 * **Note:** This function is used to avoid a
1307 * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
1308 * Safari on at least iOS 8.1-8.3 ARM64.
1311 * @param {Object} object The object to query.
1312 * @returns {*} Returns the "length" value.
1314 var getLength = baseProperty('length');
1317 * Checks if `value` is a flattenable `arguments` object or array.
1320 * @param {*} value The value to check.
1321 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
1323 function isFlattenable(value) {
1324 return isArray(value) || isArguments(value);
1328 * Converts `value` to a string key if it's not a string or symbol.
1331 * @param {*} value The value to inspect.
1332 * @returns {string|symbol} Returns the key.
1336 /*------------------------------------------------------------------------*/
1339 * Creates an array with all falsey values removed. The values `false`, `null`,
1340 * `0`, `""`, `undefined`, and `NaN` are falsey.
1346 * @param {Array} array The array to compact.
1347 * @returns {Array} Returns the new array of filtered values.
1350 * _.compact([0, 1, false, 2, '', 3]);
1353 function compact(array) {
1354 return baseFilter(array, Boolean);
1358 * Creates a new array concatenating `array` with any additional arrays
1365 * @param {Array} array The array to concatenate.
1366 * @param {...*} [values] The values to concatenate.
1367 * @returns {Array} Returns the new concatenated array.
1371 * var other = _.concat(array, 2, [3], [[4]]);
1373 * console.log(other);
1374 * // => [1, 2, 3, [4]]
1376 * console.log(array);
1380 var length = arguments.length,
1381 args = Array(length ? length - 1 : 0),
1382 array = arguments[0],
1386 args[index - 1] = arguments[index];
1389 ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1))
1394 * This method is like `_.find` except that it returns the index of the first
1395 * element `predicate` returns truthy for instead of the element itself.
1401 * @param {Array} array The array to search.
1402 * @param {Array|Function|Object|string} [predicate=_.identity]
1403 * The function invoked per iteration.
1404 * @param {number} [fromIndex=0] The index to search from.
1405 * @returns {number} Returns the index of the found element, else `-1`.
1409 * { 'user': 'barney', 'active': false },
1410 * { 'user': 'fred', 'active': false },
1411 * { 'user': 'pebbles', 'active': true }
1414 * _.findIndex(users, function(o) { return o.user == 'barney'; });
1417 * // The `_.matches` iteratee shorthand.
1418 * _.findIndex(users, { 'user': 'fred', 'active': false });
1421 * // The `_.matchesProperty` iteratee shorthand.
1422 * _.findIndex(users, ['active', false]);
1425 * // The `_.property` iteratee shorthand.
1426 * _.findIndex(users, 'active');
1429 function findIndex(array, predicate, fromIndex) {
1430 var length = array ? array.length : 0;
1434 var index = fromIndex == null ? 0 : toInteger(fromIndex);
1436 index = nativeMax(length + index, 0);
1438 return baseFindIndex(array, baseIteratee(predicate, 3), index);
1442 * Flattens `array` a single level deep.
1448 * @param {Array} array The array to flatten.
1449 * @returns {Array} Returns the new flattened array.
1452 * _.flatten([1, [2, [3, [4]], 5]]);
1453 * // => [1, 2, [3, [4]], 5]
1455 function flatten(array) {
1456 var length = array ? array.length : 0;
1457 return length ? baseFlatten(array, 1) : [];
1461 * Recursively flattens `array`.
1467 * @param {Array} array The array to flatten.
1468 * @returns {Array} Returns the new flattened array.
1471 * _.flattenDeep([1, [2, [3, [4]], 5]]);
1472 * // => [1, 2, 3, 4, 5]
1474 function flattenDeep(array) {
1475 var length = array ? array.length : 0;
1476 return length ? baseFlatten(array, INFINITY) : [];
1480 * Gets the first element of `array`.
1487 * @param {Array} array The array to query.
1488 * @returns {*} Returns the first element of `array`.
1491 * _.head([1, 2, 3]);
1497 function head(array) {
1498 return (array && array.length) ? array[0] : undefined;
1502 * Gets the index at which the first occurrence of `value` is found in `array`
1503 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
1504 * for equality comparisons. If `fromIndex` is negative, it's used as the
1505 * offset from the end of `array`.
1511 * @param {Array} array The array to search.
1512 * @param {*} value The value to search for.
1513 * @param {number} [fromIndex=0] The index to search from.
1514 * @returns {number} Returns the index of the matched value, else `-1`.
1517 * _.indexOf([1, 2, 1, 2], 2);
1520 * // Search from the `fromIndex`.
1521 * _.indexOf([1, 2, 1, 2], 2, 2);
1524 function indexOf(array, value, fromIndex) {
1525 var length = array ? array.length : 0;
1526 if (typeof fromIndex == 'number') {
1527 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1531 var index = (fromIndex || 0) - 1,
1532 isReflexive = value === value;
1534 while (++index < length) {
1535 var other = array[index];
1536 if ((isReflexive ? other === value : other !== other)) {
1544 * Gets the last element of `array`.
1550 * @param {Array} array The array to query.
1551 * @returns {*} Returns the last element of `array`.
1554 * _.last([1, 2, 3]);
1557 function last(array) {
1558 var length = array ? array.length : 0;
1559 return length ? array[length - 1] : undefined;
1563 * Creates a slice of `array` from `start` up to, but not including, `end`.
1565 * **Note:** This method is used instead of
1566 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
1573 * @param {Array} array The array to slice.
1574 * @param {number} [start=0] The start position.
1575 * @param {number} [end=array.length] The end position.
1576 * @returns {Array} Returns the slice of `array`.
1578 function slice(array, start, end) {
1579 var length = array ? array.length : 0;
1580 start = start == null ? 0 : +start;
1581 end = end === undefined ? length : +end;
1582 return length ? baseSlice(array, start, end) : [];
1585 /*------------------------------------------------------------------------*/
1588 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
1589 * chain sequences enabled. The result of such sequences must be unwrapped
1596 * @param {*} value The value to wrap.
1597 * @returns {Object} Returns the new `lodash` wrapper instance.
1601 * { 'user': 'barney', 'age': 36 },
1602 * { 'user': 'fred', 'age': 40 },
1603 * { 'user': 'pebbles', 'age': 1 }
1609 * .map(function(o) {
1610 * return o.user + ' is ' + o.age;
1614 * // => 'pebbles is 1'
1616 function chain(value) {
1617 var result = lodash(value);
1618 result.__chain__ = true;
1623 * This method invokes `interceptor` and returns `value`. The interceptor
1624 * is invoked with one argument; (value). The purpose of this method is to
1625 * "tap into" a method chain sequence in order to modify intermediate results.
1631 * @param {*} value The value to provide to `interceptor`.
1632 * @param {Function} interceptor The function to invoke.
1633 * @returns {*} Returns `value`.
1637 * .tap(function(array) {
1638 * // Mutate input array.
1645 function tap(value, interceptor) {
1651 * This method is like `_.tap` except that it returns the result of `interceptor`.
1652 * The purpose of this method is to "pass thru" values replacing intermediate
1653 * results in a method chain sequence.
1659 * @param {*} value The value to provide to `interceptor`.
1660 * @param {Function} interceptor The function to invoke.
1661 * @returns {*} Returns the result of `interceptor`.
1667 * .thru(function(value) {
1673 function thru(value, interceptor) {
1674 return interceptor(value);
1678 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
1684 * @returns {Object} Returns the new `lodash` wrapper instance.
1688 * { 'user': 'barney', 'age': 36 },
1689 * { 'user': 'fred', 'age': 40 }
1692 * // A sequence without explicit chaining.
1694 * // => { 'user': 'barney', 'age': 36 }
1696 * // A sequence with explicit chaining.
1702 * // => { 'user': 'barney' }
1704 function wrapperChain() {
1709 * Executes the chain sequence to resolve the unwrapped value.
1714 * @alias toJSON, valueOf
1716 * @returns {*} Returns the resolved unwrapped value.
1719 * _([1, 2, 3]).value();
1722 function wrapperValue() {
1723 return baseWrapperValue(this.__wrapped__, this.__actions__);
1726 /*------------------------------------------------------------------------*/
1729 * Checks if `predicate` returns truthy for **all** elements of `collection`.
1730 * Iteration is stopped once `predicate` returns falsey. The predicate is
1731 * invoked with three arguments: (value, index|key, collection).
1736 * @category Collection
1737 * @param {Array|Object} collection The collection to iterate over.
1738 * @param {Array|Function|Object|string} [predicate=_.identity]
1739 * The function invoked per iteration.
1740 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
1741 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1745 * _.every([true, 1, null, 'yes'], Boolean);
1749 * { 'user': 'barney', 'age': 36, 'active': false },
1750 * { 'user': 'fred', 'age': 40, 'active': false }
1753 * // The `_.matches` iteratee shorthand.
1754 * _.every(users, { 'user': 'barney', 'active': false });
1757 * // The `_.matchesProperty` iteratee shorthand.
1758 * _.every(users, ['active', false]);
1761 * // The `_.property` iteratee shorthand.
1762 * _.every(users, 'active');
1765 function every(collection, predicate, guard) {
1766 predicate = guard ? undefined : predicate;
1767 return baseEvery(collection, baseIteratee(predicate));
1771 * Iterates over elements of `collection`, returning an array of all elements
1772 * `predicate` returns truthy for. The predicate is invoked with three
1773 * arguments: (value, index|key, collection).
1778 * @category Collection
1779 * @param {Array|Object} collection The collection to iterate over.
1780 * @param {Array|Function|Object|string} [predicate=_.identity]
1781 * The function invoked per iteration.
1782 * @returns {Array} Returns the new filtered array.
1787 * { 'user': 'barney', 'age': 36, 'active': true },
1788 * { 'user': 'fred', 'age': 40, 'active': false }
1791 * _.filter(users, function(o) { return !o.active; });
1792 * // => objects for ['fred']
1794 * // The `_.matches` iteratee shorthand.
1795 * _.filter(users, { 'age': 36, 'active': true });
1796 * // => objects for ['barney']
1798 * // The `_.matchesProperty` iteratee shorthand.
1799 * _.filter(users, ['active', false]);
1800 * // => objects for ['fred']
1802 * // The `_.property` iteratee shorthand.
1803 * _.filter(users, 'active');
1804 * // => objects for ['barney']
1806 function filter(collection, predicate) {
1807 return baseFilter(collection, baseIteratee(predicate));
1811 * Iterates over elements of `collection`, returning the first element
1812 * `predicate` returns truthy for. The predicate is invoked with three
1813 * arguments: (value, index|key, collection).
1818 * @category Collection
1819 * @param {Array|Object} collection The collection to search.
1820 * @param {Array|Function|Object|string} [predicate=_.identity]
1821 * The function invoked per iteration.
1822 * @param {number} [fromIndex=0] The index to search from.
1823 * @returns {*} Returns the matched element, else `undefined`.
1827 * { 'user': 'barney', 'age': 36, 'active': true },
1828 * { 'user': 'fred', 'age': 40, 'active': false },
1829 * { 'user': 'pebbles', 'age': 1, 'active': true }
1832 * _.find(users, function(o) { return o.age < 40; });
1833 * // => object for 'barney'
1835 * // The `_.matches` iteratee shorthand.
1836 * _.find(users, { 'age': 1, 'active': true });
1837 * // => object for 'pebbles'
1839 * // The `_.matchesProperty` iteratee shorthand.
1840 * _.find(users, ['active', false]);
1841 * // => object for 'fred'
1843 * // The `_.property` iteratee shorthand.
1844 * _.find(users, 'active');
1845 * // => object for 'barney'
1847 var find = createFind(findIndex);
1850 * Iterates over elements of `collection` and invokes `iteratee` for each element.
1851 * The iteratee is invoked with three arguments: (value, index|key, collection).
1852 * Iteratee functions may exit iteration early by explicitly returning `false`.
1854 * **Note:** As with other "Collections" methods, objects with a "length"
1855 * property are iterated like arrays. To avoid this behavior use `_.forIn`
1856 * or `_.forOwn` for object iteration.
1862 * @category Collection
1863 * @param {Array|Object} collection The collection to iterate over.
1864 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1865 * @returns {Array|Object} Returns `collection`.
1866 * @see _.forEachRight
1869 * _([1, 2]).forEach(function(value) {
1870 * console.log(value);
1872 * // => Logs `1` then `2`.
1874 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
1877 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
1879 function forEach(collection, iteratee) {
1880 return baseEach(collection, baseIteratee(iteratee));
1884 * Creates an array of values by running each element in `collection` thru
1885 * `iteratee`. The iteratee is invoked with three arguments:
1886 * (value, index|key, collection).
1888 * Many lodash methods are guarded to work as iteratees for methods like
1889 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
1891 * The guarded methods are:
1892 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
1893 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
1894 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
1895 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
1900 * @category Collection
1901 * @param {Array|Object} collection The collection to iterate over.
1902 * @param {Array|Function|Object|string} [iteratee=_.identity]
1903 * The function invoked per iteration.
1904 * @returns {Array} Returns the new mapped array.
1907 * function square(n) {
1911 * _.map([4, 8], square);
1914 * _.map({ 'a': 4, 'b': 8 }, square);
1915 * // => [16, 64] (iteration order is not guaranteed)
1918 * { 'user': 'barney' },
1919 * { 'user': 'fred' }
1922 * // The `_.property` iteratee shorthand.
1923 * _.map(users, 'user');
1924 * // => ['barney', 'fred']
1926 function map(collection, iteratee) {
1927 return baseMap(collection, baseIteratee(iteratee));
1931 * Reduces `collection` to a value which is the accumulated result of running
1932 * each element in `collection` thru `iteratee`, where each successive
1933 * invocation is supplied the return value of the previous. If `accumulator`
1934 * is not given, the first element of `collection` is used as the initial
1935 * value. The iteratee is invoked with four arguments:
1936 * (accumulator, value, index|key, collection).
1938 * Many lodash methods are guarded to work as iteratees for methods like
1939 * `_.reduce`, `_.reduceRight`, and `_.transform`.
1941 * The guarded methods are:
1942 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
1948 * @category Collection
1949 * @param {Array|Object} collection The collection to iterate over.
1950 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1951 * @param {*} [accumulator] The initial value.
1952 * @returns {*} Returns the accumulated value.
1953 * @see _.reduceRight
1956 * _.reduce([1, 2], function(sum, n) {
1961 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
1962 * (result[value] || (result[value] = [])).push(key);
1965 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
1967 function reduce(collection, iteratee, accumulator) {
1968 return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
1972 * Gets the size of `collection` by returning its length for array-like
1973 * values or the number of own enumerable string keyed properties for objects.
1978 * @category Collection
1979 * @param {Array|Object} collection The collection to inspect.
1980 * @returns {number} Returns the collection size.
1983 * _.size([1, 2, 3]);
1986 * _.size({ 'a': 1, 'b': 2 });
1989 * _.size('pebbles');
1992 function size(collection) {
1993 if (collection == null) {
1996 collection = isArrayLike(collection) ? collection : keys(collection);
1997 return collection.length;
2001 * Checks if `predicate` returns truthy for **any** element of `collection`.
2002 * Iteration is stopped once `predicate` returns truthy. The predicate is
2003 * invoked with three arguments: (value, index|key, collection).
2008 * @category Collection
2009 * @param {Array|Object} collection The collection to iterate over.
2010 * @param {Array|Function|Object|string} [predicate=_.identity]
2011 * The function invoked per iteration.
2012 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
2013 * @returns {boolean} Returns `true` if any element passes the predicate check,
2017 * _.some([null, 0, 'yes', false], Boolean);
2021 * { 'user': 'barney', 'active': true },
2022 * { 'user': 'fred', 'active': false }
2025 * // The `_.matches` iteratee shorthand.
2026 * _.some(users, { 'user': 'barney', 'active': false });
2029 * // The `_.matchesProperty` iteratee shorthand.
2030 * _.some(users, ['active', false]);
2033 * // The `_.property` iteratee shorthand.
2034 * _.some(users, 'active');
2037 function some(collection, predicate, guard) {
2038 predicate = guard ? undefined : predicate;
2039 return baseSome(collection, baseIteratee(predicate));
2043 * Creates an array of elements, sorted in ascending order by the results of
2044 * running each element in a collection thru each iteratee. This method
2045 * performs a stable sort, that is, it preserves the original sort order of
2046 * equal elements. The iteratees are invoked with one argument: (value).
2051 * @category Collection
2052 * @param {Array|Object} collection The collection to iterate over.
2053 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
2054 * [iteratees=[_.identity]] The iteratees to sort by.
2055 * @returns {Array} Returns the new sorted array.
2059 * { 'user': 'fred', 'age': 48 },
2060 * { 'user': 'barney', 'age': 36 },
2061 * { 'user': 'fred', 'age': 40 },
2062 * { 'user': 'barney', 'age': 34 }
2065 * _.sortBy(users, function(o) { return o.user; });
2066 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
2068 * _.sortBy(users, ['user', 'age']);
2069 * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
2071 * _.sortBy(users, 'user', function(o) {
2072 * return Math.floor(o.age / 10);
2074 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
2076 function sortBy(collection, iteratee) {
2078 iteratee = baseIteratee(iteratee);
2080 return baseMap(baseMap(collection, function(value, key, collection) {
2081 return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2082 }).sort(function(object, other) {
2083 return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2084 }), baseProperty('value'));
2087 /*------------------------------------------------------------------------*/
2090 * Creates a function that invokes `func`, with the `this` binding and arguments
2091 * of the created function, while it's called less than `n` times. Subsequent
2092 * calls to the created function return the result of the last `func` invocation.
2097 * @category Function
2098 * @param {number} n The number of calls at which `func` is no longer invoked.
2099 * @param {Function} func The function to restrict.
2100 * @returns {Function} Returns the new restricted function.
2103 * jQuery(element).on('click', _.before(5, addContactToList));
2104 * // => allows adding up to 4 contacts to the list
2106 function before(n, func) {
2108 if (typeof func != 'function') {
2109 throw new TypeError(FUNC_ERROR_TEXT);
2114 result = func.apply(this, arguments);
2124 * Creates a function that invokes `func` with the `this` binding of `thisArg`
2125 * and `partials` prepended to the arguments it receives.
2127 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2128 * may be used as a placeholder for partially applied arguments.
2130 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
2131 * property of bound functions.
2136 * @category Function
2137 * @param {Function} func The function to bind.
2138 * @param {*} thisArg The `this` binding of `func`.
2139 * @param {...*} [partials] The arguments to be partially applied.
2140 * @returns {Function} Returns the new bound function.
2143 * var greet = function(greeting, punctuation) {
2144 * return greeting + ' ' + this.user + punctuation;
2147 * var object = { 'user': 'fred' };
2149 * var bound = _.bind(greet, object, 'hi');
2153 * // Bound with placeholders.
2154 * var bound = _.bind(greet, object, _, '!');
2158 var bind = rest(function(func, thisArg, partials) {
2159 return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
2163 * Defers invoking the `func` until the current call stack has cleared. Any
2164 * additional arguments are provided to `func` when it's invoked.
2169 * @category Function
2170 * @param {Function} func The function to defer.
2171 * @param {...*} [args] The arguments to invoke `func` with.
2172 * @returns {number} Returns the timer id.
2175 * _.defer(function(text) {
2176 * console.log(text);
2178 * // => Logs 'deferred' after one or more milliseconds.
2180 var defer = rest(function(func, args) {
2181 return baseDelay(func, 1, args);
2185 * Invokes `func` after `wait` milliseconds. Any additional arguments are
2186 * provided to `func` when it's invoked.
2191 * @category Function
2192 * @param {Function} func The function to delay.
2193 * @param {number} wait The number of milliseconds to delay invocation.
2194 * @param {...*} [args] The arguments to invoke `func` with.
2195 * @returns {number} Returns the timer id.
2198 * _.delay(function(text) {
2199 * console.log(text);
2200 * }, 1000, 'later');
2201 * // => Logs 'later' after one second.
2203 var delay = rest(function(func, wait, args) {
2204 return baseDelay(func, toNumber(wait) || 0, args);
2208 * Creates a function that negates the result of the predicate `func`. The
2209 * `func` predicate is invoked with the `this` binding and arguments of the
2215 * @category Function
2216 * @param {Function} predicate The predicate to negate.
2217 * @returns {Function} Returns the new negated function.
2220 * function isEven(n) {
2221 * return n % 2 == 0;
2224 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2227 function negate(predicate) {
2228 if (typeof predicate != 'function') {
2229 throw new TypeError(FUNC_ERROR_TEXT);
2232 return !predicate.apply(this, arguments);
2237 * Creates a function that is restricted to invoking `func` once. Repeat calls
2238 * to the function return the value of the first invocation. The `func` is
2239 * invoked with the `this` binding and arguments of the created function.
2244 * @category Function
2245 * @param {Function} func The function to restrict.
2246 * @returns {Function} Returns the new restricted function.
2249 * var initialize = _.once(createApplication);
2252 * // `initialize` invokes `createApplication` once
2254 function once(func) {
2255 return before(2, func);
2259 * Creates a function that invokes `func` with the `this` binding of the
2260 * created function and arguments from `start` and beyond provided as
2263 * **Note:** This method is based on the
2264 * [rest parameter](https://mdn.io/rest_parameters).
2269 * @category Function
2270 * @param {Function} func The function to apply a rest parameter to.
2271 * @param {number} [start=func.length-1] The start position of the rest parameter.
2272 * @returns {Function} Returns the new function.
2275 * var say = _.rest(function(what, names) {
2276 * return what + ' ' + _.initial(names).join(', ') +
2277 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
2280 * say('hello', 'fred', 'barney', 'pebbles');
2281 * // => 'hello fred, barney, & pebbles'
2283 function rest(func, start) {
2284 if (typeof func != 'function') {
2285 throw new TypeError(FUNC_ERROR_TEXT);
2287 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
2289 var args = arguments,
2291 length = nativeMax(args.length - start, 0),
2292 array = Array(length);
2294 while (++index < length) {
2295 array[index] = args[start + index];
2297 var otherArgs = Array(start + 1);
2299 while (++index < start) {
2300 otherArgs[index] = args[index];
2302 otherArgs[start] = array;
2303 return func.apply(this, otherArgs);
2307 /*------------------------------------------------------------------------*/
2310 * Creates a shallow clone of `value`.
2312 * **Note:** This method is loosely based on the
2313 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2314 * and supports cloning arrays, array buffers, booleans, date objects, maps,
2315 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2316 * arrays. The own enumerable properties of `arguments` objects are cloned
2317 * as plain objects. An empty object is returned for uncloneable values such
2318 * as error objects, functions, DOM nodes, and WeakMaps.
2324 * @param {*} value The value to clone.
2325 * @returns {*} Returns the cloned value.
2329 * var objects = [{ 'a': 1 }, { 'b': 2 }];
2331 * var shallow = _.clone(objects);
2332 * console.log(shallow[0] === objects[0]);
2335 function clone(value) {
2336 if (!isObject(value)) {
2339 return isArray(value) ? copyArray(value) : copyObject(value, keys(value));
2344 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2345 * comparison between two values to determine if they are equivalent.
2351 * @param {*} value The value to compare.
2352 * @param {*} other The other value to compare.
2353 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2356 * var object = { 'user': 'fred' };
2357 * var other = { 'user': 'fred' };
2359 * _.eq(object, object);
2362 * _.eq(object, other);
2368 * _.eq('a', Object('a'));
2374 function eq(value, other) {
2375 return value === other || (value !== value && other !== other);
2379 * Checks if `value` is likely an `arguments` object.
2385 * @param {*} value The value to check.
2386 * @returns {boolean} Returns `true` if `value` is correctly classified,
2390 * _.isArguments(function() { return arguments; }());
2393 * _.isArguments([1, 2, 3]);
2396 function isArguments(value) {
2397 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
2398 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
2399 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
2403 * Checks if `value` is classified as an `Array` object.
2410 * @param {*} value The value to check.
2411 * @returns {boolean} Returns `true` if `value` is correctly classified,
2415 * _.isArray([1, 2, 3]);
2418 * _.isArray(document.body.children);
2424 * _.isArray(_.noop);
2427 var isArray = Array.isArray;
2430 * Checks if `value` is array-like. A value is considered array-like if it's
2431 * not a function and has a `value.length` that's an integer greater than or
2432 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2438 * @param {*} value The value to check.
2439 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2442 * _.isArrayLike([1, 2, 3]);
2445 * _.isArrayLike(document.body.children);
2448 * _.isArrayLike('abc');
2451 * _.isArrayLike(_.noop);
2454 function isArrayLike(value) {
2455 return value != null && isLength(getLength(value)) && !isFunction(value);
2459 * This method is like `_.isArrayLike` except that it also checks if `value`
2466 * @param {*} value The value to check.
2467 * @returns {boolean} Returns `true` if `value` is an array-like object,
2471 * _.isArrayLikeObject([1, 2, 3]);
2474 * _.isArrayLikeObject(document.body.children);
2477 * _.isArrayLikeObject('abc');
2480 * _.isArrayLikeObject(_.noop);
2483 function isArrayLikeObject(value) {
2484 return isObjectLike(value) && isArrayLike(value);
2488 * Checks if `value` is classified as a boolean primitive or object.
2494 * @param {*} value The value to check.
2495 * @returns {boolean} Returns `true` if `value` is correctly classified,
2499 * _.isBoolean(false);
2502 * _.isBoolean(null);
2505 function isBoolean(value) {
2506 return value === true || value === false ||
2507 (isObjectLike(value) && objectToString.call(value) == boolTag);
2511 * Checks if `value` is classified as a `Date` object.
2517 * @param {*} value The value to check.
2518 * @returns {boolean} Returns `true` if `value` is correctly classified,
2522 * _.isDate(new Date);
2525 * _.isDate('Mon April 23 2012');
2528 function isDate(value) {
2529 return isObjectLike(value) && objectToString.call(value) == dateTag;
2533 * Checks if `value` is an empty object, collection, map, or set.
2535 * Objects are considered empty if they have no own enumerable string keyed
2538 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
2539 * jQuery-like collections are considered empty if they have a `length` of `0`.
2540 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
2546 * @param {*} value The value to check.
2547 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2559 * _.isEmpty([1, 2, 3]);
2562 * _.isEmpty({ 'a': 1 });
2565 function isEmpty(value) {
2566 if (isArrayLike(value) &&
2567 (isArray(value) || isString(value) ||
2568 isFunction(value.splice) || isArguments(value))) {
2569 return !value.length;
2571 return !keys(value).length;
2575 * Performs a deep comparison between two values to determine if they are
2578 * **Note:** This method supports comparing arrays, array buffers, booleans,
2579 * date objects, error objects, maps, numbers, `Object` objects, regexes,
2580 * sets, strings, symbols, and typed arrays. `Object` objects are compared
2581 * by their own, not inherited, enumerable properties. Functions and DOM
2582 * nodes are **not** supported.
2588 * @param {*} value The value to compare.
2589 * @param {*} other The other value to compare.
2590 * @returns {boolean} Returns `true` if the values are equivalent,
2594 * var object = { 'user': 'fred' };
2595 * var other = { 'user': 'fred' };
2597 * _.isEqual(object, other);
2603 function isEqual(value, other) {
2604 return baseIsEqual(value, other);
2608 * Checks if `value` is a finite primitive number.
2610 * **Note:** This method is based on
2611 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
2617 * @param {*} value The value to check.
2618 * @returns {boolean} Returns `true` if `value` is a finite number,
2625 * _.isFinite(Number.MIN_VALUE);
2628 * _.isFinite(Infinity);
2634 function isFinite(value) {
2635 return typeof value == 'number' && nativeIsFinite(value);
2639 * Checks if `value` is classified as a `Function` object.
2645 * @param {*} value The value to check.
2646 * @returns {boolean} Returns `true` if `value` is correctly classified,
2653 * _.isFunction(/abc/);
2656 function isFunction(value) {
2657 // The use of `Object#toString` avoids issues with the `typeof` operator
2658 // in Safari 8 which returns 'object' for typed array and weak map constructors,
2659 // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
2660 var tag = isObject(value) ? objectToString.call(value) : '';
2661 return tag == funcTag || tag == genTag;
2665 * Checks if `value` is a valid array-like length.
2667 * **Note:** This function is loosely based on
2668 * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
2674 * @param {*} value The value to check.
2675 * @returns {boolean} Returns `true` if `value` is a valid length,
2682 * _.isLength(Number.MIN_VALUE);
2685 * _.isLength(Infinity);
2691 function isLength(value) {
2692 return typeof value == 'number' &&
2693 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2697 * Checks if `value` is the
2698 * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
2699 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2705 * @param {*} value The value to check.
2706 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2712 * _.isObject([1, 2, 3]);
2715 * _.isObject(_.noop);
2721 function isObject(value) {
2722 var type = typeof value;
2723 return !!value && (type == 'object' || type == 'function');
2727 * Checks if `value` is object-like. A value is object-like if it's not `null`
2728 * and has a `typeof` result of "object".
2734 * @param {*} value The value to check.
2735 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2738 * _.isObjectLike({});
2741 * _.isObjectLike([1, 2, 3]);
2744 * _.isObjectLike(_.noop);
2747 * _.isObjectLike(null);
2750 function isObjectLike(value) {
2751 return !!value && typeof value == 'object';
2755 * Checks if `value` is `NaN`.
2757 * **Note:** This method is based on
2758 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
2759 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
2760 * `undefined` and other non-number values.
2766 * @param {*} value The value to check.
2767 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2773 * _.isNaN(new Number(NaN));
2779 * _.isNaN(undefined);
2782 function isNaN(value) {
2783 // An `NaN` primitive is the only value that is not equal to itself.
2784 // Perform the `toStringTag` check first to avoid errors with some
2785 // ActiveX objects in IE.
2786 return isNumber(value) && value != +value;
2790 * Checks if `value` is `null`.
2796 * @param {*} value The value to check.
2797 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2806 function isNull(value) {
2807 return value === null;
2811 * Checks if `value` is classified as a `Number` primitive or object.
2813 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
2814 * classified as numbers, use the `_.isFinite` method.
2820 * @param {*} value The value to check.
2821 * @returns {boolean} Returns `true` if `value` is correctly classified,
2828 * _.isNumber(Number.MIN_VALUE);
2831 * _.isNumber(Infinity);
2837 function isNumber(value) {
2838 return typeof value == 'number' ||
2839 (isObjectLike(value) && objectToString.call(value) == numberTag);
2843 * Checks if `value` is classified as a `RegExp` object.
2849 * @param {*} value The value to check.
2850 * @returns {boolean} Returns `true` if `value` is correctly classified,
2854 * _.isRegExp(/abc/);
2857 * _.isRegExp('/abc/');
2860 function isRegExp(value) {
2861 return isObject(value) && objectToString.call(value) == regexpTag;
2865 * Checks if `value` is classified as a `String` primitive or object.
2871 * @param {*} value The value to check.
2872 * @returns {boolean} Returns `true` if `value` is correctly classified,
2876 * _.isString('abc');
2882 function isString(value) {
2883 return typeof value == 'string' ||
2884 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
2888 * Checks if `value` is `undefined`.
2894 * @param {*} value The value to check.
2895 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
2898 * _.isUndefined(void 0);
2901 * _.isUndefined(null);
2904 function isUndefined(value) {
2905 return value === undefined;
2909 * Converts `value` to an array.
2915 * @param {*} value The value to convert.
2916 * @returns {Array} Returns the converted array.
2919 * _.toArray({ 'a': 1, 'b': 2 });
2923 * // => ['a', 'b', 'c']
2931 function toArray(value) {
2932 if (!isArrayLike(value)) {
2933 return values(value);
2935 return value.length ? copyArray(value) : [];
2939 * Converts `value` to an integer.
2941 * **Note:** This method is loosely based on
2942 * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
2948 * @param {*} value The value to convert.
2949 * @returns {number} Returns the converted integer.
2955 * _.toInteger(Number.MIN_VALUE);
2958 * _.toInteger(Infinity);
2959 * // => 1.7976931348623157e+308
2961 * _.toInteger('3.2');
2964 var toInteger = Number;
2967 * Converts `value` to a number.
2973 * @param {*} value The value to process.
2974 * @returns {number} Returns the number.
2980 * _.toNumber(Number.MIN_VALUE);
2983 * _.toNumber(Infinity);
2986 * _.toNumber('3.2');
2989 var toNumber = Number;
2992 * Converts `value` to a string. An empty string is returned for `null`
2993 * and `undefined` values. The sign of `-0` is preserved.
2999 * @param {*} value The value to process.
3000 * @returns {string} Returns the string.
3009 * _.toString([1, 2, 3]);
3012 function toString(value) {
3013 if (typeof value == 'string') {
3016 return value == null ? '' : (value + '');
3019 /*------------------------------------------------------------------------*/
3022 * Assigns own enumerable string keyed properties of source objects to the
3023 * destination object. Source objects are applied from left to right.
3024 * Subsequent sources overwrite property assignments of previous sources.
3026 * **Note:** This method mutates `object` and is loosely based on
3027 * [`Object.assign`](https://mdn.io/Object/assign).
3033 * @param {Object} object The destination object.
3034 * @param {...Object} [sources] The source objects.
3035 * @returns {Object} Returns `object`.
3047 * Foo.prototype.d = 4;
3048 * Bar.prototype.f = 6;
3050 * _.assign({ 'a': 1 }, new Foo, new Bar);
3051 * // => { 'a': 1, 'c': 3, 'e': 5 }
3053 var assign = createAssigner(function(object, source) {
3054 copyObject(source, keys(source), object);
3058 * This method is like `_.assign` except that it iterates over own and
3059 * inherited source properties.
3061 * **Note:** This method mutates `object`.
3068 * @param {Object} object The destination object.
3069 * @param {...Object} [sources] The source objects.
3070 * @returns {Object} Returns `object`.
3082 * Foo.prototype.c = 3;
3083 * Bar.prototype.e = 5;
3085 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
3086 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
3088 var assignIn = createAssigner(function(object, source) {
3089 copyObject(source, keysIn(source), object);
3093 * This method is like `_.assignIn` except that it accepts `customizer`
3094 * which is invoked to produce the assigned values. If `customizer` returns
3095 * `undefined`, assignment is handled by the method instead. The `customizer`
3096 * is invoked with five arguments: (objValue, srcValue, key, object, source).
3098 * **Note:** This method mutates `object`.
3105 * @param {Object} object The destination object.
3106 * @param {...Object} sources The source objects.
3107 * @param {Function} [customizer] The function to customize assigned values.
3108 * @returns {Object} Returns `object`.
3112 * function customizer(objValue, srcValue) {
3113 * return _.isUndefined(objValue) ? srcValue : objValue;
3116 * var defaults = _.partialRight(_.assignInWith, customizer);
3118 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3119 * // => { 'a': 1, 'b': 2 }
3121 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
3122 copyObject(source, keysIn(source), object, customizer);
3126 * Creates an object that inherits from the `prototype` object. If a
3127 * `properties` object is given, its own enumerable string keyed properties
3128 * are assigned to the created object.
3134 * @param {Object} prototype The object to inherit from.
3135 * @param {Object} [properties] The properties to assign to the object.
3136 * @returns {Object} Returns the new object.
3139 * function Shape() {
3144 * function Circle() {
3148 * Circle.prototype = _.create(Shape.prototype, {
3149 * 'constructor': Circle
3152 * var circle = new Circle;
3153 * circle instanceof Circle;
3156 * circle instanceof Shape;
3159 function create(prototype, properties) {
3160 var result = baseCreate(prototype);
3161 return properties ? assign(result, properties) : result;
3165 * Assigns own and inherited enumerable string keyed properties of source
3166 * objects to the destination object for all destination properties that
3167 * resolve to `undefined`. Source objects are applied from left to right.
3168 * Once a property is set, additional values of the same property are ignored.
3170 * **Note:** This method mutates `object`.
3176 * @param {Object} object The destination object.
3177 * @param {...Object} [sources] The source objects.
3178 * @returns {Object} Returns `object`.
3179 * @see _.defaultsDeep
3182 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
3183 * // => { 'user': 'barney', 'age': 36 }
3185 var defaults = rest(function(args) {
3186 args.push(undefined, assignInDefaults);
3187 return assignInWith.apply(undefined, args);
3191 * Checks if `path` is a direct property of `object`.
3197 * @param {Object} object The object to query.
3198 * @param {Array|string} path The path to check.
3199 * @returns {boolean} Returns `true` if `path` exists, else `false`.
3202 * var object = { 'a': { 'b': 2 } };
3203 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
3205 * _.has(object, 'a');
3208 * _.has(object, 'a.b');
3211 * _.has(object, ['a', 'b']);
3214 * _.has(other, 'a');
3217 function has(object, path) {
3218 return object != null && hasOwnProperty.call(object, path);
3222 * Creates an array of the own enumerable property names of `object`.
3224 * **Note:** Non-object values are coerced to objects. See the
3225 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
3232 * @param {Object} object The object to query.
3233 * @returns {Array} Returns the array of property names.
3241 * Foo.prototype.c = 3;
3244 * // => ['a', 'b'] (iteration order is not guaranteed)
3249 var keys = baseKeys;
3252 * Creates an array of the own and inherited enumerable property names of `object`.
3254 * **Note:** Non-object values are coerced to objects.
3260 * @param {Object} object The object to query.
3261 * @returns {Array} Returns the array of property names.
3269 * Foo.prototype.c = 3;
3271 * _.keysIn(new Foo);
3272 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3274 var keysIn = baseKeysIn;
3277 * Creates an object composed of the picked `object` properties.
3283 * @param {Object} object The source object.
3284 * @param {...(string|string[])} [props] The property identifiers to pick.
3285 * @returns {Object} Returns the new object.
3288 * var object = { 'a': 1, 'b': '2', 'c': 3 };
3290 * _.pick(object, ['a', 'c']);
3291 * // => { 'a': 1, 'c': 3 }
3293 var pick = rest(function(object, props) {
3294 return object == null ? {} : basePick(object, baseMap(baseFlatten(props, 1), toKey));
3298 * This method is like `_.get` except that if the resolved value is a
3299 * function it's invoked with the `this` binding of its parent object and
3300 * its result is returned.
3306 * @param {Object} object The object to query.
3307 * @param {Array|string} path The path of the property to resolve.
3308 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
3309 * @returns {*} Returns the resolved value.
3312 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3314 * _.result(object, 'a[0].b.c1');
3317 * _.result(object, 'a[0].b.c2');
3320 * _.result(object, 'a[0].b.c3', 'default');
3323 * _.result(object, 'a[0].b.c3', _.constant('default'));
3326 function result(object, path, defaultValue) {
3327 var value = object == null ? undefined : object[path];
3328 if (value === undefined) {
3329 value = defaultValue;
3331 return isFunction(value) ? value.call(object) : value;
3335 * Creates an array of the own enumerable string keyed property values of `object`.
3337 * **Note:** Non-object values are coerced to objects.
3343 * @param {Object} object The object to query.
3344 * @returns {Array} Returns the array of property values.
3352 * Foo.prototype.c = 3;
3354 * _.values(new Foo);
3355 * // => [1, 2] (iteration order is not guaranteed)
3360 function values(object) {
3361 return object ? baseValues(object, keys(object)) : [];
3364 /*------------------------------------------------------------------------*/
3367 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
3368 * their corresponding HTML entities.
3370 * **Note:** No other characters are escaped. To escape additional
3371 * characters use a third-party library like [_he_](https://mths.be/he).
3373 * Though the ">" character is escaped for symmetry, characters like
3374 * ">" and "/" don't need escaping in HTML and have no special meaning
3375 * unless they're part of a tag or unquoted attribute value. See
3376 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3377 * (under "semi-related fun fact") for more details.
3379 * Backticks are escaped because in IE < 9, they can break out of
3380 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
3381 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
3382 * [#133](https://html5sec.org/#133) of the
3383 * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
3385 * When working with HTML you should always
3386 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
3393 * @param {string} [string=''] The string to escape.
3394 * @returns {string} Returns the escaped string.
3397 * _.escape('fred, barney, & pebbles');
3398 * // => 'fred, barney, & pebbles'
3400 function escape(string) {
3401 string = toString(string);
3402 return (string && reHasUnescapedHtml.test(string))
3403 ? string.replace(reUnescapedHtml, escapeHtmlChar)
3407 /*------------------------------------------------------------------------*/
3410 * This method returns the first argument given to it.
3416 * @param {*} value Any value.
3417 * @returns {*} Returns `value`.
3420 * var object = { 'user': 'fred' };
3422 * console.log(_.identity(object) === object);
3425 function identity(value) {
3430 * Creates a function that invokes `func` with the arguments of the created
3431 * function. If `func` is a property name, the created function returns the
3432 * property value for a given element. If `func` is an array or object, the
3433 * created function returns `true` for elements that contain the equivalent
3434 * source properties, otherwise it returns `false`.
3440 * @param {*} [func=_.identity] The value to convert to a callback.
3441 * @returns {Function} Returns the callback.
3445 * { 'user': 'barney', 'age': 36, 'active': true },
3446 * { 'user': 'fred', 'age': 40, 'active': false }
3449 * // The `_.matches` iteratee shorthand.
3450 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
3451 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
3453 * // The `_.matchesProperty` iteratee shorthand.
3454 * _.filter(users, _.iteratee(['user', 'fred']));
3455 * // => [{ 'user': 'fred', 'age': 40 }]
3457 * // The `_.property` iteratee shorthand.
3458 * _.map(users, _.iteratee('user'));
3459 * // => ['barney', 'fred']
3461 * // Create custom iteratee shorthands.
3462 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
3463 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
3464 * return func.test(string);
3468 * _.filter(['abc', 'def'], /ef/);
3471 var iteratee = baseIteratee;
3474 * Creates a function that performs a partial deep comparison between a given
3475 * object and `source`, returning `true` if the given object has equivalent
3476 * property values, else `false`. The created function is equivalent to
3477 * `_.isMatch` with a `source` partially applied.
3479 * **Note:** This method supports comparing the same values as `_.isEqual`.
3485 * @param {Object} source The object of property values to match.
3486 * @returns {Function} Returns the new spec function.
3490 * { 'user': 'barney', 'age': 36, 'active': true },
3491 * { 'user': 'fred', 'age': 40, 'active': false }
3494 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
3495 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
3497 function matches(source) {
3498 return baseMatches(assign({}, source));
3502 * Adds all own enumerable string keyed function properties of a source
3503 * object to the destination object. If `object` is a function, then methods
3504 * are added to its prototype as well.
3506 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3507 * avoid conflicts caused by modifying the original.
3513 * @param {Function|Object} [object=lodash] The destination object.
3514 * @param {Object} source The object of functions to add.
3515 * @param {Object} [options={}] The options object.
3516 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
3517 * @returns {Function|Object} Returns `object`.
3520 * function vowels(string) {
3521 * return _.filter(string, function(v) {
3522 * return /[aeiou]/i.test(v);
3526 * _.mixin({ 'vowels': vowels });
3530 * _('fred').vowels().value();
3533 * _.mixin({ 'vowels': vowels }, { 'chain': false });
3534 * _('fred').vowels();
3537 function mixin(object, source, options) {
3538 var props = keys(source),
3539 methodNames = baseFunctions(source, props);
3541 if (options == null &&
3542 !(isObject(source) && (methodNames.length || !props.length))) {
3546 methodNames = baseFunctions(source, keys(source));
3548 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
3549 isFunc = isFunction(object);
3551 baseEach(methodNames, function(methodName) {
3552 var func = source[methodName];
3553 object[methodName] = func;
3555 object.prototype[methodName] = function() {
3556 var chainAll = this.__chain__;
3557 if (chain || chainAll) {
3558 var result = object(this.__wrapped__),
3559 actions = result.__actions__ = copyArray(this.__actions__);
3561 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3562 result.__chain__ = chainAll;
3565 return func.apply(object, arrayPush([this.value()], arguments));
3574 * Reverts the `_` variable to its previous value and returns a reference to
3575 * the `lodash` function.
3581 * @returns {Function} Returns the `lodash` function.
3584 * var lodash = _.noConflict();
3586 function noConflict() {
3587 if (root._ === this) {
3594 * A method that returns `undefined`.
3602 * _.times(2, _.noop);
3603 * // => [undefined, undefined]
3606 // No operation performed.
3610 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
3616 * @param {string} [prefix=''] The value to prefix the ID with.
3617 * @returns {string} Returns the unique ID.
3620 * _.uniqueId('contact_');
3621 * // => 'contact_104'
3626 function uniqueId(prefix) {
3627 var id = ++idCounter;
3628 return toString(prefix) + id;
3631 /*------------------------------------------------------------------------*/
3634 * Computes the maximum value of `array`. If `array` is empty or falsey,
3635 * `undefined` is returned.
3641 * @param {Array} array The array to iterate over.
3642 * @returns {*} Returns the maximum value.
3645 * _.max([4, 2, 8, 6]);
3651 function max(array) {
3652 return (array && array.length)
3653 ? baseExtremum(array, identity, baseGt)
3658 * Computes the minimum value of `array`. If `array` is empty or falsey,
3659 * `undefined` is returned.
3665 * @param {Array} array The array to iterate over.
3666 * @returns {*} Returns the minimum value.
3669 * _.min([4, 2, 8, 6]);
3675 function min(array) {
3676 return (array && array.length)
3677 ? baseExtremum(array, identity, baseLt)
3681 /*------------------------------------------------------------------------*/
3683 // Add methods that return wrapped values in chain sequences.
3684 lodash.assignIn = assignIn;
3685 lodash.before = before;
3687 lodash.chain = chain;
3688 lodash.compact = compact;
3689 lodash.concat = concat;
3690 lodash.create = create;
3691 lodash.defaults = defaults;
3692 lodash.defer = defer;
3693 lodash.delay = delay;
3694 lodash.filter = filter;
3695 lodash.flatten = flatten;
3696 lodash.flattenDeep = flattenDeep;
3697 lodash.iteratee = iteratee;
3700 lodash.matches = matches;
3701 lodash.mixin = mixin;
3702 lodash.negate = negate;
3705 lodash.slice = slice;
3706 lodash.sortBy = sortBy;
3709 lodash.toArray = toArray;
3710 lodash.values = values;
3713 lodash.extend = assignIn;
3715 // Add methods to `lodash.prototype`.
3716 mixin(lodash, lodash);
3718 /*------------------------------------------------------------------------*/
3720 // Add methods that return unwrapped values in chain sequences.
3721 lodash.clone = clone;
3722 lodash.escape = escape;
3723 lodash.every = every;
3725 lodash.forEach = forEach;
3728 lodash.identity = identity;
3729 lodash.indexOf = indexOf;
3730 lodash.isArguments = isArguments;
3731 lodash.isArray = isArray;
3732 lodash.isBoolean = isBoolean;
3733 lodash.isDate = isDate;
3734 lodash.isEmpty = isEmpty;
3735 lodash.isEqual = isEqual;
3736 lodash.isFinite = isFinite;
3737 lodash.isFunction = isFunction;
3738 lodash.isNaN = isNaN;
3739 lodash.isNull = isNull;
3740 lodash.isNumber = isNumber;
3741 lodash.isObject = isObject;
3742 lodash.isRegExp = isRegExp;
3743 lodash.isString = isString;
3744 lodash.isUndefined = isUndefined;
3748 lodash.noConflict = noConflict;
3750 lodash.reduce = reduce;
3751 lodash.result = result;
3754 lodash.uniqueId = uniqueId;
3757 lodash.each = forEach;
3758 lodash.first = head;
3760 mixin(lodash, (function() {
3762 baseForOwn(lodash, function(func, methodName) {
3763 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3764 source[methodName] = func;
3768 }()), { 'chain': false });
3770 /*------------------------------------------------------------------------*/
3773 * The semantic version number.
3779 lodash.VERSION = VERSION;
3781 // Add `Array` methods to `lodash.prototype`.
3782 baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3783 var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3784 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3785 retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3787 lodash.prototype[methodName] = function() {
3788 var args = arguments;
3789 if (retUnwrapped && !this.__chain__) {
3790 var value = this.value();
3791 return func.apply(isArray(value) ? value : [], args);
3793 return this[chainName](function(value) {
3794 return func.apply(isArray(value) ? value : [], args);
3799 // Add chain sequence methods to the `lodash` wrapper.
3800 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3802 /*--------------------------------------------------------------------------*/
3804 // Expose Lodash on the free variable `window` or `self` when available so it's
3805 // globally accessible, even when bundled with Browserify, Webpack, etc. This
3806 // also prevents errors in cases where Lodash is loaded by a script tag in the
3807 // presence of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch
3808 // for more details. Use `_.noConflict` to remove Lodash from the global object.
3809 (freeSelf || {})._ = lodash;
3811 // Some AMD build optimizers like r.js check for condition patterns like the following:
3812 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3813 // Define as an anonymous module so, through path mapping, it can be
3814 // referenced as the "underscore" module.
3819 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
3820 else if (freeModule) {
3821 // Export for Node.js.
3822 (freeModule.exports = lodash)._ = lodash;
3823 // Export for CommonJS support.
3824 freeExports._ = lodash;
3827 // Export to the global object.