Initial commit
[yaffs-website] / node_modules / lodash.mergewith / index.js
1 /**
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
8  */
9
10 /** Used as the size to enable large array optimizations. */
11 var LARGE_ARRAY_SIZE = 200;
12
13 /** Used to stand-in for `undefined` hash values. */
14 var HASH_UNDEFINED = '__lodash_hash_undefined__';
15
16 /** Used as references for various `Number` constants. */
17 var MAX_SAFE_INTEGER = 9007199254740991;
18
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]';
36
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]';
48
49 /**
50  * Used to match `RegExp`
51  * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
52  */
53 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
54
55 /** Used to match `RegExp` flags from their coerced string values. */
56 var reFlags = /\w*$/;
57
58 /** Used to detect host constructors (Safari). */
59 var reIsHostCtor = /^\[object .+?Constructor\]$/;
60
61 /** Used to detect unsigned integer values. */
62 var reIsUint = /^(?:0|[1-9]\d*)$/;
63
64 /** Used to identify `toStringTag` values of typed arrays. */
65 var typedArrayTags = {};
66 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
67 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
68 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
69 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
70 typedArrayTags[uint32Tag] = true;
71 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
72 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
73 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
74 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
75 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
76 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
77 typedArrayTags[setTag] = typedArrayTags[stringTag] =
78 typedArrayTags[weakMapTag] = false;
79
80 /** Used to identify `toStringTag` values supported by `_.clone`. */
81 var cloneableTags = {};
82 cloneableTags[argsTag] = cloneableTags[arrayTag] =
83 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
84 cloneableTags[boolTag] = cloneableTags[dateTag] =
85 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
86 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
87 cloneableTags[int32Tag] = cloneableTags[mapTag] =
88 cloneableTags[numberTag] = cloneableTags[objectTag] =
89 cloneableTags[regexpTag] = cloneableTags[setTag] =
90 cloneableTags[stringTag] = cloneableTags[symbolTag] =
91 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
92 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
93 cloneableTags[errorTag] = cloneableTags[funcTag] =
94 cloneableTags[weakMapTag] = false;
95
96 /** Detect free variable `global` from Node.js. */
97 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
98
99 /** Detect free variable `self`. */
100 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
101
102 /** Used as a reference to the global object. */
103 var root = freeGlobal || freeSelf || Function('return this')();
104
105 /** Detect free variable `exports`. */
106 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
107
108 /** Detect free variable `module`. */
109 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
110
111 /** Detect the popular CommonJS extension `module.exports`. */
112 var moduleExports = freeModule && freeModule.exports === freeExports;
113
114 /** Detect free variable `process` from Node.js. */
115 var freeProcess = moduleExports && freeGlobal.process;
116
117 /** Used to access faster Node.js helpers. */
118 var nodeUtil = (function() {
119   try {
120     return freeProcess && freeProcess.binding('util');
121   } catch (e) {}
122 }());
123
124 /* Node.js helper references. */
125 var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
126
127 /**
128  * Adds the key-value `pair` to `map`.
129  *
130  * @private
131  * @param {Object} map The map to modify.
132  * @param {Array} pair The key-value pair to add.
133  * @returns {Object} Returns `map`.
134  */
135 function addMapEntry(map, pair) {
136   // Don't return `map.set` because it's not chainable in IE 11.
137   map.set(pair[0], pair[1]);
138   return map;
139 }
140
141 /**
142  * Adds `value` to `set`.
143  *
144  * @private
145  * @param {Object} set The set to modify.
146  * @param {*} value The value to add.
147  * @returns {Object} Returns `set`.
148  */
149 function addSetEntry(set, value) {
150   // Don't return `set.add` because it's not chainable in IE 11.
151   set.add(value);
152   return set;
153 }
154
155 /**
156  * A faster alternative to `Function#apply`, this function invokes `func`
157  * with the `this` binding of `thisArg` and the arguments of `args`.
158  *
159  * @private
160  * @param {Function} func The function to invoke.
161  * @param {*} thisArg The `this` binding of `func`.
162  * @param {Array} args The arguments to invoke `func` with.
163  * @returns {*} Returns the result of `func`.
164  */
165 function apply(func, thisArg, args) {
166   switch (args.length) {
167     case 0: return func.call(thisArg);
168     case 1: return func.call(thisArg, args[0]);
169     case 2: return func.call(thisArg, args[0], args[1]);
170     case 3: return func.call(thisArg, args[0], args[1], args[2]);
171   }
172   return func.apply(thisArg, args);
173 }
174
175 /**
176  * A specialized version of `_.forEach` for arrays without support for
177  * iteratee shorthands.
178  *
179  * @private
180  * @param {Array} [array] The array to iterate over.
181  * @param {Function} iteratee The function invoked per iteration.
182  * @returns {Array} Returns `array`.
183  */
184 function arrayEach(array, iteratee) {
185   var index = -1,
186       length = array ? array.length : 0;
187
188   while (++index < length) {
189     if (iteratee(array[index], index, array) === false) {
190       break;
191     }
192   }
193   return array;
194 }
195
196 /**
197  * Appends the elements of `values` to `array`.
198  *
199  * @private
200  * @param {Array} array The array to modify.
201  * @param {Array} values The values to append.
202  * @returns {Array} Returns `array`.
203  */
204 function arrayPush(array, values) {
205   var index = -1,
206       length = values.length,
207       offset = array.length;
208
209   while (++index < length) {
210     array[offset + index] = values[index];
211   }
212   return array;
213 }
214
215 /**
216  * A specialized version of `_.reduce` for arrays without support for
217  * iteratee shorthands.
218  *
219  * @private
220  * @param {Array} [array] The array to iterate over.
221  * @param {Function} iteratee The function invoked per iteration.
222  * @param {*} [accumulator] The initial value.
223  * @param {boolean} [initAccum] Specify using the first element of `array` as
224  *  the initial value.
225  * @returns {*} Returns the accumulated value.
226  */
227 function arrayReduce(array, iteratee, accumulator, initAccum) {
228   var index = -1,
229       length = array ? array.length : 0;
230
231   if (initAccum && length) {
232     accumulator = array[++index];
233   }
234   while (++index < length) {
235     accumulator = iteratee(accumulator, array[index], index, array);
236   }
237   return accumulator;
238 }
239
240 /**
241  * The base implementation of `_.times` without support for iteratee shorthands
242  * or max array length checks.
243  *
244  * @private
245  * @param {number} n The number of times to invoke `iteratee`.
246  * @param {Function} iteratee The function invoked per iteration.
247  * @returns {Array} Returns the array of results.
248  */
249 function baseTimes(n, iteratee) {
250   var index = -1,
251       result = Array(n);
252
253   while (++index < n) {
254     result[index] = iteratee(index);
255   }
256   return result;
257 }
258
259 /**
260  * The base implementation of `_.unary` without support for storing metadata.
261  *
262  * @private
263  * @param {Function} func The function to cap arguments for.
264  * @returns {Function} Returns the new capped function.
265  */
266 function baseUnary(func) {
267   return function(value) {
268     return func(value);
269   };
270 }
271
272 /**
273  * Gets the value at `key` of `object`.
274  *
275  * @private
276  * @param {Object} [object] The object to query.
277  * @param {string} key The key of the property to get.
278  * @returns {*} Returns the property value.
279  */
280 function getValue(object, key) {
281   return object == null ? undefined : object[key];
282 }
283
284 /**
285  * Checks if `value` is a host object in IE < 9.
286  *
287  * @private
288  * @param {*} value The value to check.
289  * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
290  */
291 function isHostObject(value) {
292   // Many host objects are `Object` objects that can coerce to strings
293   // despite having improperly defined `toString` methods.
294   var result = false;
295   if (value != null && typeof value.toString != 'function') {
296     try {
297       result = !!(value + '');
298     } catch (e) {}
299   }
300   return result;
301 }
302
303 /**
304  * Converts `map` to its key-value pairs.
305  *
306  * @private
307  * @param {Object} map The map to convert.
308  * @returns {Array} Returns the key-value pairs.
309  */
310 function mapToArray(map) {
311   var index = -1,
312       result = Array(map.size);
313
314   map.forEach(function(value, key) {
315     result[++index] = [key, value];
316   });
317   return result;
318 }
319
320 /**
321  * Creates a unary function that invokes `func` with its argument transformed.
322  *
323  * @private
324  * @param {Function} func The function to wrap.
325  * @param {Function} transform The argument transform.
326  * @returns {Function} Returns the new function.
327  */
328 function overArg(func, transform) {
329   return function(arg) {
330     return func(transform(arg));
331   };
332 }
333
334 /**
335  * Converts `set` to an array of its values.
336  *
337  * @private
338  * @param {Object} set The set to convert.
339  * @returns {Array} Returns the values.
340  */
341 function setToArray(set) {
342   var index = -1,
343       result = Array(set.size);
344
345   set.forEach(function(value) {
346     result[++index] = value;
347   });
348   return result;
349 }
350
351 /** Used for built-in method references. */
352 var arrayProto = Array.prototype,
353     funcProto = Function.prototype,
354     objectProto = Object.prototype;
355
356 /** Used to detect overreaching core-js shims. */
357 var coreJsData = root['__core-js_shared__'];
358
359 /** Used to detect methods masquerading as native. */
360 var maskSrcKey = (function() {
361   var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
362   return uid ? ('Symbol(src)_1.' + uid) : '';
363 }());
364
365 /** Used to resolve the decompiled source of functions. */
366 var funcToString = funcProto.toString;
367
368 /** Used to check objects for own properties. */
369 var hasOwnProperty = objectProto.hasOwnProperty;
370
371 /** Used to infer the `Object` constructor. */
372 var objectCtorString = funcToString.call(Object);
373
374 /**
375  * Used to resolve the
376  * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
377  * of values.
378  */
379 var objectToString = objectProto.toString;
380
381 /** Used to detect if a method is native. */
382 var reIsNative = RegExp('^' +
383   funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
384   .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
385 );
386
387 /** Built-in value references. */
388 var Buffer = moduleExports ? root.Buffer : undefined,
389     Symbol = root.Symbol,
390     Uint8Array = root.Uint8Array,
391     getPrototype = overArg(Object.getPrototypeOf, Object),
392     objectCreate = Object.create,
393     propertyIsEnumerable = objectProto.propertyIsEnumerable,
394     splice = arrayProto.splice;
395
396 /* Built-in method references for those with the same name as other `lodash` methods. */
397 var nativeGetSymbols = Object.getOwnPropertySymbols,
398     nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
399     nativeKeys = overArg(Object.keys, Object),
400     nativeMax = Math.max;
401
402 /* Built-in method references that are verified to be native. */
403 var DataView = getNative(root, 'DataView'),
404     Map = getNative(root, 'Map'),
405     Promise = getNative(root, 'Promise'),
406     Set = getNative(root, 'Set'),
407     WeakMap = getNative(root, 'WeakMap'),
408     nativeCreate = getNative(Object, 'create');
409
410 /** Used to detect maps, sets, and weakmaps. */
411 var dataViewCtorString = toSource(DataView),
412     mapCtorString = toSource(Map),
413     promiseCtorString = toSource(Promise),
414     setCtorString = toSource(Set),
415     weakMapCtorString = toSource(WeakMap);
416
417 /** Used to convert symbols to primitives and strings. */
418 var symbolProto = Symbol ? Symbol.prototype : undefined,
419     symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
420
421 /**
422  * Creates a hash object.
423  *
424  * @private
425  * @constructor
426  * @param {Array} [entries] The key-value pairs to cache.
427  */
428 function Hash(entries) {
429   var index = -1,
430       length = entries ? entries.length : 0;
431
432   this.clear();
433   while (++index < length) {
434     var entry = entries[index];
435     this.set(entry[0], entry[1]);
436   }
437 }
438
439 /**
440  * Removes all key-value entries from the hash.
441  *
442  * @private
443  * @name clear
444  * @memberOf Hash
445  */
446 function hashClear() {
447   this.__data__ = nativeCreate ? nativeCreate(null) : {};
448 }
449
450 /**
451  * Removes `key` and its value from the hash.
452  *
453  * @private
454  * @name delete
455  * @memberOf Hash
456  * @param {Object} hash The hash to modify.
457  * @param {string} key The key of the value to remove.
458  * @returns {boolean} Returns `true` if the entry was removed, else `false`.
459  */
460 function hashDelete(key) {
461   return this.has(key) && delete this.__data__[key];
462 }
463
464 /**
465  * Gets the hash value for `key`.
466  *
467  * @private
468  * @name get
469  * @memberOf Hash
470  * @param {string} key The key of the value to get.
471  * @returns {*} Returns the entry value.
472  */
473 function hashGet(key) {
474   var data = this.__data__;
475   if (nativeCreate) {
476     var result = data[key];
477     return result === HASH_UNDEFINED ? undefined : result;
478   }
479   return hasOwnProperty.call(data, key) ? data[key] : undefined;
480 }
481
482 /**
483  * Checks if a hash value for `key` exists.
484  *
485  * @private
486  * @name has
487  * @memberOf Hash
488  * @param {string} key The key of the entry to check.
489  * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
490  */
491 function hashHas(key) {
492   var data = this.__data__;
493   return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
494 }
495
496 /**
497  * Sets the hash `key` to `value`.
498  *
499  * @private
500  * @name set
501  * @memberOf Hash
502  * @param {string} key The key of the value to set.
503  * @param {*} value The value to set.
504  * @returns {Object} Returns the hash instance.
505  */
506 function hashSet(key, value) {
507   var data = this.__data__;
508   data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
509   return this;
510 }
511
512 // Add methods to `Hash`.
513 Hash.prototype.clear = hashClear;
514 Hash.prototype['delete'] = hashDelete;
515 Hash.prototype.get = hashGet;
516 Hash.prototype.has = hashHas;
517 Hash.prototype.set = hashSet;
518
519 /**
520  * Creates an list cache object.
521  *
522  * @private
523  * @constructor
524  * @param {Array} [entries] The key-value pairs to cache.
525  */
526 function ListCache(entries) {
527   var index = -1,
528       length = entries ? entries.length : 0;
529
530   this.clear();
531   while (++index < length) {
532     var entry = entries[index];
533     this.set(entry[0], entry[1]);
534   }
535 }
536
537 /**
538  * Removes all key-value entries from the list cache.
539  *
540  * @private
541  * @name clear
542  * @memberOf ListCache
543  */
544 function listCacheClear() {
545   this.__data__ = [];
546 }
547
548 /**
549  * Removes `key` and its value from the list cache.
550  *
551  * @private
552  * @name delete
553  * @memberOf ListCache
554  * @param {string} key The key of the value to remove.
555  * @returns {boolean} Returns `true` if the entry was removed, else `false`.
556  */
557 function listCacheDelete(key) {
558   var data = this.__data__,
559       index = assocIndexOf(data, key);
560
561   if (index < 0) {
562     return false;
563   }
564   var lastIndex = data.length - 1;
565   if (index == lastIndex) {
566     data.pop();
567   } else {
568     splice.call(data, index, 1);
569   }
570   return true;
571 }
572
573 /**
574  * Gets the list cache value for `key`.
575  *
576  * @private
577  * @name get
578  * @memberOf ListCache
579  * @param {string} key The key of the value to get.
580  * @returns {*} Returns the entry value.
581  */
582 function listCacheGet(key) {
583   var data = this.__data__,
584       index = assocIndexOf(data, key);
585
586   return index < 0 ? undefined : data[index][1];
587 }
588
589 /**
590  * Checks if a list cache value for `key` exists.
591  *
592  * @private
593  * @name has
594  * @memberOf ListCache
595  * @param {string} key The key of the entry to check.
596  * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
597  */
598 function listCacheHas(key) {
599   return assocIndexOf(this.__data__, key) > -1;
600 }
601
602 /**
603  * Sets the list cache `key` to `value`.
604  *
605  * @private
606  * @name set
607  * @memberOf ListCache
608  * @param {string} key The key of the value to set.
609  * @param {*} value The value to set.
610  * @returns {Object} Returns the list cache instance.
611  */
612 function listCacheSet(key, value) {
613   var data = this.__data__,
614       index = assocIndexOf(data, key);
615
616   if (index < 0) {
617     data.push([key, value]);
618   } else {
619     data[index][1] = value;
620   }
621   return this;
622 }
623
624 // Add methods to `ListCache`.
625 ListCache.prototype.clear = listCacheClear;
626 ListCache.prototype['delete'] = listCacheDelete;
627 ListCache.prototype.get = listCacheGet;
628 ListCache.prototype.has = listCacheHas;
629 ListCache.prototype.set = listCacheSet;
630
631 /**
632  * Creates a map cache object to store key-value pairs.
633  *
634  * @private
635  * @constructor
636  * @param {Array} [entries] The key-value pairs to cache.
637  */
638 function MapCache(entries) {
639   var index = -1,
640       length = entries ? entries.length : 0;
641
642   this.clear();
643   while (++index < length) {
644     var entry = entries[index];
645     this.set(entry[0], entry[1]);
646   }
647 }
648
649 /**
650  * Removes all key-value entries from the map.
651  *
652  * @private
653  * @name clear
654  * @memberOf MapCache
655  */
656 function mapCacheClear() {
657   this.__data__ = {
658     'hash': new Hash,
659     'map': new (Map || ListCache),
660     'string': new Hash
661   };
662 }
663
664 /**
665  * Removes `key` and its value from the map.
666  *
667  * @private
668  * @name delete
669  * @memberOf MapCache
670  * @param {string} key The key of the value to remove.
671  * @returns {boolean} Returns `true` if the entry was removed, else `false`.
672  */
673 function mapCacheDelete(key) {
674   return getMapData(this, key)['delete'](key);
675 }
676
677 /**
678  * Gets the map value for `key`.
679  *
680  * @private
681  * @name get
682  * @memberOf MapCache
683  * @param {string} key The key of the value to get.
684  * @returns {*} Returns the entry value.
685  */
686 function mapCacheGet(key) {
687   return getMapData(this, key).get(key);
688 }
689
690 /**
691  * Checks if a map value for `key` exists.
692  *
693  * @private
694  * @name has
695  * @memberOf MapCache
696  * @param {string} key The key of the entry to check.
697  * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
698  */
699 function mapCacheHas(key) {
700   return getMapData(this, key).has(key);
701 }
702
703 /**
704  * Sets the map `key` to `value`.
705  *
706  * @private
707  * @name set
708  * @memberOf MapCache
709  * @param {string} key The key of the value to set.
710  * @param {*} value The value to set.
711  * @returns {Object} Returns the map cache instance.
712  */
713 function mapCacheSet(key, value) {
714   getMapData(this, key).set(key, value);
715   return this;
716 }
717
718 // Add methods to `MapCache`.
719 MapCache.prototype.clear = mapCacheClear;
720 MapCache.prototype['delete'] = mapCacheDelete;
721 MapCache.prototype.get = mapCacheGet;
722 MapCache.prototype.has = mapCacheHas;
723 MapCache.prototype.set = mapCacheSet;
724
725 /**
726  * Creates a stack cache object to store key-value pairs.
727  *
728  * @private
729  * @constructor
730  * @param {Array} [entries] The key-value pairs to cache.
731  */
732 function Stack(entries) {
733   this.__data__ = new ListCache(entries);
734 }
735
736 /**
737  * Removes all key-value entries from the stack.
738  *
739  * @private
740  * @name clear
741  * @memberOf Stack
742  */
743 function stackClear() {
744   this.__data__ = new ListCache;
745 }
746
747 /**
748  * Removes `key` and its value from the stack.
749  *
750  * @private
751  * @name delete
752  * @memberOf Stack
753  * @param {string} key The key of the value to remove.
754  * @returns {boolean} Returns `true` if the entry was removed, else `false`.
755  */
756 function stackDelete(key) {
757   return this.__data__['delete'](key);
758 }
759
760 /**
761  * Gets the stack value for `key`.
762  *
763  * @private
764  * @name get
765  * @memberOf Stack
766  * @param {string} key The key of the value to get.
767  * @returns {*} Returns the entry value.
768  */
769 function stackGet(key) {
770   return this.__data__.get(key);
771 }
772
773 /**
774  * Checks if a stack value for `key` exists.
775  *
776  * @private
777  * @name has
778  * @memberOf Stack
779  * @param {string} key The key of the entry to check.
780  * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
781  */
782 function stackHas(key) {
783   return this.__data__.has(key);
784 }
785
786 /**
787  * Sets the stack `key` to `value`.
788  *
789  * @private
790  * @name set
791  * @memberOf Stack
792  * @param {string} key The key of the value to set.
793  * @param {*} value The value to set.
794  * @returns {Object} Returns the stack cache instance.
795  */
796 function stackSet(key, value) {
797   var cache = this.__data__;
798   if (cache instanceof ListCache) {
799     var pairs = cache.__data__;
800     if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
801       pairs.push([key, value]);
802       return this;
803     }
804     cache = this.__data__ = new MapCache(pairs);
805   }
806   cache.set(key, value);
807   return this;
808 }
809
810 // Add methods to `Stack`.
811 Stack.prototype.clear = stackClear;
812 Stack.prototype['delete'] = stackDelete;
813 Stack.prototype.get = stackGet;
814 Stack.prototype.has = stackHas;
815 Stack.prototype.set = stackSet;
816
817 /**
818  * Creates an array of the enumerable property names of the array-like `value`.
819  *
820  * @private
821  * @param {*} value The value to query.
822  * @param {boolean} inherited Specify returning inherited property names.
823  * @returns {Array} Returns the array of property names.
824  */
825 function arrayLikeKeys(value, inherited) {
826   // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
827   // Safari 9 makes `arguments.length` enumerable in strict mode.
828   var result = (isArray(value) || isArguments(value))
829     ? baseTimes(value.length, String)
830     : [];
831
832   var length = result.length,
833       skipIndexes = !!length;
834
835   for (var key in value) {
836     if ((inherited || hasOwnProperty.call(value, key)) &&
837         !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
838       result.push(key);
839     }
840   }
841   return result;
842 }
843
844 /**
845  * This function is like `assignValue` except that it doesn't assign
846  * `undefined` values.
847  *
848  * @private
849  * @param {Object} object The object to modify.
850  * @param {string} key The key of the property to assign.
851  * @param {*} value The value to assign.
852  */
853 function assignMergeValue(object, key, value) {
854   if ((value !== undefined && !eq(object[key], value)) ||
855       (typeof key == 'number' && value === undefined && !(key in object))) {
856     object[key] = value;
857   }
858 }
859
860 /**
861  * Assigns `value` to `key` of `object` if the existing value is not equivalent
862  * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
863  * for equality comparisons.
864  *
865  * @private
866  * @param {Object} object The object to modify.
867  * @param {string} key The key of the property to assign.
868  * @param {*} value The value to assign.
869  */
870 function assignValue(object, key, value) {
871   var objValue = object[key];
872   if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
873       (value === undefined && !(key in object))) {
874     object[key] = value;
875   }
876 }
877
878 /**
879  * Gets the index at which the `key` is found in `array` of key-value pairs.
880  *
881  * @private
882  * @param {Array} array The array to inspect.
883  * @param {*} key The key to search for.
884  * @returns {number} Returns the index of the matched value, else `-1`.
885  */
886 function assocIndexOf(array, key) {
887   var length = array.length;
888   while (length--) {
889     if (eq(array[length][0], key)) {
890       return length;
891     }
892   }
893   return -1;
894 }
895
896 /**
897  * The base implementation of `_.assign` without support for multiple sources
898  * or `customizer` functions.
899  *
900  * @private
901  * @param {Object} object The destination object.
902  * @param {Object} source The source object.
903  * @returns {Object} Returns `object`.
904  */
905 function baseAssign(object, source) {
906   return object && copyObject(source, keys(source), object);
907 }
908
909 /**
910  * The base implementation of `_.clone` and `_.cloneDeep` which tracks
911  * traversed objects.
912  *
913  * @private
914  * @param {*} value The value to clone.
915  * @param {boolean} [isDeep] Specify a deep clone.
916  * @param {boolean} [isFull] Specify a clone including symbols.
917  * @param {Function} [customizer] The function to customize cloning.
918  * @param {string} [key] The key of `value`.
919  * @param {Object} [object] The parent object of `value`.
920  * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
921  * @returns {*} Returns the cloned value.
922  */
923 function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
924   var result;
925   if (customizer) {
926     result = object ? customizer(value, key, object, stack) : customizer(value);
927   }
928   if (result !== undefined) {
929     return result;
930   }
931   if (!isObject(value)) {
932     return value;
933   }
934   var isArr = isArray(value);
935   if (isArr) {
936     result = initCloneArray(value);
937     if (!isDeep) {
938       return copyArray(value, result);
939     }
940   } else {
941     var tag = getTag(value),
942         isFunc = tag == funcTag || tag == genTag;
943
944     if (isBuffer(value)) {
945       return cloneBuffer(value, isDeep);
946     }
947     if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
948       if (isHostObject(value)) {
949         return object ? value : {};
950       }
951       result = initCloneObject(isFunc ? {} : value);
952       if (!isDeep) {
953         return copySymbols(value, baseAssign(result, value));
954       }
955     } else {
956       if (!cloneableTags[tag]) {
957         return object ? value : {};
958       }
959       result = initCloneByTag(value, tag, baseClone, isDeep);
960     }
961   }
962   // Check for circular references and return its corresponding clone.
963   stack || (stack = new Stack);
964   var stacked = stack.get(value);
965   if (stacked) {
966     return stacked;
967   }
968   stack.set(value, result);
969
970   if (!isArr) {
971     var props = isFull ? getAllKeys(value) : keys(value);
972   }
973   arrayEach(props || value, function(subValue, key) {
974     if (props) {
975       key = subValue;
976       subValue = value[key];
977     }
978     // Recursively populate clone (susceptible to call stack limits).
979     assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
980   });
981   return result;
982 }
983
984 /**
985  * The base implementation of `_.create` without support for assigning
986  * properties to the created object.
987  *
988  * @private
989  * @param {Object} prototype The object to inherit from.
990  * @returns {Object} Returns the new object.
991  */
992 function baseCreate(proto) {
993   return isObject(proto) ? objectCreate(proto) : {};
994 }
995
996 /**
997  * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
998  * `keysFunc` and `symbolsFunc` to get the enumerable property names and
999  * symbols of `object`.
1000  *
1001  * @private
1002  * @param {Object} object The object to query.
1003  * @param {Function} keysFunc The function to get the keys of `object`.
1004  * @param {Function} symbolsFunc The function to get the symbols of `object`.
1005  * @returns {Array} Returns the array of property names and symbols.
1006  */
1007 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
1008   var result = keysFunc(object);
1009   return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
1010 }
1011
1012 /**
1013  * The base implementation of `getTag`.
1014  *
1015  * @private
1016  * @param {*} value The value to query.
1017  * @returns {string} Returns the `toStringTag`.
1018  */
1019 function baseGetTag(value) {
1020   return objectToString.call(value);
1021 }
1022
1023 /**
1024  * The base implementation of `_.isNative` without bad shim checks.
1025  *
1026  * @private
1027  * @param {*} value The value to check.
1028  * @returns {boolean} Returns `true` if `value` is a native function,
1029  *  else `false`.
1030  */
1031 function baseIsNative(value) {
1032   if (!isObject(value) || isMasked(value)) {
1033     return false;
1034   }
1035   var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
1036   return pattern.test(toSource(value));
1037 }
1038
1039 /**
1040  * The base implementation of `_.isTypedArray` without Node.js optimizations.
1041  *
1042  * @private
1043  * @param {*} value The value to check.
1044  * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
1045  */
1046 function baseIsTypedArray(value) {
1047   return isObjectLike(value) &&
1048     isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
1049 }
1050
1051 /**
1052  * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
1053  *
1054  * @private
1055  * @param {Object} object The object to query.
1056  * @returns {Array} Returns the array of property names.
1057  */
1058 function baseKeys(object) {
1059   if (!isPrototype(object)) {
1060     return nativeKeys(object);
1061   }
1062   var result = [];
1063   for (var key in Object(object)) {
1064     if (hasOwnProperty.call(object, key) && key != 'constructor') {
1065       result.push(key);
1066     }
1067   }
1068   return result;
1069 }
1070
1071 /**
1072  * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
1073  *
1074  * @private
1075  * @param {Object} object The object to query.
1076  * @returns {Array} Returns the array of property names.
1077  */
1078 function baseKeysIn(object) {
1079   if (!isObject(object)) {
1080     return nativeKeysIn(object);
1081   }
1082   var isProto = isPrototype(object),
1083       result = [];
1084
1085   for (var key in object) {
1086     if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
1087       result.push(key);
1088     }
1089   }
1090   return result;
1091 }
1092
1093 /**
1094  * The base implementation of `_.merge` without support for multiple sources.
1095  *
1096  * @private
1097  * @param {Object} object The destination object.
1098  * @param {Object} source The source object.
1099  * @param {number} srcIndex The index of `source`.
1100  * @param {Function} [customizer] The function to customize merged values.
1101  * @param {Object} [stack] Tracks traversed source values and their merged
1102  *  counterparts.
1103  */
1104 function baseMerge(object, source, srcIndex, customizer, stack) {
1105   if (object === source) {
1106     return;
1107   }
1108   if (!(isArray(source) || isTypedArray(source))) {
1109     var props = baseKeysIn(source);
1110   }
1111   arrayEach(props || source, function(srcValue, key) {
1112     if (props) {
1113       key = srcValue;
1114       srcValue = source[key];
1115     }
1116     if (isObject(srcValue)) {
1117       stack || (stack = new Stack);
1118       baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
1119     }
1120     else {
1121       var newValue = customizer
1122         ? customizer(object[key], srcValue, (key + ''), object, source, stack)
1123         : undefined;
1124
1125       if (newValue === undefined) {
1126         newValue = srcValue;
1127       }
1128       assignMergeValue(object, key, newValue);
1129     }
1130   });
1131 }
1132
1133 /**
1134  * A specialized version of `baseMerge` for arrays and objects which performs
1135  * deep merges and tracks traversed objects enabling objects with circular
1136  * references to be merged.
1137  *
1138  * @private
1139  * @param {Object} object The destination object.
1140  * @param {Object} source The source object.
1141  * @param {string} key The key of the value to merge.
1142  * @param {number} srcIndex The index of `source`.
1143  * @param {Function} mergeFunc The function to merge values.
1144  * @param {Function} [customizer] The function to customize assigned values.
1145  * @param {Object} [stack] Tracks traversed source values and their merged
1146  *  counterparts.
1147  */
1148 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
1149   var objValue = object[key],
1150       srcValue = source[key],
1151       stacked = stack.get(srcValue);
1152
1153   if (stacked) {
1154     assignMergeValue(object, key, stacked);
1155     return;
1156   }
1157   var newValue = customizer
1158     ? customizer(objValue, srcValue, (key + ''), object, source, stack)
1159     : undefined;
1160
1161   var isCommon = newValue === undefined;
1162
1163   if (isCommon) {
1164     newValue = srcValue;
1165     if (isArray(srcValue) || isTypedArray(srcValue)) {
1166       if (isArray(objValue)) {
1167         newValue = objValue;
1168       }
1169       else if (isArrayLikeObject(objValue)) {
1170         newValue = copyArray(objValue);
1171       }
1172       else {
1173         isCommon = false;
1174         newValue = baseClone(srcValue, true);
1175       }
1176     }
1177     else if (isPlainObject(srcValue) || isArguments(srcValue)) {
1178       if (isArguments(objValue)) {
1179         newValue = toPlainObject(objValue);
1180       }
1181       else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
1182         isCommon = false;
1183         newValue = baseClone(srcValue, true);
1184       }
1185       else {
1186         newValue = objValue;
1187       }
1188     }
1189     else {
1190       isCommon = false;
1191     }
1192   }
1193   if (isCommon) {
1194     // Recursively merge objects and arrays (susceptible to call stack limits).
1195     stack.set(srcValue, newValue);
1196     mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
1197     stack['delete'](srcValue);
1198   }
1199   assignMergeValue(object, key, newValue);
1200 }
1201
1202 /**
1203  * The base implementation of `_.rest` which doesn't validate or coerce arguments.
1204  *
1205  * @private
1206  * @param {Function} func The function to apply a rest parameter to.
1207  * @param {number} [start=func.length-1] The start position of the rest parameter.
1208  * @returns {Function} Returns the new function.
1209  */
1210 function baseRest(func, start) {
1211   start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
1212   return function() {
1213     var args = arguments,
1214         index = -1,
1215         length = nativeMax(args.length - start, 0),
1216         array = Array(length);
1217
1218     while (++index < length) {
1219       array[index] = args[start + index];
1220     }
1221     index = -1;
1222     var otherArgs = Array(start + 1);
1223     while (++index < start) {
1224       otherArgs[index] = args[index];
1225     }
1226     otherArgs[start] = array;
1227     return apply(func, this, otherArgs);
1228   };
1229 }
1230
1231 /**
1232  * Creates a clone of  `buffer`.
1233  *
1234  * @private
1235  * @param {Buffer} buffer The buffer to clone.
1236  * @param {boolean} [isDeep] Specify a deep clone.
1237  * @returns {Buffer} Returns the cloned buffer.
1238  */
1239 function cloneBuffer(buffer, isDeep) {
1240   if (isDeep) {
1241     return buffer.slice();
1242   }
1243   var result = new buffer.constructor(buffer.length);
1244   buffer.copy(result);
1245   return result;
1246 }
1247
1248 /**
1249  * Creates a clone of `arrayBuffer`.
1250  *
1251  * @private
1252  * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
1253  * @returns {ArrayBuffer} Returns the cloned array buffer.
1254  */
1255 function cloneArrayBuffer(arrayBuffer) {
1256   var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
1257   new Uint8Array(result).set(new Uint8Array(arrayBuffer));
1258   return result;
1259 }
1260
1261 /**
1262  * Creates a clone of `dataView`.
1263  *
1264  * @private
1265  * @param {Object} dataView The data view to clone.
1266  * @param {boolean} [isDeep] Specify a deep clone.
1267  * @returns {Object} Returns the cloned data view.
1268  */
1269 function cloneDataView(dataView, isDeep) {
1270   var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
1271   return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
1272 }
1273
1274 /**
1275  * Creates a clone of `map`.
1276  *
1277  * @private
1278  * @param {Object} map The map to clone.
1279  * @param {Function} cloneFunc The function to clone values.
1280  * @param {boolean} [isDeep] Specify a deep clone.
1281  * @returns {Object} Returns the cloned map.
1282  */
1283 function cloneMap(map, isDeep, cloneFunc) {
1284   var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
1285   return arrayReduce(array, addMapEntry, new map.constructor);
1286 }
1287
1288 /**
1289  * Creates a clone of `regexp`.
1290  *
1291  * @private
1292  * @param {Object} regexp The regexp to clone.
1293  * @returns {Object} Returns the cloned regexp.
1294  */
1295 function cloneRegExp(regexp) {
1296   var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
1297   result.lastIndex = regexp.lastIndex;
1298   return result;
1299 }
1300
1301 /**
1302  * Creates a clone of `set`.
1303  *
1304  * @private
1305  * @param {Object} set The set to clone.
1306  * @param {Function} cloneFunc The function to clone values.
1307  * @param {boolean} [isDeep] Specify a deep clone.
1308  * @returns {Object} Returns the cloned set.
1309  */
1310 function cloneSet(set, isDeep, cloneFunc) {
1311   var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
1312   return arrayReduce(array, addSetEntry, new set.constructor);
1313 }
1314
1315 /**
1316  * Creates a clone of the `symbol` object.
1317  *
1318  * @private
1319  * @param {Object} symbol The symbol object to clone.
1320  * @returns {Object} Returns the cloned symbol object.
1321  */
1322 function cloneSymbol(symbol) {
1323   return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
1324 }
1325
1326 /**
1327  * Creates a clone of `typedArray`.
1328  *
1329  * @private
1330  * @param {Object} typedArray The typed array to clone.
1331  * @param {boolean} [isDeep] Specify a deep clone.
1332  * @returns {Object} Returns the cloned typed array.
1333  */
1334 function cloneTypedArray(typedArray, isDeep) {
1335   var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
1336   return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
1337 }
1338
1339 /**
1340  * Copies the values of `source` to `array`.
1341  *
1342  * @private
1343  * @param {Array} source The array to copy values from.
1344  * @param {Array} [array=[]] The array to copy values to.
1345  * @returns {Array} Returns `array`.
1346  */
1347 function copyArray(source, array) {
1348   var index = -1,
1349       length = source.length;
1350
1351   array || (array = Array(length));
1352   while (++index < length) {
1353     array[index] = source[index];
1354   }
1355   return array;
1356 }
1357
1358 /**
1359  * Copies properties of `source` to `object`.
1360  *
1361  * @private
1362  * @param {Object} source The object to copy properties from.
1363  * @param {Array} props The property identifiers to copy.
1364  * @param {Object} [object={}] The object to copy properties to.
1365  * @param {Function} [customizer] The function to customize copied values.
1366  * @returns {Object} Returns `object`.
1367  */
1368 function copyObject(source, props, object, customizer) {
1369   object || (object = {});
1370
1371   var index = -1,
1372       length = props.length;
1373
1374   while (++index < length) {
1375     var key = props[index];
1376
1377     var newValue = customizer
1378       ? customizer(object[key], source[key], key, object, source)
1379       : undefined;
1380
1381     assignValue(object, key, newValue === undefined ? source[key] : newValue);
1382   }
1383   return object;
1384 }
1385
1386 /**
1387  * Copies own symbol properties of `source` to `object`.
1388  *
1389  * @private
1390  * @param {Object} source The object to copy symbols from.
1391  * @param {Object} [object={}] The object to copy symbols to.
1392  * @returns {Object} Returns `object`.
1393  */
1394 function copySymbols(source, object) {
1395   return copyObject(source, getSymbols(source), object);
1396 }
1397
1398 /**
1399  * Creates a function like `_.assign`.
1400  *
1401  * @private
1402  * @param {Function} assigner The function to assign values.
1403  * @returns {Function} Returns the new assigner function.
1404  */
1405 function createAssigner(assigner) {
1406   return baseRest(function(object, sources) {
1407     var index = -1,
1408         length = sources.length,
1409         customizer = length > 1 ? sources[length - 1] : undefined,
1410         guard = length > 2 ? sources[2] : undefined;
1411
1412     customizer = (assigner.length > 3 && typeof customizer == 'function')
1413       ? (length--, customizer)
1414       : undefined;
1415
1416     if (guard && isIterateeCall(sources[0], sources[1], guard)) {
1417       customizer = length < 3 ? undefined : customizer;
1418       length = 1;
1419     }
1420     object = Object(object);
1421     while (++index < length) {
1422       var source = sources[index];
1423       if (source) {
1424         assigner(object, source, index, customizer);
1425       }
1426     }
1427     return object;
1428   });
1429 }
1430
1431 /**
1432  * Creates an array of own enumerable property names and symbols of `object`.
1433  *
1434  * @private
1435  * @param {Object} object The object to query.
1436  * @returns {Array} Returns the array of property names and symbols.
1437  */
1438 function getAllKeys(object) {
1439   return baseGetAllKeys(object, keys, getSymbols);
1440 }
1441
1442 /**
1443  * Gets the data for `map`.
1444  *
1445  * @private
1446  * @param {Object} map The map to query.
1447  * @param {string} key The reference key.
1448  * @returns {*} Returns the map data.
1449  */
1450 function getMapData(map, key) {
1451   var data = map.__data__;
1452   return isKeyable(key)
1453     ? data[typeof key == 'string' ? 'string' : 'hash']
1454     : data.map;
1455 }
1456
1457 /**
1458  * Gets the native function at `key` of `object`.
1459  *
1460  * @private
1461  * @param {Object} object The object to query.
1462  * @param {string} key The key of the method to get.
1463  * @returns {*} Returns the function if it's native, else `undefined`.
1464  */
1465 function getNative(object, key) {
1466   var value = getValue(object, key);
1467   return baseIsNative(value) ? value : undefined;
1468 }
1469
1470 /**
1471  * Creates an array of the own enumerable symbol properties of `object`.
1472  *
1473  * @private
1474  * @param {Object} object The object to query.
1475  * @returns {Array} Returns the array of symbols.
1476  */
1477 var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
1478
1479 /**
1480  * Gets the `toStringTag` of `value`.
1481  *
1482  * @private
1483  * @param {*} value The value to query.
1484  * @returns {string} Returns the `toStringTag`.
1485  */
1486 var getTag = baseGetTag;
1487
1488 // Fallback for data views, maps, sets, and weak maps in IE 11,
1489 // for data views in Edge < 14, and promises in Node.js.
1490 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
1491     (Map && getTag(new Map) != mapTag) ||
1492     (Promise && getTag(Promise.resolve()) != promiseTag) ||
1493     (Set && getTag(new Set) != setTag) ||
1494     (WeakMap && getTag(new WeakMap) != weakMapTag)) {
1495   getTag = function(value) {
1496     var result = objectToString.call(value),
1497         Ctor = result == objectTag ? value.constructor : undefined,
1498         ctorString = Ctor ? toSource(Ctor) : undefined;
1499
1500     if (ctorString) {
1501       switch (ctorString) {
1502         case dataViewCtorString: return dataViewTag;
1503         case mapCtorString: return mapTag;
1504         case promiseCtorString: return promiseTag;
1505         case setCtorString: return setTag;
1506         case weakMapCtorString: return weakMapTag;
1507       }
1508     }
1509     return result;
1510   };
1511 }
1512
1513 /**
1514  * Initializes an array clone.
1515  *
1516  * @private
1517  * @param {Array} array The array to clone.
1518  * @returns {Array} Returns the initialized clone.
1519  */
1520 function initCloneArray(array) {
1521   var length = array.length,
1522       result = array.constructor(length);
1523
1524   // Add properties assigned by `RegExp#exec`.
1525   if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
1526     result.index = array.index;
1527     result.input = array.input;
1528   }
1529   return result;
1530 }
1531
1532 /**
1533  * Initializes an object clone.
1534  *
1535  * @private
1536  * @param {Object} object The object to clone.
1537  * @returns {Object} Returns the initialized clone.
1538  */
1539 function initCloneObject(object) {
1540   return (typeof object.constructor == 'function' && !isPrototype(object))
1541     ? baseCreate(getPrototype(object))
1542     : {};
1543 }
1544
1545 /**
1546  * Initializes an object clone based on its `toStringTag`.
1547  *
1548  * **Note:** This function only supports cloning values with tags of
1549  * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1550  *
1551  * @private
1552  * @param {Object} object The object to clone.
1553  * @param {string} tag The `toStringTag` of the object to clone.
1554  * @param {Function} cloneFunc The function to clone values.
1555  * @param {boolean} [isDeep] Specify a deep clone.
1556  * @returns {Object} Returns the initialized clone.
1557  */
1558 function initCloneByTag(object, tag, cloneFunc, isDeep) {
1559   var Ctor = object.constructor;
1560   switch (tag) {
1561     case arrayBufferTag:
1562       return cloneArrayBuffer(object);
1563
1564     case boolTag:
1565     case dateTag:
1566       return new Ctor(+object);
1567
1568     case dataViewTag:
1569       return cloneDataView(object, isDeep);
1570
1571     case float32Tag: case float64Tag:
1572     case int8Tag: case int16Tag: case int32Tag:
1573     case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
1574       return cloneTypedArray(object, isDeep);
1575
1576     case mapTag:
1577       return cloneMap(object, isDeep, cloneFunc);
1578
1579     case numberTag:
1580     case stringTag:
1581       return new Ctor(object);
1582
1583     case regexpTag:
1584       return cloneRegExp(object);
1585
1586     case setTag:
1587       return cloneSet(object, isDeep, cloneFunc);
1588
1589     case symbolTag:
1590       return cloneSymbol(object);
1591   }
1592 }
1593
1594 /**
1595  * Checks if `value` is a valid array-like index.
1596  *
1597  * @private
1598  * @param {*} value The value to check.
1599  * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1600  * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1601  */
1602 function isIndex(value, length) {
1603   length = length == null ? MAX_SAFE_INTEGER : length;
1604   return !!length &&
1605     (typeof value == 'number' || reIsUint.test(value)) &&
1606     (value > -1 && value % 1 == 0 && value < length);
1607 }
1608
1609 /**
1610  * Checks if the given arguments are from an iteratee call.
1611  *
1612  * @private
1613  * @param {*} value The potential iteratee value argument.
1614  * @param {*} index The potential iteratee index or key argument.
1615  * @param {*} object The potential iteratee object argument.
1616  * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
1617  *  else `false`.
1618  */
1619 function isIterateeCall(value, index, object) {
1620   if (!isObject(object)) {
1621     return false;
1622   }
1623   var type = typeof index;
1624   if (type == 'number'
1625         ? (isArrayLike(object) && isIndex(index, object.length))
1626         : (type == 'string' && index in object)
1627       ) {
1628     return eq(object[index], value);
1629   }
1630   return false;
1631 }
1632
1633 /**
1634  * Checks if `value` is suitable for use as unique object key.
1635  *
1636  * @private
1637  * @param {*} value The value to check.
1638  * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
1639  */
1640 function isKeyable(value) {
1641   var type = typeof value;
1642   return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
1643     ? (value !== '__proto__')
1644     : (value === null);
1645 }
1646
1647 /**
1648  * Checks if `func` has its source masked.
1649  *
1650  * @private
1651  * @param {Function} func The function to check.
1652  * @returns {boolean} Returns `true` if `func` is masked, else `false`.
1653  */
1654 function isMasked(func) {
1655   return !!maskSrcKey && (maskSrcKey in func);
1656 }
1657
1658 /**
1659  * Checks if `value` is likely a prototype object.
1660  *
1661  * @private
1662  * @param {*} value The value to check.
1663  * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1664  */
1665 function isPrototype(value) {
1666   var Ctor = value && value.constructor,
1667       proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1668
1669   return value === proto;
1670 }
1671
1672 /**
1673  * This function is like
1674  * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1675  * except that it includes inherited enumerable properties.
1676  *
1677  * @private
1678  * @param {Object} object The object to query.
1679  * @returns {Array} Returns the array of property names.
1680  */
1681 function nativeKeysIn(object) {
1682   var result = [];
1683   if (object != null) {
1684     for (var key in Object(object)) {
1685       result.push(key);
1686     }
1687   }
1688   return result;
1689 }
1690
1691 /**
1692  * Converts `func` to its source code.
1693  *
1694  * @private
1695  * @param {Function} func The function to process.
1696  * @returns {string} Returns the source code.
1697  */
1698 function toSource(func) {
1699   if (func != null) {
1700     try {
1701       return funcToString.call(func);
1702     } catch (e) {}
1703     try {
1704       return (func + '');
1705     } catch (e) {}
1706   }
1707   return '';
1708 }
1709
1710 /**
1711  * Performs a
1712  * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1713  * comparison between two values to determine if they are equivalent.
1714  *
1715  * @static
1716  * @memberOf _
1717  * @since 4.0.0
1718  * @category Lang
1719  * @param {*} value The value to compare.
1720  * @param {*} other The other value to compare.
1721  * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1722  * @example
1723  *
1724  * var object = { 'a': 1 };
1725  * var other = { 'a': 1 };
1726  *
1727  * _.eq(object, object);
1728  * // => true
1729  *
1730  * _.eq(object, other);
1731  * // => false
1732  *
1733  * _.eq('a', 'a');
1734  * // => true
1735  *
1736  * _.eq('a', Object('a'));
1737  * // => false
1738  *
1739  * _.eq(NaN, NaN);
1740  * // => true
1741  */
1742 function eq(value, other) {
1743   return value === other || (value !== value && other !== other);
1744 }
1745
1746 /**
1747  * Checks if `value` is likely an `arguments` object.
1748  *
1749  * @static
1750  * @memberOf _
1751  * @since 0.1.0
1752  * @category Lang
1753  * @param {*} value The value to check.
1754  * @returns {boolean} Returns `true` if `value` is an `arguments` object,
1755  *  else `false`.
1756  * @example
1757  *
1758  * _.isArguments(function() { return arguments; }());
1759  * // => true
1760  *
1761  * _.isArguments([1, 2, 3]);
1762  * // => false
1763  */
1764 function isArguments(value) {
1765   // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
1766   return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
1767     (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
1768 }
1769
1770 /**
1771  * Checks if `value` is classified as an `Array` object.
1772  *
1773  * @static
1774  * @memberOf _
1775  * @since 0.1.0
1776  * @category Lang
1777  * @param {*} value The value to check.
1778  * @returns {boolean} Returns `true` if `value` is an array, else `false`.
1779  * @example
1780  *
1781  * _.isArray([1, 2, 3]);
1782  * // => true
1783  *
1784  * _.isArray(document.body.children);
1785  * // => false
1786  *
1787  * _.isArray('abc');
1788  * // => false
1789  *
1790  * _.isArray(_.noop);
1791  * // => false
1792  */
1793 var isArray = Array.isArray;
1794
1795 /**
1796  * Checks if `value` is array-like. A value is considered array-like if it's
1797  * not a function and has a `value.length` that's an integer greater than or
1798  * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
1799  *
1800  * @static
1801  * @memberOf _
1802  * @since 4.0.0
1803  * @category Lang
1804  * @param {*} value The value to check.
1805  * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
1806  * @example
1807  *
1808  * _.isArrayLike([1, 2, 3]);
1809  * // => true
1810  *
1811  * _.isArrayLike(document.body.children);
1812  * // => true
1813  *
1814  * _.isArrayLike('abc');
1815  * // => true
1816  *
1817  * _.isArrayLike(_.noop);
1818  * // => false
1819  */
1820 function isArrayLike(value) {
1821   return value != null && isLength(value.length) && !isFunction(value);
1822 }
1823
1824 /**
1825  * This method is like `_.isArrayLike` except that it also checks if `value`
1826  * is an object.
1827  *
1828  * @static
1829  * @memberOf _
1830  * @since 4.0.0
1831  * @category Lang
1832  * @param {*} value The value to check.
1833  * @returns {boolean} Returns `true` if `value` is an array-like object,
1834  *  else `false`.
1835  * @example
1836  *
1837  * _.isArrayLikeObject([1, 2, 3]);
1838  * // => true
1839  *
1840  * _.isArrayLikeObject(document.body.children);
1841  * // => true
1842  *
1843  * _.isArrayLikeObject('abc');
1844  * // => false
1845  *
1846  * _.isArrayLikeObject(_.noop);
1847  * // => false
1848  */
1849 function isArrayLikeObject(value) {
1850   return isObjectLike(value) && isArrayLike(value);
1851 }
1852
1853 /**
1854  * Checks if `value` is a buffer.
1855  *
1856  * @static
1857  * @memberOf _
1858  * @since 4.3.0
1859  * @category Lang
1860  * @param {*} value The value to check.
1861  * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
1862  * @example
1863  *
1864  * _.isBuffer(new Buffer(2));
1865  * // => true
1866  *
1867  * _.isBuffer(new Uint8Array(2));
1868  * // => false
1869  */
1870 var isBuffer = nativeIsBuffer || stubFalse;
1871
1872 /**
1873  * Checks if `value` is classified as a `Function` object.
1874  *
1875  * @static
1876  * @memberOf _
1877  * @since 0.1.0
1878  * @category Lang
1879  * @param {*} value The value to check.
1880  * @returns {boolean} Returns `true` if `value` is a function, else `false`.
1881  * @example
1882  *
1883  * _.isFunction(_);
1884  * // => true
1885  *
1886  * _.isFunction(/abc/);
1887  * // => false
1888  */
1889 function isFunction(value) {
1890   // The use of `Object#toString` avoids issues with the `typeof` operator
1891   // in Safari 8-9 which returns 'object' for typed array and other constructors.
1892   var tag = isObject(value) ? objectToString.call(value) : '';
1893   return tag == funcTag || tag == genTag;
1894 }
1895
1896 /**
1897  * Checks if `value` is a valid array-like length.
1898  *
1899  * **Note:** This method is loosely based on
1900  * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
1901  *
1902  * @static
1903  * @memberOf _
1904  * @since 4.0.0
1905  * @category Lang
1906  * @param {*} value The value to check.
1907  * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
1908  * @example
1909  *
1910  * _.isLength(3);
1911  * // => true
1912  *
1913  * _.isLength(Number.MIN_VALUE);
1914  * // => false
1915  *
1916  * _.isLength(Infinity);
1917  * // => false
1918  *
1919  * _.isLength('3');
1920  * // => false
1921  */
1922 function isLength(value) {
1923   return typeof value == 'number' &&
1924     value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
1925 }
1926
1927 /**
1928  * Checks if `value` is the
1929  * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
1930  * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
1931  *
1932  * @static
1933  * @memberOf _
1934  * @since 0.1.0
1935  * @category Lang
1936  * @param {*} value The value to check.
1937  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
1938  * @example
1939  *
1940  * _.isObject({});
1941  * // => true
1942  *
1943  * _.isObject([1, 2, 3]);
1944  * // => true
1945  *
1946  * _.isObject(_.noop);
1947  * // => true
1948  *
1949  * _.isObject(null);
1950  * // => false
1951  */
1952 function isObject(value) {
1953   var type = typeof value;
1954   return !!value && (type == 'object' || type == 'function');
1955 }
1956
1957 /**
1958  * Checks if `value` is object-like. A value is object-like if it's not `null`
1959  * and has a `typeof` result of "object".
1960  *
1961  * @static
1962  * @memberOf _
1963  * @since 4.0.0
1964  * @category Lang
1965  * @param {*} value The value to check.
1966  * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1967  * @example
1968  *
1969  * _.isObjectLike({});
1970  * // => true
1971  *
1972  * _.isObjectLike([1, 2, 3]);
1973  * // => true
1974  *
1975  * _.isObjectLike(_.noop);
1976  * // => false
1977  *
1978  * _.isObjectLike(null);
1979  * // => false
1980  */
1981 function isObjectLike(value) {
1982   return !!value && typeof value == 'object';
1983 }
1984
1985 /**
1986  * Checks if `value` is a plain object, that is, an object created by the
1987  * `Object` constructor or one with a `[[Prototype]]` of `null`.
1988  *
1989  * @static
1990  * @memberOf _
1991  * @since 0.8.0
1992  * @category Lang
1993  * @param {*} value The value to check.
1994  * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
1995  * @example
1996  *
1997  * function Foo() {
1998  *   this.a = 1;
1999  * }
2000  *
2001  * _.isPlainObject(new Foo);
2002  * // => false
2003  *
2004  * _.isPlainObject([1, 2, 3]);
2005  * // => false
2006  *
2007  * _.isPlainObject({ 'x': 0, 'y': 0 });
2008  * // => true
2009  *
2010  * _.isPlainObject(Object.create(null));
2011  * // => true
2012  */
2013 function isPlainObject(value) {
2014   if (!isObjectLike(value) ||
2015       objectToString.call(value) != objectTag || isHostObject(value)) {
2016     return false;
2017   }
2018   var proto = getPrototype(value);
2019   if (proto === null) {
2020     return true;
2021   }
2022   var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
2023   return (typeof Ctor == 'function' &&
2024     Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
2025 }
2026
2027 /**
2028  * Checks if `value` is classified as a typed array.
2029  *
2030  * @static
2031  * @memberOf _
2032  * @since 3.0.0
2033  * @category Lang
2034  * @param {*} value The value to check.
2035  * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
2036  * @example
2037  *
2038  * _.isTypedArray(new Uint8Array);
2039  * // => true
2040  *
2041  * _.isTypedArray([]);
2042  * // => false
2043  */
2044 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
2045
2046 /**
2047  * Converts `value` to a plain object flattening inherited enumerable string
2048  * keyed properties of `value` to own properties of the plain object.
2049  *
2050  * @static
2051  * @memberOf _
2052  * @since 3.0.0
2053  * @category Lang
2054  * @param {*} value The value to convert.
2055  * @returns {Object} Returns the converted plain object.
2056  * @example
2057  *
2058  * function Foo() {
2059  *   this.b = 2;
2060  * }
2061  *
2062  * Foo.prototype.c = 3;
2063  *
2064  * _.assign({ 'a': 1 }, new Foo);
2065  * // => { 'a': 1, 'b': 2 }
2066  *
2067  * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
2068  * // => { 'a': 1, 'b': 2, 'c': 3 }
2069  */
2070 function toPlainObject(value) {
2071   return copyObject(value, keysIn(value));
2072 }
2073
2074 /**
2075  * Creates an array of the own enumerable property names of `object`.
2076  *
2077  * **Note:** Non-object values are coerced to objects. See the
2078  * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
2079  * for more details.
2080  *
2081  * @static
2082  * @since 0.1.0
2083  * @memberOf _
2084  * @category Object
2085  * @param {Object} object The object to query.
2086  * @returns {Array} Returns the array of property names.
2087  * @example
2088  *
2089  * function Foo() {
2090  *   this.a = 1;
2091  *   this.b = 2;
2092  * }
2093  *
2094  * Foo.prototype.c = 3;
2095  *
2096  * _.keys(new Foo);
2097  * // => ['a', 'b'] (iteration order is not guaranteed)
2098  *
2099  * _.keys('hi');
2100  * // => ['0', '1']
2101  */
2102 function keys(object) {
2103   return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
2104 }
2105
2106 /**
2107  * Creates an array of the own and inherited enumerable property names of `object`.
2108  *
2109  * **Note:** Non-object values are coerced to objects.
2110  *
2111  * @static
2112  * @memberOf _
2113  * @since 3.0.0
2114  * @category Object
2115  * @param {Object} object The object to query.
2116  * @returns {Array} Returns the array of property names.
2117  * @example
2118  *
2119  * function Foo() {
2120  *   this.a = 1;
2121  *   this.b = 2;
2122  * }
2123  *
2124  * Foo.prototype.c = 3;
2125  *
2126  * _.keysIn(new Foo);
2127  * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
2128  */
2129 function keysIn(object) {
2130   return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
2131 }
2132
2133 /**
2134  * This method is like `_.merge` except that it accepts `customizer` which
2135  * is invoked to produce the merged values of the destination and source
2136  * properties. If `customizer` returns `undefined`, merging is handled by the
2137  * method instead. The `customizer` is invoked with seven arguments:
2138  * (objValue, srcValue, key, object, source, stack).
2139  *
2140  * **Note:** This method mutates `object`.
2141  *
2142  * @static
2143  * @memberOf _
2144  * @since 4.0.0
2145  * @category Object
2146  * @param {Object} object The destination object.
2147  * @param {...Object} sources The source objects.
2148  * @param {Function} customizer The function to customize assigned values.
2149  * @returns {Object} Returns `object`.
2150  * @example
2151  *
2152  * function customizer(objValue, srcValue) {
2153  *   if (_.isArray(objValue)) {
2154  *     return objValue.concat(srcValue);
2155  *   }
2156  * }
2157  *
2158  * var object = { 'a': [1], 'b': [2] };
2159  * var other = { 'a': [3], 'b': [4] };
2160  *
2161  * _.mergeWith(object, other, customizer);
2162  * // => { 'a': [1, 3], 'b': [2, 4] }
2163  */
2164 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
2165   baseMerge(object, source, srcIndex, customizer);
2166 });
2167
2168 /**
2169  * This method returns a new empty array.
2170  *
2171  * @static
2172  * @memberOf _
2173  * @since 4.13.0
2174  * @category Util
2175  * @returns {Array} Returns the new empty array.
2176  * @example
2177  *
2178  * var arrays = _.times(2, _.stubArray);
2179  *
2180  * console.log(arrays);
2181  * // => [[], []]
2182  *
2183  * console.log(arrays[0] === arrays[1]);
2184  * // => false
2185  */
2186 function stubArray() {
2187   return [];
2188 }
2189
2190 /**
2191  * This method returns `false`.
2192  *
2193  * @static
2194  * @memberOf _
2195  * @since 4.13.0
2196  * @category Util
2197  * @returns {boolean} Returns `false`.
2198  * @example
2199  *
2200  * _.times(2, _.stubFalse);
2201  * // => [false, false]
2202  */
2203 function stubFalse() {
2204   return false;
2205 }
2206
2207 module.exports = mergeWith;