index.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281
  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;