clone.js 65 KB

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