3 * lodash 4.0.1 (Custom Build) <https://lodash.com/>
4 * Build: `lodash core -o ./dist/lodash.core.js`
5 * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
15 /** Used as the semantic version number. */
16 var VERSION = '4.0.1';
18 /** Used to compose bitmasks for wrapper metadata. */
22 /** Used to compose bitmasks for comparison styles. */
23 var UNORDERED_COMPARE_FLAG = 1,
24 PARTIAL_COMPARE_FLAG = 2;
26 /** Used as the `TypeError` message for "Functions" methods. */
27 var FUNC_ERROR_TEXT = 'Expected a function';
29 /** Used as references for various `Number` constants. */
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`, `invokeMap`,
424 * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
425 * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
426 * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`,
427 * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
428 * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
429 * `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
430 * `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
431 * `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`,
432 * `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`,
433 * `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`,
434 * `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`,
435 * `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`,
436 * `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith`
438 * The wrapper methods that are **not** chainable by default are:
439 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
440 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
441 * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
442 * `findLast`, `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`,
443 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
444 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
445 * `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
446 * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
447 * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`, `isMatchWith`,
448 * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`,
449 * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isString`, `isUndefined`,
450 * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`,
451 * `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`,
452 * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`,
453 * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
454 * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
455 * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
456 * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toLower`,
457 * `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`,
458 * `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
459 * `upperCase`, `upperFirst`, `value`, and `words`
464 * @param {*} value The value to wrap in a `lodash` instance.
465 * @returns {Object} Returns the new `lodash` wrapper instance.
468 * function square(n) {
472 * var wrapped = _([1, 2, 3]);
474 * // returns an unwrapped value
475 * wrapped.reduce(_.add);
478 * // returns a wrapped value
479 * var squares = wrapped.map(square);
481 * _.isArray(squares);
484 * _.isArray(squares.value());
487 function lodash(value) {
488 if (isObjectLike(value) && !isArray(value)) {
489 if (value instanceof LodashWrapper) {
492 if (hasOwnProperty.call(value, '__wrapped__')) {
493 return wrapperClone(value);
496 return new LodashWrapper(value);
500 * The base constructor for creating `lodash` wrapper objects.
503 * @param {*} value The value to wrap.
504 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
506 function LodashWrapper(value, chainAll) {
507 this.__wrapped__ = value;
508 this.__actions__ = [];
509 this.__chain__ = !!chainAll;
512 /*------------------------------------------------------------------------*/
515 * Used by `_.defaults` to customize its `_.assignIn` use.
518 * @param {*} objValue The destination value.
519 * @param {*} srcValue The source value.
520 * @param {string} key The key of the property to assign.
521 * @param {Object} object The parent object of `objValue`.
522 * @returns {*} Returns the value to assign.
524 function assignInDefaults(objValue, srcValue, key, object) {
525 if (objValue === undefined ||
526 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
533 * Assigns `value` to `key` of `object` if the existing value is not equivalent
534 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
535 * for equality comparisons.
538 * @param {Object} object The object to modify.
539 * @param {string} key The key of the property to assign.
540 * @param {*} value The value to assign.
542 function assignValue(object, key, value) {
543 var objValue = object[key];
544 if ((!eq(objValue, value) ||
545 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
546 (value === undefined && !(key in object))) {
552 * The base implementation of `_.create` without support for assigning
553 * properties to the created object.
556 * @param {Object} prototype The object to inherit from.
557 * @returns {Object} Returns the new object.
559 var baseCreate = (function() {
561 return function(prototype) {
562 if (isObject(prototype)) {
563 object.prototype = prototype;
564 var result = new object;
565 object.prototype = undefined;
572 * The base implementation of `_.delay` and `_.defer` which accepts an array
573 * of `func` arguments.
576 * @param {Function} func The function to delay.
577 * @param {number} wait The number of milliseconds to delay invocation.
578 * @param {Object} args The arguments provide to `func`.
579 * @returns {number} Returns the timer id.
581 function baseDelay(func, wait, args) {
582 if (typeof func != 'function') {
583 throw new TypeError(FUNC_ERROR_TEXT);
585 return setTimeout(function() { func.apply(undefined, args); }, wait);
589 * The base implementation of `_.forEach` without support for iteratee shorthands.
592 * @param {Array|Object} collection The collection to iterate over.
593 * @param {Function} iteratee The function invoked per iteration.
594 * @returns {Array|Object} Returns `collection`.
596 var baseEach = createBaseEach(baseForOwn);
599 * The base implementation of `_.every` without support for iteratee shorthands.
602 * @param {Array|Object} collection The collection to iterate over.
603 * @param {Function} predicate The function invoked per iteration.
604 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
606 function baseEvery(collection, predicate) {
608 baseEach(collection, function(value, index, collection) {
609 result = !!predicate(value, index, collection);
616 * The base implementation of `_.filter` without support for iteratee shorthands.
619 * @param {Array|Object} collection The collection to iterate over.
620 * @param {Function} predicate The function invoked per iteration.
621 * @returns {Array} Returns the new filtered array.
623 function baseFilter(collection, predicate) {
625 baseEach(collection, function(value, index, collection) {
626 if (predicate(value, index, collection)) {
634 * The base implementation of `_.flatten` with support for restricting flattening.
637 * @param {Array} array The array to flatten.
638 * @param {boolean} [isDeep] Specify a deep flatten.
639 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
640 * @param {Array} [result=[]] The initial result value.
641 * @returns {Array} Returns the new flattened array.
643 function baseFlatten(array, isDeep, isStrict, result) {
644 result || (result = []);
647 length = array.length;
649 while (++index < length) {
650 var value = array[index];
651 if (isArrayLikeObject(value) &&
652 (isStrict || isArray(value) || isArguments(value))) {
654 // Recursively flatten arrays (susceptible to call stack limits).
655 baseFlatten(value, isDeep, isStrict, result);
657 arrayPush(result, value);
659 } else if (!isStrict) {
660 result[result.length] = value;
667 * The base implementation of `baseForIn` and `baseForOwn` which iterates
668 * over `object` properties returned by `keysFunc` invoking `iteratee` for
669 * each property. Iteratee functions may exit iteration early by explicitly
673 * @param {Object} object The object to iterate over.
674 * @param {Function} iteratee The function invoked per iteration.
675 * @param {Function} keysFunc The function to get the keys of `object`.
676 * @returns {Object} Returns `object`.
678 var baseFor = createBaseFor();
681 * The base implementation of `_.forOwn` without support for iteratee shorthands.
684 * @param {Object} object The object to iterate over.
685 * @param {Function} iteratee The function invoked per iteration.
686 * @returns {Object} Returns `object`.
688 function baseForOwn(object, iteratee) {
689 return object && baseFor(object, iteratee, keys);
693 * The base implementation of `_.functions` which creates an array of
694 * `object` function property names filtered from those provided.
697 * @param {Object} object The object to inspect.
698 * @param {Array} props The property names to filter.
699 * @returns {Array} Returns the new array of filtered property names.
701 function baseFunctions(object, props) {
702 return baseFilter(props, function(key) {
703 return isFunction(object[key]);
708 * The base implementation of `_.isEqual` which supports partial comparisons
709 * and tracks traversed objects.
712 * @param {*} value The value to compare.
713 * @param {*} other The other value to compare.
714 * @param {Function} [customizer] The function to customize comparisons.
715 * @param {boolean} [bitmask] The bitmask of comparison flags.
716 * The bitmask may be composed of the following flags:
717 * 1 - Unordered comparison
718 * 2 - Partial comparison
719 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
720 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
722 function baseIsEqual(value, other, customizer, bitmask, stack) {
723 if (value === other) {
726 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
727 return value !== value && other !== other;
729 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
733 * A specialized version of `baseIsEqual` for arrays and objects which performs
734 * deep comparisons and tracks traversed objects enabling objects with circular
735 * references to be compared.
738 * @param {Object} object The object to compare.
739 * @param {Object} other The other object to compare.
740 * @param {Function} equalFunc The function to determine equivalents of values.
741 * @param {Function} [customizer] The function to customize comparisons.
742 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
743 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
744 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
746 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
747 var objIsArr = isArray(object),
748 othIsArr = isArray(other),
753 objTag = objectToString.call(object);
754 if (objTag == argsTag) {
759 othTag = objectToString.call(other);
760 if (othTag == argsTag) {
764 var objIsObj = objTag == objectTag && !isHostObject(object),
765 othIsObj = othTag == objectTag && !isHostObject(other),
766 isSameTag = objTag == othTag;
768 if (isSameTag && !(objIsArr || objIsObj)) {
769 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
771 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
773 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
774 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
776 if (objIsWrapped || othIsWrapped) {
777 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
783 stack || (stack = []);
784 var stacked = find(stack, function(entry) {
785 return entry[0] === object;
787 if (stacked && stacked[1]) {
788 return stacked[1] == other;
790 stack.push([object, other]);
791 var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
797 * The base implementation of `_.iteratee`.
800 * @param {*} [value=_.identity] The value to convert to an iteratee.
801 * @returns {Function} Returns the iteratee.
803 function baseIteratee(func) {
804 var type = typeof func;
805 if (type == 'function') {
810 : (type == 'object' ? baseMatches : baseProperty)(func);
814 * The base implementation of `_.keys` which doesn't skip the constructor
815 * property of prototypes or treat sparse arrays as dense.
819 * @param {Object} object The object to query.
820 * @returns {Array} Returns the array of property names.
822 function baseKeys(object) {
823 return nativeKeys(Object(object));
827 * The base implementation of `_.keysIn` which doesn't skip the constructor
828 * property of prototypes or treat sparse arrays as dense.
831 * @param {Object} object The object to query.
832 * @returns {Array} Returns the array of property names.
834 function baseKeysIn(object) {
835 object = object == null ? object : Object(object);
838 for (var key in object) {
844 // Fallback for IE < 9 with es6-shim.
845 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
846 baseKeysIn = function(object) {
847 return iteratorToArray(enumerate(object));
852 * The base implementation of `_.map` without support for iteratee shorthands.
855 * @param {Array|Object} collection The collection to iterate over.
856 * @param {Function} iteratee The function invoked per iteration.
857 * @returns {Array} Returns the new mapped array.
859 function baseMap(collection, iteratee) {
861 result = isArrayLike(collection) ? Array(collection.length) : [];
863 baseEach(collection, function(value, key, collection) {
864 result[++index] = iteratee(value, key, collection);
870 * The base implementation of `_.matches` which doesn't clone `source`.
873 * @param {Object} source The object of property values to match.
874 * @returns {Function} Returns the new function.
876 function baseMatches(source) {
877 var props = keys(source);
878 return function(object) {
879 var length = props.length;
880 if (object == null) {
883 object = Object(object);
885 var key = props[length];
886 if (!(key in object &&
887 baseIsEqual(source[key], object[key], undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG)
897 * The base implementation of `_.pick` without support for individual
901 * @param {Object} object The source object.
902 * @param {string[]} props The property names to pick.
903 * @returns {Object} Returns the new object.
905 function basePick(object, props) {
906 object = Object(object);
907 return reduce(props, function(result, key) {
909 result[key] = object[key];
916 * The base implementation of `_.property` without support for deep paths.
919 * @param {string} key The key of the property to get.
920 * @returns {Function} Returns the new function.
922 function baseProperty(key) {
923 return function(object) {
924 return object == null ? undefined : object[key];
929 * The base implementation of `_.slice` without an iteratee call guard.
932 * @param {Array} array The array to slice.
933 * @param {number} [start=0] The start position.
934 * @param {number} [end=array.length] The end position.
935 * @returns {Array} Returns the slice of `array`.
937 function baseSlice(array, start, end) {
939 length = array.length;
942 start = -start > length ? 0 : (length + start);
944 end = end > length ? length : end;
948 length = start > end ? 0 : ((end - start) >>> 0);
951 var result = Array(length);
952 while (++index < length) {
953 result[index] = array[index + start];
959 * Copies the values of `source` to `array`.
962 * @param {Array} source The array to copy values from.
963 * @param {Array} [array=[]] The array to copy values to.
964 * @returns {Array} Returns `array`.
966 function copyArray(source) {
967 return baseSlice(source, 0, source.length);
971 * The base implementation of `_.some` without support for iteratee shorthands.
974 * @param {Array|Object} collection The collection to iterate over.
975 * @param {Function} predicate The function invoked per iteration.
976 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
978 function baseSome(collection, predicate) {
981 baseEach(collection, function(value, index, collection) {
982 result = predicate(value, index, collection);
989 * The base implementation of `wrapperValue` which returns the result of
990 * performing a sequence of actions on the unwrapped `value`, where each
991 * successive action is supplied the return value of the previous.
994 * @param {*} value The unwrapped value.
995 * @param {Array} actions Actions to perform to resolve the unwrapped value.
996 * @returns {*} Returns the resolved value.
998 function baseWrapperValue(value, actions) {
1000 return reduce(actions, function(result, action) {
1001 return action.func.apply(action.thisArg, arrayPush([result], action.args));
1006 * Copies properties of `source` to `object`.
1009 * @param {Object} source The object to copy properties from.
1010 * @param {Array} props The property names to copy.
1011 * @param {Object} [object={}] The object to copy properties to.
1012 * @returns {Object} Returns `object`.
1014 var copyObject = copyObjectWith;
1017 * This function is like `copyObject` except that it accepts a function to
1018 * customize copied values.
1021 * @param {Object} source The object to copy properties from.
1022 * @param {Array} props The property names to copy.
1023 * @param {Object} [object={}] The object to copy properties to.
1024 * @param {Function} [customizer] The function to customize copied values.
1025 * @returns {Object} Returns `object`.
1027 function copyObjectWith(source, props, object, customizer) {
1028 object || (object = {});
1031 length = props.length;
1033 while (++index < length) {
1034 var key = props[index],
1035 newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
1037 assignValue(object, key, newValue);
1043 * Creates a function like `_.assign`.
1046 * @param {Function} assigner The function to assign values.
1047 * @returns {Function} Returns the new assigner function.
1049 function createAssigner(assigner) {
1050 return rest(function(object, sources) {
1052 length = sources.length,
1053 customizer = length > 1 ? sources[length - 1] : undefined;
1055 customizer = typeof customizer == 'function' ? (length--, customizer) : undefined;
1056 object = Object(object);
1057 while (++index < length) {
1058 var source = sources[index];
1060 assigner(object, source, index, customizer);
1068 * Creates a `baseEach` or `baseEachRight` function.
1071 * @param {Function} eachFunc The function to iterate over a collection.
1072 * @param {boolean} [fromRight] Specify iterating from right to left.
1073 * @returns {Function} Returns the new base function.
1075 function createBaseEach(eachFunc, fromRight) {
1076 return function(collection, iteratee) {
1077 if (collection == null) {
1080 if (!isArrayLike(collection)) {
1081 return eachFunc(collection, iteratee);
1083 var length = collection.length,
1084 index = fromRight ? length : -1,
1085 iterable = Object(collection);
1087 while ((fromRight ? index-- : ++index < length)) {
1088 if (iteratee(iterable[index], index, iterable) === false) {
1097 * Creates a base function for methods like `_.forIn`.
1100 * @param {boolean} [fromRight] Specify iterating from right to left.
1101 * @returns {Function} Returns the new base function.
1103 function createBaseFor(fromRight) {
1104 return function(object, iteratee, keysFunc) {
1106 iterable = Object(object),
1107 props = keysFunc(object),
1108 length = props.length;
1111 var key = props[fromRight ? length : ++index];
1112 if (iteratee(iterable[key], key, iterable) === false) {
1121 * Creates a function that produces an instance of `Ctor` regardless of
1122 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
1125 * @param {Function} Ctor The constructor to wrap.
1126 * @returns {Function} Returns the new wrapped function.
1128 function createCtorWrapper(Ctor) {
1130 // Use a `switch` statement to work with class constructors.
1131 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1132 // for more details.
1133 var args = arguments;
1134 var thisBinding = baseCreate(Ctor.prototype),
1135 result = Ctor.apply(thisBinding, args);
1137 // Mimic the constructor's `return` behavior.
1138 // See https://es5.github.io/#x13.2.2 for more details.
1139 return isObject(result) ? result : thisBinding;
1144 * Creates a function that wraps `func` to invoke it with the optional `this`
1145 * binding of `thisArg` and the `partials` prepended to those provided to
1149 * @param {Function} func The function to wrap.
1150 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
1151 * @param {*} thisArg The `this` binding of `func`.
1152 * @param {Array} partials The arguments to prepend to those provided to the new function.
1153 * @returns {Function} Returns the new wrapped function.
1155 function createPartialWrapper(func, bitmask, thisArg, partials) {
1156 if (typeof func != 'function') {
1157 throw new TypeError(FUNC_ERROR_TEXT);
1159 var isBind = bitmask & BIND_FLAG,
1160 Ctor = createCtorWrapper(func);
1162 function wrapper() {
1164 argsLength = arguments.length,
1166 leftLength = partials.length,
1167 args = Array(leftLength + argsLength),
1168 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
1170 while (++leftIndex < leftLength) {
1171 args[leftIndex] = partials[leftIndex];
1173 while (argsLength--) {
1174 args[leftIndex++] = arguments[++argsIndex];
1176 return fn.apply(isBind ? thisArg : this, args);
1182 * A specialized version of `baseIsEqualDeep` for arrays with support for
1183 * partial deep comparisons.
1186 * @param {Array} array The array to compare.
1187 * @param {Array} other The other array to compare.
1188 * @param {Function} equalFunc The function to determine equivalents of values.
1189 * @param {Function} [customizer] The function to customize comparisons.
1190 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1191 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
1192 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1194 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
1196 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1197 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
1198 arrLength = array.length,
1199 othLength = other.length;
1201 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1206 // Ignore non-index properties.
1207 while (++index < arrLength) {
1208 var arrValue = array[index],
1209 othValue = other[index];
1212 if (compared !== undefined) {
1219 // Recursively compare arrays (susceptible to call stack limits).
1221 if (!baseSome(other, function(othValue) {
1222 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
1227 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
1236 * A specialized version of `baseIsEqualDeep` for comparing objects of
1237 * the same `toStringTag`.
1239 * **Note:** This function only supports comparing values with tags of
1240 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1243 * @param {Object} object The object to compare.
1244 * @param {Object} other The other object to compare.
1245 * @param {string} tag The `toStringTag` of the objects to compare.
1246 * @param {Function} equalFunc The function to determine equivalents of values.
1247 * @param {Function} [customizer] The function to customize comparisons.
1248 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1249 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1251 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
1256 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
1257 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
1258 return +object == +other;
1261 return object.name == other.name && object.message == other.message;
1264 // Treat `NaN` vs. `NaN` as equal.
1265 return (object != +object) ? other != +other : object == +other;
1269 // Coerce regexes to strings and treat strings primitives and string
1270 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
1271 return object == (other + '');
1278 * A specialized version of `baseIsEqualDeep` for objects with support for
1279 * partial deep comparisons.
1282 * @param {Object} object The object to compare.
1283 * @param {Object} other The other object to compare.
1284 * @param {Function} equalFunc The function to determine equivalents of values.
1285 * @param {Function} [customizer] The function to customize comparisons.
1286 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1287 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
1288 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1290 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
1291 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1292 objProps = keys(object),
1293 objLength = objProps.length,
1294 othProps = keys(other),
1295 othLength = othProps.length;
1297 if (objLength != othLength && !isPartial) {
1300 var index = objLength;
1302 var key = objProps[index];
1303 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1309 var skipCtor = isPartial;
1310 while (++index < objLength) {
1311 key = objProps[index];
1312 var objValue = object[key],
1313 othValue = other[key];
1316 // Recursively compare objects (susceptible to call stack limits).
1317 if (!(compared === undefined
1318 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
1324 skipCtor || (skipCtor = key == 'constructor');
1326 if (result && !skipCtor) {
1327 var objCtor = object.constructor,
1328 othCtor = other.constructor;
1330 // Non `Object` object instances with different constructors are not equal.
1331 if (objCtor != othCtor &&
1332 ('constructor' in object && 'constructor' in other) &&
1333 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1334 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1342 * Gets the "length" property value of `object`.
1344 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
1345 * that affects Safari on at least iOS 8.1-8.3 ARM64.
1348 * @param {Object} object The object to query.
1349 * @returns {*} Returns the "length" value.
1351 var getLength = baseProperty('length');
1354 * Creates an array of index keys for `object` values of arrays,
1355 * `arguments` objects, and strings, otherwise `null` is returned.
1358 * @param {Object} object The object to query.
1359 * @returns {Array|null} Returns index keys, else `null`.
1361 function indexKeys(object) {
1362 var length = object ? object.length : undefined;
1363 return (isLength(length) && (isArray(object) || isString(object) || isArguments(object)))
1364 ? baseTimes(length, String)
1369 * Checks if `value` is likely a prototype object.
1372 * @param {*} value The value to check.
1373 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1375 function isPrototype(value) {
1376 var Ctor = value && value.constructor,
1377 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1379 return value === proto;
1383 * Converts `value` to a function if it's not one.
1386 * @param {*} value The value to process.
1387 * @returns {Function} Returns the function.
1389 function toFunction(value) {
1390 return typeof value == 'function' ? value : identity;
1394 * Creates a clone of `wrapper`.
1397 * @param {Object} wrapper The wrapper to clone.
1398 * @returns {Object} Returns the cloned wrapper.
1400 function wrapperClone(wrapper) {
1401 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
1402 result.__actions__ = copyArray(wrapper.__actions__);
1406 /*------------------------------------------------------------------------*/
1409 * Creates an array with all falsey values removed. The values `false`, `null`,
1410 * `0`, `""`, `undefined`, and `NaN` are falsey.
1415 * @param {Array} array The array to compact.
1416 * @returns {Array} Returns the new array of filtered values.
1419 * _.compact([0, 1, false, 2, '', 3]);
1422 function compact(array) {
1423 return baseFilter(array, Boolean);
1427 * Creates a new array concatenating `array` with any additional arrays
1433 * @param {Array} array The array to concatenate.
1434 * @param {...*} [values] The values to concatenate.
1435 * @returns {Array} Returns the new concatenated array.
1439 * var other = _.concat(array, 2, [3], [[4]]);
1441 * console.log(other);
1442 * // => [1, 2, 3, [4]]
1444 * console.log(array);
1447 var concat = rest(function(array, values) {
1448 if (!isArray(array)) {
1449 array = array == null ? [] : [Object(array)];
1451 values = baseFlatten(values);
1452 return arrayConcat(array, values);
1456 * Flattens `array` a single level.
1461 * @param {Array} array The array to flatten.
1462 * @returns {Array} Returns the new flattened array.
1465 * _.flatten([1, [2, 3, [4]]]);
1466 * // => [1, 2, 3, [4]]
1468 function flatten(array) {
1469 var length = array ? array.length : 0;
1470 return length ? baseFlatten(array) : [];
1474 * This method is like `_.flatten` except that it recursively flattens `array`.
1479 * @param {Array} array The array to recursively flatten.
1480 * @returns {Array} Returns the new flattened array.
1483 * _.flattenDeep([1, [2, 3, [4]]]);
1484 * // => [1, 2, 3, 4]
1486 function flattenDeep(array) {
1487 var length = array ? array.length : 0;
1488 return length ? baseFlatten(array, true) : [];
1492 * Gets the first element of `array`.
1498 * @param {Array} array The array to query.
1499 * @returns {*} Returns the first element of `array`.
1502 * _.head([1, 2, 3]);
1508 function head(array) {
1509 return array ? array[0] : undefined;
1513 * Gets the index at which the first occurrence of `value` is found in `array`
1514 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
1515 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
1516 * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
1517 * performs a faster binary search.
1522 * @param {Array} array The array to search.
1523 * @param {*} value The value to search for.
1524 * @param {number} [fromIndex=0] The index to search from.
1525 * @returns {number} Returns the index of the matched value, else `-1`.
1528 * _.indexOf([1, 2, 1, 2], 2);
1531 * // using `fromIndex`
1532 * _.indexOf([1, 2, 1, 2], 2, 2);
1535 function indexOf(array, value, fromIndex) {
1536 var length = array ? array.length : 0;
1537 if (typeof fromIndex == 'number') {
1538 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1542 var index = (fromIndex || 0) - 1,
1543 isReflexive = value === value;
1545 while (++index < length) {
1546 var other = array[index];
1547 if ((isReflexive ? other === value : other !== other)) {
1555 * Gets the last element of `array`.
1560 * @param {Array} array The array to query.
1561 * @returns {*} Returns the last element of `array`.
1564 * _.last([1, 2, 3]);
1567 function last(array) {
1568 var length = array ? array.length : 0;
1569 return length ? array[length - 1] : undefined;
1573 * Creates a slice of `array` from `start` up to, but not including, `end`.
1575 * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
1576 * to ensure dense arrays are returned.
1581 * @param {Array} array The array to slice.
1582 * @param {number} [start=0] The start position.
1583 * @param {number} [end=array.length] The end position.
1584 * @returns {Array} Returns the slice of `array`.
1586 function slice(array, start, end) {
1587 var length = array ? array.length : 0;
1588 start = start == null ? 0 : +start;
1589 end = end === undefined ? length : +end;
1590 return length ? baseSlice(array, start, end) : [];
1593 /*------------------------------------------------------------------------*/
1596 * Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
1597 * The result of such method chaining must be unwrapped with `_#value`.
1602 * @param {*} value The value to wrap.
1603 * @returns {Object} Returns the new `lodash` wrapper instance.
1607 * { 'user': 'barney', 'age': 36 },
1608 * { 'user': 'fred', 'age': 40 },
1609 * { 'user': 'pebbles', 'age': 1 }
1615 * .map(function(o) {
1616 * return o.user + ' is ' + o.age;
1620 * // => 'pebbles is 1'
1622 function chain(value) {
1623 var result = lodash(value);
1624 result.__chain__ = true;
1629 * This method invokes `interceptor` and returns `value`. The interceptor is
1630 * invoked with one argument; (value). The purpose of this method is to "tap into"
1631 * a method chain in order to perform operations on intermediate results within
1637 * @param {*} value The value to provide to `interceptor`.
1638 * @param {Function} interceptor The function to invoke.
1639 * @returns {*} Returns `value`.
1643 * .tap(function(array) {
1650 function tap(value, interceptor) {
1656 * This method is like `_.tap` except that it returns the result of `interceptor`.
1661 * @param {*} value The value to provide to `interceptor`.
1662 * @param {Function} interceptor The function to invoke.
1663 * @returns {*} Returns the result of `interceptor`.
1669 * .thru(function(value) {
1675 function thru(value, interceptor) {
1676 return interceptor(value);
1680 * Enables explicit method chaining on the wrapper object.
1685 * @returns {Object} Returns the new `lodash` wrapper instance.
1689 * { 'user': 'barney', 'age': 36 },
1690 * { 'user': 'fred', 'age': 40 }
1693 * // without explicit chaining
1695 * // => { 'user': 'barney', 'age': 36 }
1697 * // with explicit chaining
1703 * // => { 'user': 'barney' }
1705 function wrapperChain() {
1710 * Executes the chained sequence to extract the unwrapped value.
1714 * @alias toJSON, valueOf
1716 * @returns {*} Returns the resolved unwrapped value.
1719 * _([1, 2, 3]).value();
1722 function wrapperValue() {
1723 return baseWrapperValue(this.__wrapped__, this.__actions__);
1726 /*------------------------------------------------------------------------*/
1729 * Checks if `predicate` returns truthy for **all** elements of `collection`.
1730 * Iteration is stopped once `predicate` returns falsey. The predicate is
1731 * invoked with three arguments: (value, index|key, collection).
1735 * @category Collection
1736 * @param {Array|Object} collection The collection to iterate over.
1737 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1738 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
1739 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
1742 * _.every([true, 1, null, 'yes'], Boolean);
1746 * { 'user': 'barney', 'active': false },
1747 * { 'user': 'fred', 'active': false }
1750 * // using the `_.matches` iteratee shorthand
1751 * _.every(users, { 'user': 'barney', 'active': false });
1754 * // using the `_.matchesProperty` iteratee shorthand
1755 * _.every(users, ['active', false]);
1758 * // using the `_.property` iteratee shorthand
1759 * _.every(users, 'active');
1762 function every(collection, predicate, guard) {
1763 predicate = guard ? undefined : predicate;
1764 return baseEvery(collection, baseIteratee(predicate));
1768 * Iterates over elements of `collection`, returning an array of all elements
1769 * `predicate` returns truthy for. The predicate is invoked with three arguments:
1770 * (value, index|key, collection).
1774 * @category Collection
1775 * @param {Array|Object} collection The collection to iterate over.
1776 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1777 * @returns {Array} Returns the new filtered array.
1781 * { 'user': 'barney', 'age': 36, 'active': true },
1782 * { 'user': 'fred', 'age': 40, 'active': false }
1785 * _.filter(users, function(o) { return !o.active; });
1786 * // => objects for ['fred']
1788 * // using the `_.matches` iteratee shorthand
1789 * _.filter(users, { 'age': 36, 'active': true });
1790 * // => objects for ['barney']
1792 * // using the `_.matchesProperty` iteratee shorthand
1793 * _.filter(users, ['active', false]);
1794 * // => objects for ['fred']
1796 * // using the `_.property` iteratee shorthand
1797 * _.filter(users, 'active');
1798 * // => objects for ['barney']
1800 function filter(collection, predicate) {
1801 return baseFilter(collection, baseIteratee(predicate));
1805 * Iterates over elements of `collection`, returning the first element
1806 * `predicate` returns truthy for. The predicate is invoked with three arguments:
1807 * (value, index|key, collection).
1811 * @category Collection
1812 * @param {Array|Object} collection The collection to search.
1813 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1814 * @returns {*} Returns the matched element, else `undefined`.
1818 * { 'user': 'barney', 'age': 36, 'active': true },
1819 * { 'user': 'fred', 'age': 40, 'active': false },
1820 * { 'user': 'pebbles', 'age': 1, 'active': true }
1823 * _.find(users, function(o) { return o.age < 40; });
1824 * // => object for 'barney'
1826 * // using the `_.matches` iteratee shorthand
1827 * _.find(users, { 'age': 1, 'active': true });
1828 * // => object for 'pebbles'
1830 * // using the `_.matchesProperty` iteratee shorthand
1831 * _.find(users, ['active', false]);
1832 * // => object for 'fred'
1834 * // using the `_.property` iteratee shorthand
1835 * _.find(users, 'active');
1836 * // => object for 'barney'
1838 function find(collection, predicate) {
1839 return baseFind(collection, baseIteratee(predicate), baseEach);
1843 * Iterates over elements of `collection` invoking `iteratee` for each element.
1844 * The iteratee is invoked with three arguments: (value, index|key, collection).
1845 * Iteratee functions may exit iteration early by explicitly returning `false`.
1847 * **Note:** As with other "Collections" methods, objects with a "length" property
1848 * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
1849 * for object iteration.
1854 * @category Collection
1855 * @param {Array|Object} collection The collection to iterate over.
1856 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1857 * @returns {Array|Object} Returns `collection`.
1860 * _([1, 2]).forEach(function(value) {
1861 * console.log(value);
1863 * // => logs `1` then `2`
1865 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
1868 * // => logs 'a' then 'b' (iteration order is not guaranteed)
1870 function forEach(collection, iteratee) {
1871 return baseEach(collection, toFunction(iteratee));
1875 * Invokes the method at `path` of each element in `collection`, returning
1876 * an array of the results of each invoked method. Any additional arguments
1877 * are provided to each invoked method. If `methodName` is a function it's
1878 * invoked for, and `this` bound to, each element in `collection`.
1882 * @category Collection
1883 * @param {Array|Object} collection The collection to iterate over.
1884 * @param {Array|Function|string} path The path of the method to invoke or
1885 * the function invoked per iteration.
1886 * @param {...*} [args] The arguments to invoke each method with.
1887 * @returns {Array} Returns the array of results.
1890 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
1891 * // => [[1, 5, 7], [1, 2, 3]]
1893 * _.invokeMap([123, 456], String.prototype.split, '');
1894 * // => [['1', '2', '3'], ['4', '5', '6']]
1896 var invokeMap = rest(function(collection, path, args) {
1897 var isFunc = typeof path == 'function';
1898 return baseMap(collection, function(value) {
1899 var func = isFunc ? path : value[path];
1900 return func == null ? func : func.apply(value, args);
1905 * Creates an array of values by running each element in `collection` through
1906 * `iteratee`. The iteratee is invoked with three arguments:
1907 * (value, index|key, collection).
1909 * Many lodash methods are guarded to work as iteratees for methods like
1910 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
1912 * The guarded methods are:
1913 * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
1914 * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
1915 * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
1920 * @category Collection
1921 * @param {Array|Object} collection The collection to iterate over.
1922 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
1923 * @returns {Array} Returns the new mapped array.
1926 * function square(n) {
1930 * _.map([4, 8], square);
1933 * _.map({ 'a': 4, 'b': 8 }, square);
1934 * // => [16, 64] (iteration order is not guaranteed)
1937 * { 'user': 'barney' },
1938 * { 'user': 'fred' }
1941 * // using the `_.property` iteratee shorthand
1942 * _.map(users, 'user');
1943 * // => ['barney', 'fred']
1945 function map(collection, iteratee) {
1946 return baseMap(collection, baseIteratee(iteratee));
1950 * Reduces `collection` to a value which is the accumulated result of running
1951 * each element in `collection` through `iteratee`, where each successive
1952 * invocation is supplied the return value of the previous. If `accumulator`
1953 * is not provided the first element of `collection` is used as the initial
1954 * value. The iteratee is invoked with four arguments:
1955 * (accumulator, value, index|key, collection).
1957 * Many lodash methods are guarded to work as iteratees for methods like
1958 * `_.reduce`, `_.reduceRight`, and `_.transform`.
1960 * The guarded methods are:
1961 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
1966 * @category Collection
1967 * @param {Array|Object} collection The collection to iterate over.
1968 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1969 * @param {*} [accumulator] The initial value.
1970 * @returns {*} Returns the accumulated value.
1973 * _.reduce([1, 2], function(sum, n) {
1978 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
1979 * (result[value] || (result[value] = [])).push(key);
1982 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
1984 function reduce(collection, iteratee, accumulator) {
1985 return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
1989 * Gets the size of `collection` by returning its length for array-like
1990 * values or the number of own enumerable properties for objects.
1994 * @category Collection
1995 * @param {Array|Object} collection The collection to inspect.
1996 * @returns {number} Returns the collection size.
1999 * _.size([1, 2, 3]);
2002 * _.size({ 'a': 1, 'b': 2 });
2005 * _.size('pebbles');
2008 function size(collection) {
2009 if (collection == null) {
2012 collection = isArrayLike(collection) ? collection : keys(collection);
2013 return collection.length;
2017 * Checks if `predicate` returns truthy for **any** element of `collection`.
2018 * Iteration is stopped once `predicate` returns truthy. The predicate is
2019 * invoked with three arguments: (value, index|key, collection).
2023 * @category Collection
2024 * @param {Array|Object} collection The collection to iterate over.
2025 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
2026 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
2027 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
2030 * _.some([null, 0, 'yes', false], Boolean);
2034 * { 'user': 'barney', 'active': true },
2035 * { 'user': 'fred', 'active': false }
2038 * // using the `_.matches` iteratee shorthand
2039 * _.some(users, { 'user': 'barney', 'active': false });
2042 * // using the `_.matchesProperty` iteratee shorthand
2043 * _.some(users, ['active', false]);
2046 * // using the `_.property` iteratee shorthand
2047 * _.some(users, 'active');
2050 function some(collection, predicate, guard) {
2051 predicate = guard ? undefined : predicate;
2052 return baseSome(collection, baseIteratee(predicate));
2056 * Creates an array of elements, sorted in ascending order by the results of
2057 * running each element in a collection through each iteratee. This method
2058 * performs a stable sort, that is, it preserves the original sort order of
2059 * equal elements. The iteratees are invoked with one argument: (value).
2063 * @category Collection
2064 * @param {Array|Object} collection The collection to iterate over.
2065 * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
2066 * The iteratees to sort by, specified individually or in arrays.
2067 * @returns {Array} Returns the new sorted array.
2071 * { 'user': 'fred', 'age': 48 },
2072 * { 'user': 'barney', 'age': 36 },
2073 * { 'user': 'fred', 'age': 42 },
2074 * { 'user': 'barney', 'age': 34 }
2077 * _.sortBy(users, function(o) { return o.user; });
2078 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2080 * _.sortBy(users, ['user', 'age']);
2081 * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
2083 * _.sortBy(users, 'user', function(o) {
2084 * return Math.floor(o.age / 10);
2086 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2088 function sortBy(collection, iteratee) {
2090 iteratee = baseIteratee(iteratee);
2092 return baseMap(baseMap(collection, function(value, key, collection) {
2093 return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2094 }).sort(function(object, other) {
2095 return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2096 }), baseProperty('value'));
2099 /*------------------------------------------------------------------------*/
2102 * Gets the timestamp of the number of milliseconds that have elapsed since
2103 * the Unix epoch (1 January 1970 00:00:00 UTC).
2109 * @returns {number} Returns the timestamp.
2112 * _.defer(function(stamp) {
2113 * console.log(_.now() - stamp);
2115 * // => logs the number of milliseconds it took for the deferred function to be invoked
2119 /*------------------------------------------------------------------------*/
2122 * Creates a function that invokes `func`, with the `this` binding and arguments
2123 * of the created function, while it's called less than `n` times. Subsequent
2124 * calls to the created function return the result of the last `func` invocation.
2128 * @category Function
2129 * @param {number} n The number of calls at which `func` is no longer invoked.
2130 * @param {Function} func The function to restrict.
2131 * @returns {Function} Returns the new restricted function.
2134 * jQuery(element).on('click', _.before(5, addContactToList));
2135 * // => allows adding up to 4 contacts to the list
2137 function before(n, func) {
2139 if (typeof func != 'function') {
2140 throw new TypeError(FUNC_ERROR_TEXT);
2145 result = func.apply(this, arguments);
2155 * Creates a function that invokes `func` with the `this` binding of `thisArg`
2156 * and prepends any additional `_.bind` arguments to those provided to the
2159 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2160 * may be used as a placeholder for partially applied arguments.
2162 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
2163 * property of bound functions.
2167 * @category Function
2168 * @param {Function} func The function to bind.
2169 * @param {*} thisArg The `this` binding of `func`.
2170 * @param {...*} [partials] The arguments to be partially applied.
2171 * @returns {Function} Returns the new bound function.
2174 * var greet = function(greeting, punctuation) {
2175 * return greeting + ' ' + this.user + punctuation;
2178 * var object = { 'user': 'fred' };
2180 * var bound = _.bind(greet, object, 'hi');
2184 * // using placeholders
2185 * var bound = _.bind(greet, object, _, '!');
2189 var bind = rest(function(func, thisArg, partials) {
2190 return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
2194 * Defers invoking the `func` until the current call stack has cleared. Any
2195 * additional arguments are provided to `func` when it's invoked.
2199 * @category Function
2200 * @param {Function} func The function to defer.
2201 * @param {...*} [args] The arguments to invoke `func` with.
2202 * @returns {number} Returns the timer id.
2205 * _.defer(function(text) {
2206 * console.log(text);
2208 * // logs 'deferred' after one or more milliseconds
2210 var defer = rest(function(func, args) {
2211 return baseDelay(func, 1, args);
2215 * Invokes `func` after `wait` milliseconds. Any additional arguments are
2216 * provided to `func` when it's invoked.
2220 * @category Function
2221 * @param {Function} func The function to delay.
2222 * @param {number} wait The number of milliseconds to delay invocation.
2223 * @param {...*} [args] The arguments to invoke `func` with.
2224 * @returns {number} Returns the timer id.
2227 * _.delay(function(text) {
2228 * console.log(text);
2229 * }, 1000, 'later');
2230 * // => logs 'later' after one second
2232 var delay = rest(function(func, wait, args) {
2233 return baseDelay(func, toNumber(wait) || 0, args);
2237 * Creates a function that negates the result of the predicate `func`. The
2238 * `func` predicate is invoked with the `this` binding and arguments of the
2243 * @category Function
2244 * @param {Function} predicate The predicate to negate.
2245 * @returns {Function} Returns the new function.
2248 * function isEven(n) {
2249 * return n % 2 == 0;
2252 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2255 function negate(predicate) {
2256 if (typeof predicate != 'function') {
2257 throw new TypeError(FUNC_ERROR_TEXT);
2260 return !predicate.apply(this, arguments);
2265 * Creates a function that is restricted to invoking `func` once. Repeat calls
2266 * to the function return the value of the first invocation. The `func` is
2267 * invoked with the `this` binding and arguments of the created function.
2271 * @category Function
2272 * @param {Function} func The function to restrict.
2273 * @returns {Function} Returns the new restricted function.
2276 * var initialize = _.once(createApplication);
2279 * // `initialize` invokes `createApplication` once
2281 function once(func) {
2282 return before(2, func);
2286 * Creates a function that invokes `func` with the `this` binding of the
2287 * created function and arguments from `start` and beyond provided as an array.
2289 * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
2293 * @category Function
2294 * @param {Function} func The function to apply a rest parameter to.
2295 * @param {number} [start=func.length-1] The start position of the rest parameter.
2296 * @returns {Function} Returns the new function.
2299 * var say = _.rest(function(what, names) {
2300 * return what + ' ' + _.initial(names).join(', ') +
2301 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
2304 * say('hello', 'fred', 'barney', 'pebbles');
2305 * // => 'hello fred, barney, & pebbles'
2307 function rest(func, start) {
2308 if (typeof func != 'function') {
2309 throw new TypeError(FUNC_ERROR_TEXT);
2311 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
2313 var args = arguments,
2315 length = nativeMax(args.length - start, 0),
2316 array = Array(length);
2318 while (++index < length) {
2319 array[index] = args[start + index];
2321 var otherArgs = Array(start + 1);
2323 while (++index < start) {
2324 otherArgs[index] = args[index];
2326 otherArgs[start] = array;
2327 return func.apply(this, otherArgs);
2331 /*------------------------------------------------------------------------*/
2334 * Creates a shallow clone of `value`.
2336 * **Note:** This method is loosely based on the
2337 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2338 * and supports cloning arrays, array buffers, booleans, date objects, maps,
2339 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2340 * arrays. The own enumerable properties of `arguments` objects are cloned
2341 * as plain objects. An empty object is returned for uncloneable values such
2342 * as error objects, functions, DOM nodes, and WeakMaps.
2347 * @param {*} value The value to clone.
2348 * @returns {*} Returns the cloned value.
2351 * var objects = [{ 'a': 1 }, { 'b': 2 }];
2353 * var shallow = _.clone(objects);
2354 * console.log(shallow[0] === objects[0]);
2357 function clone(value) {
2358 if (!isObject(value)) {
2361 return isArray(value) ? copyArray(value) : copyObject(value, keys(value));
2365 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2366 * comparison between two values to determine if they are equivalent.
2371 * @param {*} value The value to compare.
2372 * @param {*} other The other value to compare.
2373 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2376 * var object = { 'user': 'fred' };
2377 * var other = { 'user': 'fred' };
2379 * _.eq(object, object);
2382 * _.eq(object, other);
2388 * _.eq('a', Object('a'));
2394 function eq(value, other) {
2395 return value === other || (value !== value && other !== other);
2399 * Checks if `value` is greater than `other`.
2404 * @param {*} value The value to compare.
2405 * @param {*} other The other value to compare.
2406 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
2418 function gt(value, other) {
2419 return value > other;
2423 * Checks if `value` is likely an `arguments` object.
2428 * @param {*} value The value to check.
2429 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2432 * _.isArguments(function() { return arguments; }());
2435 * _.isArguments([1, 2, 3]);
2438 function isArguments(value) {
2439 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
2440 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
2441 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
2445 * Checks if `value` is classified as an `Array` object.
2451 * @param {*} value The value to check.
2452 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2455 * _.isArray([1, 2, 3]);
2458 * _.isArray(document.body.children);
2464 * _.isArray(_.noop);
2467 var isArray = Array.isArray;
2470 * Checks if `value` is array-like. A value is considered array-like if it's
2471 * not a function and has a `value.length` that's an integer greater than or
2472 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2478 * @param {*} value The value to check.
2479 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2482 * _.isArrayLike([1, 2, 3]);
2485 * _.isArrayLike(document.body.children);
2488 * _.isArrayLike('abc');
2491 * _.isArrayLike(_.noop);
2494 function isArrayLike(value) {
2495 return value != null &&
2496 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
2500 * This method is like `_.isArrayLike` except that it also checks if `value`
2507 * @param {*} value The value to check.
2508 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
2511 * _.isArrayLikeObject([1, 2, 3]);
2514 * _.isArrayLikeObject(document.body.children);
2517 * _.isArrayLikeObject('abc');
2520 * _.isArrayLikeObject(_.noop);
2523 function isArrayLikeObject(value) {
2524 return isObjectLike(value) && isArrayLike(value);
2528 * Checks if `value` is classified as a boolean primitive or object.
2533 * @param {*} value The value to check.
2534 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2537 * _.isBoolean(false);
2540 * _.isBoolean(null);
2543 function isBoolean(value) {
2544 return value === true || value === false ||
2545 (isObjectLike(value) && objectToString.call(value) == boolTag);
2549 * Checks if `value` is classified as a `Date` object.
2554 * @param {*} value The value to check.
2555 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2558 * _.isDate(new Date);
2561 * _.isDate('Mon April 23 2012');
2564 function isDate(value) {
2565 return isObjectLike(value) && objectToString.call(value) == dateTag;
2569 * Checks if `value` is empty. A value is considered empty unless it's an
2570 * `arguments` object, array, string, or jQuery-like collection with a length
2571 * greater than `0` or an object with own enumerable properties.
2576 * @param {Array|Object|string} value The value to inspect.
2577 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2589 * _.isEmpty([1, 2, 3]);
2592 * _.isEmpty({ 'a': 1 });
2595 function isEmpty(value) {
2596 return (!isObjectLike(value) || isFunction(value.splice))
2598 : !keys(value).length;
2602 * Performs a deep comparison between two values to determine if they are
2605 * **Note:** This method supports comparing arrays, array buffers, booleans,
2606 * date objects, error objects, maps, numbers, `Object` objects, regexes,
2607 * sets, strings, symbols, and typed arrays. `Object` objects are compared
2608 * by their own, not inherited, enumerable properties. Functions and DOM
2609 * nodes are **not** supported.
2614 * @param {*} value The value to compare.
2615 * @param {*} other The other value to compare.
2616 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2619 * var object = { 'user': 'fred' };
2620 * var other = { 'user': 'fred' };
2622 * _.isEqual(object, other);
2628 function isEqual(value, other) {
2629 return baseIsEqual(value, other);
2633 * Checks if `value` is a finite primitive number.
2635 * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
2640 * @param {*} value The value to check.
2641 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
2647 * _.isFinite(Number.MAX_VALUE);
2653 * _.isFinite(Infinity);
2656 function isFinite(value) {
2657 return typeof value == 'number' && nativeIsFinite(value);
2661 * Checks if `value` is classified as a `Function` object.
2666 * @param {*} value The value to check.
2667 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2673 * _.isFunction(/abc/);
2676 function isFunction(value) {
2677 // The use of `Object#toString` avoids issues with the `typeof` operator
2678 // in Safari 8 which returns 'object' for typed array constructors, and
2679 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
2680 var tag = isObject(value) ? objectToString.call(value) : '';
2681 return tag == funcTag || tag == genTag;
2685 * Checks if `value` is a valid array-like length.
2687 * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
2692 * @param {*} value The value to check.
2693 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
2699 * _.isLength(Number.MIN_VALUE);
2702 * _.isLength(Infinity);
2708 function isLength(value) {
2709 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2713 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
2714 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2719 * @param {*} value The value to check.
2720 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2726 * _.isObject([1, 2, 3]);
2729 * _.isObject(_.noop);
2735 function isObject(value) {
2736 // Avoid a V8 JIT bug in Chrome 19-20.
2737 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
2738 var type = typeof value;
2739 return !!value && (type == 'object' || type == 'function');
2743 * Checks if `value` is object-like. A value is object-like if it's not `null`
2744 * and has a `typeof` result of "object".
2749 * @param {*} value The value to check.
2750 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2753 * _.isObjectLike({});
2756 * _.isObjectLike([1, 2, 3]);
2759 * _.isObjectLike(_.noop);
2762 * _.isObjectLike(null);
2765 function isObjectLike(value) {
2766 return !!value && typeof value == 'object';
2770 * Checks if `value` is `NaN`.
2772 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
2773 * which returns `true` for `undefined` and other non-numeric values.
2778 * @param {*} value The value to check.
2779 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2785 * _.isNaN(new Number(NaN));
2791 * _.isNaN(undefined);
2794 function isNaN(value) {
2795 // An `NaN` primitive is the only value that is not equal to itself.
2796 // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
2797 return isNumber(value) && value != +value;
2801 * Checks if `value` is `null`.
2806 * @param {*} value The value to check.
2807 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2816 function isNull(value) {
2817 return value === null;
2821 * Checks if `value` is classified as a `Number` primitive or object.
2823 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
2824 * as numbers, use the `_.isFinite` method.
2829 * @param {*} value The value to check.
2830 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2836 * _.isNumber(Number.MIN_VALUE);
2839 * _.isNumber(Infinity);
2845 function isNumber(value) {
2846 return typeof value == 'number' ||
2847 (isObjectLike(value) && objectToString.call(value) == numberTag);
2851 * Checks if `value` is classified as a `RegExp` object.
2856 * @param {*} value The value to check.
2857 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2860 * _.isRegExp(/abc/);
2863 * _.isRegExp('/abc/');
2866 function isRegExp(value) {
2867 return isObject(value) && objectToString.call(value) == regexpTag;
2871 * Checks if `value` is classified as a `String` primitive or object.
2876 * @param {*} value The value to check.
2877 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2880 * _.isString('abc');
2886 function isString(value) {
2887 return typeof value == 'string' ||
2888 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
2892 * Checks if `value` is `undefined`.
2897 * @param {*} value The value to check.
2898 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
2901 * _.isUndefined(void 0);
2904 * _.isUndefined(null);
2907 function isUndefined(value) {
2908 return value === undefined;
2912 * Checks if `value` is less than `other`.
2917 * @param {*} value The value to compare.
2918 * @param {*} other The other value to compare.
2919 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
2931 function lt(value, other) {
2932 return value < other;
2936 * Converts `value` to an array.
2941 * @param {*} value The value to convert.
2942 * @returns {Array} Returns the converted array.
2945 * _.toArray({ 'a': 1, 'b': 2 });
2949 * // => ['a', 'b', 'c']
2957 function toArray(value) {
2958 if (!isArrayLike(value)) {
2959 return values(value);
2961 return value.length ? copyArray(value) : [];
2965 * Converts `value` to an integer.
2967 * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
2972 * @param {*} value The value to convert.
2973 * @returns {number} Returns the converted integer.
2979 * _.toInteger(Number.MIN_VALUE);
2982 * _.toInteger(Infinity);
2983 * // => 1.7976931348623157e+308
2988 var toInteger = Number;
2991 * Converts `value` to a number.
2996 * @param {*} value The value to process.
2997 * @returns {number} Returns the number.
3003 * _.toNumber(Number.MIN_VALUE);
3006 * _.toNumber(Infinity);
3012 var toNumber = Number;
3015 * Converts `value` to a string if it's not one. An empty string is returned
3016 * for `null` and `undefined` values. The sign of `-0` is preserved.
3021 * @param {*} value The value to process.
3022 * @returns {string} Returns the string.
3031 * _.toString([1, 2, 3]);
3034 function toString(value) {
3035 if (typeof value == 'string') {
3038 return value == null ? '' : (value + '');
3041 /*------------------------------------------------------------------------*/
3044 * Assigns own enumerable properties of source objects to the destination
3045 * object. Source objects are applied from left to right. Subsequent sources
3046 * overwrite property assignments of previous sources.
3048 * **Note:** This method mutates `object` and is loosely based on
3049 * [`Object.assign`](https://mdn.io/Object/assign).
3054 * @param {Object} object The destination object.
3055 * @param {...Object} [sources] The source objects.
3056 * @returns {Object} Returns `object`.
3067 * Foo.prototype.d = 4;
3068 * Bar.prototype.f = 6;
3070 * _.assign({ 'a': 1 }, new Foo, new Bar);
3071 * // => { 'a': 1, 'c': 3, 'e': 5 }
3073 var assign = createAssigner(function(object, source) {
3074 copyObject(source, keys(source), object);
3078 * This method is like `_.assign` except that it iterates over own and
3079 * inherited source properties.
3081 * **Note:** This method mutates `object`.
3087 * @param {Object} object The destination object.
3088 * @param {...Object} [sources] The source objects.
3089 * @returns {Object} Returns `object`.
3100 * Foo.prototype.c = 3;
3101 * Bar.prototype.e = 5;
3103 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
3104 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
3106 var assignIn = createAssigner(function(object, source) {
3107 copyObject(source, keysIn(source), object);
3111 * This method is like `_.assignIn` except that it accepts `customizer` which
3112 * is invoked to produce the assigned values. If `customizer` returns `undefined`
3113 * assignment is handled by the method instead. The `customizer` is invoked
3114 * with five arguments: (objValue, srcValue, key, object, source).
3116 * **Note:** This method mutates `object`.
3122 * @param {Object} object The destination object.
3123 * @param {...Object} sources The source objects.
3124 * @param {Function} [customizer] The function to customize assigned values.
3125 * @returns {Object} Returns `object`.
3128 * function customizer(objValue, srcValue) {
3129 * return _.isUndefined(objValue) ? srcValue : objValue;
3132 * var defaults = _.partialRight(_.assignInWith, customizer);
3134 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3135 * // => { 'a': 1, 'b': 2 }
3137 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
3138 copyObjectWith(source, keysIn(source), object, customizer);
3142 * Creates an object that inherits from the `prototype` object. If a `properties`
3143 * object is provided its own enumerable properties are assigned to the created object.
3148 * @param {Object} prototype The object to inherit from.
3149 * @param {Object} [properties] The properties to assign to the object.
3150 * @returns {Object} Returns the new object.
3153 * function Shape() {
3158 * function Circle() {
3162 * Circle.prototype = _.create(Shape.prototype, {
3163 * 'constructor': Circle
3166 * var circle = new Circle;
3167 * circle instanceof Circle;
3170 * circle instanceof Shape;
3173 function create(prototype, properties) {
3174 var result = baseCreate(prototype);
3175 return properties ? assign(result, properties) : result;
3179 * Assigns own and inherited enumerable properties of source objects to the
3180 * destination object for all destination properties that resolve to `undefined`.
3181 * Source objects are applied from left to right. Once a property is set,
3182 * additional values of the same property are ignored.
3184 * **Note:** This method mutates `object`.
3189 * @param {Object} object The destination object.
3190 * @param {...Object} [sources] The source objects.
3191 * @returns {Object} Returns `object`.
3194 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
3195 * // => { 'user': 'barney', 'age': 36 }
3197 var defaults = rest(function(args) {
3198 args.push(undefined, assignInDefaults);
3199 return assignInWith.apply(undefined, args);
3203 * Checks if `path` is a direct property of `object`.
3208 * @param {Object} object The object to query.
3209 * @param {Array|string} path The path to check.
3210 * @returns {boolean} Returns `true` if `path` exists, else `false`.
3213 * var object = { 'a': { 'b': { 'c': 3 } } };
3214 * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
3216 * _.has(object, 'a');
3219 * _.has(object, 'a.b.c');
3222 * _.has(object, ['a', 'b', 'c']);
3225 * _.has(other, 'a');
3228 function has(object, path) {
3229 return object != null && hasOwnProperty.call(object, path);
3233 * Creates an array of the own enumerable property names of `object`.
3235 * **Note:** Non-object values are coerced to objects. See the
3236 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
3242 * @param {Object} object The object to query.
3243 * @returns {Array} Returns the array of property names.
3251 * Foo.prototype.c = 3;
3254 * // => ['a', 'b'] (iteration order is not guaranteed)
3259 function keys(object) {
3260 var isProto = isPrototype(object);
3261 if (!(isProto || isArrayLike(object))) {
3262 return baseKeys(object);
3264 var indexes = indexKeys(object),
3265 skipIndexes = !!indexes,
3266 result = indexes || [],
3267 length = result.length;
3269 for (var key in object) {
3270 if (hasOwnProperty.call(object, key) &&
3271 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3272 !(isProto && key == 'constructor')) {
3280 * Creates an array of the own and inherited enumerable property names of `object`.
3282 * **Note:** Non-object values are coerced to objects.
3287 * @param {Object} object The object to query.
3288 * @returns {Array} Returns the array of property names.
3296 * Foo.prototype.c = 3;
3298 * _.keysIn(new Foo);
3299 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3301 function keysIn(object) {
3303 isProto = isPrototype(object),
3304 props = baseKeysIn(object),
3305 propsLength = props.length,
3306 indexes = indexKeys(object),
3307 skipIndexes = !!indexes,
3308 result = indexes || [],
3309 length = result.length;
3311 while (++index < propsLength) {
3312 var key = props[index];
3313 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3314 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3322 * Creates an object composed of the picked `object` properties.
3327 * @param {Object} object The source object.
3328 * @param {...(string|string[])} [props] The property names to pick, specified
3329 * individually or in arrays.
3330 * @returns {Object} Returns the new object.
3333 * var object = { 'a': 1, 'b': '2', 'c': 3 };
3335 * _.pick(object, ['a', 'c']);
3336 * // => { 'a': 1, 'c': 3 }
3338 var pick = rest(function(object, props) {
3339 return object == null ? {} : basePick(object, baseFlatten(props));
3343 * This method is like `_.get` except that if the resolved value is a function
3344 * it's invoked with the `this` binding of its parent object and its result
3350 * @param {Object} object The object to query.
3351 * @param {Array|string} path The path of the property to resolve.
3352 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
3353 * @returns {*} Returns the resolved value.
3356 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3358 * _.result(object, 'a[0].b.c1');
3361 * _.result(object, 'a[0].b.c2');
3364 * _.result(object, 'a[0].b.c3', 'default');
3367 * _.result(object, 'a[0].b.c3', _.constant('default'));
3370 function result(object, path, defaultValue) {
3371 var value = object == null ? undefined : object[path];
3372 if (value === undefined) {
3373 value = defaultValue;
3375 return isFunction(value) ? value.call(object) : value;
3379 * Creates an array of the own enumerable property values of `object`.
3381 * **Note:** Non-object values are coerced to objects.
3386 * @param {Object} object The object to query.
3387 * @returns {Array} Returns the array of property values.
3395 * Foo.prototype.c = 3;
3397 * _.values(new Foo);
3398 * // => [1, 2] (iteration order is not guaranteed)
3403 function values(object) {
3404 return object ? baseValues(object, keys(object)) : [];
3407 /*------------------------------------------------------------------------*/
3410 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
3411 * their corresponding HTML entities.
3413 * **Note:** No other characters are escaped. To escape additional
3414 * characters use a third-party library like [_he_](https://mths.be/he).
3416 * Though the ">" character is escaped for symmetry, characters like
3417 * ">" and "/" don't need escaping in HTML and have no special meaning
3418 * unless they're part of a tag or unquoted attribute value.
3419 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3420 * (under "semi-related fun fact") for more details.
3422 * Backticks are escaped because in IE < 9, they can break out of
3423 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
3424 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
3425 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
3428 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
3429 * to reduce XSS vectors.
3434 * @param {string} [string=''] The string to escape.
3435 * @returns {string} Returns the escaped string.
3438 * _.escape('fred, barney, & pebbles');
3439 * // => 'fred, barney, & pebbles'
3441 function escape(string) {
3442 string = toString(string);
3443 return (string && reHasUnescapedHtml.test(string))
3444 ? string.replace(reUnescapedHtml, escapeHtmlChar)
3448 /*------------------------------------------------------------------------*/
3451 * This method returns the first argument provided to it.
3456 * @param {*} value Any value.
3457 * @returns {*} Returns `value`.
3460 * var object = { 'user': 'fred' };
3462 * _.identity(object) === object;
3465 function identity(value) {
3470 * Creates a function that invokes `func` with the arguments of the created
3471 * function. If `func` is a property name the created callback returns the
3472 * property value for a given element. If `func` is an object the created
3473 * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`.
3478 * @param {*} [func=_.identity] The value to convert to a callback.
3479 * @returns {Function} Returns the callback.
3483 * { 'user': 'barney', 'age': 36 },
3484 * { 'user': 'fred', 'age': 40 }
3487 * // create custom iteratee shorthands
3488 * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
3489 * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
3490 * return !p ? callback(func) : function(object) {
3491 * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
3495 * _.filter(users, 'age > 36');
3496 * // => [{ 'user': 'fred', 'age': 40 }]
3498 var iteratee = baseIteratee;
3501 * Creates a function that performs a deep partial comparison between a given
3502 * object and `source`, returning `true` if the given object has equivalent
3503 * property values, else `false`.
3505 * **Note:** This method supports comparing the same values as `_.isEqual`.
3510 * @param {Object} source The object of property values to match.
3511 * @returns {Function} Returns the new function.
3515 * { 'user': 'barney', 'age': 36, 'active': true },
3516 * { 'user': 'fred', 'age': 40, 'active': false }
3519 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
3520 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
3522 function matches(source) {
3523 return baseMatches(assign({}, source));
3527 * Adds all own enumerable function properties of a source object to the
3528 * destination object. If `object` is a function then methods are added to
3529 * its prototype as well.
3531 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3532 * avoid conflicts caused by modifying the original.
3537 * @param {Function|Object} [object=lodash] The destination object.
3538 * @param {Object} source The object of functions to add.
3539 * @param {Object} [options] The options object.
3540 * @param {boolean} [options.chain=true] Specify whether the functions added
3542 * @returns {Function|Object} Returns `object`.
3545 * function vowels(string) {
3546 * return _.filter(string, function(v) {
3547 * return /[aeiou]/i.test(v);
3551 * _.mixin({ 'vowels': vowels });
3555 * _('fred').vowels().value();
3558 * _.mixin({ 'vowels': vowels }, { 'chain': false });
3559 * _('fred').vowels();
3562 function mixin(object, source, options) {
3563 var props = keys(source),
3564 methodNames = baseFunctions(source, props);
3566 if (options == null &&
3567 !(isObject(source) && (methodNames.length || !props.length))) {
3571 methodNames = baseFunctions(source, keys(source));
3573 var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
3574 isFunc = isFunction(object);
3576 baseEach(methodNames, function(methodName) {
3577 var func = source[methodName];
3578 object[methodName] = func;
3580 object.prototype[methodName] = function() {
3581 var chainAll = this.__chain__;
3582 if (chain || chainAll) {
3583 var result = object(this.__wrapped__),
3584 actions = result.__actions__ = copyArray(this.__actions__);
3586 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3587 result.__chain__ = chainAll;
3590 return func.apply(object, arrayPush([this.value()], arguments));
3599 * Reverts the `_` variable to its previous value and returns a reference to
3600 * the `lodash` function.
3605 * @returns {Function} Returns the `lodash` function.
3608 * var lodash = _.noConflict();
3610 function noConflict() {
3611 if (root._ === this) {
3618 * A no-operation function that returns `undefined` regardless of the
3619 * arguments it receives.
3626 * var object = { 'user': 'fred' };
3628 * _.noop(object) === undefined;
3632 // No operation performed.
3636 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
3641 * @param {string} [prefix] The value to prefix the ID with.
3642 * @returns {string} Returns the unique ID.
3645 * _.uniqueId('contact_');
3646 * // => 'contact_104'
3651 function uniqueId(prefix) {
3652 var id = ++idCounter;
3653 return toString(prefix) + id;
3656 /*------------------------------------------------------------------------*/
3659 * Computes the maximum value of `array`. If `array` is empty or falsey
3660 * `undefined` is returned.
3665 * @param {Array} array The array to iterate over.
3666 * @returns {*} Returns the maximum value.
3669 * _.max([4, 2, 8, 6]);
3675 function max(array) {
3676 return (array && array.length)
3677 ? baseExtremum(array, identity, gt)
3682 * Computes the minimum value of `array`. If `array` is empty or falsey
3683 * `undefined` is returned.
3688 * @param {Array} array The array to iterate over.
3689 * @returns {*} Returns the minimum value.
3692 * _.min([4, 2, 8, 6]);
3698 function min(array) {
3699 return (array && array.length)
3700 ? baseExtremum(array, identity, lt)
3704 /*------------------------------------------------------------------------*/
3706 LodashWrapper.prototype = baseCreate(lodash.prototype);
3707 LodashWrapper.prototype.constructor = LodashWrapper;
3709 // Add functions that return wrapped values when chaining.
3710 lodash.assignIn = assignIn;
3711 lodash.before = before;
3713 lodash.chain = chain;
3714 lodash.compact = compact;
3715 lodash.concat = concat;
3716 lodash.create = create;
3717 lodash.defaults = defaults;
3718 lodash.defer = defer;
3719 lodash.delay = delay;
3720 lodash.filter = filter;
3721 lodash.flatten = flatten;
3722 lodash.flattenDeep = flattenDeep;
3723 lodash.invokeMap = invokeMap;
3724 lodash.iteratee = iteratee;
3727 lodash.matches = matches;
3728 lodash.mixin = mixin;
3729 lodash.negate = negate;
3732 lodash.slice = slice;
3733 lodash.sortBy = sortBy;
3736 lodash.toArray = toArray;
3737 lodash.values = values;
3740 lodash.extend = assignIn;
3742 // Add functions to `lodash.prototype`.
3743 mixin(lodash, lodash);
3745 /*------------------------------------------------------------------------*/
3747 // Add functions that return unwrapped values when chaining.
3748 lodash.clone = clone;
3749 lodash.escape = escape;
3750 lodash.every = every;
3752 lodash.forEach = forEach;
3755 lodash.identity = identity;
3756 lodash.indexOf = indexOf;
3757 lodash.isArguments = isArguments;
3758 lodash.isArray = isArray;
3759 lodash.isBoolean = isBoolean;
3760 lodash.isDate = isDate;
3761 lodash.isEmpty = isEmpty;
3762 lodash.isEqual = isEqual;
3763 lodash.isFinite = isFinite;
3764 lodash.isFunction = isFunction;
3765 lodash.isNaN = isNaN;
3766 lodash.isNull = isNull;
3767 lodash.isNumber = isNumber;
3768 lodash.isObject = isObject;
3769 lodash.isRegExp = isRegExp;
3770 lodash.isString = isString;
3771 lodash.isUndefined = isUndefined;
3775 lodash.noConflict = noConflict;
3778 lodash.reduce = reduce;
3779 lodash.result = result;
3782 lodash.uniqueId = uniqueId;
3785 lodash.each = forEach;
3786 lodash.first = head;
3788 mixin(lodash, (function() {
3790 baseForOwn(lodash, function(func, methodName) {
3791 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3792 source[methodName] = func;
3796 }()), { 'chain': false });
3798 /*------------------------------------------------------------------------*/
3801 * The semantic version number.
3807 lodash.VERSION = VERSION;
3809 // Add `Array` and `String` methods to `lodash.prototype`.
3810 baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3811 var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3812 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3813 retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3815 lodash.prototype[methodName] = function() {
3816 var args = arguments;
3817 if (retUnwrapped && !this.__chain__) {
3818 return func.apply(this.value(), args);
3820 return this[chainName](function(value) {
3821 return func.apply(value, args);
3826 // Add chaining functions to the `lodash` wrapper.
3827 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3829 /*--------------------------------------------------------------------------*/
3831 // Expose lodash on the free variable `window` or `self` when available. This
3832 // prevents errors in cases where lodash is loaded by a script tag in the presence
3833 // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
3834 (freeWindow || freeSelf || {})._ = lodash;
3836 // Some AMD build optimizers like r.js check for condition patterns like the following:
3837 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3838 // Define as an anonymous module so, through path mapping, it can be
3839 // referenced as the "underscore" module.
3844 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
3845 else if (freeExports && freeModule) {
3846 // Export for Node.js.
3847 if (moduleExports) {
3848 (freeModule.exports = lodash)._ = lodash;
3850 // Export for CommonJS support.
3851 freeExports._ = lodash;
3854 // Export to the global object.