You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 63KB

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