PageRenderTime 42ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/node_modules/sass-graph/node_modules/lodash/lodash.js

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