You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 62KB

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