PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/3.4.0/lodash.compat.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1490 lines | 1456 code | 13 blank | 21 comment | 0 complexity | e8e6471a122c512b8a8777af694f3b4f MD5 | raw file
  1. /**
  2. * @license
  3. * lodash 3.4.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.4.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_MAP_FLAG = 2,
  34. LAZY_TAKE_WHILE_FLAG = 3;
  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. } else {
  388. return orders[index] ? result : result * -1;
  389. }
  390. }
  391. }
  392. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  393. // that causes it, under certain circumstances, to provide the same value for
  394. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  395. // for more details.
  396. //
  397. // This also ensures a stable sort in V8 and other engines.
  398. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  399. return object.index - other.index;
  400. }
  401. /**
  402. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  403. *
  404. * @private
  405. * @param {string} letter The matched letter to deburr.
  406. * @returns {string} Returns the deburred letter.
  407. */
  408. function deburrLetter(letter) {
  409. return deburredLetters[letter];
  410. }
  411. /**
  412. * Used by `_.escape` to convert characters to HTML entities.
  413. *
  414. * @private
  415. * @param {string} chr The matched character to escape.
  416. * @returns {string} Returns the escaped character.
  417. */
  418. function escapeHtmlChar(chr) {
  419. return htmlEscapes[chr];
  420. }
  421. /**
  422. * Used by `_.template` to escape characters for inclusion in compiled
  423. * string literals.
  424. *
  425. * @private
  426. * @param {string} chr The matched character to escape.
  427. * @returns {string} Returns the escaped character.
  428. */
  429. function escapeStringChar(chr) {
  430. return '\\' + stringEscapes[chr];
  431. }
  432. /**
  433. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  434. * If `fromRight` is provided elements of `array` are iterated from right to left.
  435. *
  436. * @private
  437. * @param {Array} array The array to search.
  438. * @param {number} fromIndex The index to search from.
  439. * @param {boolean} [fromRight] Specify iterating from right to left.
  440. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  441. */
  442. function indexOfNaN(array, fromIndex, fromRight) {
  443. var length = array.length,
  444. index = fromIndex + (fromRight ? 0 : -1);
  445. while ((fromRight ? index-- : ++index < length)) {
  446. var other = array[index];
  447. if (other !== other) {
  448. return index;
  449. }
  450. }
  451. return -1;
  452. }
  453. /**
  454. * Checks if `value` is a host object in IE < 9.
  455. *
  456. * @private
  457. * @param {*} value The value to check.
  458. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  459. */
  460. var isHostObject = (function() {
  461. try {
  462. Object({ 'toString': 0 } + '');
  463. } catch(e) {
  464. return function() { return false; };
  465. }
  466. return function(value) {
  467. // IE < 9 presents many host objects as `Object` objects that can coerce
  468. // to strings despite having improperly defined `toString` methods.
  469. return typeof value.toString != 'function' && typeof (value + '') == 'string';
  470. };
  471. }());
  472. /**
  473. * Checks if `value` is object-like.
  474. *
  475. * @private
  476. * @param {*} value The value to check.
  477. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  478. */
  479. function isObjectLike(value) {
  480. return (value && typeof value == 'object') || false;
  481. }
  482. /**
  483. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  484. * character code is whitespace.
  485. *
  486. * @private
  487. * @param {number} charCode The character code to inspect.
  488. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  489. */
  490. function isSpace(charCode) {
  491. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  492. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  493. }
  494. /**
  495. * Replaces all `placeholder` elements in `array` with an internal placeholder
  496. * and returns an array of their indexes.
  497. *
  498. * @private
  499. * @param {Array} array The array to modify.
  500. * @param {*} placeholder The placeholder to replace.
  501. * @returns {Array} Returns the new array of placeholder indexes.
  502. */
  503. function replaceHolders(array, placeholder) {
  504. var index = -1,
  505. length = array.length,
  506. resIndex = -1,
  507. result = [];
  508. while (++index < length) {
  509. if (array[index] === placeholder) {
  510. array[index] = PLACEHOLDER;
  511. result[++resIndex] = index;
  512. }
  513. }
  514. return result;
  515. }
  516. /**
  517. * An implementation of `_.uniq` optimized for sorted arrays without support
  518. * for callback shorthands and `this` binding.
  519. *
  520. * @private
  521. * @param {Array} array The array to inspect.
  522. * @param {Function} [iteratee] The function invoked per iteration.
  523. * @returns {Array} Returns the new duplicate-value-free array.
  524. */
  525. function sortedUniq(array, iteratee) {
  526. var seen,
  527. index = -1,
  528. length = array.length,
  529. resIndex = -1,
  530. result = [];
  531. while (++index < length) {
  532. var value = array[index],
  533. computed = iteratee ? iteratee(value, index, array) : value;
  534. if (!index || seen !== computed) {
  535. seen = computed;
  536. result[++resIndex] = value;
  537. }
  538. }
  539. return result;
  540. }
  541. /**
  542. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  543. * character of `string`.
  544. *
  545. * @private
  546. * @param {string} string The string to inspect.
  547. * @returns {number} Returns the index of the first non-whitespace character.
  548. */
  549. function trimmedLeftIndex(string) {
  550. var index = -1,
  551. length = string.length;
  552. while (++index < length && isSpace(string.charCodeAt(index))) {}
  553. return index;
  554. }
  555. /**
  556. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  557. * character of `string`.
  558. *
  559. * @private
  560. * @param {string} string The string to inspect.
  561. * @returns {number} Returns the index of the last non-whitespace character.
  562. */
  563. function trimmedRightIndex(string) {
  564. var index = string.length;
  565. while (index-- && isSpace(string.charCodeAt(index))) {}
  566. return index;
  567. }
  568. /**
  569. * Used by `_.unescape` to convert HTML entities to characters.
  570. *
  571. * @private
  572. * @param {string} chr The matched character to unescape.
  573. * @returns {string} Returns the unescaped character.
  574. */
  575. function unescapeHtmlChar(chr) {
  576. return htmlUnescapes[chr];
  577. }
  578. /*--------------------------------------------------------------------------*/
  579. /**
  580. * Create a new pristine `lodash` function using the given `context` object.
  581. *
  582. * @static
  583. * @memberOf _
  584. * @category Utility
  585. * @param {Object} [context=root] The context object.
  586. * @returns {Function} Returns a new `lodash` function.
  587. * @example
  588. *
  589. * _.mixin({ 'add': function(a, b) { return a + b; } });
  590. *
  591. * var lodash = _.runInContext();
  592. * lodash.mixin({ 'sub': function(a, b) { return a - b; } });
  593. *
  594. * _.isFunction(_.add);
  595. * // => true
  596. * _.isFunction(_.sub);
  597. * // => false
  598. *
  599. * lodash.isFunction(lodash.add);
  600. * // => false
  601. * lodash.isFunction(lodash.sub);
  602. * // => true
  603. *
  604. * // using `context` to mock `Date#getTime` use in `_.now`
  605. * var mock = _.runInContext({
  606. * 'Date': function() {
  607. * return { 'getTime': getTimeMock };
  608. * }
  609. * });
  610. *
  611. * // or creating a suped-up `defer` in Node.js
  612. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  613. */
  614. function runInContext(context) {
  615. // Avoid issues with some ES3 environments that attempt to use values, named
  616. // after built-in constructors like `Object`, for the creation of literals.
  617. // ES5 clears this up by stating that literals must use built-in constructors.
  618. // See https://es5.github.io/#x11.1.5 for more details.
  619. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  620. /** Native constructor references. */
  621. var Array = context.Array,
  622. Date = context.Date,
  623. Error = context.Error,
  624. Function = context.Function,
  625. Math = context.Math,
  626. Number = context.Number,
  627. Object = context.Object,
  628. RegExp = context.RegExp,
  629. String = context.String,
  630. TypeError = context.TypeError;
  631. /** Used for native method references. */
  632. var arrayProto = Array.prototype,
  633. errorProto = Error.prototype,
  634. objectProto = Object.prototype,
  635. stringProto = String.prototype;
  636. /** Used to detect DOM support. */
  637. var document = (document = context.window) && document.document;
  638. /** Used to resolve the decompiled source of functions. */
  639. var fnToString = Function.prototype.toString;
  640. /** Used to the length of n-tuples for `_.unzip`. */
  641. var getLength = baseProperty('length');
  642. /** Used to check objects for own properties. */
  643. var hasOwnProperty = objectProto.hasOwnProperty;
  644. /** Used to generate unique IDs. */
  645. var idCounter = 0;
  646. /**
  647. * Used to resolve the `toStringTag` of values.
  648. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
  649. * for more details.
  650. */
  651. var objToString = objectProto.toString;
  652. /** Used to restore the original `_` reference in `_.noConflict`. */
  653. var oldDash = context._;
  654. /** Used to detect if a method is native. */
  655. var reNative = RegExp('^' +
  656. escapeRegExp(objToString)
  657. .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  658. );
  659. /** Native method references. */
  660. var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer,
  661. bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
  662. ceil = Math.ceil,
  663. clearTimeout = context.clearTimeout,
  664. floor = Math.floor,
  665. getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
  666. push = arrayProto.push,
  667. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  668. Set = isNative(Set = context.Set) && Set,
  669. setTimeout = context.setTimeout,
  670. splice = arrayProto.splice,
  671. Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
  672. WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap;
  673. /** Used to clone array buffers. */
  674. var Float64Array = (function() {
  675. // Safari 5 errors when using an array buffer to initialize a typed array
  676. // where the array buffer's `byteLength` is not a multiple of the typed
  677. // array's `BYTES_PER_ELEMENT`.
  678. try {
  679. var func = isNative(func = context.Float64Array) && func,
  680. result = new func(new ArrayBuffer(10), 0, 1) && func;
  681. } catch(e) {}
  682. return result;
  683. }());
  684. /* Native method references for those with the same name as other `lodash` methods. */
  685. var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
  686. nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
  687. nativeIsFinite = context.isFinite,
  688. nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
  689. nativeMax = Math.max,
  690. nativeMin = Math.min,
  691. nativeNow = isNative(nativeNow = Date.now) && nativeNow,
  692. nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite,
  693. nativeParseInt = context.parseInt,
  694. nativeRandom = Math.random;
  695. /** Used as references for `-Infinity` and `Infinity`. */
  696. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  697. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  698. /** Used as references for the maximum length and index of an array. */
  699. var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
  700. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  701. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  702. /** Used as the size, in bytes, of each `Float64Array` element. */
  703. var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
  704. /**
  705. * Used as the maximum length of an array-like value.
  706. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  707. * for more details.
  708. */
  709. var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
  710. /** Used to store function metadata. */
  711. var metaMap = WeakMap && new WeakMap;
  712. /** Used to lookup a type array constructors by `toStringTag`. */
  713. var ctorByTag = {};
  714. ctorByTag[float32Tag] = context.Float32Array;
  715. ctorByTag[float64Tag] = context.Float64Array;
  716. ctorByTag[int8Tag] = context.Int8Array;
  717. ctorByTag[int16Tag] = context.Int16Array;
  718. ctorByTag[int32Tag] = context.Int32Array;
  719. ctorByTag[uint8Tag] = context.Uint8Array;
  720. ctorByTag[uint8ClampedTag] = context.Uint8ClampedArray;
  721. ctorByTag[uint16Tag] = context.Uint16Array;
  722. ctorByTag[uint32Tag] = context.Uint32Array;
  723. /** Used to avoid iterating over non-enumerable properties in IE < 9. */
  724. var nonEnumProps = {};
  725. nonEnumProps[arrayTag] = nonEnumProps[dateTag] = nonEnumProps[numberTag] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  726. nonEnumProps[boolTag] = nonEnumProps[stringTag] = { 'constructor': true, 'toString': true, 'valueOf': true };
  727. nonEnumProps[errorTag] = nonEnumProps[funcTag] = nonEnumProps[regexpTag] = { 'constructor': true, 'toString': true };
  728. nonEnumProps[objectTag] = { 'constructor': true };
  729. arrayEach(shadowProps, function(key) {
  730. for (var tag in nonEnumProps) {
  731. if (hasOwnProperty.call(nonEnumProps, tag)) {
  732. var props = nonEnumProps[tag];
  733. props[key] = hasOwnProperty.call(props, key);
  734. }
  735. }
  736. });
  737. /*------------------------------------------------------------------------*/
  738. /**
  739. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  740. * Methods that operate on and return arrays, collections, and functions can
  741. * be chained together. Methods that return a boolean or single value will
  742. * automatically end the chain returning the unwrapped value. Explicit chaining
  743. * may be enabled using `_.chain`. The execution of chained methods is lazy,
  744. * that is, execution is deferred until `_#value` is implicitly or explicitly
  745. * called.
  746. *
  747. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  748. * fusion is an optimization that merges iteratees to avoid creating intermediate
  749. * arrays and reduce the number of iteratee executions.
  750. *
  751. * Chaining is supported in custom builds as long as the `_#value` method is
  752. * directly or indirectly included in the build.
  753. *
  754. * In addition to lodash methods, wrappers also have the following `Array` methods:
  755. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
  756. * and `unshift`
  757. *
  758. * The wrapper methods that support shortcut fusion are:
  759. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  760. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  761. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  762. * and `where`
  763. *
  764. * The chainable wrapper methods are:
  765. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  766. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  767. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
  768. * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
  769. * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
  770. * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
  771. * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
  772. * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
  773. * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  774. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  775. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
  776. * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
  777. * `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
  778. * `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
  779. * `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
  780. * `without`, `wrap`, `xor`, `zip`, and `zipObject`
  781. *
  782. * The wrapper methods that are **not** chainable by default are:
  783. * `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
  784. * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
  785. * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
  786. * `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
  787. * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
  788. * `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
  789. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
  790. * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
  791. * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
  792. * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
  793. * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
  794. * `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
  795. * `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
  796. *
  797. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  798. * otherwise an unwrapped value is returned.
  799. *
  800. * @name _
  801. * @constructor
  802. * @category Chain
  803. * @param {*} value The value to wrap in a `lodash` instance.
  804. * @returns {Object} Returns the new `lodash` wrapper instance.
  805. * @example
  806. *
  807. * var wrapped = _([1, 2, 3]);
  808. *
  809. * // returns an unwrapped value
  810. * wrapped.reduce(function(sum, n) {
  811. * return sum + n;
  812. * });
  813. * // => 6
  814. *
  815. * // returns a wrapped value
  816. * var squares = wrapped.map(function(n) {
  817. * return n * n;
  818. * });
  819. *
  820. * _.isArray(squares);
  821. * // => false
  822. *
  823. * _.isArray(squares.value());
  824. * // => true
  825. */
  826. function lodash(value) {
  827. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  828. if (value instanceof LodashWrapper) {
  829. return value;
  830. }
  831. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  832. return wrapperClone(value);
  833. }
  834. }
  835. return new LodashWrapper(value);
  836. }
  837. /**
  838. * The function whose prototype all chaining wrappers inherit from.
  839. *
  840. * @private
  841. */
  842. function baseLodash() {
  843. // No operation performed.
  844. }
  845. /**
  846. * The base constructor for creating `lodash` wrapper objects.
  847. *
  848. * @private
  849. * @param {*} value The value to wrap.
  850. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  851. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  852. */
  853. function LodashWrapper(value, chainAll, actions) {
  854. this.__wrapped__ = value;
  855. this.__actions__ = actions || [];
  856. this.__chain__ = !!chainAll;
  857. }
  858. /**
  859. * An object environment feature flags.
  860. *
  861. * @static
  862. * @memberOf _
  863. * @type Object
  864. */
  865. var support = lodash.support = {};
  866. (function(x) {
  867. var Ctor = function() { this.x = 1; },
  868. object = { '0': 1, 'length': 1 },
  869. props = [];
  870. Ctor.prototype = { 'valueOf': 1, 'y': 1 };
  871. for (var key in new Ctor) { props.push(key); }
  872. /**
  873. * Detect if the `toStringTag` of `arguments` objects is resolvable
  874. * (all but Firefox < 4, IE < 9).
  875. *
  876. * @memberOf _.support
  877. * @type boolean
  878. */
  879. support.argsTag = objToString.call(arguments) == argsTag;
  880. /**
  881. * Detect if `name` or `message` properties of `Error.prototype` are
  882. * enumerable by default (IE < 9, Safari < 5.1).
  883. *
  884. * @memberOf _.support
  885. * @type boolean
  886. */
  887. support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') ||
  888. propertyIsEnumerable.call(errorProto, 'name');
  889. /**
  890. * Detect if `prototype` properties are enumerable by default.
  891. *
  892. * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
  893. * (if the prototype or a property on the prototype has been set)
  894. * incorrectly set the `[[Enumerable]]` value of a function's `prototype`
  895. * property to `true`.
  896. *
  897. * @memberOf _.support
  898. * @type boolean
  899. */
  900. support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype');
  901. /**
  902. * Detect if functions can be decompiled by `Function#toString`
  903. * (all but Firefox OS certified apps, older Opera mobile browsers, and
  904. * the PlayStation 3; forced `false` for Windows 8 apps).
  905. *
  906. * @memberOf _.support
  907. * @type boolean
  908. */
  909. support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
  910. /**
  911. * Detect if `Function#name` is supported (all but IE).
  912. *
  913. * @memberOf _.support
  914. * @type boolean
  915. */
  916. support.funcNames = typeof Function.name == 'string';
  917. /**
  918. * Detect if the `toStringTag` of DOM nodes is resolvable (all but IE < 9).
  919. *
  920. * @memberOf _.support
  921. * @type boolean
  922. */
  923. support.nodeTag = objToString.call(document) != objectTag;
  924. /**
  925. * Detect if string indexes are non-enumerable
  926. * (IE < 9, RingoJS, Rhino, Narwhal).
  927. *
  928. * @memberOf _.support
  929. * @type boolean
  930. */
  931. support.nonEnumStrings = !propertyIsEnumerable.call('x', 0);
  932. /**
  933. * Detect if properties shadowing those on `Object.prototype` are
  934. * non-enumerable.
  935. *
  936. * In IE < 9 an object's own properties, shadowing non-enumerable ones,
  937. * are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
  938. *
  939. * @memberOf _.support
  940. * @type boolean
  941. */
  942. support.nonEnumShadows = !/valueOf/.test(props);
  943. /**
  944. * Detect if own properties are iterated after inherited properties (IE < 9).
  945. *
  946. * @memberOf _.support
  947. * @type boolean
  948. */
  949. support.ownLast = props[0] != 'x';
  950. /**
  951. * Detect if `Array#shift` and `Array#splice` augment array-like objects
  952. * correctly.
  953. *
  954. * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array `shift()`
  955. * and `splice()` functions that fail to remove the last element, `value[0]`,
  956. * of array-like objects even though the `length` property is set to `0`.
  957. * The `shift()` method is buggy in compatibility modes of IE 8, while `splice()`
  958. * is buggy regardless of mode in IE < 9.
  959. *
  960. * @memberOf _.support
  961. * @type boolean
  962. */
  963. support.spliceObjects = (splice.call(object, 0, 1), !object[0]);
  964. /**
  965. * Detect lack of support for accessing string characters by index.
  966. *
  967. * IE < 8 can't access characters by index. IE 8 can only access characters
  968. * by index on string literals, not string objects.
  969. *
  970. * @memberOf _.support
  971. * @type boolean
  972. */
  973. support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
  974. /**
  975. * Detect if the DOM is supported.
  976. *
  977. * @memberOf _.support
  978. * @type boolean
  979. */
  980. try {
  981. support.dom = document.createDocumentFragment().nodeType === 11;
  982. } catch(e) {
  983. support.dom = false;
  984. }
  985. /**
  986. * Detect if `arguments` object indexes are non-enumerable.
  987. *
  988. * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
  989. * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
  990. * `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
  991. * checks for indexes that exceed their function's formal parameters with
  992. * associated values of `0`.
  993. *
  994. * @memberOf _.support
  995. * @type boolean
  996. */
  997. try {
  998. support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
  999. } catch(e) {
  1000. support.nonEnumArgs = true;
  1001. }
  1002. }(0, 0));
  1003. /**
  1004. * By default, the template delimiters used by lodash are like those in
  1005. * embedded Ruby (ERB). Change the following template settings to use
  1006. * alternative delimiters.
  1007. *
  1008. * @static
  1009. * @memberOf _
  1010. * @type Object
  1011. */
  1012. lodash.templateSettings = {
  1013. /**
  1014. * Used to detect `data` property values to be HTML-escaped.
  1015. *
  1016. * @memberOf _.templateSettings
  1017. * @type RegExp
  1018. */
  1019. 'escape': reEscape,
  1020. /**
  1021. * Used to detect code to be evaluated.
  1022. *
  1023. * @memberOf _.templateSettings
  1024. * @type RegExp
  1025. */
  1026. 'evaluate': reEvaluate,
  1027. /**
  1028. * Used to detect `data` property values to inject.
  1029. *
  1030. * @memberOf _.templateSettings
  1031. * @type RegExp
  1032. */
  1033. 'interpolate': reInterpolate,
  1034. /**
  1035. * Used to reference the data object in the template text.
  1036. *
  1037. * @memberOf _.templateSettings
  1038. * @type string
  1039. */
  1040. 'variable': '',
  1041. /**
  1042. * Used to import variables into the compiled template.
  1043. *
  1044. * @memberOf _.templateSettings
  1045. * @type Object
  1046. */
  1047. 'imports': {
  1048. /**
  1049. * A reference to the `lodash` function.
  1050. *
  1051. * @memberOf _.templateSettings.imports
  1052. * @type Function
  1053. */
  1054. '_': lodash
  1055. }
  1056. };
  1057. /*------------------------------------------------------------------------*/
  1058. /**
  1059. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1060. *
  1061. * @private
  1062. * @param {*} value The value to wrap.
  1063. */
  1064. function LazyWrapper(value) {
  1065. this.__wrapped__ = value;
  1066. this.__actions__ = null;
  1067. this.__dir__ = 1;
  1068. this.__dropCount__ = 0;
  1069. this.__filtered__ = false;
  1070. this.__iteratees__ = null;
  1071. this.__takeCount__ = POSITIVE_INFINITY;
  1072. this.__views__ = null;
  1073. }
  1074. /**
  1075. * Creates a clone of the lazy wrapper object.
  1076. *
  1077. * @private
  1078. * @name clone
  1079. * @memberOf LazyWrapper
  1080. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1081. */
  1082. function lazyClone() {
  1083. var actions = this.__actions__,
  1084. iteratees = this.__iteratees__,
  1085. views = this.__views__,
  1086. result = new LazyWrapper(this.__wrapped__);
  1087. result.__actions__ = actions ? arrayCopy(actions) : null;
  1088. result.__dir__ = this.__dir__;
  1089. result.__dropCount__ = this.__dropCount__;
  1090. result.__filtered__ = this.__filtered__;
  1091. result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
  1092. result.__takeCount__ = this.__takeCount__;
  1093. result.__views__ = views ? arrayCopy(views) : null;
  1094. return result;
  1095. }
  1096. /**
  1097. * Reverses the direction of lazy iteration.
  1098. *
  1099. * @private
  1100. * @name reverse
  1101. * @memberOf LazyWrapper
  1102. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1103. */
  1104. function lazyReverse() {
  1105. if (this.__filtered__) {
  1106. var result = new LazyWrapper(this);
  1107. result.__dir__ = -1;
  1108. result.__filtered__ = true;
  1109. } else {
  1110. result = this.clone();
  1111. result.__dir__ *= -1;
  1112. }
  1113. return result;
  1114. }
  1115. /**
  1116. * Extracts the unwrapped value from its lazy wrapper.
  1117. *
  1118. * @private
  1119. * @name value
  1120. * @memberOf LazyWrapper
  1121. * @returns {*} Returns the unwrapped value.
  1122. */
  1123. function lazyValue() {
  1124. var array = this.__wrapped__.value();
  1125. if (!isArray(array)) {
  1126. return baseWrapperValue(array, this.__actions__);
  1127. }
  1128. var dir = this.__dir__,
  1129. isRight = dir < 0,
  1130. view = getView(0, array.length, this.__views__),
  1131. start = view.start,
  1132. end = view.end,
  1133. length = end - start,
  1134. dropCount = this.__dropCount__,
  1135. takeCount = nativeMin(length, this.__takeCount__),
  1136. index = isRight ? end : start - 1,
  1137. iteratees = this.__iteratees__,
  1138. iterLength = iteratees ? iteratees.length : 0,
  1139. resIndex = 0,
  1140. result = [];
  1141. outer:
  1142. while (length-- && resIndex < takeCount) {
  1143. index += dir;
  1144. var iterIndex = -1,
  1145. value = array[index];
  1146. while (++iterIndex < iterLength) {
  1147. var data = iteratees[iterIndex],
  1148. iteratee = data.iteratee,
  1149. type = data.type;
  1150. if (type != LAZY_DROP_WHILE_FLAG) {
  1151. var computed = iteratee(value);
  1152. } else {
  1153. data.done = data.done && (isRight ? index < data.index : index > data.index);
  1154. data.index = index;
  1155. computed = data.done || (data.done = !iteratee(value));
  1156. }
  1157. if (type == LAZY_MAP_FLAG) {
  1158. value = computed;
  1159. } else if (!computed) {
  1160. if (type == LAZY_TAKE_WHILE_FLAG) {
  1161. break outer;
  1162. } else {
  1163. continue outer;
  1164. }
  1165. }
  1166. }
  1167. if (dropCount) {
  1168. dropCount--;
  1169. } else {
  1170. result[resIndex++] = value;
  1171. }
  1172. }
  1173. return result;
  1174. }
  1175. /*------------------------------------------------------------------------*/
  1176. /**
  1177. * Creates a cache object to store key/value pairs.
  1178. *
  1179. * @private
  1180. * @static
  1181. * @name Cache
  1182. * @memberOf _.memoize
  1183. */
  1184. function MapCache() {
  1185. this.__data__ = {};
  1186. }
  1187. /**
  1188. * Removes `key` and its value from the cache.
  1189. *
  1190. * @private
  1191. * @name delete
  1192. * @memberOf _.memoize.Cache
  1193. * @param {string} key The key of the value to remove.
  1194. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1195. */
  1196. function mapDelete(key) {
  1197. return this.has(key) && delete this.__data__[key];
  1198. }
  1199. /**
  1200. * Gets the cached value for `key`.
  1201. *
  1202. * @private
  1203. * @name get
  1204. * @memberOf _.memoize.Cache
  1205. * @param {string} key The key of the value to get.
  1206. * @returns {*} Returns the cached value.
  1207. */
  1208. function mapGet(key) {
  1209. return key == '__proto__' ? undefined : this.__data__[key];
  1210. }
  1211. /**
  1212. * Checks if a cached value for `key` exists.
  1213. *
  1214. * @private
  1215. * @name has
  1216. * @memberOf _.memoize.Cache
  1217. * @param {string} key The key of the entry to check.
  1218. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1219. */
  1220. function mapHas(key) {
  1221. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1222. }
  1223. /**
  1224. * Adds `value` to `key` of the cache.
  1225. *
  1226. * @private
  1227. * @name set
  1228. * @memberOf _.memoize.Cache
  1229. * @param {string} key The key of the value to cache.
  1230. * @param {*} value The value to cache.
  1231. * @returns {Object} Returns the cache object.
  1232. */
  1233. function mapSet(key, value) {
  1234. if (key != '__proto__') {
  1235. this.__data__[key] = value;
  1236. }
  1237. return this;
  1238. }
  1239. /*------------------------------------------------------------------------*/
  1240. /**
  1241. *
  1242. * Creates a cache object to store unique values.
  1243. *
  1244. * @private
  1245. * @param {Array} [values] The values to cache.
  1246. */
  1247. function SetCache(values) {
  1248. var length = values ? values.length : 0;
  1249. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1250. while (length--) {
  1251. this.push(values[length]);
  1252. }
  1253. }
  1254. /**
  1255. * Checks if `value` is in `cache` mimicking the return signature of
  1256. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1257. *
  1258. * @private
  1259. * @param {Object} cache The cache to search.
  1260. * @param {*} value The value to search for.
  1261. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1262. */
  1263. function cacheIndexOf(cache, value) {
  1264. var data = cache.data,
  1265. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1266. return result ? 0 : -1;
  1267. }
  1268. /**
  1269. * Adds `value` to the cache.
  1270. *
  1271. * @private
  1272. * @name push
  1273. * @memberOf SetCache
  1274. * @param {*} value The value to cache.
  1275. */
  1276. function cachePush(value) {
  1277. var data = this.data;
  1278. if (typeof value == 'string' || isObject(value)) {
  1279. data.set.add(value);
  1280. } else {
  1281. data.hash[value] = true;
  1282. }
  1283. }
  1284. /*------------------------------------------------------------------------*/
  1285. /**
  1286. * Copies the values of `source` to `array`.
  1287. *
  1288. * @private
  1289. * @param {Array} source The array to copy values from.
  1290. * @param {Array} [array=[]] The array to copy values to.
  1291. * @returns {Array} Returns `array`.
  1292. */
  1293. function arrayCopy(source, array) {
  1294. var index = -1,
  1295. length = source.length;
  1296. array || (array = Array(length));
  1297. while (++index < length) {
  1298. array[index] = source[index];
  1299. }
  1300. return array;
  1301. }
  1302. /**
  1303. * A specialized version of `_.forEach` for arrays without support for callback
  1304. * shorthands or `this` binding.
  1305. *
  1306. * @private
  1307. * @param {Array} array The array to iterate over.
  1308. * @param {Function} iteratee The function invoked per iteration.
  1309. * @returns {Array} Returns `array`.
  1310. */
  1311. function arrayEach(array, iteratee) {
  1312. var index = -1,
  1313. length = array.length;
  1314. while (++index < length) {
  1315. if (iteratee(array[index], index, array) === false) {
  1316. break;
  1317. }
  1318. }
  1319. return array;
  1320. }
  1321. /**
  1322. * A specialized version of `_.forEachRight` for arrays without support for
  1323. * callback shorthands or `this` binding.
  1324. *
  1325. * @private
  1326. * @param {Array} array The array to iterate over.
  1327. * @param {Function} iteratee The function invoked per iteration.
  1328. * @returns {Array} Returns `array`.
  1329. */
  1330. function arrayEachRight(array, iteratee) {
  1331. var length = array.length;
  1332. while (length--) {
  1333. if (