PageRenderTime 30ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/files/lodash/3.3.0/lodash.js

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