index.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748
  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. /** Used as the size to enable large array optimizations. */
  10. var LARGE_ARRAY_SIZE = 200;
  11. /** Used to stand-in for `undefined` hash values. */
  12. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  13. /** Used as references for various `Number` constants. */
  14. var MAX_SAFE_INTEGER = 9007199254740991;
  15. /** `Object#toString` result references. */
  16. var argsTag = '[object Arguments]',
  17. arrayTag = '[object Array]',
  18. boolTag = '[object Boolean]',
  19. dateTag = '[object Date]',
  20. errorTag = '[object Error]',
  21. funcTag = '[object Function]',
  22. genTag = '[object GeneratorFunction]',
  23. mapTag = '[object Map]',
  24. numberTag = '[object Number]',
  25. objectTag = '[object Object]',
  26. promiseTag = '[object Promise]',
  27. regexpTag = '[object RegExp]',
  28. setTag = '[object Set]',
  29. stringTag = '[object String]',
  30. symbolTag = '[object Symbol]',
  31. weakMapTag = '[object WeakMap]';
  32. var arrayBufferTag = '[object ArrayBuffer]',
  33. dataViewTag = '[object DataView]',
  34. float32Tag = '[object Float32Array]',
  35. float64Tag = '[object Float64Array]',
  36. int8Tag = '[object Int8Array]',
  37. int16Tag = '[object Int16Array]',
  38. int32Tag = '[object Int32Array]',
  39. uint8Tag = '[object Uint8Array]',
  40. uint8ClampedTag = '[object Uint8ClampedArray]',
  41. uint16Tag = '[object Uint16Array]',
  42. uint32Tag = '[object Uint32Array]';
  43. /**
  44. * Used to match `RegExp`
  45. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  46. */
  47. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  48. /** Used to match `RegExp` flags from their coerced string values. */
  49. var reFlags = /\w*$/;
  50. /** Used to detect host constructors (Safari). */
  51. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  52. /** Used to detect unsigned integer values. */
  53. var reIsUint = /^(?:0|[1-9]\d*)$/;
  54. /** Used to identify `toStringTag` values supported by `_.clone`. */
  55. var cloneableTags = {};
  56. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  57. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  58. cloneableTags[boolTag] = cloneableTags[dateTag] =
  59. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  60. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  61. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  62. cloneableTags[numberTag] = cloneableTags[objectTag] =
  63. cloneableTags[regexpTag] = cloneableTags[setTag] =
  64. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  65. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  66. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  67. cloneableTags[errorTag] = cloneableTags[funcTag] =
  68. cloneableTags[weakMapTag] = false;
  69. /** Detect free variable `global` from Node.js. */
  70. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  71. /** Detect free variable `self`. */
  72. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  73. /** Used as a reference to the global object. */
  74. var root = freeGlobal || freeSelf || Function('return this')();
  75. /** Detect free variable `exports`. */
  76. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  77. /** Detect free variable `module`. */
  78. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  79. /** Detect the popular CommonJS extension `module.exports`. */
  80. var moduleExports = freeModule && freeModule.exports === freeExports;
  81. /**
  82. * Adds the key-value `pair` to `map`.
  83. *
  84. * @private
  85. * @param {Object} map The map to modify.
  86. * @param {Array} pair The key-value pair to add.
  87. * @returns {Object} Returns `map`.
  88. */
  89. function addMapEntry(map, pair) {
  90. // Don't return `map.set` because it's not chainable in IE 11.
  91. map.set(pair[0], pair[1]);
  92. return map;
  93. }
  94. /**
  95. * Adds `value` to `set`.
  96. *
  97. * @private
  98. * @param {Object} set The set to modify.
  99. * @param {*} value The value to add.
  100. * @returns {Object} Returns `set`.
  101. */
  102. function addSetEntry(set, value) {
  103. // Don't return `set.add` because it's not chainable in IE 11.
  104. set.add(value);
  105. return set;
  106. }
  107. /**
  108. * A specialized version of `_.forEach` for arrays without support for
  109. * iteratee shorthands.
  110. *
  111. * @private
  112. * @param {Array} [array] The array to iterate over.
  113. * @param {Function} iteratee The function invoked per iteration.
  114. * @returns {Array} Returns `array`.
  115. */
  116. function arrayEach(array, iteratee) {
  117. var index = -1,
  118. length = array ? array.length : 0;
  119. while (++index < length) {
  120. if (iteratee(array[index], index, array) === false) {
  121. break;
  122. }
  123. }
  124. return array;
  125. }
  126. /**
  127. * Appends the elements of `values` to `array`.
  128. *
  129. * @private
  130. * @param {Array} array The array to modify.
  131. * @param {Array} values The values to append.
  132. * @returns {Array} Returns `array`.
  133. */
  134. function arrayPush(array, values) {
  135. var index = -1,
  136. length = values.length,
  137. offset = array.length;
  138. while (++index < length) {
  139. array[offset + index] = values[index];
  140. }
  141. return array;
  142. }
  143. /**
  144. * A specialized version of `_.reduce` for arrays without support for
  145. * iteratee shorthands.
  146. *
  147. * @private
  148. * @param {Array} [array] The array to iterate over.
  149. * @param {Function} iteratee The function invoked per iteration.
  150. * @param {*} [accumulator] The initial value.
  151. * @param {boolean} [initAccum] Specify using the first element of `array` as
  152. * the initial value.
  153. * @returns {*} Returns the accumulated value.
  154. */
  155. function arrayReduce(array, iteratee, accumulator, initAccum) {
  156. var index = -1,
  157. length = array ? array.length : 0;
  158. if (initAccum && length) {
  159. accumulator = array[++index];
  160. }
  161. while (++index < length) {
  162. accumulator = iteratee(accumulator, array[index], index, array);
  163. }
  164. return accumulator;
  165. }
  166. /**
  167. * The base implementation of `_.times` without support for iteratee shorthands
  168. * or max array length checks.
  169. *
  170. * @private
  171. * @param {number} n The number of times to invoke `iteratee`.
  172. * @param {Function} iteratee The function invoked per iteration.
  173. * @returns {Array} Returns the array of results.
  174. */
  175. function baseTimes(n, iteratee) {
  176. var index = -1,
  177. result = Array(n);
  178. while (++index < n) {
  179. result[index] = iteratee(index);
  180. }
  181. return result;
  182. }
  183. /**
  184. * Gets the value at `key` of `object`.
  185. *
  186. * @private
  187. * @param {Object} [object] The object to query.
  188. * @param {string} key The key of the property to get.
  189. * @returns {*} Returns the property value.
  190. */
  191. function getValue(object, key) {
  192. return object == null ? undefined : object[key];
  193. }
  194. /**
  195. * Checks if `value` is a host object in IE < 9.
  196. *
  197. * @private
  198. * @param {*} value The value to check.
  199. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  200. */
  201. function isHostObject(value) {
  202. // Many host objects are `Object` objects that can coerce to strings
  203. // despite having improperly defined `toString` methods.
  204. var result = false;
  205. if (value != null && typeof value.toString != 'function') {
  206. try {
  207. result = !!(value + '');
  208. } catch (e) {}
  209. }
  210. return result;
  211. }
  212. /**
  213. * Converts `map` to its key-value pairs.
  214. *
  215. * @private
  216. * @param {Object} map The map to convert.
  217. * @returns {Array} Returns the key-value pairs.
  218. */
  219. function mapToArray(map) {
  220. var index = -1,
  221. result = Array(map.size);
  222. map.forEach(function(value, key) {
  223. result[++index] = [key, value];
  224. });
  225. return result;
  226. }
  227. /**
  228. * Creates a unary function that invokes `func` with its argument transformed.
  229. *
  230. * @private
  231. * @param {Function} func The function to wrap.
  232. * @param {Function} transform The argument transform.
  233. * @returns {Function} Returns the new function.
  234. */
  235. function overArg(func, transform) {
  236. return function(arg) {
  237. return func(transform(arg));
  238. };
  239. }
  240. /**
  241. * Converts `set` to an array of its values.
  242. *
  243. * @private
  244. * @param {Object} set The set to convert.
  245. * @returns {Array} Returns the values.
  246. */
  247. function setToArray(set) {
  248. var index = -1,
  249. result = Array(set.size);
  250. set.forEach(function(value) {
  251. result[++index] = value;
  252. });
  253. return result;
  254. }
  255. /** Used for built-in method references. */
  256. var arrayProto = Array.prototype,
  257. funcProto = Function.prototype,
  258. objectProto = Object.prototype;
  259. /** Used to detect overreaching core-js shims. */
  260. var coreJsData = root['__core-js_shared__'];
  261. /** Used to detect methods masquerading as native. */
  262. var maskSrcKey = (function() {
  263. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  264. return uid ? ('Symbol(src)_1.' + uid) : '';
  265. }());
  266. /** Used to resolve the decompiled source of functions. */
  267. var funcToString = funcProto.toString;
  268. /** Used to check objects for own properties. */
  269. var hasOwnProperty = objectProto.hasOwnProperty;
  270. /**
  271. * Used to resolve the
  272. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  273. * of values.
  274. */
  275. var objectToString = objectProto.toString;
  276. /** Used to detect if a method is native. */
  277. var reIsNative = RegExp('^' +
  278. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  279. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  280. );
  281. /** Built-in value references. */
  282. var Buffer = moduleExports ? root.Buffer : undefined,
  283. Symbol = root.Symbol,
  284. Uint8Array = root.Uint8Array,
  285. getPrototype = overArg(Object.getPrototypeOf, Object),
  286. objectCreate = Object.create,
  287. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  288. splice = arrayProto.splice;
  289. /* Built-in method references for those with the same name as other `lodash` methods. */
  290. var nativeGetSymbols = Object.getOwnPropertySymbols,
  291. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  292. nativeKeys = overArg(Object.keys, Object);
  293. /* Built-in method references that are verified to be native. */
  294. var DataView = getNative(root, 'DataView'),
  295. Map = getNative(root, 'Map'),
  296. Promise = getNative(root, 'Promise'),
  297. Set = getNative(root, 'Set'),
  298. WeakMap = getNative(root, 'WeakMap'),
  299. nativeCreate = getNative(Object, 'create');
  300. /** Used to detect maps, sets, and weakmaps. */
  301. var dataViewCtorString = toSource(DataView),
  302. mapCtorString = toSource(Map),
  303. promiseCtorString = toSource(Promise),
  304. setCtorString = toSource(Set),
  305. weakMapCtorString = toSource(WeakMap);
  306. /** Used to convert symbols to primitives and strings. */
  307. var symbolProto = Symbol ? Symbol.prototype : undefined,
  308. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
  309. /**
  310. * Creates a hash object.
  311. *
  312. * @private
  313. * @constructor
  314. * @param {Array} [entries] The key-value pairs to cache.
  315. */
  316. function Hash(entries) {
  317. var index = -1,
  318. length = entries ? entries.length : 0;
  319. this.clear();
  320. while (++index < length) {
  321. var entry = entries[index];
  322. this.set(entry[0], entry[1]);
  323. }
  324. }
  325. /**
  326. * Removes all key-value entries from the hash.
  327. *
  328. * @private
  329. * @name clear
  330. * @memberOf Hash
  331. */
  332. function hashClear() {
  333. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  334. }
  335. /**
  336. * Removes `key` and its value from the hash.
  337. *
  338. * @private
  339. * @name delete
  340. * @memberOf Hash
  341. * @param {Object} hash The hash to modify.
  342. * @param {string} key The key of the value to remove.
  343. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  344. */
  345. function hashDelete(key) {
  346. return this.has(key) && delete this.__data__[key];
  347. }
  348. /**
  349. * Gets the hash value for `key`.
  350. *
  351. * @private
  352. * @name get
  353. * @memberOf Hash
  354. * @param {string} key The key of the value to get.
  355. * @returns {*} Returns the entry value.
  356. */
  357. function hashGet(key) {
  358. var data = this.__data__;
  359. if (nativeCreate) {
  360. var result = data[key];
  361. return result === HASH_UNDEFINED ? undefined : result;
  362. }
  363. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  364. }
  365. /**
  366. * Checks if a hash value for `key` exists.
  367. *
  368. * @private
  369. * @name has
  370. * @memberOf Hash
  371. * @param {string} key The key of the entry to check.
  372. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  373. */
  374. function hashHas(key) {
  375. var data = this.__data__;
  376. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  377. }
  378. /**
  379. * Sets the hash `key` to `value`.
  380. *
  381. * @private
  382. * @name set
  383. * @memberOf Hash
  384. * @param {string} key The key of the value to set.
  385. * @param {*} value The value to set.
  386. * @returns {Object} Returns the hash instance.
  387. */
  388. function hashSet(key, value) {
  389. var data = this.__data__;
  390. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  391. return this;
  392. }
  393. // Add methods to `Hash`.
  394. Hash.prototype.clear = hashClear;
  395. Hash.prototype['delete'] = hashDelete;
  396. Hash.prototype.get = hashGet;
  397. Hash.prototype.has = hashHas;
  398. Hash.prototype.set = hashSet;
  399. /**
  400. * Creates an list cache object.
  401. *
  402. * @private
  403. * @constructor
  404. * @param {Array} [entries] The key-value pairs to cache.
  405. */
  406. function ListCache(entries) {
  407. var index = -1,
  408. length = entries ? entries.length : 0;
  409. this.clear();
  410. while (++index < length) {
  411. var entry = entries[index];
  412. this.set(entry[0], entry[1]);
  413. }
  414. }
  415. /**
  416. * Removes all key-value entries from the list cache.
  417. *
  418. * @private
  419. * @name clear
  420. * @memberOf ListCache
  421. */
  422. function listCacheClear() {
  423. this.__data__ = [];
  424. }
  425. /**
  426. * Removes `key` and its value from the list cache.
  427. *
  428. * @private
  429. * @name delete
  430. * @memberOf ListCache
  431. * @param {string} key The key of the value to remove.
  432. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  433. */
  434. function listCacheDelete(key) {
  435. var data = this.__data__,
  436. index = assocIndexOf(data, key);
  437. if (index < 0) {
  438. return false;
  439. }
  440. var lastIndex = data.length - 1;
  441. if (index == lastIndex) {
  442. data.pop();
  443. } else {
  444. splice.call(data, index, 1);
  445. }
  446. return true;
  447. }
  448. /**
  449. * Gets the list cache value for `key`.
  450. *
  451. * @private
  452. * @name get
  453. * @memberOf ListCache
  454. * @param {string} key The key of the value to get.
  455. * @returns {*} Returns the entry value.
  456. */
  457. function listCacheGet(key) {
  458. var data = this.__data__,
  459. index = assocIndexOf(data, key);
  460. return index < 0 ? undefined : data[index][1];
  461. }
  462. /**
  463. * Checks if a list cache value for `key` exists.
  464. *
  465. * @private
  466. * @name has
  467. * @memberOf ListCache
  468. * @param {string} key The key of the entry to check.
  469. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  470. */
  471. function listCacheHas(key) {
  472. return assocIndexOf(this.__data__, key) > -1;
  473. }
  474. /**
  475. * Sets the list cache `key` to `value`.
  476. *
  477. * @private
  478. * @name set
  479. * @memberOf ListCache
  480. * @param {string} key The key of the value to set.
  481. * @param {*} value The value to set.
  482. * @returns {Object} Returns the list cache instance.
  483. */
  484. function listCacheSet(key, value) {
  485. var data = this.__data__,
  486. index = assocIndexOf(data, key);
  487. if (index < 0) {
  488. data.push([key, value]);
  489. } else {
  490. data[index][1] = value;
  491. }
  492. return this;
  493. }
  494. // Add methods to `ListCache`.
  495. ListCache.prototype.clear = listCacheClear;
  496. ListCache.prototype['delete'] = listCacheDelete;
  497. ListCache.prototype.get = listCacheGet;
  498. ListCache.prototype.has = listCacheHas;
  499. ListCache.prototype.set = listCacheSet;
  500. /**
  501. * Creates a map cache object to store key-value pairs.
  502. *
  503. * @private
  504. * @constructor
  505. * @param {Array} [entries] The key-value pairs to cache.
  506. */
  507. function MapCache(entries) {
  508. var index = -1,
  509. length = entries ? entries.length : 0;
  510. this.clear();
  511. while (++index < length) {
  512. var entry = entries[index];
  513. this.set(entry[0], entry[1]);
  514. }
  515. }
  516. /**
  517. * Removes all key-value entries from the map.
  518. *
  519. * @private
  520. * @name clear
  521. * @memberOf MapCache
  522. */
  523. function mapCacheClear() {
  524. this.__data__ = {
  525. 'hash': new Hash,
  526. 'map': new (Map || ListCache),
  527. 'string': new Hash
  528. };
  529. }
  530. /**
  531. * Removes `key` and its value from the map.
  532. *
  533. * @private
  534. * @name delete
  535. * @memberOf MapCache
  536. * @param {string} key The key of the value to remove.
  537. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  538. */
  539. function mapCacheDelete(key) {
  540. return getMapData(this, key)['delete'](key);
  541. }
  542. /**
  543. * Gets the map value for `key`.
  544. *
  545. * @private
  546. * @name get
  547. * @memberOf MapCache
  548. * @param {string} key The key of the value to get.
  549. * @returns {*} Returns the entry value.
  550. */
  551. function mapCacheGet(key) {
  552. return getMapData(this, key).get(key);
  553. }
  554. /**
  555. * Checks if a map value for `key` exists.
  556. *
  557. * @private
  558. * @name has
  559. * @memberOf MapCache
  560. * @param {string} key The key of the entry to check.
  561. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  562. */
  563. function mapCacheHas(key) {
  564. return getMapData(this, key).has(key);
  565. }
  566. /**
  567. * Sets the map `key` to `value`.
  568. *
  569. * @private
  570. * @name set
  571. * @memberOf MapCache
  572. * @param {string} key The key of the value to set.
  573. * @param {*} value The value to set.
  574. * @returns {Object} Returns the map cache instance.
  575. */
  576. function mapCacheSet(key, value) {
  577. getMapData(this, key).set(key, value);
  578. return this;
  579. }
  580. // Add methods to `MapCache`.
  581. MapCache.prototype.clear = mapCacheClear;
  582. MapCache.prototype['delete'] = mapCacheDelete;
  583. MapCache.prototype.get = mapCacheGet;
  584. MapCache.prototype.has = mapCacheHas;
  585. MapCache.prototype.set = mapCacheSet;
  586. /**
  587. * Creates a stack cache object to store key-value pairs.
  588. *
  589. * @private
  590. * @constructor
  591. * @param {Array} [entries] The key-value pairs to cache.
  592. */
  593. function Stack(entries) {
  594. this.__data__ = new ListCache(entries);
  595. }
  596. /**
  597. * Removes all key-value entries from the stack.
  598. *
  599. * @private
  600. * @name clear
  601. * @memberOf Stack
  602. */
  603. function stackClear() {
  604. this.__data__ = new ListCache;
  605. }
  606. /**
  607. * Removes `key` and its value from the stack.
  608. *
  609. * @private
  610. * @name delete
  611. * @memberOf Stack
  612. * @param {string} key The key of the value to remove.
  613. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  614. */
  615. function stackDelete(key) {
  616. return this.__data__['delete'](key);
  617. }
  618. /**
  619. * Gets the stack value for `key`.
  620. *
  621. * @private
  622. * @name get
  623. * @memberOf Stack
  624. * @param {string} key The key of the value to get.
  625. * @returns {*} Returns the entry value.
  626. */
  627. function stackGet(key) {
  628. return this.__data__.get(key);
  629. }
  630. /**
  631. * Checks if a stack value for `key` exists.
  632. *
  633. * @private
  634. * @name has
  635. * @memberOf Stack
  636. * @param {string} key The key of the entry to check.
  637. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  638. */
  639. function stackHas(key) {
  640. return this.__data__.has(key);
  641. }
  642. /**
  643. * Sets the stack `key` to `value`.
  644. *
  645. * @private
  646. * @name set
  647. * @memberOf Stack
  648. * @param {string} key The key of the value to set.
  649. * @param {*} value The value to set.
  650. * @returns {Object} Returns the stack cache instance.
  651. */
  652. function stackSet(key, value) {
  653. var cache = this.__data__;
  654. if (cache instanceof ListCache) {
  655. var pairs = cache.__data__;
  656. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  657. pairs.push([key, value]);
  658. return this;
  659. }
  660. cache = this.__data__ = new MapCache(pairs);
  661. }
  662. cache.set(key, value);
  663. return this;
  664. }
  665. // Add methods to `Stack`.
  666. Stack.prototype.clear = stackClear;
  667. Stack.prototype['delete'] = stackDelete;
  668. Stack.prototype.get = stackGet;
  669. Stack.prototype.has = stackHas;
  670. Stack.prototype.set = stackSet;
  671. /**
  672. * Creates an array of the enumerable property names of the array-like `value`.
  673. *
  674. * @private
  675. * @param {*} value The value to query.
  676. * @param {boolean} inherited Specify returning inherited property names.
  677. * @returns {Array} Returns the array of property names.
  678. */
  679. function arrayLikeKeys(value, inherited) {
  680. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  681. // Safari 9 makes `arguments.length` enumerable in strict mode.
  682. var result = (isArray(value) || isArguments(value))
  683. ? baseTimes(value.length, String)
  684. : [];
  685. var length = result.length,
  686. skipIndexes = !!length;
  687. for (var key in value) {
  688. if ((inherited || hasOwnProperty.call(value, key)) &&
  689. !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  690. result.push(key);
  691. }
  692. }
  693. return result;
  694. }
  695. /**
  696. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  697. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  698. * for equality comparisons.
  699. *
  700. * @private
  701. * @param {Object} object The object to modify.
  702. * @param {string} key The key of the property to assign.
  703. * @param {*} value The value to assign.
  704. */
  705. function assignValue(object, key, value) {
  706. var objValue = object[key];
  707. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  708. (value === undefined && !(key in object))) {
  709. object[key] = value;
  710. }
  711. }
  712. /**
  713. * Gets the index at which the `key` is found in `array` of key-value pairs.
  714. *
  715. * @private
  716. * @param {Array} array The array to inspect.
  717. * @param {*} key The key to search for.
  718. * @returns {number} Returns the index of the matched value, else `-1`.
  719. */
  720. function assocIndexOf(array, key) {
  721. var length = array.length;
  722. while (length--) {
  723. if (eq(array[length][0], key)) {
  724. return length;
  725. }
  726. }
  727. return -1;
  728. }
  729. /**
  730. * The base implementation of `_.assign` without support for multiple sources
  731. * or `customizer` functions.
  732. *
  733. * @private
  734. * @param {Object} object The destination object.
  735. * @param {Object} source The source object.
  736. * @returns {Object} Returns `object`.
  737. */
  738. function baseAssign(object, source) {
  739. return object && copyObject(source, keys(source), object);
  740. }
  741. /**
  742. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  743. * traversed objects.
  744. *
  745. * @private
  746. * @param {*} value The value to clone.
  747. * @param {boolean} [isDeep] Specify a deep clone.
  748. * @param {boolean} [isFull] Specify a clone including symbols.
  749. * @param {Function} [customizer] The function to customize cloning.
  750. * @param {string} [key] The key of `value`.
  751. * @param {Object} [object] The parent object of `value`.
  752. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  753. * @returns {*} Returns the cloned value.
  754. */
  755. function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
  756. var result;
  757. if (customizer) {
  758. result = object ? customizer(value, key, object, stack) : customizer(value);
  759. }
  760. if (result !== undefined) {
  761. return result;
  762. }
  763. if (!isObject(value)) {
  764. return value;
  765. }
  766. var isArr = isArray(value);
  767. if (isArr) {
  768. result = initCloneArray(value);
  769. if (!isDeep) {
  770. return copyArray(value, result);
  771. }
  772. } else {
  773. var tag = getTag(value),
  774. isFunc = tag == funcTag || tag == genTag;
  775. if (isBuffer(value)) {
  776. return cloneBuffer(value, isDeep);
  777. }
  778. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  779. if (isHostObject(value)) {
  780. return object ? value : {};
  781. }
  782. result = initCloneObject(isFunc ? {} : value);
  783. if (!isDeep) {
  784. return copySymbols(value, baseAssign(result, value));
  785. }
  786. } else {
  787. if (!cloneableTags[tag]) {
  788. return object ? value : {};
  789. }
  790. result = initCloneByTag(value, tag, baseClone, isDeep);
  791. }
  792. }
  793. // Check for circular references and return its corresponding clone.
  794. stack || (stack = new Stack);
  795. var stacked = stack.get(value);
  796. if (stacked) {
  797. return stacked;
  798. }
  799. stack.set(value, result);
  800. if (!isArr) {
  801. var props = isFull ? getAllKeys(value) : keys(value);
  802. }
  803. arrayEach(props || value, function(subValue, key) {
  804. if (props) {
  805. key = subValue;
  806. subValue = value[key];
  807. }
  808. // Recursively populate clone (susceptible to call stack limits).
  809. assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
  810. });
  811. return result;
  812. }
  813. /**
  814. * The base implementation of `_.create` without support for assigning
  815. * properties to the created object.
  816. *
  817. * @private
  818. * @param {Object} prototype The object to inherit from.
  819. * @returns {Object} Returns the new object.
  820. */
  821. function baseCreate(proto) {
  822. return isObject(proto) ? objectCreate(proto) : {};
  823. }
  824. /**
  825. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  826. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  827. * symbols of `object`.
  828. *
  829. * @private
  830. * @param {Object} object The object to query.
  831. * @param {Function} keysFunc The function to get the keys of `object`.
  832. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  833. * @returns {Array} Returns the array of property names and symbols.
  834. */
  835. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  836. var result = keysFunc(object);
  837. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  838. }
  839. /**
  840. * The base implementation of `getTag`.
  841. *
  842. * @private
  843. * @param {*} value The value to query.
  844. * @returns {string} Returns the `toStringTag`.
  845. */
  846. function baseGetTag(value) {
  847. return objectToString.call(value);
  848. }
  849. /**
  850. * The base implementation of `_.isNative` without bad shim checks.
  851. *
  852. * @private
  853. * @param {*} value The value to check.
  854. * @returns {boolean} Returns `true` if `value` is a native function,
  855. * else `false`.
  856. */
  857. function baseIsNative(value) {
  858. if (!isObject(value) || isMasked(value)) {
  859. return false;
  860. }
  861. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  862. return pattern.test(toSource(value));
  863. }
  864. /**
  865. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  866. *
  867. * @private
  868. * @param {Object} object The object to query.
  869. * @returns {Array} Returns the array of property names.
  870. */
  871. function baseKeys(object) {
  872. if (!isPrototype(object)) {
  873. return nativeKeys(object);
  874. }
  875. var result = [];
  876. for (var key in Object(object)) {
  877. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  878. result.push(key);
  879. }
  880. }
  881. return result;
  882. }
  883. /**
  884. * Creates a clone of `buffer`.
  885. *
  886. * @private
  887. * @param {Buffer} buffer The buffer to clone.
  888. * @param {boolean} [isDeep] Specify a deep clone.
  889. * @returns {Buffer} Returns the cloned buffer.
  890. */
  891. function cloneBuffer(buffer, isDeep) {
  892. if (isDeep) {
  893. return buffer.slice();
  894. }
  895. var result = new buffer.constructor(buffer.length);
  896. buffer.copy(result);
  897. return result;
  898. }
  899. /**
  900. * Creates a clone of `arrayBuffer`.
  901. *
  902. * @private
  903. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  904. * @returns {ArrayBuffer} Returns the cloned array buffer.
  905. */
  906. function cloneArrayBuffer(arrayBuffer) {
  907. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  908. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  909. return result;
  910. }
  911. /**
  912. * Creates a clone of `dataView`.
  913. *
  914. * @private
  915. * @param {Object} dataView The data view to clone.
  916. * @param {boolean} [isDeep] Specify a deep clone.
  917. * @returns {Object} Returns the cloned data view.
  918. */
  919. function cloneDataView(dataView, isDeep) {
  920. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  921. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  922. }
  923. /**
  924. * Creates a clone of `map`.
  925. *
  926. * @private
  927. * @param {Object} map The map to clone.
  928. * @param {Function} cloneFunc The function to clone values.
  929. * @param {boolean} [isDeep] Specify a deep clone.
  930. * @returns {Object} Returns the cloned map.
  931. */
  932. function cloneMap(map, isDeep, cloneFunc) {
  933. var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
  934. return arrayReduce(array, addMapEntry, new map.constructor);
  935. }
  936. /**
  937. * Creates a clone of `regexp`.
  938. *
  939. * @private
  940. * @param {Object} regexp The regexp to clone.
  941. * @returns {Object} Returns the cloned regexp.
  942. */
  943. function cloneRegExp(regexp) {
  944. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  945. result.lastIndex = regexp.lastIndex;
  946. return result;
  947. }
  948. /**
  949. * Creates a clone of `set`.
  950. *
  951. * @private
  952. * @param {Object} set The set to clone.
  953. * @param {Function} cloneFunc The function to clone values.
  954. * @param {boolean} [isDeep] Specify a deep clone.
  955. * @returns {Object} Returns the cloned set.
  956. */
  957. function cloneSet(set, isDeep, cloneFunc) {
  958. var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
  959. return arrayReduce(array, addSetEntry, new set.constructor);
  960. }
  961. /**
  962. * Creates a clone of the `symbol` object.
  963. *
  964. * @private
  965. * @param {Object} symbol The symbol object to clone.
  966. * @returns {Object} Returns the cloned symbol object.
  967. */
  968. function cloneSymbol(symbol) {
  969. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  970. }
  971. /**
  972. * Creates a clone of `typedArray`.
  973. *
  974. * @private
  975. * @param {Object} typedArray The typed array to clone.
  976. * @param {boolean} [isDeep] Specify a deep clone.
  977. * @returns {Object} Returns the cloned typed array.
  978. */
  979. function cloneTypedArray(typedArray, isDeep) {
  980. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  981. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  982. }
  983. /**
  984. * Copies the values of `source` to `array`.
  985. *
  986. * @private
  987. * @param {Array} source The array to copy values from.
  988. * @param {Array} [array=[]] The array to copy values to.
  989. * @returns {Array} Returns `array`.
  990. */
  991. function copyArray(source, array) {
  992. var index = -1,
  993. length = source.length;
  994. array || (array = Array(length));
  995. while (++index < length) {
  996. array[index] = source[index];
  997. }
  998. return array;
  999. }
  1000. /**
  1001. * Copies properties of `source` to `object`.
  1002. *
  1003. * @private
  1004. * @param {Object} source The object to copy properties from.
  1005. * @param {Array} props The property identifiers to copy.
  1006. * @param {Object} [object={}] The object to copy properties to.
  1007. * @param {Function} [customizer] The function to customize copied values.
  1008. * @returns {Object} Returns `object`.
  1009. */
  1010. function copyObject(source, props, object, customizer) {
  1011. object || (object = {});
  1012. var index = -1,
  1013. length = props.length;
  1014. while (++index < length) {
  1015. var key = props[index];
  1016. var newValue = customizer
  1017. ? customizer(object[key], source[key], key, object, source)
  1018. : undefined;
  1019. assignValue(object, key, newValue === undefined ? source[key] : newValue);
  1020. }
  1021. return object;
  1022. }
  1023. /**
  1024. * Copies own symbol properties of `source` to `object`.
  1025. *
  1026. * @private
  1027. * @param {Object} source The object to copy symbols from.
  1028. * @param {Object} [object={}] The object to copy symbols to.
  1029. * @returns {Object} Returns `object`.
  1030. */
  1031. function copySymbols(source, object) {
  1032. return copyObject(source, getSymbols(source), object);
  1033. }
  1034. /**
  1035. * Creates an array of own enumerable property names and symbols of `object`.
  1036. *
  1037. * @private
  1038. * @param {Object} object The object to query.
  1039. * @returns {Array} Returns the array of property names and symbols.
  1040. */
  1041. function getAllKeys(object) {
  1042. return baseGetAllKeys(object, keys, getSymbols);
  1043. }
  1044. /**
  1045. * Gets the data for `map`.
  1046. *
  1047. * @private
  1048. * @param {Object} map The map to query.
  1049. * @param {string} key The reference key.
  1050. * @returns {*} Returns the map data.
  1051. */
  1052. function getMapData(map, key) {
  1053. var data = map.__data__;
  1054. return isKeyable(key)
  1055. ? data[typeof key == 'string' ? 'string' : 'hash']
  1056. : data.map;
  1057. }
  1058. /**
  1059. * Gets the native function at `key` of `object`.
  1060. *
  1061. * @private
  1062. * @param {Object} object The object to query.
  1063. * @param {string} key The key of the method to get.
  1064. * @returns {*} Returns the function if it's native, else `undefined`.
  1065. */
  1066. function getNative(object, key) {
  1067. var value = getValue(object, key);
  1068. return baseIsNative(value) ? value : undefined;
  1069. }
  1070. /**
  1071. * Creates an array of the own enumerable symbol properties of `object`.
  1072. *
  1073. * @private
  1074. * @param {Object} object The object to query.
  1075. * @returns {Array} Returns the array of symbols.
  1076. */
  1077. var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
  1078. /**
  1079. * Gets the `toStringTag` of `value`.
  1080. *
  1081. * @private
  1082. * @param {*} value The value to query.
  1083. * @returns {string} Returns the `toStringTag`.
  1084. */
  1085. var getTag = baseGetTag;
  1086. // Fallback for data views, maps, sets, and weak maps in IE 11,
  1087. // for data views in Edge < 14, and promises in Node.js.
  1088. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  1089. (Map && getTag(new Map) != mapTag) ||
  1090. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  1091. (Set && getTag(new Set) != setTag) ||
  1092. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  1093. getTag = function(value) {
  1094. var result = objectToString.call(value),
  1095. Ctor = result == objectTag ? value.constructor : undefined,
  1096. ctorString = Ctor ? toSource(Ctor) : undefined;
  1097. if (ctorString) {
  1098. switch (ctorString) {
  1099. case dataViewCtorString: return dataViewTag;
  1100. case mapCtorString: return mapTag;
  1101. case promiseCtorString: return promiseTag;
  1102. case setCtorString: return setTag;
  1103. case weakMapCtorString: return weakMapTag;
  1104. }
  1105. }
  1106. return result;
  1107. };
  1108. }
  1109. /**
  1110. * Initializes an array clone.
  1111. *
  1112. * @private
  1113. * @param {Array} array The array to clone.
  1114. * @returns {Array} Returns the initialized clone.
  1115. */
  1116. function initCloneArray(array) {
  1117. var length = array.length,
  1118. result = array.constructor(length);
  1119. // Add properties assigned by `RegExp#exec`.
  1120. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  1121. result.index = array.index;
  1122. result.input = array.input;
  1123. }
  1124. return result;
  1125. }
  1126. /**
  1127. * Initializes an object clone.
  1128. *
  1129. * @private
  1130. * @param {Object} object The object to clone.
  1131. * @returns {Object} Returns the initialized clone.
  1132. */
  1133. function initCloneObject(object) {
  1134. return (typeof object.constructor == 'function' && !isPrototype(object))
  1135. ? baseCreate(getPrototype(object))
  1136. : {};
  1137. }
  1138. /**
  1139. * Initializes an object clone based on its `toStringTag`.
  1140. *
  1141. * **Note:** This function only supports cloning values with tags of
  1142. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  1143. *
  1144. * @private
  1145. * @param {Object} object The object to clone.
  1146. * @param {string} tag The `toStringTag` of the object to clone.
  1147. * @param {Function} cloneFunc The function to clone values.
  1148. * @param {boolean} [isDeep] Specify a deep clone.
  1149. * @returns {Object} Returns the initialized clone.
  1150. */
  1151. function initCloneByTag(object, tag, cloneFunc, isDeep) {
  1152. var Ctor = object.constructor;
  1153. switch (tag) {
  1154. case arrayBufferTag:
  1155. return cloneArrayBuffer(object);
  1156. case boolTag:
  1157. case dateTag:
  1158. return new Ctor(+object);
  1159. case dataViewTag:
  1160. return cloneDataView(object, isDeep);
  1161. case float32Tag: case float64Tag:
  1162. case int8Tag: case int16Tag: case int32Tag:
  1163. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  1164. return cloneTypedArray(object, isDeep);
  1165. case mapTag:
  1166. return cloneMap(object, isDeep, cloneFunc);
  1167. case numberTag:
  1168. case stringTag:
  1169. return new Ctor(object);
  1170. case regexpTag:
  1171. return cloneRegExp(object);
  1172. case setTag:
  1173. return cloneSet(object, isDeep, cloneFunc);
  1174. case symbolTag:
  1175. return cloneSymbol(object);
  1176. }
  1177. }
  1178. /**
  1179. * Checks if `value` is a valid array-like index.
  1180. *
  1181. * @private
  1182. * @param {*} value The value to check.
  1183. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  1184. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  1185. */
  1186. function isIndex(value, length) {
  1187. length = length == null ? MAX_SAFE_INTEGER : length;
  1188. return !!length &&
  1189. (typeof value == 'number' || reIsUint.test(value)) &&
  1190. (value > -1 && value % 1 == 0 && value < length);
  1191. }
  1192. /**
  1193. * Checks if `value` is suitable for use as unique object key.
  1194. *
  1195. * @private
  1196. * @param {*} value The value to check.
  1197. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  1198. */
  1199. function isKeyable(value) {
  1200. var type = typeof value;
  1201. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  1202. ? (value !== '__proto__')
  1203. : (value === null);
  1204. }
  1205. /**
  1206. * Checks if `func` has its source masked.
  1207. *
  1208. * @private
  1209. * @param {Function} func The function to check.
  1210. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  1211. */
  1212. function isMasked(func) {
  1213. return !!maskSrcKey && (maskSrcKey in func);
  1214. }
  1215. /**
  1216. * Checks if `value` is likely a prototype object.
  1217. *
  1218. * @private
  1219. * @param {*} value The value to check.
  1220. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  1221. */
  1222. function isPrototype(value) {
  1223. var Ctor = value && value.constructor,
  1224. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  1225. return value === proto;
  1226. }
  1227. /**
  1228. * Converts `func` to its source code.
  1229. *
  1230. * @private
  1231. * @param {Function} func The function to process.
  1232. * @returns {string} Returns the source code.
  1233. */
  1234. function toSource(func) {
  1235. if (func != null) {
  1236. try {
  1237. return funcToString.call(func);
  1238. } catch (e) {}
  1239. try {
  1240. return (func + '');
  1241. } catch (e) {}
  1242. }
  1243. return '';
  1244. }
  1245. /**
  1246. * This method is like `_.clone` except that it recursively clones `value`.
  1247. *
  1248. * @static
  1249. * @memberOf _
  1250. * @since 1.0.0
  1251. * @category Lang
  1252. * @param {*} value The value to recursively clone.
  1253. * @returns {*} Returns the deep cloned value.
  1254. * @see _.clone
  1255. * @example
  1256. *
  1257. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  1258. *
  1259. * var deep = _.cloneDeep(objects);
  1260. * console.log(deep[0] === objects[0]);
  1261. * // => false
  1262. */
  1263. function cloneDeep(value) {
  1264. return baseClone(value, true, true);
  1265. }
  1266. /**
  1267. * Performs a
  1268. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  1269. * comparison between two values to determine if they are equivalent.
  1270. *
  1271. * @static
  1272. * @memberOf _
  1273. * @since 4.0.0
  1274. * @category Lang
  1275. * @param {*} value The value to compare.
  1276. * @param {*} other The other value to compare.
  1277. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1278. * @example
  1279. *
  1280. * var object = { 'a': 1 };
  1281. * var other = { 'a': 1 };
  1282. *
  1283. * _.eq(object, object);
  1284. * // => true
  1285. *
  1286. * _.eq(object, other);
  1287. * // => false
  1288. *
  1289. * _.eq('a', 'a');
  1290. * // => true
  1291. *
  1292. * _.eq('a', Object('a'));
  1293. * // => false
  1294. *
  1295. * _.eq(NaN, NaN);
  1296. * // => true
  1297. */
  1298. function eq(value, other) {
  1299. return value === other || (value !== value && other !== other);
  1300. }
  1301. /**
  1302. * Checks if `value` is likely an `arguments` object.
  1303. *
  1304. * @static
  1305. * @memberOf _
  1306. * @since 0.1.0
  1307. * @category Lang
  1308. * @param {*} value The value to check.
  1309. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  1310. * else `false`.
  1311. * @example
  1312. *
  1313. * _.isArguments(function() { return arguments; }());
  1314. * // => true
  1315. *
  1316. * _.isArguments([1, 2, 3]);
  1317. * // => false
  1318. */
  1319. function isArguments(value) {
  1320. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  1321. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  1322. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  1323. }
  1324. /**
  1325. * Checks if `value` is classified as an `Array` object.
  1326. *
  1327. * @static
  1328. * @memberOf _
  1329. * @since 0.1.0
  1330. * @category Lang
  1331. * @param {*} value The value to check.
  1332. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  1333. * @example
  1334. *
  1335. * _.isArray([1, 2, 3]);
  1336. * // => true
  1337. *
  1338. * _.isArray(document.body.children);
  1339. * // => false
  1340. *
  1341. * _.isArray('abc');
  1342. * // => false
  1343. *
  1344. * _.isArray(_.noop);
  1345. * // => false
  1346. */
  1347. var isArray = Array.isArray;
  1348. /**
  1349. * Checks if `value` is array-like. A value is considered array-like if it's
  1350. * not a function and has a `value.length` that's an integer greater than or
  1351. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  1352. *
  1353. * @static
  1354. * @memberOf _
  1355. * @since 4.0.0
  1356. * @category Lang
  1357. * @param {*} value The value to check.
  1358. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  1359. * @example
  1360. *
  1361. * _.isArrayLike([1, 2, 3]);
  1362. * // => true
  1363. *
  1364. * _.isArrayLike(document.body.children);
  1365. * // => true
  1366. *
  1367. * _.isArrayLike('abc');
  1368. * // => true
  1369. *
  1370. * _.isArrayLike(_.noop);
  1371. * // => false
  1372. */
  1373. function isArrayLike(value) {
  1374. return value != null && isLength(value.length) && !isFunction(value);
  1375. }
  1376. /**
  1377. * This method is like `_.isArrayLike` except that it also checks if `value`
  1378. * is an object.
  1379. *
  1380. * @static
  1381. * @memberOf _
  1382. * @since 4.0.0
  1383. * @category Lang
  1384. * @param {*} value The value to check.
  1385. * @returns {boolean} Returns `true` if `value` is an array-like object,
  1386. * else `false`.
  1387. * @example
  1388. *
  1389. * _.isArrayLikeObject([1, 2, 3]);
  1390. * // => true
  1391. *
  1392. * _.isArrayLikeObject(document.body.children);
  1393. * // => true
  1394. *
  1395. * _.isArrayLikeObject('abc');
  1396. * // => false
  1397. *
  1398. * _.isArrayLikeObject(_.noop);
  1399. * // => false
  1400. */
  1401. function isArrayLikeObject(value) {
  1402. return isObjectLike(value) && isArrayLike(value);
  1403. }
  1404. /**
  1405. * Checks if `value` is a buffer.
  1406. *
  1407. * @static
  1408. * @memberOf _
  1409. * @since 4.3.0
  1410. * @category Lang
  1411. * @param {*} value The value to check.
  1412. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  1413. * @example
  1414. *
  1415. * _.isBuffer(new Buffer(2));
  1416. * // => true
  1417. *
  1418. * _.isBuffer(new Uint8Array(2));
  1419. * // => false
  1420. */
  1421. var isBuffer = nativeIsBuffer || stubFalse;
  1422. /**
  1423. * Checks if `value` is classified as a `Function` object.
  1424. *
  1425. * @static
  1426. * @memberOf _
  1427. * @since 0.1.0
  1428. * @category Lang
  1429. * @param {*} value The value to check.
  1430. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  1431. * @example
  1432. *
  1433. * _.isFunction(_);
  1434. * // => true
  1435. *
  1436. * _.isFunction(/abc/);
  1437. * // => false
  1438. */
  1439. function isFunction(value) {
  1440. // The use of `Object#toString` avoids issues with the `typeof` operator
  1441. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  1442. var tag = isObject(value) ? objectToString.call(value) : '';
  1443. return tag == funcTag || tag == genTag;
  1444. }
  1445. /**
  1446. * Checks if `value` is a valid array-like length.
  1447. *
  1448. * **Note:** This method is loosely based on
  1449. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  1450. *
  1451. * @static
  1452. * @memberOf _
  1453. * @since 4.0.0
  1454. * @category Lang
  1455. * @param {*} value The value to check.
  1456. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  1457. * @example
  1458. *
  1459. * _.isLength(3);
  1460. * // => true
  1461. *
  1462. * _.isLength(Number.MIN_VALUE);
  1463. * // => false
  1464. *
  1465. * _.isLength(Infinity);
  1466. * // => false
  1467. *
  1468. * _.isLength('3');
  1469. * // => false
  1470. */
  1471. function isLength(value) {
  1472. return typeof value == 'number' &&
  1473. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  1474. }
  1475. /**
  1476. * Checks if `value` is the
  1477. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1478. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1479. *
  1480. * @static
  1481. * @memberOf _
  1482. * @since 0.1.0
  1483. * @category Lang
  1484. * @param {*} value The value to check.
  1485. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1486. * @example
  1487. *
  1488. * _.isObject({});
  1489. * // => true
  1490. *
  1491. * _.isObject([1, 2, 3]);
  1492. * // => true
  1493. *
  1494. * _.isObject(_.noop);
  1495. * // => true
  1496. *
  1497. * _.isObject(null);
  1498. * // => false
  1499. */
  1500. function isObject(value) {
  1501. var type = typeof value;
  1502. return !!value && (type == 'object' || type == 'function');
  1503. }
  1504. /**
  1505. * Checks if `value` is object-like. A value is object-like if it's not `null`
  1506. * and has a `typeof` result of "object".
  1507. *
  1508. * @static
  1509. * @memberOf _
  1510. * @since 4.0.0
  1511. * @category Lang
  1512. * @param {*} value The value to check.
  1513. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1514. * @example
  1515. *
  1516. * _.isObjectLike({});
  1517. * // => true
  1518. *
  1519. * _.isObjectLike([1, 2, 3]);
  1520. * // => true
  1521. *
  1522. * _.isObjectLike(_.noop);
  1523. * // => false
  1524. *
  1525. * _.isObjectLike(null);
  1526. * // => false
  1527. */
  1528. function isObjectLike(value) {
  1529. return !!value && typeof value == 'object';
  1530. }
  1531. /**
  1532. * Creates an array of the own enumerable property names of `object`.
  1533. *
  1534. * **Note:** Non-object values are coerced to objects. See the
  1535. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  1536. * for more details.
  1537. *
  1538. * @static
  1539. * @since 0.1.0
  1540. * @memberOf _
  1541. * @category Object
  1542. * @param {Object} object The object to query.
  1543. * @returns {Array} Returns the array of property names.
  1544. * @example
  1545. *
  1546. * function Foo() {
  1547. * this.a = 1;
  1548. * this.b = 2;
  1549. * }
  1550. *
  1551. * Foo.prototype.c = 3;
  1552. *
  1553. * _.keys(new Foo);
  1554. * // => ['a', 'b'] (iteration order is not guaranteed)
  1555. *
  1556. * _.keys('hi');
  1557. * // => ['0', '1']
  1558. */
  1559. function keys(object) {
  1560. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  1561. }
  1562. /**
  1563. * This method returns a new empty array.
  1564. *
  1565. * @static
  1566. * @memberOf _
  1567. * @since 4.13.0
  1568. * @category Util
  1569. * @returns {Array} Returns the new empty array.
  1570. * @example
  1571. *
  1572. * var arrays = _.times(2, _.stubArray);
  1573. *
  1574. * console.log(arrays);
  1575. * // => [[], []]
  1576. *
  1577. * console.log(arrays[0] === arrays[1]);
  1578. * // => false
  1579. */
  1580. function stubArray() {
  1581. return [];
  1582. }
  1583. /**
  1584. * This method returns `false`.
  1585. *
  1586. * @static
  1587. * @memberOf _
  1588. * @since 4.13.0
  1589. * @category Util
  1590. * @returns {boolean} Returns `false`.
  1591. * @example
  1592. *
  1593. * _.times(2, _.stubFalse);
  1594. * // => [false, false]
  1595. */
  1596. function stubFalse() {
  1597. return false;
  1598. }
  1599. module.exports = cloneDeep;