index.js 60 KB

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