PageRenderTime 29ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/files/lodash/3.5.0/lodash.js

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