PageRenderTime 125ms CodeModel.GetById 23ms RepoModel.GetById 2ms app.codeStats 0ms

/files/lodash/3.4.0/lodash.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1524 lines | 1490 code | 13 blank | 21 comment | 0 complexity | 7e2dd35a436f50fdcce4e2678b773c10 MD5 | raw file
  1. /**
  2. * @license
  3. * lodash 3.4.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.4.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_MAP_FLAG = 2,
  34. LAZY_TAKE_WHILE_FLAG = 3;
  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. } else {
  383. return orders[index] ? result : result * -1;
  384. }
  385. }
  386. }
  387. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  388. // that causes it, under certain circumstances, to provide the same value for
  389. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  390. // for more details.
  391. //
  392. // This also ensures a stable sort in V8 and other engines.
  393. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  394. return object.index - other.index;
  395. }
  396. /**
  397. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  398. *
  399. * @private
  400. * @param {string} letter The matched letter to deburr.
  401. * @returns {string} Returns the deburred letter.
  402. */
  403. function deburrLetter(letter) {
  404. return deburredLetters[letter];
  405. }
  406. /**
  407. * Used by `_.escape` to convert characters to HTML entities.
  408. *
  409. * @private
  410. * @param {string} chr The matched character to escape.
  411. * @returns {string} Returns the escaped character.
  412. */
  413. function escapeHtmlChar(chr) {
  414. return htmlEscapes[chr];
  415. }
  416. /**
  417. * Used by `_.template` to escape characters for inclusion in compiled
  418. * string literals.
  419. *
  420. * @private
  421. * @param {string} chr The matched character to escape.
  422. * @returns {string} Returns the escaped character.
  423. */
  424. function escapeStringChar(chr) {
  425. return '\\' + stringEscapes[chr];
  426. }
  427. /**
  428. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  429. * If `fromRight` is provided elements of `array` are iterated from right to left.
  430. *
  431. * @private
  432. * @param {Array} array The array to search.
  433. * @param {number} fromIndex The index to search from.
  434. * @param {boolean} [fromRight] Specify iterating from right to left.
  435. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  436. */
  437. function indexOfNaN(array, fromIndex, fromRight) {
  438. var length = array.length,
  439. index = fromIndex + (fromRight ? 0 : -1);
  440. while ((fromRight ? index-- : ++index < length)) {
  441. var other = array[index];
  442. if (other !== other) {
  443. return index;
  444. }
  445. }
  446. return -1;
  447. }
  448. /**
  449. * Checks if `value` is object-like.
  450. *
  451. * @private
  452. * @param {*} value The value to check.
  453. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  454. */
  455. function isObjectLike(value) {
  456. return (value && typeof value == 'object') || false;
  457. }
  458. /**
  459. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  460. * character code is whitespace.
  461. *
  462. * @private
  463. * @param {number} charCode The character code to inspect.
  464. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  465. */
  466. function isSpace(charCode) {
  467. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  468. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  469. }
  470. /**
  471. * Replaces all `placeholder` elements in `array` with an internal placeholder
  472. * and returns an array of their indexes.
  473. *
  474. * @private
  475. * @param {Array} array The array to modify.
  476. * @param {*} placeholder The placeholder to replace.
  477. * @returns {Array} Returns the new array of placeholder indexes.
  478. */
  479. function replaceHolders(array, placeholder) {
  480. var index = -1,
  481. length = array.length,
  482. resIndex = -1,
  483. result = [];
  484. while (++index < length) {
  485. if (array[index] === placeholder) {
  486. array[index] = PLACEHOLDER;
  487. result[++resIndex] = index;
  488. }
  489. }
  490. return result;
  491. }
  492. /**
  493. * An implementation of `_.uniq` optimized for sorted arrays without support
  494. * for callback shorthands and `this` binding.
  495. *
  496. * @private
  497. * @param {Array} array The array to inspect.
  498. * @param {Function} [iteratee] The function invoked per iteration.
  499. * @returns {Array} Returns the new duplicate-value-free array.
  500. */
  501. function sortedUniq(array, iteratee) {
  502. var seen,
  503. index = -1,
  504. length = array.length,
  505. resIndex = -1,
  506. result = [];
  507. while (++index < length) {
  508. var value = array[index],
  509. computed = iteratee ? iteratee(value, index, array) : value;
  510. if (!index || seen !== computed) {
  511. seen = computed;
  512. result[++resIndex] = value;
  513. }
  514. }
  515. return result;
  516. }
  517. /**
  518. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  519. * character of `string`.
  520. *
  521. * @private
  522. * @param {string} string The string to inspect.
  523. * @returns {number} Returns the index of the first non-whitespace character.
  524. */
  525. function trimmedLeftIndex(string) {
  526. var index = -1,
  527. length = string.length;
  528. while (++index < length && isSpace(string.charCodeAt(index))) {}
  529. return index;
  530. }
  531. /**
  532. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  533. * character of `string`.
  534. *
  535. * @private
  536. * @param {string} string The string to inspect.
  537. * @returns {number} Returns the index of the last non-whitespace character.
  538. */
  539. function trimmedRightIndex(string) {
  540. var index = string.length;
  541. while (index-- && isSpace(string.charCodeAt(index))) {}
  542. return index;
  543. }
  544. /**
  545. * Used by `_.unescape` to convert HTML entities to characters.
  546. *
  547. * @private
  548. * @param {string} chr The matched character to unescape.
  549. * @returns {string} Returns the unescaped character.
  550. */
  551. function unescapeHtmlChar(chr) {
  552. return htmlUnescapes[chr];
  553. }
  554. /*--------------------------------------------------------------------------*/
  555. /**
  556. * Create a new pristine `lodash` function using the given `context` object.
  557. *
  558. * @static
  559. * @memberOf _
  560. * @category Utility
  561. * @param {Object} [context=root] The context object.
  562. * @returns {Function} Returns a new `lodash` function.
  563. * @example
  564. *
  565. * _.mixin({ 'add': function(a, b) { return a + b; } });
  566. *
  567. * var lodash = _.runInContext();
  568. * lodash.mixin({ 'sub': function(a, b) { return a - b; } });
  569. *
  570. * _.isFunction(_.add);
  571. * // => true
  572. * _.isFunction(_.sub);
  573. * // => false
  574. *
  575. * lodash.isFunction(lodash.add);
  576. * // => false
  577. * lodash.isFunction(lodash.sub);
  578. * // => true
  579. *
  580. * // using `context` to mock `Date#getTime` use in `_.now`
  581. * var mock = _.runInContext({
  582. * 'Date': function() {
  583. * return { 'getTime': getTimeMock };
  584. * }
  585. * });
  586. *
  587. * // or creating a suped-up `defer` in Node.js
  588. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  589. */
  590. function runInContext(context) {
  591. // Avoid issues with some ES3 environments that attempt to use values, named
  592. // after built-in constructors like `Object`, for the creation of literals.
  593. // ES5 clears this up by stating that literals must use built-in constructors.
  594. // See https://es5.github.io/#x11.1.5 for more details.
  595. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  596. /** Native constructor references. */
  597. var Array = context.Array,
  598. Date = context.Date,
  599. Error = context.Error,
  600. Function = context.Function,
  601. Math = context.Math,
  602. Number = context.Number,
  603. Object = context.Object,
  604. RegExp = context.RegExp,
  605. String = context.String,
  606. TypeError = context.TypeError;
  607. /** Used for native method references. */
  608. var arrayProto = Array.prototype,
  609. objectProto = Object.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 also have the following `Array` methods:
  704. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
  705. * and `unshift`
  706. *
  707. * The wrapper methods that support shortcut fusion are:
  708. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  709. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  710. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  711. * and `where`
  712. *
  713. * The chainable wrapper methods are:
  714. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  715. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  716. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
  717. * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
  718. * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
  719. * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
  720. * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
  721. * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
  722. * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  723. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  724. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
  725. * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
  726. * `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
  727. * `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
  728. * `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
  729. * `without`, `wrap`, `xor`, `zip`, and `zipObject`
  730. *
  731. * The wrapper methods that are **not** chainable by default are:
  732. * `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
  733. * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
  734. * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
  735. * `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
  736. * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
  737. * `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
  738. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
  739. * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
  740. * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
  741. * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
  742. * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
  743. * `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
  744. * `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
  745. *
  746. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  747. * otherwise an unwrapped value is returned.
  748. *
  749. * @name _
  750. * @constructor
  751. * @category Chain
  752. * @param {*} value The value to wrap in a `lodash` instance.
  753. * @returns {Object} Returns the new `lodash` wrapper instance.
  754. * @example
  755. *
  756. * var wrapped = _([1, 2, 3]);
  757. *
  758. * // returns an unwrapped value
  759. * wrapped.reduce(function(sum, n) {
  760. * return sum + n;
  761. * });
  762. * // => 6
  763. *
  764. * // returns a wrapped value
  765. * var squares = wrapped.map(function(n) {
  766. * return n * n;
  767. * });
  768. *
  769. * _.isArray(squares);
  770. * // => false
  771. *
  772. * _.isArray(squares.value());
  773. * // => true
  774. */
  775. function lodash(value) {
  776. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  777. if (value instanceof LodashWrapper) {
  778. return value;
  779. }
  780. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  781. return wrapperClone(value);
  782. }
  783. }
  784. return new LodashWrapper(value);
  785. }
  786. /**
  787. * The function whose prototype all chaining wrappers inherit from.
  788. *
  789. * @private
  790. */
  791. function baseLodash() {
  792. // No operation performed.
  793. }
  794. /**
  795. * The base constructor for creating `lodash` wrapper objects.
  796. *
  797. * @private
  798. * @param {*} value The value to wrap.
  799. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  800. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  801. */
  802. function LodashWrapper(value, chainAll, actions) {
  803. this.__wrapped__ = value;
  804. this.__actions__ = actions || [];
  805. this.__chain__ = !!chainAll;
  806. }
  807. /**
  808. * An object environment feature flags.
  809. *
  810. * @static
  811. * @memberOf _
  812. * @type Object
  813. */
  814. var support = lodash.support = {};
  815. (function(x) {
  816. /**
  817. * Detect if functions can be decompiled by `Function#toString`
  818. * (all but Firefox OS certified apps, older Opera mobile browsers, and
  819. * the PlayStation 3; forced `false` for Windows 8 apps).
  820. *
  821. * @memberOf _.support
  822. * @type boolean
  823. */
  824. support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
  825. /**
  826. * Detect if `Function#name` is supported (all but IE).
  827. *
  828. * @memberOf _.support
  829. * @type boolean
  830. */
  831. support.funcNames = typeof Function.name == 'string';
  832. /**
  833. * Detect if the DOM is supported.
  834. *
  835. * @memberOf _.support
  836. * @type boolean
  837. */
  838. try {
  839. support.dom = document.createDocumentFragment().nodeType === 11;
  840. } catch(e) {
  841. support.dom = false;
  842. }
  843. /**
  844. * Detect if `arguments` object indexes are non-enumerable.
  845. *
  846. * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
  847. * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
  848. * `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
  849. * checks for indexes that exceed their function's formal parameters with
  850. * associated values of `0`.
  851. *
  852. * @memberOf _.support
  853. * @type boolean
  854. */
  855. try {
  856. support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
  857. } catch(e) {
  858. support.nonEnumArgs = true;
  859. }
  860. }(0, 0));
  861. /**
  862. * By default, the template delimiters used by lodash are like those in
  863. * embedded Ruby (ERB). Change the following template settings to use
  864. * alternative delimiters.
  865. *
  866. * @static
  867. * @memberOf _
  868. * @type Object
  869. */
  870. lodash.templateSettings = {
  871. /**
  872. * Used to detect `data` property values to be HTML-escaped.
  873. *
  874. * @memberOf _.templateSettings
  875. * @type RegExp
  876. */
  877. 'escape': reEscape,
  878. /**
  879. * Used to detect code to be evaluated.
  880. *
  881. * @memberOf _.templateSettings
  882. * @type RegExp
  883. */
  884. 'evaluate': reEvaluate,
  885. /**
  886. * Used to detect `data` property values to inject.
  887. *
  888. * @memberOf _.templateSettings
  889. * @type RegExp
  890. */
  891. 'interpolate': reInterpolate,
  892. /**
  893. * Used to reference the data object in the template text.
  894. *
  895. * @memberOf _.templateSettings
  896. * @type string
  897. */
  898. 'variable': '',
  899. /**
  900. * Used to import variables into the compiled template.
  901. *
  902. * @memberOf _.templateSettings
  903. * @type Object
  904. */
  905. 'imports': {
  906. /**
  907. * A reference to the `lodash` function.
  908. *
  909. * @memberOf _.templateSettings.imports
  910. * @type Function
  911. */
  912. '_': lodash
  913. }
  914. };
  915. /*------------------------------------------------------------------------*/
  916. /**
  917. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  918. *
  919. * @private
  920. * @param {*} value The value to wrap.
  921. */
  922. function LazyWrapper(value) {
  923. this.__wrapped__ = value;
  924. this.__actions__ = null;
  925. this.__dir__ = 1;
  926. this.__dropCount__ = 0;
  927. this.__filtered__ = false;
  928. this.__iteratees__ = null;
  929. this.__takeCount__ = POSITIVE_INFINITY;
  930. this.__views__ = null;
  931. }
  932. /**
  933. * Creates a clone of the lazy wrapper object.
  934. *
  935. * @private
  936. * @name clone
  937. * @memberOf LazyWrapper
  938. * @returns {Object} Returns the cloned `LazyWrapper` object.
  939. */
  940. function lazyClone() {
  941. var actions = this.__actions__,
  942. iteratees = this.__iteratees__,
  943. views = this.__views__,
  944. result = new LazyWrapper(this.__wrapped__);
  945. result.__actions__ = actions ? arrayCopy(actions) : null;
  946. result.__dir__ = this.__dir__;
  947. result.__dropCount__ = this.__dropCount__;
  948. result.__filtered__ = this.__filtered__;
  949. result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
  950. result.__takeCount__ = this.__takeCount__;
  951. result.__views__ = views ? arrayCopy(views) : null;
  952. return result;
  953. }
  954. /**
  955. * Reverses the direction of lazy iteration.
  956. *
  957. * @private
  958. * @name reverse
  959. * @memberOf LazyWrapper
  960. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  961. */
  962. function lazyReverse() {
  963. if (this.__filtered__) {
  964. var result = new LazyWrapper(this);
  965. result.__dir__ = -1;
  966. result.__filtered__ = true;
  967. } else {
  968. result = this.clone();
  969. result.__dir__ *= -1;
  970. }
  971. return result;
  972. }
  973. /**
  974. * Extracts the unwrapped value from its lazy wrapper.
  975. *
  976. * @private
  977. * @name value
  978. * @memberOf LazyWrapper
  979. * @returns {*} Returns the unwrapped value.
  980. */
  981. function lazyValue() {
  982. var array = this.__wrapped__.value();
  983. if (!isArray(array)) {
  984. return baseWrapperValue(array, this.__actions__);
  985. }
  986. var dir = this.__dir__,
  987. isRight = dir < 0,
  988. view = getView(0, array.length, this.__views__),
  989. start = view.start,
  990. end = view.end,
  991. length = end - start,
  992. dropCount = this.__dropCount__,
  993. takeCount = nativeMin(length, this.__takeCount__),
  994. index = isRight ? end : start - 1,
  995. iteratees = this.__iteratees__,
  996. iterLength = iteratees ? iteratees.length : 0,
  997. resIndex = 0,
  998. result = [];
  999. outer:
  1000. while (length-- && resIndex < takeCount) {
  1001. index += dir;
  1002. var iterIndex = -1,
  1003. value = array[index];
  1004. while (++iterIndex < iterLength) {
  1005. var data = iteratees[iterIndex],
  1006. iteratee = data.iteratee,
  1007. type = data.type;
  1008. if (type != LAZY_DROP_WHILE_FLAG) {
  1009. var computed = iteratee(value);
  1010. } else {
  1011. data.done = data.done && (isRight ? index < data.index : index > data.index);
  1012. data.index = index;
  1013. computed = data.done || (data.done = !iteratee(value));
  1014. }
  1015. if (type == LAZY_MAP_FLAG) {
  1016. value = computed;
  1017. } else if (!computed) {
  1018. if (type == LAZY_TAKE_WHILE_FLAG) {
  1019. break outer;
  1020. } else {
  1021. continue outer;
  1022. }
  1023. }
  1024. }
  1025. if (dropCount) {
  1026. dropCount--;
  1027. } else {
  1028. result[resIndex++] = value;
  1029. }
  1030. }
  1031. return result;
  1032. }
  1033. /*------------------------------------------------------------------------*/
  1034. /**
  1035. * Creates a cache object to store key/value pairs.
  1036. *
  1037. * @private
  1038. * @static
  1039. * @name Cache
  1040. * @memberOf _.memoize
  1041. */
  1042. function MapCache() {
  1043. this.__data__ = {};
  1044. }
  1045. /**
  1046. * Removes `key` and its value from the cache.
  1047. *
  1048. * @private
  1049. * @name delete
  1050. * @memberOf _.memoize.Cache
  1051. * @param {string} key The key of the value to remove.
  1052. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1053. */
  1054. function mapDelete(key) {
  1055. return this.has(key) && delete this.__data__[key];
  1056. }
  1057. /**
  1058. * Gets the cached value for `key`.
  1059. *
  1060. * @private
  1061. * @name get
  1062. * @memberOf _.memoize.Cache
  1063. * @param {string} key The key of the value to get.
  1064. * @returns {*} Returns the cached value.
  1065. */
  1066. function mapGet(key) {
  1067. return key == '__proto__' ? undefined : this.__data__[key];
  1068. }
  1069. /**
  1070. * Checks if a cached value for `key` exists.
  1071. *
  1072. * @private
  1073. * @name has
  1074. * @memberOf _.memoize.Cache
  1075. * @param {string} key The key of the entry to check.
  1076. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1077. */
  1078. function mapHas(key) {
  1079. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1080. }
  1081. /**
  1082. * Adds `value` to `key` of the cache.
  1083. *
  1084. * @private
  1085. * @name set
  1086. * @memberOf _.memoize.Cache
  1087. * @param {string} key The key of the value to cache.
  1088. * @param {*} value The value to cache.
  1089. * @returns {Object} Returns the cache object.
  1090. */
  1091. function mapSet(key, value) {
  1092. if (key != '__proto__') {
  1093. this.__data__[key] = value;
  1094. }
  1095. return this;
  1096. }
  1097. /*------------------------------------------------------------------------*/
  1098. /**
  1099. *
  1100. * Creates a cache object to store unique values.
  1101. *
  1102. * @private
  1103. * @param {Array} [values] The values to cache.
  1104. */
  1105. function SetCache(values) {
  1106. var length = values ? values.length : 0;
  1107. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1108. while (length--) {
  1109. this.push(values[length]);
  1110. }
  1111. }
  1112. /**
  1113. * Checks if `value` is in `cache` mimicking the return signature of
  1114. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1115. *
  1116. * @private
  1117. * @param {Object} cache The cache to search.
  1118. * @param {*} value The value to search for.
  1119. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1120. */
  1121. function cacheIndexOf(cache, value) {
  1122. var data = cache.data,
  1123. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1124. return result ? 0 : -1;
  1125. }
  1126. /**
  1127. * Adds `value` to the cache.
  1128. *
  1129. * @private
  1130. * @name push
  1131. * @memberOf SetCache
  1132. * @param {*} value The value to cache.
  1133. */
  1134. function cachePush(value) {
  1135. var data = this.data;
  1136. if (typeof value == 'string' || isObject(value)) {
  1137. data.set.add(value);
  1138. } else {
  1139. data.hash[value] = true;
  1140. }
  1141. }
  1142. /*------------------------------------------------------------------------*/
  1143. /**
  1144. * Copies the values of `source` to `array`.
  1145. *
  1146. * @private
  1147. * @param {Array} source The array to copy values from.
  1148. * @param {Array} [array=[]] The array to copy values to.
  1149. * @returns {Array} Returns `array`.
  1150. */
  1151. function arrayCopy(source, array) {
  1152. var index = -1,
  1153. length = source.length;
  1154. array || (array = Array(length));
  1155. while (++index < length) {
  1156. array[index] = source[index];
  1157. }
  1158. return array;
  1159. }
  1160. /**
  1161. * A specialized version of `_.forEach` for arrays without support for callback
  1162. * shorthands or `this` binding.
  1163. *
  1164. * @private
  1165. * @param {Array} array The array to iterate over.
  1166. * @param {Function} iteratee The function invoked per iteration.
  1167. * @returns {Array} Returns `array`.
  1168. */
  1169. function arrayEach(array, iteratee) {
  1170. var index = -1,
  1171. length = array.length;
  1172. while (++index < length) {
  1173. if (iteratee(array[index], index, array) === false) {
  1174. break;
  1175. }
  1176. }
  1177. return array;
  1178. }
  1179. /**
  1180. * A specialized version of `_.forEachRight` for arrays without support for
  1181. * callback shorthands or `this` binding.
  1182. *
  1183. * @private
  1184. * @param {Array} array The array to iterate over.
  1185. * @param {Function} iteratee The function invoked per iteration.
  1186. * @returns {Array} Returns `array`.
  1187. */
  1188. function arrayEachRight(array, iteratee) {
  1189. var length = array.length;
  1190. while (length--) {
  1191. if (iteratee(array[length], length, array) === false) {
  1192. break;
  1193. }
  1194. }
  1195. return array;
  1196. }
  1197. /**
  1198. * A specialized version of `_.every` for arrays without support for callback
  1199. * shorthands or `this` binding.
  1200. *
  1201. * @private
  1202. * @param {Array} array The array to iterate over.
  1203. * @param {Function} predicate The function invoked per iteration.
  1204. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1205. * else `false`.
  1206. */
  1207. function arrayEvery(array, predicate) {
  1208. var index = -1,
  1209. length = array.length;
  1210. while (++index < length) {
  1211. if (!predicate(array[index], index, array)) {
  1212. return false;
  1213. }
  1214. }
  1215. return true;
  1216. }
  1217. /**
  1218. * A specialized version of `_.filter` for arrays without support for callback
  1219. * shorthands or `this` binding.
  1220. *
  1221. * @private
  1222. * @param {Array} array The array to iterate over.
  1223. * @param {Function} predicate The function invoked per iteration.
  1224. * @returns {Array} Returns the new filtered array.
  1225. */
  1226. function arrayFilter(array, predicate) {
  1227. var index = -1,
  1228. length = array.length,
  1229. resIndex = -1,
  1230. result = [];
  1231. while (++index < length) {
  1232. var value = array[index];
  1233. if (predicate(value, index, array)) {
  1234. result[++resIndex] = value;
  1235. }
  1236. }
  1237. return result;
  1238. }
  1239. /**
  1240. * A specialized version of `_.map` for arrays without support for callback
  1241. * shorthands or `this` binding.
  1242. *
  1243. * @private
  1244. * @param {Array} array The array to iterate over.
  1245. * @param {Function} iteratee The function invoked per iteration.
  1246. * @returns {Array} Returns the new mapped array.
  1247. */
  1248. function arrayMap(array, iteratee) {
  1249. var index = -1,
  1250. length = array.length,
  1251. result = Array(length);
  1252. while (++index < length) {
  1253. result[index] = iteratee(array[index], index, array);
  1254. }
  1255. return result;
  1256. }
  1257. /**
  1258. * A specialized version of `_.max` for arrays without support for iteratees.
  1259. *
  1260. * @private
  1261. * @param {Array} array The array to iterate over.
  1262. * @returns {*} Returns the maximum value.
  1263. */
  1264. function arrayMax(array) {
  1265. var index = -1,
  1266. length = array.length,
  1267. result = NEGATIVE_INFINITY;
  1268. while (++index < length) {
  1269. var value = array[index];
  1270. if (value > result) {
  1271. result = value;
  1272. }
  1273. }
  1274. return result;
  1275. }
  1276. /**
  1277. * A specialized version of `_.min` for arrays without support for iteratees.
  1278. *
  1279. * @private
  1280. * @param {Array} array The array to iterate over.
  1281. * @returns {*} Returns the minimum value.
  1282. */
  1283. function arrayMin(array) {
  1284. var index = -1,
  1285. length = array.length,
  1286. result = POSITIVE_INFINITY;
  1287. while (++index < length) {
  1288. var value = array[index];
  1289. if (value < result) {
  1290. result = value;
  1291. }
  1292. }
  1293. return result;
  1294. }
  1295. /**
  1296. * A specialized version of `_.reduce` for arrays without support for callback
  1297. * shorthands or `this` binding.
  1298. *
  1299. * @private
  1300. * @param {Array} array The array to iterate over.
  1301. * @param {Function} iteratee The function invoked per iteration.
  1302. * @param {*} [accumulator] The initial value.
  1303. * @param {boolean} [initFromArray] Specify using the first element of `array`
  1304. * as the initial value.
  1305. * @returns {*} Returns the accumulated value.
  1306. */
  1307. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  1308. var index = -1,
  1309. length = array.length;
  1310. if (initFromArray && length) {
  1311. accumulator = array[++index];
  1312. }
  1313. while (++index < length) {
  1314. accumulator = iteratee(accumulator, array[index], index, array);
  1315. }
  1316. return accumulator;
  1317. }
  1318. /**
  1319. * A specialized version of `_.reduceRight` for arrays without support for
  1320. * callback shorthands or `this` binding.
  1321. *
  1322. * @private
  1323. * @param {Array} array The array to iterate over.
  1324. * @param {Function} iteratee The function invoked per iteration.
  1325. * @param {*} [accumulator] The initial value.
  1326. * @param {boolean} [initFromArray] Specify using the last element of `array`
  1327. * as the initial value.
  1328. * @returns {*} Returns the accumulated value.
  1329. */
  1330. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  1331. var length = array.length;
  1332. if (initFromArray && length) {
  1333. accumulator = array[--length];
  1334. }
  1335. while (length--) {
  1336. accumulator = iteratee(accumulator, array[length], length, array);
  1337. }
  1338. return accumulator;
  1339. }
  1340. /**
  1341. * A specialized version of `_.some` for arrays without support for callback
  1342. * shorthands or `this` binding.
  1343. *
  1344. * @private
  1345. * @param {Array} array The array to iterate over.
  1346. * @param {Function} predicate The function invoked per iteration.
  1347. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1348. * else `false`.
  1349. */
  1350. function arraySome(array, predicate) {
  1351. var index = -1,
  1352. length = array.length;
  1353. while (++index < length) {
  1354. if (predicate(array[index], index, array)) {
  1355. return true;
  1356. }
  1357. }
  1358. return false;
  1359. }
  1360. /**
  1361. * Used by `_.defaults` to customize its `_.assign` use.
  1362. *
  1363. * @private
  1364. * @param {*} objectValue The destination object property value.
  1365. * @param {*} sourceValue The source object property value.
  1366. * @returns {*} Returns the value to assign to