index.js 63 KB

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