PageRenderTime 112ms CodeModel.GetById 14ms RepoModel.GetById 6ms app.codeStats 0ms

/front/platforms/android/cordova/node_modules/lodash/index.js

https://gitlab.com/boxnia/NFU_MOVIL
JavaScript | 1514 lines | 1478 code | 14 blank | 22 comment | 0 complexity | f5d02b320d423df6e418ef39f0ee3d66 MD5 | raw file
  1. /**
  2. * @license
  3. * lodash 3.10.1 (Custom Build) <https://lodash.com/>
  4. * Build: `lodash modern -d -o ./index.js`
  5. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  6. * Based on Underscore.js 1.8.3 <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.10.1';
  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. ARY_FLAG = 128,
  24. REARG_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 as the size to enable large array optimizations. */
  32. var LARGE_ARRAY_SIZE = 200;
  33. /** Used to indicate the type of lazy iteratees. */
  34. var LAZY_FILTER_FLAG = 1,
  35. LAZY_MAP_FLAG = 2;
  36. /** Used as the `TypeError` message for "Functions" methods. */
  37. var FUNC_ERROR_TEXT = 'Expected a function';
  38. /** Used as the internal argument placeholder. */
  39. var PLACEHOLDER = '__lodash_placeholder__';
  40. /** `Object#toString` result references. */
  41. var argsTag = '[object Arguments]',
  42. arrayTag = '[object Array]',
  43. boolTag = '[object Boolean]',
  44. dateTag = '[object Date]',
  45. errorTag = '[object Error]',
  46. funcTag = '[object Function]',
  47. mapTag = '[object Map]',
  48. numberTag = '[object Number]',
  49. objectTag = '[object Object]',
  50. regexpTag = '[object RegExp]',
  51. setTag = '[object Set]',
  52. stringTag = '[object String]',
  53. weakMapTag = '[object WeakMap]';
  54. var arrayBufferTag = '[object ArrayBuffer]',
  55. float32Tag = '[object Float32Array]',
  56. float64Tag = '[object Float64Array]',
  57. int8Tag = '[object Int8Array]',
  58. int16Tag = '[object Int16Array]',
  59. int32Tag = '[object Int32Array]',
  60. uint8Tag = '[object Uint8Array]',
  61. uint8ClampedTag = '[object Uint8ClampedArray]',
  62. uint16Tag = '[object Uint16Array]',
  63. uint32Tag = '[object Uint32Array]';
  64. /** Used to match empty string literals in compiled template source. */
  65. var reEmptyStringLeading = /\b__p \+= '';/g,
  66. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  67. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  68. /** Used to match HTML entities and HTML characters. */
  69. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  70. reUnescapedHtml = /[&<>"'`]/g,
  71. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  72. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  73. /** Used to match template delimiters. */
  74. var reEscape = /<%-([\s\S]+?)%>/g,
  75. reEvaluate = /<%([\s\S]+?)%>/g,
  76. reInterpolate = /<%=([\s\S]+?)%>/g;
  77. /** Used to match property names within property paths. */
  78. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
  79. reIsPlainProp = /^\w*$/,
  80. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
  81. /**
  82. * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
  83. * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
  84. */
  85. var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
  86. reHasRegExpChars = RegExp(reRegExpChars.source);
  87. /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
  88. var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
  89. /** Used to match backslashes in property paths. */
  90. var reEscapeChar = /\\(\\)?/g;
  91. /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
  92. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  93. /** Used to match `RegExp` flags from their coerced string values. */
  94. var reFlags = /\w*$/;
  95. /** Used to detect hexadecimal string values. */
  96. var reHasHexPrefix = /^0[xX]/;
  97. /** Used to detect host constructors (Safari > 5). */
  98. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  99. /** Used to detect unsigned integer values. */
  100. var reIsUint = /^\d+$/;
  101. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  102. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  103. /** Used to ensure capturing order of template delimiters. */
  104. var reNoMatch = /($^)/;
  105. /** Used to match unescaped characters in compiled string literals. */
  106. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  107. /** Used to match words to create compound words. */
  108. var reWords = (function() {
  109. var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
  110. lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
  111. return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
  112. }());
  113. /** Used to assign default `context` object properties. */
  114. var contextProps = [
  115. 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  116. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
  117. 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
  118. 'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
  119. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
  120. ];
  121. /** Used to make template sourceURLs easier to identify. */
  122. var templateCounter = -1;
  123. /** Used to identify `toStringTag` values of typed arrays. */
  124. var typedArrayTags = {};
  125. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  126. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  127. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  128. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  129. typedArrayTags[uint32Tag] = true;
  130. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  131. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  132. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  133. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  134. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  135. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  136. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  137. /** Used to identify `toStringTag` values supported by `_.clone`. */
  138. var cloneableTags = {};
  139. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  140. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  141. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  142. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  143. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  144. cloneableTags[numberTag] = cloneableTags[objectTag] =
  145. cloneableTags[regexpTag] = cloneableTags[stringTag] =
  146. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  147. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  148. cloneableTags[errorTag] = cloneableTags[funcTag] =
  149. cloneableTags[mapTag] = cloneableTags[setTag] =
  150. cloneableTags[weakMapTag] = false;
  151. /** Used to map latin-1 supplementary letters to basic latin letters. */
  152. var deburredLetters = {
  153. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  154. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  155. '\xc7': 'C', '\xe7': 'c',
  156. '\xd0': 'D', '\xf0': 'd',
  157. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  158. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  159. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  160. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  161. '\xd1': 'N', '\xf1': 'n',
  162. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  163. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  164. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  165. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  166. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  167. '\xc6': 'Ae', '\xe6': 'ae',
  168. '\xde': 'Th', '\xfe': 'th',
  169. '\xdf': 'ss'
  170. };
  171. /** Used to map characters to HTML entities. */
  172. var htmlEscapes = {
  173. '&': '&amp;',
  174. '<': '&lt;',
  175. '>': '&gt;',
  176. '"': '&quot;',
  177. "'": '&#39;',
  178. '`': '&#96;'
  179. };
  180. /** Used to map HTML entities to characters. */
  181. var htmlUnescapes = {
  182. '&amp;': '&',
  183. '&lt;': '<',
  184. '&gt;': '>',
  185. '&quot;': '"',
  186. '&#39;': "'",
  187. '&#96;': '`'
  188. };
  189. /** Used to determine if values are of the language type `Object`. */
  190. var objectTypes = {
  191. 'function': true,
  192. 'object': true
  193. };
  194. /** Used to escape characters for inclusion in compiled regexes. */
  195. var regexpEscapes = {
  196. '0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
  197. '5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
  198. 'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
  199. 'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
  200. 'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
  201. };
  202. /** Used to escape characters for inclusion in compiled string literals. */
  203. var stringEscapes = {
  204. '\\': '\\',
  205. "'": "'",
  206. '\n': 'n',
  207. '\r': 'r',
  208. '\u2028': 'u2028',
  209. '\u2029': 'u2029'
  210. };
  211. /** Detect free variable `exports`. */
  212. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  213. /** Detect free variable `module`. */
  214. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  215. /** Detect free variable `global` from Node.js. */
  216. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
  217. /** Detect free variable `self`. */
  218. var freeSelf = objectTypes[typeof self] && self && self.Object && self;
  219. /** Detect free variable `window`. */
  220. var freeWindow = objectTypes[typeof window] && window && window.Object && window;
  221. /** Detect the popular CommonJS extension `module.exports`. */
  222. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  223. /**
  224. * Used as a reference to the global object.
  225. *
  226. * The `this` value is used if it's the global object to avoid Greasemonkey's
  227. * restricted `window` object, otherwise the `window` object is used.
  228. */
  229. var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
  230. /*--------------------------------------------------------------------------*/
  231. /**
  232. * The base implementation of `compareAscending` which compares values and
  233. * sorts them in ascending order without guaranteeing a stable sort.
  234. *
  235. * @private
  236. * @param {*} value The value to compare.
  237. * @param {*} other The other value to compare.
  238. * @returns {number} Returns the sort order indicator for `value`.
  239. */
  240. function baseCompareAscending(value, other) {
  241. if (value !== other) {
  242. var valIsNull = value === null,
  243. valIsUndef = value === undefined,
  244. valIsReflexive = value === value;
  245. var othIsNull = other === null,
  246. othIsUndef = other === undefined,
  247. othIsReflexive = other === other;
  248. if ((value > other && !othIsNull) || !valIsReflexive ||
  249. (valIsNull && !othIsUndef && othIsReflexive) ||
  250. (valIsUndef && othIsReflexive)) {
  251. return 1;
  252. }
  253. if ((value < other && !valIsNull) || !othIsReflexive ||
  254. (othIsNull && !valIsUndef && valIsReflexive) ||
  255. (othIsUndef && valIsReflexive)) {
  256. return -1;
  257. }
  258. }
  259. return 0;
  260. }
  261. /**
  262. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  263. * support for callback shorthands and `this` binding.
  264. *
  265. * @private
  266. * @param {Array} array The array to search.
  267. * @param {Function} predicate The function invoked per iteration.
  268. * @param {boolean} [fromRight] Specify iterating from right to left.
  269. * @returns {number} Returns the index of the matched value, else `-1`.
  270. */
  271. function baseFindIndex(array, predicate, fromRight) {
  272. var length = array.length,
  273. index = fromRight ? length : -1;
  274. while ((fromRight ? index-- : ++index < length)) {
  275. if (predicate(array[index], index, array)) {
  276. return index;
  277. }
  278. }
  279. return -1;
  280. }
  281. /**
  282. * The base implementation of `_.indexOf` without support for binary searches.
  283. *
  284. * @private
  285. * @param {Array} array The array to search.
  286. * @param {*} value The value to search for.
  287. * @param {number} fromIndex The index to search from.
  288. * @returns {number} Returns the index of the matched value, else `-1`.
  289. */
  290. function baseIndexOf(array, value, fromIndex) {
  291. if (value !== value) {
  292. return indexOfNaN(array, fromIndex);
  293. }
  294. var index = fromIndex - 1,
  295. length = array.length;
  296. while (++index < length) {
  297. if (array[index] === value) {
  298. return index;
  299. }
  300. }
  301. return -1;
  302. }
  303. /**
  304. * The base implementation of `_.isFunction` without support for environments
  305. * with incorrect `typeof` results.
  306. *
  307. * @private
  308. * @param {*} value The value to check.
  309. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  310. */
  311. function baseIsFunction(value) {
  312. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
  313. // See https://github.com/jashkenas/underscore/issues/1621 for more details.
  314. return typeof value == 'function' || false;
  315. }
  316. /**
  317. * Converts `value` to a string if it's not one. An empty string is returned
  318. * for `null` or `undefined` values.
  319. *
  320. * @private
  321. * @param {*} value The value to process.
  322. * @returns {string} Returns the string.
  323. */
  324. function baseToString(value) {
  325. return value == null ? '' : (value + '');
  326. }
  327. /**
  328. * Used by `_.trim` and `_.trimLeft` to get the index of the first character
  329. * of `string` that is not found in `chars`.
  330. *
  331. * @private
  332. * @param {string} string The string to inspect.
  333. * @param {string} chars The characters to find.
  334. * @returns {number} Returns the index of the first character not found in `chars`.
  335. */
  336. function charsLeftIndex(string, chars) {
  337. var index = -1,
  338. length = string.length;
  339. while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  340. return index;
  341. }
  342. /**
  343. * Used by `_.trim` and `_.trimRight` to get the index of the last character
  344. * of `string` that is not found in `chars`.
  345. *
  346. * @private
  347. * @param {string} string The string to inspect.
  348. * @param {string} chars The characters to find.
  349. * @returns {number} Returns the index of the last character not found in `chars`.
  350. */
  351. function charsRightIndex(string, chars) {
  352. var index = string.length;
  353. while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
  354. return index;
  355. }
  356. /**
  357. * Used by `_.sortBy` to compare transformed elements of a collection and stable
  358. * sort them in ascending order.
  359. *
  360. * @private
  361. * @param {Object} object The object to compare.
  362. * @param {Object} other The other object to compare.
  363. * @returns {number} Returns the sort order indicator for `object`.
  364. */
  365. function compareAscending(object, other) {
  366. return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
  367. }
  368. /**
  369. * Used by `_.sortByOrder` to compare multiple properties of a value to another
  370. * and stable sort them.
  371. *
  372. * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
  373. * a value is sorted in ascending order if its corresponding order is "asc", and
  374. * descending if "desc".
  375. *
  376. * @private
  377. * @param {Object} object The object to compare.
  378. * @param {Object} other The other object to compare.
  379. * @param {boolean[]} orders The order to sort by for each property.
  380. * @returns {number} Returns the sort order indicator for `object`.
  381. */
  382. function compareMultiple(object, other, orders) {
  383. var index = -1,
  384. objCriteria = object.criteria,
  385. othCriteria = other.criteria,
  386. length = objCriteria.length,
  387. ordersLength = orders.length;
  388. while (++index < length) {
  389. var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
  390. if (result) {
  391. if (index >= ordersLength) {
  392. return result;
  393. }
  394. var order = orders[index];
  395. return result * ((order === 'asc' || order === true) ? 1 : -1);
  396. }
  397. }
  398. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  399. // that causes it, under certain circumstances, to provide the same value for
  400. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  401. // for more details.
  402. //
  403. // This also ensures a stable sort in V8 and other engines.
  404. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  405. return object.index - other.index;
  406. }
  407. /**
  408. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  409. *
  410. * @private
  411. * @param {string} letter The matched letter to deburr.
  412. * @returns {string} Returns the deburred letter.
  413. */
  414. function deburrLetter(letter) {
  415. return deburredLetters[letter];
  416. }
  417. /**
  418. * Used by `_.escape` to convert characters to HTML entities.
  419. *
  420. * @private
  421. * @param {string} chr The matched character to escape.
  422. * @returns {string} Returns the escaped character.
  423. */
  424. function escapeHtmlChar(chr) {
  425. return htmlEscapes[chr];
  426. }
  427. /**
  428. * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
  429. *
  430. * @private
  431. * @param {string} chr The matched character to escape.
  432. * @param {string} leadingChar The capture group for a leading character.
  433. * @param {string} whitespaceChar The capture group for a whitespace character.
  434. * @returns {string} Returns the escaped character.
  435. */
  436. function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
  437. if (leadingChar) {
  438. chr = regexpEscapes[chr];
  439. } else if (whitespaceChar) {
  440. chr = stringEscapes[chr];
  441. }
  442. return '\\' + chr;
  443. }
  444. /**
  445. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  446. *
  447. * @private
  448. * @param {string} chr The matched character to escape.
  449. * @returns {string} Returns the escaped character.
  450. */
  451. function escapeStringChar(chr) {
  452. return '\\' + stringEscapes[chr];
  453. }
  454. /**
  455. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  456. *
  457. * @private
  458. * @param {Array} array The array to search.
  459. * @param {number} fromIndex The index to search from.
  460. * @param {boolean} [fromRight] Specify iterating from right to left.
  461. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  462. */
  463. function indexOfNaN(array, fromIndex, fromRight) {
  464. var length = array.length,
  465. index = fromIndex + (fromRight ? 0 : -1);
  466. while ((fromRight ? index-- : ++index < length)) {
  467. var other = array[index];
  468. if (other !== other) {
  469. return index;
  470. }
  471. }
  472. return -1;
  473. }
  474. /**
  475. * Checks if `value` is object-like.
  476. *
  477. * @private
  478. * @param {*} value The value to check.
  479. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  480. */
  481. function isObjectLike(value) {
  482. return !!value && typeof value == 'object';
  483. }
  484. /**
  485. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  486. * character code is whitespace.
  487. *
  488. * @private
  489. * @param {number} charCode The character code to inspect.
  490. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  491. */
  492. function isSpace(charCode) {
  493. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  494. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  495. }
  496. /**
  497. * Replaces all `placeholder` elements in `array` with an internal placeholder
  498. * and returns an array of their indexes.
  499. *
  500. * @private
  501. * @param {Array} array The array to modify.
  502. * @param {*} placeholder The placeholder to replace.
  503. * @returns {Array} Returns the new array of placeholder indexes.
  504. */
  505. function replaceHolders(array, placeholder) {
  506. var index = -1,
  507. length = array.length,
  508. resIndex = -1,
  509. result = [];
  510. while (++index < length) {
  511. if (array[index] === placeholder) {
  512. array[index] = PLACEHOLDER;
  513. result[++resIndex] = index;
  514. }
  515. }
  516. return result;
  517. }
  518. /**
  519. * An implementation of `_.uniq` optimized for sorted arrays without support
  520. * for callback shorthands and `this` binding.
  521. *
  522. * @private
  523. * @param {Array} array The array to inspect.
  524. * @param {Function} [iteratee] The function invoked per iteration.
  525. * @returns {Array} Returns the new duplicate-value-free array.
  526. */
  527. function sortedUniq(array, iteratee) {
  528. var seen,
  529. index = -1,
  530. length = array.length,
  531. resIndex = -1,
  532. result = [];
  533. while (++index < length) {
  534. var value = array[index],
  535. computed = iteratee ? iteratee(value, index, array) : value;
  536. if (!index || seen !== computed) {
  537. seen = computed;
  538. result[++resIndex] = value;
  539. }
  540. }
  541. return result;
  542. }
  543. /**
  544. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  545. * character of `string`.
  546. *
  547. * @private
  548. * @param {string} string The string to inspect.
  549. * @returns {number} Returns the index of the first non-whitespace character.
  550. */
  551. function trimmedLeftIndex(string) {
  552. var index = -1,
  553. length = string.length;
  554. while (++index < length && isSpace(string.charCodeAt(index))) {}
  555. return index;
  556. }
  557. /**
  558. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  559. * character of `string`.
  560. *
  561. * @private
  562. * @param {string} string The string to inspect.
  563. * @returns {number} Returns the index of the last non-whitespace character.
  564. */
  565. function trimmedRightIndex(string) {
  566. var index = string.length;
  567. while (index-- && isSpace(string.charCodeAt(index))) {}
  568. return index;
  569. }
  570. /**
  571. * Used by `_.unescape` to convert HTML entities to characters.
  572. *
  573. * @private
  574. * @param {string} chr The matched character to unescape.
  575. * @returns {string} Returns the unescaped character.
  576. */
  577. function unescapeHtmlChar(chr) {
  578. return htmlUnescapes[chr];
  579. }
  580. /*--------------------------------------------------------------------------*/
  581. /**
  582. * Create a new pristine `lodash` function using the given `context` object.
  583. *
  584. * @static
  585. * @memberOf _
  586. * @category Utility
  587. * @param {Object} [context=root] The context object.
  588. * @returns {Function} Returns a new `lodash` function.
  589. * @example
  590. *
  591. * _.mixin({ 'foo': _.constant('foo') });
  592. *
  593. * var lodash = _.runInContext();
  594. * lodash.mixin({ 'bar': lodash.constant('bar') });
  595. *
  596. * _.isFunction(_.foo);
  597. * // => true
  598. * _.isFunction(_.bar);
  599. * // => false
  600. *
  601. * lodash.isFunction(lodash.foo);
  602. * // => false
  603. * lodash.isFunction(lodash.bar);
  604. * // => true
  605. *
  606. * // using `context` to mock `Date#getTime` use in `_.now`
  607. * var mock = _.runInContext({
  608. * 'Date': function() {
  609. * return { 'getTime': getTimeMock };
  610. * }
  611. * });
  612. *
  613. * // or creating a suped-up `defer` in Node.js
  614. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  615. */
  616. function runInContext(context) {
  617. // Avoid issues with some ES3 environments that attempt to use values, named
  618. // after built-in constructors like `Object`, for the creation of literals.
  619. // ES5 clears this up by stating that literals must use built-in constructors.
  620. // See https://es5.github.io/#x11.1.5 for more details.
  621. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  622. /** Native constructor references. */
  623. var Array = context.Array,
  624. Date = context.Date,
  625. Error = context.Error,
  626. Function = context.Function,
  627. Math = context.Math,
  628. Number = context.Number,
  629. Object = context.Object,
  630. RegExp = context.RegExp,
  631. String = context.String,
  632. TypeError = context.TypeError;
  633. /** Used for native method references. */
  634. var arrayProto = Array.prototype,
  635. objectProto = Object.prototype,
  636. stringProto = String.prototype;
  637. /** Used to resolve the decompiled source of functions. */
  638. var fnToString = Function.prototype.toString;
  639. /** Used to check objects for own properties. */
  640. var hasOwnProperty = objectProto.hasOwnProperty;
  641. /** Used to generate unique IDs. */
  642. var idCounter = 0;
  643. /**
  644. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  645. * of values.
  646. */
  647. var objToString = objectProto.toString;
  648. /** Used to restore the original `_` reference in `_.noConflict`. */
  649. var oldDash = root._;
  650. /** Used to detect if a method is native. */
  651. var reIsNative = RegExp('^' +
  652. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  653. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  654. );
  655. /** Native method references. */
  656. var ArrayBuffer = context.ArrayBuffer,
  657. clearTimeout = context.clearTimeout,
  658. parseFloat = context.parseFloat,
  659. pow = Math.pow,
  660. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  661. Set = getNative(context, 'Set'),
  662. setTimeout = context.setTimeout,
  663. splice = arrayProto.splice,
  664. Uint8Array = context.Uint8Array,
  665. WeakMap = getNative(context, 'WeakMap');
  666. /* Native method references for those with the same name as other `lodash` methods. */
  667. var nativeCeil = Math.ceil,
  668. nativeCreate = getNative(Object, 'create'),
  669. nativeFloor = Math.floor,
  670. nativeIsArray = getNative(Array, 'isArray'),
  671. nativeIsFinite = context.isFinite,
  672. nativeKeys = getNative(Object, 'keys'),
  673. nativeMax = Math.max,
  674. nativeMin = Math.min,
  675. nativeNow = getNative(Date, 'now'),
  676. nativeParseInt = context.parseInt,
  677. nativeRandom = Math.random;
  678. /** Used as references for `-Infinity` and `Infinity`. */
  679. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  680. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  681. /** Used as references for the maximum length and index of an array. */
  682. var MAX_ARRAY_LENGTH = 4294967295,
  683. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  684. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  685. /**
  686. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  687. * of an array-like value.
  688. */
  689. var MAX_SAFE_INTEGER = 9007199254740991;
  690. /** Used to store function metadata. */
  691. var metaMap = WeakMap && new WeakMap;
  692. /** Used to lookup unminified function names. */
  693. var realNames = {};
  694. /*------------------------------------------------------------------------*/
  695. /**
  696. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  697. * Methods that operate on and return arrays, collections, and functions can
  698. * be chained together. Methods that retrieve a single value or may return a
  699. * primitive value will automatically end the chain returning the unwrapped
  700. * value. Explicit chaining may be enabled using `_.chain`. The execution of
  701. * chained methods is lazy, that is, execution is deferred until `_#value`
  702. * is implicitly or explicitly called.
  703. *
  704. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  705. * fusion is an optimization strategy which merge iteratee calls; this can help
  706. * to avoid the creation of intermediate data structures and greatly reduce the
  707. * number of iteratee executions.
  708. *
  709. * Chaining is supported in custom builds as long as the `_#value` method is
  710. * directly or indirectly included in the build.
  711. *
  712. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  713. *
  714. * The wrapper `Array` methods are:
  715. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
  716. * `splice`, and `unshift`
  717. *
  718. * The wrapper `String` methods are:
  719. * `replace` and `split`
  720. *
  721. * The wrapper methods that support shortcut fusion are:
  722. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  723. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  724. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  725. * and `where`
  726. *
  727. * The chainable wrapper methods are:
  728. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  729. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  730. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
  731. * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
  732. * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
  733. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  734. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  735. * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
  736. * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
  737. * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  738. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  739. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
  740. * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
  741. * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
  742. * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
  743. * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
  744. * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
  745. *
  746. * The wrapper methods that are **not** chainable by default are:
  747. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
  748. * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
  749. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
  750. * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
  751. * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  752. * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
  753. * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
  754. * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
  755. * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
  756. * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
  757. * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
  758. * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
  759. * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
  760. * `unescape`, `uniqueId`, `value`, and `words`
  761. *
  762. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  763. * otherwise an unwrapped value is returned.
  764. *
  765. * @name _
  766. * @constructor
  767. * @category Chain
  768. * @param {*} value The value to wrap in a `lodash` instance.
  769. * @returns {Object} Returns the new `lodash` wrapper instance.
  770. * @example
  771. *
  772. * var wrapped = _([1, 2, 3]);
  773. *
  774. * // returns an unwrapped value
  775. * wrapped.reduce(function(total, n) {
  776. * return total + n;
  777. * });
  778. * // => 6
  779. *
  780. * // returns a wrapped value
  781. * var squares = wrapped.map(function(n) {
  782. * return n * n;
  783. * });
  784. *
  785. * _.isArray(squares);
  786. * // => false
  787. *
  788. * _.isArray(squares.value());
  789. * // => true
  790. */
  791. function lodash(value) {
  792. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  793. if (value instanceof LodashWrapper) {
  794. return value;
  795. }
  796. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  797. return wrapperClone(value);
  798. }
  799. }
  800. return new LodashWrapper(value);
  801. }
  802. /**
  803. * The function whose prototype all chaining wrappers inherit from.
  804. *
  805. * @private
  806. */
  807. function baseLodash() {
  808. // No operation performed.
  809. }
  810. /**
  811. * The base constructor for creating `lodash` wrapper objects.
  812. *
  813. * @private
  814. * @param {*} value The value to wrap.
  815. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  816. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  817. */
  818. function LodashWrapper(value, chainAll, actions) {
  819. this.__wrapped__ = value;
  820. this.__actions__ = actions || [];
  821. this.__chain__ = !!chainAll;
  822. }
  823. /**
  824. * An object environment feature flags.
  825. *
  826. * @static
  827. * @memberOf _
  828. * @type Object
  829. */
  830. var support = lodash.support = {};
  831. /**
  832. * By default, the template delimiters used by lodash are like those in
  833. * embedded Ruby (ERB). Change the following template settings to use
  834. * alternative delimiters.
  835. *
  836. * @static
  837. * @memberOf _
  838. * @type Object
  839. */
  840. lodash.templateSettings = {
  841. /**
  842. * Used to detect `data` property values to be HTML-escaped.
  843. *
  844. * @memberOf _.templateSettings
  845. * @type RegExp
  846. */
  847. 'escape': reEscape,
  848. /**
  849. * Used to detect code to be evaluated.
  850. *
  851. * @memberOf _.templateSettings
  852. * @type RegExp
  853. */
  854. 'evaluate': reEvaluate,
  855. /**
  856. * Used to detect `data` property values to inject.
  857. *
  858. * @memberOf _.templateSettings
  859. * @type RegExp
  860. */
  861. 'interpolate': reInterpolate,
  862. /**
  863. * Used to reference the data object in the template text.
  864. *
  865. * @memberOf _.templateSettings
  866. * @type string
  867. */
  868. 'variable': '',
  869. /**
  870. * Used to import variables into the compiled template.
  871. *
  872. * @memberOf _.templateSettings
  873. * @type Object
  874. */
  875. 'imports': {
  876. /**
  877. * A reference to the `lodash` function.
  878. *
  879. * @memberOf _.templateSettings.imports
  880. * @type Function
  881. */
  882. '_': lodash
  883. }
  884. };
  885. /*------------------------------------------------------------------------*/
  886. /**
  887. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  888. *
  889. * @private
  890. * @param {*} value The value to wrap.
  891. */
  892. function LazyWrapper(value) {
  893. this.__wrapped__ = value;
  894. this.__actions__ = [];
  895. this.__dir__ = 1;
  896. this.__filtered__ = false;
  897. this.__iteratees__ = [];
  898. this.__takeCount__ = POSITIVE_INFINITY;
  899. this.__views__ = [];
  900. }
  901. /**
  902. * Creates a clone of the lazy wrapper object.
  903. *
  904. * @private
  905. * @name clone
  906. * @memberOf LazyWrapper
  907. * @returns {Object} Returns the cloned `LazyWrapper` object.
  908. */
  909. function lazyClone() {
  910. var result = new LazyWrapper(this.__wrapped__);
  911. result.__actions__ = arrayCopy(this.__actions__);
  912. result.__dir__ = this.__dir__;
  913. result.__filtered__ = this.__filtered__;
  914. result.__iteratees__ = arrayCopy(this.__iteratees__);
  915. result.__takeCount__ = this.__takeCount__;
  916. result.__views__ = arrayCopy(this.__views__);
  917. return result;
  918. }
  919. /**
  920. * Reverses the direction of lazy iteration.
  921. *
  922. * @private
  923. * @name reverse
  924. * @memberOf LazyWrapper
  925. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  926. */
  927. function lazyReverse() {
  928. if (this.__filtered__) {
  929. var result = new LazyWrapper(this);
  930. result.__dir__ = -1;
  931. result.__filtered__ = true;
  932. } else {
  933. result = this.clone();
  934. result.__dir__ *= -1;
  935. }
  936. return result;
  937. }
  938. /**
  939. * Extracts the unwrapped value from its lazy wrapper.
  940. *
  941. * @private
  942. * @name value
  943. * @memberOf LazyWrapper
  944. * @returns {*} Returns the unwrapped value.
  945. */
  946. function lazyValue() {
  947. var array = this.__wrapped__.value(),
  948. dir = this.__dir__,
  949. isArr = isArray(array),
  950. isRight = dir < 0,
  951. arrLength = isArr ? array.length : 0,
  952. view = getView(0, arrLength, this.__views__),
  953. start = view.start,
  954. end = view.end,
  955. length = end - start,
  956. index = isRight ? end : (start - 1),
  957. iteratees = this.__iteratees__,
  958. iterLength = iteratees.length,
  959. resIndex = 0,
  960. takeCount = nativeMin(length, this.__takeCount__);
  961. if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
  962. return baseWrapperValue((isRight && isArr) ? array.reverse() : array, this.__actions__);
  963. }
  964. var result = [];
  965. outer:
  966. while (length-- && resIndex < takeCount) {
  967. index += dir;
  968. var iterIndex = -1,
  969. value = array[index];
  970. while (++iterIndex < iterLength) {
  971. var data = iteratees[iterIndex],
  972. iteratee = data.iteratee,
  973. type = data.type,
  974. computed = iteratee(value);
  975. if (type == LAZY_MAP_FLAG) {
  976. value = computed;
  977. } else if (!computed) {
  978. if (type == LAZY_FILTER_FLAG) {
  979. continue outer;
  980. } else {
  981. break outer;
  982. }
  983. }
  984. }
  985. result[resIndex++] = value;
  986. }
  987. return result;
  988. }
  989. /*------------------------------------------------------------------------*/
  990. /**
  991. * Creates a cache object to store key/value pairs.
  992. *
  993. * @private
  994. * @static
  995. * @name Cache
  996. * @memberOf _.memoize
  997. */
  998. function MapCache() {
  999. this.__data__ = {};
  1000. }
  1001. /**
  1002. * Removes `key` and its value from the cache.
  1003. *
  1004. * @private
  1005. * @name delete
  1006. * @memberOf _.memoize.Cache
  1007. * @param {string} key The key of the value to remove.
  1008. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1009. */
  1010. function mapDelete(key) {
  1011. return this.has(key) && delete this.__data__[key];
  1012. }
  1013. /**
  1014. * Gets the cached value for `key`.
  1015. *
  1016. * @private
  1017. * @name get
  1018. * @memberOf _.memoize.Cache
  1019. * @param {string} key The key of the value to get.
  1020. * @returns {*} Returns the cached value.
  1021. */
  1022. function mapGet(key) {
  1023. return key == '__proto__' ? undefined : this.__data__[key];
  1024. }
  1025. /**
  1026. * Checks if a cached value for `key` exists.
  1027. *
  1028. * @private
  1029. * @name has
  1030. * @memberOf _.memoize.Cache
  1031. * @param {string} key The key of the entry to check.
  1032. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1033. */
  1034. function mapHas(key) {
  1035. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1036. }
  1037. /**
  1038. * Sets `value` to `key` of the cache.
  1039. *
  1040. * @private
  1041. * @name set
  1042. * @memberOf _.memoize.Cache
  1043. * @param {string} key The key of the value to cache.
  1044. * @param {*} value The value to cache.
  1045. * @returns {Object} Returns the cache object.
  1046. */
  1047. function mapSet(key, value) {
  1048. if (key != '__proto__') {
  1049. this.__data__[key] = value;
  1050. }
  1051. return this;
  1052. }
  1053. /*------------------------------------------------------------------------*/
  1054. /**
  1055. *
  1056. * Creates a cache object to store unique values.
  1057. *
  1058. * @private
  1059. * @param {Array} [values] The values to cache.
  1060. */
  1061. function SetCache(values) {
  1062. var length = values ? values.length : 0;
  1063. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1064. while (length--) {
  1065. this.push(values[length]);
  1066. }
  1067. }
  1068. /**
  1069. * Checks if `value` is in `cache` mimicking the return signature of
  1070. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1071. *
  1072. * @private
  1073. * @param {Object} cache The cache to search.
  1074. * @param {*} value The value to search for.
  1075. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1076. */
  1077. function cacheIndexOf(cache, value) {
  1078. var data = cache.data,
  1079. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1080. return result ? 0 : -1;
  1081. }
  1082. /**
  1083. * Adds `value` to the cache.
  1084. *
  1085. * @private
  1086. * @name push
  1087. * @memberOf SetCache
  1088. * @param {*} value The value to cache.
  1089. */
  1090. function cachePush(value) {
  1091. var data = this.data;
  1092. if (typeof value == 'string' || isObject(value)) {
  1093. data.set.add(value);
  1094. } else {
  1095. data.hash[value] = true;
  1096. }
  1097. }
  1098. /*------------------------------------------------------------------------*/
  1099. /**
  1100. * Creates a new array joining `array` with `other`.
  1101. *
  1102. * @private
  1103. * @param {Array} array The array to join.
  1104. * @param {Array} other The other array to join.
  1105. * @returns {Array} Returns the new concatenated array.
  1106. */
  1107. function arrayConcat(array, other) {
  1108. var index = -1,
  1109. length = array.length,
  1110. othIndex = -1,
  1111. othLength = other.length,
  1112. result = Array(length + othLength);
  1113. while (++index < length) {
  1114. result[index] = array[index];
  1115. }
  1116. while (++othIndex < othLength) {
  1117. result[index++] = other[othIndex];
  1118. }
  1119. return result;
  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 and `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 and `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 and `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 `baseExtremum` for arrays which invokes `iteratee`
  1197. * with one argument: (value).
  1198. *
  1199. * @private
  1200. * @param {Array} array The array to iterate over.
  1201. * @param {Function} iteratee The function invoked per iteration.
  1202. * @param {Function} comparator The function used to compare values.
  1203. * @param {*} exValue The initial extremum value.
  1204. * @returns {*} Returns the extremum value.
  1205. */
  1206. function arrayExtremum(array, iteratee, comparator, exValue) {
  1207. var index = -1,
  1208. length = array.length,
  1209. computed = exValue,
  1210. result = computed;
  1211. while (++index < length) {
  1212. var value = array[index],
  1213. current = +iteratee(value);
  1214. if (comparator(current, computed)) {
  1215. computed = current;
  1216. result = value;
  1217. }
  1218. }
  1219. return result;
  1220. }
  1221. /**
  1222. * A specialized version of `_.filter` for arrays without support for callback
  1223. * shorthands and `this` binding.
  1224. *
  1225. * @private
  1226. * @param {Array} array The array to iterate over.
  1227. * @param {Function} predicate The function invoked per iteration.
  1228. * @returns {Array} Returns the new filtered array.
  1229. */
  1230. function arrayFilter(array, predicate) {
  1231. var index = -1,
  1232. length = array.length,
  1233. resIndex = -1,
  1234. result = [];
  1235. while (++index < length) {
  1236. var value = array[index];
  1237. if (predicate(value, index, array)) {
  1238. result[++resIndex] = value;
  1239. }
  1240. }
  1241. return result;
  1242. }
  1243. /**
  1244. * A specialized version of `_.map` for arrays without support for callback
  1245. * shorthands and `this` binding.
  1246. *
  1247. * @private
  1248. * @param {Array} array The array to iterate over.
  1249. * @param {Function} iteratee The function invoked per iteration.
  1250. * @returns {Array} Returns the new mapped array.
  1251. */
  1252. function arrayMap(array, iteratee) {
  1253. var index = -1,
  1254. length = array.length,
  1255. result = Array(length);
  1256. while (++index < length) {
  1257. result[index] = iteratee(array[index], index, array);
  1258. }
  1259. return result;
  1260. }
  1261. /**
  1262. * Appends the elements of `values` to `array`.
  1263. *
  1264. * @private
  1265. * @param {Array} array The array to modify.
  1266. * @param {Array} values The values to append.
  1267. * @returns {Array} Returns `array`.
  1268. */
  1269. function arrayPush(array, values) {
  1270. var index = -1,
  1271. length = values.length,
  1272. offset = array.length;
  1273. while (++index < length) {
  1274. array[offset + index] = values[index];
  1275. }
  1276. return array;
  1277. }
  1278. /**
  1279. * A specialized version of `_.reduce` for arrays without support for callback
  1280. * shorthands and `this` binding.
  1281. *
  1282. * @private
  1283. * @param {Array} array The array to iterate over.
  1284. * @param {Function} iteratee The function invoked per iteration.
  1285. * @param {*} [accumulator] The initial value.
  1286. * @param {boolean} [initFromArray] Specify using the first element of `array`
  1287. * as the initial value.
  1288. * @returns {*} Returns the accumulated value.
  1289. */
  1290. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  1291. var index = -1,
  1292. length = array.length;
  1293. if (initFromArray && length) {
  1294. accumulator = array[++index];
  1295. }
  1296. while (++index < length) {
  1297. accumulator = iteratee(accumulator, array[index], index, array);
  1298. }
  1299. return accumulator;
  1300. }
  1301. /**
  1302. * A specialized version of `_.reduceRight` for arrays without support for
  1303. * callback shorthands and `this` binding.
  1304. *
  1305. * @private
  1306. * @param {Array} array The array to iterate over.
  1307. * @param {Function} iteratee The function invoked per iteration.
  1308. * @param {*} [accumulator] The initial value.
  1309. * @param {boolean} [initFromArray] Specify using the last element of `array`
  1310. * as the initial value.
  1311. * @returns {*} Returns the accumulated value.
  1312. */
  1313. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  1314. var length = array.length;
  1315. if (initFromArray && length) {
  1316. accumulator = array[--length];
  1317. }
  1318. while (length--) {
  1319. accumulator = iteratee(accumulator, array[length], length, array);
  1320. }
  1321. return accumulator;
  1322. }
  1323. /**
  1324. * A specialized version of `_.some` for arrays without support for callback
  1325. * shorthands and `this` binding.
  1326. *
  1327. * @private
  1328. * @param {Array} array The array to iterate over.
  1329. * @param {Function} predicate The function invoked per iteration.
  1330. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1331. * else `false`.
  1332. */
  1333. function arraySome(array, predicate) {
  1334. var index = -1,
  1335. length = array.length;
  1336. while (++index < length) {
  1337. if (predicate(array[index], index, array)) {
  1338. return true;
  1339. }
  1340. }
  1341. return false;
  1342. }
  1343. /**
  1344. * A specialized version of `_.sum` for arrays without support for callback
  1345. * shorthands and `this` binding..
  1346. *
  1347. * @private
  1348. * @param {Array} array The array to iterate over.
  1349. * @param {Function} iteratee The function invoked per iteration.
  1350. * @returns {number} Returns the sum.
  1351. */
  1352. function arraySum(array, iteratee) {
  1353. var length = array.length,
  1354. result = 0;
  1355. while (length--) {