PageRenderTime 31ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/3.0.0/lodash.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1523 lines | 1489 code | 13 blank | 21 comment | 0 complexity | 4c4f83f006672d9d6c2ea52ba43f7471 MD5 | raw file
  1. /**
  2. * @license
  3. * lodash 3.0.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.0.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. unshift = arrayProto.unshift,
  643. WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap;
  644. /** Used to clone array buffers. */
  645. var Float64Array = (function() {
  646. // Safari 5 errors when using an array buffer to initialize a typed array
  647. // where the array buffer's `byteLength` is not a multiple of the typed
  648. // array's `BYTES_PER_ELEMENT`.
  649. try {
  650. var func = isNative(func = context.Float64Array) && func,
  651. result = new func(new ArrayBuffer(10), 0, 1) && func;
  652. } catch(e) {}
  653. return result;
  654. }());
  655. /* Native method references for those with the same name as other `lodash` methods. */
  656. var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
  657. nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
  658. nativeIsFinite = context.isFinite,
  659. nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
  660. nativeMax = Math.max,
  661. nativeMin = Math.min,
  662. nativeNow = isNative(nativeNow = Date.now) && nativeNow,
  663. nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite,
  664. nativeParseInt = context.parseInt,
  665. nativeRandom = Math.random;
  666. /** Used as references for `-Infinity` and `Infinity`. */
  667. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  668. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  669. /** Used as references for the maximum length and index of an array. */
  670. var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
  671. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  672. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  673. /** Used as the size, in bytes, of each `Float64Array` element. */
  674. var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
  675. /**
  676. * Used as the maximum length of an array-like value.
  677. * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
  678. * for more details.
  679. */
  680. var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
  681. /** Used to store function metadata. */
  682. var metaMap = WeakMap && new WeakMap;
  683. /*------------------------------------------------------------------------*/
  684. /**
  685. * Creates a `lodash` object which wraps `value` to enable intuitive chaining.
  686. * Methods that operate on and return arrays, collections, and functions can
  687. * be chained together. Methods that return a boolean or single value will
  688. * automatically end the chain returning the unwrapped value. Explicit chaining
  689. * may be enabled using `_.chain`. The execution of chained methods is lazy,
  690. * that is, execution is deferred until `_#value` is implicitly or explicitly
  691. * called.
  692. *
  693. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  694. * fusion is an optimization that merges iteratees to avoid creating intermediate
  695. * arrays and reduce the number of iteratee executions.
  696. *
  697. * Chaining is supported in custom builds as long as the `_#value` method is
  698. * directly or indirectly included in the build.
  699. *
  700. * In addition to lodash methods, wrappers also have the following `Array` methods:
  701. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
  702. * and `unshift`
  703. *
  704. * The wrapper functions that support shortcut fusion are:
  705. * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`,
  706. * `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`,
  707. * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where`
  708. *
  709. * The chainable wrapper functions are:
  710. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  711. * `callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`,
  712. * `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`,
  713. * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`,
  714. * `flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`,
  715. * `forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`,
  716. * `initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`,
  717. * `mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`,
  718. * `omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`,
  719. * `pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`,
  720. * `rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
  721. * `sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`,
  722. * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
  723. * `transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`,
  724. * `where`, `without`, `wrap`, `xor`, `zip`, and `zipObject`
  725. *
  726. * The wrapper functions that are **not** chainable by default are:
  727. * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
  728. * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
  729. * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
  730. * `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
  731. * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
  732. * `isFunction`, `isMatch` , `isNative`, `isNaN`, `isNull`, `isNumber`,
  733. * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
  734. * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
  735. * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
  736. * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
  737. * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
  738. * `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
  739. * `unescape`, `uniqueId`, `value`, and `words`
  740. *
  741. * The wrapper function `sample` will return a wrapped value when `n` is provided,
  742. * otherwise an unwrapped value is returned.
  743. *
  744. * @name _
  745. * @constructor
  746. * @category Chain
  747. * @param {*} value The value to wrap in a `lodash` instance.
  748. * @returns {Object} Returns a `lodash` instance.
  749. * @example
  750. *
  751. * var wrapped = _([1, 2, 3]);
  752. *
  753. * // returns an unwrapped value
  754. * wrapped.reduce(function(sum, n) { return sum + n; });
  755. * // => 6
  756. *
  757. * // returns a wrapped value
  758. * var squares = wrapped.map(function(n) { return n * n; });
  759. *
  760. * _.isArray(squares);
  761. * // => false
  762. *
  763. * _.isArray(squares.value());
  764. * // => true
  765. */
  766. function lodash(value) {
  767. if (isObjectLike(value) && !isArray(value)) {
  768. if (value instanceof LodashWrapper) {
  769. return value;
  770. }
  771. if (hasOwnProperty.call(value, '__wrapped__')) {
  772. return new LodashWrapper(value.__wrapped__, value.__chain__, arrayCopy(value.__actions__));
  773. }
  774. }
  775. return new LodashWrapper(value);
  776. }
  777. /**
  778. * The base constructor for creating `lodash` wrapper objects.
  779. *
  780. * @private
  781. * @param {*} value The value to wrap.
  782. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  783. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  784. */
  785. function LodashWrapper(value, chainAll, actions) {
  786. this.__actions__ = actions || [];
  787. this.__chain__ = !!chainAll;
  788. this.__wrapped__ = value;
  789. }
  790. /**
  791. * An object environment feature flags.
  792. *
  793. * @static
  794. * @memberOf _
  795. * @type Object
  796. */
  797. var support = lodash.support = {};
  798. (function(x) {
  799. /**
  800. * Detect if functions can be decompiled by `Function#toString`
  801. * (all but Firefox OS certified apps, older Opera mobile browsers, and
  802. * the PlayStation 3; forced `false` for Windows 8 apps).
  803. *
  804. * @memberOf _.support
  805. * @type boolean
  806. */
  807. support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
  808. /**
  809. * Detect if `Function#name` is supported (all but IE).
  810. *
  811. * @memberOf _.support
  812. * @type boolean
  813. */
  814. support.funcNames = typeof Function.name == 'string';
  815. /**
  816. * Detect if the DOM is supported.
  817. *
  818. * @memberOf _.support
  819. * @type boolean
  820. */
  821. try {
  822. support.dom = document.createDocumentFragment().nodeType === 11;
  823. } catch(e) {
  824. support.dom = false;
  825. }
  826. /**
  827. * Detect if `arguments` object indexes are non-enumerable.
  828. *
  829. * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
  830. * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
  831. * `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
  832. * checks for indexes that exceed their function's formal parameters with
  833. * associated values of `0`.
  834. *
  835. * @memberOf _.support
  836. * @type boolean
  837. */
  838. try {
  839. support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
  840. } catch(e) {
  841. support.nonEnumArgs = true;
  842. }
  843. }(0, 0));
  844. /**
  845. * By default, the template delimiters used by lodash are like those in
  846. * embedded Ruby (ERB). Change the following template settings to use
  847. * alternative delimiters.
  848. *
  849. * @static
  850. * @memberOf _
  851. * @type Object
  852. */
  853. lodash.templateSettings = {
  854. /**
  855. * Used to detect `data` property values to be HTML-escaped.
  856. *
  857. * @memberOf _.templateSettings
  858. * @type RegExp
  859. */
  860. 'escape': reEscape,
  861. /**
  862. * Used to detect code to be evaluated.
  863. *
  864. * @memberOf _.templateSettings
  865. * @type RegExp
  866. */
  867. 'evaluate': reEvaluate,
  868. /**
  869. * Used to detect `data` property values to inject.
  870. *
  871. * @memberOf _.templateSettings
  872. * @type RegExp
  873. */
  874. 'interpolate': reInterpolate,
  875. /**
  876. * Used to reference the data object in the template text.
  877. *
  878. * @memberOf _.templateSettings
  879. * @type string
  880. */
  881. 'variable': '',
  882. /**
  883. * Used to import variables into the compiled template.
  884. *
  885. * @memberOf _.templateSettings
  886. * @type Object
  887. */
  888. 'imports': {
  889. /**
  890. * A reference to the `lodash` function.
  891. *
  892. * @memberOf _.templateSettings.imports
  893. * @type Function
  894. */
  895. '_': lodash
  896. }
  897. };
  898. /*------------------------------------------------------------------------*/
  899. /**
  900. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  901. *
  902. * @private
  903. * @param {*} value The value to wrap.
  904. */
  905. function LazyWrapper(value) {
  906. this.actions = null;
  907. this.dir = 1;
  908. this.dropCount = 0;
  909. this.filtered = false;
  910. this.iteratees = null;
  911. this.takeCount = POSITIVE_INFINITY;
  912. this.views = null;
  913. this.wrapped = value;
  914. }
  915. /**
  916. * Creates a clone of the lazy wrapper object.
  917. *
  918. * @private
  919. * @name clone
  920. * @memberOf LazyWrapper
  921. * @returns {Object} Returns the cloned `LazyWrapper` object.
  922. */
  923. function lazyClone() {
  924. var actions = this.actions,
  925. iteratees = this.iteratees,
  926. views = this.views,
  927. result = new LazyWrapper(this.wrapped);
  928. result.actions = actions ? arrayCopy(actions) : null;
  929. result.dir = this.dir;
  930. result.dropCount = this.dropCount;
  931. result.filtered = this.filtered;
  932. result.iteratees = iteratees ? arrayCopy(iteratees) : null;
  933. result.takeCount = this.takeCount;
  934. result.views = views ? arrayCopy(views) : null;
  935. return result;
  936. }
  937. /**
  938. * Reverses the direction of lazy iteration.
  939. *
  940. * @private
  941. * @name reverse
  942. * @memberOf LazyWrapper
  943. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  944. */
  945. function lazyReverse() {
  946. var filtered = this.filtered,
  947. result = filtered ? new LazyWrapper(this) : this.clone();
  948. result.dir = this.dir * -1;
  949. result.filtered = filtered;
  950. return result;
  951. }
  952. /**
  953. * Extracts the unwrapped value from its lazy wrapper.
  954. *
  955. * @private
  956. * @name value
  957. * @memberOf LazyWrapper
  958. * @returns {*} Returns the unwrapped value.
  959. */
  960. function lazyValue() {
  961. var array = this.wrapped.value();
  962. if (!isArray(array)) {
  963. return baseWrapperValue(array, this.actions);
  964. }
  965. var dir = this.dir,
  966. isRight = dir < 0,
  967. length = array.length,
  968. view = getView(0, length, this.views),
  969. start = view.start,
  970. end = view.end,
  971. dropCount = this.dropCount,
  972. takeCount = nativeMin(end - start, this.takeCount - dropCount),
  973. index = isRight ? end : start - 1,
  974. iteratees = this.iteratees,
  975. iterLength = iteratees ? iteratees.length : 0,
  976. resIndex = 0,
  977. result = [];
  978. outer:
  979. while (length-- && resIndex < takeCount) {
  980. index += dir;
  981. var iterIndex = -1,
  982. value = array[index];
  983. while (++iterIndex < iterLength) {
  984. var data = iteratees[iterIndex],
  985. iteratee = data.iteratee,
  986. computed = iteratee(value, index, array),
  987. type = data.type;
  988. if (type == LAZY_MAP_FLAG) {
  989. value = computed;
  990. } else if (!computed) {
  991. if (type == LAZY_FILTER_FLAG) {
  992. continue outer;
  993. } else {
  994. break outer;
  995. }
  996. }
  997. }
  998. if (dropCount) {
  999. dropCount--;
  1000. } else {
  1001. result[resIndex++] = value;
  1002. }
  1003. }
  1004. return isRight ? result.reverse() : result;
  1005. }
  1006. /*------------------------------------------------------------------------*/
  1007. /**
  1008. * Creates a cache object to store key/value pairs.
  1009. *
  1010. * @private
  1011. * @static
  1012. * @name Cache
  1013. * @memberOf _.memoize
  1014. */
  1015. function MapCache() {
  1016. this.__data__ = {};
  1017. }
  1018. /**
  1019. * Removes `key` and its value from the cache.
  1020. *
  1021. * @private
  1022. * @name delete
  1023. * @memberOf _.memoize.Cache
  1024. * @param {string} key The key of the value to remove.
  1025. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1026. */
  1027. function mapDelete(key) {
  1028. return this.has(key) && delete this.__data__[key];
  1029. }
  1030. /**
  1031. * Gets the cached value for `key`.
  1032. *
  1033. * @private
  1034. * @name get
  1035. * @memberOf _.memoize.Cache
  1036. * @param {string} key The key of the value to get.
  1037. * @returns {*} Returns the cached value.
  1038. */
  1039. function mapGet(key) {
  1040. return key == '__proto__' ? undefined : this.__data__[key];
  1041. }
  1042. /**
  1043. * Checks if a cached value for `key` exists.
  1044. *
  1045. * @private
  1046. * @name has
  1047. * @memberOf _.memoize.Cache
  1048. * @param {string} key The key of the entry to check.
  1049. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1050. */
  1051. function mapHas(key) {
  1052. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1053. }
  1054. /**
  1055. * Adds `value` to `key` of the cache.
  1056. *
  1057. * @private
  1058. * @name set
  1059. * @memberOf _.memoize.Cache
  1060. * @param {string} key The key of the value to cache.
  1061. * @param {*} value The value to cache.
  1062. * @returns {Object} Returns the cache object.
  1063. */
  1064. function mapSet(key, value) {
  1065. if (key != '__proto__') {
  1066. this.__data__[key] = value;
  1067. }
  1068. return this;
  1069. }
  1070. /*------------------------------------------------------------------------*/
  1071. /**
  1072. *
  1073. * Creates a cache object to store unique values.
  1074. *
  1075. * @private
  1076. * @param {Array} [values] The values to cache.
  1077. */
  1078. function SetCache(values) {
  1079. var length = values ? values.length : 0;
  1080. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1081. while (length--) {
  1082. this.push(values[length]);
  1083. }
  1084. }
  1085. /**
  1086. * Checks if `value` is in `cache` mimicking the return signature of
  1087. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1088. *
  1089. * @private
  1090. * @param {Object} cache The cache to search.
  1091. * @param {*} value The value to search for.
  1092. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1093. */
  1094. function cacheIndexOf(cache, value) {
  1095. var data = cache.data,
  1096. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1097. return result ? 0 : -1;
  1098. }
  1099. /**
  1100. * Adds `value` to the cache.
  1101. *
  1102. * @private
  1103. * @name push
  1104. * @memberOf SetCache
  1105. * @param {*} value The value to cache.
  1106. */
  1107. function cachePush(value) {
  1108. var data = this.data;
  1109. if (typeof value == 'string' || isObject(value)) {
  1110. data.set.add(value);
  1111. } else {
  1112. data.hash[value] = true;
  1113. }
  1114. }
  1115. /*------------------------------------------------------------------------*/
  1116. /**
  1117. * Copies the values of `source` to `array`.
  1118. *
  1119. * @private
  1120. * @param {Array} source The array to copy values from.
  1121. * @param {Array} [array=[]] The array to copy values to.
  1122. * @returns {Array} Returns `array`.
  1123. */
  1124. function arrayCopy(source, array) {
  1125. var index = -1,
  1126. length = source.length;
  1127. array || (array = Array(length));
  1128. while (++index < length) {
  1129. array[index] = source[index];
  1130. }
  1131. return array;
  1132. }
  1133. /**
  1134. * A specialized version of `_.forEach` for arrays without support for callback
  1135. * shorthands or `this` binding.
  1136. *
  1137. * @private
  1138. * @param {Array} array The array to iterate over.
  1139. * @param {Function} iteratee The function invoked per iteration.
  1140. * @returns {Array} Returns `array`.
  1141. */
  1142. function arrayEach(array, iteratee) {
  1143. var index = -1,
  1144. length = array.length;
  1145. while (++index < length) {
  1146. if (iteratee(array[index], index, array) === false) {
  1147. break;
  1148. }
  1149. }
  1150. return array;
  1151. }
  1152. /**
  1153. * A specialized version of `_.forEachRight` for arrays without support for
  1154. * callback shorthands or `this` binding.
  1155. *
  1156. * @private
  1157. * @param {Array} array The array to iterate over.
  1158. * @param {Function} iteratee The function invoked per iteration.
  1159. * @returns {Array} Returns `array`.
  1160. */
  1161. function arrayEachRight(array, iteratee) {
  1162. var length = array.length;
  1163. while (length--) {
  1164. if (iteratee(array[length], length, array) === false) {
  1165. break;
  1166. }
  1167. }
  1168. return array;
  1169. }
  1170. /**
  1171. * A specialized version of `_.every` for arrays without support for callback
  1172. * shorthands or `this` binding.
  1173. *
  1174. * @private
  1175. * @param {Array} array The array to iterate over.
  1176. * @param {Function} predicate The function invoked per iteration.
  1177. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1178. * else `false`.
  1179. */
  1180. function arrayEvery(array, predicate) {
  1181. var index = -1,
  1182. length = array.length;
  1183. while (++index < length) {
  1184. if (!predicate(array[index], index, array)) {
  1185. return false;
  1186. }
  1187. }
  1188. return true;
  1189. }
  1190. /**
  1191. * A specialized version of `_.filter` for arrays without support for callback
  1192. * shorthands or `this` binding.
  1193. *
  1194. * @private
  1195. * @param {Array} array The array to iterate over.
  1196. * @param {Function} predicate The function invoked per iteration.
  1197. * @returns {Array} Returns the new filtered array.
  1198. */
  1199. function arrayFilter(array, predicate) {
  1200. var index = -1,
  1201. length = array.length,
  1202. resIndex = -1,
  1203. result = [];
  1204. while (++index < length) {
  1205. var value = array[index];
  1206. if (predicate(value, index, array)) {
  1207. result[++resIndex] = value;
  1208. }
  1209. }
  1210. return result;
  1211. }
  1212. /**
  1213. * A specialized version of `_.map` for arrays without support for callback
  1214. * shorthands or `this` binding.
  1215. *
  1216. * @private
  1217. * @param {Array} array The array to iterate over.
  1218. * @param {Function} iteratee The function invoked per iteration.
  1219. * @returns {Array} Returns the new mapped array.
  1220. */
  1221. function arrayMap(array, iteratee) {
  1222. var index = -1,
  1223. length = array.length,
  1224. result = Array(length);
  1225. while (++index < length) {
  1226. result[index] = iteratee(array[index], index, array);
  1227. }
  1228. return result;
  1229. }
  1230. /**
  1231. * A specialized version of `_.max` for arrays without support for iteratees.
  1232. *
  1233. * @private
  1234. * @param {Array} array The array to iterate over.
  1235. * @returns {*} Returns the maximum value.
  1236. */
  1237. function arrayMax(array) {
  1238. var index = -1,
  1239. length = array.length,
  1240. result = NEGATIVE_INFINITY;
  1241. while (++index < length) {
  1242. var value = array[index];
  1243. if (value > result) {
  1244. result = value;
  1245. }
  1246. }
  1247. return result;
  1248. }
  1249. /**
  1250. * A specialized version of `_.min` for arrays without support for iteratees.
  1251. *
  1252. * @private
  1253. * @param {Array} array The array to iterate over.
  1254. * @returns {*} Returns the minimum value.
  1255. */
  1256. function arrayMin(array) {
  1257. var index = -1,
  1258. length = array.length,
  1259. result = POSITIVE_INFINITY;
  1260. while (++index < length) {
  1261. var value = array[index];
  1262. if (value < result) {
  1263. result = value;
  1264. }
  1265. }
  1266. return result;
  1267. }
  1268. /**
  1269. * A specialized version of `_.reduce` for arrays without support for callback
  1270. * shorthands or `this` binding.
  1271. *
  1272. * @private
  1273. * @param {Array} array The array to iterate over.
  1274. * @param {Function} iteratee The function invoked per iteration.
  1275. * @param {*} [accumulator] The initial value.
  1276. * @param {boolean} [initFromArray] Specify using the first element of `array`
  1277. * as the initial value.
  1278. * @returns {*} Returns the accumulated value.
  1279. */
  1280. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  1281. var index = -1,
  1282. length = array.length;
  1283. if (initFromArray && length) {
  1284. accumulator = array[++index];
  1285. }
  1286. while (++index < length) {
  1287. accumulator = iteratee(accumulator, array[index], index, array);
  1288. }
  1289. return accumulator;
  1290. }
  1291. /**
  1292. * A specialized version of `_.reduceRight` for arrays without support for
  1293. * callback shorthands or `this` binding.
  1294. *
  1295. * @private
  1296. * @param {Array} array The array to iterate over.
  1297. * @param {Function} iteratee The function invoked per iteration.
  1298. * @param {*} [accumulator] The initial value.
  1299. * @param {boolean} [initFromArray] Specify using the last element of `array`
  1300. * as the initial value.
  1301. * @returns {*} Returns the accumulated value.
  1302. */
  1303. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  1304. var length = array.length;
  1305. if (initFromArray && length) {
  1306. accumulator = array[--length];
  1307. }
  1308. while (length--) {
  1309. accumulator = iteratee(accumulator, array[length], length, array);
  1310. }
  1311. return accumulator;
  1312. }
  1313. /**
  1314. * A specialized version of `_.some` for arrays without support for callback
  1315. * shorthands or `this` binding.
  1316. *
  1317. * @private
  1318. * @param {Array} array The array to iterate over.
  1319. * @param {Function} predicate The function invoked per iteration.
  1320. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1321. * else `false`.
  1322. */
  1323. function arraySome(array, predicate) {
  1324. var index = -1,
  1325. length = array.length;
  1326. while (++index < length) {
  1327. if (predicate(array[index], index, array)) {
  1328. return true;
  1329. }
  1330. }
  1331. return false;
  1332. }
  1333. /**
  1334. * Used by `_.defaults` to customize its `_.assign` use.
  1335. *
  1336. * @private
  1337. * @param {*} objectValue The destination object property value.
  1338. * @param {*} sourceValue The source object property value.
  1339. * @returns {*} Returns the value to assign to the destination object.
  1340. */
  1341. function assignDefaults(objectValue, sourceValue) {
  1342. return typeof objectValue == 'undefined' ? sourceValue : objectValue;
  1343. }
  1344. /**
  1345. * Used by `_.template` to customize its `_.assign` use.
  1346. *
  1347. * **Note:** This method is like `assignDefaults` except that it ignores
  1348. * inherited property values when checking if a property is `undefined`.
  1349. *
  1350. * @private
  1351. * @param {*} objectValue The destination object property value.
  1352. * @param {*} sourceValue The source object property value.
  1353. * @param {string} key The key associated with the object and source values.
  1354. * @param {Object} object The destination object.
  1355. * @returns {*} Returns the value to assign to the destination object.
  1356. */
  1357. function assignOwnDefaults(objectValue, sourceValue, key, object) {
  1358. return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
  1359. ? sourceValue
  1360. : objectValue;
  1361. }
  1362. /**
  1363. * The