PageRenderTime 30ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lodash/4.6.1/lodash.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1478 lines | 1434 code | 18 blank | 26 comment | 0 complexity | 8067d8322069d92ac0e921fcf36c25b8 MD5 | raw file
  1. /**
  2. * @license
  3. * lodash 4.6.1 (Custom Build) <https://lodash.com/>
  4. * Build: `lodash -o ./dist/lodash.js`
  5. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright 2009-2016 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 = '4.6.1';
  15. /** Used as the size to enable large array optimizations. */
  16. var LARGE_ARRAY_SIZE = 200;
  17. /** Used as the `TypeError` message for "Functions" methods. */
  18. var FUNC_ERROR_TEXT = 'Expected a function';
  19. /** Used to stand-in for `undefined` hash values. */
  20. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  21. /** Used as the internal argument placeholder. */
  22. var PLACEHOLDER = '__lodash_placeholder__';
  23. /** Used to compose bitmasks for wrapper metadata. */
  24. var BIND_FLAG = 1,
  25. BIND_KEY_FLAG = 2,
  26. CURRY_BOUND_FLAG = 4,
  27. CURRY_FLAG = 8,
  28. CURRY_RIGHT_FLAG = 16,
  29. PARTIAL_FLAG = 32,
  30. PARTIAL_RIGHT_FLAG = 64,
  31. ARY_FLAG = 128,
  32. REARG_FLAG = 256,
  33. FLIP_FLAG = 512;
  34. /** Used to compose bitmasks for comparison styles. */
  35. var UNORDERED_COMPARE_FLAG = 1,
  36. PARTIAL_COMPARE_FLAG = 2;
  37. /** Used as default options for `_.truncate`. */
  38. var DEFAULT_TRUNC_LENGTH = 30,
  39. DEFAULT_TRUNC_OMISSION = '...';
  40. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  41. var HOT_COUNT = 150,
  42. HOT_SPAN = 16;
  43. /** Used to indicate the type of lazy iteratees. */
  44. var LAZY_FILTER_FLAG = 1,
  45. LAZY_MAP_FLAG = 2,
  46. LAZY_WHILE_FLAG = 3;
  47. /** Used as references for various `Number` constants. */
  48. var INFINITY = 1 / 0,
  49. MAX_SAFE_INTEGER = 9007199254740991,
  50. MAX_INTEGER = 1.7976931348623157e+308,
  51. NAN = 0 / 0;
  52. /** Used as references for the maximum length and index of an array. */
  53. var MAX_ARRAY_LENGTH = 4294967295,
  54. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  55. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  56. /** `Object#toString` result references. */
  57. var argsTag = '[object Arguments]',
  58. arrayTag = '[object Array]',
  59. boolTag = '[object Boolean]',
  60. dateTag = '[object Date]',
  61. errorTag = '[object Error]',
  62. funcTag = '[object Function]',
  63. genTag = '[object GeneratorFunction]',
  64. mapTag = '[object Map]',
  65. numberTag = '[object Number]',
  66. objectTag = '[object Object]',
  67. regexpTag = '[object RegExp]',
  68. setTag = '[object Set]',
  69. stringTag = '[object String]',
  70. symbolTag = '[object Symbol]',
  71. weakMapTag = '[object WeakMap]',
  72. weakSetTag = '[object WeakSet]';
  73. var arrayBufferTag = '[object ArrayBuffer]',
  74. float32Tag = '[object Float32Array]',
  75. float64Tag = '[object Float64Array]',
  76. int8Tag = '[object Int8Array]',
  77. int16Tag = '[object Int16Array]',
  78. int32Tag = '[object Int32Array]',
  79. uint8Tag = '[object Uint8Array]',
  80. uint8ClampedTag = '[object Uint8ClampedArray]',
  81. uint16Tag = '[object Uint16Array]',
  82. uint32Tag = '[object Uint32Array]';
  83. /** Used to match empty string literals in compiled template source. */
  84. var reEmptyStringLeading = /\b__p \+= '';/g,
  85. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  86. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  87. /** Used to match HTML entities and HTML characters. */
  88. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  89. reUnescapedHtml = /[&<>"'`]/g,
  90. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  91. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  92. /** Used to match template delimiters. */
  93. var reEscape = /<%-([\s\S]+?)%>/g,
  94. reEvaluate = /<%([\s\S]+?)%>/g,
  95. reInterpolate = /<%=([\s\S]+?)%>/g;
  96. /** Used to match property names within property paths. */
  97. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  98. reIsPlainProp = /^\w*$/,
  99. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
  100. /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */
  101. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  102. reHasRegExpChar = RegExp(reRegExpChar.source);
  103. /** Used to match leading and trailing whitespace. */
  104. var reTrim = /^\s+|\s+$/g,
  105. reTrimStart = /^\s+/,
  106. reTrimEnd = /\s+$/;
  107. /** Used to match backslashes in property paths. */
  108. var reEscapeChar = /\\(\\)?/g;
  109. /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
  110. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  111. /** Used to match `RegExp` flags from their coerced string values. */
  112. var reFlags = /\w*$/;
  113. /** Used to detect hexadecimal string values. */
  114. var reHasHexPrefix = /^0x/i;
  115. /** Used to detect bad signed hexadecimal string values. */
  116. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  117. /** Used to detect binary string values. */
  118. var reIsBinary = /^0b[01]+$/i;
  119. /** Used to detect host constructors (Safari > 5). */
  120. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  121. /** Used to detect octal string values. */
  122. var reIsOctal = /^0o[0-7]+$/i;
  123. /** Used to detect unsigned integer values. */
  124. var reIsUint = /^(?:0|[1-9]\d*)$/;
  125. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  126. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  127. /** Used to ensure capturing order of template delimiters. */
  128. var reNoMatch = /($^)/;
  129. /** Used to match unescaped characters in compiled string literals. */
  130. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  131. /** Used to compose unicode character classes. */
  132. var rsAstralRange = '\\ud800-\\udfff',
  133. rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
  134. rsComboSymbolsRange = '\\u20d0-\\u20f0',
  135. rsDingbatRange = '\\u2700-\\u27bf',
  136. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  137. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  138. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  139. rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d',
  140. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  141. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  142. rsVarRange = '\\ufe0e\\ufe0f',
  143. rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange;
  144. /** Used to compose unicode capture groups. */
  145. var rsAstral = '[' + rsAstralRange + ']',
  146. rsBreak = '[' + rsBreakRange + ']',
  147. rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
  148. rsDigits = '\\d+',
  149. rsDingbat = '[' + rsDingbatRange + ']',
  150. rsLower = '[' + rsLowerRange + ']',
  151. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  152. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  153. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  154. rsNonAstral = '[^' + rsAstralRange + ']',
  155. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  156. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  157. rsUpper = '[' + rsUpperRange + ']',
  158. rsZWJ = '\\u200d';
  159. /** Used to compose unicode regexes. */
  160. var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
  161. rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
  162. reOptMod = rsModifier + '?',
  163. rsOptVar = '[' + rsVarRange + ']?',
  164. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  165. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  166. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  167. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  168. /**
  169. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  170. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  171. */
  172. var reComboMark = RegExp(rsCombo, 'g');
  173. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  174. var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  175. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  176. var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
  177. /** Used to match non-compound words composed of alphanumeric characters. */
  178. var reBasicWord = /[a-zA-Z0-9]+/g;
  179. /** Used to match complex or compound words. */
  180. var reComplexWord = RegExp([
  181. rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  182. rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
  183. rsUpper + '?' + rsLowerMisc + '+',
  184. rsUpper + '+',
  185. rsDigits,
  186. rsEmoji
  187. ].join('|'), 'g');
  188. /** Used to detect strings that need a more robust regexp to match words. */
  189. var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  190. /** Used to assign default `context` object properties. */
  191. var contextProps = [
  192. 'Array', 'Buffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  193. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  194. 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  195. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_',
  196. 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  197. ];
  198. /** Used to make template sourceURLs easier to identify. */
  199. var templateCounter = -1;
  200. /** Used to identify `toStringTag` values of typed arrays. */
  201. var typedArrayTags = {};
  202. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  203. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  204. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  205. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  206. typedArrayTags[uint32Tag] = true;
  207. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  208. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  209. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  210. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  211. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  212. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  213. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  214. /** Used to identify `toStringTag` values supported by `_.clone`. */
  215. var cloneableTags = {};
  216. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  217. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  218. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  219. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  220. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  221. cloneableTags[mapTag] = cloneableTags[numberTag] =
  222. cloneableTags[objectTag] = cloneableTags[regexpTag] =
  223. cloneableTags[setTag] = cloneableTags[stringTag] =
  224. cloneableTags[symbolTag] = cloneableTags[uint8Tag] =
  225. cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] =
  226. cloneableTags[uint32Tag] = true;
  227. cloneableTags[errorTag] = cloneableTags[funcTag] =
  228. cloneableTags[weakMapTag] = false;
  229. /** Used to map latin-1 supplementary letters to basic latin letters. */
  230. var deburredLetters = {
  231. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  232. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  233. '\xc7': 'C', '\xe7': 'c',
  234. '\xd0': 'D', '\xf0': 'd',
  235. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  236. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  237. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  238. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  239. '\xd1': 'N', '\xf1': 'n',
  240. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  241. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  242. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  243. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  244. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  245. '\xc6': 'Ae', '\xe6': 'ae',
  246. '\xde': 'Th', '\xfe': 'th',
  247. '\xdf': 'ss'
  248. };
  249. /** Used to map characters to HTML entities. */
  250. var htmlEscapes = {
  251. '&': '&amp;',
  252. '<': '&lt;',
  253. '>': '&gt;',
  254. '"': '&quot;',
  255. "'": '&#39;',
  256. '`': '&#96;'
  257. };
  258. /** Used to map HTML entities to characters. */
  259. var htmlUnescapes = {
  260. '&amp;': '&',
  261. '&lt;': '<',
  262. '&gt;': '>',
  263. '&quot;': '"',
  264. '&#39;': "'",
  265. '&#96;': '`'
  266. };
  267. /** Used to determine if values are of the language type `Object`. */
  268. var objectTypes = {
  269. 'function': true,
  270. 'object': true
  271. };
  272. /** Used to escape characters for inclusion in compiled string literals. */
  273. var stringEscapes = {
  274. '\\': '\\',
  275. "'": "'",
  276. '\n': 'n',
  277. '\r': 'r',
  278. '\u2028': 'u2028',
  279. '\u2029': 'u2029'
  280. };
  281. /** Built-in method references without a dependency on `root`. */
  282. var freeParseFloat = parseFloat,
  283. freeParseInt = parseInt;
  284. /** Detect free variable `exports`. */
  285. var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
  286. ? exports
  287. : undefined;
  288. /** Detect free variable `module`. */
  289. var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
  290. ? module
  291. : undefined;
  292. /** Detect the popular CommonJS extension `module.exports`. */
  293. var moduleExports = (freeModule && freeModule.exports === freeExports)
  294. ? freeExports
  295. : undefined;
  296. /** Detect free variable `global` from Node.js. */
  297. var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
  298. /** Detect free variable `self`. */
  299. var freeSelf = checkGlobal(objectTypes[typeof self] && self);
  300. /** Detect free variable `window`. */
  301. var freeWindow = checkGlobal(objectTypes[typeof window] && window);
  302. /** Detect `this` as the global object. */
  303. var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
  304. /**
  305. * Used as a reference to the global object.
  306. *
  307. * The `this` value is used if it's the global object to avoid Greasemonkey's
  308. * restricted `window` object, otherwise the `window` object is used.
  309. */
  310. var root = freeGlobal ||
  311. ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
  312. freeSelf || thisGlobal || Function('return this')();
  313. /*--------------------------------------------------------------------------*/
  314. /**
  315. * Adds the key-value `pair` to `map`.
  316. *
  317. * @private
  318. * @param {Object} map The map to modify.
  319. * @param {Array} pair The key-value pair to add.
  320. * @returns {Object} Returns `map`.
  321. */
  322. function addMapEntry(map, pair) {
  323. // Don't return `Map#set` because it doesn't return the map instance in IE 11.
  324. map.set(pair[0], pair[1]);
  325. return map;
  326. }
  327. /**
  328. * Adds `value` to `set`.
  329. *
  330. * @private
  331. * @param {Object} set The set to modify.
  332. * @param {*} value The value to add.
  333. * @returns {Object} Returns `set`.
  334. */
  335. function addSetEntry(set, value) {
  336. set.add(value);
  337. return set;
  338. }
  339. /**
  340. * A faster alternative to `Function#apply`, this function invokes `func`
  341. * with the `this` binding of `thisArg` and the arguments of `args`.
  342. *
  343. * @private
  344. * @param {Function} func The function to invoke.
  345. * @param {*} thisArg The `this` binding of `func`.
  346. * @param {...*} args The arguments to invoke `func` with.
  347. * @returns {*} Returns the result of `func`.
  348. */
  349. function apply(func, thisArg, args) {
  350. var length = args.length;
  351. switch (length) {
  352. case 0: return func.call(thisArg);
  353. case 1: return func.call(thisArg, args[0]);
  354. case 2: return func.call(thisArg, args[0], args[1]);
  355. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  356. }
  357. return func.apply(thisArg, args);
  358. }
  359. /**
  360. * A specialized version of `baseAggregator` for arrays.
  361. *
  362. * @private
  363. * @param {Array} array The array to iterate over.
  364. * @param {Function} setter The function to set `accumulator` values.
  365. * @param {Function} iteratee The iteratee to transform keys.
  366. * @param {Object} accumulator The initial aggregated object.
  367. * @returns {Function} Returns `accumulator`.
  368. */
  369. function arrayAggregator(array, setter, iteratee, accumulator) {
  370. var index = -1,
  371. length = array.length;
  372. while (++index < length) {
  373. var value = array[index];
  374. setter(accumulator, value, iteratee(value), array);
  375. }
  376. return accumulator;
  377. }
  378. /**
  379. * Creates a new array concatenating `array` with `other`.
  380. *
  381. * @private
  382. * @param {Array} array The first array to concatenate.
  383. * @param {Array} other The second array to concatenate.
  384. * @returns {Array} Returns the new concatenated array.
  385. */
  386. function arrayConcat(array, other) {
  387. var index = -1,
  388. length = array.length,
  389. othIndex = -1,
  390. othLength = other.length,
  391. result = Array(length + othLength);
  392. while (++index < length) {
  393. result[index] = array[index];
  394. }
  395. while (++othIndex < othLength) {
  396. result[index++] = other[othIndex];
  397. }
  398. return result;
  399. }
  400. /**
  401. * A specialized version of `_.forEach` for arrays without support for
  402. * iteratee shorthands.
  403. *
  404. * @private
  405. * @param {Array} array The array to iterate over.
  406. * @param {Function} iteratee The function invoked per iteration.
  407. * @returns {Array} Returns `array`.
  408. */
  409. function arrayEach(array, iteratee) {
  410. var index = -1,
  411. length = array.length;
  412. while (++index < length) {
  413. if (iteratee(array[index], index, array) === false) {
  414. break;
  415. }
  416. }
  417. return array;
  418. }
  419. /**
  420. * A specialized version of `_.forEachRight` for arrays without support for
  421. * iteratee shorthands.
  422. *
  423. * @private
  424. * @param {Array} array The array to iterate over.
  425. * @param {Function} iteratee The function invoked per iteration.
  426. * @returns {Array} Returns `array`.
  427. */
  428. function arrayEachRight(array, iteratee) {
  429. var length = array.length;
  430. while (length--) {
  431. if (iteratee(array[length], length, array) === false) {
  432. break;
  433. }
  434. }
  435. return array;
  436. }
  437. /**
  438. * A specialized version of `_.every` for arrays without support for
  439. * iteratee shorthands.
  440. *
  441. * @private
  442. * @param {Array} array The array to iterate over.
  443. * @param {Function} predicate The function invoked per iteration.
  444. * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
  445. */
  446. function arrayEvery(array, predicate) {
  447. var index = -1,
  448. length = array.length;
  449. while (++index < length) {
  450. if (!predicate(array[index], index, array)) {
  451. return false;
  452. }
  453. }
  454. return true;
  455. }
  456. /**
  457. * A specialized version of `_.filter` for arrays without support for
  458. * iteratee shorthands.
  459. *
  460. * @private
  461. * @param {Array} array The array to iterate over.
  462. * @param {Function} predicate The function invoked per iteration.
  463. * @returns {Array} Returns the new filtered array.
  464. */
  465. function arrayFilter(array, predicate) {
  466. var index = -1,
  467. length = array.length,
  468. resIndex = 0,
  469. result = [];
  470. while (++index < length) {
  471. var value = array[index];
  472. if (predicate(value, index, array)) {
  473. result[resIndex++] = value;
  474. }
  475. }
  476. return result;
  477. }
  478. /**
  479. * A specialized version of `_.includes` for arrays without support for
  480. * specifying an index to search from.
  481. *
  482. * @private
  483. * @param {Array} array The array to search.
  484. * @param {*} target The value to search for.
  485. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  486. */
  487. function arrayIncludes(array, value) {
  488. return !!array.length && baseIndexOf(array, value, 0) > -1;
  489. }
  490. /**
  491. * This function is like `arrayIncludes` except that it accepts a comparator.
  492. *
  493. * @private
  494. * @param {Array} array The array to search.
  495. * @param {*} target The value to search for.
  496. * @param {Function} comparator The comparator invoked per element.
  497. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  498. */
  499. function arrayIncludesWith(array, value, comparator) {
  500. var index = -1,
  501. length = array.length;
  502. while (++index < length) {
  503. if (comparator(value, array[index])) {
  504. return true;
  505. }
  506. }
  507. return false;
  508. }
  509. /**
  510. * A specialized version of `_.map` for arrays without support for iteratee
  511. * shorthands.
  512. *
  513. * @private
  514. * @param {Array} array The array to iterate over.
  515. * @param {Function} iteratee The function invoked per iteration.
  516. * @returns {Array} Returns the new mapped array.
  517. */
  518. function arrayMap(array, iteratee) {
  519. var index = -1,
  520. length = array.length,
  521. result = Array(length);
  522. while (++index < length) {
  523. result[index] = iteratee(array[index], index, array);
  524. }
  525. return result;
  526. }
  527. /**
  528. * Appends the elements of `values` to `array`.
  529. *
  530. * @private
  531. * @param {Array} array The array to modify.
  532. * @param {Array} values The values to append.
  533. * @returns {Array} Returns `array`.
  534. */
  535. function arrayPush(array, values) {
  536. var index = -1,
  537. length = values.length,
  538. offset = array.length;
  539. while (++index < length) {
  540. array[offset + index] = values[index];
  541. }
  542. return array;
  543. }
  544. /**
  545. * A specialized version of `_.reduce` for arrays without support for
  546. * iteratee shorthands.
  547. *
  548. * @private
  549. * @param {Array} array The array to iterate over.
  550. * @param {Function} iteratee The function invoked per iteration.
  551. * @param {*} [accumulator] The initial value.
  552. * @param {boolean} [initAccum] Specify using the first element of `array` as the initial value.
  553. * @returns {*} Returns the accumulated value.
  554. */
  555. function arrayReduce(array, iteratee, accumulator, initAccum) {
  556. var index = -1,
  557. length = array.length;
  558. if (initAccum && length) {
  559. accumulator = array[++index];
  560. }
  561. while (++index < length) {
  562. accumulator = iteratee(accumulator, array[index], index, array);
  563. }
  564. return accumulator;
  565. }
  566. /**
  567. * A specialized version of `_.reduceRight` for arrays without support for
  568. * iteratee shorthands.
  569. *
  570. * @private
  571. * @param {Array} array The array to iterate over.
  572. * @param {Function} iteratee The function invoked per iteration.
  573. * @param {*} [accumulator] The initial value.
  574. * @param {boolean} [initAccum] Specify using the last element of `array` as the initial value.
  575. * @returns {*} Returns the accumulated value.
  576. */
  577. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  578. var length = array.length;
  579. if (initAccum && length) {
  580. accumulator = array[--length];
  581. }
  582. while (length--) {
  583. accumulator = iteratee(accumulator, array[length], length, array);
  584. }
  585. return accumulator;
  586. }
  587. /**
  588. * A specialized version of `_.some` for arrays without support for iteratee
  589. * shorthands.
  590. *
  591. * @private
  592. * @param {Array} array The array to iterate over.
  593. * @param {Function} predicate The function invoked per iteration.
  594. * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
  595. */
  596. function arraySome(array, predicate) {
  597. var index = -1,
  598. length = array.length;
  599. while (++index < length) {
  600. if (predicate(array[index], index, array)) {
  601. return true;
  602. }
  603. }
  604. return false;
  605. }
  606. /**
  607. * The base implementation of methods like `_.max` and `_.min` which accepts a
  608. * `comparator` to determine the extremum value.
  609. *
  610. * @private
  611. * @param {Array} array The array to iterate over.
  612. * @param {Function} iteratee The iteratee invoked per iteration.
  613. * @param {Function} comparator The comparator used to compare values.
  614. * @returns {*} Returns the extremum value.
  615. */
  616. function baseExtremum(array, iteratee, comparator) {
  617. var index = -1,
  618. length = array.length;
  619. while (++index < length) {
  620. var value = array[index],
  621. current = iteratee(value);
  622. if (current != null && (computed === undefined
  623. ? current === current
  624. : comparator(current, computed)
  625. )) {
  626. var computed = current,
  627. result = value;
  628. }
  629. }
  630. return result;
  631. }
  632. /**
  633. * The base implementation of methods like `_.find` and `_.findKey`, without
  634. * support for iteratee shorthands, which iterates over `collection` using
  635. * `eachFunc`.
  636. *
  637. * @private
  638. * @param {Array|Object} collection The collection to search.
  639. * @param {Function} predicate The function invoked per iteration.
  640. * @param {Function} eachFunc The function to iterate over `collection`.
  641. * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
  642. * @returns {*} Returns the found element or its key, else `undefined`.
  643. */
  644. function baseFind(collection, predicate, eachFunc, retKey) {
  645. var result;
  646. eachFunc(collection, function(value, key, collection) {
  647. if (predicate(value, key, collection)) {
  648. result = retKey ? key : value;
  649. return false;
  650. }
  651. });
  652. return result;
  653. }
  654. /**
  655. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  656. * support for iteratee shorthands.
  657. *
  658. * @private
  659. * @param {Array} array The array to search.
  660. * @param {Function} predicate The function invoked per iteration.
  661. * @param {boolean} [fromRight] Specify iterating from right to left.
  662. * @returns {number} Returns the index of the matched value, else `-1`.
  663. */
  664. function baseFindIndex(array, predicate, fromRight) {
  665. var length = array.length,
  666. index = fromRight ? length : -1;
  667. while ((fromRight ? index-- : ++index < length)) {
  668. if (predicate(array[index], index, array)) {
  669. return index;
  670. }
  671. }
  672. return -1;
  673. }
  674. /**
  675. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  676. *
  677. * @private
  678. * @param {Array} array The array to search.
  679. * @param {*} value The value to search for.
  680. * @param {number} fromIndex The index to search from.
  681. * @returns {number} Returns the index of the matched value, else `-1`.
  682. */
  683. function baseIndexOf(array, value, fromIndex) {
  684. if (value !== value) {
  685. return indexOfNaN(array, fromIndex);
  686. }
  687. var index = fromIndex - 1,
  688. length = array.length;
  689. while (++index < length) {
  690. if (array[index] === value) {
  691. return index;
  692. }
  693. }
  694. return -1;
  695. }
  696. /**
  697. * This function is like `baseIndexOf` except that it accepts a comparator.
  698. *
  699. * @private
  700. * @param {Array} array The array to search.
  701. * @param {*} value The value to search for.
  702. * @param {number} fromIndex The index to search from.
  703. * @param {Function} comparator The comparator invoked per element.
  704. * @returns {number} Returns the index of the matched value, else `-1`.
  705. */
  706. function baseIndexOfWith(array, value, fromIndex, comparator) {
  707. var index = fromIndex - 1,
  708. length = array.length;
  709. while (++index < length) {
  710. if (comparator(array[index], value)) {
  711. return index;
  712. }
  713. }
  714. return -1;
  715. }
  716. /**
  717. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  718. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  719. *
  720. * @private
  721. * @param {Array|Object} collection The collection to iterate over.
  722. * @param {Function} iteratee The function invoked per iteration.
  723. * @param {*} accumulator The initial value.
  724. * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value.
  725. * @param {Function} eachFunc The function to iterate over `collection`.
  726. * @returns {*} Returns the accumulated value.
  727. */
  728. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  729. eachFunc(collection, function(value, index, collection) {
  730. accumulator = initAccum
  731. ? (initAccum = false, value)
  732. : iteratee(accumulator, value, index, collection);
  733. });
  734. return accumulator;
  735. }
  736. /**
  737. * The base implementation of `_.sortBy` which uses `comparer` to define the
  738. * sort order of `array` and replaces criteria objects with their corresponding
  739. * values.
  740. *
  741. * @private
  742. * @param {Array} array The array to sort.
  743. * @param {Function} comparer The function to define sort order.
  744. * @returns {Array} Returns `array`.
  745. */
  746. function baseSortBy(array, comparer) {
  747. var length = array.length;
  748. array.sort(comparer);
  749. while (length--) {
  750. array[length] = array[length].value;
  751. }
  752. return array;
  753. }
  754. /**
  755. * The base implementation of `_.sum` without support for iteratee shorthands.
  756. *
  757. * @private
  758. * @param {Array} array The array to iterate over.
  759. * @param {Function} iteratee The function invoked per iteration.
  760. * @returns {number} Returns the sum.
  761. */
  762. function baseSum(array, iteratee) {
  763. var result,
  764. index = -1,
  765. length = array.length;
  766. while (++index < length) {
  767. var current = iteratee(array[index]);
  768. if (current !== undefined) {
  769. result = result === undefined ? current : (result + current);
  770. }
  771. }
  772. return result;
  773. }
  774. /**
  775. * The base implementation of `_.times` without support for iteratee shorthands
  776. * or max array length checks.
  777. *
  778. * @private
  779. * @param {number} n The number of times to invoke `iteratee`.
  780. * @param {Function} iteratee The function invoked per iteration.
  781. * @returns {Array} Returns the array of results.
  782. */
  783. function baseTimes(n, iteratee) {
  784. var index = -1,
  785. result = Array(n);
  786. while (++index < n) {
  787. result[index] = iteratee(index);
  788. }
  789. return result;
  790. }
  791. /**
  792. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  793. * of key-value pairs for `object` corresponding to the property names of `props`.
  794. *
  795. * @private
  796. * @param {Object} object The object to query.
  797. * @param {Array} props The property names to get values for.
  798. * @returns {Object} Returns the new array of key-value pairs.
  799. */
  800. function baseToPairs(object, props) {
  801. return arrayMap(props, function(key) {
  802. return [key, object[key]];
  803. });
  804. }
  805. /**
  806. * The base implementation of `_.unary` without support for storing wrapper metadata.
  807. *
  808. * @private
  809. * @param {Function} func The function to cap arguments for.
  810. * @returns {Function} Returns the new function.
  811. */
  812. function baseUnary(func) {
  813. return function(value) {
  814. return func(value);
  815. };
  816. }
  817. /**
  818. * The base implementation of `_.values` and `_.valuesIn` which creates an
  819. * array of `object` property values corresponding to the property names
  820. * of `props`.
  821. *
  822. * @private
  823. * @param {Object} object The object to query.
  824. * @param {Array} props The property names to get values for.
  825. * @returns {Object} Returns the array of property values.
  826. */
  827. function baseValues(object, props) {
  828. return arrayMap(props, function(key) {
  829. return object[key];
  830. });
  831. }
  832. /**
  833. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  834. * that is not found in the character symbols.
  835. *
  836. * @private
  837. * @param {Array} strSymbols The string symbols to inspect.
  838. * @param {Array} chrSymbols The character symbols to find.
  839. * @returns {number} Returns the index of the first unmatched string symbol.
  840. */
  841. function charsStartIndex(strSymbols, chrSymbols) {
  842. var index = -1,
  843. length = strSymbols.length;
  844. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  845. return index;
  846. }
  847. /**
  848. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  849. * that is not found in the character symbols.
  850. *
  851. * @private
  852. * @param {Array} strSymbols The string symbols to inspect.
  853. * @param {Array} chrSymbols The character symbols to find.
  854. * @returns {number} Returns the index of the last unmatched string symbol.
  855. */
  856. function charsEndIndex(strSymbols, chrSymbols) {
  857. var index = strSymbols.length;
  858. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  859. return index;
  860. }
  861. /**
  862. * Checks if `value` is a global object.
  863. *
  864. * @private
  865. * @param {*} value The value to check.
  866. * @returns {null|Object} Returns `value` if it's a global object, else `null`.
  867. */
  868. function checkGlobal(value) {
  869. return (value && value.Object === Object) ? value : null;
  870. }
  871. /**
  872. * Compares values to sort them in ascending order.
  873. *
  874. * @private
  875. * @param {*} value The value to compare.
  876. * @param {*} other The other value to compare.
  877. * @returns {number} Returns the sort order indicator for `value`.
  878. */
  879. function compareAscending(value, other) {
  880. if (value !== other) {
  881. var valIsNull = value === null,
  882. valIsUndef = value === undefined,
  883. valIsReflexive = value === value;
  884. var othIsNull = other === null,
  885. othIsUndef = other === undefined,
  886. othIsReflexive = other === other;
  887. if ((value > other && !othIsNull) || !valIsReflexive ||
  888. (valIsNull && !othIsUndef && othIsReflexive) ||
  889. (valIsUndef && othIsReflexive)) {
  890. return 1;
  891. }
  892. if ((value < other && !valIsNull) || !othIsReflexive ||
  893. (othIsNull && !valIsUndef && valIsReflexive) ||
  894. (othIsUndef && valIsReflexive)) {
  895. return -1;
  896. }
  897. }
  898. return 0;
  899. }
  900. /**
  901. * Used by `_.orderBy` to compare multiple properties of a value to another
  902. * and stable sort them.
  903. *
  904. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  905. * specify an order of "desc" for descending or "asc" for ascending sort order
  906. * of corresponding values.
  907. *
  908. * @private
  909. * @param {Object} object The object to compare.
  910. * @param {Object} other The other object to compare.
  911. * @param {boolean[]|string[]} orders The order to sort by for each property.
  912. * @returns {number} Returns the sort order indicator for `object`.
  913. */
  914. function compareMultiple(object, other, orders) {
  915. var index = -1,
  916. objCriteria = object.criteria,
  917. othCriteria = other.criteria,
  918. length = objCriteria.length,
  919. ordersLength = orders.length;
  920. while (++index < length) {
  921. var result = compareAscending(objCriteria[index], othCriteria[index]);
  922. if (result) {
  923. if (index >= ordersLength) {
  924. return result;
  925. }
  926. var order = orders[index];
  927. return result * (order == 'desc' ? -1 : 1);
  928. }
  929. }
  930. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  931. // that causes it, under certain circumstances, to provide the same value for
  932. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  933. // for more details.
  934. //
  935. // This also ensures a stable sort in V8 and other engines.
  936. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  937. return object.index - other.index;
  938. }
  939. /**
  940. * Gets the number of `placeholder` occurrences in `array`.
  941. *
  942. * @private
  943. * @param {Array} array The array to inspect.
  944. * @param {*} placeholder The placeholder to search for.
  945. * @returns {number} Returns the placeholder count.
  946. */
  947. function countHolders(array, placeholder) {
  948. var length = array.length,
  949. result = 0;
  950. while (length--) {
  951. if (array[length] === placeholder) {
  952. result++;
  953. }
  954. }
  955. return result;
  956. }
  957. /**
  958. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  959. *
  960. * @private
  961. * @param {string} letter The matched letter to deburr.
  962. * @returns {string} Returns the deburred letter.
  963. */
  964. function deburrLetter(letter) {
  965. return deburredLetters[letter];
  966. }
  967. /**
  968. * Used by `_.escape` to convert characters to HTML entities.
  969. *
  970. * @private
  971. * @param {string} chr The matched character to escape.
  972. * @returns {string} Returns the escaped character.
  973. */
  974. function escapeHtmlChar(chr) {
  975. return htmlEscapes[chr];
  976. }
  977. /**
  978. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  979. *
  980. * @private
  981. * @param {string} chr The matched character to escape.
  982. * @returns {string} Returns the escaped character.
  983. */
  984. function escapeStringChar(chr) {
  985. return '\\' + stringEscapes[chr];
  986. }
  987. /**
  988. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  989. *
  990. * @private
  991. * @param {Array} array The array to search.
  992. * @param {number} fromIndex The index to search from.
  993. * @param {boolean} [fromRight] Specify iterating from right to left.
  994. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  995. */
  996. function indexOfNaN(array, fromIndex, fromRight) {
  997. var length = array.length,
  998. index = fromIndex + (fromRight ? 0 : -1);
  999. while ((fromRight ? index-- : ++index < length)) {
  1000. var other = array[index];
  1001. if (other !== other) {
  1002. return index;
  1003. }
  1004. }
  1005. return -1;
  1006. }
  1007. /**
  1008. * Checks if `value` is a host object in IE < 9.
  1009. *
  1010. * @private
  1011. * @param {*} value The value to check.
  1012. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  1013. */
  1014. function isHostObject(value) {
  1015. // Many host objects are `Object` objects that can coerce to strings
  1016. // despite having improperly defined `toString` methods.
  1017. var result = false;
  1018. if (value != null && typeof value.toString != 'function') {
  1019. try {
  1020. result = !!(value + '');
  1021. } catch (e) {}
  1022. }
  1023. return result;
  1024. }
  1025. /**
  1026. * Checks if `value` is a valid array-like index.
  1027. *
  1028. * @private
  1029. * @param {*} value The value to check.
  1030. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  1031. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  1032. */
  1033. function isIndex(value, length) {
  1034. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  1035. length = length == null ? MAX_SAFE_INTEGER : length;
  1036. return value > -1 && value % 1 == 0 && value < length;
  1037. }
  1038. /**
  1039. * Converts `iterator` to an array.
  1040. *
  1041. * @private
  1042. * @param {Object} iterator The iterator to convert.
  1043. * @returns {Array} Returns the converted array.
  1044. */
  1045. function iteratorToArray(iterator) {
  1046. var data,
  1047. result = [];
  1048. while (!(data = iterator.next()).done) {
  1049. result.push(data.value);
  1050. }
  1051. return result;
  1052. }
  1053. /**
  1054. * Converts `map` to an array.
  1055. *
  1056. * @private
  1057. * @param {Object} map The map to convert.
  1058. * @returns {Array} Returns the converted array.
  1059. */
  1060. function mapToArray(map) {
  1061. var index = -1,
  1062. result = Array(map.size);
  1063. map.forEach(function(value, key) {
  1064. result[++index] = [key, value];
  1065. });
  1066. return result;
  1067. }
  1068. /**
  1069. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1070. * and returns an array of their indexes.
  1071. *
  1072. * @private
  1073. * @param {Array} array The array to modify.
  1074. * @param {*} placeholder The placeholder to replace.
  1075. * @returns {Array} Returns the new array of placeholder indexes.
  1076. */
  1077. function replaceHolders(array, placeholder) {
  1078. var index = -1,
  1079. length = array.length,
  1080. resIndex = 0,
  1081. result = [];
  1082. while (++index < length) {
  1083. var value = array[index];
  1084. if (value === placeholder || value === PLACEHOLDER) {
  1085. array[index] = PLACEHOLDER;
  1086. result[resIndex++] = index;
  1087. }
  1088. }
  1089. return result;
  1090. }
  1091. /**
  1092. * Converts `set` to an array.
  1093. *
  1094. * @private
  1095. * @param {Object} set The set to convert.
  1096. * @returns {Array} Returns the converted array.
  1097. */
  1098. function setToArray(set) {
  1099. var index = -1,
  1100. result = Array(set.size);
  1101. set.forEach(function(value) {
  1102. result[++index] = value;
  1103. });
  1104. return result;
  1105. }
  1106. /**
  1107. * Gets the number of symbols in `string`.
  1108. *
  1109. * @private
  1110. * @param {string} string The string to inspect.
  1111. * @returns {number} Returns the string size.
  1112. */
  1113. function stringSize(string) {
  1114. if (!(string && reHasComplexSymbol.test(string))) {
  1115. return string.length;
  1116. }
  1117. var result = reComplexSymbol.lastIndex = 0;
  1118. while (reComplexSymbol.test(string)) {
  1119. result++;
  1120. }
  1121. return result;
  1122. }
  1123. /**
  1124. * Converts `string` to an array.
  1125. *
  1126. * @private
  1127. * @param {string} string The string to convert.
  1128. * @returns {Array} Returns the converted array.
  1129. */
  1130. function stringToArray(string) {
  1131. return string.match(reComplexSymbol);
  1132. }
  1133. /**
  1134. * Used by `_.unescape` to convert HTML entities to characters.
  1135. *
  1136. * @private
  1137. * @param {string} chr The matched character to unescape.
  1138. * @returns {string} Returns the unescaped character.
  1139. */
  1140. function unescapeHtmlChar(chr) {
  1141. return htmlUnescapes[chr];
  1142. }
  1143. /*--------------------------------------------------------------------------*/
  1144. /**
  1145. * Create a new pristine `lodash` function using the `context` object.
  1146. *
  1147. * @static
  1148. * @memberOf _
  1149. * @category Util
  1150. * @param {Object} [context=root] The context object.
  1151. * @returns {Function} Returns a new `lodash` function.
  1152. * @example
  1153. *
  1154. * _.mixin({ 'foo': _.constant('foo') });
  1155. *
  1156. * var lodash = _.runInContext();
  1157. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1158. *
  1159. * _.isFunction(_.foo);
  1160. * // => true
  1161. * _.isFunction(_.bar);
  1162. * // => false
  1163. *
  1164. * lodash.isFunction(lodash.foo);
  1165. * // => false
  1166. * lodash.isFunction(lodash.bar);
  1167. * // => true
  1168. *
  1169. * // Use `context` to mock `Date#getTime` use in `_.now`.
  1170. * var mock = _.runInContext({
  1171. * 'Date': function() {
  1172. * return { 'getTime': getTimeMock };
  1173. * }
  1174. * });
  1175. *
  1176. * // Create a suped-up `defer` in Node.js.
  1177. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1178. */
  1179. function runInContext(context) {
  1180. context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
  1181. /** Built-in constructor references. */
  1182. var Date = context.Date,
  1183. Error = context.Error,
  1184. Math = context.Math,
  1185. RegExp = context.RegExp,
  1186. TypeError = context.TypeError;
  1187. /** Used for built-in method references. */
  1188. var arrayProto = context.Array.prototype,
  1189. objectProto = context.Object.prototype;
  1190. /** Used to resolve the decompiled source of functions. */
  1191. var funcToString = context.Function.prototype.toString;
  1192. /** Used to check objects for own properties. */
  1193. var hasOwnProperty = objectProto.hasOwnProperty;
  1194. /** Used to generate unique IDs. */
  1195. var idCounter = 0;
  1196. /** Used to infer the `Object` constructor. */
  1197. var objectCtorString = funcToString.call(Object);
  1198. /**
  1199. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  1200. * of values.
  1201. */
  1202. var objectToString = objectProto.toString;
  1203. /** Used to restore the original `_` reference in `_.noConflict`. */
  1204. var oldDash = root._;
  1205. /** Used to detect if a method is native. */
  1206. var reIsNative = RegExp('^' +
  1207. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1208. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1209. );
  1210. /** Built-in value references. */
  1211. var Buffer = moduleExports ? context.Buffer : undefined,
  1212. Reflect = context.Reflect,
  1213. Symbol = context.Symbol,
  1214. Uint8Array = context.Uint8Array,
  1215. clearTimeout = context.clearTimeout,
  1216. enumerate = Reflect ? Reflect.enumerate : undefined,
  1217. getPrototypeOf = Object.getPrototypeOf,
  1218. getOwnPropertySymbols = Object.getOwnPropertySymbols,
  1219. iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
  1220. objectCreate = Object.create,
  1221. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1222. setTimeout = context.setTimeout,
  1223. splice = arrayProto.splice;
  1224. /* Built-in method references for those with the same name as other `lodash` methods. */
  1225. var nativeCeil = Math.ceil,
  1226. nativeFloor = Math.floor,
  1227. nativeIsFinite = context.isFinite,
  1228. nativeJoin = arrayProto.join,
  1229. nativeKeys = Object.keys,
  1230. nativeMax = Math.max,
  1231. nativeMin = Math.min,
  1232. nativeParseInt = context.parseInt,
  1233. nativeRandom = Math.random,
  1234. nativeReverse = arrayProto.reverse;
  1235. /* Built-in method references that are verified to be native. */
  1236. var Map = getNative(context, 'Map'),
  1237. Set = getNative(context, 'Set'),
  1238. WeakMap = getNative(context, 'WeakMap'),
  1239. nativeCreate = getNative(Object, 'create');
  1240. /** Used to store function metadata. */
  1241. var metaMap = WeakMap && new WeakMap;
  1242. /** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */
  1243. var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
  1244. /** Used to lookup unminified function names. */
  1245. var realNames = {};
  1246. /** Used to detect maps, sets, and weakmaps. */
  1247. var mapCtorString = Map ? funcToString.call(Map) : '',
  1248. setCtorString = Set ? funcToString.call(Set) : '',
  1249. weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : '';
  1250. /** Used to convert symbols to primitives and strings. */
  1251. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1252. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1253. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1254. /*------------------------------------------------------------------------*/
  1255. /**
  1256. * Creates a `lodash` object which wraps `value` to enable implicit method
  1257. * chaining. Methods that operate on and return arrays, collections, and
  1258. * functions can be chained together. Methods that retrieve a single value or
  1259. * may return a primitive value will automatically end the chain sequence and
  1260. * return the unwrapped value. Otherwise, the value must be unwrapped with
  1261. * `_#value`.
  1262. *
  1263. * Explicit chaining, which must be unwrapped with `_#value` in all cases,
  1264. * may be enabled using `_.chain`.
  1265. *
  1266. * The execution of chained methods is lazy, that is, it's deferred until
  1267. * `_#value` is implicitly or explicitly called.
  1268. *
  1269. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  1270. * fusion is an optimization to merge iteratee calls; this avoids the creation
  1271. * of intermediate arrays and can greatly reduce the number of iteratee executions.
  1272. * Sections of a chain sequence qualify for shortcut fusion if the section is
  1273. * applied to an array of at least two hundred elements and any iteratees
  1274. * accept only one argument. The heuristic for whether a section qualifies
  1275. * for shortcut fusion is subject to change.
  1276. *
  1277. * Chaining is supported in custom builds as long as the `_#value` method is
  1278. * directly or indirectly included in the build.
  1279. *
  1280. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1281. *
  1282. * The wrapper `Array` methods are:
  1283. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1284. *
  1285. * The wrapper `String` methods are:
  1286. * `replace` and `split`
  1287. *
  1288. * The wrapper methods that support shortcut fusion are:
  1289. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1290. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1291. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1292. *
  1293. * The chainable wrapper methods are:
  1294. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1295. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1296. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1297. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1298. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1299. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1300. * `flatten`, `flattenDeep`, `flattenDepth`, `flip`, `flow`, `flowRight`,
  1301. * `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`, `intersection`,
  1302. * `intersectionBy`, `intersectionWith`, `invert`, `invertBy`, `invokeMap`,
  1303. * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
  1304. * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
  1305. * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`,
  1306. * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
  1307. * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
  1308. * `pullAll`, `pullAllBy`, `pullAllWith`, `pullAt`, `push`, `range`,
  1309. * `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, `sampleSize`,
  1310. * `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`,
  1311. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
  1312. * `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`,
  1313. * `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`,
  1314. * `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `update`, `values`,
  1315. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`,
  1316. * `zipObjectDeep`, and `zipWith`
  1317. *
  1318. * The wrapper methods that are **not** chainable by default are:
  1319. * `add`,