index.js 52 KB

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