PageRenderTime 28ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/3.7.0/lodash.js

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