3 * lodash 4.11.2 (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.11.2';
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 detect unsigned integer values. */
51 var reIsUint = /^(?:0|[1-9]\d*)$/;
53 /** Used to map characters to HTML entities. */
63 /** Used to determine if values are of the language type `Object`. */
69 /** Detect free variable `exports`. */
70 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
74 /** Detect free variable `module`. */
75 var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
79 /** Detect the popular CommonJS extension `module.exports`. */
80 var moduleExports = (freeModule && freeModule.exports === freeExports)
84 /** Detect free variable `global` from Node.js. */
85 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
87 /** Detect free variable `self`. */
88 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
90 /** Detect free variable `window`. */
91 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
93 /** Detect `this` as the global object. */
94 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
97 * Used as a reference to the global object.
99 * The `this` value is used if it's the global object to avoid Greasemonkey's
100 * restricted `window` object, otherwise the `window` object is used.
102 var root = freeGlobal ||
103 ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
104 freeSelf || thisGlobal || Function('return this')();
106 /*--------------------------------------------------------------------------*/
109 * Creates a new array concatenating `array` with `other`.
112 * @param {Array} array The first array to concatenate.
113 * @param {Array} other The second array to concatenate.
114 * @returns {Array} Returns the new concatenated array.
116 function arrayConcat(array, other) {
117 return arrayPush(copyArray(array), values);
121 * Appends the elements of `values` to `array`.
124 * @param {Array} array The array to modify.
125 * @param {Array} values The values to append.
126 * @returns {Array} Returns `array`.
128 function arrayPush(array, values) {
129 array.push.apply(array, values);
134 * The base implementation of methods like `_.find` and `_.findKey`, without
135 * support for iteratee shorthands, which iterates over `collection` using
139 * @param {Array|Object} collection The collection to search.
140 * @param {Function} predicate The function invoked per iteration.
141 * @param {Function} eachFunc The function to iterate over `collection`.
142 * @param {boolean} [retKey] Specify returning the key of the found element
143 * instead of the element itself.
144 * @returns {*} Returns the found element or its key, else `undefined`.
146 function baseFind(collection, predicate, eachFunc, retKey) {
148 eachFunc(collection, function(value, key, collection) {
149 if (predicate(value, key, collection)) {
150 result = retKey ? key : value;
158 * The base implementation of `_.reduce` and `_.reduceRight`, without support
159 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
162 * @param {Array|Object} collection The collection to iterate over.
163 * @param {Function} iteratee The function invoked per iteration.
164 * @param {*} accumulator The initial value.
165 * @param {boolean} initAccum Specify using the first or last element of
166 * `collection` as the initial value.
167 * @param {Function} eachFunc The function to iterate over `collection`.
168 * @returns {*} Returns the accumulated value.
170 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
171 eachFunc(collection, function(value, index, collection) {
172 accumulator = initAccum
173 ? (initAccum = false, value)
174 : iteratee(accumulator, value, index, collection);
180 * The base implementation of `_.times` without support for iteratee shorthands
181 * or max array length checks.
184 * @param {number} n The number of times to invoke `iteratee`.
185 * @param {Function} iteratee The function invoked per iteration.
186 * @returns {Array} Returns the array of results.
188 function baseTimes(n, iteratee) {
192 while (++index < n) {
193 result[index] = iteratee(index);
199 * The base implementation of `_.values` and `_.valuesIn` which creates an
200 * array of `object` property values corresponding to the property names
204 * @param {Object} object The object to query.
205 * @param {Array} props The property names to get values for.
206 * @returns {Object} Returns the array of property values.
208 function baseValues(object, props) {
209 return baseMap(props, function(key) {
215 * Checks if `value` is a global object.
218 * @param {*} value The value to check.
219 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
221 function checkGlobal(value) {
222 return (value && value.Object === Object) ? value : null;
226 * Used by `_.escape` to convert characters to HTML entities.
229 * @param {string} chr The matched character to escape.
230 * @returns {string} Returns the escaped character.
232 function escapeHtmlChar(chr) {
233 return htmlEscapes[chr];
237 * Checks if `value` is a host object in IE < 9.
240 * @param {*} value The value to check.
241 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
243 function isHostObject(value) {
244 // Many host objects are `Object` objects that can coerce to strings
245 // despite having improperly defined `toString` methods.
247 if (value != null && typeof value.toString != 'function') {
249 result = !!(value + '');
256 * Converts `iterator` to an array.
259 * @param {Object} iterator The iterator to convert.
260 * @returns {Array} Returns the converted array.
262 function iteratorToArray(iterator) {
266 while (!(data = iterator.next()).done) {
267 result.push(data.value);
272 /*--------------------------------------------------------------------------*/
274 /** Used for built-in method references. */
275 var arrayProto = Array.prototype,
276 objectProto = Object.prototype;
278 /** Used to check objects for own properties. */
279 var hasOwnProperty = objectProto.hasOwnProperty;
281 /** Used to generate unique IDs. */
285 * Used to resolve the
286 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
289 var objectToString = objectProto.toString;
291 /** Used to restore the original `_` reference in `_.noConflict`. */
292 var oldDash = root._;
294 /** Built-in value references. */
295 var Reflect = root.Reflect,
296 Symbol = root.Symbol,
297 Uint8Array = root.Uint8Array,
298 enumerate = Reflect ? Reflect.enumerate : undefined,
299 objectCreate = Object.create,
300 propertyIsEnumerable = objectProto.propertyIsEnumerable;
302 /* Built-in method references for those with the same name as other `lodash` methods. */
303 var nativeIsFinite = root.isFinite,
304 nativeKeys = Object.keys,
305 nativeMax = Math.max;
307 /*------------------------------------------------------------------------*/
310 * Creates a `lodash` object which wraps `value` to enable implicit method
311 * chain sequences. Methods that operate on and return arrays, collections,
312 * and functions can be chained together. Methods that retrieve a single value
313 * or may return a primitive value will automatically end the chain sequence
314 * and return the unwrapped value. Otherwise, the value must be unwrapped
317 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
318 * enabled using `_.chain`.
320 * The execution of chained methods is lazy, that is, it's deferred until
321 * `_#value` is implicitly or explicitly called.
323 * Lazy evaluation allows several methods to support shortcut fusion.
324 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
325 * the creation of intermediate arrays and can greatly reduce the number of
326 * iteratee executions. Sections of a chain sequence qualify for shortcut
327 * fusion if the section is applied to an array of at least `200` elements
328 * and any iteratees accept only one argument. The heuristic for whether a
329 * section qualifies for shortcut fusion is subject to change.
331 * Chaining is supported in custom builds as long as the `_#value` method is
332 * directly or indirectly included in the build.
334 * In addition to lodash methods, wrappers have `Array` and `String` methods.
336 * The wrapper `Array` methods are:
337 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
339 * The wrapper `String` methods are:
340 * `replace` and `split`
342 * The wrapper methods that support shortcut fusion are:
343 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
344 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
345 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
347 * The chainable wrapper methods are:
348 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
349 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
350 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
351 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
352 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
353 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
354 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
355 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
356 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
357 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
358 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
359 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
360 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
361 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
362 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
363 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
364 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
365 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
366 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
367 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
368 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
369 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
370 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
371 * `zipObject`, `zipObjectDeep`, and `zipWith`
373 * The wrapper methods that are **not** chainable by default are:
374 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
375 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`,
376 * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`,
377 * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`,
378 * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
379 * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`,
380 * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`,
381 * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`, `isBuffer`,
382 * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
383 * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`, `isMatch`,
384 * `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
385 * `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
386 * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`,
387 * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`,
388 * `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, `min`, `minBy`, `multiply`,
389 * `noConflict`, `noop`, `now`, `nth`, `pad`, `padEnd`, `padStart`, `parseInt`,
390 * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
391 * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
392 * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
393 * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toInteger`,
394 * `toJSON`, `toLength`, `toLower`, `toNumber`, `toSafeInteger`, `toString`,
395 * `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`,
396 * `uniqueId`, `upperCase`, `upperFirst`, `value`, and `words`
401 * @param {*} value The value to wrap in a `lodash` instance.
402 * @returns {Object} Returns the new `lodash` wrapper instance.
405 * function square(n) {
409 * var wrapped = _([1, 2, 3]);
411 * // Returns an unwrapped value.
412 * wrapped.reduce(_.add);
415 * // Returns a wrapped value.
416 * var squares = wrapped.map(square);
418 * _.isArray(squares);
421 * _.isArray(squares.value());
424 function lodash(value) {
425 return value instanceof LodashWrapper
427 : new LodashWrapper(value);
431 * The base constructor for creating `lodash` wrapper objects.
434 * @param {*} value The value to wrap.
435 * @param {boolean} [chainAll] Enable explicit method chain sequences.
437 function LodashWrapper(value, chainAll) {
438 this.__wrapped__ = value;
439 this.__actions__ = [];
440 this.__chain__ = !!chainAll;
443 LodashWrapper.prototype = baseCreate(lodash.prototype);
444 LodashWrapper.prototype.constructor = LodashWrapper;
446 /*------------------------------------------------------------------------*/
449 * Used by `_.defaults` to customize its `_.assignIn` use.
452 * @param {*} objValue The destination value.
453 * @param {*} srcValue The source value.
454 * @param {string} key The key of the property to assign.
455 * @param {Object} object The parent object of `objValue`.
456 * @returns {*} Returns the value to assign.
458 function assignInDefaults(objValue, srcValue, key, object) {
459 if (objValue === undefined ||
460 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
467 * Assigns `value` to `key` of `object` if the existing value is not equivalent
468 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
469 * for equality comparisons.
472 * @param {Object} object The object to modify.
473 * @param {string} key The key of the property to assign.
474 * @param {*} value The value to assign.
476 function assignValue(object, key, value) {
477 var objValue = object[key];
478 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
479 (value === undefined && !(key in object))) {
485 * The base implementation of `_.create` without support for assigning
486 * properties to the created object.
489 * @param {Object} prototype The object to inherit from.
490 * @returns {Object} Returns the new object.
492 function baseCreate(proto) {
493 return isObject(proto) ? objectCreate(proto) : {};
497 * The base implementation of `_.delay` and `_.defer` which accepts an array
498 * of `func` arguments.
501 * @param {Function} func The function to delay.
502 * @param {number} wait The number of milliseconds to delay invocation.
503 * @param {Object} args The arguments to provide to `func`.
504 * @returns {number} Returns the timer id.
506 function baseDelay(func, wait, args) {
507 if (typeof func != 'function') {
508 throw new TypeError(FUNC_ERROR_TEXT);
510 return setTimeout(function() { func.apply(undefined, args); }, wait);
514 * The base implementation of `_.forEach` without support for iteratee shorthands.
517 * @param {Array|Object} collection The collection to iterate over.
518 * @param {Function} iteratee The function invoked per iteration.
519 * @returns {Array|Object} Returns `collection`.
521 var baseEach = createBaseEach(baseForOwn);
524 * The base implementation of `_.every` without support for iteratee shorthands.
527 * @param {Array|Object} collection The collection to iterate over.
528 * @param {Function} predicate The function invoked per iteration.
529 * @returns {boolean} Returns `true` if all elements pass the predicate check,
532 function baseEvery(collection, predicate) {
534 baseEach(collection, function(value, index, collection) {
535 result = !!predicate(value, index, collection);
542 * The base implementation of methods like `_.max` and `_.min` which accepts a
543 * `comparator` to determine the extremum value.
546 * @param {Array} array The array to iterate over.
547 * @param {Function} iteratee The iteratee invoked per iteration.
548 * @param {Function} comparator The comparator used to compare values.
549 * @returns {*} Returns the extremum value.
551 function baseExtremum(array, iteratee, comparator) {
553 length = array.length;
555 while (++index < length) {
556 var value = array[index],
557 current = iteratee(value);
559 if (current != null && (computed === undefined
560 ? (current === current && !false)
561 : comparator(current, computed)
563 var computed = current,
571 * The base implementation of `_.filter` without support for iteratee shorthands.
574 * @param {Array|Object} collection The collection to iterate over.
575 * @param {Function} predicate The function invoked per iteration.
576 * @returns {Array} Returns the new filtered array.
578 function baseFilter(collection, predicate) {
580 baseEach(collection, function(value, index, collection) {
581 if (predicate(value, index, collection)) {
589 * The base implementation of `_.flatten` with support for restricting flattening.
592 * @param {Array} array The array to flatten.
593 * @param {number} depth The maximum recursion depth.
594 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
595 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
596 * @param {Array} [result=[]] The initial result value.
597 * @returns {Array} Returns the new flattened array.
599 function baseFlatten(array, depth, predicate, isStrict, result) {
601 length = array.length;
603 predicate || (predicate = isFlattenable);
604 result || (result = []);
606 while (++index < length) {
607 var value = array[index];
608 if (depth > 0 && predicate(value)) {
610 // Recursively flatten arrays (susceptible to call stack limits).
611 baseFlatten(value, depth - 1, predicate, isStrict, result);
613 arrayPush(result, value);
615 } else if (!isStrict) {
616 result[result.length] = value;
623 * The base implementation of `baseForOwn` which iterates over `object`
624 * properties returned by `keysFunc` and invokes `iteratee` for each property.
625 * Iteratee functions may exit iteration early by explicitly returning `false`.
628 * @param {Object} object The object to iterate over.
629 * @param {Function} iteratee The function invoked per iteration.
630 * @param {Function} keysFunc The function to get the keys of `object`.
631 * @returns {Object} Returns `object`.
633 var baseFor = createBaseFor();
636 * The base implementation of `_.forOwn` without support for iteratee shorthands.
639 * @param {Object} object The object to iterate over.
640 * @param {Function} iteratee The function invoked per iteration.
641 * @returns {Object} Returns `object`.
643 function baseForOwn(object, iteratee) {
644 return object && baseFor(object, iteratee, keys);
648 * The base implementation of `_.functions` which creates an array of
649 * `object` function property names filtered from `props`.
652 * @param {Object} object The object to inspect.
653 * @param {Array} props The property names to filter.
654 * @returns {Array} Returns the new array of filtered property names.
656 function baseFunctions(object, props) {
657 return baseFilter(props, function(key) {
658 return isFunction(object[key]);
663 * The base implementation of `_.gt` which doesn't coerce arguments to numbers.
666 * @param {*} value The value to compare.
667 * @param {*} other The other value to compare.
668 * @returns {boolean} Returns `true` if `value` is greater than `other`,
671 function baseGt(value, other) {
672 return value > other;
676 * The base implementation of `_.isEqual` which supports partial comparisons
677 * and tracks traversed objects.
680 * @param {*} value The value to compare.
681 * @param {*} other The other value to compare.
682 * @param {Function} [customizer] The function to customize comparisons.
683 * @param {boolean} [bitmask] The bitmask of comparison flags.
684 * The bitmask may be composed of the following flags:
685 * 1 - Unordered comparison
686 * 2 - Partial comparison
687 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
688 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
690 function baseIsEqual(value, other, customizer, bitmask, stack) {
691 if (value === other) {
694 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
695 return value !== value && other !== other;
697 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
701 * A specialized version of `baseIsEqual` for arrays and objects which performs
702 * deep comparisons and tracks traversed objects enabling objects with circular
703 * references to be compared.
706 * @param {Object} object The object to compare.
707 * @param {Object} other The other object to compare.
708 * @param {Function} equalFunc The function to determine equivalents of values.
709 * @param {Function} [customizer] The function to customize comparisons.
710 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
712 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
713 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
715 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
716 var objIsArr = isArray(object),
717 othIsArr = isArray(other),
722 objTag = objectToString.call(object);
723 objTag = objTag == argsTag ? objectTag : objTag;
726 othTag = objectToString.call(other);
727 othTag = othTag == argsTag ? objectTag : othTag;
729 var objIsObj = objTag == objectTag && !isHostObject(object),
730 othIsObj = othTag == objectTag && !isHostObject(other),
731 isSameTag = objTag == othTag;
733 stack || (stack = []);
734 var stacked = find(stack, function(entry) {
735 return entry[0] === object;
737 if (stacked && stacked[1]) {
738 return stacked[1] == other;
740 stack.push([object, other]);
741 if (isSameTag && !objIsObj) {
742 var result = (objIsArr || isTypedArray(object))
743 ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
744 : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
748 if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
749 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
750 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
752 if (objIsWrapped || othIsWrapped) {
753 var objUnwrapped = objIsWrapped ? object.value() : object,
754 othUnwrapped = othIsWrapped ? other.value() : other;
756 var result = equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
764 var result = equalObjects(object, other, equalFunc, customizer, bitmask, stack);
770 * The base implementation of `_.iteratee`.
773 * @param {*} [value=_.identity] The value to convert to an iteratee.
774 * @returns {Function} Returns the iteratee.
776 function baseIteratee(func) {
777 if (typeof func == 'function') {
783 return (typeof func == 'object' ? baseMatches : baseProperty)(func);
787 * The base implementation of `_.keys` which doesn't skip the constructor
788 * property of prototypes or treat sparse arrays as dense.
791 * @param {Object} object The object to query.
792 * @returns {Array} Returns the array of property names.
794 function baseKeys(object) {
795 return nativeKeys(Object(object));
799 * The base implementation of `_.keysIn` which doesn't skip the constructor
800 * property of prototypes or treat sparse arrays as dense.
803 * @param {Object} object The object to query.
804 * @returns {Array} Returns the array of property names.
806 function baseKeysIn(object) {
807 object = object == null ? object : Object(object);
810 for (var key in object) {
816 // Fallback for IE < 9 with es6-shim.
817 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
818 baseKeysIn = function(object) {
819 return iteratorToArray(enumerate(object));
824 * The base implementation of `_.lt` which doesn't coerce arguments to numbers.
827 * @param {*} value The value to compare.
828 * @param {*} other The other value to compare.
829 * @returns {boolean} Returns `true` if `value` is less than `other`,
832 function baseLt(value, other) {
833 return value < other;
837 * The base implementation of `_.map` without support for iteratee shorthands.
840 * @param {Array|Object} collection The collection to iterate over.
841 * @param {Function} iteratee The function invoked per iteration.
842 * @returns {Array} Returns the new mapped array.
844 function baseMap(collection, iteratee) {
846 result = isArrayLike(collection) ? Array(collection.length) : [];
848 baseEach(collection, function(value, key, collection) {
849 result[++index] = iteratee(value, key, collection);
855 * The base implementation of `_.matches` which doesn't clone `source`.
858 * @param {Object} source The object of property values to match.
859 * @returns {Function} Returns the new function.
861 function baseMatches(source) {
862 var props = keys(source);
863 return function(object) {
864 var length = props.length;
865 if (object == null) {
868 object = Object(object);
870 var key = props[length];
871 if (!(key in object &&
872 baseIsEqual(source[key], object[key], undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG)
882 * The base implementation of `_.pick` without support for individual
883 * property identifiers.
886 * @param {Object} object The source object.
887 * @param {string[]} props The property identifiers to pick.
888 * @returns {Object} Returns the new object.
890 function basePick(object, props) {
891 object = Object(object);
892 return reduce(props, function(result, key) {
894 result[key] = object[key];
901 * The base implementation of `_.property` without support for deep paths.
904 * @param {string} key The key of the property to get.
905 * @returns {Function} Returns the new function.
907 function baseProperty(key) {
908 return function(object) {
909 return object == null ? undefined : object[key];
914 * The base implementation of `_.slice` without an iteratee call guard.
917 * @param {Array} array The array to slice.
918 * @param {number} [start=0] The start position.
919 * @param {number} [end=array.length] The end position.
920 * @returns {Array} Returns the slice of `array`.
922 function baseSlice(array, start, end) {
924 length = array.length;
927 start = -start > length ? 0 : (length + start);
929 end = end > length ? length : end;
933 length = start > end ? 0 : ((end - start) >>> 0);
936 var result = Array(length);
937 while (++index < length) {
938 result[index] = array[index + start];
944 * Copies the values of `source` to `array`.
947 * @param {Array} source The array to copy values from.
948 * @param {Array} [array=[]] The array to copy values to.
949 * @returns {Array} Returns `array`.
951 function copyArray(source) {
952 return baseSlice(source, 0, source.length);
956 * The base implementation of `_.some` without support for iteratee shorthands.
959 * @param {Array|Object} collection The collection to iterate over.
960 * @param {Function} predicate The function invoked per iteration.
961 * @returns {boolean} Returns `true` if any element passes the predicate check,
964 function baseSome(collection, predicate) {
967 baseEach(collection, function(value, index, collection) {
968 result = predicate(value, index, collection);
975 * The base implementation of `wrapperValue` which returns the result of
976 * performing a sequence of actions on the unwrapped `value`, where each
977 * successive action is supplied the return value of the previous.
980 * @param {*} value The unwrapped value.
981 * @param {Array} actions Actions to perform to resolve the unwrapped value.
982 * @returns {*} Returns the resolved value.
984 function baseWrapperValue(value, actions) {
986 return reduce(actions, function(result, action) {
987 return action.func.apply(action.thisArg, arrayPush([result], action.args));
992 * Compares values to sort them in ascending order.
995 * @param {*} value The value to compare.
996 * @param {*} other The other value to compare.
997 * @returns {number} Returns the sort order indicator for `value`.
999 function compareAscending(value, other) {
1000 if (value !== other) {
1001 var valIsDefined = value !== undefined,
1002 valIsNull = value === null,
1003 valIsReflexive = value === value,
1004 valIsSymbol = false;
1006 var othIsDefined = other !== undefined,
1007 othIsNull = other === null,
1008 othIsReflexive = other === other,
1009 othIsSymbol = false;
1011 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
1012 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
1013 (valIsNull && othIsDefined && othIsReflexive) ||
1014 (!valIsDefined && othIsReflexive) ||
1018 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
1019 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
1020 (othIsNull && valIsDefined && valIsReflexive) ||
1021 (!othIsDefined && valIsReflexive) ||
1030 * Copies properties of `source` to `object`.
1033 * @param {Object} source The object to copy properties from.
1034 * @param {Array} props The property identifiers to copy.
1035 * @param {Object} [object={}] The object to copy properties to.
1036 * @param {Function} [customizer] The function to customize copied values.
1037 * @returns {Object} Returns `object`.
1039 function copyObject(source, props, object, customizer) {
1040 object || (object = {});
1043 length = props.length;
1045 while (++index < length) {
1046 var key = props[index];
1048 var newValue = customizer
1049 ? customizer(object[key], source[key], key, object, source)
1052 assignValue(object, key, newValue);
1058 * Creates a function like `_.assign`.
1061 * @param {Function} assigner The function to assign values.
1062 * @returns {Function} Returns the new assigner function.
1064 function createAssigner(assigner) {
1065 return rest(function(object, sources) {
1067 length = sources.length,
1068 customizer = length > 1 ? sources[length - 1] : undefined;
1070 customizer = typeof customizer == 'function'
1071 ? (length--, customizer)
1074 object = Object(object);
1075 while (++index < length) {
1076 var source = sources[index];
1078 assigner(object, source, index, customizer);
1086 * Creates a `baseEach` or `baseEachRight` function.
1089 * @param {Function} eachFunc The function to iterate over a collection.
1090 * @param {boolean} [fromRight] Specify iterating from right to left.
1091 * @returns {Function} Returns the new base function.
1093 function createBaseEach(eachFunc, fromRight) {
1094 return function(collection, iteratee) {
1095 if (collection == null) {
1098 if (!isArrayLike(collection)) {
1099 return eachFunc(collection, iteratee);
1101 var length = collection.length,
1102 index = fromRight ? length : -1,
1103 iterable = Object(collection);
1105 while ((fromRight ? index-- : ++index < length)) {
1106 if (iteratee(iterable[index], index, iterable) === false) {
1115 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
1118 * @param {boolean} [fromRight] Specify iterating from right to left.
1119 * @returns {Function} Returns the new base function.
1121 function createBaseFor(fromRight) {
1122 return function(object, iteratee, keysFunc) {
1124 iterable = Object(object),
1125 props = keysFunc(object),
1126 length = props.length;
1129 var key = props[fromRight ? length : ++index];
1130 if (iteratee(iterable[key], key, iterable) === false) {
1139 * Creates a function that produces an instance of `Ctor` regardless of
1140 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
1143 * @param {Function} Ctor The constructor to wrap.
1144 * @returns {Function} Returns the new wrapped function.
1146 function createCtorWrapper(Ctor) {
1148 // Use a `switch` statement to work with class constructors. See
1149 // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1150 // for more details.
1151 var args = arguments;
1152 var thisBinding = baseCreate(Ctor.prototype),
1153 result = Ctor.apply(thisBinding, args);
1155 // Mimic the constructor's `return` behavior.
1156 // See https://es5.github.io/#x13.2.2 for more details.
1157 return isObject(result) ? result : thisBinding;
1162 * Creates a function that wraps `func` to invoke it with the `this` binding
1163 * of `thisArg` and `partials` prepended to the arguments it receives.
1166 * @param {Function} func The function to wrap.
1167 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
1169 * @param {*} thisArg The `this` binding of `func`.
1170 * @param {Array} partials The arguments to prepend to those provided to
1172 * @returns {Function} Returns the new wrapped function.
1174 function createPartialWrapper(func, bitmask, thisArg, partials) {
1175 if (typeof func != 'function') {
1176 throw new TypeError(FUNC_ERROR_TEXT);
1178 var isBind = bitmask & BIND_FLAG,
1179 Ctor = createCtorWrapper(func);
1181 function wrapper() {
1183 argsLength = arguments.length,
1185 leftLength = partials.length,
1186 args = Array(leftLength + argsLength),
1187 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
1189 while (++leftIndex < leftLength) {
1190 args[leftIndex] = partials[leftIndex];
1192 while (argsLength--) {
1193 args[leftIndex++] = arguments[++argsIndex];
1195 return fn.apply(isBind ? thisArg : this, args);
1201 * A specialized version of `baseIsEqualDeep` for arrays with support for
1202 * partial deep comparisons.
1205 * @param {Array} array The array to compare.
1206 * @param {Array} other The other array to compare.
1207 * @param {Function} equalFunc The function to determine equivalents of values.
1208 * @param {Function} customizer The function to customize comparisons.
1209 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
1211 * @param {Object} stack Tracks traversed `array` and `other` objects.
1212 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1214 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
1216 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1217 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
1218 arrLength = array.length,
1219 othLength = other.length;
1221 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1226 // Ignore non-index properties.
1227 while (++index < arrLength) {
1228 var arrValue = array[index],
1229 othValue = other[index];
1232 if (compared !== undefined) {
1239 // Recursively compare arrays (susceptible to call stack limits).
1241 if (!baseSome(other, function(othValue) {
1242 return arrValue === othValue ||
1243 equalFunc(arrValue, othValue, customizer, bitmask, stack);
1249 arrValue === othValue ||
1250 equalFunc(arrValue, othValue, customizer, bitmask, stack)
1260 * A specialized version of `baseIsEqualDeep` for comparing objects of
1261 * the same `toStringTag`.
1263 * **Note:** This function only supports comparing values with tags of
1264 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1267 * @param {Object} object The object to compare.
1268 * @param {Object} other The other object to compare.
1269 * @param {string} tag The `toStringTag` of the objects to compare.
1270 * @param {Function} equalFunc The function to determine equivalents of values.
1271 * @param {Function} customizer The function to customize comparisons.
1272 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
1274 * @param {Object} stack Tracks traversed `object` and `other` objects.
1275 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1277 function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
1282 // Coerce dates and booleans to numbers, dates to milliseconds and
1283 // booleans to `1` or `0` treating invalid dates coerced to `NaN` as
1285 return +object == +other;
1288 return object.name == other.name && object.message == other.message;
1291 // Treat `NaN` vs. `NaN` as equal.
1292 return (object != +object) ? other != +other : object == +other;
1296 // Coerce regexes to strings and treat strings, primitives and objects,
1297 // as equal. See http://www.ecma-international.org/ecma-262/6.0/#sec-regexp.prototype.tostring
1298 // for more details.
1299 return object == (other + '');
1306 * A specialized version of `baseIsEqualDeep` for objects with support for
1307 * partial deep comparisons.
1310 * @param {Object} object The object to compare.
1311 * @param {Object} other The other object to compare.
1312 * @param {Function} equalFunc The function to determine equivalents of values.
1313 * @param {Function} customizer The function to customize comparisons.
1314 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
1316 * @param {Object} stack Tracks traversed `object` and `other` objects.
1317 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1319 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
1320 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1321 objProps = keys(object),
1322 objLength = objProps.length,
1323 othProps = keys(other),
1324 othLength = othProps.length;
1326 if (objLength != othLength && !isPartial) {
1329 var index = objLength;
1331 var key = objProps[index];
1332 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1338 var skipCtor = isPartial;
1339 while (++index < objLength) {
1340 key = objProps[index];
1341 var objValue = object[key],
1342 othValue = other[key];
1345 // Recursively compare objects (susceptible to call stack limits).
1346 if (!(compared === undefined
1347 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
1353 skipCtor || (skipCtor = key == 'constructor');
1355 if (result && !skipCtor) {
1356 var objCtor = object.constructor,
1357 othCtor = other.constructor;
1359 // Non `Object` object instances with different constructors are not equal.
1360 if (objCtor != othCtor &&
1361 ('constructor' in object && 'constructor' in other) &&
1362 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1363 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1371 * Gets the "length" property value of `object`.
1373 * **Note:** This function is used to avoid a
1374 * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
1375 * Safari on at least iOS 8.1-8.3 ARM64.
1378 * @param {Object} object The object to query.
1379 * @returns {*} Returns the "length" value.
1381 var getLength = baseProperty('length');
1384 * Creates an array of index keys for `object` values of arrays,
1385 * `arguments` objects, and strings, otherwise `null` is returned.
1388 * @param {Object} object The object to query.
1389 * @returns {Array|null} Returns index keys, else `null`.
1391 function indexKeys(object) {
1392 var length = object ? object.length : undefined;
1393 if (isLength(length) &&
1394 (isArray(object) || isString(object) || isArguments(object))) {
1395 return baseTimes(length, String);
1401 * Checks if `value` is a flattenable `arguments` object or array.
1404 * @param {*} value The value to check.
1405 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
1407 function isFlattenable(value) {
1408 return isArrayLikeObject(value) && (isArray(value) || isArguments(value));
1412 * Checks if `value` is a valid array-like index.
1415 * @param {*} value The value to check.
1416 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1417 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1419 function isIndex(value, length) {
1420 length = length == null ? MAX_SAFE_INTEGER : length;
1422 (typeof value == 'number' || reIsUint.test(value)) &&
1423 (value > -1 && value % 1 == 0 && value < length);
1427 * Checks if `value` is likely a prototype object.
1430 * @param {*} value The value to check.
1431 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1433 function isPrototype(value) {
1434 var Ctor = value && value.constructor,
1435 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1437 return value === proto;
1441 * Converts `value` to a string key if it's not a string or symbol.
1444 * @param {*} value The value to inspect.
1445 * @returns {string|symbol} Returns the key.
1449 /*------------------------------------------------------------------------*/
1452 * Creates an array with all falsey values removed. The values `false`, `null`,
1453 * `0`, `""`, `undefined`, and `NaN` are falsey.
1459 * @param {Array} array The array to compact.
1460 * @returns {Array} Returns the new array of filtered values.
1463 * _.compact([0, 1, false, 2, '', 3]);
1466 function compact(array) {
1467 return baseFilter(array, Boolean);
1471 * Creates a new array concatenating `array` with any additional arrays
1478 * @param {Array} array The array to concatenate.
1479 * @param {...*} [values] The values to concatenate.
1480 * @returns {Array} Returns the new concatenated array.
1484 * var other = _.concat(array, 2, [3], [[4]]);
1486 * console.log(other);
1487 * // => [1, 2, 3, [4]]
1489 * console.log(array);
1493 var length = arguments.length,
1494 array = castArray(arguments[0]);
1497 return length ? copyArray(array) : [];
1499 var args = Array(length - 1);
1501 args[length - 1] = arguments[length];
1503 return arrayConcat(array, baseFlatten(args, 1));
1507 * Flattens `array` a single level deep.
1513 * @param {Array} array The array to flatten.
1514 * @returns {Array} Returns the new flattened array.
1517 * _.flatten([1, [2, [3, [4]], 5]]);
1518 * // => [1, 2, [3, [4]], 5]
1520 function flatten(array) {
1521 var length = array ? array.length : 0;
1522 return length ? baseFlatten(array, 1) : [];
1526 * Recursively flattens `array`.
1532 * @param {Array} array The array to flatten.
1533 * @returns {Array} Returns the new flattened array.
1536 * _.flattenDeep([1, [2, [3, [4]], 5]]);
1537 * // => [1, 2, 3, 4, 5]
1539 function flattenDeep(array) {
1540 var length = array ? array.length : 0;
1541 return length ? baseFlatten(array, INFINITY) : [];
1545 * Gets the first element of `array`.
1552 * @param {Array} array The array to query.
1553 * @returns {*} Returns the first element of `array`.
1556 * _.head([1, 2, 3]);
1562 function head(array) {
1563 return (array && array.length) ? array[0] : undefined;
1567 * Gets the index at which the first occurrence of `value` is found in `array`
1568 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
1569 * for equality comparisons. If `fromIndex` is negative, it's used as the
1570 * offset from the end of `array`.
1576 * @param {Array} array The array to search.
1577 * @param {*} value The value to search for.
1578 * @param {number} [fromIndex=0] The index to search from.
1579 * @returns {number} Returns the index of the matched value, else `-1`.
1582 * _.indexOf([1, 2, 1, 2], 2);
1585 * // Search from the `fromIndex`.
1586 * _.indexOf([1, 2, 1, 2], 2, 2);
1589 function indexOf(array, value, fromIndex) {
1590 var length = array ? array.length : 0;
1591 if (typeof fromIndex == 'number') {
1592 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1596 var index = (fromIndex || 0) - 1,
1597 isReflexive = value === value;
1599 while (++index < length) {
1600 var other = array[index];
1601 if ((isReflexive ? other === value : other !== other)) {
1609 * Gets the last element of `array`.
1615 * @param {Array} array The array to query.
1616 * @returns {*} Returns the last element of `array`.
1619 * _.last([1, 2, 3]);
1622 function last(array) {
1623 var length = array ? array.length : 0;
1624 return length ? array[length - 1] : undefined;
1628 * Creates a slice of `array` from `start` up to, but not including, `end`.
1630 * **Note:** This method is used instead of
1631 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
1638 * @param {Array} array The array to slice.
1639 * @param {number} [start=0] The start position.
1640 * @param {number} [end=array.length] The end position.
1641 * @returns {Array} Returns the slice of `array`.
1643 function slice(array, start, end) {
1644 var length = array ? array.length : 0;
1645 start = start == null ? 0 : +start;
1646 end = end === undefined ? length : +end;
1647 return length ? baseSlice(array, start, end) : [];
1650 /*------------------------------------------------------------------------*/
1653 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
1654 * chain sequences enabled. The result of such sequences must be unwrapped
1661 * @param {*} value The value to wrap.
1662 * @returns {Object} Returns the new `lodash` wrapper instance.
1666 * { 'user': 'barney', 'age': 36 },
1667 * { 'user': 'fred', 'age': 40 },
1668 * { 'user': 'pebbles', 'age': 1 }
1674 * .map(function(o) {
1675 * return o.user + ' is ' + o.age;
1679 * // => 'pebbles is 1'
1681 function chain(value) {
1682 var result = lodash(value);
1683 result.__chain__ = true;
1688 * This method invokes `interceptor` and returns `value`. The interceptor
1689 * is invoked with one argument; (value). The purpose of this method is to
1690 * "tap into" a method chain sequence in order to modify intermediate results.
1696 * @param {*} value The value to provide to `interceptor`.
1697 * @param {Function} interceptor The function to invoke.
1698 * @returns {*} Returns `value`.
1702 * .tap(function(array) {
1703 * // Mutate input array.
1710 function tap(value, interceptor) {
1716 * This method is like `_.tap` except that it returns the result of `interceptor`.
1717 * The purpose of this method is to "pass thru" values replacing intermediate
1718 * results in a method chain sequence.
1724 * @param {*} value The value to provide to `interceptor`.
1725 * @param {Function} interceptor The function to invoke.
1726 * @returns {*} Returns the result of `interceptor`.
1732 * .thru(function(value) {
1738 function thru(value, interceptor) {
1739 return interceptor(value);
1743 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
1749 * @returns {Object} Returns the new `lodash` wrapper instance.
1753 * { 'user': 'barney', 'age': 36 },
1754 * { 'user': 'fred', 'age': 40 }
1757 * // A sequence without explicit chaining.
1759 * // => { 'user': 'barney', 'age': 36 }
1761 * // A sequence with explicit chaining.
1767 * // => { 'user': 'barney' }
1769 function wrapperChain() {
1774 * Executes the chain sequence to resolve the unwrapped value.
1779 * @alias toJSON, valueOf
1781 * @returns {*} Returns the resolved unwrapped value.
1784 * _([1, 2, 3]).value();
1787 function wrapperValue() {
1788 return baseWrapperValue(this.__wrapped__, this.__actions__);
1791 /*------------------------------------------------------------------------*/
1794 * Checks if `predicate` returns truthy for **all** elements of `collection`.
1795 * Iteration is stopped once `predicate` returns falsey. The predicate is
1796 * invoked with three arguments: (value, index|key, collection).
1801 * @category Collection
1802 * @param {Array|Object} collection The collection to iterate over.
1803 * @param {Array|Function|Object|string} [predicate=_.identity]
1804 * The function invoked per iteration.
1805 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
1806 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1810 * _.every([true, 1, null, 'yes'], Boolean);
1814 * { 'user': 'barney', 'age': 36, 'active': false },
1815 * { 'user': 'fred', 'age': 40, 'active': false }
1818 * // The `_.matches` iteratee shorthand.
1819 * _.every(users, { 'user': 'barney', 'active': false });
1822 * // The `_.matchesProperty` iteratee shorthand.
1823 * _.every(users, ['active', false]);
1826 * // The `_.property` iteratee shorthand.
1827 * _.every(users, 'active');
1830 function every(collection, predicate, guard) {
1831 predicate = guard ? undefined : predicate;
1832 return baseEvery(collection, baseIteratee(predicate));
1836 * Iterates over elements of `collection`, returning an array of all elements
1837 * `predicate` returns truthy for. The predicate is invoked with three
1838 * arguments: (value, index|key, collection).
1843 * @category Collection
1844 * @param {Array|Object} collection The collection to iterate over.
1845 * @param {Array|Function|Object|string} [predicate=_.identity]
1846 * The function invoked per iteration.
1847 * @returns {Array} Returns the new filtered array.
1852 * { 'user': 'barney', 'age': 36, 'active': true },
1853 * { 'user': 'fred', 'age': 40, 'active': false }
1856 * _.filter(users, function(o) { return !o.active; });
1857 * // => objects for ['fred']
1859 * // The `_.matches` iteratee shorthand.
1860 * _.filter(users, { 'age': 36, 'active': true });
1861 * // => objects for ['barney']
1863 * // The `_.matchesProperty` iteratee shorthand.
1864 * _.filter(users, ['active', false]);
1865 * // => objects for ['fred']
1867 * // The `_.property` iteratee shorthand.
1868 * _.filter(users, 'active');
1869 * // => objects for ['barney']
1871 function filter(collection, predicate) {
1872 return baseFilter(collection, baseIteratee(predicate));
1876 * Iterates over elements of `collection`, returning the first element
1877 * `predicate` returns truthy for. The predicate is invoked with three
1878 * arguments: (value, index|key, collection).
1883 * @category Collection
1884 * @param {Array|Object} collection The collection to search.
1885 * @param {Array|Function|Object|string} [predicate=_.identity]
1886 * The function invoked per iteration.
1887 * @returns {*} Returns the matched element, else `undefined`.
1891 * { 'user': 'barney', 'age': 36, 'active': true },
1892 * { 'user': 'fred', 'age': 40, 'active': false },
1893 * { 'user': 'pebbles', 'age': 1, 'active': true }
1896 * _.find(users, function(o) { return o.age < 40; });
1897 * // => object for 'barney'
1899 * // The `_.matches` iteratee shorthand.
1900 * _.find(users, { 'age': 1, 'active': true });
1901 * // => object for 'pebbles'
1903 * // The `_.matchesProperty` iteratee shorthand.
1904 * _.find(users, ['active', false]);
1905 * // => object for 'fred'
1907 * // The `_.property` iteratee shorthand.
1908 * _.find(users, 'active');
1909 * // => object for 'barney'
1911 function find(collection, predicate) {
1912 return baseFind(collection, baseIteratee(predicate), baseEach);
1916 * Iterates over elements of `collection` and invokes `iteratee` for each element.
1917 * The iteratee is invoked with three arguments: (value, index|key, collection).
1918 * Iteratee functions may exit iteration early by explicitly returning `false`.
1920 * **Note:** As with other "Collections" methods, objects with a "length"
1921 * property are iterated like arrays. To avoid this behavior use `_.forIn`
1922 * or `_.forOwn` for object iteration.
1928 * @category Collection
1929 * @param {Array|Object} collection The collection to iterate over.
1930 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1931 * @returns {Array|Object} Returns `collection`.
1932 * @see _.forEachRight
1935 * _([1, 2]).forEach(function(value) {
1936 * console.log(value);
1938 * // => Logs `1` then `2`.
1940 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
1943 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
1945 function forEach(collection, iteratee) {
1946 return baseEach(collection, baseIteratee(iteratee));
1950 * Creates an array of values by running each element in `collection` thru
1951 * `iteratee`. The iteratee is invoked with three arguments:
1952 * (value, index|key, collection).
1954 * Many lodash methods are guarded to work as iteratees for methods like
1955 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
1957 * The guarded methods are:
1958 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
1959 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
1960 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
1961 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
1966 * @category Collection
1967 * @param {Array|Object} collection The collection to iterate over.
1968 * @param {Array|Function|Object|string} [iteratee=_.identity]
1969 * The function invoked per iteration.
1970 * @returns {Array} Returns the new mapped array.
1973 * function square(n) {
1977 * _.map([4, 8], square);
1980 * _.map({ 'a': 4, 'b': 8 }, square);
1981 * // => [16, 64] (iteration order is not guaranteed)
1984 * { 'user': 'barney' },
1985 * { 'user': 'fred' }
1988 * // The `_.property` iteratee shorthand.
1989 * _.map(users, 'user');
1990 * // => ['barney', 'fred']
1992 function map(collection, iteratee) {
1993 return baseMap(collection, baseIteratee(iteratee));
1997 * Reduces `collection` to a value which is the accumulated result of running
1998 * each element in `collection` thru `iteratee`, where each successive
1999 * invocation is supplied the return value of the previous. If `accumulator`
2000 * is not given, the first element of `collection` is used as the initial
2001 * value. The iteratee is invoked with four arguments:
2002 * (accumulator, value, index|key, collection).
2004 * Many lodash methods are guarded to work as iteratees for methods like
2005 * `_.reduce`, `_.reduceRight`, and `_.transform`.
2007 * The guarded methods are:
2008 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
2014 * @category Collection
2015 * @param {Array|Object} collection The collection to iterate over.
2016 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
2017 * @param {*} [accumulator] The initial value.
2018 * @returns {*} Returns the accumulated value.
2019 * @see _.reduceRight
2022 * _.reduce([1, 2], function(sum, n) {
2027 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
2028 * (result[value] || (result[value] = [])).push(key);
2031 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
2033 function reduce(collection, iteratee, accumulator) {
2034 return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
2038 * Gets the size of `collection` by returning its length for array-like
2039 * values or the number of own enumerable string keyed properties for objects.
2044 * @category Collection
2045 * @param {Array|Object} collection The collection to inspect.
2046 * @returns {number} Returns the collection size.
2049 * _.size([1, 2, 3]);
2052 * _.size({ 'a': 1, 'b': 2 });
2055 * _.size('pebbles');
2058 function size(collection) {
2059 if (collection == null) {
2062 collection = isArrayLike(collection) ? collection : keys(collection);
2063 return collection.length;
2067 * Checks if `predicate` returns truthy for **any** element of `collection`.
2068 * Iteration is stopped once `predicate` returns truthy. The predicate is
2069 * invoked with three arguments: (value, index|key, collection).
2074 * @category Collection
2075 * @param {Array|Object} collection The collection to iterate over.
2076 * @param {Array|Function|Object|string} [predicate=_.identity]
2077 * The function invoked per iteration.
2078 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
2079 * @returns {boolean} Returns `true` if any element passes the predicate check,
2083 * _.some([null, 0, 'yes', false], Boolean);
2087 * { 'user': 'barney', 'active': true },
2088 * { 'user': 'fred', 'active': false }
2091 * // The `_.matches` iteratee shorthand.
2092 * _.some(users, { 'user': 'barney', 'active': false });
2095 * // The `_.matchesProperty` iteratee shorthand.
2096 * _.some(users, ['active', false]);
2099 * // The `_.property` iteratee shorthand.
2100 * _.some(users, 'active');
2103 function some(collection, predicate, guard) {
2104 predicate = guard ? undefined : predicate;
2105 return baseSome(collection, baseIteratee(predicate));
2109 * Creates an array of elements, sorted in ascending order by the results of
2110 * running each element in a collection thru each iteratee. This method
2111 * performs a stable sort, that is, it preserves the original sort order of
2112 * equal elements. The iteratees are invoked with one argument: (value).
2117 * @category Collection
2118 * @param {Array|Object} collection The collection to iterate over.
2119 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
2120 * [iteratees=[_.identity]] The iteratees to sort by.
2121 * @returns {Array} Returns the new sorted array.
2125 * { 'user': 'fred', 'age': 48 },
2126 * { 'user': 'barney', 'age': 36 },
2127 * { 'user': 'fred', 'age': 40 },
2128 * { 'user': 'barney', 'age': 34 }
2131 * _.sortBy(users, function(o) { return o.user; });
2132 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
2134 * _.sortBy(users, ['user', 'age']);
2135 * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
2137 * _.sortBy(users, 'user', function(o) {
2138 * return Math.floor(o.age / 10);
2140 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
2142 function sortBy(collection, iteratee) {
2144 iteratee = baseIteratee(iteratee);
2146 return baseMap(baseMap(collection, function(value, key, collection) {
2147 return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2148 }).sort(function(object, other) {
2149 return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2150 }), baseProperty('value'));
2153 /*------------------------------------------------------------------------*/
2156 * Creates a function that invokes `func`, with the `this` binding and arguments
2157 * of the created function, while it's called less than `n` times. Subsequent
2158 * calls to the created function return the result of the last `func` invocation.
2163 * @category Function
2164 * @param {number} n The number of calls at which `func` is no longer invoked.
2165 * @param {Function} func The function to restrict.
2166 * @returns {Function} Returns the new restricted function.
2169 * jQuery(element).on('click', _.before(5, addContactToList));
2170 * // => allows adding up to 4 contacts to the list
2172 function before(n, func) {
2174 if (typeof func != 'function') {
2175 throw new TypeError(FUNC_ERROR_TEXT);
2180 result = func.apply(this, arguments);
2190 * Creates a function that invokes `func` with the `this` binding of `thisArg`
2191 * and `partials` prepended to the arguments it receives.
2193 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2194 * may be used as a placeholder for partially applied arguments.
2196 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
2197 * property of bound functions.
2202 * @category Function
2203 * @param {Function} func The function to bind.
2204 * @param {*} thisArg The `this` binding of `func`.
2205 * @param {...*} [partials] The arguments to be partially applied.
2206 * @returns {Function} Returns the new bound function.
2209 * var greet = function(greeting, punctuation) {
2210 * return greeting + ' ' + this.user + punctuation;
2213 * var object = { 'user': 'fred' };
2215 * var bound = _.bind(greet, object, 'hi');
2219 * // Bound with placeholders.
2220 * var bound = _.bind(greet, object, _, '!');
2224 var bind = rest(function(func, thisArg, partials) {
2225 return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
2229 * Defers invoking the `func` until the current call stack has cleared. Any
2230 * additional arguments are provided to `func` when it's invoked.
2235 * @category Function
2236 * @param {Function} func The function to defer.
2237 * @param {...*} [args] The arguments to invoke `func` with.
2238 * @returns {number} Returns the timer id.
2241 * _.defer(function(text) {
2242 * console.log(text);
2244 * // => Logs 'deferred' after one or more milliseconds.
2246 var defer = rest(function(func, args) {
2247 return baseDelay(func, 1, args);
2251 * Invokes `func` after `wait` milliseconds. Any additional arguments are
2252 * provided to `func` when it's invoked.
2257 * @category Function
2258 * @param {Function} func The function to delay.
2259 * @param {number} wait The number of milliseconds to delay invocation.
2260 * @param {...*} [args] The arguments to invoke `func` with.
2261 * @returns {number} Returns the timer id.
2264 * _.delay(function(text) {
2265 * console.log(text);
2266 * }, 1000, 'later');
2267 * // => Logs 'later' after one second.
2269 var delay = rest(function(func, wait, args) {
2270 return baseDelay(func, toNumber(wait) || 0, args);
2274 * Creates a function that negates the result of the predicate `func`. The
2275 * `func` predicate is invoked with the `this` binding and arguments of the
2281 * @category Function
2282 * @param {Function} predicate The predicate to negate.
2283 * @returns {Function} Returns the new function.
2286 * function isEven(n) {
2287 * return n % 2 == 0;
2290 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2293 function negate(predicate) {
2294 if (typeof predicate != 'function') {
2295 throw new TypeError(FUNC_ERROR_TEXT);
2298 return !predicate.apply(this, arguments);
2303 * Creates a function that is restricted to invoking `func` once. Repeat calls
2304 * to the function return the value of the first invocation. The `func` is
2305 * invoked with the `this` binding and arguments of the created function.
2310 * @category Function
2311 * @param {Function} func The function to restrict.
2312 * @returns {Function} Returns the new restricted function.
2315 * var initialize = _.once(createApplication);
2318 * // `initialize` invokes `createApplication` once
2320 function once(func) {
2321 return before(2, func);
2325 * Creates a function that invokes `func` with the `this` binding of the
2326 * created function and arguments from `start` and beyond provided as
2329 * **Note:** This method is based on the
2330 * [rest parameter](https://mdn.io/rest_parameters).
2335 * @category Function
2336 * @param {Function} func The function to apply a rest parameter to.
2337 * @param {number} [start=func.length-1] The start position of the rest parameter.
2338 * @returns {Function} Returns the new function.
2341 * var say = _.rest(function(what, names) {
2342 * return what + ' ' + _.initial(names).join(', ') +
2343 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
2346 * say('hello', 'fred', 'barney', 'pebbles');
2347 * // => 'hello fred, barney, & pebbles'
2349 function rest(func, start) {
2350 if (typeof func != 'function') {
2351 throw new TypeError(FUNC_ERROR_TEXT);
2353 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
2355 var args = arguments,
2357 length = nativeMax(args.length - start, 0),
2358 array = Array(length);
2360 while (++index < length) {
2361 array[index] = args[start + index];
2363 var otherArgs = Array(start + 1);
2365 while (++index < start) {
2366 otherArgs[index] = args[index];
2368 otherArgs[start] = array;
2369 return func.apply(this, otherArgs);
2373 /*------------------------------------------------------------------------*/
2376 * Casts `value` as an array if it's not one.
2382 * @param {*} value The value to inspect.
2383 * @returns {Array} Returns the cast array.
2389 * _.castArray({ 'a': 1 });
2390 * // => [{ 'a': 1 }]
2392 * _.castArray('abc');
2395 * _.castArray(null);
2398 * _.castArray(undefined);
2404 * var array = [1, 2, 3];
2405 * console.log(_.castArray(array) === array);
2408 function castArray() {
2409 if (!arguments.length) {
2412 var value = arguments[0];
2413 return isArray(value) ? value : [value];
2417 * Creates a shallow clone of `value`.
2419 * **Note:** This method is loosely based on the
2420 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2421 * and supports cloning arrays, array buffers, booleans, date objects, maps,
2422 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2423 * arrays. The own enumerable properties of `arguments` objects are cloned
2424 * as plain objects. An empty object is returned for uncloneable values such
2425 * as error objects, functions, DOM nodes, and WeakMaps.
2431 * @param {*} value The value to clone.
2432 * @returns {*} Returns the cloned value.
2436 * var objects = [{ 'a': 1 }, { 'b': 2 }];
2438 * var shallow = _.clone(objects);
2439 * console.log(shallow[0] === objects[0]);
2442 function clone(value) {
2443 if (!isObject(value)) {
2446 return isArray(value) ? copyArray(value) : copyObject(value, keys(value));
2451 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2452 * comparison between two values to determine if they are equivalent.
2458 * @param {*} value The value to compare.
2459 * @param {*} other The other value to compare.
2460 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2463 * var object = { 'user': 'fred' };
2464 * var other = { 'user': 'fred' };
2466 * _.eq(object, object);
2469 * _.eq(object, other);
2475 * _.eq('a', Object('a'));
2481 function eq(value, other) {
2482 return value === other || (value !== value && other !== other);
2486 * Checks if `value` is likely an `arguments` object.
2492 * @param {*} value The value to check.
2493 * @returns {boolean} Returns `true` if `value` is correctly classified,
2497 * _.isArguments(function() { return arguments; }());
2500 * _.isArguments([1, 2, 3]);
2503 function isArguments(value) {
2504 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
2505 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
2506 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
2510 * Checks if `value` is classified as an `Array` object.
2517 * @param {*} value The value to check.
2518 * @returns {boolean} Returns `true` if `value` is correctly classified,
2522 * _.isArray([1, 2, 3]);
2525 * _.isArray(document.body.children);
2531 * _.isArray(_.noop);
2534 var isArray = Array.isArray;
2537 * Checks if `value` is array-like. A value is considered array-like if it's
2538 * not a function and has a `value.length` that's an integer greater than or
2539 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2545 * @param {*} value The value to check.
2546 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2549 * _.isArrayLike([1, 2, 3]);
2552 * _.isArrayLike(document.body.children);
2555 * _.isArrayLike('abc');
2558 * _.isArrayLike(_.noop);
2561 function isArrayLike(value) {
2562 return value != null && isLength(getLength(value)) && !isFunction(value);
2566 * This method is like `_.isArrayLike` except that it also checks if `value`
2573 * @param {*} value The value to check.
2574 * @returns {boolean} Returns `true` if `value` is an array-like object,
2578 * _.isArrayLikeObject([1, 2, 3]);
2581 * _.isArrayLikeObject(document.body.children);
2584 * _.isArrayLikeObject('abc');
2587 * _.isArrayLikeObject(_.noop);
2590 function isArrayLikeObject(value) {
2591 return isObjectLike(value) && isArrayLike(value);
2595 * Checks if `value` is classified as a boolean primitive or object.
2601 * @param {*} value The value to check.
2602 * @returns {boolean} Returns `true` if `value` is correctly classified,
2606 * _.isBoolean(false);
2609 * _.isBoolean(null);
2612 function isBoolean(value) {
2613 return value === true || value === false ||
2614 (isObjectLike(value) && objectToString.call(value) == boolTag);
2618 * Checks if `value` is classified as a `Date` object.
2624 * @param {*} value The value to check.
2625 * @returns {boolean} Returns `true` if `value` is correctly classified,
2629 * _.isDate(new Date);
2632 * _.isDate('Mon April 23 2012');
2635 function isDate(value) {
2636 return isObjectLike(value) && objectToString.call(value) == dateTag;
2640 * Checks if `value` is an empty object, collection, map, or set.
2642 * Objects are considered empty if they have no own enumerable string keyed
2645 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
2646 * jQuery-like collections are considered empty if they have a `length` of `0`.
2647 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
2653 * @param {*} value The value to check.
2654 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2666 * _.isEmpty([1, 2, 3]);
2669 * _.isEmpty({ 'a': 1 });
2672 function isEmpty(value) {
2673 if (isArrayLike(value) &&
2674 (isArray(value) || isString(value) ||
2675 isFunction(value.splice) || isArguments(value))) {
2676 return !value.length;
2678 return !keys(value).length;
2682 * Performs a deep comparison between two values to determine if they are
2685 * **Note:** This method supports comparing arrays, array buffers, booleans,
2686 * date objects, error objects, maps, numbers, `Object` objects, regexes,
2687 * sets, strings, symbols, and typed arrays. `Object` objects are compared
2688 * by their own, not inherited, enumerable properties. Functions and DOM
2689 * nodes are **not** supported.
2695 * @param {*} value The value to compare.
2696 * @param {*} other The other value to compare.
2697 * @returns {boolean} Returns `true` if the values are equivalent,
2701 * var object = { 'user': 'fred' };
2702 * var other = { 'user': 'fred' };
2704 * _.isEqual(object, other);
2710 function isEqual(value, other) {
2711 return baseIsEqual(value, other);
2715 * Checks if `value` is a finite primitive number.
2717 * **Note:** This method is based on
2718 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
2724 * @param {*} value The value to check.
2725 * @returns {boolean} Returns `true` if `value` is a finite number,
2732 * _.isFinite(Number.MAX_VALUE);
2738 * _.isFinite(Infinity);
2741 function isFinite(value) {
2742 return typeof value == 'number' && nativeIsFinite(value);
2746 * Checks if `value` is classified as a `Function` object.
2752 * @param {*} value The value to check.
2753 * @returns {boolean} Returns `true` if `value` is correctly classified,
2760 * _.isFunction(/abc/);
2763 function isFunction(value) {
2764 // The use of `Object#toString` avoids issues with the `typeof` operator
2765 // in Safari 8 which returns 'object' for typed array and weak map constructors,
2766 // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
2767 var tag = isObject(value) ? objectToString.call(value) : '';
2768 return tag == funcTag || tag == genTag;
2772 * Checks if `value` is a valid array-like length.
2774 * **Note:** This function is loosely based on
2775 * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
2781 * @param {*} value The value to check.
2782 * @returns {boolean} Returns `true` if `value` is a valid length,
2789 * _.isLength(Number.MIN_VALUE);
2792 * _.isLength(Infinity);
2798 function isLength(value) {
2799 return typeof value == 'number' &&
2800 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2804 * Checks if `value` is the
2805 * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
2806 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2812 * @param {*} value The value to check.
2813 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2819 * _.isObject([1, 2, 3]);
2822 * _.isObject(_.noop);
2828 function isObject(value) {
2829 var type = typeof value;
2830 return !!value && (type == 'object' || type == 'function');
2834 * Checks if `value` is object-like. A value is object-like if it's not `null`
2835 * and has a `typeof` result of "object".
2841 * @param {*} value The value to check.
2842 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2845 * _.isObjectLike({});
2848 * _.isObjectLike([1, 2, 3]);
2851 * _.isObjectLike(_.noop);
2854 * _.isObjectLike(null);
2857 function isObjectLike(value) {
2858 return !!value && typeof value == 'object';
2862 * Checks if `value` is `NaN`.
2864 * **Note:** This method is based on
2865 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
2866 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
2867 * `undefined` and other non-number values.
2873 * @param {*} value The value to check.
2874 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2880 * _.isNaN(new Number(NaN));
2886 * _.isNaN(undefined);
2889 function isNaN(value) {
2890 // An `NaN` primitive is the only value that is not equal to itself.
2891 // Perform the `toStringTag` check first to avoid errors with some
2892 // ActiveX objects in IE.
2893 return isNumber(value) && value != +value;
2897 * Checks if `value` is `null`.
2903 * @param {*} value The value to check.
2904 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2913 function isNull(value) {
2914 return value === null;
2918 * Checks if `value` is classified as a `Number` primitive or object.
2920 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
2921 * classified as numbers, use the `_.isFinite` method.
2927 * @param {*} value The value to check.
2928 * @returns {boolean} Returns `true` if `value` is correctly classified,
2935 * _.isNumber(Number.MIN_VALUE);
2938 * _.isNumber(Infinity);
2944 function isNumber(value) {
2945 return typeof value == 'number' ||
2946 (isObjectLike(value) && objectToString.call(value) == numberTag);
2950 * Checks if `value` is classified as a `RegExp` object.
2956 * @param {*} value The value to check.
2957 * @returns {boolean} Returns `true` if `value` is correctly classified,
2961 * _.isRegExp(/abc/);
2964 * _.isRegExp('/abc/');
2967 function isRegExp(value) {
2968 return isObject(value) && objectToString.call(value) == regexpTag;
2972 * Checks if `value` is classified as a `String` primitive or object.
2978 * @param {*} value The value to check.
2979 * @returns {boolean} Returns `true` if `value` is correctly classified,
2983 * _.isString('abc');
2989 function isString(value) {
2990 return typeof value == 'string' ||
2991 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
2995 * Checks if `value` is `undefined`.
3001 * @param {*} value The value to check.
3002 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
3005 * _.isUndefined(void 0);
3008 * _.isUndefined(null);
3011 function isUndefined(value) {
3012 return value === undefined;
3016 * Converts `value` to an array.
3022 * @param {*} value The value to convert.
3023 * @returns {Array} Returns the converted array.
3026 * _.toArray({ 'a': 1, 'b': 2 });
3030 * // => ['a', 'b', 'c']
3038 function toArray(value) {
3039 if (!isArrayLike(value)) {
3040 return values(value);
3042 return value.length ? copyArray(value) : [];
3046 * Converts `value` to an integer.
3048 * **Note:** This function is loosely based on
3049 * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
3055 * @param {*} value The value to convert.
3056 * @returns {number} Returns the converted integer.
3062 * _.toInteger(Number.MIN_VALUE);
3065 * _.toInteger(Infinity);
3066 * // => 1.7976931348623157e+308
3071 var toInteger = Number;
3074 * Converts `value` to a number.
3080 * @param {*} value The value to process.
3081 * @returns {number} Returns the number.
3087 * _.toNumber(Number.MIN_VALUE);
3090 * _.toNumber(Infinity);
3096 var toNumber = Number;
3099 * Converts `value` to a string. An empty string is returned for `null`
3100 * and `undefined` values. The sign of `-0` is preserved.
3106 * @param {*} value The value to process.
3107 * @returns {string} Returns the string.
3116 * _.toString([1, 2, 3]);
3119 function toString(value) {
3120 if (typeof value == 'string') {
3123 return value == null ? '' : (value + '');
3126 /*------------------------------------------------------------------------*/
3129 * Assigns own enumerable string keyed properties of source objects to the
3130 * destination object. Source objects are applied from left to right.
3131 * Subsequent sources overwrite property assignments of previous sources.
3133 * **Note:** This method mutates `object` and is loosely based on
3134 * [`Object.assign`](https://mdn.io/Object/assign).
3140 * @param {Object} object The destination object.
3141 * @param {...Object} [sources] The source objects.
3142 * @returns {Object} Returns `object`.
3154 * Foo.prototype.d = 4;
3155 * Bar.prototype.f = 6;
3157 * _.assign({ 'a': 1 }, new Foo, new Bar);
3158 * // => { 'a': 1, 'c': 3, 'e': 5 }
3160 var assign = createAssigner(function(object, source) {
3161 copyObject(source, keys(source), object);
3165 * This method is like `_.assign` except that it iterates over own and
3166 * inherited source properties.
3168 * **Note:** This method mutates `object`.
3175 * @param {Object} object The destination object.
3176 * @param {...Object} [sources] The source objects.
3177 * @returns {Object} Returns `object`.
3189 * Foo.prototype.c = 3;
3190 * Bar.prototype.e = 5;
3192 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
3193 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
3195 var assignIn = createAssigner(function(object, source) {
3196 copyObject(source, keysIn(source), object);
3200 * This method is like `_.assignIn` except that it accepts `customizer`
3201 * which is invoked to produce the assigned values. If `customizer` returns
3202 * `undefined`, assignment is handled by the method instead. The `customizer`
3203 * is invoked with five arguments: (objValue, srcValue, key, object, source).
3205 * **Note:** This method mutates `object`.
3212 * @param {Object} object The destination object.
3213 * @param {...Object} sources The source objects.
3214 * @param {Function} [customizer] The function to customize assigned values.
3215 * @returns {Object} Returns `object`.
3219 * function customizer(objValue, srcValue) {
3220 * return _.isUndefined(objValue) ? srcValue : objValue;
3223 * var defaults = _.partialRight(_.assignInWith, customizer);
3225 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3226 * // => { 'a': 1, 'b': 2 }
3228 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
3229 copyObject(source, keysIn(source), object, customizer);
3233 * Creates an object that inherits from the `prototype` object. If a
3234 * `properties` object is given, its own enumerable string keyed properties
3235 * are assigned to the created object.
3241 * @param {Object} prototype The object to inherit from.
3242 * @param {Object} [properties] The properties to assign to the object.
3243 * @returns {Object} Returns the new object.
3246 * function Shape() {
3251 * function Circle() {
3255 * Circle.prototype = _.create(Shape.prototype, {
3256 * 'constructor': Circle
3259 * var circle = new Circle;
3260 * circle instanceof Circle;
3263 * circle instanceof Shape;
3266 function create(prototype, properties) {
3267 var result = baseCreate(prototype);
3268 return properties ? assign(result, properties) : result;
3272 * Assigns own and inherited enumerable string keyed properties of source
3273 * objects to the destination object for all destination properties that
3274 * resolve to `undefined`. Source objects are applied from left to right.
3275 * Once a property is set, additional values of the same property are ignored.
3277 * **Note:** This method mutates `object`.
3283 * @param {Object} object The destination object.
3284 * @param {...Object} [sources] The source objects.
3285 * @returns {Object} Returns `object`.
3286 * @see _.defaultsDeep
3289 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
3290 * // => { 'user': 'barney', 'age': 36 }
3292 var defaults = rest(function(args) {
3293 args.push(undefined, assignInDefaults);
3294 return assignInWith.apply(undefined, args);
3298 * Checks if `path` is a direct property of `object`.
3304 * @param {Object} object The object to query.
3305 * @param {Array|string} path The path to check.
3306 * @returns {boolean} Returns `true` if `path` exists, else `false`.
3309 * var object = { 'a': { 'b': 2 } };
3310 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
3312 * _.has(object, 'a');
3315 * _.has(object, 'a.b');
3318 * _.has(object, ['a', 'b']);
3321 * _.has(other, 'a');
3324 function has(object, path) {
3325 return object != null && hasOwnProperty.call(object, path);
3329 * Creates an array of the own enumerable property names of `object`.
3331 * **Note:** Non-object values are coerced to objects. See the
3332 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
3339 * @param {Object} object The object to query.
3340 * @returns {Array} Returns the array of property names.
3348 * Foo.prototype.c = 3;
3351 * // => ['a', 'b'] (iteration order is not guaranteed)
3356 function keys(object) {
3357 var isProto = isPrototype(object);
3358 if (!(isProto || isArrayLike(object))) {
3359 return baseKeys(object);
3361 var indexes = indexKeys(object),
3362 skipIndexes = !!indexes,
3363 result = indexes || [],
3364 length = result.length;
3366 for (var key in object) {
3367 if (hasOwnProperty.call(object, key) &&
3368 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3369 !(isProto && key == 'constructor')) {
3377 * Creates an array of the own and inherited enumerable property names of `object`.
3379 * **Note:** Non-object values are coerced to objects.
3385 * @param {Object} object The object to query.
3386 * @returns {Array} Returns the array of property names.
3394 * Foo.prototype.c = 3;
3396 * _.keysIn(new Foo);
3397 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3399 function keysIn(object) {
3401 isProto = isPrototype(object),
3402 props = baseKeysIn(object),
3403 propsLength = props.length,
3404 indexes = indexKeys(object),
3405 skipIndexes = !!indexes,
3406 result = indexes || [],
3407 length = result.length;
3409 while (++index < propsLength) {
3410 var key = props[index];
3411 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3412 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3420 * Creates an object composed of the picked `object` properties.
3426 * @param {Object} object The source object.
3427 * @param {...(string|string[])} [props] The property identifiers to pick.
3428 * @returns {Object} Returns the new object.
3431 * var object = { 'a': 1, 'b': '2', 'c': 3 };
3433 * _.pick(object, ['a', 'c']);
3434 * // => { 'a': 1, 'c': 3 }
3436 var pick = rest(function(object, props) {
3437 return object == null ? {} : basePick(object, baseMap(baseFlatten(props, 1), toKey));
3441 * This method is like `_.get` except that if the resolved value is a
3442 * function it's invoked with the `this` binding of its parent object and
3443 * its result is returned.
3449 * @param {Object} object The object to query.
3450 * @param {Array|string} path The path of the property to resolve.
3451 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
3452 * @returns {*} Returns the resolved value.
3455 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3457 * _.result(object, 'a[0].b.c1');
3460 * _.result(object, 'a[0].b.c2');
3463 * _.result(object, 'a[0].b.c3', 'default');
3466 * _.result(object, 'a[0].b.c3', _.constant('default'));
3469 function result(object, path, defaultValue) {
3470 var value = object == null ? undefined : object[path];
3471 if (value === undefined) {
3472 value = defaultValue;
3474 return isFunction(value) ? value.call(object) : value;
3478 * Creates an array of the own enumerable string keyed property values of `object`.
3480 * **Note:** Non-object values are coerced to objects.
3486 * @param {Object} object The object to query.
3487 * @returns {Array} Returns the array of property values.
3495 * Foo.prototype.c = 3;
3497 * _.values(new Foo);
3498 * // => [1, 2] (iteration order is not guaranteed)
3503 function values(object) {
3504 return object ? baseValues(object, keys(object)) : [];
3507 /*------------------------------------------------------------------------*/
3510 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
3511 * their corresponding HTML entities.
3513 * **Note:** No other characters are escaped. To escape additional
3514 * characters use a third-party library like [_he_](https://mths.be/he).
3516 * Though the ">" character is escaped for symmetry, characters like
3517 * ">" and "/" don't need escaping in HTML and have no special meaning
3518 * unless they're part of a tag or unquoted attribute value. See
3519 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3520 * (under "semi-related fun fact") for more details.
3522 * Backticks are escaped because in IE < 9, they can break out of
3523 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
3524 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
3525 * [#133](https://html5sec.org/#133) of the
3526 * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
3528 * When working with HTML you should always
3529 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
3536 * @param {string} [string=''] The string to escape.
3537 * @returns {string} Returns the escaped string.
3540 * _.escape('fred, barney, & pebbles');
3541 * // => 'fred, barney, & pebbles'
3543 function escape(string) {
3544 string = toString(string);
3545 return (string && reHasUnescapedHtml.test(string))
3546 ? string.replace(reUnescapedHtml, escapeHtmlChar)
3550 /*------------------------------------------------------------------------*/
3553 * This method returns the first argument given to it.
3559 * @param {*} value Any value.
3560 * @returns {*} Returns `value`.
3563 * var object = { 'user': 'fred' };
3565 * _.identity(object) === object;
3568 function identity(value) {
3573 * Creates a function that invokes `func` with the arguments of the created
3574 * function. If `func` is a property name, the created function returns the
3575 * property value for a given element. If `func` is an array or object, the
3576 * created function returns `true` for elements that contain the equivalent
3577 * source properties, otherwise it returns `false`.
3583 * @param {*} [func=_.identity] The value to convert to a callback.
3584 * @returns {Function} Returns the callback.
3588 * { 'user': 'barney', 'age': 36, 'active': true },
3589 * { 'user': 'fred', 'age': 40, 'active': false }
3592 * // The `_.matches` iteratee shorthand.
3593 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
3594 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
3596 * // The `_.matchesProperty` iteratee shorthand.
3597 * _.filter(users, _.iteratee(['user', 'fred']));
3598 * // => [{ 'user': 'fred', 'age': 40 }]
3600 * // The `_.property` iteratee shorthand.
3601 * _.map(users, _.iteratee('user'));
3602 * // => ['barney', 'fred']
3604 * // Create custom iteratee shorthands.
3605 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
3606 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
3607 * return func.test(string);
3611 * _.filter(['abc', 'def'], /ef/);
3614 var iteratee = baseIteratee;
3617 * Creates a function that performs a partial deep comparison between a given
3618 * object and `source`, returning `true` if the given object has equivalent
3619 * property values, else `false`. The created function is equivalent to
3620 * `_.isMatch` with a `source` partially applied.
3622 * **Note:** This method supports comparing the same values as `_.isEqual`.
3628 * @param {Object} source The object of property values to match.
3629 * @returns {Function} Returns the new function.
3633 * { 'user': 'barney', 'age': 36, 'active': true },
3634 * { 'user': 'fred', 'age': 40, 'active': false }
3637 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
3638 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
3640 function matches(source) {
3641 return baseMatches(assign({}, source));
3645 * Adds all own enumerable string keyed function properties of a source
3646 * object to the destination object. If `object` is a function, then methods
3647 * are added to its prototype as well.
3649 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3650 * avoid conflicts caused by modifying the original.
3656 * @param {Function|Object} [object=lodash] The destination object.
3657 * @param {Object} source The object of functions to add.
3658 * @param {Object} [options={}] The options object.
3659 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
3660 * @returns {Function|Object} Returns `object`.
3663 * function vowels(string) {
3664 * return _.filter(string, function(v) {
3665 * return /[aeiou]/i.test(v);
3669 * _.mixin({ 'vowels': vowels });
3673 * _('fred').vowels().value();
3676 * _.mixin({ 'vowels': vowels }, { 'chain': false });
3677 * _('fred').vowels();
3680 function mixin(object, source, options) {
3681 var props = keys(source),
3682 methodNames = baseFunctions(source, props);
3684 if (options == null &&
3685 !(isObject(source) && (methodNames.length || !props.length))) {
3689 methodNames = baseFunctions(source, keys(source));
3691 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
3692 isFunc = isFunction(object);
3694 baseEach(methodNames, function(methodName) {
3695 var func = source[methodName];
3696 object[methodName] = func;
3698 object.prototype[methodName] = function() {
3699 var chainAll = this.__chain__;
3700 if (chain || chainAll) {
3701 var result = object(this.__wrapped__),
3702 actions = result.__actions__ = copyArray(this.__actions__);
3704 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3705 result.__chain__ = chainAll;
3708 return func.apply(object, arrayPush([this.value()], arguments));
3717 * Reverts the `_` variable to its previous value and returns a reference to
3718 * the `lodash` function.
3724 * @returns {Function} Returns the `lodash` function.
3727 * var lodash = _.noConflict();
3729 function noConflict() {
3730 if (root._ === this) {
3737 * A no-operation function that returns `undefined` regardless of the
3738 * arguments it receives.
3746 * var object = { 'user': 'fred' };
3748 * _.noop(object) === undefined;
3752 // No operation performed.
3756 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
3762 * @param {string} [prefix=''] The value to prefix the ID with.
3763 * @returns {string} Returns the unique ID.
3766 * _.uniqueId('contact_');
3767 * // => 'contact_104'
3772 function uniqueId(prefix) {
3773 var id = ++idCounter;
3774 return toString(prefix) + id;
3777 /*------------------------------------------------------------------------*/
3780 * Computes the maximum value of `array`. If `array` is empty or falsey,
3781 * `undefined` is returned.
3787 * @param {Array} array The array to iterate over.
3788 * @returns {*} Returns the maximum value.
3791 * _.max([4, 2, 8, 6]);
3797 function max(array) {
3798 return (array && array.length)
3799 ? baseExtremum(array, identity, baseGt)
3804 * Computes the minimum value of `array`. If `array` is empty or falsey,
3805 * `undefined` is returned.
3811 * @param {Array} array The array to iterate over.
3812 * @returns {*} Returns the minimum value.
3815 * _.min([4, 2, 8, 6]);
3821 function min(array) {
3822 return (array && array.length)
3823 ? baseExtremum(array, identity, baseLt)
3827 /*------------------------------------------------------------------------*/
3829 // Add methods that return wrapped values in chain sequences.
3830 lodash.assignIn = assignIn;
3831 lodash.before = before;
3833 lodash.chain = chain;
3834 lodash.compact = compact;
3835 lodash.concat = concat;
3836 lodash.create = create;
3837 lodash.defaults = defaults;
3838 lodash.defer = defer;
3839 lodash.delay = delay;
3840 lodash.filter = filter;
3841 lodash.flatten = flatten;
3842 lodash.flattenDeep = flattenDeep;
3843 lodash.iteratee = iteratee;
3846 lodash.matches = matches;
3847 lodash.mixin = mixin;
3848 lodash.negate = negate;
3851 lodash.slice = slice;
3852 lodash.sortBy = sortBy;
3855 lodash.toArray = toArray;
3856 lodash.values = values;
3859 lodash.extend = assignIn;
3861 // Add methods to `lodash.prototype`.
3862 mixin(lodash, lodash);
3864 /*------------------------------------------------------------------------*/
3866 // Add methods that return unwrapped values in chain sequences.
3867 lodash.clone = clone;
3868 lodash.escape = escape;
3869 lodash.every = every;
3871 lodash.forEach = forEach;
3874 lodash.identity = identity;
3875 lodash.indexOf = indexOf;
3876 lodash.isArguments = isArguments;
3877 lodash.isArray = isArray;
3878 lodash.isBoolean = isBoolean;
3879 lodash.isDate = isDate;
3880 lodash.isEmpty = isEmpty;
3881 lodash.isEqual = isEqual;
3882 lodash.isFinite = isFinite;
3883 lodash.isFunction = isFunction;
3884 lodash.isNaN = isNaN;
3885 lodash.isNull = isNull;
3886 lodash.isNumber = isNumber;
3887 lodash.isObject = isObject;
3888 lodash.isRegExp = isRegExp;
3889 lodash.isString = isString;
3890 lodash.isUndefined = isUndefined;
3894 lodash.noConflict = noConflict;
3896 lodash.reduce = reduce;
3897 lodash.result = result;
3900 lodash.uniqueId = uniqueId;
3903 lodash.each = forEach;
3904 lodash.first = head;
3906 mixin(lodash, (function() {
3908 baseForOwn(lodash, function(func, methodName) {
3909 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3910 source[methodName] = func;
3914 }()), { 'chain': false });
3916 /*------------------------------------------------------------------------*/
3919 * The semantic version number.
3925 lodash.VERSION = VERSION;
3927 // Add `Array` methods to `lodash.prototype`.
3928 baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3929 var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3930 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3931 retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3933 lodash.prototype[methodName] = function() {
3934 var args = arguments;
3935 if (retUnwrapped && !this.__chain__) {
3936 var value = this.value();
3937 return func.apply(isArray(value) ? value : [], args);
3939 return this[chainName](function(value) {
3940 return func.apply(isArray(value) ? value : [], args);
3945 // Add chain sequence methods to the `lodash` wrapper.
3946 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3948 /*--------------------------------------------------------------------------*/
3950 // Expose Lodash on the free variable `window` or `self` when available so it's
3951 // globally accessible, even when bundled with Browserify, Webpack, etc. This
3952 // also prevents errors in cases where Lodash is loaded by a script tag in the
3953 // presence of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch
3954 // for more details. Use `_.noConflict` to remove Lodash from the global object.
3955 (freeWindow || freeSelf || {})._ = lodash;
3957 // Some AMD build optimizers like r.js check for condition patterns like the following:
3958 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3959 // Define as an anonymous module so, through path mapping, it can be
3960 // referenced as the "underscore" module.
3965 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
3966 else if (freeExports && freeModule) {
3967 // Export for Node.js.
3968 if (moduleExports) {
3969 (freeModule.exports = lodash)._ = lodash;
3971 // Export for CommonJS support.
3972 freeExports._ = lodash;
3975 // Export to the global object.