index.js 46 KB

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