PageRenderTime 28ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 0ms

/files/lodash/3.8.0/lodash.js

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