2 * lodash (Custom Build) <https://lodash.com/>
3 * Build: `lodash modularize exports="npm" -o ./`
4 * Copyright jQuery Foundation and other contributors <https://jquery.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 as references for various `Number` constants. */
17 var MAX_SAFE_INTEGER = 9007199254740991;
19 /** `Object#toString` result references. */
20 var argsTag = '[object Arguments]',
21 arrayTag = '[object Array]',
22 boolTag = '[object Boolean]',
23 dateTag = '[object Date]',
24 errorTag = '[object Error]',
25 funcTag = '[object Function]',
26 genTag = '[object GeneratorFunction]',
27 mapTag = '[object Map]',
28 numberTag = '[object Number]',
29 objectTag = '[object Object]',
30 promiseTag = '[object Promise]',
31 regexpTag = '[object RegExp]',
32 setTag = '[object Set]',
33 stringTag = '[object String]',
34 symbolTag = '[object Symbol]',
35 weakMapTag = '[object WeakMap]';
37 var arrayBufferTag = '[object ArrayBuffer]',
38 dataViewTag = '[object DataView]',
39 float32Tag = '[object Float32Array]',
40 float64Tag = '[object Float64Array]',
41 int8Tag = '[object Int8Array]',
42 int16Tag = '[object Int16Array]',
43 int32Tag = '[object Int32Array]',
44 uint8Tag = '[object Uint8Array]',
45 uint8ClampedTag = '[object Uint8ClampedArray]',
46 uint16Tag = '[object Uint16Array]',
47 uint32Tag = '[object Uint32Array]';
50 * Used to match `RegExp`
51 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
53 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
55 /** Used to match `RegExp` flags from their coerced string values. */
58 /** Used to detect host constructors (Safari). */
59 var reIsHostCtor = /^\[object .+?Constructor\]$/;
61 /** Used to detect unsigned integer values. */
62 var reIsUint = /^(?:0|[1-9]\d*)$/;
64 /** Used to identify `toStringTag` values supported by `_.clone`. */
65 var cloneableTags = {};
66 cloneableTags[argsTag] = cloneableTags[arrayTag] =
67 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
68 cloneableTags[boolTag] = cloneableTags[dateTag] =
69 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
70 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
71 cloneableTags[int32Tag] = cloneableTags[mapTag] =
72 cloneableTags[numberTag] = cloneableTags[objectTag] =
73 cloneableTags[regexpTag] = cloneableTags[setTag] =
74 cloneableTags[stringTag] = cloneableTags[symbolTag] =
75 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
76 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
77 cloneableTags[errorTag] = cloneableTags[funcTag] =
78 cloneableTags[weakMapTag] = false;
80 /** Detect free variable `global` from Node.js. */
81 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
83 /** Detect free variable `self`. */
84 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
86 /** Used as a reference to the global object. */
87 var root = freeGlobal || freeSelf || Function('return this')();
89 /** Detect free variable `exports`. */
90 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
92 /** Detect free variable `module`. */
93 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
95 /** Detect the popular CommonJS extension `module.exports`. */
96 var moduleExports = freeModule && freeModule.exports === freeExports;
99 * Adds the key-value `pair` to `map`.
102 * @param {Object} map The map to modify.
103 * @param {Array} pair The key-value pair to add.
104 * @returns {Object} Returns `map`.
106 function addMapEntry(map, pair) {
107 // Don't return `map.set` because it's not chainable in IE 11.
108 map.set(pair[0], pair[1]);
113 * Adds `value` to `set`.
116 * @param {Object} set The set to modify.
117 * @param {*} value The value to add.
118 * @returns {Object} Returns `set`.
120 function addSetEntry(set, value) {
121 // Don't return `set.add` because it's not chainable in IE 11.
127 * A specialized version of `_.forEach` for arrays without support for
128 * iteratee shorthands.
131 * @param {Array} [array] The array to iterate over.
132 * @param {Function} iteratee The function invoked per iteration.
133 * @returns {Array} Returns `array`.
135 function arrayEach(array, iteratee) {
137 length = array ? array.length : 0;
139 while (++index < length) {
140 if (iteratee(array[index], index, array) === false) {
148 * Appends the elements of `values` to `array`.
151 * @param {Array} array The array to modify.
152 * @param {Array} values The values to append.
153 * @returns {Array} Returns `array`.
155 function arrayPush(array, values) {
157 length = values.length,
158 offset = array.length;
160 while (++index < length) {
161 array[offset + index] = values[index];
167 * A specialized version of `_.reduce` for arrays without support for
168 * iteratee shorthands.
171 * @param {Array} [array] The array to iterate over.
172 * @param {Function} iteratee The function invoked per iteration.
173 * @param {*} [accumulator] The initial value.
174 * @param {boolean} [initAccum] Specify using the first element of `array` as
176 * @returns {*} Returns the accumulated value.
178 function arrayReduce(array, iteratee, accumulator, initAccum) {
180 length = array ? array.length : 0;
182 if (initAccum && length) {
183 accumulator = array[++index];
185 while (++index < length) {
186 accumulator = iteratee(accumulator, array[index], index, array);
192 * The base implementation of `_.times` without support for iteratee shorthands
193 * or max array length checks.
196 * @param {number} n The number of times to invoke `iteratee`.
197 * @param {Function} iteratee The function invoked per iteration.
198 * @returns {Array} Returns the array of results.
200 function baseTimes(n, iteratee) {
204 while (++index < n) {
205 result[index] = iteratee(index);
211 * Gets the value at `key` of `object`.
214 * @param {Object} [object] The object to query.
215 * @param {string} key The key of the property to get.
216 * @returns {*} Returns the property value.
218 function getValue(object, key) {
219 return object == null ? undefined : object[key];
223 * Checks if `value` is a host object in IE < 9.
226 * @param {*} value The value to check.
227 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
229 function isHostObject(value) {
230 // Many host objects are `Object` objects that can coerce to strings
231 // despite having improperly defined `toString` methods.
233 if (value != null && typeof value.toString != 'function') {
235 result = !!(value + '');
242 * Converts `map` to its key-value pairs.
245 * @param {Object} map The map to convert.
246 * @returns {Array} Returns the key-value pairs.
248 function mapToArray(map) {
250 result = Array(map.size);
252 map.forEach(function(value, key) {
253 result[++index] = [key, value];
259 * Creates a unary function that invokes `func` with its argument transformed.
262 * @param {Function} func The function to wrap.
263 * @param {Function} transform The argument transform.
264 * @returns {Function} Returns the new function.
266 function overArg(func, transform) {
267 return function(arg) {
268 return func(transform(arg));
273 * Converts `set` to an array of its values.
276 * @param {Object} set The set to convert.
277 * @returns {Array} Returns the values.
279 function setToArray(set) {
281 result = Array(set.size);
283 set.forEach(function(value) {
284 result[++index] = value;
289 /** Used for built-in method references. */
290 var arrayProto = Array.prototype,
291 funcProto = Function.prototype,
292 objectProto = Object.prototype;
294 /** Used to detect overreaching core-js shims. */
295 var coreJsData = root['__core-js_shared__'];
297 /** Used to detect methods masquerading as native. */
298 var maskSrcKey = (function() {
299 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
300 return uid ? ('Symbol(src)_1.' + uid) : '';
303 /** Used to resolve the decompiled source of functions. */
304 var funcToString = funcProto.toString;
306 /** Used to check objects for own properties. */
307 var hasOwnProperty = objectProto.hasOwnProperty;
310 * Used to resolve the
311 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
314 var objectToString = objectProto.toString;
316 /** Used to detect if a method is native. */
317 var reIsNative = RegExp('^' +
318 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
319 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
322 /** Built-in value references. */
323 var Buffer = moduleExports ? root.Buffer : undefined,
324 Symbol = root.Symbol,
325 Uint8Array = root.Uint8Array,
326 getPrototype = overArg(Object.getPrototypeOf, Object),
327 objectCreate = Object.create,
328 propertyIsEnumerable = objectProto.propertyIsEnumerable,
329 splice = arrayProto.splice;
331 /* Built-in method references for those with the same name as other `lodash` methods. */
332 var nativeGetSymbols = Object.getOwnPropertySymbols,
333 nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
334 nativeKeys = overArg(Object.keys, Object);
336 /* Built-in method references that are verified to be native. */
337 var DataView = getNative(root, 'DataView'),
338 Map = getNative(root, 'Map'),
339 Promise = getNative(root, 'Promise'),
340 Set = getNative(root, 'Set'),
341 WeakMap = getNative(root, 'WeakMap'),
342 nativeCreate = getNative(Object, 'create');
344 /** Used to detect maps, sets, and weakmaps. */
345 var dataViewCtorString = toSource(DataView),
346 mapCtorString = toSource(Map),
347 promiseCtorString = toSource(Promise),
348 setCtorString = toSource(Set),
349 weakMapCtorString = toSource(WeakMap);
351 /** Used to convert symbols to primitives and strings. */
352 var symbolProto = Symbol ? Symbol.prototype : undefined,
353 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
356 * Creates a hash object.
360 * @param {Array} [entries] The key-value pairs to cache.
362 function Hash(entries) {
364 length = entries ? entries.length : 0;
367 while (++index < length) {
368 var entry = entries[index];
369 this.set(entry[0], entry[1]);
374 * Removes all key-value entries from the hash.
380 function hashClear() {
381 this.__data__ = nativeCreate ? nativeCreate(null) : {};
385 * Removes `key` and its value from the hash.
390 * @param {Object} hash The hash to modify.
391 * @param {string} key The key of the value to remove.
392 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
394 function hashDelete(key) {
395 return this.has(key) && delete this.__data__[key];
399 * Gets the hash value for `key`.
404 * @param {string} key The key of the value to get.
405 * @returns {*} Returns the entry value.
407 function hashGet(key) {
408 var data = this.__data__;
410 var result = data[key];
411 return result === HASH_UNDEFINED ? undefined : result;
413 return hasOwnProperty.call(data, key) ? data[key] : undefined;
417 * Checks if a hash value for `key` exists.
422 * @param {string} key The key of the entry to check.
423 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
425 function hashHas(key) {
426 var data = this.__data__;
427 return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
431 * Sets the hash `key` to `value`.
436 * @param {string} key The key of the value to set.
437 * @param {*} value The value to set.
438 * @returns {Object} Returns the hash instance.
440 function hashSet(key, value) {
441 var data = this.__data__;
442 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
446 // Add methods to `Hash`.
447 Hash.prototype.clear = hashClear;
448 Hash.prototype['delete'] = hashDelete;
449 Hash.prototype.get = hashGet;
450 Hash.prototype.has = hashHas;
451 Hash.prototype.set = hashSet;
454 * Creates an list cache object.
458 * @param {Array} [entries] The key-value pairs to cache.
460 function ListCache(entries) {
462 length = entries ? entries.length : 0;
465 while (++index < length) {
466 var entry = entries[index];
467 this.set(entry[0], entry[1]);
472 * Removes all key-value entries from the list cache.
476 * @memberOf ListCache
478 function listCacheClear() {
483 * Removes `key` and its value from the list cache.
487 * @memberOf ListCache
488 * @param {string} key The key of the value to remove.
489 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
491 function listCacheDelete(key) {
492 var data = this.__data__,
493 index = assocIndexOf(data, key);
498 var lastIndex = data.length - 1;
499 if (index == lastIndex) {
502 splice.call(data, index, 1);
508 * Gets the list cache value for `key`.
512 * @memberOf ListCache
513 * @param {string} key The key of the value to get.
514 * @returns {*} Returns the entry value.
516 function listCacheGet(key) {
517 var data = this.__data__,
518 index = assocIndexOf(data, key);
520 return index < 0 ? undefined : data[index][1];
524 * Checks if a list cache value for `key` exists.
528 * @memberOf ListCache
529 * @param {string} key The key of the entry to check.
530 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
532 function listCacheHas(key) {
533 return assocIndexOf(this.__data__, key) > -1;
537 * Sets the list cache `key` to `value`.
541 * @memberOf ListCache
542 * @param {string} key The key of the value to set.
543 * @param {*} value The value to set.
544 * @returns {Object} Returns the list cache instance.
546 function listCacheSet(key, value) {
547 var data = this.__data__,
548 index = assocIndexOf(data, key);
551 data.push([key, value]);
553 data[index][1] = value;
558 // Add methods to `ListCache`.
559 ListCache.prototype.clear = listCacheClear;
560 ListCache.prototype['delete'] = listCacheDelete;
561 ListCache.prototype.get = listCacheGet;
562 ListCache.prototype.has = listCacheHas;
563 ListCache.prototype.set = listCacheSet;
566 * Creates a map cache object to store key-value pairs.
570 * @param {Array} [entries] The key-value pairs to cache.
572 function MapCache(entries) {
574 length = entries ? entries.length : 0;
577 while (++index < length) {
578 var entry = entries[index];
579 this.set(entry[0], entry[1]);
584 * Removes all key-value entries from the map.
590 function mapCacheClear() {
593 'map': new (Map || ListCache),
599 * Removes `key` and its value from the map.
604 * @param {string} key The key of the value to remove.
605 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
607 function mapCacheDelete(key) {
608 return getMapData(this, key)['delete'](key);
612 * Gets the map value for `key`.
617 * @param {string} key The key of the value to get.
618 * @returns {*} Returns the entry value.
620 function mapCacheGet(key) {
621 return getMapData(this, key).get(key);
625 * Checks if a map value for `key` exists.
630 * @param {string} key The key of the entry to check.
631 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
633 function mapCacheHas(key) {
634 return getMapData(this, key).has(key);
638 * Sets the map `key` to `value`.
643 * @param {string} key The key of the value to set.
644 * @param {*} value The value to set.
645 * @returns {Object} Returns the map cache instance.
647 function mapCacheSet(key, value) {
648 getMapData(this, key).set(key, value);
652 // Add methods to `MapCache`.
653 MapCache.prototype.clear = mapCacheClear;
654 MapCache.prototype['delete'] = mapCacheDelete;
655 MapCache.prototype.get = mapCacheGet;
656 MapCache.prototype.has = mapCacheHas;
657 MapCache.prototype.set = mapCacheSet;
660 * Creates a stack cache object to store key-value pairs.
664 * @param {Array} [entries] The key-value pairs to cache.
666 function Stack(entries) {
667 this.__data__ = new ListCache(entries);
671 * Removes all key-value entries from the stack.
677 function stackClear() {
678 this.__data__ = new ListCache;
682 * Removes `key` and its value from the stack.
687 * @param {string} key The key of the value to remove.
688 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
690 function stackDelete(key) {
691 return this.__data__['delete'](key);
695 * Gets the stack value for `key`.
700 * @param {string} key The key of the value to get.
701 * @returns {*} Returns the entry value.
703 function stackGet(key) {
704 return this.__data__.get(key);
708 * Checks if a stack value for `key` exists.
713 * @param {string} key The key of the entry to check.
714 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
716 function stackHas(key) {
717 return this.__data__.has(key);
721 * Sets the stack `key` to `value`.
726 * @param {string} key The key of the value to set.
727 * @param {*} value The value to set.
728 * @returns {Object} Returns the stack cache instance.
730 function stackSet(key, value) {
731 var cache = this.__data__;
732 if (cache instanceof ListCache) {
733 var pairs = cache.__data__;
734 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
735 pairs.push([key, value]);
738 cache = this.__data__ = new MapCache(pairs);
740 cache.set(key, value);
744 // Add methods to `Stack`.
745 Stack.prototype.clear = stackClear;
746 Stack.prototype['delete'] = stackDelete;
747 Stack.prototype.get = stackGet;
748 Stack.prototype.has = stackHas;
749 Stack.prototype.set = stackSet;
752 * Creates an array of the enumerable property names of the array-like `value`.
755 * @param {*} value The value to query.
756 * @param {boolean} inherited Specify returning inherited property names.
757 * @returns {Array} Returns the array of property names.
759 function arrayLikeKeys(value, inherited) {
760 // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
761 // Safari 9 makes `arguments.length` enumerable in strict mode.
762 var result = (isArray(value) || isArguments(value))
763 ? baseTimes(value.length, String)
766 var length = result.length,
767 skipIndexes = !!length;
769 for (var key in value) {
770 if ((inherited || hasOwnProperty.call(value, key)) &&
771 !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
779 * Assigns `value` to `key` of `object` if the existing value is not equivalent
780 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
781 * for equality comparisons.
784 * @param {Object} object The object to modify.
785 * @param {string} key The key of the property to assign.
786 * @param {*} value The value to assign.
788 function assignValue(object, key, value) {
789 var objValue = object[key];
790 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
791 (value === undefined && !(key in object))) {
797 * Gets the index at which the `key` is found in `array` of key-value pairs.
800 * @param {Array} array The array to inspect.
801 * @param {*} key The key to search for.
802 * @returns {number} Returns the index of the matched value, else `-1`.
804 function assocIndexOf(array, key) {
805 var length = array.length;
807 if (eq(array[length][0], key)) {
815 * The base implementation of `_.assign` without support for multiple sources
816 * or `customizer` functions.
819 * @param {Object} object The destination object.
820 * @param {Object} source The source object.
821 * @returns {Object} Returns `object`.
823 function baseAssign(object, source) {
824 return object && copyObject(source, keys(source), object);
828 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
832 * @param {*} value The value to clone.
833 * @param {boolean} [isDeep] Specify a deep clone.
834 * @param {boolean} [isFull] Specify a clone including symbols.
835 * @param {Function} [customizer] The function to customize cloning.
836 * @param {string} [key] The key of `value`.
837 * @param {Object} [object] The parent object of `value`.
838 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
839 * @returns {*} Returns the cloned value.
841 function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
844 result = object ? customizer(value, key, object, stack) : customizer(value);
846 if (result !== undefined) {
849 if (!isObject(value)) {
852 var isArr = isArray(value);
854 result = initCloneArray(value);
856 return copyArray(value, result);
859 var tag = getTag(value),
860 isFunc = tag == funcTag || tag == genTag;
862 if (isBuffer(value)) {
863 return cloneBuffer(value, isDeep);
865 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
866 if (isHostObject(value)) {
867 return object ? value : {};
869 result = initCloneObject(isFunc ? {} : value);
871 return copySymbols(value, baseAssign(result, value));
874 if (!cloneableTags[tag]) {
875 return object ? value : {};
877 result = initCloneByTag(value, tag, baseClone, isDeep);
880 // Check for circular references and return its corresponding clone.
881 stack || (stack = new Stack);
882 var stacked = stack.get(value);
886 stack.set(value, result);
889 var props = isFull ? getAllKeys(value) : keys(value);
891 arrayEach(props || value, function(subValue, key) {
894 subValue = value[key];
896 // Recursively populate clone (susceptible to call stack limits).
897 assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
903 * The base implementation of `_.create` without support for assigning
904 * properties to the created object.
907 * @param {Object} prototype The object to inherit from.
908 * @returns {Object} Returns the new object.
910 function baseCreate(proto) {
911 return isObject(proto) ? objectCreate(proto) : {};
915 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
916 * `keysFunc` and `symbolsFunc` to get the enumerable property names and
917 * symbols of `object`.
920 * @param {Object} object The object to query.
921 * @param {Function} keysFunc The function to get the keys of `object`.
922 * @param {Function} symbolsFunc The function to get the symbols of `object`.
923 * @returns {Array} Returns the array of property names and symbols.
925 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
926 var result = keysFunc(object);
927 return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
931 * The base implementation of `getTag`.
934 * @param {*} value The value to query.
935 * @returns {string} Returns the `toStringTag`.
937 function baseGetTag(value) {
938 return objectToString.call(value);
942 * The base implementation of `_.isNative` without bad shim checks.
945 * @param {*} value The value to check.
946 * @returns {boolean} Returns `true` if `value` is a native function,
949 function baseIsNative(value) {
950 if (!isObject(value) || isMasked(value)) {
953 var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
954 return pattern.test(toSource(value));
958 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
961 * @param {Object} object The object to query.
962 * @returns {Array} Returns the array of property names.
964 function baseKeys(object) {
965 if (!isPrototype(object)) {
966 return nativeKeys(object);
969 for (var key in Object(object)) {
970 if (hasOwnProperty.call(object, key) && key != 'constructor') {
978 * Creates a clone of `buffer`.
981 * @param {Buffer} buffer The buffer to clone.
982 * @param {boolean} [isDeep] Specify a deep clone.
983 * @returns {Buffer} Returns the cloned buffer.
985 function cloneBuffer(buffer, isDeep) {
987 return buffer.slice();
989 var result = new buffer.constructor(buffer.length);
995 * Creates a clone of `arrayBuffer`.
998 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
999 * @returns {ArrayBuffer} Returns the cloned array buffer.
1001 function cloneArrayBuffer(arrayBuffer) {
1002 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
1003 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
1008 * Creates a clone of `dataView`.
1011 * @param {Object} dataView The data view to clone.
1012 * @param {boolean} [isDeep] Specify a deep clone.
1013 * @returns {Object} Returns the cloned data view.
1015 function cloneDataView(dataView, isDeep) {
1016 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
1017 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
1021 * Creates a clone of `map`.
1024 * @param {Object} map The map to clone.
1025 * @param {Function} cloneFunc The function to clone values.
1026 * @param {boolean} [isDeep] Specify a deep clone.
1027 * @returns {Object} Returns the cloned map.
1029 function cloneMap(map, isDeep, cloneFunc) {
1030 var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
1031 return arrayReduce(array, addMapEntry, new map.constructor);
1035 * Creates a clone of `regexp`.
1038 * @param {Object} regexp The regexp to clone.
1039 * @returns {Object} Returns the cloned regexp.
1041 function cloneRegExp(regexp) {
1042 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
1043 result.lastIndex = regexp.lastIndex;
1048 * Creates a clone of `set`.
1051 * @param {Object} set The set to clone.
1052 * @param {Function} cloneFunc The function to clone values.
1053 * @param {boolean} [isDeep] Specify a deep clone.
1054 * @returns {Object} Returns the cloned set.
1056 function cloneSet(set, isDeep, cloneFunc) {
1057 var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
1058 return arrayReduce(array, addSetEntry, new set.constructor);
1062 * Creates a clone of the `symbol` object.
1065 * @param {Object} symbol The symbol object to clone.
1066 * @returns {Object} Returns the cloned symbol object.
1068 function cloneSymbol(symbol) {
1069 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
1073 * Creates a clone of `typedArray`.
1076 * @param {Object} typedArray The typed array to clone.
1077 * @param {boolean} [isDeep] Specify a deep clone.
1078 * @returns {Object} Returns the cloned typed array.
1080 function cloneTypedArray(typedArray, isDeep) {
1081 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
1082 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
1086 * Copies the values of `source` to `array`.
1089 * @param {Array} source The array to copy values from.
1090 * @param {Array} [array=[]] The array to copy values to.
1091 * @returns {Array} Returns `array`.
1093 function copyArray(source, array) {
1095 length = source.length;
1097 array || (array = Array(length));
1098 while (++index < length) {
1099 array[index] = source[index];
1105 * Copies properties of `source` to `object`.
1108 * @param {Object} source The object to copy properties from.
1109 * @param {Array} props The property identifiers to copy.
1110 * @param {Object} [object={}] The object to copy properties to.
1111 * @param {Function} [customizer] The function to customize copied values.
1112 * @returns {Object} Returns `object`.
1114 function copyObject(source, props, object, customizer) {
1115 object || (object = {});
1118 length = props.length;
1120 while (++index < length) {
1121 var key = props[index];
1123 var newValue = customizer
1124 ? customizer(object[key], source[key], key, object, source)
1127 assignValue(object, key, newValue === undefined ? source[key] : newValue);
1133 * Copies own symbol properties of `source` to `object`.
1136 * @param {Object} source The object to copy symbols from.
1137 * @param {Object} [object={}] The object to copy symbols to.
1138 * @returns {Object} Returns `object`.
1140 function copySymbols(source, object) {
1141 return copyObject(source, getSymbols(source), object);
1145 * Creates an array of own enumerable property names and symbols of `object`.
1148 * @param {Object} object The object to query.
1149 * @returns {Array} Returns the array of property names and symbols.
1151 function getAllKeys(object) {
1152 return baseGetAllKeys(object, keys, getSymbols);
1156 * Gets the data for `map`.
1159 * @param {Object} map The map to query.
1160 * @param {string} key The reference key.
1161 * @returns {*} Returns the map data.
1163 function getMapData(map, key) {
1164 var data = map.__data__;
1165 return isKeyable(key)
1166 ? data[typeof key == 'string' ? 'string' : 'hash']
1171 * Gets the native function at `key` of `object`.
1174 * @param {Object} object The object to query.
1175 * @param {string} key The key of the method to get.
1176 * @returns {*} Returns the function if it's native, else `undefined`.
1178 function getNative(object, key) {
1179 var value = getValue(object, key);
1180 return baseIsNative(value) ? value : undefined;
1184 * Creates an array of the own enumerable symbol properties of `object`.
1187 * @param {Object} object The object to query.
1188 * @returns {Array} Returns the array of symbols.
1190 var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
1193 * Gets the `toStringTag` of `value`.
1196 * @param {*} value The value to query.
1197 * @returns {string} Returns the `toStringTag`.
1199 var getTag = baseGetTag;
1201 // Fallback for data views, maps, sets, and weak maps in IE 11,
1202 // for data views in Edge < 14, and promises in Node.js.
1203 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
1204 (Map && getTag(new Map) != mapTag) ||
1205 (Promise && getTag(Promise.resolve()) != promiseTag) ||
1206 (Set && getTag(new Set) != setTag) ||
1207 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
1208 getTag = function(value) {
1209 var result = objectToString.call(value),
1210 Ctor = result == objectTag ? value.constructor : undefined,
1211 ctorString = Ctor ? toSource(Ctor) : undefined;
1214 switch (ctorString) {
1215 case dataViewCtorString: return dataViewTag;
1216 case mapCtorString: return mapTag;
1217 case promiseCtorString: return promiseTag;
1218 case setCtorString: return setTag;
1219 case weakMapCtorString: return weakMapTag;
1227 * Initializes an array clone.
1230 * @param {Array} array The array to clone.
1231 * @returns {Array} Returns the initialized clone.
1233 function initCloneArray(array) {
1234 var length = array.length,
1235 result = array.constructor(length);
1237 // Add properties assigned by `RegExp#exec`.
1238 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
1239 result.index = array.index;
1240 result.input = array.input;
1246 * Initializes an object clone.
1249 * @param {Object} object The object to clone.
1250 * @returns {Object} Returns the initialized clone.
1252 function initCloneObject(object) {
1253 return (typeof object.constructor == 'function' && !isPrototype(object))
1254 ? baseCreate(getPrototype(object))
1259 * Initializes an object clone based on its `toStringTag`.
1261 * **Note:** This function only supports cloning values with tags of
1262 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1265 * @param {Object} object The object to clone.
1266 * @param {string} tag The `toStringTag` of the object to clone.
1267 * @param {Function} cloneFunc The function to clone values.
1268 * @param {boolean} [isDeep] Specify a deep clone.
1269 * @returns {Object} Returns the initialized clone.
1271 function initCloneByTag(object, tag, cloneFunc, isDeep) {
1272 var Ctor = object.constructor;
1274 case arrayBufferTag:
1275 return cloneArrayBuffer(object);
1279 return new Ctor(+object);
1282 return cloneDataView(object, isDeep);
1284 case float32Tag: case float64Tag:
1285 case int8Tag: case int16Tag: case int32Tag:
1286 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
1287 return cloneTypedArray(object, isDeep);
1290 return cloneMap(object, isDeep, cloneFunc);
1294 return new Ctor(object);
1297 return cloneRegExp(object);
1300 return cloneSet(object, isDeep, cloneFunc);
1303 return cloneSymbol(object);
1308 * Checks if `value` is a valid array-like index.
1311 * @param {*} value The value to check.
1312 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1313 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1315 function isIndex(value, length) {
1316 length = length == null ? MAX_SAFE_INTEGER : length;
1318 (typeof value == 'number' || reIsUint.test(value)) &&
1319 (value > -1 && value % 1 == 0 && value < length);
1323 * Checks if `value` is suitable for use as unique object key.
1326 * @param {*} value The value to check.
1327 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
1329 function isKeyable(value) {
1330 var type = typeof value;
1331 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
1332 ? (value !== '__proto__')
1337 * Checks if `func` has its source masked.
1340 * @param {Function} func The function to check.
1341 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
1343 function isMasked(func) {
1344 return !!maskSrcKey && (maskSrcKey in func);
1348 * Checks if `value` is likely a prototype object.
1351 * @param {*} value The value to check.
1352 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1354 function isPrototype(value) {
1355 var Ctor = value && value.constructor,
1356 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1358 return value === proto;
1362 * Converts `func` to its source code.
1365 * @param {Function} func The function to process.
1366 * @returns {string} Returns the source code.
1368 function toSource(func) {
1371 return funcToString.call(func);
1381 * This method is like `_.clone` except that it recursively clones `value`.
1387 * @param {*} value The value to recursively clone.
1388 * @returns {*} Returns the deep cloned value.
1392 * var objects = [{ 'a': 1 }, { 'b': 2 }];
1394 * var deep = _.cloneDeep(objects);
1395 * console.log(deep[0] === objects[0]);
1398 function cloneDeep(value) {
1399 return baseClone(value, true, true);
1404 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1405 * comparison between two values to determine if they are equivalent.
1411 * @param {*} value The value to compare.
1412 * @param {*} other The other value to compare.
1413 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1416 * var object = { 'a': 1 };
1417 * var other = { 'a': 1 };
1419 * _.eq(object, object);
1422 * _.eq(object, other);
1428 * _.eq('a', Object('a'));
1434 function eq(value, other) {
1435 return value === other || (value !== value && other !== other);
1439 * Checks if `value` is likely an `arguments` object.
1445 * @param {*} value The value to check.
1446 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
1450 * _.isArguments(function() { return arguments; }());
1453 * _.isArguments([1, 2, 3]);
1456 function isArguments(value) {
1457 // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
1458 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
1459 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
1463 * Checks if `value` is classified as an `Array` object.
1469 * @param {*} value The value to check.
1470 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
1473 * _.isArray([1, 2, 3]);
1476 * _.isArray(document.body.children);
1482 * _.isArray(_.noop);
1485 var isArray = Array.isArray;
1488 * Checks if `value` is array-like. A value is considered array-like if it's
1489 * not a function and has a `value.length` that's an integer greater than or
1490 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
1496 * @param {*} value The value to check.
1497 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
1500 * _.isArrayLike([1, 2, 3]);
1503 * _.isArrayLike(document.body.children);
1506 * _.isArrayLike('abc');
1509 * _.isArrayLike(_.noop);
1512 function isArrayLike(value) {
1513 return value != null && isLength(value.length) && !isFunction(value);
1517 * This method is like `_.isArrayLike` except that it also checks if `value`
1524 * @param {*} value The value to check.
1525 * @returns {boolean} Returns `true` if `value` is an array-like object,
1529 * _.isArrayLikeObject([1, 2, 3]);
1532 * _.isArrayLikeObject(document.body.children);
1535 * _.isArrayLikeObject('abc');
1538 * _.isArrayLikeObject(_.noop);
1541 function isArrayLikeObject(value) {
1542 return isObjectLike(value) && isArrayLike(value);
1546 * Checks if `value` is a buffer.
1552 * @param {*} value The value to check.
1553 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
1556 * _.isBuffer(new Buffer(2));
1559 * _.isBuffer(new Uint8Array(2));
1562 var isBuffer = nativeIsBuffer || stubFalse;
1565 * Checks if `value` is classified as a `Function` object.
1571 * @param {*} value The value to check.
1572 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
1578 * _.isFunction(/abc/);
1581 function isFunction(value) {
1582 // The use of `Object#toString` avoids issues with the `typeof` operator
1583 // in Safari 8-9 which returns 'object' for typed array and other constructors.
1584 var tag = isObject(value) ? objectToString.call(value) : '';
1585 return tag == funcTag || tag == genTag;
1589 * Checks if `value` is a valid array-like length.
1591 * **Note:** This method is loosely based on
1592 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
1598 * @param {*} value The value to check.
1599 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
1605 * _.isLength(Number.MIN_VALUE);
1608 * _.isLength(Infinity);
1614 function isLength(value) {
1615 return typeof value == 'number' &&
1616 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
1620 * Checks if `value` is the
1621 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
1622 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
1628 * @param {*} value The value to check.
1629 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
1635 * _.isObject([1, 2, 3]);
1638 * _.isObject(_.noop);
1644 function isObject(value) {
1645 var type = typeof value;
1646 return !!value && (type == 'object' || type == 'function');
1650 * Checks if `value` is object-like. A value is object-like if it's not `null`
1651 * and has a `typeof` result of "object".
1657 * @param {*} value The value to check.
1658 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1661 * _.isObjectLike({});
1664 * _.isObjectLike([1, 2, 3]);
1667 * _.isObjectLike(_.noop);
1670 * _.isObjectLike(null);
1673 function isObjectLike(value) {
1674 return !!value && typeof value == 'object';
1678 * Creates an array of the own enumerable property names of `object`.
1680 * **Note:** Non-object values are coerced to objects. See the
1681 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1688 * @param {Object} object The object to query.
1689 * @returns {Array} Returns the array of property names.
1697 * Foo.prototype.c = 3;
1700 * // => ['a', 'b'] (iteration order is not guaranteed)
1705 function keys(object) {
1706 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
1710 * This method returns a new empty array.
1716 * @returns {Array} Returns the new empty array.
1719 * var arrays = _.times(2, _.stubArray);
1721 * console.log(arrays);
1724 * console.log(arrays[0] === arrays[1]);
1727 function stubArray() {
1732 * This method returns `false`.
1738 * @returns {boolean} Returns `false`.
1741 * _.times(2, _.stubFalse);
1742 * // => [false, false]
1744 function stubFalse() {
1748 module.exports = cloneDeep;