index.js 57 KB

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