index.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  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. * Creates a shallow clone of `value`.
  1247. *
  1248. * **Note:** This method is loosely based on the
  1249. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  1250. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  1251. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  1252. * arrays. The own enumerable properties of `arguments` objects are cloned
  1253. * as plain objects. An empty object is returned for uncloneable values such
  1254. * as error objects, functions, DOM nodes, and WeakMaps.
  1255. *
  1256. * @static
  1257. * @memberOf _
  1258. * @since 0.1.0
  1259. * @category Lang
  1260. * @param {*} value The value to clone.
  1261. * @returns {*} Returns the cloned value.
  1262. * @see _.cloneDeep
  1263. * @example
  1264. *
  1265. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  1266. *
  1267. * var shallow = _.clone(objects);
  1268. * console.log(shallow[0] === objects[0]);
  1269. * // => true
  1270. */
  1271. function clone(value) {
  1272. return baseClone(value, false, true);
  1273. }
  1274. /**
  1275. * Performs a
  1276. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  1277. * comparison between two values to determine if they are equivalent.
  1278. *
  1279. * @static
  1280. * @memberOf _
  1281. * @since 4.0.0
  1282. * @category Lang
  1283. * @param {*} value The value to compare.
  1284. * @param {*} other The other value to compare.
  1285. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1286. * @example
  1287. *
  1288. * var object = { 'a': 1 };
  1289. * var other = { 'a': 1 };
  1290. *
  1291. * _.eq(object, object);
  1292. * // => true
  1293. *
  1294. * _.eq(object, other);
  1295. * // => false
  1296. *
  1297. * _.eq('a', 'a');
  1298. * // => true
  1299. *
  1300. * _.eq('a', Object('a'));
  1301. * // => false
  1302. *
  1303. * _.eq(NaN, NaN);
  1304. * // => true
  1305. */
  1306. function eq(value, other) {
  1307. return value === other || (value !== value && other !== other);
  1308. }
  1309. /**
  1310. * Checks if `value` is likely an `arguments` object.
  1311. *
  1312. * @static
  1313. * @memberOf _
  1314. * @since 0.1.0
  1315. * @category Lang
  1316. * @param {*} value The value to check.
  1317. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  1318. * else `false`.
  1319. * @example
  1320. *
  1321. * _.isArguments(function() { return arguments; }());
  1322. * // => true
  1323. *
  1324. * _.isArguments([1, 2, 3]);
  1325. * // => false
  1326. */
  1327. function isArguments(value) {
  1328. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  1329. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  1330. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  1331. }
  1332. /**
  1333. * Checks if `value` is classified as an `Array` object.
  1334. *
  1335. * @static
  1336. * @memberOf _
  1337. * @since 0.1.0
  1338. * @category Lang
  1339. * @param {*} value The value to check.
  1340. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  1341. * @example
  1342. *
  1343. * _.isArray([1, 2, 3]);
  1344. * // => true
  1345. *
  1346. * _.isArray(document.body.children);
  1347. * // => false
  1348. *
  1349. * _.isArray('abc');
  1350. * // => false
  1351. *
  1352. * _.isArray(_.noop);
  1353. * // => false
  1354. */
  1355. var isArray = Array.isArray;
  1356. /**
  1357. * Checks if `value` is array-like. A value is considered array-like if it's
  1358. * not a function and has a `value.length` that's an integer greater than or
  1359. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  1360. *
  1361. * @static
  1362. * @memberOf _
  1363. * @since 4.0.0
  1364. * @category Lang
  1365. * @param {*} value The value to check.
  1366. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  1367. * @example
  1368. *
  1369. * _.isArrayLike([1, 2, 3]);
  1370. * // => true
  1371. *
  1372. * _.isArrayLike(document.body.children);
  1373. * // => true
  1374. *
  1375. * _.isArrayLike('abc');
  1376. * // => true
  1377. *
  1378. * _.isArrayLike(_.noop);
  1379. * // => false
  1380. */
  1381. function isArrayLike(value) {
  1382. return value != null && isLength(value.length) && !isFunction(value);
  1383. }
  1384. /**
  1385. * This method is like `_.isArrayLike` except that it also checks if `value`
  1386. * is an object.
  1387. *
  1388. * @static
  1389. * @memberOf _
  1390. * @since 4.0.0
  1391. * @category Lang
  1392. * @param {*} value The value to check.
  1393. * @returns {boolean} Returns `true` if `value` is an array-like object,
  1394. * else `false`.
  1395. * @example
  1396. *
  1397. * _.isArrayLikeObject([1, 2, 3]);
  1398. * // => true
  1399. *
  1400. * _.isArrayLikeObject(document.body.children);
  1401. * // => true
  1402. *
  1403. * _.isArrayLikeObject('abc');
  1404. * // => false
  1405. *
  1406. * _.isArrayLikeObject(_.noop);
  1407. * // => false
  1408. */
  1409. function isArrayLikeObject(value) {
  1410. return isObjectLike(value) && isArrayLike(value);
  1411. }
  1412. /**
  1413. * Checks if `value` is a buffer.
  1414. *
  1415. * @static
  1416. * @memberOf _
  1417. * @since 4.3.0
  1418. * @category Lang
  1419. * @param {*} value The value to check.
  1420. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  1421. * @example
  1422. *
  1423. * _.isBuffer(new Buffer(2));
  1424. * // => true
  1425. *
  1426. * _.isBuffer(new Uint8Array(2));
  1427. * // => false
  1428. */
  1429. var isBuffer = nativeIsBuffer || stubFalse;
  1430. /**
  1431. * Checks if `value` is classified as a `Function` object.
  1432. *
  1433. * @static
  1434. * @memberOf _
  1435. * @since 0.1.0
  1436. * @category Lang
  1437. * @param {*} value The value to check.
  1438. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  1439. * @example
  1440. *
  1441. * _.isFunction(_);
  1442. * // => true
  1443. *
  1444. * _.isFunction(/abc/);
  1445. * // => false
  1446. */
  1447. function isFunction(value) {
  1448. // The use of `Object#toString` avoids issues with the `typeof` operator
  1449. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  1450. var tag = isObject(value) ? objectToString.call(value) : '';
  1451. return tag == funcTag || tag == genTag;
  1452. }
  1453. /**
  1454. * Checks if `value` is a valid array-like length.
  1455. *
  1456. * **Note:** This method is loosely based on
  1457. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  1458. *
  1459. * @static
  1460. * @memberOf _
  1461. * @since 4.0.0
  1462. * @category Lang
  1463. * @param {*} value The value to check.
  1464. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  1465. * @example
  1466. *
  1467. * _.isLength(3);
  1468. * // => true
  1469. *
  1470. * _.isLength(Number.MIN_VALUE);
  1471. * // => false
  1472. *
  1473. * _.isLength(Infinity);
  1474. * // => false
  1475. *
  1476. * _.isLength('3');
  1477. * // => false
  1478. */
  1479. function isLength(value) {
  1480. return typeof value == 'number' &&
  1481. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  1482. }
  1483. /**
  1484. * Checks if `value` is the
  1485. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1486. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1487. *
  1488. * @static
  1489. * @memberOf _
  1490. * @since 0.1.0
  1491. * @category Lang
  1492. * @param {*} value The value to check.
  1493. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1494. * @example
  1495. *
  1496. * _.isObject({});
  1497. * // => true
  1498. *
  1499. * _.isObject([1, 2, 3]);
  1500. * // => true
  1501. *
  1502. * _.isObject(_.noop);
  1503. * // => true
  1504. *
  1505. * _.isObject(null);
  1506. * // => false
  1507. */
  1508. function isObject(value) {
  1509. var type = typeof value;
  1510. return !!value && (type == 'object' || type == 'function');
  1511. }
  1512. /**
  1513. * Checks if `value` is object-like. A value is object-like if it's not `null`
  1514. * and has a `typeof` result of "object".
  1515. *
  1516. * @static
  1517. * @memberOf _
  1518. * @since 4.0.0
  1519. * @category Lang
  1520. * @param {*} value The value to check.
  1521. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1522. * @example
  1523. *
  1524. * _.isObjectLike({});
  1525. * // => true
  1526. *
  1527. * _.isObjectLike([1, 2, 3]);
  1528. * // => true
  1529. *
  1530. * _.isObjectLike(_.noop);
  1531. * // => false
  1532. *
  1533. * _.isObjectLike(null);
  1534. * // => false
  1535. */
  1536. function isObjectLike(value) {
  1537. return !!value && typeof value == 'object';
  1538. }
  1539. /**
  1540. * Creates an array of the own enumerable property names of `object`.
  1541. *
  1542. * **Note:** Non-object values are coerced to objects. See the
  1543. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  1544. * for more details.
  1545. *
  1546. * @static
  1547. * @since 0.1.0
  1548. * @memberOf _
  1549. * @category Object
  1550. * @param {Object} object The object to query.
  1551. * @returns {Array} Returns the array of property names.
  1552. * @example
  1553. *
  1554. * function Foo() {
  1555. * this.a = 1;
  1556. * this.b = 2;
  1557. * }
  1558. *
  1559. * Foo.prototype.c = 3;
  1560. *
  1561. * _.keys(new Foo);
  1562. * // => ['a', 'b'] (iteration order is not guaranteed)
  1563. *
  1564. * _.keys('hi');
  1565. * // => ['0', '1']
  1566. */
  1567. function keys(object) {
  1568. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  1569. }
  1570. /**
  1571. * This method returns a new empty array.
  1572. *
  1573. * @static
  1574. * @memberOf _
  1575. * @since 4.13.0
  1576. * @category Util
  1577. * @returns {Array} Returns the new empty array.
  1578. * @example
  1579. *
  1580. * var arrays = _.times(2, _.stubArray);
  1581. *
  1582. * console.log(arrays);
  1583. * // => [[], []]
  1584. *
  1585. * console.log(arrays[0] === arrays[1]);
  1586. * // => false
  1587. */
  1588. function stubArray() {
  1589. return [];
  1590. }
  1591. /**
  1592. * This method returns `false`.
  1593. *
  1594. * @static
  1595. * @memberOf _
  1596. * @since 4.13.0
  1597. * @category Util
  1598. * @returns {boolean} Returns `false`.
  1599. * @example
  1600. *
  1601. * _.times(2, _.stubFalse);
  1602. * // => [false, false]
  1603. */
  1604. function stubFalse() {
  1605. return false;
  1606. }
  1607. module.exports = clone;