index.js 52 KB

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