PageRenderTime 366ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/3.2.0/lodash.js

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