You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17112 lines
528 KiB

4 years ago
  1. /**
  2. * @license
  3. * Lodash <https://lodash.com/>
  4. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  5. * Released under MIT license <https://lodash.com/license>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. */
  9. ;(function() {
  10. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  11. var undefined;
  12. /** Used as the semantic version number. */
  13. var VERSION = '4.17.15';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Error message constants. */
  17. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  18. 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 maximum memoize cache size. */
  22. var MAX_MEMOIZE_SIZE = 500;
  23. /** Used as the internal argument placeholder. */
  24. var PLACEHOLDER = '__lodash_placeholder__';
  25. /** Used to compose bitmasks for cloning. */
  26. var CLONE_DEEP_FLAG = 1,
  27. CLONE_FLAT_FLAG = 2,
  28. CLONE_SYMBOLS_FLAG = 4;
  29. /** Used to compose bitmasks for value comparisons. */
  30. var COMPARE_PARTIAL_FLAG = 1,
  31. COMPARE_UNORDERED_FLAG = 2;
  32. /** Used to compose bitmasks for function metadata. */
  33. var WRAP_BIND_FLAG = 1,
  34. WRAP_BIND_KEY_FLAG = 2,
  35. WRAP_CURRY_BOUND_FLAG = 4,
  36. WRAP_CURRY_FLAG = 8,
  37. WRAP_CURRY_RIGHT_FLAG = 16,
  38. WRAP_PARTIAL_FLAG = 32,
  39. WRAP_PARTIAL_RIGHT_FLAG = 64,
  40. WRAP_ARY_FLAG = 128,
  41. WRAP_REARG_FLAG = 256,
  42. WRAP_FLIP_FLAG = 512;
  43. /** Used as default options for `_.truncate`. */
  44. var DEFAULT_TRUNC_LENGTH = 30,
  45. DEFAULT_TRUNC_OMISSION = '...';
  46. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  47. var HOT_COUNT = 800,
  48. HOT_SPAN = 16;
  49. /** Used to indicate the type of lazy iteratees. */
  50. var LAZY_FILTER_FLAG = 1,
  51. LAZY_MAP_FLAG = 2,
  52. LAZY_WHILE_FLAG = 3;
  53. /** Used as references for various `Number` constants. */
  54. var INFINITY = 1 / 0,
  55. MAX_SAFE_INTEGER = 9007199254740991,
  56. MAX_INTEGER = 1.7976931348623157e+308,
  57. NAN = 0 / 0;
  58. /** Used as references for the maximum length and index of an array. */
  59. var MAX_ARRAY_LENGTH = 4294967295,
  60. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  61. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  62. /** Used to associate wrap methods with their bit flags. */
  63. var wrapFlags = [
  64. ['ary', WRAP_ARY_FLAG],
  65. ['bind', WRAP_BIND_FLAG],
  66. ['bindKey', WRAP_BIND_KEY_FLAG],
  67. ['curry', WRAP_CURRY_FLAG],
  68. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  69. ['flip', WRAP_FLIP_FLAG],
  70. ['partial', WRAP_PARTIAL_FLAG],
  71. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  72. ['rearg', WRAP_REARG_FLAG]
  73. ];
  74. /** `Object#toString` result references. */
  75. var argsTag = '[object Arguments]',
  76. arrayTag = '[object Array]',
  77. asyncTag = '[object AsyncFunction]',
  78. boolTag = '[object Boolean]',
  79. dateTag = '[object Date]',
  80. domExcTag = '[object DOMException]',
  81. errorTag = '[object Error]',
  82. funcTag = '[object Function]',
  83. genTag = '[object GeneratorFunction]',
  84. mapTag = '[object Map]',
  85. numberTag = '[object Number]',
  86. nullTag = '[object Null]',
  87. objectTag = '[object Object]',
  88. promiseTag = '[object Promise]',
  89. proxyTag = '[object Proxy]',
  90. regexpTag = '[object RegExp]',
  91. setTag = '[object Set]',
  92. stringTag = '[object String]',
  93. symbolTag = '[object Symbol]',
  94. undefinedTag = '[object Undefined]',
  95. weakMapTag = '[object WeakMap]',
  96. weakSetTag = '[object WeakSet]';
  97. var arrayBufferTag = '[object ArrayBuffer]',
  98. dataViewTag = '[object DataView]',
  99. float32Tag = '[object Float32Array]',
  100. float64Tag = '[object Float64Array]',
  101. int8Tag = '[object Int8Array]',
  102. int16Tag = '[object Int16Array]',
  103. int32Tag = '[object Int32Array]',
  104. uint8Tag = '[object Uint8Array]',
  105. uint8ClampedTag = '[object Uint8ClampedArray]',
  106. uint16Tag = '[object Uint16Array]',
  107. uint32Tag = '[object Uint32Array]';
  108. /** Used to match empty string literals in compiled template source. */
  109. var reEmptyStringLeading = /\b__p \+= '';/g,
  110. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  111. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  112. /** Used to match HTML entities and HTML characters. */
  113. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  114. reUnescapedHtml = /[&<>"']/g,
  115. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  116. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  117. /** Used to match template delimiters. */
  118. var reEscape = /<%-([\s\S]+?)%>/g,
  119. reEvaluate = /<%([\s\S]+?)%>/g,
  120. reInterpolate = /<%=([\s\S]+?)%>/g;
  121. /** Used to match property names within property paths. */
  122. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  123. reIsPlainProp = /^\w*$/,
  124. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  125. /**
  126. * Used to match `RegExp`
  127. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  128. */
  129. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  130. reHasRegExpChar = RegExp(reRegExpChar.source);
  131. /** Used to match leading and trailing whitespace. */
  132. var reTrim = /^\s+|\s+$/g,
  133. reTrimStart = /^\s+/,
  134. reTrimEnd = /\s+$/;
  135. /** Used to match wrap detail comments. */
  136. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  137. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  138. reSplitDetails = /,? & /;
  139. /** Used to match words composed of alphanumeric characters. */
  140. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  141. /** Used to match backslashes in property paths. */
  142. var reEscapeChar = /\\(\\)?/g;
  143. /**
  144. * Used to match
  145. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  146. */
  147. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  148. /** Used to match `RegExp` flags from their coerced string values. */
  149. var reFlags = /\w*$/;
  150. /** Used to detect bad signed hexadecimal string values. */
  151. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  152. /** Used to detect binary string values. */
  153. var reIsBinary = /^0b[01]+$/i;
  154. /** Used to detect host constructors (Safari). */
  155. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  156. /** Used to detect octal string values. */
  157. var reIsOctal = /^0o[0-7]+$/i;
  158. /** Used to detect unsigned integer values. */
  159. var reIsUint = /^(?:0|[1-9]\d*)$/;
  160. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  161. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  162. /** Used to ensure capturing order of template delimiters. */
  163. var reNoMatch = /($^)/;
  164. /** Used to match unescaped characters in compiled string literals. */
  165. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  166. /** Used to compose unicode character classes. */
  167. var rsAstralRange = '\\ud800-\\udfff',
  168. rsComboMarksRange = '\\u0300-\\u036f',
  169. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  170. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  171. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  172. rsDingbatRange = '\\u2700-\\u27bf',
  173. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  174. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  175. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  176. rsPunctuationRange = '\\u2000-\\u206f',
  177. 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',
  178. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  179. rsVarRange = '\\ufe0e\\ufe0f',
  180. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  181. /** Used to compose unicode capture groups. */
  182. var rsApos = "['\u2019]",
  183. rsAstral = '[' + rsAstralRange + ']',
  184. rsBreak = '[' + rsBreakRange + ']',
  185. rsCombo = '[' + rsComboRange + ']',
  186. rsDigits = '\\d+',
  187. rsDingbat = '[' + rsDingbatRange + ']',
  188. rsLower = '[' + rsLowerRange + ']',
  189. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  190. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  191. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  192. rsNonAstral = '[^' + rsAstralRange + ']',
  193. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  194. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  195. rsUpper = '[' + rsUpperRange + ']',
  196. rsZWJ = '\\u200d';
  197. /** Used to compose unicode regexes. */
  198. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  199. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  200. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  201. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  202. reOptMod = rsModifier + '?',
  203. rsOptVar = '[' + rsVarRange + ']?',
  204. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  205. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  206. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  207. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  208. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  209. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  210. /** Used to match apostrophes. */
  211. var reApos = RegExp(rsApos, 'g');
  212. /**
  213. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  214. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  215. */
  216. var reComboMark = RegExp(rsCombo, 'g');
  217. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  218. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  219. /** Used to match complex or compound words. */
  220. var reUnicodeWord = RegExp([
  221. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  222. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  223. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  224. rsUpper + '+' + rsOptContrUpper,
  225. rsOrdUpper,
  226. rsOrdLower,
  227. rsDigits,
  228. rsEmoji
  229. ].join('|'), 'g');
  230. /** 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/). */
  231. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  232. /** Used to detect strings that need a more robust regexp to match words. */
  233. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  234. /** Used to assign default `context` object properties. */
  235. var contextProps = [
  236. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  237. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  238. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  239. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  240. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  241. ];
  242. /** Used to make template sourceURLs easier to identify. */
  243. var templateCounter = -1;
  244. /** Used to identify `toStringTag` values of typed arrays. */
  245. var typedArrayTags = {};
  246. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  247. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  248. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  249. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  250. typedArrayTags[uint32Tag] = true;
  251. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  252. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  253. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  254. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  255. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  256. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  257. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  258. typedArrayTags[weakMapTag] = false;
  259. /** Used to identify `toStringTag` values supported by `_.clone`. */
  260. var cloneableTags = {};
  261. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  262. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  263. cloneableTags[boolTag] = cloneableTags[dateTag] =
  264. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  265. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  266. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  267. cloneableTags[numberTag] = cloneableTags[objectTag] =
  268. cloneableTags[regexpTag] = cloneableTags[setTag] =
  269. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  270. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  271. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  272. cloneableTags[errorTag] = cloneableTags[funcTag] =
  273. cloneableTags[weakMapTag] = false;
  274. /** Used to map Latin Unicode letters to basic Latin letters. */
  275. var deburredLetters = {
  276. // Latin-1 Supplement block.
  277. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  278. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  279. '\xc7': 'C', '\xe7': 'c',
  280. '\xd0': 'D', '\xf0': 'd',
  281. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  282. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  283. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  284. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  285. '\xd1': 'N', '\xf1': 'n',
  286. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  287. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  288. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  289. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  290. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  291. '\xc6': 'Ae', '\xe6': 'ae',
  292. '\xde': 'Th', '\xfe': 'th',
  293. '\xdf': 'ss',
  294. // Latin Extended-A block.
  295. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  296. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  297. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  298. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  299. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  300. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  301. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  302. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  303. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  304. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  305. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  306. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  307. '\u0134': 'J', '\u0135': 'j',
  308. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  309. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  310. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  311. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  312. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  313. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  314. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  315. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  316. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  317. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  318. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  319. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  320. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  321. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  322. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  323. '\u0174': 'W', '\u0175': 'w',
  324. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  325. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  326. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  327. '\u0132': 'IJ', '\u0133': 'ij',
  328. '\u0152': 'Oe', '\u0153': 'oe',
  329. '\u0149': "'n", '\u017f': 's'
  330. };
  331. /** Used to map characters to HTML entities. */
  332. var htmlEscapes = {
  333. '&': '&amp;',
  334. '<': '&lt;',
  335. '>': '&gt;',
  336. '"': '&quot;',
  337. "'": '&#39;'
  338. };
  339. /** Used to map HTML entities to characters. */
  340. var htmlUnescapes = {
  341. '&amp;': '&',
  342. '&lt;': '<',
  343. '&gt;': '>',
  344. '&quot;': '"',
  345. '&#39;': "'"
  346. };
  347. /** Used to escape characters for inclusion in compiled string literals. */
  348. var stringEscapes = {
  349. '\\': '\\',
  350. "'": "'",
  351. '\n': 'n',
  352. '\r': 'r',
  353. '\u2028': 'u2028',
  354. '\u2029': 'u2029'
  355. };
  356. /** Built-in method references without a dependency on `root`. */
  357. var freeParseFloat = parseFloat,
  358. freeParseInt = parseInt;
  359. /** Detect free variable `global` from Node.js. */
  360. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  361. /** Detect free variable `self`. */
  362. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  363. /** Used as a reference to the global object. */
  364. var root = freeGlobal || freeSelf || Function('return this')();
  365. /** Detect free variable `exports`. */
  366. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  367. /** Detect free variable `module`. */
  368. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  369. /** Detect the popular CommonJS extension `module.exports`. */
  370. var moduleExports = freeModule && freeModule.exports === freeExports;
  371. /** Detect free variable `process` from Node.js. */
  372. var freeProcess = moduleExports && freeGlobal.process;
  373. /** Used to access faster Node.js helpers. */
  374. var nodeUtil = (function() {
  375. try {
  376. // Use `util.types` for Node.js 10+.
  377. var types = freeModule && freeModule.require && freeModule.require('util').types;
  378. if (types) {
  379. return types;
  380. }
  381. // Legacy `process.binding('util')` for Node.js < 10.
  382. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  383. } catch (e) {}
  384. }());
  385. /* Node.js helper references. */
  386. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  387. nodeIsDate = nodeUtil && nodeUtil.isDate,
  388. nodeIsMap = nodeUtil && nodeUtil.isMap,
  389. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  390. nodeIsSet = nodeUtil && nodeUtil.isSet,
  391. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  392. /*--------------------------------------------------------------------------*/
  393. /**
  394. * A faster alternative to `Function#apply`, this function invokes `func`
  395. * with the `this` binding of `thisArg` and the arguments of `args`.
  396. *
  397. * @private
  398. * @param {Function} func The function to invoke.
  399. * @param {*} thisArg The `this` binding of `func`.
  400. * @param {Array} args The arguments to invoke `func` with.
  401. * @returns {*} Returns the result of `func`.
  402. */
  403. function apply(func, thisArg, args) {
  404. switch (args.length) {
  405. case 0: return func.call(thisArg);
  406. case 1: return func.call(thisArg, args[0]);
  407. case 2: return func.call(thisArg, args[0], args[1]);
  408. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  409. }
  410. return func.apply(thisArg, args);
  411. }
  412. /**
  413. * A specialized version of `baseAggregator` for arrays.
  414. *
  415. * @private
  416. * @param {Array} [array] The array to iterate over.
  417. * @param {Function} setter The function to set `accumulator` values.
  418. * @param {Function} iteratee The iteratee to transform keys.
  419. * @param {Object} accumulator The initial aggregated object.
  420. * @returns {Function} Returns `accumulator`.
  421. */
  422. function arrayAggregator(array, setter, iteratee, accumulator) {
  423. var index = -1,
  424. length = array == null ? 0 : array.length;
  425. while (++index < length) {
  426. var value = array[index];
  427. setter(accumulator, value, iteratee(value), array);
  428. }
  429. return accumulator;
  430. }
  431. /**
  432. * A specialized version of `_.forEach` for arrays without support for
  433. * iteratee shorthands.
  434. *
  435. * @private
  436. * @param {Array} [array] The array to iterate over.
  437. * @param {Function} iteratee The function invoked per iteration.
  438. * @returns {Array} Returns `array`.
  439. */
  440. function arrayEach(array, iteratee) {
  441. var index = -1,
  442. length = array == null ? 0 : array.length;
  443. while (++index < length) {
  444. if (iteratee(array[index], index, array) === false) {
  445. break;
  446. }
  447. }
  448. return array;
  449. }
  450. /**
  451. * A specialized version of `_.forEachRight` for arrays without support for
  452. * iteratee shorthands.
  453. *
  454. * @private
  455. * @param {Array} [array] The array to iterate over.
  456. * @param {Function} iteratee The function invoked per iteration.
  457. * @returns {Array} Returns `array`.
  458. */
  459. function arrayEachRight(array, iteratee) {
  460. var length = array == null ? 0 : array.length;
  461. while (length--) {
  462. if (iteratee(array[length], length, array) === false) {
  463. break;
  464. }
  465. }
  466. return array;
  467. }
  468. /**
  469. * A specialized version of `_.every` for arrays without support for
  470. * iteratee shorthands.
  471. *
  472. * @private
  473. * @param {Array} [array] The array to iterate over.
  474. * @param {Function} predicate The function invoked per iteration.
  475. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  476. * else `false`.
  477. */
  478. function arrayEvery(array, predicate) {
  479. var index = -1,
  480. length = array == null ? 0 : array.length;
  481. while (++index < length) {
  482. if (!predicate(array[index], index, array)) {
  483. return false;
  484. }
  485. }
  486. return true;
  487. }
  488. /**
  489. * A specialized version of `_.filter` for arrays without support for
  490. * iteratee shorthands.
  491. *
  492. * @private
  493. * @param {Array} [array] The array to iterate over.
  494. * @param {Function} predicate The function invoked per iteration.
  495. * @returns {Array} Returns the new filtered array.
  496. */
  497. function arrayFilter(array, predicate) {
  498. var index = -1,
  499. length = array == null ? 0 : array.length,
  500. resIndex = 0,
  501. result = [];
  502. while (++index < length) {
  503. var value = array[index];
  504. if (predicate(value, index, array)) {
  505. result[resIndex++] = value;
  506. }
  507. }
  508. return result;
  509. }
  510. /**
  511. * A specialized version of `_.includes` for arrays without support for
  512. * specifying an index to search from.
  513. *
  514. * @private
  515. * @param {Array} [array] The array to inspect.
  516. * @param {*} target The value to search for.
  517. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  518. */
  519. function arrayIncludes(array, value) {
  520. var length = array == null ? 0 : array.length;
  521. return !!length && baseIndexOf(array, value, 0) > -1;
  522. }
  523. /**
  524. * This function is like `arrayIncludes` except that it accepts a comparator.
  525. *
  526. * @private
  527. * @param {Array} [array] The array to inspect.
  528. * @param {*} target The value to search for.
  529. * @param {Function} comparator The comparator invoked per element.
  530. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  531. */
  532. function arrayIncludesWith(array, value, comparator) {
  533. var index = -1,
  534. length = array == null ? 0 : array.length;
  535. while (++index < length) {
  536. if (comparator(value, array[index])) {
  537. return true;
  538. }
  539. }
  540. return false;
  541. }
  542. /**
  543. * A specialized version of `_.map` for arrays without support for iteratee
  544. * shorthands.
  545. *
  546. * @private
  547. * @param {Array} [array] The array to iterate over.
  548. * @param {Function} iteratee The function invoked per iteration.
  549. * @returns {Array} Returns the new mapped array.
  550. */
  551. function arrayMap(array, iteratee) {
  552. var index = -1,
  553. length = array == null ? 0 : array.length,
  554. result = Array(length);
  555. while (++index < length) {
  556. result[index] = iteratee(array[index], index, array);
  557. }
  558. return result;
  559. }
  560. /**
  561. * Appends the elements of `values` to `array`.
  562. *
  563. * @private
  564. * @param {Array} array The array to modify.
  565. * @param {Array} values The values to append.
  566. * @returns {Array} Returns `array`.
  567. */
  568. function arrayPush(array, values) {
  569. var index = -1,
  570. length = values.length,
  571. offset = array.length;
  572. while (++index < length) {
  573. array[offset + index] = values[index];
  574. }
  575. return array;
  576. }
  577. /**
  578. * A specialized version of `_.reduce` for arrays without support for
  579. * iteratee shorthands.
  580. *
  581. * @private
  582. * @param {Array} [array] The array to iterate over.
  583. * @param {Function} iteratee The function invoked per iteration.
  584. * @param {*} [accumulator] The initial value.
  585. * @param {boolean} [initAccum] Specify using the first element of `array` as
  586. * the initial value.
  587. * @returns {*} Returns the accumulated value.
  588. */
  589. function arrayReduce(array, iteratee, accumulator, initAccum) {
  590. var index = -1,
  591. length = array == null ? 0 : array.length;
  592. if (initAccum && length) {
  593. accumulator = array[++index];
  594. }
  595. while (++index < length) {
  596. accumulator = iteratee(accumulator, array[index], index, array);
  597. }
  598. return accumulator;
  599. }
  600. /**
  601. * A specialized version of `_.reduceRight` for arrays without support for
  602. * iteratee shorthands.
  603. *
  604. * @private
  605. * @param {Array} [array] The array to iterate over.
  606. * @param {Function} iteratee The function invoked per iteration.
  607. * @param {*} [accumulator] The initial value.
  608. * @param {boolean} [initAccum] Specify using the last element of `array` as
  609. * the initial value.
  610. * @returns {*} Returns the accumulated value.
  611. */
  612. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  613. var length = array == null ? 0 : array.length;
  614. if (initAccum && length) {
  615. accumulator = array[--length];
  616. }
  617. while (length--) {
  618. accumulator = iteratee(accumulator, array[length], length, array);
  619. }
  620. return accumulator;
  621. }
  622. /**
  623. * A specialized version of `_.some` for arrays without support for iteratee
  624. * shorthands.
  625. *
  626. * @private
  627. * @param {Array} [array] The array to iterate over.
  628. * @param {Function} predicate The function invoked per iteration.
  629. * @returns {boolean} Returns `true` if any element passes the predicate check,
  630. * else `false`.
  631. */
  632. function arraySome(array, predicate) {
  633. var index = -1,
  634. length = array == null ? 0 : array.length;
  635. while (++index < length) {
  636. if (predicate(array[index], index, array)) {
  637. return true;
  638. }
  639. }
  640. return false;
  641. }
  642. /**
  643. * Gets the size of an ASCII `string`.
  644. *
  645. * @private
  646. * @param {string} string The string inspect.
  647. * @returns {number} Returns the string size.
  648. */
  649. var asciiSize = baseProperty('length');
  650. /**
  651. * Converts an ASCII `string` to an array.
  652. *
  653. * @private
  654. * @param {string} string The string to convert.
  655. * @returns {Array} Returns the converted array.
  656. */
  657. function asciiToArray(string) {
  658. return string.split('');
  659. }
  660. /**
  661. * Splits an ASCII `string` into an array of its words.
  662. *
  663. * @private
  664. * @param {string} The string to inspect.
  665. * @returns {Array} Returns the words of `string`.
  666. */
  667. function asciiWords(string) {
  668. return string.match(reAsciiWord) || [];
  669. }
  670. /**
  671. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  672. * without support for iteratee shorthands, which iterates over `collection`
  673. * using `eachFunc`.
  674. *
  675. * @private
  676. * @param {Array|Object} collection The collection to inspect.
  677. * @param {Function} predicate The function invoked per iteration.
  678. * @param {Function} eachFunc The function to iterate over `collection`.
  679. * @returns {*} Returns the found element or its key, else `undefined`.
  680. */
  681. function baseFindKey(collection, predicate, eachFunc) {
  682. var result;
  683. eachFunc(collection, function(value, key, collection) {
  684. if (predicate(value, key, collection)) {
  685. result = key;
  686. return false;
  687. }
  688. });
  689. return result;
  690. }
  691. /**
  692. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  693. * support for iteratee shorthands.
  694. *
  695. * @private
  696. * @param {Array} array The array to inspect.
  697. * @param {Function} predicate The function invoked per iteration.
  698. * @param {number} fromIndex The index to search from.
  699. * @param {boolean} [fromRight] Specify iterating from right to left.
  700. * @returns {number} Returns the index of the matched value, else `-1`.
  701. */
  702. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  703. var length = array.length,
  704. index = fromIndex + (fromRight ? 1 : -1);
  705. while ((fromRight ? index-- : ++index < length)) {
  706. if (predicate(array[index], index, array)) {
  707. return index;
  708. }
  709. }
  710. return -1;
  711. }
  712. /**
  713. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  714. *
  715. * @private
  716. * @param {Array} array The array to inspect.
  717. * @param {*} value The value to search for.
  718. * @param {number} fromIndex The index to search from.
  719. * @returns {number} Returns the index of the matched value, else `-1`.
  720. */
  721. function baseIndexOf(array, value, fromIndex) {
  722. return value === value
  723. ? strictIndexOf(array, value, fromIndex)
  724. : baseFindIndex(array, baseIsNaN, fromIndex);
  725. }
  726. /**
  727. * This function is like `baseIndexOf` except that it accepts a comparator.
  728. *
  729. * @private
  730. * @param {Array} array The array to inspect.
  731. * @param {*} value The value to search for.
  732. * @param {number} fromIndex The index to search from.
  733. * @param {Function} comparator The comparator invoked per element.
  734. * @returns {number} Returns the index of the matched value, else `-1`.
  735. */
  736. function baseIndexOfWith(array, value, fromIndex, comparator) {
  737. var index = fromIndex - 1,
  738. length = array.length;
  739. while (++index < length) {
  740. if (comparator(array[index], value)) {
  741. return index;
  742. }
  743. }
  744. return -1;
  745. }
  746. /**
  747. * The base implementation of `_.isNaN` without support for number objects.
  748. *
  749. * @private
  750. * @param {*} value The value to check.
  751. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  752. */
  753. function baseIsNaN(value) {
  754. return value !== value;
  755. }
  756. /**
  757. * The base implementation of `_.mean` and `_.meanBy` without support for
  758. * iteratee shorthands.
  759. *
  760. * @private
  761. * @param {Array} array The array to iterate over.
  762. * @param {Function} iteratee The function invoked per iteration.
  763. * @returns {number} Returns the mean.
  764. */
  765. function baseMean(array, iteratee) {
  766. var length = array == null ? 0 : array.length;
  767. return length ? (baseSum(array, iteratee) / length) : NAN;
  768. }
  769. /**
  770. * The base implementation of `_.property` without support for deep paths.
  771. *
  772. * @private
  773. * @param {string} key The key of the property to get.
  774. * @returns {Function} Returns the new accessor function.
  775. */
  776. function baseProperty(key) {
  777. return function(object) {
  778. return object == null ? undefined : object[key];
  779. };
  780. }
  781. /**
  782. * The base implementation of `_.propertyOf` without support for deep paths.
  783. *
  784. * @private
  785. * @param {Object} object The object to query.
  786. * @returns {Function} Returns the new accessor function.
  787. */
  788. function basePropertyOf(object) {
  789. return function(key) {
  790. return object == null ? undefined : object[key];
  791. };
  792. }
  793. /**
  794. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  795. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  796. *
  797. * @private
  798. * @param {Array|Object} collection The collection to iterate over.
  799. * @param {Function} iteratee The function invoked per iteration.
  800. * @param {*} accumulator The initial value.
  801. * @param {boolean} initAccum Specify using the first or last element of
  802. * `collection` as the initial value.
  803. * @param {Function} eachFunc The function to iterate over `collection`.
  804. * @returns {*} Returns the accumulated value.
  805. */
  806. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  807. eachFunc(collection, function(value, index, collection) {
  808. accumulator = initAccum
  809. ? (initAccum = false, value)
  810. : iteratee(accumulator, value, index, collection);
  811. });
  812. return accumulator;
  813. }
  814. /**
  815. * The base implementation of `_.sortBy` which uses `comparer` to define the
  816. * sort order of `array` and replaces criteria objects with their corresponding
  817. * values.
  818. *
  819. * @private
  820. * @param {Array} array The array to sort.
  821. * @param {Function} comparer The function to define sort order.
  822. * @returns {Array} Returns `array`.
  823. */
  824. function baseSortBy(array, comparer) {
  825. var length = array.length;
  826. array.sort(comparer);
  827. while (length--) {
  828. array[length] = array[length].value;
  829. }
  830. return array;
  831. }
  832. /**
  833. * The base implementation of `_.sum` and `_.sumBy` without support for
  834. * iteratee shorthands.
  835. *
  836. * @private
  837. * @param {Array} array The array to iterate over.
  838. * @param {Function} iteratee The function invoked per iteration.
  839. * @returns {number} Returns the sum.
  840. */
  841. function baseSum(array, iteratee) {
  842. var result,
  843. index = -1,
  844. length = array.length;
  845. while (++index < length) {
  846. var current = iteratee(array[index]);
  847. if (current !== undefined) {
  848. result = result === undefined ? current : (result + current);
  849. }
  850. }
  851. return result;
  852. }
  853. /**
  854. * The base implementation of `_.times` without support for iteratee shorthands
  855. * or max array length checks.
  856. *
  857. * @private
  858. * @param {number} n The number of times to invoke `iteratee`.
  859. * @param {Function} iteratee The function invoked per iteration.
  860. * @returns {Array} Returns the array of results.
  861. */
  862. function baseTimes(n, iteratee) {
  863. var index = -1,
  864. result = Array(n);
  865. while (++index < n) {
  866. result[index] = iteratee(index);
  867. }
  868. return result;
  869. }
  870. /**
  871. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  872. * of key-value pairs for `object` corresponding to the property names of `props`.
  873. *
  874. * @private
  875. * @param {Object} object The object to query.
  876. * @param {Array} props The property names to get values for.
  877. * @returns {Object} Returns the key-value pairs.
  878. */
  879. function baseToPairs(object, props) {
  880. return arrayMap(props, function(key) {
  881. return [key, object[key]];
  882. });
  883. }
  884. /**
  885. * The base implementation of `_.unary` without support for storing metadata.
  886. *
  887. * @private
  888. * @param {Function} func The function to cap arguments for.
  889. * @returns {Function} Returns the new capped function.
  890. */
  891. function baseUnary(func) {
  892. return function(value) {
  893. return func(value);
  894. };
  895. }
  896. /**
  897. * The base implementation of `_.values` and `_.valuesIn` which creates an
  898. * array of `object` property values corresponding to the property names
  899. * of `props`.
  900. *
  901. * @private
  902. * @param {Object} object The object to query.
  903. * @param {Array} props The property names to get values for.
  904. * @returns {Object} Returns the array of property values.
  905. */
  906. function baseValues(object, props) {
  907. return arrayMap(props, function(key) {
  908. return object[key];
  909. });
  910. }
  911. /**
  912. * Checks if a `cache` value for `key` exists.
  913. *
  914. * @private
  915. * @param {Object} cache The cache to query.
  916. * @param {string} key The key of the entry to check.
  917. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  918. */
  919. function cacheHas(cache, key) {
  920. return cache.has(key);
  921. }
  922. /**
  923. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  924. * that is not found in the character symbols.
  925. *
  926. * @private
  927. * @param {Array} strSymbols The string symbols to inspect.
  928. * @param {Array} chrSymbols The character symbols to find.
  929. * @returns {number} Returns the index of the first unmatched string symbol.
  930. */
  931. function charsStartIndex(strSymbols, chrSymbols) {
  932. var index = -1,
  933. length = strSymbols.length;
  934. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  935. return index;
  936. }
  937. /**
  938. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  939. * that is not found in the character symbols.
  940. *
  941. * @private
  942. * @param {Array} strSymbols The string symbols to inspect.
  943. * @param {Array} chrSymbols The character symbols to find.
  944. * @returns {number} Returns the index of the last unmatched string symbol.
  945. */
  946. function charsEndIndex(strSymbols, chrSymbols) {
  947. var index = strSymbols.length;
  948. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  949. return index;
  950. }
  951. /**
  952. * Gets the number of `placeholder` occurrences in `array`.
  953. *
  954. * @private
  955. * @param {Array} array The array to inspect.
  956. * @param {*} placeholder The placeholder to search for.
  957. * @returns {number} Returns the placeholder count.
  958. */
  959. function countHolders(array, placeholder) {
  960. var length = array.length,
  961. result = 0;
  962. while (length--) {
  963. if (array[length] === placeholder) {
  964. ++result;
  965. }
  966. }
  967. return result;
  968. }
  969. /**
  970. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  971. * letters to basic Latin letters.
  972. *
  973. * @private
  974. * @param {string} letter The matched letter to deburr.
  975. * @returns {string} Returns the deburred letter.
  976. */
  977. var deburrLetter = basePropertyOf(deburredLetters);
  978. /**
  979. * Used by `_.escape` to convert characters to HTML entities.
  980. *
  981. * @private
  982. * @param {string} chr The matched character to escape.
  983. * @returns {string} Returns the escaped character.
  984. */
  985. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  986. /**
  987. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  988. *
  989. * @private
  990. * @param {string} chr The matched character to escape.
  991. * @returns {string} Returns the escaped character.
  992. */
  993. function escapeStringChar(chr) {
  994. return '\\' + stringEscapes[chr];
  995. }
  996. /**
  997. * Gets the value at `key` of `object`.
  998. *
  999. * @private
  1000. * @param {Object} [object] The object to query.
  1001. * @param {string} key The key of the property to get.
  1002. * @returns {*} Returns the property value.
  1003. */
  1004. function getValue(object, key) {
  1005. return object == null ? undefined : object[key];
  1006. }
  1007. /**
  1008. * Checks if `string` contains Unicode symbols.
  1009. *
  1010. * @private
  1011. * @param {string} string The string to inspect.
  1012. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1013. */
  1014. function hasUnicode(string) {
  1015. return reHasUnicode.test(string);
  1016. }
  1017. /**
  1018. * Checks if `string` contains a word composed of Unicode symbols.
  1019. *
  1020. * @private
  1021. * @param {string} string The string to inspect.
  1022. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1023. */
  1024. function hasUnicodeWord(string) {
  1025. return reHasUnicodeWord.test(string);
  1026. }
  1027. /**
  1028. * Converts `iterator` to an array.
  1029. *
  1030. * @private
  1031. * @param {Object} iterator The iterator to convert.
  1032. * @returns {Array} Returns the converted array.
  1033. */
  1034. function iteratorToArray(iterator) {
  1035. var data,
  1036. result = [];
  1037. while (!(data = iterator.next()).done) {
  1038. result.push(data.value);
  1039. }
  1040. return result;
  1041. }
  1042. /**
  1043. * Converts `map` to its key-value pairs.
  1044. *
  1045. * @private
  1046. * @param {Object} map The map to convert.
  1047. * @returns {Array} Returns the key-value pairs.
  1048. */
  1049. function mapToArray(map) {
  1050. var index = -1,
  1051. result = Array(map.size);
  1052. map.forEach(function(value, key) {
  1053. result[++index] = [key, value];
  1054. });
  1055. return result;
  1056. }
  1057. /**
  1058. * Creates a unary function that invokes `func` with its argument transformed.
  1059. *
  1060. * @private
  1061. * @param {Function} func The function to wrap.
  1062. * @param {Function} transform The argument transform.
  1063. * @returns {Function} Returns the new function.
  1064. */
  1065. function overArg(func, transform) {
  1066. return function(arg) {
  1067. return func(transform(arg));
  1068. };
  1069. }
  1070. /**
  1071. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1072. * and returns an array of their indexes.
  1073. *
  1074. * @private
  1075. * @param {Array} array The array to modify.
  1076. * @param {*} placeholder The placeholder to replace.
  1077. * @returns {Array} Returns the new array of placeholder indexes.
  1078. */
  1079. function replaceHolders(array, placeholder) {
  1080. var index = -1,
  1081. length = array.length,
  1082. resIndex = 0,
  1083. result = [];
  1084. while (++index < length) {
  1085. var value = array[index];
  1086. if (value === placeholder || value === PLACEHOLDER) {
  1087. array[index] = PLACEHOLDER;
  1088. result[resIndex++] = index;
  1089. }
  1090. }
  1091. return result;
  1092. }
  1093. /**
  1094. * Converts `set` to an array of its values.
  1095. *
  1096. * @private
  1097. * @param {Object} set The set to convert.
  1098. * @returns {Array} Returns the values.
  1099. */
  1100. function setToArray(set) {
  1101. var index = -1,
  1102. result = Array(set.size);
  1103. set.forEach(function(value) {
  1104. result[++index] = value;
  1105. });
  1106. return result;
  1107. }
  1108. /**
  1109. * Converts `set` to its value-value pairs.
  1110. *
  1111. * @private
  1112. * @param {Object} set The set to convert.
  1113. * @returns {Array} Returns the value-value pairs.
  1114. */
  1115. function setToPairs(set) {
  1116. var index = -1,
  1117. result = Array(set.size);
  1118. set.forEach(function(value) {
  1119. result[++index] = [value, value];
  1120. });
  1121. return result;
  1122. }
  1123. /**
  1124. * A specialized version of `_.indexOf` which performs strict equality
  1125. * comparisons of values, i.e. `===`.
  1126. *
  1127. * @private
  1128. * @param {Array} array The array to inspect.
  1129. * @param {*} value The value to search for.
  1130. * @param {number} fromIndex The index to search from.
  1131. * @returns {number} Returns the index of the matched value, else `-1`.
  1132. */
  1133. function strictIndexOf(array, value, fromIndex) {
  1134. var index = fromIndex - 1,
  1135. length = array.length;
  1136. while (++index < length) {
  1137. if (array[index] === value) {
  1138. return index;
  1139. }
  1140. }
  1141. return -1;
  1142. }
  1143. /**
  1144. * A specialized version of `_.lastIndexOf` which performs strict equality
  1145. * comparisons of values, i.e. `===`.
  1146. *
  1147. * @private
  1148. * @param {Array} array The array to inspect.
  1149. * @param {*} value The value to search for.
  1150. * @param {number} fromIndex The index to search from.
  1151. * @returns {number} Returns the index of the matched value, else `-1`.
  1152. */
  1153. function strictLastIndexOf(array, value, fromIndex) {
  1154. var index = fromIndex + 1;
  1155. while (index--) {
  1156. if (array[index] === value) {
  1157. return index;
  1158. }
  1159. }
  1160. return index;
  1161. }
  1162. /**
  1163. * Gets the number of symbols in `string`.
  1164. *
  1165. * @private
  1166. * @param {string} string The string to inspect.
  1167. * @returns {number} Returns the string size.
  1168. */
  1169. function stringSize(string) {
  1170. return hasUnicode(string)
  1171. ? unicodeSize(string)
  1172. : asciiSize(string);
  1173. }
  1174. /**
  1175. * Converts `string` to an array.
  1176. *
  1177. * @private
  1178. * @param {string} string The string to convert.
  1179. * @returns {Array} Returns the converted array.
  1180. */
  1181. function stringToArray(string) {
  1182. return hasUnicode(string)
  1183. ? unicodeToArray(string)
  1184. : asciiToArray(string);
  1185. }
  1186. /**
  1187. * Used by `_.unescape` to convert HTML entities to characters.
  1188. *
  1189. * @private
  1190. * @param {string} chr The matched character to unescape.
  1191. * @returns {string} Returns the unescaped character.
  1192. */
  1193. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1194. /**
  1195. * Gets the size of a Unicode `string`.
  1196. *
  1197. * @private
  1198. * @param {string} string The string inspect.
  1199. * @returns {number} Returns the string size.
  1200. */
  1201. function unicodeSize(string) {
  1202. var result = reUnicode.lastIndex = 0;
  1203. while (reUnicode.test(string)) {
  1204. ++result;
  1205. }
  1206. return result;
  1207. }
  1208. /**
  1209. * Converts a Unicode `string` to an array.
  1210. *
  1211. * @private
  1212. * @param {string} string The string to convert.
  1213. * @returns {Array} Returns the converted array.
  1214. */
  1215. function unicodeToArray(string) {
  1216. return string.match(reUnicode) || [];
  1217. }
  1218. /**
  1219. * Splits a Unicode `string` into an array of its words.
  1220. *
  1221. * @private
  1222. * @param {string} The string to inspect.
  1223. * @returns {Array} Returns the words of `string`.
  1224. */
  1225. function unicodeWords(string) {
  1226. return string.match(reUnicodeWord) || [];
  1227. }
  1228. /*--------------------------------------------------------------------------*/
  1229. /**
  1230. * Create a new pristine `lodash` function using the `context` object.
  1231. *
  1232. * @static
  1233. * @memberOf _
  1234. * @since 1.1.0
  1235. * @category Util
  1236. * @param {Object} [context=root] The context object.
  1237. * @returns {Function} Returns a new `lodash` function.
  1238. * @example
  1239. *
  1240. * _.mixin({ 'foo': _.constant('foo') });
  1241. *
  1242. * var lodash = _.runInContext();
  1243. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1244. *
  1245. * _.isFunction(_.foo);
  1246. * // => true
  1247. * _.isFunction(_.bar);
  1248. * // => false
  1249. *
  1250. * lodash.isFunction(lodash.foo);
  1251. * // => false
  1252. * lodash.isFunction(lodash.bar);
  1253. * // => true
  1254. *
  1255. * // Create a suped-up `defer` in Node.js.
  1256. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1257. */
  1258. var runInContext = (function runInContext(context) {
  1259. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1260. /** Built-in constructor references. */
  1261. var Array = context.Array,
  1262. Date = context.Date,
  1263. Error = context.Error,
  1264. Function = context.Function,
  1265. Math = context.Math,
  1266. Object = context.Object,
  1267. RegExp = context.RegExp,
  1268. String = context.String,
  1269. TypeError = context.TypeError;
  1270. /** Used for built-in method references. */
  1271. var arrayProto = Array.prototype,
  1272. funcProto = Function.prototype,
  1273. objectProto = Object.prototype;
  1274. /** Used to detect overreaching core-js shims. */
  1275. var coreJsData = context['__core-js_shared__'];
  1276. /** Used to resolve the decompiled source of functions. */
  1277. var funcToString = funcProto.toString;
  1278. /** Used to check objects for own properties. */
  1279. var hasOwnProperty = objectProto.hasOwnProperty;
  1280. /** Used to generate unique IDs. */
  1281. var idCounter = 0;
  1282. /** Used to detect methods masquerading as native. */
  1283. var maskSrcKey = (function() {
  1284. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1285. return uid ? ('Symbol(src)_1.' + uid) : '';
  1286. }());
  1287. /**
  1288. * Used to resolve the
  1289. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1290. * of values.
  1291. */
  1292. var nativeObjectToString = objectProto.toString;
  1293. /** Used to infer the `Object` constructor. */
  1294. var objectCtorString = funcToString.call(Object);
  1295. /** Used to restore the original `_` reference in `_.noConflict`. */
  1296. var oldDash = root._;
  1297. /** Used to detect if a method is native. */
  1298. var reIsNative = RegExp('^' +
  1299. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1300. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1301. );
  1302. /** Built-in value references. */
  1303. var Buffer = moduleExports ? context.Buffer : undefined,
  1304. Symbol = context.Symbol,
  1305. Uint8Array = context.Uint8Array,
  1306. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1307. getPrototype = overArg(Object.getPrototypeOf, Object),
  1308. objectCreate = Object.create,
  1309. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1310. splice = arrayProto.splice,
  1311. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1312. symIterator = Symbol ? Symbol.iterator : undefined,
  1313. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1314. var defineProperty = (function() {
  1315. try {
  1316. var func = getNative(Object, 'defineProperty');
  1317. func({}, '', {});
  1318. return func;
  1319. } catch (e) {}
  1320. }());
  1321. /** Mocked built-ins. */
  1322. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1323. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1324. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1325. /* Built-in method references for those with the same name as other `lodash` methods. */
  1326. var nativeCeil = Math.ceil,
  1327. nativeFloor = Math.floor,
  1328. nativeGetSymbols = Object.getOwnPropertySymbols,
  1329. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1330. nativeIsFinite = context.isFinite,
  1331. nativeJoin = arrayProto.join,
  1332. nativeKeys = overArg(Object.keys, Object),
  1333. nativeMax = Math.max,
  1334. nativeMin = Math.min,
  1335. nativeNow = Date.now,
  1336. nativeParseInt = context.parseInt,
  1337. nativeRandom = Math.random,
  1338. nativeReverse = arrayProto.reverse;
  1339. /* Built-in method references that are verified to be native. */
  1340. var DataView = getNative(context, 'DataView'),
  1341. Map = getNative(context, 'Map'),
  1342. Promise = getNative(context, 'Promise'),
  1343. Set = getNative(context, 'Set'),
  1344. WeakMap = getNative(context, 'WeakMap'),
  1345. nativeCreate = getNative(Object, 'create');
  1346. /** Used to store function metadata. */
  1347. var metaMap = WeakMap && new WeakMap;
  1348. /** Used to lookup unminified function names. */
  1349. var realNames = {};
  1350. /** Used to detect maps, sets, and weakmaps. */
  1351. var dataViewCtorString = toSource(DataView),
  1352. mapCtorString = toSource(Map),
  1353. promiseCtorString = toSource(Promise),
  1354. setCtorString = toSource(Set),
  1355. weakMapCtorString = toSource(WeakMap);
  1356. /** Used to convert symbols to primitives and strings. */
  1357. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1358. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1359. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1360. /*------------------------------------------------------------------------*/
  1361. /**
  1362. * Creates a `lodash` object which wraps `value` to enable implicit method
  1363. * chain sequences. Methods that operate on and return arrays, collections,
  1364. * and functions can be chained together. Methods that retrieve a single value
  1365. * or may return a primitive value will automatically end the chain sequence
  1366. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1367. * with `_#value`.
  1368. *
  1369. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1370. * enabled using `_.chain`.
  1371. *
  1372. * The execution of chained methods is lazy, that is, it's deferred until
  1373. * `_#value` is implicitly or explicitly called.
  1374. *
  1375. * Lazy evaluation allows several methods to support shortcut fusion.
  1376. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1377. * the creation of intermediate arrays and can greatly reduce the number of
  1378. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1379. * fusion if the section is applied to an array and iteratees accept only
  1380. * one argument. The heuristic for whether a section qualifies for shortcut
  1381. * fusion is subject to change.
  1382. *
  1383. * Chaining is supported in custom builds as long as the `_#value` method is
  1384. * directly or indirectly included in the build.
  1385. *
  1386. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1387. *
  1388. * The wrapper `Array` methods are:
  1389. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1390. *
  1391. * The wrapper `String` methods are:
  1392. * `replace` and `split`
  1393. *
  1394. * The wrapper methods that support shortcut fusion are:
  1395. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1396. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1397. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1398. *
  1399. * The chainable wrapper methods are:
  1400. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1401. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1402. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1403. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1404. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1405. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1406. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1407. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1408. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1409. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1410. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1411. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1412. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1413. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1414. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1415. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1416. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1417. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1418. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1419. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1420. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1421. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1422. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1423. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1424. *
  1425. * The wrapper methods that are **not** chainable by default are:
  1426. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1427. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1428. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1429. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1430. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1431. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1432. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1433. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1434. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1435. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1436. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1437. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1438. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1439. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1440. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1441. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1442. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1443. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1444. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1445. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1446. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1447. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1448. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1449. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1450. * `upperFirst`, `value`, and `words`
  1451. *
  1452. * @name _
  1453. * @constructor
  1454. * @category Seq
  1455. * @param {*} value The value to wrap in a `lodash` instance.
  1456. * @returns {Object} Returns the new `lodash` wrapper instance.
  1457. * @example
  1458. *
  1459. * function square(n) {
  1460. * return n * n;
  1461. * }
  1462. *
  1463. * var wrapped = _([1, 2, 3]);
  1464. *
  1465. * // Returns an unwrapped value.
  1466. * wrapped.reduce(_.add);
  1467. * // => 6
  1468. *
  1469. * // Returns a wrapped value.
  1470. * var squares = wrapped.map(square);
  1471. *
  1472. * _.isArray(squares);
  1473. * // => false
  1474. *
  1475. * _.isArray(squares.value());
  1476. * // => true
  1477. */
  1478. function lodash(value) {
  1479. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1480. if (value instanceof LodashWrapper) {
  1481. return value;
  1482. }
  1483. if (hasOwnProperty.call(value, '__wrapped__')) {
  1484. return wrapperClone(value);
  1485. }
  1486. }
  1487. return new LodashWrapper(value);
  1488. }
  1489. /**
  1490. * The base implementation of `_.create` without support for assigning
  1491. * properties to the created object.
  1492. *
  1493. * @private
  1494. * @param {Object} proto The object to inherit from.
  1495. * @returns {Object} Returns the new object.
  1496. */
  1497. var baseCreate = (function() {
  1498. function object() {}
  1499. return function(proto) {
  1500. if (!isObject(proto)) {
  1501. return {};
  1502. }
  1503. if (objectCreate) {
  1504. return objectCreate(proto);
  1505. }
  1506. object.prototype = proto;
  1507. var result = new object;
  1508. object.prototype = undefined;
  1509. return result;
  1510. };
  1511. }());
  1512. /**
  1513. * The function whose prototype chain sequence wrappers inherit from.
  1514. *
  1515. * @private
  1516. */
  1517. function baseLodash() {
  1518. // No operation performed.
  1519. }
  1520. /**
  1521. * The base constructor for creating `lodash` wrapper objects.
  1522. *
  1523. * @private
  1524. * @param {*} value The value to wrap.
  1525. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1526. */
  1527. function LodashWrapper(value, chainAll) {
  1528. this.__wrapped__ = value;
  1529. this.__actions__ = [];
  1530. this.__chain__ = !!chainAll;
  1531. this.__index__ = 0;
  1532. this.__values__ = undefined;
  1533. }
  1534. /**
  1535. * By default, the template delimiters used by lodash are like those in
  1536. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1537. * following template settings to use alternative delimiters.
  1538. *
  1539. * @static
  1540. * @memberOf _
  1541. * @type {Object}
  1542. */
  1543. lodash.templateSettings = {
  1544. /**
  1545. * Used to detect `data` property values to be HTML-escaped.
  1546. *
  1547. * @memberOf _.templateSettings
  1548. * @type {RegExp}
  1549. */
  1550. 'escape': reEscape,
  1551. /**
  1552. * Used to detect code to be evaluated.
  1553. *
  1554. * @memberOf _.templateSettings
  1555. * @type {RegExp}
  1556. */
  1557. 'evaluate': reEvaluate,
  1558. /**
  1559. * Used to detect `data` property values to inject.
  1560. *
  1561. * @memberOf _.templateSettings
  1562. * @type {RegExp}
  1563. */
  1564. 'interpolate': reInterpolate,
  1565. /**
  1566. * Used to reference the data object in the template text.
  1567. *
  1568. * @memberOf _.templateSettings
  1569. * @type {string}
  1570. */
  1571. 'variable': '',
  1572. /**
  1573. * Used to import variables into the compiled template.
  1574. *
  1575. * @memberOf _.templateSettings
  1576. * @type {Object}
  1577. */
  1578. 'imports': {
  1579. /**
  1580. * A reference to the `lodash` function.
  1581. *
  1582. * @memberOf _.templateSettings.imports
  1583. * @type {Function}
  1584. */
  1585. '_': lodash
  1586. }
  1587. };
  1588. // Ensure wrappers are instances of `baseLodash`.
  1589. lodash.prototype = baseLodash.prototype;
  1590. lodash.prototype.constructor = lodash;
  1591. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1592. LodashWrapper.prototype.constructor = LodashWrapper;
  1593. /*------------------------------------------------------------------------*/
  1594. /**
  1595. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1596. *
  1597. * @private
  1598. * @constructor
  1599. * @param {*} value The value to wrap.
  1600. */
  1601. function LazyWrapper(value) {
  1602. this.__wrapped__ = value;
  1603. this.__actions__ = [];
  1604. this.__dir__ = 1;
  1605. this.__filtered__ = false;
  1606. this.__iteratees__ = [];
  1607. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1608. this.__views__ = [];
  1609. }
  1610. /**
  1611. * Creates a clone of the lazy wrapper object.
  1612. *
  1613. * @private
  1614. * @name clone
  1615. * @memberOf LazyWrapper
  1616. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1617. */
  1618. function lazyClone() {
  1619. var result = new LazyWrapper(this.__wrapped__);
  1620. result.__actions__ = copyArray(this.__actions__);
  1621. result.__dir__ = this.__dir__;
  1622. result.__filtered__ = this.__filtered__;
  1623. result.__iteratees__ = copyArray(this.__iteratees__);
  1624. result.__takeCount__ = this.__takeCount__;
  1625. result.__views__ = copyArray(this.__views__);
  1626. return result;
  1627. }
  1628. /**
  1629. * Reverses the direction of lazy iteration.
  1630. *
  1631. * @private
  1632. * @name reverse
  1633. * @memberOf LazyWrapper
  1634. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1635. */
  1636. function lazyReverse() {
  1637. if (this.__filtered__) {
  1638. var result = new LazyWrapper(this);
  1639. result.__dir__ = -1;
  1640. result.__filtered__ = true;
  1641. } else {
  1642. result = this.clone();
  1643. result.__dir__ *= -1;
  1644. }
  1645. return result;
  1646. }
  1647. /**
  1648. * Extracts the unwrapped value from its lazy wrapper.
  1649. *
  1650. * @private
  1651. * @name value
  1652. * @memberOf LazyWrapper
  1653. * @returns {*} Returns the unwrapped value.
  1654. */
  1655. function lazyValue() {
  1656. var array = this.__wrapped__.value(),
  1657. dir = this.__dir__,
  1658. isArr = isArray(array),
  1659. isRight = dir < 0,
  1660. arrLength = isArr ? array.length : 0,
  1661. view = getView(0, arrLength, this.__views__),
  1662. start = view.start,
  1663. end = view.end,
  1664. length = end - start,
  1665. index = isRight ? end : (start - 1),
  1666. iteratees = this.__iteratees__,
  1667. iterLength = iteratees.length,
  1668. resIndex = 0,
  1669. takeCount = nativeMin(length, this.__takeCount__);
  1670. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1671. return baseWrapperValue(array, this.__actions__);
  1672. }
  1673. var result = [];
  1674. outer:
  1675. while (length-- && resIndex < takeCount) {
  1676. index += dir;
  1677. var iterIndex = -1,
  1678. value = array[index];
  1679. while (++iterIndex < iterLength) {
  1680. var data = iteratees[iterIndex],
  1681. iteratee = data.iteratee,
  1682. type = data.type,
  1683. computed = iteratee(value);
  1684. if (type == LAZY_MAP_FLAG) {
  1685. value = computed;
  1686. } else if (!computed) {
  1687. if (type == LAZY_FILTER_FLAG) {
  1688. continue outer;
  1689. } else {
  1690. break outer;
  1691. }
  1692. }
  1693. }
  1694. result[resIndex++] = value;
  1695. }
  1696. return result;
  1697. }
  1698. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1699. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1700. LazyWrapper.prototype.constructor = LazyWrapper;
  1701. /*------------------------------------------------------------------------*/
  1702. /**
  1703. * Creates a hash object.
  1704. *
  1705. * @private
  1706. * @constructor
  1707. * @param {Array} [entries] The key-value pairs to cache.
  1708. */
  1709. function Hash(entries) {
  1710. var index = -1,
  1711. length = entries == null ? 0 : entries.length;
  1712. this.clear();
  1713. while (++index < length) {
  1714. var entry = entries[index];
  1715. this.set(entry[0], entry[1]);
  1716. }
  1717. }
  1718. /**
  1719. * Removes all key-value entries from the hash.
  1720. *
  1721. * @private
  1722. * @name clear
  1723. * @memberOf Hash
  1724. */
  1725. function hashClear() {
  1726. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1727. this.size = 0;
  1728. }
  1729. /**
  1730. * Removes `key` and its value from the hash.
  1731. *
  1732. * @private
  1733. * @name delete
  1734. * @memberOf Hash
  1735. * @param {Object} hash The hash to modify.
  1736. * @param {string} key The key of the value to remove.
  1737. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1738. */
  1739. function hashDelete(key) {
  1740. var result = this.has(key) && delete this.__data__[key];
  1741. this.size -= result ? 1 : 0;
  1742. return result;
  1743. }
  1744. /**
  1745. * Gets the hash value for `key`.
  1746. *
  1747. * @private
  1748. * @name get
  1749. * @memberOf Hash
  1750. * @param {string} key The key of the value to get.
  1751. * @returns {*} Returns the entry value.
  1752. */
  1753. function hashGet(key) {
  1754. var data = this.__data__;
  1755. if (nativeCreate) {
  1756. var result = data[key];
  1757. return result === HASH_UNDEFINED ? undefined : result;
  1758. }
  1759. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1760. }
  1761. /**
  1762. * Checks if a hash value for `key` exists.
  1763. *
  1764. * @private
  1765. * @name has
  1766. * @memberOf Hash
  1767. * @param {string} key The key of the entry to check.
  1768. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1769. */
  1770. function hashHas(key) {
  1771. var data = this.__data__;
  1772. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1773. }
  1774. /**
  1775. * Sets the hash `key` to `value`.
  1776. *
  1777. * @private
  1778. * @name set
  1779. * @memberOf Hash
  1780. * @param {string} key The key of the value to set.
  1781. * @param {*} value The value to set.
  1782. * @returns {Object} Returns the hash instance.
  1783. */
  1784. function hashSet(key, value) {
  1785. var data = this.__data__;
  1786. this.size += this.has(key) ? 0 : 1;
  1787. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1788. return this;
  1789. }
  1790. // Add methods to `Hash`.
  1791. Hash.prototype.clear = hashClear;
  1792. Hash.prototype['delete'] = hashDelete;
  1793. Hash.prototype.get = hashGet;
  1794. Hash.prototype.has = hashHas;
  1795. Hash.prototype.set = hashSet;
  1796. /*------------------------------------------------------------------------*/
  1797. /**
  1798. * Creates an list cache object.
  1799. *
  1800. * @private
  1801. * @constructor
  1802. * @param {Array} [entries] The key-value pairs to cache.
  1803. */
  1804. function ListCache(entries) {
  1805. var index = -1,
  1806. length = entries == null ? 0 : entries.length;
  1807. this.clear();
  1808. while (++index < length) {
  1809. var entry = entries[index];
  1810. this.set(entry[0], entry[1]);
  1811. }
  1812. }
  1813. /**
  1814. * Removes all key-value entries from the list cache.
  1815. *
  1816. * @private
  1817. * @name clear
  1818. * @memberOf ListCache
  1819. */
  1820. function listCacheClear() {
  1821. this.__data__ = [];
  1822. this.size = 0;
  1823. }
  1824. /**
  1825. * Removes `key` and its value from the list cache.
  1826. *
  1827. * @private
  1828. * @name delete
  1829. * @memberOf ListCache
  1830. * @param {string} key The key of the value to remove.
  1831. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1832. */
  1833. function listCacheDelete(key) {
  1834. var data = this.__data__,
  1835. index = assocIndexOf(data, key);
  1836. if (index < 0) {
  1837. return false;
  1838. }
  1839. var lastIndex = data.length - 1;
  1840. if (index == lastIndex) {
  1841. data.pop();
  1842. } else {
  1843. splice.call(data, index, 1);
  1844. }
  1845. --this.size;
  1846. return true;
  1847. }
  1848. /**
  1849. * Gets the list cache value for `key`.
  1850. *
  1851. * @private
  1852. * @name get
  1853. * @memberOf ListCache
  1854. * @param {string} key The key of the value to get.
  1855. * @returns {*} Returns the entry value.
  1856. */
  1857. function listCacheGet(key) {
  1858. var data = this.__data__,
  1859. index = assocIndexOf(data, key);
  1860. return index < 0 ? undefined : data[index][1];
  1861. }
  1862. /**
  1863. * Checks if a list cache value for `key` exists.
  1864. *
  1865. * @private
  1866. * @name has
  1867. * @memberOf ListCache
  1868. * @param {string} key The key of the entry to check.
  1869. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1870. */
  1871. function listCacheHas(key) {
  1872. return assocIndexOf(this.__data__, key) > -1;
  1873. }
  1874. /**
  1875. * Sets the list cache `key` to `value`.
  1876. *
  1877. * @private
  1878. * @name set
  1879. * @memberOf ListCache
  1880. * @param {string} key The key of the value to set.
  1881. * @param {*} value The value to set.
  1882. * @returns {Object} Returns the list cache instance.
  1883. */
  1884. function listCacheSet(key, value) {
  1885. var data = this.__data__,
  1886. index = assocIndexOf(data, key);
  1887. if (index < 0) {
  1888. ++this.size;
  1889. data.push([key, value]);
  1890. } else {
  1891. data[index][1] = value;
  1892. }
  1893. return this;
  1894. }
  1895. // Add methods to `ListCache`.
  1896. ListCache.prototype.clear = listCacheClear;
  1897. ListCache.prototype['delete'] = listCacheDelete;
  1898. ListCache.prototype.get = listCacheGet;
  1899. ListCache.prototype.has = listCacheHas;
  1900. ListCache.prototype.set = listCacheSet;
  1901. /*------------------------------------------------------------------------*/
  1902. /**
  1903. * Creates a map cache object to store key-value pairs.
  1904. *
  1905. * @private
  1906. * @constructor
  1907. * @param {Array} [entries] The key-value pairs to cache.
  1908. */
  1909. function MapCache(entries) {
  1910. var index = -1,
  1911. length = entries == null ? 0 : entries.length;
  1912. this.clear();
  1913. while (++index < length) {
  1914. var entry = entries[index];
  1915. this.set(entry[0], entry[1]);
  1916. }
  1917. }
  1918. /**
  1919. * Removes all key-value entries from the map.
  1920. *
  1921. * @private
  1922. * @name clear
  1923. * @memberOf MapCache
  1924. */
  1925. function mapCacheClear() {
  1926. this.size = 0;
  1927. this.__data__ = {
  1928. 'hash': new Hash,
  1929. 'map': new (Map || ListCache),
  1930. 'string': new Hash
  1931. };
  1932. }
  1933. /**
  1934. * Removes `key` and its value from the map.
  1935. *
  1936. * @private
  1937. * @name delete
  1938. * @memberOf MapCache
  1939. * @param {string} key The key of the value to remove.
  1940. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1941. */
  1942. function mapCacheDelete(key) {
  1943. var result = getMapData(this, key)['delete'](key);
  1944. this.size -= result ? 1 : 0;
  1945. return result;
  1946. }
  1947. /**
  1948. * Gets the map value for `key`.
  1949. *
  1950. * @private
  1951. * @name get
  1952. * @memberOf MapCache
  1953. * @param {string} key The key of the value to get.
  1954. * @returns {*} Returns the entry value.
  1955. */
  1956. function mapCacheGet(key) {
  1957. return getMapData(this, key).get(key);
  1958. }
  1959. /**
  1960. * Checks if a map value for `key` exists.
  1961. *
  1962. * @private
  1963. * @name has
  1964. * @memberOf MapCache
  1965. * @param {string} key The key of the entry to check.
  1966. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1967. */
  1968. function mapCacheHas(key) {
  1969. return getMapData(this, key).has(key);
  1970. }
  1971. /**
  1972. * Sets the map `key` to `value`.
  1973. *
  1974. * @private
  1975. * @name set
  1976. * @memberOf MapCache
  1977. * @param {string} key The key of the value to set.
  1978. * @param {*} value The value to set.
  1979. * @returns {Object} Returns the map cache instance.
  1980. */
  1981. function mapCacheSet(key, value) {
  1982. var data = getMapData(this, key),
  1983. size = data.size;
  1984. data.set(key, value);
  1985. this.size += data.size == size ? 0 : 1;
  1986. return this;
  1987. }
  1988. // Add methods to `MapCache`.
  1989. MapCache.prototype.clear = mapCacheClear;
  1990. MapCache.prototype['delete'] = mapCacheDelete;
  1991. MapCache.prototype.get = mapCacheGet;
  1992. MapCache.prototype.has = mapCacheHas;
  1993. MapCache.prototype.set = mapCacheSet;
  1994. /*------------------------------------------------------------------------*/
  1995. /**
  1996. *
  1997. * Creates an array cache object to store unique values.
  1998. *
  1999. * @private
  2000. * @constructor
  2001. * @param {Array} [values] The values to cache.
  2002. */
  2003. function SetCache(values) {
  2004. var index = -1,
  2005. length = values == null ? 0 : values.length;
  2006. this.__data__ = new MapCache;
  2007. while (++index < length) {
  2008. this.add(values[index]);
  2009. }
  2010. }
  2011. /**
  2012. * Adds `value` to the array cache.
  2013. *
  2014. * @private
  2015. * @name add
  2016. * @memberOf SetCache
  2017. * @alias push
  2018. * @param {*} value The value to cache.
  2019. * @returns {Object} Returns the cache instance.
  2020. */
  2021. function setCacheAdd(value) {
  2022. this.__data__.set(value, HASH_UNDEFINED);
  2023. return this;
  2024. }
  2025. /**
  2026. * Checks if `value` is in the array cache.
  2027. *
  2028. * @private
  2029. * @name has
  2030. * @memberOf SetCache
  2031. * @param {*} value The value to search for.
  2032. * @returns {number} Returns `true` if `value` is found, else `false`.
  2033. */
  2034. function setCacheHas(value) {
  2035. return this.__data__.has(value);
  2036. }
  2037. // Add methods to `SetCache`.
  2038. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2039. SetCache.prototype.has = setCacheHas;
  2040. /*------------------------------------------------------------------------*/
  2041. /**
  2042. * Creates a stack cache object to store key-value pairs.
  2043. *
  2044. * @private
  2045. * @constructor
  2046. * @param {Array} [entries] The key-value pairs to cache.
  2047. */
  2048. function Stack(entries) {
  2049. var data = this.__data__ = new ListCache(entries);
  2050. this.size = data.size;
  2051. }
  2052. /**
  2053. * Removes all key-value entries from the stack.
  2054. *
  2055. * @private
  2056. * @name clear
  2057. * @memberOf Stack
  2058. */
  2059. function stackClear() {
  2060. this.__data__ = new ListCache;
  2061. this.size = 0;
  2062. }
  2063. /**
  2064. * Removes `key` and its value from the stack.
  2065. *
  2066. * @private
  2067. * @name delete
  2068. * @memberOf Stack
  2069. * @param {string} key The key of the value to remove.
  2070. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2071. */
  2072. function stackDelete(key) {
  2073. var data = this.__data__,
  2074. result = data['delete'](key);
  2075. this.size = data.size;
  2076. return result;
  2077. }
  2078. /**
  2079. * Gets the stack value for `key`.
  2080. *
  2081. * @private
  2082. * @name get
  2083. * @memberOf Stack
  2084. * @param {string} key The key of the value to get.
  2085. * @returns {*} Returns the entry value.
  2086. */
  2087. function stackGet(key) {
  2088. return this.__data__.get(key);
  2089. }
  2090. /**
  2091. * Checks if a stack value for `key` exists.
  2092. *
  2093. * @private
  2094. * @name has
  2095. * @memberOf Stack
  2096. * @param {string} key The key of the entry to check.
  2097. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2098. */
  2099. function stackHas(key) {
  2100. return this.__data__.has(key);
  2101. }
  2102. /**
  2103. * Sets the stack `key` to `value`.
  2104. *
  2105. * @private
  2106. * @name set
  2107. * @memberOf Stack
  2108. * @param {string} key The key of the value to set.
  2109. * @param {*} value The value to set.
  2110. * @returns {Object} Returns the stack cache instance.
  2111. */
  2112. function stackSet(key, value) {
  2113. var data = this.__data__;
  2114. if (data instanceof ListCache) {
  2115. var pairs = data.__data__;
  2116. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2117. pairs.push([key, value]);
  2118. this.size = ++data.size;
  2119. return this;
  2120. }
  2121. data = this.__data__ = new MapCache(pairs);
  2122. }
  2123. data.set(key, value);
  2124. this.size = data.size;
  2125. return this;
  2126. }
  2127. // Add methods to `Stack`.
  2128. Stack.prototype.clear = stackClear;
  2129. Stack.prototype['delete'] = stackDelete;
  2130. Stack.prototype.get = stackGet;
  2131. Stack.prototype.has = stackHas;
  2132. Stack.prototype.set = stackSet;
  2133. /*------------------------------------------------------------------------*/
  2134. /**
  2135. * Creates an array of the enumerable property names of the array-like `value`.
  2136. *
  2137. * @private
  2138. * @param {*} value The value to query.
  2139. * @param {boolean} inherited Specify returning inherited property names.
  2140. * @returns {Array} Returns the array of property names.
  2141. */
  2142. function arrayLikeKeys(value, inherited) {
  2143. var isArr = isArray(value),
  2144. isArg = !isArr && isArguments(value),
  2145. isBuff = !isArr && !isArg && isBuffer(value),
  2146. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2147. skipIndexes = isArr || isArg || isBuff || isType,
  2148. result = skipIndexes ? baseTimes(value.length, String) : [],
  2149. length = result.length;
  2150. for (var key in value) {
  2151. if ((inherited || hasOwnProperty.call(value, key)) &&
  2152. !(skipIndexes && (
  2153. // Safari 9 has enumerable `arguments.length` in strict mode.
  2154. key == 'length' ||
  2155. // Node.js 0.10 has enumerable non-index properties on buffers.
  2156. (isBuff && (key == 'offset' || key == 'parent')) ||
  2157. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2158. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2159. // Skip index properties.
  2160. isIndex(key, length)
  2161. ))) {
  2162. result.push(key);
  2163. }
  2164. }
  2165. return result;
  2166. }
  2167. /**
  2168. * A specialized version of `_.sample` for arrays.
  2169. *
  2170. * @private
  2171. * @param {Array} array The array to sample.
  2172. * @returns {*} Returns the random element.
  2173. */
  2174. function arraySample(array) {
  2175. var length = array.length;
  2176. return length ? array[baseRandom(0, length - 1)] : undefined;
  2177. }
  2178. /**
  2179. * A specialized version of `_.sampleSize` for arrays.
  2180. *
  2181. * @private
  2182. * @param {Array} array The array to sample.
  2183. * @param {number} n The number of elements to sample.
  2184. * @returns {Array} Returns the random elements.
  2185. */
  2186. function arraySampleSize(array, n) {
  2187. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2188. }
  2189. /**
  2190. * A specialized version of `_.shuffle` for arrays.
  2191. *
  2192. * @private
  2193. * @param {Array} array The array to shuffle.
  2194. * @returns {Array} Returns the new shuffled array.
  2195. */
  2196. function arrayShuffle(array) {
  2197. return shuffleSelf(copyArray(array));
  2198. }
  2199. /**
  2200. * This function is like `assignValue` except that it doesn't assign
  2201. * `undefined` values.
  2202. *
  2203. * @private
  2204. * @param {Object} object The object to modify.
  2205. * @param {string} key The key of the property to assign.
  2206. * @param {*} value The value to assign.
  2207. */
  2208. function assignMergeValue(object, key, value) {
  2209. if ((value !== undefined && !eq(object[key], value)) ||
  2210. (value === undefined && !(key in object))) {
  2211. baseAssignValue(object, key, value);
  2212. }
  2213. }
  2214. /**
  2215. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2216. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2217. * for equality comparisons.
  2218. *
  2219. * @private
  2220. * @param {Object} object The object to modify.
  2221. * @param {string} key The key of the property to assign.
  2222. * @param {*} value The value to assign.
  2223. */
  2224. function assignValue(object, key, value) {
  2225. var objValue = object[key];
  2226. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2227. (value === undefined && !(key in object))) {
  2228. baseAssignValue(object, key, value);
  2229. }
  2230. }
  2231. /**
  2232. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2233. *
  2234. * @private
  2235. * @param {Array} array The array to inspect.
  2236. * @param {*} key The key to search for.
  2237. * @returns {number} Returns the index of the matched value, else `-1`.
  2238. */
  2239. function assocIndexOf(array, key) {
  2240. var length = array.length;
  2241. while (length--) {
  2242. if (eq(array[length][0], key)) {
  2243. return length;
  2244. }
  2245. }
  2246. return -1;
  2247. }
  2248. /**
  2249. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2250. * by `iteratee` and values set by `setter`.
  2251. *
  2252. * @private
  2253. * @param {Array|Object} collection The collection to iterate over.
  2254. * @param {Function} setter The function to set `accumulator` values.
  2255. * @param {Function} iteratee The iteratee to transform keys.
  2256. * @param {Object} accumulator The initial aggregated object.
  2257. * @returns {Function} Returns `accumulator`.
  2258. */
  2259. function baseAggregator(collection, setter, iteratee, accumulator) {
  2260. baseEach(collection, function(value, key, collection) {
  2261. setter(accumulator, value, iteratee(value), collection);
  2262. });
  2263. return accumulator;
  2264. }
  2265. /**
  2266. * The base implementation of `_.assign` without support for multiple sources
  2267. * or `customizer` functions.
  2268. *
  2269. * @private
  2270. * @param {Object} object The destination object.
  2271. * @param {Object} source The source object.
  2272. * @returns {Object} Returns `object`.
  2273. */
  2274. function baseAssign(object, source) {
  2275. return object && copyObject(source, keys(source), object);
  2276. }
  2277. /**
  2278. * The base implementation of `_.assignIn` without support for multiple sources
  2279. * or `customizer` functions.
  2280. *
  2281. * @private
  2282. * @param {Object} object The destination object.
  2283. * @param {Object} source The source object.
  2284. * @returns {Object} Returns `object`.
  2285. */
  2286. function baseAssignIn(object, source) {
  2287. return object && copyObject(source, keysIn(source), object);
  2288. }
  2289. /**
  2290. * The base implementation of `assignValue` and `assignMergeValue` without
  2291. * value checks.
  2292. *
  2293. * @private
  2294. * @param {Object} object The object to modify.
  2295. * @param {string} key The key of the property to assign.
  2296. * @param {*} value The value to assign.
  2297. */
  2298. function baseAssignValue(object, key, value) {
  2299. if (key == '__proto__' && defineProperty) {
  2300. defineProperty(object, key, {
  2301. 'configurable': true,
  2302. 'enumerable': true,
  2303. 'value': value,
  2304. 'writable': true
  2305. });
  2306. } else {
  2307. object[key] = value;
  2308. }
  2309. }
  2310. /**
  2311. * The base implementation of `_.at` without support for individual paths.
  2312. *
  2313. * @private
  2314. * @param {Object} object The object to iterate over.
  2315. * @param {string[]} paths The property paths to pick.
  2316. * @returns {Array} Returns the picked elements.
  2317. */
  2318. function baseAt(object, paths) {
  2319. var index = -1,
  2320. length = paths.length,
  2321. result = Array(length),
  2322. skip = object == null;
  2323. while (++index < length) {
  2324. result[index] = skip ? undefined : get(object, paths[index]);
  2325. }
  2326. return result;
  2327. }
  2328. /**
  2329. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2330. *
  2331. * @private
  2332. * @param {number} number The number to clamp.
  2333. * @param {number} [lower] The lower bound.
  2334. * @param {number} upper The upper bound.
  2335. * @returns {number} Returns the clamped number.
  2336. */
  2337. function baseClamp(number, lower, upper) {
  2338. if (number === number) {
  2339. if (upper !== undefined) {
  2340. number = number <= upper ? number : upper;
  2341. }
  2342. if (lower !== undefined) {
  2343. number = number >= lower ? number : lower;
  2344. }
  2345. }
  2346. return number;
  2347. }
  2348. /**
  2349. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2350. * traversed objects.
  2351. *
  2352. * @private
  2353. * @param {*} value The value to clone.
  2354. * @param {boolean} bitmask The bitmask flags.
  2355. * 1 - Deep clone
  2356. * 2 - Flatten inherited properties
  2357. * 4 - Clone symbols
  2358. * @param {Function} [customizer] The function to customize cloning.
  2359. * @param {string} [key] The key of `value`.
  2360. * @param {Object} [object] The parent object of `value`.
  2361. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2362. * @returns {*} Returns the cloned value.
  2363. */
  2364. function baseClone(value, bitmask, customizer, key, object, stack) {
  2365. var result,
  2366. isDeep = bitmask & CLONE_DEEP_FLAG,
  2367. isFlat = bitmask & CLONE_FLAT_FLAG,
  2368. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2369. if (customizer) {
  2370. result = object ? customizer(value, key, object, stack) : customizer(value);
  2371. }
  2372. if (result !== undefined) {
  2373. return result;
  2374. }
  2375. if (!isObject(value)) {
  2376. return value;
  2377. }
  2378. var isArr = isArray(value);
  2379. if (isArr) {
  2380. result = initCloneArray(value);
  2381. if (!isDeep) {
  2382. return copyArray(value, result);
  2383. }
  2384. } else {
  2385. var tag = getTag(value),
  2386. isFunc = tag == funcTag || tag == genTag;
  2387. if (isBuffer(value)) {
  2388. return cloneBuffer(value, isDeep);
  2389. }
  2390. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2391. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2392. if (!isDeep) {
  2393. return isFlat
  2394. ? copySymbolsIn(value, baseAssignIn(result, value))
  2395. : copySymbols(value, baseAssign(result, value));
  2396. }
  2397. } else {
  2398. if (!cloneableTags[tag]) {
  2399. return object ? value : {};
  2400. }
  2401. result = initCloneByTag(value, tag, isDeep);
  2402. }
  2403. }
  2404. // Check for circular references and return its corresponding clone.
  2405. stack || (stack = new Stack);
  2406. var stacked = stack.get(value);
  2407. if (stacked) {
  2408. return stacked;
  2409. }
  2410. stack.set(value, result);
  2411. if (isSet(value)) {
  2412. value.forEach(function(subValue) {
  2413. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2414. });
  2415. } else if (isMap(value)) {
  2416. value.forEach(function(subValue, key) {
  2417. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2418. });
  2419. }
  2420. var keysFunc = isFull
  2421. ? (isFlat ? getAllKeysIn : getAllKeys)
  2422. : (isFlat ? keysIn : keys);
  2423. var props = isArr ? undefined : keysFunc(value);
  2424. arrayEach(props || value, function(subValue, key) {
  2425. if (props) {
  2426. key = subValue;
  2427. subValue = value[key];
  2428. }
  2429. // Recursively populate clone (susceptible to call stack limits).
  2430. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2431. });
  2432. return result;
  2433. }
  2434. /**
  2435. * The base implementation of `_.conforms` which doesn't clone `source`.
  2436. *
  2437. * @private
  2438. * @param {Object} source The object of property predicates to conform to.
  2439. * @returns {Function} Returns the new spec function.
  2440. */
  2441. function baseConforms(source) {
  2442. var props = keys(source);
  2443. return function(object) {
  2444. return baseConformsTo(object, source, props);
  2445. };
  2446. }
  2447. /**
  2448. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2449. *
  2450. * @private
  2451. * @param {Object} object The object to inspect.
  2452. * @param {Object} source The object of property predicates to conform to.
  2453. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2454. */
  2455. function baseConformsTo(object, source, props) {
  2456. var length = props.length;
  2457. if (object == null) {
  2458. return !length;
  2459. }
  2460. object = Object(object);
  2461. while (length--) {
  2462. var key = props[length],
  2463. predicate = source[key],
  2464. value = object[key];
  2465. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2466. return false;
  2467. }
  2468. }
  2469. return true;
  2470. }
  2471. /**
  2472. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2473. * to provide to `func`.
  2474. *
  2475. * @private
  2476. * @param {Function} func The function to delay.
  2477. * @param {number} wait The number of milliseconds to delay invocation.
  2478. * @param {Array} args The arguments to provide to `func`.
  2479. * @returns {number|Object} Returns the timer id or timeout object.
  2480. */
  2481. function baseDelay(func, wait, args) {
  2482. if (typeof func != 'function') {
  2483. throw new TypeError(FUNC_ERROR_TEXT);
  2484. }
  2485. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2486. }
  2487. /**
  2488. * The base implementation of methods like `_.difference` without support
  2489. * for excluding multiple arrays or iteratee shorthands.
  2490. *
  2491. * @private
  2492. * @param {Array} array The array to inspect.
  2493. * @param {Array} values The values to exclude.
  2494. * @param {Function} [iteratee] The iteratee invoked per element.
  2495. * @param {Function} [comparator] The comparator invoked per element.
  2496. * @returns {Array} Returns the new array of filtered values.
  2497. */
  2498. function baseDifference(array, values, iteratee, comparator) {
  2499. var index = -1,
  2500. includes = arrayIncludes,
  2501. isCommon = true,
  2502. length = array.length,
  2503. result = [],
  2504. valuesLength = values.length;
  2505. if (!length) {
  2506. return result;
  2507. }
  2508. if (iteratee) {
  2509. values = arrayMap(values, baseUnary(iteratee));
  2510. }
  2511. if (comparator) {
  2512. includes = arrayIncludesWith;
  2513. isCommon = false;
  2514. }
  2515. else if (values.length >= LARGE_ARRAY_SIZE) {
  2516. includes = cacheHas;
  2517. isCommon = false;
  2518. values = new SetCache(values);
  2519. }
  2520. outer:
  2521. while (++index < length) {
  2522. var value = array[index],
  2523. computed = iteratee == null ? value : iteratee(value);
  2524. value = (comparator || value !== 0) ? value : 0;
  2525. if (isCommon && computed === computed) {
  2526. var valuesIndex = valuesLength;
  2527. while (valuesIndex--) {
  2528. if (values[valuesIndex] === computed) {
  2529. continue outer;
  2530. }
  2531. }
  2532. result.push(value);
  2533. }
  2534. else if (!includes(values, computed, comparator)) {
  2535. result.push(value);
  2536. }
  2537. }
  2538. return result;
  2539. }
  2540. /**
  2541. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2542. *
  2543. * @private
  2544. * @param {Array|Object} collection The collection to iterate over.
  2545. * @param {Function} iteratee The function invoked per iteration.
  2546. * @returns {Array|Object} Returns `collection`.
  2547. */
  2548. var baseEach = createBaseEach(baseForOwn);
  2549. /**
  2550. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2551. *
  2552. * @private
  2553. * @param {Array|Object} collection The collection to iterate over.
  2554. * @param {Function} iteratee The function invoked per iteration.
  2555. * @returns {Array|Object} Returns `collection`.
  2556. */
  2557. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2558. /**
  2559. * The base implementation of `_.every` without support for iteratee shorthands.
  2560. *
  2561. * @private
  2562. * @param {Array|Object} collection The collection to iterate over.
  2563. * @param {Function} predicate The function invoked per iteration.
  2564. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2565. * else `false`
  2566. */
  2567. function baseEvery(collection, predicate) {
  2568. var result = true;
  2569. baseEach(collection, function(value, index, collection) {
  2570. result = !!predicate(value, index, collection);
  2571. return result;
  2572. });
  2573. return result;
  2574. }
  2575. /**
  2576. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2577. * `comparator` to determine the extremum value.
  2578. *
  2579. * @private
  2580. * @param {Array} array The array to iterate over.
  2581. * @param {Function} iteratee The iteratee invoked per iteration.
  2582. * @param {Function} comparator The comparator used to compare values.
  2583. * @returns {*} Returns the extremum value.
  2584. */
  2585. function baseExtremum(array, iteratee, comparator) {
  2586. var index = -1,
  2587. length = array.length;
  2588. while (++index < length) {
  2589. var value = array[index],
  2590. current = iteratee(value);
  2591. if (current != null && (computed === undefined
  2592. ? (current === current && !isSymbol(current))
  2593. : comparator(current, computed)
  2594. )) {
  2595. var computed = current,
  2596. result = value;
  2597. }
  2598. }
  2599. return result;
  2600. }
  2601. /**
  2602. * The base implementation of `_.fill` without an iteratee call guard.
  2603. *
  2604. * @private
  2605. * @param {Array} array The array to fill.
  2606. * @param {*} value The value to fill `array` with.
  2607. * @param {number} [start=0] The start position.
  2608. * @param {number} [end=array.length] The end position.
  2609. * @returns {Array} Returns `array`.
  2610. */
  2611. function baseFill(array, value, start, end) {
  2612. var length = array.length;
  2613. start = toInteger(start);
  2614. if (start < 0) {
  2615. start = -start > length ? 0 : (length + start);
  2616. }
  2617. end = (end === undefined || end > length) ? length : toInteger(end);
  2618. if (end < 0) {
  2619. end += length;
  2620. }
  2621. end = start > end ? 0 : toLength(end);
  2622. while (start < end) {
  2623. array[start++] = value;
  2624. }
  2625. return array;
  2626. }
  2627. /**
  2628. * The base implementation of `_.filter` without support for iteratee shorthands.
  2629. *
  2630. * @private
  2631. * @param {Array|Object} collection The collection to iterate over.
  2632. * @param {Function} predicate The function invoked per iteration.
  2633. * @returns {Array} Returns the new filtered array.
  2634. */
  2635. function baseFilter(collection, predicate) {
  2636. var result = [];
  2637. baseEach(collection, function(value, index, collection) {
  2638. if (predicate(value, index, collection)) {
  2639. result.push(value);
  2640. }
  2641. });
  2642. return result;
  2643. }
  2644. /**
  2645. * The base implementation of `_.flatten` with support for restricting flattening.
  2646. *
  2647. * @private
  2648. * @param {Array} array The array to flatten.
  2649. * @param {number} depth The maximum recursion depth.
  2650. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2651. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2652. * @param {Array} [result=[]] The initial result value.
  2653. * @returns {Array} Returns the new flattened array.
  2654. */
  2655. function baseFlatten(array, depth, predicate, isStrict, result) {
  2656. var index = -1,
  2657. length = array.length;
  2658. predicate || (predicate = isFlattenable);
  2659. result || (result = []);
  2660. while (++index < length) {
  2661. var value = array[index];
  2662. if (depth > 0 && predicate(value)) {
  2663. if (depth > 1) {
  2664. // Recursively flatten arrays (susceptible to call stack limits).
  2665. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2666. } else {
  2667. arrayPush(result, value);
  2668. }
  2669. } else if (!isStrict) {
  2670. result[result.length] = value;
  2671. }
  2672. }
  2673. return result;
  2674. }
  2675. /**
  2676. * The base implementation of `baseForOwn` which iterates over `object`
  2677. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2678. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2679. *
  2680. * @private
  2681. * @param {Object} object The object to iterate over.
  2682. * @param {Function} iteratee The function invoked per iteration.
  2683. * @param {Function} keysFunc The function to get the keys of `object`.
  2684. * @returns {Object} Returns `object`.
  2685. */
  2686. var baseFor = createBaseFor();
  2687. /**
  2688. * This function is like `baseFor` except that it iterates over properties
  2689. * in the opposite order.
  2690. *
  2691. * @private
  2692. * @param {Object} object The object to iterate over.
  2693. * @param {Function} iteratee The function invoked per iteration.
  2694. * @param {Function} keysFunc The function to get the keys of `object`.
  2695. * @returns {Object} Returns `object`.
  2696. */
  2697. var baseForRight = createBaseFor(true);
  2698. /**
  2699. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2700. *
  2701. * @private
  2702. * @param {Object} object The object to iterate over.
  2703. * @param {Function} iteratee The function invoked per iteration.
  2704. * @returns {Object} Returns `object`.
  2705. */
  2706. function baseForOwn(object, iteratee) {
  2707. return object && baseFor(object, iteratee, keys);
  2708. }
  2709. /**
  2710. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2711. *
  2712. * @private
  2713. * @param {Object} object The object to iterate over.
  2714. * @param {Function} iteratee The function invoked per iteration.
  2715. * @returns {Object} Returns `object`.
  2716. */
  2717. function baseForOwnRight(object, iteratee) {
  2718. return object && baseForRight(object, iteratee, keys);
  2719. }
  2720. /**
  2721. * The base implementation of `_.functions` which creates an array of
  2722. * `object` function property names filtered from `props`.
  2723. *
  2724. * @private
  2725. * @param {Object} object The object to inspect.
  2726. * @param {Array} props The property names to filter.
  2727. * @returns {Array} Returns the function names.
  2728. */
  2729. function baseFunctions(object, props) {
  2730. return arrayFilter(props, function(key) {
  2731. return isFunction(object[key]);
  2732. });
  2733. }
  2734. /**
  2735. * The base implementation of `_.get` without support for default values.
  2736. *
  2737. * @private
  2738. * @param {Object} object The object to query.
  2739. * @param {Array|string} path The path of the property to get.
  2740. * @returns {*} Returns the resolved value.
  2741. */
  2742. function baseGet(object, path) {
  2743. path = castPath(path, object);
  2744. var index = 0,
  2745. length = path.length;
  2746. while (object != null && index < length) {
  2747. object = object[toKey(path[index++])];
  2748. }
  2749. return (index && index == length) ? object : undefined;
  2750. }
  2751. /**
  2752. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2753. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2754. * symbols of `object`.
  2755. *
  2756. * @private
  2757. * @param {Object} object The object to query.
  2758. * @param {Function} keysFunc The function to get the keys of `object`.
  2759. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2760. * @returns {Array} Returns the array of property names and symbols.
  2761. */
  2762. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2763. var result = keysFunc(object);
  2764. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2765. }
  2766. /**
  2767. * The base implementation of `getTag` without fallbacks for buggy environments.
  2768. *
  2769. * @private
  2770. * @param {*} value The value to query.
  2771. * @returns {string} Returns the `toStringTag`.
  2772. */
  2773. function baseGetTag(value) {
  2774. if (value == null) {
  2775. return value === undefined ? undefinedTag : nullTag;
  2776. }
  2777. return (symToStringTag && symToStringTag in Object(value))
  2778. ? getRawTag(value)
  2779. : objectToString(value);
  2780. }
  2781. /**
  2782. * The base implementation of `_.gt` which doesn't coerce arguments.
  2783. *
  2784. * @private
  2785. * @param {*} value The value to compare.
  2786. * @param {*} other The other value to compare.
  2787. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2788. * else `false`.
  2789. */
  2790. function baseGt(value, other) {
  2791. return value > other;
  2792. }
  2793. /**
  2794. * The base implementation of `_.has` without support for deep paths.
  2795. *
  2796. * @private
  2797. * @param {Object} [object] The object to query.
  2798. * @param {Array|string} key The key to check.
  2799. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2800. */
  2801. function baseHas(object, key) {
  2802. return object != null && hasOwnProperty.call(object, key);
  2803. }
  2804. /**
  2805. * The base implementation of `_.hasIn` without support for deep paths.
  2806. *
  2807. * @private
  2808. * @param {Object} [object] The object to query.
  2809. * @param {Array|string} key The key to check.
  2810. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2811. */
  2812. function baseHasIn(object, key) {
  2813. return object != null && key in Object(object);
  2814. }
  2815. /**
  2816. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2817. *
  2818. * @private
  2819. * @param {number} number The number to check.
  2820. * @param {number} start The start of the range.
  2821. * @param {number} end The end of the range.
  2822. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2823. */
  2824. function baseInRange(number, start, end) {
  2825. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2826. }
  2827. /**
  2828. * The base implementation of methods like `_.intersection`, without support
  2829. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2830. *
  2831. * @private
  2832. * @param {Array} arrays The arrays to inspect.
  2833. * @param {Function} [iteratee] The iteratee invoked per element.
  2834. * @param {Function} [comparator] The comparator invoked per element.
  2835. * @returns {Array} Returns the new array of shared values.
  2836. */
  2837. function baseIntersection(arrays, iteratee, comparator) {
  2838. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2839. length = arrays[0].length,
  2840. othLength = arrays.length,
  2841. othIndex = othLength,
  2842. caches = Array(othLength),
  2843. maxLength = Infinity,
  2844. result = [];
  2845. while (othIndex--) {
  2846. var array = arrays[othIndex];
  2847. if (othIndex && iteratee) {
  2848. array = arrayMap(array, baseUnary(iteratee));
  2849. }
  2850. maxLength = nativeMin(array.length, maxLength);
  2851. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2852. ? new SetCache(othIndex && array)
  2853. : undefined;
  2854. }
  2855. array = arrays[0];
  2856. var index = -1,
  2857. seen = caches[0];
  2858. outer:
  2859. while (++index < length && result.length < maxLength) {
  2860. var value = array[index],
  2861. computed = iteratee ? iteratee(value) : value;
  2862. value = (comparator || value !== 0) ? value : 0;
  2863. if (!(seen
  2864. ? cacheHas(seen, computed)
  2865. : includes(result, computed, comparator)
  2866. )) {
  2867. othIndex = othLength;
  2868. while (--othIndex) {
  2869. var cache = caches[othIndex];
  2870. if (!(cache
  2871. ? cacheHas(cache, computed)
  2872. : includes(arrays[othIndex], computed, comparator))
  2873. ) {
  2874. continue outer;
  2875. }
  2876. }
  2877. if (seen) {
  2878. seen.push(computed);
  2879. }
  2880. result.push(value);
  2881. }
  2882. }
  2883. return result;
  2884. }
  2885. /**
  2886. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2887. * `object` with values transformed by `iteratee` and set by `setter`.
  2888. *
  2889. * @private
  2890. * @param {Object} object The object to iterate over.
  2891. * @param {Function} setter The function to set `accumulator` values.
  2892. * @param {Function} iteratee The iteratee to transform values.
  2893. * @param {Object} accumulator The initial inverted object.
  2894. * @returns {Function} Returns `accumulator`.
  2895. */
  2896. function baseInverter(object, setter, iteratee, accumulator) {
  2897. baseForOwn(object, function(value, key, object) {
  2898. setter(accumulator, iteratee(value), key, object);
  2899. });
  2900. return accumulator;
  2901. }
  2902. /**
  2903. * The base implementation of `_.invoke` without support for individual
  2904. * method arguments.
  2905. *
  2906. * @private
  2907. * @param {Object} object The object to query.
  2908. * @param {Array|string} path The path of the method to invoke.
  2909. * @param {Array} args The arguments to invoke the method with.
  2910. * @returns {*} Returns the result of the invoked method.
  2911. */
  2912. function baseInvoke(object, path, args) {
  2913. path = castPath(path, object);
  2914. object = parent(object, path);
  2915. var func = object == null ? object : object[toKey(last(path))];
  2916. return func == null ? undefined : apply(func, object, args);
  2917. }
  2918. /**
  2919. * The base implementation of `_.isArguments`.
  2920. *
  2921. * @private
  2922. * @param {*} value The value to check.
  2923. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2924. */
  2925. function baseIsArguments(value) {
  2926. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2927. }
  2928. /**
  2929. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2930. *
  2931. * @private
  2932. * @param {*} value The value to check.
  2933. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2934. */
  2935. function baseIsArrayBuffer(value) {
  2936. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2937. }
  2938. /**
  2939. * The base implementation of `_.isDate` without Node.js optimizations.
  2940. *
  2941. * @private
  2942. * @param {*} value The value to check.
  2943. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2944. */
  2945. function baseIsDate(value) {
  2946. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2947. }
  2948. /**
  2949. * The base implementation of `_.isEqual` which supports partial comparisons
  2950. * and tracks traversed objects.
  2951. *
  2952. * @private
  2953. * @param {*} value The value to compare.
  2954. * @param {*} other The other value to compare.
  2955. * @param {boolean} bitmask The bitmask flags.
  2956. * 1 - Unordered comparison
  2957. * 2 - Partial comparison
  2958. * @param {Function} [customizer] The function to customize comparisons.
  2959. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2960. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2961. */
  2962. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2963. if (value === other) {
  2964. return true;
  2965. }
  2966. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2967. return value !== value && other !== other;
  2968. }
  2969. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2970. }
  2971. /**
  2972. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2973. * deep comparisons and tracks traversed objects enabling objects with circular
  2974. * references to be compared.
  2975. *
  2976. * @private
  2977. * @param {Object} object The object to compare.
  2978. * @param {Object} other The other object to compare.
  2979. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2980. * @param {Function} customizer The function to customize comparisons.
  2981. * @param {Function} equalFunc The function to determine equivalents of values.
  2982. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2983. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2984. */
  2985. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  2986. var objIsArr = isArray(object),
  2987. othIsArr = isArray(other),
  2988. objTag = objIsArr ? arrayTag : getTag(object),
  2989. othTag = othIsArr ? arrayTag : getTag(other);
  2990. objTag = objTag == argsTag ? objectTag : objTag;
  2991. othTag = othTag == argsTag ? objectTag : othTag;
  2992. var objIsObj = objTag == objectTag,
  2993. othIsObj = othTag == objectTag,
  2994. isSameTag = objTag == othTag;
  2995. if (isSameTag && isBuffer(object)) {
  2996. if (!isBuffer(other)) {
  2997. return false;
  2998. }
  2999. objIsArr = true;
  3000. objIsObj = false;
  3001. }
  3002. if (isSameTag && !objIsObj) {
  3003. stack || (stack = new Stack);
  3004. return (objIsArr || isTypedArray(object))
  3005. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3006. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3007. }
  3008. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3009. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3010. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3011. if (objIsWrapped || othIsWrapped) {
  3012. var objUnwrapped = objIsWrapped ? object.value() : object,
  3013. othUnwrapped = othIsWrapped ? other.value() : other;
  3014. stack || (stack = new Stack);
  3015. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3016. }
  3017. }
  3018. if (!isSameTag) {
  3019. return false;
  3020. }
  3021. stack || (stack = new Stack);
  3022. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3023. }
  3024. /**
  3025. * The base implementation of `_.isMap` without Node.js optimizations.
  3026. *
  3027. * @private
  3028. * @param {*} value The value to check.
  3029. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3030. */
  3031. function baseIsMap(value) {
  3032. return isObjectLike(value) && getTag(value) == mapTag;
  3033. }
  3034. /**
  3035. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3036. *
  3037. * @private
  3038. * @param {Object} object The object to inspect.
  3039. * @param {Object} source The object of property values to match.
  3040. * @param {Array} matchData The property names, values, and compare flags to match.
  3041. * @param {Function} [customizer] The function to customize comparisons.
  3042. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3043. */
  3044. function baseIsMatch(object, source, matchData, customizer) {
  3045. var index = matchData.length,
  3046. length = index,
  3047. noCustomizer = !customizer;
  3048. if (object == null) {
  3049. return !length;
  3050. }
  3051. object = Object(object);
  3052. while (index--) {
  3053. var data = matchData[index];
  3054. if ((noCustomizer && data[2])
  3055. ? data[1] !== object[data[0]]
  3056. : !(data[0] in object)
  3057. ) {
  3058. return false;
  3059. }
  3060. }
  3061. while (++index < length) {
  3062. data = matchData[index];
  3063. var key = data[0],
  3064. objValue = object[key],
  3065. srcValue = data[1];
  3066. if (noCustomizer && data[2]) {
  3067. if (objValue === undefined && !(key in object)) {
  3068. return false;
  3069. }
  3070. } else {
  3071. var stack = new Stack;
  3072. if (customizer) {
  3073. var result = customizer(objValue, srcValue, key, object, source, stack);
  3074. }
  3075. if (!(result === undefined
  3076. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3077. : result
  3078. )) {
  3079. return false;
  3080. }
  3081. }
  3082. }
  3083. return true;
  3084. }
  3085. /**
  3086. * The base implementation of `_.isNative` without bad shim checks.
  3087. *
  3088. * @private
  3089. * @param {*} value The value to check.
  3090. * @returns {boolean} Returns `true` if `value` is a native function,
  3091. * else `false`.
  3092. */
  3093. function baseIsNative(value) {
  3094. if (!isObject(value) || isMasked(value)) {
  3095. return false;
  3096. }
  3097. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3098. return pattern.test(toSource(value));
  3099. }
  3100. /**
  3101. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3102. *
  3103. * @private
  3104. * @param {*} value The value to check.
  3105. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3106. */
  3107. function baseIsRegExp(value) {
  3108. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3109. }
  3110. /**
  3111. * The base implementation of `_.isSet` without Node.js optimizations.
  3112. *
  3113. * @private
  3114. * @param {*} value The value to check.
  3115. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3116. */
  3117. function baseIsSet(value) {
  3118. return isObjectLike(value) && getTag(value) == setTag;
  3119. }
  3120. /**
  3121. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3122. *
  3123. * @private
  3124. * @param {*} value The value to check.
  3125. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3126. */
  3127. function baseIsTypedArray(value) {
  3128. return isObjectLike(value) &&
  3129. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3130. }
  3131. /**
  3132. * The base implementation of `_.iteratee`.
  3133. *
  3134. * @private
  3135. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3136. * @returns {Function} Returns the iteratee.
  3137. */
  3138. function baseIteratee(value) {
  3139. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3140. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3141. if (typeof value == 'function') {
  3142. return value;
  3143. }
  3144. if (value == null) {
  3145. return identity;
  3146. }
  3147. if (typeof value == 'object') {
  3148. return isArray(value)
  3149. ? baseMatchesProperty(value[0], value[1])
  3150. : baseMatches(value);
  3151. }
  3152. return property(value);
  3153. }
  3154. /**
  3155. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3156. *
  3157. * @private
  3158. * @param {Object} object The object to query.
  3159. * @returns {Array} Returns the array of property names.
  3160. */
  3161. function baseKeys(object) {
  3162. if (!isPrototype(object)) {
  3163. return nativeKeys(object);
  3164. }
  3165. var result = [];
  3166. for (var key in Object(object)) {
  3167. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3168. result.push(key);
  3169. }
  3170. }
  3171. return result;
  3172. }
  3173. /**
  3174. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3175. *
  3176. * @private
  3177. * @param {Object} object The object to query.
  3178. * @returns {Array} Returns the array of property names.
  3179. */
  3180. function baseKeysIn(object) {
  3181. if (!isObject(object)) {
  3182. return nativeKeysIn(object);
  3183. }
  3184. var isProto = isPrototype(object),
  3185. result = [];
  3186. for (var key in object) {
  3187. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3188. result.push(key);
  3189. }
  3190. }
  3191. return result;
  3192. }
  3193. /**
  3194. * The base implementation of `_.lt` which doesn't coerce arguments.
  3195. *
  3196. * @private
  3197. * @param {*} value The value to compare.
  3198. * @param {*} other The other value to compare.
  3199. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3200. * else `false`.
  3201. */
  3202. function baseLt(value, other) {
  3203. return value < other;
  3204. }
  3205. /**
  3206. * The base implementation of `_.map` without support for iteratee shorthands.
  3207. *
  3208. * @private
  3209. * @param {Array|Object} collection The collection to iterate over.
  3210. * @param {Function} iteratee The function invoked per iteration.
  3211. * @returns {Array} Returns the new mapped array.
  3212. */
  3213. function baseMap(collection, iteratee) {
  3214. var index = -1,
  3215. result = isArrayLike(collection) ? Array(collection.length) : [];
  3216. baseEach(collection, function(value, key, collection) {
  3217. result[++index] = iteratee(value, key, collection);
  3218. });
  3219. return result;
  3220. }
  3221. /**
  3222. * The base implementation of `_.matches` which doesn't clone `source`.
  3223. *
  3224. * @private
  3225. * @param {Object} source The object of property values to match.
  3226. * @returns {Function} Returns the new spec function.
  3227. */
  3228. function baseMatches(source) {
  3229. var matchData = getMatchData(source);
  3230. if (matchData.length == 1 && matchData[0][2]) {
  3231. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3232. }
  3233. return function(object) {
  3234. return object === source || baseIsMatch(object, source, matchData);
  3235. };
  3236. }
  3237. /**
  3238. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3239. *
  3240. * @private
  3241. * @param {string} path The path of the property to get.
  3242. * @param {*} srcValue The value to match.
  3243. * @returns {Function} Returns the new spec function.
  3244. */
  3245. function baseMatchesProperty(path, srcValue) {
  3246. if (isKey(path) && isStrictComparable(srcValue)) {
  3247. return matchesStrictComparable(toKey(path), srcValue);
  3248. }
  3249. return function(object) {
  3250. var objValue = get(object, path);
  3251. return (objValue === undefined && objValue === srcValue)
  3252. ? hasIn(object, path)
  3253. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3254. };
  3255. }
  3256. /**
  3257. * The base implementation of `_.merge` without support for multiple sources.
  3258. *
  3259. * @private
  3260. * @param {Object} object The destination object.
  3261. * @param {Object} source The source object.
  3262. * @param {number} srcIndex The index of `source`.
  3263. * @param {Function} [customizer] The function to customize merged values.
  3264. * @param {Object} [stack] Tracks traversed source values and their merged
  3265. * counterparts.
  3266. */
  3267. function baseMerge(object, source, srcIndex, customizer, stack) {
  3268. if (object === source) {
  3269. return;
  3270. }
  3271. baseFor(source, function(srcValue, key) {
  3272. stack || (stack = new Stack);
  3273. if (isObject(srcValue)) {
  3274. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3275. }
  3276. else {
  3277. var newValue = customizer
  3278. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3279. : undefined;
  3280. if (newValue === undefined) {
  3281. newValue = srcValue;
  3282. }
  3283. assignMergeValue(object, key, newValue);
  3284. }
  3285. }, keysIn);
  3286. }
  3287. /**
  3288. * A specialized version of `baseMerge` for arrays and objects which performs
  3289. * deep merges and tracks traversed objects enabling objects with circular
  3290. * references to be merged.
  3291. *
  3292. * @private
  3293. * @param {Object} object The destination object.
  3294. * @param {Object} source The source object.
  3295. * @param {string} key The key of the value to merge.
  3296. * @param {number} srcIndex The index of `source`.
  3297. * @param {Function} mergeFunc The function to merge values.
  3298. * @param {Function} [customizer] The function to customize assigned values.
  3299. * @param {Object} [stack] Tracks traversed source values and their merged
  3300. * counterparts.
  3301. */
  3302. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3303. var objValue = safeGet(object, key),
  3304. srcValue = safeGet(source, key),
  3305. stacked = stack.get(srcValue);
  3306. if (stacked) {
  3307. assignMergeValue(object, key, stacked);
  3308. return;
  3309. }
  3310. var newValue = customizer
  3311. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3312. : undefined;
  3313. var isCommon = newValue === undefined;
  3314. if (isCommon) {
  3315. var isArr = isArray(srcValue),
  3316. isBuff = !isArr && isBuffer(srcValue),
  3317. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3318. newValue = srcValue;
  3319. if (isArr || isBuff || isTyped) {
  3320. if (isArray(objValue)) {
  3321. newValue = objValue;
  3322. }
  3323. else if (isArrayLikeObject(objValue)) {
  3324. newValue = copyArray(objValue);
  3325. }
  3326. else if (isBuff) {
  3327. isCommon = false;
  3328. newValue = cloneBuffer(srcValue, true);
  3329. }
  3330. else if (isTyped) {
  3331. isCommon = false;
  3332. newValue = cloneTypedArray(srcValue, true);
  3333. }
  3334. else {
  3335. newValue = [];
  3336. }
  3337. }
  3338. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3339. newValue = objValue;
  3340. if (isArguments(objValue)) {
  3341. newValue = toPlainObject(objValue);
  3342. }
  3343. else if (!isObject(objValue) || isFunction(objValue)) {
  3344. newValue = initCloneObject(srcValue);
  3345. }
  3346. }
  3347. else {
  3348. isCommon = false;
  3349. }
  3350. }
  3351. if (isCommon) {
  3352. // Recursively merge objects and arrays (susceptible to call stack limits).
  3353. stack.set(srcValue, newValue);
  3354. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3355. stack['delete'](srcValue);
  3356. }
  3357. assignMergeValue(object, key, newValue);
  3358. }
  3359. /**
  3360. * The base implementation of `_.nth` which doesn't coerce arguments.
  3361. *
  3362. * @private
  3363. * @param {Array} array The array to query.
  3364. * @param {number} n The index of the element to return.
  3365. * @returns {*} Returns the nth element of `array`.
  3366. */
  3367. function baseNth(array, n) {
  3368. var length = array.length;
  3369. if (!length) {
  3370. return;
  3371. }
  3372. n += n < 0 ? length : 0;
  3373. return isIndex(n, length) ? array[n] : undefined;
  3374. }
  3375. /**
  3376. * The base implementation of `_.orderBy` without param guards.
  3377. *
  3378. * @private
  3379. * @param {Array|Object} collection The collection to iterate over.
  3380. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3381. * @param {string[]} orders The sort orders of `iteratees`.
  3382. * @returns {Array} Returns the new sorted array.
  3383. */
  3384. function baseOrderBy(collection, iteratees, orders) {
  3385. var index = -1;
  3386. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3387. var result = baseMap(collection, function(value, key, collection) {
  3388. var criteria = arrayMap(iteratees, function(iteratee) {
  3389. return iteratee(value);
  3390. });
  3391. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3392. });
  3393. return baseSortBy(result, function(object, other) {
  3394. return compareMultiple(object, other, orders);
  3395. });
  3396. }
  3397. /**
  3398. * The base implementation of `_.pick` without support for individual
  3399. * property identifiers.
  3400. *
  3401. * @private
  3402. * @param {Object} object The source object.
  3403. * @param {string[]} paths The property paths to pick.
  3404. * @returns {Object} Returns the new object.
  3405. */
  3406. function basePick(object, paths) {
  3407. return basePickBy(object, paths, function(value, path) {
  3408. return hasIn(object, path);
  3409. });
  3410. }
  3411. /**
  3412. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3413. *
  3414. * @private
  3415. * @param {Object} object The source object.
  3416. * @param {string[]} paths The property paths to pick.
  3417. * @param {Function} predicate The function invoked per property.
  3418. * @returns {Object} Returns the new object.
  3419. */
  3420. function basePickBy(object, paths, predicate) {
  3421. var index = -1,
  3422. length = paths.length,
  3423. result = {};
  3424. while (++index < length) {
  3425. var path = paths[index],
  3426. value = baseGet(object, path);
  3427. if (predicate(value, path)) {
  3428. baseSet(result, castPath(path, object), value);
  3429. }
  3430. }
  3431. return result;
  3432. }
  3433. /**
  3434. * A specialized version of `baseProperty` which supports deep paths.
  3435. *
  3436. * @private
  3437. * @param {Array|string} path The path of the property to get.
  3438. * @returns {Function} Returns the new accessor function.
  3439. */
  3440. function basePropertyDeep(path) {
  3441. return function(object) {
  3442. return baseGet(object, path);
  3443. };
  3444. }
  3445. /**
  3446. * The base implementation of `_.pullAllBy` without support for iteratee
  3447. * shorthands.
  3448. *
  3449. * @private
  3450. * @param {Array} array The array to modify.
  3451. * @param {Array} values The values to remove.
  3452. * @param {Function} [iteratee] The iteratee invoked per element.
  3453. * @param {Function} [comparator] The comparator invoked per element.
  3454. * @returns {Array} Returns `array`.
  3455. */
  3456. function basePullAll(array, values, iteratee, comparator) {
  3457. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3458. index = -1,
  3459. length = values.length,
  3460. seen = array;
  3461. if (array === values) {
  3462. values = copyArray(values);
  3463. }
  3464. if (iteratee) {
  3465. seen = arrayMap(array, baseUnary(iteratee));
  3466. }
  3467. while (++index < length) {
  3468. var fromIndex = 0,
  3469. value = values[index],
  3470. computed = iteratee ? iteratee(value) : value;
  3471. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3472. if (seen !== array) {
  3473. splice.call(seen, fromIndex, 1);
  3474. }
  3475. splice.call(array, fromIndex, 1);
  3476. }
  3477. }
  3478. return array;
  3479. }
  3480. /**
  3481. * The base implementation of `_.pullAt` without support for individual
  3482. * indexes or capturing the removed elements.
  3483. *
  3484. * @private
  3485. * @param {Array} array The array to modify.
  3486. * @param {number[]} indexes The indexes of elements to remove.
  3487. * @returns {Array} Returns `array`.
  3488. */
  3489. function basePullAt(array, indexes) {
  3490. var length = array ? indexes.length : 0,
  3491. lastIndex = length - 1;
  3492. while (length--) {
  3493. var index = indexes[length];
  3494. if (length == lastIndex || index !== previous) {
  3495. var previous = index;
  3496. if (isIndex(index)) {
  3497. splice.call(array, index, 1);
  3498. } else {
  3499. baseUnset(array, index);
  3500. }
  3501. }
  3502. }
  3503. return array;
  3504. }
  3505. /**
  3506. * The base implementation of `_.random` without support for returning
  3507. * floating-point numbers.
  3508. *
  3509. * @private
  3510. * @param {number} lower The lower bound.
  3511. * @param {number} upper The upper bound.
  3512. * @returns {number} Returns the random number.
  3513. */
  3514. function baseRandom(lower, upper) {
  3515. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3516. }
  3517. /**
  3518. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3519. * coerce arguments.
  3520. *
  3521. * @private
  3522. * @param {number} start The start of the range.
  3523. * @param {number} end The end of the range.
  3524. * @param {number} step The value to increment or decrement by.
  3525. * @param {boolean} [fromRight] Specify iterating from right to left.
  3526. * @returns {Array} Returns the range of numbers.
  3527. */
  3528. function baseRange(start, end, step, fromRight) {
  3529. var index = -1,
  3530. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3531. result = Array(length);
  3532. while (length--) {
  3533. result[fromRight ? length : ++index] = start;
  3534. start += step;
  3535. }
  3536. return result;
  3537. }
  3538. /**
  3539. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3540. *
  3541. * @private
  3542. * @param {string} string The string to repeat.
  3543. * @param {number} n The number of times to repeat the string.
  3544. * @returns {string} Returns the repeated string.
  3545. */
  3546. function baseRepeat(string, n) {
  3547. var result = '';
  3548. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3549. return result;
  3550. }
  3551. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3552. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3553. do {
  3554. if (n % 2) {
  3555. result += string;
  3556. }
  3557. n = nativeFloor(n / 2);
  3558. if (n) {
  3559. string += string;
  3560. }
  3561. } while (n);
  3562. return result;
  3563. }
  3564. /**
  3565. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3566. *
  3567. * @private
  3568. * @param {Function} func The function to apply a rest parameter to.
  3569. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3570. * @returns {Function} Returns the new function.
  3571. */
  3572. function baseRest(func, start) {
  3573. return setToString(overRest(func, start, identity), func + '');
  3574. }
  3575. /**
  3576. * The base implementation of `_.sample`.
  3577. *
  3578. * @private
  3579. * @param {Array|Object} collection The collection to sample.
  3580. * @returns {*} Returns the random element.
  3581. */
  3582. function baseSample(collection) {
  3583. return arraySample(values(collection));
  3584. }
  3585. /**
  3586. * The base implementation of `_.sampleSize` without param guards.
  3587. *
  3588. * @private
  3589. * @param {Array|Object} collection The collection to sample.
  3590. * @param {number} n The number of elements to sample.
  3591. * @returns {Array} Returns the random elements.
  3592. */
  3593. function baseSampleSize(collection, n) {
  3594. var array = values(collection);
  3595. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3596. }
  3597. /**
  3598. * The base implementation of `_.set`.
  3599. *
  3600. * @private
  3601. * @param {Object} object The object to modify.
  3602. * @param {Array|string} path The path of the property to set.
  3603. * @param {*} value The value to set.
  3604. * @param {Function} [customizer] The function to customize path creation.
  3605. * @returns {Object} Returns `object`.
  3606. */
  3607. function baseSet(object, path, value, customizer) {
  3608. if (!isObject(object)) {
  3609. return object;
  3610. }
  3611. path = castPath(path, object);
  3612. var index = -1,
  3613. length = path.length,
  3614. lastIndex = length - 1,
  3615. nested = object;
  3616. while (nested != null && ++index < length) {
  3617. var key = toKey(path[index]),
  3618. newValue = value;
  3619. if (index != lastIndex) {
  3620. var objValue = nested[key];
  3621. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3622. if (newValue === undefined) {
  3623. newValue = isObject(objValue)
  3624. ? objValue
  3625. : (isIndex(path[index + 1]) ? [] : {});
  3626. }
  3627. }
  3628. assignValue(nested, key, newValue);
  3629. nested = nested[key];
  3630. }
  3631. return object;
  3632. }
  3633. /**
  3634. * The base implementation of `setData` without support for hot loop shorting.
  3635. *
  3636. * @private
  3637. * @param {Function} func The function to associate metadata with.
  3638. * @param {*} data The metadata.
  3639. * @returns {Function} Returns `func`.
  3640. */
  3641. var baseSetData = !metaMap ? identity : function(func, data) {
  3642. metaMap.set(func, data);
  3643. return func;
  3644. };
  3645. /**
  3646. * The base implementation of `setToString` without support for hot loop shorting.
  3647. *
  3648. * @private
  3649. * @param {Function} func The function to modify.
  3650. * @param {Function} string The `toString` result.
  3651. * @returns {Function} Returns `func`.
  3652. */
  3653. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3654. return defineProperty(func, 'toString', {
  3655. 'configurable': true,
  3656. 'enumerable': false,
  3657. 'value': constant(string),
  3658. 'writable': true
  3659. });
  3660. };
  3661. /**
  3662. * The base implementation of `_.shuffle`.
  3663. *
  3664. * @private
  3665. * @param {Array|Object} collection The collection to shuffle.
  3666. * @returns {Array} Returns the new shuffled array.
  3667. */
  3668. function baseShuffle(collection) {
  3669. return shuffleSelf(values(collection));
  3670. }
  3671. /**
  3672. * The base implementation of `_.slice` without an iteratee call guard.
  3673. *
  3674. * @private
  3675. * @param {Array} array The array to slice.
  3676. * @param {number} [start=0] The start position.
  3677. * @param {number} [end=array.length] The end position.
  3678. * @returns {Array} Returns the slice of `array`.
  3679. */
  3680. function baseSlice(array, start, end) {
  3681. var index = -1,
  3682. length = array.length;
  3683. if (start < 0) {
  3684. start = -start > length ? 0 : (length + start);
  3685. }
  3686. end = end > length ? length : end;
  3687. if (end < 0) {
  3688. end += length;
  3689. }
  3690. length = start > end ? 0 : ((end - start) >>> 0);
  3691. start >>>= 0;
  3692. var result = Array(length);
  3693. while (++index < length) {
  3694. result[index] = array[index + start];
  3695. }
  3696. return result;
  3697. }
  3698. /**
  3699. * The base implementation of `_.some` without support for iteratee shorthands.
  3700. *
  3701. * @private
  3702. * @param {Array|Object} collection The collection to iterate over.
  3703. * @param {Function} predicate The function invoked per iteration.
  3704. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3705. * else `false`.
  3706. */
  3707. function baseSome(collection, predicate) {
  3708. var result;
  3709. baseEach(collection, function(value, index, collection) {
  3710. result = predicate(value, index, collection);
  3711. return !result;
  3712. });
  3713. return !!result;
  3714. }
  3715. /**
  3716. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3717. * performs a binary search of `array` to determine the index at which `value`
  3718. * should be inserted into `array` in order to maintain its sort order.
  3719. *
  3720. * @private
  3721. * @param {Array} array The sorted array to inspect.
  3722. * @param {*} value The value to evaluate.
  3723. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3724. * @returns {number} Returns the index at which `value` should be inserted
  3725. * into `array`.
  3726. */
  3727. function baseSortedIndex(array, value, retHighest) {
  3728. var low = 0,
  3729. high = array == null ? low : array.length;
  3730. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3731. while (low < high) {
  3732. var mid = (low + high) >>> 1,
  3733. computed = array[mid];
  3734. if (computed !== null && !isSymbol(computed) &&
  3735. (retHighest ? (computed <= value) : (computed < value))) {
  3736. low = mid + 1;
  3737. } else {
  3738. high = mid;
  3739. }
  3740. }
  3741. return high;
  3742. }
  3743. return baseSortedIndexBy(array, value, identity, retHighest);
  3744. }
  3745. /**
  3746. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3747. * which invokes `iteratee` for `value` and each element of `array` to compute
  3748. * their sort ranking. The iteratee is invoked with one argument; (value).
  3749. *
  3750. * @private
  3751. * @param {Array} array The sorted array to inspect.
  3752. * @param {*} value The value to evaluate.
  3753. * @param {Function} iteratee The iteratee invoked per element.
  3754. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3755. * @returns {number} Returns the index at which `value` should be inserted
  3756. * into `array`.
  3757. */
  3758. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3759. value = iteratee(value);
  3760. var low = 0,
  3761. high = array == null ? 0 : array.length,
  3762. valIsNaN = value !== value,
  3763. valIsNull = value === null,
  3764. valIsSymbol = isSymbol(value),
  3765. valIsUndefined = value === undefined;
  3766. while (low < high) {
  3767. var mid = nativeFloor((low + high) / 2),
  3768. computed = iteratee(array[mid]),
  3769. othIsDefined = computed !== undefined,
  3770. othIsNull = computed === null,
  3771. othIsReflexive = computed === computed,
  3772. othIsSymbol = isSymbol(computed);
  3773. if (valIsNaN) {
  3774. var setLow = retHighest || othIsReflexive;
  3775. } else if (valIsUndefined) {
  3776. setLow = othIsReflexive && (retHighest || othIsDefined);
  3777. } else if (valIsNull) {
  3778. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3779. } else if (valIsSymbol) {
  3780. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3781. } else if (othIsNull || othIsSymbol) {
  3782. setLow = false;
  3783. } else {
  3784. setLow = retHighest ? (computed <= value) : (computed < value);
  3785. }
  3786. if (setLow) {
  3787. low = mid + 1;
  3788. } else {
  3789. high = mid;
  3790. }
  3791. }
  3792. return nativeMin(high, MAX_ARRAY_INDEX);
  3793. }
  3794. /**
  3795. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3796. * support for iteratee shorthands.
  3797. *
  3798. * @private
  3799. * @param {Array} array The array to inspect.
  3800. * @param {Function} [iteratee] The iteratee invoked per element.
  3801. * @returns {Array} Returns the new duplicate free array.
  3802. */
  3803. function baseSortedUniq(array, iteratee) {
  3804. var index = -1,
  3805. length = array.length,
  3806. resIndex = 0,
  3807. result = [];
  3808. while (++index < length) {
  3809. var value = array[index],
  3810. computed = iteratee ? iteratee(value) : value;
  3811. if (!index || !eq(computed, seen)) {
  3812. var seen = computed;
  3813. result[resIndex++] = value === 0 ? 0 : value;
  3814. }
  3815. }
  3816. return result;
  3817. }
  3818. /**
  3819. * The base implementation of `_.toNumber` which doesn't ensure correct
  3820. * conversions of binary, hexadecimal, or octal string values.
  3821. *
  3822. * @private
  3823. * @param {*} value The value to process.
  3824. * @returns {number} Returns the number.
  3825. */
  3826. function baseToNumber(value) {
  3827. if (typeof value == 'number') {
  3828. return value;
  3829. }
  3830. if (isSymbol(value)) {
  3831. return NAN;
  3832. }
  3833. return +value;
  3834. }
  3835. /**
  3836. * The base implementation of `_.toString` which doesn't convert nullish
  3837. * values to empty strings.
  3838. *
  3839. * @private
  3840. * @param {*} value The value to process.
  3841. * @returns {string} Returns the string.
  3842. */
  3843. function baseToString(value) {
  3844. // Exit early for strings to avoid a performance hit in some environments.
  3845. if (typeof value == 'string') {
  3846. return value;
  3847. }
  3848. if (isArray(value)) {
  3849. // Recursively convert values (susceptible to call stack limits).
  3850. return arrayMap(value, baseToString) + '';
  3851. }
  3852. if (isSymbol(value)) {
  3853. return symbolToString ? symbolToString.call(value) : '';
  3854. }
  3855. var result = (value + '');
  3856. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3857. }
  3858. /**
  3859. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3860. *
  3861. * @private
  3862. * @param {Array} array The array to inspect.
  3863. * @param {Function} [iteratee] The iteratee invoked per element.
  3864. * @param {Function} [comparator] The comparator invoked per element.
  3865. * @returns {Array} Returns the new duplicate free array.
  3866. */
  3867. function baseUniq(array, iteratee, comparator) {
  3868. var index = -1,
  3869. includes = arrayIncludes,
  3870. length = array.length,
  3871. isCommon = true,
  3872. result = [],
  3873. seen = result;
  3874. if (comparator) {
  3875. isCommon = false;
  3876. includes = arrayIncludesWith;
  3877. }
  3878. else if (length >= LARGE_ARRAY_SIZE) {
  3879. var set = iteratee ? null : createSet(array);
  3880. if (set) {
  3881. return setToArray(set);
  3882. }
  3883. isCommon = false;
  3884. includes = cacheHas;
  3885. seen = new SetCache;
  3886. }
  3887. else {
  3888. seen = iteratee ? [] : result;
  3889. }
  3890. outer:
  3891. while (++index < length) {
  3892. var value = array[index],
  3893. computed = iteratee ? iteratee(value) : value;
  3894. value = (comparator || value !== 0) ? value : 0;
  3895. if (isCommon && computed === computed) {
  3896. var seenIndex = seen.length;
  3897. while (seenIndex--) {
  3898. if (seen[seenIndex] === computed) {
  3899. continue outer;
  3900. }
  3901. }
  3902. if (iteratee) {
  3903. seen.push(computed);
  3904. }
  3905. result.push(value);
  3906. }
  3907. else if (!includes(seen, computed, comparator)) {
  3908. if (seen !== result) {
  3909. seen.push(computed);
  3910. }
  3911. result.push(value);
  3912. }
  3913. }
  3914. return result;
  3915. }
  3916. /**
  3917. * The base implementation of `_.unset`.
  3918. *
  3919. * @private
  3920. * @param {Object} object The object to modify.
  3921. * @param {Array|string} path The property path to unset.
  3922. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3923. */
  3924. function baseUnset(object, path) {
  3925. path = castPath(path, object);
  3926. object = parent(object, path);
  3927. return object == null || delete object[toKey(last(path))];
  3928. }
  3929. /**
  3930. * The base implementation of `_.update`.
  3931. *
  3932. * @private
  3933. * @param {Object} object The object to modify.
  3934. * @param {Array|string} path The path of the property to update.
  3935. * @param {Function} updater The function to produce the updated value.
  3936. * @param {Function} [customizer] The function to customize path creation.
  3937. * @returns {Object} Returns `object`.
  3938. */
  3939. function baseUpdate(object, path, updater, customizer) {
  3940. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3941. }
  3942. /**
  3943. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3944. * without support for iteratee shorthands.
  3945. *
  3946. * @private
  3947. * @param {Array} array The array to query.
  3948. * @param {Function} predicate The function invoked per iteration.
  3949. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3950. * @param {boolean} [fromRight] Specify iterating from right to left.
  3951. * @returns {Array} Returns the slice of `array`.
  3952. */
  3953. function baseWhile(array, predicate, isDrop, fromRight) {
  3954. var length = array.length,
  3955. index = fromRight ? length : -1;
  3956. while ((fromRight ? index-- : ++index < length) &&
  3957. predicate(array[index], index, array)) {}
  3958. return isDrop
  3959. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3960. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3961. }
  3962. /**
  3963. * The base implementation of `wrapperValue` which returns the result of
  3964. * performing a sequence of actions on the unwrapped `value`, where each
  3965. * successive action is supplied the return value of the previous.
  3966. *
  3967. * @private
  3968. * @param {*} value The unwrapped value.
  3969. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3970. * @returns {*} Returns the resolved value.
  3971. */
  3972. function baseWrapperValue(value, actions) {
  3973. var result = value;
  3974. if (result instanceof LazyWrapper) {
  3975. result = result.value();
  3976. }
  3977. return arrayReduce(actions, function(result, action) {
  3978. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3979. }, result);
  3980. }
  3981. /**
  3982. * The base implementation of methods like `_.xor`, without support for
  3983. * iteratee shorthands, that accepts an array of arrays to inspect.
  3984. *
  3985. * @private
  3986. * @param {Array} arrays The arrays to inspect.
  3987. * @param {Function} [iteratee] The iteratee invoked per element.
  3988. * @param {Function} [comparator] The comparator invoked per element.
  3989. * @returns {Array} Returns the new array of values.
  3990. */
  3991. function baseXor(arrays, iteratee, comparator) {
  3992. var length = arrays.length;
  3993. if (length < 2) {
  3994. return length ? baseUniq(arrays[0]) : [];
  3995. }
  3996. var index = -1,
  3997. result = Array(length);
  3998. while (++index < length) {
  3999. var array = arrays[index],
  4000. othIndex = -1;
  4001. while (++othIndex < length) {
  4002. if (othIndex != index) {
  4003. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4004. }
  4005. }
  4006. }
  4007. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4008. }
  4009. /**
  4010. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4011. *
  4012. * @private
  4013. * @param {Array} props The property identifiers.
  4014. * @param {Array} values The property values.
  4015. * @param {Function} assignFunc The function to assign values.
  4016. * @returns {Object} Returns the new object.
  4017. */
  4018. function baseZipObject(props, values, assignFunc) {
  4019. var index = -1,
  4020. length = props.length,
  4021. valsLength = values.length,
  4022. result = {};
  4023. while (++index < length) {
  4024. var value = index < valsLength ? values[index] : undefined;
  4025. assignFunc(result, props[index], value);
  4026. }
  4027. return result;
  4028. }
  4029. /**
  4030. * Casts `value` to an empty array if it's not an array like object.
  4031. *
  4032. * @private
  4033. * @param {*} value The value to inspect.
  4034. * @returns {Array|Object} Returns the cast array-like object.
  4035. */
  4036. function castArrayLikeObject(value) {
  4037. return isArrayLikeObject(value) ? value : [];
  4038. }
  4039. /**
  4040. * Casts `value` to `identity` if it's not a function.
  4041. *
  4042. * @private
  4043. * @param {*} value The value to inspect.
  4044. * @returns {Function} Returns cast function.
  4045. */
  4046. function castFunction(value) {
  4047. return typeof value == 'function' ? value : identity;
  4048. }
  4049. /**
  4050. * Casts `value` to a path array if it's not one.
  4051. *
  4052. * @private
  4053. * @param {*} value The value to inspect.
  4054. * @param {Object} [object] The object to query keys on.
  4055. * @returns {Array} Returns the cast property path array.
  4056. */
  4057. function castPath(value, object) {
  4058. if (isArray(value)) {
  4059. return value;
  4060. }
  4061. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4062. }
  4063. /**
  4064. * A `baseRest` alias which can be replaced with `identity` by module
  4065. * replacement plugins.
  4066. *
  4067. * @private
  4068. * @type {Function}
  4069. * @param {Function} func The function to apply a rest parameter to.
  4070. * @returns {Function} Returns the new function.
  4071. */
  4072. var castRest = baseRest;
  4073. /**
  4074. * Casts `array` to a slice if it's needed.
  4075. *
  4076. * @private
  4077. * @param {Array} array The array to inspect.
  4078. * @param {number} start The start position.
  4079. * @param {number} [end=array.length] The end position.
  4080. * @returns {Array} Returns the cast slice.
  4081. */
  4082. function castSlice(array, start, end) {
  4083. var length = array.length;
  4084. end = end === undefined ? length : end;
  4085. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4086. }
  4087. /**
  4088. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4089. *
  4090. * @private
  4091. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4092. */
  4093. var clearTimeout = ctxClearTimeout || function(id) {
  4094. return root.clearTimeout(id);
  4095. };
  4096. /**
  4097. * Creates a clone of `buffer`.
  4098. *
  4099. * @private
  4100. * @param {Buffer} buffer The buffer to clone.
  4101. * @param {boolean} [isDeep] Specify a deep clone.
  4102. * @returns {Buffer} Returns the cloned buffer.
  4103. */
  4104. function cloneBuffer(buffer, isDeep) {
  4105. if (isDeep) {
  4106. return buffer.slice();
  4107. }
  4108. var length = buffer.length,
  4109. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4110. buffer.copy(result);
  4111. return result;
  4112. }
  4113. /**
  4114. * Creates a clone of `arrayBuffer`.
  4115. *
  4116. * @private
  4117. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4118. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4119. */
  4120. function cloneArrayBuffer(arrayBuffer) {
  4121. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4122. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4123. return result;
  4124. }
  4125. /**
  4126. * Creates a clone of `dataView`.
  4127. *
  4128. * @private
  4129. * @param {Object} dataView The data view to clone.
  4130. * @param {boolean} [isDeep] Specify a deep clone.
  4131. * @returns {Object} Returns the cloned data view.
  4132. */
  4133. function cloneDataView(dataView, isDeep) {
  4134. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4135. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4136. }
  4137. /**
  4138. * Creates a clone of `regexp`.
  4139. *
  4140. * @private
  4141. * @param {Object} regexp The regexp to clone.
  4142. * @returns {Object} Returns the cloned regexp.
  4143. */
  4144. function cloneRegExp(regexp) {
  4145. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4146. result.lastIndex = regexp.lastIndex;
  4147. return result;
  4148. }
  4149. /**
  4150. * Creates a clone of the `symbol` object.
  4151. *
  4152. * @private
  4153. * @param {Object} symbol The symbol object to clone.
  4154. * @returns {Object} Returns the cloned symbol object.
  4155. */
  4156. function cloneSymbol(symbol) {
  4157. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4158. }
  4159. /**
  4160. * Creates a clone of `typedArray`.
  4161. *
  4162. * @private
  4163. * @param {Object} typedArray The typed array to clone.
  4164. * @param {boolean} [isDeep] Specify a deep clone.
  4165. * @returns {Object} Returns the cloned typed array.
  4166. */
  4167. function cloneTypedArray(typedArray, isDeep) {
  4168. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4169. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4170. }
  4171. /**
  4172. * Compares values to sort them in ascending order.
  4173. *
  4174. * @private
  4175. * @param {*} value The value to compare.
  4176. * @param {*} other The other value to compare.
  4177. * @returns {number} Returns the sort order indicator for `value`.
  4178. */
  4179. function compareAscending(value, other) {
  4180. if (value !== other) {
  4181. var valIsDefined = value !== undefined,
  4182. valIsNull = value === null,
  4183. valIsReflexive = value === value,
  4184. valIsSymbol = isSymbol(value);
  4185. var othIsDefined = other !== undefined,
  4186. othIsNull = other === null,
  4187. othIsReflexive = other === other,
  4188. othIsSymbol = isSymbol(other);
  4189. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4190. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4191. (valIsNull && othIsDefined && othIsReflexive) ||
  4192. (!valIsDefined && othIsReflexive) ||
  4193. !valIsReflexive) {
  4194. return 1;
  4195. }
  4196. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4197. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4198. (othIsNull && valIsDefined && valIsReflexive) ||
  4199. (!othIsDefined && valIsReflexive) ||
  4200. !othIsReflexive) {
  4201. return -1;
  4202. }
  4203. }
  4204. return 0;
  4205. }
  4206. /**
  4207. * Used by `_.orderBy` to compare multiple properties of a value to another
  4208. * and stable sort them.
  4209. *
  4210. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4211. * specify an order of "desc" for descending or "asc" for ascending sort order
  4212. * of corresponding values.
  4213. *
  4214. * @private
  4215. * @param {Object} object The object to compare.
  4216. * @param {Object} other The other object to compare.
  4217. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4218. * @returns {number} Returns the sort order indicator for `object`.
  4219. */
  4220. function compareMultiple(object, other, orders) {
  4221. var index = -1,
  4222. objCriteria = object.criteria,
  4223. othCriteria = other.criteria,
  4224. length = objCriteria.length,
  4225. ordersLength = orders.length;
  4226. while (++index < length) {
  4227. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4228. if (result) {
  4229. if (index >= ordersLength) {
  4230. return result;
  4231. }
  4232. var order = orders[index];
  4233. return result * (order == 'desc' ? -1 : 1);
  4234. }
  4235. }
  4236. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4237. // that causes it, under certain circumstances, to provide the same value for
  4238. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4239. // for more details.
  4240. //
  4241. // This also ensures a stable sort in V8 and other engines.
  4242. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4243. return object.index - other.index;
  4244. }
  4245. /**
  4246. * Creates an array that is the composition of partially applied arguments,
  4247. * placeholders, and provided arguments into a single array of arguments.
  4248. *
  4249. * @private
  4250. * @param {Array} args The provided arguments.
  4251. * @param {Array} partials The arguments to prepend to those provided.
  4252. * @param {Array} holders The `partials` placeholder indexes.
  4253. * @params {boolean} [isCurried] Specify composing for a curried function.
  4254. * @returns {Array} Returns the new array of composed arguments.
  4255. */
  4256. function composeArgs(args, partials, holders, isCurried) {
  4257. var argsIndex = -1,
  4258. argsLength = args.length,
  4259. holdersLength = holders.length,
  4260. leftIndex = -1,
  4261. leftLength = partials.length,
  4262. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4263. result = Array(leftLength + rangeLength),
  4264. isUncurried = !isCurried;
  4265. while (++leftIndex < leftLength) {
  4266. result[leftIndex] = partials[leftIndex];
  4267. }
  4268. while (++argsIndex < holdersLength) {
  4269. if (isUncurried || argsIndex < argsLength) {
  4270. result[holders[argsIndex]] = args[argsIndex];
  4271. }
  4272. }
  4273. while (rangeLength--) {
  4274. result[leftIndex++] = args[argsIndex++];
  4275. }
  4276. return result;
  4277. }
  4278. /**
  4279. * This function is like `composeArgs` except that the arguments composition
  4280. * is tailored for `_.partialRight`.
  4281. *
  4282. * @private
  4283. * @param {Array} args The provided arguments.
  4284. * @param {Array} partials The arguments to append to those provided.
  4285. * @param {Array} holders The `partials` placeholder indexes.
  4286. * @params {boolean} [isCurried] Specify composing for a curried function.
  4287. * @returns {Array} Returns the new array of composed arguments.
  4288. */
  4289. function composeArgsRight(args, partials, holders, isCurried) {
  4290. var argsIndex = -1,
  4291. argsLength = args.length,
  4292. holdersIndex = -1,
  4293. holdersLength = holders.length,
  4294. rightIndex = -1,
  4295. rightLength = partials.length,
  4296. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4297. result = Array(rangeLength + rightLength),
  4298. isUncurried = !isCurried;
  4299. while (++argsIndex < rangeLength) {
  4300. result[argsIndex] = args[argsIndex];
  4301. }
  4302. var offset = argsIndex;
  4303. while (++rightIndex < rightLength) {
  4304. result[offset + rightIndex] = partials[rightIndex];
  4305. }
  4306. while (++holdersIndex < holdersLength) {
  4307. if (isUncurried || argsIndex < argsLength) {
  4308. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4309. }
  4310. }
  4311. return result;
  4312. }
  4313. /**
  4314. * Copies the values of `source` to `array`.
  4315. *
  4316. * @private
  4317. * @param {Array} source The array to copy values from.
  4318. * @param {Array} [array=[]] The array to copy values to.
  4319. * @returns {Array} Returns `array`.
  4320. */
  4321. function copyArray(source, array) {
  4322. var index = -1,
  4323. length = source.length;
  4324. array || (array = Array(length));
  4325. while (++index < length) {
  4326. array[index] = source[index];
  4327. }
  4328. return array;
  4329. }
  4330. /**
  4331. * Copies properties of `source` to `object`.
  4332. *
  4333. * @private
  4334. * @param {Object} source The object to copy properties from.
  4335. * @param {Array} props The property identifiers to copy.
  4336. * @param {Object} [object={}] The object to copy properties to.
  4337. * @param {Function} [customizer] The function to customize copied values.
  4338. * @returns {Object} Returns `object`.
  4339. */
  4340. function copyObject(source, props, object, customizer) {
  4341. var isNew = !object;
  4342. object || (object = {});
  4343. var index = -1,
  4344. length = props.length;
  4345. while (++index < length) {
  4346. var key = props[index];
  4347. var newValue = customizer
  4348. ? customizer(object[key], source[key], key, object, source)
  4349. : undefined;
  4350. if (newValue === undefined) {
  4351. newValue = source[key];
  4352. }
  4353. if (isNew) {
  4354. baseAssignValue(object, key, newValue);
  4355. } else {
  4356. assignValue(object, key, newValue);
  4357. }
  4358. }
  4359. return object;
  4360. }
  4361. /**
  4362. * Copies own symbols of `source` to `object`.
  4363. *
  4364. * @private
  4365. * @param {Object} source The object to copy symbols from.
  4366. * @param {Object} [object={}] The object to copy symbols to.
  4367. * @returns {Object} Returns `object`.
  4368. */
  4369. function copySymbols(source, object) {
  4370. return copyObject(source, getSymbols(source), object);
  4371. }
  4372. /**
  4373. * Copies own and inherited symbols of `source` to `object`.
  4374. *
  4375. * @private
  4376. * @param {Object} source The object to copy symbols from.
  4377. * @param {Object} [object={}] The object to copy symbols to.
  4378. * @returns {Object} Returns `object`.
  4379. */
  4380. function copySymbolsIn(source, object) {
  4381. return copyObject(source, getSymbolsIn(source), object);
  4382. }
  4383. /**
  4384. * Creates a function like `_.groupBy`.
  4385. *
  4386. * @private
  4387. * @param {Function} setter The function to set accumulator values.
  4388. * @param {Function} [initializer] The accumulator object initializer.
  4389. * @returns {Function} Returns the new aggregator function.
  4390. */
  4391. function createAggregator(setter, initializer) {
  4392. return function(collection, iteratee) {
  4393. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4394. accumulator = initializer ? initializer() : {};
  4395. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4396. };
  4397. }
  4398. /**
  4399. * Creates a function like `_.assign`.
  4400. *
  4401. * @private
  4402. * @param {Function} assigner The function to assign values.
  4403. * @returns {Function} Returns the new assigner function.
  4404. */
  4405. function createAssigner(assigner) {
  4406. return baseRest(function(object, sources) {
  4407. var index = -1,
  4408. length = sources.length,
  4409. customizer = length > 1 ? sources[length - 1] : undefined,
  4410. guard = length > 2 ? sources[2] : undefined;
  4411. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4412. ? (length--, customizer)
  4413. : undefined;
  4414. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4415. customizer = length < 3 ? undefined : customizer;
  4416. length = 1;
  4417. }
  4418. object = Object(object);
  4419. while (++index < length) {
  4420. var source = sources[index];
  4421. if (source) {
  4422. assigner(object, source, index, customizer);
  4423. }
  4424. }
  4425. return object;
  4426. });
  4427. }
  4428. /**
  4429. * Creates a `baseEach` or `baseEachRight` function.
  4430. *
  4431. * @private
  4432. * @param {Function} eachFunc The function to iterate over a collection.
  4433. * @param {boolean} [fromRight] Specify iterating from right to left.
  4434. * @returns {Function} Returns the new base function.
  4435. */
  4436. function createBaseEach(eachFunc, fromRight) {
  4437. return function(collection, iteratee) {
  4438. if (collection == null) {
  4439. return collection;
  4440. }
  4441. if (!isArrayLike(collection)) {
  4442. return eachFunc(collection, iteratee);
  4443. }
  4444. var length = collection.length,
  4445. index = fromRight ? length : -1,
  4446. iterable = Object(collection);
  4447. while ((fromRight ? index-- : ++index < length)) {
  4448. if (iteratee(iterable[index], index, iterable) === false) {
  4449. break;
  4450. }
  4451. }
  4452. return collection;
  4453. };
  4454. }
  4455. /**
  4456. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4457. *
  4458. * @private
  4459. * @param {boolean} [fromRight] Specify iterating from right to left.
  4460. * @returns {Function} Returns the new base function.
  4461. */
  4462. function createBaseFor(fromRight) {
  4463. return function(object, iteratee, keysFunc) {
  4464. var index = -1,
  4465. iterable = Object(object),
  4466. props = keysFunc(object),
  4467. length = props.length;
  4468. while (length--) {
  4469. var key = props[fromRight ? length : ++index];
  4470. if (iteratee(iterable[key], key, iterable) === false) {
  4471. break;
  4472. }
  4473. }
  4474. return object;
  4475. };
  4476. }
  4477. /**
  4478. * Creates a function that wraps `func` to invoke it with the optional `this`
  4479. * binding of `thisArg`.
  4480. *
  4481. * @private
  4482. * @param {Function} func The function to wrap.
  4483. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4484. * @param {*} [thisArg] The `this` binding of `func`.
  4485. * @returns {Function} Returns the new wrapped function.
  4486. */
  4487. function createBind(func, bitmask, thisArg) {
  4488. var isBind = bitmask & WRAP_BIND_FLAG,
  4489. Ctor = createCtor(func);
  4490. function wrapper() {
  4491. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4492. return fn.apply(isBind ? thisArg : this, arguments);
  4493. }
  4494. return wrapper;
  4495. }
  4496. /**
  4497. * Creates a function like `_.lowerFirst`.
  4498. *
  4499. * @private
  4500. * @param {string} methodName The name of the `String` case method to use.
  4501. * @returns {Function} Returns the new case function.
  4502. */
  4503. function createCaseFirst(methodName) {
  4504. return function(string) {
  4505. string = toString(string);
  4506. var strSymbols = hasUnicode(string)
  4507. ? stringToArray(string)
  4508. : undefined;
  4509. var chr = strSymbols
  4510. ? strSymbols[0]
  4511. : string.charAt(0);
  4512. var trailing = strSymbols
  4513. ? castSlice(strSymbols, 1).join('')
  4514. : string.slice(1);
  4515. return chr[methodName]() + trailing;
  4516. };
  4517. }
  4518. /**
  4519. * Creates a function like `_.camelCase`.
  4520. *
  4521. * @private
  4522. * @param {Function} callback The function to combine each word.
  4523. * @returns {Function} Returns the new compounder function.
  4524. */
  4525. function createCompounder(callback) {
  4526. return function(string) {
  4527. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4528. };
  4529. }
  4530. /**
  4531. * Creates a function that produces an instance of `Ctor` regardless of
  4532. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4533. *
  4534. * @private
  4535. * @param {Function} Ctor The constructor to wrap.
  4536. * @returns {Function} Returns the new wrapped function.
  4537. */
  4538. function createCtor(Ctor) {
  4539. return function() {
  4540. // Use a `switch` statement to work with class constructors. See
  4541. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4542. // for more details.
  4543. var args = arguments;
  4544. switch (args.length) {
  4545. case 0: return new Ctor;
  4546. case 1: return new Ctor(args[0]);
  4547. case 2: return new Ctor(args[0], args[1]);
  4548. case 3: return new Ctor(args[0], args[1], args[2]);
  4549. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4550. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4551. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4552. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4553. }
  4554. var thisBinding = baseCreate(Ctor.prototype),
  4555. result = Ctor.apply(thisBinding, args);
  4556. // Mimic the constructor's `return` behavior.
  4557. // See https://es5.github.io/#x13.2.2 for more details.
  4558. return isObject(result) ? result : thisBinding;
  4559. };
  4560. }
  4561. /**
  4562. * Creates a function that wraps `func` to enable currying.
  4563. *
  4564. * @private
  4565. * @param {Function} func The function to wrap.
  4566. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4567. * @param {number} arity The arity of `func`.
  4568. * @returns {Function} Returns the new wrapped function.
  4569. */
  4570. function createCurry(func, bitmask, arity) {
  4571. var Ctor = createCtor(func);
  4572. function wrapper() {
  4573. var length = arguments.length,
  4574. args = Array(length),
  4575. index = length,
  4576. placeholder = getHolder(wrapper);
  4577. while (index--) {
  4578. args[index] = arguments[index];
  4579. }
  4580. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4581. ? []
  4582. : replaceHolders(args, placeholder);
  4583. length -= holders.length;
  4584. if (length < arity) {
  4585. return createRecurry(
  4586. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4587. args, holders, undefined, undefined, arity - length);
  4588. }
  4589. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4590. return apply(fn, this, args);
  4591. }
  4592. return wrapper;
  4593. }
  4594. /**
  4595. * Creates a `_.find` or `_.findLast` function.
  4596. *
  4597. * @private
  4598. * @param {Function} findIndexFunc The function to find the collection index.
  4599. * @returns {Function} Returns the new find function.
  4600. */
  4601. function createFind(findIndexFunc) {
  4602. return function(collection, predicate, fromIndex) {
  4603. var iterable = Object(collection);
  4604. if (!isArrayLike(collection)) {
  4605. var iteratee = getIteratee(predicate, 3);
  4606. collection = keys(collection);
  4607. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4608. }
  4609. var index = findIndexFunc(collection, predicate, fromIndex);
  4610. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4611. };
  4612. }
  4613. /**
  4614. * Creates a `_.flow` or `_.flowRight` function.
  4615. *
  4616. * @private
  4617. * @param {boolean} [fromRight] Specify iterating from right to left.
  4618. * @returns {Function} Returns the new flow function.
  4619. */
  4620. function createFlow(fromRight) {
  4621. return flatRest(function(funcs) {
  4622. var length = funcs.length,
  4623. index = length,
  4624. prereq = LodashWrapper.prototype.thru;
  4625. if (fromRight) {
  4626. funcs.reverse();
  4627. }
  4628. while (index--) {
  4629. var func = funcs[index];
  4630. if (typeof func != 'function') {
  4631. throw new TypeError(FUNC_ERROR_TEXT);
  4632. }
  4633. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4634. var wrapper = new LodashWrapper([], true);
  4635. }
  4636. }
  4637. index = wrapper ? index : length;
  4638. while (++index < length) {
  4639. func = funcs[index];
  4640. var funcName = getFuncName(func),
  4641. data = funcName == 'wrapper' ? getData(func) : undefined;
  4642. if (data && isLaziable(data[0]) &&
  4643. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4644. !data[4].length && data[9] == 1
  4645. ) {
  4646. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4647. } else {
  4648. wrapper = (func.length == 1 && isLaziable(func))
  4649. ? wrapper[funcName]()
  4650. : wrapper.thru(func);
  4651. }
  4652. }
  4653. return function() {
  4654. var args = arguments,
  4655. value = args[0];
  4656. if (wrapper && args.length == 1 && isArray(value)) {
  4657. return wrapper.plant(value).value();
  4658. }
  4659. var index = 0,
  4660. result = length ? funcs[index].apply(this, args) : value;
  4661. while (++index < length) {
  4662. result = funcs[index].call(this, result);
  4663. }
  4664. return result;
  4665. };
  4666. });
  4667. }
  4668. /**
  4669. * Creates a function that wraps `func` to invoke it with optional `this`
  4670. * binding of `thisArg`, partial application, and currying.
  4671. *
  4672. * @private
  4673. * @param {Function|string} func The function or method name to wrap.
  4674. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4675. * @param {*} [thisArg] The `this` binding of `func`.
  4676. * @param {Array} [partials] The arguments to prepend to those provided to
  4677. * the new function.
  4678. * @param {Array} [holders] The `partials` placeholder indexes.
  4679. * @param {Array} [partialsRight] The arguments to append to those provided
  4680. * to the new function.
  4681. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4682. * @param {Array} [argPos] The argument positions of the new function.
  4683. * @param {number} [ary] The arity cap of `func`.
  4684. * @param {number} [arity] The arity of `func`.
  4685. * @returns {Function} Returns the new wrapped function.
  4686. */
  4687. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4688. var isAry = bitmask & WRAP_ARY_FLAG,
  4689. isBind = bitmask & WRAP_BIND_FLAG,
  4690. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4691. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4692. isFlip = bitmask & WRAP_FLIP_FLAG,
  4693. Ctor = isBindKey ? undefined : createCtor(func);
  4694. function wrapper() {
  4695. var length = arguments.length,
  4696. args = Array(length),
  4697. index = length;
  4698. while (index--) {
  4699. args[index] = arguments[index];
  4700. }
  4701. if (isCurried) {
  4702. var placeholder = getHolder(wrapper),
  4703. holdersCount = countHolders(args, placeholder);
  4704. }
  4705. if (partials) {
  4706. args = composeArgs(args, partials, holders, isCurried);
  4707. }
  4708. if (partialsRight) {
  4709. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4710. }
  4711. length -= holdersCount;
  4712. if (isCurried && length < arity) {
  4713. var newHolders = replaceHolders(args, placeholder);
  4714. return createRecurry(
  4715. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4716. args, newHolders, argPos, ary, arity - length
  4717. );
  4718. }
  4719. var thisBinding = isBind ? thisArg : this,
  4720. fn = isBindKey ? thisBinding[func] : func;
  4721. length = args.length;
  4722. if (argPos) {
  4723. args = reorder(args, argPos);
  4724. } else if (isFlip && length > 1) {
  4725. args.reverse();
  4726. }
  4727. if (isAry && ary < length) {
  4728. args.length = ary;
  4729. }
  4730. if (this && this !== root && this instanceof wrapper) {
  4731. fn = Ctor || createCtor(fn);
  4732. }
  4733. return fn.apply(thisBinding, args);
  4734. }
  4735. return wrapper;
  4736. }
  4737. /**
  4738. * Creates a function like `_.invertBy`.
  4739. *
  4740. * @private
  4741. * @param {Function} setter The function to set accumulator values.
  4742. * @param {Function} toIteratee The function to resolve iteratees.
  4743. * @returns {Function} Returns the new inverter function.
  4744. */
  4745. function createInverter(setter, toIteratee) {
  4746. return function(object, iteratee) {
  4747. return baseInverter(object, setter, toIteratee(iteratee), {});
  4748. };
  4749. }
  4750. /**
  4751. * Creates a function that performs a mathematical operation on two values.
  4752. *
  4753. * @private
  4754. * @param {Function} operator The function to perform the operation.
  4755. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4756. * @returns {Function} Returns the new mathematical operation function.
  4757. */
  4758. function createMathOperation(operator, defaultValue) {
  4759. return function(value, other) {
  4760. var result;
  4761. if (value === undefined && other === undefined) {
  4762. return defaultValue;
  4763. }
  4764. if (value !== undefined) {
  4765. result = value;
  4766. }
  4767. if (other !== undefined) {
  4768. if (result === undefined) {
  4769. return other;
  4770. }
  4771. if (typeof value == 'string' || typeof other == 'string') {
  4772. value = baseToString(value);
  4773. other = baseToString(other);
  4774. } else {
  4775. value = baseToNumber(value);
  4776. other = baseToNumber(other);
  4777. }
  4778. result = operator(value, other);
  4779. }
  4780. return result;
  4781. };
  4782. }
  4783. /**
  4784. * Creates a function like `_.over`.
  4785. *
  4786. * @private
  4787. * @param {Function} arrayFunc The function to iterate over iteratees.
  4788. * @returns {Function} Returns the new over function.
  4789. */
  4790. function createOver(arrayFunc) {
  4791. return flatRest(function(iteratees) {
  4792. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4793. return baseRest(function(args) {
  4794. var thisArg = this;
  4795. return arrayFunc(iteratees, function(iteratee) {
  4796. return apply(iteratee, thisArg, args);
  4797. });
  4798. });
  4799. });
  4800. }
  4801. /**
  4802. * Creates the padding for `string` based on `length`. The `chars` string
  4803. * is truncated if the number of characters exceeds `length`.
  4804. *
  4805. * @private
  4806. * @param {number} length The padding length.
  4807. * @param {string} [chars=' '] The string used as padding.
  4808. * @returns {string} Returns the padding for `string`.
  4809. */
  4810. function createPadding(length, chars) {
  4811. chars = chars === undefined ? ' ' : baseToString(chars);
  4812. var charsLength = chars.length;
  4813. if (charsLength < 2) {
  4814. return charsLength ? baseRepeat(chars, length) : chars;
  4815. }
  4816. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4817. return hasUnicode(chars)
  4818. ? castSlice(stringToArray(result), 0, length).join('')
  4819. : result.slice(0, length);
  4820. }
  4821. /**
  4822. * Creates a function that wraps `func` to invoke it with the `this` binding
  4823. * of `thisArg` and `partials` prepended to the arguments it receives.
  4824. *
  4825. * @private
  4826. * @param {Function} func The function to wrap.
  4827. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4828. * @param {*} thisArg The `this` binding of `func`.
  4829. * @param {Array} partials The arguments to prepend to those provided to
  4830. * the new function.
  4831. * @returns {Function} Returns the new wrapped function.
  4832. */
  4833. function createPartial(func, bitmask, thisArg, partials) {
  4834. var isBind = bitmask & WRAP_BIND_FLAG,
  4835. Ctor = createCtor(func);
  4836. function wrapper() {
  4837. var argsIndex = -1,
  4838. argsLength = arguments.length,
  4839. leftIndex = -1,
  4840. leftLength = partials.length,
  4841. args = Array(leftLength + argsLength),
  4842. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4843. while (++leftIndex < leftLength) {
  4844. args[leftIndex] = partials[leftIndex];
  4845. }
  4846. while (argsLength--) {
  4847. args[leftIndex++] = arguments[++argsIndex];
  4848. }
  4849. return apply(fn, isBind ? thisArg : this, args);
  4850. }
  4851. return wrapper;
  4852. }
  4853. /**
  4854. * Creates a `_.range` or `_.rangeRight` function.
  4855. *
  4856. * @private
  4857. * @param {boolean} [fromRight] Specify iterating from right to left.
  4858. * @returns {Function} Returns the new range function.
  4859. */
  4860. function createRange(fromRight) {
  4861. return function(start, end, step) {
  4862. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4863. end = step = undefined;
  4864. }
  4865. // Ensure the sign of `-0` is preserved.
  4866. start = toFinite(start);
  4867. if (end === undefined) {
  4868. end = start;
  4869. start = 0;
  4870. } else {
  4871. end = toFinite(end);
  4872. }
  4873. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4874. return baseRange(start, end, step, fromRight);
  4875. };
  4876. }
  4877. /**
  4878. * Creates a function that performs a relational operation on two values.
  4879. *
  4880. * @private
  4881. * @param {Function} operator The function to perform the operation.
  4882. * @returns {Function} Returns the new relational operation function.
  4883. */
  4884. function createRelationalOperation(operator) {
  4885. return function(value, other) {
  4886. if (!(typeof value == 'string' && typeof other == 'string')) {
  4887. value = toNumber(value);
  4888. other = toNumber(other);
  4889. }
  4890. return operator(value, other);
  4891. };
  4892. }
  4893. /**
  4894. * Creates a function that wraps `func` to continue currying.
  4895. *
  4896. * @private
  4897. * @param {Function} func The function to wrap.
  4898. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4899. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4900. * @param {*} placeholder The placeholder value.
  4901. * @param {*} [thisArg] The `this` binding of `func`.
  4902. * @param {Array} [partials] The arguments to prepend to those provided to
  4903. * the new function.
  4904. * @param {Array} [holders] The `partials` placeholder indexes.
  4905. * @param {Array} [argPos] The argument positions of the new function.
  4906. * @param {number} [ary] The arity cap of `func`.
  4907. * @param {number} [arity] The arity of `func`.
  4908. * @returns {Function} Returns the new wrapped function.
  4909. */
  4910. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4911. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4912. newHolders = isCurry ? holders : undefined,
  4913. newHoldersRight = isCurry ? undefined : holders,
  4914. newPartials = isCurry ? partials : undefined,
  4915. newPartialsRight = isCurry ? undefined : partials;
  4916. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4917. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4918. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4919. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4920. }
  4921. var newData = [
  4922. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4923. newHoldersRight, argPos, ary, arity
  4924. ];
  4925. var result = wrapFunc.apply(undefined, newData);
  4926. if (isLaziable(func)) {
  4927. setData(result, newData);
  4928. }
  4929. result.placeholder = placeholder;
  4930. return setWrapToString(result, func, bitmask);
  4931. }
  4932. /**
  4933. * Creates a function like `_.round`.
  4934. *
  4935. * @private
  4936. * @param {string} methodName The name of the `Math` method to use when rounding.
  4937. * @returns {Function} Returns the new round function.
  4938. */
  4939. function createRound(methodName) {
  4940. var func = Math[methodName];
  4941. return function(number, precision) {
  4942. number = toNumber(number);
  4943. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4944. if (precision && nativeIsFinite(number)) {
  4945. // Shift with exponential notation to avoid floating-point issues.
  4946. // See [MDN](https://mdn.io/round#Examples) for more details.
  4947. var pair = (toString(number) + 'e').split('e'),
  4948. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4949. pair = (toString(value) + 'e').split('e');
  4950. return +(pair[0] + 'e' + (+pair[1] - precision));
  4951. }
  4952. return func(number);
  4953. };
  4954. }
  4955. /**
  4956. * Creates a set object of `values`.
  4957. *
  4958. * @private
  4959. * @param {Array} values The values to add to the set.
  4960. * @returns {Object} Returns the new set.
  4961. */
  4962. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4963. return new Set(values);
  4964. };
  4965. /**
  4966. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4967. *
  4968. * @private
  4969. * @param {Function} keysFunc The function to get the keys of a given object.
  4970. * @returns {Function} Returns the new pairs function.
  4971. */
  4972. function createToPairs(keysFunc) {
  4973. return function(object) {
  4974. var tag = getTag(object);
  4975. if (tag == mapTag) {
  4976. return mapToArray(object);
  4977. }
  4978. if (tag == setTag) {
  4979. return setToPairs(object);
  4980. }
  4981. return baseToPairs(object, keysFunc(object));
  4982. };
  4983. }
  4984. /**
  4985. * Creates a function that either curries or invokes `func` with optional
  4986. * `this` binding and partially applied arguments.
  4987. *
  4988. * @private
  4989. * @param {Function|string} func The function or method name to wrap.
  4990. * @param {number} bitmask The bitmask flags.
  4991. * 1 - `_.bind`
  4992. * 2 - `_.bindKey`
  4993. * 4 - `_.curry` or `_.curryRight` of a bound function
  4994. * 8 - `_.curry`
  4995. * 16 - `_.curryRight`
  4996. * 32 - `_.partial`
  4997. * 64 - `_.partialRight`
  4998. * 128 - `_.rearg`
  4999. * 256 - `_.ary`
  5000. * 512 - `_.flip`
  5001. * @param {*} [thisArg] The `this` binding of `func`.
  5002. * @param {Array} [partials] The arguments to be partially applied.
  5003. * @param {Array} [holders] The `partials` placeholder indexes.
  5004. * @param {Array} [argPos] The argument positions of the new function.
  5005. * @param {number} [ary] The arity cap of `func`.
  5006. * @param {number} [arity] The arity of `func`.
  5007. * @returns {Function} Returns the new wrapped function.
  5008. */
  5009. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5010. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5011. if (!isBindKey && typeof func != 'function') {
  5012. throw new TypeError(FUNC_ERROR_TEXT);
  5013. }
  5014. var length = partials ? partials.length : 0;
  5015. if (!length) {
  5016. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5017. partials = holders = undefined;
  5018. }
  5019. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5020. arity = arity === undefined ? arity : toInteger(arity);
  5021. length -= holders ? holders.length : 0;
  5022. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5023. var partialsRight = partials,
  5024. holdersRight = holders;
  5025. partials = holders = undefined;
  5026. }
  5027. var data = isBindKey ? undefined : getData(func);
  5028. var newData = [
  5029. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5030. argPos, ary, arity
  5031. ];
  5032. if (data) {
  5033. mergeData(newData, data);
  5034. }
  5035. func = newData[0];
  5036. bitmask = newData[1];
  5037. thisArg = newData[2];
  5038. partials = newData[3];
  5039. holders = newData[4];
  5040. arity = newData[9] = newData[9] === undefined
  5041. ? (isBindKey ? 0 : func.length)
  5042. : nativeMax(newData[9] - length, 0);
  5043. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5044. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5045. }
  5046. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5047. var result = createBind(func, bitmask, thisArg);
  5048. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5049. result = createCurry(func, bitmask, arity);
  5050. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5051. result = createPartial(func, bitmask, thisArg, partials);
  5052. } else {
  5053. result = createHybrid.apply(undefined, newData);
  5054. }
  5055. var setter = data ? baseSetData : setData;
  5056. return setWrapToString(setter(result, newData), func, bitmask);
  5057. }
  5058. /**
  5059. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5060. * of source objects to the destination object for all destination properties
  5061. * that resolve to `undefined`.
  5062. *
  5063. * @private
  5064. * @param {*} objValue The destination value.
  5065. * @param {*} srcValue The source value.
  5066. * @param {string} key The key of the property to assign.
  5067. * @param {Object} object The parent object of `objValue`.
  5068. * @returns {*} Returns the value to assign.
  5069. */
  5070. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5071. if (objValue === undefined ||
  5072. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5073. return srcValue;
  5074. }
  5075. return objValue;
  5076. }
  5077. /**
  5078. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5079. * objects into destination objects that are passed thru.
  5080. *
  5081. * @private
  5082. * @param {*} objValue The destination value.
  5083. * @param {*} srcValue The source value.
  5084. * @param {string} key The key of the property to merge.
  5085. * @param {Object} object The parent object of `objValue`.
  5086. * @param {Object} source The parent object of `srcValue`.
  5087. * @param {Object} [stack] Tracks traversed source values and their merged
  5088. * counterparts.
  5089. * @returns {*} Returns the value to assign.
  5090. */
  5091. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5092. if (isObject(objValue) && isObject(srcValue)) {
  5093. // Recursively merge objects and arrays (susceptible to call stack limits).
  5094. stack.set(srcValue, objValue);
  5095. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5096. stack['delete'](srcValue);
  5097. }
  5098. return objValue;
  5099. }
  5100. /**
  5101. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5102. * objects.
  5103. *
  5104. * @private
  5105. * @param {*} value The value to inspect.
  5106. * @param {string} key The key of the property to inspect.
  5107. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5108. */
  5109. function customOmitClone(value) {
  5110. return isPlainObject(value) ? undefined : value;
  5111. }
  5112. /**
  5113. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5114. * partial deep comparisons.
  5115. *
  5116. * @private
  5117. * @param {Array} array The array to compare.
  5118. * @param {Array} other The other array to compare.
  5119. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5120. * @param {Function} customizer The function to customize comparisons.
  5121. * @param {Function} equalFunc The function to determine equivalents of values.
  5122. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5123. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5124. */
  5125. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5126. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5127. arrLength = array.length,
  5128. othLength = other.length;
  5129. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5130. return false;
  5131. }
  5132. // Assume cyclic values are equal.
  5133. var stacked = stack.get(array);
  5134. if (stacked && stack.get(other)) {
  5135. return stacked == other;
  5136. }
  5137. var index = -1,
  5138. result = true,
  5139. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5140. stack.set(array, other);
  5141. stack.set(other, array);
  5142. // Ignore non-index properties.
  5143. while (++index < arrLength) {
  5144. var arrValue = array[index],
  5145. othValue = other[index];
  5146. if (customizer) {
  5147. var compared = isPartial
  5148. ? customizer(othValue, arrValue, index, other, array, stack)
  5149. : customizer(arrValue, othValue, index, array, other, stack);
  5150. }
  5151. if (compared !== undefined) {
  5152. if (compared) {
  5153. continue;
  5154. }
  5155. result = false;
  5156. break;
  5157. }
  5158. // Recursively compare arrays (susceptible to call stack limits).
  5159. if (seen) {
  5160. if (!arraySome(other, function(othValue, othIndex) {
  5161. if (!cacheHas(seen, othIndex) &&
  5162. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5163. return seen.push(othIndex);
  5164. }
  5165. })) {
  5166. result = false;
  5167. break;
  5168. }
  5169. } else if (!(
  5170. arrValue === othValue ||
  5171. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5172. )) {
  5173. result = false;
  5174. break;
  5175. }
  5176. }
  5177. stack['delete'](array);
  5178. stack['delete'](other);
  5179. return result;
  5180. }
  5181. /**
  5182. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5183. * the same `toStringTag`.
  5184. *
  5185. * **Note:** This function only supports comparing values with tags of
  5186. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5187. *
  5188. * @private
  5189. * @param {Object} object The object to compare.
  5190. * @param {Object} other The other object to compare.
  5191. * @param {string} tag The `toStringTag` of the objects to compare.
  5192. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5193. * @param {Function} customizer The function to customize comparisons.
  5194. * @param {Function} equalFunc The function to determine equivalents of values.
  5195. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5196. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5197. */
  5198. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5199. switch (tag) {
  5200. case dataViewTag:
  5201. if ((object.byteLength != other.byteLength) ||
  5202. (object.byteOffset != other.byteOffset)) {
  5203. return false;
  5204. }
  5205. object = object.buffer;
  5206. other = other.buffer;
  5207. case arrayBufferTag:
  5208. if ((object.byteLength != other.byteLength) ||
  5209. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5210. return false;
  5211. }
  5212. return true;
  5213. case boolTag:
  5214. case dateTag:
  5215. case numberTag:
  5216. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5217. // Invalid dates are coerced to `NaN`.
  5218. return eq(+object, +other);
  5219. case errorTag:
  5220. return object.name == other.name && object.message == other.message;
  5221. case regexpTag:
  5222. case stringTag:
  5223. // Coerce regexes to strings and treat strings, primitives and objects,
  5224. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5225. // for more details.
  5226. return object == (other + '');
  5227. case mapTag:
  5228. var convert = mapToArray;
  5229. case setTag:
  5230. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5231. convert || (convert = setToArray);
  5232. if (object.size != other.size && !isPartial) {
  5233. return false;
  5234. }
  5235. // Assume cyclic values are equal.
  5236. var stacked = stack.get(object);
  5237. if (stacked) {
  5238. return stacked == other;
  5239. }
  5240. bitmask |= COMPARE_UNORDERED_FLAG;
  5241. // Recursively compare objects (susceptible to call stack limits).
  5242. stack.set(object, other);
  5243. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5244. stack['delete'](object);
  5245. return result;
  5246. case symbolTag:
  5247. if (symbolValueOf) {
  5248. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5249. }
  5250. }
  5251. return false;
  5252. }
  5253. /**
  5254. * A specialized version of `baseIsEqualDeep` for objects with support for
  5255. * partial deep comparisons.
  5256. *
  5257. * @private
  5258. * @param {Object} object The object to compare.
  5259. * @param {Object} other The other object to compare.
  5260. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5261. * @param {Function} customizer The function to customize comparisons.
  5262. * @param {Function} equalFunc The function to determine equivalents of values.
  5263. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5264. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5265. */
  5266. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5267. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5268. objProps = getAllKeys(object),
  5269. objLength = objProps.length,
  5270. othProps = getAllKeys(other),
  5271. othLength = othProps.length;
  5272. if (objLength != othLength && !isPartial) {
  5273. return false;
  5274. }
  5275. var index = objLength;
  5276. while (index--) {
  5277. var key = objProps[index];
  5278. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5279. return false;
  5280. }
  5281. }
  5282. // Assume cyclic values are equal.
  5283. var stacked = stack.get(object);
  5284. if (stacked && stack.get(other)) {
  5285. return stacked == other;
  5286. }
  5287. var result = true;
  5288. stack.set(object, other);
  5289. stack.set(other, object);
  5290. var skipCtor = isPartial;
  5291. while (++index < objLength) {
  5292. key = objProps[index];
  5293. var objValue = object[key],
  5294. othValue = other[key];
  5295. if (customizer) {
  5296. var compared = isPartial
  5297. ? customizer(othValue, objValue, key, other, object, stack)
  5298. : customizer(objValue, othValue, key, object, other, stack);
  5299. }
  5300. // Recursively compare objects (susceptible to call stack limits).
  5301. if (!(compared === undefined
  5302. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5303. : compared
  5304. )) {
  5305. result = false;
  5306. break;
  5307. }
  5308. skipCtor || (skipCtor = key == 'constructor');
  5309. }
  5310. if (result && !skipCtor) {
  5311. var objCtor = object.constructor,
  5312. othCtor = other.constructor;
  5313. // Non `Object` object instances with different constructors are not equal.
  5314. if (objCtor != othCtor &&
  5315. ('constructor' in object && 'constructor' in other) &&
  5316. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5317. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5318. result = false;
  5319. }
  5320. }
  5321. stack['delete'](object);
  5322. stack['delete'](other);
  5323. return result;
  5324. }
  5325. /**
  5326. * A specialized version of `baseRest` which flattens the rest array.
  5327. *
  5328. * @private
  5329. * @param {Function} func The function to apply a rest parameter to.
  5330. * @returns {Function} Returns the new function.
  5331. */
  5332. function flatRest(func) {
  5333. return setToString(overRest(func, undefined, flatten), func + '');
  5334. }
  5335. /**
  5336. * Creates an array of own enumerable property names and symbols of `object`.
  5337. *
  5338. * @private
  5339. * @param {Object} object The object to query.
  5340. * @returns {Array} Returns the array of property names and symbols.
  5341. */
  5342. function getAllKeys(object) {
  5343. return baseGetAllKeys(object, keys, getSymbols);
  5344. }
  5345. /**
  5346. * Creates an array of own and inherited enumerable property names and
  5347. * symbols of `object`.
  5348. *
  5349. * @private
  5350. * @param {Object} object The object to query.
  5351. * @returns {Array} Returns the array of property names and symbols.
  5352. */
  5353. function getAllKeysIn(object) {
  5354. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5355. }
  5356. /**
  5357. * Gets metadata for `func`.
  5358. *
  5359. * @private
  5360. * @param {Function} func The function to query.
  5361. * @returns {*} Returns the metadata for `func`.
  5362. */
  5363. var getData = !metaMap ? noop : function(func) {
  5364. return metaMap.get(func);
  5365. };
  5366. /**
  5367. * Gets the name of `func`.
  5368. *
  5369. * @private
  5370. * @param {Function} func The function to query.
  5371. * @returns {string} Returns the function name.
  5372. */
  5373. function getFuncName(func) {
  5374. var result = (func.name + ''),
  5375. array = realNames[result],
  5376. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5377. while (length--) {
  5378. var data = array[length],
  5379. otherFunc = data.func;
  5380. if (otherFunc == null || otherFunc == func) {
  5381. return data.name;
  5382. }
  5383. }
  5384. return result;
  5385. }
  5386. /**
  5387. * Gets the argument placeholder value for `func`.
  5388. *
  5389. * @private
  5390. * @param {Function} func The function to inspect.
  5391. * @returns {*} Returns the placeholder value.
  5392. */
  5393. function getHolder(func) {
  5394. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5395. return object.placeholder;
  5396. }
  5397. /**
  5398. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5399. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5400. * If arguments are provided, the chosen function is invoked with them and
  5401. * its result is returned.
  5402. *
  5403. * @private
  5404. * @param {*} [value] The value to convert to an iteratee.
  5405. * @param {number} [arity] The arity of the created iteratee.
  5406. * @returns {Function} Returns the chosen function or its result.
  5407. */
  5408. function getIteratee() {
  5409. var result = lodash.iteratee || iteratee;
  5410. result = result === iteratee ? baseIteratee : result;
  5411. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5412. }
  5413. /**
  5414. * Gets the data for `map`.
  5415. *
  5416. * @private
  5417. * @param {Object} map The map to query.
  5418. * @param {string} key The reference key.
  5419. * @returns {*} Returns the map data.
  5420. */
  5421. function getMapData(map, key) {
  5422. var data = map.__data__;
  5423. return isKeyable(key)
  5424. ? data[typeof key == 'string' ? 'string' : 'hash']
  5425. : data.map;
  5426. }
  5427. /**
  5428. * Gets the property names, values, and compare flags of `object`.
  5429. *
  5430. * @private
  5431. * @param {Object} object The object to query.
  5432. * @returns {Array} Returns the match data of `object`.
  5433. */
  5434. function getMatchData(object) {
  5435. var result = keys(object),
  5436. length = result.length;
  5437. while (length--) {
  5438. var key = result[length],
  5439. value = object[key];
  5440. result[length] = [key, value, isStrictComparable(value)];
  5441. }
  5442. return result;
  5443. }
  5444. /**
  5445. * Gets the native function at `key` of `object`.
  5446. *
  5447. * @private
  5448. * @param {Object} object The object to query.
  5449. * @param {string} key The key of the method to get.
  5450. * @returns {*} Returns the function if it's native, else `undefined`.
  5451. */
  5452. function getNative(object, key) {
  5453. var value = getValue(object, key);
  5454. return baseIsNative(value) ? value : undefined;
  5455. }
  5456. /**
  5457. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5458. *
  5459. * @private
  5460. * @param {*} value The value to query.
  5461. * @returns {string} Returns the raw `toStringTag`.
  5462. */
  5463. function getRawTag(value) {
  5464. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5465. tag = value[symToStringTag];
  5466. try {
  5467. value[symToStringTag] = undefined;
  5468. var unmasked = true;
  5469. } catch (e) {}
  5470. var result = nativeObjectToString.call(value);
  5471. if (unmasked) {
  5472. if (isOwn) {
  5473. value[symToStringTag] = tag;
  5474. } else {
  5475. delete value[symToStringTag];
  5476. }
  5477. }
  5478. return result;
  5479. }
  5480. /**
  5481. * Creates an array of the own enumerable symbols of `object`.
  5482. *
  5483. * @private
  5484. * @param {Object} object The object to query.
  5485. * @returns {Array} Returns the array of symbols.
  5486. */
  5487. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5488. if (object == null) {
  5489. return [];
  5490. }
  5491. object = Object(object);
  5492. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5493. return propertyIsEnumerable.call(object, symbol);
  5494. });
  5495. };
  5496. /**
  5497. * Creates an array of the own and inherited enumerable symbols of `object`.
  5498. *
  5499. * @private
  5500. * @param {Object} object The object to query.
  5501. * @returns {Array} Returns the array of symbols.
  5502. */
  5503. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5504. var result = [];
  5505. while (object) {
  5506. arrayPush(result, getSymbols(object));
  5507. object = getPrototype(object);
  5508. }
  5509. return result;
  5510. };
  5511. /**
  5512. * Gets the `toStringTag` of `value`.
  5513. *
  5514. * @private
  5515. * @param {*} value The value to query.
  5516. * @returns {string} Returns the `toStringTag`.
  5517. */
  5518. var getTag = baseGetTag;
  5519. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5520. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5521. (Map && getTag(new Map) != mapTag) ||
  5522. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5523. (Set && getTag(new Set) != setTag) ||
  5524. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5525. getTag = function(value) {
  5526. var result = baseGetTag(value),
  5527. Ctor = result == objectTag ? value.constructor : undefined,
  5528. ctorString = Ctor ? toSource(Ctor) : '';
  5529. if (ctorString) {
  5530. switch (ctorString) {
  5531. case dataViewCtorString: return dataViewTag;
  5532. case mapCtorString: return mapTag;
  5533. case promiseCtorString: return promiseTag;
  5534. case setCtorString: return setTag;
  5535. case weakMapCtorString: return weakMapTag;
  5536. }
  5537. }
  5538. return result;
  5539. };
  5540. }
  5541. /**
  5542. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5543. *
  5544. * @private
  5545. * @param {number} start The start of the view.
  5546. * @param {number} end The end of the view.
  5547. * @param {Array} transforms The transformations to apply to the view.
  5548. * @returns {Object} Returns an object containing the `start` and `end`
  5549. * positions of the view.
  5550. */
  5551. function getView(start, end, transforms) {
  5552. var index = -1,
  5553. length = transforms.length;
  5554. while (++index < length) {
  5555. var data = transforms[index],
  5556. size = data.size;
  5557. switch (data.type) {
  5558. case 'drop': start += size; break;
  5559. case 'dropRight': end -= size; break;
  5560. case 'take': end = nativeMin(end, start + size); break;
  5561. case 'takeRight': start = nativeMax(start, end - size); break;
  5562. }
  5563. }
  5564. return { 'start': start, 'end': end };
  5565. }
  5566. /**
  5567. * Extracts wrapper details from the `source` body comment.
  5568. *
  5569. * @private
  5570. * @param {string} source The source to inspect.
  5571. * @returns {Array} Returns the wrapper details.
  5572. */
  5573. function getWrapDetails(source) {
  5574. var match = source.match(reWrapDetails);
  5575. return match ? match[1].split(reSplitDetails) : [];
  5576. }
  5577. /**
  5578. * Checks if `path` exists on `object`.
  5579. *
  5580. * @private
  5581. * @param {Object} object The object to query.
  5582. * @param {Array|string} path The path to check.
  5583. * @param {Function} hasFunc The function to check properties.
  5584. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5585. */
  5586. function hasPath(object, path, hasFunc) {
  5587. path = castPath(path, object);
  5588. var index = -1,
  5589. length = path.length,
  5590. result = false;
  5591. while (++index < length) {
  5592. var key = toKey(path[index]);
  5593. if (!(result = object != null && hasFunc(object, key))) {
  5594. break;
  5595. }
  5596. object = object[key];
  5597. }
  5598. if (result || ++index != length) {
  5599. return result;
  5600. }
  5601. length = object == null ? 0 : object.length;
  5602. return !!length && isLength(length) && isIndex(key, length) &&
  5603. (isArray(object) || isArguments(object));
  5604. }
  5605. /**
  5606. * Initializes an array clone.
  5607. *
  5608. * @private
  5609. * @param {Array} array The array to clone.
  5610. * @returns {Array} Returns the initialized clone.
  5611. */
  5612. function initCloneArray(array) {
  5613. var length = array.length,
  5614. result = new array.constructor(length);
  5615. // Add properties assigned by `RegExp#exec`.
  5616. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5617. result.index = array.index;
  5618. result.input = array.input;
  5619. }
  5620. return result;
  5621. }
  5622. /**
  5623. * Initializes an object clone.
  5624. *
  5625. * @private
  5626. * @param {Object} object The object to clone.
  5627. * @returns {Object} Returns the initialized clone.
  5628. */
  5629. function initCloneObject(object) {
  5630. return (typeof object.constructor == 'function' && !isPrototype(object))
  5631. ? baseCreate(getPrototype(object))
  5632. : {};
  5633. }
  5634. /**
  5635. * Initializes an object clone based on its `toStringTag`.
  5636. *
  5637. * **Note:** This function only supports cloning values with tags of
  5638. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5639. *
  5640. * @private
  5641. * @param {Object} object The object to clone.
  5642. * @param {string} tag The `toStringTag` of the object to clone.
  5643. * @param {boolean} [isDeep] Specify a deep clone.
  5644. * @returns {Object} Returns the initialized clone.
  5645. */
  5646. function initCloneByTag(object, tag, isDeep) {
  5647. var Ctor = object.constructor;
  5648. switch (tag) {
  5649. case arrayBufferTag:
  5650. return cloneArrayBuffer(object);
  5651. case boolTag:
  5652. case dateTag:
  5653. return new Ctor(+object);
  5654. case dataViewTag:
  5655. return cloneDataView(object, isDeep);
  5656. case float32Tag: case float64Tag:
  5657. case int8Tag: case int16Tag: case int32Tag:
  5658. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5659. return cloneTypedArray(object, isDeep);
  5660. case mapTag:
  5661. return new Ctor;
  5662. case numberTag:
  5663. case stringTag:
  5664. return new Ctor(object);
  5665. case regexpTag:
  5666. return cloneRegExp(object);
  5667. case setTag:
  5668. return new Ctor;
  5669. case symbolTag:
  5670. return cloneSymbol(object);
  5671. }
  5672. }
  5673. /**
  5674. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5675. *
  5676. * @private
  5677. * @param {string} source The source to modify.
  5678. * @returns {Array} details The details to insert.
  5679. * @returns {string} Returns the modified source.
  5680. */
  5681. function insertWrapDetails(source, details) {
  5682. var length = details.length;
  5683. if (!length) {
  5684. return source;
  5685. }
  5686. var lastIndex = length - 1;
  5687. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5688. details = details.join(length > 2 ? ', ' : ' ');
  5689. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5690. }
  5691. /**
  5692. * Checks if `value` is a flattenable `arguments` object or array.
  5693. *
  5694. * @private
  5695. * @param {*} value The value to check.
  5696. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5697. */
  5698. function isFlattenable(value) {
  5699. return isArray(value) || isArguments(value) ||
  5700. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5701. }
  5702. /**
  5703. * Checks if `value` is a valid array-like index.
  5704. *
  5705. * @private
  5706. * @param {*} value The value to check.
  5707. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5708. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5709. */
  5710. function isIndex(value, length) {
  5711. var type = typeof value;
  5712. length = length == null ? MAX_SAFE_INTEGER : length;
  5713. return !!length &&
  5714. (type == 'number' ||
  5715. (type != 'symbol' && reIsUint.test(value))) &&
  5716. (value > -1 && value % 1 == 0 && value < length);
  5717. }
  5718. /**
  5719. * Checks if the given arguments are from an iteratee call.
  5720. *
  5721. * @private
  5722. * @param {*} value The potential iteratee value argument.
  5723. * @param {*} index The potential iteratee index or key argument.
  5724. * @param {*} object The potential iteratee object argument.
  5725. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5726. * else `false`.
  5727. */
  5728. function isIterateeCall(value, index, object) {
  5729. if (!isObject(object)) {
  5730. return false;
  5731. }
  5732. var type = typeof index;
  5733. if (type == 'number'
  5734. ? (isArrayLike(object) && isIndex(index, object.length))
  5735. : (type == 'string' && index in object)
  5736. ) {
  5737. return eq(object[index], value);
  5738. }
  5739. return false;
  5740. }
  5741. /**
  5742. * Checks if `value` is a property name and not a property path.
  5743. *
  5744. * @private
  5745. * @param {*} value The value to check.
  5746. * @param {Object} [object] The object to query keys on.
  5747. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5748. */
  5749. function isKey(value, object) {
  5750. if (isArray(value)) {
  5751. return false;
  5752. }
  5753. var type = typeof value;
  5754. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5755. value == null || isSymbol(value)) {
  5756. return true;
  5757. }
  5758. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5759. (object != null && value in Object(object));
  5760. }
  5761. /**
  5762. * Checks if `value` is suitable for use as unique object key.
  5763. *
  5764. * @private
  5765. * @param {*} value The value to check.
  5766. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5767. */
  5768. function isKeyable(value) {
  5769. var type = typeof value;
  5770. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5771. ? (value !== '__proto__')
  5772. : (value === null);
  5773. }
  5774. /**
  5775. * Checks if `func` has a lazy counterpart.
  5776. *
  5777. * @private
  5778. * @param {Function} func The function to check.
  5779. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5780. * else `false`.
  5781. */
  5782. function isLaziable(func) {
  5783. var funcName = getFuncName(func),
  5784. other = lodash[funcName];
  5785. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5786. return false;
  5787. }
  5788. if (func === other) {
  5789. return true;
  5790. }
  5791. var data = getData(other);
  5792. return !!data && func === data[0];
  5793. }
  5794. /**
  5795. * Checks if `func` has its source masked.
  5796. *
  5797. * @private
  5798. * @param {Function} func The function to check.
  5799. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5800. */
  5801. function isMasked(func) {
  5802. return !!maskSrcKey && (maskSrcKey in func);
  5803. }
  5804. /**
  5805. * Checks if `func` is capable of being masked.
  5806. *
  5807. * @private
  5808. * @param {*} value The value to check.
  5809. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5810. */
  5811. var isMaskable = coreJsData ? isFunction : stubFalse;
  5812. /**
  5813. * Checks if `value` is likely a prototype object.
  5814. *
  5815. * @private
  5816. * @param {*} value The value to check.
  5817. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5818. */
  5819. function isPrototype(value) {
  5820. var Ctor = value && value.constructor,
  5821. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5822. return value === proto;
  5823. }
  5824. /**
  5825. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5826. *
  5827. * @private
  5828. * @param {*} value The value to check.
  5829. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5830. * equality comparisons, else `false`.
  5831. */
  5832. function isStrictComparable(value) {
  5833. return value === value && !isObject(value);
  5834. }
  5835. /**
  5836. * A specialized version of `matchesProperty` for source values suitable
  5837. * for strict equality comparisons, i.e. `===`.
  5838. *
  5839. * @private
  5840. * @param {string} key The key of the property to get.
  5841. * @param {*} srcValue The value to match.
  5842. * @returns {Function} Returns the new spec function.
  5843. */
  5844. function matchesStrictComparable(key, srcValue) {
  5845. return function(object) {
  5846. if (object == null) {
  5847. return false;
  5848. }
  5849. return object[key] === srcValue &&
  5850. (srcValue !== undefined || (key in Object(object)));
  5851. };
  5852. }
  5853. /**
  5854. * A specialized version of `_.memoize` which clears the memoized function's
  5855. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5856. *
  5857. * @private
  5858. * @param {Function} func The function to have its output memoized.
  5859. * @returns {Function} Returns the new memoized function.
  5860. */
  5861. function memoizeCapped(func) {
  5862. var result = memoize(func, function(key) {
  5863. if (cache.size === MAX_MEMOIZE_SIZE) {
  5864. cache.clear();
  5865. }
  5866. return key;
  5867. });
  5868. var cache = result.cache;
  5869. return result;
  5870. }
  5871. /**
  5872. * Merges the function metadata of `source` into `data`.
  5873. *
  5874. * Merging metadata reduces the number of wrappers used to invoke a function.
  5875. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5876. * may be applied regardless of execution order. Methods like `_.ary` and
  5877. * `_.rearg` modify function arguments, making the order in which they are
  5878. * executed important, preventing the merging of metadata. However, we make
  5879. * an exception for a safe combined case where curried functions have `_.ary`
  5880. * and or `_.rearg` applied.
  5881. *
  5882. * @private
  5883. * @param {Array} data The destination metadata.
  5884. * @param {Array} source The source metadata.
  5885. * @returns {Array} Returns `data`.
  5886. */
  5887. function mergeData(data, source) {
  5888. var bitmask = data[1],
  5889. srcBitmask = source[1],
  5890. newBitmask = bitmask | srcBitmask,
  5891. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5892. var isCombo =
  5893. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5894. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5895. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5896. // Exit early if metadata can't be merged.
  5897. if (!(isCommon || isCombo)) {
  5898. return data;
  5899. }
  5900. // Use source `thisArg` if available.
  5901. if (srcBitmask & WRAP_BIND_FLAG) {
  5902. data[2] = source[2];
  5903. // Set when currying a bound function.
  5904. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5905. }
  5906. // Compose partial arguments.
  5907. var value = source[3];
  5908. if (value) {
  5909. var partials = data[3];
  5910. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5911. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5912. }
  5913. // Compose partial right arguments.
  5914. value = source[5];
  5915. if (value) {
  5916. partials = data[5];
  5917. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5918. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5919. }
  5920. // Use source `argPos` if available.
  5921. value = source[7];
  5922. if (value) {
  5923. data[7] = value;
  5924. }
  5925. // Use source `ary` if it's smaller.
  5926. if (srcBitmask & WRAP_ARY_FLAG) {
  5927. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5928. }
  5929. // Use source `arity` if one is not provided.
  5930. if (data[9] == null) {
  5931. data[9] = source[9];
  5932. }
  5933. // Use source `func` and merge bitmasks.
  5934. data[0] = source[0];
  5935. data[1] = newBitmask;
  5936. return data;
  5937. }
  5938. /**
  5939. * This function is like
  5940. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5941. * except that it includes inherited enumerable properties.
  5942. *
  5943. * @private
  5944. * @param {Object} object The object to query.
  5945. * @returns {Array} Returns the array of property names.
  5946. */
  5947. function nativeKeysIn(object) {
  5948. var result = [];
  5949. if (object != null) {
  5950. for (var key in Object(object)) {
  5951. result.push(key);
  5952. }
  5953. }
  5954. return result;
  5955. }
  5956. /**
  5957. * Converts `value` to a string using `Object.prototype.toString`.
  5958. *
  5959. * @private
  5960. * @param {*} value The value to convert.
  5961. * @returns {string} Returns the converted string.
  5962. */
  5963. function objectToString(value) {
  5964. return nativeObjectToString.call(value);
  5965. }
  5966. /**
  5967. * A specialized version of `baseRest` which transforms the rest array.
  5968. *
  5969. * @private
  5970. * @param {Function} func The function to apply a rest parameter to.
  5971. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5972. * @param {Function} transform The rest array transform.
  5973. * @returns {Function} Returns the new function.
  5974. */
  5975. function overRest(func, start, transform) {
  5976. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5977. return function() {
  5978. var args = arguments,
  5979. index = -1,
  5980. length = nativeMax(args.length - start, 0),
  5981. array = Array(length);
  5982. while (++index < length) {
  5983. array[index] = args[start + index];
  5984. }
  5985. index = -1;
  5986. var otherArgs = Array(start + 1);
  5987. while (++index < start) {
  5988. otherArgs[index] = args[index];
  5989. }
  5990. otherArgs[start] = transform(array);
  5991. return apply(func, this, otherArgs);
  5992. };
  5993. }
  5994. /**
  5995. * Gets the parent value at `path` of `object`.
  5996. *
  5997. * @private
  5998. * @param {Object} object The object to query.
  5999. * @param {Array} path The path to get the parent value of.
  6000. * @returns {*} Returns the parent value.
  6001. */
  6002. function parent(object, path) {
  6003. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6004. }
  6005. /**
  6006. * Reorder `array` according to the specified indexes where the element at
  6007. * the first index is assigned as the first element, the element at
  6008. * the second index is assigned as the second element, and so on.
  6009. *
  6010. * @private
  6011. * @param {Array} array The array to reorder.
  6012. * @param {Array} indexes The arranged array indexes.
  6013. * @returns {Array} Returns `array`.
  6014. */
  6015. function reorder(array, indexes) {
  6016. var arrLength = array.length,
  6017. length = nativeMin(indexes.length, arrLength),
  6018. oldArray = copyArray(array);
  6019. while (length--) {
  6020. var index = indexes[length];
  6021. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6022. }
  6023. return array;
  6024. }
  6025. /**
  6026. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  6027. *
  6028. * @private
  6029. * @param {Object} object The object to query.
  6030. * @param {string} key The key of the property to get.
  6031. * @returns {*} Returns the property value.
  6032. */
  6033. function safeGet(object, key) {
  6034. if (key === 'constructor' && typeof object[key] === 'function') {
  6035. return;
  6036. }
  6037. if (key == '__proto__') {
  6038. return;
  6039. }
  6040. return object[key];
  6041. }
  6042. /**
  6043. * Sets metadata for `func`.
  6044. *
  6045. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6046. * period of time, it will trip its breaker and transition to an identity
  6047. * function to avoid garbage collection pauses in V8. See
  6048. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6049. * for more details.
  6050. *
  6051. * @private
  6052. * @param {Function} func The function to associate metadata with.
  6053. * @param {*} data The metadata.
  6054. * @returns {Function} Returns `func`.
  6055. */
  6056. var setData = shortOut(baseSetData);
  6057. /**
  6058. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6059. *
  6060. * @private
  6061. * @param {Function} func The function to delay.
  6062. * @param {number} wait The number of milliseconds to delay invocation.
  6063. * @returns {number|Object} Returns the timer id or timeout object.
  6064. */
  6065. var setTimeout = ctxSetTimeout || function(func, wait) {
  6066. return root.setTimeout(func, wait);
  6067. };
  6068. /**
  6069. * Sets the `toString` method of `func` to return `string`.
  6070. *
  6071. * @private
  6072. * @param {Function} func The function to modify.
  6073. * @param {Function} string The `toString` result.
  6074. * @returns {Function} Returns `func`.
  6075. */
  6076. var setToString = shortOut(baseSetToString);
  6077. /**
  6078. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6079. * with wrapper details in a comment at the top of the source body.
  6080. *
  6081. * @private
  6082. * @param {Function} wrapper The function to modify.
  6083. * @param {Function} reference The reference function.
  6084. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6085. * @returns {Function} Returns `wrapper`.
  6086. */
  6087. function setWrapToString(wrapper, reference, bitmask) {
  6088. var source = (reference + '');
  6089. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6090. }
  6091. /**
  6092. * Creates a function that'll short out and invoke `identity` instead
  6093. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6094. * milliseconds.
  6095. *
  6096. * @private
  6097. * @param {Function} func The function to restrict.
  6098. * @returns {Function} Returns the new shortable function.
  6099. */
  6100. function shortOut(func) {
  6101. var count = 0,
  6102. lastCalled = 0;
  6103. return function() {
  6104. var stamp = nativeNow(),
  6105. remaining = HOT_SPAN - (stamp - lastCalled);
  6106. lastCalled = stamp;
  6107. if (remaining > 0) {
  6108. if (++count >= HOT_COUNT) {
  6109. return arguments[0];
  6110. }
  6111. } else {
  6112. count = 0;
  6113. }
  6114. return func.apply(undefined, arguments);
  6115. };
  6116. }
  6117. /**
  6118. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6119. *
  6120. * @private
  6121. * @param {Array} array The array to shuffle.
  6122. * @param {number} [size=array.length] The size of `array`.
  6123. * @returns {Array} Returns `array`.
  6124. */
  6125. function shuffleSelf(array, size) {
  6126. var index = -1,
  6127. length = array.length,
  6128. lastIndex = length - 1;
  6129. size = size === undefined ? length : size;
  6130. while (++index < size) {
  6131. var rand = baseRandom(index, lastIndex),
  6132. value = array[rand];
  6133. array[rand] = array[index];
  6134. array[index] = value;
  6135. }
  6136. array.length = size;
  6137. return array;
  6138. }
  6139. /**
  6140. * Converts `string` to a property path array.
  6141. *
  6142. * @private
  6143. * @param {string} string The string to convert.
  6144. * @returns {Array} Returns the property path array.
  6145. */
  6146. var stringToPath = memoizeCapped(function(string) {
  6147. var result = [];
  6148. if (string.charCodeAt(0) === 46 /* . */) {
  6149. result.push('');
  6150. }
  6151. string.replace(rePropName, function(match, number, quote, subString) {
  6152. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6153. });
  6154. return result;
  6155. });
  6156. /**
  6157. * Converts `value` to a string key if it's not a string or symbol.
  6158. *
  6159. * @private
  6160. * @param {*} value The value to inspect.
  6161. * @returns {string|symbol} Returns the key.
  6162. */
  6163. function toKey(value) {
  6164. if (typeof value == 'string' || isSymbol(value)) {
  6165. return value;
  6166. }
  6167. var result = (value + '');
  6168. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6169. }
  6170. /**
  6171. * Converts `func` to its source code.
  6172. *
  6173. * @private
  6174. * @param {Function} func The function to convert.
  6175. * @returns {string} Returns the source code.
  6176. */
  6177. function toSource(func) {
  6178. if (func != null) {
  6179. try {
  6180. return funcToString.call(func);
  6181. } catch (e) {}
  6182. try {
  6183. return (func + '');
  6184. } catch (e) {}
  6185. }
  6186. return '';
  6187. }
  6188. /**
  6189. * Updates wrapper `details` based on `bitmask` flags.
  6190. *
  6191. * @private
  6192. * @returns {Array} details The details to modify.
  6193. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6194. * @returns {Array} Returns `details`.
  6195. */
  6196. function updateWrapDetails(details, bitmask) {
  6197. arrayEach(wrapFlags, function(pair) {
  6198. var value = '_.' + pair[0];
  6199. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6200. details.push(value);
  6201. }
  6202. });
  6203. return details.sort();
  6204. }
  6205. /**
  6206. * Creates a clone of `wrapper`.
  6207. *
  6208. * @private
  6209. * @param {Object} wrapper The wrapper to clone.
  6210. * @returns {Object} Returns the cloned wrapper.
  6211. */
  6212. function wrapperClone(wrapper) {
  6213. if (wrapper instanceof LazyWrapper) {
  6214. return wrapper.clone();
  6215. }
  6216. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6217. result.__actions__ = copyArray(wrapper.__actions__);
  6218. result.__index__ = wrapper.__index__;
  6219. result.__values__ = wrapper.__values__;
  6220. return result;
  6221. }
  6222. /*------------------------------------------------------------------------*/
  6223. /**
  6224. * Creates an array of elements split into groups the length of `size`.
  6225. * If `array` can't be split evenly, the final chunk will be the remaining
  6226. * elements.
  6227. *
  6228. * @static
  6229. * @memberOf _
  6230. * @since 3.0.0
  6231. * @category Array
  6232. * @param {Array} array The array to process.
  6233. * @param {number} [size=1] The length of each chunk
  6234. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6235. * @returns {Array} Returns the new array of chunks.
  6236. * @example
  6237. *
  6238. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6239. * // => [['a', 'b'], ['c', 'd']]
  6240. *
  6241. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6242. * // => [['a', 'b', 'c'], ['d']]
  6243. */
  6244. function chunk(array, size, guard) {
  6245. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6246. size = 1;
  6247. } else {
  6248. size = nativeMax(toInteger(size), 0);
  6249. }
  6250. var length = array == null ? 0 : array.length;
  6251. if (!length || size < 1) {
  6252. return [];
  6253. }
  6254. var index = 0,
  6255. resIndex = 0,
  6256. result = Array(nativeCeil(length / size));
  6257. while (index < length) {
  6258. result[resIndex++] = baseSlice(array, index, (index += size));
  6259. }
  6260. return result;
  6261. }
  6262. /**
  6263. * Creates an array with all falsey values removed. The values `false`, `null`,
  6264. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6265. *
  6266. * @static
  6267. * @memberOf _
  6268. * @since 0.1.0
  6269. * @category Array
  6270. * @param {Array} array The array to compact.
  6271. * @returns {Array} Returns the new array of filtered values.
  6272. * @example
  6273. *
  6274. * _.compact([0, 1, false, 2, '', 3]);
  6275. * // => [1, 2, 3]
  6276. */
  6277. function compact(array) {
  6278. var index = -1,
  6279. length = array == null ? 0 : array.length,
  6280. resIndex = 0,
  6281. result = [];
  6282. while (++index < length) {
  6283. var value = array[index];
  6284. if (value) {
  6285. result[resIndex++] = value;
  6286. }
  6287. }
  6288. return result;
  6289. }
  6290. /**
  6291. * Creates a new array concatenating `array` with any additional arrays
  6292. * and/or values.
  6293. *
  6294. * @static
  6295. * @memberOf _
  6296. * @since 4.0.0
  6297. * @category Array
  6298. * @param {Array} array The array to concatenate.
  6299. * @param {...*} [values] The values to concatenate.
  6300. * @returns {Array} Returns the new concatenated array.
  6301. * @example
  6302. *
  6303. * var array = [1];
  6304. * var other = _.concat(array, 2, [3], [[4]]);
  6305. *
  6306. * console.log(other);
  6307. * // => [1, 2, 3, [4]]
  6308. *
  6309. * console.log(array);
  6310. * // => [1]
  6311. */
  6312. function concat() {
  6313. var length = arguments.length;
  6314. if (!length) {
  6315. return [];
  6316. }
  6317. var args = Array(length - 1),
  6318. array = arguments[0],
  6319. index = length;
  6320. while (index--) {
  6321. args[index - 1] = arguments[index];
  6322. }
  6323. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6324. }
  6325. /**
  6326. * Creates an array of `array` values not included in the other given arrays
  6327. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6328. * for equality comparisons. The order and references of result values are
  6329. * determined by the first array.
  6330. *
  6331. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6332. *
  6333. * @static
  6334. * @memberOf _
  6335. * @since 0.1.0
  6336. * @category Array
  6337. * @param {Array} array The array to inspect.
  6338. * @param {...Array} [values] The values to exclude.
  6339. * @returns {Array} Returns the new array of filtered values.
  6340. * @see _.without, _.xor
  6341. * @example
  6342. *
  6343. * _.difference([2, 1], [2, 3]);
  6344. * // => [1]
  6345. */
  6346. var difference = baseRest(function(array, values) {
  6347. return isArrayLikeObject(array)
  6348. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6349. : [];
  6350. });
  6351. /**
  6352. * This method is like `_.difference` except that it accepts `iteratee` which
  6353. * is invoked for each element of `array` and `values` to generate the criterion
  6354. * by which they're compared. The order and references of result values are
  6355. * determined by the first array. The iteratee is invoked with one argument:
  6356. * (value).
  6357. *
  6358. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6359. *
  6360. * @static
  6361. * @memberOf _
  6362. * @since 4.0.0
  6363. * @category Array
  6364. * @param {Array} array The array to inspect.
  6365. * @param {...Array} [values] The values to exclude.
  6366. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6367. * @returns {Array} Returns the new array of filtered values.
  6368. * @example
  6369. *
  6370. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6371. * // => [1.2]
  6372. *
  6373. * // The `_.property` iteratee shorthand.
  6374. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6375. * // => [{ 'x': 2 }]
  6376. */
  6377. var differenceBy = baseRest(function(array, values) {
  6378. var iteratee = last(values);
  6379. if (isArrayLikeObject(iteratee)) {
  6380. iteratee = undefined;
  6381. }
  6382. return isArrayLikeObject(array)
  6383. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6384. : [];
  6385. });
  6386. /**
  6387. * This method is like `_.difference` except that it accepts `comparator`
  6388. * which is invoked to compare elements of `array` to `values`. The order and
  6389. * references of result values are determined by the first array. The comparator
  6390. * is invoked with two arguments: (arrVal, othVal).
  6391. *
  6392. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6393. *
  6394. * @static
  6395. * @memberOf _
  6396. * @since 4.0.0
  6397. * @category Array
  6398. * @param {Array} array The array to inspect.
  6399. * @param {...Array} [values] The values to exclude.
  6400. * @param {Function} [comparator] The comparator invoked per element.
  6401. * @returns {Array} Returns the new array of filtered values.
  6402. * @example
  6403. *
  6404. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6405. *
  6406. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6407. * // => [{ 'x': 2, 'y': 1 }]
  6408. */
  6409. var differenceWith = baseRest(function(array, values) {
  6410. var comparator = last(values);
  6411. if (isArrayLikeObject(comparator)) {
  6412. comparator = undefined;
  6413. }
  6414. return isArrayLikeObject(array)
  6415. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6416. : [];
  6417. });
  6418. /**
  6419. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6420. *
  6421. * @static
  6422. * @memberOf _
  6423. * @since 0.5.0
  6424. * @category Array
  6425. * @param {Array} array The array to query.
  6426. * @param {number} [n=1] The number of elements to drop.
  6427. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6428. * @returns {Array} Returns the slice of `array`.
  6429. * @example
  6430. *
  6431. * _.drop([1, 2, 3]);
  6432. * // => [2, 3]
  6433. *
  6434. * _.drop([1, 2, 3], 2);
  6435. * // => [3]
  6436. *
  6437. * _.drop([1, 2, 3], 5);
  6438. * // => []
  6439. *
  6440. * _.drop([1, 2, 3], 0);
  6441. * // => [1, 2, 3]
  6442. */
  6443. function drop(array, n, guard) {
  6444. var length = array == null ? 0 : array.length;
  6445. if (!length) {
  6446. return [];
  6447. }
  6448. n = (guard || n === undefined) ? 1 : toInteger(n);
  6449. return baseSlice(array, n < 0 ? 0 : n, length);
  6450. }
  6451. /**
  6452. * Creates a slice of `array` with `n` elements dropped from the end.
  6453. *
  6454. * @static
  6455. * @memberOf _
  6456. * @since 3.0.0
  6457. * @category Array
  6458. * @param {Array} array The array to query.
  6459. * @param {number} [n=1] The number of elements to drop.
  6460. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6461. * @returns {Array} Returns the slice of `array`.
  6462. * @example
  6463. *
  6464. * _.dropRight([1, 2, 3]);
  6465. * // => [1, 2]
  6466. *
  6467. * _.dropRight([1, 2, 3], 2);
  6468. * // => [1]
  6469. *
  6470. * _.dropRight([1, 2, 3], 5);
  6471. * // => []
  6472. *
  6473. * _.dropRight([1, 2, 3], 0);
  6474. * // => [1, 2, 3]
  6475. */
  6476. function dropRight(array, n, guard) {
  6477. var length = array == null ? 0 : array.length;
  6478. if (!length) {
  6479. return [];
  6480. }
  6481. n = (guard || n === undefined) ? 1 : toInteger(n);
  6482. n = length - n;
  6483. return baseSlice(array, 0, n < 0 ? 0 : n);
  6484. }
  6485. /**
  6486. * Creates a slice of `array` excluding elements dropped from the end.
  6487. * Elements are dropped until `predicate` returns falsey. The predicate is
  6488. * invoked with three arguments: (value, index, array).
  6489. *
  6490. * @static
  6491. * @memberOf _
  6492. * @since 3.0.0
  6493. * @category Array
  6494. * @param {Array} array The array to query.
  6495. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6496. * @returns {Array} Returns the slice of `array`.
  6497. * @example
  6498. *
  6499. * var users = [
  6500. * { 'user': 'barney', 'active': true },
  6501. * { 'user': 'fred', 'active': false },
  6502. * { 'user': 'pebbles', 'active': false }
  6503. * ];
  6504. *
  6505. * _.dropRightWhile(users, function(o) { return !o.active; });
  6506. * // => objects for ['barney']
  6507. *
  6508. * // The `_.matches` iteratee shorthand.
  6509. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6510. * // => objects for ['barney', 'fred']
  6511. *
  6512. * // The `_.matchesProperty` iteratee shorthand.
  6513. * _.dropRightWhile(users, ['active', false]);
  6514. * // => objects for ['barney']
  6515. *
  6516. * // The `_.property` iteratee shorthand.
  6517. * _.dropRightWhile(users, 'active');
  6518. * // => objects for ['barney', 'fred', 'pebbles']
  6519. */
  6520. function dropRightWhile(array, predicate) {
  6521. return (array && array.length)
  6522. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6523. : [];
  6524. }
  6525. /**
  6526. * Creates a slice of `array` excluding elements dropped from the beginning.
  6527. * Elements are dropped until `predicate` returns falsey. The predicate is
  6528. * invoked with three arguments: (value, index, array).
  6529. *
  6530. * @static
  6531. * @memberOf _
  6532. * @since 3.0.0
  6533. * @category Array
  6534. * @param {Array} array The array to query.
  6535. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6536. * @returns {Array} Returns the slice of `array`.
  6537. * @example
  6538. *
  6539. * var users = [
  6540. * { 'user': 'barney', 'active': false },
  6541. * { 'user': 'fred', 'active': false },
  6542. * { 'user': 'pebbles', 'active': true }
  6543. * ];
  6544. *
  6545. * _.dropWhile(users, function(o) { return !o.active; });
  6546. * // => objects for ['pebbles']
  6547. *
  6548. * // The `_.matches` iteratee shorthand.
  6549. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6550. * // => objects for ['fred', 'pebbles']
  6551. *
  6552. * // The `_.matchesProperty` iteratee shorthand.
  6553. * _.dropWhile(users, ['active', false]);
  6554. * // => objects for ['pebbles']
  6555. *
  6556. * // The `_.property` iteratee shorthand.
  6557. * _.dropWhile(users, 'active');
  6558. * // => objects for ['barney', 'fred', 'pebbles']
  6559. */
  6560. function dropWhile(array, predicate) {
  6561. return (array && array.length)
  6562. ? baseWhile(array, getIteratee(predicate, 3), true)
  6563. : [];
  6564. }
  6565. /**
  6566. * Fills elements of `array` with `value` from `start` up to, but not
  6567. * including, `end`.
  6568. *
  6569. * **Note:** This method mutates `array`.
  6570. *
  6571. * @static
  6572. * @memberOf _
  6573. * @since 3.2.0
  6574. * @category Array
  6575. * @param {Array} array The array to fill.
  6576. * @param {*} value The value to fill `array` with.
  6577. * @param {number} [start=0] The start position.
  6578. * @param {number} [end=array.length] The end position.
  6579. * @returns {Array} Returns `array`.
  6580. * @example
  6581. *
  6582. * var array = [1, 2, 3];
  6583. *
  6584. * _.fill(array, 'a');
  6585. * console.log(array);
  6586. * // => ['a', 'a', 'a']
  6587. *
  6588. * _.fill(Array(3), 2);
  6589. * // => [2, 2, 2]
  6590. *
  6591. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6592. * // => [4, '*', '*', 10]
  6593. */
  6594. function fill(array, value, start, end) {
  6595. var length = array == null ? 0 : array.length;
  6596. if (!length) {
  6597. return [];
  6598. }
  6599. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6600. start = 0;
  6601. end = length;
  6602. }
  6603. return baseFill(array, value, start, end);
  6604. }
  6605. /**
  6606. * This method is like `_.find` except that it returns the index of the first
  6607. * element `predicate` returns truthy for instead of the element itself.
  6608. *
  6609. * @static
  6610. * @memberOf _
  6611. * @since 1.1.0
  6612. * @category Array
  6613. * @param {Array} array The array to inspect.
  6614. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6615. * @param {number} [fromIndex=0] The index to search from.
  6616. * @returns {number} Returns the index of the found element, else `-1`.
  6617. * @example
  6618. *
  6619. * var users = [
  6620. * { 'user': 'barney', 'active': false },
  6621. * { 'user': 'fred', 'active': false },
  6622. * { 'user': 'pebbles', 'active': true }
  6623. * ];
  6624. *
  6625. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6626. * // => 0
  6627. *
  6628. * // The `_.matches` iteratee shorthand.
  6629. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6630. * // => 1
  6631. *
  6632. * // The `_.matchesProperty` iteratee shorthand.
  6633. * _.findIndex(users, ['active', false]);
  6634. * // => 0
  6635. *
  6636. * // The `_.property` iteratee shorthand.
  6637. * _.findIndex(users, 'active');
  6638. * // => 2
  6639. */
  6640. function findIndex(array, predicate, fromIndex) {
  6641. var length = array == null ? 0 : array.length;
  6642. if (!length) {
  6643. return -1;
  6644. }
  6645. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6646. if (index < 0) {
  6647. index = nativeMax(length + index, 0);
  6648. }
  6649. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6650. }
  6651. /**
  6652. * This method is like `_.findIndex` except that it iterates over elements
  6653. * of `collection` from right to left.
  6654. *
  6655. * @static
  6656. * @memberOf _
  6657. * @since 2.0.0
  6658. * @category Array
  6659. * @param {Array} array The array to inspect.
  6660. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6661. * @param {number} [fromIndex=array.length-1] The index to search from.
  6662. * @returns {number} Returns the index of the found element, else `-1`.
  6663. * @example
  6664. *
  6665. * var users = [
  6666. * { 'user': 'barney', 'active': true },
  6667. * { 'user': 'fred', 'active': false },
  6668. * { 'user': 'pebbles', 'active': false }
  6669. * ];
  6670. *
  6671. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6672. * // => 2
  6673. *
  6674. * // The `_.matches` iteratee shorthand.
  6675. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6676. * // => 0
  6677. *
  6678. * // The `_.matchesProperty` iteratee shorthand.
  6679. * _.findLastIndex(users, ['active', false]);
  6680. * // => 2
  6681. *
  6682. * // The `_.property` iteratee shorthand.
  6683. * _.findLastIndex(users, 'active');
  6684. * // => 0
  6685. */
  6686. function findLastIndex(array, predicate, fromIndex) {
  6687. var length = array == null ? 0 : array.length;
  6688. if (!length) {
  6689. return -1;
  6690. }
  6691. var index = length - 1;
  6692. if (fromIndex !== undefined) {
  6693. index = toInteger(fromIndex);
  6694. index = fromIndex < 0
  6695. ? nativeMax(length + index, 0)
  6696. : nativeMin(index, length - 1);
  6697. }
  6698. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6699. }
  6700. /**
  6701. * Flattens `array` a single level deep.
  6702. *
  6703. * @static
  6704. * @memberOf _
  6705. * @since 0.1.0
  6706. * @category Array
  6707. * @param {Array} array The array to flatten.
  6708. * @returns {Array} Returns the new flattened array.
  6709. * @example
  6710. *
  6711. * _.flatten([1, [2, [3, [4]], 5]]);
  6712. * // => [1, 2, [3, [4]], 5]
  6713. */
  6714. function flatten(array) {
  6715. var length = array == null ? 0 : array.length;
  6716. return length ? baseFlatten(array, 1) : [];
  6717. }
  6718. /**
  6719. * Recursively flattens `array`.
  6720. *
  6721. * @static
  6722. * @memberOf _
  6723. * @since 3.0.0
  6724. * @category Array
  6725. * @param {Array} array The array to flatten.
  6726. * @returns {Array} Returns the new flattened array.
  6727. * @example
  6728. *
  6729. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6730. * // => [1, 2, 3, 4, 5]
  6731. */
  6732. function flattenDeep(array) {
  6733. var length = array == null ? 0 : array.length;
  6734. return length ? baseFlatten(array, INFINITY) : [];
  6735. }
  6736. /**
  6737. * Recursively flatten `array` up to `depth` times.
  6738. *
  6739. * @static
  6740. * @memberOf _
  6741. * @since 4.4.0
  6742. * @category Array
  6743. * @param {Array} array The array to flatten.
  6744. * @param {number} [depth=1] The maximum recursion depth.
  6745. * @returns {Array} Returns the new flattened array.
  6746. * @example
  6747. *
  6748. * var array = [1, [2, [3, [4]], 5]];
  6749. *
  6750. * _.flattenDepth(array, 1);
  6751. * // => [1, 2, [3, [4]], 5]
  6752. *
  6753. * _.flattenDepth(array, 2);
  6754. * // => [1, 2, 3, [4], 5]
  6755. */
  6756. function flattenDepth(array, depth) {
  6757. var length = array == null ? 0 : array.length;
  6758. if (!length) {
  6759. return [];
  6760. }
  6761. depth = depth === undefined ? 1 : toInteger(depth);
  6762. return baseFlatten(array, depth);
  6763. }
  6764. /**
  6765. * The inverse of `_.toPairs`; this method returns an object composed
  6766. * from key-value `pairs`.
  6767. *
  6768. * @static
  6769. * @memberOf _
  6770. * @since 4.0.0
  6771. * @category Array
  6772. * @param {Array} pairs The key-value pairs.
  6773. * @returns {Object} Returns the new object.
  6774. * @example
  6775. *
  6776. * _.fromPairs([['a', 1], ['b', 2]]);
  6777. * // => { 'a': 1, 'b': 2 }
  6778. */
  6779. function fromPairs(pairs) {
  6780. var index = -1,
  6781. length = pairs == null ? 0 : pairs.length,
  6782. result = {};
  6783. while (++index < length) {
  6784. var pair = pairs[index];
  6785. result[pair[0]] = pair[1];
  6786. }
  6787. return result;
  6788. }
  6789. /**
  6790. * Gets the first element of `array`.
  6791. *
  6792. * @static
  6793. * @memberOf _
  6794. * @since 0.1.0
  6795. * @alias first
  6796. * @category Array
  6797. * @param {Array} array The array to query.
  6798. * @returns {*} Returns the first element of `array`.
  6799. * @example
  6800. *
  6801. * _.head([1, 2, 3]);
  6802. * // => 1
  6803. *
  6804. * _.head([]);
  6805. * // => undefined
  6806. */
  6807. function head(array) {
  6808. return (array && array.length) ? array[0] : undefined;
  6809. }
  6810. /**
  6811. * Gets the index at which the first occurrence of `value` is found in `array`
  6812. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6813. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6814. * offset from the end of `array`.
  6815. *
  6816. * @static
  6817. * @memberOf _
  6818. * @since 0.1.0
  6819. * @category Array
  6820. * @param {Array} array The array to inspect.
  6821. * @param {*} value The value to search for.
  6822. * @param {number} [fromIndex=0] The index to search from.
  6823. * @returns {number} Returns the index of the matched value, else `-1`.
  6824. * @example
  6825. *
  6826. * _.indexOf([1, 2, 1, 2], 2);
  6827. * // => 1
  6828. *
  6829. * // Search from the `fromIndex`.
  6830. * _.indexOf([1, 2, 1, 2], 2, 2);
  6831. * // => 3
  6832. */
  6833. function indexOf(array, value, fromIndex) {
  6834. var length = array == null ? 0 : array.length;
  6835. if (!length) {
  6836. return -1;
  6837. }
  6838. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6839. if (index < 0) {
  6840. index = nativeMax(length + index, 0);
  6841. }
  6842. return baseIndexOf(array, value, index);
  6843. }
  6844. /**
  6845. * Gets all but the last element of `array`.
  6846. *
  6847. * @static
  6848. * @memberOf _
  6849. * @since 0.1.0
  6850. * @category Array
  6851. * @param {Array} array The array to query.
  6852. * @returns {Array} Returns the slice of `array`.
  6853. * @example
  6854. *
  6855. * _.initial([1, 2, 3]);
  6856. * // => [1, 2]
  6857. */
  6858. function initial(array) {
  6859. var length = array == null ? 0 : array.length;
  6860. return length ? baseSlice(array, 0, -1) : [];
  6861. }
  6862. /**
  6863. * Creates an array of unique values that are included in all given arrays
  6864. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6865. * for equality comparisons. The order and references of result values are
  6866. * determined by the first array.
  6867. *
  6868. * @static
  6869. * @memberOf _
  6870. * @since 0.1.0
  6871. * @category Array
  6872. * @param {...Array} [arrays] The arrays to inspect.
  6873. * @returns {Array} Returns the new array of intersecting values.
  6874. * @example
  6875. *
  6876. * _.intersection([2, 1], [2, 3]);
  6877. * // => [2]
  6878. */
  6879. var intersection = baseRest(function(arrays) {
  6880. var mapped = arrayMap(arrays, castArrayLikeObject);
  6881. return (mapped.length && mapped[0] === arrays[0])
  6882. ? baseIntersection(mapped)
  6883. : [];
  6884. });
  6885. /**
  6886. * This method is like `_.intersection` except that it accepts `iteratee`
  6887. * which is invoked for each element of each `arrays` to generate the criterion
  6888. * by which they're compared. The order and references of result values are
  6889. * determined by the first array. The iteratee is invoked with one argument:
  6890. * (value).
  6891. *
  6892. * @static
  6893. * @memberOf _
  6894. * @since 4.0.0
  6895. * @category Array
  6896. * @param {...Array} [arrays] The arrays to inspect.
  6897. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6898. * @returns {Array} Returns the new array of intersecting values.
  6899. * @example
  6900. *
  6901. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6902. * // => [2.1]
  6903. *
  6904. * // The `_.property` iteratee shorthand.
  6905. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6906. * // => [{ 'x': 1 }]
  6907. */
  6908. var intersectionBy = baseRest(function(arrays) {
  6909. var iteratee = last(arrays),
  6910. mapped = arrayMap(arrays, castArrayLikeObject);
  6911. if (iteratee === last(mapped)) {
  6912. iteratee = undefined;
  6913. } else {
  6914. mapped.pop();
  6915. }
  6916. return (mapped.length && mapped[0] === arrays[0])
  6917. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6918. : [];
  6919. });
  6920. /**
  6921. * This method is like `_.intersection` except that it accepts `comparator`
  6922. * which is invoked to compare elements of `arrays`. The order and references
  6923. * of result values are determined by the first array. The comparator is
  6924. * invoked with two arguments: (arrVal, othVal).
  6925. *
  6926. * @static
  6927. * @memberOf _
  6928. * @since 4.0.0
  6929. * @category Array
  6930. * @param {...Array} [arrays] The arrays to inspect.
  6931. * @param {Function} [comparator] The comparator invoked per element.
  6932. * @returns {Array} Returns the new array of intersecting values.
  6933. * @example
  6934. *
  6935. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6936. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6937. *
  6938. * _.intersectionWith(objects, others, _.isEqual);
  6939. * // => [{ 'x': 1, 'y': 2 }]
  6940. */
  6941. var intersectionWith = baseRest(function(arrays) {
  6942. var comparator = last(arrays),
  6943. mapped = arrayMap(arrays, castArrayLikeObject);
  6944. comparator = typeof comparator == 'function' ? comparator : undefined;
  6945. if (comparator) {
  6946. mapped.pop();
  6947. }
  6948. return (mapped.length && mapped[0] === arrays[0])
  6949. ? baseIntersection(mapped, undefined, comparator)
  6950. : [];
  6951. });
  6952. /**
  6953. * Converts all elements in `array` into a string separated by `separator`.
  6954. *
  6955. * @static
  6956. * @memberOf _
  6957. * @since 4.0.0
  6958. * @category Array
  6959. * @param {Array} array The array to convert.
  6960. * @param {string} [separator=','] The element separator.
  6961. * @returns {string} Returns the joined string.
  6962. * @example
  6963. *
  6964. * _.join(['a', 'b', 'c'], '~');
  6965. * // => 'a~b~c'
  6966. */
  6967. function join(array, separator) {
  6968. return array == null ? '' : nativeJoin.call(array, separator);
  6969. }
  6970. /**
  6971. * Gets the last element of `array`.
  6972. *
  6973. * @static
  6974. * @memberOf _
  6975. * @since 0.1.0
  6976. * @category Array
  6977. * @param {Array} array The array to query.
  6978. * @returns {*} Returns the last element of `array`.
  6979. * @example
  6980. *
  6981. * _.last([1, 2, 3]);
  6982. * // => 3
  6983. */
  6984. function last(array) {
  6985. var length = array == null ? 0 : array.length;
  6986. return length ? array[length - 1] : undefined;
  6987. }
  6988. /**
  6989. * This method is like `_.indexOf` except that it iterates over elements of
  6990. * `array` from right to left.
  6991. *
  6992. * @static
  6993. * @memberOf _
  6994. * @since 0.1.0
  6995. * @category Array
  6996. * @param {Array} array The array to inspect.
  6997. * @param {*} value The value to search for.
  6998. * @param {number} [fromIndex=array.length-1] The index to search from.
  6999. * @returns {number} Returns the index of the matched value, else `-1`.
  7000. * @example
  7001. *
  7002. * _.lastIndexOf([1, 2, 1, 2], 2);
  7003. * // => 3
  7004. *
  7005. * // Search from the `fromIndex`.
  7006. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7007. * // => 1
  7008. */
  7009. function lastIndexOf(array, value, fromIndex) {
  7010. var length = array == null ? 0 : array.length;
  7011. if (!length) {
  7012. return -1;
  7013. }
  7014. var index = length;
  7015. if (fromIndex !== undefined) {
  7016. index = toInteger(fromIndex);
  7017. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7018. }
  7019. return value === value
  7020. ? strictLastIndexOf(array, value, index)
  7021. : baseFindIndex(array, baseIsNaN, index, true);
  7022. }
  7023. /**
  7024. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7025. * element from the end is returned.
  7026. *
  7027. * @static
  7028. * @memberOf _
  7029. * @since 4.11.0
  7030. * @category Array
  7031. * @param {Array} array The array to query.
  7032. * @param {number} [n=0] The index of the element to return.
  7033. * @returns {*} Returns the nth element of `array`.
  7034. * @example
  7035. *
  7036. * var array = ['a', 'b', 'c', 'd'];
  7037. *
  7038. * _.nth(array, 1);
  7039. * // => 'b'
  7040. *
  7041. * _.nth(array, -2);
  7042. * // => 'c';
  7043. */
  7044. function nth(array, n) {
  7045. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7046. }
  7047. /**
  7048. * Removes all given values from `array` using
  7049. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7050. * for equality comparisons.
  7051. *
  7052. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7053. * to remove elements from an array by predicate.
  7054. *
  7055. * @static
  7056. * @memberOf _
  7057. * @since 2.0.0
  7058. * @category Array
  7059. * @param {Array} array The array to modify.
  7060. * @param {...*} [values] The values to remove.
  7061. * @returns {Array} Returns `array`.
  7062. * @example
  7063. *
  7064. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7065. *
  7066. * _.pull(array, 'a', 'c');
  7067. * console.log(array);
  7068. * // => ['b', 'b']
  7069. */
  7070. var pull = baseRest(pullAll);
  7071. /**
  7072. * This method is like `_.pull` except that it accepts an array of values to remove.
  7073. *
  7074. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7075. *
  7076. * @static
  7077. * @memberOf _
  7078. * @since 4.0.0
  7079. * @category Array
  7080. * @param {Array} array The array to modify.
  7081. * @param {Array} values The values to remove.
  7082. * @returns {Array} Returns `array`.
  7083. * @example
  7084. *
  7085. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7086. *
  7087. * _.pullAll(array, ['a', 'c']);
  7088. * console.log(array);
  7089. * // => ['b', 'b']
  7090. */
  7091. function pullAll(array, values) {
  7092. return (array && array.length && values && values.length)
  7093. ? basePullAll(array, values)
  7094. : array;
  7095. }
  7096. /**
  7097. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7098. * invoked for each element of `array` and `values` to generate the criterion
  7099. * by which they're compared. The iteratee is invoked with one argument: (value).
  7100. *
  7101. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7102. *
  7103. * @static
  7104. * @memberOf _
  7105. * @since 4.0.0
  7106. * @category Array
  7107. * @param {Array} array The array to modify.
  7108. * @param {Array} values The values to remove.
  7109. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7110. * @returns {Array} Returns `array`.
  7111. * @example
  7112. *
  7113. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7114. *
  7115. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7116. * console.log(array);
  7117. * // => [{ 'x': 2 }]
  7118. */
  7119. function pullAllBy(array, values, iteratee) {
  7120. return (array && array.length && values && values.length)
  7121. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7122. : array;
  7123. }
  7124. /**
  7125. * This method is like `_.pullAll` except that it accepts `comparator` which
  7126. * is invoked to compare elements of `array` to `values`. The comparator is
  7127. * invoked with two arguments: (arrVal, othVal).
  7128. *
  7129. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7130. *
  7131. * @static
  7132. * @memberOf _
  7133. * @since 4.6.0
  7134. * @category Array
  7135. * @param {Array} array The array to modify.
  7136. * @param {Array} values The values to remove.
  7137. * @param {Function} [comparator] The comparator invoked per element.
  7138. * @returns {Array} Returns `array`.
  7139. * @example
  7140. *
  7141. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7142. *
  7143. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7144. * console.log(array);
  7145. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7146. */
  7147. function pullAllWith(array, values, comparator) {
  7148. return (array && array.length && values && values.length)
  7149. ? basePullAll(array, values, undefined, comparator)
  7150. : array;
  7151. }
  7152. /**
  7153. * Removes elements from `array` corresponding to `indexes` and returns an
  7154. * array of removed elements.
  7155. *
  7156. * **Note:** Unlike `_.at`, this method mutates `array`.
  7157. *
  7158. * @static
  7159. * @memberOf _
  7160. * @since 3.0.0
  7161. * @category Array
  7162. * @param {Array} array The array to modify.
  7163. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7164. * @returns {Array} Returns the new array of removed elements.
  7165. * @example
  7166. *
  7167. * var array = ['a', 'b', 'c', 'd'];
  7168. * var pulled = _.pullAt(array, [1, 3]);
  7169. *
  7170. * console.log(array);
  7171. * // => ['a', 'c']
  7172. *
  7173. * console.log(pulled);
  7174. * // => ['b', 'd']
  7175. */
  7176. var pullAt = flatRest(function(array, indexes) {
  7177. var length = array == null ? 0 : array.length,
  7178. result = baseAt(array, indexes);
  7179. basePullAt(array, arrayMap(indexes, function(index) {
  7180. return isIndex(index, length) ? +index : index;
  7181. }).sort(compareAscending));
  7182. return result;
  7183. });
  7184. /**
  7185. * Removes all elements from `array` that `predicate` returns truthy for
  7186. * and returns an array of the removed elements. The predicate is invoked
  7187. * with three arguments: (value, index, array).
  7188. *
  7189. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7190. * to pull elements from an array by value.
  7191. *
  7192. * @static
  7193. * @memberOf _
  7194. * @since 2.0.0
  7195. * @category Array
  7196. * @param {Array} array The array to modify.
  7197. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7198. * @returns {Array} Returns the new array of removed elements.
  7199. * @example
  7200. *
  7201. * var array = [1, 2, 3, 4];
  7202. * var evens = _.remove(array, function(n) {
  7203. * return n % 2 == 0;
  7204. * });
  7205. *
  7206. * console.log(array);
  7207. * // => [1, 3]
  7208. *
  7209. * console.log(evens);
  7210. * // => [2, 4]
  7211. */
  7212. function remove(array, predicate) {
  7213. var result = [];
  7214. if (!(array && array.length)) {
  7215. return result;
  7216. }
  7217. var index = -1,
  7218. indexes = [],
  7219. length = array.length;
  7220. predicate = getIteratee(predicate, 3);
  7221. while (++index < length) {
  7222. var value = array[index];
  7223. if (predicate(value, index, array)) {
  7224. result.push(value);
  7225. indexes.push(index);
  7226. }
  7227. }
  7228. basePullAt(array, indexes);
  7229. return result;
  7230. }
  7231. /**
  7232. * Reverses `array` so that the first element becomes the last, the second
  7233. * element becomes the second to last, and so on.
  7234. *
  7235. * **Note:** This method mutates `array` and is based on
  7236. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7237. *
  7238. * @static
  7239. * @memberOf _
  7240. * @since 4.0.0
  7241. * @category Array
  7242. * @param {Array} array The array to modify.
  7243. * @returns {Array} Returns `array`.
  7244. * @example
  7245. *
  7246. * var array = [1, 2, 3];
  7247. *
  7248. * _.reverse(array);
  7249. * // => [3, 2, 1]
  7250. *
  7251. * console.log(array);
  7252. * // => [3, 2, 1]
  7253. */
  7254. function reverse(array) {
  7255. return array == null ? array : nativeReverse.call(array);
  7256. }
  7257. /**
  7258. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7259. *
  7260. * **Note:** This method is used instead of
  7261. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7262. * returned.
  7263. *
  7264. * @static
  7265. * @memberOf _
  7266. * @since 3.0.0
  7267. * @category Array
  7268. * @param {Array} array The array to slice.
  7269. * @param {number} [start=0] The start position.
  7270. * @param {number} [end=array.length] The end position.
  7271. * @returns {Array} Returns the slice of `array`.
  7272. */
  7273. function slice(array, start, end) {
  7274. var length = array == null ? 0 : array.length;
  7275. if (!length) {
  7276. return [];
  7277. }
  7278. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7279. start = 0;
  7280. end = length;
  7281. }
  7282. else {
  7283. start = start == null ? 0 : toInteger(start);
  7284. end = end === undefined ? length : toInteger(end);
  7285. }
  7286. return baseSlice(array, start, end);
  7287. }
  7288. /**
  7289. * Uses a binary search to determine the lowest index at which `value`
  7290. * should be inserted into `array` in order to maintain its sort order.
  7291. *
  7292. * @static
  7293. * @memberOf _
  7294. * @since 0.1.0
  7295. * @category Array
  7296. * @param {Array} array The sorted array to inspect.
  7297. * @param {*} value The value to evaluate.
  7298. * @returns {number} Returns the index at which `value` should be inserted
  7299. * into `array`.
  7300. * @example
  7301. *
  7302. * _.sortedIndex([30, 50], 40);
  7303. * // => 1
  7304. */
  7305. function sortedIndex(array, value) {
  7306. return baseSortedIndex(array, value);
  7307. }
  7308. /**
  7309. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7310. * which is invoked for `value` and each element of `array` to compute their
  7311. * sort ranking. The iteratee is invoked with one argument: (value).
  7312. *
  7313. * @static
  7314. * @memberOf _
  7315. * @since 4.0.0
  7316. * @category Array
  7317. * @param {Array} array The sorted array to inspect.
  7318. * @param {*} value The value to evaluate.
  7319. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7320. * @returns {number} Returns the index at which `value` should be inserted
  7321. * into `array`.
  7322. * @example
  7323. *
  7324. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7325. *
  7326. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7327. * // => 0
  7328. *
  7329. * // The `_.property` iteratee shorthand.
  7330. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7331. * // => 0
  7332. */
  7333. function sortedIndexBy(array, value, iteratee) {
  7334. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7335. }
  7336. /**
  7337. * This method is like `_.indexOf` except that it performs a binary
  7338. * search on a sorted `array`.
  7339. *
  7340. * @static
  7341. * @memberOf _
  7342. * @since 4.0.0
  7343. * @category Array
  7344. * @param {Array} array The array to inspect.
  7345. * @param {*} value The value to search for.
  7346. * @returns {number} Returns the index of the matched value, else `-1`.
  7347. * @example
  7348. *
  7349. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7350. * // => 1
  7351. */
  7352. function sortedIndexOf(array, value) {
  7353. var length = array == null ? 0 : array.length;
  7354. if (length) {
  7355. var index = baseSortedIndex(array, value);
  7356. if (index < length && eq(array[index], value)) {
  7357. return index;
  7358. }
  7359. }
  7360. return -1;
  7361. }
  7362. /**
  7363. * This method is like `_.sortedIndex` except that it returns the highest
  7364. * index at which `value` should be inserted into `array` in order to
  7365. * maintain its sort order.
  7366. *
  7367. * @static
  7368. * @memberOf _
  7369. * @since 3.0.0
  7370. * @category Array
  7371. * @param {Array} array The sorted array to inspect.
  7372. * @param {*} value The value to evaluate.
  7373. * @returns {number} Returns the index at which `value` should be inserted
  7374. * into `array`.
  7375. * @example
  7376. *
  7377. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7378. * // => 4
  7379. */
  7380. function sortedLastIndex(array, value) {
  7381. return baseSortedIndex(array, value, true);
  7382. }
  7383. /**
  7384. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7385. * which is invoked for `value` and each element of `array` to compute their
  7386. * sort ranking. The iteratee is invoked with one argument: (value).
  7387. *
  7388. * @static
  7389. * @memberOf _
  7390. * @since 4.0.0
  7391. * @category Array
  7392. * @param {Array} array The sorted array to inspect.
  7393. * @param {*} value The value to evaluate.
  7394. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7395. * @returns {number} Returns the index at which `value` should be inserted
  7396. * into `array`.
  7397. * @example
  7398. *
  7399. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7400. *
  7401. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7402. * // => 1
  7403. *
  7404. * // The `_.property` iteratee shorthand.
  7405. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7406. * // => 1
  7407. */
  7408. function sortedLastIndexBy(array, value, iteratee) {
  7409. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7410. }
  7411. /**
  7412. * This method is like `_.lastIndexOf` except that it performs a binary
  7413. * search on a sorted `array`.
  7414. *
  7415. * @static
  7416. * @memberOf _
  7417. * @since 4.0.0
  7418. * @category Array
  7419. * @param {Array} array The array to inspect.
  7420. * @param {*} value The value to search for.
  7421. * @returns {number} Returns the index of the matched value, else `-1`.
  7422. * @example
  7423. *
  7424. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7425. * // => 3
  7426. */
  7427. function sortedLastIndexOf(array, value) {
  7428. var length = array == null ? 0 : array.length;
  7429. if (length) {
  7430. var index = baseSortedIndex(array, value, true) - 1;
  7431. if (eq(array[index], value)) {
  7432. return index;
  7433. }
  7434. }
  7435. return -1;
  7436. }
  7437. /**
  7438. * This method is like `_.uniq` except that it's designed and optimized
  7439. * for sorted arrays.
  7440. *
  7441. * @static
  7442. * @memberOf _
  7443. * @since 4.0.0
  7444. * @category Array
  7445. * @param {Array} array The array to inspect.
  7446. * @returns {Array} Returns the new duplicate free array.
  7447. * @example
  7448. *
  7449. * _.sortedUniq([1, 1, 2]);
  7450. * // => [1, 2]
  7451. */
  7452. function sortedUniq(array) {
  7453. return (array && array.length)
  7454. ? baseSortedUniq(array)
  7455. : [];
  7456. }
  7457. /**
  7458. * This method is like `_.uniqBy` except that it's designed and optimized
  7459. * for sorted arrays.
  7460. *
  7461. * @static
  7462. * @memberOf _
  7463. * @since 4.0.0
  7464. * @category Array
  7465. * @param {Array} array The array to inspect.
  7466. * @param {Function} [iteratee] The iteratee invoked per element.
  7467. * @returns {Array} Returns the new duplicate free array.
  7468. * @example
  7469. *
  7470. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7471. * // => [1.1, 2.3]
  7472. */
  7473. function sortedUniqBy(array, iteratee) {
  7474. return (array && array.length)
  7475. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7476. : [];
  7477. }
  7478. /**
  7479. * Gets all but the first element of `array`.
  7480. *
  7481. * @static
  7482. * @memberOf _
  7483. * @since 4.0.0
  7484. * @category Array
  7485. * @param {Array} array The array to query.
  7486. * @returns {Array} Returns the slice of `array`.
  7487. * @example
  7488. *
  7489. * _.tail([1, 2, 3]);
  7490. * // => [2, 3]
  7491. */
  7492. function tail(array) {
  7493. var length = array == null ? 0 : array.length;
  7494. return length ? baseSlice(array, 1, length) : [];
  7495. }
  7496. /**
  7497. * Creates a slice of `array` with `n` elements taken from the beginning.
  7498. *
  7499. * @static
  7500. * @memberOf _
  7501. * @since 0.1.0
  7502. * @category Array
  7503. * @param {Array} array The array to query.
  7504. * @param {number} [n=1] The number of elements to take.
  7505. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7506. * @returns {Array} Returns the slice of `array`.
  7507. * @example
  7508. *
  7509. * _.take([1, 2, 3]);
  7510. * // => [1]
  7511. *
  7512. * _.take([1, 2, 3], 2);
  7513. * // => [1, 2]
  7514. *
  7515. * _.take([1, 2, 3], 5);
  7516. * // => [1, 2, 3]
  7517. *
  7518. * _.take([1, 2, 3], 0);
  7519. * // => []
  7520. */
  7521. function take(array, n, guard) {
  7522. if (!(array && array.length)) {
  7523. return [];
  7524. }
  7525. n = (guard || n === undefined) ? 1 : toInteger(n);
  7526. return baseSlice(array, 0, n < 0 ? 0 : n);
  7527. }
  7528. /**
  7529. * Creates a slice of `array` with `n` elements taken from the end.
  7530. *
  7531. * @static
  7532. * @memberOf _
  7533. * @since 3.0.0
  7534. * @category Array
  7535. * @param {Array} array The array to query.
  7536. * @param {number} [n=1] The number of elements to take.
  7537. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7538. * @returns {Array} Returns the slice of `array`.
  7539. * @example
  7540. *
  7541. * _.takeRight([1, 2, 3]);
  7542. * // => [3]
  7543. *
  7544. * _.takeRight([1, 2, 3], 2);
  7545. * // => [2, 3]
  7546. *
  7547. * _.takeRight([1, 2, 3], 5);
  7548. * // => [1, 2, 3]
  7549. *
  7550. * _.takeRight([1, 2, 3], 0);
  7551. * // => []
  7552. */
  7553. function takeRight(array, n, guard) {
  7554. var length = array == null ? 0 : array.length;
  7555. if (!length) {
  7556. return [];
  7557. }
  7558. n = (guard || n === undefined) ? 1 : toInteger(n);
  7559. n = length - n;
  7560. return baseSlice(array, n < 0 ? 0 : n, length);
  7561. }
  7562. /**
  7563. * Creates a slice of `array` with elements taken from the end. Elements are
  7564. * taken until `predicate` returns falsey. The predicate is invoked with
  7565. * three arguments: (value, index, array).
  7566. *
  7567. * @static
  7568. * @memberOf _
  7569. * @since 3.0.0
  7570. * @category Array
  7571. * @param {Array} array The array to query.
  7572. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7573. * @returns {Array} Returns the slice of `array`.
  7574. * @example
  7575. *
  7576. * var users = [
  7577. * { 'user': 'barney', 'active': true },
  7578. * { 'user': 'fred', 'active': false },
  7579. * { 'user': 'pebbles', 'active': false }
  7580. * ];
  7581. *
  7582. * _.takeRightWhile(users, function(o) { return !o.active; });
  7583. * // => objects for ['fred', 'pebbles']
  7584. *
  7585. * // The `_.matches` iteratee shorthand.
  7586. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7587. * // => objects for ['pebbles']
  7588. *
  7589. * // The `_.matchesProperty` iteratee shorthand.
  7590. * _.takeRightWhile(users, ['active', false]);
  7591. * // => objects for ['fred', 'pebbles']
  7592. *
  7593. * // The `_.property` iteratee shorthand.
  7594. * _.takeRightWhile(users, 'active');
  7595. * // => []
  7596. */
  7597. function takeRightWhile(array, predicate) {
  7598. return (array && array.length)
  7599. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7600. : [];
  7601. }
  7602. /**
  7603. * Creates a slice of `array` with elements taken from the beginning. Elements
  7604. * are taken until `predicate` returns falsey. The predicate is invoked with
  7605. * three arguments: (value, index, array).
  7606. *
  7607. * @static
  7608. * @memberOf _
  7609. * @since 3.0.0
  7610. * @category Array
  7611. * @param {Array} array The array to query.
  7612. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7613. * @returns {Array} Returns the slice of `array`.
  7614. * @example
  7615. *
  7616. * var users = [
  7617. * { 'user': 'barney', 'active': false },
  7618. * { 'user': 'fred', 'active': false },
  7619. * { 'user': 'pebbles', 'active': true }
  7620. * ];
  7621. *
  7622. * _.takeWhile(users, function(o) { return !o.active; });
  7623. * // => objects for ['barney', 'fred']
  7624. *
  7625. * // The `_.matches` iteratee shorthand.
  7626. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7627. * // => objects for ['barney']
  7628. *
  7629. * // The `_.matchesProperty` iteratee shorthand.
  7630. * _.takeWhile(users, ['active', false]);
  7631. * // => objects for ['barney', 'fred']
  7632. *
  7633. * // The `_.property` iteratee shorthand.
  7634. * _.takeWhile(users, 'active');
  7635. * // => []
  7636. */
  7637. function takeWhile(array, predicate) {
  7638. return (array && array.length)
  7639. ? baseWhile(array, getIteratee(predicate, 3))
  7640. : [];
  7641. }
  7642. /**
  7643. * Creates an array of unique values, in order, from all given arrays using
  7644. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7645. * for equality comparisons.
  7646. *
  7647. * @static
  7648. * @memberOf _
  7649. * @since 0.1.0
  7650. * @category Array
  7651. * @param {...Array} [arrays] The arrays to inspect.
  7652. * @returns {Array} Returns the new array of combined values.
  7653. * @example
  7654. *
  7655. * _.union([2], [1, 2]);
  7656. * // => [2, 1]
  7657. */
  7658. var union = baseRest(function(arrays) {
  7659. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7660. });
  7661. /**
  7662. * This method is like `_.union` except that it accepts `iteratee` which is
  7663. * invoked for each element of each `arrays` to generate the criterion by
  7664. * which uniqueness is computed. Result values are chosen from the first
  7665. * array in which the value occurs. The iteratee is invoked with one argument:
  7666. * (value).
  7667. *
  7668. * @static
  7669. * @memberOf _
  7670. * @since 4.0.0
  7671. * @category Array
  7672. * @param {...Array} [arrays] The arrays to inspect.
  7673. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7674. * @returns {Array} Returns the new array of combined values.
  7675. * @example
  7676. *
  7677. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7678. * // => [2.1, 1.2]
  7679. *
  7680. * // The `_.property` iteratee shorthand.
  7681. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7682. * // => [{ 'x': 1 }, { 'x': 2 }]
  7683. */
  7684. var unionBy = baseRest(function(arrays) {
  7685. var iteratee = last(arrays);
  7686. if (isArrayLikeObject(iteratee)) {
  7687. iteratee = undefined;
  7688. }
  7689. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7690. });
  7691. /**
  7692. * This method is like `_.union` except that it accepts `comparator` which
  7693. * is invoked to compare elements of `arrays`. Result values are chosen from
  7694. * the first array in which the value occurs. The comparator is invoked
  7695. * with two arguments: (arrVal, othVal).
  7696. *
  7697. * @static
  7698. * @memberOf _
  7699. * @since 4.0.0
  7700. * @category Array
  7701. * @param {...Array} [arrays] The arrays to inspect.
  7702. * @param {Function} [comparator] The comparator invoked per element.
  7703. * @returns {Array} Returns the new array of combined values.
  7704. * @example
  7705. *
  7706. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7707. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7708. *
  7709. * _.unionWith(objects, others, _.isEqual);
  7710. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7711. */
  7712. var unionWith = baseRest(function(arrays) {
  7713. var comparator = last(arrays);
  7714. comparator = typeof comparator == 'function' ? comparator : undefined;
  7715. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7716. });
  7717. /**
  7718. * Creates a duplicate-free version of an array, using
  7719. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7720. * for equality comparisons, in which only the first occurrence of each element
  7721. * is kept. The order of result values is determined by the order they occur
  7722. * in the array.
  7723. *
  7724. * @static
  7725. * @memberOf _
  7726. * @since 0.1.0
  7727. * @category Array
  7728. * @param {Array} array The array to inspect.
  7729. * @returns {Array} Returns the new duplicate free array.
  7730. * @example
  7731. *
  7732. * _.uniq([2, 1, 2]);
  7733. * // => [2, 1]
  7734. */
  7735. function uniq(array) {
  7736. return (array && array.length) ? baseUniq(array) : [];
  7737. }
  7738. /**
  7739. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7740. * invoked for each element in `array` to generate the criterion by which
  7741. * uniqueness is computed. The order of result values is determined by the
  7742. * order they occur in the array. The iteratee is invoked with one argument:
  7743. * (value).
  7744. *
  7745. * @static
  7746. * @memberOf _
  7747. * @since 4.0.0
  7748. * @category Array
  7749. * @param {Array} array The array to inspect.
  7750. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7751. * @returns {Array} Returns the new duplicate free array.
  7752. * @example
  7753. *
  7754. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7755. * // => [2.1, 1.2]
  7756. *
  7757. * // The `_.property` iteratee shorthand.
  7758. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7759. * // => [{ 'x': 1 }, { 'x': 2 }]
  7760. */
  7761. function uniqBy(array, iteratee) {
  7762. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7763. }
  7764. /**
  7765. * This method is like `_.uniq` except that it accepts `comparator` which
  7766. * is invoked to compare elements of `array`. The order of result values is
  7767. * determined by the order they occur in the array.The comparator is invoked
  7768. * with two arguments: (arrVal, othVal).
  7769. *
  7770. * @static
  7771. * @memberOf _
  7772. * @since 4.0.0
  7773. * @category Array
  7774. * @param {Array} array The array to inspect.
  7775. * @param {Function} [comparator] The comparator invoked per element.
  7776. * @returns {Array} Returns the new duplicate free array.
  7777. * @example
  7778. *
  7779. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7780. *
  7781. * _.uniqWith(objects, _.isEqual);
  7782. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7783. */
  7784. function uniqWith(array, comparator) {
  7785. comparator = typeof comparator == 'function' ? comparator : undefined;
  7786. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7787. }
  7788. /**
  7789. * This method is like `_.zip` except that it accepts an array of grouped
  7790. * elements and creates an array regrouping the elements to their pre-zip
  7791. * configuration.
  7792. *
  7793. * @static
  7794. * @memberOf _
  7795. * @since 1.2.0
  7796. * @category Array
  7797. * @param {Array} array The array of grouped elements to process.
  7798. * @returns {Array} Returns the new array of regrouped elements.
  7799. * @example
  7800. *
  7801. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7802. * // => [['a', 1, true], ['b', 2, false]]
  7803. *
  7804. * _.unzip(zipped);
  7805. * // => [['a', 'b'], [1, 2], [true, false]]
  7806. */
  7807. function unzip(array) {
  7808. if (!(array && array.length)) {
  7809. return [];
  7810. }
  7811. var length = 0;
  7812. array = arrayFilter(array, function(group) {
  7813. if (isArrayLikeObject(group)) {
  7814. length = nativeMax(group.length, length);
  7815. return true;
  7816. }
  7817. });
  7818. return baseTimes(length, function(index) {
  7819. return arrayMap(array, baseProperty(index));
  7820. });
  7821. }
  7822. /**
  7823. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7824. * how regrouped values should be combined. The iteratee is invoked with the
  7825. * elements of each group: (...group).
  7826. *
  7827. * @static
  7828. * @memberOf _
  7829. * @since 3.8.0
  7830. * @category Array
  7831. * @param {Array} array The array of grouped elements to process.
  7832. * @param {Function} [iteratee=_.identity] The function to combine
  7833. * regrouped values.
  7834. * @returns {Array} Returns the new array of regrouped elements.
  7835. * @example
  7836. *
  7837. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7838. * // => [[1, 10, 100], [2, 20, 200]]
  7839. *
  7840. * _.unzipWith(zipped, _.add);
  7841. * // => [3, 30, 300]
  7842. */
  7843. function unzipWith(array, iteratee) {
  7844. if (!(array && array.length)) {
  7845. return [];
  7846. }
  7847. var result = unzip(array);
  7848. if (iteratee == null) {
  7849. return result;
  7850. }
  7851. return arrayMap(result, function(group) {
  7852. return apply(iteratee, undefined, group);
  7853. });
  7854. }
  7855. /**
  7856. * Creates an array excluding all given values using
  7857. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7858. * for equality comparisons.
  7859. *
  7860. * **Note:** Unlike `_.pull`, this method returns a new array.
  7861. *
  7862. * @static
  7863. * @memberOf _
  7864. * @since 0.1.0
  7865. * @category Array
  7866. * @param {Array} array The array to inspect.
  7867. * @param {...*} [values] The values to exclude.
  7868. * @returns {Array} Returns the new array of filtered values.
  7869. * @see _.difference, _.xor
  7870. * @example
  7871. *
  7872. * _.without([2, 1, 2, 3], 1, 2);
  7873. * // => [3]
  7874. */
  7875. var without = baseRest(function(array, values) {
  7876. return isArrayLikeObject(array)
  7877. ? baseDifference(array, values)
  7878. : [];
  7879. });
  7880. /**
  7881. * Creates an array of unique values that is the
  7882. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7883. * of the given arrays. The order of result values is determined by the order
  7884. * they occur in the arrays.
  7885. *
  7886. * @static
  7887. * @memberOf _
  7888. * @since 2.4.0
  7889. * @category Array
  7890. * @param {...Array} [arrays] The arrays to inspect.
  7891. * @returns {Array} Returns the new array of filtered values.
  7892. * @see _.difference, _.without
  7893. * @example
  7894. *
  7895. * _.xor([2, 1], [2, 3]);
  7896. * // => [1, 3]
  7897. */
  7898. var xor = baseRest(function(arrays) {
  7899. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7900. });
  7901. /**
  7902. * This method is like `_.xor` except that it accepts `iteratee` which is
  7903. * invoked for each element of each `arrays` to generate the criterion by
  7904. * which by which they're compared. The order of result values is determined
  7905. * by the order they occur in the arrays. The iteratee is invoked with one
  7906. * argument: (value).
  7907. *
  7908. * @static
  7909. * @memberOf _
  7910. * @since 4.0.0
  7911. * @category Array
  7912. * @param {...Array} [arrays] The arrays to inspect.
  7913. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7914. * @returns {Array} Returns the new array of filtered values.
  7915. * @example
  7916. *
  7917. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7918. * // => [1.2, 3.4]
  7919. *
  7920. * // The `_.property` iteratee shorthand.
  7921. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7922. * // => [{ 'x': 2 }]
  7923. */
  7924. var xorBy = baseRest(function(arrays) {
  7925. var iteratee = last(arrays);
  7926. if (isArrayLikeObject(iteratee)) {
  7927. iteratee = undefined;
  7928. }
  7929. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7930. });
  7931. /**
  7932. * This method is like `_.xor` except that it accepts `comparator` which is
  7933. * invoked to compare elements of `arrays`. The order of result values is
  7934. * determined by the order they occur in the arrays. The comparator is invoked
  7935. * with two arguments: (arrVal, othVal).
  7936. *
  7937. * @static
  7938. * @memberOf _
  7939. * @since 4.0.0
  7940. * @category Array
  7941. * @param {...Array} [arrays] The arrays to inspect.
  7942. * @param {Function} [comparator] The comparator invoked per element.
  7943. * @returns {Array} Returns the new array of filtered values.
  7944. * @example
  7945. *
  7946. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7947. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7948. *
  7949. * _.xorWith(objects, others, _.isEqual);
  7950. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7951. */
  7952. var xorWith = baseRest(function(arrays) {
  7953. var comparator = last(arrays);
  7954. comparator = typeof comparator == 'function' ? comparator : undefined;
  7955. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7956. });
  7957. /**
  7958. * Creates an array of grouped elements, the first of which contains the
  7959. * first elements of the given arrays, the second of which contains the
  7960. * second elements of the given arrays, and so on.
  7961. *
  7962. * @static
  7963. * @memberOf _
  7964. * @since 0.1.0
  7965. * @category Array
  7966. * @param {...Array} [arrays] The arrays to process.
  7967. * @returns {Array} Returns the new array of grouped elements.
  7968. * @example
  7969. *
  7970. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7971. * // => [['a', 1, true], ['b', 2, false]]
  7972. */
  7973. var zip = baseRest(unzip);
  7974. /**
  7975. * This method is like `_.fromPairs` except that it accepts two arrays,
  7976. * one of property identifiers and one of corresponding values.
  7977. *
  7978. * @static
  7979. * @memberOf _
  7980. * @since 0.4.0
  7981. * @category Array
  7982. * @param {Array} [props=[]] The property identifiers.
  7983. * @param {Array} [values=[]] The property values.
  7984. * @returns {Object} Returns the new object.
  7985. * @example
  7986. *
  7987. * _.zipObject(['a', 'b'], [1, 2]);
  7988. * // => { 'a': 1, 'b': 2 }
  7989. */
  7990. function zipObject(props, values) {
  7991. return baseZipObject(props || [], values || [], assignValue);
  7992. }
  7993. /**
  7994. * This method is like `_.zipObject` except that it supports property paths.
  7995. *
  7996. * @static
  7997. * @memberOf _
  7998. * @since 4.1.0
  7999. * @category Array
  8000. * @param {Array} [props=[]] The property identifiers.
  8001. * @param {Array} [values=[]] The property values.
  8002. * @returns {Object} Returns the new object.
  8003. * @example
  8004. *
  8005. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8006. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8007. */
  8008. function zipObjectDeep(props, values) {
  8009. return baseZipObject(props || [], values || [], baseSet);
  8010. }
  8011. /**
  8012. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8013. * how grouped values should be combined. The iteratee is invoked with the
  8014. * elements of each group: (...group).
  8015. *
  8016. * @static
  8017. * @memberOf _
  8018. * @since 3.8.0
  8019. * @category Array
  8020. * @param {...Array} [arrays] The arrays to process.
  8021. * @param {Function} [iteratee=_.identity] The function to combine
  8022. * grouped values.
  8023. * @returns {Array} Returns the new array of grouped elements.
  8024. * @example
  8025. *
  8026. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8027. * return a + b + c;
  8028. * });
  8029. * // => [111, 222]
  8030. */
  8031. var zipWith = baseRest(function(arrays) {
  8032. var length = arrays.length,
  8033. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8034. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8035. return unzipWith(arrays, iteratee);
  8036. });
  8037. /*------------------------------------------------------------------------*/
  8038. /**
  8039. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8040. * chain sequences enabled. The result of such sequences must be unwrapped
  8041. * with `_#value`.
  8042. *
  8043. * @static
  8044. * @memberOf _
  8045. * @since 1.3.0
  8046. * @category Seq
  8047. * @param {*} value The value to wrap.
  8048. * @returns {Object} Returns the new `lodash` wrapper instance.
  8049. * @example
  8050. *
  8051. * var users = [
  8052. * { 'user': 'barney', 'age': 36 },
  8053. * { 'user': 'fred', 'age': 40 },
  8054. * { 'user': 'pebbles', 'age': 1 }
  8055. * ];
  8056. *
  8057. * var youngest = _
  8058. * .chain(users)
  8059. * .sortBy('age')
  8060. * .map(function(o) {
  8061. * return o.user + ' is ' + o.age;
  8062. * })
  8063. * .head()
  8064. * .value();
  8065. * // => 'pebbles is 1'
  8066. */
  8067. function chain(value) {
  8068. var result = lodash(value);
  8069. result.__chain__ = true;
  8070. return result;
  8071. }
  8072. /**
  8073. * This method invokes `interceptor` and returns `value`. The interceptor
  8074. * is invoked with one argument; (value). The purpose of this method is to
  8075. * "tap into" a method chain sequence in order to modify intermediate results.
  8076. *
  8077. * @static
  8078. * @memberOf _
  8079. * @since 0.1.0
  8080. * @category Seq
  8081. * @param {*} value The value to provide to `interceptor`.
  8082. * @param {Function} interceptor The function to invoke.
  8083. * @returns {*} Returns `value`.
  8084. * @example
  8085. *
  8086. * _([1, 2, 3])
  8087. * .tap(function(array) {
  8088. * // Mutate input array.
  8089. * array.pop();
  8090. * })
  8091. * .reverse()
  8092. * .value();
  8093. * // => [2, 1]
  8094. */
  8095. function tap(value, interceptor) {
  8096. interceptor(value);
  8097. return value;
  8098. }
  8099. /**
  8100. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8101. * The purpose of this method is to "pass thru" values replacing intermediate
  8102. * results in a method chain sequence.
  8103. *
  8104. * @static
  8105. * @memberOf _
  8106. * @since 3.0.0
  8107. * @category Seq
  8108. * @param {*} value The value to provide to `interceptor`.
  8109. * @param {Function} interceptor The function to invoke.
  8110. * @returns {*} Returns the result of `interceptor`.
  8111. * @example
  8112. *
  8113. * _(' abc ')
  8114. * .chain()
  8115. * .trim()
  8116. * .thru(function(value) {
  8117. * return [value];
  8118. * })
  8119. * .value();
  8120. * // => ['abc']
  8121. */
  8122. function thru(value, interceptor) {
  8123. return interceptor(value);
  8124. }
  8125. /**
  8126. * This method is the wrapper version of `_.at`.
  8127. *
  8128. * @name at
  8129. * @memberOf _
  8130. * @since 1.0.0
  8131. * @category Seq
  8132. * @param {...(string|string[])} [paths] The property paths to pick.
  8133. * @returns {Object} Returns the new `lodash` wrapper instance.
  8134. * @example
  8135. *
  8136. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8137. *
  8138. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8139. * // => [3, 4]
  8140. */
  8141. var wrapperAt = flatRest(function(paths) {
  8142. var length = paths.length,
  8143. start = length ? paths[0] : 0,
  8144. value = this.__wrapped__,
  8145. interceptor = function(object) { return baseAt(object, paths); };
  8146. if (length > 1 || this.__actions__.length ||
  8147. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8148. return this.thru(interceptor);
  8149. }
  8150. value = value.slice(start, +start + (length ? 1 : 0));
  8151. value.__actions__.push({
  8152. 'func': thru,
  8153. 'args': [interceptor],
  8154. 'thisArg': undefined
  8155. });
  8156. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8157. if (length && !array.length) {
  8158. array.push(undefined);
  8159. }
  8160. return array;
  8161. });
  8162. });
  8163. /**
  8164. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8165. *
  8166. * @name chain
  8167. * @memberOf _
  8168. * @since 0.1.0
  8169. * @category Seq
  8170. * @returns {Object} Returns the new `lodash` wrapper instance.
  8171. * @example
  8172. *
  8173. * var users = [
  8174. * { 'user': 'barney', 'age': 36 },
  8175. * { 'user': 'fred', 'age': 40 }
  8176. * ];
  8177. *
  8178. * // A sequence without explicit chaining.
  8179. * _(users).head();
  8180. * // => { 'user': 'barney', 'age': 36 }
  8181. *
  8182. * // A sequence with explicit chaining.
  8183. * _(users)
  8184. * .chain()
  8185. * .head()
  8186. * .pick('user')
  8187. * .value();
  8188. * // => { 'user': 'barney' }
  8189. */
  8190. function wrapperChain() {
  8191. return chain(this);
  8192. }
  8193. /**
  8194. * Executes the chain sequence and returns the wrapped result.
  8195. *
  8196. * @name commit
  8197. * @memberOf _
  8198. * @since 3.2.0
  8199. * @category Seq
  8200. * @returns {Object} Returns the new `lodash` wrapper instance.
  8201. * @example
  8202. *
  8203. * var array = [1, 2];
  8204. * var wrapped = _(array).push(3);
  8205. *
  8206. * console.log(array);
  8207. * // => [1, 2]
  8208. *
  8209. * wrapped = wrapped.commit();
  8210. * console.log(array);
  8211. * // => [1, 2, 3]
  8212. *
  8213. * wrapped.last();
  8214. * // => 3
  8215. *
  8216. * console.log(array);
  8217. * // => [1, 2, 3]
  8218. */
  8219. function wrapperCommit() {
  8220. return new LodashWrapper(this.value(), this.__chain__);
  8221. }
  8222. /**
  8223. * Gets the next value on a wrapped object following the
  8224. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8225. *
  8226. * @name next
  8227. * @memberOf _
  8228. * @since 4.0.0
  8229. * @category Seq
  8230. * @returns {Object} Returns the next iterator value.
  8231. * @example
  8232. *
  8233. * var wrapped = _([1, 2]);
  8234. *
  8235. * wrapped.next();
  8236. * // => { 'done': false, 'value': 1 }
  8237. *
  8238. * wrapped.next();
  8239. * // => { 'done': false, 'value': 2 }
  8240. *
  8241. * wrapped.next();
  8242. * // => { 'done': true, 'value': undefined }
  8243. */
  8244. function wrapperNext() {
  8245. if (this.__values__ === undefined) {
  8246. this.__values__ = toArray(this.value());
  8247. }
  8248. var done = this.__index__ >= this.__values__.length,
  8249. value = done ? undefined : this.__values__[this.__index__++];
  8250. return { 'done': done, 'value': value };
  8251. }
  8252. /**
  8253. * Enables the wrapper to be iterable.
  8254. *
  8255. * @name Symbol.iterator
  8256. * @memberOf _
  8257. * @since 4.0.0
  8258. * @category Seq
  8259. * @returns {Object} Returns the wrapper object.
  8260. * @example
  8261. *
  8262. * var wrapped = _([1, 2]);
  8263. *
  8264. * wrapped[Symbol.iterator]() === wrapped;
  8265. * // => true
  8266. *
  8267. * Array.from(wrapped);
  8268. * // => [1, 2]
  8269. */
  8270. function wrapperToIterator() {
  8271. return this;
  8272. }
  8273. /**
  8274. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8275. *
  8276. * @name plant
  8277. * @memberOf _
  8278. * @since 3.2.0
  8279. * @category Seq
  8280. * @param {*} value The value to plant.
  8281. * @returns {Object} Returns the new `lodash` wrapper instance.
  8282. * @example
  8283. *
  8284. * function square(n) {
  8285. * return n * n;
  8286. * }
  8287. *
  8288. * var wrapped = _([1, 2]).map(square);
  8289. * var other = wrapped.plant([3, 4]);
  8290. *
  8291. * other.value();
  8292. * // => [9, 16]
  8293. *
  8294. * wrapped.value();
  8295. * // => [1, 4]
  8296. */
  8297. function wrapperPlant(value) {
  8298. var result,
  8299. parent = this;
  8300. while (parent instanceof baseLodash) {
  8301. var clone = wrapperClone(parent);
  8302. clone.__index__ = 0;
  8303. clone.__values__ = undefined;
  8304. if (result) {
  8305. previous.__wrapped__ = clone;
  8306. } else {
  8307. result = clone;
  8308. }
  8309. var previous = clone;
  8310. parent = parent.__wrapped__;
  8311. }
  8312. previous.__wrapped__ = value;
  8313. return result;
  8314. }
  8315. /**
  8316. * This method is the wrapper version of `_.reverse`.
  8317. *
  8318. * **Note:** This method mutates the wrapped array.
  8319. *
  8320. * @name reverse
  8321. * @memberOf _
  8322. * @since 0.1.0
  8323. * @category Seq
  8324. * @returns {Object} Returns the new `lodash` wrapper instance.
  8325. * @example
  8326. *
  8327. * var array = [1, 2, 3];
  8328. *
  8329. * _(array).reverse().value()
  8330. * // => [3, 2, 1]
  8331. *
  8332. * console.log(array);
  8333. * // => [3, 2, 1]
  8334. */
  8335. function wrapperReverse() {
  8336. var value = this.__wrapped__;
  8337. if (value instanceof LazyWrapper) {
  8338. var wrapped = value;
  8339. if (this.__actions__.length) {
  8340. wrapped = new LazyWrapper(this);
  8341. }
  8342. wrapped = wrapped.reverse();
  8343. wrapped.__actions__.push({
  8344. 'func': thru,
  8345. 'args': [reverse],
  8346. 'thisArg': undefined
  8347. });
  8348. return new LodashWrapper(wrapped, this.__chain__);
  8349. }
  8350. return this.thru(reverse);
  8351. }
  8352. /**
  8353. * Executes the chain sequence to resolve the unwrapped value.
  8354. *
  8355. * @name value
  8356. * @memberOf _
  8357. * @since 0.1.0
  8358. * @alias toJSON, valueOf
  8359. * @category Seq
  8360. * @returns {*} Returns the resolved unwrapped value.
  8361. * @example
  8362. *
  8363. * _([1, 2, 3]).value();
  8364. * // => [1, 2, 3]
  8365. */
  8366. function wrapperValue() {
  8367. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8368. }
  8369. /*------------------------------------------------------------------------*/
  8370. /**
  8371. * Creates an object composed of keys generated from the results of running
  8372. * each element of `collection` thru `iteratee`. The corresponding value of
  8373. * each key is the number of times the key was returned by `iteratee`. The
  8374. * iteratee is invoked with one argument: (value).
  8375. *
  8376. * @static
  8377. * @memberOf _
  8378. * @since 0.5.0
  8379. * @category Collection
  8380. * @param {Array|Object} collection The collection to iterate over.
  8381. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8382. * @returns {Object} Returns the composed aggregate object.
  8383. * @example
  8384. *
  8385. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8386. * // => { '4': 1, '6': 2 }
  8387. *
  8388. * // The `_.property` iteratee shorthand.
  8389. * _.countBy(['one', 'two', 'three'], 'length');
  8390. * // => { '3': 2, '5': 1 }
  8391. */
  8392. var countBy = createAggregator(function(result, value, key) {
  8393. if (hasOwnProperty.call(result, key)) {
  8394. ++result[key];
  8395. } else {
  8396. baseAssignValue(result, key, 1);
  8397. }
  8398. });
  8399. /**
  8400. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8401. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8402. * invoked with three arguments: (value, index|key, collection).
  8403. *
  8404. * **Note:** This method returns `true` for
  8405. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8406. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8407. * elements of empty collections.
  8408. *
  8409. * @static
  8410. * @memberOf _
  8411. * @since 0.1.0
  8412. * @category Collection
  8413. * @param {Array|Object} collection The collection to iterate over.
  8414. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8415. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8416. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8417. * else `false`.
  8418. * @example
  8419. *
  8420. * _.every([true, 1, null, 'yes'], Boolean);
  8421. * // => false
  8422. *
  8423. * var users = [
  8424. * { 'user': 'barney', 'age': 36, 'active': false },
  8425. * { 'user': 'fred', 'age': 40, 'active': false }
  8426. * ];
  8427. *
  8428. * // The `_.matches` iteratee shorthand.
  8429. * _.every(users, { 'user': 'barney', 'active': false });
  8430. * // => false
  8431. *
  8432. * // The `_.matchesProperty` iteratee shorthand.
  8433. * _.every(users, ['active', false]);
  8434. * // => true
  8435. *
  8436. * // The `_.property` iteratee shorthand.
  8437. * _.every(users, 'active');
  8438. * // => false
  8439. */
  8440. function every(collection, predicate, guard) {
  8441. var func = isArray(collection) ? arrayEvery : baseEvery;
  8442. if (guard && isIterateeCall(collection, predicate, guard)) {
  8443. predicate = undefined;
  8444. }
  8445. return func(collection, getIteratee(predicate, 3));
  8446. }
  8447. /**
  8448. * Iterates over elements of `collection`, returning an array of all elements
  8449. * `predicate` returns truthy for. The predicate is invoked with three
  8450. * arguments: (value, index|key, collection).
  8451. *
  8452. * **Note:** Unlike `_.remove`, this method returns a new array.
  8453. *
  8454. * @static
  8455. * @memberOf _
  8456. * @since 0.1.0
  8457. * @category Collection
  8458. * @param {Array|Object} collection The collection to iterate over.
  8459. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8460. * @returns {Array} Returns the new filtered array.
  8461. * @see _.reject
  8462. * @example
  8463. *
  8464. * var users = [
  8465. * { 'user': 'barney', 'age': 36, 'active': true },
  8466. * { 'user': 'fred', 'age': 40, 'active': false }
  8467. * ];
  8468. *
  8469. * _.filter(users, function(o) { return !o.active; });
  8470. * // => objects for ['fred']
  8471. *
  8472. * // The `_.matches` iteratee shorthand.
  8473. * _.filter(users, { 'age': 36, 'active': true });
  8474. * // => objects for ['barney']
  8475. *
  8476. * // The `_.matchesProperty` iteratee shorthand.
  8477. * _.filter(users, ['active', false]);
  8478. * // => objects for ['fred']
  8479. *
  8480. * // The `_.property` iteratee shorthand.
  8481. * _.filter(users, 'active');
  8482. * // => objects for ['barney']
  8483. */
  8484. function filter(collection, predicate) {
  8485. var func = isArray(collection) ? arrayFilter : baseFilter;
  8486. return func(collection, getIteratee(predicate, 3));
  8487. }
  8488. /**
  8489. * Iterates over elements of `collection`, returning the first element
  8490. * `predicate` returns truthy for. The predicate is invoked with three
  8491. * arguments: (value, index|key, collection).
  8492. *
  8493. * @static
  8494. * @memberOf _
  8495. * @since 0.1.0
  8496. * @category Collection
  8497. * @param {Array|Object} collection The collection to inspect.
  8498. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8499. * @param {number} [fromIndex=0] The index to search from.
  8500. * @returns {*} Returns the matched element, else `undefined`.
  8501. * @example
  8502. *
  8503. * var users = [
  8504. * { 'user': 'barney', 'age': 36, 'active': true },
  8505. * { 'user': 'fred', 'age': 40, 'active': false },
  8506. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8507. * ];
  8508. *
  8509. * _.find(users, function(o) { return o.age < 40; });
  8510. * // => object for 'barney'
  8511. *
  8512. * // The `_.matches` iteratee shorthand.
  8513. * _.find(users, { 'age': 1, 'active': true });
  8514. * // => object for 'pebbles'
  8515. *
  8516. * // The `_.matchesProperty` iteratee shorthand.
  8517. * _.find(users, ['active', false]);
  8518. * // => object for 'fred'
  8519. *
  8520. * // The `_.property` iteratee shorthand.
  8521. * _.find(users, 'active');
  8522. * // => object for 'barney'
  8523. */
  8524. var find = createFind(findIndex);
  8525. /**
  8526. * This method is like `_.find` except that it iterates over elements of
  8527. * `collection` from right to left.
  8528. *
  8529. * @static
  8530. * @memberOf _
  8531. * @since 2.0.0
  8532. * @category Collection
  8533. * @param {Array|Object} collection The collection to inspect.
  8534. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8535. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8536. * @returns {*} Returns the matched element, else `undefined`.
  8537. * @example
  8538. *
  8539. * _.findLast([1, 2, 3, 4], function(n) {
  8540. * return n % 2 == 1;
  8541. * });
  8542. * // => 3
  8543. */
  8544. var findLast = createFind(findLastIndex);
  8545. /**
  8546. * Creates a flattened array of values by running each element in `collection`
  8547. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8548. * with three arguments: (value, index|key, collection).
  8549. *
  8550. * @static
  8551. * @memberOf _
  8552. * @since 4.0.0
  8553. * @category Collection
  8554. * @param {Array|Object} collection The collection to iterate over.
  8555. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8556. * @returns {Array} Returns the new flattened array.
  8557. * @example
  8558. *
  8559. * function duplicate(n) {
  8560. * return [n, n];
  8561. * }
  8562. *
  8563. * _.flatMap([1, 2], duplicate);
  8564. * // => [1, 1, 2, 2]
  8565. */
  8566. function flatMap(collection, iteratee) {
  8567. return baseFlatten(map(collection, iteratee), 1);
  8568. }
  8569. /**
  8570. * This method is like `_.flatMap` except that it recursively flattens the
  8571. * mapped results.
  8572. *
  8573. * @static
  8574. * @memberOf _
  8575. * @since 4.7.0
  8576. * @category Collection
  8577. * @param {Array|Object} collection The collection to iterate over.
  8578. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8579. * @returns {Array} Returns the new flattened array.
  8580. * @example
  8581. *
  8582. * function duplicate(n) {
  8583. * return [[[n, n]]];
  8584. * }
  8585. *
  8586. * _.flatMapDeep([1, 2], duplicate);
  8587. * // => [1, 1, 2, 2]
  8588. */
  8589. function flatMapDeep(collection, iteratee) {
  8590. return baseFlatten(map(collection, iteratee), INFINITY);
  8591. }
  8592. /**
  8593. * This method is like `_.flatMap` except that it recursively flattens the
  8594. * mapped results up to `depth` times.
  8595. *
  8596. * @static
  8597. * @memberOf _
  8598. * @since 4.7.0
  8599. * @category Collection
  8600. * @param {Array|Object} collection The collection to iterate over.
  8601. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8602. * @param {number} [depth=1] The maximum recursion depth.
  8603. * @returns {Array} Returns the new flattened array.
  8604. * @example
  8605. *
  8606. * function duplicate(n) {
  8607. * return [[[n, n]]];
  8608. * }
  8609. *
  8610. * _.flatMapDepth([1, 2], duplicate, 2);
  8611. * // => [[1, 1], [2, 2]]
  8612. */
  8613. function flatMapDepth(collection, iteratee, depth) {
  8614. depth = depth === undefined ? 1 : toInteger(depth);
  8615. return baseFlatten(map(collection, iteratee), depth);
  8616. }
  8617. /**
  8618. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8619. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8620. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8621. *
  8622. * **Note:** As with other "Collections" methods, objects with a "length"
  8623. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8624. * or `_.forOwn` for object iteration.
  8625. *
  8626. * @static
  8627. * @memberOf _
  8628. * @since 0.1.0
  8629. * @alias each
  8630. * @category Collection
  8631. * @param {Array|Object} collection The collection to iterate over.
  8632. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8633. * @returns {Array|Object} Returns `collection`.
  8634. * @see _.forEachRight
  8635. * @example
  8636. *
  8637. * _.forEach([1, 2], function(value) {
  8638. * console.log(value);
  8639. * });
  8640. * // => Logs `1` then `2`.
  8641. *
  8642. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8643. * console.log(key);
  8644. * });
  8645. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8646. */
  8647. function forEach(collection, iteratee) {
  8648. var func = isArray(collection) ? arrayEach : baseEach;
  8649. return func(collection, getIteratee(iteratee, 3));
  8650. }
  8651. /**
  8652. * This method is like `_.forEach` except that it iterates over elements of
  8653. * `collection` from right to left.
  8654. *
  8655. * @static
  8656. * @memberOf _
  8657. * @since 2.0.0
  8658. * @alias eachRight
  8659. * @category Collection
  8660. * @param {Array|Object} collection The collection to iterate over.
  8661. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8662. * @returns {Array|Object} Returns `collection`.
  8663. * @see _.forEach
  8664. * @example
  8665. *
  8666. * _.forEachRight([1, 2], function(value) {
  8667. * console.log(value);
  8668. * });
  8669. * // => Logs `2` then `1`.
  8670. */
  8671. function forEachRight(collection, iteratee) {
  8672. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8673. return func(collection, getIteratee(iteratee, 3));
  8674. }
  8675. /**
  8676. * Creates an object composed of keys generated from the results of running
  8677. * each element of `collection` thru `iteratee`. The order of grouped values
  8678. * is determined by the order they occur in `collection`. The corresponding
  8679. * value of each key is an array of elements responsible for generating the
  8680. * key. The iteratee is invoked with one argument: (value).
  8681. *
  8682. * @static
  8683. * @memberOf _
  8684. * @since 0.1.0
  8685. * @category Collection
  8686. * @param {Array|Object} collection The collection to iterate over.
  8687. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8688. * @returns {Object} Returns the composed aggregate object.
  8689. * @example
  8690. *
  8691. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8692. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8693. *
  8694. * // The `_.property` iteratee shorthand.
  8695. * _.groupBy(['one', 'two', 'three'], 'length');
  8696. * // => { '3': ['one', 'two'], '5': ['three'] }
  8697. */
  8698. var groupBy = createAggregator(function(result, value, key) {
  8699. if (hasOwnProperty.call(result, key)) {
  8700. result[key].push(value);
  8701. } else {
  8702. baseAssignValue(result, key, [value]);
  8703. }
  8704. });
  8705. /**
  8706. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8707. * checked for a substring of `value`, otherwise
  8708. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8709. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8710. * the offset from the end of `collection`.
  8711. *
  8712. * @static
  8713. * @memberOf _
  8714. * @since 0.1.0
  8715. * @category Collection
  8716. * @param {Array|Object|string} collection The collection to inspect.
  8717. * @param {*} value The value to search for.
  8718. * @param {number} [fromIndex=0] The index to search from.
  8719. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8720. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8721. * @example
  8722. *
  8723. * _.includes([1, 2, 3], 1);
  8724. * // => true
  8725. *
  8726. * _.includes([1, 2, 3], 1, 2);
  8727. * // => false
  8728. *
  8729. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8730. * // => true
  8731. *
  8732. * _.includes('abcd', 'bc');
  8733. * // => true
  8734. */
  8735. function includes(collection, value, fromIndex, guard) {
  8736. collection = isArrayLike(collection) ? collection : values(collection);
  8737. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8738. var length = collection.length;
  8739. if (fromIndex < 0) {
  8740. fromIndex = nativeMax(length + fromIndex, 0);
  8741. }
  8742. return isString(collection)
  8743. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8744. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8745. }
  8746. /**
  8747. * Invokes the method at `path` of each element in `collection`, returning
  8748. * an array of the results of each invoked method. Any additional arguments
  8749. * are provided to each invoked method. If `path` is a function, it's invoked
  8750. * for, and `this` bound to, each element in `collection`.
  8751. *
  8752. * @static
  8753. * @memberOf _
  8754. * @since 4.0.0
  8755. * @category Collection
  8756. * @param {Array|Object} collection The collection to iterate over.
  8757. * @param {Array|Function|string} path The path of the method to invoke or
  8758. * the function invoked per iteration.
  8759. * @param {...*} [args] The arguments to invoke each method with.
  8760. * @returns {Array} Returns the array of results.
  8761. * @example
  8762. *
  8763. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8764. * // => [[1, 5, 7], [1, 2, 3]]
  8765. *
  8766. * _.invokeMap([123, 456], String.prototype.split, '');
  8767. * // => [['1', '2', '3'], ['4', '5', '6']]
  8768. */
  8769. var invokeMap = baseRest(function(collection, path, args) {
  8770. var index = -1,
  8771. isFunc = typeof path == 'function',
  8772. result = isArrayLike(collection) ? Array(collection.length) : [];
  8773. baseEach(collection, function(value) {
  8774. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8775. });
  8776. return result;
  8777. });
  8778. /**
  8779. * Creates an object composed of keys generated from the results of running
  8780. * each element of `collection` thru `iteratee`. The corresponding value of
  8781. * each key is the last element responsible for generating the key. The
  8782. * iteratee is invoked with one argument: (value).
  8783. *
  8784. * @static
  8785. * @memberOf _
  8786. * @since 4.0.0
  8787. * @category Collection
  8788. * @param {Array|Object} collection The collection to iterate over.
  8789. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8790. * @returns {Object} Returns the composed aggregate object.
  8791. * @example
  8792. *
  8793. * var array = [
  8794. * { 'dir': 'left', 'code': 97 },
  8795. * { 'dir': 'right', 'code': 100 }
  8796. * ];
  8797. *
  8798. * _.keyBy(array, function(o) {
  8799. * return String.fromCharCode(o.code);
  8800. * });
  8801. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8802. *
  8803. * _.keyBy(array, 'dir');
  8804. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8805. */
  8806. var keyBy = createAggregator(function(result, value, key) {
  8807. baseAssignValue(result, key, value);
  8808. });
  8809. /**
  8810. * Creates an array of values by running each element in `collection` thru
  8811. * `iteratee`. The iteratee is invoked with three arguments:
  8812. * (value, index|key, collection).
  8813. *
  8814. * Many lodash methods are guarded to work as iteratees for methods like
  8815. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8816. *
  8817. * The guarded methods are:
  8818. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8819. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8820. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8821. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8822. *
  8823. * @static
  8824. * @memberOf _
  8825. * @since 0.1.0
  8826. * @category Collection
  8827. * @param {Array|Object} collection The collection to iterate over.
  8828. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8829. * @returns {Array} Returns the new mapped array.
  8830. * @example
  8831. *
  8832. * function square(n) {
  8833. * return n * n;
  8834. * }
  8835. *
  8836. * _.map([4, 8], square);
  8837. * // => [16, 64]
  8838. *
  8839. * _.map({ 'a': 4, 'b': 8 }, square);
  8840. * // => [16, 64] (iteration order is not guaranteed)
  8841. *
  8842. * var users = [
  8843. * { 'user': 'barney' },
  8844. * { 'user': 'fred' }
  8845. * ];
  8846. *
  8847. * // The `_.property` iteratee shorthand.
  8848. * _.map(users, 'user');
  8849. * // => ['barney', 'fred']
  8850. */
  8851. function map(collection, iteratee) {
  8852. var func = isArray(collection) ? arrayMap : baseMap;
  8853. return func(collection, getIteratee(iteratee, 3));
  8854. }
  8855. /**
  8856. * This method is like `_.sortBy` except that it allows specifying the sort
  8857. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8858. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8859. * descending or "asc" for ascending sort order of corresponding values.
  8860. *
  8861. * @static
  8862. * @memberOf _
  8863. * @since 4.0.0
  8864. * @category Collection
  8865. * @param {Array|Object} collection The collection to iterate over.
  8866. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8867. * The iteratees to sort by.
  8868. * @param {string[]} [orders] The sort orders of `iteratees`.
  8869. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8870. * @returns {Array} Returns the new sorted array.
  8871. * @example
  8872. *
  8873. * var users = [
  8874. * { 'user': 'fred', 'age': 48 },
  8875. * { 'user': 'barney', 'age': 34 },
  8876. * { 'user': 'fred', 'age': 40 },
  8877. * { 'user': 'barney', 'age': 36 }
  8878. * ];
  8879. *
  8880. * // Sort by `user` in ascending order and by `age` in descending order.
  8881. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8882. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8883. */
  8884. function orderBy(collection, iteratees, orders, guard) {
  8885. if (collection == null) {
  8886. return [];
  8887. }
  8888. if (!isArray(iteratees)) {
  8889. iteratees = iteratees == null ? [] : [iteratees];
  8890. }
  8891. orders = guard ? undefined : orders;
  8892. if (!isArray(orders)) {
  8893. orders = orders == null ? [] : [orders];
  8894. }
  8895. return baseOrderBy(collection, iteratees, orders);
  8896. }
  8897. /**
  8898. * Creates an array of elements split into two groups, the first of which
  8899. * contains elements `predicate` returns truthy for, the second of which
  8900. * contains elements `predicate` returns falsey for. The predicate is
  8901. * invoked with one argument: (value).
  8902. *
  8903. * @static
  8904. * @memberOf _
  8905. * @since 3.0.0
  8906. * @category Collection
  8907. * @param {Array|Object} collection The collection to iterate over.
  8908. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8909. * @returns {Array} Returns the array of grouped elements.
  8910. * @example
  8911. *
  8912. * var users = [
  8913. * { 'user': 'barney', 'age': 36, 'active': false },
  8914. * { 'user': 'fred', 'age': 40, 'active': true },
  8915. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8916. * ];
  8917. *
  8918. * _.partition(users, function(o) { return o.active; });
  8919. * // => objects for [['fred'], ['barney', 'pebbles']]
  8920. *
  8921. * // The `_.matches` iteratee shorthand.
  8922. * _.partition(users, { 'age': 1, 'active': false });
  8923. * // => objects for [['pebbles'], ['barney', 'fred']]
  8924. *
  8925. * // The `_.matchesProperty` iteratee shorthand.
  8926. * _.partition(users, ['active', false]);
  8927. * // => objects for [['barney', 'pebbles'], ['fred']]
  8928. *
  8929. * // The `_.property` iteratee shorthand.
  8930. * _.partition(users, 'active');
  8931. * // => objects for [['fred'], ['barney', 'pebbles']]
  8932. */
  8933. var partition = createAggregator(function(result, value, key) {
  8934. result[key ? 0 : 1].push(value);
  8935. }, function() { return [[], []]; });
  8936. /**
  8937. * Reduces `collection` to a value which is the accumulated result of running
  8938. * each element in `collection` thru `iteratee`, where each successive
  8939. * invocation is supplied the return value of the previous. If `accumulator`
  8940. * is not given, the first element of `collection` is used as the initial
  8941. * value. The iteratee is invoked with four arguments:
  8942. * (accumulator, value, index|key, collection).
  8943. *
  8944. * Many lodash methods are guarded to work as iteratees for methods like
  8945. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8946. *
  8947. * The guarded methods are:
  8948. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8949. * and `sortBy`
  8950. *
  8951. * @static
  8952. * @memberOf _
  8953. * @since 0.1.0
  8954. * @category Collection
  8955. * @param {Array|Object} collection The collection to iterate over.
  8956. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8957. * @param {*} [accumulator] The initial value.
  8958. * @returns {*} Returns the accumulated value.
  8959. * @see _.reduceRight
  8960. * @example
  8961. *
  8962. * _.reduce([1, 2], function(sum, n) {
  8963. * return sum + n;
  8964. * }, 0);
  8965. * // => 3
  8966. *
  8967. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8968. * (result[value] || (result[value] = [])).push(key);
  8969. * return result;
  8970. * }, {});
  8971. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8972. */
  8973. function reduce(collection, iteratee, accumulator) {
  8974. var func = isArray(collection) ? arrayReduce : baseReduce,
  8975. initAccum = arguments.length < 3;
  8976. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8977. }
  8978. /**
  8979. * This method is like `_.reduce` except that it iterates over elements of
  8980. * `collection` from right to left.
  8981. *
  8982. * @static
  8983. * @memberOf _
  8984. * @since 0.1.0
  8985. * @category Collection
  8986. * @param {Array|Object} collection The collection to iterate over.
  8987. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8988. * @param {*} [accumulator] The initial value.
  8989. * @returns {*} Returns the accumulated value.
  8990. * @see _.reduce
  8991. * @example
  8992. *
  8993. * var array = [[0, 1], [2, 3], [4, 5]];
  8994. *
  8995. * _.reduceRight(array, function(flattened, other) {
  8996. * return flattened.concat(other);
  8997. * }, []);
  8998. * // => [4, 5, 2, 3, 0, 1]
  8999. */
  9000. function reduceRight(collection, iteratee, accumulator) {
  9001. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9002. initAccum = arguments.length < 3;
  9003. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9004. }
  9005. /**
  9006. * The opposite of `_.filter`; this method returns the elements of `collection`
  9007. * that `predicate` does **not** return truthy for.
  9008. *
  9009. * @static
  9010. * @memberOf _
  9011. * @since 0.1.0
  9012. * @category Collection
  9013. * @param {Array|Object} collection The collection to iterate over.
  9014. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9015. * @returns {Array} Returns the new filtered array.
  9016. * @see _.filter
  9017. * @example
  9018. *
  9019. * var users = [
  9020. * { 'user': 'barney', 'age': 36, 'active': false },
  9021. * { 'user': 'fred', 'age': 40, 'active': true }
  9022. * ];
  9023. *
  9024. * _.reject(users, function(o) { return !o.active; });
  9025. * // => objects for ['fred']
  9026. *
  9027. * // The `_.matches` iteratee shorthand.
  9028. * _.reject(users, { 'age': 40, 'active': true });
  9029. * // => objects for ['barney']
  9030. *
  9031. * // The `_.matchesProperty` iteratee shorthand.
  9032. * _.reject(users, ['active', false]);
  9033. * // => objects for ['fred']
  9034. *
  9035. * // The `_.property` iteratee shorthand.
  9036. * _.reject(users, 'active');
  9037. * // => objects for ['barney']
  9038. */
  9039. function reject(collection, predicate) {
  9040. var func = isArray(collection) ? arrayFilter : baseFilter;
  9041. return func(collection, negate(getIteratee(predicate, 3)));
  9042. }
  9043. /**
  9044. * Gets a random element from `collection`.
  9045. *
  9046. * @static
  9047. * @memberOf _
  9048. * @since 2.0.0
  9049. * @category Collection
  9050. * @param {Array|Object} collection The collection to sample.
  9051. * @returns {*} Returns the random element.
  9052. * @example
  9053. *
  9054. * _.sample([1, 2, 3, 4]);
  9055. * // => 2
  9056. */
  9057. function sample(collection) {
  9058. var func = isArray(collection) ? arraySample : baseSample;
  9059. return func(collection);
  9060. }
  9061. /**
  9062. * Gets `n` random elements at unique keys from `collection` up to the
  9063. * size of `collection`.
  9064. *
  9065. * @static
  9066. * @memberOf _
  9067. * @since 4.0.0
  9068. * @category Collection
  9069. * @param {Array|Object} collection The collection to sample.
  9070. * @param {number} [n=1] The number of elements to sample.
  9071. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9072. * @returns {Array} Returns the random elements.
  9073. * @example
  9074. *
  9075. * _.sampleSize([1, 2, 3], 2);
  9076. * // => [3, 1]
  9077. *
  9078. * _.sampleSize([1, 2, 3], 4);
  9079. * // => [2, 3, 1]
  9080. */
  9081. function sampleSize(collection, n, guard) {
  9082. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9083. n = 1;
  9084. } else {
  9085. n = toInteger(n);
  9086. }
  9087. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9088. return func(collection, n);
  9089. }
  9090. /**
  9091. * Creates an array of shuffled values, using a version of the
  9092. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9093. *
  9094. * @static
  9095. * @memberOf _
  9096. * @since 0.1.0
  9097. * @category Collection
  9098. * @param {Array|Object} collection The collection to shuffle.
  9099. * @returns {Array} Returns the new shuffled array.
  9100. * @example
  9101. *
  9102. * _.shuffle([1, 2, 3, 4]);
  9103. * // => [4, 1, 3, 2]
  9104. */
  9105. function shuffle(collection) {
  9106. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9107. return func(collection);
  9108. }
  9109. /**
  9110. * Gets the size of `collection` by returning its length for array-like
  9111. * values or the number of own enumerable string keyed properties for objects.
  9112. *
  9113. * @static
  9114. * @memberOf _
  9115. * @since 0.1.0
  9116. * @category Collection
  9117. * @param {Array|Object|string} collection The collection to inspect.
  9118. * @returns {number} Returns the collection size.
  9119. * @example
  9120. *
  9121. * _.size([1, 2, 3]);
  9122. * // => 3
  9123. *
  9124. * _.size({ 'a': 1, 'b': 2 });
  9125. * // => 2
  9126. *
  9127. * _.size('pebbles');
  9128. * // => 7
  9129. */
  9130. function size(collection) {
  9131. if (collection == null) {
  9132. return 0;
  9133. }
  9134. if (isArrayLike(collection)) {
  9135. return isString(collection) ? stringSize(collection) : collection.length;
  9136. }
  9137. var tag = getTag(collection);
  9138. if (tag == mapTag || tag == setTag) {
  9139. return collection.size;
  9140. }
  9141. return baseKeys(collection).length;
  9142. }
  9143. /**
  9144. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9145. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9146. * invoked with three arguments: (value, index|key, collection).
  9147. *
  9148. * @static
  9149. * @memberOf _
  9150. * @since 0.1.0
  9151. * @category Collection
  9152. * @param {Array|Object} collection The collection to iterate over.
  9153. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9154. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9155. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9156. * else `false`.
  9157. * @example
  9158. *
  9159. * _.some([null, 0, 'yes', false], Boolean);
  9160. * // => true
  9161. *
  9162. * var users = [
  9163. * { 'user': 'barney', 'active': true },
  9164. * { 'user': 'fred', 'active': false }
  9165. * ];
  9166. *
  9167. * // The `_.matches` iteratee shorthand.
  9168. * _.some(users, { 'user': 'barney', 'active': false });
  9169. * // => false
  9170. *
  9171. * // The `_.matchesProperty` iteratee shorthand.
  9172. * _.some(users, ['active', false]);
  9173. * // => true
  9174. *
  9175. * // The `_.property` iteratee shorthand.
  9176. * _.some(users, 'active');
  9177. * // => true
  9178. */
  9179. function some(collection, predicate, guard) {
  9180. var func = isArray(collection) ? arraySome : baseSome;
  9181. if (guard && isIterateeCall(collection, predicate, guard)) {
  9182. predicate = undefined;
  9183. }
  9184. return func(collection, getIteratee(predicate, 3));
  9185. }
  9186. /**
  9187. * Creates an array of elements, sorted in ascending order by the results of
  9188. * running each element in a collection thru each iteratee. This method
  9189. * performs a stable sort, that is, it preserves the original sort order of
  9190. * equal elements. The iteratees are invoked with one argument: (value).
  9191. *
  9192. * @static
  9193. * @memberOf _
  9194. * @since 0.1.0
  9195. * @category Collection
  9196. * @param {Array|Object} collection The collection to iterate over.
  9197. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9198. * The iteratees to sort by.
  9199. * @returns {Array} Returns the new sorted array.
  9200. * @example
  9201. *
  9202. * var users = [
  9203. * { 'user': 'fred', 'age': 48 },
  9204. * { 'user': 'barney', 'age': 36 },
  9205. * { 'user': 'fred', 'age': 40 },
  9206. * { 'user': 'barney', 'age': 34 }
  9207. * ];
  9208. *
  9209. * _.sortBy(users, [function(o) { return o.user; }]);
  9210. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9211. *
  9212. * _.sortBy(users, ['user', 'age']);
  9213. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9214. */
  9215. var sortBy = baseRest(function(collection, iteratees) {
  9216. if (collection == null) {
  9217. return [];
  9218. }
  9219. var length = iteratees.length;
  9220. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9221. iteratees = [];
  9222. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9223. iteratees = [iteratees[0]];
  9224. }
  9225. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9226. });
  9227. /*------------------------------------------------------------------------*/
  9228. /**
  9229. * Gets the timestamp of the number of milliseconds that have elapsed since
  9230. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9231. *
  9232. * @static
  9233. * @memberOf _
  9234. * @since 2.4.0
  9235. * @category Date
  9236. * @returns {number} Returns the timestamp.
  9237. * @example
  9238. *
  9239. * _.defer(function(stamp) {
  9240. * console.log(_.now() - stamp);
  9241. * }, _.now());
  9242. * // => Logs the number of milliseconds it took for the deferred invocation.
  9243. */
  9244. var now = ctxNow || function() {
  9245. return root.Date.now();
  9246. };
  9247. /*------------------------------------------------------------------------*/
  9248. /**
  9249. * The opposite of `_.before`; this method creates a function that invokes
  9250. * `func` once it's called `n` or more times.
  9251. *
  9252. * @static
  9253. * @memberOf _
  9254. * @since 0.1.0
  9255. * @category Function
  9256. * @param {number} n The number of calls before `func` is invoked.
  9257. * @param {Function} func The function to restrict.
  9258. * @returns {Function} Returns the new restricted function.
  9259. * @example
  9260. *
  9261. * var saves = ['profile', 'settings'];
  9262. *
  9263. * var done = _.after(saves.length, function() {
  9264. * console.log('done saving!');
  9265. * });
  9266. *
  9267. * _.forEach(saves, function(type) {
  9268. * asyncSave({ 'type': type, 'complete': done });
  9269. * });
  9270. * // => Logs 'done saving!' after the two async saves have completed.
  9271. */
  9272. function after(n, func) {
  9273. if (typeof func != 'function') {
  9274. throw new TypeError(FUNC_ERROR_TEXT);
  9275. }
  9276. n = toInteger(n);
  9277. return function() {
  9278. if (--n < 1) {
  9279. return func.apply(this, arguments);
  9280. }
  9281. };
  9282. }
  9283. /**
  9284. * Creates a function that invokes `func`, with up to `n` arguments,
  9285. * ignoring any additional arguments.
  9286. *
  9287. * @static
  9288. * @memberOf _
  9289. * @since 3.0.0
  9290. * @category Function
  9291. * @param {Function} func The function to cap arguments for.
  9292. * @param {number} [n=func.length] The arity cap.
  9293. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9294. * @returns {Function} Returns the new capped function.
  9295. * @example
  9296. *
  9297. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9298. * // => [6, 8, 10]
  9299. */
  9300. function ary(func, n, guard) {
  9301. n = guard ? undefined : n;
  9302. n = (func && n == null) ? func.length : n;
  9303. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9304. }
  9305. /**
  9306. * Creates a function that invokes `func`, with the `this` binding and arguments
  9307. * of the created function, while it's called less than `n` times. Subsequent
  9308. * calls to the created function return the result of the last `func` invocation.
  9309. *
  9310. * @static
  9311. * @memberOf _
  9312. * @since 3.0.0
  9313. * @category Function
  9314. * @param {number} n The number of calls at which `func` is no longer invoked.
  9315. * @param {Function} func The function to restrict.
  9316. * @returns {Function} Returns the new restricted function.
  9317. * @example
  9318. *
  9319. * jQuery(element).on('click', _.before(5, addContactToList));
  9320. * // => Allows adding up to 4 contacts to the list.
  9321. */
  9322. function before(n, func) {
  9323. var result;
  9324. if (typeof func != 'function') {
  9325. throw new TypeError(FUNC_ERROR_TEXT);
  9326. }
  9327. n = toInteger(n);
  9328. return function() {
  9329. if (--n > 0) {
  9330. result = func.apply(this, arguments);
  9331. }
  9332. if (n <= 1) {
  9333. func = undefined;
  9334. }
  9335. return result;
  9336. };
  9337. }
  9338. /**
  9339. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9340. * and `partials` prepended to the arguments it receives.
  9341. *
  9342. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9343. * may be used as a placeholder for partially applied arguments.
  9344. *
  9345. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9346. * property of bound functions.
  9347. *
  9348. * @static
  9349. * @memberOf _
  9350. * @since 0.1.0
  9351. * @category Function
  9352. * @param {Function} func The function to bind.
  9353. * @param {*} thisArg The `this` binding of `func`.
  9354. * @param {...*} [partials] The arguments to be partially applied.
  9355. * @returns {Function} Returns the new bound function.
  9356. * @example
  9357. *
  9358. * function greet(greeting, punctuation) {
  9359. * return greeting + ' ' + this.user + punctuation;
  9360. * }
  9361. *
  9362. * var object = { 'user': 'fred' };
  9363. *
  9364. * var bound = _.bind(greet, object, 'hi');
  9365. * bound('!');
  9366. * // => 'hi fred!'
  9367. *
  9368. * // Bound with placeholders.
  9369. * var bound = _.bind(greet, object, _, '!');
  9370. * bound('hi');
  9371. * // => 'hi fred!'
  9372. */
  9373. var bind = baseRest(function(func, thisArg, partials) {
  9374. var bitmask = WRAP_BIND_FLAG;
  9375. if (partials.length) {
  9376. var holders = replaceHolders(partials, getHolder(bind));
  9377. bitmask |= WRAP_PARTIAL_FLAG;
  9378. }
  9379. return createWrap(func, bitmask, thisArg, partials, holders);
  9380. });
  9381. /**
  9382. * Creates a function that invokes the method at `object[key]` with `partials`
  9383. * prepended to the arguments it receives.
  9384. *
  9385. * This method differs from `_.bind` by allowing bound functions to reference
  9386. * methods that may be redefined or don't yet exist. See
  9387. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9388. * for more details.
  9389. *
  9390. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9391. * builds, may be used as a placeholder for partially applied arguments.
  9392. *
  9393. * @static
  9394. * @memberOf _
  9395. * @since 0.10.0
  9396. * @category Function
  9397. * @param {Object} object The object to invoke the method on.
  9398. * @param {string} key The key of the method.
  9399. * @param {...*} [partials] The arguments to be partially applied.
  9400. * @returns {Function} Returns the new bound function.
  9401. * @example
  9402. *
  9403. * var object = {
  9404. * 'user': 'fred',
  9405. * 'greet': function(greeting, punctuation) {
  9406. * return greeting + ' ' + this.user + punctuation;
  9407. * }
  9408. * };
  9409. *
  9410. * var bound = _.bindKey(object, 'greet', 'hi');
  9411. * bound('!');
  9412. * // => 'hi fred!'
  9413. *
  9414. * object.greet = function(greeting, punctuation) {
  9415. * return greeting + 'ya ' + this.user + punctuation;
  9416. * };
  9417. *
  9418. * bound('!');
  9419. * // => 'hiya fred!'
  9420. *
  9421. * // Bound with placeholders.
  9422. * var bound = _.bindKey(object, 'greet', _, '!');
  9423. * bound('hi');
  9424. * // => 'hiya fred!'
  9425. */
  9426. var bindKey = baseRest(function(object, key, partials) {
  9427. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9428. if (partials.length) {
  9429. var holders = replaceHolders(partials, getHolder(bindKey));
  9430. bitmask |= WRAP_PARTIAL_FLAG;
  9431. }
  9432. return createWrap(key, bitmask, object, partials, holders);
  9433. });
  9434. /**
  9435. * Creates a function that accepts arguments of `func` and either invokes
  9436. * `func` returning its result, if at least `arity` number of arguments have
  9437. * been provided, or returns a function that accepts the remaining `func`
  9438. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9439. * is not sufficient.
  9440. *
  9441. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9442. * may be used as a placeholder for provided arguments.
  9443. *
  9444. * **Note:** This method doesn't set the "length" property of curried functions.
  9445. *
  9446. * @static
  9447. * @memberOf _
  9448. * @since 2.0.0
  9449. * @category Function
  9450. * @param {Function} func The function to curry.
  9451. * @param {number} [arity=func.length] The arity of `func`.
  9452. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9453. * @returns {Function} Returns the new curried function.
  9454. * @example
  9455. *
  9456. * var abc = function(a, b, c) {
  9457. * return [a, b, c];
  9458. * };
  9459. *
  9460. * var curried = _.curry(abc);
  9461. *
  9462. * curried(1)(2)(3);
  9463. * // => [1, 2, 3]
  9464. *
  9465. * curried(1, 2)(3);
  9466. * // => [1, 2, 3]
  9467. *
  9468. * curried(1, 2, 3);
  9469. * // => [1, 2, 3]
  9470. *
  9471. * // Curried with placeholders.
  9472. * curried(1)(_, 3)(2);
  9473. * // => [1, 2, 3]
  9474. */
  9475. function curry(func, arity, guard) {
  9476. arity = guard ? undefined : arity;
  9477. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9478. result.placeholder = curry.placeholder;
  9479. return result;
  9480. }
  9481. /**
  9482. * This method is like `_.curry` except that arguments are applied to `func`
  9483. * in the manner of `_.partialRight` instead of `_.partial`.
  9484. *
  9485. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9486. * builds, may be used as a placeholder for provided arguments.
  9487. *
  9488. * **Note:** This method doesn't set the "length" property of curried functions.
  9489. *
  9490. * @static
  9491. * @memberOf _
  9492. * @since 3.0.0
  9493. * @category Function
  9494. * @param {Function} func The function to curry.
  9495. * @param {number} [arity=func.length] The arity of `func`.
  9496. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9497. * @returns {Function} Returns the new curried function.
  9498. * @example
  9499. *
  9500. * var abc = function(a, b, c) {
  9501. * return [a, b, c];
  9502. * };
  9503. *
  9504. * var curried = _.curryRight(abc);
  9505. *
  9506. * curried(3)(2)(1);
  9507. * // => [1, 2, 3]
  9508. *
  9509. * curried(2, 3)(1);
  9510. * // => [1, 2, 3]
  9511. *
  9512. * curried(1, 2, 3);
  9513. * // => [1, 2, 3]
  9514. *
  9515. * // Curried with placeholders.
  9516. * curried(3)(1, _)(2);
  9517. * // => [1, 2, 3]
  9518. */
  9519. function curryRight(func, arity, guard) {
  9520. arity = guard ? undefined : arity;
  9521. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9522. result.placeholder = curryRight.placeholder;
  9523. return result;
  9524. }
  9525. /**
  9526. * Creates a debounced function that delays invoking `func` until after `wait`
  9527. * milliseconds have elapsed since the last time the debounced function was
  9528. * invoked. The debounced function comes with a `cancel` method to cancel
  9529. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9530. * Provide `options` to indicate whether `func` should be invoked on the
  9531. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9532. * with the last arguments provided to the debounced function. Subsequent
  9533. * calls to the debounced function return the result of the last `func`
  9534. * invocation.
  9535. *
  9536. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9537. * invoked on the trailing edge of the timeout only if the debounced function
  9538. * is invoked more than once during the `wait` timeout.
  9539. *
  9540. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9541. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9542. *
  9543. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9544. * for details over the differences between `_.debounce` and `_.throttle`.
  9545. *
  9546. * @static
  9547. * @memberOf _
  9548. * @since 0.1.0
  9549. * @category Function
  9550. * @param {Function} func The function to debounce.
  9551. * @param {number} [wait=0] The number of milliseconds to delay.
  9552. * @param {Object} [options={}] The options object.
  9553. * @param {boolean} [options.leading=false]
  9554. * Specify invoking on the leading edge of the timeout.
  9555. * @param {number} [options.maxWait]
  9556. * The maximum time `func` is allowed to be delayed before it's invoked.
  9557. * @param {boolean} [options.trailing=true]
  9558. * Specify invoking on the trailing edge of the timeout.
  9559. * @returns {Function} Returns the new debounced function.
  9560. * @example
  9561. *
  9562. * // Avoid costly calculations while the window size is in flux.
  9563. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9564. *
  9565. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9566. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9567. * 'leading': true,
  9568. * 'trailing': false
  9569. * }));
  9570. *
  9571. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9572. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9573. * var source = new EventSource('/stream');
  9574. * jQuery(source).on('message', debounced);
  9575. *
  9576. * // Cancel the trailing debounced invocation.
  9577. * jQuery(window).on('popstate', debounced.cancel);
  9578. */
  9579. function debounce(func, wait, options) {
  9580. var lastArgs,
  9581. lastThis,
  9582. maxWait,
  9583. result,
  9584. timerId,
  9585. lastCallTime,
  9586. lastInvokeTime = 0,
  9587. leading = false,
  9588. maxing = false,
  9589. trailing = true;
  9590. if (typeof func != 'function') {
  9591. throw new TypeError(FUNC_ERROR_TEXT);
  9592. }
  9593. wait = toNumber(wait) || 0;
  9594. if (isObject(options)) {
  9595. leading = !!options.leading;
  9596. maxing = 'maxWait' in options;
  9597. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9598. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9599. }
  9600. function invokeFunc(time) {
  9601. var args = lastArgs,
  9602. thisArg = lastThis;
  9603. lastArgs = lastThis = undefined;
  9604. lastInvokeTime = time;
  9605. result = func.apply(thisArg, args);
  9606. return result;
  9607. }
  9608. function leadingEdge(time) {
  9609. // Reset any `maxWait` timer.
  9610. lastInvokeTime = time;
  9611. // Start the timer for the trailing edge.
  9612. timerId = setTimeout(timerExpired, wait);
  9613. // Invoke the leading edge.
  9614. return leading ? invokeFunc(time) : result;
  9615. }
  9616. function remainingWait(time) {
  9617. var timeSinceLastCall = time - lastCallTime,
  9618. timeSinceLastInvoke = time - lastInvokeTime,
  9619. timeWaiting = wait - timeSinceLastCall;
  9620. return maxing
  9621. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9622. : timeWaiting;
  9623. }
  9624. function shouldInvoke(time) {
  9625. var timeSinceLastCall = time - lastCallTime,
  9626. timeSinceLastInvoke = time - lastInvokeTime;
  9627. // Either this is the first call, activity has stopped and we're at the
  9628. // trailing edge, the system time has gone backwards and we're treating
  9629. // it as the trailing edge, or we've hit the `maxWait` limit.
  9630. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9631. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9632. }
  9633. function timerExpired() {
  9634. var time = now();
  9635. if (shouldInvoke(time)) {
  9636. return trailingEdge(time);
  9637. }
  9638. // Restart the timer.
  9639. timerId = setTimeout(timerExpired, remainingWait(time));
  9640. }
  9641. function trailingEdge(time) {
  9642. timerId = undefined;
  9643. // Only invoke if we have `lastArgs` which means `func` has been
  9644. // debounced at least once.
  9645. if (trailing && lastArgs) {
  9646. return invokeFunc(time);
  9647. }
  9648. lastArgs = lastThis = undefined;
  9649. return result;
  9650. }
  9651. function cancel() {
  9652. if (timerId !== undefined) {
  9653. clearTimeout(timerId);
  9654. }
  9655. lastInvokeTime = 0;
  9656. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9657. }
  9658. function flush() {
  9659. return timerId === undefined ? result : trailingEdge(now());
  9660. }
  9661. function debounced() {
  9662. var time = now(),
  9663. isInvoking = shouldInvoke(time);
  9664. lastArgs = arguments;
  9665. lastThis = this;
  9666. lastCallTime = time;
  9667. if (isInvoking) {
  9668. if (timerId === undefined) {
  9669. return leadingEdge(lastCallTime);
  9670. }
  9671. if (maxing) {
  9672. // Handle invocations in a tight loop.
  9673. clearTimeout(timerId);
  9674. timerId = setTimeout(timerExpired, wait);
  9675. return invokeFunc(lastCallTime);
  9676. }
  9677. }
  9678. if (timerId === undefined) {
  9679. timerId = setTimeout(timerExpired, wait);
  9680. }
  9681. return result;
  9682. }
  9683. debounced.cancel = cancel;
  9684. debounced.flush = flush;
  9685. return debounced;
  9686. }
  9687. /**
  9688. * Defers invoking the `func` until the current call stack has cleared. Any
  9689. * additional arguments are provided to `func` when it's invoked.
  9690. *
  9691. * @static
  9692. * @memberOf _
  9693. * @since 0.1.0
  9694. * @category Function
  9695. * @param {Function} func The function to defer.
  9696. * @param {...*} [args] The arguments to invoke `func` with.
  9697. * @returns {number} Returns the timer id.
  9698. * @example
  9699. *
  9700. * _.defer(function(text) {
  9701. * console.log(text);
  9702. * }, 'deferred');
  9703. * // => Logs 'deferred' after one millisecond.
  9704. */
  9705. var defer = baseRest(function(func, args) {
  9706. return baseDelay(func, 1, args);
  9707. });
  9708. /**
  9709. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9710. * provided to `func` when it's invoked.
  9711. *
  9712. * @static
  9713. * @memberOf _
  9714. * @since 0.1.0
  9715. * @category Function
  9716. * @param {Function} func The function to delay.
  9717. * @param {number} wait The number of milliseconds to delay invocation.
  9718. * @param {...*} [args] The arguments to invoke `func` with.
  9719. * @returns {number} Returns the timer id.
  9720. * @example
  9721. *
  9722. * _.delay(function(text) {
  9723. * console.log(text);
  9724. * }, 1000, 'later');
  9725. * // => Logs 'later' after one second.
  9726. */
  9727. var delay = baseRest(function(func, wait, args) {
  9728. return baseDelay(func, toNumber(wait) || 0, args);
  9729. });
  9730. /**
  9731. * Creates a function that invokes `func` with arguments reversed.
  9732. *
  9733. * @static
  9734. * @memberOf _
  9735. * @since 4.0.0
  9736. * @category Function
  9737. * @param {Function} func The function to flip arguments for.
  9738. * @returns {Function} Returns the new flipped function.
  9739. * @example
  9740. *
  9741. * var flipped = _.flip(function() {
  9742. * return _.toArray(arguments);
  9743. * });
  9744. *
  9745. * flipped('a', 'b', 'c', 'd');
  9746. * // => ['d', 'c', 'b', 'a']
  9747. */
  9748. function flip(func) {
  9749. return createWrap(func, WRAP_FLIP_FLAG);
  9750. }
  9751. /**
  9752. * Creates a function that memoizes the result of `func`. If `resolver` is
  9753. * provided, it determines the cache key for storing the result based on the
  9754. * arguments provided to the memoized function. By default, the first argument
  9755. * provided to the memoized function is used as the map cache key. The `func`
  9756. * is invoked with the `this` binding of the memoized function.
  9757. *
  9758. * **Note:** The cache is exposed as the `cache` property on the memoized
  9759. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9760. * constructor with one whose instances implement the
  9761. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9762. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9763. *
  9764. * @static
  9765. * @memberOf _
  9766. * @since 0.1.0
  9767. * @category Function
  9768. * @param {Function} func The function to have its output memoized.
  9769. * @param {Function} [resolver] The function to resolve the cache key.
  9770. * @returns {Function} Returns the new memoized function.
  9771. * @example
  9772. *
  9773. * var object = { 'a': 1, 'b': 2 };
  9774. * var other = { 'c': 3, 'd': 4 };
  9775. *
  9776. * var values = _.memoize(_.values);
  9777. * values(object);
  9778. * // => [1, 2]
  9779. *
  9780. * values(other);
  9781. * // => [3, 4]
  9782. *
  9783. * object.a = 2;
  9784. * values(object);
  9785. * // => [1, 2]
  9786. *
  9787. * // Modify the result cache.
  9788. * values.cache.set(object, ['a', 'b']);
  9789. * values(object);
  9790. * // => ['a', 'b']
  9791. *
  9792. * // Replace `_.memoize.Cache`.
  9793. * _.memoize.Cache = WeakMap;
  9794. */
  9795. function memoize(func, resolver) {
  9796. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9797. throw new TypeError(FUNC_ERROR_TEXT);
  9798. }
  9799. var memoized = function() {
  9800. var args = arguments,
  9801. key = resolver ? resolver.apply(this, args) : args[0],
  9802. cache = memoized.cache;
  9803. if (cache.has(key)) {
  9804. return cache.get(key);
  9805. }
  9806. var result = func.apply(this, args);
  9807. memoized.cache = cache.set(key, result) || cache;
  9808. return result;
  9809. };
  9810. memoized.cache = new (memoize.Cache || MapCache);
  9811. return memoized;
  9812. }
  9813. // Expose `MapCache`.
  9814. memoize.Cache = MapCache;
  9815. /**
  9816. * Creates a function that negates the result of the predicate `func`. The
  9817. * `func` predicate is invoked with the `this` binding and arguments of the
  9818. * created function.
  9819. *
  9820. * @static
  9821. * @memberOf _
  9822. * @since 3.0.0
  9823. * @category Function
  9824. * @param {Function} predicate The predicate to negate.
  9825. * @returns {Function} Returns the new negated function.
  9826. * @example
  9827. *
  9828. * function isEven(n) {
  9829. * return n % 2 == 0;
  9830. * }
  9831. *
  9832. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9833. * // => [1, 3, 5]
  9834. */
  9835. function negate(predicate) {
  9836. if (typeof predicate != 'function') {
  9837. throw new TypeError(FUNC_ERROR_TEXT);
  9838. }
  9839. return function() {
  9840. var args = arguments;
  9841. switch (args.length) {
  9842. case 0: return !predicate.call(this);
  9843. case 1: return !predicate.call(this, args[0]);
  9844. case 2: return !predicate.call(this, args[0], args[1]);
  9845. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9846. }
  9847. return !predicate.apply(this, args);
  9848. };
  9849. }
  9850. /**
  9851. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9852. * to the function return the value of the first invocation. The `func` is
  9853. * invoked with the `this` binding and arguments of the created function.
  9854. *
  9855. * @static
  9856. * @memberOf _
  9857. * @since 0.1.0
  9858. * @category Function
  9859. * @param {Function} func The function to restrict.
  9860. * @returns {Function} Returns the new restricted function.
  9861. * @example
  9862. *
  9863. * var initialize = _.once(createApplication);
  9864. * initialize();
  9865. * initialize();
  9866. * // => `createApplication` is invoked once
  9867. */
  9868. function once(func) {
  9869. return before(2, func);
  9870. }
  9871. /**
  9872. * Creates a function that invokes `func` with its arguments transformed.
  9873. *
  9874. * @static
  9875. * @since 4.0.0
  9876. * @memberOf _
  9877. * @category Function
  9878. * @param {Function} func The function to wrap.
  9879. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9880. * The argument transforms.
  9881. * @returns {Function} Returns the new function.
  9882. * @example
  9883. *
  9884. * function doubled(n) {
  9885. * return n * 2;
  9886. * }
  9887. *
  9888. * function square(n) {
  9889. * return n * n;
  9890. * }
  9891. *
  9892. * var func = _.overArgs(function(x, y) {
  9893. * return [x, y];
  9894. * }, [square, doubled]);
  9895. *
  9896. * func(9, 3);
  9897. * // => [81, 6]
  9898. *
  9899. * func(10, 5);
  9900. * // => [100, 10]
  9901. */
  9902. var overArgs = castRest(function(func, transforms) {
  9903. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9904. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9905. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9906. var funcsLength = transforms.length;
  9907. return baseRest(function(args) {
  9908. var index = -1,
  9909. length = nativeMin(args.length, funcsLength);
  9910. while (++index < length) {
  9911. args[index] = transforms[index].call(this, args[index]);
  9912. }
  9913. return apply(func, this, args);
  9914. });
  9915. });
  9916. /**
  9917. * Creates a function that invokes `func` with `partials` prepended to the
  9918. * arguments it receives. This method is like `_.bind` except it does **not**
  9919. * alter the `this` binding.
  9920. *
  9921. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9922. * builds, may be used as a placeholder for partially applied arguments.
  9923. *
  9924. * **Note:** This method doesn't set the "length" property of partially
  9925. * applied functions.
  9926. *
  9927. * @static
  9928. * @memberOf _
  9929. * @since 0.2.0
  9930. * @category Function
  9931. * @param {Function} func The function to partially apply arguments to.
  9932. * @param {...*} [partials] The arguments to be partially applied.
  9933. * @returns {Function} Returns the new partially applied function.
  9934. * @example
  9935. *
  9936. * function greet(greeting, name) {
  9937. * return greeting + ' ' + name;
  9938. * }
  9939. *
  9940. * var sayHelloTo = _.partial(greet, 'hello');
  9941. * sayHelloTo('fred');
  9942. * // => 'hello fred'
  9943. *
  9944. * // Partially applied with placeholders.
  9945. * var greetFred = _.partial(greet, _, 'fred');
  9946. * greetFred('hi');
  9947. * // => 'hi fred'
  9948. */
  9949. var partial = baseRest(function(func, partials) {
  9950. var holders = replaceHolders(partials, getHolder(partial));
  9951. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9952. });
  9953. /**
  9954. * This method is like `_.partial` except that partially applied arguments
  9955. * are appended to the arguments it receives.
  9956. *
  9957. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9958. * builds, may be used as a placeholder for partially applied arguments.
  9959. *
  9960. * **Note:** This method doesn't set the "length" property of partially
  9961. * applied functions.
  9962. *
  9963. * @static
  9964. * @memberOf _
  9965. * @since 1.0.0
  9966. * @category Function
  9967. * @param {Function} func The function to partially apply arguments to.
  9968. * @param {...*} [partials] The arguments to be partially applied.
  9969. * @returns {Function} Returns the new partially applied function.
  9970. * @example
  9971. *
  9972. * function greet(greeting, name) {
  9973. * return greeting + ' ' + name;
  9974. * }
  9975. *
  9976. * var greetFred = _.partialRight(greet, 'fred');
  9977. * greetFred('hi');
  9978. * // => 'hi fred'
  9979. *
  9980. * // Partially applied with placeholders.
  9981. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9982. * sayHelloTo('fred');
  9983. * // => 'hello fred'
  9984. */
  9985. var partialRight = baseRest(function(func, partials) {
  9986. var holders = replaceHolders(partials, getHolder(partialRight));
  9987. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9988. });
  9989. /**
  9990. * Creates a function that invokes `func` with arguments arranged according
  9991. * to the specified `indexes` where the argument value at the first index is
  9992. * provided as the first argument, the argument value at the second index is
  9993. * provided as the second argument, and so on.
  9994. *
  9995. * @static
  9996. * @memberOf _
  9997. * @since 3.0.0
  9998. * @category Function
  9999. * @param {Function} func The function to rearrange arguments for.
  10000. * @param {...(number|number[])} indexes The arranged argument indexes.
  10001. * @returns {Function} Returns the new function.
  10002. * @example
  10003. *
  10004. * var rearged = _.rearg(function(a, b, c) {
  10005. * return [a, b, c];
  10006. * }, [2, 0, 1]);
  10007. *
  10008. * rearged('b', 'c', 'a')
  10009. * // => ['a', 'b', 'c']
  10010. */
  10011. var rearg = flatRest(function(func, indexes) {
  10012. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10013. });
  10014. /**
  10015. * Creates a function that invokes `func` with the `this` binding of the
  10016. * created function and arguments from `start` and beyond provided as
  10017. * an array.
  10018. *
  10019. * **Note:** This method is based on the
  10020. * [rest parameter](https://mdn.io/rest_parameters).
  10021. *
  10022. * @static
  10023. * @memberOf _
  10024. * @since 4.0.0
  10025. * @category Function
  10026. * @param {Function} func The function to apply a rest parameter to.
  10027. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10028. * @returns {Function} Returns the new function.
  10029. * @example
  10030. *
  10031. * var say = _.rest(function(what, names) {
  10032. * return what + ' ' + _.initial(names).join(', ') +
  10033. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10034. * });
  10035. *
  10036. * say('hello', 'fred', 'barney', 'pebbles');
  10037. * // => 'hello fred, barney, & pebbles'
  10038. */
  10039. function rest(func, start) {
  10040. if (typeof func != 'function') {
  10041. throw new TypeError(FUNC_ERROR_TEXT);
  10042. }
  10043. start = start === undefined ? start : toInteger(start);
  10044. return baseRest(func, start);
  10045. }
  10046. /**
  10047. * Creates a function that invokes `func` with the `this` binding of the
  10048. * create function and an array of arguments much like
  10049. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10050. *
  10051. * **Note:** This method is based on the
  10052. * [spread operator](https://mdn.io/spread_operator).
  10053. *
  10054. * @static
  10055. * @memberOf _
  10056. * @since 3.2.0
  10057. * @category Function
  10058. * @param {Function} func The function to spread arguments over.
  10059. * @param {number} [start=0] The start position of the spread.
  10060. * @returns {Function} Returns the new function.
  10061. * @example
  10062. *
  10063. * var say = _.spread(function(who, what) {
  10064. * return who + ' says ' + what;
  10065. * });
  10066. *
  10067. * say(['fred', 'hello']);
  10068. * // => 'fred says hello'
  10069. *
  10070. * var numbers = Promise.all([
  10071. * Promise.resolve(40),
  10072. * Promise.resolve(36)
  10073. * ]);
  10074. *
  10075. * numbers.then(_.spread(function(x, y) {
  10076. * return x + y;
  10077. * }));
  10078. * // => a Promise of 76
  10079. */
  10080. function spread(func, start) {
  10081. if (typeof func != 'function') {
  10082. throw new TypeError(FUNC_ERROR_TEXT);
  10083. }
  10084. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10085. return baseRest(function(args) {
  10086. var array = args[start],
  10087. otherArgs = castSlice(args, 0, start);
  10088. if (array) {
  10089. arrayPush(otherArgs, array);
  10090. }
  10091. return apply(func, this, otherArgs);
  10092. });
  10093. }
  10094. /**
  10095. * Creates a throttled function that only invokes `func` at most once per
  10096. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10097. * method to cancel delayed `func` invocations and a `flush` method to
  10098. * immediately invoke them. Provide `options` to indicate whether `func`
  10099. * should be invoked on the leading and/or trailing edge of the `wait`
  10100. * timeout. The `func` is invoked with the last arguments provided to the
  10101. * throttled function. Subsequent calls to the throttled function return the
  10102. * result of the last `func` invocation.
  10103. *
  10104. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10105. * invoked on the trailing edge of the timeout only if the throttled function
  10106. * is invoked more than once during the `wait` timeout.
  10107. *
  10108. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10109. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10110. *
  10111. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10112. * for details over the differences between `_.throttle` and `_.debounce`.
  10113. *
  10114. * @static
  10115. * @memberOf _
  10116. * @since 0.1.0
  10117. * @category Function
  10118. * @param {Function} func The function to throttle.
  10119. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10120. * @param {Object} [options={}] The options object.
  10121. * @param {boolean} [options.leading=true]
  10122. * Specify invoking on the leading edge of the timeout.
  10123. * @param {boolean} [options.trailing=true]
  10124. * Specify invoking on the trailing edge of the timeout.
  10125. * @returns {Function} Returns the new throttled function.
  10126. * @example
  10127. *
  10128. * // Avoid excessively updating the position while scrolling.
  10129. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10130. *
  10131. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10132. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10133. * jQuery(element).on('click', throttled);
  10134. *
  10135. * // Cancel the trailing throttled invocation.
  10136. * jQuery(window).on('popstate', throttled.cancel);
  10137. */
  10138. function throttle(func, wait, options) {
  10139. var leading = true,
  10140. trailing = true;
  10141. if (typeof func != 'function') {
  10142. throw new TypeError(FUNC_ERROR_TEXT);
  10143. }
  10144. if (isObject(options)) {
  10145. leading = 'leading' in options ? !!options.leading : leading;
  10146. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10147. }
  10148. return debounce(func, wait, {
  10149. 'leading': leading,
  10150. 'maxWait': wait,
  10151. 'trailing': trailing
  10152. });
  10153. }
  10154. /**
  10155. * Creates a function that accepts up to one argument, ignoring any
  10156. * additional arguments.
  10157. *
  10158. * @static
  10159. * @memberOf _
  10160. * @since 4.0.0
  10161. * @category Function
  10162. * @param {Function} func The function to cap arguments for.
  10163. * @returns {Function} Returns the new capped function.
  10164. * @example
  10165. *
  10166. * _.map(['6', '8', '10'], _.unary(parseInt));
  10167. * // => [6, 8, 10]
  10168. */
  10169. function unary(func) {
  10170. return ary(func, 1);
  10171. }
  10172. /**
  10173. * Creates a function that provides `value` to `wrapper` as its first
  10174. * argument. Any additional arguments provided to the function are appended
  10175. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10176. * binding of the created function.
  10177. *
  10178. * @static
  10179. * @memberOf _
  10180. * @since 0.1.0
  10181. * @category Function
  10182. * @param {*} value The value to wrap.
  10183. * @param {Function} [wrapper=identity] The wrapper function.
  10184. * @returns {Function} Returns the new function.
  10185. * @example
  10186. *
  10187. * var p = _.wrap(_.escape, function(func, text) {
  10188. * return '<p>' + func(text) + '</p>';
  10189. * });
  10190. *
  10191. * p('fred, barney, & pebbles');
  10192. * // => '<p>fred, barney, &amp; pebbles</p>'
  10193. */
  10194. function wrap(value, wrapper) {
  10195. return partial(castFunction(wrapper), value);
  10196. }
  10197. /*------------------------------------------------------------------------*/
  10198. /**
  10199. * Casts `value` as an array if it's not one.
  10200. *
  10201. * @static
  10202. * @memberOf _
  10203. * @since 4.4.0
  10204. * @category Lang
  10205. * @param {*} value The value to inspect.
  10206. * @returns {Array} Returns the cast array.
  10207. * @example
  10208. *
  10209. * _.castArray(1);
  10210. * // => [1]
  10211. *
  10212. * _.castArray({ 'a': 1 });
  10213. * // => [{ 'a': 1 }]
  10214. *
  10215. * _.castArray('abc');
  10216. * // => ['abc']
  10217. *
  10218. * _.castArray(null);
  10219. * // => [null]
  10220. *
  10221. * _.castArray(undefined);
  10222. * // => [undefined]
  10223. *
  10224. * _.castArray();
  10225. * // => []
  10226. *
  10227. * var array = [1, 2, 3];
  10228. * console.log(_.castArray(array) === array);
  10229. * // => true
  10230. */
  10231. function castArray() {
  10232. if (!arguments.length) {
  10233. return [];
  10234. }
  10235. var value = arguments[0];
  10236. return isArray(value) ? value : [value];
  10237. }
  10238. /**
  10239. * Creates a shallow clone of `value`.
  10240. *
  10241. * **Note:** This method is loosely based on the
  10242. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10243. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10244. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10245. * arrays. The own enumerable properties of `arguments` objects are cloned
  10246. * as plain objects. An empty object is returned for uncloneable values such
  10247. * as error objects, functions, DOM nodes, and WeakMaps.
  10248. *
  10249. * @static
  10250. * @memberOf _
  10251. * @since 0.1.0
  10252. * @category Lang
  10253. * @param {*} value The value to clone.
  10254. * @returns {*} Returns the cloned value.
  10255. * @see _.cloneDeep
  10256. * @example
  10257. *
  10258. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10259. *
  10260. * var shallow = _.clone(objects);
  10261. * console.log(shallow[0] === objects[0]);
  10262. * // => true
  10263. */
  10264. function clone(value) {
  10265. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10266. }
  10267. /**
  10268. * This method is like `_.clone` except that it accepts `customizer` which
  10269. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10270. * cloning is handled by the method instead. The `customizer` is invoked with
  10271. * up to four arguments; (value [, index|key, object, stack]).
  10272. *
  10273. * @static
  10274. * @memberOf _
  10275. * @since 4.0.0
  10276. * @category Lang
  10277. * @param {*} value The value to clone.
  10278. * @param {Function} [customizer] The function to customize cloning.
  10279. * @returns {*} Returns the cloned value.
  10280. * @see _.cloneDeepWith
  10281. * @example
  10282. *
  10283. * function customizer(value) {
  10284. * if (_.isElement(value)) {
  10285. * return value.cloneNode(false);
  10286. * }
  10287. * }
  10288. *
  10289. * var el = _.cloneWith(document.body, customizer);
  10290. *
  10291. * console.log(el === document.body);
  10292. * // => false
  10293. * console.log(el.nodeName);
  10294. * // => 'BODY'
  10295. * console.log(el.childNodes.length);
  10296. * // => 0
  10297. */
  10298. function cloneWith(value, customizer) {
  10299. customizer = typeof customizer == 'function' ? customizer : undefined;
  10300. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10301. }
  10302. /**
  10303. * This method is like `_.clone` except that it recursively clones `value`.
  10304. *
  10305. * @static
  10306. * @memberOf _
  10307. * @since 1.0.0
  10308. * @category Lang
  10309. * @param {*} value The value to recursively clone.
  10310. * @returns {*} Returns the deep cloned value.
  10311. * @see _.clone
  10312. * @example
  10313. *
  10314. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10315. *
  10316. * var deep = _.cloneDeep(objects);
  10317. * console.log(deep[0] === objects[0]);
  10318. * // => false
  10319. */
  10320. function cloneDeep(value) {
  10321. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10322. }
  10323. /**
  10324. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10325. *
  10326. * @static
  10327. * @memberOf _
  10328. * @since 4.0.0
  10329. * @category Lang
  10330. * @param {*} value The value to recursively clone.
  10331. * @param {Function} [customizer] The function to customize cloning.
  10332. * @returns {*} Returns the deep cloned value.
  10333. * @see _.cloneWith
  10334. * @example
  10335. *
  10336. * function customizer(value) {
  10337. * if (_.isElement(value)) {
  10338. * return value.cloneNode(true);
  10339. * }
  10340. * }
  10341. *
  10342. * var el = _.cloneDeepWith(document.body, customizer);
  10343. *
  10344. * console.log(el === document.body);
  10345. * // => false
  10346. * console.log(el.nodeName);
  10347. * // => 'BODY'
  10348. * console.log(el.childNodes.length);
  10349. * // => 20
  10350. */
  10351. function cloneDeepWith(value, customizer) {
  10352. customizer = typeof customizer == 'function' ? customizer : undefined;
  10353. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10354. }
  10355. /**
  10356. * Checks if `object` conforms to `source` by invoking the predicate
  10357. * properties of `source` with the corresponding property values of `object`.
  10358. *
  10359. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10360. * partially applied.
  10361. *
  10362. * @static
  10363. * @memberOf _
  10364. * @since 4.14.0
  10365. * @category Lang
  10366. * @param {Object} object The object to inspect.
  10367. * @param {Object} source The object of property predicates to conform to.
  10368. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10369. * @example
  10370. *
  10371. * var object = { 'a': 1, 'b': 2 };
  10372. *
  10373. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10374. * // => true
  10375. *
  10376. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10377. * // => false
  10378. */
  10379. function conformsTo(object, source) {
  10380. return source == null || baseConformsTo(object, source, keys(source));
  10381. }
  10382. /**
  10383. * Performs a
  10384. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10385. * comparison between two values to determine if they are equivalent.
  10386. *
  10387. * @static
  10388. * @memberOf _
  10389. * @since 4.0.0
  10390. * @category Lang
  10391. * @param {*} value The value to compare.
  10392. * @param {*} other The other value to compare.
  10393. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10394. * @example
  10395. *
  10396. * var object = { 'a': 1 };
  10397. * var other = { 'a': 1 };
  10398. *
  10399. * _.eq(object, object);
  10400. * // => true
  10401. *
  10402. * _.eq(object, other);
  10403. * // => false
  10404. *
  10405. * _.eq('a', 'a');
  10406. * // => true
  10407. *
  10408. * _.eq('a', Object('a'));
  10409. * // => false
  10410. *
  10411. * _.eq(NaN, NaN);
  10412. * // => true
  10413. */
  10414. function eq(value, other) {
  10415. return value === other || (value !== value && other !== other);
  10416. }
  10417. /**
  10418. * Checks if `value` is greater than `other`.
  10419. *
  10420. * @static
  10421. * @memberOf _
  10422. * @since 3.9.0
  10423. * @category Lang
  10424. * @param {*} value The value to compare.
  10425. * @param {*} other The other value to compare.
  10426. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10427. * else `false`.
  10428. * @see _.lt
  10429. * @example
  10430. *
  10431. * _.gt(3, 1);
  10432. * // => true
  10433. *
  10434. * _.gt(3, 3);
  10435. * // => false
  10436. *
  10437. * _.gt(1, 3);
  10438. * // => false
  10439. */
  10440. var gt = createRelationalOperation(baseGt);
  10441. /**
  10442. * Checks if `value` is greater than or equal to `other`.
  10443. *
  10444. * @static
  10445. * @memberOf _
  10446. * @since 3.9.0
  10447. * @category Lang
  10448. * @param {*} value The value to compare.
  10449. * @param {*} other The other value to compare.
  10450. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10451. * `other`, else `false`.
  10452. * @see _.lte
  10453. * @example
  10454. *
  10455. * _.gte(3, 1);
  10456. * // => true
  10457. *
  10458. * _.gte(3, 3);
  10459. * // => true
  10460. *
  10461. * _.gte(1, 3);
  10462. * // => false
  10463. */
  10464. var gte = createRelationalOperation(function(value, other) {
  10465. return value >= other;
  10466. });
  10467. /**
  10468. * Checks if `value` is likely an `arguments` object.
  10469. *
  10470. * @static
  10471. * @memberOf _
  10472. * @since 0.1.0
  10473. * @category Lang
  10474. * @param {*} value The value to check.
  10475. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10476. * else `false`.
  10477. * @example
  10478. *
  10479. * _.isArguments(function() { return arguments; }());
  10480. * // => true
  10481. *
  10482. * _.isArguments([1, 2, 3]);
  10483. * // => false
  10484. */
  10485. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10486. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10487. !propertyIsEnumerable.call(value, 'callee');
  10488. };
  10489. /**
  10490. * Checks if `value` is classified as an `Array` object.
  10491. *
  10492. * @static
  10493. * @memberOf _
  10494. * @since 0.1.0
  10495. * @category Lang
  10496. * @param {*} value The value to check.
  10497. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10498. * @example
  10499. *
  10500. * _.isArray([1, 2, 3]);
  10501. * // => true
  10502. *
  10503. * _.isArray(document.body.children);
  10504. * // => false
  10505. *
  10506. * _.isArray('abc');
  10507. * // => false
  10508. *
  10509. * _.isArray(_.noop);
  10510. * // => false
  10511. */
  10512. var isArray = Array.isArray;
  10513. /**
  10514. * Checks if `value` is classified as an `ArrayBuffer` object.
  10515. *
  10516. * @static
  10517. * @memberOf _
  10518. * @since 4.3.0
  10519. * @category Lang
  10520. * @param {*} value The value to check.
  10521. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10522. * @example
  10523. *
  10524. * _.isArrayBuffer(new ArrayBuffer(2));
  10525. * // => true
  10526. *
  10527. * _.isArrayBuffer(new Array(2));
  10528. * // => false
  10529. */
  10530. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10531. /**
  10532. * Checks if `value` is array-like. A value is considered array-like if it's
  10533. * not a function and has a `value.length` that's an integer greater than or
  10534. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10535. *
  10536. * @static
  10537. * @memberOf _
  10538. * @since 4.0.0
  10539. * @category Lang
  10540. * @param {*} value The value to check.
  10541. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10542. * @example
  10543. *
  10544. * _.isArrayLike([1, 2, 3]);
  10545. * // => true
  10546. *
  10547. * _.isArrayLike(document.body.children);
  10548. * // => true
  10549. *
  10550. * _.isArrayLike('abc');
  10551. * // => true
  10552. *
  10553. * _.isArrayLike(_.noop);
  10554. * // => false
  10555. */
  10556. function isArrayLike(value) {
  10557. return value != null && isLength(value.length) && !isFunction(value);
  10558. }
  10559. /**
  10560. * This method is like `_.isArrayLike` except that it also checks if `value`
  10561. * is an object.
  10562. *
  10563. * @static
  10564. * @memberOf _
  10565. * @since 4.0.0
  10566. * @category Lang
  10567. * @param {*} value The value to check.
  10568. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10569. * else `false`.
  10570. * @example
  10571. *
  10572. * _.isArrayLikeObject([1, 2, 3]);
  10573. * // => true
  10574. *
  10575. * _.isArrayLikeObject(document.body.children);
  10576. * // => true
  10577. *
  10578. * _.isArrayLikeObject('abc');
  10579. * // => false
  10580. *
  10581. * _.isArrayLikeObject(_.noop);
  10582. * // => false
  10583. */
  10584. function isArrayLikeObject(value) {
  10585. return isObjectLike(value) && isArrayLike(value);
  10586. }
  10587. /**
  10588. * Checks if `value` is classified as a boolean primitive or object.
  10589. *
  10590. * @static
  10591. * @memberOf _
  10592. * @since 0.1.0
  10593. * @category Lang
  10594. * @param {*} value The value to check.
  10595. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10596. * @example
  10597. *
  10598. * _.isBoolean(false);
  10599. * // => true
  10600. *
  10601. * _.isBoolean(null);
  10602. * // => false
  10603. */
  10604. function isBoolean(value) {
  10605. return value === true || value === false ||
  10606. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10607. }
  10608. /**
  10609. * Checks if `value` is a buffer.
  10610. *
  10611. * @static
  10612. * @memberOf _
  10613. * @since 4.3.0
  10614. * @category Lang
  10615. * @param {*} value The value to check.
  10616. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10617. * @example
  10618. *
  10619. * _.isBuffer(new Buffer(2));
  10620. * // => true
  10621. *
  10622. * _.isBuffer(new Uint8Array(2));
  10623. * // => false
  10624. */
  10625. var isBuffer = nativeIsBuffer || stubFalse;
  10626. /**
  10627. * Checks if `value` is classified as a `Date` object.
  10628. *
  10629. * @static
  10630. * @memberOf _
  10631. * @since 0.1.0
  10632. * @category Lang
  10633. * @param {*} value The value to check.
  10634. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10635. * @example
  10636. *
  10637. * _.isDate(new Date);
  10638. * // => true
  10639. *
  10640. * _.isDate('Mon April 23 2012');
  10641. * // => false
  10642. */
  10643. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10644. /**
  10645. * Checks if `value` is likely a DOM element.
  10646. *
  10647. * @static
  10648. * @memberOf _
  10649. * @since 0.1.0
  10650. * @category Lang
  10651. * @param {*} value The value to check.
  10652. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10653. * @example
  10654. *
  10655. * _.isElement(document.body);
  10656. * // => true
  10657. *
  10658. * _.isElement('<body>');
  10659. * // => false
  10660. */
  10661. function isElement(value) {
  10662. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10663. }
  10664. /**
  10665. * Checks if `value` is an empty object, collection, map, or set.
  10666. *
  10667. * Objects are considered empty if they have no own enumerable string keyed
  10668. * properties.
  10669. *
  10670. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10671. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10672. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10673. *
  10674. * @static
  10675. * @memberOf _
  10676. * @since 0.1.0
  10677. * @category Lang
  10678. * @param {*} value The value to check.
  10679. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10680. * @example
  10681. *
  10682. * _.isEmpty(null);
  10683. * // => true
  10684. *
  10685. * _.isEmpty(true);
  10686. * // => true
  10687. *
  10688. * _.isEmpty(1);
  10689. * // => true
  10690. *
  10691. * _.isEmpty([1, 2, 3]);
  10692. * // => false
  10693. *
  10694. * _.isEmpty({ 'a': 1 });
  10695. * // => false
  10696. */
  10697. function isEmpty(value) {
  10698. if (value == null) {
  10699. return true;
  10700. }
  10701. if (isArrayLike(value) &&
  10702. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10703. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10704. return !value.length;
  10705. }
  10706. var tag = getTag(value);
  10707. if (tag == mapTag || tag == setTag) {
  10708. return !value.size;
  10709. }
  10710. if (isPrototype(value)) {
  10711. return !baseKeys(value).length;
  10712. }
  10713. for (var key in value) {
  10714. if (hasOwnProperty.call(value, key)) {
  10715. return false;
  10716. }
  10717. }
  10718. return true;
  10719. }
  10720. /**
  10721. * Performs a deep comparison between two values to determine if they are
  10722. * equivalent.
  10723. *
  10724. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10725. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10726. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10727. * by their own, not inherited, enumerable properties. Functions and DOM
  10728. * nodes are compared by strict equality, i.e. `===`.
  10729. *
  10730. * @static
  10731. * @memberOf _
  10732. * @since 0.1.0
  10733. * @category Lang
  10734. * @param {*} value The value to compare.
  10735. * @param {*} other The other value to compare.
  10736. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10737. * @example
  10738. *
  10739. * var object = { 'a': 1 };
  10740. * var other = { 'a': 1 };
  10741. *
  10742. * _.isEqual(object, other);
  10743. * // => true
  10744. *
  10745. * object === other;
  10746. * // => false
  10747. */
  10748. function isEqual(value, other) {
  10749. return baseIsEqual(value, other);
  10750. }
  10751. /**
  10752. * This method is like `_.isEqual` except that it accepts `customizer` which
  10753. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10754. * are handled by the method instead. The `customizer` is invoked with up to
  10755. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10756. *
  10757. * @static
  10758. * @memberOf _
  10759. * @since 4.0.0
  10760. * @category Lang
  10761. * @param {*} value The value to compare.
  10762. * @param {*} other The other value to compare.
  10763. * @param {Function} [customizer] The function to customize comparisons.
  10764. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10765. * @example
  10766. *
  10767. * function isGreeting(value) {
  10768. * return /^h(?:i|ello)$/.test(value);
  10769. * }
  10770. *
  10771. * function customizer(objValue, othValue) {
  10772. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10773. * return true;
  10774. * }
  10775. * }
  10776. *
  10777. * var array = ['hello', 'goodbye'];
  10778. * var other = ['hi', 'goodbye'];
  10779. *
  10780. * _.isEqualWith(array, other, customizer);
  10781. * // => true
  10782. */
  10783. function isEqualWith(value, other, customizer) {
  10784. customizer = typeof customizer == 'function' ? customizer : undefined;
  10785. var result = customizer ? customizer(value, other) : undefined;
  10786. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10787. }
  10788. /**
  10789. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10790. * `SyntaxError`, `TypeError`, or `URIError` object.
  10791. *
  10792. * @static
  10793. * @memberOf _
  10794. * @since 3.0.0
  10795. * @category Lang
  10796. * @param {*} value The value to check.
  10797. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10798. * @example
  10799. *
  10800. * _.isError(new Error);
  10801. * // => true
  10802. *
  10803. * _.isError(Error);
  10804. * // => false
  10805. */
  10806. function isError(value) {
  10807. if (!isObjectLike(value)) {
  10808. return false;
  10809. }
  10810. var tag = baseGetTag(value);
  10811. return tag == errorTag || tag == domExcTag ||
  10812. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10813. }
  10814. /**
  10815. * Checks if `value` is a finite primitive number.
  10816. *
  10817. * **Note:** This method is based on
  10818. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10819. *
  10820. * @static
  10821. * @memberOf _
  10822. * @since 0.1.0
  10823. * @category Lang
  10824. * @param {*} value The value to check.
  10825. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10826. * @example
  10827. *
  10828. * _.isFinite(3);
  10829. * // => true
  10830. *
  10831. * _.isFinite(Number.MIN_VALUE);
  10832. * // => true
  10833. *
  10834. * _.isFinite(Infinity);
  10835. * // => false
  10836. *
  10837. * _.isFinite('3');
  10838. * // => false
  10839. */
  10840. function isFinite(value) {
  10841. return typeof value == 'number' && nativeIsFinite(value);
  10842. }
  10843. /**
  10844. * Checks if `value` is classified as a `Function` object.
  10845. *
  10846. * @static
  10847. * @memberOf _
  10848. * @since 0.1.0
  10849. * @category Lang
  10850. * @param {*} value The value to check.
  10851. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10852. * @example
  10853. *
  10854. * _.isFunction(_);
  10855. * // => true
  10856. *
  10857. * _.isFunction(/abc/);
  10858. * // => false
  10859. */
  10860. function isFunction(value) {
  10861. if (!isObject(value)) {
  10862. return false;
  10863. }
  10864. // The use of `Object#toString` avoids issues with the `typeof` operator
  10865. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10866. var tag = baseGetTag(value);
  10867. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10868. }
  10869. /**
  10870. * Checks if `value` is an integer.
  10871. *
  10872. * **Note:** This method is based on
  10873. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10874. *
  10875. * @static
  10876. * @memberOf _
  10877. * @since 4.0.0
  10878. * @category Lang
  10879. * @param {*} value The value to check.
  10880. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10881. * @example
  10882. *
  10883. * _.isInteger(3);
  10884. * // => true
  10885. *
  10886. * _.isInteger(Number.MIN_VALUE);
  10887. * // => false
  10888. *
  10889. * _.isInteger(Infinity);
  10890. * // => false
  10891. *
  10892. * _.isInteger('3');
  10893. * // => false
  10894. */
  10895. function isInteger(value) {
  10896. return typeof value == 'number' && value == toInteger(value);
  10897. }
  10898. /**
  10899. * Checks if `value` is a valid array-like length.
  10900. *
  10901. * **Note:** This method is loosely based on
  10902. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10903. *
  10904. * @static
  10905. * @memberOf _
  10906. * @since 4.0.0
  10907. * @category Lang
  10908. * @param {*} value The value to check.
  10909. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10910. * @example
  10911. *
  10912. * _.isLength(3);
  10913. * // => true
  10914. *
  10915. * _.isLength(Number.MIN_VALUE);
  10916. * // => false
  10917. *
  10918. * _.isLength(Infinity);
  10919. * // => false
  10920. *
  10921. * _.isLength('3');
  10922. * // => false
  10923. */
  10924. function isLength(value) {
  10925. return typeof value == 'number' &&
  10926. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10927. }
  10928. /**
  10929. * Checks if `value` is the
  10930. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10931. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10932. *
  10933. * @static
  10934. * @memberOf _
  10935. * @since 0.1.0
  10936. * @category Lang
  10937. * @param {*} value The value to check.
  10938. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10939. * @example
  10940. *
  10941. * _.isObject({});
  10942. * // => true
  10943. *
  10944. * _.isObject([1, 2, 3]);
  10945. * // => true
  10946. *
  10947. * _.isObject(_.noop);
  10948. * // => true
  10949. *
  10950. * _.isObject(null);
  10951. * // => false
  10952. */
  10953. function isObject(value) {
  10954. var type = typeof value;
  10955. return value != null && (type == 'object' || type == 'function');
  10956. }
  10957. /**
  10958. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10959. * and has a `typeof` result of "object".
  10960. *
  10961. * @static
  10962. * @memberOf _
  10963. * @since 4.0.0
  10964. * @category Lang
  10965. * @param {*} value The value to check.
  10966. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10967. * @example
  10968. *
  10969. * _.isObjectLike({});
  10970. * // => true
  10971. *
  10972. * _.isObjectLike([1, 2, 3]);
  10973. * // => true
  10974. *
  10975. * _.isObjectLike(_.noop);
  10976. * // => false
  10977. *
  10978. * _.isObjectLike(null);
  10979. * // => false
  10980. */
  10981. function isObjectLike(value) {
  10982. return value != null && typeof value == 'object';
  10983. }
  10984. /**
  10985. * Checks if `value` is classified as a `Map` object.
  10986. *
  10987. * @static
  10988. * @memberOf _
  10989. * @since 4.3.0
  10990. * @category Lang
  10991. * @param {*} value The value to check.
  10992. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  10993. * @example
  10994. *
  10995. * _.isMap(new Map);
  10996. * // => true
  10997. *
  10998. * _.isMap(new WeakMap);
  10999. * // => false
  11000. */
  11001. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11002. /**
  11003. * Performs a partial deep comparison between `object` and `source` to
  11004. * determine if `object` contains equivalent property values.
  11005. *
  11006. * **Note:** This method is equivalent to `_.matches` when `source` is
  11007. * partially applied.
  11008. *
  11009. * Partial comparisons will match empty array and empty object `source`
  11010. * values against any array or object value, respectively. See `_.isEqual`
  11011. * for a list of supported value comparisons.
  11012. *
  11013. * @static
  11014. * @memberOf _
  11015. * @since 3.0.0
  11016. * @category Lang
  11017. * @param {Object} object The object to inspect.
  11018. * @param {Object} source The object of property values to match.
  11019. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11020. * @example
  11021. *
  11022. * var object = { 'a': 1, 'b': 2 };
  11023. *
  11024. * _.isMatch(object, { 'b': 2 });
  11025. * // => true
  11026. *
  11027. * _.isMatch(object, { 'b': 1 });
  11028. * // => false
  11029. */
  11030. function isMatch(object, source) {
  11031. return object === source || baseIsMatch(object, source, getMatchData(source));
  11032. }
  11033. /**
  11034. * This method is like `_.isMatch` except that it accepts `customizer` which
  11035. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11036. * are handled by the method instead. The `customizer` is invoked with five
  11037. * arguments: (objValue, srcValue, index|key, object, source).
  11038. *
  11039. * @static
  11040. * @memberOf _
  11041. * @since 4.0.0
  11042. * @category Lang
  11043. * @param {Object} object The object to inspect.
  11044. * @param {Object} source The object of property values to match.
  11045. * @param {Function} [customizer] The function to customize comparisons.
  11046. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11047. * @example
  11048. *
  11049. * function isGreeting(value) {
  11050. * return /^h(?:i|ello)$/.test(value);
  11051. * }
  11052. *
  11053. * function customizer(objValue, srcValue) {
  11054. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11055. * return true;
  11056. * }
  11057. * }
  11058. *
  11059. * var object = { 'greeting': 'hello' };
  11060. * var source = { 'greeting': 'hi' };
  11061. *
  11062. * _.isMatchWith(object, source, customizer);
  11063. * // => true
  11064. */
  11065. function isMatchWith(object, source, customizer) {
  11066. customizer = typeof customizer == 'function' ? customizer : undefined;
  11067. return baseIsMatch(object, source, getMatchData(source), customizer);
  11068. }
  11069. /**
  11070. * Checks if `value` is `NaN`.
  11071. *
  11072. * **Note:** This method is based on
  11073. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11074. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11075. * `undefined` and other non-number values.
  11076. *
  11077. * @static
  11078. * @memberOf _
  11079. * @since 0.1.0
  11080. * @category Lang
  11081. * @param {*} value The value to check.
  11082. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11083. * @example
  11084. *
  11085. * _.isNaN(NaN);
  11086. * // => true
  11087. *
  11088. * _.isNaN(new Number(NaN));
  11089. * // => true
  11090. *
  11091. * isNaN(undefined);
  11092. * // => true
  11093. *
  11094. * _.isNaN(undefined);
  11095. * // => false
  11096. */
  11097. function isNaN(value) {
  11098. // An `NaN` primitive is the only value that is not equal to itself.
  11099. // Perform the `toStringTag` check first to avoid errors with some
  11100. // ActiveX objects in IE.
  11101. return isNumber(value) && value != +value;
  11102. }
  11103. /**
  11104. * Checks if `value` is a pristine native function.
  11105. *
  11106. * **Note:** This method can't reliably detect native functions in the presence
  11107. * of the core-js package because core-js circumvents this kind of detection.
  11108. * Despite multiple requests, the core-js maintainer has made it clear: any
  11109. * attempt to fix the detection will be obstructed. As a result, we're left
  11110. * with little choice but to throw an error. Unfortunately, this also affects
  11111. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11112. * which rely on core-js.
  11113. *
  11114. * @static
  11115. * @memberOf _
  11116. * @since 3.0.0
  11117. * @category Lang
  11118. * @param {*} value The value to check.
  11119. * @returns {boolean} Returns `true` if `value` is a native function,
  11120. * else `false`.
  11121. * @example
  11122. *
  11123. * _.isNative(Array.prototype.push);
  11124. * // => true
  11125. *
  11126. * _.isNative(_);
  11127. * // => false
  11128. */
  11129. function isNative(value) {
  11130. if (isMaskable(value)) {
  11131. throw new Error(CORE_ERROR_TEXT);
  11132. }
  11133. return baseIsNative(value);
  11134. }
  11135. /**
  11136. * Checks if `value` is `null`.
  11137. *
  11138. * @static
  11139. * @memberOf _
  11140. * @since 0.1.0
  11141. * @category Lang
  11142. * @param {*} value The value to check.
  11143. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11144. * @example
  11145. *
  11146. * _.isNull(null);
  11147. * // => true
  11148. *
  11149. * _.isNull(void 0);
  11150. * // => false
  11151. */
  11152. function isNull(value) {
  11153. return value === null;
  11154. }
  11155. /**
  11156. * Checks if `value` is `null` or `undefined`.
  11157. *
  11158. * @static
  11159. * @memberOf _
  11160. * @since 4.0.0
  11161. * @category Lang
  11162. * @param {*} value The value to check.
  11163. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11164. * @example
  11165. *
  11166. * _.isNil(null);
  11167. * // => true
  11168. *
  11169. * _.isNil(void 0);
  11170. * // => true
  11171. *
  11172. * _.isNil(NaN);
  11173. * // => false
  11174. */
  11175. function isNil(value) {
  11176. return value == null;
  11177. }
  11178. /**
  11179. * Checks if `value` is classified as a `Number` primitive or object.
  11180. *
  11181. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11182. * classified as numbers, use the `_.isFinite` method.
  11183. *
  11184. * @static
  11185. * @memberOf _
  11186. * @since 0.1.0
  11187. * @category Lang
  11188. * @param {*} value The value to check.
  11189. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11190. * @example
  11191. *
  11192. * _.isNumber(3);
  11193. * // => true
  11194. *
  11195. * _.isNumber(Number.MIN_VALUE);
  11196. * // => true
  11197. *
  11198. * _.isNumber(Infinity);
  11199. * // => true
  11200. *
  11201. * _.isNumber('3');
  11202. * // => false
  11203. */
  11204. function isNumber(value) {
  11205. return typeof value == 'number' ||
  11206. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11207. }
  11208. /**
  11209. * Checks if `value` is a plain object, that is, an object created by the
  11210. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11211. *
  11212. * @static
  11213. * @memberOf _
  11214. * @since 0.8.0
  11215. * @category Lang
  11216. * @param {*} value The value to check.
  11217. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11218. * @example
  11219. *
  11220. * function Foo() {
  11221. * this.a = 1;
  11222. * }
  11223. *
  11224. * _.isPlainObject(new Foo);
  11225. * // => false
  11226. *
  11227. * _.isPlainObject([1, 2, 3]);
  11228. * // => false
  11229. *
  11230. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11231. * // => true
  11232. *
  11233. * _.isPlainObject(Object.create(null));
  11234. * // => true
  11235. */
  11236. function isPlainObject(value) {
  11237. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11238. return false;
  11239. }
  11240. var proto = getPrototype(value);
  11241. if (proto === null) {
  11242. return true;
  11243. }
  11244. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11245. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11246. funcToString.call(Ctor) == objectCtorString;
  11247. }
  11248. /**
  11249. * Checks if `value` is classified as a `RegExp` object.
  11250. *
  11251. * @static
  11252. * @memberOf _
  11253. * @since 0.1.0
  11254. * @category Lang
  11255. * @param {*} value The value to check.
  11256. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11257. * @example
  11258. *
  11259. * _.isRegExp(/abc/);
  11260. * // => true
  11261. *
  11262. * _.isRegExp('/abc/');
  11263. * // => false
  11264. */
  11265. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11266. /**
  11267. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11268. * double precision number which isn't the result of a rounded unsafe integer.
  11269. *
  11270. * **Note:** This method is based on
  11271. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11272. *
  11273. * @static
  11274. * @memberOf _
  11275. * @since 4.0.0
  11276. * @category Lang
  11277. * @param {*} value The value to check.
  11278. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11279. * @example
  11280. *
  11281. * _.isSafeInteger(3);
  11282. * // => true
  11283. *
  11284. * _.isSafeInteger(Number.MIN_VALUE);
  11285. * // => false
  11286. *
  11287. * _.isSafeInteger(Infinity);
  11288. * // => false
  11289. *
  11290. * _.isSafeInteger('3');
  11291. * // => false
  11292. */
  11293. function isSafeInteger(value) {
  11294. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11295. }
  11296. /**
  11297. * Checks if `value` is classified as a `Set` object.
  11298. *
  11299. * @static
  11300. * @memberOf _
  11301. * @since 4.3.0
  11302. * @category Lang
  11303. * @param {*} value The value to check.
  11304. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11305. * @example
  11306. *
  11307. * _.isSet(new Set);
  11308. * // => true
  11309. *
  11310. * _.isSet(new WeakSet);
  11311. * // => false
  11312. */
  11313. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11314. /**
  11315. * Checks if `value` is classified as a `String` primitive or object.
  11316. *
  11317. * @static
  11318. * @since 0.1.0
  11319. * @memberOf _
  11320. * @category Lang
  11321. * @param {*} value The value to check.
  11322. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11323. * @example
  11324. *
  11325. * _.isString('abc');
  11326. * // => true
  11327. *
  11328. * _.isString(1);
  11329. * // => false
  11330. */
  11331. function isString(value) {
  11332. return typeof value == 'string' ||
  11333. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11334. }
  11335. /**
  11336. * Checks if `value` is classified as a `Symbol` primitive or object.
  11337. *
  11338. * @static
  11339. * @memberOf _
  11340. * @since 4.0.0
  11341. * @category Lang
  11342. * @param {*} value The value to check.
  11343. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11344. * @example
  11345. *
  11346. * _.isSymbol(Symbol.iterator);
  11347. * // => true
  11348. *
  11349. * _.isSymbol('abc');
  11350. * // => false
  11351. */
  11352. function isSymbol(value) {
  11353. return typeof value == 'symbol' ||
  11354. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11355. }
  11356. /**
  11357. * Checks if `value` is classified as a typed array.
  11358. *
  11359. * @static
  11360. * @memberOf _
  11361. * @since 3.0.0
  11362. * @category Lang
  11363. * @param {*} value The value to check.
  11364. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11365. * @example
  11366. *
  11367. * _.isTypedArray(new Uint8Array);
  11368. * // => true
  11369. *
  11370. * _.isTypedArray([]);
  11371. * // => false
  11372. */
  11373. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11374. /**
  11375. * Checks if `value` is `undefined`.
  11376. *
  11377. * @static
  11378. * @since 0.1.0
  11379. * @memberOf _
  11380. * @category Lang
  11381. * @param {*} value The value to check.
  11382. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11383. * @example
  11384. *
  11385. * _.isUndefined(void 0);
  11386. * // => true
  11387. *
  11388. * _.isUndefined(null);
  11389. * // => false
  11390. */
  11391. function isUndefined(value) {
  11392. return value === undefined;
  11393. }
  11394. /**
  11395. * Checks if `value` is classified as a `WeakMap` object.
  11396. *
  11397. * @static
  11398. * @memberOf _
  11399. * @since 4.3.0
  11400. * @category Lang
  11401. * @param {*} value The value to check.
  11402. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11403. * @example
  11404. *
  11405. * _.isWeakMap(new WeakMap);
  11406. * // => true
  11407. *
  11408. * _.isWeakMap(new Map);
  11409. * // => false
  11410. */
  11411. function isWeakMap(value) {
  11412. return isObjectLike(value) && getTag(value) == weakMapTag;
  11413. }
  11414. /**
  11415. * Checks if `value` is classified as a `WeakSet` object.
  11416. *
  11417. * @static
  11418. * @memberOf _
  11419. * @since 4.3.0
  11420. * @category Lang
  11421. * @param {*} value The value to check.
  11422. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11423. * @example
  11424. *
  11425. * _.isWeakSet(new WeakSet);
  11426. * // => true
  11427. *
  11428. * _.isWeakSet(new Set);
  11429. * // => false
  11430. */
  11431. function isWeakSet(value) {
  11432. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11433. }
  11434. /**
  11435. * Checks if `value` is less than `other`.
  11436. *
  11437. * @static
  11438. * @memberOf _
  11439. * @since 3.9.0
  11440. * @category Lang
  11441. * @param {*} value The value to compare.
  11442. * @param {*} other The other value to compare.
  11443. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11444. * else `false`.
  11445. * @see _.gt
  11446. * @example
  11447. *
  11448. * _.lt(1, 3);
  11449. * // => true
  11450. *
  11451. * _.lt(3, 3);
  11452. * // => false
  11453. *
  11454. * _.lt(3, 1);
  11455. * // => false
  11456. */
  11457. var lt = createRelationalOperation(baseLt);
  11458. /**
  11459. * Checks if `value` is less than or equal to `other`.
  11460. *
  11461. * @static
  11462. * @memberOf _
  11463. * @since 3.9.0
  11464. * @category Lang
  11465. * @param {*} value The value to compare.
  11466. * @param {*} other The other value to compare.
  11467. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11468. * `other`, else `false`.
  11469. * @see _.gte
  11470. * @example
  11471. *
  11472. * _.lte(1, 3);
  11473. * // => true
  11474. *
  11475. * _.lte(3, 3);
  11476. * // => true
  11477. *
  11478. * _.lte(3, 1);
  11479. * // => false
  11480. */
  11481. var lte = createRelationalOperation(function(value, other) {
  11482. return value <= other;
  11483. });
  11484. /**
  11485. * Converts `value` to an array.
  11486. *
  11487. * @static
  11488. * @since 0.1.0
  11489. * @memberOf _
  11490. * @category Lang
  11491. * @param {*} value The value to convert.
  11492. * @returns {Array} Returns the converted array.
  11493. * @example
  11494. *
  11495. * _.toArray({ 'a': 1, 'b': 2 });
  11496. * // => [1, 2]
  11497. *
  11498. * _.toArray('abc');
  11499. * // => ['a', 'b', 'c']
  11500. *
  11501. * _.toArray(1);
  11502. * // => []
  11503. *
  11504. * _.toArray(null);
  11505. * // => []
  11506. */
  11507. function toArray(value) {
  11508. if (!value) {
  11509. return [];
  11510. }
  11511. if (isArrayLike(value)) {
  11512. return isString(value) ? stringToArray(value) : copyArray(value);
  11513. }
  11514. if (symIterator && value[symIterator]) {
  11515. return iteratorToArray(value[symIterator]());
  11516. }
  11517. var tag = getTag(value),
  11518. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11519. return func(value);
  11520. }
  11521. /**
  11522. * Converts `value` to a finite number.
  11523. *
  11524. * @static
  11525. * @memberOf _
  11526. * @since 4.12.0
  11527. * @category Lang
  11528. * @param {*} value The value to convert.
  11529. * @returns {number} Returns the converted number.
  11530. * @example
  11531. *
  11532. * _.toFinite(3.2);
  11533. * // => 3.2
  11534. *
  11535. * _.toFinite(Number.MIN_VALUE);
  11536. * // => 5e-324
  11537. *
  11538. * _.toFinite(Infinity);
  11539. * // => 1.7976931348623157e+308
  11540. *
  11541. * _.toFinite('3.2');
  11542. * // => 3.2
  11543. */
  11544. function toFinite(value) {
  11545. if (!value) {
  11546. return value === 0 ? value : 0;
  11547. }
  11548. value = toNumber(value);
  11549. if (value === INFINITY || value === -INFINITY) {
  11550. var sign = (value < 0 ? -1 : 1);
  11551. return sign * MAX_INTEGER;
  11552. }
  11553. return value === value ? value : 0;
  11554. }
  11555. /**
  11556. * Converts `value` to an integer.
  11557. *
  11558. * **Note:** This method is loosely based on
  11559. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11560. *
  11561. * @static
  11562. * @memberOf _
  11563. * @since 4.0.0
  11564. * @category Lang
  11565. * @param {*} value The value to convert.
  11566. * @returns {number} Returns the converted integer.
  11567. * @example
  11568. *
  11569. * _.toInteger(3.2);
  11570. * // => 3
  11571. *
  11572. * _.toInteger(Number.MIN_VALUE);
  11573. * // => 0
  11574. *
  11575. * _.toInteger(Infinity);
  11576. * // => 1.7976931348623157e+308
  11577. *
  11578. * _.toInteger('3.2');
  11579. * // => 3
  11580. */
  11581. function toInteger(value) {
  11582. var result = toFinite(value),
  11583. remainder = result % 1;
  11584. return result === result ? (remainder ? result - remainder : result) : 0;
  11585. }
  11586. /**
  11587. * Converts `value` to an integer suitable for use as the length of an
  11588. * array-like object.
  11589. *
  11590. * **Note:** This method is based on
  11591. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11592. *
  11593. * @static
  11594. * @memberOf _
  11595. * @since 4.0.0
  11596. * @category Lang
  11597. * @param {*} value The value to convert.
  11598. * @returns {number} Returns the converted integer.
  11599. * @example
  11600. *
  11601. * _.toLength(3.2);
  11602. * // => 3
  11603. *
  11604. * _.toLength(Number.MIN_VALUE);
  11605. * // => 0
  11606. *
  11607. * _.toLength(Infinity);
  11608. * // => 4294967295
  11609. *
  11610. * _.toLength('3.2');
  11611. * // => 3
  11612. */
  11613. function toLength(value) {
  11614. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11615. }
  11616. /**
  11617. * Converts `value` to a number.
  11618. *
  11619. * @static
  11620. * @memberOf _
  11621. * @since 4.0.0
  11622. * @category Lang
  11623. * @param {*} value The value to process.
  11624. * @returns {number} Returns the number.
  11625. * @example
  11626. *
  11627. * _.toNumber(3.2);
  11628. * // => 3.2
  11629. *
  11630. * _.toNumber(Number.MIN_VALUE);
  11631. * // => 5e-324
  11632. *
  11633. * _.toNumber(Infinity);
  11634. * // => Infinity
  11635. *
  11636. * _.toNumber('3.2');
  11637. * // => 3.2
  11638. */
  11639. function toNumber(value) {
  11640. if (typeof value == 'number') {
  11641. return value;
  11642. }
  11643. if (isSymbol(value)) {
  11644. return NAN;
  11645. }
  11646. if (isObject(value)) {
  11647. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11648. value = isObject(other) ? (other + '') : other;
  11649. }
  11650. if (typeof value != 'string') {
  11651. return value === 0 ? value : +value;
  11652. }
  11653. value = value.replace(reTrim, '');
  11654. var isBinary = reIsBinary.test(value);
  11655. return (isBinary || reIsOctal.test(value))
  11656. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11657. : (reIsBadHex.test(value) ? NAN : +value);
  11658. }
  11659. /**
  11660. * Converts `value` to a plain object flattening inherited enumerable string
  11661. * keyed properties of `value` to own properties of the plain object.
  11662. *
  11663. * @static
  11664. * @memberOf _
  11665. * @since 3.0.0
  11666. * @category Lang
  11667. * @param {*} value The value to convert.
  11668. * @returns {Object} Returns the converted plain object.
  11669. * @example
  11670. *
  11671. * function Foo() {
  11672. * this.b = 2;
  11673. * }
  11674. *
  11675. * Foo.prototype.c = 3;
  11676. *
  11677. * _.assign({ 'a': 1 }, new Foo);
  11678. * // => { 'a': 1, 'b': 2 }
  11679. *
  11680. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11681. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11682. */
  11683. function toPlainObject(value) {
  11684. return copyObject(value, keysIn(value));
  11685. }
  11686. /**
  11687. * Converts `value` to a safe integer. A safe integer can be compared and
  11688. * represented correctly.
  11689. *
  11690. * @static
  11691. * @memberOf _
  11692. * @since 4.0.0
  11693. * @category Lang
  11694. * @param {*} value The value to convert.
  11695. * @returns {number} Returns the converted integer.
  11696. * @example
  11697. *
  11698. * _.toSafeInteger(3.2);
  11699. * // => 3
  11700. *
  11701. * _.toSafeInteger(Number.MIN_VALUE);
  11702. * // => 0
  11703. *
  11704. * _.toSafeInteger(Infinity);
  11705. * // => 9007199254740991
  11706. *
  11707. * _.toSafeInteger('3.2');
  11708. * // => 3
  11709. */
  11710. function toSafeInteger(value) {
  11711. return value
  11712. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11713. : (value === 0 ? value : 0);
  11714. }
  11715. /**
  11716. * Converts `value` to a string. An empty string is returned for `null`
  11717. * and `undefined` values. The sign of `-0` is preserved.
  11718. *
  11719. * @static
  11720. * @memberOf _
  11721. * @since 4.0.0
  11722. * @category Lang
  11723. * @param {*} value The value to convert.
  11724. * @returns {string} Returns the converted string.
  11725. * @example
  11726. *
  11727. * _.toString(null);
  11728. * // => ''
  11729. *
  11730. * _.toString(-0);
  11731. * // => '-0'
  11732. *
  11733. * _.toString([1, 2, 3]);
  11734. * // => '1,2,3'
  11735. */
  11736. function toString(value) {
  11737. return value == null ? '' : baseToString(value);
  11738. }
  11739. /*------------------------------------------------------------------------*/
  11740. /**
  11741. * Assigns own enumerable string keyed properties of source objects to the
  11742. * destination object. Source objects are applied from left to right.
  11743. * Subsequent sources overwrite property assignments of previous sources.
  11744. *
  11745. * **Note:** This method mutates `object` and is loosely based on
  11746. * [`Object.assign`](https://mdn.io/Object/assign).
  11747. *
  11748. * @static
  11749. * @memberOf _
  11750. * @since 0.10.0
  11751. * @category Object
  11752. * @param {Object} object The destination object.
  11753. * @param {...Object} [sources] The source objects.
  11754. * @returns {Object} Returns `object`.
  11755. * @see _.assignIn
  11756. * @example
  11757. *
  11758. * function Foo() {
  11759. * this.a = 1;
  11760. * }
  11761. *
  11762. * function Bar() {
  11763. * this.c = 3;
  11764. * }
  11765. *
  11766. * Foo.prototype.b = 2;
  11767. * Bar.prototype.d = 4;
  11768. *
  11769. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11770. * // => { 'a': 1, 'c': 3 }
  11771. */
  11772. var assign = createAssigner(function(object, source) {
  11773. if (isPrototype(source) || isArrayLike(source)) {
  11774. copyObject(source, keys(source), object);
  11775. return;
  11776. }
  11777. for (var key in source) {
  11778. if (hasOwnProperty.call(source, key)) {
  11779. assignValue(object, key, source[key]);
  11780. }
  11781. }
  11782. });
  11783. /**
  11784. * This method is like `_.assign` except that it iterates over own and
  11785. * inherited source properties.
  11786. *
  11787. * **Note:** This method mutates `object`.
  11788. *
  11789. * @static
  11790. * @memberOf _
  11791. * @since 4.0.0
  11792. * @alias extend
  11793. * @category Object
  11794. * @param {Object} object The destination object.
  11795. * @param {...Object} [sources] The source objects.
  11796. * @returns {Object} Returns `object`.
  11797. * @see _.assign
  11798. * @example
  11799. *
  11800. * function Foo() {
  11801. * this.a = 1;
  11802. * }
  11803. *
  11804. * function Bar() {
  11805. * this.c = 3;
  11806. * }
  11807. *
  11808. * Foo.prototype.b = 2;
  11809. * Bar.prototype.d = 4;
  11810. *
  11811. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11812. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11813. */
  11814. var assignIn = createAssigner(function(object, source) {
  11815. copyObject(source, keysIn(source), object);
  11816. });
  11817. /**
  11818. * This method is like `_.assignIn` except that it accepts `customizer`
  11819. * which is invoked to produce the assigned values. If `customizer` returns
  11820. * `undefined`, assignment is handled by the method instead. The `customizer`
  11821. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11822. *
  11823. * **Note:** This method mutates `object`.
  11824. *
  11825. * @static
  11826. * @memberOf _
  11827. * @since 4.0.0
  11828. * @alias extendWith
  11829. * @category Object
  11830. * @param {Object} object The destination object.
  11831. * @param {...Object} sources The source objects.
  11832. * @param {Function} [customizer] The function to customize assigned values.
  11833. * @returns {Object} Returns `object`.
  11834. * @see _.assignWith
  11835. * @example
  11836. *
  11837. * function customizer(objValue, srcValue) {
  11838. * return _.isUndefined(objValue) ? srcValue : objValue;
  11839. * }
  11840. *
  11841. * var defaults = _.partialRight(_.assignInWith, customizer);
  11842. *
  11843. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11844. * // => { 'a': 1, 'b': 2 }
  11845. */
  11846. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11847. copyObject(source, keysIn(source), object, customizer);
  11848. });
  11849. /**
  11850. * This method is like `_.assign` except that it accepts `customizer`
  11851. * which is invoked to produce the assigned values. If `customizer` returns
  11852. * `undefined`, assignment is handled by the method instead. The `customizer`
  11853. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11854. *
  11855. * **Note:** This method mutates `object`.
  11856. *
  11857. * @static
  11858. * @memberOf _
  11859. * @since 4.0.0
  11860. * @category Object
  11861. * @param {Object} object The destination object.
  11862. * @param {...Object} sources The source objects.
  11863. * @param {Function} [customizer] The function to customize assigned values.
  11864. * @returns {Object} Returns `object`.
  11865. * @see _.assignInWith
  11866. * @example
  11867. *
  11868. * function customizer(objValue, srcValue) {
  11869. * return _.isUndefined(objValue) ? srcValue : objValue;
  11870. * }
  11871. *
  11872. * var defaults = _.partialRight(_.assignWith, customizer);
  11873. *
  11874. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11875. * // => { 'a': 1, 'b': 2 }
  11876. */
  11877. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11878. copyObject(source, keys(source), object, customizer);
  11879. });
  11880. /**
  11881. * Creates an array of values corresponding to `paths` of `object`.
  11882. *
  11883. * @static
  11884. * @memberOf _
  11885. * @since 1.0.0
  11886. * @category Object
  11887. * @param {Object} object The object to iterate over.
  11888. * @param {...(string|string[])} [paths] The property paths to pick.
  11889. * @returns {Array} Returns the picked values.
  11890. * @example
  11891. *
  11892. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11893. *
  11894. * _.at(object, ['a[0].b.c', 'a[1]']);
  11895. * // => [3, 4]
  11896. */
  11897. var at = flatRest(baseAt);
  11898. /**
  11899. * Creates an object that inherits from the `prototype` object. If a
  11900. * `properties` object is given, its own enumerable string keyed properties
  11901. * are assigned to the created object.
  11902. *
  11903. * @static
  11904. * @memberOf _
  11905. * @since 2.3.0
  11906. * @category Object
  11907. * @param {Object} prototype The object to inherit from.
  11908. * @param {Object} [properties] The properties to assign to the object.
  11909. * @returns {Object} Returns the new object.
  11910. * @example
  11911. *
  11912. * function Shape() {
  11913. * this.x = 0;
  11914. * this.y = 0;
  11915. * }
  11916. *
  11917. * function Circle() {
  11918. * Shape.call(this);
  11919. * }
  11920. *
  11921. * Circle.prototype = _.create(Shape.prototype, {
  11922. * 'constructor': Circle
  11923. * });
  11924. *
  11925. * var circle = new Circle;
  11926. * circle instanceof Circle;
  11927. * // => true
  11928. *
  11929. * circle instanceof Shape;
  11930. * // => true
  11931. */
  11932. function create(prototype, properties) {
  11933. var result = baseCreate(prototype);
  11934. return properties == null ? result : baseAssign(result, properties);
  11935. }
  11936. /**
  11937. * Assigns own and inherited enumerable string keyed properties of source
  11938. * objects to the destination object for all destination properties that
  11939. * resolve to `undefined`. Source objects are applied from left to right.
  11940. * Once a property is set, additional values of the same property are ignored.
  11941. *
  11942. * **Note:** This method mutates `object`.
  11943. *
  11944. * @static
  11945. * @since 0.1.0
  11946. * @memberOf _
  11947. * @category Object
  11948. * @param {Object} object The destination object.
  11949. * @param {...Object} [sources] The source objects.
  11950. * @returns {Object} Returns `object`.
  11951. * @see _.defaultsDeep
  11952. * @example
  11953. *
  11954. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11955. * // => { 'a': 1, 'b': 2 }
  11956. */
  11957. var defaults = baseRest(function(object, sources) {
  11958. object = Object(object);
  11959. var index = -1;
  11960. var length = sources.length;
  11961. var guard = length > 2 ? sources[2] : undefined;
  11962. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  11963. length = 1;
  11964. }
  11965. while (++index < length) {
  11966. var source = sources[index];
  11967. var props = keysIn(source);
  11968. var propsIndex = -1;
  11969. var propsLength = props.length;
  11970. while (++propsIndex < propsLength) {
  11971. var key = props[propsIndex];
  11972. var value = object[key];
  11973. if (value === undefined ||
  11974. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  11975. object[key] = source[key];
  11976. }
  11977. }
  11978. }
  11979. return object;
  11980. });
  11981. /**
  11982. * This method is like `_.defaults` except that it recursively assigns
  11983. * default properties.
  11984. *
  11985. * **Note:** This method mutates `object`.
  11986. *
  11987. * @static
  11988. * @memberOf _
  11989. * @since 3.10.0
  11990. * @category Object
  11991. * @param {Object} object The destination object.
  11992. * @param {...Object} [sources] The source objects.
  11993. * @returns {Object} Returns `object`.
  11994. * @see _.defaults
  11995. * @example
  11996. *
  11997. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11998. * // => { 'a': { 'b': 2, 'c': 3 } }
  11999. */
  12000. var defaultsDeep = baseRest(function(args) {
  12001. args.push(undefined, customDefaultsMerge);
  12002. return apply(mergeWith, undefined, args);
  12003. });
  12004. /**
  12005. * This method is like `_.find` except that it returns the key of the first
  12006. * element `predicate` returns truthy for instead of the element itself.
  12007. *
  12008. * @static
  12009. * @memberOf _
  12010. * @since 1.1.0
  12011. * @category Object
  12012. * @param {Object} object The object to inspect.
  12013. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12014. * @returns {string|undefined} Returns the key of the matched element,
  12015. * else `undefined`.
  12016. * @example
  12017. *
  12018. * var users = {
  12019. * 'barney': { 'age': 36, 'active': true },
  12020. * 'fred': { 'age': 40, 'active': false },
  12021. * 'pebbles': { 'age': 1, 'active': true }
  12022. * };
  12023. *
  12024. * _.findKey(users, function(o) { return o.age < 40; });
  12025. * // => 'barney' (iteration order is not guaranteed)
  12026. *
  12027. * // The `_.matches` iteratee shorthand.
  12028. * _.findKey(users, { 'age': 1, 'active': true });
  12029. * // => 'pebbles'
  12030. *
  12031. * // The `_.matchesProperty` iteratee shorthand.
  12032. * _.findKey(users, ['active', false]);
  12033. * // => 'fred'
  12034. *
  12035. * // The `_.property` iteratee shorthand.
  12036. * _.findKey(users, 'active');
  12037. * // => 'barney'
  12038. */
  12039. function findKey(object, predicate) {
  12040. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12041. }
  12042. /**
  12043. * This method is like `_.findKey` except that it iterates over elements of
  12044. * a collection in the opposite order.
  12045. *
  12046. * @static
  12047. * @memberOf _
  12048. * @since 2.0.0
  12049. * @category Object
  12050. * @param {Object} object The object to inspect.
  12051. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12052. * @returns {string|undefined} Returns the key of the matched element,
  12053. * else `undefined`.
  12054. * @example
  12055. *
  12056. * var users = {
  12057. * 'barney': { 'age': 36, 'active': true },
  12058. * 'fred': { 'age': 40, 'active': false },
  12059. * 'pebbles': { 'age': 1, 'active': true }
  12060. * };
  12061. *
  12062. * _.findLastKey(users, function(o) { return o.age < 40; });
  12063. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12064. *
  12065. * // The `_.matches` iteratee shorthand.
  12066. * _.findLastKey(users, { 'age': 36, 'active': true });
  12067. * // => 'barney'
  12068. *
  12069. * // The `_.matchesProperty` iteratee shorthand.
  12070. * _.findLastKey(users, ['active', false]);
  12071. * // => 'fred'
  12072. *
  12073. * // The `_.property` iteratee shorthand.
  12074. * _.findLastKey(users, 'active');
  12075. * // => 'pebbles'
  12076. */
  12077. function findLastKey(object, predicate) {
  12078. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12079. }
  12080. /**
  12081. * Iterates over own and inherited enumerable string keyed properties of an
  12082. * object and invokes `iteratee` for each property. The iteratee is invoked
  12083. * with three arguments: (value, key, object). Iteratee functions may exit
  12084. * iteration early by explicitly returning `false`.
  12085. *
  12086. * @static
  12087. * @memberOf _
  12088. * @since 0.3.0
  12089. * @category Object
  12090. * @param {Object} object The object to iterate over.
  12091. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12092. * @returns {Object} Returns `object`.
  12093. * @see _.forInRight
  12094. * @example
  12095. *
  12096. * function Foo() {
  12097. * this.a = 1;
  12098. * this.b = 2;
  12099. * }
  12100. *
  12101. * Foo.prototype.c = 3;
  12102. *
  12103. * _.forIn(new Foo, function(value, key) {
  12104. * console.log(key);
  12105. * });
  12106. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12107. */
  12108. function forIn(object, iteratee) {
  12109. return object == null
  12110. ? object
  12111. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12112. }
  12113. /**
  12114. * This method is like `_.forIn` except that it iterates over properties of
  12115. * `object` in the opposite order.
  12116. *
  12117. * @static
  12118. * @memberOf _
  12119. * @since 2.0.0
  12120. * @category Object
  12121. * @param {Object} object The object to iterate over.
  12122. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12123. * @returns {Object} Returns `object`.
  12124. * @see _.forIn
  12125. * @example
  12126. *
  12127. * function Foo() {
  12128. * this.a = 1;
  12129. * this.b = 2;
  12130. * }
  12131. *
  12132. * Foo.prototype.c = 3;
  12133. *
  12134. * _.forInRight(new Foo, function(value, key) {
  12135. * console.log(key);
  12136. * });
  12137. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12138. */
  12139. function forInRight(object, iteratee) {
  12140. return object == null
  12141. ? object
  12142. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12143. }
  12144. /**
  12145. * Iterates over own enumerable string keyed properties of an object and
  12146. * invokes `iteratee` for each property. The iteratee is invoked with three
  12147. * arguments: (value, key, object). Iteratee functions may exit iteration
  12148. * early by explicitly returning `false`.
  12149. *
  12150. * @static
  12151. * @memberOf _
  12152. * @since 0.3.0
  12153. * @category Object
  12154. * @param {Object} object The object to iterate over.
  12155. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12156. * @returns {Object} Returns `object`.
  12157. * @see _.forOwnRight
  12158. * @example
  12159. *
  12160. * function Foo() {
  12161. * this.a = 1;
  12162. * this.b = 2;
  12163. * }
  12164. *
  12165. * Foo.prototype.c = 3;
  12166. *
  12167. * _.forOwn(new Foo, function(value, key) {
  12168. * console.log(key);
  12169. * });
  12170. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12171. */
  12172. function forOwn(object, iteratee) {
  12173. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12174. }
  12175. /**
  12176. * This method is like `_.forOwn` except that it iterates over properties of
  12177. * `object` in the opposite order.
  12178. *
  12179. * @static
  12180. * @memberOf _
  12181. * @since 2.0.0
  12182. * @category Object
  12183. * @param {Object} object The object to iterate over.
  12184. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12185. * @returns {Object} Returns `object`.
  12186. * @see _.forOwn
  12187. * @example
  12188. *
  12189. * function Foo() {
  12190. * this.a = 1;
  12191. * this.b = 2;
  12192. * }
  12193. *
  12194. * Foo.prototype.c = 3;
  12195. *
  12196. * _.forOwnRight(new Foo, function(value, key) {
  12197. * console.log(key);
  12198. * });
  12199. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12200. */
  12201. function forOwnRight(object, iteratee) {
  12202. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12203. }
  12204. /**
  12205. * Creates an array of function property names from own enumerable properties
  12206. * of `object`.
  12207. *
  12208. * @static
  12209. * @since 0.1.0
  12210. * @memberOf _
  12211. * @category Object
  12212. * @param {Object} object The object to inspect.
  12213. * @returns {Array} Returns the function names.
  12214. * @see _.functionsIn
  12215. * @example
  12216. *
  12217. * function Foo() {
  12218. * this.a = _.constant('a');
  12219. * this.b = _.constant('b');
  12220. * }
  12221. *
  12222. * Foo.prototype.c = _.constant('c');
  12223. *
  12224. * _.functions(new Foo);
  12225. * // => ['a', 'b']
  12226. */
  12227. function functions(object) {
  12228. return object == null ? [] : baseFunctions(object, keys(object));
  12229. }
  12230. /**
  12231. * Creates an array of function property names from own and inherited
  12232. * enumerable properties of `object`.
  12233. *
  12234. * @static
  12235. * @memberOf _
  12236. * @since 4.0.0
  12237. * @category Object
  12238. * @param {Object} object The object to inspect.
  12239. * @returns {Array} Returns the function names.
  12240. * @see _.functions
  12241. * @example
  12242. *
  12243. * function Foo() {
  12244. * this.a = _.constant('a');
  12245. * this.b = _.constant('b');
  12246. * }
  12247. *
  12248. * Foo.prototype.c = _.constant('c');
  12249. *
  12250. * _.functionsIn(new Foo);
  12251. * // => ['a', 'b', 'c']
  12252. */
  12253. function functionsIn(object) {
  12254. return object == null ? [] : baseFunctions(object, keysIn(object));
  12255. }
  12256. /**
  12257. * Gets the value at `path` of `object`. If the resolved value is
  12258. * `undefined`, the `defaultValue` is returned in its place.
  12259. *
  12260. * @static
  12261. * @memberOf _
  12262. * @since 3.7.0
  12263. * @category Object
  12264. * @param {Object} object The object to query.
  12265. * @param {Array|string} path The path of the property to get.
  12266. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12267. * @returns {*} Returns the resolved value.
  12268. * @example
  12269. *
  12270. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12271. *
  12272. * _.get(object, 'a[0].b.c');
  12273. * // => 3
  12274. *
  12275. * _.get(object, ['a', '0', 'b', 'c']);
  12276. * // => 3
  12277. *
  12278. * _.get(object, 'a.b.c', 'default');
  12279. * // => 'default'
  12280. */
  12281. function get(object, path, defaultValue) {
  12282. var result = object == null ? undefined : baseGet(object, path);
  12283. return result === undefined ? defaultValue : result;
  12284. }
  12285. /**
  12286. * Checks if `path` is a direct property of `object`.
  12287. *
  12288. * @static
  12289. * @since 0.1.0
  12290. * @memberOf _
  12291. * @category Object
  12292. * @param {Object} object The object to query.
  12293. * @param {Array|string} path The path to check.
  12294. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12295. * @example
  12296. *
  12297. * var object = { 'a': { 'b': 2 } };
  12298. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12299. *
  12300. * _.has(object, 'a');
  12301. * // => true
  12302. *
  12303. * _.has(object, 'a.b');
  12304. * // => true
  12305. *
  12306. * _.has(object, ['a', 'b']);
  12307. * // => true
  12308. *
  12309. * _.has(other, 'a');
  12310. * // => false
  12311. */
  12312. function has(object, path) {
  12313. return object != null && hasPath(object, path, baseHas);
  12314. }
  12315. /**
  12316. * Checks if `path` is a direct or inherited property of `object`.
  12317. *
  12318. * @static
  12319. * @memberOf _
  12320. * @since 4.0.0
  12321. * @category Object
  12322. * @param {Object} object The object to query.
  12323. * @param {Array|string} path The path to check.
  12324. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12325. * @example
  12326. *
  12327. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12328. *
  12329. * _.hasIn(object, 'a');
  12330. * // => true
  12331. *
  12332. * _.hasIn(object, 'a.b');
  12333. * // => true
  12334. *
  12335. * _.hasIn(object, ['a', 'b']);
  12336. * // => true
  12337. *
  12338. * _.hasIn(object, 'b');
  12339. * // => false
  12340. */
  12341. function hasIn(object, path) {
  12342. return object != null && hasPath(object, path, baseHasIn);
  12343. }
  12344. /**
  12345. * Creates an object composed of the inverted keys and values of `object`.
  12346. * If `object` contains duplicate values, subsequent values overwrite
  12347. * property assignments of previous values.
  12348. *
  12349. * @static
  12350. * @memberOf _
  12351. * @since 0.7.0
  12352. * @category Object
  12353. * @param {Object} object The object to invert.
  12354. * @returns {Object} Returns the new inverted object.
  12355. * @example
  12356. *
  12357. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12358. *
  12359. * _.invert(object);
  12360. * // => { '1': 'c', '2': 'b' }
  12361. */
  12362. var invert = createInverter(function(result, value, key) {
  12363. if (value != null &&
  12364. typeof value.toString != 'function') {
  12365. value = nativeObjectToString.call(value);
  12366. }
  12367. result[value] = key;
  12368. }, constant(identity));
  12369. /**
  12370. * This method is like `_.invert` except that the inverted object is generated
  12371. * from the results of running each element of `object` thru `iteratee`. The
  12372. * corresponding inverted value of each inverted key is an array of keys
  12373. * responsible for generating the inverted value. The iteratee is invoked
  12374. * with one argument: (value).
  12375. *
  12376. * @static
  12377. * @memberOf _
  12378. * @since 4.1.0
  12379. * @category Object
  12380. * @param {Object} object The object to invert.
  12381. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12382. * @returns {Object} Returns the new inverted object.
  12383. * @example
  12384. *
  12385. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12386. *
  12387. * _.invertBy(object);
  12388. * // => { '1': ['a', 'c'], '2': ['b'] }
  12389. *
  12390. * _.invertBy(object, function(value) {
  12391. * return 'group' + value;
  12392. * });
  12393. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12394. */
  12395. var invertBy = createInverter(function(result, value, key) {
  12396. if (value != null &&
  12397. typeof value.toString != 'function') {
  12398. value = nativeObjectToString.call(value);
  12399. }
  12400. if (hasOwnProperty.call(result, value)) {
  12401. result[value].push(key);
  12402. } else {
  12403. result[value] = [key];
  12404. }
  12405. }, getIteratee);
  12406. /**
  12407. * Invokes the method at `path` of `object`.
  12408. *
  12409. * @static
  12410. * @memberOf _
  12411. * @since 4.0.0
  12412. * @category Object
  12413. * @param {Object} object The object to query.
  12414. * @param {Array|string} path The path of the method to invoke.
  12415. * @param {...*} [args] The arguments to invoke the method with.
  12416. * @returns {*} Returns the result of the invoked method.
  12417. * @example
  12418. *
  12419. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12420. *
  12421. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12422. * // => [2, 3]
  12423. */
  12424. var invoke = baseRest(baseInvoke);
  12425. /**
  12426. * Creates an array of the own enumerable property names of `object`.
  12427. *
  12428. * **Note:** Non-object values are coerced to objects. See the
  12429. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12430. * for more details.
  12431. *
  12432. * @static
  12433. * @since 0.1.0
  12434. * @memberOf _
  12435. * @category Object
  12436. * @param {Object} object The object to query.
  12437. * @returns {Array} Returns the array of property names.
  12438. * @example
  12439. *
  12440. * function Foo() {
  12441. * this.a = 1;
  12442. * this.b = 2;
  12443. * }
  12444. *
  12445. * Foo.prototype.c = 3;
  12446. *
  12447. * _.keys(new Foo);
  12448. * // => ['a', 'b'] (iteration order is not guaranteed)
  12449. *
  12450. * _.keys('hi');
  12451. * // => ['0', '1']
  12452. */
  12453. function keys(object) {
  12454. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12455. }
  12456. /**
  12457. * Creates an array of the own and inherited enumerable property names of `object`.
  12458. *
  12459. * **Note:** Non-object values are coerced to objects.
  12460. *
  12461. * @static
  12462. * @memberOf _
  12463. * @since 3.0.0
  12464. * @category Object
  12465. * @param {Object} object The object to query.
  12466. * @returns {Array} Returns the array of property names.
  12467. * @example
  12468. *
  12469. * function Foo() {
  12470. * this.a = 1;
  12471. * this.b = 2;
  12472. * }
  12473. *
  12474. * Foo.prototype.c = 3;
  12475. *
  12476. * _.keysIn(new Foo);
  12477. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12478. */
  12479. function keysIn(object) {
  12480. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12481. }
  12482. /**
  12483. * The opposite of `_.mapValues`; this method creates an object with the
  12484. * same values as `object` and keys generated by running each own enumerable
  12485. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12486. * with three arguments: (value, key, object).
  12487. *
  12488. * @static
  12489. * @memberOf _
  12490. * @since 3.8.0
  12491. * @category Object
  12492. * @param {Object} object The object to iterate over.
  12493. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12494. * @returns {Object} Returns the new mapped object.
  12495. * @see _.mapValues
  12496. * @example
  12497. *
  12498. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12499. * return key + value;
  12500. * });
  12501. * // => { 'a1': 1, 'b2': 2 }
  12502. */
  12503. function mapKeys(object, iteratee) {
  12504. var result = {};
  12505. iteratee = getIteratee(iteratee, 3);
  12506. baseForOwn(object, function(value, key, object) {
  12507. baseAssignValue(result, iteratee(value, key, object), value);
  12508. });
  12509. return result;
  12510. }
  12511. /**
  12512. * Creates an object with the same keys as `object` and values generated
  12513. * by running each own enumerable string keyed property of `object` thru
  12514. * `iteratee`. The iteratee is invoked with three arguments:
  12515. * (value, key, object).
  12516. *
  12517. * @static
  12518. * @memberOf _
  12519. * @since 2.4.0
  12520. * @category Object
  12521. * @param {Object} object The object to iterate over.
  12522. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12523. * @returns {Object} Returns the new mapped object.
  12524. * @see _.mapKeys
  12525. * @example
  12526. *
  12527. * var users = {
  12528. * 'fred': { 'user': 'fred', 'age': 40 },
  12529. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12530. * };
  12531. *
  12532. * _.mapValues(users, function(o) { return o.age; });
  12533. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12534. *
  12535. * // The `_.property` iteratee shorthand.
  12536. * _.mapValues(users, 'age');
  12537. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12538. */
  12539. function mapValues(object, iteratee) {
  12540. var result = {};
  12541. iteratee = getIteratee(iteratee, 3);
  12542. baseForOwn(object, function(value, key, object) {
  12543. baseAssignValue(result, key, iteratee(value, key, object));
  12544. });
  12545. return result;
  12546. }
  12547. /**
  12548. * This method is like `_.assign` except that it recursively merges own and
  12549. * inherited enumerable string keyed properties of source objects into the
  12550. * destination object. Source properties that resolve to `undefined` are
  12551. * skipped if a destination value exists. Array and plain object properties
  12552. * are merged recursively. Other objects and value types are overridden by
  12553. * assignment. Source objects are applied from left to right. Subsequent
  12554. * sources overwrite property assignments of previous sources.
  12555. *
  12556. * **Note:** This method mutates `object`.
  12557. *
  12558. * @static
  12559. * @memberOf _
  12560. * @since 0.5.0
  12561. * @category Object
  12562. * @param {Object} object The destination object.
  12563. * @param {...Object} [sources] The source objects.
  12564. * @returns {Object} Returns `object`.
  12565. * @example
  12566. *
  12567. * var object = {
  12568. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12569. * };
  12570. *
  12571. * var other = {
  12572. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12573. * };
  12574. *
  12575. * _.merge(object, other);
  12576. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12577. */
  12578. var merge = createAssigner(function(object, source, srcIndex) {
  12579. baseMerge(object, source, srcIndex);
  12580. });
  12581. /**
  12582. * This method is like `_.merge` except that it accepts `customizer` which
  12583. * is invoked to produce the merged values of the destination and source
  12584. * properties. If `customizer` returns `undefined`, merging is handled by the
  12585. * method instead. The `customizer` is invoked with six arguments:
  12586. * (objValue, srcValue, key, object, source, stack).
  12587. *
  12588. * **Note:** This method mutates `object`.
  12589. *
  12590. * @static
  12591. * @memberOf _
  12592. * @since 4.0.0
  12593. * @category Object
  12594. * @param {Object} object The destination object.
  12595. * @param {...Object} sources The source objects.
  12596. * @param {Function} customizer The function to customize assigned values.
  12597. * @returns {Object} Returns `object`.
  12598. * @example
  12599. *
  12600. * function customizer(objValue, srcValue) {
  12601. * if (_.isArray(objValue)) {
  12602. * return objValue.concat(srcValue);
  12603. * }
  12604. * }
  12605. *
  12606. * var object = { 'a': [1], 'b': [2] };
  12607. * var other = { 'a': [3], 'b': [4] };
  12608. *
  12609. * _.mergeWith(object, other, customizer);
  12610. * // => { 'a': [1, 3], 'b': [2, 4] }
  12611. */
  12612. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12613. baseMerge(object, source, srcIndex, customizer);
  12614. });
  12615. /**
  12616. * The opposite of `_.pick`; this method creates an object composed of the
  12617. * own and inherited enumerable property paths of `object` that are not omitted.
  12618. *
  12619. * **Note:** This method is considerably slower than `_.pick`.
  12620. *
  12621. * @static
  12622. * @since 0.1.0
  12623. * @memberOf _
  12624. * @category Object
  12625. * @param {Object} object The source object.
  12626. * @param {...(string|string[])} [paths] The property paths to omit.
  12627. * @returns {Object} Returns the new object.
  12628. * @example
  12629. *
  12630. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12631. *
  12632. * _.omit(object, ['a', 'c']);
  12633. * // => { 'b': '2' }
  12634. */
  12635. var omit = flatRest(function(object, paths) {
  12636. var result = {};
  12637. if (object == null) {
  12638. return result;
  12639. }
  12640. var isDeep = false;
  12641. paths = arrayMap(paths, function(path) {
  12642. path = castPath(path, object);
  12643. isDeep || (isDeep = path.length > 1);
  12644. return path;
  12645. });
  12646. copyObject(object, getAllKeysIn(object), result);
  12647. if (isDeep) {
  12648. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12649. }
  12650. var length = paths.length;
  12651. while (length--) {
  12652. baseUnset(result, paths[length]);
  12653. }
  12654. return result;
  12655. });
  12656. /**
  12657. * The opposite of `_.pickBy`; this method creates an object composed of
  12658. * the own and inherited enumerable string keyed properties of `object` that
  12659. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12660. * arguments: (value, key).
  12661. *
  12662. * @static
  12663. * @memberOf _
  12664. * @since 4.0.0
  12665. * @category Object
  12666. * @param {Object} object The source object.
  12667. * @param {Function} [predicate=_.identity] The function invoked per property.
  12668. * @returns {Object} Returns the new object.
  12669. * @example
  12670. *
  12671. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12672. *
  12673. * _.omitBy(object, _.isNumber);
  12674. * // => { 'b': '2' }
  12675. */
  12676. function omitBy(object, predicate) {
  12677. return pickBy(object, negate(getIteratee(predicate)));
  12678. }
  12679. /**
  12680. * Creates an object composed of the picked `object` properties.
  12681. *
  12682. * @static
  12683. * @since 0.1.0
  12684. * @memberOf _
  12685. * @category Object
  12686. * @param {Object} object The source object.
  12687. * @param {...(string|string[])} [paths] The property paths to pick.
  12688. * @returns {Object} Returns the new object.
  12689. * @example
  12690. *
  12691. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12692. *
  12693. * _.pick(object, ['a', 'c']);
  12694. * // => { 'a': 1, 'c': 3 }
  12695. */
  12696. var pick = flatRest(function(object, paths) {
  12697. return object == null ? {} : basePick(object, paths);
  12698. });
  12699. /**
  12700. * Creates an object composed of the `object` properties `predicate` returns
  12701. * truthy for. The predicate is invoked with two arguments: (value, key).
  12702. *
  12703. * @static
  12704. * @memberOf _
  12705. * @since 4.0.0
  12706. * @category Object
  12707. * @param {Object} object The source object.
  12708. * @param {Function} [predicate=_.identity] The function invoked per property.
  12709. * @returns {Object} Returns the new object.
  12710. * @example
  12711. *
  12712. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12713. *
  12714. * _.pickBy(object, _.isNumber);
  12715. * // => { 'a': 1, 'c': 3 }
  12716. */
  12717. function pickBy(object, predicate) {
  12718. if (object == null) {
  12719. return {};
  12720. }
  12721. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12722. return [prop];
  12723. });
  12724. predicate = getIteratee(predicate);
  12725. return basePickBy(object, props, function(value, path) {
  12726. return predicate(value, path[0]);
  12727. });
  12728. }
  12729. /**
  12730. * This method is like `_.get` except that if the resolved value is a
  12731. * function it's invoked with the `this` binding of its parent object and
  12732. * its result is returned.
  12733. *
  12734. * @static
  12735. * @since 0.1.0
  12736. * @memberOf _
  12737. * @category Object
  12738. * @param {Object} object The object to query.
  12739. * @param {Array|string} path The path of the property to resolve.
  12740. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12741. * @returns {*} Returns the resolved value.
  12742. * @example
  12743. *
  12744. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12745. *
  12746. * _.result(object, 'a[0].b.c1');
  12747. * // => 3
  12748. *
  12749. * _.result(object, 'a[0].b.c2');
  12750. * // => 4
  12751. *
  12752. * _.result(object, 'a[0].b.c3', 'default');
  12753. * // => 'default'
  12754. *
  12755. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12756. * // => 'default'
  12757. */
  12758. function result(object, path, defaultValue) {
  12759. path = castPath(path, object);
  12760. var index = -1,
  12761. length = path.length;
  12762. // Ensure the loop is entered when path is empty.
  12763. if (!length) {
  12764. length = 1;
  12765. object = undefined;
  12766. }
  12767. while (++index < length) {
  12768. var value = object == null ? undefined : object[toKey(path[index])];
  12769. if (value === undefined) {
  12770. index = length;
  12771. value = defaultValue;
  12772. }
  12773. object = isFunction(value) ? value.call(object) : value;
  12774. }
  12775. return object;
  12776. }
  12777. /**
  12778. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12779. * it's created. Arrays are created for missing index properties while objects
  12780. * are created for all other missing properties. Use `_.setWith` to customize
  12781. * `path` creation.
  12782. *
  12783. * **Note:** This method mutates `object`.
  12784. *
  12785. * @static
  12786. * @memberOf _
  12787. * @since 3.7.0
  12788. * @category Object
  12789. * @param {Object} object The object to modify.
  12790. * @param {Array|string} path The path of the property to set.
  12791. * @param {*} value The value to set.
  12792. * @returns {Object} Returns `object`.
  12793. * @example
  12794. *
  12795. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12796. *
  12797. * _.set(object, 'a[0].b.c', 4);
  12798. * console.log(object.a[0].b.c);
  12799. * // => 4
  12800. *
  12801. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12802. * console.log(object.x[0].y.z);
  12803. * // => 5
  12804. */
  12805. function set(object, path, value) {
  12806. return object == null ? object : baseSet(object, path, value);
  12807. }
  12808. /**
  12809. * This method is like `_.set` except that it accepts `customizer` which is
  12810. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12811. * path creation is handled by the method instead. The `customizer` is invoked
  12812. * with three arguments: (nsValue, key, nsObject).
  12813. *
  12814. * **Note:** This method mutates `object`.
  12815. *
  12816. * @static
  12817. * @memberOf _
  12818. * @since 4.0.0
  12819. * @category Object
  12820. * @param {Object} object The object to modify.
  12821. * @param {Array|string} path The path of the property to set.
  12822. * @param {*} value The value to set.
  12823. * @param {Function} [customizer] The function to customize assigned values.
  12824. * @returns {Object} Returns `object`.
  12825. * @example
  12826. *
  12827. * var object = {};
  12828. *
  12829. * _.setWith(object, '[0][1]', 'a', Object);
  12830. * // => { '0': { '1': 'a' } }
  12831. */
  12832. function setWith(object, path, value, customizer) {
  12833. customizer = typeof customizer == 'function' ? customizer : undefined;
  12834. return object == null ? object : baseSet(object, path, value, customizer);
  12835. }
  12836. /**
  12837. * Creates an array of own enumerable string keyed-value pairs for `object`
  12838. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12839. * entries are returned.
  12840. *
  12841. * @static
  12842. * @memberOf _
  12843. * @since 4.0.0
  12844. * @alias entries
  12845. * @category Object
  12846. * @param {Object} object The object to query.
  12847. * @returns {Array} Returns the key-value pairs.
  12848. * @example
  12849. *
  12850. * function Foo() {
  12851. * this.a = 1;
  12852. * this.b = 2;
  12853. * }
  12854. *
  12855. * Foo.prototype.c = 3;
  12856. *
  12857. * _.toPairs(new Foo);
  12858. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12859. */
  12860. var toPairs = createToPairs(keys);
  12861. /**
  12862. * Creates an array of own and inherited enumerable string keyed-value pairs
  12863. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12864. * or set, its entries are returned.
  12865. *
  12866. * @static
  12867. * @memberOf _
  12868. * @since 4.0.0
  12869. * @alias entriesIn
  12870. * @category Object
  12871. * @param {Object} object The object to query.
  12872. * @returns {Array} Returns the key-value pairs.
  12873. * @example
  12874. *
  12875. * function Foo() {
  12876. * this.a = 1;
  12877. * this.b = 2;
  12878. * }
  12879. *
  12880. * Foo.prototype.c = 3;
  12881. *
  12882. * _.toPairsIn(new Foo);
  12883. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12884. */
  12885. var toPairsIn = createToPairs(keysIn);
  12886. /**
  12887. * An alternative to `_.reduce`; this method transforms `object` to a new
  12888. * `accumulator` object which is the result of running each of its own
  12889. * enumerable string keyed properties thru `iteratee`, with each invocation
  12890. * potentially mutating the `accumulator` object. If `accumulator` is not
  12891. * provided, a new object with the same `[[Prototype]]` will be used. The
  12892. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12893. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12894. *
  12895. * @static
  12896. * @memberOf _
  12897. * @since 1.3.0
  12898. * @category Object
  12899. * @param {Object} object The object to iterate over.
  12900. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12901. * @param {*} [accumulator] The custom accumulator value.
  12902. * @returns {*} Returns the accumulated value.
  12903. * @example
  12904. *
  12905. * _.transform([2, 3, 4], function(result, n) {
  12906. * result.push(n *= n);
  12907. * return n % 2 == 0;
  12908. * }, []);
  12909. * // => [4, 9]
  12910. *
  12911. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12912. * (result[value] || (result[value] = [])).push(key);
  12913. * }, {});
  12914. * // => { '1': ['a', 'c'], '2': ['b'] }
  12915. */
  12916. function transform(object, iteratee, accumulator) {
  12917. var isArr = isArray(object),
  12918. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12919. iteratee = getIteratee(iteratee, 4);
  12920. if (accumulator == null) {
  12921. var Ctor = object && object.constructor;
  12922. if (isArrLike) {
  12923. accumulator = isArr ? new Ctor : [];
  12924. }
  12925. else if (isObject(object)) {
  12926. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12927. }
  12928. else {
  12929. accumulator = {};
  12930. }
  12931. }
  12932. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12933. return iteratee(accumulator, value, index, object);
  12934. });
  12935. return accumulator;
  12936. }
  12937. /**
  12938. * Removes the property at `path` of `object`.
  12939. *
  12940. * **Note:** This method mutates `object`.
  12941. *
  12942. * @static
  12943. * @memberOf _
  12944. * @since 4.0.0
  12945. * @category Object
  12946. * @param {Object} object The object to modify.
  12947. * @param {Array|string} path The path of the property to unset.
  12948. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12949. * @example
  12950. *
  12951. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12952. * _.unset(object, 'a[0].b.c');
  12953. * // => true
  12954. *
  12955. * console.log(object);
  12956. * // => { 'a': [{ 'b': {} }] };
  12957. *
  12958. * _.unset(object, ['a', '0', 'b', 'c']);
  12959. * // => true
  12960. *
  12961. * console.log(object);
  12962. * // => { 'a': [{ 'b': {} }] };
  12963. */
  12964. function unset(object, path) {
  12965. return object == null ? true : baseUnset(object, path);
  12966. }
  12967. /**
  12968. * This method is like `_.set` except that accepts `updater` to produce the
  12969. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12970. * is invoked with one argument: (value).
  12971. *
  12972. * **Note:** This method mutates `object`.
  12973. *
  12974. * @static
  12975. * @memberOf _
  12976. * @since 4.6.0
  12977. * @category Object
  12978. * @param {Object} object The object to modify.
  12979. * @param {Array|string} path The path of the property to set.
  12980. * @param {Function} updater The function to produce the updated value.
  12981. * @returns {Object} Returns `object`.
  12982. * @example
  12983. *
  12984. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12985. *
  12986. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12987. * console.log(object.a[0].b.c);
  12988. * // => 9
  12989. *
  12990. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12991. * console.log(object.x[0].y.z);
  12992. * // => 0
  12993. */
  12994. function update(object, path, updater) {
  12995. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12996. }
  12997. /**
  12998. * This method is like `_.update` except that it accepts `customizer` which is
  12999. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13000. * path creation is handled by the method instead. The `customizer` is invoked
  13001. * with three arguments: (nsValue, key, nsObject).
  13002. *
  13003. * **Note:** This method mutates `object`.
  13004. *
  13005. * @static
  13006. * @memberOf _
  13007. * @since 4.6.0
  13008. * @category Object
  13009. * @param {Object} object The object to modify.
  13010. * @param {Array|string} path The path of the property to set.
  13011. * @param {Function} updater The function to produce the updated value.
  13012. * @param {Function} [customizer] The function to customize assigned values.
  13013. * @returns {Object} Returns `object`.
  13014. * @example
  13015. *
  13016. * var object = {};
  13017. *
  13018. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13019. * // => { '0': { '1': 'a' } }
  13020. */
  13021. function updateWith(object, path, updater, customizer) {
  13022. customizer = typeof customizer == 'function' ? customizer : undefined;
  13023. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13024. }
  13025. /**
  13026. * Creates an array of the own enumerable string keyed property values of `object`.
  13027. *
  13028. * **Note:** Non-object values are coerced to objects.
  13029. *
  13030. * @static
  13031. * @since 0.1.0
  13032. * @memberOf _
  13033. * @category Object
  13034. * @param {Object} object The object to query.
  13035. * @returns {Array} Returns the array of property values.
  13036. * @example
  13037. *
  13038. * function Foo() {
  13039. * this.a = 1;
  13040. * this.b = 2;
  13041. * }
  13042. *
  13043. * Foo.prototype.c = 3;
  13044. *
  13045. * _.values(new Foo);
  13046. * // => [1, 2] (iteration order is not guaranteed)
  13047. *
  13048. * _.values('hi');
  13049. * // => ['h', 'i']
  13050. */
  13051. function values(object) {
  13052. return object == null ? [] : baseValues(object, keys(object));
  13053. }
  13054. /**
  13055. * Creates an array of the own and inherited enumerable string keyed property
  13056. * values of `object`.
  13057. *
  13058. * **Note:** Non-object values are coerced to objects.
  13059. *
  13060. * @static
  13061. * @memberOf _
  13062. * @since 3.0.0
  13063. * @category Object
  13064. * @param {Object} object The object to query.
  13065. * @returns {Array} Returns the array of property values.
  13066. * @example
  13067. *
  13068. * function Foo() {
  13069. * this.a = 1;
  13070. * this.b = 2;
  13071. * }
  13072. *
  13073. * Foo.prototype.c = 3;
  13074. *
  13075. * _.valuesIn(new Foo);
  13076. * // => [1, 2, 3] (iteration order is not guaranteed)
  13077. */
  13078. function valuesIn(object) {
  13079. return object == null ? [] : baseValues(object, keysIn(object));
  13080. }
  13081. /*------------------------------------------------------------------------*/
  13082. /**
  13083. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13084. *
  13085. * @static
  13086. * @memberOf _
  13087. * @since 4.0.0
  13088. * @category Number
  13089. * @param {number} number The number to clamp.
  13090. * @param {number} [lower] The lower bound.
  13091. * @param {number} upper The upper bound.
  13092. * @returns {number} Returns the clamped number.
  13093. * @example
  13094. *
  13095. * _.clamp(-10, -5, 5);
  13096. * // => -5
  13097. *
  13098. * _.clamp(10, -5, 5);
  13099. * // => 5
  13100. */
  13101. function clamp(number, lower, upper) {
  13102. if (upper === undefined) {
  13103. upper = lower;
  13104. lower = undefined;
  13105. }
  13106. if (upper !== undefined) {
  13107. upper = toNumber(upper);
  13108. upper = upper === upper ? upper : 0;
  13109. }
  13110. if (lower !== undefined) {
  13111. lower = toNumber(lower);
  13112. lower = lower === lower ? lower : 0;
  13113. }
  13114. return baseClamp(toNumber(number), lower, upper);
  13115. }
  13116. /**
  13117. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13118. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13119. * If `start` is greater than `end` the params are swapped to support
  13120. * negative ranges.
  13121. *
  13122. * @static
  13123. * @memberOf _
  13124. * @since 3.3.0
  13125. * @category Number
  13126. * @param {number} number The number to check.
  13127. * @param {number} [start=0] The start of the range.
  13128. * @param {number} end The end of the range.
  13129. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13130. * @see _.range, _.rangeRight
  13131. * @example
  13132. *
  13133. * _.inRange(3, 2, 4);
  13134. * // => true
  13135. *
  13136. * _.inRange(4, 8);
  13137. * // => true
  13138. *
  13139. * _.inRange(4, 2);
  13140. * // => false
  13141. *
  13142. * _.inRange(2, 2);
  13143. * // => false
  13144. *
  13145. * _.inRange(1.2, 2);
  13146. * // => true
  13147. *
  13148. * _.inRange(5.2, 4);
  13149. * // => false
  13150. *
  13151. * _.inRange(-3, -2, -6);
  13152. * // => true
  13153. */
  13154. function inRange(number, start, end) {
  13155. start = toFinite(start);
  13156. if (end === undefined) {
  13157. end = start;
  13158. start = 0;
  13159. } else {
  13160. end = toFinite(end);
  13161. }
  13162. number = toNumber(number);
  13163. return baseInRange(number, start, end);
  13164. }
  13165. /**
  13166. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13167. * If only one argument is provided a number between `0` and the given number
  13168. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13169. * floats, a floating-point number is returned instead of an integer.
  13170. *
  13171. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13172. * floating-point values which can produce unexpected results.
  13173. *
  13174. * @static
  13175. * @memberOf _
  13176. * @since 0.7.0
  13177. * @category Number
  13178. * @param {number} [lower=0] The lower bound.
  13179. * @param {number} [upper=1] The upper bound.
  13180. * @param {boolean} [floating] Specify returning a floating-point number.
  13181. * @returns {number} Returns the random number.
  13182. * @example
  13183. *
  13184. * _.random(0, 5);
  13185. * // => an integer between 0 and 5
  13186. *
  13187. * _.random(5);
  13188. * // => also an integer between 0 and 5
  13189. *
  13190. * _.random(5, true);
  13191. * // => a floating-point number between 0 and 5
  13192. *
  13193. * _.random(1.2, 5.2);
  13194. * // => a floating-point number between 1.2 and 5.2
  13195. */
  13196. function random(lower, upper, floating) {
  13197. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13198. upper = floating = undefined;
  13199. }
  13200. if (floating === undefined) {
  13201. if (typeof upper == 'boolean') {
  13202. floating = upper;
  13203. upper = undefined;
  13204. }
  13205. else if (typeof lower == 'boolean') {
  13206. floating = lower;
  13207. lower = undefined;
  13208. }
  13209. }
  13210. if (lower === undefined && upper === undefined) {
  13211. lower = 0;
  13212. upper = 1;
  13213. }
  13214. else {
  13215. lower = toFinite(lower);
  13216. if (upper === undefined) {
  13217. upper = lower;
  13218. lower = 0;
  13219. } else {
  13220. upper = toFinite(upper);
  13221. }
  13222. }
  13223. if (lower > upper) {
  13224. var temp = lower;
  13225. lower = upper;
  13226. upper = temp;
  13227. }
  13228. if (floating || lower % 1 || upper % 1) {
  13229. var rand = nativeRandom();
  13230. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13231. }
  13232. return baseRandom(lower, upper);
  13233. }
  13234. /*------------------------------------------------------------------------*/
  13235. /**
  13236. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13237. *
  13238. * @static
  13239. * @memberOf _
  13240. * @since 3.0.0
  13241. * @category String
  13242. * @param {string} [string=''] The string to convert.
  13243. * @returns {string} Returns the camel cased string.
  13244. * @example
  13245. *
  13246. * _.camelCase('Foo Bar');
  13247. * // => 'fooBar'
  13248. *
  13249. * _.camelCase('--foo-bar--');
  13250. * // => 'fooBar'
  13251. *
  13252. * _.camelCase('__FOO_BAR__');
  13253. * // => 'fooBar'
  13254. */
  13255. var camelCase = createCompounder(function(result, word, index) {
  13256. word = word.toLowerCase();
  13257. return result + (index ? capitalize(word) : word);
  13258. });
  13259. /**
  13260. * Converts the first character of `string` to upper case and the remaining
  13261. * to lower case.
  13262. *
  13263. * @static
  13264. * @memberOf _
  13265. * @since 3.0.0
  13266. * @category String
  13267. * @param {string} [string=''] The string to capitalize.
  13268. * @returns {string} Returns the capitalized string.
  13269. * @example
  13270. *
  13271. * _.capitalize('FRED');
  13272. * // => 'Fred'
  13273. */
  13274. function capitalize(string) {
  13275. return upperFirst(toString(string).toLowerCase());
  13276. }
  13277. /**
  13278. * Deburrs `string` by converting
  13279. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13280. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13281. * letters to basic Latin letters and removing
  13282. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13283. *
  13284. * @static
  13285. * @memberOf _
  13286. * @since 3.0.0
  13287. * @category String
  13288. * @param {string} [string=''] The string to deburr.
  13289. * @returns {string} Returns the deburred string.
  13290. * @example
  13291. *
  13292. * _.deburr('déjà vu');
  13293. * // => 'deja vu'
  13294. */
  13295. function deburr(string) {
  13296. string = toString(string);
  13297. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13298. }
  13299. /**
  13300. * Checks if `string` ends with the given target string.
  13301. *
  13302. * @static
  13303. * @memberOf _
  13304. * @since 3.0.0
  13305. * @category String
  13306. * @param {string} [string=''] The string to inspect.
  13307. * @param {string} [target] The string to search for.
  13308. * @param {number} [position=string.length] The position to search up to.
  13309. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13310. * else `false`.
  13311. * @example
  13312. *
  13313. * _.endsWith('abc', 'c');
  13314. * // => true
  13315. *
  13316. * _.endsWith('abc', 'b');
  13317. * // => false
  13318. *
  13319. * _.endsWith('abc', 'b', 2);
  13320. * // => true
  13321. */
  13322. function endsWith(string, target, position) {
  13323. string = toString(string);
  13324. target = baseToString(target);
  13325. var length = string.length;
  13326. position = position === undefined
  13327. ? length
  13328. : baseClamp(toInteger(position), 0, length);
  13329. var end = position;
  13330. position -= target.length;
  13331. return position >= 0 && string.slice(position, end) == target;
  13332. }
  13333. /**
  13334. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13335. * corresponding HTML entities.
  13336. *
  13337. * **Note:** No other characters are escaped. To escape additional
  13338. * characters use a third-party library like [_he_](https://mths.be/he).
  13339. *
  13340. * Though the ">" character is escaped for symmetry, characters like
  13341. * ">" and "/" don't need escaping in HTML and have no special meaning
  13342. * unless they're part of a tag or unquoted attribute value. See
  13343. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13344. * (under "semi-related fun fact") for more details.
  13345. *
  13346. * When working with HTML you should always
  13347. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13348. * XSS vectors.
  13349. *
  13350. * @static
  13351. * @since 0.1.0
  13352. * @memberOf _
  13353. * @category String
  13354. * @param {string} [string=''] The string to escape.
  13355. * @returns {string} Returns the escaped string.
  13356. * @example
  13357. *
  13358. * _.escape('fred, barney, & pebbles');
  13359. * // => 'fred, barney, &amp; pebbles'
  13360. */
  13361. function escape(string) {
  13362. string = toString(string);
  13363. return (string && reHasUnescapedHtml.test(string))
  13364. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13365. : string;
  13366. }
  13367. /**
  13368. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13369. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13370. *
  13371. * @static
  13372. * @memberOf _
  13373. * @since 3.0.0
  13374. * @category String
  13375. * @param {string} [string=''] The string to escape.
  13376. * @returns {string} Returns the escaped string.
  13377. * @example
  13378. *
  13379. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13380. * // => '\[lodash\]\(https://lodash\.com/\)'
  13381. */
  13382. function escapeRegExp(string) {
  13383. string = toString(string);
  13384. return (string && reHasRegExpChar.test(string))
  13385. ? string.replace(reRegExpChar, '\\$&')
  13386. : string;
  13387. }
  13388. /**
  13389. * Converts `string` to
  13390. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13391. *
  13392. * @static
  13393. * @memberOf _
  13394. * @since 3.0.0
  13395. * @category String
  13396. * @param {string} [string=''] The string to convert.
  13397. * @returns {string} Returns the kebab cased string.
  13398. * @example
  13399. *
  13400. * _.kebabCase('Foo Bar');
  13401. * // => 'foo-bar'
  13402. *
  13403. * _.kebabCase('fooBar');
  13404. * // => 'foo-bar'
  13405. *
  13406. * _.kebabCase('__FOO_BAR__');
  13407. * // => 'foo-bar'
  13408. */
  13409. var kebabCase = createCompounder(function(result, word, index) {
  13410. return result + (index ? '-' : '') + word.toLowerCase();
  13411. });
  13412. /**
  13413. * Converts `string`, as space separated words, to lower case.
  13414. *
  13415. * @static
  13416. * @memberOf _
  13417. * @since 4.0.0
  13418. * @category String
  13419. * @param {string} [string=''] The string to convert.
  13420. * @returns {string} Returns the lower cased string.
  13421. * @example
  13422. *
  13423. * _.lowerCase('--Foo-Bar--');
  13424. * // => 'foo bar'
  13425. *
  13426. * _.lowerCase('fooBar');
  13427. * // => 'foo bar'
  13428. *
  13429. * _.lowerCase('__FOO_BAR__');
  13430. * // => 'foo bar'
  13431. */
  13432. var lowerCase = createCompounder(function(result, word, index) {
  13433. return result + (index ? ' ' : '') + word.toLowerCase();
  13434. });
  13435. /**
  13436. * Converts the first character of `string` to lower case.
  13437. *
  13438. * @static
  13439. * @memberOf _
  13440. * @since 4.0.0
  13441. * @category String
  13442. * @param {string} [string=''] The string to convert.
  13443. * @returns {string} Returns the converted string.
  13444. * @example
  13445. *
  13446. * _.lowerFirst('Fred');
  13447. * // => 'fred'
  13448. *
  13449. * _.lowerFirst('FRED');
  13450. * // => 'fRED'
  13451. */
  13452. var lowerFirst = createCaseFirst('toLowerCase');
  13453. /**
  13454. * Pads `string` on the left and right sides if it's shorter than `length`.
  13455. * Padding characters are truncated if they can't be evenly divided by `length`.
  13456. *
  13457. * @static
  13458. * @memberOf _
  13459. * @since 3.0.0
  13460. * @category String
  13461. * @param {string} [string=''] The string to pad.
  13462. * @param {number} [length=0] The padding length.
  13463. * @param {string} [chars=' '] The string used as padding.
  13464. * @returns {string} Returns the padded string.
  13465. * @example
  13466. *
  13467. * _.pad('abc', 8);
  13468. * // => ' abc '
  13469. *
  13470. * _.pad('abc', 8, '_-');
  13471. * // => '_-abc_-_'
  13472. *
  13473. * _.pad('abc', 3);
  13474. * // => 'abc'
  13475. */
  13476. function pad(string, length, chars) {
  13477. string = toString(string);
  13478. length = toInteger(length);
  13479. var strLength = length ? stringSize(string) : 0;
  13480. if (!length || strLength >= length) {
  13481. return string;
  13482. }
  13483. var mid = (length - strLength) / 2;
  13484. return (
  13485. createPadding(nativeFloor(mid), chars) +
  13486. string +
  13487. createPadding(nativeCeil(mid), chars)
  13488. );
  13489. }
  13490. /**
  13491. * Pads `string` on the right side if it's shorter than `length`. Padding
  13492. * characters are truncated if they exceed `length`.
  13493. *
  13494. * @static
  13495. * @memberOf _
  13496. * @since 4.0.0
  13497. * @category String
  13498. * @param {string} [string=''] The string to pad.
  13499. * @param {number} [length=0] The padding length.
  13500. * @param {string} [chars=' '] The string used as padding.
  13501. * @returns {string} Returns the padded string.
  13502. * @example
  13503. *
  13504. * _.padEnd('abc', 6);
  13505. * // => 'abc '
  13506. *
  13507. * _.padEnd('abc', 6, '_-');
  13508. * // => 'abc_-_'
  13509. *
  13510. * _.padEnd('abc', 3);
  13511. * // => 'abc'
  13512. */
  13513. function padEnd(string, length, chars) {
  13514. string = toString(string);
  13515. length = toInteger(length);
  13516. var strLength = length ? stringSize(string) : 0;
  13517. return (length && strLength < length)
  13518. ? (string + createPadding(length - strLength, chars))
  13519. : string;
  13520. }
  13521. /**
  13522. * Pads `string` on the left side if it's shorter than `length`. Padding
  13523. * characters are truncated if they exceed `length`.
  13524. *
  13525. * @static
  13526. * @memberOf _
  13527. * @since 4.0.0
  13528. * @category String
  13529. * @param {string} [string=''] The string to pad.
  13530. * @param {number} [length=0] The padding length.
  13531. * @param {string} [chars=' '] The string used as padding.
  13532. * @returns {string} Returns the padded string.
  13533. * @example
  13534. *
  13535. * _.padStart('abc', 6);
  13536. * // => ' abc'
  13537. *
  13538. * _.padStart('abc', 6, '_-');
  13539. * // => '_-_abc'
  13540. *
  13541. * _.padStart('abc', 3);
  13542. * // => 'abc'
  13543. */
  13544. function padStart(string, length, chars) {
  13545. string = toString(string);
  13546. length = toInteger(length);
  13547. var strLength = length ? stringSize(string) : 0;
  13548. return (length && strLength < length)
  13549. ? (createPadding(length - strLength, chars) + string)
  13550. : string;
  13551. }
  13552. /**
  13553. * Converts `string` to an integer of the specified radix. If `radix` is
  13554. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13555. * hexadecimal, in which case a `radix` of `16` is used.
  13556. *
  13557. * **Note:** This method aligns with the
  13558. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13559. *
  13560. * @static
  13561. * @memberOf _
  13562. * @since 1.1.0
  13563. * @category String
  13564. * @param {string} string The string to convert.
  13565. * @param {number} [radix=10] The radix to interpret `value` by.
  13566. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13567. * @returns {number} Returns the converted integer.
  13568. * @example
  13569. *
  13570. * _.parseInt('08');
  13571. * // => 8
  13572. *
  13573. * _.map(['6', '08', '10'], _.parseInt);
  13574. * // => [6, 8, 10]
  13575. */
  13576. function parseInt(string, radix, guard) {
  13577. if (guard || radix == null) {
  13578. radix = 0;
  13579. } else if (radix) {
  13580. radix = +radix;
  13581. }
  13582. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13583. }
  13584. /**
  13585. * Repeats the given string `n` times.
  13586. *
  13587. * @static
  13588. * @memberOf _
  13589. * @since 3.0.0
  13590. * @category String
  13591. * @param {string} [string=''] The string to repeat.
  13592. * @param {number} [n=1] The number of times to repeat the string.
  13593. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13594. * @returns {string} Returns the repeated string.
  13595. * @example
  13596. *
  13597. * _.repeat('*', 3);
  13598. * // => '***'
  13599. *
  13600. * _.repeat('abc', 2);
  13601. * // => 'abcabc'
  13602. *
  13603. * _.repeat('abc', 0);
  13604. * // => ''
  13605. */
  13606. function repeat(string, n, guard) {
  13607. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13608. n = 1;
  13609. } else {
  13610. n = toInteger(n);
  13611. }
  13612. return baseRepeat(toString(string), n);
  13613. }
  13614. /**
  13615. * Replaces matches for `pattern` in `string` with `replacement`.
  13616. *
  13617. * **Note:** This method is based on
  13618. * [`String#replace`](https://mdn.io/String/replace).
  13619. *
  13620. * @static
  13621. * @memberOf _
  13622. * @since 4.0.0
  13623. * @category String
  13624. * @param {string} [string=''] The string to modify.
  13625. * @param {RegExp|string} pattern The pattern to replace.
  13626. * @param {Function|string} replacement The match replacement.
  13627. * @returns {string} Returns the modified string.
  13628. * @example
  13629. *
  13630. * _.replace('Hi Fred', 'Fred', 'Barney');
  13631. * // => 'Hi Barney'
  13632. */
  13633. function replace() {
  13634. var args = arguments,
  13635. string = toString(args[0]);
  13636. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13637. }
  13638. /**
  13639. * Converts `string` to
  13640. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13641. *
  13642. * @static
  13643. * @memberOf _
  13644. * @since 3.0.0
  13645. * @category String
  13646. * @param {string} [string=''] The string to convert.
  13647. * @returns {string} Returns the snake cased string.
  13648. * @example
  13649. *
  13650. * _.snakeCase('Foo Bar');
  13651. * // => 'foo_bar'
  13652. *
  13653. * _.snakeCase('fooBar');
  13654. * // => 'foo_bar'
  13655. *
  13656. * _.snakeCase('--FOO-BAR--');
  13657. * // => 'foo_bar'
  13658. */
  13659. var snakeCase = createCompounder(function(result, word, index) {
  13660. return result + (index ? '_' : '') + word.toLowerCase();
  13661. });
  13662. /**
  13663. * Splits `string` by `separator`.
  13664. *
  13665. * **Note:** This method is based on
  13666. * [`String#split`](https://mdn.io/String/split).
  13667. *
  13668. * @static
  13669. * @memberOf _
  13670. * @since 4.0.0
  13671. * @category String
  13672. * @param {string} [string=''] The string to split.
  13673. * @param {RegExp|string} separator The separator pattern to split by.
  13674. * @param {number} [limit] The length to truncate results to.
  13675. * @returns {Array} Returns the string segments.
  13676. * @example
  13677. *
  13678. * _.split('a-b-c', '-', 2);
  13679. * // => ['a', 'b']
  13680. */
  13681. function split(string, separator, limit) {
  13682. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13683. separator = limit = undefined;
  13684. }
  13685. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13686. if (!limit) {
  13687. return [];
  13688. }
  13689. string = toString(string);
  13690. if (string && (
  13691. typeof separator == 'string' ||
  13692. (separator != null && !isRegExp(separator))
  13693. )) {
  13694. separator = baseToString(separator);
  13695. if (!separator && hasUnicode(string)) {
  13696. return castSlice(stringToArray(string), 0, limit);
  13697. }
  13698. }
  13699. return string.split(separator, limit);
  13700. }
  13701. /**
  13702. * Converts `string` to
  13703. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13704. *
  13705. * @static
  13706. * @memberOf _
  13707. * @since 3.1.0
  13708. * @category String
  13709. * @param {string} [string=''] The string to convert.
  13710. * @returns {string} Returns the start cased string.
  13711. * @example
  13712. *
  13713. * _.startCase('--foo-bar--');
  13714. * // => 'Foo Bar'
  13715. *
  13716. * _.startCase('fooBar');
  13717. * // => 'Foo Bar'
  13718. *
  13719. * _.startCase('__FOO_BAR__');
  13720. * // => 'FOO BAR'
  13721. */
  13722. var startCase = createCompounder(function(result, word, index) {
  13723. return result + (index ? ' ' : '') + upperFirst(word);
  13724. });
  13725. /**
  13726. * Checks if `string` starts with the given target string.
  13727. *
  13728. * @static
  13729. * @memberOf _
  13730. * @since 3.0.0
  13731. * @category String
  13732. * @param {string} [string=''] The string to inspect.
  13733. * @param {string} [target] The string to search for.
  13734. * @param {number} [position=0] The position to search from.
  13735. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13736. * else `false`.
  13737. * @example
  13738. *
  13739. * _.startsWith('abc', 'a');
  13740. * // => true
  13741. *
  13742. * _.startsWith('abc', 'b');
  13743. * // => false
  13744. *
  13745. * _.startsWith('abc', 'b', 1);
  13746. * // => true
  13747. */
  13748. function startsWith(string, target, position) {
  13749. string = toString(string);
  13750. position = position == null
  13751. ? 0
  13752. : baseClamp(toInteger(position), 0, string.length);
  13753. target = baseToString(target);
  13754. return string.slice(position, position + target.length) == target;
  13755. }
  13756. /**
  13757. * Creates a compiled template function that can interpolate data properties
  13758. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13759. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13760. * properties may be accessed as free variables in the template. If a setting
  13761. * object is given, it takes precedence over `_.templateSettings` values.
  13762. *
  13763. * **Note:** In the development build `_.template` utilizes
  13764. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13765. * for easier debugging.
  13766. *
  13767. * For more information on precompiling templates see
  13768. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13769. *
  13770. * For more information on Chrome extension sandboxes see
  13771. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13772. *
  13773. * @static
  13774. * @since 0.1.0
  13775. * @memberOf _
  13776. * @category String
  13777. * @param {string} [string=''] The template string.
  13778. * @param {Object} [options={}] The options object.
  13779. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13780. * The HTML "escape" delimiter.
  13781. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13782. * The "evaluate" delimiter.
  13783. * @param {Object} [options.imports=_.templateSettings.imports]
  13784. * An object to import into the template as free variables.
  13785. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13786. * The "interpolate" delimiter.
  13787. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13788. * The sourceURL of the compiled template.
  13789. * @param {string} [options.variable='obj']
  13790. * The data object variable name.
  13791. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13792. * @returns {Function} Returns the compiled template function.
  13793. * @example
  13794. *
  13795. * // Use the "interpolate" delimiter to create a compiled template.
  13796. * var compiled = _.template('hello <%= user %>!');
  13797. * compiled({ 'user': 'fred' });
  13798. * // => 'hello fred!'
  13799. *
  13800. * // Use the HTML "escape" delimiter to escape data property values.
  13801. * var compiled = _.template('<b><%- value %></b>');
  13802. * compiled({ 'value': '<script>' });
  13803. * // => '<b>&lt;script&gt;</b>'
  13804. *
  13805. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13806. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13807. * compiled({ 'users': ['fred', 'barney'] });
  13808. * // => '<li>fred</li><li>barney</li>'
  13809. *
  13810. * // Use the internal `print` function in "evaluate" delimiters.
  13811. * var compiled = _.template('<% print("hello " + user); %>!');
  13812. * compiled({ 'user': 'barney' });
  13813. * // => 'hello barney!'
  13814. *
  13815. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13816. * // Disable support by replacing the "interpolate" delimiter.
  13817. * var compiled = _.template('hello ${ user }!');
  13818. * compiled({ 'user': 'pebbles' });
  13819. * // => 'hello pebbles!'
  13820. *
  13821. * // Use backslashes to treat delimiters as plain text.
  13822. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13823. * compiled({ 'value': 'ignored' });
  13824. * // => '<%- value %>'
  13825. *
  13826. * // Use the `imports` option to import `jQuery` as `jq`.
  13827. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13828. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13829. * compiled({ 'users': ['fred', 'barney'] });
  13830. * // => '<li>fred</li><li>barney</li>'
  13831. *
  13832. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13833. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13834. * compiled(data);
  13835. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13836. *
  13837. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13838. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13839. * compiled.source;
  13840. * // => function(data) {
  13841. * // var __t, __p = '';
  13842. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13843. * // return __p;
  13844. * // }
  13845. *
  13846. * // Use custom template delimiters.
  13847. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13848. * var compiled = _.template('hello {{ user }}!');
  13849. * compiled({ 'user': 'mustache' });
  13850. * // => 'hello mustache!'
  13851. *
  13852. * // Use the `source` property to inline compiled templates for meaningful
  13853. * // line numbers in error messages and stack traces.
  13854. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13855. * var JST = {\
  13856. * "main": ' + _.template(mainText).source + '\
  13857. * };\
  13858. * ');
  13859. */
  13860. function template(string, options, guard) {
  13861. // Based on John Resig's `tmpl` implementation
  13862. // (http://ejohn.org/blog/javascript-micro-templating/)
  13863. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13864. var settings = lodash.templateSettings;
  13865. if (guard && isIterateeCall(string, options, guard)) {
  13866. options = undefined;
  13867. }
  13868. string = toString(string);
  13869. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13870. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13871. importsKeys = keys(imports),
  13872. importsValues = baseValues(imports, importsKeys);
  13873. var isEscaping,
  13874. isEvaluating,
  13875. index = 0,
  13876. interpolate = options.interpolate || reNoMatch,
  13877. source = "__p += '";
  13878. // Compile the regexp to match each delimiter.
  13879. var reDelimiters = RegExp(
  13880. (options.escape || reNoMatch).source + '|' +
  13881. interpolate.source + '|' +
  13882. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13883. (options.evaluate || reNoMatch).source + '|$'
  13884. , 'g');
  13885. // Use a sourceURL for easier debugging.
  13886. // The sourceURL gets injected into the source that's eval-ed, so be careful
  13887. // with lookup (in case of e.g. prototype pollution), and strip newlines if any.
  13888. // A newline wouldn't be a valid sourceURL anyway, and it'd enable code injection.
  13889. var sourceURL = '//# sourceURL=' +
  13890. (hasOwnProperty.call(options, 'sourceURL')
  13891. ? (options.sourceURL + '').replace(/[\r\n]/g, ' ')
  13892. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13893. ) + '\n';
  13894. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13895. interpolateValue || (interpolateValue = esTemplateValue);
  13896. // Escape characters that can't be included in string literals.
  13897. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13898. // Replace delimiters with snippets.
  13899. if (escapeValue) {
  13900. isEscaping = true;
  13901. source += "' +\n__e(" + escapeValue + ") +\n'";
  13902. }
  13903. if (evaluateValue) {
  13904. isEvaluating = true;
  13905. source += "';\n" + evaluateValue + ";\n__p += '";
  13906. }
  13907. if (interpolateValue) {
  13908. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13909. }
  13910. index = offset + match.length;
  13911. // The JS engine embedded in Adobe products needs `match` returned in
  13912. // order to produce the correct `offset` value.
  13913. return match;
  13914. });
  13915. source += "';\n";
  13916. // If `variable` is not specified wrap a with-statement around the generated
  13917. // code to add the data object to the top of the scope chain.
  13918. // Like with sourceURL, we take care to not check the option's prototype,
  13919. // as this configuration is a code injection vector.
  13920. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  13921. if (!variable) {
  13922. source = 'with (obj) {\n' + source + '\n}\n';
  13923. }
  13924. // Cleanup code by stripping empty strings.
  13925. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13926. .replace(reEmptyStringMiddle, '$1')
  13927. .replace(reEmptyStringTrailing, '$1;');
  13928. // Frame code as the function body.
  13929. source = 'function(' + (variable || 'obj') + ') {\n' +
  13930. (variable
  13931. ? ''
  13932. : 'obj || (obj = {});\n'
  13933. ) +
  13934. "var __t, __p = ''" +
  13935. (isEscaping
  13936. ? ', __e = _.escape'
  13937. : ''
  13938. ) +
  13939. (isEvaluating
  13940. ? ', __j = Array.prototype.join;\n' +
  13941. "function print() { __p += __j.call(arguments, '') }\n"
  13942. : ';\n'
  13943. ) +
  13944. source +
  13945. 'return __p\n}';
  13946. var result = attempt(function() {
  13947. return Function(importsKeys, sourceURL + 'return ' + source)
  13948. .apply(undefined, importsValues);
  13949. });
  13950. // Provide the compiled function's source by its `toString` method or
  13951. // the `source` property as a convenience for inlining compiled templates.
  13952. result.source = source;
  13953. if (isError(result)) {
  13954. throw result;
  13955. }
  13956. return result;
  13957. }
  13958. /**
  13959. * Converts `string`, as a whole, to lower case just like
  13960. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13961. *
  13962. * @static
  13963. * @memberOf _
  13964. * @since 4.0.0
  13965. * @category String
  13966. * @param {string} [string=''] The string to convert.
  13967. * @returns {string} Returns the lower cased string.
  13968. * @example
  13969. *
  13970. * _.toLower('--Foo-Bar--');
  13971. * // => '--foo-bar--'
  13972. *
  13973. * _.toLower('fooBar');
  13974. * // => 'foobar'
  13975. *
  13976. * _.toLower('__FOO_BAR__');
  13977. * // => '__foo_bar__'
  13978. */
  13979. function toLower(value) {
  13980. return toString(value).toLowerCase();
  13981. }
  13982. /**
  13983. * Converts `string`, as a whole, to upper case just like
  13984. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13985. *
  13986. * @static
  13987. * @memberOf _
  13988. * @since 4.0.0
  13989. * @category String
  13990. * @param {string} [string=''] The string to convert.
  13991. * @returns {string} Returns the upper cased string.
  13992. * @example
  13993. *
  13994. * _.toUpper('--foo-bar--');
  13995. * // => '--FOO-BAR--'
  13996. *
  13997. * _.toUpper('fooBar');
  13998. * // => 'FOOBAR'
  13999. *
  14000. * _.toUpper('__foo_bar__');
  14001. * // => '__FOO_BAR__'
  14002. */
  14003. function toUpper(value) {
  14004. return toString(value).toUpperCase();
  14005. }
  14006. /**
  14007. * Removes leading and trailing whitespace or specified characters from `string`.
  14008. *
  14009. * @static
  14010. * @memberOf _
  14011. * @since 3.0.0
  14012. * @category String
  14013. * @param {string} [string=''] The string to trim.
  14014. * @param {string} [chars=whitespace] The characters to trim.
  14015. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14016. * @returns {string} Returns the trimmed string.
  14017. * @example
  14018. *
  14019. * _.trim(' abc ');
  14020. * // => 'abc'
  14021. *
  14022. * _.trim('-_-abc-_-', '_-');
  14023. * // => 'abc'
  14024. *
  14025. * _.map([' foo ', ' bar '], _.trim);
  14026. * // => ['foo', 'bar']
  14027. */
  14028. function trim(string, chars, guard) {
  14029. string = toString(string);
  14030. if (string && (guard || chars === undefined)) {
  14031. return string.replace(reTrim, '');
  14032. }
  14033. if (!string || !(chars = baseToString(chars))) {
  14034. return string;
  14035. }
  14036. var strSymbols = stringToArray(string),
  14037. chrSymbols = stringToArray(chars),
  14038. start = charsStartIndex(strSymbols, chrSymbols),
  14039. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14040. return castSlice(strSymbols, start, end).join('');
  14041. }
  14042. /**
  14043. * Removes trailing whitespace or specified characters from `string`.
  14044. *
  14045. * @static
  14046. * @memberOf _
  14047. * @since 4.0.0
  14048. * @category String
  14049. * @param {string} [string=''] The string to trim.
  14050. * @param {string} [chars=whitespace] The characters to trim.
  14051. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14052. * @returns {string} Returns the trimmed string.
  14053. * @example
  14054. *
  14055. * _.trimEnd(' abc ');
  14056. * // => ' abc'
  14057. *
  14058. * _.trimEnd('-_-abc-_-', '_-');
  14059. * // => '-_-abc'
  14060. */
  14061. function trimEnd(string, chars, guard) {
  14062. string = toString(string);
  14063. if (string && (guard || chars === undefined)) {
  14064. return string.replace(reTrimEnd, '');
  14065. }
  14066. if (!string || !(chars = baseToString(chars))) {
  14067. return string;
  14068. }
  14069. var strSymbols = stringToArray(string),
  14070. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14071. return castSlice(strSymbols, 0, end).join('');
  14072. }
  14073. /**
  14074. * Removes leading whitespace or specified characters from `string`.
  14075. *
  14076. * @static
  14077. * @memberOf _
  14078. * @since 4.0.0
  14079. * @category String
  14080. * @param {string} [string=''] The string to trim.
  14081. * @param {string} [chars=whitespace] The characters to trim.
  14082. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14083. * @returns {string} Returns the trimmed string.
  14084. * @example
  14085. *
  14086. * _.trimStart(' abc ');
  14087. * // => 'abc '
  14088. *
  14089. * _.trimStart('-_-abc-_-', '_-');
  14090. * // => 'abc-_-'
  14091. */
  14092. function trimStart(string, chars, guard) {
  14093. string = toString(string);
  14094. if (string && (guard || chars === undefined)) {
  14095. return string.replace(reTrimStart, '');
  14096. }
  14097. if (!string || !(chars = baseToString(chars))) {
  14098. return string;
  14099. }
  14100. var strSymbols = stringToArray(string),
  14101. start = charsStartIndex(strSymbols, stringToArray(chars));
  14102. return castSlice(strSymbols, start).join('');
  14103. }
  14104. /**
  14105. * Truncates `string` if it's longer than the given maximum string length.
  14106. * The last characters of the truncated string are replaced with the omission
  14107. * string which defaults to "...".
  14108. *
  14109. * @static
  14110. * @memberOf _
  14111. * @since 4.0.0
  14112. * @category String
  14113. * @param {string} [string=''] The string to truncate.
  14114. * @param {Object} [options={}] The options object.
  14115. * @param {number} [options.length=30] The maximum string length.
  14116. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14117. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14118. * @returns {string} Returns the truncated string.
  14119. * @example
  14120. *
  14121. * _.truncate('hi-diddly-ho there, neighborino');
  14122. * // => 'hi-diddly-ho there, neighbo...'
  14123. *
  14124. * _.truncate('hi-diddly-ho there, neighborino', {
  14125. * 'length': 24,
  14126. * 'separator': ' '
  14127. * });
  14128. * // => 'hi-diddly-ho there,...'
  14129. *
  14130. * _.truncate('hi-diddly-ho there, neighborino', {
  14131. * 'length': 24,
  14132. * 'separator': /,? +/
  14133. * });
  14134. * // => 'hi-diddly-ho there...'
  14135. *
  14136. * _.truncate('hi-diddly-ho there, neighborino', {
  14137. * 'omission': ' [...]'
  14138. * });
  14139. * // => 'hi-diddly-ho there, neig [...]'
  14140. */
  14141. function truncate(string, options) {
  14142. var length = DEFAULT_TRUNC_LENGTH,
  14143. omission = DEFAULT_TRUNC_OMISSION;
  14144. if (isObject(options)) {
  14145. var separator = 'separator' in options ? options.separator : separator;
  14146. length = 'length' in options ? toInteger(options.length) : length;
  14147. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14148. }
  14149. string = toString(string);
  14150. var strLength = string.length;
  14151. if (hasUnicode(string)) {
  14152. var strSymbols = stringToArray(string);
  14153. strLength = strSymbols.length;
  14154. }
  14155. if (length >= strLength) {
  14156. return string;
  14157. }
  14158. var end = length - stringSize(omission);
  14159. if (end < 1) {
  14160. return omission;
  14161. }
  14162. var result = strSymbols
  14163. ? castSlice(strSymbols, 0, end).join('')
  14164. : string.slice(0, end);
  14165. if (separator === undefined) {
  14166. return result + omission;
  14167. }
  14168. if (strSymbols) {
  14169. end += (result.length - end);
  14170. }
  14171. if (isRegExp(separator)) {
  14172. if (string.slice(end).search(separator)) {
  14173. var match,
  14174. substring = result;
  14175. if (!separator.global) {
  14176. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14177. }
  14178. separator.lastIndex = 0;
  14179. while ((match = separator.exec(substring))) {
  14180. var newEnd = match.index;
  14181. }
  14182. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14183. }
  14184. } else if (string.indexOf(baseToString(separator), end) != end) {
  14185. var index = result.lastIndexOf(separator);
  14186. if (index > -1) {
  14187. result = result.slice(0, index);
  14188. }
  14189. }
  14190. return result + omission;
  14191. }
  14192. /**
  14193. * The inverse of `_.escape`; this method converts the HTML entities
  14194. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14195. * their corresponding characters.
  14196. *
  14197. * **Note:** No other HTML entities are unescaped. To unescape additional
  14198. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14199. *
  14200. * @static
  14201. * @memberOf _
  14202. * @since 0.6.0
  14203. * @category String
  14204. * @param {string} [string=''] The string to unescape.
  14205. * @returns {string} Returns the unescaped string.
  14206. * @example
  14207. *
  14208. * _.unescape('fred, barney, &amp; pebbles');
  14209. * // => 'fred, barney, & pebbles'
  14210. */
  14211. function unescape(string) {
  14212. string = toString(string);
  14213. return (string && reHasEscapedHtml.test(string))
  14214. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14215. : string;
  14216. }
  14217. /**
  14218. * Converts `string`, as space separated words, to upper case.
  14219. *
  14220. * @static
  14221. * @memberOf _
  14222. * @since 4.0.0
  14223. * @category String
  14224. * @param {string} [string=''] The string to convert.
  14225. * @returns {string} Returns the upper cased string.
  14226. * @example
  14227. *
  14228. * _.upperCase('--foo-bar');
  14229. * // => 'FOO BAR'
  14230. *
  14231. * _.upperCase('fooBar');
  14232. * // => 'FOO BAR'
  14233. *
  14234. * _.upperCase('__foo_bar__');
  14235. * // => 'FOO BAR'
  14236. */
  14237. var upperCase = createCompounder(function(result, word, index) {
  14238. return result + (index ? ' ' : '') + word.toUpperCase();
  14239. });
  14240. /**
  14241. * Converts the first character of `string` to upper case.
  14242. *
  14243. * @static
  14244. * @memberOf _
  14245. * @since 4.0.0
  14246. * @category String
  14247. * @param {string} [string=''] The string to convert.
  14248. * @returns {string} Returns the converted string.
  14249. * @example
  14250. *
  14251. * _.upperFirst('fred');
  14252. * // => 'Fred'
  14253. *
  14254. * _.upperFirst('FRED');
  14255. * // => 'FRED'
  14256. */
  14257. var upperFirst = createCaseFirst('toUpperCase');
  14258. /**
  14259. * Splits `string` into an array of its words.
  14260. *
  14261. * @static
  14262. * @memberOf _
  14263. * @since 3.0.0
  14264. * @category String
  14265. * @param {string} [string=''] The string to inspect.
  14266. * @param {RegExp|string} [pattern] The pattern to match words.
  14267. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14268. * @returns {Array} Returns the words of `string`.
  14269. * @example
  14270. *
  14271. * _.words('fred, barney, & pebbles');
  14272. * // => ['fred', 'barney', 'pebbles']
  14273. *
  14274. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14275. * // => ['fred', 'barney', '&', 'pebbles']
  14276. */
  14277. function words(string, pattern, guard) {
  14278. string = toString(string);
  14279. pattern = guard ? undefined : pattern;
  14280. if (pattern === undefined) {
  14281. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14282. }
  14283. return string.match(pattern) || [];
  14284. }
  14285. /*------------------------------------------------------------------------*/
  14286. /**
  14287. * Attempts to invoke `func`, returning either the result or the caught error
  14288. * object. Any additional arguments are provided to `func` when it's invoked.
  14289. *
  14290. * @static
  14291. * @memberOf _
  14292. * @since 3.0.0
  14293. * @category Util
  14294. * @param {Function} func The function to attempt.
  14295. * @param {...*} [args] The arguments to invoke `func` with.
  14296. * @returns {*} Returns the `func` result or error object.
  14297. * @example
  14298. *
  14299. * // Avoid throwing errors for invalid selectors.
  14300. * var elements = _.attempt(function(selector) {
  14301. * return document.querySelectorAll(selector);
  14302. * }, '>_>');
  14303. *
  14304. * if (_.isError(elements)) {
  14305. * elements = [];
  14306. * }
  14307. */
  14308. var attempt = baseRest(function(func, args) {
  14309. try {
  14310. return apply(func, undefined, args);
  14311. } catch (e) {
  14312. return isError(e) ? e : new Error(e);
  14313. }
  14314. });
  14315. /**
  14316. * Binds methods of an object to the object itself, overwriting the existing
  14317. * method.
  14318. *
  14319. * **Note:** This method doesn't set the "length" property of bound functions.
  14320. *
  14321. * @static
  14322. * @since 0.1.0
  14323. * @memberOf _
  14324. * @category Util
  14325. * @param {Object} object The object to bind and assign the bound methods to.
  14326. * @param {...(string|string[])} methodNames The object method names to bind.
  14327. * @returns {Object} Returns `object`.
  14328. * @example
  14329. *
  14330. * var view = {
  14331. * 'label': 'docs',
  14332. * 'click': function() {
  14333. * console.log('clicked ' + this.label);
  14334. * }
  14335. * };
  14336. *
  14337. * _.bindAll(view, ['click']);
  14338. * jQuery(element).on('click', view.click);
  14339. * // => Logs 'clicked docs' when clicked.
  14340. */
  14341. var bindAll = flatRest(function(object, methodNames) {
  14342. arrayEach(methodNames, function(key) {
  14343. key = toKey(key);
  14344. baseAssignValue(object, key, bind(object[key], object));
  14345. });
  14346. return object;
  14347. });
  14348. /**
  14349. * Creates a function that iterates over `pairs` and invokes the corresponding
  14350. * function of the first predicate to return truthy. The predicate-function
  14351. * pairs are invoked with the `this` binding and arguments of the created
  14352. * function.
  14353. *
  14354. * @static
  14355. * @memberOf _
  14356. * @since 4.0.0
  14357. * @category Util
  14358. * @param {Array} pairs The predicate-function pairs.
  14359. * @returns {Function} Returns the new composite function.
  14360. * @example
  14361. *
  14362. * var func = _.cond([
  14363. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14364. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14365. * [_.stubTrue, _.constant('no match')]
  14366. * ]);
  14367. *
  14368. * func({ 'a': 1, 'b': 2 });
  14369. * // => 'matches A'
  14370. *
  14371. * func({ 'a': 0, 'b': 1 });
  14372. * // => 'matches B'
  14373. *
  14374. * func({ 'a': '1', 'b': '2' });
  14375. * // => 'no match'
  14376. */
  14377. function cond(pairs) {
  14378. var length = pairs == null ? 0 : pairs.length,
  14379. toIteratee = getIteratee();
  14380. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14381. if (typeof pair[1] != 'function') {
  14382. throw new TypeError(FUNC_ERROR_TEXT);
  14383. }
  14384. return [toIteratee(pair[0]), pair[1]];
  14385. });
  14386. return baseRest(function(args) {
  14387. var index = -1;
  14388. while (++index < length) {
  14389. var pair = pairs[index];
  14390. if (apply(pair[0], this, args)) {
  14391. return apply(pair[1], this, args);
  14392. }
  14393. }
  14394. });
  14395. }
  14396. /**
  14397. * Creates a function that invokes the predicate properties of `source` with
  14398. * the corresponding property values of a given object, returning `true` if
  14399. * all predicates return truthy, else `false`.
  14400. *
  14401. * **Note:** The created function is equivalent to `_.conformsTo` with
  14402. * `source` partially applied.
  14403. *
  14404. * @static
  14405. * @memberOf _
  14406. * @since 4.0.0
  14407. * @category Util
  14408. * @param {Object} source The object of property predicates to conform to.
  14409. * @returns {Function} Returns the new spec function.
  14410. * @example
  14411. *
  14412. * var objects = [
  14413. * { 'a': 2, 'b': 1 },
  14414. * { 'a': 1, 'b': 2 }
  14415. * ];
  14416. *
  14417. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14418. * // => [{ 'a': 1, 'b': 2 }]
  14419. */
  14420. function conforms(source) {
  14421. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14422. }
  14423. /**
  14424. * Creates a function that returns `value`.
  14425. *
  14426. * @static
  14427. * @memberOf _
  14428. * @since 2.4.0
  14429. * @category Util
  14430. * @param {*} value The value to return from the new function.
  14431. * @returns {Function} Returns the new constant function.
  14432. * @example
  14433. *
  14434. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14435. *
  14436. * console.log(objects);
  14437. * // => [{ 'a': 1 }, { 'a': 1 }]
  14438. *
  14439. * console.log(objects[0] === objects[1]);
  14440. * // => true
  14441. */
  14442. function constant(value) {
  14443. return function() {
  14444. return value;
  14445. };
  14446. }
  14447. /**
  14448. * Checks `value` to determine whether a default value should be returned in
  14449. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14450. * or `undefined`.
  14451. *
  14452. * @static
  14453. * @memberOf _
  14454. * @since 4.14.0
  14455. * @category Util
  14456. * @param {*} value The value to check.
  14457. * @param {*} defaultValue The default value.
  14458. * @returns {*} Returns the resolved value.
  14459. * @example
  14460. *
  14461. * _.defaultTo(1, 10);
  14462. * // => 1
  14463. *
  14464. * _.defaultTo(undefined, 10);
  14465. * // => 10
  14466. */
  14467. function defaultTo(value, defaultValue) {
  14468. return (value == null || value !== value) ? defaultValue : value;
  14469. }
  14470. /**
  14471. * Creates a function that returns the result of invoking the given functions
  14472. * with the `this` binding of the created function, where each successive
  14473. * invocation is supplied the return value of the previous.
  14474. *
  14475. * @static
  14476. * @memberOf _
  14477. * @since 3.0.0
  14478. * @category Util
  14479. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14480. * @returns {Function} Returns the new composite function.
  14481. * @see _.flowRight
  14482. * @example
  14483. *
  14484. * function square(n) {
  14485. * return n * n;
  14486. * }
  14487. *
  14488. * var addSquare = _.flow([_.add, square]);
  14489. * addSquare(1, 2);
  14490. * // => 9
  14491. */
  14492. var flow = createFlow();
  14493. /**
  14494. * This method is like `_.flow` except that it creates a function that
  14495. * invokes the given functions from right to left.
  14496. *
  14497. * @static
  14498. * @since 3.0.0
  14499. * @memberOf _
  14500. * @category Util
  14501. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14502. * @returns {Function} Returns the new composite function.
  14503. * @see _.flow
  14504. * @example
  14505. *
  14506. * function square(n) {
  14507. * return n * n;
  14508. * }
  14509. *
  14510. * var addSquare = _.flowRight([square, _.add]);
  14511. * addSquare(1, 2);
  14512. * // => 9
  14513. */
  14514. var flowRight = createFlow(true);
  14515. /**
  14516. * This method returns the first argument it receives.
  14517. *
  14518. * @static
  14519. * @since 0.1.0
  14520. * @memberOf _
  14521. * @category Util
  14522. * @param {*} value Any value.
  14523. * @returns {*} Returns `value`.
  14524. * @example
  14525. *
  14526. * var object = { 'a': 1 };
  14527. *
  14528. * console.log(_.identity(object) === object);
  14529. * // => true
  14530. */
  14531. function identity(value) {
  14532. return value;
  14533. }
  14534. /**
  14535. * Creates a function that invokes `func` with the arguments of the created
  14536. * function. If `func` is a property name, the created function returns the
  14537. * property value for a given element. If `func` is an array or object, the
  14538. * created function returns `true` for elements that contain the equivalent
  14539. * source properties, otherwise it returns `false`.
  14540. *
  14541. * @static
  14542. * @since 4.0.0
  14543. * @memberOf _
  14544. * @category Util
  14545. * @param {*} [func=_.identity] The value to convert to a callback.
  14546. * @returns {Function} Returns the callback.
  14547. * @example
  14548. *
  14549. * var users = [
  14550. * { 'user': 'barney', 'age': 36, 'active': true },
  14551. * { 'user': 'fred', 'age': 40, 'active': false }
  14552. * ];
  14553. *
  14554. * // The `_.matches` iteratee shorthand.
  14555. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14556. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14557. *
  14558. * // The `_.matchesProperty` iteratee shorthand.
  14559. * _.filter(users, _.iteratee(['user', 'fred']));
  14560. * // => [{ 'user': 'fred', 'age': 40 }]
  14561. *
  14562. * // The `_.property` iteratee shorthand.
  14563. * _.map(users, _.iteratee('user'));
  14564. * // => ['barney', 'fred']
  14565. *
  14566. * // Create custom iteratee shorthands.
  14567. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14568. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14569. * return func.test(string);
  14570. * };
  14571. * });
  14572. *
  14573. * _.filter(['abc', 'def'], /ef/);
  14574. * // => ['def']
  14575. */
  14576. function iteratee(func) {
  14577. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14578. }
  14579. /**
  14580. * Creates a function that performs a partial deep comparison between a given
  14581. * object and `source`, returning `true` if the given object has equivalent
  14582. * property values, else `false`.
  14583. *
  14584. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14585. * partially applied.
  14586. *
  14587. * Partial comparisons will match empty array and empty object `source`
  14588. * values against any array or object value, respectively. See `_.isEqual`
  14589. * for a list of supported value comparisons.
  14590. *
  14591. * @static
  14592. * @memberOf _
  14593. * @since 3.0.0
  14594. * @category Util
  14595. * @param {Object} source The object of property values to match.
  14596. * @returns {Function} Returns the new spec function.
  14597. * @example
  14598. *
  14599. * var objects = [
  14600. * { 'a': 1, 'b': 2, 'c': 3 },
  14601. * { 'a': 4, 'b': 5, 'c': 6 }
  14602. * ];
  14603. *
  14604. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14605. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14606. */
  14607. function matches(source) {
  14608. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14609. }
  14610. /**
  14611. * Creates a function that performs a partial deep comparison between the
  14612. * value at `path` of a given object to `srcValue`, returning `true` if the
  14613. * object value is equivalent, else `false`.
  14614. *
  14615. * **Note:** Partial comparisons will match empty array and empty object
  14616. * `srcValue` values against any array or object value, respectively. See
  14617. * `_.isEqual` for a list of supported value comparisons.
  14618. *
  14619. * @static
  14620. * @memberOf _
  14621. * @since 3.2.0
  14622. * @category Util
  14623. * @param {Array|string} path The path of the property to get.
  14624. * @param {*} srcValue The value to match.
  14625. * @returns {Function} Returns the new spec function.
  14626. * @example
  14627. *
  14628. * var objects = [
  14629. * { 'a': 1, 'b': 2, 'c': 3 },
  14630. * { 'a': 4, 'b': 5, 'c': 6 }
  14631. * ];
  14632. *
  14633. * _.find(objects, _.matchesProperty('a', 4));
  14634. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14635. */
  14636. function matchesProperty(path, srcValue) {
  14637. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14638. }
  14639. /**
  14640. * Creates a function that invokes the method at `path` of a given object.
  14641. * Any additional arguments are provided to the invoked method.
  14642. *
  14643. * @static
  14644. * @memberOf _
  14645. * @since 3.7.0
  14646. * @category Util
  14647. * @param {Array|string} path The path of the method to invoke.
  14648. * @param {...*} [args] The arguments to invoke the method with.
  14649. * @returns {Function} Returns the new invoker function.
  14650. * @example
  14651. *
  14652. * var objects = [
  14653. * { 'a': { 'b': _.constant(2) } },
  14654. * { 'a': { 'b': _.constant(1) } }
  14655. * ];
  14656. *
  14657. * _.map(objects, _.method('a.b'));
  14658. * // => [2, 1]
  14659. *
  14660. * _.map(objects, _.method(['a', 'b']));
  14661. * // => [2, 1]
  14662. */
  14663. var method = baseRest(function(path, args) {
  14664. return function(object) {
  14665. return baseInvoke(object, path, args);
  14666. };
  14667. });
  14668. /**
  14669. * The opposite of `_.method`; this method creates a function that invokes
  14670. * the method at a given path of `object`. Any additional arguments are
  14671. * provided to the invoked method.
  14672. *
  14673. * @static
  14674. * @memberOf _
  14675. * @since 3.7.0
  14676. * @category Util
  14677. * @param {Object} object The object to query.
  14678. * @param {...*} [args] The arguments to invoke the method with.
  14679. * @returns {Function} Returns the new invoker function.
  14680. * @example
  14681. *
  14682. * var array = _.times(3, _.constant),
  14683. * object = { 'a': array, 'b': array, 'c': array };
  14684. *
  14685. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14686. * // => [2, 0]
  14687. *
  14688. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14689. * // => [2, 0]
  14690. */
  14691. var methodOf = baseRest(function(object, args) {
  14692. return function(path) {
  14693. return baseInvoke(object, path, args);
  14694. };
  14695. });
  14696. /**
  14697. * Adds all own enumerable string keyed function properties of a source
  14698. * object to the destination object. If `object` is a function, then methods
  14699. * are added to its prototype as well.
  14700. *
  14701. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14702. * avoid conflicts caused by modifying the original.
  14703. *
  14704. * @static
  14705. * @since 0.1.0
  14706. * @memberOf _
  14707. * @category Util
  14708. * @param {Function|Object} [object=lodash] The destination object.
  14709. * @param {Object} source The object of functions to add.
  14710. * @param {Object} [options={}] The options object.
  14711. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14712. * @returns {Function|Object} Returns `object`.
  14713. * @example
  14714. *
  14715. * function vowels(string) {
  14716. * return _.filter(string, function(v) {
  14717. * return /[aeiou]/i.test(v);
  14718. * });
  14719. * }
  14720. *
  14721. * _.mixin({ 'vowels': vowels });
  14722. * _.vowels('fred');
  14723. * // => ['e']
  14724. *
  14725. * _('fred').vowels().value();
  14726. * // => ['e']
  14727. *
  14728. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14729. * _('fred').vowels();
  14730. * // => ['e']
  14731. */
  14732. function mixin(object, source, options) {
  14733. var props = keys(source),
  14734. methodNames = baseFunctions(source, props);
  14735. if (options == null &&
  14736. !(isObject(source) && (methodNames.length || !props.length))) {
  14737. options = source;
  14738. source = object;
  14739. object = this;
  14740. methodNames = baseFunctions(source, keys(source));
  14741. }
  14742. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14743. isFunc = isFunction(object);
  14744. arrayEach(methodNames, function(methodName) {
  14745. var func = source[methodName];
  14746. object[methodName] = func;
  14747. if (isFunc) {
  14748. object.prototype[methodName] = function() {
  14749. var chainAll = this.__chain__;
  14750. if (chain || chainAll) {
  14751. var result = object(this.__wrapped__),
  14752. actions = result.__actions__ = copyArray(this.__actions__);
  14753. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14754. result.__chain__ = chainAll;
  14755. return result;
  14756. }
  14757. return func.apply(object, arrayPush([this.value()], arguments));
  14758. };
  14759. }
  14760. });
  14761. return object;
  14762. }
  14763. /**
  14764. * Reverts the `_` variable to its previous value and returns a reference to
  14765. * the `lodash` function.
  14766. *
  14767. * @static
  14768. * @since 0.1.0
  14769. * @memberOf _
  14770. * @category Util
  14771. * @returns {Function} Returns the `lodash` function.
  14772. * @example
  14773. *
  14774. * var lodash = _.noConflict();
  14775. */
  14776. function noConflict() {
  14777. if (root._ === this) {
  14778. root._ = oldDash;
  14779. }
  14780. return this;
  14781. }
  14782. /**
  14783. * This method returns `undefined`.
  14784. *
  14785. * @static
  14786. * @memberOf _
  14787. * @since 2.3.0
  14788. * @category Util
  14789. * @example
  14790. *
  14791. * _.times(2, _.noop);
  14792. * // => [undefined, undefined]
  14793. */
  14794. function noop() {
  14795. // No operation performed.
  14796. }
  14797. /**
  14798. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14799. * the nth argument from the end is returned.
  14800. *
  14801. * @static
  14802. * @memberOf _
  14803. * @since 4.0.0
  14804. * @category Util
  14805. * @param {number} [n=0] The index of the argument to return.
  14806. * @returns {Function} Returns the new pass-thru function.
  14807. * @example
  14808. *
  14809. * var func = _.nthArg(1);
  14810. * func('a', 'b', 'c', 'd');
  14811. * // => 'b'
  14812. *
  14813. * var func = _.nthArg(-2);
  14814. * func('a', 'b', 'c', 'd');
  14815. * // => 'c'
  14816. */
  14817. function nthArg(n) {
  14818. n = toInteger(n);
  14819. return baseRest(function(args) {
  14820. return baseNth(args, n);
  14821. });
  14822. }
  14823. /**
  14824. * Creates a function that invokes `iteratees` with the arguments it receives
  14825. * and returns their results.
  14826. *
  14827. * @static
  14828. * @memberOf _
  14829. * @since 4.0.0
  14830. * @category Util
  14831. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14832. * The iteratees to invoke.
  14833. * @returns {Function} Returns the new function.
  14834. * @example
  14835. *
  14836. * var func = _.over([Math.max, Math.min]);
  14837. *
  14838. * func(1, 2, 3, 4);
  14839. * // => [4, 1]
  14840. */
  14841. var over = createOver(arrayMap);
  14842. /**
  14843. * Creates a function that checks if **all** of the `predicates` return
  14844. * truthy when invoked with the arguments it receives.
  14845. *
  14846. * @static
  14847. * @memberOf _
  14848. * @since 4.0.0
  14849. * @category Util
  14850. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14851. * The predicates to check.
  14852. * @returns {Function} Returns the new function.
  14853. * @example
  14854. *
  14855. * var func = _.overEvery([Boolean, isFinite]);
  14856. *
  14857. * func('1');
  14858. * // => true
  14859. *
  14860. * func(null);
  14861. * // => false
  14862. *
  14863. * func(NaN);
  14864. * // => false
  14865. */
  14866. var overEvery = createOver(arrayEvery);
  14867. /**
  14868. * Creates a function that checks if **any** of the `predicates` return
  14869. * truthy when invoked with the arguments it receives.
  14870. *
  14871. * @static
  14872. * @memberOf _
  14873. * @since 4.0.0
  14874. * @category Util
  14875. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14876. * The predicates to check.
  14877. * @returns {Function} Returns the new function.
  14878. * @example
  14879. *
  14880. * var func = _.overSome([Boolean, isFinite]);
  14881. *
  14882. * func('1');
  14883. * // => true
  14884. *
  14885. * func(null);
  14886. * // => true
  14887. *
  14888. * func(NaN);
  14889. * // => false
  14890. */
  14891. var overSome = createOver(arraySome);
  14892. /**
  14893. * Creates a function that returns the value at `path` of a given object.
  14894. *
  14895. * @static
  14896. * @memberOf _
  14897. * @since 2.4.0
  14898. * @category Util
  14899. * @param {Array|string} path The path of the property to get.
  14900. * @returns {Function} Returns the new accessor function.
  14901. * @example
  14902. *
  14903. * var objects = [
  14904. * { 'a': { 'b': 2 } },
  14905. * { 'a': { 'b': 1 } }
  14906. * ];
  14907. *
  14908. * _.map(objects, _.property('a.b'));
  14909. * // => [2, 1]
  14910. *
  14911. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14912. * // => [1, 2]
  14913. */
  14914. function property(path) {
  14915. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14916. }
  14917. /**
  14918. * The opposite of `_.property`; this method creates a function that returns
  14919. * the value at a given path of `object`.
  14920. *
  14921. * @static
  14922. * @memberOf _
  14923. * @since 3.0.0
  14924. * @category Util
  14925. * @param {Object} object The object to query.
  14926. * @returns {Function} Returns the new accessor function.
  14927. * @example
  14928. *
  14929. * var array = [0, 1, 2],
  14930. * object = { 'a': array, 'b': array, 'c': array };
  14931. *
  14932. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14933. * // => [2, 0]
  14934. *
  14935. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14936. * // => [2, 0]
  14937. */
  14938. function propertyOf(object) {
  14939. return function(path) {
  14940. return object == null ? undefined : baseGet(object, path);
  14941. };
  14942. }
  14943. /**
  14944. * Creates an array of numbers (positive and/or negative) progressing from
  14945. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14946. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14947. * it's set to `start` with `start` then set to `0`.
  14948. *
  14949. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14950. * floating-point values which can produce unexpected results.
  14951. *
  14952. * @static
  14953. * @since 0.1.0
  14954. * @memberOf _
  14955. * @category Util
  14956. * @param {number} [start=0] The start of the range.
  14957. * @param {number} end The end of the range.
  14958. * @param {number} [step=1] The value to increment or decrement by.
  14959. * @returns {Array} Returns the range of numbers.
  14960. * @see _.inRange, _.rangeRight
  14961. * @example
  14962. *
  14963. * _.range(4);
  14964. * // => [0, 1, 2, 3]
  14965. *
  14966. * _.range(-4);
  14967. * // => [0, -1, -2, -3]
  14968. *
  14969. * _.range(1, 5);
  14970. * // => [1, 2, 3, 4]
  14971. *
  14972. * _.range(0, 20, 5);
  14973. * // => [0, 5, 10, 15]
  14974. *
  14975. * _.range(0, -4, -1);
  14976. * // => [0, -1, -2, -3]
  14977. *
  14978. * _.range(1, 4, 0);
  14979. * // => [1, 1, 1]
  14980. *
  14981. * _.range(0);
  14982. * // => []
  14983. */
  14984. var range = createRange();
  14985. /**
  14986. * This method is like `_.range` except that it populates values in
  14987. * descending order.
  14988. *
  14989. * @static
  14990. * @memberOf _
  14991. * @since 4.0.0
  14992. * @category Util
  14993. * @param {number} [start=0] The start of the range.
  14994. * @param {number} end The end of the range.
  14995. * @param {number} [step=1] The value to increment or decrement by.
  14996. * @returns {Array} Returns the range of numbers.
  14997. * @see _.inRange, _.range
  14998. * @example
  14999. *
  15000. * _.rangeRight(4);
  15001. * // => [3, 2, 1, 0]
  15002. *
  15003. * _.rangeRight(-4);
  15004. * // => [-3, -2, -1, 0]
  15005. *
  15006. * _.rangeRight(1, 5);
  15007. * // => [4, 3, 2, 1]
  15008. *
  15009. * _.rangeRight(0, 20, 5);
  15010. * // => [15, 10, 5, 0]
  15011. *
  15012. * _.rangeRight(0, -4, -1);
  15013. * // => [-3, -2, -1, 0]
  15014. *
  15015. * _.rangeRight(1, 4, 0);
  15016. * // => [1, 1, 1]
  15017. *
  15018. * _.rangeRight(0);
  15019. * // => []
  15020. */
  15021. var rangeRight = createRange(true);
  15022. /**
  15023. * This method returns a new empty array.
  15024. *
  15025. * @static
  15026. * @memberOf _
  15027. * @since 4.13.0
  15028. * @category Util
  15029. * @returns {Array} Returns the new empty array.
  15030. * @example
  15031. *
  15032. * var arrays = _.times(2, _.stubArray);
  15033. *
  15034. * console.log(arrays);
  15035. * // => [[], []]
  15036. *
  15037. * console.log(arrays[0] === arrays[1]);
  15038. * // => false
  15039. */
  15040. function stubArray() {
  15041. return [];
  15042. }
  15043. /**
  15044. * This method returns `false`.
  15045. *
  15046. * @static
  15047. * @memberOf _
  15048. * @since 4.13.0
  15049. * @category Util
  15050. * @returns {boolean} Returns `false`.
  15051. * @example
  15052. *
  15053. * _.times(2, _.stubFalse);
  15054. * // => [false, false]
  15055. */
  15056. function stubFalse() {
  15057. return false;
  15058. }
  15059. /**
  15060. * This method returns a new empty object.
  15061. *
  15062. * @static
  15063. * @memberOf _
  15064. * @since 4.13.0
  15065. * @category Util
  15066. * @returns {Object} Returns the new empty object.
  15067. * @example
  15068. *
  15069. * var objects = _.times(2, _.stubObject);
  15070. *
  15071. * console.log(objects);
  15072. * // => [{}, {}]
  15073. *
  15074. * console.log(objects[0] === objects[1]);
  15075. * // => false
  15076. */
  15077. function stubObject() {
  15078. return {};
  15079. }
  15080. /**
  15081. * This method returns an empty string.
  15082. *
  15083. * @static
  15084. * @memberOf _
  15085. * @since 4.13.0
  15086. * @category Util
  15087. * @returns {string} Returns the empty string.
  15088. * @example
  15089. *
  15090. * _.times(2, _.stubString);
  15091. * // => ['', '']
  15092. */
  15093. function stubString() {
  15094. return '';
  15095. }
  15096. /**
  15097. * This method returns `true`.
  15098. *
  15099. * @static
  15100. * @memberOf _
  15101. * @since 4.13.0
  15102. * @category Util
  15103. * @returns {boolean} Returns `true`.
  15104. * @example
  15105. *
  15106. * _.times(2, _.stubTrue);
  15107. * // => [true, true]
  15108. */
  15109. function stubTrue() {
  15110. return true;
  15111. }
  15112. /**
  15113. * Invokes the iteratee `n` times, returning an array of the results of
  15114. * each invocation. The iteratee is invoked with one argument; (index).
  15115. *
  15116. * @static
  15117. * @since 0.1.0
  15118. * @memberOf _
  15119. * @category Util
  15120. * @param {number} n The number of times to invoke `iteratee`.
  15121. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15122. * @returns {Array} Returns the array of results.
  15123. * @example
  15124. *
  15125. * _.times(3, String);
  15126. * // => ['0', '1', '2']
  15127. *
  15128. * _.times(4, _.constant(0));
  15129. * // => [0, 0, 0, 0]
  15130. */
  15131. function times(n, iteratee) {
  15132. n = toInteger(n);
  15133. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15134. return [];
  15135. }
  15136. var index = MAX_ARRAY_LENGTH,
  15137. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15138. iteratee = getIteratee(iteratee);
  15139. n -= MAX_ARRAY_LENGTH;
  15140. var result = baseTimes(length, iteratee);
  15141. while (++index < n) {
  15142. iteratee(index);
  15143. }
  15144. return result;
  15145. }
  15146. /**
  15147. * Converts `value` to a property path array.
  15148. *
  15149. * @static
  15150. * @memberOf _
  15151. * @since 4.0.0
  15152. * @category Util
  15153. * @param {*} value The value to convert.
  15154. * @returns {Array} Returns the new property path array.
  15155. * @example
  15156. *
  15157. * _.toPath('a.b.c');
  15158. * // => ['a', 'b', 'c']
  15159. *
  15160. * _.toPath('a[0].b.c');
  15161. * // => ['a', '0', 'b', 'c']
  15162. */
  15163. function toPath(value) {
  15164. if (isArray(value)) {
  15165. return arrayMap(value, toKey);
  15166. }
  15167. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15168. }
  15169. /**
  15170. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15171. *
  15172. * @static
  15173. * @since 0.1.0
  15174. * @memberOf _
  15175. * @category Util
  15176. * @param {string} [prefix=''] The value to prefix the ID with.
  15177. * @returns {string} Returns the unique ID.
  15178. * @example
  15179. *
  15180. * _.uniqueId('contact_');
  15181. * // => 'contact_104'
  15182. *
  15183. * _.uniqueId();
  15184. * // => '105'
  15185. */
  15186. function uniqueId(prefix) {
  15187. var id = ++idCounter;
  15188. return toString(prefix) + id;
  15189. }
  15190. /*------------------------------------------------------------------------*/
  15191. /**
  15192. * Adds two numbers.
  15193. *
  15194. * @static
  15195. * @memberOf _
  15196. * @since 3.4.0
  15197. * @category Math
  15198. * @param {number} augend The first number in an addition.
  15199. * @param {number} addend The second number in an addition.
  15200. * @returns {number} Returns the total.
  15201. * @example
  15202. *
  15203. * _.add(6, 4);
  15204. * // => 10
  15205. */
  15206. var add = createMathOperation(function(augend, addend) {
  15207. return augend + addend;
  15208. }, 0);
  15209. /**
  15210. * Computes `number` rounded up to `precision`.
  15211. *
  15212. * @static
  15213. * @memberOf _
  15214. * @since 3.10.0
  15215. * @category Math
  15216. * @param {number} number The number to round up.
  15217. * @param {number} [precision=0] The precision to round up to.
  15218. * @returns {number} Returns the rounded up number.
  15219. * @example
  15220. *
  15221. * _.ceil(4.006);
  15222. * // => 5
  15223. *
  15224. * _.ceil(6.004, 2);
  15225. * // => 6.01
  15226. *
  15227. * _.ceil(6040, -2);
  15228. * // => 6100
  15229. */
  15230. var ceil = createRound('ceil');
  15231. /**
  15232. * Divide two numbers.
  15233. *
  15234. * @static
  15235. * @memberOf _
  15236. * @since 4.7.0
  15237. * @category Math
  15238. * @param {number} dividend The first number in a division.
  15239. * @param {number} divisor The second number in a division.
  15240. * @returns {number} Returns the quotient.
  15241. * @example
  15242. *
  15243. * _.divide(6, 4);
  15244. * // => 1.5
  15245. */
  15246. var divide = createMathOperation(function(dividend, divisor) {
  15247. return dividend / divisor;
  15248. }, 1);
  15249. /**
  15250. * Computes `number` rounded down to `precision`.
  15251. *
  15252. * @static
  15253. * @memberOf _
  15254. * @since 3.10.0
  15255. * @category Math
  15256. * @param {number} number The number to round down.
  15257. * @param {number} [precision=0] The precision to round down to.
  15258. * @returns {number} Returns the rounded down number.
  15259. * @example
  15260. *
  15261. * _.floor(4.006);
  15262. * // => 4
  15263. *
  15264. * _.floor(0.046, 2);
  15265. * // => 0.04
  15266. *
  15267. * _.floor(4060, -2);
  15268. * // => 4000
  15269. */
  15270. var floor = createRound('floor');
  15271. /**
  15272. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15273. * `undefined` is returned.
  15274. *
  15275. * @static
  15276. * @since 0.1.0
  15277. * @memberOf _
  15278. * @category Math
  15279. * @param {Array} array The array to iterate over.
  15280. * @returns {*} Returns the maximum value.
  15281. * @example
  15282. *
  15283. * _.max([4, 2, 8, 6]);
  15284. * // => 8
  15285. *
  15286. * _.max([]);
  15287. * // => undefined
  15288. */
  15289. function max(array) {
  15290. return (array && array.length)
  15291. ? baseExtremum(array, identity, baseGt)
  15292. : undefined;
  15293. }
  15294. /**
  15295. * This method is like `_.max` except that it accepts `iteratee` which is
  15296. * invoked for each element in `array` to generate the criterion by which
  15297. * the value is ranked. The iteratee is invoked with one argument: (value).
  15298. *
  15299. * @static
  15300. * @memberOf _
  15301. * @since 4.0.0
  15302. * @category Math
  15303. * @param {Array} array The array to iterate over.
  15304. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15305. * @returns {*} Returns the maximum value.
  15306. * @example
  15307. *
  15308. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15309. *
  15310. * _.maxBy(objects, function(o) { return o.n; });
  15311. * // => { 'n': 2 }
  15312. *
  15313. * // The `_.property` iteratee shorthand.
  15314. * _.maxBy(objects, 'n');
  15315. * // => { 'n': 2 }
  15316. */
  15317. function maxBy(array, iteratee) {
  15318. return (array && array.length)
  15319. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15320. : undefined;
  15321. }
  15322. /**
  15323. * Computes the mean of the values in `array`.
  15324. *
  15325. * @static
  15326. * @memberOf _
  15327. * @since 4.0.0
  15328. * @category Math
  15329. * @param {Array} array The array to iterate over.
  15330. * @returns {number} Returns the mean.
  15331. * @example
  15332. *
  15333. * _.mean([4, 2, 8, 6]);
  15334. * // => 5
  15335. */
  15336. function mean(array) {
  15337. return baseMean(array, identity);
  15338. }
  15339. /**
  15340. * This method is like `_.mean` except that it accepts `iteratee` which is
  15341. * invoked for each element in `array` to generate the value to be averaged.
  15342. * The iteratee is invoked with one argument: (value).
  15343. *
  15344. * @static
  15345. * @memberOf _
  15346. * @since 4.7.0
  15347. * @category Math
  15348. * @param {Array} array The array to iterate over.
  15349. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15350. * @returns {number} Returns the mean.
  15351. * @example
  15352. *
  15353. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15354. *
  15355. * _.meanBy(objects, function(o) { return o.n; });
  15356. * // => 5
  15357. *
  15358. * // The `_.property` iteratee shorthand.
  15359. * _.meanBy(objects, 'n');
  15360. * // => 5
  15361. */
  15362. function meanBy(array, iteratee) {
  15363. return baseMean(array, getIteratee(iteratee, 2));
  15364. }
  15365. /**
  15366. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15367. * `undefined` is returned.
  15368. *
  15369. * @static
  15370. * @since 0.1.0
  15371. * @memberOf _
  15372. * @category Math
  15373. * @param {Array} array The array to iterate over.
  15374. * @returns {*} Returns the minimum value.
  15375. * @example
  15376. *
  15377. * _.min([4, 2, 8, 6]);
  15378. * // => 2
  15379. *
  15380. * _.min([]);
  15381. * // => undefined
  15382. */
  15383. function min(array) {
  15384. return (array && array.length)
  15385. ? baseExtremum(array, identity, baseLt)
  15386. : undefined;
  15387. }
  15388. /**
  15389. * This method is like `_.min` except that it accepts `iteratee` which is
  15390. * invoked for each element in `array` to generate the criterion by which
  15391. * the value is ranked. The iteratee is invoked with one argument: (value).
  15392. *
  15393. * @static
  15394. * @memberOf _
  15395. * @since 4.0.0
  15396. * @category Math
  15397. * @param {Array} array The array to iterate over.
  15398. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15399. * @returns {*} Returns the minimum value.
  15400. * @example
  15401. *
  15402. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15403. *
  15404. * _.minBy(objects, function(o) { return o.n; });
  15405. * // => { 'n': 1 }
  15406. *
  15407. * // The `_.property` iteratee shorthand.
  15408. * _.minBy(objects, 'n');
  15409. * // => { 'n': 1 }
  15410. */
  15411. function minBy(array, iteratee) {
  15412. return (array && array.length)
  15413. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15414. : undefined;
  15415. }
  15416. /**
  15417. * Multiply two numbers.
  15418. *
  15419. * @static
  15420. * @memberOf _
  15421. * @since 4.7.0
  15422. * @category Math
  15423. * @param {number} multiplier The first number in a multiplication.
  15424. * @param {number} multiplicand The second number in a multiplication.
  15425. * @returns {number} Returns the product.
  15426. * @example
  15427. *
  15428. * _.multiply(6, 4);
  15429. * // => 24
  15430. */
  15431. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15432. return multiplier * multiplicand;
  15433. }, 1);
  15434. /**
  15435. * Computes `number` rounded to `precision`.
  15436. *
  15437. * @static
  15438. * @memberOf _
  15439. * @since 3.10.0
  15440. * @category Math
  15441. * @param {number} number The number to round.
  15442. * @param {number} [precision=0] The precision to round to.
  15443. * @returns {number} Returns the rounded number.
  15444. * @example
  15445. *
  15446. * _.round(4.006);
  15447. * // => 4
  15448. *
  15449. * _.round(4.006, 2);
  15450. * // => 4.01
  15451. *
  15452. * _.round(4060, -2);
  15453. * // => 4100
  15454. */
  15455. var round = createRound('round');
  15456. /**
  15457. * Subtract two numbers.
  15458. *
  15459. * @static
  15460. * @memberOf _
  15461. * @since 4.0.0
  15462. * @category Math
  15463. * @param {number} minuend The first number in a subtraction.
  15464. * @param {number} subtrahend The second number in a subtraction.
  15465. * @returns {number} Returns the difference.
  15466. * @example
  15467. *
  15468. * _.subtract(6, 4);
  15469. * // => 2
  15470. */
  15471. var subtract = createMathOperation(function(minuend, subtrahend) {
  15472. return minuend - subtrahend;
  15473. }, 0);
  15474. /**
  15475. * Computes the sum of the values in `array`.
  15476. *
  15477. * @static
  15478. * @memberOf _
  15479. * @since 3.4.0
  15480. * @category Math
  15481. * @param {Array} array The array to iterate over.
  15482. * @returns {number} Returns the sum.
  15483. * @example
  15484. *
  15485. * _.sum([4, 2, 8, 6]);
  15486. * // => 20
  15487. */
  15488. function sum(array) {
  15489. return (array && array.length)
  15490. ? baseSum(array, identity)
  15491. : 0;
  15492. }
  15493. /**
  15494. * This method is like `_.sum` except that it accepts `iteratee` which is
  15495. * invoked for each element in `array` to generate the value to be summed.
  15496. * The iteratee is invoked with one argument: (value).
  15497. *
  15498. * @static
  15499. * @memberOf _
  15500. * @since 4.0.0
  15501. * @category Math
  15502. * @param {Array} array The array to iterate over.
  15503. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15504. * @returns {number} Returns the sum.
  15505. * @example
  15506. *
  15507. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15508. *
  15509. * _.sumBy(objects, function(o) { return o.n; });
  15510. * // => 20
  15511. *
  15512. * // The `_.property` iteratee shorthand.
  15513. * _.sumBy(objects, 'n');
  15514. * // => 20
  15515. */
  15516. function sumBy(array, iteratee) {
  15517. return (array && array.length)
  15518. ? baseSum(array, getIteratee(iteratee, 2))
  15519. : 0;
  15520. }
  15521. /*------------------------------------------------------------------------*/
  15522. // Add methods that return wrapped values in chain sequences.
  15523. lodash.after = after;
  15524. lodash.ary = ary;
  15525. lodash.assign = assign;
  15526. lodash.assignIn = assignIn;
  15527. lodash.assignInWith = assignInWith;
  15528. lodash.assignWith = assignWith;
  15529. lodash.at = at;
  15530. lodash.before = before;
  15531. lodash.bind = bind;
  15532. lodash.bindAll = bindAll;
  15533. lodash.bindKey = bindKey;
  15534. lodash.castArray = castArray;
  15535. lodash.chain = chain;
  15536. lodash.chunk = chunk;
  15537. lodash.compact = compact;
  15538. lodash.concat = concat;
  15539. lodash.cond = cond;
  15540. lodash.conforms = conforms;
  15541. lodash.constant = constant;
  15542. lodash.countBy = countBy;
  15543. lodash.create = create;
  15544. lodash.curry = curry;
  15545. lodash.curryRight = curryRight;
  15546. lodash.debounce = debounce;
  15547. lodash.defaults = defaults;
  15548. lodash.defaultsDeep = defaultsDeep;
  15549. lodash.defer = defer;
  15550. lodash.delay = delay;
  15551. lodash.difference = difference;
  15552. lodash.differenceBy = differenceBy;
  15553. lodash.differenceWith = differenceWith;
  15554. lodash.drop = drop;
  15555. lodash.dropRight = dropRight;
  15556. lodash.dropRightWhile = dropRightWhile;
  15557. lodash.dropWhile = dropWhile;
  15558. lodash.fill = fill;
  15559. lodash.filter = filter;
  15560. lodash.flatMap = flatMap;
  15561. lodash.flatMapDeep = flatMapDeep;
  15562. lodash.flatMapDepth = flatMapDepth;
  15563. lodash.flatten = flatten;
  15564. lodash.flattenDeep = flattenDeep;
  15565. lodash.flattenDepth = flattenDepth;
  15566. lodash.flip = flip;
  15567. lodash.flow = flow;
  15568. lodash.flowRight = flowRight;
  15569. lodash.fromPairs = fromPairs;
  15570. lodash.functions = functions;
  15571. lodash.functionsIn = functionsIn;
  15572. lodash.groupBy = groupBy;
  15573. lodash.initial = initial;
  15574. lodash.intersection = intersection;
  15575. lodash.intersectionBy = intersectionBy;
  15576. lodash.intersectionWith = intersectionWith;
  15577. lodash.invert = invert;
  15578. lodash.invertBy = invertBy;
  15579. lodash.invokeMap = invokeMap;
  15580. lodash.iteratee = iteratee;
  15581. lodash.keyBy = keyBy;
  15582. lodash.keys = keys;
  15583. lodash.keysIn = keysIn;
  15584. lodash.map = map;
  15585. lodash.mapKeys = mapKeys;
  15586. lodash.mapValues = mapValues;
  15587. lodash.matches = matches;
  15588. lodash.matchesProperty = matchesProperty;
  15589. lodash.memoize = memoize;
  15590. lodash.merge = merge;
  15591. lodash.mergeWith = mergeWith;
  15592. lodash.method = method;
  15593. lodash.methodOf = methodOf;
  15594. lodash.mixin = mixin;
  15595. lodash.negate = negate;
  15596. lodash.nthArg = nthArg;
  15597. lodash.omit = omit;
  15598. lodash.omitBy = omitBy;
  15599. lodash.once = once;
  15600. lodash.orderBy = orderBy;
  15601. lodash.over = over;
  15602. lodash.overArgs = overArgs;
  15603. lodash.overEvery = overEvery;
  15604. lodash.overSome = overSome;
  15605. lodash.partial = partial;
  15606. lodash.partialRight = partialRight;
  15607. lodash.partition = partition;
  15608. lodash.pick = pick;
  15609. lodash.pickBy = pickBy;
  15610. lodash.property = property;
  15611. lodash.propertyOf = propertyOf;
  15612. lodash.pull = pull;
  15613. lodash.pullAll = pullAll;
  15614. lodash.pullAllBy = pullAllBy;
  15615. lodash.pullAllWith = pullAllWith;
  15616. lodash.pullAt = pullAt;
  15617. lodash.range = range;
  15618. lodash.rangeRight = rangeRight;
  15619. lodash.rearg = rearg;
  15620. lodash.reject = reject;
  15621. lodash.remove = remove;
  15622. lodash.rest = rest;
  15623. lodash.reverse = reverse;
  15624. lodash.sampleSize = sampleSize;
  15625. lodash.set = set;
  15626. lodash.setWith = setWith;
  15627. lodash.shuffle = shuffle;
  15628. lodash.slice = slice;
  15629. lodash.sortBy = sortBy;
  15630. lodash.sortedUniq = sortedUniq;
  15631. lodash.sortedUniqBy = sortedUniqBy;
  15632. lodash.split = split;
  15633. lodash.spread = spread;
  15634. lodash.tail = tail;
  15635. lodash.take = take;
  15636. lodash.takeRight = takeRight;
  15637. lodash.takeRightWhile = takeRightWhile;
  15638. lodash.takeWhile = takeWhile;
  15639. lodash.tap = tap;
  15640. lodash.throttle = throttle;
  15641. lodash.thru = thru;
  15642. lodash.toArray = toArray;
  15643. lodash.toPairs = toPairs;
  15644. lodash.toPairsIn = toPairsIn;
  15645. lodash.toPath = toPath;
  15646. lodash.toPlainObject = toPlainObject;
  15647. lodash.transform = transform;
  15648. lodash.unary = unary;
  15649. lodash.union = union;
  15650. lodash.unionBy = unionBy;
  15651. lodash.unionWith = unionWith;
  15652. lodash.uniq = uniq;
  15653. lodash.uniqBy = uniqBy;
  15654. lodash.uniqWith = uniqWith;
  15655. lodash.unset = unset;
  15656. lodash.unzip = unzip;
  15657. lodash.unzipWith = unzipWith;
  15658. lodash.update = update;
  15659. lodash.updateWith = updateWith;
  15660. lodash.values = values;
  15661. lodash.valuesIn = valuesIn;
  15662. lodash.without = without;
  15663. lodash.words = words;
  15664. lodash.wrap = wrap;
  15665. lodash.xor = xor;
  15666. lodash.xorBy = xorBy;
  15667. lodash.xorWith = xorWith;
  15668. lodash.zip = zip;
  15669. lodash.zipObject = zipObject;
  15670. lodash.zipObjectDeep = zipObjectDeep;
  15671. lodash.zipWith = zipWith;
  15672. // Add aliases.
  15673. lodash.entries = toPairs;
  15674. lodash.entriesIn = toPairsIn;
  15675. lodash.extend = assignIn;
  15676. lodash.extendWith = assignInWith;
  15677. // Add methods to `lodash.prototype`.
  15678. mixin(lodash, lodash);
  15679. /*------------------------------------------------------------------------*/
  15680. // Add methods that return unwrapped values in chain sequences.
  15681. lodash.add = add;
  15682. lodash.attempt = attempt;
  15683. lodash.camelCase = camelCase;
  15684. lodash.capitalize = capitalize;
  15685. lodash.ceil = ceil;
  15686. lodash.clamp = clamp;
  15687. lodash.clone = clone;
  15688. lodash.cloneDeep = cloneDeep;
  15689. lodash.cloneDeepWith = cloneDeepWith;
  15690. lodash.cloneWith = cloneWith;
  15691. lodash.conformsTo = conformsTo;
  15692. lodash.deburr = deburr;
  15693. lodash.defaultTo = defaultTo;
  15694. lodash.divide = divide;
  15695. lodash.endsWith = endsWith;
  15696. lodash.eq = eq;
  15697. lodash.escape = escape;
  15698. lodash.escapeRegExp = escapeRegExp;
  15699. lodash.every = every;
  15700. lodash.find = find;
  15701. lodash.findIndex = findIndex;
  15702. lodash.findKey = findKey;
  15703. lodash.findLast = findLast;
  15704. lodash.findLastIndex = findLastIndex;
  15705. lodash.findLastKey = findLastKey;
  15706. lodash.floor = floor;
  15707. lodash.forEach = forEach;
  15708. lodash.forEachRight = forEachRight;
  15709. lodash.forIn = forIn;
  15710. lodash.forInRight = forInRight;
  15711. lodash.forOwn = forOwn;
  15712. lodash.forOwnRight = forOwnRight;
  15713. lodash.get = get;
  15714. lodash.gt = gt;
  15715. lodash.gte = gte;
  15716. lodash.has = has;
  15717. lodash.hasIn = hasIn;
  15718. lodash.head = head;
  15719. lodash.identity = identity;
  15720. lodash.includes = includes;
  15721. lodash.indexOf = indexOf;
  15722. lodash.inRange = inRange;
  15723. lodash.invoke = invoke;
  15724. lodash.isArguments = isArguments;
  15725. lodash.isArray = isArray;
  15726. lodash.isArrayBuffer = isArrayBuffer;
  15727. lodash.isArrayLike = isArrayLike;
  15728. lodash.isArrayLikeObject = isArrayLikeObject;
  15729. lodash.isBoolean = isBoolean;
  15730. lodash.isBuffer = isBuffer;
  15731. lodash.isDate = isDate;
  15732. lodash.isElement = isElement;
  15733. lodash.isEmpty = isEmpty;
  15734. lodash.isEqual = isEqual;
  15735. lodash.isEqualWith = isEqualWith;
  15736. lodash.isError = isError;
  15737. lodash.isFinite = isFinite;
  15738. lodash.isFunction = isFunction;
  15739. lodash.isInteger = isInteger;
  15740. lodash.isLength = isLength;
  15741. lodash.isMap = isMap;
  15742. lodash.isMatch = isMatch;
  15743. lodash.isMatchWith = isMatchWith;
  15744. lodash.isNaN = isNaN;
  15745. lodash.isNative = isNative;
  15746. lodash.isNil = isNil;
  15747. lodash.isNull = isNull;
  15748. lodash.isNumber = isNumber;
  15749. lodash.isObject = isObject;
  15750. lodash.isObjectLike = isObjectLike;
  15751. lodash.isPlainObject = isPlainObject;
  15752. lodash.isRegExp = isRegExp;
  15753. lodash.isSafeInteger = isSafeInteger;
  15754. lodash.isSet = isSet;
  15755. lodash.isString = isString;
  15756. lodash.isSymbol = isSymbol;
  15757. lodash.isTypedArray = isTypedArray;
  15758. lodash.isUndefined = isUndefined;
  15759. lodash.isWeakMap = isWeakMap;
  15760. lodash.isWeakSet = isWeakSet;
  15761. lodash.join = join;
  15762. lodash.kebabCase = kebabCase;
  15763. lodash.last = last;
  15764. lodash.lastIndexOf = lastIndexOf;
  15765. lodash.lowerCase = lowerCase;
  15766. lodash.lowerFirst = lowerFirst;
  15767. lodash.lt = lt;
  15768. lodash.lte = lte;
  15769. lodash.max = max;
  15770. lodash.maxBy = maxBy;
  15771. lodash.mean = mean;
  15772. lodash.meanBy = meanBy;
  15773. lodash.min = min;
  15774. lodash.minBy = minBy;
  15775. lodash.stubArray = stubArray;
  15776. lodash.stubFalse = stubFalse;
  15777. lodash.stubObject = stubObject;
  15778. lodash.stubString = stubString;
  15779. lodash.stubTrue = stubTrue;
  15780. lodash.multiply = multiply;
  15781. lodash.nth = nth;
  15782. lodash.noConflict = noConflict;
  15783. lodash.noop = noop;
  15784. lodash.now = now;
  15785. lodash.pad = pad;
  15786. lodash.padEnd = padEnd;
  15787. lodash.padStart = padStart;
  15788. lodash.parseInt = parseInt;
  15789. lodash.random = random;
  15790. lodash.reduce = reduce;
  15791. lodash.reduceRight = reduceRight;
  15792. lodash.repeat = repeat;
  15793. lodash.replace = replace;
  15794. lodash.result = result;
  15795. lodash.round = round;
  15796. lodash.runInContext = runInContext;
  15797. lodash.sample = sample;
  15798. lodash.size = size;
  15799. lodash.snakeCase = snakeCase;
  15800. lodash.some = some;
  15801. lodash.sortedIndex = sortedIndex;
  15802. lodash.sortedIndexBy = sortedIndexBy;
  15803. lodash.sortedIndexOf = sortedIndexOf;
  15804. lodash.sortedLastIndex = sortedLastIndex;
  15805. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15806. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15807. lodash.startCase = startCase;
  15808. lodash.startsWith = startsWith;
  15809. lodash.subtract = subtract;
  15810. lodash.sum = sum;
  15811. lodash.sumBy = sumBy;
  15812. lodash.template = template;
  15813. lodash.times = times;
  15814. lodash.toFinite = toFinite;
  15815. lodash.toInteger = toInteger;
  15816. lodash.toLength = toLength;
  15817. lodash.toLower = toLower;
  15818. lodash.toNumber = toNumber;
  15819. lodash.toSafeInteger = toSafeInteger;
  15820. lodash.toString = toString;
  15821. lodash.toUpper = toUpper;
  15822. lodash.trim = trim;
  15823. lodash.trimEnd = trimEnd;
  15824. lodash.trimStart = trimStart;
  15825. lodash.truncate = truncate;
  15826. lodash.unescape = unescape;
  15827. lodash.uniqueId = uniqueId;
  15828. lodash.upperCase = upperCase;
  15829. lodash.upperFirst = upperFirst;
  15830. // Add aliases.
  15831. lodash.each = forEach;
  15832. lodash.eachRight = forEachRight;
  15833. lodash.first = head;
  15834. mixin(lodash, (function() {
  15835. var source = {};
  15836. baseForOwn(lodash, function(func, methodName) {
  15837. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15838. source[methodName] = func;
  15839. }
  15840. });
  15841. return source;
  15842. }()), { 'chain': false });
  15843. /*------------------------------------------------------------------------*/
  15844. /**
  15845. * The semantic version number.
  15846. *
  15847. * @static
  15848. * @memberOf _
  15849. * @type {string}
  15850. */
  15851. lodash.VERSION = VERSION;
  15852. // Assign default placeholders.
  15853. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15854. lodash[methodName].placeholder = lodash;
  15855. });
  15856. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15857. arrayEach(['drop', 'take'], function(methodName, index) {
  15858. LazyWrapper.prototype[methodName] = function(n) {
  15859. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15860. var result = (this.__filtered__ && !index)
  15861. ? new LazyWrapper(this)
  15862. : this.clone();
  15863. if (result.__filtered__) {
  15864. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15865. } else {
  15866. result.__views__.push({
  15867. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15868. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15869. });
  15870. }
  15871. return result;
  15872. };
  15873. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15874. return this.reverse()[methodName](n).reverse();
  15875. };
  15876. });
  15877. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15878. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15879. var type = index + 1,
  15880. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15881. LazyWrapper.prototype[methodName] = function(iteratee) {
  15882. var result = this.clone();
  15883. result.__iteratees__.push({
  15884. 'iteratee': getIteratee(iteratee, 3),
  15885. 'type': type
  15886. });
  15887. result.__filtered__ = result.__filtered__ || isFilter;
  15888. return result;
  15889. };
  15890. });
  15891. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15892. arrayEach(['head', 'last'], function(methodName, index) {
  15893. var takeName = 'take' + (index ? 'Right' : '');
  15894. LazyWrapper.prototype[methodName] = function() {
  15895. return this[takeName](1).value()[0];
  15896. };
  15897. });
  15898. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15899. arrayEach(['initial', 'tail'], function(methodName, index) {
  15900. var dropName = 'drop' + (index ? '' : 'Right');
  15901. LazyWrapper.prototype[methodName] = function() {
  15902. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15903. };
  15904. });
  15905. LazyWrapper.prototype.compact = function() {
  15906. return this.filter(identity);
  15907. };
  15908. LazyWrapper.prototype.find = function(predicate) {
  15909. return this.filter(predicate).head();
  15910. };
  15911. LazyWrapper.prototype.findLast = function(predicate) {
  15912. return this.reverse().find(predicate);
  15913. };
  15914. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15915. if (typeof path == 'function') {
  15916. return new LazyWrapper(this);
  15917. }
  15918. return this.map(function(value) {
  15919. return baseInvoke(value, path, args);
  15920. });
  15921. });
  15922. LazyWrapper.prototype.reject = function(predicate) {
  15923. return this.filter(negate(getIteratee(predicate)));
  15924. };
  15925. LazyWrapper.prototype.slice = function(start, end) {
  15926. start = toInteger(start);
  15927. var result = this;
  15928. if (result.__filtered__ && (start > 0 || end < 0)) {
  15929. return new LazyWrapper(result);
  15930. }
  15931. if (start < 0) {
  15932. result = result.takeRight(-start);
  15933. } else if (start) {
  15934. result = result.drop(start);
  15935. }
  15936. if (end !== undefined) {
  15937. end = toInteger(end);
  15938. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15939. }
  15940. return result;
  15941. };
  15942. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15943. return this.reverse().takeWhile(predicate).reverse();
  15944. };
  15945. LazyWrapper.prototype.toArray = function() {
  15946. return this.take(MAX_ARRAY_LENGTH);
  15947. };
  15948. // Add `LazyWrapper` methods to `lodash.prototype`.
  15949. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15950. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15951. isTaker = /^(?:head|last)$/.test(methodName),
  15952. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15953. retUnwrapped = isTaker || /^find/.test(methodName);
  15954. if (!lodashFunc) {
  15955. return;
  15956. }
  15957. lodash.prototype[methodName] = function() {
  15958. var value = this.__wrapped__,
  15959. args = isTaker ? [1] : arguments,
  15960. isLazy = value instanceof LazyWrapper,
  15961. iteratee = args[0],
  15962. useLazy = isLazy || isArray(value);
  15963. var interceptor = function(value) {
  15964. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15965. return (isTaker && chainAll) ? result[0] : result;
  15966. };
  15967. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15968. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15969. isLazy = useLazy = false;
  15970. }
  15971. var chainAll = this.__chain__,
  15972. isHybrid = !!this.__actions__.length,
  15973. isUnwrapped = retUnwrapped && !chainAll,
  15974. onlyLazy = isLazy && !isHybrid;
  15975. if (!retUnwrapped && useLazy) {
  15976. value = onlyLazy ? value : new LazyWrapper(this);
  15977. var result = func.apply(value, args);
  15978. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15979. return new LodashWrapper(result, chainAll);
  15980. }
  15981. if (isUnwrapped && onlyLazy) {
  15982. return func.apply(this, args);
  15983. }
  15984. result = this.thru(interceptor);
  15985. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15986. };
  15987. });
  15988. // Add `Array` methods to `lodash.prototype`.
  15989. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15990. var func = arrayProto[methodName],
  15991. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  15992. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  15993. lodash.prototype[methodName] = function() {
  15994. var args = arguments;
  15995. if (retUnwrapped && !this.__chain__) {
  15996. var value = this.value();
  15997. return func.apply(isArray(value) ? value : [], args);
  15998. }
  15999. return this[chainName](function(value) {
  16000. return func.apply(isArray(value) ? value : [], args);
  16001. });
  16002. };
  16003. });
  16004. // Map minified method names to their real names.
  16005. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16006. var lodashFunc = lodash[methodName];
  16007. if (lodashFunc) {
  16008. var key = lodashFunc.name + '';
  16009. if (!hasOwnProperty.call(realNames, key)) {
  16010. realNames[key] = [];
  16011. }
  16012. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  16013. }
  16014. });
  16015. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16016. 'name': 'wrapper',
  16017. 'func': undefined
  16018. }];
  16019. // Add methods to `LazyWrapper`.
  16020. LazyWrapper.prototype.clone = lazyClone;
  16021. LazyWrapper.prototype.reverse = lazyReverse;
  16022. LazyWrapper.prototype.value = lazyValue;
  16023. // Add chain sequence methods to the `lodash` wrapper.
  16024. lodash.prototype.at = wrapperAt;
  16025. lodash.prototype.chain = wrapperChain;
  16026. lodash.prototype.commit = wrapperCommit;
  16027. lodash.prototype.next = wrapperNext;
  16028. lodash.prototype.plant = wrapperPlant;
  16029. lodash.prototype.reverse = wrapperReverse;
  16030. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16031. // Add lazy aliases.
  16032. lodash.prototype.first = lodash.prototype.head;
  16033. if (symIterator) {
  16034. lodash.prototype[symIterator] = wrapperToIterator;
  16035. }
  16036. return lodash;
  16037. });
  16038. /*--------------------------------------------------------------------------*/
  16039. // Export lodash.
  16040. var _ = runInContext();
  16041. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16042. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16043. // Expose Lodash on the global object to prevent errors when Lodash is
  16044. // loaded by a script tag in the presence of an AMD loader.
  16045. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16046. // Use `_.noConflict` to remove Lodash from the global object.
  16047. root._ = _;
  16048. // Define as an anonymous module so, through path mapping, it can be
  16049. // referenced as the "underscore" module.
  16050. define(function() {
  16051. return _;
  16052. });
  16053. }
  16054. // Check for `exports` after `define` in case a build optimizer adds it.
  16055. else if (freeModule) {
  16056. // Export for Node.js.
  16057. (freeModule.exports = _)._ = _;
  16058. // Export for CommonJS support.
  16059. freeExports._ = _;
  16060. }
  16061. else {
  16062. // Export to the global object.
  16063. root._ = _;
  16064. }
  16065. }.call(this));