3 * lodash 4.5.1 (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.5.1';
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. */
31 MAX_SAFE_INTEGER = 9007199254740991;
33 /** `Object#toString` result references. */
34 var argsTag = '[object Arguments]',
35 arrayTag = '[object Array]',
36 boolTag = '[object Boolean]',
37 dateTag = '[object Date]',
38 errorTag = '[object Error]',
39 funcTag = '[object Function]',
40 genTag = '[object GeneratorFunction]',
41 numberTag = '[object Number]',
42 objectTag = '[object Object]',
43 regexpTag = '[object RegExp]',
44 stringTag = '[object String]';
46 /** Used to match HTML entities and HTML characters. */
47 var reUnescapedHtml = /[&<>"'`]/g,
48 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
50 /** Used to detect unsigned integer values. */
51 var reIsUint = /^(?:0|[1-9]\d*)$/;
53 /** Used to map characters to HTML entities. */
63 /** Used to determine if values are of the language type `Object`. */
69 /** Detect free variable `exports`. */
70 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
74 /** Detect free variable `module`. */
75 var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
79 /** Detect the popular CommonJS extension `module.exports`. */
80 var moduleExports = (freeModule && freeModule.exports === freeExports)
84 /** Detect free variable `global` from Node.js. */
85 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
87 /** Detect free variable `self`. */
88 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
90 /** Detect free variable `window`. */
91 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
93 /** Detect `this` as the global object. */
94 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
97 * Used as a reference to the global object.
99 * The `this` value is used if it's the global object to avoid Greasemonkey's
100 * restricted `window` object, otherwise the `window` object is used.
102 var root = freeGlobal ||
103 ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
104 freeSelf || thisGlobal || Function('return this')();
106 /*--------------------------------------------------------------------------*/
109 * Creates a new array concatenating `array` with `other`.
112 * @param {Array} array The first array to concatenate.
113 * @param {Array} other The second array to concatenate.
114 * @returns {Array} Returns the new concatenated array.
116 function arrayConcat(array, other) {
117 return arrayPush(copyArray(array), values);
121 * Appends the elements of `values` to `array`.
124 * @param {Array} array The array to modify.
125 * @param {Array} values The values to append.
126 * @returns {Array} Returns `array`.
128 function arrayPush(array, values) {
130 length = values.length,
131 offset = array.length;
133 while (++index < length) {
134 array[offset + index] = values[index];
140 * The base implementation of methods like `_.max` and `_.min` which accepts a
141 * `comparator` to determine the extremum value.
144 * @param {Array} array The array to iterate over.
145 * @param {Function} iteratee The iteratee invoked per iteration.
146 * @param {Function} comparator The comparator used to compare values.
147 * @returns {*} Returns the extremum value.
149 function baseExtremum(array, iteratee, comparator) {
151 length = array.length;
153 while (++index < length) {
154 var value = array[index],
155 current = iteratee(value);
157 if (current != null && (computed === undefined
158 ? current === current
159 : comparator(current, computed)
161 var computed = current,
169 * The base implementation of methods like `_.find` and `_.findKey`, without
170 * support for iteratee shorthands, which iterates over `collection` using
174 * @param {Array|Object} collection The collection to search.
175 * @param {Function} predicate The function invoked per iteration.
176 * @param {Function} eachFunc The function to iterate over `collection`.
177 * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
178 * @returns {*} Returns the found element or its key, else `undefined`.
180 function baseFind(collection, predicate, eachFunc, retKey) {
182 eachFunc(collection, function(value, key, collection) {
183 if (predicate(value, key, collection)) {
184 result = retKey ? key : value;
192 * The base implementation of `_.reduce` and `_.reduceRight`, without support
193 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
196 * @param {Array|Object} collection The collection to iterate over.
197 * @param {Function} iteratee The function invoked per iteration.
198 * @param {*} accumulator The initial value.
199 * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value.
200 * @param {Function} eachFunc The function to iterate over `collection`.
201 * @returns {*} Returns the accumulated value.
203 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
204 eachFunc(collection, function(value, index, collection) {
205 accumulator = initAccum
206 ? (initAccum = false, value)
207 : iteratee(accumulator, value, index, collection);
213 * The base implementation of `_.times` without support for iteratee shorthands
214 * or max array length checks.
217 * @param {number} n The number of times to invoke `iteratee`.
218 * @param {Function} iteratee The function invoked per iteration.
219 * @returns {Array} Returns the array of results.
221 function baseTimes(n, iteratee) {
225 while (++index < n) {
226 result[index] = iteratee(index);
232 * The base implementation of `_.values` and `_.valuesIn` which creates an
233 * array of `object` property values corresponding to the property names
237 * @param {Object} object The object to query.
238 * @param {Array} props The property names to get values for.
239 * @returns {Object} Returns the array of property values.
241 function baseValues(object, props) {
242 return baseMap(props, function(key) {
248 * Checks if `value` is a global object.
251 * @param {*} value The value to check.
252 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
254 function checkGlobal(value) {
255 return (value && value.Object === Object) ? value : null;
259 * Compares values to sort them in ascending order.
262 * @param {*} value The value to compare.
263 * @param {*} other The other value to compare.
264 * @returns {number} Returns the sort order indicator for `value`.
266 function compareAscending(value, other) {
267 if (value !== other) {
268 var valIsNull = value === null,
269 valIsUndef = value === undefined,
270 valIsReflexive = value === value;
272 var othIsNull = other === null,
273 othIsUndef = other === undefined,
274 othIsReflexive = other === other;
276 if ((value > other && !othIsNull) || !valIsReflexive ||
277 (valIsNull && !othIsUndef && othIsReflexive) ||
278 (valIsUndef && othIsReflexive)) {
281 if ((value < other && !valIsNull) || !othIsReflexive ||
282 (othIsNull && !valIsUndef && valIsReflexive) ||
283 (othIsUndef && valIsReflexive)) {
291 * Used by `_.escape` to convert characters to HTML entities.
294 * @param {string} chr The matched character to escape.
295 * @returns {string} Returns the escaped character.
297 function escapeHtmlChar(chr) {
298 return htmlEscapes[chr];
302 * Checks if `value` is a host object in IE < 9.
305 * @param {*} value The value to check.
306 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
308 function isHostObject(value) {
309 // Many host objects are `Object` objects that can coerce to strings
310 // despite having improperly defined `toString` methods.
312 if (value != null && typeof value.toString != 'function') {
314 result = !!(value + '');
321 * Checks if `value` is a valid array-like index.
324 * @param {*} value The value to check.
325 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
326 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
328 function isIndex(value, length) {
329 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
330 length = length == null ? MAX_SAFE_INTEGER : length;
331 return value > -1 && value % 1 == 0 && value < length;
335 * Converts `iterator` to an array.
338 * @param {Object} iterator The iterator to convert.
339 * @returns {Array} Returns the converted array.
341 function iteratorToArray(iterator) {
345 while (!(data = iterator.next()).done) {
346 result.push(data.value);
351 /*--------------------------------------------------------------------------*/
353 /** Used for built-in method references. */
354 var arrayProto = Array.prototype,
355 objectProto = Object.prototype;
357 /** Used to check objects for own properties. */
358 var hasOwnProperty = objectProto.hasOwnProperty;
360 /** Used to generate unique IDs. */
364 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
367 var objectToString = objectProto.toString;
369 /** Used to restore the original `_` reference in `_.noConflict`. */
370 var oldDash = root._;
372 /** Built-in value references. */
373 var Reflect = root.Reflect,
374 Symbol = root.Symbol,
375 Uint8Array = root.Uint8Array,
376 enumerate = Reflect ? Reflect.enumerate : undefined,
377 objectCreate = Object.create,
378 propertyIsEnumerable = objectProto.propertyIsEnumerable;
380 /* Built-in method references for those with the same name as other `lodash` methods. */
381 var nativeIsFinite = root.isFinite,
382 nativeKeys = Object.keys,
383 nativeMax = Math.max;
385 /*------------------------------------------------------------------------*/
388 * Creates a `lodash` object which wraps `value` to enable implicit method
389 * chaining. Methods that operate on and return arrays, collections, and
390 * functions can be chained together. Methods that retrieve a single value or
391 * may return a primitive value will automatically end the chain sequence and
392 * return the unwrapped value. Otherwise, the value must be unwrapped with
395 * Explicit chaining, which must be unwrapped with `_#value` in all cases,
396 * may be enabled using `_.chain`.
398 * The execution of chained methods is lazy, that is, it's deferred until
399 * `_#value` is implicitly or explicitly called.
401 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
402 * fusion is an optimization to merge iteratee calls; this avoids the creation
403 * of intermediate arrays and can greatly reduce the number of iteratee executions.
404 * Sections of a chain sequence qualify for shortcut fusion if the section is
405 * applied to an array of at least two hundred elements and any iteratees
406 * accept only one argument. The heuristic for whether a section qualifies
407 * for shortcut fusion is subject to change.
409 * Chaining is supported in custom builds as long as the `_#value` method is
410 * directly or indirectly included in the build.
412 * In addition to lodash methods, wrappers have `Array` and `String` methods.
414 * The wrapper `Array` methods are:
415 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
417 * The wrapper `String` methods are:
418 * `replace` and `split`
420 * The wrapper methods that support shortcut fusion are:
421 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
422 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
423 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
425 * The chainable wrapper methods are:
426 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
427 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
428 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
429 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
430 * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
431 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flattenDepth`,
432 * `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, `functionsIn`,
433 * `groupBy`, `initial`, `intersection`, `intersectionBy`, `intersectionWith`,
434 * `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`,
435 * `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, `memoize`,
436 * `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, `nthArg`,
437 * `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, `overEvery`,
438 * `overSome`, `partial`, `partialRight`, `partition`, `pick`, `pickBy`, `plant`,
439 * `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`,
440 * `range`, `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
441 * `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`,
442 * `splice`, `spread`, `tail`, `take`, `takeRight`, `takeRightWhile`,
443 * `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, `toPairs`, `toPairsIn`,
444 * `toPath`, `toPlainObject`, `transform`, `unary`, `union`, `unionBy`,
445 * `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, `unshift`, `unzip`,
446 * `unzipWith`, `values`, `valuesIn`, `without`, `wrap`, `xor`, `xorBy`,
447 * `xorWith`, `zip`, `zipObject`, `zipObjectDeep`, and `zipWith`
449 * The wrapper methods that are **not** chainable by default are:
450 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
451 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
452 * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
453 * `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`, `forIn`,
454 * `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`,
455 * `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`,
456 * `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
457 * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
458 * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`,
459 * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
460 * `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
461 * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`,
462 * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`,
463 * `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`, `noConflict`, `noop`,
464 * `now`, `pad`, `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`,
465 * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `sample`,
466 * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`,
467 * `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, `startsWith`, `subtract`,
468 * `sum`, `sumBy`, `template`, `times`, `toLower`, `toInteger`, `toLength`,
469 * `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, `trimEnd`,
470 * `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, `upperFirst`,
471 * `value`, and `words`
476 * @param {*} value The value to wrap in a `lodash` instance.
477 * @returns {Object} Returns the new `lodash` wrapper instance.
480 * function square(n) {
484 * var wrapped = _([1, 2, 3]);
486 * // Returns an unwrapped value.
487 * wrapped.reduce(_.add);
490 * // Returns a wrapped value.
491 * var squares = wrapped.map(square);
493 * _.isArray(squares);
496 * _.isArray(squares.value());
499 function lodash(value) {
500 if (isObjectLike(value) && !isArray(value)) {
501 if (value instanceof LodashWrapper) {
504 if (hasOwnProperty.call(value, '__wrapped__')) {
505 return wrapperClone(value);
508 return new LodashWrapper(value);
512 * The base constructor for creating `lodash` wrapper objects.
515 * @param {*} value The value to wrap.
516 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
518 function LodashWrapper(value, chainAll) {
519 this.__wrapped__ = value;
520 this.__actions__ = [];
521 this.__chain__ = !!chainAll;
524 /*------------------------------------------------------------------------*/
527 * Used by `_.defaults` to customize its `_.assignIn` use.
530 * @param {*} objValue The destination value.
531 * @param {*} srcValue The source value.
532 * @param {string} key The key of the property to assign.
533 * @param {Object} object The parent object of `objValue`.
534 * @returns {*} Returns the value to assign.
536 function assignInDefaults(objValue, srcValue, key, object) {
537 if (objValue === undefined ||
538 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
545 * Assigns `value` to `key` of `object` if the existing value is not equivalent
546 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
547 * for equality comparisons.
550 * @param {Object} object The object to modify.
551 * @param {string} key The key of the property to assign.
552 * @param {*} value The value to assign.
554 function assignValue(object, key, value) {
555 var objValue = object[key];
556 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
557 (value === undefined && !(key in object))) {
563 * Casts `value` to `identity` if it's not a function.
566 * @param {*} value The value to inspect.
567 * @returns {Array} Returns the array-like object.
569 function baseCastFunction(value) {
570 return typeof value == 'function' ? value : identity;
574 * The base implementation of `_.create` without support for assigning
575 * properties to the created object.
578 * @param {Object} prototype The object to inherit from.
579 * @returns {Object} Returns the new object.
581 function baseCreate(proto) {
582 return isObject(proto) ? objectCreate(proto) : {};
586 * The base implementation of `_.delay` and `_.defer` which accepts an array
587 * of `func` arguments.
590 * @param {Function} func The function to delay.
591 * @param {number} wait The number of milliseconds to delay invocation.
592 * @param {Object} args The arguments to provide to `func`.
593 * @returns {number} Returns the timer id.
595 function baseDelay(func, wait, args) {
596 if (typeof func != 'function') {
597 throw new TypeError(FUNC_ERROR_TEXT);
599 return setTimeout(function() { func.apply(undefined, args); }, wait);
603 * The base implementation of `_.forEach` without support for iteratee shorthands.
606 * @param {Array|Object} collection The collection to iterate over.
607 * @param {Function} iteratee The function invoked per iteration.
608 * @returns {Array|Object} Returns `collection`.
610 var baseEach = createBaseEach(baseForOwn);
613 * The base implementation of `_.every` without support for iteratee shorthands.
616 * @param {Array|Object} collection The collection to iterate over.
617 * @param {Function} predicate The function invoked per iteration.
618 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
620 function baseEvery(collection, predicate) {
622 baseEach(collection, function(value, index, collection) {
623 result = !!predicate(value, index, collection);
630 * The base implementation of `_.filter` without support for iteratee shorthands.
633 * @param {Array|Object} collection The collection to iterate over.
634 * @param {Function} predicate The function invoked per iteration.
635 * @returns {Array} Returns the new filtered array.
637 function baseFilter(collection, predicate) {
639 baseEach(collection, function(value, index, collection) {
640 if (predicate(value, index, collection)) {
648 * The base implementation of `_.flatten` with support for restricting flattening.
651 * @param {Array} array The array to flatten.
652 * @param {number} depth The maximum recursion depth.
653 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
654 * @param {Array} [result=[]] The initial result value.
655 * @returns {Array} Returns the new flattened array.
657 function baseFlatten(array, depth, isStrict, result) {
658 result || (result = []);
661 length = array.length;
663 while (++index < length) {
664 var value = array[index];
665 if (depth > 0 && isArrayLikeObject(value) &&
666 (isStrict || isArray(value) || isArguments(value))) {
668 // Recursively flatten arrays (susceptible to call stack limits).
669 baseFlatten(value, depth - 1, isStrict, result);
671 arrayPush(result, value);
673 } else if (!isStrict) {
674 result[result.length] = value;
681 * The base implementation of `baseForIn` and `baseForOwn` which iterates
682 * over `object` properties returned by `keysFunc` invoking `iteratee` for
683 * each property. Iteratee functions may exit iteration early by explicitly
687 * @param {Object} object The object to iterate over.
688 * @param {Function} iteratee The function invoked per iteration.
689 * @param {Function} keysFunc The function to get the keys of `object`.
690 * @returns {Object} Returns `object`.
692 var baseFor = createBaseFor();
695 * The base implementation of `_.forOwn` without support for iteratee shorthands.
698 * @param {Object} object The object to iterate over.
699 * @param {Function} iteratee The function invoked per iteration.
700 * @returns {Object} Returns `object`.
702 function baseForOwn(object, iteratee) {
703 return object && baseFor(object, iteratee, keys);
707 * The base implementation of `_.functions` which creates an array of
708 * `object` function property names filtered from `props`.
711 * @param {Object} object The object to inspect.
712 * @param {Array} props The property names to filter.
713 * @returns {Array} Returns the new array of filtered property names.
715 function baseFunctions(object, props) {
716 return baseFilter(props, function(key) {
717 return isFunction(object[key]);
722 * The base implementation of `_.isEqual` which supports partial comparisons
723 * and tracks traversed objects.
726 * @param {*} value The value to compare.
727 * @param {*} other The other value to compare.
728 * @param {Function} [customizer] The function to customize comparisons.
729 * @param {boolean} [bitmask] The bitmask of comparison flags.
730 * The bitmask may be composed of the following flags:
731 * 1 - Unordered comparison
732 * 2 - Partial comparison
733 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
734 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
736 function baseIsEqual(value, other, customizer, bitmask, stack) {
737 if (value === other) {
740 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
741 return value !== value && other !== other;
743 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
747 * A specialized version of `baseIsEqual` for arrays and objects which performs
748 * deep comparisons and tracks traversed objects enabling objects with circular
749 * references to be compared.
752 * @param {Object} object The object to compare.
753 * @param {Object} other The other object to compare.
754 * @param {Function} equalFunc The function to determine equivalents of values.
755 * @param {Function} [customizer] The function to customize comparisons.
756 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
757 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
758 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
760 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
761 var objIsArr = isArray(object),
762 othIsArr = isArray(other),
767 objTag = objectToString.call(object);
768 if (objTag == argsTag) {
773 othTag = objectToString.call(other);
774 if (othTag == argsTag) {
778 var objIsObj = objTag == objectTag && !isHostObject(object),
779 othIsObj = othTag == objectTag && !isHostObject(other),
780 isSameTag = objTag == othTag;
782 if (isSameTag && !(objIsArr || objIsObj)) {
783 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
785 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
787 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
788 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
790 if (objIsWrapped || othIsWrapped) {
791 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
797 stack || (stack = []);
798 var stacked = find(stack, function(entry) {
799 return entry[0] === object;
801 if (stacked && stacked[1]) {
802 return stacked[1] == other;
804 stack.push([object, other]);
805 var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
811 * The base implementation of `_.iteratee`.
814 * @param {*} [value=_.identity] The value to convert to an iteratee.
815 * @returns {Function} Returns the iteratee.
817 function baseIteratee(func) {
818 var type = typeof func;
819 if (type == 'function') {
824 : (type == 'object' ? baseMatches : baseProperty)(func);
828 * The base implementation of `_.keys` 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 baseKeys(object) {
836 return nativeKeys(Object(object));
840 * The base implementation of `_.keysIn` which doesn't skip the constructor
841 * property of prototypes or treat sparse arrays as dense.
844 * @param {Object} object The object to query.
845 * @returns {Array} Returns the array of property names.
847 function baseKeysIn(object) {
848 object = object == null ? object : Object(object);
851 for (var key in object) {
857 // Fallback for IE < 9 with es6-shim.
858 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
859 baseKeysIn = function(object) {
860 return iteratorToArray(enumerate(object));
865 * The base implementation of `_.map` without support for iteratee shorthands.
868 * @param {Array|Object} collection The collection to iterate over.
869 * @param {Function} iteratee The function invoked per iteration.
870 * @returns {Array} Returns the new mapped array.
872 function baseMap(collection, iteratee) {
874 result = isArrayLike(collection) ? Array(collection.length) : [];
876 baseEach(collection, function(value, key, collection) {
877 result[++index] = iteratee(value, key, collection);
883 * The base implementation of `_.matches` which doesn't clone `source`.
886 * @param {Object} source The object of property values to match.
887 * @returns {Function} Returns the new function.
889 function baseMatches(source) {
890 var props = keys(source);
891 return function(object) {
892 var length = props.length;
893 if (object == null) {
896 object = Object(object);
898 var key = props[length];
899 if (!(key in object &&
900 baseIsEqual(source[key], object[key], undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG)
910 * The base implementation of `_.pick` without support for individual
914 * @param {Object} object The source object.
915 * @param {string[]} props The property names to pick.
916 * @returns {Object} Returns the new object.
918 function basePick(object, props) {
919 object = Object(object);
920 return reduce(props, function(result, key) {
922 result[key] = object[key];
929 * The base implementation of `_.property` without support for deep paths.
932 * @param {string} key The key of the property to get.
933 * @returns {Function} Returns the new function.
935 function baseProperty(key) {
936 return function(object) {
937 return object == null ? undefined : object[key];
942 * The base implementation of `_.slice` without an iteratee call guard.
945 * @param {Array} array The array to slice.
946 * @param {number} [start=0] The start position.
947 * @param {number} [end=array.length] The end position.
948 * @returns {Array} Returns the slice of `array`.
950 function baseSlice(array, start, end) {
952 length = array.length;
955 start = -start > length ? 0 : (length + start);
957 end = end > length ? length : end;
961 length = start > end ? 0 : ((end - start) >>> 0);
964 var result = Array(length);
965 while (++index < length) {
966 result[index] = array[index + start];
972 * Copies the values of `source` to `array`.
975 * @param {Array} source The array to copy values from.
976 * @param {Array} [array=[]] The array to copy values to.
977 * @returns {Array} Returns `array`.
979 function copyArray(source) {
980 return baseSlice(source, 0, source.length);
984 * The base implementation of `_.some` without support for iteratee shorthands.
987 * @param {Array|Object} collection The collection to iterate over.
988 * @param {Function} predicate The function invoked per iteration.
989 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
991 function baseSome(collection, predicate) {
994 baseEach(collection, function(value, index, collection) {
995 result = predicate(value, index, collection);
1002 * The base implementation of `wrapperValue` which returns the result of
1003 * performing a sequence of actions on the unwrapped `value`, where each
1004 * successive action is supplied the return value of the previous.
1007 * @param {*} value The unwrapped value.
1008 * @param {Array} actions Actions to perform to resolve the unwrapped value.
1009 * @returns {*} Returns the resolved value.
1011 function baseWrapperValue(value, actions) {
1013 return reduce(actions, function(result, action) {
1014 return action.func.apply(action.thisArg, arrayPush([result], action.args));
1019 * Copies properties of `source` to `object`.
1022 * @param {Object} source The object to copy properties from.
1023 * @param {Array} props The property names to copy.
1024 * @param {Object} [object={}] The object to copy properties to.
1025 * @returns {Object} Returns `object`.
1027 var copyObject = copyObjectWith;
1030 * This function is like `copyObject` except that it accepts a function to
1031 * customize copied values.
1034 * @param {Object} source The object to copy properties from.
1035 * @param {Array} props The property names to copy.
1036 * @param {Object} [object={}] The object to copy properties to.
1037 * @param {Function} [customizer] The function to customize copied values.
1038 * @returns {Object} Returns `object`.
1040 function copyObjectWith(source, props, object, customizer) {
1041 object || (object = {});
1044 length = props.length;
1046 while (++index < length) {
1047 var key = props[index];
1049 var newValue = customizer
1050 ? customizer(object[key], source[key], key, object, source)
1053 assignValue(object, key, newValue);
1059 * Creates a function like `_.assign`.
1062 * @param {Function} assigner The function to assign values.
1063 * @returns {Function} Returns the new assigner function.
1065 function createAssigner(assigner) {
1066 return rest(function(object, sources) {
1068 length = sources.length,
1069 customizer = length > 1 ? sources[length - 1] : undefined;
1071 customizer = typeof customizer == 'function'
1072 ? (length--, customizer)
1075 object = Object(object);
1076 while (++index < length) {
1077 var source = sources[index];
1079 assigner(object, source, index, customizer);
1087 * Creates a `baseEach` or `baseEachRight` function.
1090 * @param {Function} eachFunc The function to iterate over a collection.
1091 * @param {boolean} [fromRight] Specify iterating from right to left.
1092 * @returns {Function} Returns the new base function.
1094 function createBaseEach(eachFunc, fromRight) {
1095 return function(collection, iteratee) {
1096 if (collection == null) {
1099 if (!isArrayLike(collection)) {
1100 return eachFunc(collection, iteratee);
1102 var length = collection.length,
1103 index = fromRight ? length : -1,
1104 iterable = Object(collection);
1106 while ((fromRight ? index-- : ++index < length)) {
1107 if (iteratee(iterable[index], index, iterable) === false) {
1116 * Creates a base function for methods like `_.forIn`.
1119 * @param {boolean} [fromRight] Specify iterating from right to left.
1120 * @returns {Function} Returns the new base function.
1122 function createBaseFor(fromRight) {
1123 return function(object, iteratee, keysFunc) {
1125 iterable = Object(object),
1126 props = keysFunc(object),
1127 length = props.length;
1130 var key = props[fromRight ? length : ++index];
1131 if (iteratee(iterable[key], key, iterable) === false) {
1140 * Creates a function that produces an instance of `Ctor` regardless of
1141 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
1144 * @param {Function} Ctor The constructor to wrap.
1145 * @returns {Function} Returns the new wrapped function.
1147 function createCtorWrapper(Ctor) {
1149 // Use a `switch` statement to work with class constructors.
1150 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1151 // for more details.
1152 var args = arguments;
1153 var thisBinding = baseCreate(Ctor.prototype),
1154 result = Ctor.apply(thisBinding, args);
1156 // Mimic the constructor's `return` behavior.
1157 // See https://es5.github.io/#x13.2.2 for more details.
1158 return isObject(result) ? result : thisBinding;
1163 * Creates a function that wraps `func` to invoke it with the optional `this`
1164 * binding of `thisArg` and the `partials` prepended to those provided to
1168 * @param {Function} func The function to wrap.
1169 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
1170 * @param {*} thisArg The `this` binding of `func`.
1171 * @param {Array} partials The arguments to prepend to those provided to the new function.
1172 * @returns {Function} Returns the new wrapped function.
1174 function createPartialWrapper(func, bitmask, thisArg, partials) {
1175 if (typeof func != 'function') {
1176 throw new TypeError(FUNC_ERROR_TEXT);
1178 var isBind = bitmask & BIND_FLAG,
1179 Ctor = createCtorWrapper(func);
1181 function wrapper() {
1183 argsLength = arguments.length,
1185 leftLength = partials.length,
1186 args = Array(leftLength + argsLength),
1187 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
1189 while (++leftIndex < leftLength) {
1190 args[leftIndex] = partials[leftIndex];
1192 while (argsLength--) {
1193 args[leftIndex++] = arguments[++argsIndex];
1195 return fn.apply(isBind ? thisArg : this, args);
1201 * A specialized version of `baseIsEqualDeep` for arrays with support for
1202 * partial deep comparisons.
1205 * @param {Array} array The array to compare.
1206 * @param {Array} other The other array to compare.
1207 * @param {Function} equalFunc The function to determine equivalents of values.
1208 * @param {Function} [customizer] The function to customize comparisons.
1209 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1210 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
1211 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1213 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
1215 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1216 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
1217 arrLength = array.length,
1218 othLength = other.length;
1220 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1225 // Ignore non-index properties.
1226 while (++index < arrLength) {
1227 var arrValue = array[index],
1228 othValue = other[index];
1231 if (compared !== undefined) {
1238 // Recursively compare arrays (susceptible to call stack limits).
1240 if (!baseSome(other, function(othValue) {
1241 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
1246 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
1255 * A specialized version of `baseIsEqualDeep` for comparing objects of
1256 * the same `toStringTag`.
1258 * **Note:** This function only supports comparing values with tags of
1259 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1262 * @param {Object} object The object to compare.
1263 * @param {Object} other The other object to compare.
1264 * @param {string} tag The `toStringTag` of the objects to compare.
1265 * @param {Function} equalFunc The function to determine equivalents of values.
1266 * @param {Function} [customizer] The function to customize comparisons.
1267 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1268 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1270 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
1275 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
1276 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
1277 return +object == +other;
1280 return object.name == other.name && object.message == other.message;
1283 // Treat `NaN` vs. `NaN` as equal.
1284 return (object != +object) ? other != +other : object == +other;
1288 // Coerce regexes to strings and treat strings primitives and string
1289 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
1290 return object == (other + '');
1297 * A specialized version of `baseIsEqualDeep` for objects with support for
1298 * partial deep comparisons.
1301 * @param {Object} object The object to compare.
1302 * @param {Object} other The other object to compare.
1303 * @param {Function} equalFunc The function to determine equivalents of values.
1304 * @param {Function} [customizer] The function to customize comparisons.
1305 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1306 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
1307 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1309 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
1310 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1311 objProps = keys(object),
1312 objLength = objProps.length,
1313 othProps = keys(other),
1314 othLength = othProps.length;
1316 if (objLength != othLength && !isPartial) {
1319 var index = objLength;
1321 var key = objProps[index];
1322 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1328 var skipCtor = isPartial;
1329 while (++index < objLength) {
1330 key = objProps[index];
1331 var objValue = object[key],
1332 othValue = other[key];
1335 // Recursively compare objects (susceptible to call stack limits).
1336 if (!(compared === undefined
1337 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
1343 skipCtor || (skipCtor = key == 'constructor');
1345 if (result && !skipCtor) {
1346 var objCtor = object.constructor,
1347 othCtor = other.constructor;
1349 // Non `Object` object instances with different constructors are not equal.
1350 if (objCtor != othCtor &&
1351 ('constructor' in object && 'constructor' in other) &&
1352 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1353 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1361 * Gets the "length" property value of `object`.
1363 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
1364 * that affects Safari on at least iOS 8.1-8.3 ARM64.
1367 * @param {Object} object The object to query.
1368 * @returns {*} Returns the "length" value.
1370 var getLength = baseProperty('length');
1373 * Creates an array of index keys for `object` values of arrays,
1374 * `arguments` objects, and strings, otherwise `null` is returned.
1377 * @param {Object} object The object to query.
1378 * @returns {Array|null} Returns index keys, else `null`.
1380 function indexKeys(object) {
1381 var length = object ? object.length : undefined;
1382 if (isLength(length) &&
1383 (isArray(object) || isString(object) || isArguments(object))) {
1384 return baseTimes(length, String);
1390 * Checks if `value` is likely a prototype object.
1393 * @param {*} value The value to check.
1394 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1396 function isPrototype(value) {
1397 var Ctor = value && value.constructor,
1398 proto = (isFunction(Ctor) && Ctor.prototype) || objectProto;
1400 return value === proto;
1404 * Creates a clone of `wrapper`.
1407 * @param {Object} wrapper The wrapper to clone.
1408 * @returns {Object} Returns the cloned wrapper.
1410 function wrapperClone(wrapper) {
1411 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
1412 result.__actions__ = copyArray(wrapper.__actions__);
1416 /*------------------------------------------------------------------------*/
1419 * Creates an array with all falsey values removed. The values `false`, `null`,
1420 * `0`, `""`, `undefined`, and `NaN` are falsey.
1425 * @param {Array} array The array to compact.
1426 * @returns {Array} Returns the new array of filtered values.
1429 * _.compact([0, 1, false, 2, '', 3]);
1432 function compact(array) {
1433 return baseFilter(array, Boolean);
1437 * Creates a new array concatenating `array` with any additional arrays
1443 * @param {Array} array The array to concatenate.
1444 * @param {...*} [values] The values to concatenate.
1445 * @returns {Array} Returns the new concatenated array.
1449 * var other = _.concat(array, 2, [3], [[4]]);
1451 * console.log(other);
1452 * // => [1, 2, 3, [4]]
1454 * console.log(array);
1457 var concat = rest(function(array, values) {
1458 if (!isArray(array)) {
1459 array = array == null ? [] : [Object(array)];
1461 values = baseFlatten(values, 1);
1462 return arrayConcat(array, values);
1466 * Flattens `array` a single level deep.
1471 * @param {Array} array The array to flatten.
1472 * @returns {Array} Returns the new flattened array.
1475 * _.flatten([1, [2, [3, [4]], 5]]);
1476 * // => [1, 2, [3, [4]], 5]
1478 function flatten(array) {
1479 var length = array ? array.length : 0;
1480 return length ? baseFlatten(array, 1) : [];
1484 * Recursively flattens `array`.
1489 * @param {Array} array The array to flatten.
1490 * @returns {Array} Returns the new flattened array.
1493 * _.flattenDeep([1, [2, [3, [4]], 5]]);
1494 * // => [1, 2, 3, 4, 5]
1496 function flattenDeep(array) {
1497 var length = array ? array.length : 0;
1498 return length ? baseFlatten(array, INFINITY) : [];
1502 * Gets the first element of `array`.
1508 * @param {Array} array The array to query.
1509 * @returns {*} Returns the first element of `array`.
1512 * _.head([1, 2, 3]);
1518 function head(array) {
1519 return array ? array[0] : undefined;
1523 * Gets the index at which the first occurrence of `value` is found in `array`
1524 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
1525 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
1526 * from the end of `array`.
1531 * @param {Array} array The array to search.
1532 * @param {*} value The value to search for.
1533 * @param {number} [fromIndex=0] The index to search from.
1534 * @returns {number} Returns the index of the matched value, else `-1`.
1537 * _.indexOf([1, 2, 1, 2], 2);
1540 * // Search from the `fromIndex`.
1541 * _.indexOf([1, 2, 1, 2], 2, 2);
1544 function indexOf(array, value, fromIndex) {
1545 var length = array ? array.length : 0;
1546 if (typeof fromIndex == 'number') {
1547 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1551 var index = (fromIndex || 0) - 1,
1552 isReflexive = value === value;
1554 while (++index < length) {
1555 var other = array[index];
1556 if ((isReflexive ? other === value : other !== other)) {
1564 * Gets the last element of `array`.
1569 * @param {Array} array The array to query.
1570 * @returns {*} Returns the last element of `array`.
1573 * _.last([1, 2, 3]);
1576 function last(array) {
1577 var length = array ? array.length : 0;
1578 return length ? array[length - 1] : undefined;
1582 * Creates a slice of `array` from `start` up to, but not including, `end`.
1584 * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
1585 * to ensure dense arrays are returned.
1590 * @param {Array} array The array to slice.
1591 * @param {number} [start=0] The start position.
1592 * @param {number} [end=array.length] The end position.
1593 * @returns {Array} Returns the slice of `array`.
1595 function slice(array, start, end) {
1596 var length = array ? array.length : 0;
1597 start = start == null ? 0 : +start;
1598 end = end === undefined ? length : +end;
1599 return length ? baseSlice(array, start, end) : [];
1602 /*------------------------------------------------------------------------*/
1605 * Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
1606 * The result of such method chaining must be unwrapped with `_#value`.
1611 * @param {*} value The value to wrap.
1612 * @returns {Object} Returns the new `lodash` wrapper instance.
1616 * { 'user': 'barney', 'age': 36 },
1617 * { 'user': 'fred', 'age': 40 },
1618 * { 'user': 'pebbles', 'age': 1 }
1624 * .map(function(o) {
1625 * return o.user + ' is ' + o.age;
1629 * // => 'pebbles is 1'
1631 function chain(value) {
1632 var result = lodash(value);
1633 result.__chain__ = true;
1638 * This method invokes `interceptor` and returns `value`. The interceptor
1639 * is invoked with one argument; (value). The purpose of this method is to
1640 * "tap into" a method chain in order to modify intermediate results.
1645 * @param {*} value The value to provide to `interceptor`.
1646 * @param {Function} interceptor The function to invoke.
1647 * @returns {*} Returns `value`.
1651 * .tap(function(array) {
1652 * // Mutate input array.
1659 function tap(value, interceptor) {
1665 * This method is like `_.tap` except that it returns the result of `interceptor`.
1666 * The purpose of this method is to "pass thru" values replacing intermediate
1667 * results in a method chain.
1672 * @param {*} value The value to provide to `interceptor`.
1673 * @param {Function} interceptor The function to invoke.
1674 * @returns {*} Returns the result of `interceptor`.
1680 * .thru(function(value) {
1686 function thru(value, interceptor) {
1687 return interceptor(value);
1691 * Enables explicit method chaining on the wrapper object.
1696 * @returns {Object} Returns the new `lodash` wrapper instance.
1700 * { 'user': 'barney', 'age': 36 },
1701 * { 'user': 'fred', 'age': 40 }
1704 * // A sequence without explicit chaining.
1706 * // => { 'user': 'barney', 'age': 36 }
1708 * // A sequence with explicit chaining.
1714 * // => { 'user': 'barney' }
1716 function wrapperChain() {
1721 * Executes the chained sequence to extract the unwrapped value.
1725 * @alias toJSON, valueOf
1727 * @returns {*} Returns the resolved unwrapped value.
1730 * _([1, 2, 3]).value();
1733 function wrapperValue() {
1734 return baseWrapperValue(this.__wrapped__, this.__actions__);
1737 /*------------------------------------------------------------------------*/
1740 * Checks if `predicate` returns truthy for **all** elements of `collection`.
1741 * Iteration is stopped once `predicate` returns falsey. The predicate is
1742 * invoked with three arguments: (value, index|key, collection).
1746 * @category Collection
1747 * @param {Array|Object} collection The collection to iterate over.
1748 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1749 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
1750 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
1753 * _.every([true, 1, null, 'yes'], Boolean);
1757 * { 'user': 'barney', 'active': false },
1758 * { 'user': 'fred', 'active': false }
1761 * // The `_.matches` iteratee shorthand.
1762 * _.every(users, { 'user': 'barney', 'active': false });
1765 * // The `_.matchesProperty` iteratee shorthand.
1766 * _.every(users, ['active', false]);
1769 * // The `_.property` iteratee shorthand.
1770 * _.every(users, 'active');
1773 function every(collection, predicate, guard) {
1774 predicate = guard ? undefined : predicate;
1775 return baseEvery(collection, baseIteratee(predicate));
1779 * Iterates over elements of `collection`, returning an array of all elements
1780 * `predicate` returns truthy for. The predicate is invoked with three arguments:
1781 * (value, index|key, collection).
1785 * @category Collection
1786 * @param {Array|Object} collection The collection to iterate over.
1787 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1788 * @returns {Array} Returns the new filtered array.
1792 * { 'user': 'barney', 'age': 36, 'active': true },
1793 * { 'user': 'fred', 'age': 40, 'active': false }
1796 * _.filter(users, function(o) { return !o.active; });
1797 * // => objects for ['fred']
1799 * // The `_.matches` iteratee shorthand.
1800 * _.filter(users, { 'age': 36, 'active': true });
1801 * // => objects for ['barney']
1803 * // The `_.matchesProperty` iteratee shorthand.
1804 * _.filter(users, ['active', false]);
1805 * // => objects for ['fred']
1807 * // The `_.property` iteratee shorthand.
1808 * _.filter(users, 'active');
1809 * // => objects for ['barney']
1811 function filter(collection, predicate) {
1812 return baseFilter(collection, baseIteratee(predicate));
1816 * Iterates over elements of `collection`, returning the first element
1817 * `predicate` returns truthy for. The predicate is invoked with three arguments:
1818 * (value, index|key, collection).
1822 * @category Collection
1823 * @param {Array|Object} collection The collection to search.
1824 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1825 * @returns {*} Returns the matched element, else `undefined`.
1829 * { 'user': 'barney', 'age': 36, 'active': true },
1830 * { 'user': 'fred', 'age': 40, 'active': false },
1831 * { 'user': 'pebbles', 'age': 1, 'active': true }
1834 * _.find(users, function(o) { return o.age < 40; });
1835 * // => object for 'barney'
1837 * // The `_.matches` iteratee shorthand.
1838 * _.find(users, { 'age': 1, 'active': true });
1839 * // => object for 'pebbles'
1841 * // The `_.matchesProperty` iteratee shorthand.
1842 * _.find(users, ['active', false]);
1843 * // => object for 'fred'
1845 * // The `_.property` iteratee shorthand.
1846 * _.find(users, 'active');
1847 * // => object for 'barney'
1849 function find(collection, predicate) {
1850 return baseFind(collection, baseIteratee(predicate), baseEach);
1854 * Iterates over elements of `collection` invoking `iteratee` for each element.
1855 * The iteratee is invoked with three arguments: (value, index|key, collection).
1856 * Iteratee functions may exit iteration early by explicitly returning `false`.
1858 * **Note:** As with other "Collections" methods, objects with a "length" property
1859 * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
1860 * for object iteration.
1865 * @category Collection
1866 * @param {Array|Object} collection The collection to iterate over.
1867 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1868 * @returns {Array|Object} Returns `collection`.
1871 * _([1, 2]).forEach(function(value) {
1872 * console.log(value);
1874 * // => logs `1` then `2`
1876 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
1879 * // => logs 'a' then 'b' (iteration order is not guaranteed)
1881 function forEach(collection, iteratee) {
1882 return baseEach(collection, baseCastFunction(iteratee));
1886 * Creates an array of values by running each element in `collection` through
1887 * `iteratee`. The iteratee is invoked with three arguments:
1888 * (value, index|key, collection).
1890 * Many lodash methods are guarded to work as iteratees for methods like
1891 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
1893 * The guarded methods are:
1894 * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
1895 * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
1896 * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
1901 * @category Collection
1902 * @param {Array|Object} collection The collection to iterate over.
1903 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
1904 * @returns {Array} Returns the new mapped array.
1907 * function square(n) {
1911 * _.map([4, 8], square);
1914 * _.map({ 'a': 4, 'b': 8 }, square);
1915 * // => [16, 64] (iteration order is not guaranteed)
1918 * { 'user': 'barney' },
1919 * { 'user': 'fred' }
1922 * // The `_.property` iteratee shorthand.
1923 * _.map(users, 'user');
1924 * // => ['barney', 'fred']
1926 function map(collection, iteratee) {
1927 return baseMap(collection, baseIteratee(iteratee));
1931 * Reduces `collection` to a value which is the accumulated result of running
1932 * each element in `collection` through `iteratee`, where each successive
1933 * invocation is supplied the return value of the previous. If `accumulator`
1934 * is not given the first element of `collection` is used as the initial
1935 * value. The iteratee is invoked with four arguments:
1936 * (accumulator, value, index|key, collection).
1938 * Many lodash methods are guarded to work as iteratees for methods like
1939 * `_.reduce`, `_.reduceRight`, and `_.transform`.
1941 * The guarded methods are:
1942 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
1947 * @category Collection
1948 * @param {Array|Object} collection The collection to iterate over.
1949 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1950 * @param {*} [accumulator] The initial value.
1951 * @returns {*} Returns the accumulated value.
1954 * _.reduce([1, 2], function(sum, n) {
1959 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
1960 * (result[value] || (result[value] = [])).push(key);
1963 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
1965 function reduce(collection, iteratee, accumulator) {
1966 return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
1970 * Gets the size of `collection` by returning its length for array-like
1971 * values or the number of own enumerable properties for objects.
1975 * @category Collection
1976 * @param {Array|Object} collection The collection to inspect.
1977 * @returns {number} Returns the collection size.
1980 * _.size([1, 2, 3]);
1983 * _.size({ 'a': 1, 'b': 2 });
1986 * _.size('pebbles');
1989 function size(collection) {
1990 if (collection == null) {
1993 collection = isArrayLike(collection) ? collection : keys(collection);
1994 return collection.length;
1998 * Checks if `predicate` returns truthy for **any** element of `collection`.
1999 * Iteration is stopped once `predicate` returns truthy. The predicate is
2000 * invoked with three arguments: (value, index|key, collection).
2004 * @category Collection
2005 * @param {Array|Object} collection The collection to iterate over.
2006 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
2007 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
2008 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
2011 * _.some([null, 0, 'yes', false], Boolean);
2015 * { 'user': 'barney', 'active': true },
2016 * { 'user': 'fred', 'active': false }
2019 * // The `_.matches` iteratee shorthand.
2020 * _.some(users, { 'user': 'barney', 'active': false });
2023 * // The `_.matchesProperty` iteratee shorthand.
2024 * _.some(users, ['active', false]);
2027 * // The `_.property` iteratee shorthand.
2028 * _.some(users, 'active');
2031 function some(collection, predicate, guard) {
2032 predicate = guard ? undefined : predicate;
2033 return baseSome(collection, baseIteratee(predicate));
2037 * Creates an array of elements, sorted in ascending order by the results of
2038 * running each element in a collection through each iteratee. This method
2039 * performs a stable sort, that is, it preserves the original sort order of
2040 * equal elements. The iteratees are invoked with one argument: (value).
2044 * @category Collection
2045 * @param {Array|Object} collection The collection to iterate over.
2046 * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
2047 * The iteratees to sort by, specified individually or in arrays.
2048 * @returns {Array} Returns the new sorted array.
2052 * { 'user': 'fred', 'age': 48 },
2053 * { 'user': 'barney', 'age': 36 },
2054 * { 'user': 'fred', 'age': 42 },
2055 * { 'user': 'barney', 'age': 34 }
2058 * _.sortBy(users, function(o) { return o.user; });
2059 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2061 * _.sortBy(users, ['user', 'age']);
2062 * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
2064 * _.sortBy(users, 'user', function(o) {
2065 * return Math.floor(o.age / 10);
2067 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2069 function sortBy(collection, iteratee) {
2071 iteratee = baseIteratee(iteratee);
2073 return baseMap(baseMap(collection, function(value, key, collection) {
2074 return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2075 }).sort(function(object, other) {
2076 return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2077 }), baseProperty('value'));
2080 /*------------------------------------------------------------------------*/
2083 * Creates a function that invokes `func`, with the `this` binding and arguments
2084 * of the created function, while it's called less than `n` times. Subsequent
2085 * calls to the created function return the result of the last `func` invocation.
2089 * @category Function
2090 * @param {number} n The number of calls at which `func` is no longer invoked.
2091 * @param {Function} func The function to restrict.
2092 * @returns {Function} Returns the new restricted function.
2095 * jQuery(element).on('click', _.before(5, addContactToList));
2096 * // => allows adding up to 4 contacts to the list
2098 function before(n, func) {
2100 if (typeof func != 'function') {
2101 throw new TypeError(FUNC_ERROR_TEXT);
2106 result = func.apply(this, arguments);
2116 * Creates a function that invokes `func` with the `this` binding of `thisArg`
2117 * and prepends any additional `_.bind` arguments to those provided to the
2120 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2121 * may be used as a placeholder for partially applied arguments.
2123 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
2124 * property of bound functions.
2128 * @category Function
2129 * @param {Function} func The function to bind.
2130 * @param {*} thisArg The `this` binding of `func`.
2131 * @param {...*} [partials] The arguments to be partially applied.
2132 * @returns {Function} Returns the new bound function.
2135 * var greet = function(greeting, punctuation) {
2136 * return greeting + ' ' + this.user + punctuation;
2139 * var object = { 'user': 'fred' };
2141 * var bound = _.bind(greet, object, 'hi');
2145 * // Bound with placeholders.
2146 * var bound = _.bind(greet, object, _, '!');
2150 var bind = rest(function(func, thisArg, partials) {
2151 return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
2155 * Defers invoking the `func` until the current call stack has cleared. Any
2156 * additional arguments are provided to `func` when it's invoked.
2160 * @category Function
2161 * @param {Function} func The function to defer.
2162 * @param {...*} [args] The arguments to invoke `func` with.
2163 * @returns {number} Returns the timer id.
2166 * _.defer(function(text) {
2167 * console.log(text);
2169 * // => logs 'deferred' after one or more milliseconds
2171 var defer = rest(function(func, args) {
2172 return baseDelay(func, 1, args);
2176 * Invokes `func` after `wait` milliseconds. Any additional arguments are
2177 * provided to `func` when it's invoked.
2181 * @category Function
2182 * @param {Function} func The function to delay.
2183 * @param {number} wait The number of milliseconds to delay invocation.
2184 * @param {...*} [args] The arguments to invoke `func` with.
2185 * @returns {number} Returns the timer id.
2188 * _.delay(function(text) {
2189 * console.log(text);
2190 * }, 1000, 'later');
2191 * // => logs 'later' after one second
2193 var delay = rest(function(func, wait, args) {
2194 return baseDelay(func, toNumber(wait) || 0, args);
2198 * Creates a function that negates the result of the predicate `func`. The
2199 * `func` predicate is invoked with the `this` binding and arguments of the
2204 * @category Function
2205 * @param {Function} predicate The predicate to negate.
2206 * @returns {Function} Returns the new function.
2209 * function isEven(n) {
2210 * return n % 2 == 0;
2213 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2216 function negate(predicate) {
2217 if (typeof predicate != 'function') {
2218 throw new TypeError(FUNC_ERROR_TEXT);
2221 return !predicate.apply(this, arguments);
2226 * Creates a function that is restricted to invoking `func` once. Repeat calls
2227 * to the function return the value of the first invocation. The `func` is
2228 * invoked with the `this` binding and arguments of the created function.
2232 * @category Function
2233 * @param {Function} func The function to restrict.
2234 * @returns {Function} Returns the new restricted function.
2237 * var initialize = _.once(createApplication);
2240 * // `initialize` invokes `createApplication` once
2242 function once(func) {
2243 return before(2, func);
2247 * Creates a function that invokes `func` with the `this` binding of the
2248 * created function and arguments from `start` and beyond provided as an array.
2250 * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
2254 * @category Function
2255 * @param {Function} func The function to apply a rest parameter to.
2256 * @param {number} [start=func.length-1] The start position of the rest parameter.
2257 * @returns {Function} Returns the new function.
2260 * var say = _.rest(function(what, names) {
2261 * return what + ' ' + _.initial(names).join(', ') +
2262 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
2265 * say('hello', 'fred', 'barney', 'pebbles');
2266 * // => 'hello fred, barney, & pebbles'
2268 function rest(func, start) {
2269 if (typeof func != 'function') {
2270 throw new TypeError(FUNC_ERROR_TEXT);
2272 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
2274 var args = arguments,
2276 length = nativeMax(args.length - start, 0),
2277 array = Array(length);
2279 while (++index < length) {
2280 array[index] = args[start + index];
2282 var otherArgs = Array(start + 1);
2284 while (++index < start) {
2285 otherArgs[index] = args[index];
2287 otherArgs[start] = array;
2288 return func.apply(this, otherArgs);
2292 /*------------------------------------------------------------------------*/
2295 * Creates a shallow clone of `value`.
2297 * **Note:** This method is loosely based on the
2298 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2299 * and supports cloning arrays, array buffers, booleans, date objects, maps,
2300 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2301 * arrays. The own enumerable properties of `arguments` objects are cloned
2302 * as plain objects. An empty object is returned for uncloneable values such
2303 * as error objects, functions, DOM nodes, and WeakMaps.
2308 * @param {*} value The value to clone.
2309 * @returns {*} Returns the cloned value.
2312 * var objects = [{ 'a': 1 }, { 'b': 2 }];
2314 * var shallow = _.clone(objects);
2315 * console.log(shallow[0] === objects[0]);
2318 function clone(value) {
2319 if (!isObject(value)) {
2322 return isArray(value) ? copyArray(value) : copyObject(value, keys(value));
2326 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2327 * comparison between two values to determine if they are equivalent.
2332 * @param {*} value The value to compare.
2333 * @param {*} other The other value to compare.
2334 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2337 * var object = { 'user': 'fred' };
2338 * var other = { 'user': 'fred' };
2340 * _.eq(object, object);
2343 * _.eq(object, other);
2349 * _.eq('a', Object('a'));
2355 function eq(value, other) {
2356 return value === other || (value !== value && other !== other);
2360 * Checks if `value` is greater than `other`.
2365 * @param {*} value The value to compare.
2366 * @param {*} other The other value to compare.
2367 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
2379 function gt(value, other) {
2380 return value > other;
2384 * Checks if `value` is likely an `arguments` object.
2389 * @param {*} value The value to check.
2390 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2393 * _.isArguments(function() { return arguments; }());
2396 * _.isArguments([1, 2, 3]);
2399 function isArguments(value) {
2400 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
2401 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
2402 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
2406 * Checks if `value` is classified as an `Array` object.
2412 * @param {*} value The value to check.
2413 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2416 * _.isArray([1, 2, 3]);
2419 * _.isArray(document.body.children);
2425 * _.isArray(_.noop);
2428 var isArray = Array.isArray;
2431 * Checks if `value` is array-like. A value is considered array-like if it's
2432 * not a function and has a `value.length` that's an integer greater than or
2433 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2438 * @param {*} value The value to check.
2439 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2442 * _.isArrayLike([1, 2, 3]);
2445 * _.isArrayLike(document.body.children);
2448 * _.isArrayLike('abc');
2451 * _.isArrayLike(_.noop);
2454 function isArrayLike(value) {
2455 return value != null &&
2456 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
2460 * This method is like `_.isArrayLike` except that it also checks if `value`
2466 * @param {*} value The value to check.
2467 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
2470 * _.isArrayLikeObject([1, 2, 3]);
2473 * _.isArrayLikeObject(document.body.children);
2476 * _.isArrayLikeObject('abc');
2479 * _.isArrayLikeObject(_.noop);
2482 function isArrayLikeObject(value) {
2483 return isObjectLike(value) && isArrayLike(value);
2487 * Checks if `value` is classified as a boolean primitive or object.
2492 * @param {*} value The value to check.
2493 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2496 * _.isBoolean(false);
2499 * _.isBoolean(null);
2502 function isBoolean(value) {
2503 return value === true || value === false ||
2504 (isObjectLike(value) && objectToString.call(value) == boolTag);
2508 * Checks if `value` is classified as a `Date` object.
2513 * @param {*} value The value to check.
2514 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2517 * _.isDate(new Date);
2520 * _.isDate('Mon April 23 2012');
2523 function isDate(value) {
2524 return isObjectLike(value) && objectToString.call(value) == dateTag;
2528 * Checks if `value` is empty. A value is considered empty unless it's an
2529 * `arguments` object, array, string, or jQuery-like collection with a length
2530 * greater than `0` or an object with own enumerable properties.
2535 * @param {Array|Object|string} value The value to inspect.
2536 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2548 * _.isEmpty([1, 2, 3]);
2551 * _.isEmpty({ 'a': 1 });
2554 function isEmpty(value) {
2555 if (isArrayLike(value) &&
2556 (isArray(value) || isString(value) ||
2557 isFunction(value.splice) || isArguments(value))) {
2558 return !value.length;
2560 for (var key in value) {
2561 if (hasOwnProperty.call(value, key)) {
2569 * Performs a deep comparison between two values to determine if they are
2572 * **Note:** This method supports comparing arrays, array buffers, booleans,
2573 * date objects, error objects, maps, numbers, `Object` objects, regexes,
2574 * sets, strings, symbols, and typed arrays. `Object` objects are compared
2575 * by their own, not inherited, enumerable properties. Functions and DOM
2576 * nodes are **not** supported.
2581 * @param {*} value The value to compare.
2582 * @param {*} other The other value to compare.
2583 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2586 * var object = { 'user': 'fred' };
2587 * var other = { 'user': 'fred' };
2589 * _.isEqual(object, other);
2595 function isEqual(value, other) {
2596 return baseIsEqual(value, other);
2600 * Checks if `value` is a finite primitive number.
2602 * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
2607 * @param {*} value The value to check.
2608 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
2614 * _.isFinite(Number.MAX_VALUE);
2620 * _.isFinite(Infinity);
2623 function isFinite(value) {
2624 return typeof value == 'number' && nativeIsFinite(value);
2628 * Checks if `value` is classified as a `Function` object.
2633 * @param {*} value The value to check.
2634 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2640 * _.isFunction(/abc/);
2643 function isFunction(value) {
2644 // The use of `Object#toString` avoids issues with the `typeof` operator
2645 // in Safari 8 which returns 'object' for typed array constructors, and
2646 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
2647 var tag = isObject(value) ? objectToString.call(value) : '';
2648 return tag == funcTag || tag == genTag;
2652 * Checks if `value` is a valid array-like length.
2654 * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
2659 * @param {*} value The value to check.
2660 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
2666 * _.isLength(Number.MIN_VALUE);
2669 * _.isLength(Infinity);
2675 function isLength(value) {
2676 return typeof value == 'number' &&
2677 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2681 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
2682 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2687 * @param {*} value The value to check.
2688 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2694 * _.isObject([1, 2, 3]);
2697 * _.isObject(_.noop);
2703 function isObject(value) {
2704 var type = typeof value;
2705 return !!value && (type == 'object' || type == 'function');
2709 * Checks if `value` is object-like. A value is object-like if it's not `null`
2710 * and has a `typeof` result of "object".
2715 * @param {*} value The value to check.
2716 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2719 * _.isObjectLike({});
2722 * _.isObjectLike([1, 2, 3]);
2725 * _.isObjectLike(_.noop);
2728 * _.isObjectLike(null);
2731 function isObjectLike(value) {
2732 return !!value && typeof value == 'object';
2736 * Checks if `value` is `NaN`.
2738 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
2739 * which returns `true` for `undefined` and other non-numeric values.
2744 * @param {*} value The value to check.
2745 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2751 * _.isNaN(new Number(NaN));
2757 * _.isNaN(undefined);
2760 function isNaN(value) {
2761 // An `NaN` primitive is the only value that is not equal to itself.
2762 // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
2763 return isNumber(value) && value != +value;
2767 * Checks if `value` is `null`.
2772 * @param {*} value The value to check.
2773 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2782 function isNull(value) {
2783 return value === null;
2787 * Checks if `value` is classified as a `Number` primitive or object.
2789 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
2790 * as numbers, use the `_.isFinite` method.
2795 * @param {*} value The value to check.
2796 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2802 * _.isNumber(Number.MIN_VALUE);
2805 * _.isNumber(Infinity);
2811 function isNumber(value) {
2812 return typeof value == 'number' ||
2813 (isObjectLike(value) && objectToString.call(value) == numberTag);
2817 * Checks if `value` is classified as a `RegExp` object.
2822 * @param {*} value The value to check.
2823 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2826 * _.isRegExp(/abc/);
2829 * _.isRegExp('/abc/');
2832 function isRegExp(value) {
2833 return isObject(value) && objectToString.call(value) == regexpTag;
2837 * Checks if `value` is classified as a `String` primitive or object.
2842 * @param {*} value The value to check.
2843 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2846 * _.isString('abc');
2852 function isString(value) {
2853 return typeof value == 'string' ||
2854 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
2858 * Checks if `value` is `undefined`.
2863 * @param {*} value The value to check.
2864 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
2867 * _.isUndefined(void 0);
2870 * _.isUndefined(null);
2873 function isUndefined(value) {
2874 return value === undefined;
2878 * Checks if `value` is less than `other`.
2883 * @param {*} value The value to compare.
2884 * @param {*} other The other value to compare.
2885 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
2897 function lt(value, other) {
2898 return value < other;
2902 * Converts `value` to an array.
2907 * @param {*} value The value to convert.
2908 * @returns {Array} Returns the converted array.
2911 * _.toArray({ 'a': 1, 'b': 2 });
2915 * // => ['a', 'b', 'c']
2923 function toArray(value) {
2924 if (!isArrayLike(value)) {
2925 return values(value);
2927 return value.length ? copyArray(value) : [];
2931 * Converts `value` to an integer.
2933 * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
2938 * @param {*} value The value to convert.
2939 * @returns {number} Returns the converted integer.
2945 * _.toInteger(Number.MIN_VALUE);
2948 * _.toInteger(Infinity);
2949 * // => 1.7976931348623157e+308
2954 var toInteger = Number;
2957 * Converts `value` to a number.
2962 * @param {*} value The value to process.
2963 * @returns {number} Returns the number.
2969 * _.toNumber(Number.MIN_VALUE);
2972 * _.toNumber(Infinity);
2978 var toNumber = Number;
2981 * Converts `value` to a string if it's not one. An empty string is returned
2982 * for `null` and `undefined` values. The sign of `-0` is preserved.
2987 * @param {*} value The value to process.
2988 * @returns {string} Returns the string.
2997 * _.toString([1, 2, 3]);
3000 function toString(value) {
3001 if (typeof value == 'string') {
3004 return value == null ? '' : (value + '');
3007 /*------------------------------------------------------------------------*/
3010 * Assigns own enumerable properties of source objects to the destination
3011 * object. Source objects are applied from left to right. Subsequent sources
3012 * overwrite property assignments of previous sources.
3014 * **Note:** This method mutates `object` and is loosely based on
3015 * [`Object.assign`](https://mdn.io/Object/assign).
3020 * @param {Object} object The destination object.
3021 * @param {...Object} [sources] The source objects.
3022 * @returns {Object} Returns `object`.
3033 * Foo.prototype.d = 4;
3034 * Bar.prototype.f = 6;
3036 * _.assign({ 'a': 1 }, new Foo, new Bar);
3037 * // => { 'a': 1, 'c': 3, 'e': 5 }
3039 var assign = createAssigner(function(object, source) {
3040 copyObject(source, keys(source), object);
3044 * This method is like `_.assign` except that it iterates over own and
3045 * inherited source properties.
3047 * **Note:** This method mutates `object`.
3053 * @param {Object} object The destination object.
3054 * @param {...Object} [sources] The source objects.
3055 * @returns {Object} Returns `object`.
3066 * Foo.prototype.c = 3;
3067 * Bar.prototype.e = 5;
3069 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
3070 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
3072 var assignIn = createAssigner(function(object, source) {
3073 copyObject(source, keysIn(source), object);
3077 * This method is like `_.assignIn` except that it accepts `customizer` which
3078 * is invoked to produce the assigned values. If `customizer` returns `undefined`
3079 * assignment is handled by the method instead. The `customizer` is invoked
3080 * with five arguments: (objValue, srcValue, key, object, source).
3082 * **Note:** This method mutates `object`.
3088 * @param {Object} object The destination object.
3089 * @param {...Object} sources The source objects.
3090 * @param {Function} [customizer] The function to customize assigned values.
3091 * @returns {Object} Returns `object`.
3094 * function customizer(objValue, srcValue) {
3095 * return _.isUndefined(objValue) ? srcValue : objValue;
3098 * var defaults = _.partialRight(_.assignInWith, customizer);
3100 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3101 * // => { 'a': 1, 'b': 2 }
3103 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
3104 copyObjectWith(source, keysIn(source), object, customizer);
3108 * Creates an object that inherits from the `prototype` object. If a `properties`
3109 * object is given its own enumerable properties are assigned to the created object.
3114 * @param {Object} prototype The object to inherit from.
3115 * @param {Object} [properties] The properties to assign to the object.
3116 * @returns {Object} Returns the new object.
3119 * function Shape() {
3124 * function Circle() {
3128 * Circle.prototype = _.create(Shape.prototype, {
3129 * 'constructor': Circle
3132 * var circle = new Circle;
3133 * circle instanceof Circle;
3136 * circle instanceof Shape;
3139 function create(prototype, properties) {
3140 var result = baseCreate(prototype);
3141 return properties ? assign(result, properties) : result;
3145 * Assigns own and inherited enumerable properties of source objects to the
3146 * destination object for all destination properties that resolve to `undefined`.
3147 * Source objects are applied from left to right. Once a property is set,
3148 * additional values of the same property are ignored.
3150 * **Note:** This method mutates `object`.
3155 * @param {Object} object The destination object.
3156 * @param {...Object} [sources] The source objects.
3157 * @returns {Object} Returns `object`.
3160 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
3161 * // => { 'user': 'barney', 'age': 36 }
3163 var defaults = rest(function(args) {
3164 args.push(undefined, assignInDefaults);
3165 return assignInWith.apply(undefined, args);
3169 * Checks if `path` is a direct property of `object`.
3174 * @param {Object} object The object to query.
3175 * @param {Array|string} path The path to check.
3176 * @returns {boolean} Returns `true` if `path` exists, else `false`.
3179 * var object = { 'a': { 'b': { 'c': 3 } } };
3180 * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
3182 * _.has(object, 'a');
3185 * _.has(object, 'a.b.c');
3188 * _.has(object, ['a', 'b', 'c']);
3191 * _.has(other, 'a');
3194 function has(object, path) {
3195 return object != null && hasOwnProperty.call(object, path);
3199 * Creates an array of the own enumerable property names of `object`.
3201 * **Note:** Non-object values are coerced to objects. See the
3202 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
3208 * @param {Object} object The object to query.
3209 * @returns {Array} Returns the array of property names.
3217 * Foo.prototype.c = 3;
3220 * // => ['a', 'b'] (iteration order is not guaranteed)
3225 function keys(object) {
3226 var isProto = isPrototype(object);
3227 if (!(isProto || isArrayLike(object))) {
3228 return baseKeys(object);
3230 var indexes = indexKeys(object),
3231 skipIndexes = !!indexes,
3232 result = indexes || [],
3233 length = result.length;
3235 for (var key in object) {
3236 if (hasOwnProperty.call(object, key) &&
3237 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3238 !(isProto && key == 'constructor')) {
3246 * Creates an array of the own and inherited enumerable property names of `object`.
3248 * **Note:** Non-object values are coerced to objects.
3253 * @param {Object} object The object to query.
3254 * @returns {Array} Returns the array of property names.
3262 * Foo.prototype.c = 3;
3264 * _.keysIn(new Foo);
3265 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3267 function keysIn(object) {
3269 isProto = isPrototype(object),
3270 props = baseKeysIn(object),
3271 propsLength = props.length,
3272 indexes = indexKeys(object),
3273 skipIndexes = !!indexes,
3274 result = indexes || [],
3275 length = result.length;
3277 while (++index < propsLength) {
3278 var key = props[index];
3279 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3280 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3288 * Creates an object composed of the picked `object` properties.
3293 * @param {Object} object The source object.
3294 * @param {...(string|string[])} [props] The property names to pick, specified
3295 * individually or in arrays.
3296 * @returns {Object} Returns the new object.
3299 * var object = { 'a': 1, 'b': '2', 'c': 3 };
3301 * _.pick(object, ['a', 'c']);
3302 * // => { 'a': 1, 'c': 3 }
3304 var pick = rest(function(object, props) {
3305 return object == null ? {} : basePick(object, baseFlatten(props, 1));
3309 * This method is like `_.get` except that if the resolved value is a function
3310 * it's invoked with the `this` binding of its parent object and its result
3316 * @param {Object} object The object to query.
3317 * @param {Array|string} path The path of the property to resolve.
3318 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
3319 * @returns {*} Returns the resolved value.
3322 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3324 * _.result(object, 'a[0].b.c1');
3327 * _.result(object, 'a[0].b.c2');
3330 * _.result(object, 'a[0].b.c3', 'default');
3333 * _.result(object, 'a[0].b.c3', _.constant('default'));
3336 function result(object, path, defaultValue) {
3337 var value = object == null ? undefined : object[path];
3338 if (value === undefined) {
3339 value = defaultValue;
3341 return isFunction(value) ? value.call(object) : value;
3345 * Creates an array of the own enumerable property values of `object`.
3347 * **Note:** Non-object values are coerced to objects.
3352 * @param {Object} object The object to query.
3353 * @returns {Array} Returns the array of property values.
3361 * Foo.prototype.c = 3;
3363 * _.values(new Foo);
3364 * // => [1, 2] (iteration order is not guaranteed)
3369 function values(object) {
3370 return object ? baseValues(object, keys(object)) : [];
3373 /*------------------------------------------------------------------------*/
3376 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
3377 * their corresponding HTML entities.
3379 * **Note:** No other characters are escaped. To escape additional
3380 * characters use a third-party library like [_he_](https://mths.be/he).
3382 * Though the ">" character is escaped for symmetry, characters like
3383 * ">" and "/" don't need escaping in HTML and have no special meaning
3384 * unless they're part of a tag or unquoted attribute value.
3385 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3386 * (under "semi-related fun fact") for more details.
3388 * Backticks are escaped because in IE < 9, they can break out of
3389 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
3390 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
3391 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
3394 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
3395 * to reduce XSS vectors.
3400 * @param {string} [string=''] The string to escape.
3401 * @returns {string} Returns the escaped string.
3404 * _.escape('fred, barney, & pebbles');
3405 * // => 'fred, barney, & pebbles'
3407 function escape(string) {
3408 string = toString(string);
3409 return (string && reHasUnescapedHtml.test(string))
3410 ? string.replace(reUnescapedHtml, escapeHtmlChar)
3414 /*------------------------------------------------------------------------*/
3417 * This method returns the first argument given to it.
3422 * @param {*} value Any value.
3423 * @returns {*} Returns `value`.
3426 * var object = { 'user': 'fred' };
3428 * _.identity(object) === object;
3431 function identity(value) {
3436 * Creates a function that invokes `func` with the arguments of the created
3437 * function. If `func` is a property name the created callback returns the
3438 * property value for a given element. If `func` is an object the created
3439 * callback returns `true` for elements that contain the equivalent object
3440 * properties, otherwise it returns `false`.
3445 * @param {*} [func=_.identity] The value to convert to a callback.
3446 * @returns {Function} Returns the callback.
3450 * { 'user': 'barney', 'age': 36 },
3451 * { 'user': 'fred', 'age': 40 }
3454 * // Create custom iteratee shorthands.
3455 * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
3456 * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
3457 * return !p ? callback(func) : function(object) {
3458 * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
3462 * _.filter(users, 'age > 36');
3463 * // => [{ 'user': 'fred', 'age': 40 }]
3465 var iteratee = baseIteratee;
3468 * Creates a function that performs a partial deep comparison between a given
3469 * object and `source`, returning `true` if the given object has equivalent
3470 * property values, else `false`. The created function is equivalent to
3471 * `_.isMatch` with a `source` partially applied.
3473 * **Note:** This method supports comparing the same values as `_.isEqual`.
3478 * @param {Object} source The object of property values to match.
3479 * @returns {Function} Returns the new function.
3483 * { 'user': 'barney', 'age': 36, 'active': true },
3484 * { 'user': 'fred', 'age': 40, 'active': false }
3487 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
3488 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
3490 function matches(source) {
3491 return baseMatches(assign({}, source));
3495 * Adds all own enumerable function properties of a source object to the
3496 * destination object. If `object` is a function then methods are added to
3497 * its prototype as well.
3499 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3500 * avoid conflicts caused by modifying the original.
3505 * @param {Function|Object} [object=lodash] The destination object.
3506 * @param {Object} source The object of functions to add.
3507 * @param {Object} [options] The options object.
3508 * @param {boolean} [options.chain=true] Specify whether the functions added
3510 * @returns {Function|Object} Returns `object`.
3513 * function vowels(string) {
3514 * return _.filter(string, function(v) {
3515 * return /[aeiou]/i.test(v);
3519 * _.mixin({ 'vowels': vowels });
3523 * _('fred').vowels().value();
3526 * _.mixin({ 'vowels': vowels }, { 'chain': false });
3527 * _('fred').vowels();
3530 function mixin(object, source, options) {
3531 var props = keys(source),
3532 methodNames = baseFunctions(source, props);
3534 if (options == null &&
3535 !(isObject(source) && (methodNames.length || !props.length))) {
3539 methodNames = baseFunctions(source, keys(source));
3541 var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
3542 isFunc = isFunction(object);
3544 baseEach(methodNames, function(methodName) {
3545 var func = source[methodName];
3546 object[methodName] = func;
3548 object.prototype[methodName] = function() {
3549 var chainAll = this.__chain__;
3550 if (chain || chainAll) {
3551 var result = object(this.__wrapped__),
3552 actions = result.__actions__ = copyArray(this.__actions__);
3554 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3555 result.__chain__ = chainAll;
3558 return func.apply(object, arrayPush([this.value()], arguments));
3567 * Reverts the `_` variable to its previous value and returns a reference to
3568 * the `lodash` function.
3573 * @returns {Function} Returns the `lodash` function.
3576 * var lodash = _.noConflict();
3578 function noConflict() {
3579 if (root._ === this) {
3586 * A no-operation function that returns `undefined` regardless of the
3587 * arguments it receives.
3594 * var object = { 'user': 'fred' };
3596 * _.noop(object) === undefined;
3600 // No operation performed.
3604 * Generates a unique ID. If `prefix` is given the ID is appended to it.
3609 * @param {string} [prefix=''] The value to prefix the ID with.
3610 * @returns {string} Returns the unique ID.
3613 * _.uniqueId('contact_');
3614 * // => 'contact_104'
3619 function uniqueId(prefix) {
3620 var id = ++idCounter;
3621 return toString(prefix) + id;
3624 /*------------------------------------------------------------------------*/
3627 * Computes the maximum value of `array`. If `array` is empty or falsey
3628 * `undefined` is returned.
3633 * @param {Array} array The array to iterate over.
3634 * @returns {*} Returns the maximum value.
3637 * _.max([4, 2, 8, 6]);
3643 function max(array) {
3644 return (array && array.length)
3645 ? baseExtremum(array, identity, gt)
3650 * Computes the minimum value of `array`. If `array` is empty or falsey
3651 * `undefined` is returned.
3656 * @param {Array} array The array to iterate over.
3657 * @returns {*} Returns the minimum value.
3660 * _.min([4, 2, 8, 6]);
3666 function min(array) {
3667 return (array && array.length)
3668 ? baseExtremum(array, identity, lt)
3672 /*------------------------------------------------------------------------*/
3674 LodashWrapper.prototype = baseCreate(lodash.prototype);
3675 LodashWrapper.prototype.constructor = LodashWrapper;
3677 // Add functions that return wrapped values when chaining.
3678 lodash.assignIn = assignIn;
3679 lodash.before = before;
3681 lodash.chain = chain;
3682 lodash.compact = compact;
3683 lodash.concat = concat;
3684 lodash.create = create;
3685 lodash.defaults = defaults;
3686 lodash.defer = defer;
3687 lodash.delay = delay;
3688 lodash.filter = filter;
3689 lodash.flatten = flatten;
3690 lodash.flattenDeep = flattenDeep;
3691 lodash.iteratee = iteratee;
3694 lodash.matches = matches;
3695 lodash.mixin = mixin;
3696 lodash.negate = negate;
3699 lodash.slice = slice;
3700 lodash.sortBy = sortBy;
3703 lodash.toArray = toArray;
3704 lodash.values = values;
3707 lodash.extend = assignIn;
3709 // Add functions to `lodash.prototype`.
3710 mixin(lodash, lodash);
3712 /*------------------------------------------------------------------------*/
3714 // Add functions that return unwrapped values when chaining.
3715 lodash.clone = clone;
3716 lodash.escape = escape;
3717 lodash.every = every;
3719 lodash.forEach = forEach;
3722 lodash.identity = identity;
3723 lodash.indexOf = indexOf;
3724 lodash.isArguments = isArguments;
3725 lodash.isArray = isArray;
3726 lodash.isBoolean = isBoolean;
3727 lodash.isDate = isDate;
3728 lodash.isEmpty = isEmpty;
3729 lodash.isEqual = isEqual;
3730 lodash.isFinite = isFinite;
3731 lodash.isFunction = isFunction;
3732 lodash.isNaN = isNaN;
3733 lodash.isNull = isNull;
3734 lodash.isNumber = isNumber;
3735 lodash.isObject = isObject;
3736 lodash.isRegExp = isRegExp;
3737 lodash.isString = isString;
3738 lodash.isUndefined = isUndefined;
3742 lodash.noConflict = noConflict;
3744 lodash.reduce = reduce;
3745 lodash.result = result;
3748 lodash.uniqueId = uniqueId;
3751 lodash.each = forEach;
3752 lodash.first = head;
3754 mixin(lodash, (function() {
3756 baseForOwn(lodash, function(func, methodName) {
3757 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3758 source[methodName] = func;
3762 }()), { 'chain': false });
3764 /*------------------------------------------------------------------------*/
3767 * The semantic version number.
3773 lodash.VERSION = VERSION;
3775 // Add `Array` and `String` methods to `lodash.prototype`.
3776 baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3777 var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3778 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3779 retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3781 lodash.prototype[methodName] = function() {
3782 var args = arguments;
3783 if (retUnwrapped && !this.__chain__) {
3784 return func.apply(this.value(), args);
3786 return this[chainName](function(value) {
3787 return func.apply(value, args);
3792 // Add chaining functions to the `lodash` wrapper.
3793 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3795 /*--------------------------------------------------------------------------*/
3797 // Expose lodash on the free variable `window` or `self` when available. This
3798 // prevents errors in cases where lodash is loaded by a script tag in the presence
3799 // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
3800 (freeWindow || freeSelf || {})._ = lodash;
3802 // Some AMD build optimizers like r.js check for condition patterns like the following:
3803 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3804 // Define as an anonymous module so, through path mapping, it can be
3805 // referenced as the "underscore" module.
3810 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
3811 else if (freeExports && freeModule) {
3812 // Export for Node.js.
3813 if (moduleExports) {
3814 (freeModule.exports = lodash)._ = lodash;
3816 // Export for CommonJS support.
3817 freeExports._ = lodash;
3820 // Export to the global object.