index.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368
  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 `_.forEach` without support for iteratee shorthands.
  735. *
  736. * @private
  737. * @param {Array|Object} collection The collection to iterate over.
  738. * @param {Function} iteratee The function invoked per iteration.
  739. * @returns {Array|Object} Returns `collection`.
  740. */
  741. var baseEach = createBaseEach(baseForOwn);
  742. /**
  743. * The base implementation of `baseForOwn` which iterates over `object`
  744. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  745. * Iteratee functions may exit iteration early by explicitly returning `false`.
  746. *
  747. * @private
  748. * @param {Object} object The object to iterate over.
  749. * @param {Function} iteratee The function invoked per iteration.
  750. * @param {Function} keysFunc The function to get the keys of `object`.
  751. * @returns {Object} Returns `object`.
  752. */
  753. var baseFor = createBaseFor();
  754. /**
  755. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  756. *
  757. * @private
  758. * @param {Object} object The object to iterate over.
  759. * @param {Function} iteratee The function invoked per iteration.
  760. * @returns {Object} Returns `object`.
  761. */
  762. function baseForOwn(object, iteratee) {
  763. return object && baseFor(object, iteratee, keys);
  764. }
  765. /**
  766. * The base implementation of `_.get` without support for default values.
  767. *
  768. * @private
  769. * @param {Object} object The object to query.
  770. * @param {Array|string} path The path of the property to get.
  771. * @returns {*} Returns the resolved value.
  772. */
  773. function baseGet(object, path) {
  774. path = isKey(path, object) ? [path] : castPath(path);
  775. var index = 0,
  776. length = path.length;
  777. while (object != null && index < length) {
  778. object = object[toKey(path[index++])];
  779. }
  780. return (index && index == length) ? object : undefined;
  781. }
  782. /**
  783. * The base implementation of `getTag`.
  784. *
  785. * @private
  786. * @param {*} value The value to query.
  787. * @returns {string} Returns the `toStringTag`.
  788. */
  789. function baseGetTag(value) {
  790. return objectToString.call(value);
  791. }
  792. /**
  793. * The base implementation of `_.hasIn` without support for deep paths.
  794. *
  795. * @private
  796. * @param {Object} [object] The object to query.
  797. * @param {Array|string} key The key to check.
  798. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  799. */
  800. function baseHasIn(object, key) {
  801. return object != null && key in Object(object);
  802. }
  803. /**
  804. * The base implementation of `_.isEqual` which supports partial comparisons
  805. * and tracks traversed objects.
  806. *
  807. * @private
  808. * @param {*} value The value to compare.
  809. * @param {*} other The other value to compare.
  810. * @param {Function} [customizer] The function to customize comparisons.
  811. * @param {boolean} [bitmask] The bitmask of comparison flags.
  812. * The bitmask may be composed of the following flags:
  813. * 1 - Unordered comparison
  814. * 2 - Partial comparison
  815. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  816. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  817. */
  818. function baseIsEqual(value, other, customizer, bitmask, stack) {
  819. if (value === other) {
  820. return true;
  821. }
  822. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  823. return value !== value && other !== other;
  824. }
  825. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  826. }
  827. /**
  828. * A specialized version of `baseIsEqual` for arrays and objects which performs
  829. * deep comparisons and tracks traversed objects enabling objects with circular
  830. * references to be compared.
  831. *
  832. * @private
  833. * @param {Object} object The object to compare.
  834. * @param {Object} other The other object to compare.
  835. * @param {Function} equalFunc The function to determine equivalents of values.
  836. * @param {Function} [customizer] The function to customize comparisons.
  837. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  838. * for more details.
  839. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  840. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  841. */
  842. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  843. var objIsArr = isArray(object),
  844. othIsArr = isArray(other),
  845. objTag = arrayTag,
  846. othTag = arrayTag;
  847. if (!objIsArr) {
  848. objTag = getTag(object);
  849. objTag = objTag == argsTag ? objectTag : objTag;
  850. }
  851. if (!othIsArr) {
  852. othTag = getTag(other);
  853. othTag = othTag == argsTag ? objectTag : othTag;
  854. }
  855. var objIsObj = objTag == objectTag && !isHostObject(object),
  856. othIsObj = othTag == objectTag && !isHostObject(other),
  857. isSameTag = objTag == othTag;
  858. if (isSameTag && !objIsObj) {
  859. stack || (stack = new Stack);
  860. return (objIsArr || isTypedArray(object))
  861. ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
  862. : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  863. }
  864. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  865. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  866. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  867. if (objIsWrapped || othIsWrapped) {
  868. var objUnwrapped = objIsWrapped ? object.value() : object,
  869. othUnwrapped = othIsWrapped ? other.value() : other;
  870. stack || (stack = new Stack);
  871. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  872. }
  873. }
  874. if (!isSameTag) {
  875. return false;
  876. }
  877. stack || (stack = new Stack);
  878. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  879. }
  880. /**
  881. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  882. *
  883. * @private
  884. * @param {Object} object The object to inspect.
  885. * @param {Object} source The object of property values to match.
  886. * @param {Array} matchData The property names, values, and compare flags to match.
  887. * @param {Function} [customizer] The function to customize comparisons.
  888. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  889. */
  890. function baseIsMatch(object, source, matchData, customizer) {
  891. var index = matchData.length,
  892. length = index,
  893. noCustomizer = !customizer;
  894. if (object == null) {
  895. return !length;
  896. }
  897. object = Object(object);
  898. while (index--) {
  899. var data = matchData[index];
  900. if ((noCustomizer && data[2])
  901. ? data[1] !== object[data[0]]
  902. : !(data[0] in object)
  903. ) {
  904. return false;
  905. }
  906. }
  907. while (++index < length) {
  908. data = matchData[index];
  909. var key = data[0],
  910. objValue = object[key],
  911. srcValue = data[1];
  912. if (noCustomizer && data[2]) {
  913. if (objValue === undefined && !(key in object)) {
  914. return false;
  915. }
  916. } else {
  917. var stack = new Stack;
  918. if (customizer) {
  919. var result = customizer(objValue, srcValue, key, object, source, stack);
  920. }
  921. if (!(result === undefined
  922. ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
  923. : result
  924. )) {
  925. return false;
  926. }
  927. }
  928. }
  929. return true;
  930. }
  931. /**
  932. * The base implementation of `_.isNative` without bad shim checks.
  933. *
  934. * @private
  935. * @param {*} value The value to check.
  936. * @returns {boolean} Returns `true` if `value` is a native function,
  937. * else `false`.
  938. */
  939. function baseIsNative(value) {
  940. if (!isObject(value) || isMasked(value)) {
  941. return false;
  942. }
  943. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  944. return pattern.test(toSource(value));
  945. }
  946. /**
  947. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  948. *
  949. * @private
  950. * @param {*} value The value to check.
  951. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  952. */
  953. function baseIsTypedArray(value) {
  954. return isObjectLike(value) &&
  955. isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  956. }
  957. /**
  958. * The base implementation of `_.iteratee`.
  959. *
  960. * @private
  961. * @param {*} [value=_.identity] The value to convert to an iteratee.
  962. * @returns {Function} Returns the iteratee.
  963. */
  964. function baseIteratee(value) {
  965. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  966. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  967. if (typeof value == 'function') {
  968. return value;
  969. }
  970. if (value == null) {
  971. return identity;
  972. }
  973. if (typeof value == 'object') {
  974. return isArray(value)
  975. ? baseMatchesProperty(value[0], value[1])
  976. : baseMatches(value);
  977. }
  978. return property(value);
  979. }
  980. /**
  981. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  982. *
  983. * @private
  984. * @param {Object} object The object to query.
  985. * @returns {Array} Returns the array of property names.
  986. */
  987. function baseKeys(object) {
  988. if (!isPrototype(object)) {
  989. return nativeKeys(object);
  990. }
  991. var result = [];
  992. for (var key in Object(object)) {
  993. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  994. result.push(key);
  995. }
  996. }
  997. return result;
  998. }
  999. /**
  1000. * The base implementation of `_.matches` which doesn't clone `source`.
  1001. *
  1002. * @private
  1003. * @param {Object} source The object of property values to match.
  1004. * @returns {Function} Returns the new spec function.
  1005. */
  1006. function baseMatches(source) {
  1007. var matchData = getMatchData(source);
  1008. if (matchData.length == 1 && matchData[0][2]) {
  1009. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  1010. }
  1011. return function(object) {
  1012. return object === source || baseIsMatch(object, source, matchData);
  1013. };
  1014. }
  1015. /**
  1016. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  1017. *
  1018. * @private
  1019. * @param {string} path The path of the property to get.
  1020. * @param {*} srcValue The value to match.
  1021. * @returns {Function} Returns the new spec function.
  1022. */
  1023. function baseMatchesProperty(path, srcValue) {
  1024. if (isKey(path) && isStrictComparable(srcValue)) {
  1025. return matchesStrictComparable(toKey(path), srcValue);
  1026. }
  1027. return function(object) {
  1028. var objValue = get(object, path);
  1029. return (objValue === undefined && objValue === srcValue)
  1030. ? hasIn(object, path)
  1031. : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  1032. };
  1033. }
  1034. /**
  1035. * A specialized version of `baseProperty` which supports deep paths.
  1036. *
  1037. * @private
  1038. * @param {Array|string} path The path of the property to get.
  1039. * @returns {Function} Returns the new accessor function.
  1040. */
  1041. function basePropertyDeep(path) {
  1042. return function(object) {
  1043. return baseGet(object, path);
  1044. };
  1045. }
  1046. /**
  1047. * The base implementation of `_.some` without support for iteratee shorthands.
  1048. *
  1049. * @private
  1050. * @param {Array|Object} collection The collection to iterate over.
  1051. * @param {Function} predicate The function invoked per iteration.
  1052. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1053. * else `false`.
  1054. */
  1055. function baseSome(collection, predicate) {
  1056. var result;
  1057. baseEach(collection, function(value, index, collection) {
  1058. result = predicate(value, index, collection);
  1059. return !result;
  1060. });
  1061. return !!result;
  1062. }
  1063. /**
  1064. * The base implementation of `_.toString` which doesn't convert nullish
  1065. * values to empty strings.
  1066. *
  1067. * @private
  1068. * @param {*} value The value to process.
  1069. * @returns {string} Returns the string.
  1070. */
  1071. function baseToString(value) {
  1072. // Exit early for strings to avoid a performance hit in some environments.
  1073. if (typeof value == 'string') {
  1074. return value;
  1075. }
  1076. if (isSymbol(value)) {
  1077. return symbolToString ? symbolToString.call(value) : '';
  1078. }
  1079. var result = (value + '');
  1080. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  1081. }
  1082. /**
  1083. * Casts `value` to a path array if it's not one.
  1084. *
  1085. * @private
  1086. * @param {*} value The value to inspect.
  1087. * @returns {Array} Returns the cast property path array.
  1088. */
  1089. function castPath(value) {
  1090. return isArray(value) ? value : stringToPath(value);
  1091. }
  1092. /**
  1093. * Creates a `baseEach` or `baseEachRight` function.
  1094. *
  1095. * @private
  1096. * @param {Function} eachFunc The function to iterate over a collection.
  1097. * @param {boolean} [fromRight] Specify iterating from right to left.
  1098. * @returns {Function} Returns the new base function.
  1099. */
  1100. function createBaseEach(eachFunc, fromRight) {
  1101. return function(collection, iteratee) {
  1102. if (collection == null) {
  1103. return collection;
  1104. }
  1105. if (!isArrayLike(collection)) {
  1106. return eachFunc(collection, iteratee);
  1107. }
  1108. var length = collection.length,
  1109. index = fromRight ? length : -1,
  1110. iterable = Object(collection);
  1111. while ((fromRight ? index-- : ++index < length)) {
  1112. if (iteratee(iterable[index], index, iterable) === false) {
  1113. break;
  1114. }
  1115. }
  1116. return collection;
  1117. };
  1118. }
  1119. /**
  1120. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  1121. *
  1122. * @private
  1123. * @param {boolean} [fromRight] Specify iterating from right to left.
  1124. * @returns {Function} Returns the new base function.
  1125. */
  1126. function createBaseFor(fromRight) {
  1127. return function(object, iteratee, keysFunc) {
  1128. var index = -1,
  1129. iterable = Object(object),
  1130. props = keysFunc(object),
  1131. length = props.length;
  1132. while (length--) {
  1133. var key = props[fromRight ? length : ++index];
  1134. if (iteratee(iterable[key], key, iterable) === false) {
  1135. break;
  1136. }
  1137. }
  1138. return object;
  1139. };
  1140. }
  1141. /**
  1142. * A specialized version of `baseIsEqualDeep` for arrays with support for
  1143. * partial deep comparisons.
  1144. *
  1145. * @private
  1146. * @param {Array} array The array to compare.
  1147. * @param {Array} other The other array to compare.
  1148. * @param {Function} equalFunc The function to determine equivalents of values.
  1149. * @param {Function} customizer The function to customize comparisons.
  1150. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1151. * for more details.
  1152. * @param {Object} stack Tracks traversed `array` and `other` objects.
  1153. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  1154. */
  1155. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  1156. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  1157. arrLength = array.length,
  1158. othLength = other.length;
  1159. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  1160. return false;
  1161. }
  1162. // Assume cyclic values are equal.
  1163. var stacked = stack.get(array);
  1164. if (stacked && stack.get(other)) {
  1165. return stacked == other;
  1166. }
  1167. var index = -1,
  1168. result = true,
  1169. seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
  1170. stack.set(array, other);
  1171. stack.set(other, array);
  1172. // Ignore non-index properties.
  1173. while (++index < arrLength) {
  1174. var arrValue = array[index],
  1175. othValue = other[index];
  1176. if (customizer) {
  1177. var compared = isPartial
  1178. ? customizer(othValue, arrValue, index, other, array, stack)
  1179. : customizer(arrValue, othValue, index, array, other, stack);
  1180. }
  1181. if (compared !== undefined) {
  1182. if (compared) {
  1183. continue;
  1184. }
  1185. result = false;
  1186. break;
  1187. }
  1188. // Recursively compare arrays (susceptible to call stack limits).
  1189. if (seen) {
  1190. if (!arraySome(other, function(othValue, othIndex) {
  1191. if (!seen.has(othIndex) &&
  1192. (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  1193. return seen.add(othIndex);
  1194. }
  1195. })) {
  1196. result = false;
  1197. break;
  1198. }
  1199. } else if (!(
  1200. arrValue === othValue ||
  1201. equalFunc(arrValue, othValue, customizer, bitmask, stack)
  1202. )) {
  1203. result = false;
  1204. break;
  1205. }
  1206. }
  1207. stack['delete'](array);
  1208. stack['delete'](other);
  1209. return result;
  1210. }
  1211. /**
  1212. * A specialized version of `baseIsEqualDeep` for comparing objects of
  1213. * the same `toStringTag`.
  1214. *
  1215. * **Note:** This function only supports comparing values with tags of
  1216. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  1217. *
  1218. * @private
  1219. * @param {Object} object The object to compare.
  1220. * @param {Object} other The other object to compare.
  1221. * @param {string} tag The `toStringTag` of the objects to compare.
  1222. * @param {Function} equalFunc The function to determine equivalents of values.
  1223. * @param {Function} customizer The function to customize comparisons.
  1224. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1225. * for more details.
  1226. * @param {Object} stack Tracks traversed `object` and `other` objects.
  1227. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1228. */
  1229. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  1230. switch (tag) {
  1231. case dataViewTag:
  1232. if ((object.byteLength != other.byteLength) ||
  1233. (object.byteOffset != other.byteOffset)) {
  1234. return false;
  1235. }
  1236. object = object.buffer;
  1237. other = other.buffer;
  1238. case arrayBufferTag:
  1239. if ((object.byteLength != other.byteLength) ||
  1240. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  1241. return false;
  1242. }
  1243. return true;
  1244. case boolTag:
  1245. case dateTag:
  1246. case numberTag:
  1247. // Coerce booleans to `1` or `0` and dates to milliseconds.
  1248. // Invalid dates are coerced to `NaN`.
  1249. return eq(+object, +other);
  1250. case errorTag:
  1251. return object.name == other.name && object.message == other.message;
  1252. case regexpTag:
  1253. case stringTag:
  1254. // Coerce regexes to strings and treat strings, primitives and objects,
  1255. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  1256. // for more details.
  1257. return object == (other + '');
  1258. case mapTag:
  1259. var convert = mapToArray;
  1260. case setTag:
  1261. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  1262. convert || (convert = setToArray);
  1263. if (object.size != other.size && !isPartial) {
  1264. return false;
  1265. }
  1266. // Assume cyclic values are equal.
  1267. var stacked = stack.get(object);
  1268. if (stacked) {
  1269. return stacked == other;
  1270. }
  1271. bitmask |= UNORDERED_COMPARE_FLAG;
  1272. // Recursively compare objects (susceptible to call stack limits).
  1273. stack.set(object, other);
  1274. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  1275. stack['delete'](object);
  1276. return result;
  1277. case symbolTag:
  1278. if (symbolValueOf) {
  1279. return symbolValueOf.call(object) == symbolValueOf.call(other);
  1280. }
  1281. }
  1282. return false;
  1283. }
  1284. /**
  1285. * A specialized version of `baseIsEqualDeep` for objects with support for
  1286. * partial deep comparisons.
  1287. *
  1288. * @private
  1289. * @param {Object} object The object to compare.
  1290. * @param {Object} other The other object to compare.
  1291. * @param {Function} equalFunc The function to determine equivalents of values.
  1292. * @param {Function} customizer The function to customize comparisons.
  1293. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1294. * for more details.
  1295. * @param {Object} stack Tracks traversed `object` and `other` objects.
  1296. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1297. */
  1298. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  1299. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  1300. objProps = keys(object),
  1301. objLength = objProps.length,
  1302. othProps = keys(other),
  1303. othLength = othProps.length;
  1304. if (objLength != othLength && !isPartial) {
  1305. return false;
  1306. }
  1307. var index = objLength;
  1308. while (index--) {
  1309. var key = objProps[index];
  1310. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  1311. return false;
  1312. }
  1313. }
  1314. // Assume cyclic values are equal.
  1315. var stacked = stack.get(object);
  1316. if (stacked && stack.get(other)) {
  1317. return stacked == other;
  1318. }
  1319. var result = true;
  1320. stack.set(object, other);
  1321. stack.set(other, object);
  1322. var skipCtor = isPartial;
  1323. while (++index < objLength) {
  1324. key = objProps[index];
  1325. var objValue = object[key],
  1326. othValue = other[key];
  1327. if (customizer) {
  1328. var compared = isPartial
  1329. ? customizer(othValue, objValue, key, other, object, stack)
  1330. : customizer(objValue, othValue, key, object, other, stack);
  1331. }
  1332. // Recursively compare objects (susceptible to call stack limits).
  1333. if (!(compared === undefined
  1334. ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
  1335. : compared
  1336. )) {
  1337. result = false;
  1338. break;
  1339. }
  1340. skipCtor || (skipCtor = key == 'constructor');
  1341. }
  1342. if (result && !skipCtor) {
  1343. var objCtor = object.constructor,
  1344. othCtor = other.constructor;
  1345. // Non `Object` object instances with different constructors are not equal.
  1346. if (objCtor != othCtor &&
  1347. ('constructor' in object && 'constructor' in other) &&
  1348. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  1349. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  1350. result = false;
  1351. }
  1352. }
  1353. stack['delete'](object);
  1354. stack['delete'](other);
  1355. return result;
  1356. }
  1357. /**
  1358. * Gets the data for `map`.
  1359. *
  1360. * @private
  1361. * @param {Object} map The map to query.
  1362. * @param {string} key The reference key.
  1363. * @returns {*} Returns the map data.
  1364. */
  1365. function getMapData(map, key) {
  1366. var data = map.__data__;
  1367. return isKeyable(key)
  1368. ? data[typeof key == 'string' ? 'string' : 'hash']
  1369. : data.map;
  1370. }
  1371. /**
  1372. * Gets the property names, values, and compare flags of `object`.
  1373. *
  1374. * @private
  1375. * @param {Object} object The object to query.
  1376. * @returns {Array} Returns the match data of `object`.
  1377. */
  1378. function getMatchData(object) {
  1379. var result = keys(object),
  1380. length = result.length;
  1381. while (length--) {
  1382. var key = result[length],
  1383. value = object[key];
  1384. result[length] = [key, value, isStrictComparable(value)];
  1385. }
  1386. return result;
  1387. }
  1388. /**
  1389. * Gets the native function at `key` of `object`.
  1390. *
  1391. * @private
  1392. * @param {Object} object The object to query.
  1393. * @param {string} key The key of the method to get.
  1394. * @returns {*} Returns the function if it's native, else `undefined`.
  1395. */
  1396. function getNative(object, key) {
  1397. var value = getValue(object, key);
  1398. return baseIsNative(value) ? value : undefined;
  1399. }
  1400. /**
  1401. * Gets the `toStringTag` of `value`.
  1402. *
  1403. * @private
  1404. * @param {*} value The value to query.
  1405. * @returns {string} Returns the `toStringTag`.
  1406. */
  1407. var getTag = baseGetTag;
  1408. // Fallback for data views, maps, sets, and weak maps in IE 11,
  1409. // for data views in Edge < 14, and promises in Node.js.
  1410. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  1411. (Map && getTag(new Map) != mapTag) ||
  1412. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  1413. (Set && getTag(new Set) != setTag) ||
  1414. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  1415. getTag = function(value) {
  1416. var result = objectToString.call(value),
  1417. Ctor = result == objectTag ? value.constructor : undefined,
  1418. ctorString = Ctor ? toSource(Ctor) : undefined;
  1419. if (ctorString) {
  1420. switch (ctorString) {
  1421. case dataViewCtorString: return dataViewTag;
  1422. case mapCtorString: return mapTag;
  1423. case promiseCtorString: return promiseTag;
  1424. case setCtorString: return setTag;
  1425. case weakMapCtorString: return weakMapTag;
  1426. }
  1427. }
  1428. return result;
  1429. };
  1430. }
  1431. /**
  1432. * Checks if `path` exists on `object`.
  1433. *
  1434. * @private
  1435. * @param {Object} object The object to query.
  1436. * @param {Array|string} path The path to check.
  1437. * @param {Function} hasFunc The function to check properties.
  1438. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  1439. */
  1440. function hasPath(object, path, hasFunc) {
  1441. path = isKey(path, object) ? [path] : castPath(path);
  1442. var result,
  1443. index = -1,
  1444. length = path.length;
  1445. while (++index < length) {
  1446. var key = toKey(path[index]);
  1447. if (!(result = object != null && hasFunc(object, key))) {
  1448. break;
  1449. }
  1450. object = object[key];
  1451. }
  1452. if (result) {
  1453. return result;
  1454. }
  1455. var length = object ? object.length : 0;
  1456. return !!length && isLength(length) && isIndex(key, length) &&
  1457. (isArray(object) || isArguments(object));
  1458. }
  1459. /**
  1460. * Checks if `value` is a valid array-like index.
  1461. *
  1462. * @private
  1463. * @param {*} value The value to check.
  1464. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  1465. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  1466. */
  1467. function isIndex(value, length) {
  1468. length = length == null ? MAX_SAFE_INTEGER : length;
  1469. return !!length &&
  1470. (typeof value == 'number' || reIsUint.test(value)) &&
  1471. (value > -1 && value % 1 == 0 && value < length);
  1472. }
  1473. /**
  1474. * Checks if the given arguments are from an iteratee call.
  1475. *
  1476. * @private
  1477. * @param {*} value The potential iteratee value argument.
  1478. * @param {*} index The potential iteratee index or key argument.
  1479. * @param {*} object The potential iteratee object argument.
  1480. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  1481. * else `false`.
  1482. */
  1483. function isIterateeCall(value, index, object) {
  1484. if (!isObject(object)) {
  1485. return false;
  1486. }
  1487. var type = typeof index;
  1488. if (type == 'number'
  1489. ? (isArrayLike(object) && isIndex(index, object.length))
  1490. : (type == 'string' && index in object)
  1491. ) {
  1492. return eq(object[index], value);
  1493. }
  1494. return false;
  1495. }
  1496. /**
  1497. * Checks if `value` is a property name and not a property path.
  1498. *
  1499. * @private
  1500. * @param {*} value The value to check.
  1501. * @param {Object} [object] The object to query keys on.
  1502. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  1503. */
  1504. function isKey(value, object) {
  1505. if (isArray(value)) {
  1506. return false;
  1507. }
  1508. var type = typeof value;
  1509. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  1510. value == null || isSymbol(value)) {
  1511. return true;
  1512. }
  1513. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  1514. (object != null && value in Object(object));
  1515. }
  1516. /**
  1517. * Checks if `value` is suitable for use as unique object key.
  1518. *
  1519. * @private
  1520. * @param {*} value The value to check.
  1521. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  1522. */
  1523. function isKeyable(value) {
  1524. var type = typeof value;
  1525. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  1526. ? (value !== '__proto__')
  1527. : (value === null);
  1528. }
  1529. /**
  1530. * Checks if `func` has its source masked.
  1531. *
  1532. * @private
  1533. * @param {Function} func The function to check.
  1534. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  1535. */
  1536. function isMasked(func) {
  1537. return !!maskSrcKey && (maskSrcKey in func);
  1538. }
  1539. /**
  1540. * Checks if `value` is likely a prototype object.
  1541. *
  1542. * @private
  1543. * @param {*} value The value to check.
  1544. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  1545. */
  1546. function isPrototype(value) {
  1547. var Ctor = value && value.constructor,
  1548. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  1549. return value === proto;
  1550. }
  1551. /**
  1552. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  1553. *
  1554. * @private
  1555. * @param {*} value The value to check.
  1556. * @returns {boolean} Returns `true` if `value` if suitable for strict
  1557. * equality comparisons, else `false`.
  1558. */
  1559. function isStrictComparable(value) {
  1560. return value === value && !isObject(value);
  1561. }
  1562. /**
  1563. * A specialized version of `matchesProperty` for source values suitable
  1564. * for strict equality comparisons, i.e. `===`.
  1565. *
  1566. * @private
  1567. * @param {string} key The key of the property to get.
  1568. * @param {*} srcValue The value to match.
  1569. * @returns {Function} Returns the new spec function.
  1570. */
  1571. function matchesStrictComparable(key, srcValue) {
  1572. return function(object) {
  1573. if (object == null) {
  1574. return false;
  1575. }
  1576. return object[key] === srcValue &&
  1577. (srcValue !== undefined || (key in Object(object)));
  1578. };
  1579. }
  1580. /**
  1581. * Converts `string` to a property path array.
  1582. *
  1583. * @private
  1584. * @param {string} string The string to convert.
  1585. * @returns {Array} Returns the property path array.
  1586. */
  1587. var stringToPath = memoize(function(string) {
  1588. string = toString(string);
  1589. var result = [];
  1590. if (reLeadingDot.test(string)) {
  1591. result.push('');
  1592. }
  1593. string.replace(rePropName, function(match, number, quote, string) {
  1594. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  1595. });
  1596. return result;
  1597. });
  1598. /**
  1599. * Converts `value` to a string key if it's not a string or symbol.
  1600. *
  1601. * @private
  1602. * @param {*} value The value to inspect.
  1603. * @returns {string|symbol} Returns the key.
  1604. */
  1605. function toKey(value) {
  1606. if (typeof value == 'string' || isSymbol(value)) {
  1607. return value;
  1608. }
  1609. var result = (value + '');
  1610. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  1611. }
  1612. /**
  1613. * Converts `func` to its source code.
  1614. *
  1615. * @private
  1616. * @param {Function} func The function to process.
  1617. * @returns {string} Returns the source code.
  1618. */
  1619. function toSource(func) {
  1620. if (func != null) {
  1621. try {
  1622. return funcToString.call(func);
  1623. } catch (e) {}
  1624. try {
  1625. return (func + '');
  1626. } catch (e) {}
  1627. }
  1628. return '';
  1629. }
  1630. /**
  1631. * Checks if `predicate` returns truthy for **any** element of `collection`.
  1632. * Iteration is stopped once `predicate` returns truthy. The predicate is
  1633. * invoked with three arguments: (value, index|key, collection).
  1634. *
  1635. * @static
  1636. * @memberOf _
  1637. * @since 0.1.0
  1638. * @category Collection
  1639. * @param {Array|Object} collection The collection to iterate over.
  1640. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  1641. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  1642. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1643. * else `false`.
  1644. * @example
  1645. *
  1646. * _.some([null, 0, 'yes', false], Boolean);
  1647. * // => true
  1648. *
  1649. * var users = [
  1650. * { 'user': 'barney', 'active': true },
  1651. * { 'user': 'fred', 'active': false }
  1652. * ];
  1653. *
  1654. * // The `_.matches` iteratee shorthand.
  1655. * _.some(users, { 'user': 'barney', 'active': false });
  1656. * // => false
  1657. *
  1658. * // The `_.matchesProperty` iteratee shorthand.
  1659. * _.some(users, ['active', false]);
  1660. * // => true
  1661. *
  1662. * // The `_.property` iteratee shorthand.
  1663. * _.some(users, 'active');
  1664. * // => true
  1665. */
  1666. function some(collection, predicate, guard) {
  1667. var func = isArray(collection) ? arraySome : baseSome;
  1668. if (guard && isIterateeCall(collection, predicate, guard)) {
  1669. predicate = undefined;
  1670. }
  1671. return func(collection, baseIteratee(predicate, 3));
  1672. }
  1673. /**
  1674. * Creates a function that memoizes the result of `func`. If `resolver` is
  1675. * provided, it determines the cache key for storing the result based on the
  1676. * arguments provided to the memoized function. By default, the first argument
  1677. * provided to the memoized function is used as the map cache key. The `func`
  1678. * is invoked with the `this` binding of the memoized function.
  1679. *
  1680. * **Note:** The cache is exposed as the `cache` property on the memoized
  1681. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  1682. * constructor with one whose instances implement the
  1683. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  1684. * method interface of `delete`, `get`, `has`, and `set`.
  1685. *
  1686. * @static
  1687. * @memberOf _
  1688. * @since 0.1.0
  1689. * @category Function
  1690. * @param {Function} func The function to have its output memoized.
  1691. * @param {Function} [resolver] The function to resolve the cache key.
  1692. * @returns {Function} Returns the new memoized function.
  1693. * @example
  1694. *
  1695. * var object = { 'a': 1, 'b': 2 };
  1696. * var other = { 'c': 3, 'd': 4 };
  1697. *
  1698. * var values = _.memoize(_.values);
  1699. * values(object);
  1700. * // => [1, 2]
  1701. *
  1702. * values(other);
  1703. * // => [3, 4]
  1704. *
  1705. * object.a = 2;
  1706. * values(object);
  1707. * // => [1, 2]
  1708. *
  1709. * // Modify the result cache.
  1710. * values.cache.set(object, ['a', 'b']);
  1711. * values(object);
  1712. * // => ['a', 'b']
  1713. *
  1714. * // Replace `_.memoize.Cache`.
  1715. * _.memoize.Cache = WeakMap;
  1716. */
  1717. function memoize(func, resolver) {
  1718. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  1719. throw new TypeError(FUNC_ERROR_TEXT);
  1720. }
  1721. var memoized = function() {
  1722. var args = arguments,
  1723. key = resolver ? resolver.apply(this, args) : args[0],
  1724. cache = memoized.cache;
  1725. if (cache.has(key)) {
  1726. return cache.get(key);
  1727. }
  1728. var result = func.apply(this, args);
  1729. memoized.cache = cache.set(key, result);
  1730. return result;
  1731. };
  1732. memoized.cache = new (memoize.Cache || MapCache);
  1733. return memoized;
  1734. }
  1735. // Assign cache to `_.memoize`.
  1736. memoize.Cache = MapCache;
  1737. /**
  1738. * Performs a
  1739. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  1740. * comparison between two values to determine if they are equivalent.
  1741. *
  1742. * @static
  1743. * @memberOf _
  1744. * @since 4.0.0
  1745. * @category Lang
  1746. * @param {*} value The value to compare.
  1747. * @param {*} other The other value to compare.
  1748. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1749. * @example
  1750. *
  1751. * var object = { 'a': 1 };
  1752. * var other = { 'a': 1 };
  1753. *
  1754. * _.eq(object, object);
  1755. * // => true
  1756. *
  1757. * _.eq(object, other);
  1758. * // => false
  1759. *
  1760. * _.eq('a', 'a');
  1761. * // => true
  1762. *
  1763. * _.eq('a', Object('a'));
  1764. * // => false
  1765. *
  1766. * _.eq(NaN, NaN);
  1767. * // => true
  1768. */
  1769. function eq(value, other) {
  1770. return value === other || (value !== value && other !== other);
  1771. }
  1772. /**
  1773. * Checks if `value` is likely an `arguments` object.
  1774. *
  1775. * @static
  1776. * @memberOf _
  1777. * @since 0.1.0
  1778. * @category Lang
  1779. * @param {*} value The value to check.
  1780. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  1781. * else `false`.
  1782. * @example
  1783. *
  1784. * _.isArguments(function() { return arguments; }());
  1785. * // => true
  1786. *
  1787. * _.isArguments([1, 2, 3]);
  1788. * // => false
  1789. */
  1790. function isArguments(value) {
  1791. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  1792. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  1793. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  1794. }
  1795. /**
  1796. * Checks if `value` is classified as an `Array` object.
  1797. *
  1798. * @static
  1799. * @memberOf _
  1800. * @since 0.1.0
  1801. * @category Lang
  1802. * @param {*} value The value to check.
  1803. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  1804. * @example
  1805. *
  1806. * _.isArray([1, 2, 3]);
  1807. * // => true
  1808. *
  1809. * _.isArray(document.body.children);
  1810. * // => false
  1811. *
  1812. * _.isArray('abc');
  1813. * // => false
  1814. *
  1815. * _.isArray(_.noop);
  1816. * // => false
  1817. */
  1818. var isArray = Array.isArray;
  1819. /**
  1820. * Checks if `value` is array-like. A value is considered array-like if it's
  1821. * not a function and has a `value.length` that's an integer greater than or
  1822. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  1823. *
  1824. * @static
  1825. * @memberOf _
  1826. * @since 4.0.0
  1827. * @category Lang
  1828. * @param {*} value The value to check.
  1829. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  1830. * @example
  1831. *
  1832. * _.isArrayLike([1, 2, 3]);
  1833. * // => true
  1834. *
  1835. * _.isArrayLike(document.body.children);
  1836. * // => true
  1837. *
  1838. * _.isArrayLike('abc');
  1839. * // => true
  1840. *
  1841. * _.isArrayLike(_.noop);
  1842. * // => false
  1843. */
  1844. function isArrayLike(value) {
  1845. return value != null && isLength(value.length) && !isFunction(value);
  1846. }
  1847. /**
  1848. * This method is like `_.isArrayLike` except that it also checks if `value`
  1849. * is an object.
  1850. *
  1851. * @static
  1852. * @memberOf _
  1853. * @since 4.0.0
  1854. * @category Lang
  1855. * @param {*} value The value to check.
  1856. * @returns {boolean} Returns `true` if `value` is an array-like object,
  1857. * else `false`.
  1858. * @example
  1859. *
  1860. * _.isArrayLikeObject([1, 2, 3]);
  1861. * // => true
  1862. *
  1863. * _.isArrayLikeObject(document.body.children);
  1864. * // => true
  1865. *
  1866. * _.isArrayLikeObject('abc');
  1867. * // => false
  1868. *
  1869. * _.isArrayLikeObject(_.noop);
  1870. * // => false
  1871. */
  1872. function isArrayLikeObject(value) {
  1873. return isObjectLike(value) && isArrayLike(value);
  1874. }
  1875. /**
  1876. * Checks if `value` is classified as a `Function` object.
  1877. *
  1878. * @static
  1879. * @memberOf _
  1880. * @since 0.1.0
  1881. * @category Lang
  1882. * @param {*} value The value to check.
  1883. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  1884. * @example
  1885. *
  1886. * _.isFunction(_);
  1887. * // => true
  1888. *
  1889. * _.isFunction(/abc/);
  1890. * // => false
  1891. */
  1892. function isFunction(value) {
  1893. // The use of `Object#toString` avoids issues with the `typeof` operator
  1894. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  1895. var tag = isObject(value) ? objectToString.call(value) : '';
  1896. return tag == funcTag || tag == genTag;
  1897. }
  1898. /**
  1899. * Checks if `value` is a valid array-like length.
  1900. *
  1901. * **Note:** This method is loosely based on
  1902. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  1903. *
  1904. * @static
  1905. * @memberOf _
  1906. * @since 4.0.0
  1907. * @category Lang
  1908. * @param {*} value The value to check.
  1909. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  1910. * @example
  1911. *
  1912. * _.isLength(3);
  1913. * // => true
  1914. *
  1915. * _.isLength(Number.MIN_VALUE);
  1916. * // => false
  1917. *
  1918. * _.isLength(Infinity);
  1919. * // => false
  1920. *
  1921. * _.isLength('3');
  1922. * // => false
  1923. */
  1924. function isLength(value) {
  1925. return typeof value == 'number' &&
  1926. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  1927. }
  1928. /**
  1929. * Checks if `value` is the
  1930. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1931. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1932. *
  1933. * @static
  1934. * @memberOf _
  1935. * @since 0.1.0
  1936. * @category Lang
  1937. * @param {*} value The value to check.
  1938. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1939. * @example
  1940. *
  1941. * _.isObject({});
  1942. * // => true
  1943. *
  1944. * _.isObject([1, 2, 3]);
  1945. * // => true
  1946. *
  1947. * _.isObject(_.noop);
  1948. * // => true
  1949. *
  1950. * _.isObject(null);
  1951. * // => false
  1952. */
  1953. function isObject(value) {
  1954. var type = typeof value;
  1955. return !!value && (type == 'object' || type == 'function');
  1956. }
  1957. /**
  1958. * Checks if `value` is object-like. A value is object-like if it's not `null`
  1959. * and has a `typeof` result of "object".
  1960. *
  1961. * @static
  1962. * @memberOf _
  1963. * @since 4.0.0
  1964. * @category Lang
  1965. * @param {*} value The value to check.
  1966. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1967. * @example
  1968. *
  1969. * _.isObjectLike({});
  1970. * // => true
  1971. *
  1972. * _.isObjectLike([1, 2, 3]);
  1973. * // => true
  1974. *
  1975. * _.isObjectLike(_.noop);
  1976. * // => false
  1977. *
  1978. * _.isObjectLike(null);
  1979. * // => false
  1980. */
  1981. function isObjectLike(value) {
  1982. return !!value && typeof value == 'object';
  1983. }
  1984. /**
  1985. * Checks if `value` is classified as a `Symbol` primitive or object.
  1986. *
  1987. * @static
  1988. * @memberOf _
  1989. * @since 4.0.0
  1990. * @category Lang
  1991. * @param {*} value The value to check.
  1992. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  1993. * @example
  1994. *
  1995. * _.isSymbol(Symbol.iterator);
  1996. * // => true
  1997. *
  1998. * _.isSymbol('abc');
  1999. * // => false
  2000. */
  2001. function isSymbol(value) {
  2002. return typeof value == 'symbol' ||
  2003. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  2004. }
  2005. /**
  2006. * Checks if `value` is classified as a typed array.
  2007. *
  2008. * @static
  2009. * @memberOf _
  2010. * @since 3.0.0
  2011. * @category Lang
  2012. * @param {*} value The value to check.
  2013. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  2014. * @example
  2015. *
  2016. * _.isTypedArray(new Uint8Array);
  2017. * // => true
  2018. *
  2019. * _.isTypedArray([]);
  2020. * // => false
  2021. */
  2022. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  2023. /**
  2024. * Converts `value` to a string. An empty string is returned for `null`
  2025. * and `undefined` values. The sign of `-0` is preserved.
  2026. *
  2027. * @static
  2028. * @memberOf _
  2029. * @since 4.0.0
  2030. * @category Lang
  2031. * @param {*} value The value to process.
  2032. * @returns {string} Returns the string.
  2033. * @example
  2034. *
  2035. * _.toString(null);
  2036. * // => ''
  2037. *
  2038. * _.toString(-0);
  2039. * // => '-0'
  2040. *
  2041. * _.toString([1, 2, 3]);
  2042. * // => '1,2,3'
  2043. */
  2044. function toString(value) {
  2045. return value == null ? '' : baseToString(value);
  2046. }
  2047. /**
  2048. * Gets the value at `path` of `object`. If the resolved value is
  2049. * `undefined`, the `defaultValue` is returned in its place.
  2050. *
  2051. * @static
  2052. * @memberOf _
  2053. * @since 3.7.0
  2054. * @category Object
  2055. * @param {Object} object The object to query.
  2056. * @param {Array|string} path The path of the property to get.
  2057. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  2058. * @returns {*} Returns the resolved value.
  2059. * @example
  2060. *
  2061. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  2062. *
  2063. * _.get(object, 'a[0].b.c');
  2064. * // => 3
  2065. *
  2066. * _.get(object, ['a', '0', 'b', 'c']);
  2067. * // => 3
  2068. *
  2069. * _.get(object, 'a.b.c', 'default');
  2070. * // => 'default'
  2071. */
  2072. function get(object, path, defaultValue) {
  2073. var result = object == null ? undefined : baseGet(object, path);
  2074. return result === undefined ? defaultValue : result;
  2075. }
  2076. /**
  2077. * Checks if `path` is a direct or inherited property of `object`.
  2078. *
  2079. * @static
  2080. * @memberOf _
  2081. * @since 4.0.0
  2082. * @category Object
  2083. * @param {Object} object The object to query.
  2084. * @param {Array|string} path The path to check.
  2085. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  2086. * @example
  2087. *
  2088. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  2089. *
  2090. * _.hasIn(object, 'a');
  2091. * // => true
  2092. *
  2093. * _.hasIn(object, 'a.b');
  2094. * // => true
  2095. *
  2096. * _.hasIn(object, ['a', 'b']);
  2097. * // => true
  2098. *
  2099. * _.hasIn(object, 'b');
  2100. * // => false
  2101. */
  2102. function hasIn(object, path) {
  2103. return object != null && hasPath(object, path, baseHasIn);
  2104. }
  2105. /**
  2106. * Creates an array of the own enumerable property names of `object`.
  2107. *
  2108. * **Note:** Non-object values are coerced to objects. See the
  2109. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  2110. * for more details.
  2111. *
  2112. * @static
  2113. * @since 0.1.0
  2114. * @memberOf _
  2115. * @category Object
  2116. * @param {Object} object The object to query.
  2117. * @returns {Array} Returns the array of property names.
  2118. * @example
  2119. *
  2120. * function Foo() {
  2121. * this.a = 1;
  2122. * this.b = 2;
  2123. * }
  2124. *
  2125. * Foo.prototype.c = 3;
  2126. *
  2127. * _.keys(new Foo);
  2128. * // => ['a', 'b'] (iteration order is not guaranteed)
  2129. *
  2130. * _.keys('hi');
  2131. * // => ['0', '1']
  2132. */
  2133. function keys(object) {
  2134. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  2135. }
  2136. /**
  2137. * This method returns the first argument it receives.
  2138. *
  2139. * @static
  2140. * @since 0.1.0
  2141. * @memberOf _
  2142. * @category Util
  2143. * @param {*} value Any value.
  2144. * @returns {*} Returns `value`.
  2145. * @example
  2146. *
  2147. * var object = { 'a': 1 };
  2148. *
  2149. * console.log(_.identity(object) === object);
  2150. * // => true
  2151. */
  2152. function identity(value) {
  2153. return value;
  2154. }
  2155. /**
  2156. * Creates a function that returns the value at `path` of a given object.
  2157. *
  2158. * @static
  2159. * @memberOf _
  2160. * @since 2.4.0
  2161. * @category Util
  2162. * @param {Array|string} path The path of the property to get.
  2163. * @returns {Function} Returns the new accessor function.
  2164. * @example
  2165. *
  2166. * var objects = [
  2167. * { 'a': { 'b': 2 } },
  2168. * { 'a': { 'b': 1 } }
  2169. * ];
  2170. *
  2171. * _.map(objects, _.property('a.b'));
  2172. * // => [2, 1]
  2173. *
  2174. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  2175. * // => [1, 2]
  2176. */
  2177. function property(path) {
  2178. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  2179. }
  2180. module.exports = some;