PageRenderTime 78ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 0ms

/files/lodash/4.0.1/lodash.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1450 lines | 1406 code | 18 blank | 26 comment | 0 complexity | 9c4bec23dc8397f9d537341f20eb4995 MD5 | raw file
  1. /**
  2. * @license
  3. * lodash 4.0.1 (Custom Build) <https://lodash.com/>
  4. * Build: `lodash -o ./dist/lodash.js`
  5. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. * Available under MIT license <https://lodash.com/license>
  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.0.1';
  15. /** Used to compose bitmasks for wrapper metadata. */
  16. var BIND_FLAG = 1,
  17. BIND_KEY_FLAG = 2,
  18. CURRY_BOUND_FLAG = 4,
  19. CURRY_FLAG = 8,
  20. CURRY_RIGHT_FLAG = 16,
  21. PARTIAL_FLAG = 32,
  22. PARTIAL_RIGHT_FLAG = 64,
  23. ARY_FLAG = 128,
  24. REARG_FLAG = 256,
  25. FLIP_FLAG = 512;
  26. /** Used to compose bitmasks for comparison styles. */
  27. var UNORDERED_COMPARE_FLAG = 1,
  28. PARTIAL_COMPARE_FLAG = 2;
  29. /** Used as default options for `_.truncate`. */
  30. var DEFAULT_TRUNC_LENGTH = 30,
  31. DEFAULT_TRUNC_OMISSION = '...';
  32. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  33. var HOT_COUNT = 150,
  34. HOT_SPAN = 16;
  35. /** Used as the size to enable large array optimizations. */
  36. var LARGE_ARRAY_SIZE = 200;
  37. /** Used to indicate the type of lazy iteratees. */
  38. var LAZY_FILTER_FLAG = 1,
  39. LAZY_MAP_FLAG = 2,
  40. LAZY_WHILE_FLAG = 3;
  41. /** Used as the `TypeError` message for "Functions" methods. */
  42. var FUNC_ERROR_TEXT = 'Expected a function';
  43. /** Used to stand-in for `undefined` hash values. */
  44. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  45. /** Used as references for various `Number` constants. */
  46. var INFINITY = 1 / 0,
  47. MAX_SAFE_INTEGER = 9007199254740991,
  48. MAX_INTEGER = 1.7976931348623157e+308,
  49. NAN = 0 / 0;
  50. /** Used as references for the maximum length and index of an array. */
  51. var MAX_ARRAY_LENGTH = 4294967295,
  52. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  53. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  54. /** Used as the internal argument placeholder. */
  55. var PLACEHOLDER = '__lodash_placeholder__';
  56. /** `Object#toString` result references. */
  57. var argsTag = '[object Arguments]',
  58. arrayTag = '[object Array]',
  59. boolTag = '[object Boolean]',
  60. dateTag = '[object Date]',
  61. errorTag = '[object Error]',
  62. funcTag = '[object Function]',
  63. genTag = '[object GeneratorFunction]',
  64. mapTag = '[object Map]',
  65. numberTag = '[object Number]',
  66. objectTag = '[object Object]',
  67. regexpTag = '[object RegExp]',
  68. setTag = '[object Set]',
  69. stringTag = '[object String]',
  70. symbolTag = '[object Symbol]',
  71. weakMapTag = '[object WeakMap]';
  72. var arrayBufferTag = '[object ArrayBuffer]',
  73. float32Tag = '[object Float32Array]',
  74. float64Tag = '[object Float64Array]',
  75. int8Tag = '[object Int8Array]',
  76. int16Tag = '[object Int16Array]',
  77. int32Tag = '[object Int32Array]',
  78. uint8Tag = '[object Uint8Array]',
  79. uint8ClampedTag = '[object Uint8ClampedArray]',
  80. uint16Tag = '[object Uint16Array]',
  81. uint32Tag = '[object Uint32Array]';
  82. /** Used to match empty string literals in compiled template source. */
  83. var reEmptyStringLeading = /\b__p \+= '';/g,
  84. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  85. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  86. /** Used to match HTML entities and HTML characters. */
  87. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  88. reUnescapedHtml = /[&<>"'`]/g,
  89. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  90. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  91. /** Used to match template delimiters. */
  92. var reEscape = /<%-([\s\S]+?)%>/g,
  93. reEvaluate = /<%([\s\S]+?)%>/g,
  94. reInterpolate = /<%=([\s\S]+?)%>/g;
  95. /** Used to match property names within property paths. */
  96. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  97. reIsPlainProp = /^\w*$/,
  98. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
  99. /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */
  100. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  101. reHasRegExpChar = RegExp(reRegExpChar.source);
  102. /** Used to match leading and trailing whitespace. */
  103. var reTrim = /^\s+|\s+$/g,
  104. reTrimStart = /^\s+/,
  105. reTrimEnd = /\s+$/;
  106. /** Used to match backslashes in property paths. */
  107. var reEscapeChar = /\\(\\)?/g;
  108. /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
  109. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  110. /** Used to match `RegExp` flags from their coerced string values. */
  111. var reFlags = /\w*$/;
  112. /** Used to detect hexadecimal string values. */
  113. var reHasHexPrefix = /^0x/i;
  114. /** Used to detect bad signed hexadecimal string values. */
  115. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  116. /** Used to detect binary string values. */
  117. var reIsBinary = /^0b[01]+$/i;
  118. /** Used to detect host constructors (Safari > 5). */
  119. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  120. /** Used to detect octal string values. */
  121. var reIsOctal = /^0o[0-7]+$/i;
  122. /** Used to detect unsigned integer values. */
  123. var reIsUint = /^(?:0|[1-9]\d*)$/;
  124. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  125. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  126. /** Used to ensure capturing order of template delimiters. */
  127. var reNoMatch = /($^)/;
  128. /** Used to match unescaped characters in compiled string literals. */
  129. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  130. /** Used to compose unicode character classes. */
  131. var rsAstralRange = '\\ud800-\\udfff',
  132. rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
  133. rsComboSymbolsRange = '\\u20d0-\\u20f0',
  134. rsDingbatRange = '\\u2700-\\u27bf',
  135. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  136. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  137. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  138. rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d',
  139. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  140. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  141. rsVarRange = '\\ufe0e\\ufe0f',
  142. rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange;
  143. /** Used to compose unicode capture groups. */
  144. var rsAstral = '[' + rsAstralRange + ']',
  145. rsBreak = '[' + rsBreakRange + ']',
  146. rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
  147. rsDigits = '\\d+',
  148. rsDingbat = '[' + rsDingbatRange + ']',
  149. rsLower = '[' + rsLowerRange + ']',
  150. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  151. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  152. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  153. rsNonAstral = '[^' + rsAstralRange + ']',
  154. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  155. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  156. rsUpper = '[' + rsUpperRange + ']',
  157. rsZWJ = '\\u200d';
  158. /** Used to compose unicode regexes. */
  159. var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
  160. rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
  161. reOptMod = rsModifier + '?',
  162. rsOptVar = '[' + rsVarRange + ']?',
  163. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  164. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  165. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  166. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  167. /**
  168. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  169. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  170. */
  171. var reComboMark = RegExp(rsCombo, 'g');
  172. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  173. var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  174. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  175. var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
  176. /** Used to match non-compound words composed of alphanumeric characters. */
  177. var reBasicWord = /[a-zA-Z0-9]+/g;
  178. /** Used to match complex or compound words. */
  179. var reComplexWord = RegExp([
  180. rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  181. rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
  182. rsUpper + '?' + rsLowerMisc + '+',
  183. rsUpper + '+',
  184. rsDigits,
  185. rsEmoji
  186. ].join('|'), 'g');
  187. /** Used to detect strings that need a more robust regexp to match words. */
  188. var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  189. /** Used to assign default `context` object properties. */
  190. var contextProps = [
  191. 'Array', 'Date', 'Error', 'Float32Array', 'Float64Array', 'Function',
  192. 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  193. 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  194. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_',
  195. 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  196. ];
  197. /** Used to make template sourceURLs easier to identify. */
  198. var templateCounter = -1;
  199. /** Used to identify `toStringTag` values of typed arrays. */
  200. var typedArrayTags = {};
  201. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  202. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  203. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  204. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  205. typedArrayTags[uint32Tag] = true;
  206. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  207. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  208. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  209. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  210. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  211. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  212. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  213. /** Used to identify `toStringTag` values supported by `_.clone`. */
  214. var cloneableTags = {};
  215. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  216. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  217. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  218. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  219. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  220. cloneableTags[mapTag] = cloneableTags[numberTag] =
  221. cloneableTags[objectTag] = cloneableTags[regexpTag] =
  222. cloneableTags[setTag] = cloneableTags[stringTag] =
  223. cloneableTags[symbolTag] = cloneableTags[uint8Tag] =
  224. cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] =
  225. cloneableTags[uint32Tag] = true;
  226. cloneableTags[errorTag] = cloneableTags[funcTag] =
  227. cloneableTags[weakMapTag] = false;
  228. /** Used to map latin-1 supplementary letters to basic latin letters. */
  229. var deburredLetters = {
  230. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  231. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  232. '\xc7': 'C', '\xe7': 'c',
  233. '\xd0': 'D', '\xf0': 'd',
  234. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  235. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  236. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  237. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  238. '\xd1': 'N', '\xf1': 'n',
  239. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  240. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  241. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  242. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  243. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  244. '\xc6': 'Ae', '\xe6': 'ae',
  245. '\xde': 'Th', '\xfe': 'th',
  246. '\xdf': 'ss'
  247. };
  248. /** Used to map characters to HTML entities. */
  249. var htmlEscapes = {
  250. '&': '&amp;',
  251. '<': '&lt;',
  252. '>': '&gt;',
  253. '"': '&quot;',
  254. "'": '&#39;',
  255. '`': '&#96;'
  256. };
  257. /** Used to map HTML entities to characters. */
  258. var htmlUnescapes = {
  259. '&amp;': '&',
  260. '&lt;': '<',
  261. '&gt;': '>',
  262. '&quot;': '"',
  263. '&#39;': "'",
  264. '&#96;': '`'
  265. };
  266. /** Used to determine if values are of the language type `Object`. */
  267. var objectTypes = {
  268. 'function': true,
  269. 'object': true
  270. };
  271. /** Used to escape characters for inclusion in compiled string literals. */
  272. var stringEscapes = {
  273. '\\': '\\',
  274. "'": "'",
  275. '\n': 'n',
  276. '\r': 'r',
  277. '\u2028': 'u2028',
  278. '\u2029': 'u2029'
  279. };
  280. /** Built-in method references without a dependency on `root`. */
  281. var freeParseFloat = parseFloat,
  282. freeParseInt = parseInt;
  283. /** Detect free variable `exports`. */
  284. var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
  285. /** Detect free variable `module`. */
  286. var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
  287. /** Detect free variable `global` from Node.js. */
  288. var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
  289. /** Detect free variable `self`. */
  290. var freeSelf = checkGlobal(objectTypes[typeof self] && self);
  291. /** Detect free variable `window`. */
  292. var freeWindow = checkGlobal(objectTypes[typeof window] && window);
  293. /** Detect the popular CommonJS extension `module.exports`. */
  294. var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null;
  295. /** Detect `this` as the global object. */
  296. var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
  297. /**
  298. * Used as a reference to the global object.
  299. *
  300. * The `this` value is used if it's the global object to avoid Greasemonkey's
  301. * restricted `window` object, otherwise the `window` object is used.
  302. */
  303. var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
  304. /*--------------------------------------------------------------------------*/
  305. /**
  306. * Adds the key-value `pair` to `map`.
  307. *
  308. * @private
  309. * @param {Object} map The map to modify.
  310. * @param {Array} pair The key-value pair to add.
  311. * @returns {Object} Returns `map`.
  312. */
  313. function addMapEntry(map, pair) {
  314. map.set(pair[0], pair[1]);
  315. return map;
  316. }
  317. /**
  318. * Adds `value` to `set`.
  319. *
  320. * @private
  321. * @param {Object} set The set to modify.
  322. * @param {*} value The value to add.
  323. * @returns {Object} Returns `set`.
  324. */
  325. function addSetEntry(set, value) {
  326. set.add(value);
  327. return set;
  328. }
  329. /**
  330. * A faster alternative to `Function#apply`, this function invokes `func`
  331. * with the `this` binding of `thisArg` and the arguments of `args`.
  332. *
  333. * @private
  334. * @param {Function} func The function to invoke.
  335. * @param {*} thisArg The `this` binding of `func`.
  336. * @param {...*} [args] The arguments to invoke `func` with.
  337. * @returns {*} Returns the result of `func`.
  338. */
  339. function apply(func, thisArg, args) {
  340. var length = args ? args.length : 0;
  341. switch (length) {
  342. case 0: return func.call(thisArg);
  343. case 1: return func.call(thisArg, args[0]);
  344. case 2: return func.call(thisArg, args[0], args[1]);
  345. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  346. }
  347. return func.apply(thisArg, args);
  348. }
  349. /**
  350. * Creates a new array concatenating `array` with `other`.
  351. *
  352. * @private
  353. * @param {Array} array The first array to concatenate.
  354. * @param {Array} other The second array to concatenate.
  355. * @returns {Array} Returns the new concatenated array.
  356. */
  357. function arrayConcat(array, other) {
  358. var index = -1,
  359. length = array.length,
  360. othIndex = -1,
  361. othLength = other.length,
  362. result = Array(length + othLength);
  363. while (++index < length) {
  364. result[index] = array[index];
  365. }
  366. while (++othIndex < othLength) {
  367. result[index++] = other[othIndex];
  368. }
  369. return result;
  370. }
  371. /**
  372. * A specialized version of `_.forEach` for arrays without support for
  373. * iteratee shorthands.
  374. *
  375. * @private
  376. * @param {Array} array The array to iterate over.
  377. * @param {Function} iteratee The function invoked per iteration.
  378. * @returns {Array} Returns `array`.
  379. */
  380. function arrayEach(array, iteratee) {
  381. var index = -1,
  382. length = array.length;
  383. while (++index < length) {
  384. if (iteratee(array[index], index, array) === false) {
  385. break;
  386. }
  387. }
  388. return array;
  389. }
  390. /**
  391. * A specialized version of `_.forEachRight` for arrays without support for
  392. * iteratee shorthands.
  393. *
  394. * @private
  395. * @param {Array} array The array to iterate over.
  396. * @param {Function} iteratee The function invoked per iteration.
  397. * @returns {Array} Returns `array`.
  398. */
  399. function arrayEachRight(array, iteratee) {
  400. var length = array.length;
  401. while (length--) {
  402. if (iteratee(array[length], length, array) === false) {
  403. break;
  404. }
  405. }
  406. return array;
  407. }
  408. /**
  409. * A specialized version of `_.every` for arrays without support for
  410. * iteratee shorthands.
  411. *
  412. * @private
  413. * @param {Array} array The array to iterate over.
  414. * @param {Function} predicate The function invoked per iteration.
  415. * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
  416. */
  417. function arrayEvery(array, predicate) {
  418. var index = -1,
  419. length = array.length;
  420. while (++index < length) {
  421. if (!predicate(array[index], index, array)) {
  422. return false;
  423. }
  424. }
  425. return true;
  426. }
  427. /**
  428. * A specialized version of `_.filter` for arrays without support for
  429. * iteratee shorthands.
  430. *
  431. * @private
  432. * @param {Array} array The array to iterate over.
  433. * @param {Function} predicate The function invoked per iteration.
  434. * @returns {Array} Returns the new filtered array.
  435. */
  436. function arrayFilter(array, predicate) {
  437. var index = -1,
  438. length = array.length,
  439. resIndex = -1,
  440. result = [];
  441. while (++index < length) {
  442. var value = array[index];
  443. if (predicate(value, index, array)) {
  444. result[++resIndex] = value;
  445. }
  446. }
  447. return result;
  448. }
  449. /**
  450. * A specialized version of `_.includes` for arrays without support for
  451. * specifying an index to search from.
  452. *
  453. * @private
  454. * @param {Array} array The array to search.
  455. * @param {*} target The value to search for.
  456. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  457. */
  458. function arrayIncludes(array, value) {
  459. return !!array.length && baseIndexOf(array, value, 0) > -1;
  460. }
  461. /**
  462. * A specialized version of `_.includesWith` for arrays without support for
  463. * specifying an index to search from.
  464. *
  465. * @private
  466. * @param {Array} array The array to search.
  467. * @param {*} target The value to search for.
  468. * @param {Function} comparator The comparator invoked per element.
  469. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  470. */
  471. function arrayIncludesWith(array, value, comparator) {
  472. var index = -1,
  473. length = array.length;
  474. while (++index < length) {
  475. if (comparator(value, array[index])) {
  476. return true;
  477. }
  478. }
  479. return false;
  480. }
  481. /**
  482. * A specialized version of `_.map` for arrays without support for iteratee
  483. * shorthands.
  484. *
  485. * @private
  486. * @param {Array} array The array to iterate over.
  487. * @param {Function} iteratee The function invoked per iteration.
  488. * @returns {Array} Returns the new mapped array.
  489. */
  490. function arrayMap(array, iteratee) {
  491. var index = -1,
  492. length = array.length,
  493. result = Array(length);
  494. while (++index < length) {
  495. result[index] = iteratee(array[index], index, array);
  496. }
  497. return result;
  498. }
  499. /**
  500. * Appends the elements of `values` to `array`.
  501. *
  502. * @private
  503. * @param {Array} array The array to modify.
  504. * @param {Array} values The values to append.
  505. * @returns {Array} Returns `array`.
  506. */
  507. function arrayPush(array, values) {
  508. var index = -1,
  509. length = values.length,
  510. offset = array.length;
  511. while (++index < length) {
  512. array[offset + index] = values[index];
  513. }
  514. return array;
  515. }
  516. /**
  517. * A specialized version of `_.reduce` for arrays without support for
  518. * iteratee shorthands.
  519. *
  520. * @private
  521. * @param {Array} array The array to iterate over.
  522. * @param {Function} iteratee The function invoked per iteration.
  523. * @param {*} [accumulator] The initial value.
  524. * @param {boolean} [initAccum] Specify using the first element of `array` as the initial value.
  525. * @returns {*} Returns the accumulated value.
  526. */
  527. function arrayReduce(array, iteratee, accumulator, initAccum) {
  528. var index = -1,
  529. length = array.length;
  530. if (initAccum && length) {
  531. accumulator = array[++index];
  532. }
  533. while (++index < length) {
  534. accumulator = iteratee(accumulator, array[index], index, array);
  535. }
  536. return accumulator;
  537. }
  538. /**
  539. * A specialized version of `_.reduceRight` for arrays without support for
  540. * iteratee shorthands.
  541. *
  542. * @private
  543. * @param {Array} array The array to iterate over.
  544. * @param {Function} iteratee The function invoked per iteration.
  545. * @param {*} [accumulator] The initial value.
  546. * @param {boolean} [initAccum] Specify using the last element of `array` as the initial value.
  547. * @returns {*} Returns the accumulated value.
  548. */
  549. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  550. var length = array.length;
  551. if (initAccum && length) {
  552. accumulator = array[--length];
  553. }
  554. while (length--) {
  555. accumulator = iteratee(accumulator, array[length], length, array);
  556. }
  557. return accumulator;
  558. }
  559. /**
  560. * A specialized version of `_.some` for arrays without support for iteratee
  561. * shorthands.
  562. *
  563. * @private
  564. * @param {Array} array The array to iterate over.
  565. * @param {Function} predicate The function invoked per iteration.
  566. * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
  567. */
  568. function arraySome(array, predicate) {
  569. var index = -1,
  570. length = array.length;
  571. while (++index < length) {
  572. if (predicate(array[index], index, array)) {
  573. return true;
  574. }
  575. }
  576. return false;
  577. }
  578. /**
  579. * The base implementation of methods like `_.max` and `_.min` which accepts a
  580. * `comparator` to determine the extremum value.
  581. *
  582. * @private
  583. * @param {Array} array The array to iterate over.
  584. * @param {Function} iteratee The iteratee invoked per iteration.
  585. * @param {Function} comparator The comparator used to compare values.
  586. * @returns {*} Returns the extremum value.
  587. */
  588. function baseExtremum(array, iteratee, comparator) {
  589. var index = -1,
  590. length = array.length;
  591. while (++index < length) {
  592. var value = array[index],
  593. current = iteratee(value);
  594. if (current != null && (computed === undefined
  595. ? current === current
  596. : comparator(current, computed)
  597. )) {
  598. var computed = current,
  599. result = value;
  600. }
  601. }
  602. return result;
  603. }
  604. /**
  605. * The base implementation of methods like `_.find` and `_.findKey`, without
  606. * support for iteratee shorthands, which iterates over `collection` using
  607. * `eachFunc`.
  608. *
  609. * @private
  610. * @param {Array|Object} collection The collection to search.
  611. * @param {Function} predicate The function invoked per iteration.
  612. * @param {Function} eachFunc The function to iterate over `collection`.
  613. * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
  614. * @returns {*} Returns the found element or its key, else `undefined`.
  615. */
  616. function baseFind(collection, predicate, eachFunc, retKey) {
  617. var result;
  618. eachFunc(collection, function(value, key, collection) {
  619. if (predicate(value, key, collection)) {
  620. result = retKey ? key : value;
  621. return false;
  622. }
  623. });
  624. return result;
  625. }
  626. /**
  627. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  628. * support for iteratee shorthands.
  629. *
  630. * @private
  631. * @param {Array} array The array to search.
  632. * @param {Function} predicate The function invoked per iteration.
  633. * @param {boolean} [fromRight] Specify iterating from right to left.
  634. * @returns {number} Returns the index of the matched value, else `-1`.
  635. */
  636. function baseFindIndex(array, predicate, fromRight) {
  637. var length = array.length,
  638. index = fromRight ? length : -1;
  639. while ((fromRight ? index-- : ++index < length)) {
  640. if (predicate(array[index], index, array)) {
  641. return index;
  642. }
  643. }
  644. return -1;
  645. }
  646. /**
  647. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  648. *
  649. * @private
  650. * @param {Array} array The array to search.
  651. * @param {*} value The value to search for.
  652. * @param {number} fromIndex The index to search from.
  653. * @returns {number} Returns the index of the matched value, else `-1`.
  654. */
  655. function baseIndexOf(array, value, fromIndex) {
  656. if (value !== value) {
  657. return indexOfNaN(array, fromIndex);
  658. }
  659. var index = fromIndex - 1,
  660. length = array.length;
  661. while (++index < length) {
  662. if (array[index] === value) {
  663. return index;
  664. }
  665. }
  666. return -1;
  667. }
  668. /**
  669. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  670. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  671. *
  672. * @private
  673. * @param {Array|Object} collection The collection to iterate over.
  674. * @param {Function} iteratee The function invoked per iteration.
  675. * @param {*} accumulator The initial value.
  676. * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value.
  677. * @param {Function} eachFunc The function to iterate over `collection`.
  678. * @returns {*} Returns the accumulated value.
  679. */
  680. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  681. eachFunc(collection, function(value, index, collection) {
  682. accumulator = initAccum
  683. ? (initAccum = false, value)
  684. : iteratee(accumulator, value, index, collection);
  685. });
  686. return accumulator;
  687. }
  688. /**
  689. * The base implementation of `_.sortBy` which uses `comparer` to define
  690. * the sort order of `array` and replaces criteria objects with their
  691. * corresponding values.
  692. *
  693. * @private
  694. * @param {Array} array The array to sort.
  695. * @param {Function} comparer The function to define sort order.
  696. * @returns {Array} Returns `array`.
  697. */
  698. function baseSortBy(array, comparer) {
  699. var length = array.length;
  700. array.sort(comparer);
  701. while (length--) {
  702. array[length] = array[length].value;
  703. }
  704. return array;
  705. }
  706. /**
  707. * The base implementation of `_.sum` without support for iteratee shorthands.
  708. *
  709. * @private
  710. * @param {Array} array The array to iterate over.
  711. * @param {Function} iteratee The function invoked per iteration.
  712. * @returns {number} Returns the sum.
  713. */
  714. function baseSum(array, iteratee) {
  715. var result,
  716. index = -1,
  717. length = array.length;
  718. while (++index < length) {
  719. var current = iteratee(array[index]);
  720. if (current !== undefined) {
  721. result = result === undefined ? current : (result + current);
  722. }
  723. }
  724. return result;
  725. }
  726. /**
  727. * The base implementation of `_.times` without support for iteratee shorthands
  728. * or max array length checks.
  729. *
  730. * @private
  731. * @param {number} n The number of times to invoke `iteratee`.
  732. * @param {Function} iteratee The function invoked per iteration.
  733. * @returns {Array} Returns the array of results.
  734. */
  735. function baseTimes(n, iteratee) {
  736. var index = -1,
  737. result = Array(n);
  738. while (++index < n) {
  739. result[index] = iteratee(index);
  740. }
  741. return result;
  742. }
  743. /**
  744. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  745. * of key-value pairs for `object` corresponding to the property names of `props`.
  746. *
  747. * @private
  748. * @param {Object} object The object to query.
  749. * @param {Array} props The property names to get values for.
  750. * @returns {Object} Returns the new array of key-value pairs.
  751. */
  752. function baseToPairs(object, props) {
  753. return arrayMap(props, function(key) {
  754. return [key, object[key]];
  755. });
  756. }
  757. /**
  758. * The base implementation of `_.unary` without support for storing wrapper metadata.
  759. *
  760. * @private
  761. * @param {Function} func The function to cap arguments for.
  762. * @returns {Function} Returns the new function.
  763. */
  764. function baseUnary(func) {
  765. return function(value) {
  766. return func(value);
  767. };
  768. }
  769. /**
  770. * The base implementation of `_.values` and `_.valuesIn` which creates an
  771. * array of `object` property values corresponding to the property names
  772. * of `props`.
  773. *
  774. * @private
  775. * @param {Object} object The object to query.
  776. * @param {Array} props The property names to get values for.
  777. * @returns {Object} Returns the array of property values.
  778. */
  779. function baseValues(object, props) {
  780. return arrayMap(props, function(key) {
  781. return object[key];
  782. });
  783. }
  784. /**
  785. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  786. * that is not found in the character symbols.
  787. *
  788. * @private
  789. * @param {Array} strSymbols The string symbols to inspect.
  790. * @param {Array} chrSymbols The character symbols to find.
  791. * @returns {number} Returns the index of the first unmatched string symbol.
  792. */
  793. function charsStartIndex(strSymbols, chrSymbols) {
  794. var index = -1,
  795. length = strSymbols.length;
  796. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  797. return index;
  798. }
  799. /**
  800. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  801. * that is not found in the character symbols.
  802. *
  803. * @private
  804. * @param {Array} strSymbols The string symbols to inspect.
  805. * @param {Array} chrSymbols The character symbols to find.
  806. * @returns {number} Returns the index of the last unmatched string symbol.
  807. */
  808. function charsEndIndex(strSymbols, chrSymbols) {
  809. var index = strSymbols.length;
  810. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  811. return index;
  812. }
  813. /**
  814. * Checks if `value` is a global object.
  815. *
  816. * @private
  817. * @param {*} value The value to check.
  818. * @returns {null|Object} Returns `value` if it's a global object, else `null`.
  819. */
  820. function checkGlobal(value) {
  821. return (value && value.Object === Object) ? value : null;
  822. }
  823. /**
  824. * Compares values to sort them in ascending order.
  825. *
  826. * @private
  827. * @param {*} value The value to compare.
  828. * @param {*} other The other value to compare.
  829. * @returns {number} Returns the sort order indicator for `value`.
  830. */
  831. function compareAscending(value, other) {
  832. if (value !== other) {
  833. var valIsNull = value === null,
  834. valIsUndef = value === undefined,
  835. valIsReflexive = value === value;
  836. var othIsNull = other === null,
  837. othIsUndef = other === undefined,
  838. othIsReflexive = other === other;
  839. if ((value > other && !othIsNull) || !valIsReflexive ||
  840. (valIsNull && !othIsUndef && othIsReflexive) ||
  841. (valIsUndef && othIsReflexive)) {
  842. return 1;
  843. }
  844. if ((value < other && !valIsNull) || !othIsReflexive ||
  845. (othIsNull && !valIsUndef && valIsReflexive) ||
  846. (othIsUndef && valIsReflexive)) {
  847. return -1;
  848. }
  849. }
  850. return 0;
  851. }
  852. /**
  853. * Used by `_.orderBy` to compare multiple properties of a value to another
  854. * and stable sort them.
  855. *
  856. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  857. * specify an order of "desc" for descending or "asc" for ascending sort order
  858. * of corresponding values.
  859. *
  860. * @private
  861. * @param {Object} object The object to compare.
  862. * @param {Object} other The other object to compare.
  863. * @param {boolean[]|string[]} orders The order to sort by for each property.
  864. * @returns {number} Returns the sort order indicator for `object`.
  865. */
  866. function compareMultiple(object, other, orders) {
  867. var index = -1,
  868. objCriteria = object.criteria,
  869. othCriteria = other.criteria,
  870. length = objCriteria.length,
  871. ordersLength = orders.length;
  872. while (++index < length) {
  873. var result = compareAscending(objCriteria[index], othCriteria[index]);
  874. if (result) {
  875. if (index >= ordersLength) {
  876. return result;
  877. }
  878. var order = orders[index];
  879. return result * (order == 'desc' ? -1 : 1);
  880. }
  881. }
  882. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  883. // that causes it, under certain circumstances, to provide the same value for
  884. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  885. // for more details.
  886. //
  887. // This also ensures a stable sort in V8 and other engines.
  888. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  889. return object.index - other.index;
  890. }
  891. /**
  892. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  893. *
  894. * @private
  895. * @param {string} letter The matched letter to deburr.
  896. * @returns {string} Returns the deburred letter.
  897. */
  898. function deburrLetter(letter) {
  899. return deburredLetters[letter];
  900. }
  901. /**
  902. * Used by `_.escape` to convert characters to HTML entities.
  903. *
  904. * @private
  905. * @param {string} chr The matched character to escape.
  906. * @returns {string} Returns the escaped character.
  907. */
  908. function escapeHtmlChar(chr) {
  909. return htmlEscapes[chr];
  910. }
  911. /**
  912. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  913. *
  914. * @private
  915. * @param {string} chr The matched character to escape.
  916. * @returns {string} Returns the escaped character.
  917. */
  918. function escapeStringChar(chr) {
  919. return '\\' + stringEscapes[chr];
  920. }
  921. /**
  922. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  923. *
  924. * @private
  925. * @param {Array} array The array to search.
  926. * @param {number} fromIndex The index to search from.
  927. * @param {boolean} [fromRight] Specify iterating from right to left.
  928. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  929. */
  930. function indexOfNaN(array, fromIndex, fromRight) {
  931. var length = array.length,
  932. index = fromIndex + (fromRight ? 0 : -1);
  933. while ((fromRight ? index-- : ++index < length)) {
  934. var other = array[index];
  935. if (other !== other) {
  936. return index;
  937. }
  938. }
  939. return -1;
  940. }
  941. /**
  942. * Checks if `value` is a host object in IE < 9.
  943. *
  944. * @private
  945. * @param {*} value The value to check.
  946. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  947. */
  948. function isHostObject(value) {
  949. // Many host objects are `Object` objects that can coerce to strings
  950. // despite having improperly defined `toString` methods.
  951. var result = false;
  952. if (value != null && typeof value.toString != 'function') {
  953. try {
  954. result = !!(value + '');
  955. } catch (e) {}
  956. }
  957. return result;
  958. }
  959. /**
  960. * Checks if `value` is a valid array-like index.
  961. *
  962. * @private
  963. * @param {*} value The value to check.
  964. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  965. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  966. */
  967. function isIndex(value, length) {
  968. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  969. length = length == null ? MAX_SAFE_INTEGER : length;
  970. return value > -1 && value % 1 == 0 && value < length;
  971. }
  972. /**
  973. * Converts `iterator` to an array.
  974. *
  975. * @private
  976. * @param {Object} iterator The iterator to convert.
  977. * @returns {Array} Returns the converted array.
  978. */
  979. function iteratorToArray(iterator) {
  980. var data,
  981. result = [];
  982. while (!(data = iterator.next()).done) {
  983. result.push(data.value);
  984. }
  985. return result;
  986. }
  987. /**
  988. * Converts `map` to an array.
  989. *
  990. * @private
  991. * @param {Object} map The map to convert.
  992. * @returns {Array} Returns the converted array.
  993. */
  994. function mapToArray(map) {
  995. var index = -1,
  996. result = Array(map.size);
  997. map.forEach(function(value, key) {
  998. result[++index] = [key, value];
  999. });
  1000. return result;
  1001. }
  1002. /**
  1003. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1004. * and returns an array of their indexes.
  1005. *
  1006. * @private
  1007. * @param {Array} array The array to modify.
  1008. * @param {*} placeholder The placeholder to replace.
  1009. * @returns {Array} Returns the new array of placeholder indexes.
  1010. */
  1011. function replaceHolders(array, placeholder) {
  1012. var index = -1,
  1013. length = array.length,
  1014. resIndex = -1,
  1015. result = [];
  1016. while (++index < length) {
  1017. if (array[index] === placeholder) {
  1018. array[index] = PLACEHOLDER;
  1019. result[++resIndex] = index;
  1020. }
  1021. }
  1022. return result;
  1023. }
  1024. /**
  1025. * Converts `set` to an array.
  1026. *
  1027. * @private
  1028. * @param {Object} set The set to convert.
  1029. * @returns {Array} Returns the converted array.
  1030. */
  1031. function setToArray(set) {
  1032. var index = -1,
  1033. result = Array(set.size);
  1034. set.forEach(function(value) {
  1035. result[++index] = value;
  1036. });
  1037. return result;
  1038. }
  1039. /**
  1040. * Gets the number of symbols in `string`.
  1041. *
  1042. * @private
  1043. * @param {string} string The string to inspect.
  1044. * @returns {number} Returns the string size.
  1045. */
  1046. function stringSize(string) {
  1047. if (!(string && reHasComplexSymbol.test(string))) {
  1048. return string.length;
  1049. }
  1050. var result = reComplexSymbol.lastIndex = 0;
  1051. while (reComplexSymbol.test(string)) {
  1052. result++;
  1053. }
  1054. return result;
  1055. }
  1056. /**
  1057. * Converts `string` to an array.
  1058. *
  1059. * @private
  1060. * @param {string} string The string to convert.
  1061. * @returns {Array} Returns the converted array.
  1062. */
  1063. function stringToArray(string) {
  1064. return string.match(reComplexSymbol);
  1065. }
  1066. /**
  1067. * Used by `_.unescape` to convert HTML entities to characters.
  1068. *
  1069. * @private
  1070. * @param {string} chr The matched character to unescape.
  1071. * @returns {string} Returns the unescaped character.
  1072. */
  1073. function unescapeHtmlChar(chr) {
  1074. return htmlUnescapes[chr];
  1075. }
  1076. /*--------------------------------------------------------------------------*/
  1077. /**
  1078. * Create a new pristine `lodash` function using the `context` object.
  1079. *
  1080. * @static
  1081. * @memberOf _
  1082. * @category Util
  1083. * @param {Object} [context=root] The context object.
  1084. * @returns {Function} Returns a new `lodash` function.
  1085. * @example
  1086. *
  1087. * _.mixin({ 'foo': _.constant('foo') });
  1088. *
  1089. * var lodash = _.runInContext();
  1090. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1091. *
  1092. * _.isFunction(_.foo);
  1093. * // => true
  1094. * _.isFunction(_.bar);
  1095. * // => false
  1096. *
  1097. * lodash.isFunction(lodash.foo);
  1098. * // => false
  1099. * lodash.isFunction(lodash.bar);
  1100. * // => true
  1101. *
  1102. * // using `context` to mock `Date#getTime` use in `_.now`
  1103. * var mock = _.runInContext({
  1104. * 'Date': function() {
  1105. * return { 'getTime': getTimeMock };
  1106. * }
  1107. * });
  1108. *
  1109. * // or creating a suped-up `defer` in Node.js
  1110. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1111. */
  1112. function runInContext(context) {
  1113. context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
  1114. /** Built-in constructor references. */
  1115. var Date = context.Date,
  1116. Error = context.Error,
  1117. Math = context.Math,
  1118. RegExp = context.RegExp,
  1119. TypeError = context.TypeError;
  1120. /** Used for built-in method references. */
  1121. var arrayProto = context.Array.prototype,
  1122. objectProto = context.Object.prototype;
  1123. /** Used to resolve the decompiled source of functions. */
  1124. var funcToString = context.Function.prototype.toString;
  1125. /** Used to check objects for own properties. */
  1126. var hasOwnProperty = objectProto.hasOwnProperty;
  1127. /** Used to generate unique IDs. */
  1128. var idCounter = 0;
  1129. /** Used to infer the `Object` constructor. */
  1130. var objectCtorString = funcToString.call(Object);
  1131. /**
  1132. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  1133. * of values.
  1134. */
  1135. var objectToString = objectProto.toString;
  1136. /** Used to restore the original `_` reference in `_.noConflict`. */
  1137. var oldDash = root._;
  1138. /** Used to detect if a method is native. */
  1139. var reIsNative = RegExp('^' +
  1140. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1141. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1142. );
  1143. /** Built-in value references. */
  1144. var Reflect = context.Reflect,
  1145. Symbol = context.Symbol,
  1146. Uint8Array = context.Uint8Array,
  1147. clearTimeout = context.clearTimeout,
  1148. enumerate = Reflect ? Reflect.enumerate : undefined,
  1149. getPrototypeOf = Object.getPrototypeOf,
  1150. getOwnPropertySymbols = Object.getOwnPropertySymbols,
  1151. iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
  1152. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1153. setTimeout = context.setTimeout,
  1154. splice = arrayProto.splice;
  1155. /* Built-in method references for those with the same name as other `lodash` methods. */
  1156. var nativeCeil = Math.ceil,
  1157. nativeFloor = Math.floor,
  1158. nativeIsFinite = context.isFinite,
  1159. nativeJoin = arrayProto.join,
  1160. nativeKeys = Object.keys,
  1161. nativeMax = Math.max,
  1162. nativeMin = Math.min,
  1163. nativeParseInt = context.parseInt,
  1164. nativeRandom = Math.random,
  1165. nativeReverse = arrayProto.reverse;
  1166. /* Built-in method references that are verified to be native. */
  1167. var Map = getNative(context, 'Map'),
  1168. Set = getNative(context, 'Set'),
  1169. WeakMap = getNative(context, 'WeakMap'),
  1170. nativeCreate = getNative(Object, 'create');
  1171. /** Used to store function metadata. */
  1172. var metaMap = WeakMap && new WeakMap;
  1173. /** Used to detect maps and sets. */
  1174. var mapCtorString = Map ? funcToString.call(Map) : '',
  1175. setCtorString = Set ? funcToString.call(Set) : '';
  1176. /** Used to convert symbols to primitives and strings. */
  1177. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1178. symbolValueOf = Symbol ? symbolProto.valueOf : undefined,
  1179. symbolToString = Symbol ? symbolProto.toString : undefined;
  1180. /** Used to lookup unminified function names. */
  1181. var realNames = {};
  1182. /*------------------------------------------------------------------------*/
  1183. /**
  1184. * Creates a `lodash` object which wraps `value` to enable implicit method
  1185. * chaining. Methods that operate on and return arrays, collections, and
  1186. * functions can be chained together. Methods that retrieve a single value or
  1187. * may return a primitive value will automatically end the chain sequence and
  1188. * return the unwrapped value. Otherwise, the value must be unwrapped with
  1189. * `_#value`.
  1190. *
  1191. * Explicit chaining, which must be unwrapped with `_#value` in all cases,
  1192. * may be enabled using `_.chain`.
  1193. *
  1194. * The execution of chained methods is lazy, that is, it's deferred until
  1195. * `_#value` is implicitly or explicitly called.
  1196. *
  1197. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  1198. * fusion is an optimization to merge iteratee calls; this avoids the creation
  1199. * of intermediate arrays and can greatly reduce the number of iteratee executions.
  1200. * Sections of a chain sequence qualify for shortcut fusion if the section is
  1201. * applied to an array of at least two hundred elements and any iteratees
  1202. * accept only one argument. The heuristic for whether a section qualifies
  1203. * for shortcut fusion is subject to change.
  1204. *
  1205. * Chaining is supported in custom builds as long as the `_#value` method is
  1206. * directly or indirectly included in the build.
  1207. *
  1208. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1209. *
  1210. * The wrapper `Array` methods are:
  1211. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1212. *
  1213. * The wrapper `String` methods are:
  1214. * `replace` and `split`
  1215. *
  1216. * The wrapper methods that support shortcut fusion are:
  1217. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1218. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1219. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1220. *
  1221. * The chainable wrapper methods are:
  1222. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
  1223. * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
  1224. * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`,
  1225. * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
  1226. * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
  1227. * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
  1228. * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`,
  1229. * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invokeMap`,
  1230. * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
  1231. * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
  1232. * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`,
  1233. * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
  1234. * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
  1235. * `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
  1236. * `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
  1237. * `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`,
  1238. * `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`,
  1239. * `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`,
  1240. * `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`,
  1241. * `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`,
  1242. * `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith`
  1243. *
  1244. * The wrapper methods that are **not** chainable by default are:
  1245. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1246. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
  1247. * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
  1248. * `findLast`, `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`,
  1249. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1250. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1251. * `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
  1252. * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
  1253. * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`, `isMatchWith`,
  1254. * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`,
  1255. * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isString`, `isUndefined`,
  1256. * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`,
  1257. * `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`,
  1258. * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`,
  1259. * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
  1260. * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
  1261. * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
  1262. * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toLower`,
  1263. * `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`,
  1264. * `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
  1265. * `upperCase`, `upperFirst`, `value`, and `words`
  1266. *
  1267. * @name _
  1268. * @constructor
  1269. * @category Seq
  1270. * @param {*} value The value to wrap in a `lodash` instance.
  1271. * @returns {Object} Returns the new `lodash` wrapper instance.
  1272. * @example
  1273. *
  1274. * function square(n) {
  1275. * return n * n;
  1276. * }
  1277. *
  1278. * var wrapped = _([1, 2, 3]);
  1279. *
  1280. * // returns an unwrapped value
  1281. * wrapped.reduce(_.add);
  1282. * // => 6
  1283. *
  1284. * // returns a wrapped value
  1285. * var squares = wrapped.map(square);
  1286. *
  1287. * _.isArray(squares);
  1288. * // => false
  1289. *
  1290. * _.isArray(squares.value());
  1291. * // => true
  1292. */
  1293. function lodash(value) {
  1294. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1295. if (value instanceof LodashWrapper) {
  1296. return value;
  1297. }