index.js 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254
  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. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  1517. *
  1518. * @private
  1519. * @param {*} objValue The destination value.
  1520. * @param {*} srcValue The source value.
  1521. * @param {string} key The key of the property to merge.
  1522. * @param {Object} object The parent object of `objValue`.
  1523. * @param {Object} source The parent object of `srcValue`.
  1524. * @param {Object} [stack] Tracks traversed source values and their merged
  1525. * counterparts.
  1526. * @returns {*} Returns the value to assign.
  1527. */
  1528. function mergeDefaults(objValue, srcValue, key, object, source, stack) {
  1529. if (isObject(objValue) && isObject(srcValue)) {
  1530. // Recursively merge objects and arrays (susceptible to call stack limits).
  1531. stack.set(srcValue, objValue);
  1532. baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
  1533. stack['delete'](srcValue);
  1534. }
  1535. return objValue;
  1536. }
  1537. /**
  1538. * This function is like
  1539. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  1540. * except that it includes inherited enumerable properties.
  1541. *
  1542. * @private
  1543. * @param {Object} object The object to query.
  1544. * @returns {Array} Returns the array of property names.
  1545. */
  1546. function nativeKeysIn(object) {
  1547. var result = [];
  1548. if (object != null) {
  1549. for (var key in Object(object)) {
  1550. result.push(key);
  1551. }
  1552. }
  1553. return result;
  1554. }
  1555. /**
  1556. * Converts `func` to its source code.
  1557. *
  1558. * @private
  1559. * @param {Function} func The function to process.
  1560. * @returns {string} Returns the source code.
  1561. */
  1562. function toSource(func) {
  1563. if (func != null) {
  1564. try {
  1565. return funcToString.call(func);
  1566. } catch (e) {}
  1567. try {
  1568. return (func + '');
  1569. } catch (e) {}
  1570. }
  1571. return '';
  1572. }
  1573. /**
  1574. * Performs a
  1575. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  1576. * comparison between two values to determine if they are equivalent.
  1577. *
  1578. * @static
  1579. * @memberOf _
  1580. * @since 4.0.0
  1581. * @category Lang
  1582. * @param {*} value The value to compare.
  1583. * @param {*} other The other value to compare.
  1584. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1585. * @example
  1586. *
  1587. * var object = { 'a': 1 };
  1588. * var other = { 'a': 1 };
  1589. *
  1590. * _.eq(object, object);
  1591. * // => true
  1592. *
  1593. * _.eq(object, other);
  1594. * // => false
  1595. *
  1596. * _.eq('a', 'a');
  1597. * // => true
  1598. *
  1599. * _.eq('a', Object('a'));
  1600. * // => false
  1601. *
  1602. * _.eq(NaN, NaN);
  1603. * // => true
  1604. */
  1605. function eq(value, other) {
  1606. return value === other || (value !== value && other !== other);
  1607. }
  1608. /**
  1609. * Checks if `value` is likely an `arguments` object.
  1610. *
  1611. * @static
  1612. * @memberOf _
  1613. * @since 0.1.0
  1614. * @category Lang
  1615. * @param {*} value The value to check.
  1616. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  1617. * else `false`.
  1618. * @example
  1619. *
  1620. * _.isArguments(function() { return arguments; }());
  1621. * // => true
  1622. *
  1623. * _.isArguments([1, 2, 3]);
  1624. * // => false
  1625. */
  1626. function isArguments(value) {
  1627. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  1628. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  1629. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  1630. }
  1631. /**
  1632. * Checks if `value` is classified as an `Array` object.
  1633. *
  1634. * @static
  1635. * @memberOf _
  1636. * @since 0.1.0
  1637. * @category Lang
  1638. * @param {*} value The value to check.
  1639. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  1640. * @example
  1641. *
  1642. * _.isArray([1, 2, 3]);
  1643. * // => true
  1644. *
  1645. * _.isArray(document.body.children);
  1646. * // => false
  1647. *
  1648. * _.isArray('abc');
  1649. * // => false
  1650. *
  1651. * _.isArray(_.noop);
  1652. * // => false
  1653. */
  1654. var isArray = Array.isArray;
  1655. /**
  1656. * Checks if `value` is array-like. A value is considered array-like if it's
  1657. * not a function and has a `value.length` that's an integer greater than or
  1658. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  1659. *
  1660. * @static
  1661. * @memberOf _
  1662. * @since 4.0.0
  1663. * @category Lang
  1664. * @param {*} value The value to check.
  1665. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  1666. * @example
  1667. *
  1668. * _.isArrayLike([1, 2, 3]);
  1669. * // => true
  1670. *
  1671. * _.isArrayLike(document.body.children);
  1672. * // => true
  1673. *
  1674. * _.isArrayLike('abc');
  1675. * // => true
  1676. *
  1677. * _.isArrayLike(_.noop);
  1678. * // => false
  1679. */
  1680. function isArrayLike(value) {
  1681. return value != null && isLength(value.length) && !isFunction(value);
  1682. }
  1683. /**
  1684. * This method is like `_.isArrayLike` except that it also checks if `value`
  1685. * is an object.
  1686. *
  1687. * @static
  1688. * @memberOf _
  1689. * @since 4.0.0
  1690. * @category Lang
  1691. * @param {*} value The value to check.
  1692. * @returns {boolean} Returns `true` if `value` is an array-like object,
  1693. * else `false`.
  1694. * @example
  1695. *
  1696. * _.isArrayLikeObject([1, 2, 3]);
  1697. * // => true
  1698. *
  1699. * _.isArrayLikeObject(document.body.children);
  1700. * // => true
  1701. *
  1702. * _.isArrayLikeObject('abc');
  1703. * // => false
  1704. *
  1705. * _.isArrayLikeObject(_.noop);
  1706. * // => false
  1707. */
  1708. function isArrayLikeObject(value) {
  1709. return isObjectLike(value) && isArrayLike(value);
  1710. }
  1711. /**
  1712. * Checks if `value` is a buffer.
  1713. *
  1714. * @static
  1715. * @memberOf _
  1716. * @since 4.3.0
  1717. * @category Lang
  1718. * @param {*} value The value to check.
  1719. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  1720. * @example
  1721. *
  1722. * _.isBuffer(new Buffer(2));
  1723. * // => true
  1724. *
  1725. * _.isBuffer(new Uint8Array(2));
  1726. * // => false
  1727. */
  1728. var isBuffer = nativeIsBuffer || stubFalse;
  1729. /**
  1730. * Checks if `value` is classified as a `Function` object.
  1731. *
  1732. * @static
  1733. * @memberOf _
  1734. * @since 0.1.0
  1735. * @category Lang
  1736. * @param {*} value The value to check.
  1737. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  1738. * @example
  1739. *
  1740. * _.isFunction(_);
  1741. * // => true
  1742. *
  1743. * _.isFunction(/abc/);
  1744. * // => false
  1745. */
  1746. function isFunction(value) {
  1747. // The use of `Object#toString` avoids issues with the `typeof` operator
  1748. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  1749. var tag = isObject(value) ? objectToString.call(value) : '';
  1750. return tag == funcTag || tag == genTag;
  1751. }
  1752. /**
  1753. * Checks if `value` is a valid array-like length.
  1754. *
  1755. * **Note:** This method is loosely based on
  1756. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  1757. *
  1758. * @static
  1759. * @memberOf _
  1760. * @since 4.0.0
  1761. * @category Lang
  1762. * @param {*} value The value to check.
  1763. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  1764. * @example
  1765. *
  1766. * _.isLength(3);
  1767. * // => true
  1768. *
  1769. * _.isLength(Number.MIN_VALUE);
  1770. * // => false
  1771. *
  1772. * _.isLength(Infinity);
  1773. * // => false
  1774. *
  1775. * _.isLength('3');
  1776. * // => false
  1777. */
  1778. function isLength(value) {
  1779. return typeof value == 'number' &&
  1780. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  1781. }
  1782. /**
  1783. * Checks if `value` is the
  1784. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1785. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1786. *
  1787. * @static
  1788. * @memberOf _
  1789. * @since 0.1.0
  1790. * @category Lang
  1791. * @param {*} value The value to check.
  1792. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1793. * @example
  1794. *
  1795. * _.isObject({});
  1796. * // => true
  1797. *
  1798. * _.isObject([1, 2, 3]);
  1799. * // => true
  1800. *
  1801. * _.isObject(_.noop);
  1802. * // => true
  1803. *
  1804. * _.isObject(null);
  1805. * // => false
  1806. */
  1807. function isObject(value) {
  1808. var type = typeof value;
  1809. return !!value && (type == 'object' || type == 'function');
  1810. }
  1811. /**
  1812. * Checks if `value` is object-like. A value is object-like if it's not `null`
  1813. * and has a `typeof` result of "object".
  1814. *
  1815. * @static
  1816. * @memberOf _
  1817. * @since 4.0.0
  1818. * @category Lang
  1819. * @param {*} value The value to check.
  1820. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1821. * @example
  1822. *
  1823. * _.isObjectLike({});
  1824. * // => true
  1825. *
  1826. * _.isObjectLike([1, 2, 3]);
  1827. * // => true
  1828. *
  1829. * _.isObjectLike(_.noop);
  1830. * // => false
  1831. *
  1832. * _.isObjectLike(null);
  1833. * // => false
  1834. */
  1835. function isObjectLike(value) {
  1836. return !!value && typeof value == 'object';
  1837. }
  1838. /**
  1839. * Checks if `value` is a plain object, that is, an object created by the
  1840. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  1841. *
  1842. * @static
  1843. * @memberOf _
  1844. * @since 0.8.0
  1845. * @category Lang
  1846. * @param {*} value The value to check.
  1847. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  1848. * @example
  1849. *
  1850. * function Foo() {
  1851. * this.a = 1;
  1852. * }
  1853. *
  1854. * _.isPlainObject(new Foo);
  1855. * // => false
  1856. *
  1857. * _.isPlainObject([1, 2, 3]);
  1858. * // => false
  1859. *
  1860. * _.isPlainObject({ 'x': 0, 'y': 0 });
  1861. * // => true
  1862. *
  1863. * _.isPlainObject(Object.create(null));
  1864. * // => true
  1865. */
  1866. function isPlainObject(value) {
  1867. if (!isObjectLike(value) ||
  1868. objectToString.call(value) != objectTag || isHostObject(value)) {
  1869. return false;
  1870. }
  1871. var proto = getPrototype(value);
  1872. if (proto === null) {
  1873. return true;
  1874. }
  1875. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  1876. return (typeof Ctor == 'function' &&
  1877. Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
  1878. }
  1879. /**
  1880. * Checks if `value` is classified as a typed array.
  1881. *
  1882. * @static
  1883. * @memberOf _
  1884. * @since 3.0.0
  1885. * @category Lang
  1886. * @param {*} value The value to check.
  1887. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  1888. * @example
  1889. *
  1890. * _.isTypedArray(new Uint8Array);
  1891. * // => true
  1892. *
  1893. * _.isTypedArray([]);
  1894. * // => false
  1895. */
  1896. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  1897. /**
  1898. * Converts `value` to a plain object flattening inherited enumerable string
  1899. * keyed properties of `value` to own properties of the plain object.
  1900. *
  1901. * @static
  1902. * @memberOf _
  1903. * @since 3.0.0
  1904. * @category Lang
  1905. * @param {*} value The value to convert.
  1906. * @returns {Object} Returns the converted plain object.
  1907. * @example
  1908. *
  1909. * function Foo() {
  1910. * this.b = 2;
  1911. * }
  1912. *
  1913. * Foo.prototype.c = 3;
  1914. *
  1915. * _.assign({ 'a': 1 }, new Foo);
  1916. * // => { 'a': 1, 'b': 2 }
  1917. *
  1918. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  1919. * // => { 'a': 1, 'b': 2, 'c': 3 }
  1920. */
  1921. function toPlainObject(value) {
  1922. return copyObject(value, keysIn(value));
  1923. }
  1924. /**
  1925. * This method is like `_.defaults` except that it recursively assigns
  1926. * default properties.
  1927. *
  1928. * **Note:** This method mutates `object`.
  1929. *
  1930. * @static
  1931. * @memberOf _
  1932. * @since 3.10.0
  1933. * @category Object
  1934. * @param {Object} object The destination object.
  1935. * @param {...Object} [sources] The source objects.
  1936. * @returns {Object} Returns `object`.
  1937. * @see _.defaults
  1938. * @example
  1939. *
  1940. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  1941. * // => { 'a': { 'b': 2, 'c': 3 } }
  1942. */
  1943. var defaultsDeep = baseRest(function(args) {
  1944. args.push(undefined, mergeDefaults);
  1945. return apply(mergeWith, undefined, args);
  1946. });
  1947. /**
  1948. * Creates an array of the own enumerable property names of `object`.
  1949. *
  1950. * **Note:** Non-object values are coerced to objects. See the
  1951. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  1952. * for more details.
  1953. *
  1954. * @static
  1955. * @since 0.1.0
  1956. * @memberOf _
  1957. * @category Object
  1958. * @param {Object} object The object to query.
  1959. * @returns {Array} Returns the array of property names.
  1960. * @example
  1961. *
  1962. * function Foo() {
  1963. * this.a = 1;
  1964. * this.b = 2;
  1965. * }
  1966. *
  1967. * Foo.prototype.c = 3;
  1968. *
  1969. * _.keys(new Foo);
  1970. * // => ['a', 'b'] (iteration order is not guaranteed)
  1971. *
  1972. * _.keys('hi');
  1973. * // => ['0', '1']
  1974. */
  1975. function keys(object) {
  1976. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  1977. }
  1978. /**
  1979. * Creates an array of the own and inherited enumerable property names of `object`.
  1980. *
  1981. * **Note:** Non-object values are coerced to objects.
  1982. *
  1983. * @static
  1984. * @memberOf _
  1985. * @since 3.0.0
  1986. * @category Object
  1987. * @param {Object} object The object to query.
  1988. * @returns {Array} Returns the array of property names.
  1989. * @example
  1990. *
  1991. * function Foo() {
  1992. * this.a = 1;
  1993. * this.b = 2;
  1994. * }
  1995. *
  1996. * Foo.prototype.c = 3;
  1997. *
  1998. * _.keysIn(new Foo);
  1999. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  2000. */
  2001. function keysIn(object) {
  2002. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  2003. }
  2004. /**
  2005. * This method is like `_.merge` except that it accepts `customizer` which
  2006. * is invoked to produce the merged values of the destination and source
  2007. * properties. If `customizer` returns `undefined`, merging is handled by the
  2008. * method instead. The `customizer` is invoked with seven arguments:
  2009. * (objValue, srcValue, key, object, source, stack).
  2010. *
  2011. * **Note:** This method mutates `object`.
  2012. *
  2013. * @static
  2014. * @memberOf _
  2015. * @since 4.0.0
  2016. * @category Object
  2017. * @param {Object} object The destination object.
  2018. * @param {...Object} sources The source objects.
  2019. * @param {Function} customizer The function to customize assigned values.
  2020. * @returns {Object} Returns `object`.
  2021. * @example
  2022. *
  2023. * function customizer(objValue, srcValue) {
  2024. * if (_.isArray(objValue)) {
  2025. * return objValue.concat(srcValue);
  2026. * }
  2027. * }
  2028. *
  2029. * var object = { 'a': [1], 'b': [2] };
  2030. * var other = { 'a': [3], 'b': [4] };
  2031. *
  2032. * _.mergeWith(object, other, customizer);
  2033. * // => { 'a': [1, 3], 'b': [2, 4] }
  2034. */
  2035. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  2036. baseMerge(object, source, srcIndex, customizer);
  2037. });
  2038. /**
  2039. * This method returns a new empty array.
  2040. *
  2041. * @static
  2042. * @memberOf _
  2043. * @since 4.13.0
  2044. * @category Util
  2045. * @returns {Array} Returns the new empty array.
  2046. * @example
  2047. *
  2048. * var arrays = _.times(2, _.stubArray);
  2049. *
  2050. * console.log(arrays);
  2051. * // => [[], []]
  2052. *
  2053. * console.log(arrays[0] === arrays[1]);
  2054. * // => false
  2055. */
  2056. function stubArray() {
  2057. return [];
  2058. }
  2059. /**
  2060. * This method returns `false`.
  2061. *
  2062. * @static
  2063. * @memberOf _
  2064. * @since 4.13.0
  2065. * @category Util
  2066. * @returns {boolean} Returns `false`.
  2067. * @example
  2068. *
  2069. * _.times(2, _.stubFalse);
  2070. * // => [false, false]
  2071. */
  2072. function stubFalse() {
  2073. return false;
  2074. }
  2075. module.exports = defaultsDeep;