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

/files/lodash/3.9.3/lodash.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1517 lines | 1483 code | 13 blank | 21 comment | 0 complexity | c4ad16b54512458de542e589e3645577 MD5 | raw file
  1. /**
  2. * @license
  3. * lodash 3.9.3 (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.9.3';
  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 detect unsigned integer values. */
  100. var reIsUint = /^\d+$/;
  101. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  102. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  103. /** Used to ensure capturing order of template delimiters. */
  104. var reNoMatch = /($^)/;
  105. /** Used to match unescaped characters in compiled string literals. */
  106. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  107. /** Used to match words to create compound words. */
  108. var reWords = (function() {
  109. var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
  110. lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
  111. return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
  112. }());
  113. /** Used to detect and test for whitespace. */
  114. var whitespace = (
  115. // Basic whitespace characters.
  116. ' \t\x0b\f\xa0\ufeff' +
  117. // Line terminators.
  118. '\n\r\u2028\u2029' +
  119. // Unicode category "Zs" space separators.
  120. '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
  121. );
  122. /** Used to assign default `context` object properties. */
  123. var contextProps = [
  124. 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  125. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
  126. 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'document',
  127. 'isFinite', 'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
  128. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', 'window'
  129. ];
  130. /** Used to make template sourceURLs easier to identify. */
  131. var templateCounter = -1;
  132. /** Used to identify `toStringTag` values of typed arrays. */
  133. var typedArrayTags = {};
  134. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  135. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  136. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  137. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  138. typedArrayTags[uint32Tag] = true;
  139. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  140. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  141. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  142. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  143. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  144. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  145. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  146. /** Used to identify `toStringTag` values supported by `_.clone`. */
  147. var cloneableTags = {};
  148. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  149. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  150. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  151. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  152. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  153. cloneableTags[numberTag] = cloneableTags[objectTag] =
  154. cloneableTags[regexpTag] = cloneableTags[stringTag] =
  155. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  156. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  157. cloneableTags[errorTag] = cloneableTags[funcTag] =
  158. cloneableTags[mapTag] = cloneableTags[setTag] =
  159. cloneableTags[weakMapTag] = false;
  160. /** Used as an internal `_.debounce` options object by `_.throttle`. */
  161. var debounceOptions = {
  162. 'leading': false,
  163. 'maxWait': 0,
  164. 'trailing': false
  165. };
  166. /** Used to map latin-1 supplementary letters to basic latin letters. */
  167. var deburredLetters = {
  168. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  169. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  170. '\xc7': 'C', '\xe7': 'c',
  171. '\xd0': 'D', '\xf0': 'd',
  172. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  173. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  174. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  175. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  176. '\xd1': 'N', '\xf1': 'n',
  177. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  178. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  179. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  180. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  181. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  182. '\xc6': 'Ae', '\xe6': 'ae',
  183. '\xde': 'Th', '\xfe': 'th',
  184. '\xdf': 'ss'
  185. };
  186. /** Used to map characters to HTML entities. */
  187. var htmlEscapes = {
  188. '&': '&amp;',
  189. '<': '&lt;',
  190. '>': '&gt;',
  191. '"': '&quot;',
  192. "'": '&#39;',
  193. '`': '&#96;'
  194. };
  195. /** Used to map HTML entities to characters. */
  196. var htmlUnescapes = {
  197. '&amp;': '&',
  198. '&lt;': '<',
  199. '&gt;': '>',
  200. '&quot;': '"',
  201. '&#39;': "'",
  202. '&#96;': '`'
  203. };
  204. /** Used to determine if values are of the language type `Object`. */
  205. var objectTypes = {
  206. 'function': true,
  207. 'object': true
  208. };
  209. /** Used to escape characters for inclusion in compiled string literals. */
  210. var stringEscapes = {
  211. '\\': '\\',
  212. "'": "'",
  213. '\n': 'n',
  214. '\r': 'r',
  215. '\u2028': 'u2028',
  216. '\u2029': 'u2029'
  217. };
  218. /** Detect free variable `exports`. */
  219. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  220. /** Detect free variable `module`. */
  221. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  222. /** Detect free variable `global` from Node.js. */
  223. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
  224. /** Detect free variable `self`. */
  225. var freeSelf = objectTypes[typeof self] && self && self.Object && self;
  226. /** Detect free variable `window`. */
  227. var freeWindow = objectTypes[typeof window] && window && window.Object && window;
  228. /** Detect the popular CommonJS extension `module.exports`. */
  229. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  230. /**
  231. * Used as a reference to the global object.
  232. *
  233. * The `this` value is used if it's the global object to avoid Greasemonkey's
  234. * restricted `window` object, otherwise the `window` object is used.
  235. */
  236. var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
  237. /*--------------------------------------------------------------------------*/
  238. /**
  239. * The base implementation of `compareAscending` which compares values and
  240. * sorts them in ascending order without guaranteeing a stable sort.
  241. *
  242. * @private
  243. * @param {*} value The value to compare.
  244. * @param {*} other The other value to compare.
  245. * @returns {number} Returns the sort order indicator for `value`.
  246. */
  247. function baseCompareAscending(value, other) {
  248. if (value !== other) {
  249. var valIsNull = value === null,
  250. valIsUndef = value === undefined,
  251. valIsReflexive = value === value;
  252. var othIsNull = other === null,
  253. othIsUndef = other === undefined,
  254. othIsReflexive = other === other;
  255. if ((value > other && !othIsNull) || !valIsReflexive ||
  256. (valIsNull && !othIsUndef && othIsReflexive) ||
  257. (valIsUndef && othIsReflexive)) {
  258. return 1;
  259. }
  260. if ((value < other && !valIsNull) || !othIsReflexive ||
  261. (othIsNull && !valIsUndef && valIsReflexive) ||
  262. (othIsUndef && valIsReflexive)) {
  263. return -1;
  264. }
  265. }
  266. return 0;
  267. }
  268. /**
  269. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  270. * support for callback shorthands and `this` binding.
  271. *
  272. * @private
  273. * @param {Array} array The array to search.
  274. * @param {Function} predicate The function invoked per iteration.
  275. * @param {boolean} [fromRight] Specify iterating from right to left.
  276. * @returns {number} Returns the index of the matched value, else `-1`.
  277. */
  278. function baseFindIndex(array, predicate, fromRight) {
  279. var length = array.length,
  280. index = fromRight ? length : -1;
  281. while ((fromRight ? index-- : ++index < length)) {
  282. if (predicate(array[index], index, array)) {
  283. return index;
  284. }
  285. }
  286. return -1;
  287. }
  288. /**
  289. * The base implementation of `_.indexOf` without support for binary searches.
  290. *
  291. * @private
  292. * @param {Array} array The array to search.
  293. * @param {*} value The value to search for.
  294. * @param {number} fromIndex The index to search from.
  295. * @returns {number} Returns the index of the matched value, else `-1`.
  296. */
  297. function baseIndexOf(array, value, fromIndex) {
  298. if (value !== value) {
  299. return indexOfNaN(array, fromIndex);
  300. }
  301. var index = fromIndex - 1,
  302. length = array.length;
  303. while (++index < length) {
  304. if (array[index] === value) {
  305. return index;
  306. }
  307. }
  308. return -1;
  309. }
  310. /**
  311. * The base implementation of `_.isFunction` without support for environments
  312. * with incorrect `typeof` results.
  313. *
  314. * @private
  315. * @param {*} value The value to check.
  316. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  317. */
  318. function baseIsFunction(value) {
  319. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
  320. // See https://github.com/jashkenas/underscore/issues/1621 for more details.
  321. return typeof value == 'function' || false;
  322. }
  323. /**
  324. * Converts `value` to a string if it's not one. An empty string is returned
  325. * for `null` or `undefined` values.
  326. *
  327. * @private
  328. * @param {*} value The value to process.
  329. * @returns {string} Returns the string.
  330. */
  331. function baseToString(value) {
  332. if (typeof value == 'string') {
  333. return value;
  334. }
  335. return value == null ? '' : (value + '');
  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. /**
  575. * Create a new pristine `lodash` function using the given `context` object.
  576. *
  577. * @static
  578. * @memberOf _
  579. * @category Utility
  580. * @param {Object} [context=root] The context object.
  581. * @returns {Function} Returns a new `lodash` function.
  582. * @example
  583. *
  584. * _.mixin({ 'foo': _.constant('foo') });
  585. *
  586. * var lodash = _.runInContext();
  587. * lodash.mixin({ 'bar': lodash.constant('bar') });
  588. *
  589. * _.isFunction(_.foo);
  590. * // => true
  591. * _.isFunction(_.bar);
  592. * // => false
  593. *
  594. * lodash.isFunction(lodash.foo);
  595. * // => false
  596. * lodash.isFunction(lodash.bar);
  597. * // => true
  598. *
  599. * // using `context` to mock `Date#getTime` use in `_.now`
  600. * var mock = _.runInContext({
  601. * 'Date': function() {
  602. * return { 'getTime': getTimeMock };
  603. * }
  604. * });
  605. *
  606. * // or creating a suped-up `defer` in Node.js
  607. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  608. */
  609. function runInContext(context) {
  610. // Avoid issues with some ES3 environments that attempt to use values, named
  611. // after built-in constructors like `Object`, for the creation of literals.
  612. // ES5 clears this up by stating that literals must use built-in constructors.
  613. // See https://es5.github.io/#x11.1.5 for more details.
  614. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  615. /** Native constructor references. */
  616. var Array = context.Array,
  617. Date = context.Date,
  618. Error = context.Error,
  619. Function = context.Function,
  620. Math = context.Math,
  621. Number = context.Number,
  622. Object = context.Object,
  623. RegExp = context.RegExp,
  624. String = context.String,
  625. TypeError = context.TypeError;
  626. /** Used for native method references. */
  627. var arrayProto = Array.prototype,
  628. objectProto = Object.prototype,
  629. stringProto = String.prototype;
  630. /** Used to detect DOM support. */
  631. var document = (document = context.window) ? document.document : null;
  632. /** Used to resolve the decompiled source of functions. */
  633. var fnToString = Function.prototype.toString;
  634. /** Used to check objects for own properties. */
  635. var hasOwnProperty = objectProto.hasOwnProperty;
  636. /** Used to generate unique IDs. */
  637. var idCounter = 0;
  638. /**
  639. * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
  640. * of values.
  641. */
  642. var objToString = objectProto.toString;
  643. /** Used to restore the original `_` reference in `_.noConflict`. */
  644. var oldDash = context._;
  645. /** Used to detect if a method is native. */
  646. var reIsNative = RegExp('^' +
  647. escapeRegExp(fnToString.call(hasOwnProperty))
  648. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  649. );
  650. /** Native method references. */
  651. var ArrayBuffer = getNative(context, 'ArrayBuffer'),
  652. bufferSlice = getNative(ArrayBuffer && new ArrayBuffer(0), 'slice'),
  653. ceil = Math.ceil,
  654. clearTimeout = context.clearTimeout,
  655. floor = Math.floor,
  656. getPrototypeOf = getNative(Object, 'getPrototypeOf'),
  657. parseFloat = context.parseFloat,
  658. push = arrayProto.push,
  659. Set = getNative(context, 'Set'),
  660. setTimeout = context.setTimeout,
  661. splice = arrayProto.splice,
  662. Uint8Array = getNative(context, 'Uint8Array'),
  663. WeakMap = getNative(context, 'WeakMap');
  664. /** Used to clone array buffers. */
  665. var Float64Array = (function() {
  666. // Safari 5 errors when using an array buffer to initialize a typed array
  667. // where the array buffer's `byteLength` is not a multiple of the typed
  668. // array's `BYTES_PER_ELEMENT`.
  669. try {
  670. var func = getNative(context, 'Float64Array'),
  671. result = new func(new ArrayBuffer(10), 0, 1) && func;
  672. } catch(e) {}
  673. return result || null;
  674. }());
  675. /* Native method references for those with the same name as other `lodash` methods. */
  676. var nativeCreate = getNative(Object, 'create'),
  677. nativeIsArray = getNative(Array, 'isArray'),
  678. nativeIsFinite = context.isFinite,
  679. nativeKeys = getNative(Object, 'keys'),
  680. nativeMax = Math.max,
  681. nativeMin = Math.min,
  682. nativeNow = getNative(Date, 'now'),
  683. nativeNumIsFinite = getNative(Number, 'isFinite'),
  684. nativeParseInt = context.parseInt,
  685. nativeRandom = Math.random;
  686. /** Used as references for `-Infinity` and `Infinity`. */
  687. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  688. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  689. /** Used as references for the maximum length and index of an array. */
  690. var MAX_ARRAY_LENGTH = 4294967295,
  691. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  692. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  693. /** Used as the size, in bytes, of each `Float64Array` element. */
  694. var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
  695. /**
  696. * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  697. * of an array-like value.
  698. */
  699. var MAX_SAFE_INTEGER = 9007199254740991;
  700. /** Used to store function metadata. */
  701. var metaMap = WeakMap && new WeakMap;
  702. /** Used to lookup unminified function names. */
  703. var realNames = {};
  704. /*------------------------------------------------------------------------*/
  705. /**
  706. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  707. * Methods that operate on and return arrays, collections, and functions can
  708. * be chained together. Methods that return a boolean or single value will
  709. * automatically end the chain returning the unwrapped value. Explicit chaining
  710. * may be enabled using `_.chain`. The execution of chained methods is lazy,
  711. * that is, execution is deferred until `_#value` is implicitly or explicitly
  712. * called.
  713. *
  714. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  715. * fusion is an optimization that merges iteratees to avoid creating intermediate
  716. * arrays and reduce the number of iteratee executions.
  717. *
  718. * Chaining is supported in custom builds as long as the `_#value` method is
  719. * directly or indirectly included in the build.
  720. *
  721. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  722. *
  723. * The wrapper `Array` methods are:
  724. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
  725. * `splice`, and `unshift`
  726. *
  727. * The wrapper `String` methods are:
  728. * `replace` and `split`
  729. *
  730. * The wrapper methods that support shortcut fusion are:
  731. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  732. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  733. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  734. * and `where`
  735. *
  736. * The chainable wrapper methods are:
  737. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  738. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  739. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
  740. * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
  741. * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
  742. * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
  743. * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
  744. * `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  745. * `memoize`, `merge`, `method`, `methodOf`, `mixin`, `negate`, `omit`, `once`,
  746. * `pairs`, `partial`, `partialRight`, `partition`, `pick`, `plant`, `pluck`,
  747. * `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, `rearg`,
  748. * `reject`, `remove`, `rest`, `restParam`, `reverse`, `set`, `shuffle`,
  749. * `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, `spread`,
  750. * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
  751. * `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
  752. * `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `where`, `without`,
  753. * `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
  754. *
  755. * The wrapper methods that are **not** chainable by default are:
  756. * `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
  757. * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
  758. * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `get`,
  759. * `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`,
  760. * `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
  761. * `isFinite` `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
  762. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
  763. * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lt`, `lte`,
  764. * `max`, `min`, `noConflict`, `noop`, `now`, `pad`, `padLeft`, `padRight`,
  765. * `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`,
  766. * `runInContext`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
  767. * `sortedLastIndex`, `startCase`, `startsWith`, `sum`, `template`, `trim`,
  768. * `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
  769. *
  770. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  771. * otherwise an unwrapped value is returned.
  772. *
  773. * @name _
  774. * @constructor
  775. * @category Chain
  776. * @param {*} value The value to wrap in a `lodash` instance.
  777. * @returns {Object} Returns the new `lodash` wrapper instance.
  778. * @example
  779. *
  780. * var wrapped = _([1, 2, 3]);
  781. *
  782. * // returns an unwrapped value
  783. * wrapped.reduce(function(total, n) {
  784. * return total + n;
  785. * });
  786. * // => 6
  787. *
  788. * // returns a wrapped value
  789. * var squares = wrapped.map(function(n) {
  790. * return n * n;
  791. * });
  792. *
  793. * _.isArray(squares);
  794. * // => false
  795. *
  796. * _.isArray(squares.value());
  797. * // => true
  798. */
  799. function lodash(value) {
  800. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  801. if (value instanceof LodashWrapper) {
  802. return value;
  803. }
  804. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  805. return wrapperClone(value);
  806. }
  807. }
  808. return new LodashWrapper(value);
  809. }
  810. /**
  811. * The function whose prototype all chaining wrappers inherit from.
  812. *
  813. * @private
  814. */
  815. function baseLodash() {
  816. // No operation performed.
  817. }
  818. /**
  819. * The base constructor for creating `lodash` wrapper objects.
  820. *
  821. * @private
  822. * @param {*} value The value to wrap.
  823. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  824. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  825. */
  826. function LodashWrapper(value, chainAll, actions) {
  827. this.__wrapped__ = value;
  828. this.__actions__ = actions || [];
  829. this.__chain__ = !!chainAll;
  830. }
  831. /**
  832. * An object environment feature flags.
  833. *
  834. * @static
  835. * @memberOf _
  836. * @type Object
  837. */
  838. var support = lodash.support = {};
  839. (function(x) {
  840. var Ctor = function() { this.x = x; },
  841. object = { '0': x, 'length': x },
  842. props = [];
  843. Ctor.prototype = { 'valueOf': x, 'y': x };
  844. for (var key in new Ctor) { props.push(key); }
  845. /**
  846. * Detect if the DOM is supported.
  847. *
  848. * @memberOf _.support
  849. * @type boolean
  850. */
  851. try {
  852. support.dom = document.createDocumentFragment().nodeType === 11;
  853. } catch(e) {
  854. support.dom = false;
  855. }
  856. }(1, 0));
  857. /**
  858. * By default, the template delimiters used by lodash are like those in
  859. * embedded Ruby (ERB). Change the following template settings to use
  860. * alternative delimiters.
  861. *
  862. * @static
  863. * @memberOf _
  864. * @type Object
  865. */
  866. lodash.templateSettings = {
  867. /**
  868. * Used to detect `data` property values to be HTML-escaped.
  869. *
  870. * @memberOf _.templateSettings
  871. * @type RegExp
  872. */
  873. 'escape': reEscape,
  874. /**
  875. * Used to detect code to be evaluated.
  876. *
  877. * @memberOf _.templateSettings
  878. * @type RegExp
  879. */
  880. 'evaluate': reEvaluate,
  881. /**
  882. * Used to detect `data` property values to inject.
  883. *
  884. * @memberOf _.templateSettings
  885. * @type RegExp
  886. */
  887. 'interpolate': reInterpolate,
  888. /**
  889. * Used to reference the data object in the template text.
  890. *
  891. * @memberOf _.templateSettings
  892. * @type string
  893. */
  894. 'variable': '',
  895. /**
  896. * Used to import variables into the compiled template.
  897. *
  898. * @memberOf _.templateSettings
  899. * @type Object
  900. */
  901. 'imports': {
  902. /**
  903. * A reference to the `lodash` function.
  904. *
  905. * @memberOf _.templateSettings.imports
  906. * @type Function
  907. */
  908. '_': lodash
  909. }
  910. };
  911. /*------------------------------------------------------------------------*/
  912. /**
  913. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  914. *
  915. * @private
  916. * @param {*} value The value to wrap.
  917. */
  918. function LazyWrapper(value) {
  919. this.__wrapped__ = value;
  920. this.__actions__ = null;
  921. this.__dir__ = 1;
  922. this.__dropCount__ = 0;
  923. this.__filtered__ = false;
  924. this.__iteratees__ = null;
  925. this.__takeCount__ = POSITIVE_INFINITY;
  926. this.__views__ = null;
  927. }
  928. /**
  929. * Creates a clone of the lazy wrapper object.
  930. *
  931. * @private
  932. * @name clone
  933. * @memberOf LazyWrapper
  934. * @returns {Object} Returns the cloned `LazyWrapper` object.
  935. */
  936. function lazyClone() {
  937. var actions = this.__actions__,
  938. iteratees = this.__iteratees__,
  939. views = this.__views__,
  940. result = new LazyWrapper(this.__wrapped__);
  941. result.__actions__ = actions ? arrayCopy(actions) : null;
  942. result.__dir__ = this.__dir__;
  943. result.__filtered__ = this.__filtered__;
  944. result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
  945. result.__takeCount__ = this.__takeCount__;
  946. result.__views__ = views ? arrayCopy(views) : null;
  947. return result;
  948. }
  949. /**
  950. * Reverses the direction of lazy iteration.
  951. *
  952. * @private
  953. * @name reverse
  954. * @memberOf LazyWrapper
  955. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  956. */
  957. function lazyReverse() {
  958. if (this.__filtered__) {
  959. var result = new LazyWrapper(this);
  960. result.__dir__ = -1;
  961. result.__filtered__ = true;
  962. } else {
  963. result = this.clone();
  964. result.__dir__ *= -1;
  965. }
  966. return result;
  967. }
  968. /**
  969. * Extracts the unwrapped value from its lazy wrapper.
  970. *
  971. * @private
  972. * @name value
  973. * @memberOf LazyWrapper
  974. * @returns {*} Returns the unwrapped value.
  975. */
  976. function lazyValue() {
  977. var array = this.__wrapped__.value();
  978. if (!isArray(array)) {
  979. return baseWrapperValue(array, this.__actions__);
  980. }
  981. var dir = this.__dir__,
  982. isRight = dir < 0,
  983. view = getView(0, array.length, this.__views__),
  984. start = view.start,
  985. end = view.end,
  986. length = end - start,
  987. index = isRight ? end : (start - 1),
  988. takeCount = nativeMin(length, this.__takeCount__),
  989. iteratees = this.__iteratees__,
  990. iterLength = iteratees ? iteratees.length : 0,
  991. resIndex = 0,
  992. result = [];
  993. outer:
  994. while (length-- && resIndex < takeCount) {
  995. index += dir;
  996. var iterIndex = -1,
  997. value = array[index];
  998. while (++iterIndex < iterLength) {
  999. var data = iteratees[iterIndex],
  1000. iteratee = data.iteratee,
  1001. type = data.type;
  1002. if (type == LAZY_DROP_WHILE_FLAG) {
  1003. if (data.done && (isRight ? (index > data.index) : (index < data.index))) {
  1004. data.count = 0;
  1005. data.done = false;
  1006. }
  1007. data.index = index;
  1008. if (!data.done) {
  1009. var limit = data.limit;
  1010. if (!(data.done = limit > -1 ? (data.count++ >= limit) : !iteratee(value))) {
  1011. continue outer;
  1012. }
  1013. }
  1014. } else {
  1015. var computed = iteratee(value);
  1016. if (type == LAZY_MAP_FLAG) {
  1017. value = computed;
  1018. } else if (!computed) {
  1019. if (type == LAZY_FILTER_FLAG) {
  1020. continue outer;
  1021. } else {
  1022. break outer;
  1023. }
  1024. }
  1025. }
  1026. }
  1027. result[resIndex++] = value;
  1028. }
  1029. return result;
  1030. }
  1031. /*------------------------------------------------------------------------*/
  1032. /**
  1033. * Creates a cache object to store key/value pairs.
  1034. *
  1035. * @private
  1036. * @static
  1037. * @name Cache
  1038. * @memberOf _.memoize
  1039. */
  1040. function MapCache() {
  1041. this.__data__ = {};
  1042. }
  1043. /**
  1044. * Removes `key` and its value from the cache.
  1045. *
  1046. * @private
  1047. * @name delete
  1048. * @memberOf _.memoize.Cache
  1049. * @param {string} key The key of the value to remove.
  1050. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1051. */
  1052. function mapDelete(key) {
  1053. return this.has(key) && delete this.__data__[key];
  1054. }
  1055. /**
  1056. * Gets the cached value for `key`.
  1057. *
  1058. * @private
  1059. * @name get
  1060. * @memberOf _.memoize.Cache
  1061. * @param {string} key The key of the value to get.
  1062. * @returns {*} Returns the cached value.
  1063. */
  1064. function mapGet(key) {
  1065. return key == '__proto__' ? undefined : this.__data__[key];
  1066. }
  1067. /**
  1068. * Checks if a cached value for `key` exists.
  1069. *
  1070. * @private
  1071. * @name has
  1072. * @memberOf _.memoize.Cache
  1073. * @param {string} key The key of the entry to check.
  1074. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1075. */
  1076. function mapHas(key) {
  1077. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1078. }
  1079. /**
  1080. * Sets `value` to `key` of the cache.
  1081. *
  1082. * @private
  1083. * @name set
  1084. * @memberOf _.memoize.Cache
  1085. * @param {string} key The key of the value to cache.
  1086. * @param {*} value The value to cache.
  1087. * @returns {Object} Returns the cache object.
  1088. */
  1089. function mapSet(key, value) {
  1090. if (key != '__proto__') {
  1091. this.__data__[key] = value;
  1092. }
  1093. return this;
  1094. }
  1095. /*------------------------------------------------------------------------*/
  1096. /**
  1097. *
  1098. * Creates a cache object to store unique values.
  1099. *
  1100. * @private
  1101. * @param {Array} [values] The values to cache.
  1102. */
  1103. function SetCache(values) {
  1104. var length = values ? values.length : 0;
  1105. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1106. while (length--) {
  1107. this.push(values[length]);
  1108. }
  1109. }
  1110. /**
  1111. * Checks if `value` is in `cache` mimicking the return signature of
  1112. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1113. *
  1114. * @private
  1115. * @param {Object} cache The cache to search.
  1116. * @param {*} value The value to search for.
  1117. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1118. */
  1119. function cacheIndexOf(cache, value) {
  1120. var data = cache.data,
  1121. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1122. return result ? 0 : -1;
  1123. }
  1124. /**
  1125. * Adds `value` to the cache.
  1126. *
  1127. * @private
  1128. * @name push
  1129. * @memberOf SetCache
  1130. * @param {*} value The value to cache.
  1131. */
  1132. function cachePush(value) {
  1133. var data = this.data;
  1134. if (typeof value == 'string' || isObject(value)) {
  1135. data.set.add(value);
  1136. } else {
  1137. data.hash[value] = true;
  1138. }
  1139. }
  1140. /*------------------------------------------------------------------------*/
  1141. /**
  1142. * Copies the values of `source` to `array`.
  1143. *
  1144. * @private
  1145. * @param {Array} source The array to copy values from.
  1146. * @param {Array} [array=[]] The array to copy values to.
  1147. * @returns {Array} Returns `array`.
  1148. */
  1149. function arrayCopy(source, array) {
  1150. var index = -1,
  1151. length = source.length;
  1152. array || (array = Array(length));
  1153. while (++index < length) {
  1154. array[index] = source[index];
  1155. }
  1156. return array;
  1157. }
  1158. /**
  1159. * A specialized version of `_.forEach` for arrays without support for callback
  1160. * shorthands and `this` binding.
  1161. *
  1162. * @private
  1163. * @param {Array} array The array to iterate over.
  1164. * @param {Function} iteratee The function invoked per iteration.
  1165. * @returns {Array} Returns `array`.
  1166. */
  1167. function arrayEach(array, iteratee) {
  1168. var index = -1,
  1169. length = array.length;
  1170. while (++index < length) {
  1171. if (iteratee(array[index], index, array) === false) {
  1172. break;
  1173. }
  1174. }
  1175. return array;
  1176. }
  1177. /**
  1178. * A specialized version of `_.forEachRight` for arrays without support for
  1179. * callback shorthands and `this` binding.
  1180. *
  1181. * @private
  1182. * @param {Array} array The array to iterate over.
  1183. * @param {Function} iteratee The function invoked per iteration.
  1184. * @returns {Array} Returns `array`.
  1185. */
  1186. function arrayEachRight(array, iteratee) {
  1187. var length = array.length;
  1188. while (length--) {
  1189. if (iteratee(array[length], length, array) === false) {
  1190. break;
  1191. }
  1192. }
  1193. return array;
  1194. }
  1195. /**
  1196. * A specialized version of `_.every` for arrays without support for callback
  1197. * shorthands and `this` binding.
  1198. *
  1199. * @private
  1200. * @param {Array} array The array to iterate over.
  1201. * @param {Function} predicate The function invoked per iteration.
  1202. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1203. * else `false`.
  1204. */
  1205. function arrayEvery(array, predicate) {
  1206. var index = -1,
  1207. length = array.length;
  1208. while (++index < length) {
  1209. if (!predicate(array[index], index, array)) {
  1210. return false;
  1211. }
  1212. }
  1213. return true;
  1214. }
  1215. /**
  1216. * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
  1217. * with one argument: (value).
  1218. *
  1219. * @private
  1220. * @param {Array} array The array to iterate over.
  1221. * @param {Function} iteratee The function invoked per iteration.
  1222. * @param {Function} comparator The function used to compare values.
  1223. * @param {*} exValue The initial extremum value.
  1224. * @returns {*} Returns the extremum value.
  1225. */
  1226. function arrayExtremum(array, iteratee, comparator, exValue) {
  1227. var index = -1,
  1228. length = array.length,
  1229. computed = exValue,
  1230. result = computed;
  1231. while (++index < length) {
  1232. var value = array[index],
  1233. current = +iteratee(value);
  1234. if (comparator(current, computed)) {
  1235. computed = current;
  1236. result = value;
  1237. }
  1238. }
  1239. return result;
  1240. }
  1241. /**
  1242. * A specialized version of `_.filter` for arrays without support for callback
  1243. * shorthands and `this` binding.
  1244. *
  1245. * @private
  1246. * @param {Array} array The array to iterate over.
  1247. * @param {Function} predicate The function invoked per iteration.
  1248. * @returns {Array} Returns the new filtered array.
  1249. */
  1250. function arrayFilter(array, predicate) {
  1251. var index = -1,
  1252. length = array.length,
  1253. resIndex = -1,
  1254. result = [];
  1255. while (++index < length) {
  1256. var value = array[index];
  1257. if (predicate(value, index, array)) {
  1258. result[++resIndex] = value;
  1259. }
  1260. }
  1261. return result;
  1262. }
  1263. /**
  1264. * A specialized version of `_.map` for arrays without support for callback
  1265. * shorthands and `this` binding.
  1266. *
  1267. * @private
  1268. * @param {Array} array The array to iterate over.
  1269. * @param {Function} iteratee The function invoked per iteration.
  1270. * @returns {Array} Returns the new mapped array.
  1271. */
  1272. function arrayMap(array, iteratee) {
  1273. var index = -1,
  1274. length = array.length,
  1275. result = Array(length);
  1276. while (++index < length) {
  1277. result[index] = iteratee(array[index], index, array);
  1278. }
  1279. return result;
  1280. }
  1281. /**
  1282. * A specialized version of `_.reduce` for arrays without support for callback
  1283. * shorthands and `this` binding.
  1284. *
  1285. * @private
  1286. * @param {Array} array The array to iterate over.
  1287. * @param {Function} iteratee The function invoked per iteration.
  1288. * @param {*} [accumulator] The initial value.
  1289. * @param {boolean} [initFromArray] Specify using the first element of `array`
  1290. * as the initial value.
  1291. * @returns {*} Returns the accumulated value.
  1292. */
  1293. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  1294. var index = -1,
  1295. length = array.length;
  1296. if (initFromArray && length) {
  1297. accumulator = array[++index];
  1298. }
  1299. while (++index < length) {
  1300. accumulator = iteratee(accumulator, array[index], index, array);
  1301. }
  1302. return accumulator;
  1303. }
  1304. /**
  1305. * A specialized version of `_.reduceRight` for arrays without support for
  1306. * callback shorthands and `this` binding.
  1307. *
  1308. * @private
  1309. * @param {Array} array The array to iterate over.
  1310. * @param {Function} iteratee The function invoked per iteration.
  1311. * @param {*} [accumulator] The initial value.
  1312. * @param {boolean} [initFromArray] Specify using the last element of `array`
  1313. * as the initial value.
  1314. * @returns {*} Returns the accumulated value.
  1315. */
  1316. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  1317. var length = array.length;
  1318. if (initFromArray && length) {
  1319. accumulator = array[--length];
  1320. }
  1321. while (length--) {
  1322. accumulator = iteratee(accumulator, array[length], length, array);
  1323. }
  1324. return accumulator;
  1325. }
  1326. /**
  1327. * A specialized version of `_.some` for arrays without support for callback
  1328. * shorthands and `this` binding.
  1329. *
  1330. * @private
  1331. * @param {Array} array The array to iterate over.
  1332. * @param {Function} predicate The function invoked per iteration.
  1333. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1334. * else `false`.
  1335. */
  1336. function arraySome(array, predicate) {
  1337. var index = -1,
  1338. length = array.length;
  1339. while (++index < length) {
  1340. if (predicate(array[index], index, array)) {
  1341. return true;
  1342. }
  1343. }
  1344. return false;
  1345. }
  1346. /**
  1347. * A specialized version of `_.sum` for arrays without support for iteratees.
  1348. *
  1349. * @private
  1350. * @param {Array} array The array to iterate over.
  1351. * @returns {number} Returns the sum.
  1352. */
  1353. function arraySum(array) {
  1354. var length = array.length,
  1355. result = 0;
  1356. while (le