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 63KB

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