3 * lodash 4.0.0 (Custom Build) <https://lodash.com/>
4 * Build: `lodash core -o ./dist/lodash.core.js`
5 * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
15 /** Used as the semantic version number. */
16 var VERSION = '4.0.0';
18 /** Used to compose bitmasks for wrapper metadata. */
22 /** Used to compose bitmasks for comparison styles. */
23 var UNORDERED_COMPARE_FLAG = 1,
24 PARTIAL_COMPARE_FLAG = 2;
26 /** Used as the `TypeError` message for "Functions" methods. */
27 var FUNC_ERROR_TEXT = 'Expected a function';
29 /** Used as references for various `Number` constants. */
30 var MAX_SAFE_INTEGER = 9007199254740991;
32 /** `Object#toString` result references. */
33 var argsTag = '[object Arguments]',
34 arrayTag = '[object Array]',
35 boolTag = '[object Boolean]',
36 dateTag = '[object Date]',
37 errorTag = '[object Error]',
38 funcTag = '[object Function]',
39 genTag = '[object GeneratorFunction]',
40 numberTag = '[object Number]',
41 objectTag = '[object Object]',
42 regexpTag = '[object RegExp]',
43 stringTag = '[object String]';
45 /** Used to match HTML entities and HTML characters. */
46 var reUnescapedHtml = /[&<>"'`]/g,
47 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
49 /** Used to detect unsigned integer values. */
50 var reIsUint = /^(?:0|[1-9]\d*)$/;
52 /** Used to map characters to HTML entities. */
62 /** Used to determine if values are of the language type `Object`. */
68 /** Detect free variable `exports`. */
69 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
71 /** Detect free variable `module`. */
72 var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
74 /** Detect free variable `global` from Node.js. */
75 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
77 /** Detect free variable `self`. */
78 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
80 /** Detect free variable `window`. */
81 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
83 /** Detect the popular CommonJS extension `module.exports`. */
84 var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null;
86 /** Detect `this` as the global object. */
87 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
90 * Used as a reference to the global object.
92 * The `this` value is used if it's the global object to avoid Greasemonkey's
93 * restricted `window` object, otherwise the `window` object is used.
95 var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
97 /*--------------------------------------------------------------------------*/
100 * Creates a new array concatenating `array` with `other`.
103 * @param {Array} array The first array to concatenate.
104 * @param {Array} other The second array to concatenate.
105 * @returns {Array} Returns the new concatenated array.
107 function arrayConcat(array, other) {
108 return arrayPush(copyArray(array), values);
112 * Appends the elements of `values` to `array`.
115 * @param {Array} array The array to modify.
116 * @param {Array} values The values to append.
117 * @returns {Array} Returns `array`.
119 function arrayPush(array, values) {
121 length = values.length,
122 offset = array.length;
124 while (++index < length) {
125 array[offset + index] = values[index];
131 * The base implementation of methods like `_.max` and `_.min` which accepts a
132 * `comparator` to determine the extremum value.
135 * @param {Array} array The array to iterate over.
136 * @param {Function} iteratee The iteratee invoked per iteration.
137 * @param {Function} comparator The comparator used to compare values.
138 * @returns {*} Returns the extremum value.
140 function baseExtremum(array, iteratee, comparator) {
142 length = array.length;
144 while (++index < length) {
145 var value = array[index],
146 current = iteratee(value);
148 if (current != null && (computed === undefined
149 ? current === current
150 : comparator(current, computed)
152 var computed = current,
160 * The base implementation of methods like `_.find` and `_.findKey`, without
161 * support for iteratee shorthands, which iterates over `collection` using
162 * the provided `eachFunc`.
165 * @param {Array|Object} collection The collection to search.
166 * @param {Function} predicate The function invoked per iteration.
167 * @param {Function} eachFunc The function to iterate over `collection`.
168 * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
169 * @returns {*} Returns the found element or its key, else `undefined`.
171 function baseFind(collection, predicate, eachFunc, retKey) {
173 eachFunc(collection, function(value, key, collection) {
174 if (predicate(value, key, collection)) {
175 result = retKey ? key : value;
183 * The base implementation of `_.reduce` and `_.reduceRight`, without support
184 * for iteratee shorthands, which iterates over `collection` using the provided
188 * @param {Array|Object} collection The collection to iterate over.
189 * @param {Function} iteratee The function invoked per iteration.
190 * @param {*} accumulator The initial value.
191 * @param {boolean} initFromCollection Specify using the first or last element of `collection` as the initial value.
192 * @param {Function} eachFunc The function to iterate over `collection`.
193 * @returns {*} Returns the accumulated value.
195 function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
196 eachFunc(collection, function(value, index, collection) {
197 accumulator = initFromCollection
198 ? (initFromCollection = false, value)
199 : iteratee(accumulator, value, index, collection);
205 * The base implementation of `_.times` without support for iteratee shorthands
206 * or max array length checks.
209 * @param {number} n The number of times to invoke `iteratee`.
210 * @param {Function} iteratee The function invoked per iteration.
211 * @returns {Array} Returns the array of results.
213 function baseTimes(n, iteratee) {
217 while (++index < n) {
218 result[index] = iteratee(index);
224 * The base implementation of `_.values` and `_.valuesIn` which creates an
225 * array of `object` property values corresponding to the property names
229 * @param {Object} object The object to query.
230 * @param {Array} props The property names to get values for.
231 * @returns {Object} Returns the array of property values.
233 function baseValues(object, props) {
234 return baseMap(props, function(key) {
240 * Checks if `value` is a global object.
243 * @param {*} value The value to check.
244 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
246 function checkGlobal(value) {
247 return (value && value.Object === Object) ? value : null;
251 * Compares values to sort them in ascending order.
254 * @param {*} value The value to compare.
255 * @param {*} other The other value to compare.
256 * @returns {number} Returns the sort order indicator for `value`.
258 function compareAscending(value, other) {
259 if (value !== other) {
260 var valIsNull = value === null,
261 valIsUndef = value === undefined,
262 valIsReflexive = value === value;
264 var othIsNull = other === null,
265 othIsUndef = other === undefined,
266 othIsReflexive = other === other;
268 if ((value > other && !othIsNull) || !valIsReflexive ||
269 (valIsNull && !othIsUndef && othIsReflexive) ||
270 (valIsUndef && othIsReflexive)) {
273 if ((value < other && !valIsNull) || !othIsReflexive ||
274 (othIsNull && !valIsUndef && valIsReflexive) ||
275 (othIsUndef && valIsReflexive)) {
283 * Used by `_.escape` to convert characters to HTML entities.
286 * @param {string} chr The matched character to escape.
287 * @returns {string} Returns the escaped character.
289 function escapeHtmlChar(chr) {
290 return htmlEscapes[chr];
294 * Checks if `value` is a host object in IE < 9.
297 * @param {*} value The value to check.
298 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
300 function isHostObject(value) {
301 // Many host objects are `Object` objects that can coerce to strings
302 // despite having improperly defined `toString` methods.
304 if (value != null && typeof value.toString != 'function') {
306 result = !!(value + '');
313 * Checks if `value` is a valid array-like index.
316 * @param {*} value The value to check.
317 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
318 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
320 function isIndex(value, length) {
321 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
322 length = length == null ? MAX_SAFE_INTEGER : length;
323 return value > -1 && value % 1 == 0 && value < length;
327 * Converts `iterator` to an array.
330 * @param {Object} iterator The iterator to convert.
331 * @returns {Array} Returns the converted array.
333 function iteratorToArray(iterator) {
337 while (!(data = iterator.next()).done) {
338 result.push(data.value);
343 /*--------------------------------------------------------------------------*/
345 /** Used for built-in method references. */
346 var arrayProto = Array.prototype,
347 objectProto = Object.prototype;
349 /** Used to check objects for own properties. */
350 var hasOwnProperty = objectProto.hasOwnProperty;
352 /** Used to generate unique IDs. */
356 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
359 var objectToString = objectProto.toString;
361 /** Used to restore the original `_` reference in `_.noConflict`. */
362 var oldDash = root._;
364 /** Built-in value references. */
365 var _Symbol = root.Symbol,
366 Reflect = root.Reflect,
367 Uint8Array = root.Uint8Array,
368 enumerate = Reflect ? Reflect.enumerate : undefined,
369 propertyIsEnumerable = objectProto.propertyIsEnumerable;
371 /* Built-in method references for those with the same name as other `lodash` methods. */
372 var nativeIsFinite = root.isFinite,
373 nativeKeys = Object.keys,
374 nativeMax = Math.max;
376 /*------------------------------------------------------------------------*/
379 * Creates a `lodash` object which wraps `value` to enable implicit method
380 * chaining. Methods that operate on and return arrays, collections, and
381 * functions can be chained together. Methods that retrieve a single value or
382 * may return a primitive value will automatically end the chain sequence and
383 * return the unwrapped value. Otherwise, the value must be unwrapped with
386 * Explicit chaining, which must be unwrapped with `_#value` in all cases,
387 * may be enabled using `_.chain`.
389 * The execution of chained methods is lazy, that is, it's deferred until
390 * `_#value` is implicitly or explicitly called.
392 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
393 * fusion is an optimization to merge iteratee calls; this avoids the creation
394 * of intermediate arrays and can greatly reduce the number of iteratee executions.
395 * Sections of a chain sequence qualify for shortcut fusion if the section is
396 * applied to an array of at least two hundred elements and any iteratees
397 * accept only one argument. The heuristic for whether a section qualifies
398 * for shortcut fusion is subject to change.
400 * Chaining is supported in custom builds as long as the `_#value` method is
401 * directly or indirectly included in the build.
403 * In addition to lodash methods, wrappers have `Array` and `String` methods.
405 * The wrapper `Array` methods are:
406 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
408 * The wrapper `String` methods are:
409 * `replace` and `split`
411 * The wrapper methods that support shortcut fusion are:
412 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
413 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
414 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
416 * The chainable wrapper methods are:
417 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
418 * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
419 * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`,
420 * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
421 * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
422 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
423 * `flowRight`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
424 * `forOwnRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`,
425 * `intersection`, `intersectionBy`, `intersectionWith`, invert`, `invokeMap`,
426 * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
427 * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
428 * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`,
429 * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
430 * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
431 * `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
432 * `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
433 * `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`,
434 * `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`,
435 * `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`,
436 * `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`,
437 * `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`,
438 * `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith`
440 * The wrapper methods that are **not** chainable by default are:
441 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
442 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
443 * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
444 * `findLast`, `findLastIndex`, `findLastKey`, `floor`, `get`, `gt`, `gte`,
445 * `has`, `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`,
446 * `invoke`, `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`,
447 * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
448 * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`,
449 * `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
450 * `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
451 * `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`, `last`,
452 * `lastIndexOf`, `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`,
453 * `mean`, `min`, `minBy`, `noConflict`, `noop`, `now`, `pad`, `padEnd`,
454 * `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`,
455 * `result`, `round`, `runInContext`, `sample`, `shift`, `size`, `snakeCase`,
456 * `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`,
457 * `startCase`, `startsWith`, `subtract`, `sum`, sumBy`, `template`, `times`,
458 * `toLower`, `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, toString`,
459 * `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
460 * `upperCase`, `upperFirst`, `value`, and `words`
465 * @param {*} value The value to wrap in a `lodash` instance.
466 * @returns {Object} Returns the new `lodash` wrapper instance.
469 * function square(n) {
473 * var wrapped = _([1, 2, 3]);
475 * // returns an unwrapped value
476 * wrapped.reduce(_.add);
479 * // returns a wrapped value
480 * var squares = wrapped.map(square);
482 * _.isArray(squares);
485 * _.isArray(squares.value());
488 function lodash(value) {
489 if (isObjectLike(value) && !isArray(value)) {
490 if (value instanceof LodashWrapper) {
493 if (hasOwnProperty.call(value, '__wrapped__')) {
494 return wrapperClone(value);
497 return new LodashWrapper(value);
501 * The base constructor for creating `lodash` wrapper objects.
504 * @param {*} value The value to wrap.
505 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
507 function LodashWrapper(value, chainAll) {
508 this.__wrapped__ = value;
509 this.__actions__ = [];
510 this.__chain__ = !!chainAll;
513 /*------------------------------------------------------------------------*/
516 * Used by `_.defaults` to customize its `_.assignIn` use.
519 * @param {*} objValue The destination value.
520 * @param {*} srcValue The source value.
521 * @param {string} key The key of the property to assign.
522 * @param {Object} object The parent object of `objValue`.
523 * @returns {*} Returns the value to assign.
525 function assignInDefaults(objValue, srcValue, key, object) {
526 if (objValue === undefined ||
527 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
534 * Assigns `value` to `key` of `object` if the existing value is not equivalent
535 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
536 * for equality comparisons.
539 * @param {Object} object The object to modify.
540 * @param {string} key The key of the property to assign.
541 * @param {*} value The value to assign.
543 function assignValue(object, key, value) {
544 var objValue = object[key];
545 if ((!eq(objValue, value) ||
546 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
547 (value === undefined && !(key in object))) {
553 * The base implementation of `_.create` without support for assigning
554 * properties to the created object.
557 * @param {Object} prototype The object to inherit from.
558 * @returns {Object} Returns the new object.
560 var baseCreate = (function() {
562 return function(prototype) {
563 if (isObject(prototype)) {
564 object.prototype = prototype;
565 var result = new object;
566 object.prototype = undefined;
573 * The base implementation of `_.delay` and `_.defer` which accepts an array
574 * of `func` arguments.
577 * @param {Function} func The function to delay.
578 * @param {number} wait The number of milliseconds to delay invocation.
579 * @param {Object} args The arguments provide to `func`.
580 * @returns {number} Returns the timer id.
582 function baseDelay(func, wait, args) {
583 if (typeof func != 'function') {
584 throw new TypeError(FUNC_ERROR_TEXT);
586 return setTimeout(function() { func.apply(undefined, args); }, wait);
590 * The base implementation of `_.forEach` without support for iteratee shorthands.
593 * @param {Array|Object} collection The collection to iterate over.
594 * @param {Function} iteratee The function invoked per iteration.
595 * @returns {Array|Object} Returns `collection`.
597 var baseEach = createBaseEach(baseForOwn);
600 * The base implementation of `_.every` without support for iteratee shorthands.
603 * @param {Array|Object} collection The collection to iterate over.
604 * @param {Function} predicate The function invoked per iteration.
605 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
607 function baseEvery(collection, predicate) {
609 baseEach(collection, function(value, index, collection) {
610 result = !!predicate(value, index, collection);
617 * The base implementation of `_.filter` without support for iteratee shorthands.
620 * @param {Array|Object} collection The collection to iterate over.
621 * @param {Function} predicate The function invoked per iteration.
622 * @returns {Array} Returns the new filtered array.
624 function baseFilter(collection, predicate) {
626 baseEach(collection, function(value, index, collection) {
627 if (predicate(value, index, collection)) {
635 * The base implementation of `_.flatten` with support for restricting flattening.
638 * @param {Array} array The array to flatten.
639 * @param {boolean} [isDeep] Specify a deep flatten.
640 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
641 * @param {Array} [result=[]] The initial result value.
642 * @returns {Array} Returns the new flattened array.
644 function baseFlatten(array, isDeep, isStrict, result) {
645 result || (result = []);
648 length = array.length;
650 while (++index < length) {
651 var value = array[index];
652 if (isArrayLikeObject(value) &&
653 (isStrict || isArray(value) || isArguments(value))) {
655 // Recursively flatten arrays (susceptible to call stack limits).
656 baseFlatten(value, isDeep, isStrict, result);
658 arrayPush(result, value);
660 } else if (!isStrict) {
661 result[result.length] = value;
668 * The base implementation of `baseForIn` and `baseForOwn` which iterates
669 * over `object` properties returned by `keysFunc` invoking `iteratee` for
670 * each property. Iteratee functions may exit iteration early by explicitly
674 * @param {Object} object The object to iterate over.
675 * @param {Function} iteratee The function invoked per iteration.
676 * @param {Function} keysFunc The function to get the keys of `object`.
677 * @returns {Object} Returns `object`.
679 var baseFor = createBaseFor();
682 * The base implementation of `_.forOwn` without support for iteratee shorthands.
685 * @param {Object} object The object to iterate over.
686 * @param {Function} iteratee The function invoked per iteration.
687 * @returns {Object} Returns `object`.
689 function baseForOwn(object, iteratee) {
690 return object && baseFor(object, iteratee, keys);
694 * The base implementation of `_.functions` which creates an array of
695 * `object` function property names filtered from those provided.
698 * @param {Object} object The object to inspect.
699 * @param {Array} props The property names to filter.
700 * @returns {Array} Returns the new array of filtered property names.
702 function baseFunctions(object, props) {
703 return baseFilter(props, function(key) {
704 return isFunction(object[key]);
709 * The base implementation of `_.isEqual` which supports partial comparisons
710 * and tracks traversed objects.
713 * @param {*} value The value to compare.
714 * @param {*} other The other value to compare.
715 * @param {Function} [customizer] The function to customize comparisons.
716 * @param {boolean} [bitmask] The bitmask of comparison flags.
717 * The bitmask may be composed of the following flags:
718 * 1 - Unordered comparison
719 * 2 - Partial comparison
720 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
721 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
723 function baseIsEqual(value, other, customizer, bitmask, stack) {
724 if (value === other) {
727 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
728 return value !== value && other !== other;
730 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
734 * A specialized version of `baseIsEqual` for arrays and objects which performs
735 * deep comparisons and tracks traversed objects enabling objects with circular
736 * references to be compared.
739 * @param {Object} object The object to compare.
740 * @param {Object} other The other object to compare.
741 * @param {Function} equalFunc The function to determine equivalents of values.
742 * @param {Function} [customizer] The function to customize comparisons.
743 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
744 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
745 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
747 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
748 var objIsArr = isArray(object),
749 othIsArr = isArray(other),
754 objTag = objectToString.call(object);
755 if (objTag == argsTag) {
760 othTag = objectToString.call(other);
761 if (othTag == argsTag) {
765 var objIsObj = objTag == objectTag && !isHostObject(object),
766 othIsObj = othTag == objectTag && !isHostObject(other),
767 isSameTag = objTag == othTag;
769 if (isSameTag && !(objIsArr || objIsObj)) {
770 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
772 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
774 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
775 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
777 if (objIsWrapped || othIsWrapped) {
778 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
784 stack || (stack = []);
785 var stacked = find(stack, function(entry) {
786 return entry[0] === object;
788 if (stacked && stacked[1]) {
789 return stacked[1] == other;
791 stack.push([object, other]);
792 var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
798 * The base implementation of `_.iteratee`.
801 * @param {*} [value=_.identity] The value to convert to an iteratee.
802 * @returns {Function} Returns the iteratee.
804 function baseIteratee(func) {
805 var type = typeof func;
806 if (type == 'function') {
811 : (type == 'object' ? baseMatches : baseProperty)(func);
815 * The base implementation of `_.keys` which doesn't skip the constructor
816 * property of prototypes or treat sparse arrays as dense.
820 * @param {Object} object The object to query.
821 * @returns {Array} Returns the array of property names.
823 function baseKeys(object) {
824 return nativeKeys(Object(object));
828 * The base implementation of `_.keysIn` which doesn't skip the constructor
829 * property of prototypes or treat sparse arrays as dense.
832 * @param {Object} object The object to query.
833 * @returns {Array} Returns the array of property names.
835 function baseKeysIn(object) {
836 object = object == null ? object : Object(object);
839 for (var key in object) {
845 // Fallback for IE < 9 with es6-shim.
846 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
847 baseKeysIn = function(object) {
848 return iteratorToArray(enumerate(object));
853 * The base implementation of `_.map` without support for iteratee shorthands.
856 * @param {Array|Object} collection The collection to iterate over.
857 * @param {Function} iteratee The function invoked per iteration.
858 * @returns {Array} Returns the new mapped array.
860 function baseMap(collection, iteratee) {
862 result = isArrayLike(collection) ? Array(collection.length) : [];
864 baseEach(collection, function(value, key, collection) {
865 result[++index] = iteratee(value, key, collection);
871 * The base implementation of `_.matches` which doesn't clone `source`.
874 * @param {Object} source The object of property values to match.
875 * @returns {Function} Returns the new function.
877 function baseMatches(source) {
878 var props = keys(source),
879 length = props.length;
881 return function(object) {
882 if (object == null) {
885 object = Object(object);
887 var key = props[length];
888 if (!(key in object && baseIsEqual(source[key], object[key], undefined, true))) {
897 * The base implementation of `_.pick` without support for individual
901 * @param {Object} object The source object.
902 * @param {string[]} props The property names to pick.
903 * @returns {Object} Returns the new object.
905 function basePick(object, props) {
906 object = Object(object);
907 return reduce(props, function(result, key) {
909 result[key] = object[key];
916 * The base implementation of `_.property` without support for deep paths.
919 * @param {string} key The key of the property to get.
920 * @returns {Function} Returns the new function.
922 function baseProperty(key) {
923 return function(object) {
924 return object == null ? undefined : object[key];
929 * The base implementation of `_.slice` without an iteratee call guard.
932 * @param {Array} array The array to slice.
933 * @param {number} [start=0] The start position.
934 * @param {number} [end=array.length] The end position.
935 * @returns {Array} Returns the slice of `array`.
937 function baseSlice(array, start, end) {
939 length = array.length;
942 start = -start > length ? 0 : (length + start);
944 end = end > length ? length : end;
948 length = start > end ? 0 : ((end - start) >>> 0);
951 var result = Array(length);
952 while (++index < length) {
953 result[index] = array[index + start];
959 * Copies the values of `source` to `array`.
962 * @param {Array} source The array to copy values from.
963 * @param {Array} [array=[]] The array to copy values to.
964 * @returns {Array} Returns `array`.
966 function copyArray(source) {
967 return baseSlice(source, 0, source.length);
971 * The base implementation of `_.some` without support for iteratee shorthands.
974 * @param {Array|Object} collection The collection to iterate over.
975 * @param {Function} predicate The function invoked per iteration.
976 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
978 function baseSome(collection, predicate) {
981 baseEach(collection, function(value, index, collection) {
982 result = predicate(value, index, collection);
989 * The base implementation of `wrapperValue` which returns the result of
990 * performing a sequence of actions on the unwrapped `value`, where each
991 * successive action is supplied the return value of the previous.
994 * @param {*} value The unwrapped value.
995 * @param {Array} actions Actions to perform to resolve the unwrapped value.
996 * @returns {*} Returns the resolved value.
998 function baseWrapperValue(value, actions) {
1000 return reduce(actions, function(result, action) {
1001 return action.func.apply(action.thisArg, arrayPush([result], action.args));
1006 * Copies properties of `source` to `object`.
1009 * @param {Object} source The object to copy properties from.
1010 * @param {Array} props The property names to copy.
1011 * @param {Object} [object={}] The object to copy properties to.
1012 * @returns {Object} Returns `object`.
1014 var copyObject = copyObjectWith;
1017 * This function is like `copyObject` except that it accepts a function to
1018 * customize copied values.
1021 * @param {Object} source The object to copy properties from.
1022 * @param {Array} props The property names to copy.
1023 * @param {Object} [object={}] The object to copy properties to.
1024 * @param {Function} [customizer] The function to customize copied values.
1025 * @returns {Object} Returns `object`.
1027 function copyObjectWith(source, props, object, customizer) {
1028 object || (object = {});
1031 length = props.length;
1033 while (++index < length) {
1034 var key = props[index],
1035 newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
1037 assignValue(object, key, newValue);
1043 * Creates a function like `_.assign`.
1046 * @param {Function} assigner The function to assign values.
1047 * @returns {Function} Returns the new assigner function.
1049 function createAssigner(assigner) {
1050 return rest(function(object, sources) {
1052 length = sources.length,
1053 customizer = length > 1 ? sources[length - 1] : undefined;
1055 customizer = typeof customizer == 'function' ? (length--, customizer) : undefined;
1056 object = Object(object);
1057 while (++index < length) {
1058 var source = sources[index];
1060 assigner(object, source, customizer);
1068 * Creates a `baseEach` or `baseEachRight` function.
1071 * @param {Function} eachFunc The function to iterate over a collection.
1072 * @param {boolean} [fromRight] Specify iterating from right to left.
1073 * @returns {Function} Returns the new base function.
1075 function createBaseEach(eachFunc, fromRight) {
1076 return function(collection, iteratee) {
1077 if (collection == null) {
1080 if (!isArrayLike(collection)) {
1081 return eachFunc(collection, iteratee);
1083 var length = collection.length,
1084 index = fromRight ? length : -1,
1085 iterable = Object(collection);
1087 while ((fromRight ? index-- : ++index < length)) {
1088 if (iteratee(iterable[index], index, iterable) === false) {
1097 * Creates a base function for methods like `_.forIn`.
1100 * @param {boolean} [fromRight] Specify iterating from right to left.
1101 * @returns {Function} Returns the new base function.
1103 function createBaseFor(fromRight) {
1104 return function(object, iteratee, keysFunc) {
1106 iterable = Object(object),
1107 props = keysFunc(object),
1108 length = props.length;
1111 var key = props[fromRight ? length : ++index];
1112 if (iteratee(iterable[key], key, iterable) === false) {
1121 * Creates a function that produces an instance of `Ctor` regardless of
1122 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
1125 * @param {Function} Ctor The constructor to wrap.
1126 * @returns {Function} Returns the new wrapped function.
1128 function createCtorWrapper(Ctor) {
1130 // Use a `switch` statement to work with class constructors.
1131 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1132 // for more details.
1133 var args = arguments;
1134 var thisBinding = baseCreate(Ctor.prototype),
1135 result = Ctor.apply(thisBinding, args);
1137 // Mimic the constructor's `return` behavior.
1138 // See https://es5.github.io/#x13.2.2 for more details.
1139 return isObject(result) ? result : thisBinding;
1144 * Creates a function that wraps `func` to invoke it with the optional `this`
1145 * binding of `thisArg` and the `partials` prepended to those provided to
1149 * @param {Function} func The function to wrap.
1150 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
1151 * @param {*} thisArg The `this` binding of `func`.
1152 * @param {Array} partials The arguments to prepend to those provided to the new function.
1153 * @returns {Function} Returns the new wrapped function.
1155 function createPartialWrapper(func, bitmask, thisArg, partials) {
1156 if (typeof func != 'function') {
1157 throw new TypeError(FUNC_ERROR_TEXT);
1159 var isBind = bitmask & BIND_FLAG,
1160 Ctor = createCtorWrapper(func);
1162 function wrapper() {
1164 argsLength = arguments.length,
1166 leftLength = partials.length,
1167 args = Array(leftLength + argsLength),
1168 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
1170 while (++leftIndex < leftLength) {
1171 args[leftIndex] = partials[leftIndex];
1173 while (argsLength--) {
1174 args[leftIndex++] = arguments[++argsIndex];
1176 return fn.apply(isBind ? thisArg : this, args);
1182 * A specialized version of `baseIsEqualDeep` for arrays with support for
1183 * partial deep comparisons.
1186 * @param {Array} array The array to compare.
1187 * @param {Array} other The other array to compare.
1188 * @param {Function} equalFunc The function to determine equivalents of values.
1189 * @param {Function} [customizer] The function to customize comparisons.
1190 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1191 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
1192 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1194 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
1196 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1197 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
1198 arrLength = array.length,
1199 othLength = other.length;
1201 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1206 // Ignore non-index properties.
1207 while (++index < arrLength) {
1208 var arrValue = array[index],
1209 othValue = other[index];
1212 if (compared !== undefined) {
1219 // Recursively compare arrays (susceptible to call stack limits).
1221 if (!baseSome(other, function(othValue) {
1222 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
1227 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
1236 * A specialized version of `baseIsEqualDeep` for comparing objects of
1237 * the same `toStringTag`.
1239 * **Note:** This function only supports comparing values with tags of
1240 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1243 * @param {Object} object The object to compare.
1244 * @param {Object} other The other object to compare.
1245 * @param {string} tag The `toStringTag` of the objects to compare.
1246 * @param {Function} equalFunc The function to determine equivalents of values.
1247 * @param {Function} [customizer] The function to customize comparisons.
1248 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1249 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1251 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
1256 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
1257 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
1258 return +object == +other;
1261 return object.name == other.name && object.message == other.message;
1264 // Treat `NaN` vs. `NaN` as equal.
1265 return (object != +object) ? other != +other : object == +other;
1269 // Coerce regexes to strings and treat strings primitives and string
1270 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
1271 return object == (other + '');
1278 * A specialized version of `baseIsEqualDeep` for objects with support for
1279 * partial deep comparisons.
1282 * @param {Object} object The object to compare.
1283 * @param {Object} other The other object to compare.
1284 * @param {Function} equalFunc The function to determine equivalents of values.
1285 * @param {Function} [customizer] The function to customize comparisons.
1286 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1287 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
1288 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1290 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
1291 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1292 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
1293 objProps = keys(object),
1294 objLength = objProps.length,
1295 othProps = keys(other),
1296 othLength = othProps.length;
1298 if (objLength != othLength && !isPartial) {
1301 var index = objLength;
1303 var key = objProps[index];
1304 if (!(isPartial ? key in other : hasOwnProperty.call(other, key)) ||
1305 !(isUnordered || key == othProps[index])) {
1311 var skipCtor = isPartial;
1312 while (++index < objLength) {
1313 key = objProps[index];
1314 var objValue = object[key],
1315 othValue = other[key];
1318 // Recursively compare objects (susceptible to call stack limits).
1319 if (!(compared === undefined
1320 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
1326 skipCtor || (skipCtor = key == 'constructor');
1328 if (result && !skipCtor) {
1329 var objCtor = object.constructor,
1330 othCtor = other.constructor;
1332 // Non `Object` object instances with different constructors are not equal.
1333 if (objCtor != othCtor &&
1334 ('constructor' in object && 'constructor' in other) &&
1335 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1336 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1344 * Gets the "length" property value of `object`.
1346 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
1347 * that affects Safari on at least iOS 8.1-8.3 ARM64.
1350 * @param {Object} object The object to query.
1351 * @returns {*} Returns the "length" value.
1353 var getLength = baseProperty('length');
1356 * Creates an array of index keys for `object` values of arrays,
1357 * `arguments` objects, and strings, otherwise `null` is returned.
1360 * @param {Object} object The object to query.
1361 * @returns {Array|null} Returns index keys, else `null`.
1363 function indexKeys(object) {
1364 var length = object ? object.length : undefined;
1365 return (isLength(length) && (isArray(object) || isString(object) || isArguments(object)))
1366 ? baseTimes(length, String)
1371 * Checks if `value` is likely a prototype object.
1374 * @param {*} value The value to check.
1375 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1377 function isPrototype(value) {
1378 var Ctor = value && value.constructor,
1379 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1381 return value === proto;
1385 * Converts `value` to a function if it's not one.
1388 * @param {*} value The value to process.
1389 * @returns {Function} Returns the function.
1391 function toFunction(value) {
1392 return typeof value == 'function' ? value : identity;
1396 * Creates a clone of `wrapper`.
1399 * @param {Object} wrapper The wrapper to clone.
1400 * @returns {Object} Returns the cloned wrapper.
1402 function wrapperClone(wrapper) {
1403 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
1404 result.__actions__ = copyArray(wrapper.__actions__);
1408 /*------------------------------------------------------------------------*/
1411 * Creates an array with all falsey values removed. The values `false`, `null`,
1412 * `0`, `""`, `undefined`, and `NaN` are falsey.
1417 * @param {Array} array The array to compact.
1418 * @returns {Array} Returns the new array of filtered values.
1421 * _.compact([0, 1, false, 2, '', 3]);
1424 function compact(array) {
1425 return baseFilter(array, Boolean);
1429 * Creates a new array concatenating `array` with any additional arrays
1435 * @param {Array} array The array to concatenate.
1436 * @param {...*} [values] The values to concatenate.
1437 * @returns {Array} Returns the new concatenated array.
1441 * var other = _.concat(array, 2, [3], [[4]]);
1443 * console.log(other);
1444 * // => [1, 2, 3, [4]]
1446 * console.log(array);
1449 var concat = rest(function(array, values) {
1450 values = baseFlatten(values);
1451 return arrayConcat(isArray(array) ? array : [Object(array)], values);
1455 * Flattens `array` a single level.
1460 * @param {Array} array The array to flatten.
1461 * @returns {Array} Returns the new flattened array.
1464 * _.flatten([1, [2, 3, [4]]]);
1465 * // => [1, 2, 3, [4]]
1467 function flatten(array) {
1468 var length = array ? array.length : 0;
1469 return length ? baseFlatten(array) : [];
1473 * This method is like `_.flatten` except that it recursively flattens `array`.
1478 * @param {Array} array The array to recursively flatten.
1479 * @returns {Array} Returns the new flattened array.
1482 * _.flattenDeep([1, [2, 3, [4]]]);
1483 * // => [1, 2, 3, 4]
1485 function flattenDeep(array) {
1486 var length = array ? array.length : 0;
1487 return length ? baseFlatten(array, true) : [];
1491 * Gets the first element of `array`.
1497 * @param {Array} array The array to query.
1498 * @returns {*} Returns the first element of `array`.
1501 * _.head([1, 2, 3]);
1507 function head(array) {
1508 return array ? array[0] : undefined;
1512 * Gets the index at which the first occurrence of `value` is found in `array`
1513 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
1514 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
1515 * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
1516 * performs a faster binary search.
1521 * @param {Array} array The array to search.
1522 * @param {*} value The value to search for.
1523 * @param {number} [fromIndex=0] The index to search from.
1524 * @returns {number} Returns the index of the matched value, else `-1`.
1527 * _.indexOf([1, 2, 1, 2], 2);
1530 * // using `fromIndex`
1531 * _.indexOf([1, 2, 1, 2], 2, 2);
1534 function indexOf(array, value, fromIndex) {
1535 var length = array ? array.length : 0;
1536 if (typeof fromIndex == 'number') {
1537 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1541 var index = (fromIndex || 0) - 1,
1542 isReflexive = value === value;
1544 while (++index < length) {
1545 var other = array[index];
1546 if ((isReflexive ? other === value : other !== other)) {
1554 * Gets the last element of `array`.
1559 * @param {Array} array The array to query.
1560 * @returns {*} Returns the last element of `array`.
1563 * _.last([1, 2, 3]);
1566 function last(array) {
1567 var length = array ? array.length : 0;
1568 return length ? array[length - 1] : undefined;
1572 * Creates a slice of `array` from `start` up to, but not including, `end`.
1574 * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
1575 * to ensure dense arrays are returned.
1580 * @param {Array} array The array to slice.
1581 * @param {number} [start=0] The start position.
1582 * @param {number} [end=array.length] The end position.
1583 * @returns {Array} Returns the slice of `array`.
1585 function slice(array, start, end) {
1586 var length = array ? array.length : 0;
1587 return length ? baseSlice(array, start, end) : [];
1590 /*------------------------------------------------------------------------*/
1593 * Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
1594 * The result of such method chaining must be unwrapped with `_#value`.
1599 * @param {*} value The value to wrap.
1600 * @returns {Object} Returns the new `lodash` wrapper instance.
1604 * { 'user': 'barney', 'age': 36 },
1605 * { 'user': 'fred', 'age': 40 },
1606 * { 'user': 'pebbles', 'age': 1 }
1612 * .map(function(o) {
1613 * return o.user + ' is ' + o.age;
1617 * // => 'pebbles is 1'
1619 function chain(value) {
1620 var result = lodash(value);
1621 result.__chain__ = true;
1626 * This method invokes `interceptor` and returns `value`. The interceptor is
1627 * invoked with one argument; (value). The purpose of this method is to "tap into"
1628 * a method chain in order to perform operations on intermediate results within
1634 * @param {*} value The value to provide to `interceptor`.
1635 * @param {Function} interceptor The function to invoke.
1636 * @returns {*} Returns `value`.
1640 * .tap(function(array) {
1647 function tap(value, interceptor) {
1653 * This method is like `_.tap` except that it returns the result of `interceptor`.
1658 * @param {*} value The value to provide to `interceptor`.
1659 * @param {Function} interceptor The function to invoke.
1660 * @returns {*} Returns the result of `interceptor`.
1666 * .thru(function(value) {
1672 function thru(value, interceptor) {
1673 return interceptor(value);
1677 * Enables explicit method chaining on the wrapper object.
1682 * @returns {Object} Returns the new `lodash` wrapper instance.
1686 * { 'user': 'barney', 'age': 36 },
1687 * { 'user': 'fred', 'age': 40 }
1690 * // without explicit chaining
1692 * // => { 'user': 'barney', 'age': 36 }
1694 * // with explicit chaining
1700 * // => { 'user': 'barney' }
1702 function wrapperChain() {
1707 * Executes the chained sequence to extract the unwrapped value.
1711 * @alias run, toJSON, valueOf
1713 * @returns {*} Returns the resolved unwrapped value.
1716 * _([1, 2, 3]).value();
1719 function wrapperValue() {
1720 return baseWrapperValue(this.__wrapped__, this.__actions__);
1723 /*------------------------------------------------------------------------*/
1726 * Checks if `predicate` returns truthy for **all** elements of `collection`.
1727 * Iteration is stopped once `predicate` returns falsey. The predicate is
1728 * invoked with three arguments: (value, index|key, collection).
1732 * @category Collection
1733 * @param {Array|Object} collection The collection to iterate over.
1734 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1735 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
1736 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
1739 * _.every([true, 1, null, 'yes'], Boolean);
1743 * { 'user': 'barney', 'active': false },
1744 * { 'user': 'fred', 'active': false }
1747 * // using the `_.matches` iteratee shorthand
1748 * _.every(users, { 'user': 'barney', 'active': false });
1751 * // using the `_.matchesProperty` iteratee shorthand
1752 * _.every(users, ['active', false]);
1755 * // using the `_.property` iteratee shorthand
1756 * _.every(users, 'active');
1759 function every(collection, predicate, guard) {
1760 predicate = guard ? undefined : predicate;
1761 return baseEvery(collection, baseIteratee(predicate));
1765 * Iterates over elements of `collection`, returning an array of all elements
1766 * `predicate` returns truthy for. The predicate is invoked with three arguments:
1767 * (value, index|key, collection).
1771 * @category Collection
1772 * @param {Array|Object} collection The collection to iterate over.
1773 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1774 * @returns {Array} Returns the new filtered array.
1778 * { 'user': 'barney', 'age': 36, 'active': true },
1779 * { 'user': 'fred', 'age': 40, 'active': false }
1782 * _.filter(users, function(o) { return !o.active; });
1783 * // => objects for ['fred']
1785 * // using the `_.matches` iteratee shorthand
1786 * _.filter(users, { 'age': 36, 'active': true });
1787 * // => objects for ['barney']
1789 * // using the `_.matchesProperty` iteratee shorthand
1790 * _.filter(users, ['active', false]);
1791 * // => objects for ['fred']
1793 * // using the `_.property` iteratee shorthand
1794 * _.filter(users, 'active');
1795 * // => objects for ['barney']
1797 function filter(collection, predicate) {
1798 return baseFilter(collection, baseIteratee(predicate));
1802 * Iterates over elements of `collection`, returning the first element
1803 * `predicate` returns truthy for. The predicate is invoked with three arguments:
1804 * (value, index|key, collection).
1808 * @category Collection
1809 * @param {Array|Object} collection The collection to search.
1810 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1811 * @returns {*} Returns the matched element, else `undefined`.
1815 * { 'user': 'barney', 'age': 36, 'active': true },
1816 * { 'user': 'fred', 'age': 40, 'active': false },
1817 * { 'user': 'pebbles', 'age': 1, 'active': true }
1820 * _.find(users, function(o) { return o.age < 40; });
1821 * // => object for 'barney'
1823 * // using the `_.matches` iteratee shorthand
1824 * _.find(users, { 'age': 1, 'active': true });
1825 * // => object for 'pebbles'
1827 * // using the `_.matchesProperty` iteratee shorthand
1828 * _.find(users, ['active', false]);
1829 * // => object for 'fred'
1831 * // using the `_.property` iteratee shorthand
1832 * _.find(users, 'active');
1833 * // => object for 'barney'
1835 function find(collection, predicate) {
1836 return baseFind(collection, baseIteratee(predicate), baseEach);
1840 * Iterates over elements of `collection` invoking `iteratee` for each element.
1841 * The iteratee is invoked with three arguments: (value, index|key, collection).
1842 * Iteratee functions may exit iteration early by explicitly returning `false`.
1844 * **Note:** As with other "Collections" methods, objects with a "length" property
1845 * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
1846 * for object iteration.
1851 * @category Collection
1852 * @param {Array|Object} collection The collection to iterate over.
1853 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1854 * @returns {Array|Object} Returns `collection`.
1857 * _([1, 2]).forEach(function(value) {
1858 * console.log(value);
1860 * // => logs `1` then `2`
1862 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
1865 * // => logs 'a' then 'b' (iteration order is not guaranteed)
1867 function forEach(collection, iteratee) {
1868 return baseEach(collection, toFunction(iteratee));
1872 * Invokes the method at `path` of each element in `collection`, returning
1873 * an array of the results of each invoked method. Any additional arguments
1874 * are provided to each invoked method. If `methodName` is a function it's
1875 * invoked for, and `this` bound to, each element in `collection`.
1879 * @category Collection
1880 * @param {Array|Object} collection The collection to iterate over.
1881 * @param {Array|Function|string} path The path of the method to invoke or
1882 * the function invoked per iteration.
1883 * @param {...*} [args] The arguments to invoke each method with.
1884 * @returns {Array} Returns the array of results.
1887 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
1888 * // => [[1, 5, 7], [1, 2, 3]]
1890 * _.invokeMap([123, 456], String.prototype.split, '');
1891 * // => [['1', '2', '3'], ['4', '5', '6']]
1893 var invokeMap = rest(function(collection, path, args) {
1894 var isFunc = typeof path == 'function';
1895 return baseMap(collection, function(value) {
1896 var func = isFunc ? path : value[path];
1897 return func == null ? func : func.apply(value, args);
1902 * Creates an array of values by running each element in `collection` through
1903 * `iteratee`. The iteratee is invoked with three arguments:
1904 * (value, index|key, collection).
1906 * Many lodash methods are guarded to work as iteratees for methods like
1907 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
1909 * The guarded methods are:
1910 * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
1911 * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
1912 * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
1917 * @category Collection
1918 * @param {Array|Object} collection The collection to iterate over.
1919 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
1920 * @returns {Array} Returns the new mapped array.
1923 * function square(n) {
1927 * _.map([1, 2], square);
1930 * _.map({ 'a': 1, 'b': 2 }, square);
1931 * // => [3, 6] (iteration order is not guaranteed)
1934 * { 'user': 'barney' },
1935 * { 'user': 'fred' }
1938 * // using the `_.property` iteratee shorthand
1939 * _.map(users, 'user');
1940 * // => ['barney', 'fred']
1942 function map(collection, iteratee) {
1943 return baseMap(collection, baseIteratee(iteratee));
1947 * Reduces `collection` to a value which is the accumulated result of running
1948 * each element in `collection` through `iteratee`, where each successive
1949 * invocation is supplied the return value of the previous. If `accumulator`
1950 * is not provided the first element of `collection` is used as the initial
1951 * value. The iteratee is invoked with four arguments:
1952 * (accumulator, value, index|key, collection).
1954 * Many lodash methods are guarded to work as iteratees for methods like
1955 * `_.reduce`, `_.reduceRight`, and `_.transform`.
1957 * The guarded methods are:
1958 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
1963 * @category Collection
1964 * @param {Array|Object} collection The collection to iterate over.
1965 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1966 * @param {*} [accumulator] The initial value.
1967 * @returns {*} Returns the accumulated value.
1970 * _.reduce([1, 2], function(sum, n) {
1975 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
1976 * (result[value] || (result[value] = [])).push(key);
1979 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
1981 function reduce(collection, iteratee, accumulator) {
1982 return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
1986 * Gets the size of `collection` by returning its length for array-like
1987 * values or the number of own enumerable properties for objects.
1991 * @category Collection
1992 * @param {Array|Object} collection The collection to inspect.
1993 * @returns {number} Returns the collection size.
1996 * _.size([1, 2, 3]);
1999 * _.size({ 'a': 1, 'b': 2 });
2002 * _.size('pebbles');
2005 function size(collection) {
2006 if (collection == null) {
2009 collection = isArrayLike(collection) ? collection : keys(collection);
2010 return collection.length;
2014 * Checks if `predicate` returns truthy for **any** element of `collection`.
2015 * Iteration is stopped once `predicate` returns truthy. The predicate is
2016 * invoked with three arguments: (value, index|key, collection).
2020 * @category Collection
2021 * @param {Array|Object} collection The collection to iterate over.
2022 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
2023 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
2024 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
2027 * _.some([null, 0, 'yes', false], Boolean);
2031 * { 'user': 'barney', 'active': true },
2032 * { 'user': 'fred', 'active': false }
2035 * // using the `_.matches` iteratee shorthand
2036 * _.some(users, { 'user': 'barney', 'active': false });
2039 * // using the `_.matchesProperty` iteratee shorthand
2040 * _.some(users, ['active', false]);
2043 * // using the `_.property` iteratee shorthand
2044 * _.some(users, 'active');
2047 function some(collection, predicate, guard) {
2048 predicate = guard ? undefined : predicate;
2049 return baseSome(collection, baseIteratee(predicate));
2053 * Creates an array of elements, sorted in ascending order by the results of
2054 * running each element in a collection through each iteratee. This method
2055 * performs a stable sort, that is, it preserves the original sort order of
2056 * equal elements. The iteratees are invoked with one argument: (value).
2060 * @category Collection
2061 * @param {Array|Object} collection The collection to iterate over.
2062 * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
2063 * The iteratees to sort by, specified individually or in arrays.
2064 * @returns {Array} Returns the new sorted array.
2068 * { 'user': 'fred', 'age': 48 },
2069 * { 'user': 'barney', 'age': 36 },
2070 * { 'user': 'fred', 'age': 42 },
2071 * { 'user': 'barney', 'age': 34 }
2074 * _.sortBy(users, function(o) { return o.user; });
2075 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2077 * _.sortBy(users, ['user', 'age']);
2078 * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
2080 * _.sortBy(users, 'user', function(o) {
2081 * return Math.floor(o.age / 10);
2083 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2085 function sortBy(collection, iteratee) {
2087 iteratee = baseIteratee(iteratee);
2089 return baseMap(baseMap(collection, function(value, key, collection) {
2090 return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2091 }).sort(function(object, other) {
2092 return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2093 }), baseProperty('value'));
2096 /*------------------------------------------------------------------------*/
2099 * Gets the timestamp of the number of milliseconds that have elapsed since
2100 * the Unix epoch (1 January 1970 00:00:00 UTC).
2106 * @returns {number} Returns the timestamp.
2109 * _.defer(function(stamp) {
2110 * console.log(_.now() - stamp);
2112 * // => logs the number of milliseconds it took for the deferred function to be invoked
2116 /*------------------------------------------------------------------------*/
2119 * Creates a function that invokes `func`, with the `this` binding and arguments
2120 * of the created function, while it's called less than `n` times. Subsequent
2121 * calls to the created function return the result of the last `func` invocation.
2125 * @category Function
2126 * @param {number} n The number of calls at which `func` is no longer invoked.
2127 * @param {Function} func The function to restrict.
2128 * @returns {Function} Returns the new restricted function.
2131 * jQuery(element).on('click', _.before(5, addContactToList));
2132 * // => allows adding up to 4 contacts to the list
2134 function before(n, func) {
2136 if (typeof func != 'function') {
2137 throw new TypeError(FUNC_ERROR_TEXT);
2142 result = func.apply(this, arguments);
2152 * Creates a function that invokes `func` with the `this` binding of `thisArg`
2153 * and prepends any additional `_.bind` arguments to those provided to the
2156 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2157 * may be used as a placeholder for partially applied arguments.
2159 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
2160 * property of bound functions.
2164 * @category Function
2165 * @param {Function} func The function to bind.
2166 * @param {*} thisArg The `this` binding of `func`.
2167 * @param {...*} [partials] The arguments to be partially applied.
2168 * @returns {Function} Returns the new bound function.
2171 * var greet = function(greeting, punctuation) {
2172 * return greeting + ' ' + this.user + punctuation;
2175 * var object = { 'user': 'fred' };
2177 * var bound = _.bind(greet, object, 'hi');
2181 * // using placeholders
2182 * var bound = _.bind(greet, object, _, '!');
2186 var bind = rest(function(func, thisArg, partials) {
2187 return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
2191 * Defers invoking the `func` until the current call stack has cleared. Any
2192 * additional arguments are provided to `func` when it's invoked.
2196 * @category Function
2197 * @param {Function} func The function to defer.
2198 * @param {...*} [args] The arguments to invoke `func` with.
2199 * @returns {number} Returns the timer id.
2202 * _.defer(function(text) {
2203 * console.log(text);
2205 * // logs 'deferred' after one or more milliseconds
2207 var defer = rest(function(func, args) {
2208 return baseDelay(func, 1, args);
2212 * Invokes `func` after `wait` milliseconds. Any additional arguments are
2213 * provided to `func` when it's invoked.
2217 * @category Function
2218 * @param {Function} func The function to delay.
2219 * @param {number} wait The number of milliseconds to delay invocation.
2220 * @param {...*} [args] The arguments to invoke `func` with.
2221 * @returns {number} Returns the timer id.
2224 * _.delay(function(text) {
2225 * console.log(text);
2226 * }, 1000, 'later');
2227 * // => logs 'later' after one second
2229 var delay = rest(function(func, wait, args) {
2230 return baseDelay(func, toNumber(wait) || 0, args);
2234 * Creates a function that negates the result of the predicate `func`. The
2235 * `func` predicate is invoked with the `this` binding and arguments of the
2240 * @category Function
2241 * @param {Function} predicate The predicate to negate.
2242 * @returns {Function} Returns the new function.
2245 * function isEven(n) {
2246 * return n % 2 == 0;
2249 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2252 function negate(predicate) {
2253 if (typeof predicate != 'function') {
2254 throw new TypeError(FUNC_ERROR_TEXT);
2257 return !predicate.apply(this, arguments);
2262 * Creates a function that is restricted to invoking `func` once. Repeat calls
2263 * to the function return the value of the first invocation. The `func` is
2264 * invoked with the `this` binding and arguments of the created function.
2268 * @category Function
2269 * @param {Function} func The function to restrict.
2270 * @returns {Function} Returns the new restricted function.
2273 * var initialize = _.once(createApplication);
2276 * // `initialize` invokes `createApplication` once
2278 function once(func) {
2279 return before(2, func);
2283 * Creates a function that invokes `func` with the `this` binding of the
2284 * created function and arguments from `start` and beyond provided as an array.
2286 * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
2290 * @category Function
2291 * @param {Function} func The function to apply a rest parameter to.
2292 * @param {number} [start=func.length-1] The start position of the rest parameter.
2293 * @returns {Function} Returns the new function.
2296 * var say = _.rest(function(what, names) {
2297 * return what + ' ' + _.initial(names).join(', ') +
2298 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
2301 * say('hello', 'fred', 'barney', 'pebbles');
2302 * // => 'hello fred, barney, & pebbles'
2304 function rest(func, start) {
2305 if (typeof func != 'function') {
2306 throw new TypeError(FUNC_ERROR_TEXT);
2308 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
2310 var args = arguments,
2312 length = nativeMax(args.length - start, 0),
2313 array = Array(length);
2315 while (++index < length) {
2316 array[index] = args[start + index];
2318 var otherArgs = Array(start + 1);
2320 while (++index < start) {
2321 otherArgs[index] = args[index];
2323 otherArgs[start] = array;
2324 return func.apply(this, otherArgs);
2328 /*------------------------------------------------------------------------*/
2331 * Creates a shallow clone of `value`.
2333 * **Note:** This method is loosely based on the
2334 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2335 * and supports cloning arrays, array buffers, booleans, date objects, maps,
2336 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2337 * arrays. The own enumerable properties of `arguments` objects are cloned
2338 * as plain objects. An empty object is returned for uncloneable values such
2339 * as error objects, functions, DOM nodes, and WeakMaps.
2344 * @param {*} value The value to clone.
2345 * @returns {*} Returns the cloned value.
2348 * var objects = [{ 'a': 1 }, { 'b': 2 }];
2350 * var shallow = _.clone(objects);
2351 * console.log(shallow[0] === objects[0]);
2354 function clone(value) {
2355 if (!isObject(value)) {
2358 return isArray(value) ? copyArray(value) : copyObject(value, keys(value));
2362 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2363 * comparison between two values to determine if they are equivalent.
2368 * @param {*} value The value to compare.
2369 * @param {*} other The other value to compare.
2370 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2373 * var object = { 'user': 'fred' };
2374 * var other = { 'user': 'fred' };
2376 * _.eq(object, object);
2379 * _.eq(object, other);
2385 * _.eq('a', Object('a'));
2391 function eq(value, other) {
2392 return value === other || (value !== value && other !== other);
2396 * Checks if `value` is greater than `other`.
2401 * @param {*} value The value to compare.
2402 * @param {*} other The other value to compare.
2403 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
2415 function gt(value, other) {
2416 return value > other;
2420 * Checks if `value` is likely an `arguments` object.
2425 * @param {*} value The value to check.
2426 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2429 * _.isArguments(function() { return arguments; }());
2432 * _.isArguments([1, 2, 3]);
2435 function isArguments(value) {
2436 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
2437 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
2438 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
2442 * Checks if `value` is classified as an `Array` object.
2448 * @param {*} value The value to check.
2449 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2452 * _.isArray([1, 2, 3]);
2455 * _.isArray(document.body.children);
2461 * _.isArray(_.noop);
2464 var isArray = Array.isArray;
2467 * Checks if `value` is array-like. A value is considered array-like if it's
2468 * not a function and has a `value.length` that's an integer greater than or
2469 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2475 * @param {*} value The value to check.
2476 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2479 * _.isArrayLike([1, 2, 3]);
2482 * _.isArrayLike(document.body.children);
2485 * _.isArrayLike('abc');
2488 * _.isArrayLike(_.noop);
2491 function isArrayLike(value) {
2492 return value != null &&
2493 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
2497 * This method is like `_.isArrayLike` except that it also checks if `value`
2504 * @param {*} value The value to check.
2505 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
2508 * _.isArrayLikeObject([1, 2, 3]);
2511 * _.isArrayLikeObject(document.body.children);
2514 * _.isArrayLikeObject('abc');
2517 * _.isArrayLikeObject(_.noop);
2520 function isArrayLikeObject(value) {
2521 return isObjectLike(value) && isArrayLike(value);
2525 * Checks if `value` is classified as a boolean primitive or object.
2530 * @param {*} value The value to check.
2531 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2534 * _.isBoolean(false);
2537 * _.isBoolean(null);
2540 function isBoolean(value) {
2541 return value === true || value === false ||
2542 (isObjectLike(value) && objectToString.call(value) == boolTag);
2546 * Checks if `value` is classified as a `Date` object.
2551 * @param {*} value The value to check.
2552 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2555 * _.isDate(new Date);
2558 * _.isDate('Mon April 23 2012');
2561 function isDate(value) {
2562 return isObjectLike(value) && objectToString.call(value) == dateTag;
2566 * Checks if `value` is empty. A value is considered empty unless it's an
2567 * `arguments` object, array, string, or jQuery-like collection with a length
2568 * greater than `0` or an object with own enumerable properties.
2573 * @param {Array|Object|string} value The value to inspect.
2574 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2586 * _.isEmpty([1, 2, 3]);
2589 * _.isEmpty({ 'a': 1 });
2592 function isEmpty(value) {
2593 return (!isObjectLike(value) || isFunction(value.splice))
2595 : !keys(value).length;
2599 * Performs a deep comparison between two values to determine if they are
2602 * **Note:** This method supports comparing arrays, array buffers, booleans,
2603 * date objects, error objects, maps, numbers, `Object` objects, regexes,
2604 * sets, strings, symbols, and typed arrays. `Object` objects are compared
2605 * by their own, not inherited, enumerable properties. Functions and DOM
2606 * nodes are **not** supported.
2611 * @param {*} value The value to compare.
2612 * @param {*} other The other value to compare.
2613 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2616 * var object = { 'user': 'fred' };
2617 * var other = { 'user': 'fred' };
2619 * _.isEqual(object, other);
2625 function isEqual(value, other) {
2626 return baseIsEqual(value, other);
2630 * Checks if `value` is a finite primitive number.
2632 * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
2637 * @param {*} value The value to check.
2638 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
2644 * _.isFinite(Number.MAX_VALUE);
2650 * _.isFinite(Infinity);
2653 function isFinite(value) {
2654 return typeof value == 'number' && nativeIsFinite(value);
2658 * Checks if `value` is classified as a `Function` object.
2663 * @param {*} value The value to check.
2664 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2670 * _.isFunction(/abc/);
2673 function isFunction(value) {
2674 // The use of `Object#toString` avoids issues with the `typeof` operator
2675 // in Safari 8 which returns 'object' for typed array constructors, and
2676 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
2677 var tag = isObject(value) ? objectToString.call(value) : '';
2678 return tag == funcTag || tag == genTag;
2682 * Checks if `value` is a valid array-like length.
2684 * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
2689 * @param {*} value The value to check.
2690 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
2696 * _.isLength(Number.MIN_VALUE);
2699 * _.isLength(Infinity);
2705 function isLength(value) {
2706 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2710 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
2711 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2716 * @param {*} value The value to check.
2717 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2723 * _.isObject([1, 2, 3]);
2726 * _.isObject(_.noop);
2732 function isObject(value) {
2733 // Avoid a V8 JIT bug in Chrome 19-20.
2734 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
2735 var type = typeof value;
2736 return !!value && (type == 'object' || type == 'function');
2740 * Checks if `value` is object-like. A value is object-like if it's not `null`
2741 * and has a `typeof` result of "object".
2746 * @param {*} value The value to check.
2747 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2750 * _.isObjectLike({});
2753 * _.isObjectLike([1, 2, 3]);
2756 * _.isObjectLike(_.noop);
2759 * _.isObjectLike(null);
2762 function isObjectLike(value) {
2763 return !!value && typeof value == 'object';
2767 * Checks if `value` is `NaN`.
2769 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
2770 * which returns `true` for `undefined` and other non-numeric values.
2775 * @param {*} value The value to check.
2776 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2782 * _.isNaN(new Number(NaN));
2788 * _.isNaN(undefined);
2791 function isNaN(value) {
2792 // An `NaN` primitive is the only value that is not equal to itself.
2793 // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
2794 return isNumber(value) && value != +value;
2798 * Checks if `value` is `null`.
2803 * @param {*} value The value to check.
2804 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2813 function isNull(value) {
2814 return value === null;
2818 * Checks if `value` is classified as a `Number` primitive or object.
2820 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
2821 * as numbers, use the `_.isFinite` method.
2826 * @param {*} value The value to check.
2827 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2833 * _.isNumber(Number.MIN_VALUE);
2836 * _.isNumber(Infinity);
2842 function isNumber(value) {
2843 return typeof value == 'number' ||
2844 (isObjectLike(value) && objectToString.call(value) == numberTag);
2848 * Checks if `value` is classified as a `RegExp` object.
2853 * @param {*} value The value to check.
2854 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2857 * _.isRegExp(/abc/);
2860 * _.isRegExp('/abc/');
2863 function isRegExp(value) {
2864 return isObject(value) && objectToString.call(value) == regexpTag;
2868 * Checks if `value` is classified as a `String` primitive or object.
2873 * @param {*} value The value to check.
2874 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2877 * _.isString('abc');
2883 function isString(value) {
2884 return typeof value == 'string' ||
2885 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
2889 * Checks if `value` is `undefined`.
2894 * @param {*} value The value to check.
2895 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
2898 * _.isUndefined(void 0);
2901 * _.isUndefined(null);
2904 function isUndefined(value) {
2905 return value === undefined;
2909 * Checks if `value` is less than `other`.
2914 * @param {*} value The value to compare.
2915 * @param {*} other The other value to compare.
2916 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
2928 function lt(value, other) {
2929 return value < other;
2933 * Converts `value` to an array.
2938 * @param {*} value The value to convert.
2939 * @returns {Array} Returns the converted array.
2942 * _.toArray({ 'a': 1, 'b': 2 });
2946 * // => ['a', 'b', 'c']
2954 function toArray(value) {
2955 if (!isArrayLike(value)) {
2956 return values(value);
2958 return value.length ? copyArray(value) : [];
2962 * Converts `value` to an integer.
2964 * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
2969 * @param {*} value The value to convert.
2970 * @returns {number} Returns the converted integer.
2976 * _.toInteger(Number.MIN_VALUE);
2979 * _.toInteger(Infinity);
2980 * // => 1.7976931348623157e+308
2985 var toInteger = Number;
2988 * Converts `value` to a number.
2993 * @param {*} value The value to process.
2994 * @returns {number} Returns the number.
3000 * _.toNumber(Number.MIN_VALUE);
3003 * _.toNumber(Infinity);
3009 var toNumber = Number;
3012 * Converts `value` to a string if it's not one. An empty string is returned
3013 * for `null` and `undefined` values. The sign of `-0` is preserved.
3018 * @param {*} value The value to process.
3019 * @returns {string} Returns the string.
3028 * _.toString([1, 2, 3]);
3031 function toString(value) {
3032 if (typeof value == 'string') {
3035 return value == null ? '' : (value + '');
3038 /*------------------------------------------------------------------------*/
3041 * Assigns own enumerable properties of source objects to the destination
3042 * object. Source objects are applied from left to right. Subsequent sources
3043 * overwrite property assignments of previous sources.
3045 * **Note:** This method mutates `object` and is loosely based on
3046 * [`Object.assign`](https://mdn.io/Object/assign).
3051 * @param {Object} object The destination object.
3052 * @param {...Object} [sources] The source objects.
3053 * @returns {Object} Returns `object`.
3064 * Foo.prototype.d = 4;
3065 * Bar.prototype.f = 6;
3067 * _.assign({ 'a': 1 }, new Foo, new Bar);
3068 * // => { 'a': 1, 'c': 3, 'e': 5 }
3070 var assign = createAssigner(function(object, source) {
3071 copyObject(source, keys(source), object);
3075 * This method is like `_.assign` except that it iterates over own and
3076 * inherited source properties.
3078 * **Note:** This method mutates `object`.
3084 * @param {Object} object The destination object.
3085 * @param {...Object} [sources] The source objects.
3086 * @returns {Object} Returns `object`.
3097 * Foo.prototype.c = 3;
3098 * Bar.prototype.e = 5;
3100 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
3101 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
3103 var assignIn = createAssigner(function(object, source) {
3104 copyObject(source, keysIn(source), object);
3108 * This method is like `_.assignIn` except that it accepts `customizer` which
3109 * is invoked to produce the assigned values. If `customizer` returns `undefined`
3110 * assignment is handled by the method instead. The `customizer` is invoked
3111 * with five arguments: (objValue, srcValue, key, object, source).
3113 * **Note:** This method mutates `object`.
3119 * @param {Object} object The destination object.
3120 * @param {...Object} sources The source objects.
3121 * @param {Function} [customizer] The function to customize assigned values.
3122 * @returns {Object} Returns `object`.
3125 * function customizer(objValue, srcValue) {
3126 * return _.isUndefined(objValue) ? srcValue : objValue;
3129 * var defaults = _.partialRight(_.assignInWith, customizer);
3131 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3132 * // => { 'a': 1, 'b': 2 }
3134 var assignInWith = createAssigner(function(object, source, customizer) {
3135 copyObjectWith(source, keysIn(source), object, customizer);
3139 * Creates an object that inherits from the `prototype` object. If a `properties`
3140 * object is provided its own enumerable properties are assigned to the created object.
3145 * @param {Object} prototype The object to inherit from.
3146 * @param {Object} [properties] The properties to assign to the object.
3147 * @returns {Object} Returns the new object.
3150 * function Shape() {
3155 * function Circle() {
3159 * Circle.prototype = _.create(Shape.prototype, {
3160 * 'constructor': Circle
3163 * var circle = new Circle;
3164 * circle instanceof Circle;
3167 * circle instanceof Shape;
3170 function create(prototype, properties) {
3171 var result = baseCreate(prototype);
3172 return properties ? assign(result, properties) : result;
3176 * Assigns own and inherited enumerable properties of source objects to the
3177 * destination object for all destination properties that resolve to `undefined`.
3178 * Source objects are applied from left to right. Once a property is set,
3179 * additional values of the same property are ignored.
3181 * **Note:** This method mutates `object`.
3186 * @param {Object} object The destination object.
3187 * @param {...Object} [sources] The source objects.
3188 * @returns {Object} Returns `object`.
3191 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
3192 * // => { 'user': 'barney', 'age': 36 }
3194 var defaults = rest(function(args) {
3195 args.push(undefined, assignInDefaults);
3196 return assignInWith.apply(undefined, args);
3200 * Checks if `path` is a direct property of `object`.
3205 * @param {Object} object The object to query.
3206 * @param {Array|string} path The path to check.
3207 * @returns {boolean} Returns `true` if `path` exists, else `false`.
3210 * var object = { 'a': { 'b': { 'c': 3 } } };
3211 * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
3213 * _.has(object, 'a');
3216 * _.has(object, 'a.b.c');
3219 * _.has(object, ['a', 'b', 'c']);
3222 * _.has(other, 'a');
3225 function has(object, path) {
3226 return object != null && hasOwnProperty.call(object, path);
3230 * Creates an array of the own enumerable property names of `object`.
3232 * **Note:** Non-object values are coerced to objects. See the
3233 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
3239 * @param {Object} object The object to query.
3240 * @returns {Array} Returns the array of property names.
3248 * Foo.prototype.c = 3;
3251 * // => ['a', 'b'] (iteration order is not guaranteed)
3256 function keys(object) {
3257 var isProto = isPrototype(object);
3258 if (!(isProto || isArrayLike(object))) {
3259 return baseKeys(object);
3261 var indexes = indexKeys(object),
3262 skipIndexes = !!indexes,
3263 result = indexes || [],
3264 length = result.length;
3266 for (var key in object) {
3267 if (hasOwnProperty.call(object, key) &&
3268 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3269 !(isProto && key == 'constructor')) {
3277 * Creates an array of the own and inherited enumerable property names of `object`.
3279 * **Note:** Non-object values are coerced to objects.
3284 * @param {Object} object The object to query.
3285 * @returns {Array} Returns the array of property names.
3293 * Foo.prototype.c = 3;
3295 * _.keysIn(new Foo);
3296 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3298 function keysIn(object) {
3300 isProto = isPrototype(object),
3301 props = baseKeysIn(object),
3302 propsLength = props.length,
3303 indexes = indexKeys(object),
3304 skipIndexes = !!indexes,
3305 result = indexes || [],
3306 length = result.length;
3308 while (++index < propsLength) {
3309 var key = props[index];
3310 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3311 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3319 * Creates an object composed of the picked `object` properties.
3324 * @param {Object} object The source object.
3325 * @param {...(string|string[])} [props] The property names to pick, specified
3326 * individually or in arrays.
3327 * @returns {Object} Returns the new object.
3330 * var object = { 'a': 1, 'b': '2', 'c': 3 };
3332 * _.pick(object, ['a', 'c']);
3333 * // => { 'a': 1, 'c': 3 }
3335 var pick = rest(function(object, props) {
3336 return object == null ? {} : basePick(object, baseFlatten(props));
3340 * This method is like `_.get` except that if the resolved value is a function
3341 * it's invoked with the `this` binding of its parent object and its result
3347 * @param {Object} object The object to query.
3348 * @param {Array|string} path The path of the property to resolve.
3349 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
3350 * @returns {*} Returns the resolved value.
3353 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3355 * _.result(object, 'a[0].b.c1');
3358 * _.result(object, 'a[0].b.c2');
3361 * _.result(object, 'a[0].b.c3', 'default');
3364 * _.result(object, 'a[0].b.c3', _.constant('default'));
3367 function result(object, path, defaultValue) {
3368 var value = object == null ? undefined : object[path];
3369 if (value === undefined) {
3370 value = defaultValue;
3372 return isFunction(value) ? value.call(object) : value;
3376 * Creates an array of the own enumerable property values of `object`.
3378 * **Note:** Non-object values are coerced to objects.
3383 * @param {Object} object The object to query.
3384 * @returns {Array} Returns the array of property values.
3392 * Foo.prototype.c = 3;
3394 * _.values(new Foo);
3395 * // => [1, 2] (iteration order is not guaranteed)
3400 function values(object) {
3401 return object ? baseValues(object, keys(object)) : [];
3404 /*------------------------------------------------------------------------*/
3407 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
3408 * their corresponding HTML entities.
3410 * **Note:** No other characters are escaped. To escape additional
3411 * characters use a third-party library like [_he_](https://mths.be/he).
3413 * Though the ">" character is escaped for symmetry, characters like
3414 * ">" and "/" don't need escaping in HTML and have no special meaning
3415 * unless they're part of a tag or unquoted attribute value.
3416 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3417 * (under "semi-related fun fact") for more details.
3419 * Backticks are escaped because in IE < 9, they can break out of
3420 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
3421 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
3422 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
3425 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
3426 * to reduce XSS vectors.
3431 * @param {string} [string=''] The string to escape.
3432 * @returns {string} Returns the escaped string.
3435 * _.escape('fred, barney, & pebbles');
3436 * // => 'fred, barney, & pebbles'
3438 function escape(string) {
3439 string = toString(string);
3440 return (string && reHasUnescapedHtml.test(string))
3441 ? string.replace(reUnescapedHtml, escapeHtmlChar)
3445 /*------------------------------------------------------------------------*/
3448 * This method returns the first argument provided to it.
3453 * @param {*} value Any value.
3454 * @returns {*} Returns `value`.
3457 * var object = { 'user': 'fred' };
3459 * _.identity(object) === object;
3462 function identity(value) {
3467 * Creates a function that invokes `func` with the arguments of the created
3468 * function. If `func` is a property name the created callback returns the
3469 * property value for a given element. If `func` is an object the created
3470 * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`.
3475 * @param {*} [func=_.identity] The value to convert to a callback.
3476 * @returns {Function} Returns the callback.
3480 * { 'user': 'barney', 'age': 36 },
3481 * { 'user': 'fred', 'age': 40 }
3484 * // create custom iteratee shorthands
3485 * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
3486 * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
3487 * return !p ? callback(func) : function(object) {
3488 * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
3492 * _.filter(users, 'age > 36');
3493 * // => [{ 'user': 'fred', 'age': 40 }]
3495 var iteratee = baseIteratee;
3498 * Adds all own enumerable function properties of a source object to the
3499 * destination object. If `object` is a function then methods are added to
3500 * its prototype as well.
3502 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3503 * avoid conflicts caused by modifying the original.
3508 * @param {Function|Object} [object=lodash] The destination object.
3509 * @param {Object} source The object of functions to add.
3510 * @param {Object} [options] The options object.
3511 * @param {boolean} [options.chain=true] Specify whether the functions added
3513 * @returns {Function|Object} Returns `object`.
3516 * function vowels(string) {
3517 * return _.filter(string, function(v) {
3518 * return /[aeiou]/i.test(v);
3522 * _.mixin({ 'vowels': vowels });
3526 * _('fred').vowels().value();
3529 * _.mixin({ 'vowels': vowels }, { 'chain': false });
3530 * _('fred').vowels();
3533 function mixin(object, source, options) {
3534 var props = keys(source),
3535 methodNames = baseFunctions(source, props);
3537 if (options == null &&
3538 !(isObject(source) && (methodNames.length || !props.length))) {
3542 methodNames = baseFunctions(source, keys(source));
3544 var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
3545 isFunc = isFunction(object);
3547 baseEach(methodNames, function(methodName) {
3548 var func = source[methodName];
3549 object[methodName] = func;
3551 object.prototype[methodName] = function() {
3552 var chainAll = this.__chain__;
3553 if (chain || chainAll) {
3554 var result = object(this.__wrapped__),
3555 actions = result.__actions__ = copyArray(this.__actions__);
3557 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3558 result.__chain__ = chainAll;
3561 return func.apply(object, arrayPush([this.value()], arguments));
3570 * Reverts the `_` variable to its previous value and returns a reference to
3571 * the `lodash` function.
3576 * @returns {Function} Returns the `lodash` function.
3579 * var lodash = _.noConflict();
3581 function noConflict() {
3587 * A no-operation function that returns `undefined` regardless of the
3588 * arguments it receives.
3595 * var object = { 'user': 'fred' };
3597 * _.noop(object) === undefined;
3601 // No operation performed.
3605 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
3610 * @param {string} [prefix] The value to prefix the ID with.
3611 * @returns {string} Returns the unique ID.
3614 * _.uniqueId('contact_');
3615 * // => 'contact_104'
3620 function uniqueId(prefix) {
3621 var id = ++idCounter;
3622 return toString(prefix) + id;
3625 /*------------------------------------------------------------------------*/
3628 * Computes the maximum value of `array`. If `array` is empty or falsey
3629 * `undefined` is returned.
3634 * @param {Array} array The array to iterate over.
3635 * @returns {*} Returns the maximum value.
3638 * _.max([4, 2, 8, 6]);
3644 function max(array) {
3645 return (array && array.length)
3646 ? baseExtremum(array, identity, gt)
3651 * Computes the minimum value of `array`. If `array` is empty or falsey
3652 * `undefined` is returned.
3657 * @param {Array} array The array to iterate over.
3658 * @returns {*} Returns the minimum value.
3661 * _.min([4, 2, 8, 6]);
3667 function min(array) {
3668 return (array && array.length)
3669 ? baseExtremum(array, identity, lt)
3673 /*------------------------------------------------------------------------*/
3675 LodashWrapper.prototype = baseCreate(lodash.prototype);
3676 LodashWrapper.prototype.constructor = LodashWrapper;
3678 // Add functions that return wrapped values when chaining.
3679 lodash.assignIn = assignIn;
3680 lodash.before = before;
3682 lodash.chain = chain;
3683 lodash.compact = compact;
3684 lodash.concat = concat;
3685 lodash.create = create;
3686 lodash.defaults = defaults;
3687 lodash.defer = defer;
3688 lodash.delay = delay;
3689 lodash.filter = filter;
3690 lodash.flatten = flatten;
3691 lodash.flattenDeep = flattenDeep;
3692 lodash.invokeMap = invokeMap;
3693 lodash.iteratee = iteratee;
3696 lodash.mixin = mixin;
3697 lodash.negate = negate;
3700 lodash.slice = slice;
3701 lodash.sortBy = sortBy;
3704 lodash.toArray = toArray;
3705 lodash.values = values;
3708 lodash.each = forEach;
3709 lodash.extend = assignIn;
3711 // Add functions to `lodash.prototype`.
3712 mixin(lodash, lodash);
3714 /*------------------------------------------------------------------------*/
3716 // Add functions that return unwrapped values when chaining.
3717 lodash.clone = clone;
3718 lodash.escape = escape;
3719 lodash.every = every;
3721 lodash.forEach = forEach;
3724 lodash.identity = identity;
3725 lodash.indexOf = indexOf;
3726 lodash.isArguments = isArguments;
3727 lodash.isArray = isArray;
3728 lodash.isBoolean = isBoolean;
3729 lodash.isDate = isDate;
3730 lodash.isEmpty = isEmpty;
3731 lodash.isEqual = isEqual;
3732 lodash.isFinite = isFinite;
3733 lodash.isFunction = isFunction;
3734 lodash.isNaN = isNaN;
3735 lodash.isNull = isNull;
3736 lodash.isNumber = isNumber;
3737 lodash.isObject = isObject;
3738 lodash.isRegExp = isRegExp;
3739 lodash.isString = isString;
3740 lodash.isUndefined = isUndefined;
3744 lodash.noConflict = noConflict;
3747 lodash.reduce = reduce;
3748 lodash.result = result;
3751 lodash.uniqueId = uniqueId;
3754 lodash.first = head;
3756 mixin(lodash, (function() {
3758 baseForOwn(lodash, function(func, methodName) {
3759 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3760 source[methodName] = func;
3764 }()), { 'chain': false });
3766 /*------------------------------------------------------------------------*/
3769 * The semantic version number.
3775 lodash.VERSION = VERSION;
3777 // Add `Array` and `String` methods to `lodash.prototype`.
3778 baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3779 var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3780 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3781 retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3783 lodash.prototype[methodName] = function() {
3784 var args = arguments;
3785 if (retUnwrapped && !this.__chain__) {
3786 return func.apply(this.value(), args);
3788 return this[chainName](function(value) {
3789 return func.apply(value, args);
3794 // Add chaining functions to the `lodash` wrapper.
3795 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3797 /*--------------------------------------------------------------------------*/
3799 // Expose lodash on the free variable `window` or `self` when available. This
3800 // prevents errors in cases where lodash is loaded by a script tag in the presence
3801 // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
3802 (freeWindow || freeSelf || {})._ = lodash;
3804 // Some AMD build optimizers like r.js check for condition patterns like the following:
3805 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3806 // Define as an anonymous module so, through path mapping, it can be
3807 // referenced as the "underscore" module.
3812 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
3813 else if (freeExports && freeModule) {
3814 // Export for Node.js.
3815 if (moduleExports) {
3816 (freeModule.exports = lodash)._ = lodash;
3818 // Export for CommonJS support.
3819 freeExports._ = lodash;
3822 // Export to the global object.