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

/files/lodash/3.3.0/lodash.compat.js

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