3 * lodash 4.3.0 (Custom Build) <https://lodash.com/>
4 * Build: `lodash core -o ./dist/lodash.core.js`
5 * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
15 /** Used as the semantic version number. */
16 var VERSION = '4.3.0';
18 /** Used to compose bitmasks for wrapper metadata. */
22 /** Used to compose bitmasks for comparison styles. */
23 var UNORDERED_COMPARE_FLAG = 1,
24 PARTIAL_COMPARE_FLAG = 2;
26 /** Used as the `TypeError` message for "Functions" methods. */
27 var FUNC_ERROR_TEXT = 'Expected a function';
29 /** Used as references for various `Number` constants. */
30 var MAX_SAFE_INTEGER = 9007199254740991;
32 /** `Object#toString` result references. */
33 var argsTag = '[object Arguments]',
34 arrayTag = '[object Array]',
35 boolTag = '[object Boolean]',
36 dateTag = '[object Date]',
37 errorTag = '[object Error]',
38 funcTag = '[object Function]',
39 genTag = '[object GeneratorFunction]',
40 numberTag = '[object Number]',
41 objectTag = '[object Object]',
42 regexpTag = '[object RegExp]',
43 stringTag = '[object String]';
45 /** Used to match HTML entities and HTML characters. */
46 var reUnescapedHtml = /[&<>"'`]/g,
47 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
49 /** Used to detect unsigned integer values. */
50 var reIsUint = /^(?:0|[1-9]\d*)$/;
52 /** Used to map characters to HTML entities. */
62 /** Used to determine if values are of the language type `Object`. */
68 /** Detect free variable `exports`. */
69 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
71 /** Detect free variable `module`. */
72 var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
74 /** Detect free variable `global` from Node.js. */
75 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
77 /** Detect free variable `self`. */
78 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
80 /** Detect free variable `window`. */
81 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
83 /** Detect the popular CommonJS extension `module.exports`. */
84 var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null;
86 /** Detect `this` as the global object. */
87 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
90 * Used as a reference to the global object.
92 * The `this` value is used if it's the global object to avoid Greasemonkey's
93 * restricted `window` object, otherwise the `window` object is used.
95 var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
97 /*--------------------------------------------------------------------------*/
100 * Creates a new array concatenating `array` with `other`.
103 * @param {Array} array The first array to concatenate.
104 * @param {Array} other The second array to concatenate.
105 * @returns {Array} Returns the new concatenated array.
107 function arrayConcat(array, other) {
108 return arrayPush(copyArray(array), values);
112 * Appends the elements of `values` to `array`.
115 * @param {Array} array The array to modify.
116 * @param {Array} values The values to append.
117 * @returns {Array} Returns `array`.
119 function arrayPush(array, values) {
121 length = values.length,
122 offset = array.length;
124 while (++index < length) {
125 array[offset + index] = values[index];
131 * The base implementation of methods like `_.max` and `_.min` which accepts a
132 * `comparator` to determine the extremum value.
135 * @param {Array} array The array to iterate over.
136 * @param {Function} iteratee The iteratee invoked per iteration.
137 * @param {Function} comparator The comparator used to compare values.
138 * @returns {*} Returns the extremum value.
140 function baseExtremum(array, iteratee, comparator) {
142 length = array.length;
144 while (++index < length) {
145 var value = array[index],
146 current = iteratee(value);
148 if (current != null && (computed === undefined
149 ? current === current
150 : comparator(current, computed)
152 var computed = current,
160 * The base implementation of methods like `_.find` and `_.findKey`, without
161 * support for iteratee shorthands, which iterates over `collection` using
165 * @param {Array|Object} collection The collection to search.
166 * @param {Function} predicate The function invoked per iteration.
167 * @param {Function} eachFunc The function to iterate over `collection`.
168 * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
169 * @returns {*} Returns the found element or its key, else `undefined`.
171 function baseFind(collection, predicate, eachFunc, retKey) {
173 eachFunc(collection, function(value, key, collection) {
174 if (predicate(value, key, collection)) {
175 result = retKey ? key : value;
183 * The base implementation of `_.reduce` and `_.reduceRight`, without support
184 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
187 * @param {Array|Object} collection The collection to iterate over.
188 * @param {Function} iteratee The function invoked per iteration.
189 * @param {*} accumulator The initial value.
190 * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value.
191 * @param {Function} eachFunc The function to iterate over `collection`.
192 * @returns {*} Returns the accumulated value.
194 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
195 eachFunc(collection, function(value, index, collection) {
196 accumulator = initAccum
197 ? (initAccum = false, value)
198 : iteratee(accumulator, value, index, collection);
204 * The base implementation of `_.times` without support for iteratee shorthands
205 * or max array length checks.
208 * @param {number} n The number of times to invoke `iteratee`.
209 * @param {Function} iteratee The function invoked per iteration.
210 * @returns {Array} Returns the array of results.
212 function baseTimes(n, iteratee) {
216 while (++index < n) {
217 result[index] = iteratee(index);
223 * The base implementation of `_.values` and `_.valuesIn` which creates an
224 * array of `object` property values corresponding to the property names
228 * @param {Object} object The object to query.
229 * @param {Array} props The property names to get values for.
230 * @returns {Object} Returns the array of property values.
232 function baseValues(object, props) {
233 return baseMap(props, function(key) {
239 * Checks if `value` is a global object.
242 * @param {*} value The value to check.
243 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
245 function checkGlobal(value) {
246 return (value && value.Object === Object) ? value : null;
250 * Compares values to sort them in ascending order.
253 * @param {*} value The value to compare.
254 * @param {*} other The other value to compare.
255 * @returns {number} Returns the sort order indicator for `value`.
257 function compareAscending(value, other) {
258 if (value !== other) {
259 var valIsNull = value === null,
260 valIsUndef = value === undefined,
261 valIsReflexive = value === value;
263 var othIsNull = other === null,
264 othIsUndef = other === undefined,
265 othIsReflexive = other === other;
267 if ((value > other && !othIsNull) || !valIsReflexive ||
268 (valIsNull && !othIsUndef && othIsReflexive) ||
269 (valIsUndef && othIsReflexive)) {
272 if ((value < other && !valIsNull) || !othIsReflexive ||
273 (othIsNull && !valIsUndef && valIsReflexive) ||
274 (othIsUndef && valIsReflexive)) {
282 * Used by `_.escape` to convert characters to HTML entities.
285 * @param {string} chr The matched character to escape.
286 * @returns {string} Returns the escaped character.
288 function escapeHtmlChar(chr) {
289 return htmlEscapes[chr];
293 * Checks if `value` is a host object in IE < 9.
296 * @param {*} value The value to check.
297 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
299 function isHostObject(value) {
300 // Many host objects are `Object` objects that can coerce to strings
301 // despite having improperly defined `toString` methods.
303 if (value != null && typeof value.toString != 'function') {
305 result = !!(value + '');
312 * Checks if `value` is a valid array-like index.
315 * @param {*} value The value to check.
316 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
317 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
319 function isIndex(value, length) {
320 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
321 length = length == null ? MAX_SAFE_INTEGER : length;
322 return value > -1 && value % 1 == 0 && value < length;
326 * Converts `iterator` to an array.
329 * @param {Object} iterator The iterator to convert.
330 * @returns {Array} Returns the converted array.
332 function iteratorToArray(iterator) {
336 while (!(data = iterator.next()).done) {
337 result.push(data.value);
342 /*--------------------------------------------------------------------------*/
344 /** Used for built-in method references. */
345 var arrayProto = Array.prototype,
346 objectProto = Object.prototype;
348 /** Used to check objects for own properties. */
349 var hasOwnProperty = objectProto.hasOwnProperty;
351 /** Used to generate unique IDs. */
355 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
358 var objectToString = objectProto.toString;
360 /** Used to restore the original `_` reference in `_.noConflict`. */
361 var oldDash = root._;
363 /** Built-in value references. */
364 var Reflect = root.Reflect,
365 Symbol = root.Symbol,
366 Uint8Array = root.Uint8Array,
367 enumerate = Reflect ? Reflect.enumerate : undefined,
368 propertyIsEnumerable = objectProto.propertyIsEnumerable;
370 /* Built-in method references for those with the same name as other `lodash` methods. */
371 var nativeIsFinite = root.isFinite,
372 nativeKeys = Object.keys,
373 nativeMax = Math.max;
375 /*------------------------------------------------------------------------*/
378 * Creates a `lodash` object which wraps `value` to enable implicit method
379 * chaining. Methods that operate on and return arrays, collections, and
380 * functions can be chained together. Methods that retrieve a single value or
381 * may return a primitive value will automatically end the chain sequence and
382 * return the unwrapped value. Otherwise, the value must be unwrapped with
385 * Explicit chaining, which must be unwrapped with `_#value` in all cases,
386 * may be enabled using `_.chain`.
388 * The execution of chained methods is lazy, that is, it's deferred until
389 * `_#value` is implicitly or explicitly called.
391 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
392 * fusion is an optimization to merge iteratee calls; this avoids the creation
393 * of intermediate arrays and can greatly reduce the number of iteratee executions.
394 * Sections of a chain sequence qualify for shortcut fusion if the section is
395 * applied to an array of at least two hundred elements and any iteratees
396 * accept only one argument. The heuristic for whether a section qualifies
397 * for shortcut fusion is subject to change.
399 * Chaining is supported in custom builds as long as the `_#value` method is
400 * directly or indirectly included in the build.
402 * In addition to lodash methods, wrappers have `Array` and `String` methods.
404 * The wrapper `Array` methods are:
405 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
407 * The wrapper `String` methods are:
408 * `replace` and `split`
410 * The wrapper methods that support shortcut fusion are:
411 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
412 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
413 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
415 * The chainable wrapper methods are:
416 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
417 * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
418 * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`,
419 * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
420 * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
421 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
422 * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`,
423 * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invertBy`,
424 * `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`,
425 * `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`,
426 * `method`, `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`,
427 * `orderBy`, `over`, `overArgs`, `overEvery`, `overSome`, `partial`,
428 * `partialRight`, `partition`, `pick`, `pickBy`, `plant`, `property`,
429 * `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`,
430 * `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, `sampleSize`,
431 * `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`,
432 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
433 * `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`,
434 * `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`,
435 * `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`,
436 * `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`,
437 * `zipObjectDeep`, and `zipWith`
439 * The wrapper methods that are **not** chainable by default are:
440 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
441 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
442 * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
443 * `findLast`, `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`,
444 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
445 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
446 * `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
447 * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
448 * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`, `isMatchWith`,
449 * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`,
450 * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isString`, `isUndefined`,
451 * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`,
452 * `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`,
453 * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`,
454 * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
455 * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
456 * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
457 * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toLower`,
458 * `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`,
459 * `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
460 * `upperCase`, `upperFirst`, `value`, and `words`
465 * @param {*} value The value to wrap in a `lodash` instance.
466 * @returns {Object} Returns the new `lodash` wrapper instance.
469 * function square(n) {
473 * var wrapped = _([1, 2, 3]);
475 * // Returns an unwrapped value.
476 * wrapped.reduce(_.add);
479 * // Returns a wrapped value.
480 * var squares = wrapped.map(square);
482 * _.isArray(squares);
485 * _.isArray(squares.value());
488 function lodash(value) {
489 if (isObjectLike(value) && !isArray(value)) {
490 if (value instanceof LodashWrapper) {
493 if (hasOwnProperty.call(value, '__wrapped__')) {
494 return wrapperClone(value);
497 return new LodashWrapper(value);
501 * The base constructor for creating `lodash` wrapper objects.
504 * @param {*} value The value to wrap.
505 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
507 function LodashWrapper(value, chainAll) {
508 this.__wrapped__ = value;
509 this.__actions__ = [];
510 this.__chain__ = !!chainAll;
513 /*------------------------------------------------------------------------*/
516 * Used by `_.defaults` to customize its `_.assignIn` use.
519 * @param {*} objValue The destination value.
520 * @param {*} srcValue The source value.
521 * @param {string} key The key of the property to assign.
522 * @param {Object} object The parent object of `objValue`.
523 * @returns {*} Returns the value to assign.
525 function assignInDefaults(objValue, srcValue, key, object) {
526 if (objValue === undefined ||
527 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
534 * Assigns `value` to `key` of `object` if the existing value is not equivalent
535 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
536 * for equality comparisons.
539 * @param {Object} object The object to modify.
540 * @param {string} key The key of the property to assign.
541 * @param {*} value The value to assign.
543 function assignValue(object, key, value) {
544 var objValue = object[key];
545 if ((!eq(objValue, value) ||
546 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
547 (value === undefined && !(key in object))) {
553 * The base implementation of `_.create` without support for assigning
554 * properties to the created object.
557 * @param {Object} prototype The object to inherit from.
558 * @returns {Object} Returns the new object.
560 var baseCreate = (function() {
562 return function(prototype) {
563 if (isObject(prototype)) {
564 object.prototype = prototype;
565 var result = new object;
566 object.prototype = undefined;
573 * The base implementation of `_.delay` and `_.defer` which accepts an array
574 * of `func` arguments.
577 * @param {Function} func The function to delay.
578 * @param {number} wait The number of milliseconds to delay invocation.
579 * @param {Object} args The arguments to provide to `func`.
580 * @returns {number} Returns the timer id.
582 function baseDelay(func, wait, args) {
583 if (typeof func != 'function') {
584 throw new TypeError(FUNC_ERROR_TEXT);
586 return setTimeout(function() { func.apply(undefined, args); }, wait);
590 * The base implementation of `_.forEach` without support for iteratee shorthands.
593 * @param {Array|Object} collection The collection to iterate over.
594 * @param {Function} iteratee The function invoked per iteration.
595 * @returns {Array|Object} Returns `collection`.
597 var baseEach = createBaseEach(baseForOwn);
600 * The base implementation of `_.every` without support for iteratee shorthands.
603 * @param {Array|Object} collection The collection to iterate over.
604 * @param {Function} predicate The function invoked per iteration.
605 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
607 function baseEvery(collection, predicate) {
609 baseEach(collection, function(value, index, collection) {
610 result = !!predicate(value, index, collection);
617 * The base implementation of `_.filter` without support for iteratee shorthands.
620 * @param {Array|Object} collection The collection to iterate over.
621 * @param {Function} predicate The function invoked per iteration.
622 * @returns {Array} Returns the new filtered array.
624 function baseFilter(collection, predicate) {
626 baseEach(collection, function(value, index, collection) {
627 if (predicate(value, index, collection)) {
635 * The base implementation of `_.flatten` with support for restricting flattening.
638 * @param {Array} array The array to flatten.
639 * @param {boolean} [isDeep] Specify a deep flatten.
640 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
641 * @param {Array} [result=[]] The initial result value.
642 * @returns {Array} Returns the new flattened array.
644 function baseFlatten(array, isDeep, isStrict, result) {
645 result || (result = []);
648 length = array.length;
650 while (++index < length) {
651 var value = array[index];
652 if (isArrayLikeObject(value) &&
653 (isStrict || isArray(value) || isArguments(value))) {
655 // Recursively flatten arrays (susceptible to call stack limits).
656 baseFlatten(value, isDeep, isStrict, result);
658 arrayPush(result, value);
660 } else if (!isStrict) {
661 result[result.length] = value;
668 * The base implementation of `baseForIn` and `baseForOwn` which iterates
669 * over `object` properties returned by `keysFunc` invoking `iteratee` for
670 * each property. Iteratee functions may exit iteration early by explicitly
674 * @param {Object} object The object to iterate over.
675 * @param {Function} iteratee The function invoked per iteration.
676 * @param {Function} keysFunc The function to get the keys of `object`.
677 * @returns {Object} Returns `object`.
679 var baseFor = createBaseFor();
682 * The base implementation of `_.forOwn` without support for iteratee shorthands.
685 * @param {Object} object The object to iterate over.
686 * @param {Function} iteratee The function invoked per iteration.
687 * @returns {Object} Returns `object`.
689 function baseForOwn(object, iteratee) {
690 return object && baseFor(object, iteratee, keys);
694 * The base implementation of `_.functions` which creates an array of
695 * `object` function property names filtered from `props`.
698 * @param {Object} object The object to inspect.
699 * @param {Array} props The property names to filter.
700 * @returns {Array} Returns the new array of filtered property names.
702 function baseFunctions(object, props) {
703 return baseFilter(props, function(key) {
704 return isFunction(object[key]);
709 * The base implementation of `_.isEqual` which supports partial comparisons
710 * and tracks traversed objects.
713 * @param {*} value The value to compare.
714 * @param {*} other The other value to compare.
715 * @param {Function} [customizer] The function to customize comparisons.
716 * @param {boolean} [bitmask] The bitmask of comparison flags.
717 * The bitmask may be composed of the following flags:
718 * 1 - Unordered comparison
719 * 2 - Partial comparison
720 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
721 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
723 function baseIsEqual(value, other, customizer, bitmask, stack) {
724 if (value === other) {
727 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
728 return value !== value && other !== other;
730 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
734 * A specialized version of `baseIsEqual` for arrays and objects which performs
735 * deep comparisons and tracks traversed objects enabling objects with circular
736 * references to be compared.
739 * @param {Object} object The object to compare.
740 * @param {Object} other The other object to compare.
741 * @param {Function} equalFunc The function to determine equivalents of values.
742 * @param {Function} [customizer] The function to customize comparisons.
743 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
744 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
745 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
747 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
748 var objIsArr = isArray(object),
749 othIsArr = isArray(other),
754 objTag = objectToString.call(object);
755 if (objTag == argsTag) {
760 othTag = objectToString.call(other);
761 if (othTag == argsTag) {
765 var objIsObj = objTag == objectTag && !isHostObject(object),
766 othIsObj = othTag == objectTag && !isHostObject(other),
767 isSameTag = objTag == othTag;
769 if (isSameTag && !(objIsArr || objIsObj)) {
770 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
772 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
774 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
775 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
777 if (objIsWrapped || othIsWrapped) {
778 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
784 stack || (stack = []);
785 var stacked = find(stack, function(entry) {
786 return entry[0] === object;
788 if (stacked && stacked[1]) {
789 return stacked[1] == other;
791 stack.push([object, other]);
792 var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
798 * The base implementation of `_.iteratee`.
801 * @param {*} [value=_.identity] The value to convert to an iteratee.
802 * @returns {Function} Returns the iteratee.
804 function baseIteratee(func) {
805 var type = typeof func;
806 if (type == 'function') {
811 : (type == 'object' ? baseMatches : baseProperty)(func);
815 * The base implementation of `_.keys` which doesn't skip the constructor
816 * property of prototypes or treat sparse arrays as dense.
820 * @param {Object} object The object to query.
821 * @returns {Array} Returns the array of property names.
823 function baseKeys(object) {
824 return nativeKeys(Object(object));
828 * The base implementation of `_.keysIn` which doesn't skip the constructor
829 * property of prototypes or treat sparse arrays as dense.
832 * @param {Object} object The object to query.
833 * @returns {Array} Returns the array of property names.
835 function baseKeysIn(object) {
836 object = object == null ? object : Object(object);
839 for (var key in object) {
845 // Fallback for IE < 9 with es6-shim.
846 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
847 baseKeysIn = function(object) {
848 return iteratorToArray(enumerate(object));
853 * The base implementation of `_.map` without support for iteratee shorthands.
856 * @param {Array|Object} collection The collection to iterate over.
857 * @param {Function} iteratee The function invoked per iteration.
858 * @returns {Array} Returns the new mapped array.
860 function baseMap(collection, iteratee) {
862 result = isArrayLike(collection) ? Array(collection.length) : [];
864 baseEach(collection, function(value, key, collection) {
865 result[++index] = iteratee(value, key, collection);
871 * The base implementation of `_.matches` which doesn't clone `source`.
874 * @param {Object} source The object of property values to match.
875 * @returns {Function} Returns the new function.
877 function baseMatches(source) {
878 var props = keys(source);
879 return function(object) {
880 var length = props.length;
881 if (object == null) {
884 object = Object(object);
886 var key = props[length];
887 if (!(key in object &&
888 baseIsEqual(source[key], object[key], undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG)
898 * The base implementation of `_.pick` without support for individual
902 * @param {Object} object The source object.
903 * @param {string[]} props The property names to pick.
904 * @returns {Object} Returns the new object.
906 function basePick(object, props) {
907 object = Object(object);
908 return reduce(props, function(result, key) {
910 result[key] = object[key];
917 * The base implementation of `_.property` without support for deep paths.
920 * @param {string} key The key of the property to get.
921 * @returns {Function} Returns the new function.
923 function baseProperty(key) {
924 return function(object) {
925 return object == null ? undefined : object[key];
930 * The base implementation of `_.slice` without an iteratee call guard.
933 * @param {Array} array The array to slice.
934 * @param {number} [start=0] The start position.
935 * @param {number} [end=array.length] The end position.
936 * @returns {Array} Returns the slice of `array`.
938 function baseSlice(array, start, end) {
940 length = array.length;
943 start = -start > length ? 0 : (length + start);
945 end = end > length ? length : end;
949 length = start > end ? 0 : ((end - start) >>> 0);
952 var result = Array(length);
953 while (++index < length) {
954 result[index] = array[index + start];
960 * Copies the values of `source` to `array`.
963 * @param {Array} source The array to copy values from.
964 * @param {Array} [array=[]] The array to copy values to.
965 * @returns {Array} Returns `array`.
967 function copyArray(source) {
968 return baseSlice(source, 0, source.length);
972 * The base implementation of `_.some` without support for iteratee shorthands.
975 * @param {Array|Object} collection The collection to iterate over.
976 * @param {Function} predicate The function invoked per iteration.
977 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
979 function baseSome(collection, predicate) {
982 baseEach(collection, function(value, index, collection) {
983 result = predicate(value, index, collection);
990 * The base implementation of `wrapperValue` which returns the result of
991 * performing a sequence of actions on the unwrapped `value`, where each
992 * successive action is supplied the return value of the previous.
995 * @param {*} value The unwrapped value.
996 * @param {Array} actions Actions to perform to resolve the unwrapped value.
997 * @returns {*} Returns the resolved value.
999 function baseWrapperValue(value, actions) {
1001 return reduce(actions, function(result, action) {
1002 return action.func.apply(action.thisArg, arrayPush([result], action.args));
1007 * Copies properties of `source` to `object`.
1010 * @param {Object} source The object to copy properties from.
1011 * @param {Array} props The property names to copy.
1012 * @param {Object} [object={}] The object to copy properties to.
1013 * @returns {Object} Returns `object`.
1015 var copyObject = copyObjectWith;
1018 * This function is like `copyObject` except that it accepts a function to
1019 * customize copied values.
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 * @param {Function} [customizer] The function to customize copied values.
1026 * @returns {Object} Returns `object`.
1028 function copyObjectWith(source, props, object, customizer) {
1029 object || (object = {});
1032 length = props.length;
1034 while (++index < length) {
1035 var key = props[index],
1036 newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
1038 assignValue(object, key, newValue);
1044 * Creates a function like `_.assign`.
1047 * @param {Function} assigner The function to assign values.
1048 * @returns {Function} Returns the new assigner function.
1050 function createAssigner(assigner) {
1051 return rest(function(object, sources) {
1053 length = sources.length,
1054 customizer = length > 1 ? sources[length - 1] : undefined;
1056 customizer = typeof customizer == 'function' ? (length--, customizer) : undefined;
1057 object = Object(object);
1058 while (++index < length) {
1059 var source = sources[index];
1061 assigner(object, source, index, customizer);
1069 * Creates a `baseEach` or `baseEachRight` function.
1072 * @param {Function} eachFunc The function to iterate over a collection.
1073 * @param {boolean} [fromRight] Specify iterating from right to left.
1074 * @returns {Function} Returns the new base function.
1076 function createBaseEach(eachFunc, fromRight) {
1077 return function(collection, iteratee) {
1078 if (collection == null) {
1081 if (!isArrayLike(collection)) {
1082 return eachFunc(collection, iteratee);
1084 var length = collection.length,
1085 index = fromRight ? length : -1,
1086 iterable = Object(collection);
1088 while ((fromRight ? index-- : ++index < length)) {
1089 if (iteratee(iterable[index], index, iterable) === false) {
1098 * Creates a base function for methods like `_.forIn`.
1101 * @param {boolean} [fromRight] Specify iterating from right to left.
1102 * @returns {Function} Returns the new base function.
1104 function createBaseFor(fromRight) {
1105 return function(object, iteratee, keysFunc) {
1107 iterable = Object(object),
1108 props = keysFunc(object),
1109 length = props.length;
1112 var key = props[fromRight ? length : ++index];
1113 if (iteratee(iterable[key], key, iterable) === false) {
1122 * Creates a function that produces an instance of `Ctor` regardless of
1123 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
1126 * @param {Function} Ctor The constructor to wrap.
1127 * @returns {Function} Returns the new wrapped function.
1129 function createCtorWrapper(Ctor) {
1131 // Use a `switch` statement to work with class constructors.
1132 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1133 // for more details.
1134 var args = arguments;
1135 var thisBinding = baseCreate(Ctor.prototype),
1136 result = Ctor.apply(thisBinding, args);
1138 // Mimic the constructor's `return` behavior.
1139 // See https://es5.github.io/#x13.2.2 for more details.
1140 return isObject(result) ? result : thisBinding;
1145 * Creates a function that wraps `func` to invoke it with the optional `this`
1146 * binding of `thisArg` and the `partials` prepended to those provided to
1150 * @param {Function} func The function to wrap.
1151 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
1152 * @param {*} thisArg The `this` binding of `func`.
1153 * @param {Array} partials The arguments to prepend to those provided to the new function.
1154 * @returns {Function} Returns the new wrapped function.
1156 function createPartialWrapper(func, bitmask, thisArg, partials) {
1157 if (typeof func != 'function') {
1158 throw new TypeError(FUNC_ERROR_TEXT);
1160 var isBind = bitmask & BIND_FLAG,
1161 Ctor = createCtorWrapper(func);
1163 function wrapper() {
1165 argsLength = arguments.length,
1167 leftLength = partials.length,
1168 args = Array(leftLength + argsLength),
1169 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
1171 while (++leftIndex < leftLength) {
1172 args[leftIndex] = partials[leftIndex];
1174 while (argsLength--) {
1175 args[leftIndex++] = arguments[++argsIndex];
1177 return fn.apply(isBind ? thisArg : this, args);
1183 * A specialized version of `baseIsEqualDeep` for arrays with support for
1184 * partial deep comparisons.
1187 * @param {Array} array The array to compare.
1188 * @param {Array} other The other array to compare.
1189 * @param {Function} equalFunc The function to determine equivalents of values.
1190 * @param {Function} [customizer] The function to customize comparisons.
1191 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1192 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
1193 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1195 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
1197 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1198 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
1199 arrLength = array.length,
1200 othLength = other.length;
1202 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1207 // Ignore non-index properties.
1208 while (++index < arrLength) {
1209 var arrValue = array[index],
1210 othValue = other[index];
1213 if (compared !== undefined) {
1220 // Recursively compare arrays (susceptible to call stack limits).
1222 if (!baseSome(other, function(othValue) {
1223 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
1228 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
1237 * A specialized version of `baseIsEqualDeep` for comparing objects of
1238 * the same `toStringTag`.
1240 * **Note:** This function only supports comparing values with tags of
1241 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1244 * @param {Object} object The object to compare.
1245 * @param {Object} other The other object to compare.
1246 * @param {string} tag The `toStringTag` of the objects to compare.
1247 * @param {Function} equalFunc The function to determine equivalents of values.
1248 * @param {Function} [customizer] The function to customize comparisons.
1249 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1250 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1252 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
1257 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
1258 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
1259 return +object == +other;
1262 return object.name == other.name && object.message == other.message;
1265 // Treat `NaN` vs. `NaN` as equal.
1266 return (object != +object) ? other != +other : object == +other;
1270 // Coerce regexes to strings and treat strings primitives and string
1271 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
1272 return object == (other + '');
1279 * A specialized version of `baseIsEqualDeep` for objects with support for
1280 * partial deep comparisons.
1283 * @param {Object} object The object to compare.
1284 * @param {Object} other The other object to compare.
1285 * @param {Function} equalFunc The function to determine equivalents of values.
1286 * @param {Function} [customizer] The function to customize comparisons.
1287 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1288 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
1289 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1291 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
1292 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1293 objProps = keys(object),
1294 objLength = objProps.length,
1295 othProps = keys(other),
1296 othLength = othProps.length;
1298 if (objLength != othLength && !isPartial) {
1301 var index = objLength;
1303 var key = objProps[index];
1304 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1310 var skipCtor = isPartial;
1311 while (++index < objLength) {
1312 key = objProps[index];
1313 var objValue = object[key],
1314 othValue = other[key];
1317 // Recursively compare objects (susceptible to call stack limits).
1318 if (!(compared === undefined
1319 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
1325 skipCtor || (skipCtor = key == 'constructor');
1327 if (result && !skipCtor) {
1328 var objCtor = object.constructor,
1329 othCtor = other.constructor;
1331 // Non `Object` object instances with different constructors are not equal.
1332 if (objCtor != othCtor &&
1333 ('constructor' in object && 'constructor' in other) &&
1334 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1335 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1343 * Gets the "length" property value of `object`.
1345 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
1346 * that affects Safari on at least iOS 8.1-8.3 ARM64.
1349 * @param {Object} object The object to query.
1350 * @returns {*} Returns the "length" value.
1352 var getLength = baseProperty('length');
1355 * Creates an array of index keys for `object` values of arrays,
1356 * `arguments` objects, and strings, otherwise `null` is returned.
1359 * @param {Object} object The object to query.
1360 * @returns {Array|null} Returns index keys, else `null`.
1362 function indexKeys(object) {
1363 var length = object ? object.length : undefined;
1364 if (isLength(length) &&
1365 (isArray(object) || isString(object) || isArguments(object))) {
1366 return baseTimes(length, String);
1372 * Checks if `value` is likely a prototype object.
1375 * @param {*} value The value to check.
1376 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1378 function isPrototype(value) {
1379 var Ctor = value && value.constructor,
1380 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1382 return value === proto;
1386 * Converts `value` to a function if it's not one.
1389 * @param {*} value The value to process.
1390 * @returns {Function} Returns the function.
1392 function toFunction(value) {
1393 return typeof value == 'function' ? value : identity;
1397 * Creates a clone of `wrapper`.
1400 * @param {Object} wrapper The wrapper to clone.
1401 * @returns {Object} Returns the cloned wrapper.
1403 function wrapperClone(wrapper) {
1404 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
1405 result.__actions__ = copyArray(wrapper.__actions__);
1409 /*------------------------------------------------------------------------*/
1412 * Creates an array with all falsey values removed. The values `false`, `null`,
1413 * `0`, `""`, `undefined`, and `NaN` are falsey.
1418 * @param {Array} array The array to compact.
1419 * @returns {Array} Returns the new array of filtered values.
1422 * _.compact([0, 1, false, 2, '', 3]);
1425 function compact(array) {
1426 return baseFilter(array, Boolean);
1430 * Creates a new array concatenating `array` with any additional arrays
1436 * @param {Array} array The array to concatenate.
1437 * @param {...*} [values] The values to concatenate.
1438 * @returns {Array} Returns the new concatenated array.
1442 * var other = _.concat(array, 2, [3], [[4]]);
1444 * console.log(other);
1445 * // => [1, 2, 3, [4]]
1447 * console.log(array);
1450 var concat = rest(function(array, values) {
1451 if (!isArray(array)) {
1452 array = array == null ? [] : [Object(array)];
1454 values = baseFlatten(values);
1455 return arrayConcat(array, values);
1459 * Flattens `array` a single level.
1464 * @param {Array} array The array to flatten.
1465 * @returns {Array} Returns the new flattened array.
1468 * _.flatten([1, [2, 3, [4]]]);
1469 * // => [1, 2, 3, [4]]
1471 function flatten(array) {
1472 var length = array ? array.length : 0;
1473 return length ? baseFlatten(array) : [];
1477 * This method is like `_.flatten` except that it recursively flattens `array`.
1482 * @param {Array} array The array to recursively flatten.
1483 * @returns {Array} Returns the new flattened array.
1486 * _.flattenDeep([1, [2, 3, [4]]]);
1487 * // => [1, 2, 3, 4]
1489 function flattenDeep(array) {
1490 var length = array ? array.length : 0;
1491 return length ? baseFlatten(array, true) : [];
1495 * Gets the first element of `array`.
1501 * @param {Array} array The array to query.
1502 * @returns {*} Returns the first element of `array`.
1505 * _.head([1, 2, 3]);
1511 function head(array) {
1512 return array ? array[0] : undefined;
1516 * Gets the index at which the first occurrence of `value` is found in `array`
1517 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
1518 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
1519 * from the end of `array`.
1524 * @param {Array} array The array to search.
1525 * @param {*} value The value to search for.
1526 * @param {number} [fromIndex=0] The index to search from.
1527 * @returns {number} Returns the index of the matched value, else `-1`.
1530 * _.indexOf([1, 2, 1, 2], 2);
1533 * // Search from the `fromIndex`.
1534 * _.indexOf([1, 2, 1, 2], 2, 2);
1537 function indexOf(array, value, fromIndex) {
1538 var length = array ? array.length : 0;
1539 if (typeof fromIndex == 'number') {
1540 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1544 var index = (fromIndex || 0) - 1,
1545 isReflexive = value === value;
1547 while (++index < length) {
1548 var other = array[index];
1549 if ((isReflexive ? other === value : other !== other)) {
1557 * Gets the last element of `array`.
1562 * @param {Array} array The array to query.
1563 * @returns {*} Returns the last element of `array`.
1566 * _.last([1, 2, 3]);
1569 function last(array) {
1570 var length = array ? array.length : 0;
1571 return length ? array[length - 1] : undefined;
1575 * Creates a slice of `array` from `start` up to, but not including, `end`.
1577 * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
1578 * to ensure dense arrays are returned.
1583 * @param {Array} array The array to slice.
1584 * @param {number} [start=0] The start position.
1585 * @param {number} [end=array.length] The end position.
1586 * @returns {Array} Returns the slice of `array`.
1588 function slice(array, start, end) {
1589 var length = array ? array.length : 0;
1590 start = start == null ? 0 : +start;
1591 end = end === undefined ? length : +end;
1592 return length ? baseSlice(array, start, end) : [];
1595 /*------------------------------------------------------------------------*/
1598 * Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
1599 * The result of such method chaining must be unwrapped with `_#value`.
1604 * @param {*} value The value to wrap.
1605 * @returns {Object} Returns the new `lodash` wrapper instance.
1609 * { 'user': 'barney', 'age': 36 },
1610 * { 'user': 'fred', 'age': 40 },
1611 * { 'user': 'pebbles', 'age': 1 }
1617 * .map(function(o) {
1618 * return o.user + ' is ' + o.age;
1622 * // => 'pebbles is 1'
1624 function chain(value) {
1625 var result = lodash(value);
1626 result.__chain__ = true;
1631 * This method invokes `interceptor` and returns `value`. The interceptor
1632 * is invoked with one argument; (value). The purpose of this method is to
1633 * "tap into" a method chain in order to modify intermediate results.
1638 * @param {*} value The value to provide to `interceptor`.
1639 * @param {Function} interceptor The function to invoke.
1640 * @returns {*} Returns `value`.
1644 * .tap(function(array) {
1645 * // Mutate input array.
1652 function tap(value, interceptor) {
1658 * This method is like `_.tap` except that it returns the result of `interceptor`.
1659 * The purpose of this method is to "pass thru" values replacing intermediate
1660 * results in a method chain.
1665 * @param {*} value The value to provide to `interceptor`.
1666 * @param {Function} interceptor The function to invoke.
1667 * @returns {*} Returns the result of `interceptor`.
1673 * .thru(function(value) {
1679 function thru(value, interceptor) {
1680 return interceptor(value);
1684 * Enables explicit method chaining on the wrapper object.
1689 * @returns {Object} Returns the new `lodash` wrapper instance.
1693 * { 'user': 'barney', 'age': 36 },
1694 * { 'user': 'fred', 'age': 40 }
1697 * // A sequence without explicit chaining.
1699 * // => { 'user': 'barney', 'age': 36 }
1701 * // A sequence with explicit chaining.
1707 * // => { 'user': 'barney' }
1709 function wrapperChain() {
1714 * Executes the chained sequence to extract the unwrapped value.
1718 * @alias toJSON, valueOf
1720 * @returns {*} Returns the resolved unwrapped value.
1723 * _([1, 2, 3]).value();
1726 function wrapperValue() {
1727 return baseWrapperValue(this.__wrapped__, this.__actions__);
1730 /*------------------------------------------------------------------------*/
1733 * Checks if `predicate` returns truthy for **all** elements of `collection`.
1734 * Iteration is stopped once `predicate` returns falsey. The predicate is
1735 * invoked with three arguments: (value, index|key, collection).
1739 * @category Collection
1740 * @param {Array|Object} collection The collection to iterate over.
1741 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1742 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
1743 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
1746 * _.every([true, 1, null, 'yes'], Boolean);
1750 * { 'user': 'barney', 'active': false },
1751 * { 'user': 'fred', 'active': false }
1754 * // The `_.matches` iteratee shorthand.
1755 * _.every(users, { 'user': 'barney', 'active': false });
1758 * // The `_.matchesProperty` iteratee shorthand.
1759 * _.every(users, ['active', false]);
1762 * // The `_.property` iteratee shorthand.
1763 * _.every(users, 'active');
1766 function every(collection, predicate, guard) {
1767 predicate = guard ? undefined : predicate;
1768 return baseEvery(collection, baseIteratee(predicate));
1772 * Iterates over elements of `collection`, returning an array of all elements
1773 * `predicate` returns truthy for. The predicate is invoked with three arguments:
1774 * (value, index|key, collection).
1778 * @category Collection
1779 * @param {Array|Object} collection The collection to iterate over.
1780 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1781 * @returns {Array} Returns the new filtered array.
1785 * { 'user': 'barney', 'age': 36, 'active': true },
1786 * { 'user': 'fred', 'age': 40, 'active': false }
1789 * _.filter(users, function(o) { return !o.active; });
1790 * // => objects for ['fred']
1792 * // The `_.matches` iteratee shorthand.
1793 * _.filter(users, { 'age': 36, 'active': true });
1794 * // => objects for ['barney']
1796 * // The `_.matchesProperty` iteratee shorthand.
1797 * _.filter(users, ['active', false]);
1798 * // => objects for ['fred']
1800 * // The `_.property` iteratee shorthand.
1801 * _.filter(users, 'active');
1802 * // => objects for ['barney']
1804 function filter(collection, predicate) {
1805 return baseFilter(collection, baseIteratee(predicate));
1809 * Iterates over elements of `collection`, returning the first element
1810 * `predicate` returns truthy for. The predicate is invoked with three arguments:
1811 * (value, index|key, collection).
1815 * @category Collection
1816 * @param {Array|Object} collection The collection to search.
1817 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1818 * @returns {*} Returns the matched element, else `undefined`.
1822 * { 'user': 'barney', 'age': 36, 'active': true },
1823 * { 'user': 'fred', 'age': 40, 'active': false },
1824 * { 'user': 'pebbles', 'age': 1, 'active': true }
1827 * _.find(users, function(o) { return o.age < 40; });
1828 * // => object for 'barney'
1830 * // The `_.matches` iteratee shorthand.
1831 * _.find(users, { 'age': 1, 'active': true });
1832 * // => object for 'pebbles'
1834 * // The `_.matchesProperty` iteratee shorthand.
1835 * _.find(users, ['active', false]);
1836 * // => object for 'fred'
1838 * // The `_.property` iteratee shorthand.
1839 * _.find(users, 'active');
1840 * // => object for 'barney'
1842 function find(collection, predicate) {
1843 return baseFind(collection, baseIteratee(predicate), baseEach);
1847 * Iterates over elements of `collection` invoking `iteratee` for each element.
1848 * The iteratee is invoked with three arguments: (value, index|key, collection).
1849 * Iteratee functions may exit iteration early by explicitly returning `false`.
1851 * **Note:** As with other "Collections" methods, objects with a "length" property
1852 * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
1853 * for object iteration.
1858 * @category Collection
1859 * @param {Array|Object} collection The collection to iterate over.
1860 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1861 * @returns {Array|Object} Returns `collection`.
1864 * _([1, 2]).forEach(function(value) {
1865 * console.log(value);
1867 * // => logs `1` then `2`
1869 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
1872 * // => logs 'a' then 'b' (iteration order is not guaranteed)
1874 function forEach(collection, iteratee) {
1875 return baseEach(collection, toFunction(iteratee));
1879 * Creates an array of values by running each element in `collection` through
1880 * `iteratee`. The iteratee is invoked with three arguments:
1881 * (value, index|key, collection).
1883 * Many lodash methods are guarded to work as iteratees for methods like
1884 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
1886 * The guarded methods are:
1887 * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
1888 * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
1889 * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
1894 * @category Collection
1895 * @param {Array|Object} collection The collection to iterate over.
1896 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
1897 * @returns {Array} Returns the new mapped array.
1900 * function square(n) {
1904 * _.map([4, 8], square);
1907 * _.map({ 'a': 4, 'b': 8 }, square);
1908 * // => [16, 64] (iteration order is not guaranteed)
1911 * { 'user': 'barney' },
1912 * { 'user': 'fred' }
1915 * // The `_.property` iteratee shorthand.
1916 * _.map(users, 'user');
1917 * // => ['barney', 'fred']
1919 function map(collection, iteratee) {
1920 return baseMap(collection, baseIteratee(iteratee));
1924 * Reduces `collection` to a value which is the accumulated result of running
1925 * each element in `collection` through `iteratee`, where each successive
1926 * invocation is supplied the return value of the previous. If `accumulator`
1927 * is not given the first element of `collection` is used as the initial
1928 * value. The iteratee is invoked with four arguments:
1929 * (accumulator, value, index|key, collection).
1931 * Many lodash methods are guarded to work as iteratees for methods like
1932 * `_.reduce`, `_.reduceRight`, and `_.transform`.
1934 * The guarded methods are:
1935 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
1940 * @category Collection
1941 * @param {Array|Object} collection The collection to iterate over.
1942 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1943 * @param {*} [accumulator] The initial value.
1944 * @returns {*} Returns the accumulated value.
1947 * _.reduce([1, 2], function(sum, n) {
1952 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
1953 * (result[value] || (result[value] = [])).push(key);
1956 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
1958 function reduce(collection, iteratee, accumulator) {
1959 return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
1963 * Gets the size of `collection` by returning its length for array-like
1964 * values or the number of own enumerable properties for objects.
1968 * @category Collection
1969 * @param {Array|Object} collection The collection to inspect.
1970 * @returns {number} Returns the collection size.
1973 * _.size([1, 2, 3]);
1976 * _.size({ 'a': 1, 'b': 2 });
1979 * _.size('pebbles');
1982 function size(collection) {
1983 if (collection == null) {
1986 collection = isArrayLike(collection) ? collection : keys(collection);
1987 return collection.length;
1991 * Checks if `predicate` returns truthy for **any** element of `collection`.
1992 * Iteration is stopped once `predicate` returns truthy. The predicate is
1993 * invoked with three arguments: (value, index|key, collection).
1997 * @category Collection
1998 * @param {Array|Object} collection The collection to iterate over.
1999 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
2000 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
2001 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
2004 * _.some([null, 0, 'yes', false], Boolean);
2008 * { 'user': 'barney', 'active': true },
2009 * { 'user': 'fred', 'active': false }
2012 * // The `_.matches` iteratee shorthand.
2013 * _.some(users, { 'user': 'barney', 'active': false });
2016 * // The `_.matchesProperty` iteratee shorthand.
2017 * _.some(users, ['active', false]);
2020 * // The `_.property` iteratee shorthand.
2021 * _.some(users, 'active');
2024 function some(collection, predicate, guard) {
2025 predicate = guard ? undefined : predicate;
2026 return baseSome(collection, baseIteratee(predicate));
2030 * Creates an array of elements, sorted in ascending order by the results of
2031 * running each element in a collection through each iteratee. This method
2032 * performs a stable sort, that is, it preserves the original sort order of
2033 * equal elements. The iteratees are invoked with one argument: (value).
2037 * @category Collection
2038 * @param {Array|Object} collection The collection to iterate over.
2039 * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
2040 * The iteratees to sort by, specified individually or in arrays.
2041 * @returns {Array} Returns the new sorted array.
2045 * { 'user': 'fred', 'age': 48 },
2046 * { 'user': 'barney', 'age': 36 },
2047 * { 'user': 'fred', 'age': 42 },
2048 * { 'user': 'barney', 'age': 34 }
2051 * _.sortBy(users, function(o) { return o.user; });
2052 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2054 * _.sortBy(users, ['user', 'age']);
2055 * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
2057 * _.sortBy(users, 'user', function(o) {
2058 * return Math.floor(o.age / 10);
2060 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2062 function sortBy(collection, iteratee) {
2064 iteratee = baseIteratee(iteratee);
2066 return baseMap(baseMap(collection, function(value, key, collection) {
2067 return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2068 }).sort(function(object, other) {
2069 return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2070 }), baseProperty('value'));
2073 /*------------------------------------------------------------------------*/
2076 * Creates a function that invokes `func`, with the `this` binding and arguments
2077 * of the created function, while it's called less than `n` times. Subsequent
2078 * calls to the created function return the result of the last `func` invocation.
2082 * @category Function
2083 * @param {number} n The number of calls at which `func` is no longer invoked.
2084 * @param {Function} func The function to restrict.
2085 * @returns {Function} Returns the new restricted function.
2088 * jQuery(element).on('click', _.before(5, addContactToList));
2089 * // => allows adding up to 4 contacts to the list
2091 function before(n, func) {
2093 if (typeof func != 'function') {
2094 throw new TypeError(FUNC_ERROR_TEXT);
2099 result = func.apply(this, arguments);
2109 * Creates a function that invokes `func` with the `this` binding of `thisArg`
2110 * and prepends any additional `_.bind` arguments to those provided to the
2113 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2114 * may be used as a placeholder for partially applied arguments.
2116 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
2117 * property of bound functions.
2121 * @category Function
2122 * @param {Function} func The function to bind.
2123 * @param {*} thisArg The `this` binding of `func`.
2124 * @param {...*} [partials] The arguments to be partially applied.
2125 * @returns {Function} Returns the new bound function.
2128 * var greet = function(greeting, punctuation) {
2129 * return greeting + ' ' + this.user + punctuation;
2132 * var object = { 'user': 'fred' };
2134 * var bound = _.bind(greet, object, 'hi');
2138 * // Bound with placeholders.
2139 * var bound = _.bind(greet, object, _, '!');
2143 var bind = rest(function(func, thisArg, partials) {
2144 return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
2148 * Defers invoking the `func` until the current call stack has cleared. Any
2149 * additional arguments are provided to `func` when it's invoked.
2153 * @category Function
2154 * @param {Function} func The function to defer.
2155 * @param {...*} [args] The arguments to invoke `func` with.
2156 * @returns {number} Returns the timer id.
2159 * _.defer(function(text) {
2160 * console.log(text);
2162 * // => logs 'deferred' after one or more milliseconds
2164 var defer = rest(function(func, args) {
2165 return baseDelay(func, 1, args);
2169 * Invokes `func` after `wait` milliseconds. Any additional arguments are
2170 * provided to `func` when it's invoked.
2174 * @category Function
2175 * @param {Function} func The function to delay.
2176 * @param {number} wait The number of milliseconds to delay invocation.
2177 * @param {...*} [args] The arguments to invoke `func` with.
2178 * @returns {number} Returns the timer id.
2181 * _.delay(function(text) {
2182 * console.log(text);
2183 * }, 1000, 'later');
2184 * // => logs 'later' after one second
2186 var delay = rest(function(func, wait, args) {
2187 return baseDelay(func, toNumber(wait) || 0, args);
2191 * Creates a function that negates the result of the predicate `func`. The
2192 * `func` predicate is invoked with the `this` binding and arguments of the
2197 * @category Function
2198 * @param {Function} predicate The predicate to negate.
2199 * @returns {Function} Returns the new function.
2202 * function isEven(n) {
2203 * return n % 2 == 0;
2206 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2209 function negate(predicate) {
2210 if (typeof predicate != 'function') {
2211 throw new TypeError(FUNC_ERROR_TEXT);
2214 return !predicate.apply(this, arguments);
2219 * Creates a function that is restricted to invoking `func` once. Repeat calls
2220 * to the function return the value of the first invocation. The `func` is
2221 * invoked with the `this` binding and arguments of the created function.
2225 * @category Function
2226 * @param {Function} func The function to restrict.
2227 * @returns {Function} Returns the new restricted function.
2230 * var initialize = _.once(createApplication);
2233 * // `initialize` invokes `createApplication` once
2235 function once(func) {
2236 return before(2, func);
2240 * Creates a function that invokes `func` with the `this` binding of the
2241 * created function and arguments from `start` and beyond provided as an array.
2243 * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
2247 * @category Function
2248 * @param {Function} func The function to apply a rest parameter to.
2249 * @param {number} [start=func.length-1] The start position of the rest parameter.
2250 * @returns {Function} Returns the new function.
2253 * var say = _.rest(function(what, names) {
2254 * return what + ' ' + _.initial(names).join(', ') +
2255 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
2258 * say('hello', 'fred', 'barney', 'pebbles');
2259 * // => 'hello fred, barney, & pebbles'
2261 function rest(func, start) {
2262 if (typeof func != 'function') {
2263 throw new TypeError(FUNC_ERROR_TEXT);
2265 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
2267 var args = arguments,
2269 length = nativeMax(args.length - start, 0),
2270 array = Array(length);
2272 while (++index < length) {
2273 array[index] = args[start + index];
2275 var otherArgs = Array(start + 1);
2277 while (++index < start) {
2278 otherArgs[index] = args[index];
2280 otherArgs[start] = array;
2281 return func.apply(this, otherArgs);
2285 /*------------------------------------------------------------------------*/
2288 * Creates a shallow clone of `value`.
2290 * **Note:** This method is loosely based on the
2291 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2292 * and supports cloning arrays, array buffers, booleans, date objects, maps,
2293 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2294 * arrays. The own enumerable properties of `arguments` objects are cloned
2295 * as plain objects. An empty object is returned for uncloneable values such
2296 * as error objects, functions, DOM nodes, and WeakMaps.
2301 * @param {*} value The value to clone.
2302 * @returns {*} Returns the cloned value.
2305 * var objects = [{ 'a': 1 }, { 'b': 2 }];
2307 * var shallow = _.clone(objects);
2308 * console.log(shallow[0] === objects[0]);
2311 function clone(value) {
2312 if (!isObject(value)) {
2315 return isArray(value) ? copyArray(value) : copyObject(value, keys(value));
2319 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2320 * comparison between two values to determine if they are equivalent.
2325 * @param {*} value The value to compare.
2326 * @param {*} other The other value to compare.
2327 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2330 * var object = { 'user': 'fred' };
2331 * var other = { 'user': 'fred' };
2333 * _.eq(object, object);
2336 * _.eq(object, other);
2342 * _.eq('a', Object('a'));
2348 function eq(value, other) {
2349 return value === other || (value !== value && other !== other);
2353 * Checks if `value` is greater than `other`.
2358 * @param {*} value The value to compare.
2359 * @param {*} other The other value to compare.
2360 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
2372 function gt(value, other) {
2373 return value > other;
2377 * Checks if `value` is likely an `arguments` object.
2382 * @param {*} value The value to check.
2383 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2386 * _.isArguments(function() { return arguments; }());
2389 * _.isArguments([1, 2, 3]);
2392 function isArguments(value) {
2393 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
2394 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
2395 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
2399 * Checks if `value` is classified as an `Array` object.
2405 * @param {*} value The value to check.
2406 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2409 * _.isArray([1, 2, 3]);
2412 * _.isArray(document.body.children);
2418 * _.isArray(_.noop);
2421 var isArray = Array.isArray;
2424 * Checks if `value` is array-like. A value is considered array-like if it's
2425 * not a function and has a `value.length` that's an integer greater than or
2426 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2432 * @param {*} value The value to check.
2433 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2436 * _.isArrayLike([1, 2, 3]);
2439 * _.isArrayLike(document.body.children);
2442 * _.isArrayLike('abc');
2445 * _.isArrayLike(_.noop);
2448 function isArrayLike(value) {
2449 return value != null &&
2450 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
2454 * This method is like `_.isArrayLike` except that it also checks if `value`
2461 * @param {*} value The value to check.
2462 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
2465 * _.isArrayLikeObject([1, 2, 3]);
2468 * _.isArrayLikeObject(document.body.children);
2471 * _.isArrayLikeObject('abc');
2474 * _.isArrayLikeObject(_.noop);
2477 function isArrayLikeObject(value) {
2478 return isObjectLike(value) && isArrayLike(value);
2482 * Checks if `value` is classified as a boolean primitive or object.
2487 * @param {*} value The value to check.
2488 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2491 * _.isBoolean(false);
2494 * _.isBoolean(null);
2497 function isBoolean(value) {
2498 return value === true || value === false ||
2499 (isObjectLike(value) && objectToString.call(value) == boolTag);
2503 * Checks if `value` is classified as a `Date` object.
2508 * @param {*} value The value to check.
2509 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2512 * _.isDate(new Date);
2515 * _.isDate('Mon April 23 2012');
2518 function isDate(value) {
2519 return isObjectLike(value) && objectToString.call(value) == dateTag;
2523 * Checks if `value` is empty. A value is considered empty unless it's an
2524 * `arguments` object, array, string, or jQuery-like collection with a length
2525 * greater than `0` or an object with own enumerable properties.
2530 * @param {Array|Object|string} value The value to inspect.
2531 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2543 * _.isEmpty([1, 2, 3]);
2546 * _.isEmpty({ 'a': 1 });
2549 function isEmpty(value) {
2550 if (isArrayLike(value) &&
2551 (isArray(value) || isString(value) || isFunction(value.splice) || isArguments(value))) {
2552 return !value.length;
2554 for (var key in value) {
2555 if (hasOwnProperty.call(value, key)) {
2563 * Performs a deep comparison between two values to determine if they are
2566 * **Note:** This method supports comparing arrays, array buffers, booleans,
2567 * date objects, error objects, maps, numbers, `Object` objects, regexes,
2568 * sets, strings, symbols, and typed arrays. `Object` objects are compared
2569 * by their own, not inherited, enumerable properties. Functions and DOM
2570 * nodes are **not** supported.
2575 * @param {*} value The value to compare.
2576 * @param {*} other The other value to compare.
2577 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2580 * var object = { 'user': 'fred' };
2581 * var other = { 'user': 'fred' };
2583 * _.isEqual(object, other);
2589 function isEqual(value, other) {
2590 return baseIsEqual(value, other);
2594 * Checks if `value` is a finite primitive number.
2596 * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
2601 * @param {*} value The value to check.
2602 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
2608 * _.isFinite(Number.MAX_VALUE);
2614 * _.isFinite(Infinity);
2617 function isFinite(value) {
2618 return typeof value == 'number' && nativeIsFinite(value);
2622 * Checks if `value` is classified as a `Function` object.
2627 * @param {*} value The value to check.
2628 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2634 * _.isFunction(/abc/);
2637 function isFunction(value) {
2638 // The use of `Object#toString` avoids issues with the `typeof` operator
2639 // in Safari 8 which returns 'object' for typed array constructors, and
2640 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
2641 var tag = isObject(value) ? objectToString.call(value) : '';
2642 return tag == funcTag || tag == genTag;
2646 * Checks if `value` is a valid array-like length.
2648 * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
2653 * @param {*} value The value to check.
2654 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
2660 * _.isLength(Number.MIN_VALUE);
2663 * _.isLength(Infinity);
2669 function isLength(value) {
2670 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2674 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
2675 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2680 * @param {*} value The value to check.
2681 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2687 * _.isObject([1, 2, 3]);
2690 * _.isObject(_.noop);
2696 function isObject(value) {
2697 var type = typeof value;
2698 return !!value && (type == 'object' || type == 'function');
2702 * Checks if `value` is object-like. A value is object-like if it's not `null`
2703 * and has a `typeof` result of "object".
2708 * @param {*} value The value to check.
2709 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2712 * _.isObjectLike({});
2715 * _.isObjectLike([1, 2, 3]);
2718 * _.isObjectLike(_.noop);
2721 * _.isObjectLike(null);
2724 function isObjectLike(value) {
2725 return !!value && typeof value == 'object';
2729 * Checks if `value` is `NaN`.
2731 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
2732 * which returns `true` for `undefined` and other non-numeric values.
2737 * @param {*} value The value to check.
2738 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2744 * _.isNaN(new Number(NaN));
2750 * _.isNaN(undefined);
2753 function isNaN(value) {
2754 // An `NaN` primitive is the only value that is not equal to itself.
2755 // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
2756 return isNumber(value) && value != +value;
2760 * Checks if `value` is `null`.
2765 * @param {*} value The value to check.
2766 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2775 function isNull(value) {
2776 return value === null;
2780 * Checks if `value` is classified as a `Number` primitive or object.
2782 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
2783 * as numbers, use the `_.isFinite` method.
2788 * @param {*} value The value to check.
2789 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2795 * _.isNumber(Number.MIN_VALUE);
2798 * _.isNumber(Infinity);
2804 function isNumber(value) {
2805 return typeof value == 'number' ||
2806 (isObjectLike(value) && objectToString.call(value) == numberTag);
2810 * Checks if `value` is classified as a `RegExp` object.
2815 * @param {*} value The value to check.
2816 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2819 * _.isRegExp(/abc/);
2822 * _.isRegExp('/abc/');
2825 function isRegExp(value) {
2826 return isObject(value) && objectToString.call(value) == regexpTag;
2830 * Checks if `value` is classified as a `String` primitive or object.
2835 * @param {*} value The value to check.
2836 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2839 * _.isString('abc');
2845 function isString(value) {
2846 return typeof value == 'string' ||
2847 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
2851 * Checks if `value` is `undefined`.
2856 * @param {*} value The value to check.
2857 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
2860 * _.isUndefined(void 0);
2863 * _.isUndefined(null);
2866 function isUndefined(value) {
2867 return value === undefined;
2871 * Checks if `value` is less than `other`.
2876 * @param {*} value The value to compare.
2877 * @param {*} other The other value to compare.
2878 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
2890 function lt(value, other) {
2891 return value < other;
2895 * Converts `value` to an array.
2900 * @param {*} value The value to convert.
2901 * @returns {Array} Returns the converted array.
2904 * _.toArray({ 'a': 1, 'b': 2 });
2908 * // => ['a', 'b', 'c']
2916 function toArray(value) {
2917 if (!isArrayLike(value)) {
2918 return values(value);
2920 return value.length ? copyArray(value) : [];
2924 * Converts `value` to an integer.
2926 * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
2931 * @param {*} value The value to convert.
2932 * @returns {number} Returns the converted integer.
2938 * _.toInteger(Number.MIN_VALUE);
2941 * _.toInteger(Infinity);
2942 * // => 1.7976931348623157e+308
2947 var toInteger = Number;
2950 * Converts `value` to a number.
2955 * @param {*} value The value to process.
2956 * @returns {number} Returns the number.
2962 * _.toNumber(Number.MIN_VALUE);
2965 * _.toNumber(Infinity);
2971 var toNumber = Number;
2974 * Converts `value` to a string if it's not one. An empty string is returned
2975 * for `null` and `undefined` values. The sign of `-0` is preserved.
2980 * @param {*} value The value to process.
2981 * @returns {string} Returns the string.
2990 * _.toString([1, 2, 3]);
2993 function toString(value) {
2994 if (typeof value == 'string') {
2997 return value == null ? '' : (value + '');
3000 /*------------------------------------------------------------------------*/
3003 * Assigns own enumerable properties of source objects to the destination
3004 * object. Source objects are applied from left to right. Subsequent sources
3005 * overwrite property assignments of previous sources.
3007 * **Note:** This method mutates `object` and is loosely based on
3008 * [`Object.assign`](https://mdn.io/Object/assign).
3013 * @param {Object} object The destination object.
3014 * @param {...Object} [sources] The source objects.
3015 * @returns {Object} Returns `object`.
3026 * Foo.prototype.d = 4;
3027 * Bar.prototype.f = 6;
3029 * _.assign({ 'a': 1 }, new Foo, new Bar);
3030 * // => { 'a': 1, 'c': 3, 'e': 5 }
3032 var assign = createAssigner(function(object, source) {
3033 copyObject(source, keys(source), object);
3037 * This method is like `_.assign` except that it iterates over own and
3038 * inherited source properties.
3040 * **Note:** This method mutates `object`.
3046 * @param {Object} object The destination object.
3047 * @param {...Object} [sources] The source objects.
3048 * @returns {Object} Returns `object`.
3059 * Foo.prototype.c = 3;
3060 * Bar.prototype.e = 5;
3062 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
3063 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
3065 var assignIn = createAssigner(function(object, source) {
3066 copyObject(source, keysIn(source), object);
3070 * This method is like `_.assignIn` except that it accepts `customizer` which
3071 * is invoked to produce the assigned values. If `customizer` returns `undefined`
3072 * assignment is handled by the method instead. The `customizer` is invoked
3073 * with five arguments: (objValue, srcValue, key, object, source).
3075 * **Note:** This method mutates `object`.
3081 * @param {Object} object The destination object.
3082 * @param {...Object} sources The source objects.
3083 * @param {Function} [customizer] The function to customize assigned values.
3084 * @returns {Object} Returns `object`.
3087 * function customizer(objValue, srcValue) {
3088 * return _.isUndefined(objValue) ? srcValue : objValue;
3091 * var defaults = _.partialRight(_.assignInWith, customizer);
3093 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3094 * // => { 'a': 1, 'b': 2 }
3096 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
3097 copyObjectWith(source, keysIn(source), object, customizer);
3101 * Creates an object that inherits from the `prototype` object. If a `properties`
3102 * object is given its own enumerable properties are assigned to the created object.
3107 * @param {Object} prototype The object to inherit from.
3108 * @param {Object} [properties] The properties to assign to the object.
3109 * @returns {Object} Returns the new object.
3112 * function Shape() {
3117 * function Circle() {
3121 * Circle.prototype = _.create(Shape.prototype, {
3122 * 'constructor': Circle
3125 * var circle = new Circle;
3126 * circle instanceof Circle;
3129 * circle instanceof Shape;
3132 function create(prototype, properties) {
3133 var result = baseCreate(prototype);
3134 return properties ? assign(result, properties) : result;
3138 * Assigns own and inherited enumerable properties of source objects to the
3139 * destination object for all destination properties that resolve to `undefined`.
3140 * Source objects are applied from left to right. Once a property is set,
3141 * additional values of the same property are ignored.
3143 * **Note:** This method mutates `object`.
3148 * @param {Object} object The destination object.
3149 * @param {...Object} [sources] The source objects.
3150 * @returns {Object} Returns `object`.
3153 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
3154 * // => { 'user': 'barney', 'age': 36 }
3156 var defaults = rest(function(args) {
3157 args.push(undefined, assignInDefaults);
3158 return assignInWith.apply(undefined, args);
3162 * Checks if `path` is a direct property of `object`.
3167 * @param {Object} object The object to query.
3168 * @param {Array|string} path The path to check.
3169 * @returns {boolean} Returns `true` if `path` exists, else `false`.
3172 * var object = { 'a': { 'b': { 'c': 3 } } };
3173 * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
3175 * _.has(object, 'a');
3178 * _.has(object, 'a.b.c');
3181 * _.has(object, ['a', 'b', 'c']);
3184 * _.has(other, 'a');
3187 function has(object, path) {
3188 return object != null && hasOwnProperty.call(object, path);
3192 * Creates an array of the own enumerable property names of `object`.
3194 * **Note:** Non-object values are coerced to objects. See the
3195 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
3201 * @param {Object} object The object to query.
3202 * @returns {Array} Returns the array of property names.
3210 * Foo.prototype.c = 3;
3213 * // => ['a', 'b'] (iteration order is not guaranteed)
3218 function keys(object) {
3219 var isProto = isPrototype(object);
3220 if (!(isProto || isArrayLike(object))) {
3221 return baseKeys(object);
3223 var indexes = indexKeys(object),
3224 skipIndexes = !!indexes,
3225 result = indexes || [],
3226 length = result.length;
3228 for (var key in object) {
3229 if (hasOwnProperty.call(object, key) &&
3230 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3231 !(isProto && key == 'constructor')) {
3239 * Creates an array of the own and inherited enumerable property names of `object`.
3241 * **Note:** Non-object values are coerced to objects.
3246 * @param {Object} object The object to query.
3247 * @returns {Array} Returns the array of property names.
3255 * Foo.prototype.c = 3;
3257 * _.keysIn(new Foo);
3258 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3260 function keysIn(object) {
3262 isProto = isPrototype(object),
3263 props = baseKeysIn(object),
3264 propsLength = props.length,
3265 indexes = indexKeys(object),
3266 skipIndexes = !!indexes,
3267 result = indexes || [],
3268 length = result.length;
3270 while (++index < propsLength) {
3271 var key = props[index];
3272 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3273 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3281 * Creates an object composed of the picked `object` properties.
3286 * @param {Object} object The source object.
3287 * @param {...(string|string[])} [props] The property names to pick, specified
3288 * individually or in arrays.
3289 * @returns {Object} Returns the new object.
3292 * var object = { 'a': 1, 'b': '2', 'c': 3 };
3294 * _.pick(object, ['a', 'c']);
3295 * // => { 'a': 1, 'c': 3 }
3297 var pick = rest(function(object, props) {
3298 return object == null ? {} : basePick(object, baseFlatten(props));
3302 * This method is like `_.get` except that if the resolved value is a function
3303 * it's invoked with the `this` binding of its parent object and its result
3309 * @param {Object} object The object to query.
3310 * @param {Array|string} path The path of the property to resolve.
3311 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
3312 * @returns {*} Returns the resolved value.
3315 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3317 * _.result(object, 'a[0].b.c1');
3320 * _.result(object, 'a[0].b.c2');
3323 * _.result(object, 'a[0].b.c3', 'default');
3326 * _.result(object, 'a[0].b.c3', _.constant('default'));
3329 function result(object, path, defaultValue) {
3330 var value = object == null ? undefined : object[path];
3331 if (value === undefined) {
3332 value = defaultValue;
3334 return isFunction(value) ? value.call(object) : value;
3338 * Creates an array of the own enumerable property values of `object`.
3340 * **Note:** Non-object values are coerced to objects.
3345 * @param {Object} object The object to query.
3346 * @returns {Array} Returns the array of property values.
3354 * Foo.prototype.c = 3;
3356 * _.values(new Foo);
3357 * // => [1, 2] (iteration order is not guaranteed)
3362 function values(object) {
3363 return object ? baseValues(object, keys(object)) : [];
3366 /*------------------------------------------------------------------------*/
3369 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
3370 * their corresponding HTML entities.
3372 * **Note:** No other characters are escaped. To escape additional
3373 * characters use a third-party library like [_he_](https://mths.be/he).
3375 * Though the ">" character is escaped for symmetry, characters like
3376 * ">" and "/" don't need escaping in HTML and have no special meaning
3377 * unless they're part of a tag or unquoted attribute value.
3378 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3379 * (under "semi-related fun fact") for more details.
3381 * Backticks are escaped because in IE < 9, they can break out of
3382 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
3383 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
3384 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
3387 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
3388 * to reduce XSS vectors.
3393 * @param {string} [string=''] The string to escape.
3394 * @returns {string} Returns the escaped string.
3397 * _.escape('fred, barney, & pebbles');
3398 * // => 'fred, barney, & pebbles'
3400 function escape(string) {
3401 string = toString(string);
3402 return (string && reHasUnescapedHtml.test(string))
3403 ? string.replace(reUnescapedHtml, escapeHtmlChar)
3407 /*------------------------------------------------------------------------*/
3410 * This method returns the first argument given to it.
3415 * @param {*} value Any value.
3416 * @returns {*} Returns `value`.
3419 * var object = { 'user': 'fred' };
3421 * _.identity(object) === object;
3424 function identity(value) {
3429 * Creates a function that invokes `func` with the arguments of the created
3430 * function. If `func` is a property name the created callback returns the
3431 * property value for a given element. If `func` is an object the created
3432 * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`.
3437 * @param {*} [func=_.identity] The value to convert to a callback.
3438 * @returns {Function} Returns the callback.
3442 * { 'user': 'barney', 'age': 36 },
3443 * { 'user': 'fred', 'age': 40 }
3446 * // Create custom iteratee shorthands.
3447 * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
3448 * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
3449 * return !p ? callback(func) : function(object) {
3450 * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
3454 * _.filter(users, 'age > 36');
3455 * // => [{ 'user': 'fred', 'age': 40 }]
3457 var iteratee = baseIteratee;
3460 * Creates a function that performs a deep partial comparison between a given
3461 * object and `source`, returning `true` if the given object has equivalent
3462 * property values, else `false`.
3464 * **Note:** This method supports comparing the same values as `_.isEqual`.
3469 * @param {Object} source The object of property values to match.
3470 * @returns {Function} Returns the new function.
3474 * { 'user': 'barney', 'age': 36, 'active': true },
3475 * { 'user': 'fred', 'age': 40, 'active': false }
3478 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
3479 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
3481 function matches(source) {
3482 return baseMatches(assign({}, source));
3486 * Adds all own enumerable function properties of a source object to the
3487 * destination object. If `object` is a function then methods are added to
3488 * its prototype as well.
3490 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3491 * avoid conflicts caused by modifying the original.
3496 * @param {Function|Object} [object=lodash] The destination object.
3497 * @param {Object} source The object of functions to add.
3498 * @param {Object} [options] The options object.
3499 * @param {boolean} [options.chain=true] Specify whether the functions added
3501 * @returns {Function|Object} Returns `object`.
3504 * function vowels(string) {
3505 * return _.filter(string, function(v) {
3506 * return /[aeiou]/i.test(v);
3510 * _.mixin({ 'vowels': vowels });
3514 * _('fred').vowels().value();
3517 * _.mixin({ 'vowels': vowels }, { 'chain': false });
3518 * _('fred').vowels();
3521 function mixin(object, source, options) {
3522 var props = keys(source),
3523 methodNames = baseFunctions(source, props);
3525 if (options == null &&
3526 !(isObject(source) && (methodNames.length || !props.length))) {
3530 methodNames = baseFunctions(source, keys(source));
3532 var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
3533 isFunc = isFunction(object);
3535 baseEach(methodNames, function(methodName) {
3536 var func = source[methodName];
3537 object[methodName] = func;
3539 object.prototype[methodName] = function() {
3540 var chainAll = this.__chain__;
3541 if (chain || chainAll) {
3542 var result = object(this.__wrapped__),
3543 actions = result.__actions__ = copyArray(this.__actions__);
3545 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3546 result.__chain__ = chainAll;
3549 return func.apply(object, arrayPush([this.value()], arguments));
3558 * Reverts the `_` variable to its previous value and returns a reference to
3559 * the `lodash` function.
3564 * @returns {Function} Returns the `lodash` function.
3567 * var lodash = _.noConflict();
3569 function noConflict() {
3570 if (root._ === this) {
3577 * A no-operation function that returns `undefined` regardless of the
3578 * arguments it receives.
3585 * var object = { 'user': 'fred' };
3587 * _.noop(object) === undefined;
3591 // No operation performed.
3595 * Generates a unique ID. If `prefix` is given the ID is appended to it.
3600 * @param {string} [prefix] The value to prefix the ID with.
3601 * @returns {string} Returns the unique ID.
3604 * _.uniqueId('contact_');
3605 * // => 'contact_104'
3610 function uniqueId(prefix) {
3611 var id = ++idCounter;
3612 return toString(prefix) + id;
3615 /*------------------------------------------------------------------------*/
3618 * Computes the maximum value of `array`. If `array` is empty or falsey
3619 * `undefined` is returned.
3624 * @param {Array} array The array to iterate over.
3625 * @returns {*} Returns the maximum value.
3628 * _.max([4, 2, 8, 6]);
3634 function max(array) {
3635 return (array && array.length)
3636 ? baseExtremum(array, identity, gt)
3641 * Computes the minimum value of `array`. If `array` is empty or falsey
3642 * `undefined` is returned.
3647 * @param {Array} array The array to iterate over.
3648 * @returns {*} Returns the minimum value.
3651 * _.min([4, 2, 8, 6]);
3657 function min(array) {
3658 return (array && array.length)
3659 ? baseExtremum(array, identity, lt)
3663 /*------------------------------------------------------------------------*/
3665 LodashWrapper.prototype = baseCreate(lodash.prototype);
3666 LodashWrapper.prototype.constructor = LodashWrapper;
3668 // Add functions that return wrapped values when chaining.
3669 lodash.assignIn = assignIn;
3670 lodash.before = before;
3672 lodash.chain = chain;
3673 lodash.compact = compact;
3674 lodash.concat = concat;
3675 lodash.create = create;
3676 lodash.defaults = defaults;
3677 lodash.defer = defer;
3678 lodash.delay = delay;
3679 lodash.filter = filter;
3680 lodash.flatten = flatten;
3681 lodash.flattenDeep = flattenDeep;
3682 lodash.iteratee = iteratee;
3685 lodash.matches = matches;
3686 lodash.mixin = mixin;
3687 lodash.negate = negate;
3690 lodash.slice = slice;
3691 lodash.sortBy = sortBy;
3694 lodash.toArray = toArray;
3695 lodash.values = values;
3698 lodash.extend = assignIn;
3700 // Add functions to `lodash.prototype`.
3701 mixin(lodash, lodash);
3703 /*------------------------------------------------------------------------*/
3705 // Add functions that return unwrapped values when chaining.
3706 lodash.clone = clone;
3707 lodash.escape = escape;
3708 lodash.every = every;
3710 lodash.forEach = forEach;
3713 lodash.identity = identity;
3714 lodash.indexOf = indexOf;
3715 lodash.isArguments = isArguments;
3716 lodash.isArray = isArray;
3717 lodash.isBoolean = isBoolean;
3718 lodash.isDate = isDate;
3719 lodash.isEmpty = isEmpty;
3720 lodash.isEqual = isEqual;
3721 lodash.isFinite = isFinite;
3722 lodash.isFunction = isFunction;
3723 lodash.isNaN = isNaN;
3724 lodash.isNull = isNull;
3725 lodash.isNumber = isNumber;
3726 lodash.isObject = isObject;
3727 lodash.isRegExp = isRegExp;
3728 lodash.isString = isString;
3729 lodash.isUndefined = isUndefined;
3733 lodash.noConflict = noConflict;
3735 lodash.reduce = reduce;
3736 lodash.result = result;
3739 lodash.uniqueId = uniqueId;
3742 lodash.each = forEach;
3743 lodash.first = head;
3745 mixin(lodash, (function() {
3747 baseForOwn(lodash, function(func, methodName) {
3748 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3749 source[methodName] = func;
3753 }()), { 'chain': false });
3755 /*------------------------------------------------------------------------*/
3758 * The semantic version number.
3764 lodash.VERSION = VERSION;
3766 // Add `Array` and `String` methods to `lodash.prototype`.
3767 baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3768 var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3769 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3770 retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3772 lodash.prototype[methodName] = function() {
3773 var args = arguments;
3774 if (retUnwrapped && !this.__chain__) {
3775 return func.apply(this.value(), args);
3777 return this[chainName](function(value) {
3778 return func.apply(value, args);
3783 // Add chaining functions to the `lodash` wrapper.
3784 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3786 /*--------------------------------------------------------------------------*/
3788 // Expose lodash on the free variable `window` or `self` when available. This
3789 // prevents errors in cases where lodash is loaded by a script tag in the presence
3790 // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
3791 (freeWindow || freeSelf || {})._ = lodash;
3793 // Some AMD build optimizers like r.js check for condition patterns like the following:
3794 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3795 // Define as an anonymous module so, through path mapping, it can be
3796 // referenced as the "underscore" module.
3801 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
3802 else if (freeExports && freeModule) {
3803 // Export for Node.js.
3804 if (moduleExports) {
3805 (freeModule.exports = lodash)._ = lodash;
3807 // Export for CommonJS support.
3808 freeExports._ = lodash;
3811 // Export to the global object.