index.js 63 KB

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