2 * Lodash (Custom Build) <https://lodash.com/>
3 * Build: `lodash modularize exports="npm" -o ./`
4 * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
5 * Released under MIT license <https://lodash.com/license>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
10 /** Used as the size to enable large array optimizations. */
11 var LARGE_ARRAY_SIZE = 200;
13 /** Used to stand-in for `undefined` hash values. */
14 var HASH_UNDEFINED = '__lodash_hash_undefined__';
16 /** Used to detect hot functions by number of calls within a span of milliseconds. */
20 /** Used as references for various `Number` constants. */
21 var MAX_SAFE_INTEGER = 9007199254740991;
23 /** `Object#toString` result references. */
24 var argsTag = '[object Arguments]',
25 arrayTag = '[object Array]',
26 asyncTag = '[object AsyncFunction]',
27 boolTag = '[object Boolean]',
28 dateTag = '[object Date]',
29 errorTag = '[object Error]',
30 funcTag = '[object Function]',
31 genTag = '[object GeneratorFunction]',
32 mapTag = '[object Map]',
33 numberTag = '[object Number]',
34 nullTag = '[object Null]',
35 objectTag = '[object Object]',
36 proxyTag = '[object Proxy]',
37 regexpTag = '[object RegExp]',
38 setTag = '[object Set]',
39 stringTag = '[object String]',
40 undefinedTag = '[object Undefined]',
41 weakMapTag = '[object WeakMap]';
43 var arrayBufferTag = '[object ArrayBuffer]',
44 dataViewTag = '[object DataView]',
45 float32Tag = '[object Float32Array]',
46 float64Tag = '[object Float64Array]',
47 int8Tag = '[object Int8Array]',
48 int16Tag = '[object Int16Array]',
49 int32Tag = '[object Int32Array]',
50 uint8Tag = '[object Uint8Array]',
51 uint8ClampedTag = '[object Uint8ClampedArray]',
52 uint16Tag = '[object Uint16Array]',
53 uint32Tag = '[object Uint32Array]';
56 * Used to match `RegExp`
57 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
59 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
61 /** Used to detect host constructors (Safari). */
62 var reIsHostCtor = /^\[object .+?Constructor\]$/;
64 /** Used to detect unsigned integer values. */
65 var reIsUint = /^(?:0|[1-9]\d*)$/;
67 /** Used to identify `toStringTag` values of typed arrays. */
68 var typedArrayTags = {};
69 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
70 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
71 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
72 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
73 typedArrayTags[uint32Tag] = true;
74 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
75 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
76 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
77 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
78 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
79 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
80 typedArrayTags[setTag] = typedArrayTags[stringTag] =
81 typedArrayTags[weakMapTag] = false;
83 /** Detect free variable `global` from Node.js. */
84 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
86 /** Detect free variable `self`. */
87 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
89 /** Used as a reference to the global object. */
90 var root = freeGlobal || freeSelf || Function('return this')();
92 /** Detect free variable `exports`. */
93 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
95 /** Detect free variable `module`. */
96 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
98 /** Detect the popular CommonJS extension `module.exports`. */
99 var moduleExports = freeModule && freeModule.exports === freeExports;
101 /** Detect free variable `process` from Node.js. */
102 var freeProcess = moduleExports && freeGlobal.process;
104 /** Used to access faster Node.js helpers. */
105 var nodeUtil = (function() {
107 // Use `util.types` for Node.js 10+.
108 var types = freeModule && freeModule.require && freeModule.require('util').types;
114 // Legacy `process.binding('util')` for Node.js < 10.
115 return freeProcess && freeProcess.binding && freeProcess.binding('util');
119 /* Node.js helper references. */
120 var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
123 * A faster alternative to `Function#apply`, this function invokes `func`
124 * with the `this` binding of `thisArg` and the arguments of `args`.
127 * @param {Function} func The function to invoke.
128 * @param {*} thisArg The `this` binding of `func`.
129 * @param {Array} args The arguments to invoke `func` with.
130 * @returns {*} Returns the result of `func`.
132 function apply(func, thisArg, args) {
133 switch (args.length) {
134 case 0: return func.call(thisArg);
135 case 1: return func.call(thisArg, args[0]);
136 case 2: return func.call(thisArg, args[0], args[1]);
137 case 3: return func.call(thisArg, args[0], args[1], args[2]);
139 return func.apply(thisArg, args);
143 * The base implementation of `_.times` without support for iteratee shorthands
144 * or max array length checks.
147 * @param {number} n The number of times to invoke `iteratee`.
148 * @param {Function} iteratee The function invoked per iteration.
149 * @returns {Array} Returns the array of results.
151 function baseTimes(n, iteratee) {
155 while (++index < n) {
156 result[index] = iteratee(index);
162 * The base implementation of `_.unary` without support for storing metadata.
165 * @param {Function} func The function to cap arguments for.
166 * @returns {Function} Returns the new capped function.
168 function baseUnary(func) {
169 return function(value) {
175 * Gets the value at `key` of `object`.
178 * @param {Object} [object] The object to query.
179 * @param {string} key The key of the property to get.
180 * @returns {*} Returns the property value.
182 function getValue(object, key) {
183 return object == null ? undefined : object[key];
187 * Creates a unary function that invokes `func` with its argument transformed.
190 * @param {Function} func The function to wrap.
191 * @param {Function} transform The argument transform.
192 * @returns {Function} Returns the new function.
194 function overArg(func, transform) {
195 return function(arg) {
196 return func(transform(arg));
200 /** Used for built-in method references. */
201 var arrayProto = Array.prototype,
202 funcProto = Function.prototype,
203 objectProto = Object.prototype;
205 /** Used to detect overreaching core-js shims. */
206 var coreJsData = root['__core-js_shared__'];
208 /** Used to resolve the decompiled source of functions. */
209 var funcToString = funcProto.toString;
211 /** Used to check objects for own properties. */
212 var hasOwnProperty = objectProto.hasOwnProperty;
214 /** Used to detect methods masquerading as native. */
215 var maskSrcKey = (function() {
216 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
217 return uid ? ('Symbol(src)_1.' + uid) : '';
221 * Used to resolve the
222 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
225 var nativeObjectToString = objectProto.toString;
227 /** Used to infer the `Object` constructor. */
228 var objectCtorString = funcToString.call(Object);
230 /** Used to detect if a method is native. */
231 var reIsNative = RegExp('^' +
232 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
233 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
236 /** Built-in value references. */
237 var Buffer = moduleExports ? root.Buffer : undefined,
238 Symbol = root.Symbol,
239 Uint8Array = root.Uint8Array,
240 allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
241 getPrototype = overArg(Object.getPrototypeOf, Object),
242 objectCreate = Object.create,
243 propertyIsEnumerable = objectProto.propertyIsEnumerable,
244 splice = arrayProto.splice,
245 symToStringTag = Symbol ? Symbol.toStringTag : undefined;
247 var defineProperty = (function() {
249 var func = getNative(Object, 'defineProperty');
255 /* Built-in method references for those with the same name as other `lodash` methods. */
256 var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
257 nativeMax = Math.max,
258 nativeNow = Date.now;
260 /* Built-in method references that are verified to be native. */
261 var Map = getNative(root, 'Map'),
262 nativeCreate = getNative(Object, 'create');
265 * The base implementation of `_.create` without support for assigning
266 * properties to the created object.
269 * @param {Object} proto The object to inherit from.
270 * @returns {Object} Returns the new object.
272 var baseCreate = (function() {
274 return function(proto) {
275 if (!isObject(proto)) {
279 return objectCreate(proto);
281 object.prototype = proto;
282 var result = new object;
283 object.prototype = undefined;
289 * Creates a hash object.
293 * @param {Array} [entries] The key-value pairs to cache.
295 function Hash(entries) {
297 length = entries == null ? 0 : entries.length;
300 while (++index < length) {
301 var entry = entries[index];
302 this.set(entry[0], entry[1]);
307 * Removes all key-value entries from the hash.
313 function hashClear() {
314 this.__data__ = nativeCreate ? nativeCreate(null) : {};
319 * Removes `key` and its value from the hash.
324 * @param {Object} hash The hash to modify.
325 * @param {string} key The key of the value to remove.
326 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
328 function hashDelete(key) {
329 var result = this.has(key) && delete this.__data__[key];
330 this.size -= result ? 1 : 0;
335 * Gets the hash value for `key`.
340 * @param {string} key The key of the value to get.
341 * @returns {*} Returns the entry value.
343 function hashGet(key) {
344 var data = this.__data__;
346 var result = data[key];
347 return result === HASH_UNDEFINED ? undefined : result;
349 return hasOwnProperty.call(data, key) ? data[key] : undefined;
353 * Checks if a hash value for `key` exists.
358 * @param {string} key The key of the entry to check.
359 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
361 function hashHas(key) {
362 var data = this.__data__;
363 return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
367 * Sets the hash `key` to `value`.
372 * @param {string} key The key of the value to set.
373 * @param {*} value The value to set.
374 * @returns {Object} Returns the hash instance.
376 function hashSet(key, value) {
377 var data = this.__data__;
378 this.size += this.has(key) ? 0 : 1;
379 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
383 // Add methods to `Hash`.
384 Hash.prototype.clear = hashClear;
385 Hash.prototype['delete'] = hashDelete;
386 Hash.prototype.get = hashGet;
387 Hash.prototype.has = hashHas;
388 Hash.prototype.set = hashSet;
391 * Creates an list cache object.
395 * @param {Array} [entries] The key-value pairs to cache.
397 function ListCache(entries) {
399 length = entries == null ? 0 : entries.length;
402 while (++index < length) {
403 var entry = entries[index];
404 this.set(entry[0], entry[1]);
409 * Removes all key-value entries from the list cache.
413 * @memberOf ListCache
415 function listCacheClear() {
421 * Removes `key` and its value from the list cache.
425 * @memberOf ListCache
426 * @param {string} key The key of the value to remove.
427 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
429 function listCacheDelete(key) {
430 var data = this.__data__,
431 index = assocIndexOf(data, key);
436 var lastIndex = data.length - 1;
437 if (index == lastIndex) {
440 splice.call(data, index, 1);
447 * Gets the list cache value for `key`.
451 * @memberOf ListCache
452 * @param {string} key The key of the value to get.
453 * @returns {*} Returns the entry value.
455 function listCacheGet(key) {
456 var data = this.__data__,
457 index = assocIndexOf(data, key);
459 return index < 0 ? undefined : data[index][1];
463 * Checks if a list cache value for `key` exists.
467 * @memberOf ListCache
468 * @param {string} key The key of the entry to check.
469 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
471 function listCacheHas(key) {
472 return assocIndexOf(this.__data__, key) > -1;
476 * Sets the list cache `key` to `value`.
480 * @memberOf ListCache
481 * @param {string} key The key of the value to set.
482 * @param {*} value The value to set.
483 * @returns {Object} Returns the list cache instance.
485 function listCacheSet(key, value) {
486 var data = this.__data__,
487 index = assocIndexOf(data, key);
491 data.push([key, value]);
493 data[index][1] = value;
498 // Add methods to `ListCache`.
499 ListCache.prototype.clear = listCacheClear;
500 ListCache.prototype['delete'] = listCacheDelete;
501 ListCache.prototype.get = listCacheGet;
502 ListCache.prototype.has = listCacheHas;
503 ListCache.prototype.set = listCacheSet;
506 * Creates a map cache object to store key-value pairs.
510 * @param {Array} [entries] The key-value pairs to cache.
512 function MapCache(entries) {
514 length = entries == null ? 0 : entries.length;
517 while (++index < length) {
518 var entry = entries[index];
519 this.set(entry[0], entry[1]);
524 * Removes all key-value entries from the map.
530 function mapCacheClear() {
534 'map': new (Map || ListCache),
540 * Removes `key` and its value from the map.
545 * @param {string} key The key of the value to remove.
546 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
548 function mapCacheDelete(key) {
549 var result = getMapData(this, key)['delete'](key);
550 this.size -= result ? 1 : 0;
555 * Gets the map value for `key`.
560 * @param {string} key The key of the value to get.
561 * @returns {*} Returns the entry value.
563 function mapCacheGet(key) {
564 return getMapData(this, key).get(key);
568 * Checks if a map value for `key` exists.
573 * @param {string} key The key of the entry to check.
574 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
576 function mapCacheHas(key) {
577 return getMapData(this, key).has(key);
581 * Sets the map `key` to `value`.
586 * @param {string} key The key of the value to set.
587 * @param {*} value The value to set.
588 * @returns {Object} Returns the map cache instance.
590 function mapCacheSet(key, value) {
591 var data = getMapData(this, key),
594 data.set(key, value);
595 this.size += data.size == size ? 0 : 1;
599 // Add methods to `MapCache`.
600 MapCache.prototype.clear = mapCacheClear;
601 MapCache.prototype['delete'] = mapCacheDelete;
602 MapCache.prototype.get = mapCacheGet;
603 MapCache.prototype.has = mapCacheHas;
604 MapCache.prototype.set = mapCacheSet;
607 * Creates a stack cache object to store key-value pairs.
611 * @param {Array} [entries] The key-value pairs to cache.
613 function Stack(entries) {
614 var data = this.__data__ = new ListCache(entries);
615 this.size = data.size;
619 * Removes all key-value entries from the stack.
625 function stackClear() {
626 this.__data__ = new ListCache;
631 * Removes `key` and its value from the stack.
636 * @param {string} key The key of the value to remove.
637 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
639 function stackDelete(key) {
640 var data = this.__data__,
641 result = data['delete'](key);
643 this.size = data.size;
648 * Gets the stack value for `key`.
653 * @param {string} key The key of the value to get.
654 * @returns {*} Returns the entry value.
656 function stackGet(key) {
657 return this.__data__.get(key);
661 * Checks if a stack value for `key` exists.
666 * @param {string} key The key of the entry to check.
667 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
669 function stackHas(key) {
670 return this.__data__.has(key);
674 * Sets the stack `key` to `value`.
679 * @param {string} key The key of the value to set.
680 * @param {*} value The value to set.
681 * @returns {Object} Returns the stack cache instance.
683 function stackSet(key, value) {
684 var data = this.__data__;
685 if (data instanceof ListCache) {
686 var pairs = data.__data__;
687 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
688 pairs.push([key, value]);
689 this.size = ++data.size;
692 data = this.__data__ = new MapCache(pairs);
694 data.set(key, value);
695 this.size = data.size;
699 // Add methods to `Stack`.
700 Stack.prototype.clear = stackClear;
701 Stack.prototype['delete'] = stackDelete;
702 Stack.prototype.get = stackGet;
703 Stack.prototype.has = stackHas;
704 Stack.prototype.set = stackSet;
707 * Creates an array of the enumerable property names of the array-like `value`.
710 * @param {*} value The value to query.
711 * @param {boolean} inherited Specify returning inherited property names.
712 * @returns {Array} Returns the array of property names.
714 function arrayLikeKeys(value, inherited) {
715 var isArr = isArray(value),
716 isArg = !isArr && isArguments(value),
717 isBuff = !isArr && !isArg && isBuffer(value),
718 isType = !isArr && !isArg && !isBuff && isTypedArray(value),
719 skipIndexes = isArr || isArg || isBuff || isType,
720 result = skipIndexes ? baseTimes(value.length, String) : [],
721 length = result.length;
723 for (var key in value) {
724 if ((inherited || hasOwnProperty.call(value, key)) &&
726 // Safari 9 has enumerable `arguments.length` in strict mode.
728 // Node.js 0.10 has enumerable non-index properties on buffers.
729 (isBuff && (key == 'offset' || key == 'parent')) ||
730 // PhantomJS 2 has enumerable non-index properties on typed arrays.
731 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
732 // Skip index properties.
742 * This function is like `assignValue` except that it doesn't assign
743 * `undefined` values.
746 * @param {Object} object The object to modify.
747 * @param {string} key The key of the property to assign.
748 * @param {*} value The value to assign.
750 function assignMergeValue(object, key, value) {
751 if ((value !== undefined && !eq(object[key], value)) ||
752 (value === undefined && !(key in object))) {
753 baseAssignValue(object, key, value);
758 * Assigns `value` to `key` of `object` if the existing value is not equivalent
759 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
760 * for equality comparisons.
763 * @param {Object} object The object to modify.
764 * @param {string} key The key of the property to assign.
765 * @param {*} value The value to assign.
767 function assignValue(object, key, value) {
768 var objValue = object[key];
769 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
770 (value === undefined && !(key in object))) {
771 baseAssignValue(object, key, value);
776 * Gets the index at which the `key` is found in `array` of key-value pairs.
779 * @param {Array} array The array to inspect.
780 * @param {*} key The key to search for.
781 * @returns {number} Returns the index of the matched value, else `-1`.
783 function assocIndexOf(array, key) {
784 var length = array.length;
786 if (eq(array[length][0], key)) {
794 * The base implementation of `assignValue` and `assignMergeValue` without
798 * @param {Object} object The object to modify.
799 * @param {string} key The key of the property to assign.
800 * @param {*} value The value to assign.
802 function baseAssignValue(object, key, value) {
803 if (key == '__proto__' && defineProperty) {
804 defineProperty(object, key, {
805 'configurable': true,
816 * The base implementation of `baseForOwn` which iterates over `object`
817 * properties returned by `keysFunc` and invokes `iteratee` for each property.
818 * Iteratee functions may exit iteration early by explicitly returning `false`.
821 * @param {Object} object The object to iterate over.
822 * @param {Function} iteratee The function invoked per iteration.
823 * @param {Function} keysFunc The function to get the keys of `object`.
824 * @returns {Object} Returns `object`.
826 var baseFor = createBaseFor();
829 * The base implementation of `getTag` without fallbacks for buggy environments.
832 * @param {*} value The value to query.
833 * @returns {string} Returns the `toStringTag`.
835 function baseGetTag(value) {
837 return value === undefined ? undefinedTag : nullTag;
839 return (symToStringTag && symToStringTag in Object(value))
841 : objectToString(value);
845 * The base implementation of `_.isArguments`.
848 * @param {*} value The value to check.
849 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
851 function baseIsArguments(value) {
852 return isObjectLike(value) && baseGetTag(value) == argsTag;
856 * The base implementation of `_.isNative` without bad shim checks.
859 * @param {*} value The value to check.
860 * @returns {boolean} Returns `true` if `value` is a native function,
863 function baseIsNative(value) {
864 if (!isObject(value) || isMasked(value)) {
867 var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
868 return pattern.test(toSource(value));
872 * The base implementation of `_.isTypedArray` without Node.js optimizations.
875 * @param {*} value The value to check.
876 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
878 function baseIsTypedArray(value) {
879 return isObjectLike(value) &&
880 isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
884 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
887 * @param {Object} object The object to query.
888 * @returns {Array} Returns the array of property names.
890 function baseKeysIn(object) {
891 if (!isObject(object)) {
892 return nativeKeysIn(object);
894 var isProto = isPrototype(object),
897 for (var key in object) {
898 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
906 * The base implementation of `_.merge` without support for multiple sources.
909 * @param {Object} object The destination object.
910 * @param {Object} source The source object.
911 * @param {number} srcIndex The index of `source`.
912 * @param {Function} [customizer] The function to customize merged values.
913 * @param {Object} [stack] Tracks traversed source values and their merged
916 function baseMerge(object, source, srcIndex, customizer, stack) {
917 if (object === source) {
920 baseFor(source, function(srcValue, key) {
921 stack || (stack = new Stack);
922 if (isObject(srcValue)) {
923 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
926 var newValue = customizer
927 ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
930 if (newValue === undefined) {
933 assignMergeValue(object, key, newValue);
939 * A specialized version of `baseMerge` for arrays and objects which performs
940 * deep merges and tracks traversed objects enabling objects with circular
941 * references to be merged.
944 * @param {Object} object The destination object.
945 * @param {Object} source The source object.
946 * @param {string} key The key of the value to merge.
947 * @param {number} srcIndex The index of `source`.
948 * @param {Function} mergeFunc The function to merge values.
949 * @param {Function} [customizer] The function to customize assigned values.
950 * @param {Object} [stack] Tracks traversed source values and their merged
953 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
954 var objValue = safeGet(object, key),
955 srcValue = safeGet(source, key),
956 stacked = stack.get(srcValue);
959 assignMergeValue(object, key, stacked);
962 var newValue = customizer
963 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
966 var isCommon = newValue === undefined;
969 var isArr = isArray(srcValue),
970 isBuff = !isArr && isBuffer(srcValue),
971 isTyped = !isArr && !isBuff && isTypedArray(srcValue);
974 if (isArr || isBuff || isTyped) {
975 if (isArray(objValue)) {
978 else if (isArrayLikeObject(objValue)) {
979 newValue = copyArray(objValue);
983 newValue = cloneBuffer(srcValue, true);
987 newValue = cloneTypedArray(srcValue, true);
993 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
995 if (isArguments(objValue)) {
996 newValue = toPlainObject(objValue);
998 else if (!isObject(objValue) || isFunction(objValue)) {
999 newValue = initCloneObject(srcValue);
1007 // Recursively merge objects and arrays (susceptible to call stack limits).
1008 stack.set(srcValue, newValue);
1009 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
1010 stack['delete'](srcValue);
1012 assignMergeValue(object, key, newValue);
1016 * The base implementation of `_.rest` which doesn't validate or coerce arguments.
1019 * @param {Function} func The function to apply a rest parameter to.
1020 * @param {number} [start=func.length-1] The start position of the rest parameter.
1021 * @returns {Function} Returns the new function.
1023 function baseRest(func, start) {
1024 return setToString(overRest(func, start, identity), func + '');
1028 * The base implementation of `setToString` without support for hot loop shorting.
1031 * @param {Function} func The function to modify.
1032 * @param {Function} string The `toString` result.
1033 * @returns {Function} Returns `func`.
1035 var baseSetToString = !defineProperty ? identity : function(func, string) {
1036 return defineProperty(func, 'toString', {
1037 'configurable': true,
1038 'enumerable': false,
1039 'value': constant(string),
1045 * Creates a clone of `buffer`.
1048 * @param {Buffer} buffer The buffer to clone.
1049 * @param {boolean} [isDeep] Specify a deep clone.
1050 * @returns {Buffer} Returns the cloned buffer.
1052 function cloneBuffer(buffer, isDeep) {
1054 return buffer.slice();
1056 var length = buffer.length,
1057 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
1059 buffer.copy(result);
1064 * Creates a clone of `arrayBuffer`.
1067 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
1068 * @returns {ArrayBuffer} Returns the cloned array buffer.
1070 function cloneArrayBuffer(arrayBuffer) {
1071 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
1072 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
1077 * Creates a clone of `typedArray`.
1080 * @param {Object} typedArray The typed array to clone.
1081 * @param {boolean} [isDeep] Specify a deep clone.
1082 * @returns {Object} Returns the cloned typed array.
1084 function cloneTypedArray(typedArray, isDeep) {
1085 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
1086 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
1090 * Copies the values of `source` to `array`.
1093 * @param {Array} source The array to copy values from.
1094 * @param {Array} [array=[]] The array to copy values to.
1095 * @returns {Array} Returns `array`.
1097 function copyArray(source, array) {
1099 length = source.length;
1101 array || (array = Array(length));
1102 while (++index < length) {
1103 array[index] = source[index];
1109 * Copies properties of `source` to `object`.
1112 * @param {Object} source The object to copy properties from.
1113 * @param {Array} props The property identifiers to copy.
1114 * @param {Object} [object={}] The object to copy properties to.
1115 * @param {Function} [customizer] The function to customize copied values.
1116 * @returns {Object} Returns `object`.
1118 function copyObject(source, props, object, customizer) {
1119 var isNew = !object;
1120 object || (object = {});
1123 length = props.length;
1125 while (++index < length) {
1126 var key = props[index];
1128 var newValue = customizer
1129 ? customizer(object[key], source[key], key, object, source)
1132 if (newValue === undefined) {
1133 newValue = source[key];
1136 baseAssignValue(object, key, newValue);
1138 assignValue(object, key, newValue);
1145 * Creates a function like `_.assign`.
1148 * @param {Function} assigner The function to assign values.
1149 * @returns {Function} Returns the new assigner function.
1151 function createAssigner(assigner) {
1152 return baseRest(function(object, sources) {
1154 length = sources.length,
1155 customizer = length > 1 ? sources[length - 1] : undefined,
1156 guard = length > 2 ? sources[2] : undefined;
1158 customizer = (assigner.length > 3 && typeof customizer == 'function')
1159 ? (length--, customizer)
1162 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
1163 customizer = length < 3 ? undefined : customizer;
1166 object = Object(object);
1167 while (++index < length) {
1168 var source = sources[index];
1170 assigner(object, source, index, customizer);
1178 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
1181 * @param {boolean} [fromRight] Specify iterating from right to left.
1182 * @returns {Function} Returns the new base function.
1184 function createBaseFor(fromRight) {
1185 return function(object, iteratee, keysFunc) {
1187 iterable = Object(object),
1188 props = keysFunc(object),
1189 length = props.length;
1192 var key = props[fromRight ? length : ++index];
1193 if (iteratee(iterable[key], key, iterable) === false) {
1202 * Gets the data for `map`.
1205 * @param {Object} map The map to query.
1206 * @param {string} key The reference key.
1207 * @returns {*} Returns the map data.
1209 function getMapData(map, key) {
1210 var data = map.__data__;
1211 return isKeyable(key)
1212 ? data[typeof key == 'string' ? 'string' : 'hash']
1217 * Gets the native function at `key` of `object`.
1220 * @param {Object} object The object to query.
1221 * @param {string} key The key of the method to get.
1222 * @returns {*} Returns the function if it's native, else `undefined`.
1224 function getNative(object, key) {
1225 var value = getValue(object, key);
1226 return baseIsNative(value) ? value : undefined;
1230 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
1233 * @param {*} value The value to query.
1234 * @returns {string} Returns the raw `toStringTag`.
1236 function getRawTag(value) {
1237 var isOwn = hasOwnProperty.call(value, symToStringTag),
1238 tag = value[symToStringTag];
1241 value[symToStringTag] = undefined;
1242 var unmasked = true;
1245 var result = nativeObjectToString.call(value);
1248 value[symToStringTag] = tag;
1250 delete value[symToStringTag];
1257 * Initializes an object clone.
1260 * @param {Object} object The object to clone.
1261 * @returns {Object} Returns the initialized clone.
1263 function initCloneObject(object) {
1264 return (typeof object.constructor == 'function' && !isPrototype(object))
1265 ? baseCreate(getPrototype(object))
1270 * Checks if `value` is a valid array-like index.
1273 * @param {*} value The value to check.
1274 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1275 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1277 function isIndex(value, length) {
1278 var type = typeof value;
1279 length = length == null ? MAX_SAFE_INTEGER : length;
1282 (type == 'number' ||
1283 (type != 'symbol' && reIsUint.test(value))) &&
1284 (value > -1 && value % 1 == 0 && value < length);
1288 * Checks if the given arguments are from an iteratee call.
1291 * @param {*} value The potential iteratee value argument.
1292 * @param {*} index The potential iteratee index or key argument.
1293 * @param {*} object The potential iteratee object argument.
1294 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
1297 function isIterateeCall(value, index, object) {
1298 if (!isObject(object)) {
1301 var type = typeof index;
1302 if (type == 'number'
1303 ? (isArrayLike(object) && isIndex(index, object.length))
1304 : (type == 'string' && index in object)
1306 return eq(object[index], value);
1312 * Checks if `value` is suitable for use as unique object key.
1315 * @param {*} value The value to check.
1316 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
1318 function isKeyable(value) {
1319 var type = typeof value;
1320 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
1321 ? (value !== '__proto__')
1326 * Checks if `func` has its source masked.
1329 * @param {Function} func The function to check.
1330 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
1332 function isMasked(func) {
1333 return !!maskSrcKey && (maskSrcKey in func);
1337 * Checks if `value` is likely a prototype object.
1340 * @param {*} value The value to check.
1341 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1343 function isPrototype(value) {
1344 var Ctor = value && value.constructor,
1345 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1347 return value === proto;
1351 * This function is like
1352 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1353 * except that it includes inherited enumerable properties.
1356 * @param {Object} object The object to query.
1357 * @returns {Array} Returns the array of property names.
1359 function nativeKeysIn(object) {
1361 if (object != null) {
1362 for (var key in Object(object)) {
1370 * Converts `value` to a string using `Object.prototype.toString`.
1373 * @param {*} value The value to convert.
1374 * @returns {string} Returns the converted string.
1376 function objectToString(value) {
1377 return nativeObjectToString.call(value);
1381 * A specialized version of `baseRest` which transforms the rest array.
1384 * @param {Function} func The function to apply a rest parameter to.
1385 * @param {number} [start=func.length-1] The start position of the rest parameter.
1386 * @param {Function} transform The rest array transform.
1387 * @returns {Function} Returns the new function.
1389 function overRest(func, start, transform) {
1390 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
1392 var args = arguments,
1394 length = nativeMax(args.length - start, 0),
1395 array = Array(length);
1397 while (++index < length) {
1398 array[index] = args[start + index];
1401 var otherArgs = Array(start + 1);
1402 while (++index < start) {
1403 otherArgs[index] = args[index];
1405 otherArgs[start] = transform(array);
1406 return apply(func, this, otherArgs);
1411 * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
1414 * @param {Object} object The object to query.
1415 * @param {string} key The key of the property to get.
1416 * @returns {*} Returns the property value.
1418 function safeGet(object, key) {
1419 if (key === 'constructor' && typeof object[key] === 'function') {
1423 if (key == '__proto__') {
1431 * Sets the `toString` method of `func` to return `string`.
1434 * @param {Function} func The function to modify.
1435 * @param {Function} string The `toString` result.
1436 * @returns {Function} Returns `func`.
1438 var setToString = shortOut(baseSetToString);
1441 * Creates a function that'll short out and invoke `identity` instead
1442 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
1446 * @param {Function} func The function to restrict.
1447 * @returns {Function} Returns the new shortable function.
1449 function shortOut(func) {
1454 var stamp = nativeNow(),
1455 remaining = HOT_SPAN - (stamp - lastCalled);
1458 if (remaining > 0) {
1459 if (++count >= HOT_COUNT) {
1460 return arguments[0];
1465 return func.apply(undefined, arguments);
1470 * Converts `func` to its source code.
1473 * @param {Function} func The function to convert.
1474 * @returns {string} Returns the source code.
1476 function toSource(func) {
1479 return funcToString.call(func);
1490 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1491 * comparison between two values to determine if they are equivalent.
1497 * @param {*} value The value to compare.
1498 * @param {*} other The other value to compare.
1499 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1502 * var object = { 'a': 1 };
1503 * var other = { 'a': 1 };
1505 * _.eq(object, object);
1508 * _.eq(object, other);
1514 * _.eq('a', Object('a'));
1520 function eq(value, other) {
1521 return value === other || (value !== value && other !== other);
1525 * Checks if `value` is likely an `arguments` object.
1531 * @param {*} value The value to check.
1532 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
1536 * _.isArguments(function() { return arguments; }());
1539 * _.isArguments([1, 2, 3]);
1542 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
1543 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
1544 !propertyIsEnumerable.call(value, 'callee');
1548 * Checks if `value` is classified as an `Array` object.
1554 * @param {*} value The value to check.
1555 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
1558 * _.isArray([1, 2, 3]);
1561 * _.isArray(document.body.children);
1567 * _.isArray(_.noop);
1570 var isArray = Array.isArray;
1573 * Checks if `value` is array-like. A value is considered array-like if it's
1574 * not a function and has a `value.length` that's an integer greater than or
1575 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
1581 * @param {*} value The value to check.
1582 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
1585 * _.isArrayLike([1, 2, 3]);
1588 * _.isArrayLike(document.body.children);
1591 * _.isArrayLike('abc');
1594 * _.isArrayLike(_.noop);
1597 function isArrayLike(value) {
1598 return value != null && isLength(value.length) && !isFunction(value);
1602 * This method is like `_.isArrayLike` except that it also checks if `value`
1609 * @param {*} value The value to check.
1610 * @returns {boolean} Returns `true` if `value` is an array-like object,
1614 * _.isArrayLikeObject([1, 2, 3]);
1617 * _.isArrayLikeObject(document.body.children);
1620 * _.isArrayLikeObject('abc');
1623 * _.isArrayLikeObject(_.noop);
1626 function isArrayLikeObject(value) {
1627 return isObjectLike(value) && isArrayLike(value);
1631 * Checks if `value` is a buffer.
1637 * @param {*} value The value to check.
1638 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
1641 * _.isBuffer(new Buffer(2));
1644 * _.isBuffer(new Uint8Array(2));
1647 var isBuffer = nativeIsBuffer || stubFalse;
1650 * Checks if `value` is classified as a `Function` object.
1656 * @param {*} value The value to check.
1657 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
1663 * _.isFunction(/abc/);
1666 function isFunction(value) {
1667 if (!isObject(value)) {
1670 // The use of `Object#toString` avoids issues with the `typeof` operator
1671 // in Safari 9 which returns 'object' for typed arrays and other constructors.
1672 var tag = baseGetTag(value);
1673 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
1677 * Checks if `value` is a valid array-like length.
1679 * **Note:** This method is loosely based on
1680 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
1686 * @param {*} value The value to check.
1687 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
1693 * _.isLength(Number.MIN_VALUE);
1696 * _.isLength(Infinity);
1702 function isLength(value) {
1703 return typeof value == 'number' &&
1704 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
1708 * Checks if `value` is the
1709 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
1710 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
1716 * @param {*} value The value to check.
1717 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
1723 * _.isObject([1, 2, 3]);
1726 * _.isObject(_.noop);
1732 function isObject(value) {
1733 var type = typeof value;
1734 return value != null && (type == 'object' || type == 'function');
1738 * Checks if `value` is object-like. A value is object-like if it's not `null`
1739 * and has a `typeof` result of "object".
1745 * @param {*} value The value to check.
1746 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1749 * _.isObjectLike({});
1752 * _.isObjectLike([1, 2, 3]);
1755 * _.isObjectLike(_.noop);
1758 * _.isObjectLike(null);
1761 function isObjectLike(value) {
1762 return value != null && typeof value == 'object';
1766 * Checks if `value` is a plain object, that is, an object created by the
1767 * `Object` constructor or one with a `[[Prototype]]` of `null`.
1773 * @param {*} value The value to check.
1774 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
1781 * _.isPlainObject(new Foo);
1784 * _.isPlainObject([1, 2, 3]);
1787 * _.isPlainObject({ 'x': 0, 'y': 0 });
1790 * _.isPlainObject(Object.create(null));
1793 function isPlainObject(value) {
1794 if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
1797 var proto = getPrototype(value);
1798 if (proto === null) {
1801 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
1802 return typeof Ctor == 'function' && Ctor instanceof Ctor &&
1803 funcToString.call(Ctor) == objectCtorString;
1807 * Checks if `value` is classified as a typed array.
1813 * @param {*} value The value to check.
1814 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
1817 * _.isTypedArray(new Uint8Array);
1820 * _.isTypedArray([]);
1823 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
1826 * Converts `value` to a plain object flattening inherited enumerable string
1827 * keyed properties of `value` to own properties of the plain object.
1833 * @param {*} value The value to convert.
1834 * @returns {Object} Returns the converted plain object.
1841 * Foo.prototype.c = 3;
1843 * _.assign({ 'a': 1 }, new Foo);
1844 * // => { 'a': 1, 'b': 2 }
1846 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
1847 * // => { 'a': 1, 'b': 2, 'c': 3 }
1849 function toPlainObject(value) {
1850 return copyObject(value, keysIn(value));
1854 * Creates an array of the own and inherited enumerable property names of `object`.
1856 * **Note:** Non-object values are coerced to objects.
1862 * @param {Object} object The object to query.
1863 * @returns {Array} Returns the array of property names.
1871 * Foo.prototype.c = 3;
1873 * _.keysIn(new Foo);
1874 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
1876 function keysIn(object) {
1877 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
1881 * This method is like `_.assign` except that it recursively merges own and
1882 * inherited enumerable string keyed properties of source objects into the
1883 * destination object. Source properties that resolve to `undefined` are
1884 * skipped if a destination value exists. Array and plain object properties
1885 * are merged recursively. Other objects and value types are overridden by
1886 * assignment. Source objects are applied from left to right. Subsequent
1887 * sources overwrite property assignments of previous sources.
1889 * **Note:** This method mutates `object`.
1895 * @param {Object} object The destination object.
1896 * @param {...Object} [sources] The source objects.
1897 * @returns {Object} Returns `object`.
1901 * 'a': [{ 'b': 2 }, { 'd': 4 }]
1905 * 'a': [{ 'c': 3 }, { 'e': 5 }]
1908 * _.merge(object, other);
1909 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
1911 var merge = createAssigner(function(object, source, srcIndex) {
1912 baseMerge(object, source, srcIndex);
1916 * Creates a function that returns `value`.
1922 * @param {*} value The value to return from the new function.
1923 * @returns {Function} Returns the new constant function.
1926 * var objects = _.times(2, _.constant({ 'a': 1 }));
1928 * console.log(objects);
1929 * // => [{ 'a': 1 }, { 'a': 1 }]
1931 * console.log(objects[0] === objects[1]);
1934 function constant(value) {
1941 * This method returns the first argument it receives.
1947 * @param {*} value Any value.
1948 * @returns {*} Returns `value`.
1951 * var object = { 'a': 1 };
1953 * console.log(_.identity(object) === object);
1956 function identity(value) {
1961 * This method returns `false`.
1967 * @returns {boolean} Returns `false`.
1970 * _.times(2, _.stubFalse);
1971 * // => [false, false]
1973 function stubFalse() {
1977 module.exports = merge;