PageRenderTime 48ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/files/lodash/3.6.0/lodash.js

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