index.js 48 KB

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