index.js 63 KB

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