PageRenderTime 29ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/3.5.0/lodash.compat.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1489 lines | 1455 code | 13 blank | 21 comment | 0 complexity | 89b023a57c4367e55f00efb7f54d51bb MD5 | raw file
  1. /**
  2. * @license
  3. * lodash 3.5.0 (Custom Build) <https://lodash.com/>
  4. * Build: `lodash compat -o ./lodash.js`
  5. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  6. * Based on Underscore.js 1.8.2 <http://underscorejs.org/LICENSE>
  7. * Copyright 2009-2015 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 = '3.5.0';
  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. REARG_FLAG = 128,
  24. ARY_FLAG = 256;
  25. /** Used as default options for `_.trunc`. */
  26. var DEFAULT_TRUNC_LENGTH = 30,
  27. DEFAULT_TRUNC_OMISSION = '...';
  28. /** Used to detect when a function becomes hot. */
  29. var HOT_COUNT = 150,
  30. HOT_SPAN = 16;
  31. /** Used to indicate the type of lazy iteratees. */
  32. var LAZY_DROP_WHILE_FLAG = 0,
  33. LAZY_FILTER_FLAG = 1,
  34. LAZY_MAP_FLAG = 2;
  35. /** Used as the `TypeError` message for "Functions" methods. */
  36. var FUNC_ERROR_TEXT = 'Expected a function';
  37. /** Used as the internal argument placeholder. */
  38. var PLACEHOLDER = '__lodash_placeholder__';
  39. /** `Object#toString` result references. */
  40. var argsTag = '[object Arguments]',
  41. arrayTag = '[object Array]',
  42. boolTag = '[object Boolean]',
  43. dateTag = '[object Date]',
  44. errorTag = '[object Error]',
  45. funcTag = '[object Function]',
  46. mapTag = '[object Map]',
  47. numberTag = '[object Number]',
  48. objectTag = '[object Object]',
  49. regexpTag = '[object RegExp]',
  50. setTag = '[object Set]',
  51. stringTag = '[object String]',
  52. weakMapTag = '[object WeakMap]';
  53. var arrayBufferTag = '[object ArrayBuffer]',
  54. float32Tag = '[object Float32Array]',
  55. float64Tag = '[object Float64Array]',
  56. int8Tag = '[object Int8Array]',
  57. int16Tag = '[object Int16Array]',
  58. int32Tag = '[object Int32Array]',
  59. uint8Tag = '[object Uint8Array]',
  60. uint8ClampedTag = '[object Uint8ClampedArray]',
  61. uint16Tag = '[object Uint16Array]',
  62. uint32Tag = '[object Uint32Array]';
  63. /** Used to match empty string literals in compiled template source. */
  64. var reEmptyStringLeading = /\b__p \+= '';/g,
  65. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  66. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  67. /** Used to match HTML entities and HTML characters. */
  68. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  69. reUnescapedHtml = /[&<>"'`]/g,
  70. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  71. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  72. /** Used to match template delimiters. */
  73. var reEscape = /<%-([\s\S]+?)%>/g,
  74. reEvaluate = /<%([\s\S]+?)%>/g,
  75. reInterpolate = /<%=([\s\S]+?)%>/g;
  76. /**
  77. * Used to match ES template delimiters.
  78. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
  79. * for more details.
  80. */
  81. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  82. /** Used to match `RegExp` flags from their coerced string values. */
  83. var reFlags = /\w*$/;
  84. /** Used to detect named functions. */
  85. var reFuncName = /^\s*function[ \n\r\t]+\w/;
  86. /** Used to detect hexadecimal string values. */
  87. var reHexPrefix = /^0[xX]/;
  88. /** Used to detect host constructors (Safari > 5). */
  89. var reHostCtor = /^\[object .+?Constructor\]$/;
  90. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  91. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  92. /** Used to ensure capturing order of template delimiters. */
  93. var reNoMatch = /($^)/;
  94. /**
  95. * Used to match `RegExp` special characters.
  96. * See this [article on `RegExp` characters](http://www.regular-expressions.info/characters.html#special)
  97. * for more details.
  98. */
  99. var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
  100. reHasRegExpChars = RegExp(reRegExpChars.source);
  101. /** Used to detect functions containing a `this` reference. */
  102. var reThis = /\bthis\b/;
  103. /** Used to match unescaped characters in compiled string literals. */
  104. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  105. /** Used to match words to create compound words. */
  106. var reWords = (function() {
  107. var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
  108. lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
  109. return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
  110. }());
  111. /** Used to detect and test for whitespace. */
  112. var whitespace = (
  113. // Basic whitespace characters.
  114. ' \t\x0b\f\xa0\ufeff' +
  115. // Line terminators.
  116. '\n\r\u2028\u2029' +
  117. // Unicode category "Zs" space separators.
  118. '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
  119. );
  120. /** Used to assign default `context` object properties. */
  121. var contextProps = [
  122. 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  123. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
  124. 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'document',
  125. 'isFinite', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
  126. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  127. 'window', 'WinRTError'
  128. ];
  129. /** Used to fix the JScript `[[DontEnum]]` bug. */
  130. var shadowProps = [
  131. 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
  132. 'toLocaleString', 'toString', 'valueOf'
  133. ];
  134. /** Used to make template sourceURLs easier to identify. */
  135. var templateCounter = -1;
  136. /** Used to identify `toStringTag` values of typed arrays. */
  137. var typedArrayTags = {};
  138. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  139. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  140. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  141. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  142. typedArrayTags[uint32Tag] = true;
  143. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  144. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  145. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  146. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  147. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  148. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  149. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  150. /** Used to identify `toStringTag` values supported by `_.clone`. */
  151. var cloneableTags = {};
  152. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  153. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  154. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  155. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  156. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  157. cloneableTags[numberTag] = cloneableTags[objectTag] =
  158. cloneableTags[regexpTag] = cloneableTags[stringTag] =
  159. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  160. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  161. cloneableTags[errorTag] = cloneableTags[funcTag] =
  162. cloneableTags[mapTag] = cloneableTags[setTag] =
  163. cloneableTags[weakMapTag] = false;
  164. /** Used as an internal `_.debounce` options object by `_.throttle`. */
  165. var debounceOptions = {
  166. 'leading': false,
  167. 'maxWait': 0,
  168. 'trailing': false
  169. };
  170. /** Used to map latin-1 supplementary letters to basic latin letters. */
  171. var deburredLetters = {
  172. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  173. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  174. '\xc7': 'C', '\xe7': 'c',
  175. '\xd0': 'D', '\xf0': 'd',
  176. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  177. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  178. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  179. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  180. '\xd1': 'N', '\xf1': 'n',
  181. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  182. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  183. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  184. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  185. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  186. '\xc6': 'Ae', '\xe6': 'ae',
  187. '\xde': 'Th', '\xfe': 'th',
  188. '\xdf': 'ss'
  189. };
  190. /** Used to map characters to HTML entities. */
  191. var htmlEscapes = {
  192. '&': '&amp;',
  193. '<': '&lt;',
  194. '>': '&gt;',
  195. '"': '&quot;',
  196. "'": '&#39;',
  197. '`': '&#96;'
  198. };
  199. /** Used to map HTML entities to characters. */
  200. var htmlUnescapes = {
  201. '&amp;': '&',
  202. '&lt;': '<',
  203. '&gt;': '>',
  204. '&quot;': '"',
  205. '&#39;': "'",
  206. '&#96;': '`'
  207. };
  208. /** Used to determine if values are of the language type `Object`. */
  209. var objectTypes = {
  210. 'function': true,
  211. 'object': true
  212. };
  213. /** Used to escape characters for inclusion in compiled string literals. */
  214. var stringEscapes = {
  215. '\\': '\\',
  216. "'": "'",
  217. '\n': 'n',
  218. '\r': 'r',
  219. '\u2028': 'u2028',
  220. '\u2029': 'u2029'
  221. };
  222. /** Detect free variable `exports`. */
  223. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  224. /** Detect free variable `module`. */
  225. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  226. /** Detect free variable `global` from Node.js. */
  227. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
  228. /** Detect free variable `window`. */
  229. var freeWindow = objectTypes[typeof window] && window;
  230. /** Detect the popular CommonJS extension `module.exports`. */
  231. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  232. /**
  233. * Used as a reference to the global object.
  234. *
  235. * The `this` value is used if it is the global object to avoid Greasemonkey's
  236. * restricted `window` object, otherwise the `window` object is used.
  237. */
  238. var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || this;
  239. /*--------------------------------------------------------------------------*/
  240. /**
  241. * The base implementation of `compareAscending` which compares values and
  242. * sorts them in ascending order without guaranteeing a stable sort.
  243. *
  244. * @private
  245. * @param {*} value The value to compare to `other`.
  246. * @param {*} other The value to compare to `value`.
  247. * @returns {number} Returns the sort order indicator for `value`.
  248. */
  249. function baseCompareAscending(value, other) {
  250. if (value !== other) {
  251. var valIsReflexive = value === value,
  252. othIsReflexive = other === other;
  253. if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
  254. return 1;
  255. }
  256. if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
  257. return -1;
  258. }
  259. }
  260. return 0;
  261. }
  262. /**
  263. * The base implementation of `_.indexOf` without support for binary searches.
  264. *
  265. * @private
  266. * @param {Array} array The array to search.
  267. * @param {*} value The value to search for.
  268. * @param {number} fromIndex The index to search from.
  269. * @returns {number} Returns the index of the matched value, else `-1`.
  270. */
  271. function baseIndexOf(array, value, fromIndex) {
  272. if (value !== value) {
  273. return indexOfNaN(array, fromIndex);
  274. }
  275. var index = fromIndex - 1,
  276. length = array.length;
  277. while (++index < length) {
  278. if (array[index] === value) {
  279. return index;
  280. }
  281. }
  282. return -1;
  283. }
  284. /**
  285. * The base implementation of `_.isFunction` without support for environments
  286. * with incorrect `typeof` results.
  287. *
  288. * @private
  289. * @param {*} value The value to check.
  290. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  291. */
  292. function baseIsFunction(value) {
  293. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
  294. // See https://github.com/jashkenas/underscore/issues/1621 for more details.
  295. return typeof value == 'function' || false;
  296. }
  297. /**
  298. * Converts `value` to a string if it is not one. An empty string is returned
  299. * for `null` or `undefined` values.
  300. *
  301. * @private
  302. * @param {*} value The value to process.
  303. * @returns {string} Returns the string.
  304. */
  305. function baseToString(value) {
  306. if (typeof value == 'string') {
  307. return value;
  308. }
  309. return value == null ? '' : (value + '');
  310. }
  311. /**
  312. * Used by `_.max` and `_.min` as the default callback for string values.
  313. *
  314. * @private
  315. * @param {string} string The string to inspect.
  316. * @returns {number} Returns the code unit of the first character of the string.
  317. */
  318. function charAtCallback(string) {
  319. return string.charCodeAt(0);
  320. }
  321. /**
  322. * Used by `_.trim` and `_.trimLeft` to get the index of the first character
  323. * of `string` that is not found in `chars`.
  324. *
  325. * @private
  326. * @param {string} string The string to inspect.
  327. * @param {string} chars The characters to find.
  328. * @returns {number} Returns the index of the first character not found in `chars`.
  329. */
  330. function charsLeftIndex(string, chars) {
  331. var index = -1,
  332. length = string.length;
  333. while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  334. return index;
  335. }
  336. /**
  337. * Used by `_.trim` and `_.trimRight` to get the index of the last character
  338. * of `string` that is not found in `chars`.
  339. *
  340. * @private
  341. * @param {string} string The string to inspect.
  342. * @param {string} chars The characters to find.
  343. * @returns {number} Returns the index of the last character not found in `chars`.
  344. */
  345. function charsRightIndex(string, chars) {
  346. var index = string.length;
  347. while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
  348. return index;
  349. }
  350. /**
  351. * Used by `_.sortBy` to compare transformed elements of a collection and stable
  352. * sort them in ascending order.
  353. *
  354. * @private
  355. * @param {Object} object The object to compare to `other`.
  356. * @param {Object} other The object to compare to `object`.
  357. * @returns {number} Returns the sort order indicator for `object`.
  358. */
  359. function compareAscending(object, other) {
  360. return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
  361. }
  362. /**
  363. * Used by `_.sortByOrder` to compare multiple properties of each element
  364. * in a collection and stable sort them in the following order:
  365. *
  366. * If orders is unspecified, sort in ascending order for all properties.
  367. * Otherwise, for each property, sort in ascending order if its corresponding value in
  368. * orders is true, and descending order if false.
  369. *
  370. * @private
  371. * @param {Object} object The object to compare to `other`.
  372. * @param {Object} other The object to compare to `object`.
  373. * @param {boolean[]} orders The order to sort by for each property.
  374. * @returns {number} Returns the sort order indicator for `object`.
  375. */
  376. function compareMultiple(object, other, orders) {
  377. var index = -1,
  378. objCriteria = object.criteria,
  379. othCriteria = other.criteria,
  380. length = objCriteria.length,
  381. ordersLength = orders.length;
  382. while (++index < length) {
  383. var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
  384. if (result) {
  385. if (index >= ordersLength) {
  386. return result;
  387. }
  388. return result * (orders[index] ? 1 : -1);
  389. }
  390. }
  391. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  392. // that causes it, under certain circumstances, to provide the same value for
  393. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  394. // for more details.
  395. //
  396. // This also ensures a stable sort in V8 and other engines.
  397. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  398. return object.index - other.index;
  399. }
  400. /**
  401. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  402. *
  403. * @private
  404. * @param {string} letter The matched letter to deburr.
  405. * @returns {string} Returns the deburred letter.
  406. */
  407. function deburrLetter(letter) {
  408. return deburredLetters[letter];
  409. }
  410. /**
  411. * Used by `_.escape` to convert characters to HTML entities.
  412. *
  413. * @private
  414. * @param {string} chr The matched character to escape.
  415. * @returns {string} Returns the escaped character.
  416. */
  417. function escapeHtmlChar(chr) {
  418. return htmlEscapes[chr];
  419. }
  420. /**
  421. * Used by `_.template` to escape characters for inclusion in compiled
  422. * string literals.
  423. *
  424. * @private
  425. * @param {string} chr The matched character to escape.
  426. * @returns {string} Returns the escaped character.
  427. */
  428. function escapeStringChar(chr) {
  429. return '\\' + stringEscapes[chr];
  430. }
  431. /**
  432. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  433. * If `fromRight` is provided elements of `array` are iterated from right to left.
  434. *
  435. * @private
  436. * @param {Array} array The array to search.
  437. * @param {number} fromIndex The index to search from.
  438. * @param {boolean} [fromRight] Specify iterating from right to left.
  439. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  440. */
  441. function indexOfNaN(array, fromIndex, fromRight) {
  442. var length = array.length,
  443. index = fromIndex + (fromRight ? 0 : -1);
  444. while ((fromRight ? index-- : ++index < length)) {
  445. var other = array[index];
  446. if (other !== other) {
  447. return index;
  448. }
  449. }
  450. return -1;
  451. }
  452. /**
  453. * Checks if `value` is a host object in IE < 9.
  454. *
  455. * @private
  456. * @param {*} value The value to check.
  457. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  458. */
  459. var isHostObject = (function() {
  460. try {
  461. Object({ 'toString': 0 } + '');
  462. } catch(e) {
  463. return function() { return false; };
  464. }
  465. return function(value) {
  466. // IE < 9 presents many host objects as `Object` objects that can coerce
  467. // to strings despite having improperly defined `toString` methods.
  468. return typeof value.toString != 'function' && typeof (value + '') == 'string';
  469. };
  470. }());
  471. /**
  472. * Checks if `value` is object-like.
  473. *
  474. * @private
  475. * @param {*} value The value to check.
  476. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  477. */
  478. function isObjectLike(value) {
  479. return (value && typeof value == 'object') || false;
  480. }
  481. /**
  482. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  483. * character code is whitespace.
  484. *
  485. * @private
  486. * @param {number} charCode The character code to inspect.
  487. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  488. */
  489. function isSpace(charCode) {
  490. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  491. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  492. }
  493. /**
  494. * Replaces all `placeholder` elements in `array` with an internal placeholder
  495. * and returns an array of their indexes.
  496. *
  497. * @private
  498. * @param {Array} array The array to modify.
  499. * @param {*} placeholder The placeholder to replace.
  500. * @returns {Array} Returns the new array of placeholder indexes.
  501. */
  502. function replaceHolders(array, placeholder) {
  503. var index = -1,
  504. length = array.length,
  505. resIndex = -1,
  506. result = [];
  507. while (++index < length) {
  508. if (array[index] === placeholder) {
  509. array[index] = PLACEHOLDER;
  510. result[++resIndex] = index;
  511. }
  512. }
  513. return result;
  514. }
  515. /**
  516. * An implementation of `_.uniq` optimized for sorted arrays without support
  517. * for callback shorthands and `this` binding.
  518. *
  519. * @private
  520. * @param {Array} array The array to inspect.
  521. * @param {Function} [iteratee] The function invoked per iteration.
  522. * @returns {Array} Returns the new duplicate-value-free array.
  523. */
  524. function sortedUniq(array, iteratee) {
  525. var seen,
  526. index = -1,
  527. length = array.length,
  528. resIndex = -1,
  529. result = [];
  530. while (++index < length) {
  531. var value = array[index],
  532. computed = iteratee ? iteratee(value, index, array) : value;
  533. if (!index || seen !== computed) {
  534. seen = computed;
  535. result[++resIndex] = value;
  536. }
  537. }
  538. return result;
  539. }
  540. /**
  541. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  542. * character of `string`.
  543. *
  544. * @private
  545. * @param {string} string The string to inspect.
  546. * @returns {number} Returns the index of the first non-whitespace character.
  547. */
  548. function trimmedLeftIndex(string) {
  549. var index = -1,
  550. length = string.length;
  551. while (++index < length && isSpace(string.charCodeAt(index))) {}
  552. return index;
  553. }
  554. /**
  555. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  556. * character of `string`.
  557. *
  558. * @private
  559. * @param {string} string The string to inspect.
  560. * @returns {number} Returns the index of the last non-whitespace character.
  561. */
  562. function trimmedRightIndex(string) {
  563. var index = string.length;
  564. while (index-- && isSpace(string.charCodeAt(index))) {}
  565. return index;
  566. }
  567. /**
  568. * Used by `_.unescape` to convert HTML entities to characters.
  569. *
  570. * @private
  571. * @param {string} chr The matched character to unescape.
  572. * @returns {string} Returns the unescaped character.
  573. */
  574. function unescapeHtmlChar(chr) {
  575. return htmlUnescapes[chr];
  576. }
  577. /*--------------------------------------------------------------------------*/
  578. /**
  579. * Create a new pristine `lodash` function using the given `context` object.
  580. *
  581. * @static
  582. * @memberOf _
  583. * @category Utility
  584. * @param {Object} [context=root] The context object.
  585. * @returns {Function} Returns a new `lodash` function.
  586. * @example
  587. *
  588. * _.mixin({ 'add': function(a, b) { return a + b; } });
  589. *
  590. * var lodash = _.runInContext();
  591. * lodash.mixin({ 'sub': function(a, b) { return a - b; } });
  592. *
  593. * _.isFunction(_.add);
  594. * // => true
  595. * _.isFunction(_.sub);
  596. * // => false
  597. *
  598. * lodash.isFunction(lodash.add);
  599. * // => false
  600. * lodash.isFunction(lodash.sub);
  601. * // => true
  602. *
  603. * // using `context` to mock `Date#getTime` use in `_.now`
  604. * var mock = _.runInContext({
  605. * 'Date': function() {
  606. * return { 'getTime': getTimeMock };
  607. * }
  608. * });
  609. *
  610. * // or creating a suped-up `defer` in Node.js
  611. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  612. */
  613. function runInContext(context) {
  614. // Avoid issues with some ES3 environments that attempt to use values, named
  615. // after built-in constructors like `Object`, for the creation of literals.
  616. // ES5 clears this up by stating that literals must use built-in constructors.
  617. // See https://es5.github.io/#x11.1.5 for more details.
  618. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  619. /** Native constructor references. */
  620. var Array = context.Array,
  621. Date = context.Date,
  622. Error = context.Error,
  623. Function = context.Function,
  624. Math = context.Math,
  625. Number = context.Number,
  626. Object = context.Object,
  627. RegExp = context.RegExp,
  628. String = context.String,
  629. TypeError = context.TypeError;
  630. /** Used for native method references. */
  631. var arrayProto = Array.prototype,
  632. errorProto = Error.prototype,
  633. objectProto = Object.prototype,
  634. stringProto = String.prototype;
  635. /** Used to detect DOM support. */
  636. var document = (document = context.window) && document.document;
  637. /** Used to resolve the decompiled source of functions. */
  638. var fnToString = Function.prototype.toString;
  639. /** Used to the length of n-tuples for `_.unzip`. */
  640. var getLength = baseProperty('length');
  641. /** Used to check objects for own properties. */
  642. var hasOwnProperty = objectProto.hasOwnProperty;
  643. /** Used to generate unique IDs. */
  644. var idCounter = 0;
  645. /**
  646. * Used to resolve the `toStringTag` of values.
  647. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
  648. * for more details.
  649. */
  650. var objToString = objectProto.toString;
  651. /** Used to restore the original `_` reference in `_.noConflict`. */
  652. var oldDash = context._;
  653. /** Used to detect if a method is native. */
  654. var reNative = RegExp('^' +
  655. escapeRegExp(objToString)
  656. .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  657. );
  658. /** Native method references. */
  659. var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer,
  660. bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
  661. ceil = Math.ceil,
  662. clearTimeout = context.clearTimeout,
  663. floor = Math.floor,
  664. getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
  665. push = arrayProto.push,
  666. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  667. Set = isNative(Set = context.Set) && Set,
  668. setTimeout = context.setTimeout,
  669. splice = arrayProto.splice,
  670. Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
  671. WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap;
  672. /** Used to clone array buffers. */
  673. var Float64Array = (function() {
  674. // Safari 5 errors when using an array buffer to initialize a typed array
  675. // where the array buffer's `byteLength` is not a multiple of the typed
  676. // array's `BYTES_PER_ELEMENT`.
  677. try {
  678. var func = isNative(func = context.Float64Array) && func,
  679. result = new func(new ArrayBuffer(10), 0, 1) && func;
  680. } catch(e) {}
  681. return result;
  682. }());
  683. /* Native method references for those with the same name as other `lodash` methods. */
  684. var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
  685. nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
  686. nativeIsFinite = context.isFinite,
  687. nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
  688. nativeMax = Math.max,
  689. nativeMin = Math.min,
  690. nativeNow = isNative(nativeNow = Date.now) && nativeNow,
  691. nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite,
  692. nativeParseInt = context.parseInt,
  693. nativeRandom = Math.random;
  694. /** Used as references for `-Infinity` and `Infinity`. */
  695. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  696. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  697. /** Used as references for the maximum length and index of an array. */
  698. var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
  699. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  700. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  701. /** Used as the size, in bytes, of each `Float64Array` element. */
  702. var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
  703. /**
  704. * Used as the maximum length of an array-like value.
  705. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  706. * for more details.
  707. */
  708. var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
  709. /** Used to store function metadata. */
  710. var metaMap = WeakMap && new WeakMap;
  711. /** Used to lookup a type array constructors by `toStringTag`. */
  712. var ctorByTag = {};
  713. ctorByTag[float32Tag] = context.Float32Array;
  714. ctorByTag[float64Tag] = context.Float64Array;
  715. ctorByTag[int8Tag] = context.Int8Array;
  716. ctorByTag[int16Tag] = context.Int16Array;
  717. ctorByTag[int32Tag] = context.Int32Array;
  718. ctorByTag[uint8Tag] = context.Uint8Array;
  719. ctorByTag[uint8ClampedTag] = context.Uint8ClampedArray;
  720. ctorByTag[uint16Tag] = context.Uint16Array;
  721. ctorByTag[uint32Tag] = context.Uint32Array;
  722. /** Used to avoid iterating over non-enumerable properties in IE < 9. */
  723. var nonEnumProps = {};
  724. nonEnumProps[arrayTag] = nonEnumProps[dateTag] = nonEnumProps[numberTag] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  725. nonEnumProps[boolTag] = nonEnumProps[stringTag] = { 'constructor': true, 'toString': true, 'valueOf': true };
  726. nonEnumProps[errorTag] = nonEnumProps[funcTag] = nonEnumProps[regexpTag] = { 'constructor': true, 'toString': true };
  727. nonEnumProps[objectTag] = { 'constructor': true };
  728. arrayEach(shadowProps, function(key) {
  729. for (var tag in nonEnumProps) {
  730. if (hasOwnProperty.call(nonEnumProps, tag)) {
  731. var props = nonEnumProps[tag];
  732. props[key] = hasOwnProperty.call(props, key);
  733. }
  734. }
  735. });
  736. /*------------------------------------------------------------------------*/
  737. /**
  738. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  739. * Methods that operate on and return arrays, collections, and functions can
  740. * be chained together. Methods that return a boolean or single value will
  741. * automatically end the chain returning the unwrapped value. Explicit chaining
  742. * may be enabled using `_.chain`. The execution of chained methods is lazy,
  743. * that is, execution is deferred until `_#value` is implicitly or explicitly
  744. * called.
  745. *
  746. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  747. * fusion is an optimization that merges iteratees to avoid creating intermediate
  748. * arrays and reduce the number of iteratee executions.
  749. *
  750. * Chaining is supported in custom builds as long as the `_#value` method is
  751. * directly or indirectly included in the build.
  752. *
  753. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  754. *
  755. * The wrapper `Array` methods are:
  756. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
  757. * `splice`, and `unshift`
  758. *
  759. * The wrapper `String` methods are:
  760. * `replace` and `split`
  761. *
  762. * The wrapper methods that support shortcut fusion are:
  763. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  764. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  765. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  766. * and `where`
  767. *
  768. * The chainable wrapper methods are:
  769. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  770. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  771. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
  772. * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
  773. * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
  774. * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
  775. * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
  776. * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
  777. * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  778. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  779. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
  780. * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
  781. * `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
  782. * `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
  783. * `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
  784. * `without`, `wrap`, `xor`, `zip`, and `zipObject`
  785. *
  786. * The wrapper methods that are **not** chainable by default are:
  787. * `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
  788. * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
  789. * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
  790. * `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
  791. * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
  792. * `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
  793. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
  794. * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
  795. * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
  796. * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
  797. * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
  798. * `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
  799. * `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
  800. *
  801. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  802. * otherwise an unwrapped value is returned.
  803. *
  804. * @name _
  805. * @constructor
  806. * @category Chain
  807. * @param {*} value The value to wrap in a `lodash` instance.
  808. * @returns {Object} Returns the new `lodash` wrapper instance.
  809. * @example
  810. *
  811. * var wrapped = _([1, 2, 3]);
  812. *
  813. * // returns an unwrapped value
  814. * wrapped.reduce(function(sum, n) {
  815. * return sum + n;
  816. * });
  817. * // => 6
  818. *
  819. * // returns a wrapped value
  820. * var squares = wrapped.map(function(n) {
  821. * return n * n;
  822. * });
  823. *
  824. * _.isArray(squares);
  825. * // => false
  826. *
  827. * _.isArray(squares.value());
  828. * // => true
  829. */
  830. function lodash(value) {
  831. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  832. if (value instanceof LodashWrapper) {
  833. return value;
  834. }
  835. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  836. return wrapperClone(value);
  837. }
  838. }
  839. return new LodashWrapper(value);
  840. }
  841. /**
  842. * The function whose prototype all chaining wrappers inherit from.
  843. *
  844. * @private
  845. */
  846. function baseLodash() {
  847. // No operation performed.
  848. }
  849. /**
  850. * The base constructor for creating `lodash` wrapper objects.
  851. *
  852. * @private
  853. * @param {*} value The value to wrap.
  854. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  855. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  856. */
  857. function LodashWrapper(value, chainAll, actions) {
  858. this.__wrapped__ = value;
  859. this.__actions__ = actions || [];
  860. this.__chain__ = !!chainAll;
  861. }
  862. /**
  863. * An object environment feature flags.
  864. *
  865. * @static
  866. * @memberOf _
  867. * @type Object
  868. */
  869. var support = lodash.support = {};
  870. (function(x) {
  871. var Ctor = function() { this.x = 1; },
  872. object = { '0': 1, 'length': 1 },
  873. props = [];
  874. Ctor.prototype = { 'valueOf': 1, 'y': 1 };
  875. for (var key in new Ctor) { props.push(key); }
  876. /**
  877. * Detect if the `toStringTag` of `arguments` objects is resolvable
  878. * (all but Firefox < 4, IE < 9).
  879. *
  880. * @memberOf _.support
  881. * @type boolean
  882. */
  883. support.argsTag = objToString.call(arguments) == argsTag;
  884. /**
  885. * Detect if `name` or `message` properties of `Error.prototype` are
  886. * enumerable by default (IE < 9, Safari < 5.1).
  887. *
  888. * @memberOf _.support
  889. * @type boolean
  890. */
  891. support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') ||
  892. propertyIsEnumerable.call(errorProto, 'name');
  893. /**
  894. * Detect if `prototype` properties are enumerable by default.
  895. *
  896. * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
  897. * (if the prototype or a property on the prototype has been set)
  898. * incorrectly set the `[[Enumerable]]` value of a function's `prototype`
  899. * property to `true`.
  900. *
  901. * @memberOf _.support
  902. * @type boolean
  903. */
  904. support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype');
  905. /**
  906. * Detect if functions can be decompiled by `Function#toString`
  907. * (all but Firefox OS certified apps, older Opera mobile browsers, and
  908. * the PlayStation 3; forced `false` for Windows 8 apps).
  909. *
  910. * @memberOf _.support
  911. * @type boolean
  912. */
  913. support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
  914. /**
  915. * Detect if `Function#name` is supported (all but IE).
  916. *
  917. * @memberOf _.support
  918. * @type boolean
  919. */
  920. support.funcNames = typeof Function.name == 'string';
  921. /**
  922. * Detect if the `toStringTag` of DOM nodes is resolvable (all but IE < 9).
  923. *
  924. * @memberOf _.support
  925. * @type boolean
  926. */
  927. support.nodeTag = objToString.call(document) != objectTag;
  928. /**
  929. * Detect if string indexes are non-enumerable
  930. * (IE < 9, RingoJS, Rhino, Narwhal).
  931. *
  932. * @memberOf _.support
  933. * @type boolean
  934. */
  935. support.nonEnumStrings = !propertyIsEnumerable.call('x', 0);
  936. /**
  937. * Detect if properties shadowing those on `Object.prototype` are
  938. * non-enumerable.
  939. *
  940. * In IE < 9 an object's own properties, shadowing non-enumerable ones,
  941. * are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
  942. *
  943. * @memberOf _.support
  944. * @type boolean
  945. */
  946. support.nonEnumShadows = !/valueOf/.test(props);
  947. /**
  948. * Detect if own properties are iterated after inherited properties (IE < 9).
  949. *
  950. * @memberOf _.support
  951. * @type boolean
  952. */
  953. support.ownLast = props[0] != 'x';
  954. /**
  955. * Detect if `Array#shift` and `Array#splice` augment array-like objects
  956. * correctly.
  957. *
  958. * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array `shift()`
  959. * and `splice()` functions that fail to remove the last element, `value[0]`,
  960. * of array-like objects even though the `length` property is set to `0`.
  961. * The `shift()` method is buggy in compatibility modes of IE 8, while `splice()`
  962. * is buggy regardless of mode in IE < 9.
  963. *
  964. * @memberOf _.support
  965. * @type boolean
  966. */
  967. support.spliceObjects = (splice.call(object, 0, 1), !object[0]);
  968. /**
  969. * Detect lack of support for accessing string characters by index.
  970. *
  971. * IE < 8 can't access characters by index. IE 8 can only access characters
  972. * by index on string literals, not string objects.
  973. *
  974. * @memberOf _.support
  975. * @type boolean
  976. */
  977. support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
  978. /**
  979. * Detect if the DOM is supported.
  980. *
  981. * @memberOf _.support
  982. * @type boolean
  983. */
  984. try {
  985. support.dom = document.createDocumentFragment().nodeType === 11;
  986. } catch(e) {
  987. support.dom = false;
  988. }
  989. /**
  990. * Detect if `arguments` object indexes are non-enumerable.
  991. *
  992. * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
  993. * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
  994. * `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
  995. * checks for indexes that exceed their function's formal parameters with
  996. * associated values of `0`.
  997. *
  998. * @memberOf _.support
  999. * @type boolean
  1000. */
  1001. try {
  1002. support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
  1003. } catch(e) {
  1004. support.nonEnumArgs = true;
  1005. }
  1006. }(0, 0));
  1007. /**
  1008. * By default, the template delimiters used by lodash are like those in
  1009. * embedded Ruby (ERB). Change the following template settings to use
  1010. * alternative delimiters.
  1011. *
  1012. * @static
  1013. * @memberOf _
  1014. * @type Object
  1015. */
  1016. lodash.templateSettings = {
  1017. /**
  1018. * Used to detect `data` property values to be HTML-escaped.
  1019. *
  1020. * @memberOf _.templateSettings
  1021. * @type RegExp
  1022. */
  1023. 'escape': reEscape,
  1024. /**
  1025. * Used to detect code to be evaluated.
  1026. *
  1027. * @memberOf _.templateSettings
  1028. * @type RegExp
  1029. */
  1030. 'evaluate': reEvaluate,
  1031. /**
  1032. * Used to detect `data` property values to inject.
  1033. *
  1034. * @memberOf _.templateSettings
  1035. * @type RegExp
  1036. */
  1037. 'interpolate': reInterpolate,
  1038. /**
  1039. * Used to reference the data object in the template text.
  1040. *
  1041. * @memberOf _.templateSettings
  1042. * @type string
  1043. */
  1044. 'variable': '',
  1045. /**
  1046. * Used to import variables into the compiled template.
  1047. *
  1048. * @memberOf _.templateSettings
  1049. * @type Object
  1050. */
  1051. 'imports': {
  1052. /**
  1053. * A reference to the `lodash` function.
  1054. *
  1055. * @memberOf _.templateSettings.imports
  1056. * @type Function
  1057. */
  1058. '_': lodash
  1059. }
  1060. };
  1061. /*------------------------------------------------------------------------*/
  1062. /**
  1063. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1064. *
  1065. * @private
  1066. * @param {*} value The value to wrap.
  1067. */
  1068. function LazyWrapper(value) {
  1069. this.__wrapped__ = value;
  1070. this.__actions__ = null;
  1071. this.__dir__ = 1;
  1072. this.__dropCount__ = 0;
  1073. this.__filtered__ = false;
  1074. this.__iteratees__ = null;
  1075. this.__takeCount__ = POSITIVE_INFINITY;
  1076. this.__views__ = null;
  1077. }
  1078. /**
  1079. * Creates a clone of the lazy wrapper object.
  1080. *
  1081. * @private
  1082. * @name clone
  1083. * @memberOf LazyWrapper
  1084. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1085. */
  1086. function lazyClone() {
  1087. var actions = this.__actions__,
  1088. iteratees = this.__iteratees__,
  1089. views = this.__views__,
  1090. result = new LazyWrapper(this.__wrapped__);
  1091. result.__actions__ = actions ? arrayCopy(actions) : null;
  1092. result.__dir__ = this.__dir__;
  1093. result.__filtered__ = this.__filtered__;
  1094. result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
  1095. result.__takeCount__ = this.__takeCount__;
  1096. result.__views__ = views ? arrayCopy(views) : null;
  1097. return result;
  1098. }
  1099. /**
  1100. * Reverses the direction of lazy iteration.
  1101. *
  1102. * @private
  1103. * @name reverse
  1104. * @memberOf LazyWrapper
  1105. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1106. */
  1107. function lazyReverse() {
  1108. if (this.__filtered__) {
  1109. var result = new LazyWrapper(this);
  1110. result.__dir__ = -1;
  1111. result.__filtered__ = true;
  1112. } else {
  1113. result = this.clone();
  1114. result.__dir__ *= -1;
  1115. }
  1116. return result;
  1117. }
  1118. /**
  1119. * Extracts the unwrapped value from its lazy wrapper.
  1120. *
  1121. * @private
  1122. * @name value
  1123. * @memberOf LazyWrapper
  1124. * @returns {*} Returns the unwrapped value.
  1125. */
  1126. function lazyValue() {
  1127. var array = this.__wrapped__.value();
  1128. if (!isArray(array)) {
  1129. return baseWrapperValue(array, this.__actions__);
  1130. }
  1131. var dir = this.__dir__,
  1132. isRight = dir < 0,
  1133. view = getView(0, array.length, this.__views__),
  1134. start = view.start,
  1135. end = view.end,
  1136. length = end - start,
  1137. index = isRight ? end : (start - 1),
  1138. takeCount = nativeMin(length, this.__takeCount__),
  1139. iteratees = this.__iteratees__,
  1140. iterLength = iteratees ? iteratees.length : 0,
  1141. resIndex = 0,
  1142. result = [];
  1143. outer:
  1144. while (length-- && resIndex < takeCount) {
  1145. index += dir;
  1146. var iterIndex = -1,
  1147. value = array[index];
  1148. while (++iterIndex < iterLength) {
  1149. var data = iteratees[iterIndex],
  1150. iteratee = data.iteratee,
  1151. type = data.type;
  1152. if (type == LAZY_DROP_WHILE_FLAG) {
  1153. if (data.done && (isRight ? (index > data.index) : (index < data.index))) {
  1154. data.count = 0;
  1155. data.done = false;
  1156. }
  1157. data.index = index;
  1158. if (!data.done) {
  1159. var limit = data.limit;
  1160. if (!(data.done = limit > -1 ? (data.count++ >= limit) : !iteratee(value))) {
  1161. continue outer;
  1162. }
  1163. }
  1164. } else {
  1165. var computed = iteratee(value);
  1166. if (type == LAZY_MAP_FLAG) {
  1167. value = computed;
  1168. } else if (!computed) {
  1169. if (type == LAZY_FILTER_FLAG) {
  1170. continue outer;
  1171. } else {
  1172. break outer;
  1173. }
  1174. }
  1175. }
  1176. }
  1177. result[resIndex++] = value;
  1178. }
  1179. return result;
  1180. }
  1181. /*------------------------------------------------------------------------*/
  1182. /**
  1183. * Creates a cache object to store key/value pairs.
  1184. *
  1185. * @private
  1186. * @static
  1187. * @name Cache
  1188. * @memberOf _.memoize
  1189. */
  1190. function MapCache() {
  1191. this.__data__ = {};
  1192. }
  1193. /**
  1194. * Removes `key` and its value from the cache.
  1195. *
  1196. * @private
  1197. * @name delete
  1198. * @memberOf _.memoize.Cache
  1199. * @param {string} key The key of the value to remove.
  1200. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1201. */
  1202. function mapDelete(key) {
  1203. return this.has(key) && delete this.__data__[key];
  1204. }
  1205. /**
  1206. * Gets the cached value for `key`.
  1207. *
  1208. * @private
  1209. * @name get
  1210. * @memberOf _.memoize.Cache
  1211. * @param {string} key The key of the value to get.
  1212. * @returns {*} Returns the cached value.
  1213. */
  1214. function mapGet(key) {
  1215. return key == '__proto__' ? undefined : this.__data__[key];
  1216. }
  1217. /**
  1218. * Checks if a cached value for `key` exists.
  1219. *
  1220. * @private
  1221. * @name has
  1222. * @memberOf _.memoize.Cache
  1223. * @param {string} key The key of the entry to check.
  1224. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1225. */
  1226. function mapHas(key) {
  1227. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1228. }
  1229. /**
  1230. * Adds `value` to `key` of the cache.
  1231. *
  1232. * @private
  1233. * @name set
  1234. * @memberOf _.memoize.Cache
  1235. * @param {string} key The key of the value to cache.
  1236. * @param {*} value The value to cache.
  1237. * @returns {Object} Returns the cache object.
  1238. */
  1239. function mapSet(key, value) {
  1240. if (key != '__proto__') {
  1241. this.__data__[key] = value;
  1242. }
  1243. return this;
  1244. }
  1245. /*------------------------------------------------------------------------*/
  1246. /**
  1247. *
  1248. * Creates a cache object to store unique values.
  1249. *
  1250. * @private
  1251. * @param {Array} [values] The values to cache.
  1252. */
  1253. function SetCache(values) {
  1254. var length = values ? values.length : 0;
  1255. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1256. while (length--) {
  1257. this.push(values[length]);
  1258. }
  1259. }
  1260. /**
  1261. * Checks if `value` is in `cache` mimicking the return signature of
  1262. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1263. *
  1264. * @private
  1265. * @param {Object} cache The cache to search.
  1266. * @param {*} value The value to search for.
  1267. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1268. */
  1269. function cacheIndexOf(cache, value) {
  1270. var data = cache.data,
  1271. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1272. return result ? 0 : -1;
  1273. }
  1274. /**
  1275. * Adds `value` to the cache.
  1276. *
  1277. * @private
  1278. * @name push
  1279. * @memberOf SetCache
  1280. * @param {*} value The value to cache.
  1281. */
  1282. function cachePush(value) {
  1283. var data = this.data;
  1284. if (typeof value == 'string' || isObject(value)) {
  1285. data.set.add(value);
  1286. } else {
  1287. data.hash[value] = true;
  1288. }
  1289. }
  1290. /*------------------------------------------------------------------------*/
  1291. /**
  1292. * Copies the values of `source` to `array`.
  1293. *
  1294. * @private
  1295. * @param {Array} source The array to copy values from.
  1296. * @param {Array} [array=[]] The array to copy values to.
  1297. * @returns {Array} Returns `array`.
  1298. */
  1299. function arrayCopy(source, array) {
  1300. var index = -1,
  1301. length = source.length;
  1302. array || (array = Array(length));
  1303. while (++index < length) {
  1304. array[index] = source[index];
  1305. }
  1306. return array;
  1307. }
  1308. /**
  1309. * A specialized version of `_.forEach` for arrays without support for callback
  1310. * shorthands or `this` binding.
  1311. *
  1312. * @private
  1313. * @param {Array} array The array to iterate over.
  1314. * @param {Function} iteratee The function invoked per iteration.
  1315. * @returns {Array} Returns `array`.
  1316. */
  1317. function arrayEach(array, iteratee) {
  1318. var index = -1,
  1319. length = array.length;
  1320. while (++index < length) {
  1321. if (iteratee(array[index], index, array) === false) {
  1322. break;
  1323. }
  1324. }
  1325. return array;
  1326. }
  1327. /**
  1328. * A specialized version of `_.forEachRight` for arrays without support for
  1329. * callback shorthands or `this` binding.
  1330. *
  1331. * @private
  1332. * @param {Array} array The array to iterate over.
  1333. * @param {Function} iteratee The function invoked per iteration