PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/files/lodash/3.2.0/lodash.compat.js

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