index.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  1. /**
  2. * Lodash (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modularize exports="npm" -o ./`
  4. * Copyright JS Foundation and other contributors <https://js.foundation/>
  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 to stand-in for `undefined` hash values. */
  12. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  13. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  14. var HOT_COUNT = 800,
  15. HOT_SPAN = 16;
  16. /** Used as references for various `Number` constants. */
  17. var MAX_SAFE_INTEGER = 9007199254740991;
  18. /** `Object#toString` result references. */
  19. var argsTag = '[object Arguments]',
  20. arrayTag = '[object Array]',
  21. asyncTag = '[object AsyncFunction]',
  22. boolTag = '[object Boolean]',
  23. dateTag = '[object Date]',
  24. errorTag = '[object Error]',
  25. funcTag = '[object Function]',
  26. genTag = '[object GeneratorFunction]',
  27. mapTag = '[object Map]',
  28. numberTag = '[object Number]',
  29. nullTag = '[object Null]',
  30. objectTag = '[object Object]',
  31. proxyTag = '[object Proxy]',
  32. regexpTag = '[object RegExp]',
  33. setTag = '[object Set]',
  34. stringTag = '[object String]',
  35. undefinedTag = '[object Undefined]',
  36. weakMapTag = '[object WeakMap]';
  37. var arrayBufferTag = '[object ArrayBuffer]',
  38. dataViewTag = '[object DataView]',
  39. float32Tag = '[object Float32Array]',
  40. float64Tag = '[object Float64Array]',
  41. int8Tag = '[object Int8Array]',
  42. int16Tag = '[object Int16Array]',
  43. int32Tag = '[object Int32Array]',
  44. uint8Tag = '[object Uint8Array]',
  45. uint8ClampedTag = '[object Uint8ClampedArray]',
  46. uint16Tag = '[object Uint16Array]',
  47. uint32Tag = '[object Uint32Array]';
  48. /**
  49. * Used to match `RegExp`
  50. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  51. */
  52. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  53. /** Used to detect host constructors (Safari). */
  54. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  55. /** Used to detect unsigned integer values. */
  56. var reIsUint = /^(?:0|[1-9]\d*)$/;
  57. /** Used to identify `toStringTag` values of typed arrays. */
  58. var typedArrayTags = {};
  59. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  60. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  61. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  62. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  63. typedArrayTags[uint32Tag] = true;
  64. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  65. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  66. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  67. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  68. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  69. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  70. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  71. typedArrayTags[weakMapTag] = false;
  72. /** Detect free variable `global` from Node.js. */
  73. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  74. /** Detect free variable `self`. */
  75. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  76. /** Used as a reference to the global object. */
  77. var root = freeGlobal || freeSelf || Function('return this')();
  78. /** Detect free variable `exports`. */
  79. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  80. /** Detect free variable `module`. */
  81. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  82. /** Detect the popular CommonJS extension `module.exports`. */
  83. var moduleExports = freeModule && freeModule.exports === freeExports;
  84. /** Detect free variable `process` from Node.js. */
  85. var freeProcess = moduleExports && freeGlobal.process;
  86. /** Used to access faster Node.js helpers. */
  87. var nodeUtil = (function() {
  88. try {
  89. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  90. } catch (e) {}
  91. }());
  92. /* Node.js helper references. */
  93. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  94. /**
  95. * A faster alternative to `Function#apply`, this function invokes `func`
  96. * with the `this` binding of `thisArg` and the arguments of `args`.
  97. *
  98. * @private
  99. * @param {Function} func The function to invoke.
  100. * @param {*} thisArg The `this` binding of `func`.
  101. * @param {Array} args The arguments to invoke `func` with.
  102. * @returns {*} Returns the result of `func`.
  103. */
  104. function apply(func, thisArg, args) {
  105. switch (args.length) {
  106. case 0: return func.call(thisArg);
  107. case 1: return func.call(thisArg, args[0]);
  108. case 2: return func.call(thisArg, args[0], args[1]);
  109. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  110. }
  111. return func.apply(thisArg, args);
  112. }
  113. /**
  114. * The base implementation of `_.times` without support for iteratee shorthands
  115. * or max array length checks.
  116. *
  117. * @private
  118. * @param {number} n The number of times to invoke `iteratee`.
  119. * @param {Function} iteratee The function invoked per iteration.
  120. * @returns {Array} Returns the array of results.
  121. */
  122. function baseTimes(n, iteratee) {
  123. var index = -1,
  124. result = Array(n);
  125. while (++index < n) {
  126. result[index] = iteratee(index);
  127. }
  128. return result;
  129. }
  130. /**
  131. * The base implementation of `_.unary` without support for storing metadata.
  132. *
  133. * @private
  134. * @param {Function} func The function to cap arguments for.
  135. * @returns {Function} Returns the new capped function.
  136. */
  137. function baseUnary(func) {
  138. return function(value) {
  139. return func(value);
  140. };
  141. }
  142. /**
  143. * Gets the value at `key` of `object`.
  144. *
  145. * @private
  146. * @param {Object} [object] The object to query.
  147. * @param {string} key The key of the property to get.
  148. * @returns {*} Returns the property value.
  149. */
  150. function getValue(object, key) {
  151. return object == null ? undefined : object[key];
  152. }
  153. /**
  154. * Creates a unary function that invokes `func` with its argument transformed.
  155. *
  156. * @private
  157. * @param {Function} func The function to wrap.
  158. * @param {Function} transform The argument transform.
  159. * @returns {Function} Returns the new function.
  160. */
  161. function overArg(func, transform) {
  162. return function(arg) {
  163. return func(transform(arg));
  164. };
  165. }
  166. /**
  167. * Gets the value at `key`, unless `key` is "__proto__".
  168. *
  169. * @private
  170. * @param {Object} object The object to query.
  171. * @param {string} key The key of the property to get.
  172. * @returns {*} Returns the property value.
  173. */
  174. function safeGet(object, key) {
  175. return key == '__proto__'
  176. ? undefined
  177. : object[key];
  178. }
  179. /** Used for built-in method references. */
  180. var arrayProto = Array.prototype,
  181. funcProto = Function.prototype,
  182. objectProto = Object.prototype;
  183. /** Used to detect overreaching core-js shims. */
  184. var coreJsData = root['__core-js_shared__'];
  185. /** Used to resolve the decompiled source of functions. */
  186. var funcToString = funcProto.toString;
  187. /** Used to check objects for own properties. */
  188. var hasOwnProperty = objectProto.hasOwnProperty;
  189. /** Used to detect methods masquerading as native. */
  190. var maskSrcKey = (function() {
  191. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  192. return uid ? ('Symbol(src)_1.' + uid) : '';
  193. }());
  194. /**
  195. * Used to resolve the
  196. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  197. * of values.
  198. */
  199. var nativeObjectToString = objectProto.toString;
  200. /** Used to infer the `Object` constructor. */
  201. var objectCtorString = funcToString.call(Object);
  202. /** Used to detect if a method is native. */
  203. var reIsNative = RegExp('^' +
  204. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  205. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  206. );
  207. /** Built-in value references. */
  208. var Buffer = moduleExports ? root.Buffer : undefined,
  209. Symbol = root.Symbol,
  210. Uint8Array = root.Uint8Array,
  211. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  212. getPrototype = overArg(Object.getPrototypeOf, Object),
  213. objectCreate = Object.create,
  214. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  215. splice = arrayProto.splice,
  216. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  217. var defineProperty = (function() {
  218. try {
  219. var func = getNative(Object, 'defineProperty');
  220. func({}, '', {});
  221. return func;
  222. } catch (e) {}
  223. }());
  224. /* Built-in method references for those with the same name as other `lodash` methods. */
  225. var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  226. nativeMax = Math.max,
  227. nativeNow = Date.now;
  228. /* Built-in method references that are verified to be native. */
  229. var Map = getNative(root, 'Map'),
  230. nativeCreate = getNative(Object, 'create');
  231. /**
  232. * The base implementation of `_.create` without support for assigning
  233. * properties to the created object.
  234. *
  235. * @private
  236. * @param {Object} proto The object to inherit from.
  237. * @returns {Object} Returns the new object.
  238. */
  239. var baseCreate = (function() {
  240. function object() {}
  241. return function(proto) {
  242. if (!isObject(proto)) {
  243. return {};
  244. }
  245. if (objectCreate) {
  246. return objectCreate(proto);
  247. }
  248. object.prototype = proto;
  249. var result = new object;
  250. object.prototype = undefined;
  251. return result;
  252. };
  253. }());
  254. /**
  255. * Creates a hash object.
  256. *
  257. * @private
  258. * @constructor
  259. * @param {Array} [entries] The key-value pairs to cache.
  260. */
  261. function Hash(entries) {
  262. var index = -1,
  263. length = entries == null ? 0 : entries.length;
  264. this.clear();
  265. while (++index < length) {
  266. var entry = entries[index];
  267. this.set(entry[0], entry[1]);
  268. }
  269. }
  270. /**
  271. * Removes all key-value entries from the hash.
  272. *
  273. * @private
  274. * @name clear
  275. * @memberOf Hash
  276. */
  277. function hashClear() {
  278. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  279. this.size = 0;
  280. }
  281. /**
  282. * Removes `key` and its value from the hash.
  283. *
  284. * @private
  285. * @name delete
  286. * @memberOf Hash
  287. * @param {Object} hash The hash to modify.
  288. * @param {string} key The key of the value to remove.
  289. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  290. */
  291. function hashDelete(key) {
  292. var result = this.has(key) && delete this.__data__[key];
  293. this.size -= result ? 1 : 0;
  294. return result;
  295. }
  296. /**
  297. * Gets the hash value for `key`.
  298. *
  299. * @private
  300. * @name get
  301. * @memberOf Hash
  302. * @param {string} key The key of the value to get.
  303. * @returns {*} Returns the entry value.
  304. */
  305. function hashGet(key) {
  306. var data = this.__data__;
  307. if (nativeCreate) {
  308. var result = data[key];
  309. return result === HASH_UNDEFINED ? undefined : result;
  310. }
  311. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  312. }
  313. /**
  314. * Checks if a hash value for `key` exists.
  315. *
  316. * @private
  317. * @name has
  318. * @memberOf Hash
  319. * @param {string} key The key of the entry to check.
  320. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  321. */
  322. function hashHas(key) {
  323. var data = this.__data__;
  324. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  325. }
  326. /**
  327. * Sets the hash `key` to `value`.
  328. *
  329. * @private
  330. * @name set
  331. * @memberOf Hash
  332. * @param {string} key The key of the value to set.
  333. * @param {*} value The value to set.
  334. * @returns {Object} Returns the hash instance.
  335. */
  336. function hashSet(key, value) {
  337. var data = this.__data__;
  338. this.size += this.has(key) ? 0 : 1;
  339. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  340. return this;
  341. }
  342. // Add methods to `Hash`.
  343. Hash.prototype.clear = hashClear;
  344. Hash.prototype['delete'] = hashDelete;
  345. Hash.prototype.get = hashGet;
  346. Hash.prototype.has = hashHas;
  347. Hash.prototype.set = hashSet;
  348. /**
  349. * Creates an list cache object.
  350. *
  351. * @private
  352. * @constructor
  353. * @param {Array} [entries] The key-value pairs to cache.
  354. */
  355. function ListCache(entries) {
  356. var index = -1,
  357. length = entries == null ? 0 : entries.length;
  358. this.clear();
  359. while (++index < length) {
  360. var entry = entries[index];
  361. this.set(entry[0], entry[1]);
  362. }
  363. }
  364. /**
  365. * Removes all key-value entries from the list cache.
  366. *
  367. * @private
  368. * @name clear
  369. * @memberOf ListCache
  370. */
  371. function listCacheClear() {
  372. this.__data__ = [];
  373. this.size = 0;
  374. }
  375. /**
  376. * Removes `key` and its value from the list cache.
  377. *
  378. * @private
  379. * @name delete
  380. * @memberOf ListCache
  381. * @param {string} key The key of the value to remove.
  382. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  383. */
  384. function listCacheDelete(key) {
  385. var data = this.__data__,
  386. index = assocIndexOf(data, key);
  387. if (index < 0) {
  388. return false;
  389. }
  390. var lastIndex = data.length - 1;
  391. if (index == lastIndex) {
  392. data.pop();
  393. } else {
  394. splice.call(data, index, 1);
  395. }
  396. --this.size;
  397. return true;
  398. }
  399. /**
  400. * Gets the list cache value for `key`.
  401. *
  402. * @private
  403. * @name get
  404. * @memberOf ListCache
  405. * @param {string} key The key of the value to get.
  406. * @returns {*} Returns the entry value.
  407. */
  408. function listCacheGet(key) {
  409. var data = this.__data__,
  410. index = assocIndexOf(data, key);
  411. return index < 0 ? undefined : data[index][1];
  412. }
  413. /**
  414. * Checks if a list cache value for `key` exists.
  415. *
  416. * @private
  417. * @name has
  418. * @memberOf ListCache
  419. * @param {string} key The key of the entry to check.
  420. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  421. */
  422. function listCacheHas(key) {
  423. return assocIndexOf(this.__data__, key) > -1;
  424. }
  425. /**
  426. * Sets the list cache `key` to `value`.
  427. *
  428. * @private
  429. * @name set
  430. * @memberOf ListCache
  431. * @param {string} key The key of the value to set.
  432. * @param {*} value The value to set.
  433. * @returns {Object} Returns the list cache instance.
  434. */
  435. function listCacheSet(key, value) {
  436. var data = this.__data__,
  437. index = assocIndexOf(data, key);
  438. if (index < 0) {
  439. ++this.size;
  440. data.push([key, value]);
  441. } else {
  442. data[index][1] = value;
  443. }
  444. return this;
  445. }
  446. // Add methods to `ListCache`.
  447. ListCache.prototype.clear = listCacheClear;
  448. ListCache.prototype['delete'] = listCacheDelete;
  449. ListCache.prototype.get = listCacheGet;
  450. ListCache.prototype.has = listCacheHas;
  451. ListCache.prototype.set = listCacheSet;
  452. /**
  453. * Creates a map cache object to store key-value pairs.
  454. *
  455. * @private
  456. * @constructor
  457. * @param {Array} [entries] The key-value pairs to cache.
  458. */
  459. function MapCache(entries) {
  460. var index = -1,
  461. length = entries == null ? 0 : entries.length;
  462. this.clear();
  463. while (++index < length) {
  464. var entry = entries[index];
  465. this.set(entry[0], entry[1]);
  466. }
  467. }
  468. /**
  469. * Removes all key-value entries from the map.
  470. *
  471. * @private
  472. * @name clear
  473. * @memberOf MapCache
  474. */
  475. function mapCacheClear() {
  476. this.size = 0;
  477. this.__data__ = {
  478. 'hash': new Hash,
  479. 'map': new (Map || ListCache),
  480. 'string': new Hash
  481. };
  482. }
  483. /**
  484. * Removes `key` and its value from the map.
  485. *
  486. * @private
  487. * @name delete
  488. * @memberOf MapCache
  489. * @param {string} key The key of the value to remove.
  490. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  491. */
  492. function mapCacheDelete(key) {
  493. var result = getMapData(this, key)['delete'](key);
  494. this.size -= result ? 1 : 0;
  495. return result;
  496. }
  497. /**
  498. * Gets the map value for `key`.
  499. *
  500. * @private
  501. * @name get
  502. * @memberOf MapCache
  503. * @param {string} key The key of the value to get.
  504. * @returns {*} Returns the entry value.
  505. */
  506. function mapCacheGet(key) {
  507. return getMapData(this, key).get(key);
  508. }
  509. /**
  510. * Checks if a map value for `key` exists.
  511. *
  512. * @private
  513. * @name has
  514. * @memberOf MapCache
  515. * @param {string} key The key of the entry to check.
  516. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  517. */
  518. function mapCacheHas(key) {
  519. return getMapData(this, key).has(key);
  520. }
  521. /**
  522. * Sets the map `key` to `value`.
  523. *
  524. * @private
  525. * @name set
  526. * @memberOf MapCache
  527. * @param {string} key The key of the value to set.
  528. * @param {*} value The value to set.
  529. * @returns {Object} Returns the map cache instance.
  530. */
  531. function mapCacheSet(key, value) {
  532. var data = getMapData(this, key),
  533. size = data.size;
  534. data.set(key, value);
  535. this.size += data.size == size ? 0 : 1;
  536. return this;
  537. }
  538. // Add methods to `MapCache`.
  539. MapCache.prototype.clear = mapCacheClear;
  540. MapCache.prototype['delete'] = mapCacheDelete;
  541. MapCache.prototype.get = mapCacheGet;
  542. MapCache.prototype.has = mapCacheHas;
  543. MapCache.prototype.set = mapCacheSet;
  544. /**
  545. * Creates a stack cache object to store key-value pairs.
  546. *
  547. * @private
  548. * @constructor
  549. * @param {Array} [entries] The key-value pairs to cache.
  550. */
  551. function Stack(entries) {
  552. var data = this.__data__ = new ListCache(entries);
  553. this.size = data.size;
  554. }
  555. /**
  556. * Removes all key-value entries from the stack.
  557. *
  558. * @private
  559. * @name clear
  560. * @memberOf Stack
  561. */
  562. function stackClear() {
  563. this.__data__ = new ListCache;
  564. this.size = 0;
  565. }
  566. /**
  567. * Removes `key` and its value from the stack.
  568. *
  569. * @private
  570. * @name delete
  571. * @memberOf Stack
  572. * @param {string} key The key of the value to remove.
  573. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  574. */
  575. function stackDelete(key) {
  576. var data = this.__data__,
  577. result = data['delete'](key);
  578. this.size = data.size;
  579. return result;
  580. }
  581. /**
  582. * Gets the stack value for `key`.
  583. *
  584. * @private
  585. * @name get
  586. * @memberOf Stack
  587. * @param {string} key The key of the value to get.
  588. * @returns {*} Returns the entry value.
  589. */
  590. function stackGet(key) {
  591. return this.__data__.get(key);
  592. }
  593. /**
  594. * Checks if a stack value for `key` exists.
  595. *
  596. * @private
  597. * @name has
  598. * @memberOf Stack
  599. * @param {string} key The key of the entry to check.
  600. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  601. */
  602. function stackHas(key) {
  603. return this.__data__.has(key);
  604. }
  605. /**
  606. * Sets the stack `key` to `value`.
  607. *
  608. * @private
  609. * @name set
  610. * @memberOf Stack
  611. * @param {string} key The key of the value to set.
  612. * @param {*} value The value to set.
  613. * @returns {Object} Returns the stack cache instance.
  614. */
  615. function stackSet(key, value) {
  616. var data = this.__data__;
  617. if (data instanceof ListCache) {
  618. var pairs = data.__data__;
  619. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  620. pairs.push([key, value]);
  621. this.size = ++data.size;
  622. return this;
  623. }
  624. data = this.__data__ = new MapCache(pairs);
  625. }
  626. data.set(key, value);
  627. this.size = data.size;
  628. return this;
  629. }
  630. // Add methods to `Stack`.
  631. Stack.prototype.clear = stackClear;
  632. Stack.prototype['delete'] = stackDelete;
  633. Stack.prototype.get = stackGet;
  634. Stack.prototype.has = stackHas;
  635. Stack.prototype.set = stackSet;
  636. /**
  637. * Creates an array of the enumerable property names of the array-like `value`.
  638. *
  639. * @private
  640. * @param {*} value The value to query.
  641. * @param {boolean} inherited Specify returning inherited property names.
  642. * @returns {Array} Returns the array of property names.
  643. */
  644. function arrayLikeKeys(value, inherited) {
  645. var isArr = isArray(value),
  646. isArg = !isArr && isArguments(value),
  647. isBuff = !isArr && !isArg && isBuffer(value),
  648. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  649. skipIndexes = isArr || isArg || isBuff || isType,
  650. result = skipIndexes ? baseTimes(value.length, String) : [],
  651. length = result.length;
  652. for (var key in value) {
  653. if ((inherited || hasOwnProperty.call(value, key)) &&
  654. !(skipIndexes && (
  655. // Safari 9 has enumerable `arguments.length` in strict mode.
  656. key == 'length' ||
  657. // Node.js 0.10 has enumerable non-index properties on buffers.
  658. (isBuff && (key == 'offset' || key == 'parent')) ||
  659. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  660. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  661. // Skip index properties.
  662. isIndex(key, length)
  663. ))) {
  664. result.push(key);
  665. }
  666. }
  667. return result;
  668. }
  669. /**
  670. * This function is like `assignValue` except that it doesn't assign
  671. * `undefined` values.
  672. *
  673. * @private
  674. * @param {Object} object The object to modify.
  675. * @param {string} key The key of the property to assign.
  676. * @param {*} value The value to assign.
  677. */
  678. function assignMergeValue(object, key, value) {
  679. if ((value !== undefined && !eq(object[key], value)) ||
  680. (value === undefined && !(key in object))) {
  681. baseAssignValue(object, key, value);
  682. }
  683. }
  684. /**
  685. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  686. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  687. * for equality comparisons.
  688. *
  689. * @private
  690. * @param {Object} object The object to modify.
  691. * @param {string} key The key of the property to assign.
  692. * @param {*} value The value to assign.
  693. */
  694. function assignValue(object, key, value) {
  695. var objValue = object[key];
  696. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  697. (value === undefined && !(key in object))) {
  698. baseAssignValue(object, key, value);
  699. }
  700. }
  701. /**
  702. * Gets the index at which the `key` is found in `array` of key-value pairs.
  703. *
  704. * @private
  705. * @param {Array} array The array to inspect.
  706. * @param {*} key The key to search for.
  707. * @returns {number} Returns the index of the matched value, else `-1`.
  708. */
  709. function assocIndexOf(array, key) {
  710. var length = array.length;
  711. while (length--) {
  712. if (eq(array[length][0], key)) {
  713. return length;
  714. }
  715. }
  716. return -1;
  717. }
  718. /**
  719. * The base implementation of `assignValue` and `assignMergeValue` without
  720. * value checks.
  721. *
  722. * @private
  723. * @param {Object} object The object to modify.
  724. * @param {string} key The key of the property to assign.
  725. * @param {*} value The value to assign.
  726. */
  727. function baseAssignValue(object, key, value) {
  728. if (key == '__proto__' && defineProperty) {
  729. defineProperty(object, key, {
  730. 'configurable': true,
  731. 'enumerable': true,
  732. 'value': value,
  733. 'writable': true
  734. });
  735. } else {
  736. object[key] = value;
  737. }
  738. }
  739. /**
  740. * The base implementation of `baseForOwn` which iterates over `object`
  741. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  742. * Iteratee functions may exit iteration early by explicitly returning `false`.
  743. *
  744. * @private
  745. * @param {Object} object The object to iterate over.
  746. * @param {Function} iteratee The function invoked per iteration.
  747. * @param {Function} keysFunc The function to get the keys of `object`.
  748. * @returns {Object} Returns `object`.
  749. */
  750. var baseFor = createBaseFor();
  751. /**
  752. * The base implementation of `getTag` without fallbacks for buggy environments.
  753. *
  754. * @private
  755. * @param {*} value The value to query.
  756. * @returns {string} Returns the `toStringTag`.
  757. */
  758. function baseGetTag(value) {
  759. if (value == null) {
  760. return value === undefined ? undefinedTag : nullTag;
  761. }
  762. return (symToStringTag && symToStringTag in Object(value))
  763. ? getRawTag(value)
  764. : objectToString(value);
  765. }
  766. /**
  767. * The base implementation of `_.isArguments`.
  768. *
  769. * @private
  770. * @param {*} value The value to check.
  771. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  772. */
  773. function baseIsArguments(value) {
  774. return isObjectLike(value) && baseGetTag(value) == argsTag;
  775. }
  776. /**
  777. * The base implementation of `_.isNative` without bad shim checks.
  778. *
  779. * @private
  780. * @param {*} value The value to check.
  781. * @returns {boolean} Returns `true` if `value` is a native function,
  782. * else `false`.
  783. */
  784. function baseIsNative(value) {
  785. if (!isObject(value) || isMasked(value)) {
  786. return false;
  787. }
  788. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  789. return pattern.test(toSource(value));
  790. }
  791. /**
  792. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  793. *
  794. * @private
  795. * @param {*} value The value to check.
  796. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  797. */
  798. function baseIsTypedArray(value) {
  799. return isObjectLike(value) &&
  800. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  801. }
  802. /**
  803. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  804. *
  805. * @private
  806. * @param {Object} object The object to query.
  807. * @returns {Array} Returns the array of property names.
  808. */
  809. function baseKeysIn(object) {
  810. if (!isObject(object)) {
  811. return nativeKeysIn(object);
  812. }
  813. var isProto = isPrototype(object),
  814. result = [];
  815. for (var key in object) {
  816. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  817. result.push(key);
  818. }
  819. }
  820. return result;
  821. }
  822. /**
  823. * The base implementation of `_.merge` without support for multiple sources.
  824. *
  825. * @private
  826. * @param {Object} object The destination object.
  827. * @param {Object} source The source object.
  828. * @param {number} srcIndex The index of `source`.
  829. * @param {Function} [customizer] The function to customize merged values.
  830. * @param {Object} [stack] Tracks traversed source values and their merged
  831. * counterparts.
  832. */
  833. function baseMerge(object, source, srcIndex, customizer, stack) {
  834. if (object === source) {
  835. return;
  836. }
  837. baseFor(source, function(srcValue, key) {
  838. if (isObject(srcValue)) {
  839. stack || (stack = new Stack);
  840. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  841. }
  842. else {
  843. var newValue = customizer
  844. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  845. : undefined;
  846. if (newValue === undefined) {
  847. newValue = srcValue;
  848. }
  849. assignMergeValue(object, key, newValue);
  850. }
  851. }, keysIn);
  852. }
  853. /**
  854. * A specialized version of `baseMerge` for arrays and objects which performs
  855. * deep merges and tracks traversed objects enabling objects with circular
  856. * references to be merged.
  857. *
  858. * @private
  859. * @param {Object} object The destination object.
  860. * @param {Object} source The source object.
  861. * @param {string} key The key of the value to merge.
  862. * @param {number} srcIndex The index of `source`.
  863. * @param {Function} mergeFunc The function to merge values.
  864. * @param {Function} [customizer] The function to customize assigned values.
  865. * @param {Object} [stack] Tracks traversed source values and their merged
  866. * counterparts.
  867. */
  868. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  869. var objValue = safeGet(object, key),
  870. srcValue = safeGet(source, key),
  871. stacked = stack.get(srcValue);
  872. if (stacked) {
  873. assignMergeValue(object, key, stacked);
  874. return;
  875. }
  876. var newValue = customizer
  877. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  878. : undefined;
  879. var isCommon = newValue === undefined;
  880. if (isCommon) {
  881. var isArr = isArray(srcValue),
  882. isBuff = !isArr && isBuffer(srcValue),
  883. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  884. newValue = srcValue;
  885. if (isArr || isBuff || isTyped) {
  886. if (isArray(objValue)) {
  887. newValue = objValue;
  888. }
  889. else if (isArrayLikeObject(objValue)) {
  890. newValue = copyArray(objValue);
  891. }
  892. else if (isBuff) {
  893. isCommon = false;
  894. newValue = cloneBuffer(srcValue, true);
  895. }
  896. else if (isTyped) {
  897. isCommon = false;
  898. newValue = cloneTypedArray(srcValue, true);
  899. }
  900. else {
  901. newValue = [];
  902. }
  903. }
  904. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  905. newValue = objValue;
  906. if (isArguments(objValue)) {
  907. newValue = toPlainObject(objValue);
  908. }
  909. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  910. newValue = initCloneObject(srcValue);
  911. }
  912. }
  913. else {
  914. isCommon = false;
  915. }
  916. }
  917. if (isCommon) {
  918. // Recursively merge objects and arrays (susceptible to call stack limits).
  919. stack.set(srcValue, newValue);
  920. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  921. stack['delete'](srcValue);
  922. }
  923. assignMergeValue(object, key, newValue);
  924. }
  925. /**
  926. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  927. *
  928. * @private
  929. * @param {Function} func The function to apply a rest parameter to.
  930. * @param {number} [start=func.length-1] The start position of the rest parameter.
  931. * @returns {Function} Returns the new function.
  932. */
  933. function baseRest(func, start) {
  934. return setToString(overRest(func, start, identity), func + '');
  935. }
  936. /**
  937. * The base implementation of `setToString` without support for hot loop shorting.
  938. *
  939. * @private
  940. * @param {Function} func The function to modify.
  941. * @param {Function} string The `toString` result.
  942. * @returns {Function} Returns `func`.
  943. */
  944. var baseSetToString = !defineProperty ? identity : function(func, string) {
  945. return defineProperty(func, 'toString', {
  946. 'configurable': true,
  947. 'enumerable': false,
  948. 'value': constant(string),
  949. 'writable': true
  950. });
  951. };
  952. /**
  953. * Creates a clone of `buffer`.
  954. *
  955. * @private
  956. * @param {Buffer} buffer The buffer to clone.
  957. * @param {boolean} [isDeep] Specify a deep clone.
  958. * @returns {Buffer} Returns the cloned buffer.
  959. */
  960. function cloneBuffer(buffer, isDeep) {
  961. if (isDeep) {
  962. return buffer.slice();
  963. }
  964. var length = buffer.length,
  965. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  966. buffer.copy(result);
  967. return result;
  968. }
  969. /**
  970. * Creates a clone of `arrayBuffer`.
  971. *
  972. * @private
  973. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  974. * @returns {ArrayBuffer} Returns the cloned array buffer.
  975. */
  976. function cloneArrayBuffer(arrayBuffer) {
  977. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  978. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  979. return result;
  980. }
  981. /**
  982. * Creates a clone of `typedArray`.
  983. *
  984. * @private
  985. * @param {Object} typedArray The typed array to clone.
  986. * @param {boolean} [isDeep] Specify a deep clone.
  987. * @returns {Object} Returns the cloned typed array.
  988. */
  989. function cloneTypedArray(typedArray, isDeep) {
  990. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  991. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  992. }
  993. /**
  994. * Copies the values of `source` to `array`.
  995. *
  996. * @private
  997. * @param {Array} source The array to copy values from.
  998. * @param {Array} [array=[]] The array to copy values to.
  999. * @returns {Array} Returns `array`.
  1000. */
  1001. function copyArray(source, array) {
  1002. var index = -1,
  1003. length = source.length;
  1004. array || (array = Array(length));
  1005. while (++index < length) {
  1006. array[index] = source[index];
  1007. }
  1008. return array;
  1009. }
  1010. /**
  1011. * Copies properties of `source` to `object`.
  1012. *
  1013. * @private
  1014. * @param {Object} source The object to copy properties from.
  1015. * @param {Array} props The property identifiers to copy.
  1016. * @param {Object} [object={}] The object to copy properties to.
  1017. * @param {Function} [customizer] The function to customize copied values.
  1018. * @returns {Object} Returns `object`.
  1019. */
  1020. function copyObject(source, props, object, customizer) {
  1021. var isNew = !object;
  1022. object || (object = {});
  1023. var index = -1,
  1024. length = props.length;
  1025. while (++index < length) {
  1026. var key = props[index];
  1027. var newValue = customizer
  1028. ? customizer(object[key], source[key], key, object, source)
  1029. : undefined;
  1030. if (newValue === undefined) {
  1031. newValue = source[key];
  1032. }
  1033. if (isNew) {
  1034. baseAssignValue(object, key, newValue);
  1035. } else {
  1036. assignValue(object, key, newValue);
  1037. }
  1038. }
  1039. return object;
  1040. }
  1041. /**
  1042. * Creates a function like `_.assign`.
  1043. *
  1044. * @private
  1045. * @param {Function} assigner The function to assign values.
  1046. * @returns {Function} Returns the new assigner function.
  1047. */
  1048. function createAssigner(assigner) {
  1049. return baseRest(function(object, sources) {
  1050. var index = -1,
  1051. length = sources.length,
  1052. customizer = length > 1 ? sources[length - 1] : undefined,
  1053. guard = length > 2 ? sources[2] : undefined;
  1054. customizer = (assigner.length > 3 && typeof customizer == 'function')
  1055. ? (length--, customizer)
  1056. : undefined;
  1057. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  1058. customizer = length < 3 ? undefined : customizer;
  1059. length = 1;
  1060. }
  1061. object = Object(object);
  1062. while (++index < length) {
  1063. var source = sources[index];
  1064. if (source) {
  1065. assigner(object, source, index, customizer);
  1066. }
  1067. }
  1068. return object;
  1069. });
  1070. }
  1071. /**
  1072. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  1073. *
  1074. * @private
  1075. * @param {boolean} [fromRight] Specify iterating from right to left.
  1076. * @returns {Function} Returns the new base function.
  1077. */
  1078. function createBaseFor(fromRight) {
  1079. return function(object, iteratee, keysFunc) {
  1080. var index = -1,
  1081. iterable = Object(object),
  1082. props = keysFunc(object),
  1083. length = props.length;
  1084. while (length--) {
  1085. var key = props[fromRight ? length : ++index];
  1086. if (iteratee(iterable[key], key, iterable) === false) {
  1087. break;
  1088. }
  1089. }
  1090. return object;
  1091. };
  1092. }
  1093. /**
  1094. * Gets the data for `map`.
  1095. *
  1096. * @private
  1097. * @param {Object} map The map to query.
  1098. * @param {string} key The reference key.
  1099. * @returns {*} Returns the map data.
  1100. */
  1101. function getMapData(map, key) {
  1102. var data = map.__data__;
  1103. return isKeyable(key)
  1104. ? data[typeof key == 'string' ? 'string' : 'hash']
  1105. : data.map;
  1106. }
  1107. /**
  1108. * Gets the native function at `key` of `object`.
  1109. *
  1110. * @private
  1111. * @param {Object} object The object to query.
  1112. * @param {string} key The key of the method to get.
  1113. * @returns {*} Returns the function if it's native, else `undefined`.
  1114. */
  1115. function getNative(object, key) {
  1116. var value = getValue(object, key);
  1117. return baseIsNative(value) ? value : undefined;
  1118. }
  1119. /**
  1120. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  1121. *
  1122. * @private
  1123. * @param {*} value The value to query.
  1124. * @returns {string} Returns the raw `toStringTag`.
  1125. */
  1126. function getRawTag(value) {
  1127. var isOwn = hasOwnProperty.call(value, symToStringTag),
  1128. tag = value[symToStringTag];
  1129. try {
  1130. value[symToStringTag] = undefined;
  1131. var unmasked = true;
  1132. } catch (e) {}
  1133. var result = nativeObjectToString.call(value);
  1134. if (unmasked) {
  1135. if (isOwn) {
  1136. value[symToStringTag] = tag;
  1137. } else {
  1138. delete value[symToStringTag];
  1139. }
  1140. }
  1141. return result;
  1142. }
  1143. /**
  1144. * Initializes an object clone.
  1145. *
  1146. * @private
  1147. * @param {Object} object The object to clone.
  1148. * @returns {Object} Returns the initialized clone.
  1149. */
  1150. function initCloneObject(object) {
  1151. return (typeof object.constructor == 'function' && !isPrototype(object))
  1152. ? baseCreate(getPrototype(object))
  1153. : {};
  1154. }
  1155. /**
  1156. * Checks if `value` is a valid array-like index.
  1157. *
  1158. * @private
  1159. * @param {*} value The value to check.
  1160. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  1161. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  1162. */
  1163. function isIndex(value, length) {
  1164. var type = typeof value;
  1165. length = length == null ? MAX_SAFE_INTEGER : length;
  1166. return !!length &&
  1167. (type == 'number' ||
  1168. (type != 'symbol' && reIsUint.test(value))) &&
  1169. (value > -1 && value % 1 == 0 && value < length);
  1170. }
  1171. /**
  1172. * Checks if the given arguments are from an iteratee call.
  1173. *
  1174. * @private
  1175. * @param {*} value The potential iteratee value argument.
  1176. * @param {*} index The potential iteratee index or key argument.
  1177. * @param {*} object The potential iteratee object argument.
  1178. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  1179. * else `false`.
  1180. */
  1181. function isIterateeCall(value, index, object) {
  1182. if (!isObject(object)) {
  1183. return false;
  1184. }
  1185. var type = typeof index;
  1186. if (type == 'number'
  1187. ? (isArrayLike(object) && isIndex(index, object.length))
  1188. : (type == 'string' && index in object)
  1189. ) {
  1190. return eq(object[index], value);
  1191. }
  1192. return false;
  1193. }
  1194. /**
  1195. * Checks if `value` is suitable for use as unique object key.
  1196. *
  1197. * @private
  1198. * @param {*} value The value to check.
  1199. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  1200. */
  1201. function isKeyable(value) {
  1202. var type = typeof value;
  1203. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  1204. ? (value !== '__proto__')
  1205. : (value === null);
  1206. }
  1207. /**
  1208. * Checks if `func` has its source masked.
  1209. *
  1210. * @private
  1211. * @param {Function} func The function to check.
  1212. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  1213. */
  1214. function isMasked(func) {
  1215. return !!maskSrcKey && (maskSrcKey in func);
  1216. }
  1217. /**
  1218. * Checks if `value` is likely a prototype object.
  1219. *
  1220. * @private
  1221. * @param {*} value The value to check.
  1222. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  1223. */
  1224. function isPrototype(value) {
  1225. var Ctor = value && value.constructor,
  1226. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  1227. return value === proto;
  1228. }
  1229. /**
  1230. * This function is like
  1231. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  1232. * except that it includes inherited enumerable properties.
  1233. *
  1234. * @private
  1235. * @param {Object} object The object to query.
  1236. * @returns {Array} Returns the array of property names.
  1237. */
  1238. function nativeKeysIn(object) {
  1239. var result = [];
  1240. if (object != null) {
  1241. for (var key in Object(object)) {
  1242. result.push(key);
  1243. }
  1244. }
  1245. return result;
  1246. }
  1247. /**
  1248. * Converts `value` to a string using `Object.prototype.toString`.
  1249. *
  1250. * @private
  1251. * @param {*} value The value to convert.
  1252. * @returns {string} Returns the converted string.
  1253. */
  1254. function objectToString(value) {
  1255. return nativeObjectToString.call(value);
  1256. }
  1257. /**
  1258. * A specialized version of `baseRest` which transforms the rest array.
  1259. *
  1260. * @private
  1261. * @param {Function} func The function to apply a rest parameter to.
  1262. * @param {number} [start=func.length-1] The start position of the rest parameter.
  1263. * @param {Function} transform The rest array transform.
  1264. * @returns {Function} Returns the new function.
  1265. */
  1266. function overRest(func, start, transform) {
  1267. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  1268. return function() {
  1269. var args = arguments,
  1270. index = -1,
  1271. length = nativeMax(args.length - start, 0),
  1272. array = Array(length);
  1273. while (++index < length) {
  1274. array[index] = args[start + index];
  1275. }
  1276. index = -1;
  1277. var otherArgs = Array(start + 1);
  1278. while (++index < start) {
  1279. otherArgs[index] = args[index];
  1280. }
  1281. otherArgs[start] = transform(array);
  1282. return apply(func, this, otherArgs);
  1283. };
  1284. }
  1285. /**
  1286. * Sets the `toString` method of `func` to return `string`.
  1287. *
  1288. * @private
  1289. * @param {Function} func The function to modify.
  1290. * @param {Function} string The `toString` result.
  1291. * @returns {Function} Returns `func`.
  1292. */
  1293. var setToString = shortOut(baseSetToString);
  1294. /**
  1295. * Creates a function that'll short out and invoke `identity` instead
  1296. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  1297. * milliseconds.
  1298. *
  1299. * @private
  1300. * @param {Function} func The function to restrict.
  1301. * @returns {Function} Returns the new shortable function.
  1302. */
  1303. function shortOut(func) {
  1304. var count = 0,
  1305. lastCalled = 0;
  1306. return function() {
  1307. var stamp = nativeNow(),
  1308. remaining = HOT_SPAN - (stamp - lastCalled);
  1309. lastCalled = stamp;
  1310. if (remaining > 0) {
  1311. if (++count >= HOT_COUNT) {
  1312. return arguments[0];
  1313. }
  1314. } else {
  1315. count = 0;
  1316. }
  1317. return func.apply(undefined, arguments);
  1318. };
  1319. }
  1320. /**
  1321. * Converts `func` to its source code.
  1322. *
  1323. * @private
  1324. * @param {Function} func The function to convert.
  1325. * @returns {string} Returns the source code.
  1326. */
  1327. function toSource(func) {
  1328. if (func != null) {
  1329. try {
  1330. return funcToString.call(func);
  1331. } catch (e) {}
  1332. try {
  1333. return (func + '');
  1334. } catch (e) {}
  1335. }
  1336. return '';
  1337. }
  1338. /**
  1339. * Performs a
  1340. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  1341. * comparison between two values to determine if they are equivalent.
  1342. *
  1343. * @static
  1344. * @memberOf _
  1345. * @since 4.0.0
  1346. * @category Lang
  1347. * @param {*} value The value to compare.
  1348. * @param {*} other The other value to compare.
  1349. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1350. * @example
  1351. *
  1352. * var object = { 'a': 1 };
  1353. * var other = { 'a': 1 };
  1354. *
  1355. * _.eq(object, object);
  1356. * // => true
  1357. *
  1358. * _.eq(object, other);
  1359. * // => false
  1360. *
  1361. * _.eq('a', 'a');
  1362. * // => true
  1363. *
  1364. * _.eq('a', Object('a'));
  1365. * // => false
  1366. *
  1367. * _.eq(NaN, NaN);
  1368. * // => true
  1369. */
  1370. function eq(value, other) {
  1371. return value === other || (value !== value && other !== other);
  1372. }
  1373. /**
  1374. * Checks if `value` is likely an `arguments` object.
  1375. *
  1376. * @static
  1377. * @memberOf _
  1378. * @since 0.1.0
  1379. * @category Lang
  1380. * @param {*} value The value to check.
  1381. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  1382. * else `false`.
  1383. * @example
  1384. *
  1385. * _.isArguments(function() { return arguments; }());
  1386. * // => true
  1387. *
  1388. * _.isArguments([1, 2, 3]);
  1389. * // => false
  1390. */
  1391. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  1392. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  1393. !propertyIsEnumerable.call(value, 'callee');
  1394. };
  1395. /**
  1396. * Checks if `value` is classified as an `Array` object.
  1397. *
  1398. * @static
  1399. * @memberOf _
  1400. * @since 0.1.0
  1401. * @category Lang
  1402. * @param {*} value The value to check.
  1403. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  1404. * @example
  1405. *
  1406. * _.isArray([1, 2, 3]);
  1407. * // => true
  1408. *
  1409. * _.isArray(document.body.children);
  1410. * // => false
  1411. *
  1412. * _.isArray('abc');
  1413. * // => false
  1414. *
  1415. * _.isArray(_.noop);
  1416. * // => false
  1417. */
  1418. var isArray = Array.isArray;
  1419. /**
  1420. * Checks if `value` is array-like. A value is considered array-like if it's
  1421. * not a function and has a `value.length` that's an integer greater than or
  1422. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  1423. *
  1424. * @static
  1425. * @memberOf _
  1426. * @since 4.0.0
  1427. * @category Lang
  1428. * @param {*} value The value to check.
  1429. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  1430. * @example
  1431. *
  1432. * _.isArrayLike([1, 2, 3]);
  1433. * // => true
  1434. *
  1435. * _.isArrayLike(document.body.children);
  1436. * // => true
  1437. *
  1438. * _.isArrayLike('abc');
  1439. * // => true
  1440. *
  1441. * _.isArrayLike(_.noop);
  1442. * // => false
  1443. */
  1444. function isArrayLike(value) {
  1445. return value != null && isLength(value.length) && !isFunction(value);
  1446. }
  1447. /**
  1448. * This method is like `_.isArrayLike` except that it also checks if `value`
  1449. * is an object.
  1450. *
  1451. * @static
  1452. * @memberOf _
  1453. * @since 4.0.0
  1454. * @category Lang
  1455. * @param {*} value The value to check.
  1456. * @returns {boolean} Returns `true` if `value` is an array-like object,
  1457. * else `false`.
  1458. * @example
  1459. *
  1460. * _.isArrayLikeObject([1, 2, 3]);
  1461. * // => true
  1462. *
  1463. * _.isArrayLikeObject(document.body.children);
  1464. * // => true
  1465. *
  1466. * _.isArrayLikeObject('abc');
  1467. * // => false
  1468. *
  1469. * _.isArrayLikeObject(_.noop);
  1470. * // => false
  1471. */
  1472. function isArrayLikeObject(value) {
  1473. return isObjectLike(value) && isArrayLike(value);
  1474. }
  1475. /**
  1476. * Checks if `value` is a buffer.
  1477. *
  1478. * @static
  1479. * @memberOf _
  1480. * @since 4.3.0
  1481. * @category Lang
  1482. * @param {*} value The value to check.
  1483. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  1484. * @example
  1485. *
  1486. * _.isBuffer(new Buffer(2));
  1487. * // => true
  1488. *
  1489. * _.isBuffer(new Uint8Array(2));
  1490. * // => false
  1491. */
  1492. var isBuffer = nativeIsBuffer || stubFalse;
  1493. /**
  1494. * Checks if `value` is classified as a `Function` object.
  1495. *
  1496. * @static
  1497. * @memberOf _
  1498. * @since 0.1.0
  1499. * @category Lang
  1500. * @param {*} value The value to check.
  1501. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  1502. * @example
  1503. *
  1504. * _.isFunction(_);
  1505. * // => true
  1506. *
  1507. * _.isFunction(/abc/);
  1508. * // => false
  1509. */
  1510. function isFunction(value) {
  1511. if (!isObject(value)) {
  1512. return false;
  1513. }
  1514. // The use of `Object#toString` avoids issues with the `typeof` operator
  1515. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  1516. var tag = baseGetTag(value);
  1517. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  1518. }
  1519. /**
  1520. * Checks if `value` is a valid array-like length.
  1521. *
  1522. * **Note:** This method is loosely based on
  1523. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  1524. *
  1525. * @static
  1526. * @memberOf _
  1527. * @since 4.0.0
  1528. * @category Lang
  1529. * @param {*} value The value to check.
  1530. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  1531. * @example
  1532. *
  1533. * _.isLength(3);
  1534. * // => true
  1535. *
  1536. * _.isLength(Number.MIN_VALUE);
  1537. * // => false
  1538. *
  1539. * _.isLength(Infinity);
  1540. * // => false
  1541. *
  1542. * _.isLength('3');
  1543. * // => false
  1544. */
  1545. function isLength(value) {
  1546. return typeof value == 'number' &&
  1547. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  1548. }
  1549. /**
  1550. * Checks if `value` is the
  1551. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1552. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1553. *
  1554. * @static
  1555. * @memberOf _
  1556. * @since 0.1.0
  1557. * @category Lang
  1558. * @param {*} value The value to check.
  1559. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1560. * @example
  1561. *
  1562. * _.isObject({});
  1563. * // => true
  1564. *
  1565. * _.isObject([1, 2, 3]);
  1566. * // => true
  1567. *
  1568. * _.isObject(_.noop);
  1569. * // => true
  1570. *
  1571. * _.isObject(null);
  1572. * // => false
  1573. */
  1574. function isObject(value) {
  1575. var type = typeof value;
  1576. return value != null && (type == 'object' || type == 'function');
  1577. }
  1578. /**
  1579. * Checks if `value` is object-like. A value is object-like if it's not `null`
  1580. * and has a `typeof` result of "object".
  1581. *
  1582. * @static
  1583. * @memberOf _
  1584. * @since 4.0.0
  1585. * @category Lang
  1586. * @param {*} value The value to check.
  1587. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1588. * @example
  1589. *
  1590. * _.isObjectLike({});
  1591. * // => true
  1592. *
  1593. * _.isObjectLike([1, 2, 3]);
  1594. * // => true
  1595. *
  1596. * _.isObjectLike(_.noop);
  1597. * // => false
  1598. *
  1599. * _.isObjectLike(null);
  1600. * // => false
  1601. */
  1602. function isObjectLike(value) {
  1603. return value != null && typeof value == 'object';
  1604. }
  1605. /**
  1606. * Checks if `value` is a plain object, that is, an object created by the
  1607. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  1608. *
  1609. * @static
  1610. * @memberOf _
  1611. * @since 0.8.0
  1612. * @category Lang
  1613. * @param {*} value The value to check.
  1614. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  1615. * @example
  1616. *
  1617. * function Foo() {
  1618. * this.a = 1;
  1619. * }
  1620. *
  1621. * _.isPlainObject(new Foo);
  1622. * // => false
  1623. *
  1624. * _.isPlainObject([1, 2, 3]);
  1625. * // => false
  1626. *
  1627. * _.isPlainObject({ 'x': 0, 'y': 0 });
  1628. * // => true
  1629. *
  1630. * _.isPlainObject(Object.create(null));
  1631. * // => true
  1632. */
  1633. function isPlainObject(value) {
  1634. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  1635. return false;
  1636. }
  1637. var proto = getPrototype(value);
  1638. if (proto === null) {
  1639. return true;
  1640. }
  1641. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  1642. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  1643. funcToString.call(Ctor) == objectCtorString;
  1644. }
  1645. /**
  1646. * Checks if `value` is classified as a typed array.
  1647. *
  1648. * @static
  1649. * @memberOf _
  1650. * @since 3.0.0
  1651. * @category Lang
  1652. * @param {*} value The value to check.
  1653. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  1654. * @example
  1655. *
  1656. * _.isTypedArray(new Uint8Array);
  1657. * // => true
  1658. *
  1659. * _.isTypedArray([]);
  1660. * // => false
  1661. */
  1662. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  1663. /**
  1664. * Converts `value` to a plain object flattening inherited enumerable string
  1665. * keyed properties of `value` to own properties of the plain object.
  1666. *
  1667. * @static
  1668. * @memberOf _
  1669. * @since 3.0.0
  1670. * @category Lang
  1671. * @param {*} value The value to convert.
  1672. * @returns {Object} Returns the converted plain object.
  1673. * @example
  1674. *
  1675. * function Foo() {
  1676. * this.b = 2;
  1677. * }
  1678. *
  1679. * Foo.prototype.c = 3;
  1680. *
  1681. * _.assign({ 'a': 1 }, new Foo);
  1682. * // => { 'a': 1, 'b': 2 }
  1683. *
  1684. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  1685. * // => { 'a': 1, 'b': 2, 'c': 3 }
  1686. */
  1687. function toPlainObject(value) {
  1688. return copyObject(value, keysIn(value));
  1689. }
  1690. /**
  1691. * Creates an array of the own and inherited enumerable property names of `object`.
  1692. *
  1693. * **Note:** Non-object values are coerced to objects.
  1694. *
  1695. * @static
  1696. * @memberOf _
  1697. * @since 3.0.0
  1698. * @category Object
  1699. * @param {Object} object The object to query.
  1700. * @returns {Array} Returns the array of property names.
  1701. * @example
  1702. *
  1703. * function Foo() {
  1704. * this.a = 1;
  1705. * this.b = 2;
  1706. * }
  1707. *
  1708. * Foo.prototype.c = 3;
  1709. *
  1710. * _.keysIn(new Foo);
  1711. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  1712. */
  1713. function keysIn(object) {
  1714. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  1715. }
  1716. /**
  1717. * This method is like `_.merge` except that it accepts `customizer` which
  1718. * is invoked to produce the merged values of the destination and source
  1719. * properties. If `customizer` returns `undefined`, merging is handled by the
  1720. * method instead. The `customizer` is invoked with six arguments:
  1721. * (objValue, srcValue, key, object, source, stack).
  1722. *
  1723. * **Note:** This method mutates `object`.
  1724. *
  1725. * @static
  1726. * @memberOf _
  1727. * @since 4.0.0
  1728. * @category Object
  1729. * @param {Object} object The destination object.
  1730. * @param {...Object} sources The source objects.
  1731. * @param {Function} customizer The function to customize assigned values.
  1732. * @returns {Object} Returns `object`.
  1733. * @example
  1734. *
  1735. * function customizer(objValue, srcValue) {
  1736. * if (_.isArray(objValue)) {
  1737. * return objValue.concat(srcValue);
  1738. * }
  1739. * }
  1740. *
  1741. * var object = { 'a': [1], 'b': [2] };
  1742. * var other = { 'a': [3], 'b': [4] };
  1743. *
  1744. * _.mergeWith(object, other, customizer);
  1745. * // => { 'a': [1, 3], 'b': [2, 4] }
  1746. */
  1747. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  1748. baseMerge(object, source, srcIndex, customizer);
  1749. });
  1750. /**
  1751. * Creates a function that returns `value`.
  1752. *
  1753. * @static
  1754. * @memberOf _
  1755. * @since 2.4.0
  1756. * @category Util
  1757. * @param {*} value The value to return from the new function.
  1758. * @returns {Function} Returns the new constant function.
  1759. * @example
  1760. *
  1761. * var objects = _.times(2, _.constant({ 'a': 1 }));
  1762. *
  1763. * console.log(objects);
  1764. * // => [{ 'a': 1 }, { 'a': 1 }]
  1765. *
  1766. * console.log(objects[0] === objects[1]);
  1767. * // => true
  1768. */
  1769. function constant(value) {
  1770. return function() {
  1771. return value;
  1772. };
  1773. }
  1774. /**
  1775. * This method returns the first argument it receives.
  1776. *
  1777. * @static
  1778. * @since 0.1.0
  1779. * @memberOf _
  1780. * @category Util
  1781. * @param {*} value Any value.
  1782. * @returns {*} Returns `value`.
  1783. * @example
  1784. *
  1785. * var object = { 'a': 1 };
  1786. *
  1787. * console.log(_.identity(object) === object);
  1788. * // => true
  1789. */
  1790. function identity(value) {
  1791. return value;
  1792. }
  1793. /**
  1794. * This method returns `false`.
  1795. *
  1796. * @static
  1797. * @memberOf _
  1798. * @since 4.13.0
  1799. * @category Util
  1800. * @returns {boolean} Returns `false`.
  1801. * @example
  1802. *
  1803. * _.times(2, _.stubFalse);
  1804. * // => [false, false]
  1805. */
  1806. function stubFalse() {
  1807. return false;
  1808. }
  1809. module.exports = mergeWith;