index.js 62 KB

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