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.

17161 lines
530 KiB

  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.20';
  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. if (iteratees.length) {
  3386. iteratees = arrayMap(iteratees, function(iteratee) {
  3387. if (isArray(iteratee)) {
  3388. return function(value) {
  3389. return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
  3390. }
  3391. }
  3392. return iteratee;
  3393. });
  3394. } else {
  3395. iteratees = [identity];
  3396. }
  3397. var index = -1;
  3398. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  3399. var result = baseMap(collection, function(value, key, collection) {
  3400. var criteria = arrayMap(iteratees, function(iteratee) {
  3401. return iteratee(value);
  3402. });
  3403. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3404. });
  3405. return baseSortBy(result, function(object, other) {
  3406. return compareMultiple(object, other, orders);
  3407. });
  3408. }
  3409. /**
  3410. * The base implementation of `_.pick` without support for individual
  3411. * property identifiers.
  3412. *
  3413. * @private
  3414. * @param {Object} object The source object.
  3415. * @param {string[]} paths The property paths to pick.
  3416. * @returns {Object} Returns the new object.
  3417. */
  3418. function basePick(object, paths) {
  3419. return basePickBy(object, paths, function(value, path) {
  3420. return hasIn(object, path);
  3421. });
  3422. }
  3423. /**
  3424. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3425. *
  3426. * @private
  3427. * @param {Object} object The source object.
  3428. * @param {string[]} paths The property paths to pick.
  3429. * @param {Function} predicate The function invoked per property.
  3430. * @returns {Object} Returns the new object.
  3431. */
  3432. function basePickBy(object, paths, predicate) {
  3433. var index = -1,
  3434. length = paths.length,
  3435. result = {};
  3436. while (++index < length) {
  3437. var path = paths[index],
  3438. value = baseGet(object, path);
  3439. if (predicate(value, path)) {
  3440. baseSet(result, castPath(path, object), value);
  3441. }
  3442. }
  3443. return result;
  3444. }
  3445. /**
  3446. * A specialized version of `baseProperty` which supports deep paths.
  3447. *
  3448. * @private
  3449. * @param {Array|string} path The path of the property to get.
  3450. * @returns {Function} Returns the new accessor function.
  3451. */
  3452. function basePropertyDeep(path) {
  3453. return function(object) {
  3454. return baseGet(object, path);
  3455. };
  3456. }
  3457. /**
  3458. * The base implementation of `_.pullAllBy` without support for iteratee
  3459. * shorthands.
  3460. *
  3461. * @private
  3462. * @param {Array} array The array to modify.
  3463. * @param {Array} values The values to remove.
  3464. * @param {Function} [iteratee] The iteratee invoked per element.
  3465. * @param {Function} [comparator] The comparator invoked per element.
  3466. * @returns {Array} Returns `array`.
  3467. */
  3468. function basePullAll(array, values, iteratee, comparator) {
  3469. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3470. index = -1,
  3471. length = values.length,
  3472. seen = array;
  3473. if (array === values) {
  3474. values = copyArray(values);
  3475. }
  3476. if (iteratee) {
  3477. seen = arrayMap(array, baseUnary(iteratee));
  3478. }
  3479. while (++index < length) {
  3480. var fromIndex = 0,
  3481. value = values[index],
  3482. computed = iteratee ? iteratee(value) : value;
  3483. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3484. if (seen !== array) {
  3485. splice.call(seen, fromIndex, 1);
  3486. }
  3487. splice.call(array, fromIndex, 1);
  3488. }
  3489. }
  3490. return array;
  3491. }
  3492. /**
  3493. * The base implementation of `_.pullAt` without support for individual
  3494. * indexes or capturing the removed elements.
  3495. *
  3496. * @private
  3497. * @param {Array} array The array to modify.
  3498. * @param {number[]} indexes The indexes of elements to remove.
  3499. * @returns {Array} Returns `array`.
  3500. */
  3501. function basePullAt(array, indexes) {
  3502. var length = array ? indexes.length : 0,
  3503. lastIndex = length - 1;
  3504. while (length--) {
  3505. var index = indexes[length];
  3506. if (length == lastIndex || index !== previous) {
  3507. var previous = index;
  3508. if (isIndex(index)) {
  3509. splice.call(array, index, 1);
  3510. } else {
  3511. baseUnset(array, index);
  3512. }
  3513. }
  3514. }
  3515. return array;
  3516. }
  3517. /**
  3518. * The base implementation of `_.random` without support for returning
  3519. * floating-point numbers.
  3520. *
  3521. * @private
  3522. * @param {number} lower The lower bound.
  3523. * @param {number} upper The upper bound.
  3524. * @returns {number} Returns the random number.
  3525. */
  3526. function baseRandom(lower, upper) {
  3527. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3528. }
  3529. /**
  3530. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3531. * coerce arguments.
  3532. *
  3533. * @private
  3534. * @param {number} start The start of the range.
  3535. * @param {number} end The end of the range.
  3536. * @param {number} step The value to increment or decrement by.
  3537. * @param {boolean} [fromRight] Specify iterating from right to left.
  3538. * @returns {Array} Returns the range of numbers.
  3539. */
  3540. function baseRange(start, end, step, fromRight) {
  3541. var index = -1,
  3542. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3543. result = Array(length);
  3544. while (length--) {
  3545. result[fromRight ? length : ++index] = start;
  3546. start += step;
  3547. }
  3548. return result;
  3549. }
  3550. /**
  3551. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3552. *
  3553. * @private
  3554. * @param {string} string The string to repeat.
  3555. * @param {number} n The number of times to repeat the string.
  3556. * @returns {string} Returns the repeated string.
  3557. */
  3558. function baseRepeat(string, n) {
  3559. var result = '';
  3560. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3561. return result;
  3562. }
  3563. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3564. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3565. do {
  3566. if (n % 2) {
  3567. result += string;
  3568. }
  3569. n = nativeFloor(n / 2);
  3570. if (n) {
  3571. string += string;
  3572. }
  3573. } while (n);
  3574. return result;
  3575. }
  3576. /**
  3577. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3578. *
  3579. * @private
  3580. * @param {Function} func The function to apply a rest parameter to.
  3581. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3582. * @returns {Function} Returns the new function.
  3583. */
  3584. function baseRest(func, start) {
  3585. return setToString(overRest(func, start, identity), func + '');
  3586. }
  3587. /**
  3588. * The base implementation of `_.sample`.
  3589. *
  3590. * @private
  3591. * @param {Array|Object} collection The collection to sample.
  3592. * @returns {*} Returns the random element.
  3593. */
  3594. function baseSample(collection) {
  3595. return arraySample(values(collection));
  3596. }
  3597. /**
  3598. * The base implementation of `_.sampleSize` without param guards.
  3599. *
  3600. * @private
  3601. * @param {Array|Object} collection The collection to sample.
  3602. * @param {number} n The number of elements to sample.
  3603. * @returns {Array} Returns the random elements.
  3604. */
  3605. function baseSampleSize(collection, n) {
  3606. var array = values(collection);
  3607. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3608. }
  3609. /**
  3610. * The base implementation of `_.set`.
  3611. *
  3612. * @private
  3613. * @param {Object} object The object to modify.
  3614. * @param {Array|string} path The path of the property to set.
  3615. * @param {*} value The value to set.
  3616. * @param {Function} [customizer] The function to customize path creation.
  3617. * @returns {Object} Returns `object`.
  3618. */
  3619. function baseSet(object, path, value, customizer) {
  3620. if (!isObject(object)) {
  3621. return object;
  3622. }
  3623. path = castPath(path, object);
  3624. var index = -1,
  3625. length = path.length,
  3626. lastIndex = length - 1,
  3627. nested = object;
  3628. while (nested != null && ++index < length) {
  3629. var key = toKey(path[index]),
  3630. newValue = value;
  3631. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  3632. return object;
  3633. }
  3634. if (index != lastIndex) {
  3635. var objValue = nested[key];
  3636. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3637. if (newValue === undefined) {
  3638. newValue = isObject(objValue)
  3639. ? objValue
  3640. : (isIndex(path[index + 1]) ? [] : {});
  3641. }
  3642. }
  3643. assignValue(nested, key, newValue);
  3644. nested = nested[key];
  3645. }
  3646. return object;
  3647. }
  3648. /**
  3649. * The base implementation of `setData` without support for hot loop shorting.
  3650. *
  3651. * @private
  3652. * @param {Function} func The function to associate metadata with.
  3653. * @param {*} data The metadata.
  3654. * @returns {Function} Returns `func`.
  3655. */
  3656. var baseSetData = !metaMap ? identity : function(func, data) {
  3657. metaMap.set(func, data);
  3658. return func;
  3659. };
  3660. /**
  3661. * The base implementation of `setToString` without support for hot loop shorting.
  3662. *
  3663. * @private
  3664. * @param {Function} func The function to modify.
  3665. * @param {Function} string The `toString` result.
  3666. * @returns {Function} Returns `func`.
  3667. */
  3668. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3669. return defineProperty(func, 'toString', {
  3670. 'configurable': true,
  3671. 'enumerable': false,
  3672. 'value': constant(string),
  3673. 'writable': true
  3674. });
  3675. };
  3676. /**
  3677. * The base implementation of `_.shuffle`.
  3678. *
  3679. * @private
  3680. * @param {Array|Object} collection The collection to shuffle.
  3681. * @returns {Array} Returns the new shuffled array.
  3682. */
  3683. function baseShuffle(collection) {
  3684. return shuffleSelf(values(collection));
  3685. }
  3686. /**
  3687. * The base implementation of `_.slice` without an iteratee call guard.
  3688. *
  3689. * @private
  3690. * @param {Array} array The array to slice.
  3691. * @param {number} [start=0] The start position.
  3692. * @param {number} [end=array.length] The end position.
  3693. * @returns {Array} Returns the slice of `array`.
  3694. */
  3695. function baseSlice(array, start, end) {
  3696. var index = -1,
  3697. length = array.length;
  3698. if (start < 0) {
  3699. start = -start > length ? 0 : (length + start);
  3700. }
  3701. end = end > length ? length : end;
  3702. if (end < 0) {
  3703. end += length;
  3704. }
  3705. length = start > end ? 0 : ((end - start) >>> 0);
  3706. start >>>= 0;
  3707. var result = Array(length);
  3708. while (++index < length) {
  3709. result[index] = array[index + start];
  3710. }
  3711. return result;
  3712. }
  3713. /**
  3714. * The base implementation of `_.some` without support for iteratee shorthands.
  3715. *
  3716. * @private
  3717. * @param {Array|Object} collection The collection to iterate over.
  3718. * @param {Function} predicate The function invoked per iteration.
  3719. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3720. * else `false`.
  3721. */
  3722. function baseSome(collection, predicate) {
  3723. var result;
  3724. baseEach(collection, function(value, index, collection) {
  3725. result = predicate(value, index, collection);
  3726. return !result;
  3727. });
  3728. return !!result;
  3729. }
  3730. /**
  3731. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3732. * performs a binary search of `array` to determine the index at which `value`
  3733. * should be inserted into `array` in order to maintain its sort order.
  3734. *
  3735. * @private
  3736. * @param {Array} array The sorted array to inspect.
  3737. * @param {*} value The value to evaluate.
  3738. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3739. * @returns {number} Returns the index at which `value` should be inserted
  3740. * into `array`.
  3741. */
  3742. function baseSortedIndex(array, value, retHighest) {
  3743. var low = 0,
  3744. high = array == null ? low : array.length;
  3745. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3746. while (low < high) {
  3747. var mid = (low + high) >>> 1,
  3748. computed = array[mid];
  3749. if (computed !== null && !isSymbol(computed) &&
  3750. (retHighest ? (computed <= value) : (computed < value))) {
  3751. low = mid + 1;
  3752. } else {
  3753. high = mid;
  3754. }
  3755. }
  3756. return high;
  3757. }
  3758. return baseSortedIndexBy(array, value, identity, retHighest);
  3759. }
  3760. /**
  3761. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3762. * which invokes `iteratee` for `value` and each element of `array` to compute
  3763. * their sort ranking. The iteratee is invoked with one argument; (value).
  3764. *
  3765. * @private
  3766. * @param {Array} array The sorted array to inspect.
  3767. * @param {*} value The value to evaluate.
  3768. * @param {Function} iteratee The iteratee invoked per element.
  3769. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3770. * @returns {number} Returns the index at which `value` should be inserted
  3771. * into `array`.
  3772. */
  3773. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3774. var low = 0,
  3775. high = array == null ? 0 : array.length;
  3776. if (high === 0) {
  3777. return 0;
  3778. }
  3779. value = iteratee(value);
  3780. var valIsNaN = value !== value,
  3781. valIsNull = value === null,
  3782. valIsSymbol = isSymbol(value),
  3783. valIsUndefined = value === undefined;
  3784. while (low < high) {
  3785. var mid = nativeFloor((low + high) / 2),
  3786. computed = iteratee(array[mid]),
  3787. othIsDefined = computed !== undefined,
  3788. othIsNull = computed === null,
  3789. othIsReflexive = computed === computed,
  3790. othIsSymbol = isSymbol(computed);
  3791. if (valIsNaN) {
  3792. var setLow = retHighest || othIsReflexive;
  3793. } else if (valIsUndefined) {
  3794. setLow = othIsReflexive && (retHighest || othIsDefined);
  3795. } else if (valIsNull) {
  3796. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3797. } else if (valIsSymbol) {
  3798. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3799. } else if (othIsNull || othIsSymbol) {
  3800. setLow = false;
  3801. } else {
  3802. setLow = retHighest ? (computed <= value) : (computed < value);
  3803. }
  3804. if (setLow) {
  3805. low = mid + 1;
  3806. } else {
  3807. high = mid;
  3808. }
  3809. }
  3810. return nativeMin(high, MAX_ARRAY_INDEX);
  3811. }
  3812. /**
  3813. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3814. * support for iteratee shorthands.
  3815. *
  3816. * @private
  3817. * @param {Array} array The array to inspect.
  3818. * @param {Function} [iteratee] The iteratee invoked per element.
  3819. * @returns {Array} Returns the new duplicate free array.
  3820. */
  3821. function baseSortedUniq(array, iteratee) {
  3822. var index = -1,
  3823. length = array.length,
  3824. resIndex = 0,
  3825. result = [];
  3826. while (++index < length) {
  3827. var value = array[index],
  3828. computed = iteratee ? iteratee(value) : value;
  3829. if (!index || !eq(computed, seen)) {
  3830. var seen = computed;
  3831. result[resIndex++] = value === 0 ? 0 : value;
  3832. }
  3833. }
  3834. return result;
  3835. }
  3836. /**
  3837. * The base implementation of `_.toNumber` which doesn't ensure correct
  3838. * conversions of binary, hexadecimal, or octal string values.
  3839. *
  3840. * @private
  3841. * @param {*} value The value to process.
  3842. * @returns {number} Returns the number.
  3843. */
  3844. function baseToNumber(value) {
  3845. if (typeof value == 'number') {
  3846. return value;
  3847. }
  3848. if (isSymbol(value)) {
  3849. return NAN;
  3850. }
  3851. return +value;
  3852. }
  3853. /**
  3854. * The base implementation of `_.toString` which doesn't convert nullish
  3855. * values to empty strings.
  3856. *
  3857. * @private
  3858. * @param {*} value The value to process.
  3859. * @returns {string} Returns the string.
  3860. */
  3861. function baseToString(value) {
  3862. // Exit early for strings to avoid a performance hit in some environments.
  3863. if (typeof value == 'string') {
  3864. return value;
  3865. }
  3866. if (isArray(value)) {
  3867. // Recursively convert values (susceptible to call stack limits).
  3868. return arrayMap(value, baseToString) + '';
  3869. }
  3870. if (isSymbol(value)) {
  3871. return symbolToString ? symbolToString.call(value) : '';
  3872. }
  3873. var result = (value + '');
  3874. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3875. }
  3876. /**
  3877. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3878. *
  3879. * @private
  3880. * @param {Array} array The array to inspect.
  3881. * @param {Function} [iteratee] The iteratee invoked per element.
  3882. * @param {Function} [comparator] The comparator invoked per element.
  3883. * @returns {Array} Returns the new duplicate free array.
  3884. */
  3885. function baseUniq(array, iteratee, comparator) {
  3886. var index = -1,
  3887. includes = arrayIncludes,
  3888. length = array.length,
  3889. isCommon = true,
  3890. result = [],
  3891. seen = result;
  3892. if (comparator) {
  3893. isCommon = false;
  3894. includes = arrayIncludesWith;
  3895. }
  3896. else if (length >= LARGE_ARRAY_SIZE) {
  3897. var set = iteratee ? null : createSet(array);
  3898. if (set) {
  3899. return setToArray(set);
  3900. }
  3901. isCommon = false;
  3902. includes = cacheHas;
  3903. seen = new SetCache;
  3904. }
  3905. else {
  3906. seen = iteratee ? [] : result;
  3907. }
  3908. outer:
  3909. while (++index < length) {
  3910. var value = array[index],
  3911. computed = iteratee ? iteratee(value) : value;
  3912. value = (comparator || value !== 0) ? value : 0;
  3913. if (isCommon && computed === computed) {
  3914. var seenIndex = seen.length;
  3915. while (seenIndex--) {
  3916. if (seen[seenIndex] === computed) {
  3917. continue outer;
  3918. }
  3919. }
  3920. if (iteratee) {
  3921. seen.push(computed);
  3922. }
  3923. result.push(value);
  3924. }
  3925. else if (!includes(seen, computed, comparator)) {
  3926. if (seen !== result) {
  3927. seen.push(computed);
  3928. }
  3929. result.push(value);
  3930. }
  3931. }
  3932. return result;
  3933. }
  3934. /**
  3935. * The base implementation of `_.unset`.
  3936. *
  3937. * @private
  3938. * @param {Object} object The object to modify.
  3939. * @param {Array|string} path The property path to unset.
  3940. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3941. */
  3942. function baseUnset(object, path) {
  3943. path = castPath(path, object);
  3944. object = parent(object, path);
  3945. return object == null || delete object[toKey(last(path))];
  3946. }
  3947. /**
  3948. * The base implementation of `_.update`.
  3949. *
  3950. * @private
  3951. * @param {Object} object The object to modify.
  3952. * @param {Array|string} path The path of the property to update.
  3953. * @param {Function} updater The function to produce the updated value.
  3954. * @param {Function} [customizer] The function to customize path creation.
  3955. * @returns {Object} Returns `object`.
  3956. */
  3957. function baseUpdate(object, path, updater, customizer) {
  3958. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3959. }
  3960. /**
  3961. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3962. * without support for iteratee shorthands.
  3963. *
  3964. * @private
  3965. * @param {Array} array The array to query.
  3966. * @param {Function} predicate The function invoked per iteration.
  3967. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3968. * @param {boolean} [fromRight] Specify iterating from right to left.
  3969. * @returns {Array} Returns the slice of `array`.
  3970. */
  3971. function baseWhile(array, predicate, isDrop, fromRight) {
  3972. var length = array.length,
  3973. index = fromRight ? length : -1;
  3974. while ((fromRight ? index-- : ++index < length) &&
  3975. predicate(array[index], index, array)) {}
  3976. return isDrop
  3977. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3978. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3979. }
  3980. /**
  3981. * The base implementation of `wrapperValue` which returns the result of
  3982. * performing a sequence of actions on the unwrapped `value`, where each
  3983. * successive action is supplied the return value of the previous.
  3984. *
  3985. * @private
  3986. * @param {*} value The unwrapped value.
  3987. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3988. * @returns {*} Returns the resolved value.
  3989. */
  3990. function baseWrapperValue(value, actions) {
  3991. var result = value;
  3992. if (result instanceof LazyWrapper) {
  3993. result = result.value();
  3994. }
  3995. return arrayReduce(actions, function(result, action) {
  3996. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3997. }, result);
  3998. }
  3999. /**
  4000. * The base implementation of methods like `_.xor`, without support for
  4001. * iteratee shorthands, that accepts an array of arrays to inspect.
  4002. *
  4003. * @private
  4004. * @param {Array} arrays The arrays to inspect.
  4005. * @param {Function} [iteratee] The iteratee invoked per element.
  4006. * @param {Function} [comparator] The comparator invoked per element.
  4007. * @returns {Array} Returns the new array of values.
  4008. */
  4009. function baseXor(arrays, iteratee, comparator) {
  4010. var length = arrays.length;
  4011. if (length < 2) {
  4012. return length ? baseUniq(arrays[0]) : [];
  4013. }
  4014. var index = -1,
  4015. result = Array(length);
  4016. while (++index < length) {
  4017. var array = arrays[index],
  4018. othIndex = -1;
  4019. while (++othIndex < length) {
  4020. if (othIndex != index) {
  4021. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4022. }
  4023. }
  4024. }
  4025. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4026. }
  4027. /**
  4028. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4029. *
  4030. * @private
  4031. * @param {Array} props The property identifiers.
  4032. * @param {Array} values The property values.
  4033. * @param {Function} assignFunc The function to assign values.
  4034. * @returns {Object} Returns the new object.
  4035. */
  4036. function baseZipObject(props, values, assignFunc) {
  4037. var index = -1,
  4038. length = props.length,
  4039. valsLength = values.length,
  4040. result = {};
  4041. while (++index < length) {
  4042. var value = index < valsLength ? values[index] : undefined;
  4043. assignFunc(result, props[index], value);
  4044. }
  4045. return result;
  4046. }
  4047. /**
  4048. * Casts `value` to an empty array if it's not an array like object.
  4049. *
  4050. * @private
  4051. * @param {*} value The value to inspect.
  4052. * @returns {Array|Object} Returns the cast array-like object.
  4053. */
  4054. function castArrayLikeObject(value) {
  4055. return isArrayLikeObject(value) ? value : [];
  4056. }
  4057. /**
  4058. * Casts `value` to `identity` if it's not a function.
  4059. *
  4060. * @private
  4061. * @param {*} value The value to inspect.
  4062. * @returns {Function} Returns cast function.
  4063. */
  4064. function castFunction(value) {
  4065. return typeof value == 'function' ? value : identity;
  4066. }
  4067. /**
  4068. * Casts `value` to a path array if it's not one.
  4069. *
  4070. * @private
  4071. * @param {*} value The value to inspect.
  4072. * @param {Object} [object] The object to query keys on.
  4073. * @returns {Array} Returns the cast property path array.
  4074. */
  4075. function castPath(value, object) {
  4076. if (isArray(value)) {
  4077. return value;
  4078. }
  4079. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4080. }
  4081. /**
  4082. * A `baseRest` alias which can be replaced with `identity` by module
  4083. * replacement plugins.
  4084. *
  4085. * @private
  4086. * @type {Function}
  4087. * @param {Function} func The function to apply a rest parameter to.
  4088. * @returns {Function} Returns the new function.
  4089. */
  4090. var castRest = baseRest;
  4091. /**
  4092. * Casts `array` to a slice if it's needed.
  4093. *
  4094. * @private
  4095. * @param {Array} array The array to inspect.
  4096. * @param {number} start The start position.
  4097. * @param {number} [end=array.length] The end position.
  4098. * @returns {Array} Returns the cast slice.
  4099. */
  4100. function castSlice(array, start, end) {
  4101. var length = array.length;
  4102. end = end === undefined ? length : end;
  4103. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4104. }
  4105. /**
  4106. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4107. *
  4108. * @private
  4109. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4110. */
  4111. var clearTimeout = ctxClearTimeout || function(id) {
  4112. return root.clearTimeout(id);
  4113. };
  4114. /**
  4115. * Creates a clone of `buffer`.
  4116. *
  4117. * @private
  4118. * @param {Buffer} buffer The buffer to clone.
  4119. * @param {boolean} [isDeep] Specify a deep clone.
  4120. * @returns {Buffer} Returns the cloned buffer.
  4121. */
  4122. function cloneBuffer(buffer, isDeep) {
  4123. if (isDeep) {
  4124. return buffer.slice();
  4125. }
  4126. var length = buffer.length,
  4127. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4128. buffer.copy(result);
  4129. return result;
  4130. }
  4131. /**
  4132. * Creates a clone of `arrayBuffer`.
  4133. *
  4134. * @private
  4135. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4136. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4137. */
  4138. function cloneArrayBuffer(arrayBuffer) {
  4139. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4140. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4141. return result;
  4142. }
  4143. /**
  4144. * Creates a clone of `dataView`.
  4145. *
  4146. * @private
  4147. * @param {Object} dataView The data view to clone.
  4148. * @param {boolean} [isDeep] Specify a deep clone.
  4149. * @returns {Object} Returns the cloned data view.
  4150. */
  4151. function cloneDataView(dataView, isDeep) {
  4152. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4153. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4154. }
  4155. /**
  4156. * Creates a clone of `regexp`.
  4157. *
  4158. * @private
  4159. * @param {Object} regexp The regexp to clone.
  4160. * @returns {Object} Returns the cloned regexp.
  4161. */
  4162. function cloneRegExp(regexp) {
  4163. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4164. result.lastIndex = regexp.lastIndex;
  4165. return result;
  4166. }
  4167. /**
  4168. * Creates a clone of the `symbol` object.
  4169. *
  4170. * @private
  4171. * @param {Object} symbol The symbol object to clone.
  4172. * @returns {Object} Returns the cloned symbol object.
  4173. */
  4174. function cloneSymbol(symbol) {
  4175. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4176. }
  4177. /**
  4178. * Creates a clone of `typedArray`.
  4179. *
  4180. * @private
  4181. * @param {Object} typedArray The typed array to clone.
  4182. * @param {boolean} [isDeep] Specify a deep clone.
  4183. * @returns {Object} Returns the cloned typed array.
  4184. */
  4185. function cloneTypedArray(typedArray, isDeep) {
  4186. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4187. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4188. }
  4189. /**
  4190. * Compares values to sort them in ascending order.
  4191. *
  4192. * @private
  4193. * @param {*} value The value to compare.
  4194. * @param {*} other The other value to compare.
  4195. * @returns {number} Returns the sort order indicator for `value`.
  4196. */
  4197. function compareAscending(value, other) {
  4198. if (value !== other) {
  4199. var valIsDefined = value !== undefined,
  4200. valIsNull = value === null,
  4201. valIsReflexive = value === value,
  4202. valIsSymbol = isSymbol(value);
  4203. var othIsDefined = other !== undefined,
  4204. othIsNull = other === null,
  4205. othIsReflexive = other === other,
  4206. othIsSymbol = isSymbol(other);
  4207. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4208. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4209. (valIsNull && othIsDefined && othIsReflexive) ||
  4210. (!valIsDefined && othIsReflexive) ||
  4211. !valIsReflexive) {
  4212. return 1;
  4213. }
  4214. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4215. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4216. (othIsNull && valIsDefined && valIsReflexive) ||
  4217. (!othIsDefined && valIsReflexive) ||
  4218. !othIsReflexive) {
  4219. return -1;
  4220. }
  4221. }
  4222. return 0;
  4223. }
  4224. /**
  4225. * Used by `_.orderBy` to compare multiple properties of a value to another
  4226. * and stable sort them.
  4227. *
  4228. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4229. * specify an order of "desc" for descending or "asc" for ascending sort order
  4230. * of corresponding values.
  4231. *
  4232. * @private
  4233. * @param {Object} object The object to compare.
  4234. * @param {Object} other The other object to compare.
  4235. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4236. * @returns {number} Returns the sort order indicator for `object`.
  4237. */
  4238. function compareMultiple(object, other, orders) {
  4239. var index = -1,
  4240. objCriteria = object.criteria,
  4241. othCriteria = other.criteria,
  4242. length = objCriteria.length,
  4243. ordersLength = orders.length;
  4244. while (++index < length) {
  4245. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4246. if (result) {
  4247. if (index >= ordersLength) {
  4248. return result;
  4249. }
  4250. var order = orders[index];
  4251. return result * (order == 'desc' ? -1 : 1);
  4252. }
  4253. }
  4254. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4255. // that causes it, under certain circumstances, to provide the same value for
  4256. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4257. // for more details.
  4258. //
  4259. // This also ensures a stable sort in V8 and other engines.
  4260. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4261. return object.index - other.index;
  4262. }
  4263. /**
  4264. * Creates an array that is the composition of partially applied arguments,
  4265. * placeholders, and provided arguments into a single array of arguments.
  4266. *
  4267. * @private
  4268. * @param {Array} args The provided arguments.
  4269. * @param {Array} partials The arguments to prepend to those provided.
  4270. * @param {Array} holders The `partials` placeholder indexes.
  4271. * @params {boolean} [isCurried] Specify composing for a curried function.
  4272. * @returns {Array} Returns the new array of composed arguments.
  4273. */
  4274. function composeArgs(args, partials, holders, isCurried) {
  4275. var argsIndex = -1,
  4276. argsLength = args.length,
  4277. holdersLength = holders.length,
  4278. leftIndex = -1,
  4279. leftLength = partials.length,
  4280. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4281. result = Array(leftLength + rangeLength),
  4282. isUncurried = !isCurried;
  4283. while (++leftIndex < leftLength) {
  4284. result[leftIndex] = partials[leftIndex];
  4285. }
  4286. while (++argsIndex < holdersLength) {
  4287. if (isUncurried || argsIndex < argsLength) {
  4288. result[holders[argsIndex]] = args[argsIndex];
  4289. }
  4290. }
  4291. while (rangeLength--) {
  4292. result[leftIndex++] = args[argsIndex++];
  4293. }
  4294. return result;
  4295. }
  4296. /**
  4297. * This function is like `composeArgs` except that the arguments composition
  4298. * is tailored for `_.partialRight`.
  4299. *
  4300. * @private
  4301. * @param {Array} args The provided arguments.
  4302. * @param {Array} partials The arguments to append to those provided.
  4303. * @param {Array} holders The `partials` placeholder indexes.
  4304. * @params {boolean} [isCurried] Specify composing for a curried function.
  4305. * @returns {Array} Returns the new array of composed arguments.
  4306. */
  4307. function composeArgsRight(args, partials, holders, isCurried) {
  4308. var argsIndex = -1,
  4309. argsLength = args.length,
  4310. holdersIndex = -1,
  4311. holdersLength = holders.length,
  4312. rightIndex = -1,
  4313. rightLength = partials.length,
  4314. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4315. result = Array(rangeLength + rightLength),
  4316. isUncurried = !isCurried;
  4317. while (++argsIndex < rangeLength) {
  4318. result[argsIndex] = args[argsIndex];
  4319. }
  4320. var offset = argsIndex;
  4321. while (++rightIndex < rightLength) {
  4322. result[offset + rightIndex] = partials[rightIndex];
  4323. }
  4324. while (++holdersIndex < holdersLength) {
  4325. if (isUncurried || argsIndex < argsLength) {
  4326. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4327. }
  4328. }
  4329. return result;
  4330. }
  4331. /**
  4332. * Copies the values of `source` to `array`.
  4333. *
  4334. * @private
  4335. * @param {Array} source The array to copy values from.
  4336. * @param {Array} [array=[]] The array to copy values to.
  4337. * @returns {Array} Returns `array`.
  4338. */
  4339. function copyArray(source, array) {
  4340. var index = -1,
  4341. length = source.length;
  4342. array || (array = Array(length));
  4343. while (++index < length) {
  4344. array[index] = source[index];
  4345. }
  4346. return array;
  4347. }
  4348. /**
  4349. * Copies properties of `source` to `object`.
  4350. *
  4351. * @private
  4352. * @param {Object} source The object to copy properties from.
  4353. * @param {Array} props The property identifiers to copy.
  4354. * @param {Object} [object={}] The object to copy properties to.
  4355. * @param {Function} [customizer] The function to customize copied values.
  4356. * @returns {Object} Returns `object`.
  4357. */
  4358. function copyObject(source, props, object, customizer) {
  4359. var isNew = !object;
  4360. object || (object = {});
  4361. var index = -1,
  4362. length = props.length;
  4363. while (++index < length) {
  4364. var key = props[index];
  4365. var newValue = customizer
  4366. ? customizer(object[key], source[key], key, object, source)
  4367. : undefined;
  4368. if (newValue === undefined) {
  4369. newValue = source[key];
  4370. }
  4371. if (isNew) {
  4372. baseAssignValue(object, key, newValue);
  4373. } else {
  4374. assignValue(object, key, newValue);
  4375. }
  4376. }
  4377. return object;
  4378. }
  4379. /**
  4380. * Copies own symbols of `source` to `object`.
  4381. *
  4382. * @private
  4383. * @param {Object} source The object to copy symbols from.
  4384. * @param {Object} [object={}] The object to copy symbols to.
  4385. * @returns {Object} Returns `object`.
  4386. */
  4387. function copySymbols(source, object) {
  4388. return copyObject(source, getSymbols(source), object);
  4389. }
  4390. /**
  4391. * Copies own and inherited symbols of `source` to `object`.
  4392. *
  4393. * @private
  4394. * @param {Object} source The object to copy symbols from.
  4395. * @param {Object} [object={}] The object to copy symbols to.
  4396. * @returns {Object} Returns `object`.
  4397. */
  4398. function copySymbolsIn(source, object) {
  4399. return copyObject(source, getSymbolsIn(source), object);
  4400. }
  4401. /**
  4402. * Creates a function like `_.groupBy`.
  4403. *
  4404. * @private
  4405. * @param {Function} setter The function to set accumulator values.
  4406. * @param {Function} [initializer] The accumulator object initializer.
  4407. * @returns {Function} Returns the new aggregator function.
  4408. */
  4409. function createAggregator(setter, initializer) {
  4410. return function(collection, iteratee) {
  4411. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4412. accumulator = initializer ? initializer() : {};
  4413. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4414. };
  4415. }
  4416. /**
  4417. * Creates a function like `_.assign`.
  4418. *
  4419. * @private
  4420. * @param {Function} assigner The function to assign values.
  4421. * @returns {Function} Returns the new assigner function.
  4422. */
  4423. function createAssigner(assigner) {
  4424. return baseRest(function(object, sources) {
  4425. var index = -1,
  4426. length = sources.length,
  4427. customizer = length > 1 ? sources[length - 1] : undefined,
  4428. guard = length > 2 ? sources[2] : undefined;
  4429. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4430. ? (length--, customizer)
  4431. : undefined;
  4432. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4433. customizer = length < 3 ? undefined : customizer;
  4434. length = 1;
  4435. }
  4436. object = Object(object);
  4437. while (++index < length) {
  4438. var source = sources[index];
  4439. if (source) {
  4440. assigner(object, source, index, customizer);
  4441. }
  4442. }
  4443. return object;
  4444. });
  4445. }
  4446. /**
  4447. * Creates a `baseEach` or `baseEachRight` function.
  4448. *
  4449. * @private
  4450. * @param {Function} eachFunc The function to iterate over a collection.
  4451. * @param {boolean} [fromRight] Specify iterating from right to left.
  4452. * @returns {Function} Returns the new base function.
  4453. */
  4454. function createBaseEach(eachFunc, fromRight) {
  4455. return function(collection, iteratee) {
  4456. if (collection == null) {
  4457. return collection;
  4458. }
  4459. if (!isArrayLike(collection)) {
  4460. return eachFunc(collection, iteratee);
  4461. }
  4462. var length = collection.length,
  4463. index = fromRight ? length : -1,
  4464. iterable = Object(collection);
  4465. while ((fromRight ? index-- : ++index < length)) {
  4466. if (iteratee(iterable[index], index, iterable) === false) {
  4467. break;
  4468. }
  4469. }
  4470. return collection;
  4471. };
  4472. }
  4473. /**
  4474. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4475. *
  4476. * @private
  4477. * @param {boolean} [fromRight] Specify iterating from right to left.
  4478. * @returns {Function} Returns the new base function.
  4479. */
  4480. function createBaseFor(fromRight) {
  4481. return function(object, iteratee, keysFunc) {
  4482. var index = -1,
  4483. iterable = Object(object),
  4484. props = keysFunc(object),
  4485. length = props.length;
  4486. while (length--) {
  4487. var key = props[fromRight ? length : ++index];
  4488. if (iteratee(iterable[key], key, iterable) === false) {
  4489. break;
  4490. }
  4491. }
  4492. return object;
  4493. };
  4494. }
  4495. /**
  4496. * Creates a function that wraps `func` to invoke it with the optional `this`
  4497. * binding of `thisArg`.
  4498. *
  4499. * @private
  4500. * @param {Function} func The function to wrap.
  4501. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4502. * @param {*} [thisArg] The `this` binding of `func`.
  4503. * @returns {Function} Returns the new wrapped function.
  4504. */
  4505. function createBind(func, bitmask, thisArg) {
  4506. var isBind = bitmask & WRAP_BIND_FLAG,
  4507. Ctor = createCtor(func);
  4508. function wrapper() {
  4509. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4510. return fn.apply(isBind ? thisArg : this, arguments);
  4511. }
  4512. return wrapper;
  4513. }
  4514. /**
  4515. * Creates a function like `_.lowerFirst`.
  4516. *
  4517. * @private
  4518. * @param {string} methodName The name of the `String` case method to use.
  4519. * @returns {Function} Returns the new case function.
  4520. */
  4521. function createCaseFirst(methodName) {
  4522. return function(string) {
  4523. string = toString(string);
  4524. var strSymbols = hasUnicode(string)
  4525. ? stringToArray(string)
  4526. : undefined;
  4527. var chr = strSymbols
  4528. ? strSymbols[0]
  4529. : string.charAt(0);
  4530. var trailing = strSymbols
  4531. ? castSlice(strSymbols, 1).join('')
  4532. : string.slice(1);
  4533. return chr[methodName]() + trailing;
  4534. };
  4535. }
  4536. /**
  4537. * Creates a function like `_.camelCase`.
  4538. *
  4539. * @private
  4540. * @param {Function} callback The function to combine each word.
  4541. * @returns {Function} Returns the new compounder function.
  4542. */
  4543. function createCompounder(callback) {
  4544. return function(string) {
  4545. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4546. };
  4547. }
  4548. /**
  4549. * Creates a function that produces an instance of `Ctor` regardless of
  4550. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4551. *
  4552. * @private
  4553. * @param {Function} Ctor The constructor to wrap.
  4554. * @returns {Function} Returns the new wrapped function.
  4555. */
  4556. function createCtor(Ctor) {
  4557. return function() {
  4558. // Use a `switch` statement to work with class constructors. See
  4559. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4560. // for more details.
  4561. var args = arguments;
  4562. switch (args.length) {
  4563. case 0: return new Ctor;
  4564. case 1: return new Ctor(args[0]);
  4565. case 2: return new Ctor(args[0], args[1]);
  4566. case 3: return new Ctor(args[0], args[1], args[2]);
  4567. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4568. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4569. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4570. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4571. }
  4572. var thisBinding = baseCreate(Ctor.prototype),
  4573. result = Ctor.apply(thisBinding, args);
  4574. // Mimic the constructor's `return` behavior.
  4575. // See https://es5.github.io/#x13.2.2 for more details.
  4576. return isObject(result) ? result : thisBinding;
  4577. };
  4578. }
  4579. /**
  4580. * Creates a function that wraps `func` to enable currying.
  4581. *
  4582. * @private
  4583. * @param {Function} func The function to wrap.
  4584. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4585. * @param {number} arity The arity of `func`.
  4586. * @returns {Function} Returns the new wrapped function.
  4587. */
  4588. function createCurry(func, bitmask, arity) {
  4589. var Ctor = createCtor(func);
  4590. function wrapper() {
  4591. var length = arguments.length,
  4592. args = Array(length),
  4593. index = length,
  4594. placeholder = getHolder(wrapper);
  4595. while (index--) {
  4596. args[index] = arguments[index];
  4597. }
  4598. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4599. ? []
  4600. : replaceHolders(args, placeholder);
  4601. length -= holders.length;
  4602. if (length < arity) {
  4603. return createRecurry(
  4604. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4605. args, holders, undefined, undefined, arity - length);
  4606. }
  4607. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4608. return apply(fn, this, args);
  4609. }
  4610. return wrapper;
  4611. }
  4612. /**
  4613. * Creates a `_.find` or `_.findLast` function.
  4614. *
  4615. * @private
  4616. * @param {Function} findIndexFunc The function to find the collection index.
  4617. * @returns {Function} Returns the new find function.
  4618. */
  4619. function createFind(findIndexFunc) {
  4620. return function(collection, predicate, fromIndex) {
  4621. var iterable = Object(collection);
  4622. if (!isArrayLike(collection)) {
  4623. var iteratee = getIteratee(predicate, 3);
  4624. collection = keys(collection);
  4625. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4626. }
  4627. var index = findIndexFunc(collection, predicate, fromIndex);
  4628. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4629. };
  4630. }
  4631. /**
  4632. * Creates a `_.flow` or `_.flowRight` function.
  4633. *
  4634. * @private
  4635. * @param {boolean} [fromRight] Specify iterating from right to left.
  4636. * @returns {Function} Returns the new flow function.
  4637. */
  4638. function createFlow(fromRight) {
  4639. return flatRest(function(funcs) {
  4640. var length = funcs.length,
  4641. index = length,
  4642. prereq = LodashWrapper.prototype.thru;
  4643. if (fromRight) {
  4644. funcs.reverse();
  4645. }
  4646. while (index--) {
  4647. var func = funcs[index];
  4648. if (typeof func != 'function') {
  4649. throw new TypeError(FUNC_ERROR_TEXT);
  4650. }
  4651. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4652. var wrapper = new LodashWrapper([], true);
  4653. }
  4654. }
  4655. index = wrapper ? index : length;
  4656. while (++index < length) {
  4657. func = funcs[index];
  4658. var funcName = getFuncName(func),
  4659. data = funcName == 'wrapper' ? getData(func) : undefined;
  4660. if (data && isLaziable(data[0]) &&
  4661. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4662. !data[4].length && data[9] == 1
  4663. ) {
  4664. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4665. } else {
  4666. wrapper = (func.length == 1 && isLaziable(func))
  4667. ? wrapper[funcName]()
  4668. : wrapper.thru(func);
  4669. }
  4670. }
  4671. return function() {
  4672. var args = arguments,
  4673. value = args[0];
  4674. if (wrapper && args.length == 1 && isArray(value)) {
  4675. return wrapper.plant(value).value();
  4676. }
  4677. var index = 0,
  4678. result = length ? funcs[index].apply(this, args) : value;
  4679. while (++index < length) {
  4680. result = funcs[index].call(this, result);
  4681. }
  4682. return result;
  4683. };
  4684. });
  4685. }
  4686. /**
  4687. * Creates a function that wraps `func` to invoke it with optional `this`
  4688. * binding of `thisArg`, partial application, and currying.
  4689. *
  4690. * @private
  4691. * @param {Function|string} func The function or method name to wrap.
  4692. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4693. * @param {*} [thisArg] The `this` binding of `func`.
  4694. * @param {Array} [partials] The arguments to prepend to those provided to
  4695. * the new function.
  4696. * @param {Array} [holders] The `partials` placeholder indexes.
  4697. * @param {Array} [partialsRight] The arguments to append to those provided
  4698. * to the new function.
  4699. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4700. * @param {Array} [argPos] The argument positions of the new function.
  4701. * @param {number} [ary] The arity cap of `func`.
  4702. * @param {number} [arity] The arity of `func`.
  4703. * @returns {Function} Returns the new wrapped function.
  4704. */
  4705. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4706. var isAry = bitmask & WRAP_ARY_FLAG,
  4707. isBind = bitmask & WRAP_BIND_FLAG,
  4708. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4709. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4710. isFlip = bitmask & WRAP_FLIP_FLAG,
  4711. Ctor = isBindKey ? undefined : createCtor(func);
  4712. function wrapper() {
  4713. var length = arguments.length,
  4714. args = Array(length),
  4715. index = length;
  4716. while (index--) {
  4717. args[index] = arguments[index];
  4718. }
  4719. if (isCurried) {
  4720. var placeholder = getHolder(wrapper),
  4721. holdersCount = countHolders(args, placeholder);
  4722. }
  4723. if (partials) {
  4724. args = composeArgs(args, partials, holders, isCurried);
  4725. }
  4726. if (partialsRight) {
  4727. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4728. }
  4729. length -= holdersCount;
  4730. if (isCurried && length < arity) {
  4731. var newHolders = replaceHolders(args, placeholder);
  4732. return createRecurry(
  4733. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4734. args, newHolders, argPos, ary, arity - length
  4735. );
  4736. }
  4737. var thisBinding = isBind ? thisArg : this,
  4738. fn = isBindKey ? thisBinding[func] : func;
  4739. length = args.length;
  4740. if (argPos) {
  4741. args = reorder(args, argPos);
  4742. } else if (isFlip && length > 1) {
  4743. args.reverse();
  4744. }
  4745. if (isAry && ary < length) {
  4746. args.length = ary;
  4747. }
  4748. if (this && this !== root && this instanceof wrapper) {
  4749. fn = Ctor || createCtor(fn);
  4750. }
  4751. return fn.apply(thisBinding, args);
  4752. }
  4753. return wrapper;
  4754. }
  4755. /**
  4756. * Creates a function like `_.invertBy`.
  4757. *
  4758. * @private
  4759. * @param {Function} setter The function to set accumulator values.
  4760. * @param {Function} toIteratee The function to resolve iteratees.
  4761. * @returns {Function} Returns the new inverter function.
  4762. */
  4763. function createInverter(setter, toIteratee) {
  4764. return function(object, iteratee) {
  4765. return baseInverter(object, setter, toIteratee(iteratee), {});
  4766. };
  4767. }
  4768. /**
  4769. * Creates a function that performs a mathematical operation on two values.
  4770. *
  4771. * @private
  4772. * @param {Function} operator The function to perform the operation.
  4773. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4774. * @returns {Function} Returns the new mathematical operation function.
  4775. */
  4776. function createMathOperation(operator, defaultValue) {
  4777. return function(value, other) {
  4778. var result;
  4779. if (value === undefined && other === undefined) {
  4780. return defaultValue;
  4781. }
  4782. if (value !== undefined) {
  4783. result = value;
  4784. }
  4785. if (other !== undefined) {
  4786. if (result === undefined) {
  4787. return other;
  4788. }
  4789. if (typeof value == 'string' || typeof other == 'string') {
  4790. value = baseToString(value);
  4791. other = baseToString(other);
  4792. } else {
  4793. value = baseToNumber(value);
  4794. other = baseToNumber(other);
  4795. }
  4796. result = operator(value, other);
  4797. }
  4798. return result;
  4799. };
  4800. }
  4801. /**
  4802. * Creates a function like `_.over`.
  4803. *
  4804. * @private
  4805. * @param {Function} arrayFunc The function to iterate over iteratees.
  4806. * @returns {Function} Returns the new over function.
  4807. */
  4808. function createOver(arrayFunc) {
  4809. return flatRest(function(iteratees) {
  4810. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4811. return baseRest(function(args) {
  4812. var thisArg = this;
  4813. return arrayFunc(iteratees, function(iteratee) {
  4814. return apply(iteratee, thisArg, args);
  4815. });
  4816. });
  4817. });
  4818. }
  4819. /**
  4820. * Creates the padding for `string` based on `length`. The `chars` string
  4821. * is truncated if the number of characters exceeds `length`.
  4822. *
  4823. * @private
  4824. * @param {number} length The padding length.
  4825. * @param {string} [chars=' '] The string used as padding.
  4826. * @returns {string} Returns the padding for `string`.
  4827. */
  4828. function createPadding(length, chars) {
  4829. chars = chars === undefined ? ' ' : baseToString(chars);
  4830. var charsLength = chars.length;
  4831. if (charsLength < 2) {
  4832. return charsLength ? baseRepeat(chars, length) : chars;
  4833. }
  4834. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4835. return hasUnicode(chars)
  4836. ? castSlice(stringToArray(result), 0, length).join('')
  4837. : result.slice(0, length);
  4838. }
  4839. /**
  4840. * Creates a function that wraps `func` to invoke it with the `this` binding
  4841. * of `thisArg` and `partials` prepended to the arguments it receives.
  4842. *
  4843. * @private
  4844. * @param {Function} func The function to wrap.
  4845. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4846. * @param {*} thisArg The `this` binding of `func`.
  4847. * @param {Array} partials The arguments to prepend to those provided to
  4848. * the new function.
  4849. * @returns {Function} Returns the new wrapped function.
  4850. */
  4851. function createPartial(func, bitmask, thisArg, partials) {
  4852. var isBind = bitmask & WRAP_BIND_FLAG,
  4853. Ctor = createCtor(func);
  4854. function wrapper() {
  4855. var argsIndex = -1,
  4856. argsLength = arguments.length,
  4857. leftIndex = -1,
  4858. leftLength = partials.length,
  4859. args = Array(leftLength + argsLength),
  4860. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4861. while (++leftIndex < leftLength) {
  4862. args[leftIndex] = partials[leftIndex];
  4863. }
  4864. while (argsLength--) {
  4865. args[leftIndex++] = arguments[++argsIndex];
  4866. }
  4867. return apply(fn, isBind ? thisArg : this, args);
  4868. }
  4869. return wrapper;
  4870. }
  4871. /**
  4872. * Creates a `_.range` or `_.rangeRight` function.
  4873. *
  4874. * @private
  4875. * @param {boolean} [fromRight] Specify iterating from right to left.
  4876. * @returns {Function} Returns the new range function.
  4877. */
  4878. function createRange(fromRight) {
  4879. return function(start, end, step) {
  4880. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4881. end = step = undefined;
  4882. }
  4883. // Ensure the sign of `-0` is preserved.
  4884. start = toFinite(start);
  4885. if (end === undefined) {
  4886. end = start;
  4887. start = 0;
  4888. } else {
  4889. end = toFinite(end);
  4890. }
  4891. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4892. return baseRange(start, end, step, fromRight);
  4893. };
  4894. }
  4895. /**
  4896. * Creates a function that performs a relational operation on two values.
  4897. *
  4898. * @private
  4899. * @param {Function} operator The function to perform the operation.
  4900. * @returns {Function} Returns the new relational operation function.
  4901. */
  4902. function createRelationalOperation(operator) {
  4903. return function(value, other) {
  4904. if (!(typeof value == 'string' && typeof other == 'string')) {
  4905. value = toNumber(value);
  4906. other = toNumber(other);
  4907. }
  4908. return operator(value, other);
  4909. };
  4910. }
  4911. /**
  4912. * Creates a function that wraps `func` to continue currying.
  4913. *
  4914. * @private
  4915. * @param {Function} func The function to wrap.
  4916. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4917. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4918. * @param {*} placeholder The placeholder value.
  4919. * @param {*} [thisArg] The `this` binding of `func`.
  4920. * @param {Array} [partials] The arguments to prepend to those provided to
  4921. * the new function.
  4922. * @param {Array} [holders] The `partials` placeholder indexes.
  4923. * @param {Array} [argPos] The argument positions of the new function.
  4924. * @param {number} [ary] The arity cap of `func`.
  4925. * @param {number} [arity] The arity of `func`.
  4926. * @returns {Function} Returns the new wrapped function.
  4927. */
  4928. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4929. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4930. newHolders = isCurry ? holders : undefined,
  4931. newHoldersRight = isCurry ? undefined : holders,
  4932. newPartials = isCurry ? partials : undefined,
  4933. newPartialsRight = isCurry ? undefined : partials;
  4934. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4935. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4936. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4937. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4938. }
  4939. var newData = [
  4940. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4941. newHoldersRight, argPos, ary, arity
  4942. ];
  4943. var result = wrapFunc.apply(undefined, newData);
  4944. if (isLaziable(func)) {
  4945. setData(result, newData);
  4946. }
  4947. result.placeholder = placeholder;
  4948. return setWrapToString(result, func, bitmask);
  4949. }
  4950. /**
  4951. * Creates a function like `_.round`.
  4952. *
  4953. * @private
  4954. * @param {string} methodName The name of the `Math` method to use when rounding.
  4955. * @returns {Function} Returns the new round function.
  4956. */
  4957. function createRound(methodName) {
  4958. var func = Math[methodName];
  4959. return function(number, precision) {
  4960. number = toNumber(number);
  4961. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4962. if (precision && nativeIsFinite(number)) {
  4963. // Shift with exponential notation to avoid floating-point issues.
  4964. // See [MDN](https://mdn.io/round#Examples) for more details.
  4965. var pair = (toString(number) + 'e').split('e'),
  4966. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4967. pair = (toString(value) + 'e').split('e');
  4968. return +(pair[0] + 'e' + (+pair[1] - precision));
  4969. }
  4970. return func(number);
  4971. };
  4972. }
  4973. /**
  4974. * Creates a set object of `values`.
  4975. *
  4976. * @private
  4977. * @param {Array} values The values to add to the set.
  4978. * @returns {Object} Returns the new set.
  4979. */
  4980. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4981. return new Set(values);
  4982. };
  4983. /**
  4984. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4985. *
  4986. * @private
  4987. * @param {Function} keysFunc The function to get the keys of a given object.
  4988. * @returns {Function} Returns the new pairs function.
  4989. */
  4990. function createToPairs(keysFunc) {
  4991. return function(object) {
  4992. var tag = getTag(object);
  4993. if (tag == mapTag) {
  4994. return mapToArray(object);
  4995. }
  4996. if (tag == setTag) {
  4997. return setToPairs(object);
  4998. }
  4999. return baseToPairs(object, keysFunc(object));
  5000. };
  5001. }
  5002. /**
  5003. * Creates a function that either curries or invokes `func` with optional
  5004. * `this` binding and partially applied arguments.
  5005. *
  5006. * @private
  5007. * @param {Function|string} func The function or method name to wrap.
  5008. * @param {number} bitmask The bitmask flags.
  5009. * 1 - `_.bind`
  5010. * 2 - `_.bindKey`
  5011. * 4 - `_.curry` or `_.curryRight` of a bound function
  5012. * 8 - `_.curry`
  5013. * 16 - `_.curryRight`
  5014. * 32 - `_.partial`
  5015. * 64 - `_.partialRight`
  5016. * 128 - `_.rearg`
  5017. * 256 - `_.ary`
  5018. * 512 - `_.flip`
  5019. * @param {*} [thisArg] The `this` binding of `func`.
  5020. * @param {Array} [partials] The arguments to be partially applied.
  5021. * @param {Array} [holders] The `partials` placeholder indexes.
  5022. * @param {Array} [argPos] The argument positions of the new function.
  5023. * @param {number} [ary] The arity cap of `func`.
  5024. * @param {number} [arity] The arity of `func`.
  5025. * @returns {Function} Returns the new wrapped function.
  5026. */
  5027. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5028. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5029. if (!isBindKey && typeof func != 'function') {
  5030. throw new TypeError(FUNC_ERROR_TEXT);
  5031. }
  5032. var length = partials ? partials.length : 0;
  5033. if (!length) {
  5034. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5035. partials = holders = undefined;
  5036. }
  5037. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5038. arity = arity === undefined ? arity : toInteger(arity);
  5039. length -= holders ? holders.length : 0;
  5040. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5041. var partialsRight = partials,
  5042. holdersRight = holders;
  5043. partials = holders = undefined;
  5044. }
  5045. var data = isBindKey ? undefined : getData(func);
  5046. var newData = [
  5047. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5048. argPos, ary, arity
  5049. ];
  5050. if (data) {
  5051. mergeData(newData, data);
  5052. }
  5053. func = newData[0];
  5054. bitmask = newData[1];
  5055. thisArg = newData[2];
  5056. partials = newData[3];
  5057. holders = newData[4];
  5058. arity = newData[9] = newData[9] === undefined
  5059. ? (isBindKey ? 0 : func.length)
  5060. : nativeMax(newData[9] - length, 0);
  5061. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5062. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5063. }
  5064. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5065. var result = createBind(func, bitmask, thisArg);
  5066. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5067. result = createCurry(func, bitmask, arity);
  5068. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5069. result = createPartial(func, bitmask, thisArg, partials);
  5070. } else {
  5071. result = createHybrid.apply(undefined, newData);
  5072. }
  5073. var setter = data ? baseSetData : setData;
  5074. return setWrapToString(setter(result, newData), func, bitmask);
  5075. }
  5076. /**
  5077. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5078. * of source objects to the destination object for all destination properties
  5079. * that resolve to `undefined`.
  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 assign.
  5085. * @param {Object} object The parent object of `objValue`.
  5086. * @returns {*} Returns the value to assign.
  5087. */
  5088. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5089. if (objValue === undefined ||
  5090. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5091. return srcValue;
  5092. }
  5093. return objValue;
  5094. }
  5095. /**
  5096. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5097. * objects into destination objects that are passed thru.
  5098. *
  5099. * @private
  5100. * @param {*} objValue The destination value.
  5101. * @param {*} srcValue The source value.
  5102. * @param {string} key The key of the property to merge.
  5103. * @param {Object} object The parent object of `objValue`.
  5104. * @param {Object} source The parent object of `srcValue`.
  5105. * @param {Object} [stack] Tracks traversed source values and their merged
  5106. * counterparts.
  5107. * @returns {*} Returns the value to assign.
  5108. */
  5109. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5110. if (isObject(objValue) && isObject(srcValue)) {
  5111. // Recursively merge objects and arrays (susceptible to call stack limits).
  5112. stack.set(srcValue, objValue);
  5113. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5114. stack['delete'](srcValue);
  5115. }
  5116. return objValue;
  5117. }
  5118. /**
  5119. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5120. * objects.
  5121. *
  5122. * @private
  5123. * @param {*} value The value to inspect.
  5124. * @param {string} key The key of the property to inspect.
  5125. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5126. */
  5127. function customOmitClone(value) {
  5128. return isPlainObject(value) ? undefined : value;
  5129. }
  5130. /**
  5131. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5132. * partial deep comparisons.
  5133. *
  5134. * @private
  5135. * @param {Array} array The array to compare.
  5136. * @param {Array} other The other array to compare.
  5137. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5138. * @param {Function} customizer The function to customize comparisons.
  5139. * @param {Function} equalFunc The function to determine equivalents of values.
  5140. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5141. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5142. */
  5143. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5144. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5145. arrLength = array.length,
  5146. othLength = other.length;
  5147. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5148. return false;
  5149. }
  5150. // Check that cyclic values are equal.
  5151. var arrStacked = stack.get(array);
  5152. var othStacked = stack.get(other);
  5153. if (arrStacked && othStacked) {
  5154. return arrStacked == other && othStacked == array;
  5155. }
  5156. var index = -1,
  5157. result = true,
  5158. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5159. stack.set(array, other);
  5160. stack.set(other, array);
  5161. // Ignore non-index properties.
  5162. while (++index < arrLength) {
  5163. var arrValue = array[index],
  5164. othValue = other[index];
  5165. if (customizer) {
  5166. var compared = isPartial
  5167. ? customizer(othValue, arrValue, index, other, array, stack)
  5168. : customizer(arrValue, othValue, index, array, other, stack);
  5169. }
  5170. if (compared !== undefined) {
  5171. if (compared) {
  5172. continue;
  5173. }
  5174. result = false;
  5175. break;
  5176. }
  5177. // Recursively compare arrays (susceptible to call stack limits).
  5178. if (seen) {
  5179. if (!arraySome(other, function(othValue, othIndex) {
  5180. if (!cacheHas(seen, othIndex) &&
  5181. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5182. return seen.push(othIndex);
  5183. }
  5184. })) {
  5185. result = false;
  5186. break;
  5187. }
  5188. } else if (!(
  5189. arrValue === othValue ||
  5190. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5191. )) {
  5192. result = false;
  5193. break;
  5194. }
  5195. }
  5196. stack['delete'](array);
  5197. stack['delete'](other);
  5198. return result;
  5199. }
  5200. /**
  5201. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5202. * the same `toStringTag`.
  5203. *
  5204. * **Note:** This function only supports comparing values with tags of
  5205. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5206. *
  5207. * @private
  5208. * @param {Object} object The object to compare.
  5209. * @param {Object} other The other object to compare.
  5210. * @param {string} tag The `toStringTag` of the objects to compare.
  5211. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5212. * @param {Function} customizer The function to customize comparisons.
  5213. * @param {Function} equalFunc The function to determine equivalents of values.
  5214. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5215. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5216. */
  5217. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5218. switch (tag) {
  5219. case dataViewTag:
  5220. if ((object.byteLength != other.byteLength) ||
  5221. (object.byteOffset != other.byteOffset)) {
  5222. return false;
  5223. }
  5224. object = object.buffer;
  5225. other = other.buffer;
  5226. case arrayBufferTag:
  5227. if ((object.byteLength != other.byteLength) ||
  5228. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5229. return false;
  5230. }
  5231. return true;
  5232. case boolTag:
  5233. case dateTag:
  5234. case numberTag:
  5235. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5236. // Invalid dates are coerced to `NaN`.
  5237. return eq(+object, +other);
  5238. case errorTag:
  5239. return object.name == other.name && object.message == other.message;
  5240. case regexpTag:
  5241. case stringTag:
  5242. // Coerce regexes to strings and treat strings, primitives and objects,
  5243. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5244. // for more details.
  5245. return object == (other + '');
  5246. case mapTag:
  5247. var convert = mapToArray;
  5248. case setTag:
  5249. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5250. convert || (convert = setToArray);
  5251. if (object.size != other.size && !isPartial) {
  5252. return false;
  5253. }
  5254. // Assume cyclic values are equal.
  5255. var stacked = stack.get(object);
  5256. if (stacked) {
  5257. return stacked == other;
  5258. }
  5259. bitmask |= COMPARE_UNORDERED_FLAG;
  5260. // Recursively compare objects (susceptible to call stack limits).
  5261. stack.set(object, other);
  5262. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5263. stack['delete'](object);
  5264. return result;
  5265. case symbolTag:
  5266. if (symbolValueOf) {
  5267. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5268. }
  5269. }
  5270. return false;
  5271. }
  5272. /**
  5273. * A specialized version of `baseIsEqualDeep` for objects with support for
  5274. * partial deep comparisons.
  5275. *
  5276. * @private
  5277. * @param {Object} object The object to compare.
  5278. * @param {Object} other The other object to compare.
  5279. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5280. * @param {Function} customizer The function to customize comparisons.
  5281. * @param {Function} equalFunc The function to determine equivalents of values.
  5282. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5283. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5284. */
  5285. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5286. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5287. objProps = getAllKeys(object),
  5288. objLength = objProps.length,
  5289. othProps = getAllKeys(other),
  5290. othLength = othProps.length;
  5291. if (objLength != othLength && !isPartial) {
  5292. return false;
  5293. }
  5294. var index = objLength;
  5295. while (index--) {
  5296. var key = objProps[index];
  5297. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5298. return false;
  5299. }
  5300. }
  5301. // Check that cyclic values are equal.
  5302. var objStacked = stack.get(object);
  5303. var othStacked = stack.get(other);
  5304. if (objStacked && othStacked) {
  5305. return objStacked == other && othStacked == object;
  5306. }
  5307. var result = true;
  5308. stack.set(object, other);
  5309. stack.set(other, object);
  5310. var skipCtor = isPartial;
  5311. while (++index < objLength) {
  5312. key = objProps[index];
  5313. var objValue = object[key],
  5314. othValue = other[key];
  5315. if (customizer) {
  5316. var compared = isPartial
  5317. ? customizer(othValue, objValue, key, other, object, stack)
  5318. : customizer(objValue, othValue, key, object, other, stack);
  5319. }
  5320. // Recursively compare objects (susceptible to call stack limits).
  5321. if (!(compared === undefined
  5322. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5323. : compared
  5324. )) {
  5325. result = false;
  5326. break;
  5327. }
  5328. skipCtor || (skipCtor = key == 'constructor');
  5329. }
  5330. if (result && !skipCtor) {
  5331. var objCtor = object.constructor,
  5332. othCtor = other.constructor;
  5333. // Non `Object` object instances with different constructors are not equal.
  5334. if (objCtor != othCtor &&
  5335. ('constructor' in object && 'constructor' in other) &&
  5336. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5337. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5338. result = false;
  5339. }
  5340. }
  5341. stack['delete'](object);
  5342. stack['delete'](other);
  5343. return result;
  5344. }
  5345. /**
  5346. * A specialized version of `baseRest` which flattens the rest array.
  5347. *
  5348. * @private
  5349. * @param {Function} func The function to apply a rest parameter to.
  5350. * @returns {Function} Returns the new function.
  5351. */
  5352. function flatRest(func) {
  5353. return setToString(overRest(func, undefined, flatten), func + '');
  5354. }
  5355. /**
  5356. * Creates an array of own enumerable property names and symbols of `object`.
  5357. *
  5358. * @private
  5359. * @param {Object} object The object to query.
  5360. * @returns {Array} Returns the array of property names and symbols.
  5361. */
  5362. function getAllKeys(object) {
  5363. return baseGetAllKeys(object, keys, getSymbols);
  5364. }
  5365. /**
  5366. * Creates an array of own and inherited enumerable property names and
  5367. * symbols of `object`.
  5368. *
  5369. * @private
  5370. * @param {Object} object The object to query.
  5371. * @returns {Array} Returns the array of property names and symbols.
  5372. */
  5373. function getAllKeysIn(object) {
  5374. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5375. }
  5376. /**
  5377. * Gets metadata for `func`.
  5378. *
  5379. * @private
  5380. * @param {Function} func The function to query.
  5381. * @returns {*} Returns the metadata for `func`.
  5382. */
  5383. var getData = !metaMap ? noop : function(func) {
  5384. return metaMap.get(func);
  5385. };
  5386. /**
  5387. * Gets the name of `func`.
  5388. *
  5389. * @private
  5390. * @param {Function} func The function to query.
  5391. * @returns {string} Returns the function name.
  5392. */
  5393. function getFuncName(func) {
  5394. var result = (func.name + ''),
  5395. array = realNames[result],
  5396. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5397. while (length--) {
  5398. var data = array[length],
  5399. otherFunc = data.func;
  5400. if (otherFunc == null || otherFunc == func) {
  5401. return data.name;
  5402. }
  5403. }
  5404. return result;
  5405. }
  5406. /**
  5407. * Gets the argument placeholder value for `func`.
  5408. *
  5409. * @private
  5410. * @param {Function} func The function to inspect.
  5411. * @returns {*} Returns the placeholder value.
  5412. */
  5413. function getHolder(func) {
  5414. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5415. return object.placeholder;
  5416. }
  5417. /**
  5418. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5419. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5420. * If arguments are provided, the chosen function is invoked with them and
  5421. * its result is returned.
  5422. *
  5423. * @private
  5424. * @param {*} [value] The value to convert to an iteratee.
  5425. * @param {number} [arity] The arity of the created iteratee.
  5426. * @returns {Function} Returns the chosen function or its result.
  5427. */
  5428. function getIteratee() {
  5429. var result = lodash.iteratee || iteratee;
  5430. result = result === iteratee ? baseIteratee : result;
  5431. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5432. }
  5433. /**
  5434. * Gets the data for `map`.
  5435. *
  5436. * @private
  5437. * @param {Object} map The map to query.
  5438. * @param {string} key The reference key.
  5439. * @returns {*} Returns the map data.
  5440. */
  5441. function getMapData(map, key) {
  5442. var data = map.__data__;
  5443. return isKeyable(key)
  5444. ? data[typeof key == 'string' ? 'string' : 'hash']
  5445. : data.map;
  5446. }
  5447. /**
  5448. * Gets the property names, values, and compare flags of `object`.
  5449. *
  5450. * @private
  5451. * @param {Object} object The object to query.
  5452. * @returns {Array} Returns the match data of `object`.
  5453. */
  5454. function getMatchData(object) {
  5455. var result = keys(object),
  5456. length = result.length;
  5457. while (length--) {
  5458. var key = result[length],
  5459. value = object[key];
  5460. result[length] = [key, value, isStrictComparable(value)];
  5461. }
  5462. return result;
  5463. }
  5464. /**
  5465. * Gets the native function at `key` of `object`.
  5466. *
  5467. * @private
  5468. * @param {Object} object The object to query.
  5469. * @param {string} key The key of the method to get.
  5470. * @returns {*} Returns the function if it's native, else `undefined`.
  5471. */
  5472. function getNative(object, key) {
  5473. var value = getValue(object, key);
  5474. return baseIsNative(value) ? value : undefined;
  5475. }
  5476. /**
  5477. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5478. *
  5479. * @private
  5480. * @param {*} value The value to query.
  5481. * @returns {string} Returns the raw `toStringTag`.
  5482. */
  5483. function getRawTag(value) {
  5484. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5485. tag = value[symToStringTag];
  5486. try {
  5487. value[symToStringTag] = undefined;
  5488. var unmasked = true;
  5489. } catch (e) {}
  5490. var result = nativeObjectToString.call(value);
  5491. if (unmasked) {
  5492. if (isOwn) {
  5493. value[symToStringTag] = tag;
  5494. } else {
  5495. delete value[symToStringTag];
  5496. }
  5497. }
  5498. return result;
  5499. }
  5500. /**
  5501. * Creates an array of the own enumerable symbols of `object`.
  5502. *
  5503. * @private
  5504. * @param {Object} object The object to query.
  5505. * @returns {Array} Returns the array of symbols.
  5506. */
  5507. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5508. if (object == null) {
  5509. return [];
  5510. }
  5511. object = Object(object);
  5512. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5513. return propertyIsEnumerable.call(object, symbol);
  5514. });
  5515. };
  5516. /**
  5517. * Creates an array of the own and inherited enumerable symbols of `object`.
  5518. *
  5519. * @private
  5520. * @param {Object} object The object to query.
  5521. * @returns {Array} Returns the array of symbols.
  5522. */
  5523. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5524. var result = [];
  5525. while (object) {
  5526. arrayPush(result, getSymbols(object));
  5527. object = getPrototype(object);
  5528. }
  5529. return result;
  5530. };
  5531. /**
  5532. * Gets the `toStringTag` of `value`.
  5533. *
  5534. * @private
  5535. * @param {*} value The value to query.
  5536. * @returns {string} Returns the `toStringTag`.
  5537. */
  5538. var getTag = baseGetTag;
  5539. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5540. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5541. (Map && getTag(new Map) != mapTag) ||
  5542. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5543. (Set && getTag(new Set) != setTag) ||
  5544. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5545. getTag = function(value) {
  5546. var result = baseGetTag(value),
  5547. Ctor = result == objectTag ? value.constructor : undefined,
  5548. ctorString = Ctor ? toSource(Ctor) : '';
  5549. if (ctorString) {
  5550. switch (ctorString) {
  5551. case dataViewCtorString: return dataViewTag;
  5552. case mapCtorString: return mapTag;
  5553. case promiseCtorString: return promiseTag;
  5554. case setCtorString: return setTag;
  5555. case weakMapCtorString: return weakMapTag;
  5556. }
  5557. }
  5558. return result;
  5559. };
  5560. }
  5561. /**
  5562. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5563. *
  5564. * @private
  5565. * @param {number} start The start of the view.
  5566. * @param {number} end The end of the view.
  5567. * @param {Array} transforms The transformations to apply to the view.
  5568. * @returns {Object} Returns an object containing the `start` and `end`
  5569. * positions of the view.
  5570. */
  5571. function getView(start, end, transforms) {
  5572. var index = -1,
  5573. length = transforms.length;
  5574. while (++index < length) {
  5575. var data = transforms[index],
  5576. size = data.size;
  5577. switch (data.type) {
  5578. case 'drop': start += size; break;
  5579. case 'dropRight': end -= size; break;
  5580. case 'take': end = nativeMin(end, start + size); break;
  5581. case 'takeRight': start = nativeMax(start, end - size); break;
  5582. }
  5583. }
  5584. return { 'start': start, 'end': end };
  5585. }
  5586. /**
  5587. * Extracts wrapper details from the `source` body comment.
  5588. *
  5589. * @private
  5590. * @param {string} source The source to inspect.
  5591. * @returns {Array} Returns the wrapper details.
  5592. */
  5593. function getWrapDetails(source) {
  5594. var match = source.match(reWrapDetails);
  5595. return match ? match[1].split(reSplitDetails) : [];
  5596. }
  5597. /**
  5598. * Checks if `path` exists on `object`.
  5599. *
  5600. * @private
  5601. * @param {Object} object The object to query.
  5602. * @param {Array|string} path The path to check.
  5603. * @param {Function} hasFunc The function to check properties.
  5604. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5605. */
  5606. function hasPath(object, path, hasFunc) {
  5607. path = castPath(path, object);
  5608. var index = -1,
  5609. length = path.length,
  5610. result = false;
  5611. while (++index < length) {
  5612. var key = toKey(path[index]);
  5613. if (!(result = object != null && hasFunc(object, key))) {
  5614. break;
  5615. }
  5616. object = object[key];
  5617. }
  5618. if (result || ++index != length) {
  5619. return result;
  5620. }
  5621. length = object == null ? 0 : object.length;
  5622. return !!length && isLength(length) && isIndex(key, length) &&
  5623. (isArray(object) || isArguments(object));
  5624. }
  5625. /**
  5626. * Initializes an array clone.
  5627. *
  5628. * @private
  5629. * @param {Array} array The array to clone.
  5630. * @returns {Array} Returns the initialized clone.
  5631. */
  5632. function initCloneArray(array) {
  5633. var length = array.length,
  5634. result = new array.constructor(length);
  5635. // Add properties assigned by `RegExp#exec`.
  5636. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5637. result.index = array.index;
  5638. result.input = array.input;
  5639. }
  5640. return result;
  5641. }
  5642. /**
  5643. * Initializes an object clone.
  5644. *
  5645. * @private
  5646. * @param {Object} object The object to clone.
  5647. * @returns {Object} Returns the initialized clone.
  5648. */
  5649. function initCloneObject(object) {
  5650. return (typeof object.constructor == 'function' && !isPrototype(object))
  5651. ? baseCreate(getPrototype(object))
  5652. : {};
  5653. }
  5654. /**
  5655. * Initializes an object clone based on its `toStringTag`.
  5656. *
  5657. * **Note:** This function only supports cloning values with tags of
  5658. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5659. *
  5660. * @private
  5661. * @param {Object} object The object to clone.
  5662. * @param {string} tag The `toStringTag` of the object to clone.
  5663. * @param {boolean} [isDeep] Specify a deep clone.
  5664. * @returns {Object} Returns the initialized clone.
  5665. */
  5666. function initCloneByTag(object, tag, isDeep) {
  5667. var Ctor = object.constructor;
  5668. switch (tag) {
  5669. case arrayBufferTag:
  5670. return cloneArrayBuffer(object);
  5671. case boolTag:
  5672. case dateTag:
  5673. return new Ctor(+object);
  5674. case dataViewTag:
  5675. return cloneDataView(object, isDeep);
  5676. case float32Tag: case float64Tag:
  5677. case int8Tag: case int16Tag: case int32Tag:
  5678. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5679. return cloneTypedArray(object, isDeep);
  5680. case mapTag:
  5681. return new Ctor;
  5682. case numberTag:
  5683. case stringTag:
  5684. return new Ctor(object);
  5685. case regexpTag:
  5686. return cloneRegExp(object);
  5687. case setTag:
  5688. return new Ctor;
  5689. case symbolTag:
  5690. return cloneSymbol(object);
  5691. }
  5692. }
  5693. /**
  5694. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5695. *
  5696. * @private
  5697. * @param {string} source The source to modify.
  5698. * @returns {Array} details The details to insert.
  5699. * @returns {string} Returns the modified source.
  5700. */
  5701. function insertWrapDetails(source, details) {
  5702. var length = details.length;
  5703. if (!length) {
  5704. return source;
  5705. }
  5706. var lastIndex = length - 1;
  5707. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5708. details = details.join(length > 2 ? ', ' : ' ');
  5709. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5710. }
  5711. /**
  5712. * Checks if `value` is a flattenable `arguments` object or array.
  5713. *
  5714. * @private
  5715. * @param {*} value The value to check.
  5716. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5717. */
  5718. function isFlattenable(value) {
  5719. return isArray(value) || isArguments(value) ||
  5720. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5721. }
  5722. /**
  5723. * Checks if `value` is a valid array-like index.
  5724. *
  5725. * @private
  5726. * @param {*} value The value to check.
  5727. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5728. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5729. */
  5730. function isIndex(value, length) {
  5731. var type = typeof value;
  5732. length = length == null ? MAX_SAFE_INTEGER : length;
  5733. return !!length &&
  5734. (type == 'number' ||
  5735. (type != 'symbol' && reIsUint.test(value))) &&
  5736. (value > -1 && value % 1 == 0 && value < length);
  5737. }
  5738. /**
  5739. * Checks if the given arguments are from an iteratee call.
  5740. *
  5741. * @private
  5742. * @param {*} value The potential iteratee value argument.
  5743. * @param {*} index The potential iteratee index or key argument.
  5744. * @param {*} object The potential iteratee object argument.
  5745. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5746. * else `false`.
  5747. */
  5748. function isIterateeCall(value, index, object) {
  5749. if (!isObject(object)) {
  5750. return false;
  5751. }
  5752. var type = typeof index;
  5753. if (type == 'number'
  5754. ? (isArrayLike(object) && isIndex(index, object.length))
  5755. : (type == 'string' && index in object)
  5756. ) {
  5757. return eq(object[index], value);
  5758. }
  5759. return false;
  5760. }
  5761. /**
  5762. * Checks if `value` is a property name and not a property path.
  5763. *
  5764. * @private
  5765. * @param {*} value The value to check.
  5766. * @param {Object} [object] The object to query keys on.
  5767. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5768. */
  5769. function isKey(value, object) {
  5770. if (isArray(value)) {
  5771. return false;
  5772. }
  5773. var type = typeof value;
  5774. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5775. value == null || isSymbol(value)) {
  5776. return true;
  5777. }
  5778. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5779. (object != null && value in Object(object));
  5780. }
  5781. /**
  5782. * Checks if `value` is suitable for use as unique object key.
  5783. *
  5784. * @private
  5785. * @param {*} value The value to check.
  5786. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5787. */
  5788. function isKeyable(value) {
  5789. var type = typeof value;
  5790. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5791. ? (value !== '__proto__')
  5792. : (value === null);
  5793. }
  5794. /**
  5795. * Checks if `func` has a lazy counterpart.
  5796. *
  5797. * @private
  5798. * @param {Function} func The function to check.
  5799. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5800. * else `false`.
  5801. */
  5802. function isLaziable(func) {
  5803. var funcName = getFuncName(func),
  5804. other = lodash[funcName];
  5805. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5806. return false;
  5807. }
  5808. if (func === other) {
  5809. return true;
  5810. }
  5811. var data = getData(other);
  5812. return !!data && func === data[0];
  5813. }
  5814. /**
  5815. * Checks if `func` has its source masked.
  5816. *
  5817. * @private
  5818. * @param {Function} func The function to check.
  5819. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5820. */
  5821. function isMasked(func) {
  5822. return !!maskSrcKey && (maskSrcKey in func);
  5823. }
  5824. /**
  5825. * Checks if `func` is capable of being masked.
  5826. *
  5827. * @private
  5828. * @param {*} value The value to check.
  5829. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5830. */
  5831. var isMaskable = coreJsData ? isFunction : stubFalse;
  5832. /**
  5833. * Checks if `value` is likely a prototype object.
  5834. *
  5835. * @private
  5836. * @param {*} value The value to check.
  5837. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5838. */
  5839. function isPrototype(value) {
  5840. var Ctor = value && value.constructor,
  5841. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5842. return value === proto;
  5843. }
  5844. /**
  5845. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5846. *
  5847. * @private
  5848. * @param {*} value The value to check.
  5849. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5850. * equality comparisons, else `false`.
  5851. */
  5852. function isStrictComparable(value) {
  5853. return value === value && !isObject(value);
  5854. }
  5855. /**
  5856. * A specialized version of `matchesProperty` for source values suitable
  5857. * for strict equality comparisons, i.e. `===`.
  5858. *
  5859. * @private
  5860. * @param {string} key The key of the property to get.
  5861. * @param {*} srcValue The value to match.
  5862. * @returns {Function} Returns the new spec function.
  5863. */
  5864. function matchesStrictComparable(key, srcValue) {
  5865. return function(object) {
  5866. if (object == null) {
  5867. return false;
  5868. }
  5869. return object[key] === srcValue &&
  5870. (srcValue !== undefined || (key in Object(object)));
  5871. };
  5872. }
  5873. /**
  5874. * A specialized version of `_.memoize` which clears the memoized function's
  5875. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5876. *
  5877. * @private
  5878. * @param {Function} func The function to have its output memoized.
  5879. * @returns {Function} Returns the new memoized function.
  5880. */
  5881. function memoizeCapped(func) {
  5882. var result = memoize(func, function(key) {
  5883. if (cache.size === MAX_MEMOIZE_SIZE) {
  5884. cache.clear();
  5885. }
  5886. return key;
  5887. });
  5888. var cache = result.cache;
  5889. return result;
  5890. }
  5891. /**
  5892. * Merges the function metadata of `source` into `data`.
  5893. *
  5894. * Merging metadata reduces the number of wrappers used to invoke a function.
  5895. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5896. * may be applied regardless of execution order. Methods like `_.ary` and
  5897. * `_.rearg` modify function arguments, making the order in which they are
  5898. * executed important, preventing the merging of metadata. However, we make
  5899. * an exception for a safe combined case where curried functions have `_.ary`
  5900. * and or `_.rearg` applied.
  5901. *
  5902. * @private
  5903. * @param {Array} data The destination metadata.
  5904. * @param {Array} source The source metadata.
  5905. * @returns {Array} Returns `data`.
  5906. */
  5907. function mergeData(data, source) {
  5908. var bitmask = data[1],
  5909. srcBitmask = source[1],
  5910. newBitmask = bitmask | srcBitmask,
  5911. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5912. var isCombo =
  5913. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5914. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5915. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5916. // Exit early if metadata can't be merged.
  5917. if (!(isCommon || isCombo)) {
  5918. return data;
  5919. }
  5920. // Use source `thisArg` if available.
  5921. if (srcBitmask & WRAP_BIND_FLAG) {
  5922. data[2] = source[2];
  5923. // Set when currying a bound function.
  5924. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5925. }
  5926. // Compose partial arguments.
  5927. var value = source[3];
  5928. if (value) {
  5929. var partials = data[3];
  5930. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5931. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5932. }
  5933. // Compose partial right arguments.
  5934. value = source[5];
  5935. if (value) {
  5936. partials = data[5];
  5937. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5938. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5939. }
  5940. // Use source `argPos` if available.
  5941. value = source[7];
  5942. if (value) {
  5943. data[7] = value;
  5944. }
  5945. // Use source `ary` if it's smaller.
  5946. if (srcBitmask & WRAP_ARY_FLAG) {
  5947. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5948. }
  5949. // Use source `arity` if one is not provided.
  5950. if (data[9] == null) {
  5951. data[9] = source[9];
  5952. }
  5953. // Use source `func` and merge bitmasks.
  5954. data[0] = source[0];
  5955. data[1] = newBitmask;
  5956. return data;
  5957. }
  5958. /**
  5959. * This function is like
  5960. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5961. * except that it includes inherited enumerable properties.
  5962. *
  5963. * @private
  5964. * @param {Object} object The object to query.
  5965. * @returns {Array} Returns the array of property names.
  5966. */
  5967. function nativeKeysIn(object) {
  5968. var result = [];
  5969. if (object != null) {
  5970. for (var key in Object(object)) {
  5971. result.push(key);
  5972. }
  5973. }
  5974. return result;
  5975. }
  5976. /**
  5977. * Converts `value` to a string using `Object.prototype.toString`.
  5978. *
  5979. * @private
  5980. * @param {*} value The value to convert.
  5981. * @returns {string} Returns the converted string.
  5982. */
  5983. function objectToString(value) {
  5984. return nativeObjectToString.call(value);
  5985. }
  5986. /**
  5987. * A specialized version of `baseRest` which transforms the rest array.
  5988. *
  5989. * @private
  5990. * @param {Function} func The function to apply a rest parameter to.
  5991. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5992. * @param {Function} transform The rest array transform.
  5993. * @returns {Function} Returns the new function.
  5994. */
  5995. function overRest(func, start, transform) {
  5996. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5997. return function() {
  5998. var args = arguments,
  5999. index = -1,
  6000. length = nativeMax(args.length - start, 0),
  6001. array = Array(length);
  6002. while (++index < length) {
  6003. array[index] = args[start + index];
  6004. }
  6005. index = -1;
  6006. var otherArgs = Array(start + 1);
  6007. while (++index < start) {
  6008. otherArgs[index] = args[index];
  6009. }
  6010. otherArgs[start] = transform(array);
  6011. return apply(func, this, otherArgs);
  6012. };
  6013. }
  6014. /**
  6015. * Gets the parent value at `path` of `object`.
  6016. *
  6017. * @private
  6018. * @param {Object} object The object to query.
  6019. * @param {Array} path The path to get the parent value of.
  6020. * @returns {*} Returns the parent value.
  6021. */
  6022. function parent(object, path) {
  6023. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6024. }
  6025. /**
  6026. * Reorder `array` according to the specified indexes where the element at
  6027. * the first index is assigned as the first element, the element at
  6028. * the second index is assigned as the second element, and so on.
  6029. *
  6030. * @private
  6031. * @param {Array} array The array to reorder.
  6032. * @param {Array} indexes The arranged array indexes.
  6033. * @returns {Array} Returns `array`.
  6034. */
  6035. function reorder(array, indexes) {
  6036. var arrLength = array.length,
  6037. length = nativeMin(indexes.length, arrLength),
  6038. oldArray = copyArray(array);
  6039. while (length--) {
  6040. var index = indexes[length];
  6041. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6042. }
  6043. return array;
  6044. }
  6045. /**
  6046. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  6047. *
  6048. * @private
  6049. * @param {Object} object The object to query.
  6050. * @param {string} key The key of the property to get.
  6051. * @returns {*} Returns the property value.
  6052. */
  6053. function safeGet(object, key) {
  6054. if (key === 'constructor' && typeof object[key] === 'function') {
  6055. return;
  6056. }
  6057. if (key == '__proto__') {
  6058. return;
  6059. }
  6060. return object[key];
  6061. }
  6062. /**
  6063. * Sets metadata for `func`.
  6064. *
  6065. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6066. * period of time, it will trip its breaker and transition to an identity
  6067. * function to avoid garbage collection pauses in V8. See
  6068. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6069. * for more details.
  6070. *
  6071. * @private
  6072. * @param {Function} func The function to associate metadata with.
  6073. * @param {*} data The metadata.
  6074. * @returns {Function} Returns `func`.
  6075. */
  6076. var setData = shortOut(baseSetData);
  6077. /**
  6078. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6079. *
  6080. * @private
  6081. * @param {Function} func The function to delay.
  6082. * @param {number} wait The number of milliseconds to delay invocation.
  6083. * @returns {number|Object} Returns the timer id or timeout object.
  6084. */
  6085. var setTimeout = ctxSetTimeout || function(func, wait) {
  6086. return root.setTimeout(func, wait);
  6087. };
  6088. /**
  6089. * Sets the `toString` method of `func` to return `string`.
  6090. *
  6091. * @private
  6092. * @param {Function} func The function to modify.
  6093. * @param {Function} string The `toString` result.
  6094. * @returns {Function} Returns `func`.
  6095. */
  6096. var setToString = shortOut(baseSetToString);
  6097. /**
  6098. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6099. * with wrapper details in a comment at the top of the source body.
  6100. *
  6101. * @private
  6102. * @param {Function} wrapper The function to modify.
  6103. * @param {Function} reference The reference function.
  6104. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6105. * @returns {Function} Returns `wrapper`.
  6106. */
  6107. function setWrapToString(wrapper, reference, bitmask) {
  6108. var source = (reference + '');
  6109. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6110. }
  6111. /**
  6112. * Creates a function that'll short out and invoke `identity` instead
  6113. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6114. * milliseconds.
  6115. *
  6116. * @private
  6117. * @param {Function} func The function to restrict.
  6118. * @returns {Function} Returns the new shortable function.
  6119. */
  6120. function shortOut(func) {
  6121. var count = 0,
  6122. lastCalled = 0;
  6123. return function() {
  6124. var stamp = nativeNow(),
  6125. remaining = HOT_SPAN - (stamp - lastCalled);
  6126. lastCalled = stamp;
  6127. if (remaining > 0) {
  6128. if (++count >= HOT_COUNT) {
  6129. return arguments[0];
  6130. }
  6131. } else {
  6132. count = 0;
  6133. }
  6134. return func.apply(undefined, arguments);
  6135. };
  6136. }
  6137. /**
  6138. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6139. *
  6140. * @private
  6141. * @param {Array} array The array to shuffle.
  6142. * @param {number} [size=array.length] The size of `array`.
  6143. * @returns {Array} Returns `array`.
  6144. */
  6145. function shuffleSelf(array, size) {
  6146. var index = -1,
  6147. length = array.length,
  6148. lastIndex = length - 1;
  6149. size = size === undefined ? length : size;
  6150. while (++index < size) {
  6151. var rand = baseRandom(index, lastIndex),
  6152. value = array[rand];
  6153. array[rand] = array[index];
  6154. array[index] = value;
  6155. }
  6156. array.length = size;
  6157. return array;
  6158. }
  6159. /**
  6160. * Converts `string` to a property path array.
  6161. *
  6162. * @private
  6163. * @param {string} string The string to convert.
  6164. * @returns {Array} Returns the property path array.
  6165. */
  6166. var stringToPath = memoizeCapped(function(string) {
  6167. var result = [];
  6168. if (string.charCodeAt(0) === 46 /* . */) {
  6169. result.push('');
  6170. }
  6171. string.replace(rePropName, function(match, number, quote, subString) {
  6172. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6173. });
  6174. return result;
  6175. });
  6176. /**
  6177. * Converts `value` to a string key if it's not a string or symbol.
  6178. *
  6179. * @private
  6180. * @param {*} value The value to inspect.
  6181. * @returns {string|symbol} Returns the key.
  6182. */
  6183. function toKey(value) {
  6184. if (typeof value == 'string' || isSymbol(value)) {
  6185. return value;
  6186. }
  6187. var result = (value + '');
  6188. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6189. }
  6190. /**
  6191. * Converts `func` to its source code.
  6192. *
  6193. * @private
  6194. * @param {Function} func The function to convert.
  6195. * @returns {string} Returns the source code.
  6196. */
  6197. function toSource(func) {
  6198. if (func != null) {
  6199. try {
  6200. return funcToString.call(func);
  6201. } catch (e) {}
  6202. try {
  6203. return (func + '');
  6204. } catch (e) {}
  6205. }
  6206. return '';
  6207. }
  6208. /**
  6209. * Updates wrapper `details` based on `bitmask` flags.
  6210. *
  6211. * @private
  6212. * @returns {Array} details The details to modify.
  6213. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6214. * @returns {Array} Returns `details`.
  6215. */
  6216. function updateWrapDetails(details, bitmask) {
  6217. arrayEach(wrapFlags, function(pair) {
  6218. var value = '_.' + pair[0];
  6219. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6220. details.push(value);
  6221. }
  6222. });
  6223. return details.sort();
  6224. }
  6225. /**
  6226. * Creates a clone of `wrapper`.
  6227. *
  6228. * @private
  6229. * @param {Object} wrapper The wrapper to clone.
  6230. * @returns {Object} Returns the cloned wrapper.
  6231. */
  6232. function wrapperClone(wrapper) {
  6233. if (wrapper instanceof LazyWrapper) {
  6234. return wrapper.clone();
  6235. }
  6236. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6237. result.__actions__ = copyArray(wrapper.__actions__);
  6238. result.__index__ = wrapper.__index__;
  6239. result.__values__ = wrapper.__values__;
  6240. return result;
  6241. }
  6242. /*------------------------------------------------------------------------*/
  6243. /**
  6244. * Creates an array of elements split into groups the length of `size`.
  6245. * If `array` can't be split evenly, the final chunk will be the remaining
  6246. * elements.
  6247. *
  6248. * @static
  6249. * @memberOf _
  6250. * @since 3.0.0
  6251. * @category Array
  6252. * @param {Array} array The array to process.
  6253. * @param {number} [size=1] The length of each chunk
  6254. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6255. * @returns {Array} Returns the new array of chunks.
  6256. * @example
  6257. *
  6258. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6259. * // => [['a', 'b'], ['c', 'd']]
  6260. *
  6261. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6262. * // => [['a', 'b', 'c'], ['d']]
  6263. */
  6264. function chunk(array, size, guard) {
  6265. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6266. size = 1;
  6267. } else {
  6268. size = nativeMax(toInteger(size), 0);
  6269. }
  6270. var length = array == null ? 0 : array.length;
  6271. if (!length || size < 1) {
  6272. return [];
  6273. }
  6274. var index = 0,
  6275. resIndex = 0,
  6276. result = Array(nativeCeil(length / size));
  6277. while (index < length) {
  6278. result[resIndex++] = baseSlice(array, index, (index += size));
  6279. }
  6280. return result;
  6281. }
  6282. /**
  6283. * Creates an array with all falsey values removed. The values `false`, `null`,
  6284. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6285. *
  6286. * @static
  6287. * @memberOf _
  6288. * @since 0.1.0
  6289. * @category Array
  6290. * @param {Array} array The array to compact.
  6291. * @returns {Array} Returns the new array of filtered values.
  6292. * @example
  6293. *
  6294. * _.compact([0, 1, false, 2, '', 3]);
  6295. * // => [1, 2, 3]
  6296. */
  6297. function compact(array) {
  6298. var index = -1,
  6299. length = array == null ? 0 : array.length,
  6300. resIndex = 0,
  6301. result = [];
  6302. while (++index < length) {
  6303. var value = array[index];
  6304. if (value) {
  6305. result[resIndex++] = value;
  6306. }
  6307. }
  6308. return result;
  6309. }
  6310. /**
  6311. * Creates a new array concatenating `array` with any additional arrays
  6312. * and/or values.
  6313. *
  6314. * @static
  6315. * @memberOf _
  6316. * @since 4.0.0
  6317. * @category Array
  6318. * @param {Array} array The array to concatenate.
  6319. * @param {...*} [values] The values to concatenate.
  6320. * @returns {Array} Returns the new concatenated array.
  6321. * @example
  6322. *
  6323. * var array = [1];
  6324. * var other = _.concat(array, 2, [3], [[4]]);
  6325. *
  6326. * console.log(other);
  6327. * // => [1, 2, 3, [4]]
  6328. *
  6329. * console.log(array);
  6330. * // => [1]
  6331. */
  6332. function concat() {
  6333. var length = arguments.length;
  6334. if (!length) {
  6335. return [];
  6336. }
  6337. var args = Array(length - 1),
  6338. array = arguments[0],
  6339. index = length;
  6340. while (index--) {
  6341. args[index - 1] = arguments[index];
  6342. }
  6343. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6344. }
  6345. /**
  6346. * Creates an array of `array` values not included in the other given arrays
  6347. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6348. * for equality comparisons. The order and references of result values are
  6349. * determined by the first array.
  6350. *
  6351. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6352. *
  6353. * @static
  6354. * @memberOf _
  6355. * @since 0.1.0
  6356. * @category Array
  6357. * @param {Array} array The array to inspect.
  6358. * @param {...Array} [values] The values to exclude.
  6359. * @returns {Array} Returns the new array of filtered values.
  6360. * @see _.without, _.xor
  6361. * @example
  6362. *
  6363. * _.difference([2, 1], [2, 3]);
  6364. * // => [1]
  6365. */
  6366. var difference = baseRest(function(array, values) {
  6367. return isArrayLikeObject(array)
  6368. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6369. : [];
  6370. });
  6371. /**
  6372. * This method is like `_.difference` except that it accepts `iteratee` which
  6373. * is invoked for each element of `array` and `values` to generate the criterion
  6374. * by which they're compared. The order and references of result values are
  6375. * determined by the first array. The iteratee is invoked with one argument:
  6376. * (value).
  6377. *
  6378. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6379. *
  6380. * @static
  6381. * @memberOf _
  6382. * @since 4.0.0
  6383. * @category Array
  6384. * @param {Array} array The array to inspect.
  6385. * @param {...Array} [values] The values to exclude.
  6386. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6387. * @returns {Array} Returns the new array of filtered values.
  6388. * @example
  6389. *
  6390. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6391. * // => [1.2]
  6392. *
  6393. * // The `_.property` iteratee shorthand.
  6394. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6395. * // => [{ 'x': 2 }]
  6396. */
  6397. var differenceBy = baseRest(function(array, values) {
  6398. var iteratee = last(values);
  6399. if (isArrayLikeObject(iteratee)) {
  6400. iteratee = undefined;
  6401. }
  6402. return isArrayLikeObject(array)
  6403. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6404. : [];
  6405. });
  6406. /**
  6407. * This method is like `_.difference` except that it accepts `comparator`
  6408. * which is invoked to compare elements of `array` to `values`. The order and
  6409. * references of result values are determined by the first array. The comparator
  6410. * is invoked with two arguments: (arrVal, othVal).
  6411. *
  6412. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6413. *
  6414. * @static
  6415. * @memberOf _
  6416. * @since 4.0.0
  6417. * @category Array
  6418. * @param {Array} array The array to inspect.
  6419. * @param {...Array} [values] The values to exclude.
  6420. * @param {Function} [comparator] The comparator invoked per element.
  6421. * @returns {Array} Returns the new array of filtered values.
  6422. * @example
  6423. *
  6424. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6425. *
  6426. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6427. * // => [{ 'x': 2, 'y': 1 }]
  6428. */
  6429. var differenceWith = baseRest(function(array, values) {
  6430. var comparator = last(values);
  6431. if (isArrayLikeObject(comparator)) {
  6432. comparator = undefined;
  6433. }
  6434. return isArrayLikeObject(array)
  6435. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6436. : [];
  6437. });
  6438. /**
  6439. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6440. *
  6441. * @static
  6442. * @memberOf _
  6443. * @since 0.5.0
  6444. * @category Array
  6445. * @param {Array} array The array to query.
  6446. * @param {number} [n=1] The number of elements to drop.
  6447. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6448. * @returns {Array} Returns the slice of `array`.
  6449. * @example
  6450. *
  6451. * _.drop([1, 2, 3]);
  6452. * // => [2, 3]
  6453. *
  6454. * _.drop([1, 2, 3], 2);
  6455. * // => [3]
  6456. *
  6457. * _.drop([1, 2, 3], 5);
  6458. * // => []
  6459. *
  6460. * _.drop([1, 2, 3], 0);
  6461. * // => [1, 2, 3]
  6462. */
  6463. function drop(array, n, guard) {
  6464. var length = array == null ? 0 : array.length;
  6465. if (!length) {
  6466. return [];
  6467. }
  6468. n = (guard || n === undefined) ? 1 : toInteger(n);
  6469. return baseSlice(array, n < 0 ? 0 : n, length);
  6470. }
  6471. /**
  6472. * Creates a slice of `array` with `n` elements dropped from the end.
  6473. *
  6474. * @static
  6475. * @memberOf _
  6476. * @since 3.0.0
  6477. * @category Array
  6478. * @param {Array} array The array to query.
  6479. * @param {number} [n=1] The number of elements to drop.
  6480. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6481. * @returns {Array} Returns the slice of `array`.
  6482. * @example
  6483. *
  6484. * _.dropRight([1, 2, 3]);
  6485. * // => [1, 2]
  6486. *
  6487. * _.dropRight([1, 2, 3], 2);
  6488. * // => [1]
  6489. *
  6490. * _.dropRight([1, 2, 3], 5);
  6491. * // => []
  6492. *
  6493. * _.dropRight([1, 2, 3], 0);
  6494. * // => [1, 2, 3]
  6495. */
  6496. function dropRight(array, n, guard) {
  6497. var length = array == null ? 0 : array.length;
  6498. if (!length) {
  6499. return [];
  6500. }
  6501. n = (guard || n === undefined) ? 1 : toInteger(n);
  6502. n = length - n;
  6503. return baseSlice(array, 0, n < 0 ? 0 : n);
  6504. }
  6505. /**
  6506. * Creates a slice of `array` excluding elements dropped from the end.
  6507. * Elements are dropped until `predicate` returns falsey. The predicate is
  6508. * invoked with three arguments: (value, index, array).
  6509. *
  6510. * @static
  6511. * @memberOf _
  6512. * @since 3.0.0
  6513. * @category Array
  6514. * @param {Array} array The array to query.
  6515. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6516. * @returns {Array} Returns the slice of `array`.
  6517. * @example
  6518. *
  6519. * var users = [
  6520. * { 'user': 'barney', 'active': true },
  6521. * { 'user': 'fred', 'active': false },
  6522. * { 'user': 'pebbles', 'active': false }
  6523. * ];
  6524. *
  6525. * _.dropRightWhile(users, function(o) { return !o.active; });
  6526. * // => objects for ['barney']
  6527. *
  6528. * // The `_.matches` iteratee shorthand.
  6529. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6530. * // => objects for ['barney', 'fred']
  6531. *
  6532. * // The `_.matchesProperty` iteratee shorthand.
  6533. * _.dropRightWhile(users, ['active', false]);
  6534. * // => objects for ['barney']
  6535. *
  6536. * // The `_.property` iteratee shorthand.
  6537. * _.dropRightWhile(users, 'active');
  6538. * // => objects for ['barney', 'fred', 'pebbles']
  6539. */
  6540. function dropRightWhile(array, predicate) {
  6541. return (array && array.length)
  6542. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6543. : [];
  6544. }
  6545. /**
  6546. * Creates a slice of `array` excluding elements dropped from the beginning.
  6547. * Elements are dropped until `predicate` returns falsey. The predicate is
  6548. * invoked with three arguments: (value, index, array).
  6549. *
  6550. * @static
  6551. * @memberOf _
  6552. * @since 3.0.0
  6553. * @category Array
  6554. * @param {Array} array The array to query.
  6555. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6556. * @returns {Array} Returns the slice of `array`.
  6557. * @example
  6558. *
  6559. * var users = [
  6560. * { 'user': 'barney', 'active': false },
  6561. * { 'user': 'fred', 'active': false },
  6562. * { 'user': 'pebbles', 'active': true }
  6563. * ];
  6564. *
  6565. * _.dropWhile(users, function(o) { return !o.active; });
  6566. * // => objects for ['pebbles']
  6567. *
  6568. * // The `_.matches` iteratee shorthand.
  6569. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6570. * // => objects for ['fred', 'pebbles']
  6571. *
  6572. * // The `_.matchesProperty` iteratee shorthand.
  6573. * _.dropWhile(users, ['active', false]);
  6574. * // => objects for ['pebbles']
  6575. *
  6576. * // The `_.property` iteratee shorthand.
  6577. * _.dropWhile(users, 'active');
  6578. * // => objects for ['barney', 'fred', 'pebbles']
  6579. */
  6580. function dropWhile(array, predicate) {
  6581. return (array && array.length)
  6582. ? baseWhile(array, getIteratee(predicate, 3), true)
  6583. : [];
  6584. }
  6585. /**
  6586. * Fills elements of `array` with `value` from `start` up to, but not
  6587. * including, `end`.
  6588. *
  6589. * **Note:** This method mutates `array`.
  6590. *
  6591. * @static
  6592. * @memberOf _
  6593. * @since 3.2.0
  6594. * @category Array
  6595. * @param {Array} array The array to fill.
  6596. * @param {*} value The value to fill `array` with.
  6597. * @param {number} [start=0] The start position.
  6598. * @param {number} [end=array.length] The end position.
  6599. * @returns {Array} Returns `array`.
  6600. * @example
  6601. *
  6602. * var array = [1, 2, 3];
  6603. *
  6604. * _.fill(array, 'a');
  6605. * console.log(array);
  6606. * // => ['a', 'a', 'a']
  6607. *
  6608. * _.fill(Array(3), 2);
  6609. * // => [2, 2, 2]
  6610. *
  6611. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6612. * // => [4, '*', '*', 10]
  6613. */
  6614. function fill(array, value, start, end) {
  6615. var length = array == null ? 0 : array.length;
  6616. if (!length) {
  6617. return [];
  6618. }
  6619. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6620. start = 0;
  6621. end = length;
  6622. }
  6623. return baseFill(array, value, start, end);
  6624. }
  6625. /**
  6626. * This method is like `_.find` except that it returns the index of the first
  6627. * element `predicate` returns truthy for instead of the element itself.
  6628. *
  6629. * @static
  6630. * @memberOf _
  6631. * @since 1.1.0
  6632. * @category Array
  6633. * @param {Array} array The array to inspect.
  6634. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6635. * @param {number} [fromIndex=0] The index to search from.
  6636. * @returns {number} Returns the index of the found element, else `-1`.
  6637. * @example
  6638. *
  6639. * var users = [
  6640. * { 'user': 'barney', 'active': false },
  6641. * { 'user': 'fred', 'active': false },
  6642. * { 'user': 'pebbles', 'active': true }
  6643. * ];
  6644. *
  6645. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6646. * // => 0
  6647. *
  6648. * // The `_.matches` iteratee shorthand.
  6649. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6650. * // => 1
  6651. *
  6652. * // The `_.matchesProperty` iteratee shorthand.
  6653. * _.findIndex(users, ['active', false]);
  6654. * // => 0
  6655. *
  6656. * // The `_.property` iteratee shorthand.
  6657. * _.findIndex(users, 'active');
  6658. * // => 2
  6659. */
  6660. function findIndex(array, predicate, fromIndex) {
  6661. var length = array == null ? 0 : array.length;
  6662. if (!length) {
  6663. return -1;
  6664. }
  6665. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6666. if (index < 0) {
  6667. index = nativeMax(length + index, 0);
  6668. }
  6669. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6670. }
  6671. /**
  6672. * This method is like `_.findIndex` except that it iterates over elements
  6673. * of `collection` from right to left.
  6674. *
  6675. * @static
  6676. * @memberOf _
  6677. * @since 2.0.0
  6678. * @category Array
  6679. * @param {Array} array The array to inspect.
  6680. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6681. * @param {number} [fromIndex=array.length-1] The index to search from.
  6682. * @returns {number} Returns the index of the found element, else `-1`.
  6683. * @example
  6684. *
  6685. * var users = [
  6686. * { 'user': 'barney', 'active': true },
  6687. * { 'user': 'fred', 'active': false },
  6688. * { 'user': 'pebbles', 'active': false }
  6689. * ];
  6690. *
  6691. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6692. * // => 2
  6693. *
  6694. * // The `_.matches` iteratee shorthand.
  6695. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6696. * // => 0
  6697. *
  6698. * // The `_.matchesProperty` iteratee shorthand.
  6699. * _.findLastIndex(users, ['active', false]);
  6700. * // => 2
  6701. *
  6702. * // The `_.property` iteratee shorthand.
  6703. * _.findLastIndex(users, 'active');
  6704. * // => 0
  6705. */
  6706. function findLastIndex(array, predicate, fromIndex) {
  6707. var length = array == null ? 0 : array.length;
  6708. if (!length) {
  6709. return -1;
  6710. }
  6711. var index = length - 1;
  6712. if (fromIndex !== undefined) {
  6713. index = toInteger(fromIndex);
  6714. index = fromIndex < 0
  6715. ? nativeMax(length + index, 0)
  6716. : nativeMin(index, length - 1);
  6717. }
  6718. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6719. }
  6720. /**
  6721. * Flattens `array` a single level deep.
  6722. *
  6723. * @static
  6724. * @memberOf _
  6725. * @since 0.1.0
  6726. * @category Array
  6727. * @param {Array} array The array to flatten.
  6728. * @returns {Array} Returns the new flattened array.
  6729. * @example
  6730. *
  6731. * _.flatten([1, [2, [3, [4]], 5]]);
  6732. * // => [1, 2, [3, [4]], 5]
  6733. */
  6734. function flatten(array) {
  6735. var length = array == null ? 0 : array.length;
  6736. return length ? baseFlatten(array, 1) : [];
  6737. }
  6738. /**
  6739. * Recursively flattens `array`.
  6740. *
  6741. * @static
  6742. * @memberOf _
  6743. * @since 3.0.0
  6744. * @category Array
  6745. * @param {Array} array The array to flatten.
  6746. * @returns {Array} Returns the new flattened array.
  6747. * @example
  6748. *
  6749. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6750. * // => [1, 2, 3, 4, 5]
  6751. */
  6752. function flattenDeep(array) {
  6753. var length = array == null ? 0 : array.length;
  6754. return length ? baseFlatten(array, INFINITY) : [];
  6755. }
  6756. /**
  6757. * Recursively flatten `array` up to `depth` times.
  6758. *
  6759. * @static
  6760. * @memberOf _
  6761. * @since 4.4.0
  6762. * @category Array
  6763. * @param {Array} array The array to flatten.
  6764. * @param {number} [depth=1] The maximum recursion depth.
  6765. * @returns {Array} Returns the new flattened array.
  6766. * @example
  6767. *
  6768. * var array = [1, [2, [3, [4]], 5]];
  6769. *
  6770. * _.flattenDepth(array, 1);
  6771. * // => [1, 2, [3, [4]], 5]
  6772. *
  6773. * _.flattenDepth(array, 2);
  6774. * // => [1, 2, 3, [4], 5]
  6775. */
  6776. function flattenDepth(array, depth) {
  6777. var length = array == null ? 0 : array.length;
  6778. if (!length) {
  6779. return [];
  6780. }
  6781. depth = depth === undefined ? 1 : toInteger(depth);
  6782. return baseFlatten(array, depth);
  6783. }
  6784. /**
  6785. * The inverse of `_.toPairs`; this method returns an object composed
  6786. * from key-value `pairs`.
  6787. *
  6788. * @static
  6789. * @memberOf _
  6790. * @since 4.0.0
  6791. * @category Array
  6792. * @param {Array} pairs The key-value pairs.
  6793. * @returns {Object} Returns the new object.
  6794. * @example
  6795. *
  6796. * _.fromPairs([['a', 1], ['b', 2]]);
  6797. * // => { 'a': 1, 'b': 2 }
  6798. */
  6799. function fromPairs(pairs) {
  6800. var index = -1,
  6801. length = pairs == null ? 0 : pairs.length,
  6802. result = {};
  6803. while (++index < length) {
  6804. var pair = pairs[index];
  6805. result[pair[0]] = pair[1];
  6806. }
  6807. return result;
  6808. }
  6809. /**
  6810. * Gets the first element of `array`.
  6811. *
  6812. * @static
  6813. * @memberOf _
  6814. * @since 0.1.0
  6815. * @alias first
  6816. * @category Array
  6817. * @param {Array} array The array to query.
  6818. * @returns {*} Returns the first element of `array`.
  6819. * @example
  6820. *
  6821. * _.head([1, 2, 3]);
  6822. * // => 1
  6823. *
  6824. * _.head([]);
  6825. * // => undefined
  6826. */
  6827. function head(array) {
  6828. return (array && array.length) ? array[0] : undefined;
  6829. }
  6830. /**
  6831. * Gets the index at which the first occurrence of `value` is found in `array`
  6832. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6833. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6834. * offset from the end of `array`.
  6835. *
  6836. * @static
  6837. * @memberOf _
  6838. * @since 0.1.0
  6839. * @category Array
  6840. * @param {Array} array The array to inspect.
  6841. * @param {*} value The value to search for.
  6842. * @param {number} [fromIndex=0] The index to search from.
  6843. * @returns {number} Returns the index of the matched value, else `-1`.
  6844. * @example
  6845. *
  6846. * _.indexOf([1, 2, 1, 2], 2);
  6847. * // => 1
  6848. *
  6849. * // Search from the `fromIndex`.
  6850. * _.indexOf([1, 2, 1, 2], 2, 2);
  6851. * // => 3
  6852. */
  6853. function indexOf(array, value, fromIndex) {
  6854. var length = array == null ? 0 : array.length;
  6855. if (!length) {
  6856. return -1;
  6857. }
  6858. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6859. if (index < 0) {
  6860. index = nativeMax(length + index, 0);
  6861. }
  6862. return baseIndexOf(array, value, index);
  6863. }
  6864. /**
  6865. * Gets all but the last element of `array`.
  6866. *
  6867. * @static
  6868. * @memberOf _
  6869. * @since 0.1.0
  6870. * @category Array
  6871. * @param {Array} array The array to query.
  6872. * @returns {Array} Returns the slice of `array`.
  6873. * @example
  6874. *
  6875. * _.initial([1, 2, 3]);
  6876. * // => [1, 2]
  6877. */
  6878. function initial(array) {
  6879. var length = array == null ? 0 : array.length;
  6880. return length ? baseSlice(array, 0, -1) : [];
  6881. }
  6882. /**
  6883. * Creates an array of unique values that are included in all given arrays
  6884. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6885. * for equality comparisons. The order and references of result values are
  6886. * determined by the first array.
  6887. *
  6888. * @static
  6889. * @memberOf _
  6890. * @since 0.1.0
  6891. * @category Array
  6892. * @param {...Array} [arrays] The arrays to inspect.
  6893. * @returns {Array} Returns the new array of intersecting values.
  6894. * @example
  6895. *
  6896. * _.intersection([2, 1], [2, 3]);
  6897. * // => [2]
  6898. */
  6899. var intersection = baseRest(function(arrays) {
  6900. var mapped = arrayMap(arrays, castArrayLikeObject);
  6901. return (mapped.length && mapped[0] === arrays[0])
  6902. ? baseIntersection(mapped)
  6903. : [];
  6904. });
  6905. /**
  6906. * This method is like `_.intersection` except that it accepts `iteratee`
  6907. * which is invoked for each element of each `arrays` to generate the criterion
  6908. * by which they're compared. The order and references of result values are
  6909. * determined by the first array. The iteratee is invoked with one argument:
  6910. * (value).
  6911. *
  6912. * @static
  6913. * @memberOf _
  6914. * @since 4.0.0
  6915. * @category Array
  6916. * @param {...Array} [arrays] The arrays to inspect.
  6917. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6918. * @returns {Array} Returns the new array of intersecting values.
  6919. * @example
  6920. *
  6921. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6922. * // => [2.1]
  6923. *
  6924. * // The `_.property` iteratee shorthand.
  6925. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6926. * // => [{ 'x': 1 }]
  6927. */
  6928. var intersectionBy = baseRest(function(arrays) {
  6929. var iteratee = last(arrays),
  6930. mapped = arrayMap(arrays, castArrayLikeObject);
  6931. if (iteratee === last(mapped)) {
  6932. iteratee = undefined;
  6933. } else {
  6934. mapped.pop();
  6935. }
  6936. return (mapped.length && mapped[0] === arrays[0])
  6937. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6938. : [];
  6939. });
  6940. /**
  6941. * This method is like `_.intersection` except that it accepts `comparator`
  6942. * which is invoked to compare elements of `arrays`. The order and references
  6943. * of result values are determined by the first array. The comparator is
  6944. * invoked with two arguments: (arrVal, othVal).
  6945. *
  6946. * @static
  6947. * @memberOf _
  6948. * @since 4.0.0
  6949. * @category Array
  6950. * @param {...Array} [arrays] The arrays to inspect.
  6951. * @param {Function} [comparator] The comparator invoked per element.
  6952. * @returns {Array} Returns the new array of intersecting values.
  6953. * @example
  6954. *
  6955. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6956. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6957. *
  6958. * _.intersectionWith(objects, others, _.isEqual);
  6959. * // => [{ 'x': 1, 'y': 2 }]
  6960. */
  6961. var intersectionWith = baseRest(function(arrays) {
  6962. var comparator = last(arrays),
  6963. mapped = arrayMap(arrays, castArrayLikeObject);
  6964. comparator = typeof comparator == 'function' ? comparator : undefined;
  6965. if (comparator) {
  6966. mapped.pop();
  6967. }
  6968. return (mapped.length && mapped[0] === arrays[0])
  6969. ? baseIntersection(mapped, undefined, comparator)
  6970. : [];
  6971. });
  6972. /**
  6973. * Converts all elements in `array` into a string separated by `separator`.
  6974. *
  6975. * @static
  6976. * @memberOf _
  6977. * @since 4.0.0
  6978. * @category Array
  6979. * @param {Array} array The array to convert.
  6980. * @param {string} [separator=','] The element separator.
  6981. * @returns {string} Returns the joined string.
  6982. * @example
  6983. *
  6984. * _.join(['a', 'b', 'c'], '~');
  6985. * // => 'a~b~c'
  6986. */
  6987. function join(array, separator) {
  6988. return array == null ? '' : nativeJoin.call(array, separator);
  6989. }
  6990. /**
  6991. * Gets the last element of `array`.
  6992. *
  6993. * @static
  6994. * @memberOf _
  6995. * @since 0.1.0
  6996. * @category Array
  6997. * @param {Array} array The array to query.
  6998. * @returns {*} Returns the last element of `array`.
  6999. * @example
  7000. *
  7001. * _.last([1, 2, 3]);
  7002. * // => 3
  7003. */
  7004. function last(array) {
  7005. var length = array == null ? 0 : array.length;
  7006. return length ? array[length - 1] : undefined;
  7007. }
  7008. /**
  7009. * This method is like `_.indexOf` except that it iterates over elements of
  7010. * `array` from right to left.
  7011. *
  7012. * @static
  7013. * @memberOf _
  7014. * @since 0.1.0
  7015. * @category Array
  7016. * @param {Array} array The array to inspect.
  7017. * @param {*} value The value to search for.
  7018. * @param {number} [fromIndex=array.length-1] The index to search from.
  7019. * @returns {number} Returns the index of the matched value, else `-1`.
  7020. * @example
  7021. *
  7022. * _.lastIndexOf([1, 2, 1, 2], 2);
  7023. * // => 3
  7024. *
  7025. * // Search from the `fromIndex`.
  7026. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7027. * // => 1
  7028. */
  7029. function lastIndexOf(array, value, fromIndex) {
  7030. var length = array == null ? 0 : array.length;
  7031. if (!length) {
  7032. return -1;
  7033. }
  7034. var index = length;
  7035. if (fromIndex !== undefined) {
  7036. index = toInteger(fromIndex);
  7037. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7038. }
  7039. return value === value
  7040. ? strictLastIndexOf(array, value, index)
  7041. : baseFindIndex(array, baseIsNaN, index, true);
  7042. }
  7043. /**
  7044. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7045. * element from the end is returned.
  7046. *
  7047. * @static
  7048. * @memberOf _
  7049. * @since 4.11.0
  7050. * @category Array
  7051. * @param {Array} array The array to query.
  7052. * @param {number} [n=0] The index of the element to return.
  7053. * @returns {*} Returns the nth element of `array`.
  7054. * @example
  7055. *
  7056. * var array = ['a', 'b', 'c', 'd'];
  7057. *
  7058. * _.nth(array, 1);
  7059. * // => 'b'
  7060. *
  7061. * _.nth(array, -2);
  7062. * // => 'c';
  7063. */
  7064. function nth(array, n) {
  7065. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7066. }
  7067. /**
  7068. * Removes all given values from `array` using
  7069. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7070. * for equality comparisons.
  7071. *
  7072. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7073. * to remove elements from an array by predicate.
  7074. *
  7075. * @static
  7076. * @memberOf _
  7077. * @since 2.0.0
  7078. * @category Array
  7079. * @param {Array} array The array to modify.
  7080. * @param {...*} [values] The values to remove.
  7081. * @returns {Array} Returns `array`.
  7082. * @example
  7083. *
  7084. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7085. *
  7086. * _.pull(array, 'a', 'c');
  7087. * console.log(array);
  7088. * // => ['b', 'b']
  7089. */
  7090. var pull = baseRest(pullAll);
  7091. /**
  7092. * This method is like `_.pull` except that it accepts an array of values to remove.
  7093. *
  7094. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7095. *
  7096. * @static
  7097. * @memberOf _
  7098. * @since 4.0.0
  7099. * @category Array
  7100. * @param {Array} array The array to modify.
  7101. * @param {Array} values The values to remove.
  7102. * @returns {Array} Returns `array`.
  7103. * @example
  7104. *
  7105. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7106. *
  7107. * _.pullAll(array, ['a', 'c']);
  7108. * console.log(array);
  7109. * // => ['b', 'b']
  7110. */
  7111. function pullAll(array, values) {
  7112. return (array && array.length && values && values.length)
  7113. ? basePullAll(array, values)
  7114. : array;
  7115. }
  7116. /**
  7117. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7118. * invoked for each element of `array` and `values` to generate the criterion
  7119. * by which they're compared. The iteratee is invoked with one argument: (value).
  7120. *
  7121. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7122. *
  7123. * @static
  7124. * @memberOf _
  7125. * @since 4.0.0
  7126. * @category Array
  7127. * @param {Array} array The array to modify.
  7128. * @param {Array} values The values to remove.
  7129. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7130. * @returns {Array} Returns `array`.
  7131. * @example
  7132. *
  7133. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7134. *
  7135. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7136. * console.log(array);
  7137. * // => [{ 'x': 2 }]
  7138. */
  7139. function pullAllBy(array, values, iteratee) {
  7140. return (array && array.length && values && values.length)
  7141. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7142. : array;
  7143. }
  7144. /**
  7145. * This method is like `_.pullAll` except that it accepts `comparator` which
  7146. * is invoked to compare elements of `array` to `values`. The comparator is
  7147. * invoked with two arguments: (arrVal, othVal).
  7148. *
  7149. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7150. *
  7151. * @static
  7152. * @memberOf _
  7153. * @since 4.6.0
  7154. * @category Array
  7155. * @param {Array} array The array to modify.
  7156. * @param {Array} values The values to remove.
  7157. * @param {Function} [comparator] The comparator invoked per element.
  7158. * @returns {Array} Returns `array`.
  7159. * @example
  7160. *
  7161. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7162. *
  7163. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7164. * console.log(array);
  7165. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7166. */
  7167. function pullAllWith(array, values, comparator) {
  7168. return (array && array.length && values && values.length)
  7169. ? basePullAll(array, values, undefined, comparator)
  7170. : array;
  7171. }
  7172. /**
  7173. * Removes elements from `array` corresponding to `indexes` and returns an
  7174. * array of removed elements.
  7175. *
  7176. * **Note:** Unlike `_.at`, this method mutates `array`.
  7177. *
  7178. * @static
  7179. * @memberOf _
  7180. * @since 3.0.0
  7181. * @category Array
  7182. * @param {Array} array The array to modify.
  7183. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7184. * @returns {Array} Returns the new array of removed elements.
  7185. * @example
  7186. *
  7187. * var array = ['a', 'b', 'c', 'd'];
  7188. * var pulled = _.pullAt(array, [1, 3]);
  7189. *
  7190. * console.log(array);
  7191. * // => ['a', 'c']
  7192. *
  7193. * console.log(pulled);
  7194. * // => ['b', 'd']
  7195. */
  7196. var pullAt = flatRest(function(array, indexes) {
  7197. var length = array == null ? 0 : array.length,
  7198. result = baseAt(array, indexes);
  7199. basePullAt(array, arrayMap(indexes, function(index) {
  7200. return isIndex(index, length) ? +index : index;
  7201. }).sort(compareAscending));
  7202. return result;
  7203. });
  7204. /**
  7205. * Removes all elements from `array` that `predicate` returns truthy for
  7206. * and returns an array of the removed elements. The predicate is invoked
  7207. * with three arguments: (value, index, array).
  7208. *
  7209. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7210. * to pull elements from an array by value.
  7211. *
  7212. * @static
  7213. * @memberOf _
  7214. * @since 2.0.0
  7215. * @category Array
  7216. * @param {Array} array The array to modify.
  7217. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7218. * @returns {Array} Returns the new array of removed elements.
  7219. * @example
  7220. *
  7221. * var array = [1, 2, 3, 4];
  7222. * var evens = _.remove(array, function(n) {
  7223. * return n % 2 == 0;
  7224. * });
  7225. *
  7226. * console.log(array);
  7227. * // => [1, 3]
  7228. *
  7229. * console.log(evens);
  7230. * // => [2, 4]
  7231. */
  7232. function remove(array, predicate) {
  7233. var result = [];
  7234. if (!(array && array.length)) {
  7235. return result;
  7236. }
  7237. var index = -1,
  7238. indexes = [],
  7239. length = array.length;
  7240. predicate = getIteratee(predicate, 3);
  7241. while (++index < length) {
  7242. var value = array[index];
  7243. if (predicate(value, index, array)) {
  7244. result.push(value);
  7245. indexes.push(index);
  7246. }
  7247. }
  7248. basePullAt(array, indexes);
  7249. return result;
  7250. }
  7251. /**
  7252. * Reverses `array` so that the first element becomes the last, the second
  7253. * element becomes the second to last, and so on.
  7254. *
  7255. * **Note:** This method mutates `array` and is based on
  7256. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7257. *
  7258. * @static
  7259. * @memberOf _
  7260. * @since 4.0.0
  7261. * @category Array
  7262. * @param {Array} array The array to modify.
  7263. * @returns {Array} Returns `array`.
  7264. * @example
  7265. *
  7266. * var array = [1, 2, 3];
  7267. *
  7268. * _.reverse(array);
  7269. * // => [3, 2, 1]
  7270. *
  7271. * console.log(array);
  7272. * // => [3, 2, 1]
  7273. */
  7274. function reverse(array) {
  7275. return array == null ? array : nativeReverse.call(array);
  7276. }
  7277. /**
  7278. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7279. *
  7280. * **Note:** This method is used instead of
  7281. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7282. * returned.
  7283. *
  7284. * @static
  7285. * @memberOf _
  7286. * @since 3.0.0
  7287. * @category Array
  7288. * @param {Array} array The array to slice.
  7289. * @param {number} [start=0] The start position.
  7290. * @param {number} [end=array.length] The end position.
  7291. * @returns {Array} Returns the slice of `array`.
  7292. */
  7293. function slice(array, start, end) {
  7294. var length = array == null ? 0 : array.length;
  7295. if (!length) {
  7296. return [];
  7297. }
  7298. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7299. start = 0;
  7300. end = length;
  7301. }
  7302. else {
  7303. start = start == null ? 0 : toInteger(start);
  7304. end = end === undefined ? length : toInteger(end);
  7305. }
  7306. return baseSlice(array, start, end);
  7307. }
  7308. /**
  7309. * Uses a binary search to determine the lowest index at which `value`
  7310. * should be inserted into `array` in order to maintain its sort order.
  7311. *
  7312. * @static
  7313. * @memberOf _
  7314. * @since 0.1.0
  7315. * @category Array
  7316. * @param {Array} array The sorted array to inspect.
  7317. * @param {*} value The value to evaluate.
  7318. * @returns {number} Returns the index at which `value` should be inserted
  7319. * into `array`.
  7320. * @example
  7321. *
  7322. * _.sortedIndex([30, 50], 40);
  7323. * // => 1
  7324. */
  7325. function sortedIndex(array, value) {
  7326. return baseSortedIndex(array, value);
  7327. }
  7328. /**
  7329. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7330. * which is invoked for `value` and each element of `array` to compute their
  7331. * sort ranking. The iteratee is invoked with one argument: (value).
  7332. *
  7333. * @static
  7334. * @memberOf _
  7335. * @since 4.0.0
  7336. * @category Array
  7337. * @param {Array} array The sorted array to inspect.
  7338. * @param {*} value The value to evaluate.
  7339. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7340. * @returns {number} Returns the index at which `value` should be inserted
  7341. * into `array`.
  7342. * @example
  7343. *
  7344. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7345. *
  7346. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7347. * // => 0
  7348. *
  7349. * // The `_.property` iteratee shorthand.
  7350. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7351. * // => 0
  7352. */
  7353. function sortedIndexBy(array, value, iteratee) {
  7354. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7355. }
  7356. /**
  7357. * This method is like `_.indexOf` except that it performs a binary
  7358. * search on a sorted `array`.
  7359. *
  7360. * @static
  7361. * @memberOf _
  7362. * @since 4.0.0
  7363. * @category Array
  7364. * @param {Array} array The array to inspect.
  7365. * @param {*} value The value to search for.
  7366. * @returns {number} Returns the index of the matched value, else `-1`.
  7367. * @example
  7368. *
  7369. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7370. * // => 1
  7371. */
  7372. function sortedIndexOf(array, value) {
  7373. var length = array == null ? 0 : array.length;
  7374. if (length) {
  7375. var index = baseSortedIndex(array, value);
  7376. if (index < length && eq(array[index], value)) {
  7377. return index;
  7378. }
  7379. }
  7380. return -1;
  7381. }
  7382. /**
  7383. * This method is like `_.sortedIndex` except that it returns the highest
  7384. * index at which `value` should be inserted into `array` in order to
  7385. * maintain its sort order.
  7386. *
  7387. * @static
  7388. * @memberOf _
  7389. * @since 3.0.0
  7390. * @category Array
  7391. * @param {Array} array The sorted array to inspect.
  7392. * @param {*} value The value to evaluate.
  7393. * @returns {number} Returns the index at which `value` should be inserted
  7394. * into `array`.
  7395. * @example
  7396. *
  7397. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7398. * // => 4
  7399. */
  7400. function sortedLastIndex(array, value) {
  7401. return baseSortedIndex(array, value, true);
  7402. }
  7403. /**
  7404. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7405. * which is invoked for `value` and each element of `array` to compute their
  7406. * sort ranking. The iteratee is invoked with one argument: (value).
  7407. *
  7408. * @static
  7409. * @memberOf _
  7410. * @since 4.0.0
  7411. * @category Array
  7412. * @param {Array} array The sorted array to inspect.
  7413. * @param {*} value The value to evaluate.
  7414. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7415. * @returns {number} Returns the index at which `value` should be inserted
  7416. * into `array`.
  7417. * @example
  7418. *
  7419. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7420. *
  7421. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7422. * // => 1
  7423. *
  7424. * // The `_.property` iteratee shorthand.
  7425. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7426. * // => 1
  7427. */
  7428. function sortedLastIndexBy(array, value, iteratee) {
  7429. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7430. }
  7431. /**
  7432. * This method is like `_.lastIndexOf` except that it performs a binary
  7433. * search on a sorted `array`.
  7434. *
  7435. * @static
  7436. * @memberOf _
  7437. * @since 4.0.0
  7438. * @category Array
  7439. * @param {Array} array The array to inspect.
  7440. * @param {*} value The value to search for.
  7441. * @returns {number} Returns the index of the matched value, else `-1`.
  7442. * @example
  7443. *
  7444. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7445. * // => 3
  7446. */
  7447. function sortedLastIndexOf(array, value) {
  7448. var length = array == null ? 0 : array.length;
  7449. if (length) {
  7450. var index = baseSortedIndex(array, value, true) - 1;
  7451. if (eq(array[index], value)) {
  7452. return index;
  7453. }
  7454. }
  7455. return -1;
  7456. }
  7457. /**
  7458. * This method is like `_.uniq` 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. * @returns {Array} Returns the new duplicate free array.
  7467. * @example
  7468. *
  7469. * _.sortedUniq([1, 1, 2]);
  7470. * // => [1, 2]
  7471. */
  7472. function sortedUniq(array) {
  7473. return (array && array.length)
  7474. ? baseSortedUniq(array)
  7475. : [];
  7476. }
  7477. /**
  7478. * This method is like `_.uniqBy` except that it's designed and optimized
  7479. * for sorted arrays.
  7480. *
  7481. * @static
  7482. * @memberOf _
  7483. * @since 4.0.0
  7484. * @category Array
  7485. * @param {Array} array The array to inspect.
  7486. * @param {Function} [iteratee] The iteratee invoked per element.
  7487. * @returns {Array} Returns the new duplicate free array.
  7488. * @example
  7489. *
  7490. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7491. * // => [1.1, 2.3]
  7492. */
  7493. function sortedUniqBy(array, iteratee) {
  7494. return (array && array.length)
  7495. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7496. : [];
  7497. }
  7498. /**
  7499. * Gets all but the first element of `array`.
  7500. *
  7501. * @static
  7502. * @memberOf _
  7503. * @since 4.0.0
  7504. * @category Array
  7505. * @param {Array} array The array to query.
  7506. * @returns {Array} Returns the slice of `array`.
  7507. * @example
  7508. *
  7509. * _.tail([1, 2, 3]);
  7510. * // => [2, 3]
  7511. */
  7512. function tail(array) {
  7513. var length = array == null ? 0 : array.length;
  7514. return length ? baseSlice(array, 1, length) : [];
  7515. }
  7516. /**
  7517. * Creates a slice of `array` with `n` elements taken from the beginning.
  7518. *
  7519. * @static
  7520. * @memberOf _
  7521. * @since 0.1.0
  7522. * @category Array
  7523. * @param {Array} array The array to query.
  7524. * @param {number} [n=1] The number of elements to take.
  7525. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7526. * @returns {Array} Returns the slice of `array`.
  7527. * @example
  7528. *
  7529. * _.take([1, 2, 3]);
  7530. * // => [1]
  7531. *
  7532. * _.take([1, 2, 3], 2);
  7533. * // => [1, 2]
  7534. *
  7535. * _.take([1, 2, 3], 5);
  7536. * // => [1, 2, 3]
  7537. *
  7538. * _.take([1, 2, 3], 0);
  7539. * // => []
  7540. */
  7541. function take(array, n, guard) {
  7542. if (!(array && array.length)) {
  7543. return [];
  7544. }
  7545. n = (guard || n === undefined) ? 1 : toInteger(n);
  7546. return baseSlice(array, 0, n < 0 ? 0 : n);
  7547. }
  7548. /**
  7549. * Creates a slice of `array` with `n` elements taken from the end.
  7550. *
  7551. * @static
  7552. * @memberOf _
  7553. * @since 3.0.0
  7554. * @category Array
  7555. * @param {Array} array The array to query.
  7556. * @param {number} [n=1] The number of elements to take.
  7557. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7558. * @returns {Array} Returns the slice of `array`.
  7559. * @example
  7560. *
  7561. * _.takeRight([1, 2, 3]);
  7562. * // => [3]
  7563. *
  7564. * _.takeRight([1, 2, 3], 2);
  7565. * // => [2, 3]
  7566. *
  7567. * _.takeRight([1, 2, 3], 5);
  7568. * // => [1, 2, 3]
  7569. *
  7570. * _.takeRight([1, 2, 3], 0);
  7571. * // => []
  7572. */
  7573. function takeRight(array, n, guard) {
  7574. var length = array == null ? 0 : array.length;
  7575. if (!length) {
  7576. return [];
  7577. }
  7578. n = (guard || n === undefined) ? 1 : toInteger(n);
  7579. n = length - n;
  7580. return baseSlice(array, n < 0 ? 0 : n, length);
  7581. }
  7582. /**
  7583. * Creates a slice of `array` with elements taken from the end. Elements are
  7584. * taken until `predicate` returns falsey. The predicate is invoked with
  7585. * three arguments: (value, index, array).
  7586. *
  7587. * @static
  7588. * @memberOf _
  7589. * @since 3.0.0
  7590. * @category Array
  7591. * @param {Array} array The array to query.
  7592. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7593. * @returns {Array} Returns the slice of `array`.
  7594. * @example
  7595. *
  7596. * var users = [
  7597. * { 'user': 'barney', 'active': true },
  7598. * { 'user': 'fred', 'active': false },
  7599. * { 'user': 'pebbles', 'active': false }
  7600. * ];
  7601. *
  7602. * _.takeRightWhile(users, function(o) { return !o.active; });
  7603. * // => objects for ['fred', 'pebbles']
  7604. *
  7605. * // The `_.matches` iteratee shorthand.
  7606. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7607. * // => objects for ['pebbles']
  7608. *
  7609. * // The `_.matchesProperty` iteratee shorthand.
  7610. * _.takeRightWhile(users, ['active', false]);
  7611. * // => objects for ['fred', 'pebbles']
  7612. *
  7613. * // The `_.property` iteratee shorthand.
  7614. * _.takeRightWhile(users, 'active');
  7615. * // => []
  7616. */
  7617. function takeRightWhile(array, predicate) {
  7618. return (array && array.length)
  7619. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7620. : [];
  7621. }
  7622. /**
  7623. * Creates a slice of `array` with elements taken from the beginning. Elements
  7624. * are taken until `predicate` returns falsey. The predicate is invoked with
  7625. * three arguments: (value, index, array).
  7626. *
  7627. * @static
  7628. * @memberOf _
  7629. * @since 3.0.0
  7630. * @category Array
  7631. * @param {Array} array The array to query.
  7632. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7633. * @returns {Array} Returns the slice of `array`.
  7634. * @example
  7635. *
  7636. * var users = [
  7637. * { 'user': 'barney', 'active': false },
  7638. * { 'user': 'fred', 'active': false },
  7639. * { 'user': 'pebbles', 'active': true }
  7640. * ];
  7641. *
  7642. * _.takeWhile(users, function(o) { return !o.active; });
  7643. * // => objects for ['barney', 'fred']
  7644. *
  7645. * // The `_.matches` iteratee shorthand.
  7646. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7647. * // => objects for ['barney']
  7648. *
  7649. * // The `_.matchesProperty` iteratee shorthand.
  7650. * _.takeWhile(users, ['active', false]);
  7651. * // => objects for ['barney', 'fred']
  7652. *
  7653. * // The `_.property` iteratee shorthand.
  7654. * _.takeWhile(users, 'active');
  7655. * // => []
  7656. */
  7657. function takeWhile(array, predicate) {
  7658. return (array && array.length)
  7659. ? baseWhile(array, getIteratee(predicate, 3))
  7660. : [];
  7661. }
  7662. /**
  7663. * Creates an array of unique values, in order, from all given arrays using
  7664. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7665. * for equality comparisons.
  7666. *
  7667. * @static
  7668. * @memberOf _
  7669. * @since 0.1.0
  7670. * @category Array
  7671. * @param {...Array} [arrays] The arrays to inspect.
  7672. * @returns {Array} Returns the new array of combined values.
  7673. * @example
  7674. *
  7675. * _.union([2], [1, 2]);
  7676. * // => [2, 1]
  7677. */
  7678. var union = baseRest(function(arrays) {
  7679. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7680. });
  7681. /**
  7682. * This method is like `_.union` except that it accepts `iteratee` which is
  7683. * invoked for each element of each `arrays` to generate the criterion by
  7684. * which uniqueness is computed. Result values are chosen from the first
  7685. * array in which the value occurs. The iteratee is invoked with one argument:
  7686. * (value).
  7687. *
  7688. * @static
  7689. * @memberOf _
  7690. * @since 4.0.0
  7691. * @category Array
  7692. * @param {...Array} [arrays] The arrays to inspect.
  7693. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7694. * @returns {Array} Returns the new array of combined values.
  7695. * @example
  7696. *
  7697. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7698. * // => [2.1, 1.2]
  7699. *
  7700. * // The `_.property` iteratee shorthand.
  7701. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7702. * // => [{ 'x': 1 }, { 'x': 2 }]
  7703. */
  7704. var unionBy = baseRest(function(arrays) {
  7705. var iteratee = last(arrays);
  7706. if (isArrayLikeObject(iteratee)) {
  7707. iteratee = undefined;
  7708. }
  7709. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7710. });
  7711. /**
  7712. * This method is like `_.union` except that it accepts `comparator` which
  7713. * is invoked to compare elements of `arrays`. Result values are chosen from
  7714. * the first array in which the value occurs. The comparator is invoked
  7715. * with two arguments: (arrVal, othVal).
  7716. *
  7717. * @static
  7718. * @memberOf _
  7719. * @since 4.0.0
  7720. * @category Array
  7721. * @param {...Array} [arrays] The arrays to inspect.
  7722. * @param {Function} [comparator] The comparator invoked per element.
  7723. * @returns {Array} Returns the new array of combined values.
  7724. * @example
  7725. *
  7726. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7727. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7728. *
  7729. * _.unionWith(objects, others, _.isEqual);
  7730. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7731. */
  7732. var unionWith = baseRest(function(arrays) {
  7733. var comparator = last(arrays);
  7734. comparator = typeof comparator == 'function' ? comparator : undefined;
  7735. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7736. });
  7737. /**
  7738. * Creates a duplicate-free version of an array, using
  7739. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7740. * for equality comparisons, in which only the first occurrence of each element
  7741. * is kept. The order of result values is determined by the order they occur
  7742. * in the array.
  7743. *
  7744. * @static
  7745. * @memberOf _
  7746. * @since 0.1.0
  7747. * @category Array
  7748. * @param {Array} array The array to inspect.
  7749. * @returns {Array} Returns the new duplicate free array.
  7750. * @example
  7751. *
  7752. * _.uniq([2, 1, 2]);
  7753. * // => [2, 1]
  7754. */
  7755. function uniq(array) {
  7756. return (array && array.length) ? baseUniq(array) : [];
  7757. }
  7758. /**
  7759. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7760. * invoked for each element in `array` to generate the criterion by which
  7761. * uniqueness is computed. The order of result values is determined by the
  7762. * order they occur in the array. The iteratee is invoked with one argument:
  7763. * (value).
  7764. *
  7765. * @static
  7766. * @memberOf _
  7767. * @since 4.0.0
  7768. * @category Array
  7769. * @param {Array} array The array to inspect.
  7770. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7771. * @returns {Array} Returns the new duplicate free array.
  7772. * @example
  7773. *
  7774. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7775. * // => [2.1, 1.2]
  7776. *
  7777. * // The `_.property` iteratee shorthand.
  7778. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7779. * // => [{ 'x': 1 }, { 'x': 2 }]
  7780. */
  7781. function uniqBy(array, iteratee) {
  7782. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7783. }
  7784. /**
  7785. * This method is like `_.uniq` except that it accepts `comparator` which
  7786. * is invoked to compare elements of `array`. The order of result values is
  7787. * determined by the order they occur in the array.The comparator is invoked
  7788. * with two arguments: (arrVal, othVal).
  7789. *
  7790. * @static
  7791. * @memberOf _
  7792. * @since 4.0.0
  7793. * @category Array
  7794. * @param {Array} array The array to inspect.
  7795. * @param {Function} [comparator] The comparator invoked per element.
  7796. * @returns {Array} Returns the new duplicate free array.
  7797. * @example
  7798. *
  7799. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7800. *
  7801. * _.uniqWith(objects, _.isEqual);
  7802. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7803. */
  7804. function uniqWith(array, comparator) {
  7805. comparator = typeof comparator == 'function' ? comparator : undefined;
  7806. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7807. }
  7808. /**
  7809. * This method is like `_.zip` except that it accepts an array of grouped
  7810. * elements and creates an array regrouping the elements to their pre-zip
  7811. * configuration.
  7812. *
  7813. * @static
  7814. * @memberOf _
  7815. * @since 1.2.0
  7816. * @category Array
  7817. * @param {Array} array The array of grouped elements to process.
  7818. * @returns {Array} Returns the new array of regrouped elements.
  7819. * @example
  7820. *
  7821. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7822. * // => [['a', 1, true], ['b', 2, false]]
  7823. *
  7824. * _.unzip(zipped);
  7825. * // => [['a', 'b'], [1, 2], [true, false]]
  7826. */
  7827. function unzip(array) {
  7828. if (!(array && array.length)) {
  7829. return [];
  7830. }
  7831. var length = 0;
  7832. array = arrayFilter(array, function(group) {
  7833. if (isArrayLikeObject(group)) {
  7834. length = nativeMax(group.length, length);
  7835. return true;
  7836. }
  7837. });
  7838. return baseTimes(length, function(index) {
  7839. return arrayMap(array, baseProperty(index));
  7840. });
  7841. }
  7842. /**
  7843. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7844. * how regrouped values should be combined. The iteratee is invoked with the
  7845. * elements of each group: (...group).
  7846. *
  7847. * @static
  7848. * @memberOf _
  7849. * @since 3.8.0
  7850. * @category Array
  7851. * @param {Array} array The array of grouped elements to process.
  7852. * @param {Function} [iteratee=_.identity] The function to combine
  7853. * regrouped values.
  7854. * @returns {Array} Returns the new array of regrouped elements.
  7855. * @example
  7856. *
  7857. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7858. * // => [[1, 10, 100], [2, 20, 200]]
  7859. *
  7860. * _.unzipWith(zipped, _.add);
  7861. * // => [3, 30, 300]
  7862. */
  7863. function unzipWith(array, iteratee) {
  7864. if (!(array && array.length)) {
  7865. return [];
  7866. }
  7867. var result = unzip(array);
  7868. if (iteratee == null) {
  7869. return result;
  7870. }
  7871. return arrayMap(result, function(group) {
  7872. return apply(iteratee, undefined, group);
  7873. });
  7874. }
  7875. /**
  7876. * Creates an array excluding all given values using
  7877. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7878. * for equality comparisons.
  7879. *
  7880. * **Note:** Unlike `_.pull`, this method returns a new array.
  7881. *
  7882. * @static
  7883. * @memberOf _
  7884. * @since 0.1.0
  7885. * @category Array
  7886. * @param {Array} array The array to inspect.
  7887. * @param {...*} [values] The values to exclude.
  7888. * @returns {Array} Returns the new array of filtered values.
  7889. * @see _.difference, _.xor
  7890. * @example
  7891. *
  7892. * _.without([2, 1, 2, 3], 1, 2);
  7893. * // => [3]
  7894. */
  7895. var without = baseRest(function(array, values) {
  7896. return isArrayLikeObject(array)
  7897. ? baseDifference(array, values)
  7898. : [];
  7899. });
  7900. /**
  7901. * Creates an array of unique values that is the
  7902. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7903. * of the given arrays. The order of result values is determined by the order
  7904. * they occur in the arrays.
  7905. *
  7906. * @static
  7907. * @memberOf _
  7908. * @since 2.4.0
  7909. * @category Array
  7910. * @param {...Array} [arrays] The arrays to inspect.
  7911. * @returns {Array} Returns the new array of filtered values.
  7912. * @see _.difference, _.without
  7913. * @example
  7914. *
  7915. * _.xor([2, 1], [2, 3]);
  7916. * // => [1, 3]
  7917. */
  7918. var xor = baseRest(function(arrays) {
  7919. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7920. });
  7921. /**
  7922. * This method is like `_.xor` except that it accepts `iteratee` which is
  7923. * invoked for each element of each `arrays` to generate the criterion by
  7924. * which by which they're compared. The order of result values is determined
  7925. * by the order they occur in the arrays. The iteratee is invoked with one
  7926. * argument: (value).
  7927. *
  7928. * @static
  7929. * @memberOf _
  7930. * @since 4.0.0
  7931. * @category Array
  7932. * @param {...Array} [arrays] The arrays to inspect.
  7933. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7934. * @returns {Array} Returns the new array of filtered values.
  7935. * @example
  7936. *
  7937. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7938. * // => [1.2, 3.4]
  7939. *
  7940. * // The `_.property` iteratee shorthand.
  7941. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7942. * // => [{ 'x': 2 }]
  7943. */
  7944. var xorBy = baseRest(function(arrays) {
  7945. var iteratee = last(arrays);
  7946. if (isArrayLikeObject(iteratee)) {
  7947. iteratee = undefined;
  7948. }
  7949. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7950. });
  7951. /**
  7952. * This method is like `_.xor` except that it accepts `comparator` which is
  7953. * invoked to compare elements of `arrays`. The order of result values is
  7954. * determined by the order they occur in the arrays. The comparator is invoked
  7955. * with two arguments: (arrVal, othVal).
  7956. *
  7957. * @static
  7958. * @memberOf _
  7959. * @since 4.0.0
  7960. * @category Array
  7961. * @param {...Array} [arrays] The arrays to inspect.
  7962. * @param {Function} [comparator] The comparator invoked per element.
  7963. * @returns {Array} Returns the new array of filtered values.
  7964. * @example
  7965. *
  7966. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7967. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7968. *
  7969. * _.xorWith(objects, others, _.isEqual);
  7970. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7971. */
  7972. var xorWith = baseRest(function(arrays) {
  7973. var comparator = last(arrays);
  7974. comparator = typeof comparator == 'function' ? comparator : undefined;
  7975. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7976. });
  7977. /**
  7978. * Creates an array of grouped elements, the first of which contains the
  7979. * first elements of the given arrays, the second of which contains the
  7980. * second elements of the given arrays, and so on.
  7981. *
  7982. * @static
  7983. * @memberOf _
  7984. * @since 0.1.0
  7985. * @category Array
  7986. * @param {...Array} [arrays] The arrays to process.
  7987. * @returns {Array} Returns the new array of grouped elements.
  7988. * @example
  7989. *
  7990. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7991. * // => [['a', 1, true], ['b', 2, false]]
  7992. */
  7993. var zip = baseRest(unzip);
  7994. /**
  7995. * This method is like `_.fromPairs` except that it accepts two arrays,
  7996. * one of property identifiers and one of corresponding values.
  7997. *
  7998. * @static
  7999. * @memberOf _
  8000. * @since 0.4.0
  8001. * @category Array
  8002. * @param {Array} [props=[]] The property identifiers.
  8003. * @param {Array} [values=[]] The property values.
  8004. * @returns {Object} Returns the new object.
  8005. * @example
  8006. *
  8007. * _.zipObject(['a', 'b'], [1, 2]);
  8008. * // => { 'a': 1, 'b': 2 }
  8009. */
  8010. function zipObject(props, values) {
  8011. return baseZipObject(props || [], values || [], assignValue);
  8012. }
  8013. /**
  8014. * This method is like `_.zipObject` except that it supports property paths.
  8015. *
  8016. * @static
  8017. * @memberOf _
  8018. * @since 4.1.0
  8019. * @category Array
  8020. * @param {Array} [props=[]] The property identifiers.
  8021. * @param {Array} [values=[]] The property values.
  8022. * @returns {Object} Returns the new object.
  8023. * @example
  8024. *
  8025. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8026. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8027. */
  8028. function zipObjectDeep(props, values) {
  8029. return baseZipObject(props || [], values || [], baseSet);
  8030. }
  8031. /**
  8032. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8033. * how grouped values should be combined. The iteratee is invoked with the
  8034. * elements of each group: (...group).
  8035. *
  8036. * @static
  8037. * @memberOf _
  8038. * @since 3.8.0
  8039. * @category Array
  8040. * @param {...Array} [arrays] The arrays to process.
  8041. * @param {Function} [iteratee=_.identity] The function to combine
  8042. * grouped values.
  8043. * @returns {Array} Returns the new array of grouped elements.
  8044. * @example
  8045. *
  8046. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8047. * return a + b + c;
  8048. * });
  8049. * // => [111, 222]
  8050. */
  8051. var zipWith = baseRest(function(arrays) {
  8052. var length = arrays.length,
  8053. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8054. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8055. return unzipWith(arrays, iteratee);
  8056. });
  8057. /*------------------------------------------------------------------------*/
  8058. /**
  8059. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8060. * chain sequences enabled. The result of such sequences must be unwrapped
  8061. * with `_#value`.
  8062. *
  8063. * @static
  8064. * @memberOf _
  8065. * @since 1.3.0
  8066. * @category Seq
  8067. * @param {*} value The value to wrap.
  8068. * @returns {Object} Returns the new `lodash` wrapper instance.
  8069. * @example
  8070. *
  8071. * var users = [
  8072. * { 'user': 'barney', 'age': 36 },
  8073. * { 'user': 'fred', 'age': 40 },
  8074. * { 'user': 'pebbles', 'age': 1 }
  8075. * ];
  8076. *
  8077. * var youngest = _
  8078. * .chain(users)
  8079. * .sortBy('age')
  8080. * .map(function(o) {
  8081. * return o.user + ' is ' + o.age;
  8082. * })
  8083. * .head()
  8084. * .value();
  8085. * // => 'pebbles is 1'
  8086. */
  8087. function chain(value) {
  8088. var result = lodash(value);
  8089. result.__chain__ = true;
  8090. return result;
  8091. }
  8092. /**
  8093. * This method invokes `interceptor` and returns `value`. The interceptor
  8094. * is invoked with one argument; (value). The purpose of this method is to
  8095. * "tap into" a method chain sequence in order to modify intermediate results.
  8096. *
  8097. * @static
  8098. * @memberOf _
  8099. * @since 0.1.0
  8100. * @category Seq
  8101. * @param {*} value The value to provide to `interceptor`.
  8102. * @param {Function} interceptor The function to invoke.
  8103. * @returns {*} Returns `value`.
  8104. * @example
  8105. *
  8106. * _([1, 2, 3])
  8107. * .tap(function(array) {
  8108. * // Mutate input array.
  8109. * array.pop();
  8110. * })
  8111. * .reverse()
  8112. * .value();
  8113. * // => [2, 1]
  8114. */
  8115. function tap(value, interceptor) {
  8116. interceptor(value);
  8117. return value;
  8118. }
  8119. /**
  8120. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8121. * The purpose of this method is to "pass thru" values replacing intermediate
  8122. * results in a method chain sequence.
  8123. *
  8124. * @static
  8125. * @memberOf _
  8126. * @since 3.0.0
  8127. * @category Seq
  8128. * @param {*} value The value to provide to `interceptor`.
  8129. * @param {Function} interceptor The function to invoke.
  8130. * @returns {*} Returns the result of `interceptor`.
  8131. * @example
  8132. *
  8133. * _(' abc ')
  8134. * .chain()
  8135. * .trim()
  8136. * .thru(function(value) {
  8137. * return [value];
  8138. * })
  8139. * .value();
  8140. * // => ['abc']
  8141. */
  8142. function thru(value, interceptor) {
  8143. return interceptor(value);
  8144. }
  8145. /**
  8146. * This method is the wrapper version of `_.at`.
  8147. *
  8148. * @name at
  8149. * @memberOf _
  8150. * @since 1.0.0
  8151. * @category Seq
  8152. * @param {...(string|string[])} [paths] The property paths to pick.
  8153. * @returns {Object} Returns the new `lodash` wrapper instance.
  8154. * @example
  8155. *
  8156. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8157. *
  8158. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8159. * // => [3, 4]
  8160. */
  8161. var wrapperAt = flatRest(function(paths) {
  8162. var length = paths.length,
  8163. start = length ? paths[0] : 0,
  8164. value = this.__wrapped__,
  8165. interceptor = function(object) { return baseAt(object, paths); };
  8166. if (length > 1 || this.__actions__.length ||
  8167. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8168. return this.thru(interceptor);
  8169. }
  8170. value = value.slice(start, +start + (length ? 1 : 0));
  8171. value.__actions__.push({
  8172. 'func': thru,
  8173. 'args': [interceptor],
  8174. 'thisArg': undefined
  8175. });
  8176. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8177. if (length && !array.length) {
  8178. array.push(undefined);
  8179. }
  8180. return array;
  8181. });
  8182. });
  8183. /**
  8184. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8185. *
  8186. * @name chain
  8187. * @memberOf _
  8188. * @since 0.1.0
  8189. * @category Seq
  8190. * @returns {Object} Returns the new `lodash` wrapper instance.
  8191. * @example
  8192. *
  8193. * var users = [
  8194. * { 'user': 'barney', 'age': 36 },
  8195. * { 'user': 'fred', 'age': 40 }
  8196. * ];
  8197. *
  8198. * // A sequence without explicit chaining.
  8199. * _(users).head();
  8200. * // => { 'user': 'barney', 'age': 36 }
  8201. *
  8202. * // A sequence with explicit chaining.
  8203. * _(users)
  8204. * .chain()
  8205. * .head()
  8206. * .pick('user')
  8207. * .value();
  8208. * // => { 'user': 'barney' }
  8209. */
  8210. function wrapperChain() {
  8211. return chain(this);
  8212. }
  8213. /**
  8214. * Executes the chain sequence and returns the wrapped result.
  8215. *
  8216. * @name commit
  8217. * @memberOf _
  8218. * @since 3.2.0
  8219. * @category Seq
  8220. * @returns {Object} Returns the new `lodash` wrapper instance.
  8221. * @example
  8222. *
  8223. * var array = [1, 2];
  8224. * var wrapped = _(array).push(3);
  8225. *
  8226. * console.log(array);
  8227. * // => [1, 2]
  8228. *
  8229. * wrapped = wrapped.commit();
  8230. * console.log(array);
  8231. * // => [1, 2, 3]
  8232. *
  8233. * wrapped.last();
  8234. * // => 3
  8235. *
  8236. * console.log(array);
  8237. * // => [1, 2, 3]
  8238. */
  8239. function wrapperCommit() {
  8240. return new LodashWrapper(this.value(), this.__chain__);
  8241. }
  8242. /**
  8243. * Gets the next value on a wrapped object following the
  8244. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8245. *
  8246. * @name next
  8247. * @memberOf _
  8248. * @since 4.0.0
  8249. * @category Seq
  8250. * @returns {Object} Returns the next iterator value.
  8251. * @example
  8252. *
  8253. * var wrapped = _([1, 2]);
  8254. *
  8255. * wrapped.next();
  8256. * // => { 'done': false, 'value': 1 }
  8257. *
  8258. * wrapped.next();
  8259. * // => { 'done': false, 'value': 2 }
  8260. *
  8261. * wrapped.next();
  8262. * // => { 'done': true, 'value': undefined }
  8263. */
  8264. function wrapperNext() {
  8265. if (this.__values__ === undefined) {
  8266. this.__values__ = toArray(this.value());
  8267. }
  8268. var done = this.__index__ >= this.__values__.length,
  8269. value = done ? undefined : this.__values__[this.__index__++];
  8270. return { 'done': done, 'value': value };
  8271. }
  8272. /**
  8273. * Enables the wrapper to be iterable.
  8274. *
  8275. * @name Symbol.iterator
  8276. * @memberOf _
  8277. * @since 4.0.0
  8278. * @category Seq
  8279. * @returns {Object} Returns the wrapper object.
  8280. * @example
  8281. *
  8282. * var wrapped = _([1, 2]);
  8283. *
  8284. * wrapped[Symbol.iterator]() === wrapped;
  8285. * // => true
  8286. *
  8287. * Array.from(wrapped);
  8288. * // => [1, 2]
  8289. */
  8290. function wrapperToIterator() {
  8291. return this;
  8292. }
  8293. /**
  8294. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8295. *
  8296. * @name plant
  8297. * @memberOf _
  8298. * @since 3.2.0
  8299. * @category Seq
  8300. * @param {*} value The value to plant.
  8301. * @returns {Object} Returns the new `lodash` wrapper instance.
  8302. * @example
  8303. *
  8304. * function square(n) {
  8305. * return n * n;
  8306. * }
  8307. *
  8308. * var wrapped = _([1, 2]).map(square);
  8309. * var other = wrapped.plant([3, 4]);
  8310. *
  8311. * other.value();
  8312. * // => [9, 16]
  8313. *
  8314. * wrapped.value();
  8315. * // => [1, 4]
  8316. */
  8317. function wrapperPlant(value) {
  8318. var result,
  8319. parent = this;
  8320. while (parent instanceof baseLodash) {
  8321. var clone = wrapperClone(parent);
  8322. clone.__index__ = 0;
  8323. clone.__values__ = undefined;
  8324. if (result) {
  8325. previous.__wrapped__ = clone;
  8326. } else {
  8327. result = clone;
  8328. }
  8329. var previous = clone;
  8330. parent = parent.__wrapped__;
  8331. }
  8332. previous.__wrapped__ = value;
  8333. return result;
  8334. }
  8335. /**
  8336. * This method is the wrapper version of `_.reverse`.
  8337. *
  8338. * **Note:** This method mutates the wrapped array.
  8339. *
  8340. * @name reverse
  8341. * @memberOf _
  8342. * @since 0.1.0
  8343. * @category Seq
  8344. * @returns {Object} Returns the new `lodash` wrapper instance.
  8345. * @example
  8346. *
  8347. * var array = [1, 2, 3];
  8348. *
  8349. * _(array).reverse().value()
  8350. * // => [3, 2, 1]
  8351. *
  8352. * console.log(array);
  8353. * // => [3, 2, 1]
  8354. */
  8355. function wrapperReverse() {
  8356. var value = this.__wrapped__;
  8357. if (value instanceof LazyWrapper) {
  8358. var wrapped = value;
  8359. if (this.__actions__.length) {
  8360. wrapped = new LazyWrapper(this);
  8361. }
  8362. wrapped = wrapped.reverse();
  8363. wrapped.__actions__.push({
  8364. 'func': thru,
  8365. 'args': [reverse],
  8366. 'thisArg': undefined
  8367. });
  8368. return new LodashWrapper(wrapped, this.__chain__);
  8369. }
  8370. return this.thru(reverse);
  8371. }
  8372. /**
  8373. * Executes the chain sequence to resolve the unwrapped value.
  8374. *
  8375. * @name value
  8376. * @memberOf _
  8377. * @since 0.1.0
  8378. * @alias toJSON, valueOf
  8379. * @category Seq
  8380. * @returns {*} Returns the resolved unwrapped value.
  8381. * @example
  8382. *
  8383. * _([1, 2, 3]).value();
  8384. * // => [1, 2, 3]
  8385. */
  8386. function wrapperValue() {
  8387. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8388. }
  8389. /*------------------------------------------------------------------------*/
  8390. /**
  8391. * Creates an object composed of keys generated from the results of running
  8392. * each element of `collection` thru `iteratee`. The corresponding value of
  8393. * each key is the number of times the key was returned by `iteratee`. The
  8394. * iteratee is invoked with one argument: (value).
  8395. *
  8396. * @static
  8397. * @memberOf _
  8398. * @since 0.5.0
  8399. * @category Collection
  8400. * @param {Array|Object} collection The collection to iterate over.
  8401. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8402. * @returns {Object} Returns the composed aggregate object.
  8403. * @example
  8404. *
  8405. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8406. * // => { '4': 1, '6': 2 }
  8407. *
  8408. * // The `_.property` iteratee shorthand.
  8409. * _.countBy(['one', 'two', 'three'], 'length');
  8410. * // => { '3': 2, '5': 1 }
  8411. */
  8412. var countBy = createAggregator(function(result, value, key) {
  8413. if (hasOwnProperty.call(result, key)) {
  8414. ++result[key];
  8415. } else {
  8416. baseAssignValue(result, key, 1);
  8417. }
  8418. });
  8419. /**
  8420. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8421. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8422. * invoked with three arguments: (value, index|key, collection).
  8423. *
  8424. * **Note:** This method returns `true` for
  8425. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8426. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8427. * elements of empty collections.
  8428. *
  8429. * @static
  8430. * @memberOf _
  8431. * @since 0.1.0
  8432. * @category Collection
  8433. * @param {Array|Object} collection The collection to iterate over.
  8434. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8435. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8436. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8437. * else `false`.
  8438. * @example
  8439. *
  8440. * _.every([true, 1, null, 'yes'], Boolean);
  8441. * // => false
  8442. *
  8443. * var users = [
  8444. * { 'user': 'barney', 'age': 36, 'active': false },
  8445. * { 'user': 'fred', 'age': 40, 'active': false }
  8446. * ];
  8447. *
  8448. * // The `_.matches` iteratee shorthand.
  8449. * _.every(users, { 'user': 'barney', 'active': false });
  8450. * // => false
  8451. *
  8452. * // The `_.matchesProperty` iteratee shorthand.
  8453. * _.every(users, ['active', false]);
  8454. * // => true
  8455. *
  8456. * // The `_.property` iteratee shorthand.
  8457. * _.every(users, 'active');
  8458. * // => false
  8459. */
  8460. function every(collection, predicate, guard) {
  8461. var func = isArray(collection) ? arrayEvery : baseEvery;
  8462. if (guard && isIterateeCall(collection, predicate, guard)) {
  8463. predicate = undefined;
  8464. }
  8465. return func(collection, getIteratee(predicate, 3));
  8466. }
  8467. /**
  8468. * Iterates over elements of `collection`, returning an array of all elements
  8469. * `predicate` returns truthy for. The predicate is invoked with three
  8470. * arguments: (value, index|key, collection).
  8471. *
  8472. * **Note:** Unlike `_.remove`, this method returns a new array.
  8473. *
  8474. * @static
  8475. * @memberOf _
  8476. * @since 0.1.0
  8477. * @category Collection
  8478. * @param {Array|Object} collection The collection to iterate over.
  8479. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8480. * @returns {Array} Returns the new filtered array.
  8481. * @see _.reject
  8482. * @example
  8483. *
  8484. * var users = [
  8485. * { 'user': 'barney', 'age': 36, 'active': true },
  8486. * { 'user': 'fred', 'age': 40, 'active': false }
  8487. * ];
  8488. *
  8489. * _.filter(users, function(o) { return !o.active; });
  8490. * // => objects for ['fred']
  8491. *
  8492. * // The `_.matches` iteratee shorthand.
  8493. * _.filter(users, { 'age': 36, 'active': true });
  8494. * // => objects for ['barney']
  8495. *
  8496. * // The `_.matchesProperty` iteratee shorthand.
  8497. * _.filter(users, ['active', false]);
  8498. * // => objects for ['fred']
  8499. *
  8500. * // The `_.property` iteratee shorthand.
  8501. * _.filter(users, 'active');
  8502. * // => objects for ['barney']
  8503. *
  8504. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  8505. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  8506. * // => objects for ['fred', 'barney']
  8507. */
  8508. function filter(collection, predicate) {
  8509. var func = isArray(collection) ? arrayFilter : baseFilter;
  8510. return func(collection, getIteratee(predicate, 3));
  8511. }
  8512. /**
  8513. * Iterates over elements of `collection`, returning the first element
  8514. * `predicate` returns truthy for. The predicate is invoked with three
  8515. * arguments: (value, index|key, collection).
  8516. *
  8517. * @static
  8518. * @memberOf _
  8519. * @since 0.1.0
  8520. * @category Collection
  8521. * @param {Array|Object} collection The collection to inspect.
  8522. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8523. * @param {number} [fromIndex=0] The index to search from.
  8524. * @returns {*} Returns the matched element, else `undefined`.
  8525. * @example
  8526. *
  8527. * var users = [
  8528. * { 'user': 'barney', 'age': 36, 'active': true },
  8529. * { 'user': 'fred', 'age': 40, 'active': false },
  8530. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8531. * ];
  8532. *
  8533. * _.find(users, function(o) { return o.age < 40; });
  8534. * // => object for 'barney'
  8535. *
  8536. * // The `_.matches` iteratee shorthand.
  8537. * _.find(users, { 'age': 1, 'active': true });
  8538. * // => object for 'pebbles'
  8539. *
  8540. * // The `_.matchesProperty` iteratee shorthand.
  8541. * _.find(users, ['active', false]);
  8542. * // => object for 'fred'
  8543. *
  8544. * // The `_.property` iteratee shorthand.
  8545. * _.find(users, 'active');
  8546. * // => object for 'barney'
  8547. */
  8548. var find = createFind(findIndex);
  8549. /**
  8550. * This method is like `_.find` except that it iterates over elements of
  8551. * `collection` from right to left.
  8552. *
  8553. * @static
  8554. * @memberOf _
  8555. * @since 2.0.0
  8556. * @category Collection
  8557. * @param {Array|Object} collection The collection to inspect.
  8558. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8559. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8560. * @returns {*} Returns the matched element, else `undefined`.
  8561. * @example
  8562. *
  8563. * _.findLast([1, 2, 3, 4], function(n) {
  8564. * return n % 2 == 1;
  8565. * });
  8566. * // => 3
  8567. */
  8568. var findLast = createFind(findLastIndex);
  8569. /**
  8570. * Creates a flattened array of values by running each element in `collection`
  8571. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8572. * with three arguments: (value, index|key, collection).
  8573. *
  8574. * @static
  8575. * @memberOf _
  8576. * @since 4.0.0
  8577. * @category Collection
  8578. * @param {Array|Object} collection The collection to iterate over.
  8579. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8580. * @returns {Array} Returns the new flattened array.
  8581. * @example
  8582. *
  8583. * function duplicate(n) {
  8584. * return [n, n];
  8585. * }
  8586. *
  8587. * _.flatMap([1, 2], duplicate);
  8588. * // => [1, 1, 2, 2]
  8589. */
  8590. function flatMap(collection, iteratee) {
  8591. return baseFlatten(map(collection, iteratee), 1);
  8592. }
  8593. /**
  8594. * This method is like `_.flatMap` except that it recursively flattens the
  8595. * mapped results.
  8596. *
  8597. * @static
  8598. * @memberOf _
  8599. * @since 4.7.0
  8600. * @category Collection
  8601. * @param {Array|Object} collection The collection to iterate over.
  8602. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8603. * @returns {Array} Returns the new flattened array.
  8604. * @example
  8605. *
  8606. * function duplicate(n) {
  8607. * return [[[n, n]]];
  8608. * }
  8609. *
  8610. * _.flatMapDeep([1, 2], duplicate);
  8611. * // => [1, 1, 2, 2]
  8612. */
  8613. function flatMapDeep(collection, iteratee) {
  8614. return baseFlatten(map(collection, iteratee), INFINITY);
  8615. }
  8616. /**
  8617. * This method is like `_.flatMap` except that it recursively flattens the
  8618. * mapped results up to `depth` times.
  8619. *
  8620. * @static
  8621. * @memberOf _
  8622. * @since 4.7.0
  8623. * @category Collection
  8624. * @param {Array|Object} collection The collection to iterate over.
  8625. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8626. * @param {number} [depth=1] The maximum recursion depth.
  8627. * @returns {Array} Returns the new flattened array.
  8628. * @example
  8629. *
  8630. * function duplicate(n) {
  8631. * return [[[n, n]]];
  8632. * }
  8633. *
  8634. * _.flatMapDepth([1, 2], duplicate, 2);
  8635. * // => [[1, 1], [2, 2]]
  8636. */
  8637. function flatMapDepth(collection, iteratee, depth) {
  8638. depth = depth === undefined ? 1 : toInteger(depth);
  8639. return baseFlatten(map(collection, iteratee), depth);
  8640. }
  8641. /**
  8642. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8643. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8644. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8645. *
  8646. * **Note:** As with other "Collections" methods, objects with a "length"
  8647. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8648. * or `_.forOwn` for object iteration.
  8649. *
  8650. * @static
  8651. * @memberOf _
  8652. * @since 0.1.0
  8653. * @alias each
  8654. * @category Collection
  8655. * @param {Array|Object} collection The collection to iterate over.
  8656. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8657. * @returns {Array|Object} Returns `collection`.
  8658. * @see _.forEachRight
  8659. * @example
  8660. *
  8661. * _.forEach([1, 2], function(value) {
  8662. * console.log(value);
  8663. * });
  8664. * // => Logs `1` then `2`.
  8665. *
  8666. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8667. * console.log(key);
  8668. * });
  8669. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8670. */
  8671. function forEach(collection, iteratee) {
  8672. var func = isArray(collection) ? arrayEach : baseEach;
  8673. return func(collection, getIteratee(iteratee, 3));
  8674. }
  8675. /**
  8676. * This method is like `_.forEach` except that it iterates over elements of
  8677. * `collection` from right to left.
  8678. *
  8679. * @static
  8680. * @memberOf _
  8681. * @since 2.0.0
  8682. * @alias eachRight
  8683. * @category Collection
  8684. * @param {Array|Object} collection The collection to iterate over.
  8685. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8686. * @returns {Array|Object} Returns `collection`.
  8687. * @see _.forEach
  8688. * @example
  8689. *
  8690. * _.forEachRight([1, 2], function(value) {
  8691. * console.log(value);
  8692. * });
  8693. * // => Logs `2` then `1`.
  8694. */
  8695. function forEachRight(collection, iteratee) {
  8696. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8697. return func(collection, getIteratee(iteratee, 3));
  8698. }
  8699. /**
  8700. * Creates an object composed of keys generated from the results of running
  8701. * each element of `collection` thru `iteratee`. The order of grouped values
  8702. * is determined by the order they occur in `collection`. The corresponding
  8703. * value of each key is an array of elements responsible for generating the
  8704. * key. The iteratee is invoked with one argument: (value).
  8705. *
  8706. * @static
  8707. * @memberOf _
  8708. * @since 0.1.0
  8709. * @category Collection
  8710. * @param {Array|Object} collection The collection to iterate over.
  8711. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8712. * @returns {Object} Returns the composed aggregate object.
  8713. * @example
  8714. *
  8715. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8716. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8717. *
  8718. * // The `_.property` iteratee shorthand.
  8719. * _.groupBy(['one', 'two', 'three'], 'length');
  8720. * // => { '3': ['one', 'two'], '5': ['three'] }
  8721. */
  8722. var groupBy = createAggregator(function(result, value, key) {
  8723. if (hasOwnProperty.call(result, key)) {
  8724. result[key].push(value);
  8725. } else {
  8726. baseAssignValue(result, key, [value]);
  8727. }
  8728. });
  8729. /**
  8730. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8731. * checked for a substring of `value`, otherwise
  8732. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8733. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8734. * the offset from the end of `collection`.
  8735. *
  8736. * @static
  8737. * @memberOf _
  8738. * @since 0.1.0
  8739. * @category Collection
  8740. * @param {Array|Object|string} collection The collection to inspect.
  8741. * @param {*} value The value to search for.
  8742. * @param {number} [fromIndex=0] The index to search from.
  8743. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8744. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8745. * @example
  8746. *
  8747. * _.includes([1, 2, 3], 1);
  8748. * // => true
  8749. *
  8750. * _.includes([1, 2, 3], 1, 2);
  8751. * // => false
  8752. *
  8753. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8754. * // => true
  8755. *
  8756. * _.includes('abcd', 'bc');
  8757. * // => true
  8758. */
  8759. function includes(collection, value, fromIndex, guard) {
  8760. collection = isArrayLike(collection) ? collection : values(collection);
  8761. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8762. var length = collection.length;
  8763. if (fromIndex < 0) {
  8764. fromIndex = nativeMax(length + fromIndex, 0);
  8765. }
  8766. return isString(collection)
  8767. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8768. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8769. }
  8770. /**
  8771. * Invokes the method at `path` of each element in `collection`, returning
  8772. * an array of the results of each invoked method. Any additional arguments
  8773. * are provided to each invoked method. If `path` is a function, it's invoked
  8774. * for, and `this` bound to, each element in `collection`.
  8775. *
  8776. * @static
  8777. * @memberOf _
  8778. * @since 4.0.0
  8779. * @category Collection
  8780. * @param {Array|Object} collection The collection to iterate over.
  8781. * @param {Array|Function|string} path The path of the method to invoke or
  8782. * the function invoked per iteration.
  8783. * @param {...*} [args] The arguments to invoke each method with.
  8784. * @returns {Array} Returns the array of results.
  8785. * @example
  8786. *
  8787. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8788. * // => [[1, 5, 7], [1, 2, 3]]
  8789. *
  8790. * _.invokeMap([123, 456], String.prototype.split, '');
  8791. * // => [['1', '2', '3'], ['4', '5', '6']]
  8792. */
  8793. var invokeMap = baseRest(function(collection, path, args) {
  8794. var index = -1,
  8795. isFunc = typeof path == 'function',
  8796. result = isArrayLike(collection) ? Array(collection.length) : [];
  8797. baseEach(collection, function(value) {
  8798. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8799. });
  8800. return result;
  8801. });
  8802. /**
  8803. * Creates an object composed of keys generated from the results of running
  8804. * each element of `collection` thru `iteratee`. The corresponding value of
  8805. * each key is the last element responsible for generating the key. The
  8806. * iteratee is invoked with one argument: (value).
  8807. *
  8808. * @static
  8809. * @memberOf _
  8810. * @since 4.0.0
  8811. * @category Collection
  8812. * @param {Array|Object} collection The collection to iterate over.
  8813. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8814. * @returns {Object} Returns the composed aggregate object.
  8815. * @example
  8816. *
  8817. * var array = [
  8818. * { 'dir': 'left', 'code': 97 },
  8819. * { 'dir': 'right', 'code': 100 }
  8820. * ];
  8821. *
  8822. * _.keyBy(array, function(o) {
  8823. * return String.fromCharCode(o.code);
  8824. * });
  8825. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8826. *
  8827. * _.keyBy(array, 'dir');
  8828. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8829. */
  8830. var keyBy = createAggregator(function(result, value, key) {
  8831. baseAssignValue(result, key, value);
  8832. });
  8833. /**
  8834. * Creates an array of values by running each element in `collection` thru
  8835. * `iteratee`. The iteratee is invoked with three arguments:
  8836. * (value, index|key, collection).
  8837. *
  8838. * Many lodash methods are guarded to work as iteratees for methods like
  8839. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8840. *
  8841. * The guarded methods are:
  8842. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8843. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8844. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8845. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8846. *
  8847. * @static
  8848. * @memberOf _
  8849. * @since 0.1.0
  8850. * @category Collection
  8851. * @param {Array|Object} collection The collection to iterate over.
  8852. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8853. * @returns {Array} Returns the new mapped array.
  8854. * @example
  8855. *
  8856. * function square(n) {
  8857. * return n * n;
  8858. * }
  8859. *
  8860. * _.map([4, 8], square);
  8861. * // => [16, 64]
  8862. *
  8863. * _.map({ 'a': 4, 'b': 8 }, square);
  8864. * // => [16, 64] (iteration order is not guaranteed)
  8865. *
  8866. * var users = [
  8867. * { 'user': 'barney' },
  8868. * { 'user': 'fred' }
  8869. * ];
  8870. *
  8871. * // The `_.property` iteratee shorthand.
  8872. * _.map(users, 'user');
  8873. * // => ['barney', 'fred']
  8874. */
  8875. function map(collection, iteratee) {
  8876. var func = isArray(collection) ? arrayMap : baseMap;
  8877. return func(collection, getIteratee(iteratee, 3));
  8878. }
  8879. /**
  8880. * This method is like `_.sortBy` except that it allows specifying the sort
  8881. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8882. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8883. * descending or "asc" for ascending sort order of corresponding values.
  8884. *
  8885. * @static
  8886. * @memberOf _
  8887. * @since 4.0.0
  8888. * @category Collection
  8889. * @param {Array|Object} collection The collection to iterate over.
  8890. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8891. * The iteratees to sort by.
  8892. * @param {string[]} [orders] The sort orders of `iteratees`.
  8893. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8894. * @returns {Array} Returns the new sorted array.
  8895. * @example
  8896. *
  8897. * var users = [
  8898. * { 'user': 'fred', 'age': 48 },
  8899. * { 'user': 'barney', 'age': 34 },
  8900. * { 'user': 'fred', 'age': 40 },
  8901. * { 'user': 'barney', 'age': 36 }
  8902. * ];
  8903. *
  8904. * // Sort by `user` in ascending order and by `age` in descending order.
  8905. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8906. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8907. */
  8908. function orderBy(collection, iteratees, orders, guard) {
  8909. if (collection == null) {
  8910. return [];
  8911. }
  8912. if (!isArray(iteratees)) {
  8913. iteratees = iteratees == null ? [] : [iteratees];
  8914. }
  8915. orders = guard ? undefined : orders;
  8916. if (!isArray(orders)) {
  8917. orders = orders == null ? [] : [orders];
  8918. }
  8919. return baseOrderBy(collection, iteratees, orders);
  8920. }
  8921. /**
  8922. * Creates an array of elements split into two groups, the first of which
  8923. * contains elements `predicate` returns truthy for, the second of which
  8924. * contains elements `predicate` returns falsey for. The predicate is
  8925. * invoked with one argument: (value).
  8926. *
  8927. * @static
  8928. * @memberOf _
  8929. * @since 3.0.0
  8930. * @category Collection
  8931. * @param {Array|Object} collection The collection to iterate over.
  8932. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8933. * @returns {Array} Returns the array of grouped elements.
  8934. * @example
  8935. *
  8936. * var users = [
  8937. * { 'user': 'barney', 'age': 36, 'active': false },
  8938. * { 'user': 'fred', 'age': 40, 'active': true },
  8939. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8940. * ];
  8941. *
  8942. * _.partition(users, function(o) { return o.active; });
  8943. * // => objects for [['fred'], ['barney', 'pebbles']]
  8944. *
  8945. * // The `_.matches` iteratee shorthand.
  8946. * _.partition(users, { 'age': 1, 'active': false });
  8947. * // => objects for [['pebbles'], ['barney', 'fred']]
  8948. *
  8949. * // The `_.matchesProperty` iteratee shorthand.
  8950. * _.partition(users, ['active', false]);
  8951. * // => objects for [['barney', 'pebbles'], ['fred']]
  8952. *
  8953. * // The `_.property` iteratee shorthand.
  8954. * _.partition(users, 'active');
  8955. * // => objects for [['fred'], ['barney', 'pebbles']]
  8956. */
  8957. var partition = createAggregator(function(result, value, key) {
  8958. result[key ? 0 : 1].push(value);
  8959. }, function() { return [[], []]; });
  8960. /**
  8961. * Reduces `collection` to a value which is the accumulated result of running
  8962. * each element in `collection` thru `iteratee`, where each successive
  8963. * invocation is supplied the return value of the previous. If `accumulator`
  8964. * is not given, the first element of `collection` is used as the initial
  8965. * value. The iteratee is invoked with four arguments:
  8966. * (accumulator, value, index|key, collection).
  8967. *
  8968. * Many lodash methods are guarded to work as iteratees for methods like
  8969. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8970. *
  8971. * The guarded methods are:
  8972. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8973. * and `sortBy`
  8974. *
  8975. * @static
  8976. * @memberOf _
  8977. * @since 0.1.0
  8978. * @category Collection
  8979. * @param {Array|Object} collection The collection to iterate over.
  8980. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8981. * @param {*} [accumulator] The initial value.
  8982. * @returns {*} Returns the accumulated value.
  8983. * @see _.reduceRight
  8984. * @example
  8985. *
  8986. * _.reduce([1, 2], function(sum, n) {
  8987. * return sum + n;
  8988. * }, 0);
  8989. * // => 3
  8990. *
  8991. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8992. * (result[value] || (result[value] = [])).push(key);
  8993. * return result;
  8994. * }, {});
  8995. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8996. */
  8997. function reduce(collection, iteratee, accumulator) {
  8998. var func = isArray(collection) ? arrayReduce : baseReduce,
  8999. initAccum = arguments.length < 3;
  9000. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  9001. }
  9002. /**
  9003. * This method is like `_.reduce` except that it iterates over elements of
  9004. * `collection` from right to left.
  9005. *
  9006. * @static
  9007. * @memberOf _
  9008. * @since 0.1.0
  9009. * @category Collection
  9010. * @param {Array|Object} collection The collection to iterate over.
  9011. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9012. * @param {*} [accumulator] The initial value.
  9013. * @returns {*} Returns the accumulated value.
  9014. * @see _.reduce
  9015. * @example
  9016. *
  9017. * var array = [[0, 1], [2, 3], [4, 5]];
  9018. *
  9019. * _.reduceRight(array, function(flattened, other) {
  9020. * return flattened.concat(other);
  9021. * }, []);
  9022. * // => [4, 5, 2, 3, 0, 1]
  9023. */
  9024. function reduceRight(collection, iteratee, accumulator) {
  9025. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9026. initAccum = arguments.length < 3;
  9027. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9028. }
  9029. /**
  9030. * The opposite of `_.filter`; this method returns the elements of `collection`
  9031. * that `predicate` does **not** return truthy for.
  9032. *
  9033. * @static
  9034. * @memberOf _
  9035. * @since 0.1.0
  9036. * @category Collection
  9037. * @param {Array|Object} collection The collection to iterate over.
  9038. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9039. * @returns {Array} Returns the new filtered array.
  9040. * @see _.filter
  9041. * @example
  9042. *
  9043. * var users = [
  9044. * { 'user': 'barney', 'age': 36, 'active': false },
  9045. * { 'user': 'fred', 'age': 40, 'active': true }
  9046. * ];
  9047. *
  9048. * _.reject(users, function(o) { return !o.active; });
  9049. * // => objects for ['fred']
  9050. *
  9051. * // The `_.matches` iteratee shorthand.
  9052. * _.reject(users, { 'age': 40, 'active': true });
  9053. * // => objects for ['barney']
  9054. *
  9055. * // The `_.matchesProperty` iteratee shorthand.
  9056. * _.reject(users, ['active', false]);
  9057. * // => objects for ['fred']
  9058. *
  9059. * // The `_.property` iteratee shorthand.
  9060. * _.reject(users, 'active');
  9061. * // => objects for ['barney']
  9062. */
  9063. function reject(collection, predicate) {
  9064. var func = isArray(collection) ? arrayFilter : baseFilter;
  9065. return func(collection, negate(getIteratee(predicate, 3)));
  9066. }
  9067. /**
  9068. * Gets a random element from `collection`.
  9069. *
  9070. * @static
  9071. * @memberOf _
  9072. * @since 2.0.0
  9073. * @category Collection
  9074. * @param {Array|Object} collection The collection to sample.
  9075. * @returns {*} Returns the random element.
  9076. * @example
  9077. *
  9078. * _.sample([1, 2, 3, 4]);
  9079. * // => 2
  9080. */
  9081. function sample(collection) {
  9082. var func = isArray(collection) ? arraySample : baseSample;
  9083. return func(collection);
  9084. }
  9085. /**
  9086. * Gets `n` random elements at unique keys from `collection` up to the
  9087. * size of `collection`.
  9088. *
  9089. * @static
  9090. * @memberOf _
  9091. * @since 4.0.0
  9092. * @category Collection
  9093. * @param {Array|Object} collection The collection to sample.
  9094. * @param {number} [n=1] The number of elements to sample.
  9095. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9096. * @returns {Array} Returns the random elements.
  9097. * @example
  9098. *
  9099. * _.sampleSize([1, 2, 3], 2);
  9100. * // => [3, 1]
  9101. *
  9102. * _.sampleSize([1, 2, 3], 4);
  9103. * // => [2, 3, 1]
  9104. */
  9105. function sampleSize(collection, n, guard) {
  9106. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9107. n = 1;
  9108. } else {
  9109. n = toInteger(n);
  9110. }
  9111. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9112. return func(collection, n);
  9113. }
  9114. /**
  9115. * Creates an array of shuffled values, using a version of the
  9116. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9117. *
  9118. * @static
  9119. * @memberOf _
  9120. * @since 0.1.0
  9121. * @category Collection
  9122. * @param {Array|Object} collection The collection to shuffle.
  9123. * @returns {Array} Returns the new shuffled array.
  9124. * @example
  9125. *
  9126. * _.shuffle([1, 2, 3, 4]);
  9127. * // => [4, 1, 3, 2]
  9128. */
  9129. function shuffle(collection) {
  9130. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9131. return func(collection);
  9132. }
  9133. /**
  9134. * Gets the size of `collection` by returning its length for array-like
  9135. * values or the number of own enumerable string keyed properties for objects.
  9136. *
  9137. * @static
  9138. * @memberOf _
  9139. * @since 0.1.0
  9140. * @category Collection
  9141. * @param {Array|Object|string} collection The collection to inspect.
  9142. * @returns {number} Returns the collection size.
  9143. * @example
  9144. *
  9145. * _.size([1, 2, 3]);
  9146. * // => 3
  9147. *
  9148. * _.size({ 'a': 1, 'b': 2 });
  9149. * // => 2
  9150. *
  9151. * _.size('pebbles');
  9152. * // => 7
  9153. */
  9154. function size(collection) {
  9155. if (collection == null) {
  9156. return 0;
  9157. }
  9158. if (isArrayLike(collection)) {
  9159. return isString(collection) ? stringSize(collection) : collection.length;
  9160. }
  9161. var tag = getTag(collection);
  9162. if (tag == mapTag || tag == setTag) {
  9163. return collection.size;
  9164. }
  9165. return baseKeys(collection).length;
  9166. }
  9167. /**
  9168. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9169. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9170. * invoked with three arguments: (value, index|key, collection).
  9171. *
  9172. * @static
  9173. * @memberOf _
  9174. * @since 0.1.0
  9175. * @category Collection
  9176. * @param {Array|Object} collection The collection to iterate over.
  9177. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9178. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9179. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9180. * else `false`.
  9181. * @example
  9182. *
  9183. * _.some([null, 0, 'yes', false], Boolean);
  9184. * // => true
  9185. *
  9186. * var users = [
  9187. * { 'user': 'barney', 'active': true },
  9188. * { 'user': 'fred', 'active': false }
  9189. * ];
  9190. *
  9191. * // The `_.matches` iteratee shorthand.
  9192. * _.some(users, { 'user': 'barney', 'active': false });
  9193. * // => false
  9194. *
  9195. * // The `_.matchesProperty` iteratee shorthand.
  9196. * _.some(users, ['active', false]);
  9197. * // => true
  9198. *
  9199. * // The `_.property` iteratee shorthand.
  9200. * _.some(users, 'active');
  9201. * // => true
  9202. */
  9203. function some(collection, predicate, guard) {
  9204. var func = isArray(collection) ? arraySome : baseSome;
  9205. if (guard && isIterateeCall(collection, predicate, guard)) {
  9206. predicate = undefined;
  9207. }
  9208. return func(collection, getIteratee(predicate, 3));
  9209. }
  9210. /**
  9211. * Creates an array of elements, sorted in ascending order by the results of
  9212. * running each element in a collection thru each iteratee. This method
  9213. * performs a stable sort, that is, it preserves the original sort order of
  9214. * equal elements. The iteratees are invoked with one argument: (value).
  9215. *
  9216. * @static
  9217. * @memberOf _
  9218. * @since 0.1.0
  9219. * @category Collection
  9220. * @param {Array|Object} collection The collection to iterate over.
  9221. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9222. * The iteratees to sort by.
  9223. * @returns {Array} Returns the new sorted array.
  9224. * @example
  9225. *
  9226. * var users = [
  9227. * { 'user': 'fred', 'age': 48 },
  9228. * { 'user': 'barney', 'age': 36 },
  9229. * { 'user': 'fred', 'age': 30 },
  9230. * { 'user': 'barney', 'age': 34 }
  9231. * ];
  9232. *
  9233. * _.sortBy(users, [function(o) { return o.user; }]);
  9234. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  9235. *
  9236. * _.sortBy(users, ['user', 'age']);
  9237. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  9238. */
  9239. var sortBy = baseRest(function(collection, iteratees) {
  9240. if (collection == null) {
  9241. return [];
  9242. }
  9243. var length = iteratees.length;
  9244. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9245. iteratees = [];
  9246. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9247. iteratees = [iteratees[0]];
  9248. }
  9249. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9250. });
  9251. /*------------------------------------------------------------------------*/
  9252. /**
  9253. * Gets the timestamp of the number of milliseconds that have elapsed since
  9254. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9255. *
  9256. * @static
  9257. * @memberOf _
  9258. * @since 2.4.0
  9259. * @category Date
  9260. * @returns {number} Returns the timestamp.
  9261. * @example
  9262. *
  9263. * _.defer(function(stamp) {
  9264. * console.log(_.now() - stamp);
  9265. * }, _.now());
  9266. * // => Logs the number of milliseconds it took for the deferred invocation.
  9267. */
  9268. var now = ctxNow || function() {
  9269. return root.Date.now();
  9270. };
  9271. /*------------------------------------------------------------------------*/
  9272. /**
  9273. * The opposite of `_.before`; this method creates a function that invokes
  9274. * `func` once it's called `n` or more times.
  9275. *
  9276. * @static
  9277. * @memberOf _
  9278. * @since 0.1.0
  9279. * @category Function
  9280. * @param {number} n The number of calls before `func` is invoked.
  9281. * @param {Function} func The function to restrict.
  9282. * @returns {Function} Returns the new restricted function.
  9283. * @example
  9284. *
  9285. * var saves = ['profile', 'settings'];
  9286. *
  9287. * var done = _.after(saves.length, function() {
  9288. * console.log('done saving!');
  9289. * });
  9290. *
  9291. * _.forEach(saves, function(type) {
  9292. * asyncSave({ 'type': type, 'complete': done });
  9293. * });
  9294. * // => Logs 'done saving!' after the two async saves have completed.
  9295. */
  9296. function after(n, func) {
  9297. if (typeof func != 'function') {
  9298. throw new TypeError(FUNC_ERROR_TEXT);
  9299. }
  9300. n = toInteger(n);
  9301. return function() {
  9302. if (--n < 1) {
  9303. return func.apply(this, arguments);
  9304. }
  9305. };
  9306. }
  9307. /**
  9308. * Creates a function that invokes `func`, with up to `n` arguments,
  9309. * ignoring any additional arguments.
  9310. *
  9311. * @static
  9312. * @memberOf _
  9313. * @since 3.0.0
  9314. * @category Function
  9315. * @param {Function} func The function to cap arguments for.
  9316. * @param {number} [n=func.length] The arity cap.
  9317. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9318. * @returns {Function} Returns the new capped function.
  9319. * @example
  9320. *
  9321. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9322. * // => [6, 8, 10]
  9323. */
  9324. function ary(func, n, guard) {
  9325. n = guard ? undefined : n;
  9326. n = (func && n == null) ? func.length : n;
  9327. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9328. }
  9329. /**
  9330. * Creates a function that invokes `func`, with the `this` binding and arguments
  9331. * of the created function, while it's called less than `n` times. Subsequent
  9332. * calls to the created function return the result of the last `func` invocation.
  9333. *
  9334. * @static
  9335. * @memberOf _
  9336. * @since 3.0.0
  9337. * @category Function
  9338. * @param {number} n The number of calls at which `func` is no longer invoked.
  9339. * @param {Function} func The function to restrict.
  9340. * @returns {Function} Returns the new restricted function.
  9341. * @example
  9342. *
  9343. * jQuery(element).on('click', _.before(5, addContactToList));
  9344. * // => Allows adding up to 4 contacts to the list.
  9345. */
  9346. function before(n, func) {
  9347. var result;
  9348. if (typeof func != 'function') {
  9349. throw new TypeError(FUNC_ERROR_TEXT);
  9350. }
  9351. n = toInteger(n);
  9352. return function() {
  9353. if (--n > 0) {
  9354. result = func.apply(this, arguments);
  9355. }
  9356. if (n <= 1) {
  9357. func = undefined;
  9358. }
  9359. return result;
  9360. };
  9361. }
  9362. /**
  9363. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9364. * and `partials` prepended to the arguments it receives.
  9365. *
  9366. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9367. * may be used as a placeholder for partially applied arguments.
  9368. *
  9369. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9370. * property of bound functions.
  9371. *
  9372. * @static
  9373. * @memberOf _
  9374. * @since 0.1.0
  9375. * @category Function
  9376. * @param {Function} func The function to bind.
  9377. * @param {*} thisArg The `this` binding of `func`.
  9378. * @param {...*} [partials] The arguments to be partially applied.
  9379. * @returns {Function} Returns the new bound function.
  9380. * @example
  9381. *
  9382. * function greet(greeting, punctuation) {
  9383. * return greeting + ' ' + this.user + punctuation;
  9384. * }
  9385. *
  9386. * var object = { 'user': 'fred' };
  9387. *
  9388. * var bound = _.bind(greet, object, 'hi');
  9389. * bound('!');
  9390. * // => 'hi fred!'
  9391. *
  9392. * // Bound with placeholders.
  9393. * var bound = _.bind(greet, object, _, '!');
  9394. * bound('hi');
  9395. * // => 'hi fred!'
  9396. */
  9397. var bind = baseRest(function(func, thisArg, partials) {
  9398. var bitmask = WRAP_BIND_FLAG;
  9399. if (partials.length) {
  9400. var holders = replaceHolders(partials, getHolder(bind));
  9401. bitmask |= WRAP_PARTIAL_FLAG;
  9402. }
  9403. return createWrap(func, bitmask, thisArg, partials, holders);
  9404. });
  9405. /**
  9406. * Creates a function that invokes the method at `object[key]` with `partials`
  9407. * prepended to the arguments it receives.
  9408. *
  9409. * This method differs from `_.bind` by allowing bound functions to reference
  9410. * methods that may be redefined or don't yet exist. See
  9411. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9412. * for more details.
  9413. *
  9414. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9415. * builds, may be used as a placeholder for partially applied arguments.
  9416. *
  9417. * @static
  9418. * @memberOf _
  9419. * @since 0.10.0
  9420. * @category Function
  9421. * @param {Object} object The object to invoke the method on.
  9422. * @param {string} key The key of the method.
  9423. * @param {...*} [partials] The arguments to be partially applied.
  9424. * @returns {Function} Returns the new bound function.
  9425. * @example
  9426. *
  9427. * var object = {
  9428. * 'user': 'fred',
  9429. * 'greet': function(greeting, punctuation) {
  9430. * return greeting + ' ' + this.user + punctuation;
  9431. * }
  9432. * };
  9433. *
  9434. * var bound = _.bindKey(object, 'greet', 'hi');
  9435. * bound('!');
  9436. * // => 'hi fred!'
  9437. *
  9438. * object.greet = function(greeting, punctuation) {
  9439. * return greeting + 'ya ' + this.user + punctuation;
  9440. * };
  9441. *
  9442. * bound('!');
  9443. * // => 'hiya fred!'
  9444. *
  9445. * // Bound with placeholders.
  9446. * var bound = _.bindKey(object, 'greet', _, '!');
  9447. * bound('hi');
  9448. * // => 'hiya fred!'
  9449. */
  9450. var bindKey = baseRest(function(object, key, partials) {
  9451. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9452. if (partials.length) {
  9453. var holders = replaceHolders(partials, getHolder(bindKey));
  9454. bitmask |= WRAP_PARTIAL_FLAG;
  9455. }
  9456. return createWrap(key, bitmask, object, partials, holders);
  9457. });
  9458. /**
  9459. * Creates a function that accepts arguments of `func` and either invokes
  9460. * `func` returning its result, if at least `arity` number of arguments have
  9461. * been provided, or returns a function that accepts the remaining `func`
  9462. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9463. * is not sufficient.
  9464. *
  9465. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9466. * may be used as a placeholder for provided arguments.
  9467. *
  9468. * **Note:** This method doesn't set the "length" property of curried functions.
  9469. *
  9470. * @static
  9471. * @memberOf _
  9472. * @since 2.0.0
  9473. * @category Function
  9474. * @param {Function} func The function to curry.
  9475. * @param {number} [arity=func.length] The arity of `func`.
  9476. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9477. * @returns {Function} Returns the new curried function.
  9478. * @example
  9479. *
  9480. * var abc = function(a, b, c) {
  9481. * return [a, b, c];
  9482. * };
  9483. *
  9484. * var curried = _.curry(abc);
  9485. *
  9486. * curried(1)(2)(3);
  9487. * // => [1, 2, 3]
  9488. *
  9489. * curried(1, 2)(3);
  9490. * // => [1, 2, 3]
  9491. *
  9492. * curried(1, 2, 3);
  9493. * // => [1, 2, 3]
  9494. *
  9495. * // Curried with placeholders.
  9496. * curried(1)(_, 3)(2);
  9497. * // => [1, 2, 3]
  9498. */
  9499. function curry(func, arity, guard) {
  9500. arity = guard ? undefined : arity;
  9501. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9502. result.placeholder = curry.placeholder;
  9503. return result;
  9504. }
  9505. /**
  9506. * This method is like `_.curry` except that arguments are applied to `func`
  9507. * in the manner of `_.partialRight` instead of `_.partial`.
  9508. *
  9509. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9510. * builds, may be used as a placeholder for provided arguments.
  9511. *
  9512. * **Note:** This method doesn't set the "length" property of curried functions.
  9513. *
  9514. * @static
  9515. * @memberOf _
  9516. * @since 3.0.0
  9517. * @category Function
  9518. * @param {Function} func The function to curry.
  9519. * @param {number} [arity=func.length] The arity of `func`.
  9520. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9521. * @returns {Function} Returns the new curried function.
  9522. * @example
  9523. *
  9524. * var abc = function(a, b, c) {
  9525. * return [a, b, c];
  9526. * };
  9527. *
  9528. * var curried = _.curryRight(abc);
  9529. *
  9530. * curried(3)(2)(1);
  9531. * // => [1, 2, 3]
  9532. *
  9533. * curried(2, 3)(1);
  9534. * // => [1, 2, 3]
  9535. *
  9536. * curried(1, 2, 3);
  9537. * // => [1, 2, 3]
  9538. *
  9539. * // Curried with placeholders.
  9540. * curried(3)(1, _)(2);
  9541. * // => [1, 2, 3]
  9542. */
  9543. function curryRight(func, arity, guard) {
  9544. arity = guard ? undefined : arity;
  9545. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9546. result.placeholder = curryRight.placeholder;
  9547. return result;
  9548. }
  9549. /**
  9550. * Creates a debounced function that delays invoking `func` until after `wait`
  9551. * milliseconds have elapsed since the last time the debounced function was
  9552. * invoked. The debounced function comes with a `cancel` method to cancel
  9553. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9554. * Provide `options` to indicate whether `func` should be invoked on the
  9555. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9556. * with the last arguments provided to the debounced function. Subsequent
  9557. * calls to the debounced function return the result of the last `func`
  9558. * invocation.
  9559. *
  9560. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9561. * invoked on the trailing edge of the timeout only if the debounced function
  9562. * is invoked more than once during the `wait` timeout.
  9563. *
  9564. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9565. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9566. *
  9567. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9568. * for details over the differences between `_.debounce` and `_.throttle`.
  9569. *
  9570. * @static
  9571. * @memberOf _
  9572. * @since 0.1.0
  9573. * @category Function
  9574. * @param {Function} func The function to debounce.
  9575. * @param {number} [wait=0] The number of milliseconds to delay.
  9576. * @param {Object} [options={}] The options object.
  9577. * @param {boolean} [options.leading=false]
  9578. * Specify invoking on the leading edge of the timeout.
  9579. * @param {number} [options.maxWait]
  9580. * The maximum time `func` is allowed to be delayed before it's invoked.
  9581. * @param {boolean} [options.trailing=true]
  9582. * Specify invoking on the trailing edge of the timeout.
  9583. * @returns {Function} Returns the new debounced function.
  9584. * @example
  9585. *
  9586. * // Avoid costly calculations while the window size is in flux.
  9587. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9588. *
  9589. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9590. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9591. * 'leading': true,
  9592. * 'trailing': false
  9593. * }));
  9594. *
  9595. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9596. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9597. * var source = new EventSource('/stream');
  9598. * jQuery(source).on('message', debounced);
  9599. *
  9600. * // Cancel the trailing debounced invocation.
  9601. * jQuery(window).on('popstate', debounced.cancel);
  9602. */
  9603. function debounce(func, wait, options) {
  9604. var lastArgs,
  9605. lastThis,
  9606. maxWait,
  9607. result,
  9608. timerId,
  9609. lastCallTime,
  9610. lastInvokeTime = 0,
  9611. leading = false,
  9612. maxing = false,
  9613. trailing = true;
  9614. if (typeof func != 'function') {
  9615. throw new TypeError(FUNC_ERROR_TEXT);
  9616. }
  9617. wait = toNumber(wait) || 0;
  9618. if (isObject(options)) {
  9619. leading = !!options.leading;
  9620. maxing = 'maxWait' in options;
  9621. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9622. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9623. }
  9624. function invokeFunc(time) {
  9625. var args = lastArgs,
  9626. thisArg = lastThis;
  9627. lastArgs = lastThis = undefined;
  9628. lastInvokeTime = time;
  9629. result = func.apply(thisArg, args);
  9630. return result;
  9631. }
  9632. function leadingEdge(time) {
  9633. // Reset any `maxWait` timer.
  9634. lastInvokeTime = time;
  9635. // Start the timer for the trailing edge.
  9636. timerId = setTimeout(timerExpired, wait);
  9637. // Invoke the leading edge.
  9638. return leading ? invokeFunc(time) : result;
  9639. }
  9640. function remainingWait(time) {
  9641. var timeSinceLastCall = time - lastCallTime,
  9642. timeSinceLastInvoke = time - lastInvokeTime,
  9643. timeWaiting = wait - timeSinceLastCall;
  9644. return maxing
  9645. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9646. : timeWaiting;
  9647. }
  9648. function shouldInvoke(time) {
  9649. var timeSinceLastCall = time - lastCallTime,
  9650. timeSinceLastInvoke = time - lastInvokeTime;
  9651. // Either this is the first call, activity has stopped and we're at the
  9652. // trailing edge, the system time has gone backwards and we're treating
  9653. // it as the trailing edge, or we've hit the `maxWait` limit.
  9654. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9655. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9656. }
  9657. function timerExpired() {
  9658. var time = now();
  9659. if (shouldInvoke(time)) {
  9660. return trailingEdge(time);
  9661. }
  9662. // Restart the timer.
  9663. timerId = setTimeout(timerExpired, remainingWait(time));
  9664. }
  9665. function trailingEdge(time) {
  9666. timerId = undefined;
  9667. // Only invoke if we have `lastArgs` which means `func` has been
  9668. // debounced at least once.
  9669. if (trailing && lastArgs) {
  9670. return invokeFunc(time);
  9671. }
  9672. lastArgs = lastThis = undefined;
  9673. return result;
  9674. }
  9675. function cancel() {
  9676. if (timerId !== undefined) {
  9677. clearTimeout(timerId);
  9678. }
  9679. lastInvokeTime = 0;
  9680. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9681. }
  9682. function flush() {
  9683. return timerId === undefined ? result : trailingEdge(now());
  9684. }
  9685. function debounced() {
  9686. var time = now(),
  9687. isInvoking = shouldInvoke(time);
  9688. lastArgs = arguments;
  9689. lastThis = this;
  9690. lastCallTime = time;
  9691. if (isInvoking) {
  9692. if (timerId === undefined) {
  9693. return leadingEdge(lastCallTime);
  9694. }
  9695. if (maxing) {
  9696. // Handle invocations in a tight loop.
  9697. clearTimeout(timerId);
  9698. timerId = setTimeout(timerExpired, wait);
  9699. return invokeFunc(lastCallTime);
  9700. }
  9701. }
  9702. if (timerId === undefined) {
  9703. timerId = setTimeout(timerExpired, wait);
  9704. }
  9705. return result;
  9706. }
  9707. debounced.cancel = cancel;
  9708. debounced.flush = flush;
  9709. return debounced;
  9710. }
  9711. /**
  9712. * Defers invoking the `func` until the current call stack has cleared. Any
  9713. * additional arguments are provided to `func` when it's invoked.
  9714. *
  9715. * @static
  9716. * @memberOf _
  9717. * @since 0.1.0
  9718. * @category Function
  9719. * @param {Function} func The function to defer.
  9720. * @param {...*} [args] The arguments to invoke `func` with.
  9721. * @returns {number} Returns the timer id.
  9722. * @example
  9723. *
  9724. * _.defer(function(text) {
  9725. * console.log(text);
  9726. * }, 'deferred');
  9727. * // => Logs 'deferred' after one millisecond.
  9728. */
  9729. var defer = baseRest(function(func, args) {
  9730. return baseDelay(func, 1, args);
  9731. });
  9732. /**
  9733. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9734. * provided to `func` when it's invoked.
  9735. *
  9736. * @static
  9737. * @memberOf _
  9738. * @since 0.1.0
  9739. * @category Function
  9740. * @param {Function} func The function to delay.
  9741. * @param {number} wait The number of milliseconds to delay invocation.
  9742. * @param {...*} [args] The arguments to invoke `func` with.
  9743. * @returns {number} Returns the timer id.
  9744. * @example
  9745. *
  9746. * _.delay(function(text) {
  9747. * console.log(text);
  9748. * }, 1000, 'later');
  9749. * // => Logs 'later' after one second.
  9750. */
  9751. var delay = baseRest(function(func, wait, args) {
  9752. return baseDelay(func, toNumber(wait) || 0, args);
  9753. });
  9754. /**
  9755. * Creates a function that invokes `func` with arguments reversed.
  9756. *
  9757. * @static
  9758. * @memberOf _
  9759. * @since 4.0.0
  9760. * @category Function
  9761. * @param {Function} func The function to flip arguments for.
  9762. * @returns {Function} Returns the new flipped function.
  9763. * @example
  9764. *
  9765. * var flipped = _.flip(function() {
  9766. * return _.toArray(arguments);
  9767. * });
  9768. *
  9769. * flipped('a', 'b', 'c', 'd');
  9770. * // => ['d', 'c', 'b', 'a']
  9771. */
  9772. function flip(func) {
  9773. return createWrap(func, WRAP_FLIP_FLAG);
  9774. }
  9775. /**
  9776. * Creates a function that memoizes the result of `func`. If `resolver` is
  9777. * provided, it determines the cache key for storing the result based on the
  9778. * arguments provided to the memoized function. By default, the first argument
  9779. * provided to the memoized function is used as the map cache key. The `func`
  9780. * is invoked with the `this` binding of the memoized function.
  9781. *
  9782. * **Note:** The cache is exposed as the `cache` property on the memoized
  9783. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9784. * constructor with one whose instances implement the
  9785. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9786. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9787. *
  9788. * @static
  9789. * @memberOf _
  9790. * @since 0.1.0
  9791. * @category Function
  9792. * @param {Function} func The function to have its output memoized.
  9793. * @param {Function} [resolver] The function to resolve the cache key.
  9794. * @returns {Function} Returns the new memoized function.
  9795. * @example
  9796. *
  9797. * var object = { 'a': 1, 'b': 2 };
  9798. * var other = { 'c': 3, 'd': 4 };
  9799. *
  9800. * var values = _.memoize(_.values);
  9801. * values(object);
  9802. * // => [1, 2]
  9803. *
  9804. * values(other);
  9805. * // => [3, 4]
  9806. *
  9807. * object.a = 2;
  9808. * values(object);
  9809. * // => [1, 2]
  9810. *
  9811. * // Modify the result cache.
  9812. * values.cache.set(object, ['a', 'b']);
  9813. * values(object);
  9814. * // => ['a', 'b']
  9815. *
  9816. * // Replace `_.memoize.Cache`.
  9817. * _.memoize.Cache = WeakMap;
  9818. */
  9819. function memoize(func, resolver) {
  9820. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9821. throw new TypeError(FUNC_ERROR_TEXT);
  9822. }
  9823. var memoized = function() {
  9824. var args = arguments,
  9825. key = resolver ? resolver.apply(this, args) : args[0],
  9826. cache = memoized.cache;
  9827. if (cache.has(key)) {
  9828. return cache.get(key);
  9829. }
  9830. var result = func.apply(this, args);
  9831. memoized.cache = cache.set(key, result) || cache;
  9832. return result;
  9833. };
  9834. memoized.cache = new (memoize.Cache || MapCache);
  9835. return memoized;
  9836. }
  9837. // Expose `MapCache`.
  9838. memoize.Cache = MapCache;
  9839. /**
  9840. * Creates a function that negates the result of the predicate `func`. The
  9841. * `func` predicate is invoked with the `this` binding and arguments of the
  9842. * created function.
  9843. *
  9844. * @static
  9845. * @memberOf _
  9846. * @since 3.0.0
  9847. * @category Function
  9848. * @param {Function} predicate The predicate to negate.
  9849. * @returns {Function} Returns the new negated function.
  9850. * @example
  9851. *
  9852. * function isEven(n) {
  9853. * return n % 2 == 0;
  9854. * }
  9855. *
  9856. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9857. * // => [1, 3, 5]
  9858. */
  9859. function negate(predicate) {
  9860. if (typeof predicate != 'function') {
  9861. throw new TypeError(FUNC_ERROR_TEXT);
  9862. }
  9863. return function() {
  9864. var args = arguments;
  9865. switch (args.length) {
  9866. case 0: return !predicate.call(this);
  9867. case 1: return !predicate.call(this, args[0]);
  9868. case 2: return !predicate.call(this, args[0], args[1]);
  9869. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9870. }
  9871. return !predicate.apply(this, args);
  9872. };
  9873. }
  9874. /**
  9875. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9876. * to the function return the value of the first invocation. The `func` is
  9877. * invoked with the `this` binding and arguments of the created function.
  9878. *
  9879. * @static
  9880. * @memberOf _
  9881. * @since 0.1.0
  9882. * @category Function
  9883. * @param {Function} func The function to restrict.
  9884. * @returns {Function} Returns the new restricted function.
  9885. * @example
  9886. *
  9887. * var initialize = _.once(createApplication);
  9888. * initialize();
  9889. * initialize();
  9890. * // => `createApplication` is invoked once
  9891. */
  9892. function once(func) {
  9893. return before(2, func);
  9894. }
  9895. /**
  9896. * Creates a function that invokes `func` with its arguments transformed.
  9897. *
  9898. * @static
  9899. * @since 4.0.0
  9900. * @memberOf _
  9901. * @category Function
  9902. * @param {Function} func The function to wrap.
  9903. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9904. * The argument transforms.
  9905. * @returns {Function} Returns the new function.
  9906. * @example
  9907. *
  9908. * function doubled(n) {
  9909. * return n * 2;
  9910. * }
  9911. *
  9912. * function square(n) {
  9913. * return n * n;
  9914. * }
  9915. *
  9916. * var func = _.overArgs(function(x, y) {
  9917. * return [x, y];
  9918. * }, [square, doubled]);
  9919. *
  9920. * func(9, 3);
  9921. * // => [81, 6]
  9922. *
  9923. * func(10, 5);
  9924. * // => [100, 10]
  9925. */
  9926. var overArgs = castRest(function(func, transforms) {
  9927. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9928. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9929. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9930. var funcsLength = transforms.length;
  9931. return baseRest(function(args) {
  9932. var index = -1,
  9933. length = nativeMin(args.length, funcsLength);
  9934. while (++index < length) {
  9935. args[index] = transforms[index].call(this, args[index]);
  9936. }
  9937. return apply(func, this, args);
  9938. });
  9939. });
  9940. /**
  9941. * Creates a function that invokes `func` with `partials` prepended to the
  9942. * arguments it receives. This method is like `_.bind` except it does **not**
  9943. * alter the `this` binding.
  9944. *
  9945. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9946. * builds, may be used as a placeholder for partially applied arguments.
  9947. *
  9948. * **Note:** This method doesn't set the "length" property of partially
  9949. * applied functions.
  9950. *
  9951. * @static
  9952. * @memberOf _
  9953. * @since 0.2.0
  9954. * @category Function
  9955. * @param {Function} func The function to partially apply arguments to.
  9956. * @param {...*} [partials] The arguments to be partially applied.
  9957. * @returns {Function} Returns the new partially applied function.
  9958. * @example
  9959. *
  9960. * function greet(greeting, name) {
  9961. * return greeting + ' ' + name;
  9962. * }
  9963. *
  9964. * var sayHelloTo = _.partial(greet, 'hello');
  9965. * sayHelloTo('fred');
  9966. * // => 'hello fred'
  9967. *
  9968. * // Partially applied with placeholders.
  9969. * var greetFred = _.partial(greet, _, 'fred');
  9970. * greetFred('hi');
  9971. * // => 'hi fred'
  9972. */
  9973. var partial = baseRest(function(func, partials) {
  9974. var holders = replaceHolders(partials, getHolder(partial));
  9975. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9976. });
  9977. /**
  9978. * This method is like `_.partial` except that partially applied arguments
  9979. * are appended to the arguments it receives.
  9980. *
  9981. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9982. * builds, may be used as a placeholder for partially applied arguments.
  9983. *
  9984. * **Note:** This method doesn't set the "length" property of partially
  9985. * applied functions.
  9986. *
  9987. * @static
  9988. * @memberOf _
  9989. * @since 1.0.0
  9990. * @category Function
  9991. * @param {Function} func The function to partially apply arguments to.
  9992. * @param {...*} [partials] The arguments to be partially applied.
  9993. * @returns {Function} Returns the new partially applied function.
  9994. * @example
  9995. *
  9996. * function greet(greeting, name) {
  9997. * return greeting + ' ' + name;
  9998. * }
  9999. *
  10000. * var greetFred = _.partialRight(greet, 'fred');
  10001. * greetFred('hi');
  10002. * // => 'hi fred'
  10003. *
  10004. * // Partially applied with placeholders.
  10005. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  10006. * sayHelloTo('fred');
  10007. * // => 'hello fred'
  10008. */
  10009. var partialRight = baseRest(function(func, partials) {
  10010. var holders = replaceHolders(partials, getHolder(partialRight));
  10011. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  10012. });
  10013. /**
  10014. * Creates a function that invokes `func` with arguments arranged according
  10015. * to the specified `indexes` where the argument value at the first index is
  10016. * provided as the first argument, the argument value at the second index is
  10017. * provided as the second argument, and so on.
  10018. *
  10019. * @static
  10020. * @memberOf _
  10021. * @since 3.0.0
  10022. * @category Function
  10023. * @param {Function} func The function to rearrange arguments for.
  10024. * @param {...(number|number[])} indexes The arranged argument indexes.
  10025. * @returns {Function} Returns the new function.
  10026. * @example
  10027. *
  10028. * var rearged = _.rearg(function(a, b, c) {
  10029. * return [a, b, c];
  10030. * }, [2, 0, 1]);
  10031. *
  10032. * rearged('b', 'c', 'a')
  10033. * // => ['a', 'b', 'c']
  10034. */
  10035. var rearg = flatRest(function(func, indexes) {
  10036. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10037. });
  10038. /**
  10039. * Creates a function that invokes `func` with the `this` binding of the
  10040. * created function and arguments from `start` and beyond provided as
  10041. * an array.
  10042. *
  10043. * **Note:** This method is based on the
  10044. * [rest parameter](https://mdn.io/rest_parameters).
  10045. *
  10046. * @static
  10047. * @memberOf _
  10048. * @since 4.0.0
  10049. * @category Function
  10050. * @param {Function} func The function to apply a rest parameter to.
  10051. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10052. * @returns {Function} Returns the new function.
  10053. * @example
  10054. *
  10055. * var say = _.rest(function(what, names) {
  10056. * return what + ' ' + _.initial(names).join(', ') +
  10057. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10058. * });
  10059. *
  10060. * say('hello', 'fred', 'barney', 'pebbles');
  10061. * // => 'hello fred, barney, & pebbles'
  10062. */
  10063. function rest(func, start) {
  10064. if (typeof func != 'function') {
  10065. throw new TypeError(FUNC_ERROR_TEXT);
  10066. }
  10067. start = start === undefined ? start : toInteger(start);
  10068. return baseRest(func, start);
  10069. }
  10070. /**
  10071. * Creates a function that invokes `func` with the `this` binding of the
  10072. * create function and an array of arguments much like
  10073. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10074. *
  10075. * **Note:** This method is based on the
  10076. * [spread operator](https://mdn.io/spread_operator).
  10077. *
  10078. * @static
  10079. * @memberOf _
  10080. * @since 3.2.0
  10081. * @category Function
  10082. * @param {Function} func The function to spread arguments over.
  10083. * @param {number} [start=0] The start position of the spread.
  10084. * @returns {Function} Returns the new function.
  10085. * @example
  10086. *
  10087. * var say = _.spread(function(who, what) {
  10088. * return who + ' says ' + what;
  10089. * });
  10090. *
  10091. * say(['fred', 'hello']);
  10092. * // => 'fred says hello'
  10093. *
  10094. * var numbers = Promise.all([
  10095. * Promise.resolve(40),
  10096. * Promise.resolve(36)
  10097. * ]);
  10098. *
  10099. * numbers.then(_.spread(function(x, y) {
  10100. * return x + y;
  10101. * }));
  10102. * // => a Promise of 76
  10103. */
  10104. function spread(func, start) {
  10105. if (typeof func != 'function') {
  10106. throw new TypeError(FUNC_ERROR_TEXT);
  10107. }
  10108. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10109. return baseRest(function(args) {
  10110. var array = args[start],
  10111. otherArgs = castSlice(args, 0, start);
  10112. if (array) {
  10113. arrayPush(otherArgs, array);
  10114. }
  10115. return apply(func, this, otherArgs);
  10116. });
  10117. }
  10118. /**
  10119. * Creates a throttled function that only invokes `func` at most once per
  10120. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10121. * method to cancel delayed `func` invocations and a `flush` method to
  10122. * immediately invoke them. Provide `options` to indicate whether `func`
  10123. * should be invoked on the leading and/or trailing edge of the `wait`
  10124. * timeout. The `func` is invoked with the last arguments provided to the
  10125. * throttled function. Subsequent calls to the throttled function return the
  10126. * result of the last `func` invocation.
  10127. *
  10128. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10129. * invoked on the trailing edge of the timeout only if the throttled function
  10130. * is invoked more than once during the `wait` timeout.
  10131. *
  10132. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10133. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10134. *
  10135. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10136. * for details over the differences between `_.throttle` and `_.debounce`.
  10137. *
  10138. * @static
  10139. * @memberOf _
  10140. * @since 0.1.0
  10141. * @category Function
  10142. * @param {Function} func The function to throttle.
  10143. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10144. * @param {Object} [options={}] The options object.
  10145. * @param {boolean} [options.leading=true]
  10146. * Specify invoking on the leading edge of the timeout.
  10147. * @param {boolean} [options.trailing=true]
  10148. * Specify invoking on the trailing edge of the timeout.
  10149. * @returns {Function} Returns the new throttled function.
  10150. * @example
  10151. *
  10152. * // Avoid excessively updating the position while scrolling.
  10153. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10154. *
  10155. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10156. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10157. * jQuery(element).on('click', throttled);
  10158. *
  10159. * // Cancel the trailing throttled invocation.
  10160. * jQuery(window).on('popstate', throttled.cancel);
  10161. */
  10162. function throttle(func, wait, options) {
  10163. var leading = true,
  10164. trailing = true;
  10165. if (typeof func != 'function') {
  10166. throw new TypeError(FUNC_ERROR_TEXT);
  10167. }
  10168. if (isObject(options)) {
  10169. leading = 'leading' in options ? !!options.leading : leading;
  10170. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10171. }
  10172. return debounce(func, wait, {
  10173. 'leading': leading,
  10174. 'maxWait': wait,
  10175. 'trailing': trailing
  10176. });
  10177. }
  10178. /**
  10179. * Creates a function that accepts up to one argument, ignoring any
  10180. * additional arguments.
  10181. *
  10182. * @static
  10183. * @memberOf _
  10184. * @since 4.0.0
  10185. * @category Function
  10186. * @param {Function} func The function to cap arguments for.
  10187. * @returns {Function} Returns the new capped function.
  10188. * @example
  10189. *
  10190. * _.map(['6', '8', '10'], _.unary(parseInt));
  10191. * // => [6, 8, 10]
  10192. */
  10193. function unary(func) {
  10194. return ary(func, 1);
  10195. }
  10196. /**
  10197. * Creates a function that provides `value` to `wrapper` as its first
  10198. * argument. Any additional arguments provided to the function are appended
  10199. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10200. * binding of the created function.
  10201. *
  10202. * @static
  10203. * @memberOf _
  10204. * @since 0.1.0
  10205. * @category Function
  10206. * @param {*} value The value to wrap.
  10207. * @param {Function} [wrapper=identity] The wrapper function.
  10208. * @returns {Function} Returns the new function.
  10209. * @example
  10210. *
  10211. * var p = _.wrap(_.escape, function(func, text) {
  10212. * return '<p>' + func(text) + '</p>';
  10213. * });
  10214. *
  10215. * p('fred, barney, & pebbles');
  10216. * // => '<p>fred, barney, &amp; pebbles</p>'
  10217. */
  10218. function wrap(value, wrapper) {
  10219. return partial(castFunction(wrapper), value);
  10220. }
  10221. /*------------------------------------------------------------------------*/
  10222. /**
  10223. * Casts `value` as an array if it's not one.
  10224. *
  10225. * @static
  10226. * @memberOf _
  10227. * @since 4.4.0
  10228. * @category Lang
  10229. * @param {*} value The value to inspect.
  10230. * @returns {Array} Returns the cast array.
  10231. * @example
  10232. *
  10233. * _.castArray(1);
  10234. * // => [1]
  10235. *
  10236. * _.castArray({ 'a': 1 });
  10237. * // => [{ 'a': 1 }]
  10238. *
  10239. * _.castArray('abc');
  10240. * // => ['abc']
  10241. *
  10242. * _.castArray(null);
  10243. * // => [null]
  10244. *
  10245. * _.castArray(undefined);
  10246. * // => [undefined]
  10247. *
  10248. * _.castArray();
  10249. * // => []
  10250. *
  10251. * var array = [1, 2, 3];
  10252. * console.log(_.castArray(array) === array);
  10253. * // => true
  10254. */
  10255. function castArray() {
  10256. if (!arguments.length) {
  10257. return [];
  10258. }
  10259. var value = arguments[0];
  10260. return isArray(value) ? value : [value];
  10261. }
  10262. /**
  10263. * Creates a shallow clone of `value`.
  10264. *
  10265. * **Note:** This method is loosely based on the
  10266. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10267. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10268. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10269. * arrays. The own enumerable properties of `arguments` objects are cloned
  10270. * as plain objects. An empty object is returned for uncloneable values such
  10271. * as error objects, functions, DOM nodes, and WeakMaps.
  10272. *
  10273. * @static
  10274. * @memberOf _
  10275. * @since 0.1.0
  10276. * @category Lang
  10277. * @param {*} value The value to clone.
  10278. * @returns {*} Returns the cloned value.
  10279. * @see _.cloneDeep
  10280. * @example
  10281. *
  10282. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10283. *
  10284. * var shallow = _.clone(objects);
  10285. * console.log(shallow[0] === objects[0]);
  10286. * // => true
  10287. */
  10288. function clone(value) {
  10289. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10290. }
  10291. /**
  10292. * This method is like `_.clone` except that it accepts `customizer` which
  10293. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10294. * cloning is handled by the method instead. The `customizer` is invoked with
  10295. * up to four arguments; (value [, index|key, object, stack]).
  10296. *
  10297. * @static
  10298. * @memberOf _
  10299. * @since 4.0.0
  10300. * @category Lang
  10301. * @param {*} value The value to clone.
  10302. * @param {Function} [customizer] The function to customize cloning.
  10303. * @returns {*} Returns the cloned value.
  10304. * @see _.cloneDeepWith
  10305. * @example
  10306. *
  10307. * function customizer(value) {
  10308. * if (_.isElement(value)) {
  10309. * return value.cloneNode(false);
  10310. * }
  10311. * }
  10312. *
  10313. * var el = _.cloneWith(document.body, customizer);
  10314. *
  10315. * console.log(el === document.body);
  10316. * // => false
  10317. * console.log(el.nodeName);
  10318. * // => 'BODY'
  10319. * console.log(el.childNodes.length);
  10320. * // => 0
  10321. */
  10322. function cloneWith(value, customizer) {
  10323. customizer = typeof customizer == 'function' ? customizer : undefined;
  10324. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10325. }
  10326. /**
  10327. * This method is like `_.clone` except that it recursively clones `value`.
  10328. *
  10329. * @static
  10330. * @memberOf _
  10331. * @since 1.0.0
  10332. * @category Lang
  10333. * @param {*} value The value to recursively clone.
  10334. * @returns {*} Returns the deep cloned value.
  10335. * @see _.clone
  10336. * @example
  10337. *
  10338. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10339. *
  10340. * var deep = _.cloneDeep(objects);
  10341. * console.log(deep[0] === objects[0]);
  10342. * // => false
  10343. */
  10344. function cloneDeep(value) {
  10345. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10346. }
  10347. /**
  10348. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10349. *
  10350. * @static
  10351. * @memberOf _
  10352. * @since 4.0.0
  10353. * @category Lang
  10354. * @param {*} value The value to recursively clone.
  10355. * @param {Function} [customizer] The function to customize cloning.
  10356. * @returns {*} Returns the deep cloned value.
  10357. * @see _.cloneWith
  10358. * @example
  10359. *
  10360. * function customizer(value) {
  10361. * if (_.isElement(value)) {
  10362. * return value.cloneNode(true);
  10363. * }
  10364. * }
  10365. *
  10366. * var el = _.cloneDeepWith(document.body, customizer);
  10367. *
  10368. * console.log(el === document.body);
  10369. * // => false
  10370. * console.log(el.nodeName);
  10371. * // => 'BODY'
  10372. * console.log(el.childNodes.length);
  10373. * // => 20
  10374. */
  10375. function cloneDeepWith(value, customizer) {
  10376. customizer = typeof customizer == 'function' ? customizer : undefined;
  10377. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10378. }
  10379. /**
  10380. * Checks if `object` conforms to `source` by invoking the predicate
  10381. * properties of `source` with the corresponding property values of `object`.
  10382. *
  10383. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10384. * partially applied.
  10385. *
  10386. * @static
  10387. * @memberOf _
  10388. * @since 4.14.0
  10389. * @category Lang
  10390. * @param {Object} object The object to inspect.
  10391. * @param {Object} source The object of property predicates to conform to.
  10392. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10393. * @example
  10394. *
  10395. * var object = { 'a': 1, 'b': 2 };
  10396. *
  10397. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10398. * // => true
  10399. *
  10400. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10401. * // => false
  10402. */
  10403. function conformsTo(object, source) {
  10404. return source == null || baseConformsTo(object, source, keys(source));
  10405. }
  10406. /**
  10407. * Performs a
  10408. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10409. * comparison between two values to determine if they are equivalent.
  10410. *
  10411. * @static
  10412. * @memberOf _
  10413. * @since 4.0.0
  10414. * @category Lang
  10415. * @param {*} value The value to compare.
  10416. * @param {*} other The other value to compare.
  10417. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10418. * @example
  10419. *
  10420. * var object = { 'a': 1 };
  10421. * var other = { 'a': 1 };
  10422. *
  10423. * _.eq(object, object);
  10424. * // => true
  10425. *
  10426. * _.eq(object, other);
  10427. * // => false
  10428. *
  10429. * _.eq('a', 'a');
  10430. * // => true
  10431. *
  10432. * _.eq('a', Object('a'));
  10433. * // => false
  10434. *
  10435. * _.eq(NaN, NaN);
  10436. * // => true
  10437. */
  10438. function eq(value, other) {
  10439. return value === other || (value !== value && other !== other);
  10440. }
  10441. /**
  10442. * Checks if `value` is greater than `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 `other`,
  10451. * else `false`.
  10452. * @see _.lt
  10453. * @example
  10454. *
  10455. * _.gt(3, 1);
  10456. * // => true
  10457. *
  10458. * _.gt(3, 3);
  10459. * // => false
  10460. *
  10461. * _.gt(1, 3);
  10462. * // => false
  10463. */
  10464. var gt = createRelationalOperation(baseGt);
  10465. /**
  10466. * Checks if `value` is greater than or equal to `other`.
  10467. *
  10468. * @static
  10469. * @memberOf _
  10470. * @since 3.9.0
  10471. * @category Lang
  10472. * @param {*} value The value to compare.
  10473. * @param {*} other The other value to compare.
  10474. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10475. * `other`, else `false`.
  10476. * @see _.lte
  10477. * @example
  10478. *
  10479. * _.gte(3, 1);
  10480. * // => true
  10481. *
  10482. * _.gte(3, 3);
  10483. * // => true
  10484. *
  10485. * _.gte(1, 3);
  10486. * // => false
  10487. */
  10488. var gte = createRelationalOperation(function(value, other) {
  10489. return value >= other;
  10490. });
  10491. /**
  10492. * Checks if `value` is likely an `arguments` object.
  10493. *
  10494. * @static
  10495. * @memberOf _
  10496. * @since 0.1.0
  10497. * @category Lang
  10498. * @param {*} value The value to check.
  10499. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10500. * else `false`.
  10501. * @example
  10502. *
  10503. * _.isArguments(function() { return arguments; }());
  10504. * // => true
  10505. *
  10506. * _.isArguments([1, 2, 3]);
  10507. * // => false
  10508. */
  10509. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10510. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10511. !propertyIsEnumerable.call(value, 'callee');
  10512. };
  10513. /**
  10514. * Checks if `value` is classified as an `Array` object.
  10515. *
  10516. * @static
  10517. * @memberOf _
  10518. * @since 0.1.0
  10519. * @category Lang
  10520. * @param {*} value The value to check.
  10521. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10522. * @example
  10523. *
  10524. * _.isArray([1, 2, 3]);
  10525. * // => true
  10526. *
  10527. * _.isArray(document.body.children);
  10528. * // => false
  10529. *
  10530. * _.isArray('abc');
  10531. * // => false
  10532. *
  10533. * _.isArray(_.noop);
  10534. * // => false
  10535. */
  10536. var isArray = Array.isArray;
  10537. /**
  10538. * Checks if `value` is classified as an `ArrayBuffer` object.
  10539. *
  10540. * @static
  10541. * @memberOf _
  10542. * @since 4.3.0
  10543. * @category Lang
  10544. * @param {*} value The value to check.
  10545. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10546. * @example
  10547. *
  10548. * _.isArrayBuffer(new ArrayBuffer(2));
  10549. * // => true
  10550. *
  10551. * _.isArrayBuffer(new Array(2));
  10552. * // => false
  10553. */
  10554. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10555. /**
  10556. * Checks if `value` is array-like. A value is considered array-like if it's
  10557. * not a function and has a `value.length` that's an integer greater than or
  10558. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10559. *
  10560. * @static
  10561. * @memberOf _
  10562. * @since 4.0.0
  10563. * @category Lang
  10564. * @param {*} value The value to check.
  10565. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10566. * @example
  10567. *
  10568. * _.isArrayLike([1, 2, 3]);
  10569. * // => true
  10570. *
  10571. * _.isArrayLike(document.body.children);
  10572. * // => true
  10573. *
  10574. * _.isArrayLike('abc');
  10575. * // => true
  10576. *
  10577. * _.isArrayLike(_.noop);
  10578. * // => false
  10579. */
  10580. function isArrayLike(value) {
  10581. return value != null && isLength(value.length) && !isFunction(value);
  10582. }
  10583. /**
  10584. * This method is like `_.isArrayLike` except that it also checks if `value`
  10585. * is an object.
  10586. *
  10587. * @static
  10588. * @memberOf _
  10589. * @since 4.0.0
  10590. * @category Lang
  10591. * @param {*} value The value to check.
  10592. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10593. * else `false`.
  10594. * @example
  10595. *
  10596. * _.isArrayLikeObject([1, 2, 3]);
  10597. * // => true
  10598. *
  10599. * _.isArrayLikeObject(document.body.children);
  10600. * // => true
  10601. *
  10602. * _.isArrayLikeObject('abc');
  10603. * // => false
  10604. *
  10605. * _.isArrayLikeObject(_.noop);
  10606. * // => false
  10607. */
  10608. function isArrayLikeObject(value) {
  10609. return isObjectLike(value) && isArrayLike(value);
  10610. }
  10611. /**
  10612. * Checks if `value` is classified as a boolean primitive or object.
  10613. *
  10614. * @static
  10615. * @memberOf _
  10616. * @since 0.1.0
  10617. * @category Lang
  10618. * @param {*} value The value to check.
  10619. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10620. * @example
  10621. *
  10622. * _.isBoolean(false);
  10623. * // => true
  10624. *
  10625. * _.isBoolean(null);
  10626. * // => false
  10627. */
  10628. function isBoolean(value) {
  10629. return value === true || value === false ||
  10630. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10631. }
  10632. /**
  10633. * Checks if `value` is a buffer.
  10634. *
  10635. * @static
  10636. * @memberOf _
  10637. * @since 4.3.0
  10638. * @category Lang
  10639. * @param {*} value The value to check.
  10640. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10641. * @example
  10642. *
  10643. * _.isBuffer(new Buffer(2));
  10644. * // => true
  10645. *
  10646. * _.isBuffer(new Uint8Array(2));
  10647. * // => false
  10648. */
  10649. var isBuffer = nativeIsBuffer || stubFalse;
  10650. /**
  10651. * Checks if `value` is classified as a `Date` object.
  10652. *
  10653. * @static
  10654. * @memberOf _
  10655. * @since 0.1.0
  10656. * @category Lang
  10657. * @param {*} value The value to check.
  10658. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10659. * @example
  10660. *
  10661. * _.isDate(new Date);
  10662. * // => true
  10663. *
  10664. * _.isDate('Mon April 23 2012');
  10665. * // => false
  10666. */
  10667. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10668. /**
  10669. * Checks if `value` is likely a DOM element.
  10670. *
  10671. * @static
  10672. * @memberOf _
  10673. * @since 0.1.0
  10674. * @category Lang
  10675. * @param {*} value The value to check.
  10676. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10677. * @example
  10678. *
  10679. * _.isElement(document.body);
  10680. * // => true
  10681. *
  10682. * _.isElement('<body>');
  10683. * // => false
  10684. */
  10685. function isElement(value) {
  10686. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10687. }
  10688. /**
  10689. * Checks if `value` is an empty object, collection, map, or set.
  10690. *
  10691. * Objects are considered empty if they have no own enumerable string keyed
  10692. * properties.
  10693. *
  10694. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10695. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10696. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10697. *
  10698. * @static
  10699. * @memberOf _
  10700. * @since 0.1.0
  10701. * @category Lang
  10702. * @param {*} value The value to check.
  10703. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10704. * @example
  10705. *
  10706. * _.isEmpty(null);
  10707. * // => true
  10708. *
  10709. * _.isEmpty(true);
  10710. * // => true
  10711. *
  10712. * _.isEmpty(1);
  10713. * // => true
  10714. *
  10715. * _.isEmpty([1, 2, 3]);
  10716. * // => false
  10717. *
  10718. * _.isEmpty({ 'a': 1 });
  10719. * // => false
  10720. */
  10721. function isEmpty(value) {
  10722. if (value == null) {
  10723. return true;
  10724. }
  10725. if (isArrayLike(value) &&
  10726. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10727. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10728. return !value.length;
  10729. }
  10730. var tag = getTag(value);
  10731. if (tag == mapTag || tag == setTag) {
  10732. return !value.size;
  10733. }
  10734. if (isPrototype(value)) {
  10735. return !baseKeys(value).length;
  10736. }
  10737. for (var key in value) {
  10738. if (hasOwnProperty.call(value, key)) {
  10739. return false;
  10740. }
  10741. }
  10742. return true;
  10743. }
  10744. /**
  10745. * Performs a deep comparison between two values to determine if they are
  10746. * equivalent.
  10747. *
  10748. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10749. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10750. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10751. * by their own, not inherited, enumerable properties. Functions and DOM
  10752. * nodes are compared by strict equality, i.e. `===`.
  10753. *
  10754. * @static
  10755. * @memberOf _
  10756. * @since 0.1.0
  10757. * @category Lang
  10758. * @param {*} value The value to compare.
  10759. * @param {*} other The other value to compare.
  10760. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10761. * @example
  10762. *
  10763. * var object = { 'a': 1 };
  10764. * var other = { 'a': 1 };
  10765. *
  10766. * _.isEqual(object, other);
  10767. * // => true
  10768. *
  10769. * object === other;
  10770. * // => false
  10771. */
  10772. function isEqual(value, other) {
  10773. return baseIsEqual(value, other);
  10774. }
  10775. /**
  10776. * This method is like `_.isEqual` except that it accepts `customizer` which
  10777. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10778. * are handled by the method instead. The `customizer` is invoked with up to
  10779. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10780. *
  10781. * @static
  10782. * @memberOf _
  10783. * @since 4.0.0
  10784. * @category Lang
  10785. * @param {*} value The value to compare.
  10786. * @param {*} other The other value to compare.
  10787. * @param {Function} [customizer] The function to customize comparisons.
  10788. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10789. * @example
  10790. *
  10791. * function isGreeting(value) {
  10792. * return /^h(?:i|ello)$/.test(value);
  10793. * }
  10794. *
  10795. * function customizer(objValue, othValue) {
  10796. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10797. * return true;
  10798. * }
  10799. * }
  10800. *
  10801. * var array = ['hello', 'goodbye'];
  10802. * var other = ['hi', 'goodbye'];
  10803. *
  10804. * _.isEqualWith(array, other, customizer);
  10805. * // => true
  10806. */
  10807. function isEqualWith(value, other, customizer) {
  10808. customizer = typeof customizer == 'function' ? customizer : undefined;
  10809. var result = customizer ? customizer(value, other) : undefined;
  10810. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10811. }
  10812. /**
  10813. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10814. * `SyntaxError`, `TypeError`, or `URIError` object.
  10815. *
  10816. * @static
  10817. * @memberOf _
  10818. * @since 3.0.0
  10819. * @category Lang
  10820. * @param {*} value The value to check.
  10821. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10822. * @example
  10823. *
  10824. * _.isError(new Error);
  10825. * // => true
  10826. *
  10827. * _.isError(Error);
  10828. * // => false
  10829. */
  10830. function isError(value) {
  10831. if (!isObjectLike(value)) {
  10832. return false;
  10833. }
  10834. var tag = baseGetTag(value);
  10835. return tag == errorTag || tag == domExcTag ||
  10836. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10837. }
  10838. /**
  10839. * Checks if `value` is a finite primitive number.
  10840. *
  10841. * **Note:** This method is based on
  10842. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10843. *
  10844. * @static
  10845. * @memberOf _
  10846. * @since 0.1.0
  10847. * @category Lang
  10848. * @param {*} value The value to check.
  10849. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10850. * @example
  10851. *
  10852. * _.isFinite(3);
  10853. * // => true
  10854. *
  10855. * _.isFinite(Number.MIN_VALUE);
  10856. * // => true
  10857. *
  10858. * _.isFinite(Infinity);
  10859. * // => false
  10860. *
  10861. * _.isFinite('3');
  10862. * // => false
  10863. */
  10864. function isFinite(value) {
  10865. return typeof value == 'number' && nativeIsFinite(value);
  10866. }
  10867. /**
  10868. * Checks if `value` is classified as a `Function` object.
  10869. *
  10870. * @static
  10871. * @memberOf _
  10872. * @since 0.1.0
  10873. * @category Lang
  10874. * @param {*} value The value to check.
  10875. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10876. * @example
  10877. *
  10878. * _.isFunction(_);
  10879. * // => true
  10880. *
  10881. * _.isFunction(/abc/);
  10882. * // => false
  10883. */
  10884. function isFunction(value) {
  10885. if (!isObject(value)) {
  10886. return false;
  10887. }
  10888. // The use of `Object#toString` avoids issues with the `typeof` operator
  10889. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10890. var tag = baseGetTag(value);
  10891. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10892. }
  10893. /**
  10894. * Checks if `value` is an integer.
  10895. *
  10896. * **Note:** This method is based on
  10897. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10898. *
  10899. * @static
  10900. * @memberOf _
  10901. * @since 4.0.0
  10902. * @category Lang
  10903. * @param {*} value The value to check.
  10904. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10905. * @example
  10906. *
  10907. * _.isInteger(3);
  10908. * // => true
  10909. *
  10910. * _.isInteger(Number.MIN_VALUE);
  10911. * // => false
  10912. *
  10913. * _.isInteger(Infinity);
  10914. * // => false
  10915. *
  10916. * _.isInteger('3');
  10917. * // => false
  10918. */
  10919. function isInteger(value) {
  10920. return typeof value == 'number' && value == toInteger(value);
  10921. }
  10922. /**
  10923. * Checks if `value` is a valid array-like length.
  10924. *
  10925. * **Note:** This method is loosely based on
  10926. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10927. *
  10928. * @static
  10929. * @memberOf _
  10930. * @since 4.0.0
  10931. * @category Lang
  10932. * @param {*} value The value to check.
  10933. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10934. * @example
  10935. *
  10936. * _.isLength(3);
  10937. * // => true
  10938. *
  10939. * _.isLength(Number.MIN_VALUE);
  10940. * // => false
  10941. *
  10942. * _.isLength(Infinity);
  10943. * // => false
  10944. *
  10945. * _.isLength('3');
  10946. * // => false
  10947. */
  10948. function isLength(value) {
  10949. return typeof value == 'number' &&
  10950. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10951. }
  10952. /**
  10953. * Checks if `value` is the
  10954. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10955. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10956. *
  10957. * @static
  10958. * @memberOf _
  10959. * @since 0.1.0
  10960. * @category Lang
  10961. * @param {*} value The value to check.
  10962. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10963. * @example
  10964. *
  10965. * _.isObject({});
  10966. * // => true
  10967. *
  10968. * _.isObject([1, 2, 3]);
  10969. * // => true
  10970. *
  10971. * _.isObject(_.noop);
  10972. * // => true
  10973. *
  10974. * _.isObject(null);
  10975. * // => false
  10976. */
  10977. function isObject(value) {
  10978. var type = typeof value;
  10979. return value != null && (type == 'object' || type == 'function');
  10980. }
  10981. /**
  10982. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10983. * and has a `typeof` result of "object".
  10984. *
  10985. * @static
  10986. * @memberOf _
  10987. * @since 4.0.0
  10988. * @category Lang
  10989. * @param {*} value The value to check.
  10990. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10991. * @example
  10992. *
  10993. * _.isObjectLike({});
  10994. * // => true
  10995. *
  10996. * _.isObjectLike([1, 2, 3]);
  10997. * // => true
  10998. *
  10999. * _.isObjectLike(_.noop);
  11000. * // => false
  11001. *
  11002. * _.isObjectLike(null);
  11003. * // => false
  11004. */
  11005. function isObjectLike(value) {
  11006. return value != null && typeof value == 'object';
  11007. }
  11008. /**
  11009. * Checks if `value` is classified as a `Map` object.
  11010. *
  11011. * @static
  11012. * @memberOf _
  11013. * @since 4.3.0
  11014. * @category Lang
  11015. * @param {*} value The value to check.
  11016. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11017. * @example
  11018. *
  11019. * _.isMap(new Map);
  11020. * // => true
  11021. *
  11022. * _.isMap(new WeakMap);
  11023. * // => false
  11024. */
  11025. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11026. /**
  11027. * Performs a partial deep comparison between `object` and `source` to
  11028. * determine if `object` contains equivalent property values.
  11029. *
  11030. * **Note:** This method is equivalent to `_.matches` when `source` is
  11031. * partially applied.
  11032. *
  11033. * Partial comparisons will match empty array and empty object `source`
  11034. * values against any array or object value, respectively. See `_.isEqual`
  11035. * for a list of supported value comparisons.
  11036. *
  11037. * @static
  11038. * @memberOf _
  11039. * @since 3.0.0
  11040. * @category Lang
  11041. * @param {Object} object The object to inspect.
  11042. * @param {Object} source The object of property values to match.
  11043. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11044. * @example
  11045. *
  11046. * var object = { 'a': 1, 'b': 2 };
  11047. *
  11048. * _.isMatch(object, { 'b': 2 });
  11049. * // => true
  11050. *
  11051. * _.isMatch(object, { 'b': 1 });
  11052. * // => false
  11053. */
  11054. function isMatch(object, source) {
  11055. return object === source || baseIsMatch(object, source, getMatchData(source));
  11056. }
  11057. /**
  11058. * This method is like `_.isMatch` except that it accepts `customizer` which
  11059. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11060. * are handled by the method instead. The `customizer` is invoked with five
  11061. * arguments: (objValue, srcValue, index|key, object, source).
  11062. *
  11063. * @static
  11064. * @memberOf _
  11065. * @since 4.0.0
  11066. * @category Lang
  11067. * @param {Object} object The object to inspect.
  11068. * @param {Object} source The object of property values to match.
  11069. * @param {Function} [customizer] The function to customize comparisons.
  11070. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11071. * @example
  11072. *
  11073. * function isGreeting(value) {
  11074. * return /^h(?:i|ello)$/.test(value);
  11075. * }
  11076. *
  11077. * function customizer(objValue, srcValue) {
  11078. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11079. * return true;
  11080. * }
  11081. * }
  11082. *
  11083. * var object = { 'greeting': 'hello' };
  11084. * var source = { 'greeting': 'hi' };
  11085. *
  11086. * _.isMatchWith(object, source, customizer);
  11087. * // => true
  11088. */
  11089. function isMatchWith(object, source, customizer) {
  11090. customizer = typeof customizer == 'function' ? customizer : undefined;
  11091. return baseIsMatch(object, source, getMatchData(source), customizer);
  11092. }
  11093. /**
  11094. * Checks if `value` is `NaN`.
  11095. *
  11096. * **Note:** This method is based on
  11097. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11098. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11099. * `undefined` and other non-number values.
  11100. *
  11101. * @static
  11102. * @memberOf _
  11103. * @since 0.1.0
  11104. * @category Lang
  11105. * @param {*} value The value to check.
  11106. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11107. * @example
  11108. *
  11109. * _.isNaN(NaN);
  11110. * // => true
  11111. *
  11112. * _.isNaN(new Number(NaN));
  11113. * // => true
  11114. *
  11115. * isNaN(undefined);
  11116. * // => true
  11117. *
  11118. * _.isNaN(undefined);
  11119. * // => false
  11120. */
  11121. function isNaN(value) {
  11122. // An `NaN` primitive is the only value that is not equal to itself.
  11123. // Perform the `toStringTag` check first to avoid errors with some
  11124. // ActiveX objects in IE.
  11125. return isNumber(value) && value != +value;
  11126. }
  11127. /**
  11128. * Checks if `value` is a pristine native function.
  11129. *
  11130. * **Note:** This method can't reliably detect native functions in the presence
  11131. * of the core-js package because core-js circumvents this kind of detection.
  11132. * Despite multiple requests, the core-js maintainer has made it clear: any
  11133. * attempt to fix the detection will be obstructed. As a result, we're left
  11134. * with little choice but to throw an error. Unfortunately, this also affects
  11135. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11136. * which rely on core-js.
  11137. *
  11138. * @static
  11139. * @memberOf _
  11140. * @since 3.0.0
  11141. * @category Lang
  11142. * @param {*} value The value to check.
  11143. * @returns {boolean} Returns `true` if `value` is a native function,
  11144. * else `false`.
  11145. * @example
  11146. *
  11147. * _.isNative(Array.prototype.push);
  11148. * // => true
  11149. *
  11150. * _.isNative(_);
  11151. * // => false
  11152. */
  11153. function isNative(value) {
  11154. if (isMaskable(value)) {
  11155. throw new Error(CORE_ERROR_TEXT);
  11156. }
  11157. return baseIsNative(value);
  11158. }
  11159. /**
  11160. * Checks if `value` is `null`.
  11161. *
  11162. * @static
  11163. * @memberOf _
  11164. * @since 0.1.0
  11165. * @category Lang
  11166. * @param {*} value The value to check.
  11167. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11168. * @example
  11169. *
  11170. * _.isNull(null);
  11171. * // => true
  11172. *
  11173. * _.isNull(void 0);
  11174. * // => false
  11175. */
  11176. function isNull(value) {
  11177. return value === null;
  11178. }
  11179. /**
  11180. * Checks if `value` is `null` or `undefined`.
  11181. *
  11182. * @static
  11183. * @memberOf _
  11184. * @since 4.0.0
  11185. * @category Lang
  11186. * @param {*} value The value to check.
  11187. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11188. * @example
  11189. *
  11190. * _.isNil(null);
  11191. * // => true
  11192. *
  11193. * _.isNil(void 0);
  11194. * // => true
  11195. *
  11196. * _.isNil(NaN);
  11197. * // => false
  11198. */
  11199. function isNil(value) {
  11200. return value == null;
  11201. }
  11202. /**
  11203. * Checks if `value` is classified as a `Number` primitive or object.
  11204. *
  11205. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11206. * classified as numbers, use the `_.isFinite` method.
  11207. *
  11208. * @static
  11209. * @memberOf _
  11210. * @since 0.1.0
  11211. * @category Lang
  11212. * @param {*} value The value to check.
  11213. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11214. * @example
  11215. *
  11216. * _.isNumber(3);
  11217. * // => true
  11218. *
  11219. * _.isNumber(Number.MIN_VALUE);
  11220. * // => true
  11221. *
  11222. * _.isNumber(Infinity);
  11223. * // => true
  11224. *
  11225. * _.isNumber('3');
  11226. * // => false
  11227. */
  11228. function isNumber(value) {
  11229. return typeof value == 'number' ||
  11230. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11231. }
  11232. /**
  11233. * Checks if `value` is a plain object, that is, an object created by the
  11234. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11235. *
  11236. * @static
  11237. * @memberOf _
  11238. * @since 0.8.0
  11239. * @category Lang
  11240. * @param {*} value The value to check.
  11241. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11242. * @example
  11243. *
  11244. * function Foo() {
  11245. * this.a = 1;
  11246. * }
  11247. *
  11248. * _.isPlainObject(new Foo);
  11249. * // => false
  11250. *
  11251. * _.isPlainObject([1, 2, 3]);
  11252. * // => false
  11253. *
  11254. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11255. * // => true
  11256. *
  11257. * _.isPlainObject(Object.create(null));
  11258. * // => true
  11259. */
  11260. function isPlainObject(value) {
  11261. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11262. return false;
  11263. }
  11264. var proto = getPrototype(value);
  11265. if (proto === null) {
  11266. return true;
  11267. }
  11268. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11269. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11270. funcToString.call(Ctor) == objectCtorString;
  11271. }
  11272. /**
  11273. * Checks if `value` is classified as a `RegExp` object.
  11274. *
  11275. * @static
  11276. * @memberOf _
  11277. * @since 0.1.0
  11278. * @category Lang
  11279. * @param {*} value The value to check.
  11280. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11281. * @example
  11282. *
  11283. * _.isRegExp(/abc/);
  11284. * // => true
  11285. *
  11286. * _.isRegExp('/abc/');
  11287. * // => false
  11288. */
  11289. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11290. /**
  11291. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11292. * double precision number which isn't the result of a rounded unsafe integer.
  11293. *
  11294. * **Note:** This method is based on
  11295. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11296. *
  11297. * @static
  11298. * @memberOf _
  11299. * @since 4.0.0
  11300. * @category Lang
  11301. * @param {*} value The value to check.
  11302. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11303. * @example
  11304. *
  11305. * _.isSafeInteger(3);
  11306. * // => true
  11307. *
  11308. * _.isSafeInteger(Number.MIN_VALUE);
  11309. * // => false
  11310. *
  11311. * _.isSafeInteger(Infinity);
  11312. * // => false
  11313. *
  11314. * _.isSafeInteger('3');
  11315. * // => false
  11316. */
  11317. function isSafeInteger(value) {
  11318. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11319. }
  11320. /**
  11321. * Checks if `value` is classified as a `Set` object.
  11322. *
  11323. * @static
  11324. * @memberOf _
  11325. * @since 4.3.0
  11326. * @category Lang
  11327. * @param {*} value The value to check.
  11328. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11329. * @example
  11330. *
  11331. * _.isSet(new Set);
  11332. * // => true
  11333. *
  11334. * _.isSet(new WeakSet);
  11335. * // => false
  11336. */
  11337. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11338. /**
  11339. * Checks if `value` is classified as a `String` primitive or object.
  11340. *
  11341. * @static
  11342. * @since 0.1.0
  11343. * @memberOf _
  11344. * @category Lang
  11345. * @param {*} value The value to check.
  11346. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11347. * @example
  11348. *
  11349. * _.isString('abc');
  11350. * // => true
  11351. *
  11352. * _.isString(1);
  11353. * // => false
  11354. */
  11355. function isString(value) {
  11356. return typeof value == 'string' ||
  11357. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11358. }
  11359. /**
  11360. * Checks if `value` is classified as a `Symbol` primitive or object.
  11361. *
  11362. * @static
  11363. * @memberOf _
  11364. * @since 4.0.0
  11365. * @category Lang
  11366. * @param {*} value The value to check.
  11367. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11368. * @example
  11369. *
  11370. * _.isSymbol(Symbol.iterator);
  11371. * // => true
  11372. *
  11373. * _.isSymbol('abc');
  11374. * // => false
  11375. */
  11376. function isSymbol(value) {
  11377. return typeof value == 'symbol' ||
  11378. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11379. }
  11380. /**
  11381. * Checks if `value` is classified as a typed array.
  11382. *
  11383. * @static
  11384. * @memberOf _
  11385. * @since 3.0.0
  11386. * @category Lang
  11387. * @param {*} value The value to check.
  11388. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11389. * @example
  11390. *
  11391. * _.isTypedArray(new Uint8Array);
  11392. * // => true
  11393. *
  11394. * _.isTypedArray([]);
  11395. * // => false
  11396. */
  11397. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11398. /**
  11399. * Checks if `value` is `undefined`.
  11400. *
  11401. * @static
  11402. * @since 0.1.0
  11403. * @memberOf _
  11404. * @category Lang
  11405. * @param {*} value The value to check.
  11406. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11407. * @example
  11408. *
  11409. * _.isUndefined(void 0);
  11410. * // => true
  11411. *
  11412. * _.isUndefined(null);
  11413. * // => false
  11414. */
  11415. function isUndefined(value) {
  11416. return value === undefined;
  11417. }
  11418. /**
  11419. * Checks if `value` is classified as a `WeakMap` object.
  11420. *
  11421. * @static
  11422. * @memberOf _
  11423. * @since 4.3.0
  11424. * @category Lang
  11425. * @param {*} value The value to check.
  11426. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11427. * @example
  11428. *
  11429. * _.isWeakMap(new WeakMap);
  11430. * // => true
  11431. *
  11432. * _.isWeakMap(new Map);
  11433. * // => false
  11434. */
  11435. function isWeakMap(value) {
  11436. return isObjectLike(value) && getTag(value) == weakMapTag;
  11437. }
  11438. /**
  11439. * Checks if `value` is classified as a `WeakSet` object.
  11440. *
  11441. * @static
  11442. * @memberOf _
  11443. * @since 4.3.0
  11444. * @category Lang
  11445. * @param {*} value The value to check.
  11446. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11447. * @example
  11448. *
  11449. * _.isWeakSet(new WeakSet);
  11450. * // => true
  11451. *
  11452. * _.isWeakSet(new Set);
  11453. * // => false
  11454. */
  11455. function isWeakSet(value) {
  11456. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11457. }
  11458. /**
  11459. * Checks if `value` is less than `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 `other`,
  11468. * else `false`.
  11469. * @see _.gt
  11470. * @example
  11471. *
  11472. * _.lt(1, 3);
  11473. * // => true
  11474. *
  11475. * _.lt(3, 3);
  11476. * // => false
  11477. *
  11478. * _.lt(3, 1);
  11479. * // => false
  11480. */
  11481. var lt = createRelationalOperation(baseLt);
  11482. /**
  11483. * Checks if `value` is less than or equal to `other`.
  11484. *
  11485. * @static
  11486. * @memberOf _
  11487. * @since 3.9.0
  11488. * @category Lang
  11489. * @param {*} value The value to compare.
  11490. * @param {*} other The other value to compare.
  11491. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11492. * `other`, else `false`.
  11493. * @see _.gte
  11494. * @example
  11495. *
  11496. * _.lte(1, 3);
  11497. * // => true
  11498. *
  11499. * _.lte(3, 3);
  11500. * // => true
  11501. *
  11502. * _.lte(3, 1);
  11503. * // => false
  11504. */
  11505. var lte = createRelationalOperation(function(value, other) {
  11506. return value <= other;
  11507. });
  11508. /**
  11509. * Converts `value` to an array.
  11510. *
  11511. * @static
  11512. * @since 0.1.0
  11513. * @memberOf _
  11514. * @category Lang
  11515. * @param {*} value The value to convert.
  11516. * @returns {Array} Returns the converted array.
  11517. * @example
  11518. *
  11519. * _.toArray({ 'a': 1, 'b': 2 });
  11520. * // => [1, 2]
  11521. *
  11522. * _.toArray('abc');
  11523. * // => ['a', 'b', 'c']
  11524. *
  11525. * _.toArray(1);
  11526. * // => []
  11527. *
  11528. * _.toArray(null);
  11529. * // => []
  11530. */
  11531. function toArray(value) {
  11532. if (!value) {
  11533. return [];
  11534. }
  11535. if (isArrayLike(value)) {
  11536. return isString(value) ? stringToArray(value) : copyArray(value);
  11537. }
  11538. if (symIterator && value[symIterator]) {
  11539. return iteratorToArray(value[symIterator]());
  11540. }
  11541. var tag = getTag(value),
  11542. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11543. return func(value);
  11544. }
  11545. /**
  11546. * Converts `value` to a finite number.
  11547. *
  11548. * @static
  11549. * @memberOf _
  11550. * @since 4.12.0
  11551. * @category Lang
  11552. * @param {*} value The value to convert.
  11553. * @returns {number} Returns the converted number.
  11554. * @example
  11555. *
  11556. * _.toFinite(3.2);
  11557. * // => 3.2
  11558. *
  11559. * _.toFinite(Number.MIN_VALUE);
  11560. * // => 5e-324
  11561. *
  11562. * _.toFinite(Infinity);
  11563. * // => 1.7976931348623157e+308
  11564. *
  11565. * _.toFinite('3.2');
  11566. * // => 3.2
  11567. */
  11568. function toFinite(value) {
  11569. if (!value) {
  11570. return value === 0 ? value : 0;
  11571. }
  11572. value = toNumber(value);
  11573. if (value === INFINITY || value === -INFINITY) {
  11574. var sign = (value < 0 ? -1 : 1);
  11575. return sign * MAX_INTEGER;
  11576. }
  11577. return value === value ? value : 0;
  11578. }
  11579. /**
  11580. * Converts `value` to an integer.
  11581. *
  11582. * **Note:** This method is loosely based on
  11583. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11584. *
  11585. * @static
  11586. * @memberOf _
  11587. * @since 4.0.0
  11588. * @category Lang
  11589. * @param {*} value The value to convert.
  11590. * @returns {number} Returns the converted integer.
  11591. * @example
  11592. *
  11593. * _.toInteger(3.2);
  11594. * // => 3
  11595. *
  11596. * _.toInteger(Number.MIN_VALUE);
  11597. * // => 0
  11598. *
  11599. * _.toInteger(Infinity);
  11600. * // => 1.7976931348623157e+308
  11601. *
  11602. * _.toInteger('3.2');
  11603. * // => 3
  11604. */
  11605. function toInteger(value) {
  11606. var result = toFinite(value),
  11607. remainder = result % 1;
  11608. return result === result ? (remainder ? result - remainder : result) : 0;
  11609. }
  11610. /**
  11611. * Converts `value` to an integer suitable for use as the length of an
  11612. * array-like object.
  11613. *
  11614. * **Note:** This method is based on
  11615. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11616. *
  11617. * @static
  11618. * @memberOf _
  11619. * @since 4.0.0
  11620. * @category Lang
  11621. * @param {*} value The value to convert.
  11622. * @returns {number} Returns the converted integer.
  11623. * @example
  11624. *
  11625. * _.toLength(3.2);
  11626. * // => 3
  11627. *
  11628. * _.toLength(Number.MIN_VALUE);
  11629. * // => 0
  11630. *
  11631. * _.toLength(Infinity);
  11632. * // => 4294967295
  11633. *
  11634. * _.toLength('3.2');
  11635. * // => 3
  11636. */
  11637. function toLength(value) {
  11638. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11639. }
  11640. /**
  11641. * Converts `value` to a number.
  11642. *
  11643. * @static
  11644. * @memberOf _
  11645. * @since 4.0.0
  11646. * @category Lang
  11647. * @param {*} value The value to process.
  11648. * @returns {number} Returns the number.
  11649. * @example
  11650. *
  11651. * _.toNumber(3.2);
  11652. * // => 3.2
  11653. *
  11654. * _.toNumber(Number.MIN_VALUE);
  11655. * // => 5e-324
  11656. *
  11657. * _.toNumber(Infinity);
  11658. * // => Infinity
  11659. *
  11660. * _.toNumber('3.2');
  11661. * // => 3.2
  11662. */
  11663. function toNumber(value) {
  11664. if (typeof value == 'number') {
  11665. return value;
  11666. }
  11667. if (isSymbol(value)) {
  11668. return NAN;
  11669. }
  11670. if (isObject(value)) {
  11671. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11672. value = isObject(other) ? (other + '') : other;
  11673. }
  11674. if (typeof value != 'string') {
  11675. return value === 0 ? value : +value;
  11676. }
  11677. value = value.replace(reTrim, '');
  11678. var isBinary = reIsBinary.test(value);
  11679. return (isBinary || reIsOctal.test(value))
  11680. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11681. : (reIsBadHex.test(value) ? NAN : +value);
  11682. }
  11683. /**
  11684. * Converts `value` to a plain object flattening inherited enumerable string
  11685. * keyed properties of `value` to own properties of the plain object.
  11686. *
  11687. * @static
  11688. * @memberOf _
  11689. * @since 3.0.0
  11690. * @category Lang
  11691. * @param {*} value The value to convert.
  11692. * @returns {Object} Returns the converted plain object.
  11693. * @example
  11694. *
  11695. * function Foo() {
  11696. * this.b = 2;
  11697. * }
  11698. *
  11699. * Foo.prototype.c = 3;
  11700. *
  11701. * _.assign({ 'a': 1 }, new Foo);
  11702. * // => { 'a': 1, 'b': 2 }
  11703. *
  11704. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11705. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11706. */
  11707. function toPlainObject(value) {
  11708. return copyObject(value, keysIn(value));
  11709. }
  11710. /**
  11711. * Converts `value` to a safe integer. A safe integer can be compared and
  11712. * represented correctly.
  11713. *
  11714. * @static
  11715. * @memberOf _
  11716. * @since 4.0.0
  11717. * @category Lang
  11718. * @param {*} value The value to convert.
  11719. * @returns {number} Returns the converted integer.
  11720. * @example
  11721. *
  11722. * _.toSafeInteger(3.2);
  11723. * // => 3
  11724. *
  11725. * _.toSafeInteger(Number.MIN_VALUE);
  11726. * // => 0
  11727. *
  11728. * _.toSafeInteger(Infinity);
  11729. * // => 9007199254740991
  11730. *
  11731. * _.toSafeInteger('3.2');
  11732. * // => 3
  11733. */
  11734. function toSafeInteger(value) {
  11735. return value
  11736. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11737. : (value === 0 ? value : 0);
  11738. }
  11739. /**
  11740. * Converts `value` to a string. An empty string is returned for `null`
  11741. * and `undefined` values. The sign of `-0` is preserved.
  11742. *
  11743. * @static
  11744. * @memberOf _
  11745. * @since 4.0.0
  11746. * @category Lang
  11747. * @param {*} value The value to convert.
  11748. * @returns {string} Returns the converted string.
  11749. * @example
  11750. *
  11751. * _.toString(null);
  11752. * // => ''
  11753. *
  11754. * _.toString(-0);
  11755. * // => '-0'
  11756. *
  11757. * _.toString([1, 2, 3]);
  11758. * // => '1,2,3'
  11759. */
  11760. function toString(value) {
  11761. return value == null ? '' : baseToString(value);
  11762. }
  11763. /*------------------------------------------------------------------------*/
  11764. /**
  11765. * Assigns own enumerable string keyed properties of source objects to the
  11766. * destination object. Source objects are applied from left to right.
  11767. * Subsequent sources overwrite property assignments of previous sources.
  11768. *
  11769. * **Note:** This method mutates `object` and is loosely based on
  11770. * [`Object.assign`](https://mdn.io/Object/assign).
  11771. *
  11772. * @static
  11773. * @memberOf _
  11774. * @since 0.10.0
  11775. * @category Object
  11776. * @param {Object} object The destination object.
  11777. * @param {...Object} [sources] The source objects.
  11778. * @returns {Object} Returns `object`.
  11779. * @see _.assignIn
  11780. * @example
  11781. *
  11782. * function Foo() {
  11783. * this.a = 1;
  11784. * }
  11785. *
  11786. * function Bar() {
  11787. * this.c = 3;
  11788. * }
  11789. *
  11790. * Foo.prototype.b = 2;
  11791. * Bar.prototype.d = 4;
  11792. *
  11793. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11794. * // => { 'a': 1, 'c': 3 }
  11795. */
  11796. var assign = createAssigner(function(object, source) {
  11797. if (isPrototype(source) || isArrayLike(source)) {
  11798. copyObject(source, keys(source), object);
  11799. return;
  11800. }
  11801. for (var key in source) {
  11802. if (hasOwnProperty.call(source, key)) {
  11803. assignValue(object, key, source[key]);
  11804. }
  11805. }
  11806. });
  11807. /**
  11808. * This method is like `_.assign` except that it iterates over own and
  11809. * inherited source properties.
  11810. *
  11811. * **Note:** This method mutates `object`.
  11812. *
  11813. * @static
  11814. * @memberOf _
  11815. * @since 4.0.0
  11816. * @alias extend
  11817. * @category Object
  11818. * @param {Object} object The destination object.
  11819. * @param {...Object} [sources] The source objects.
  11820. * @returns {Object} Returns `object`.
  11821. * @see _.assign
  11822. * @example
  11823. *
  11824. * function Foo() {
  11825. * this.a = 1;
  11826. * }
  11827. *
  11828. * function Bar() {
  11829. * this.c = 3;
  11830. * }
  11831. *
  11832. * Foo.prototype.b = 2;
  11833. * Bar.prototype.d = 4;
  11834. *
  11835. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11836. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11837. */
  11838. var assignIn = createAssigner(function(object, source) {
  11839. copyObject(source, keysIn(source), object);
  11840. });
  11841. /**
  11842. * This method is like `_.assignIn` except that it accepts `customizer`
  11843. * which is invoked to produce the assigned values. If `customizer` returns
  11844. * `undefined`, assignment is handled by the method instead. The `customizer`
  11845. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11846. *
  11847. * **Note:** This method mutates `object`.
  11848. *
  11849. * @static
  11850. * @memberOf _
  11851. * @since 4.0.0
  11852. * @alias extendWith
  11853. * @category Object
  11854. * @param {Object} object The destination object.
  11855. * @param {...Object} sources The source objects.
  11856. * @param {Function} [customizer] The function to customize assigned values.
  11857. * @returns {Object} Returns `object`.
  11858. * @see _.assignWith
  11859. * @example
  11860. *
  11861. * function customizer(objValue, srcValue) {
  11862. * return _.isUndefined(objValue) ? srcValue : objValue;
  11863. * }
  11864. *
  11865. * var defaults = _.partialRight(_.assignInWith, customizer);
  11866. *
  11867. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11868. * // => { 'a': 1, 'b': 2 }
  11869. */
  11870. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11871. copyObject(source, keysIn(source), object, customizer);
  11872. });
  11873. /**
  11874. * This method is like `_.assign` except that it accepts `customizer`
  11875. * which is invoked to produce the assigned values. If `customizer` returns
  11876. * `undefined`, assignment is handled by the method instead. The `customizer`
  11877. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11878. *
  11879. * **Note:** This method mutates `object`.
  11880. *
  11881. * @static
  11882. * @memberOf _
  11883. * @since 4.0.0
  11884. * @category Object
  11885. * @param {Object} object The destination object.
  11886. * @param {...Object} sources The source objects.
  11887. * @param {Function} [customizer] The function to customize assigned values.
  11888. * @returns {Object} Returns `object`.
  11889. * @see _.assignInWith
  11890. * @example
  11891. *
  11892. * function customizer(objValue, srcValue) {
  11893. * return _.isUndefined(objValue) ? srcValue : objValue;
  11894. * }
  11895. *
  11896. * var defaults = _.partialRight(_.assignWith, customizer);
  11897. *
  11898. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11899. * // => { 'a': 1, 'b': 2 }
  11900. */
  11901. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11902. copyObject(source, keys(source), object, customizer);
  11903. });
  11904. /**
  11905. * Creates an array of values corresponding to `paths` of `object`.
  11906. *
  11907. * @static
  11908. * @memberOf _
  11909. * @since 1.0.0
  11910. * @category Object
  11911. * @param {Object} object The object to iterate over.
  11912. * @param {...(string|string[])} [paths] The property paths to pick.
  11913. * @returns {Array} Returns the picked values.
  11914. * @example
  11915. *
  11916. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11917. *
  11918. * _.at(object, ['a[0].b.c', 'a[1]']);
  11919. * // => [3, 4]
  11920. */
  11921. var at = flatRest(baseAt);
  11922. /**
  11923. * Creates an object that inherits from the `prototype` object. If a
  11924. * `properties` object is given, its own enumerable string keyed properties
  11925. * are assigned to the created object.
  11926. *
  11927. * @static
  11928. * @memberOf _
  11929. * @since 2.3.0
  11930. * @category Object
  11931. * @param {Object} prototype The object to inherit from.
  11932. * @param {Object} [properties] The properties to assign to the object.
  11933. * @returns {Object} Returns the new object.
  11934. * @example
  11935. *
  11936. * function Shape() {
  11937. * this.x = 0;
  11938. * this.y = 0;
  11939. * }
  11940. *
  11941. * function Circle() {
  11942. * Shape.call(this);
  11943. * }
  11944. *
  11945. * Circle.prototype = _.create(Shape.prototype, {
  11946. * 'constructor': Circle
  11947. * });
  11948. *
  11949. * var circle = new Circle;
  11950. * circle instanceof Circle;
  11951. * // => true
  11952. *
  11953. * circle instanceof Shape;
  11954. * // => true
  11955. */
  11956. function create(prototype, properties) {
  11957. var result = baseCreate(prototype);
  11958. return properties == null ? result : baseAssign(result, properties);
  11959. }
  11960. /**
  11961. * Assigns own and inherited enumerable string keyed properties of source
  11962. * objects to the destination object for all destination properties that
  11963. * resolve to `undefined`. Source objects are applied from left to right.
  11964. * Once a property is set, additional values of the same property are ignored.
  11965. *
  11966. * **Note:** This method mutates `object`.
  11967. *
  11968. * @static
  11969. * @since 0.1.0
  11970. * @memberOf _
  11971. * @category Object
  11972. * @param {Object} object The destination object.
  11973. * @param {...Object} [sources] The source objects.
  11974. * @returns {Object} Returns `object`.
  11975. * @see _.defaultsDeep
  11976. * @example
  11977. *
  11978. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11979. * // => { 'a': 1, 'b': 2 }
  11980. */
  11981. var defaults = baseRest(function(object, sources) {
  11982. object = Object(object);
  11983. var index = -1;
  11984. var length = sources.length;
  11985. var guard = length > 2 ? sources[2] : undefined;
  11986. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  11987. length = 1;
  11988. }
  11989. while (++index < length) {
  11990. var source = sources[index];
  11991. var props = keysIn(source);
  11992. var propsIndex = -1;
  11993. var propsLength = props.length;
  11994. while (++propsIndex < propsLength) {
  11995. var key = props[propsIndex];
  11996. var value = object[key];
  11997. if (value === undefined ||
  11998. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  11999. object[key] = source[key];
  12000. }
  12001. }
  12002. }
  12003. return object;
  12004. });
  12005. /**
  12006. * This method is like `_.defaults` except that it recursively assigns
  12007. * default properties.
  12008. *
  12009. * **Note:** This method mutates `object`.
  12010. *
  12011. * @static
  12012. * @memberOf _
  12013. * @since 3.10.0
  12014. * @category Object
  12015. * @param {Object} object The destination object.
  12016. * @param {...Object} [sources] The source objects.
  12017. * @returns {Object} Returns `object`.
  12018. * @see _.defaults
  12019. * @example
  12020. *
  12021. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  12022. * // => { 'a': { 'b': 2, 'c': 3 } }
  12023. */
  12024. var defaultsDeep = baseRest(function(args) {
  12025. args.push(undefined, customDefaultsMerge);
  12026. return apply(mergeWith, undefined, args);
  12027. });
  12028. /**
  12029. * This method is like `_.find` except that it returns the key of the first
  12030. * element `predicate` returns truthy for instead of the element itself.
  12031. *
  12032. * @static
  12033. * @memberOf _
  12034. * @since 1.1.0
  12035. * @category Object
  12036. * @param {Object} object The object to inspect.
  12037. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12038. * @returns {string|undefined} Returns the key of the matched element,
  12039. * else `undefined`.
  12040. * @example
  12041. *
  12042. * var users = {
  12043. * 'barney': { 'age': 36, 'active': true },
  12044. * 'fred': { 'age': 40, 'active': false },
  12045. * 'pebbles': { 'age': 1, 'active': true }
  12046. * };
  12047. *
  12048. * _.findKey(users, function(o) { return o.age < 40; });
  12049. * // => 'barney' (iteration order is not guaranteed)
  12050. *
  12051. * // The `_.matches` iteratee shorthand.
  12052. * _.findKey(users, { 'age': 1, 'active': true });
  12053. * // => 'pebbles'
  12054. *
  12055. * // The `_.matchesProperty` iteratee shorthand.
  12056. * _.findKey(users, ['active', false]);
  12057. * // => 'fred'
  12058. *
  12059. * // The `_.property` iteratee shorthand.
  12060. * _.findKey(users, 'active');
  12061. * // => 'barney'
  12062. */
  12063. function findKey(object, predicate) {
  12064. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12065. }
  12066. /**
  12067. * This method is like `_.findKey` except that it iterates over elements of
  12068. * a collection in the opposite order.
  12069. *
  12070. * @static
  12071. * @memberOf _
  12072. * @since 2.0.0
  12073. * @category Object
  12074. * @param {Object} object The object to inspect.
  12075. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12076. * @returns {string|undefined} Returns the key of the matched element,
  12077. * else `undefined`.
  12078. * @example
  12079. *
  12080. * var users = {
  12081. * 'barney': { 'age': 36, 'active': true },
  12082. * 'fred': { 'age': 40, 'active': false },
  12083. * 'pebbles': { 'age': 1, 'active': true }
  12084. * };
  12085. *
  12086. * _.findLastKey(users, function(o) { return o.age < 40; });
  12087. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12088. *
  12089. * // The `_.matches` iteratee shorthand.
  12090. * _.findLastKey(users, { 'age': 36, 'active': true });
  12091. * // => 'barney'
  12092. *
  12093. * // The `_.matchesProperty` iteratee shorthand.
  12094. * _.findLastKey(users, ['active', false]);
  12095. * // => 'fred'
  12096. *
  12097. * // The `_.property` iteratee shorthand.
  12098. * _.findLastKey(users, 'active');
  12099. * // => 'pebbles'
  12100. */
  12101. function findLastKey(object, predicate) {
  12102. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12103. }
  12104. /**
  12105. * Iterates over own and inherited enumerable string keyed properties of an
  12106. * object and invokes `iteratee` for each property. The iteratee is invoked
  12107. * with three arguments: (value, key, object). Iteratee functions may exit
  12108. * iteration early by explicitly returning `false`.
  12109. *
  12110. * @static
  12111. * @memberOf _
  12112. * @since 0.3.0
  12113. * @category Object
  12114. * @param {Object} object The object to iterate over.
  12115. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12116. * @returns {Object} Returns `object`.
  12117. * @see _.forInRight
  12118. * @example
  12119. *
  12120. * function Foo() {
  12121. * this.a = 1;
  12122. * this.b = 2;
  12123. * }
  12124. *
  12125. * Foo.prototype.c = 3;
  12126. *
  12127. * _.forIn(new Foo, function(value, key) {
  12128. * console.log(key);
  12129. * });
  12130. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12131. */
  12132. function forIn(object, iteratee) {
  12133. return object == null
  12134. ? object
  12135. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12136. }
  12137. /**
  12138. * This method is like `_.forIn` except that it iterates over properties of
  12139. * `object` in the opposite order.
  12140. *
  12141. * @static
  12142. * @memberOf _
  12143. * @since 2.0.0
  12144. * @category Object
  12145. * @param {Object} object The object to iterate over.
  12146. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12147. * @returns {Object} Returns `object`.
  12148. * @see _.forIn
  12149. * @example
  12150. *
  12151. * function Foo() {
  12152. * this.a = 1;
  12153. * this.b = 2;
  12154. * }
  12155. *
  12156. * Foo.prototype.c = 3;
  12157. *
  12158. * _.forInRight(new Foo, function(value, key) {
  12159. * console.log(key);
  12160. * });
  12161. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12162. */
  12163. function forInRight(object, iteratee) {
  12164. return object == null
  12165. ? object
  12166. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12167. }
  12168. /**
  12169. * Iterates over own enumerable string keyed properties of an object and
  12170. * invokes `iteratee` for each property. The iteratee is invoked with three
  12171. * arguments: (value, key, object). Iteratee functions may exit iteration
  12172. * early by explicitly returning `false`.
  12173. *
  12174. * @static
  12175. * @memberOf _
  12176. * @since 0.3.0
  12177. * @category Object
  12178. * @param {Object} object The object to iterate over.
  12179. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12180. * @returns {Object} Returns `object`.
  12181. * @see _.forOwnRight
  12182. * @example
  12183. *
  12184. * function Foo() {
  12185. * this.a = 1;
  12186. * this.b = 2;
  12187. * }
  12188. *
  12189. * Foo.prototype.c = 3;
  12190. *
  12191. * _.forOwn(new Foo, function(value, key) {
  12192. * console.log(key);
  12193. * });
  12194. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12195. */
  12196. function forOwn(object, iteratee) {
  12197. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12198. }
  12199. /**
  12200. * This method is like `_.forOwn` except that it iterates over properties of
  12201. * `object` in the opposite order.
  12202. *
  12203. * @static
  12204. * @memberOf _
  12205. * @since 2.0.0
  12206. * @category Object
  12207. * @param {Object} object The object to iterate over.
  12208. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12209. * @returns {Object} Returns `object`.
  12210. * @see _.forOwn
  12211. * @example
  12212. *
  12213. * function Foo() {
  12214. * this.a = 1;
  12215. * this.b = 2;
  12216. * }
  12217. *
  12218. * Foo.prototype.c = 3;
  12219. *
  12220. * _.forOwnRight(new Foo, function(value, key) {
  12221. * console.log(key);
  12222. * });
  12223. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12224. */
  12225. function forOwnRight(object, iteratee) {
  12226. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12227. }
  12228. /**
  12229. * Creates an array of function property names from own enumerable properties
  12230. * of `object`.
  12231. *
  12232. * @static
  12233. * @since 0.1.0
  12234. * @memberOf _
  12235. * @category Object
  12236. * @param {Object} object The object to inspect.
  12237. * @returns {Array} Returns the function names.
  12238. * @see _.functionsIn
  12239. * @example
  12240. *
  12241. * function Foo() {
  12242. * this.a = _.constant('a');
  12243. * this.b = _.constant('b');
  12244. * }
  12245. *
  12246. * Foo.prototype.c = _.constant('c');
  12247. *
  12248. * _.functions(new Foo);
  12249. * // => ['a', 'b']
  12250. */
  12251. function functions(object) {
  12252. return object == null ? [] : baseFunctions(object, keys(object));
  12253. }
  12254. /**
  12255. * Creates an array of function property names from own and inherited
  12256. * enumerable properties of `object`.
  12257. *
  12258. * @static
  12259. * @memberOf _
  12260. * @since 4.0.0
  12261. * @category Object
  12262. * @param {Object} object The object to inspect.
  12263. * @returns {Array} Returns the function names.
  12264. * @see _.functions
  12265. * @example
  12266. *
  12267. * function Foo() {
  12268. * this.a = _.constant('a');
  12269. * this.b = _.constant('b');
  12270. * }
  12271. *
  12272. * Foo.prototype.c = _.constant('c');
  12273. *
  12274. * _.functionsIn(new Foo);
  12275. * // => ['a', 'b', 'c']
  12276. */
  12277. function functionsIn(object) {
  12278. return object == null ? [] : baseFunctions(object, keysIn(object));
  12279. }
  12280. /**
  12281. * Gets the value at `path` of `object`. If the resolved value is
  12282. * `undefined`, the `defaultValue` is returned in its place.
  12283. *
  12284. * @static
  12285. * @memberOf _
  12286. * @since 3.7.0
  12287. * @category Object
  12288. * @param {Object} object The object to query.
  12289. * @param {Array|string} path The path of the property to get.
  12290. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12291. * @returns {*} Returns the resolved value.
  12292. * @example
  12293. *
  12294. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12295. *
  12296. * _.get(object, 'a[0].b.c');
  12297. * // => 3
  12298. *
  12299. * _.get(object, ['a', '0', 'b', 'c']);
  12300. * // => 3
  12301. *
  12302. * _.get(object, 'a.b.c', 'default');
  12303. * // => 'default'
  12304. */
  12305. function get(object, path, defaultValue) {
  12306. var result = object == null ? undefined : baseGet(object, path);
  12307. return result === undefined ? defaultValue : result;
  12308. }
  12309. /**
  12310. * Checks if `path` is a direct property of `object`.
  12311. *
  12312. * @static
  12313. * @since 0.1.0
  12314. * @memberOf _
  12315. * @category Object
  12316. * @param {Object} object The object to query.
  12317. * @param {Array|string} path The path to check.
  12318. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12319. * @example
  12320. *
  12321. * var object = { 'a': { 'b': 2 } };
  12322. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12323. *
  12324. * _.has(object, 'a');
  12325. * // => true
  12326. *
  12327. * _.has(object, 'a.b');
  12328. * // => true
  12329. *
  12330. * _.has(object, ['a', 'b']);
  12331. * // => true
  12332. *
  12333. * _.has(other, 'a');
  12334. * // => false
  12335. */
  12336. function has(object, path) {
  12337. return object != null && hasPath(object, path, baseHas);
  12338. }
  12339. /**
  12340. * Checks if `path` is a direct or inherited property of `object`.
  12341. *
  12342. * @static
  12343. * @memberOf _
  12344. * @since 4.0.0
  12345. * @category Object
  12346. * @param {Object} object The object to query.
  12347. * @param {Array|string} path The path to check.
  12348. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12349. * @example
  12350. *
  12351. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12352. *
  12353. * _.hasIn(object, 'a');
  12354. * // => true
  12355. *
  12356. * _.hasIn(object, 'a.b');
  12357. * // => true
  12358. *
  12359. * _.hasIn(object, ['a', 'b']);
  12360. * // => true
  12361. *
  12362. * _.hasIn(object, 'b');
  12363. * // => false
  12364. */
  12365. function hasIn(object, path) {
  12366. return object != null && hasPath(object, path, baseHasIn);
  12367. }
  12368. /**
  12369. * Creates an object composed of the inverted keys and values of `object`.
  12370. * If `object` contains duplicate values, subsequent values overwrite
  12371. * property assignments of previous values.
  12372. *
  12373. * @static
  12374. * @memberOf _
  12375. * @since 0.7.0
  12376. * @category Object
  12377. * @param {Object} object The object to invert.
  12378. * @returns {Object} Returns the new inverted object.
  12379. * @example
  12380. *
  12381. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12382. *
  12383. * _.invert(object);
  12384. * // => { '1': 'c', '2': 'b' }
  12385. */
  12386. var invert = createInverter(function(result, value, key) {
  12387. if (value != null &&
  12388. typeof value.toString != 'function') {
  12389. value = nativeObjectToString.call(value);
  12390. }
  12391. result[value] = key;
  12392. }, constant(identity));
  12393. /**
  12394. * This method is like `_.invert` except that the inverted object is generated
  12395. * from the results of running each element of `object` thru `iteratee`. The
  12396. * corresponding inverted value of each inverted key is an array of keys
  12397. * responsible for generating the inverted value. The iteratee is invoked
  12398. * with one argument: (value).
  12399. *
  12400. * @static
  12401. * @memberOf _
  12402. * @since 4.1.0
  12403. * @category Object
  12404. * @param {Object} object The object to invert.
  12405. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12406. * @returns {Object} Returns the new inverted object.
  12407. * @example
  12408. *
  12409. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12410. *
  12411. * _.invertBy(object);
  12412. * // => { '1': ['a', 'c'], '2': ['b'] }
  12413. *
  12414. * _.invertBy(object, function(value) {
  12415. * return 'group' + value;
  12416. * });
  12417. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12418. */
  12419. var invertBy = createInverter(function(result, value, key) {
  12420. if (value != null &&
  12421. typeof value.toString != 'function') {
  12422. value = nativeObjectToString.call(value);
  12423. }
  12424. if (hasOwnProperty.call(result, value)) {
  12425. result[value].push(key);
  12426. } else {
  12427. result[value] = [key];
  12428. }
  12429. }, getIteratee);
  12430. /**
  12431. * Invokes the method at `path` of `object`.
  12432. *
  12433. * @static
  12434. * @memberOf _
  12435. * @since 4.0.0
  12436. * @category Object
  12437. * @param {Object} object The object to query.
  12438. * @param {Array|string} path The path of the method to invoke.
  12439. * @param {...*} [args] The arguments to invoke the method with.
  12440. * @returns {*} Returns the result of the invoked method.
  12441. * @example
  12442. *
  12443. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12444. *
  12445. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12446. * // => [2, 3]
  12447. */
  12448. var invoke = baseRest(baseInvoke);
  12449. /**
  12450. * Creates an array of the own enumerable property names of `object`.
  12451. *
  12452. * **Note:** Non-object values are coerced to objects. See the
  12453. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12454. * for more details.
  12455. *
  12456. * @static
  12457. * @since 0.1.0
  12458. * @memberOf _
  12459. * @category Object
  12460. * @param {Object} object The object to query.
  12461. * @returns {Array} Returns the array of property names.
  12462. * @example
  12463. *
  12464. * function Foo() {
  12465. * this.a = 1;
  12466. * this.b = 2;
  12467. * }
  12468. *
  12469. * Foo.prototype.c = 3;
  12470. *
  12471. * _.keys(new Foo);
  12472. * // => ['a', 'b'] (iteration order is not guaranteed)
  12473. *
  12474. * _.keys('hi');
  12475. * // => ['0', '1']
  12476. */
  12477. function keys(object) {
  12478. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12479. }
  12480. /**
  12481. * Creates an array of the own and inherited enumerable property names of `object`.
  12482. *
  12483. * **Note:** Non-object values are coerced to objects.
  12484. *
  12485. * @static
  12486. * @memberOf _
  12487. * @since 3.0.0
  12488. * @category Object
  12489. * @param {Object} object The object to query.
  12490. * @returns {Array} Returns the array of property names.
  12491. * @example
  12492. *
  12493. * function Foo() {
  12494. * this.a = 1;
  12495. * this.b = 2;
  12496. * }
  12497. *
  12498. * Foo.prototype.c = 3;
  12499. *
  12500. * _.keysIn(new Foo);
  12501. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12502. */
  12503. function keysIn(object) {
  12504. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12505. }
  12506. /**
  12507. * The opposite of `_.mapValues`; this method creates an object with the
  12508. * same values as `object` and keys generated by running each own enumerable
  12509. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12510. * with three arguments: (value, key, object).
  12511. *
  12512. * @static
  12513. * @memberOf _
  12514. * @since 3.8.0
  12515. * @category Object
  12516. * @param {Object} object The object to iterate over.
  12517. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12518. * @returns {Object} Returns the new mapped object.
  12519. * @see _.mapValues
  12520. * @example
  12521. *
  12522. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12523. * return key + value;
  12524. * });
  12525. * // => { 'a1': 1, 'b2': 2 }
  12526. */
  12527. function mapKeys(object, iteratee) {
  12528. var result = {};
  12529. iteratee = getIteratee(iteratee, 3);
  12530. baseForOwn(object, function(value, key, object) {
  12531. baseAssignValue(result, iteratee(value, key, object), value);
  12532. });
  12533. return result;
  12534. }
  12535. /**
  12536. * Creates an object with the same keys as `object` and values generated
  12537. * by running each own enumerable string keyed property of `object` thru
  12538. * `iteratee`. The iteratee is invoked with three arguments:
  12539. * (value, key, object).
  12540. *
  12541. * @static
  12542. * @memberOf _
  12543. * @since 2.4.0
  12544. * @category Object
  12545. * @param {Object} object The object to iterate over.
  12546. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12547. * @returns {Object} Returns the new mapped object.
  12548. * @see _.mapKeys
  12549. * @example
  12550. *
  12551. * var users = {
  12552. * 'fred': { 'user': 'fred', 'age': 40 },
  12553. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12554. * };
  12555. *
  12556. * _.mapValues(users, function(o) { return o.age; });
  12557. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12558. *
  12559. * // The `_.property` iteratee shorthand.
  12560. * _.mapValues(users, 'age');
  12561. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12562. */
  12563. function mapValues(object, iteratee) {
  12564. var result = {};
  12565. iteratee = getIteratee(iteratee, 3);
  12566. baseForOwn(object, function(value, key, object) {
  12567. baseAssignValue(result, key, iteratee(value, key, object));
  12568. });
  12569. return result;
  12570. }
  12571. /**
  12572. * This method is like `_.assign` except that it recursively merges own and
  12573. * inherited enumerable string keyed properties of source objects into the
  12574. * destination object. Source properties that resolve to `undefined` are
  12575. * skipped if a destination value exists. Array and plain object properties
  12576. * are merged recursively. Other objects and value types are overridden by
  12577. * assignment. Source objects are applied from left to right. Subsequent
  12578. * sources overwrite property assignments of previous sources.
  12579. *
  12580. * **Note:** This method mutates `object`.
  12581. *
  12582. * @static
  12583. * @memberOf _
  12584. * @since 0.5.0
  12585. * @category Object
  12586. * @param {Object} object The destination object.
  12587. * @param {...Object} [sources] The source objects.
  12588. * @returns {Object} Returns `object`.
  12589. * @example
  12590. *
  12591. * var object = {
  12592. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12593. * };
  12594. *
  12595. * var other = {
  12596. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12597. * };
  12598. *
  12599. * _.merge(object, other);
  12600. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12601. */
  12602. var merge = createAssigner(function(object, source, srcIndex) {
  12603. baseMerge(object, source, srcIndex);
  12604. });
  12605. /**
  12606. * This method is like `_.merge` except that it accepts `customizer` which
  12607. * is invoked to produce the merged values of the destination and source
  12608. * properties. If `customizer` returns `undefined`, merging is handled by the
  12609. * method instead. The `customizer` is invoked with six arguments:
  12610. * (objValue, srcValue, key, object, source, stack).
  12611. *
  12612. * **Note:** This method mutates `object`.
  12613. *
  12614. * @static
  12615. * @memberOf _
  12616. * @since 4.0.0
  12617. * @category Object
  12618. * @param {Object} object The destination object.
  12619. * @param {...Object} sources The source objects.
  12620. * @param {Function} customizer The function to customize assigned values.
  12621. * @returns {Object} Returns `object`.
  12622. * @example
  12623. *
  12624. * function customizer(objValue, srcValue) {
  12625. * if (_.isArray(objValue)) {
  12626. * return objValue.concat(srcValue);
  12627. * }
  12628. * }
  12629. *
  12630. * var object = { 'a': [1], 'b': [2] };
  12631. * var other = { 'a': [3], 'b': [4] };
  12632. *
  12633. * _.mergeWith(object, other, customizer);
  12634. * // => { 'a': [1, 3], 'b': [2, 4] }
  12635. */
  12636. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12637. baseMerge(object, source, srcIndex, customizer);
  12638. });
  12639. /**
  12640. * The opposite of `_.pick`; this method creates an object composed of the
  12641. * own and inherited enumerable property paths of `object` that are not omitted.
  12642. *
  12643. * **Note:** This method is considerably slower than `_.pick`.
  12644. *
  12645. * @static
  12646. * @since 0.1.0
  12647. * @memberOf _
  12648. * @category Object
  12649. * @param {Object} object The source object.
  12650. * @param {...(string|string[])} [paths] The property paths to omit.
  12651. * @returns {Object} Returns the new object.
  12652. * @example
  12653. *
  12654. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12655. *
  12656. * _.omit(object, ['a', 'c']);
  12657. * // => { 'b': '2' }
  12658. */
  12659. var omit = flatRest(function(object, paths) {
  12660. var result = {};
  12661. if (object == null) {
  12662. return result;
  12663. }
  12664. var isDeep = false;
  12665. paths = arrayMap(paths, function(path) {
  12666. path = castPath(path, object);
  12667. isDeep || (isDeep = path.length > 1);
  12668. return path;
  12669. });
  12670. copyObject(object, getAllKeysIn(object), result);
  12671. if (isDeep) {
  12672. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12673. }
  12674. var length = paths.length;
  12675. while (length--) {
  12676. baseUnset(result, paths[length]);
  12677. }
  12678. return result;
  12679. });
  12680. /**
  12681. * The opposite of `_.pickBy`; this method creates an object composed of
  12682. * the own and inherited enumerable string keyed properties of `object` that
  12683. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12684. * arguments: (value, key).
  12685. *
  12686. * @static
  12687. * @memberOf _
  12688. * @since 4.0.0
  12689. * @category Object
  12690. * @param {Object} object The source object.
  12691. * @param {Function} [predicate=_.identity] The function invoked per property.
  12692. * @returns {Object} Returns the new object.
  12693. * @example
  12694. *
  12695. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12696. *
  12697. * _.omitBy(object, _.isNumber);
  12698. * // => { 'b': '2' }
  12699. */
  12700. function omitBy(object, predicate) {
  12701. return pickBy(object, negate(getIteratee(predicate)));
  12702. }
  12703. /**
  12704. * Creates an object composed of the picked `object` properties.
  12705. *
  12706. * @static
  12707. * @since 0.1.0
  12708. * @memberOf _
  12709. * @category Object
  12710. * @param {Object} object The source object.
  12711. * @param {...(string|string[])} [paths] The property paths to pick.
  12712. * @returns {Object} Returns the new object.
  12713. * @example
  12714. *
  12715. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12716. *
  12717. * _.pick(object, ['a', 'c']);
  12718. * // => { 'a': 1, 'c': 3 }
  12719. */
  12720. var pick = flatRest(function(object, paths) {
  12721. return object == null ? {} : basePick(object, paths);
  12722. });
  12723. /**
  12724. * Creates an object composed of the `object` properties `predicate` returns
  12725. * truthy for. The predicate is invoked with two arguments: (value, key).
  12726. *
  12727. * @static
  12728. * @memberOf _
  12729. * @since 4.0.0
  12730. * @category Object
  12731. * @param {Object} object The source object.
  12732. * @param {Function} [predicate=_.identity] The function invoked per property.
  12733. * @returns {Object} Returns the new object.
  12734. * @example
  12735. *
  12736. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12737. *
  12738. * _.pickBy(object, _.isNumber);
  12739. * // => { 'a': 1, 'c': 3 }
  12740. */
  12741. function pickBy(object, predicate) {
  12742. if (object == null) {
  12743. return {};
  12744. }
  12745. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12746. return [prop];
  12747. });
  12748. predicate = getIteratee(predicate);
  12749. return basePickBy(object, props, function(value, path) {
  12750. return predicate(value, path[0]);
  12751. });
  12752. }
  12753. /**
  12754. * This method is like `_.get` except that if the resolved value is a
  12755. * function it's invoked with the `this` binding of its parent object and
  12756. * its result is returned.
  12757. *
  12758. * @static
  12759. * @since 0.1.0
  12760. * @memberOf _
  12761. * @category Object
  12762. * @param {Object} object The object to query.
  12763. * @param {Array|string} path The path of the property to resolve.
  12764. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12765. * @returns {*} Returns the resolved value.
  12766. * @example
  12767. *
  12768. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12769. *
  12770. * _.result(object, 'a[0].b.c1');
  12771. * // => 3
  12772. *
  12773. * _.result(object, 'a[0].b.c2');
  12774. * // => 4
  12775. *
  12776. * _.result(object, 'a[0].b.c3', 'default');
  12777. * // => 'default'
  12778. *
  12779. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12780. * // => 'default'
  12781. */
  12782. function result(object, path, defaultValue) {
  12783. path = castPath(path, object);
  12784. var index = -1,
  12785. length = path.length;
  12786. // Ensure the loop is entered when path is empty.
  12787. if (!length) {
  12788. length = 1;
  12789. object = undefined;
  12790. }
  12791. while (++index < length) {
  12792. var value = object == null ? undefined : object[toKey(path[index])];
  12793. if (value === undefined) {
  12794. index = length;
  12795. value = defaultValue;
  12796. }
  12797. object = isFunction(value) ? value.call(object) : value;
  12798. }
  12799. return object;
  12800. }
  12801. /**
  12802. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12803. * it's created. Arrays are created for missing index properties while objects
  12804. * are created for all other missing properties. Use `_.setWith` to customize
  12805. * `path` creation.
  12806. *
  12807. * **Note:** This method mutates `object`.
  12808. *
  12809. * @static
  12810. * @memberOf _
  12811. * @since 3.7.0
  12812. * @category Object
  12813. * @param {Object} object The object to modify.
  12814. * @param {Array|string} path The path of the property to set.
  12815. * @param {*} value The value to set.
  12816. * @returns {Object} Returns `object`.
  12817. * @example
  12818. *
  12819. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12820. *
  12821. * _.set(object, 'a[0].b.c', 4);
  12822. * console.log(object.a[0].b.c);
  12823. * // => 4
  12824. *
  12825. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12826. * console.log(object.x[0].y.z);
  12827. * // => 5
  12828. */
  12829. function set(object, path, value) {
  12830. return object == null ? object : baseSet(object, path, value);
  12831. }
  12832. /**
  12833. * This method is like `_.set` except that it accepts `customizer` which is
  12834. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12835. * path creation is handled by the method instead. The `customizer` is invoked
  12836. * with three arguments: (nsValue, key, nsObject).
  12837. *
  12838. * **Note:** This method mutates `object`.
  12839. *
  12840. * @static
  12841. * @memberOf _
  12842. * @since 4.0.0
  12843. * @category Object
  12844. * @param {Object} object The object to modify.
  12845. * @param {Array|string} path The path of the property to set.
  12846. * @param {*} value The value to set.
  12847. * @param {Function} [customizer] The function to customize assigned values.
  12848. * @returns {Object} Returns `object`.
  12849. * @example
  12850. *
  12851. * var object = {};
  12852. *
  12853. * _.setWith(object, '[0][1]', 'a', Object);
  12854. * // => { '0': { '1': 'a' } }
  12855. */
  12856. function setWith(object, path, value, customizer) {
  12857. customizer = typeof customizer == 'function' ? customizer : undefined;
  12858. return object == null ? object : baseSet(object, path, value, customizer);
  12859. }
  12860. /**
  12861. * Creates an array of own enumerable string keyed-value pairs for `object`
  12862. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12863. * entries are returned.
  12864. *
  12865. * @static
  12866. * @memberOf _
  12867. * @since 4.0.0
  12868. * @alias entries
  12869. * @category Object
  12870. * @param {Object} object The object to query.
  12871. * @returns {Array} Returns the key-value pairs.
  12872. * @example
  12873. *
  12874. * function Foo() {
  12875. * this.a = 1;
  12876. * this.b = 2;
  12877. * }
  12878. *
  12879. * Foo.prototype.c = 3;
  12880. *
  12881. * _.toPairs(new Foo);
  12882. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12883. */
  12884. var toPairs = createToPairs(keys);
  12885. /**
  12886. * Creates an array of own and inherited enumerable string keyed-value pairs
  12887. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12888. * or set, its entries are returned.
  12889. *
  12890. * @static
  12891. * @memberOf _
  12892. * @since 4.0.0
  12893. * @alias entriesIn
  12894. * @category Object
  12895. * @param {Object} object The object to query.
  12896. * @returns {Array} Returns the key-value pairs.
  12897. * @example
  12898. *
  12899. * function Foo() {
  12900. * this.a = 1;
  12901. * this.b = 2;
  12902. * }
  12903. *
  12904. * Foo.prototype.c = 3;
  12905. *
  12906. * _.toPairsIn(new Foo);
  12907. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12908. */
  12909. var toPairsIn = createToPairs(keysIn);
  12910. /**
  12911. * An alternative to `_.reduce`; this method transforms `object` to a new
  12912. * `accumulator` object which is the result of running each of its own
  12913. * enumerable string keyed properties thru `iteratee`, with each invocation
  12914. * potentially mutating the `accumulator` object. If `accumulator` is not
  12915. * provided, a new object with the same `[[Prototype]]` will be used. The
  12916. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12917. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12918. *
  12919. * @static
  12920. * @memberOf _
  12921. * @since 1.3.0
  12922. * @category Object
  12923. * @param {Object} object The object to iterate over.
  12924. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12925. * @param {*} [accumulator] The custom accumulator value.
  12926. * @returns {*} Returns the accumulated value.
  12927. * @example
  12928. *
  12929. * _.transform([2, 3, 4], function(result, n) {
  12930. * result.push(n *= n);
  12931. * return n % 2 == 0;
  12932. * }, []);
  12933. * // => [4, 9]
  12934. *
  12935. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12936. * (result[value] || (result[value] = [])).push(key);
  12937. * }, {});
  12938. * // => { '1': ['a', 'c'], '2': ['b'] }
  12939. */
  12940. function transform(object, iteratee, accumulator) {
  12941. var isArr = isArray(object),
  12942. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12943. iteratee = getIteratee(iteratee, 4);
  12944. if (accumulator == null) {
  12945. var Ctor = object && object.constructor;
  12946. if (isArrLike) {
  12947. accumulator = isArr ? new Ctor : [];
  12948. }
  12949. else if (isObject(object)) {
  12950. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12951. }
  12952. else {
  12953. accumulator = {};
  12954. }
  12955. }
  12956. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12957. return iteratee(accumulator, value, index, object);
  12958. });
  12959. return accumulator;
  12960. }
  12961. /**
  12962. * Removes the property at `path` of `object`.
  12963. *
  12964. * **Note:** This method mutates `object`.
  12965. *
  12966. * @static
  12967. * @memberOf _
  12968. * @since 4.0.0
  12969. * @category Object
  12970. * @param {Object} object The object to modify.
  12971. * @param {Array|string} path The path of the property to unset.
  12972. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12973. * @example
  12974. *
  12975. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12976. * _.unset(object, 'a[0].b.c');
  12977. * // => true
  12978. *
  12979. * console.log(object);
  12980. * // => { 'a': [{ 'b': {} }] };
  12981. *
  12982. * _.unset(object, ['a', '0', 'b', 'c']);
  12983. * // => true
  12984. *
  12985. * console.log(object);
  12986. * // => { 'a': [{ 'b': {} }] };
  12987. */
  12988. function unset(object, path) {
  12989. return object == null ? true : baseUnset(object, path);
  12990. }
  12991. /**
  12992. * This method is like `_.set` except that accepts `updater` to produce the
  12993. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12994. * is invoked with one argument: (value).
  12995. *
  12996. * **Note:** This method mutates `object`.
  12997. *
  12998. * @static
  12999. * @memberOf _
  13000. * @since 4.6.0
  13001. * @category Object
  13002. * @param {Object} object The object to modify.
  13003. * @param {Array|string} path The path of the property to set.
  13004. * @param {Function} updater The function to produce the updated value.
  13005. * @returns {Object} Returns `object`.
  13006. * @example
  13007. *
  13008. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13009. *
  13010. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  13011. * console.log(object.a[0].b.c);
  13012. * // => 9
  13013. *
  13014. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  13015. * console.log(object.x[0].y.z);
  13016. * // => 0
  13017. */
  13018. function update(object, path, updater) {
  13019. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  13020. }
  13021. /**
  13022. * This method is like `_.update` except that it accepts `customizer` which is
  13023. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13024. * path creation is handled by the method instead. The `customizer` is invoked
  13025. * with three arguments: (nsValue, key, nsObject).
  13026. *
  13027. * **Note:** This method mutates `object`.
  13028. *
  13029. * @static
  13030. * @memberOf _
  13031. * @since 4.6.0
  13032. * @category Object
  13033. * @param {Object} object The object to modify.
  13034. * @param {Array|string} path The path of the property to set.
  13035. * @param {Function} updater The function to produce the updated value.
  13036. * @param {Function} [customizer] The function to customize assigned values.
  13037. * @returns {Object} Returns `object`.
  13038. * @example
  13039. *
  13040. * var object = {};
  13041. *
  13042. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13043. * // => { '0': { '1': 'a' } }
  13044. */
  13045. function updateWith(object, path, updater, customizer) {
  13046. customizer = typeof customizer == 'function' ? customizer : undefined;
  13047. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13048. }
  13049. /**
  13050. * Creates an array of the own enumerable string keyed property values of `object`.
  13051. *
  13052. * **Note:** Non-object values are coerced to objects.
  13053. *
  13054. * @static
  13055. * @since 0.1.0
  13056. * @memberOf _
  13057. * @category Object
  13058. * @param {Object} object The object to query.
  13059. * @returns {Array} Returns the array of property values.
  13060. * @example
  13061. *
  13062. * function Foo() {
  13063. * this.a = 1;
  13064. * this.b = 2;
  13065. * }
  13066. *
  13067. * Foo.prototype.c = 3;
  13068. *
  13069. * _.values(new Foo);
  13070. * // => [1, 2] (iteration order is not guaranteed)
  13071. *
  13072. * _.values('hi');
  13073. * // => ['h', 'i']
  13074. */
  13075. function values(object) {
  13076. return object == null ? [] : baseValues(object, keys(object));
  13077. }
  13078. /**
  13079. * Creates an array of the own and inherited enumerable string keyed property
  13080. * values of `object`.
  13081. *
  13082. * **Note:** Non-object values are coerced to objects.
  13083. *
  13084. * @static
  13085. * @memberOf _
  13086. * @since 3.0.0
  13087. * @category Object
  13088. * @param {Object} object The object to query.
  13089. * @returns {Array} Returns the array of property values.
  13090. * @example
  13091. *
  13092. * function Foo() {
  13093. * this.a = 1;
  13094. * this.b = 2;
  13095. * }
  13096. *
  13097. * Foo.prototype.c = 3;
  13098. *
  13099. * _.valuesIn(new Foo);
  13100. * // => [1, 2, 3] (iteration order is not guaranteed)
  13101. */
  13102. function valuesIn(object) {
  13103. return object == null ? [] : baseValues(object, keysIn(object));
  13104. }
  13105. /*------------------------------------------------------------------------*/
  13106. /**
  13107. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13108. *
  13109. * @static
  13110. * @memberOf _
  13111. * @since 4.0.0
  13112. * @category Number
  13113. * @param {number} number The number to clamp.
  13114. * @param {number} [lower] The lower bound.
  13115. * @param {number} upper The upper bound.
  13116. * @returns {number} Returns the clamped number.
  13117. * @example
  13118. *
  13119. * _.clamp(-10, -5, 5);
  13120. * // => -5
  13121. *
  13122. * _.clamp(10, -5, 5);
  13123. * // => 5
  13124. */
  13125. function clamp(number, lower, upper) {
  13126. if (upper === undefined) {
  13127. upper = lower;
  13128. lower = undefined;
  13129. }
  13130. if (upper !== undefined) {
  13131. upper = toNumber(upper);
  13132. upper = upper === upper ? upper : 0;
  13133. }
  13134. if (lower !== undefined) {
  13135. lower = toNumber(lower);
  13136. lower = lower === lower ? lower : 0;
  13137. }
  13138. return baseClamp(toNumber(number), lower, upper);
  13139. }
  13140. /**
  13141. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13142. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13143. * If `start` is greater than `end` the params are swapped to support
  13144. * negative ranges.
  13145. *
  13146. * @static
  13147. * @memberOf _
  13148. * @since 3.3.0
  13149. * @category Number
  13150. * @param {number} number The number to check.
  13151. * @param {number} [start=0] The start of the range.
  13152. * @param {number} end The end of the range.
  13153. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13154. * @see _.range, _.rangeRight
  13155. * @example
  13156. *
  13157. * _.inRange(3, 2, 4);
  13158. * // => true
  13159. *
  13160. * _.inRange(4, 8);
  13161. * // => true
  13162. *
  13163. * _.inRange(4, 2);
  13164. * // => false
  13165. *
  13166. * _.inRange(2, 2);
  13167. * // => false
  13168. *
  13169. * _.inRange(1.2, 2);
  13170. * // => true
  13171. *
  13172. * _.inRange(5.2, 4);
  13173. * // => false
  13174. *
  13175. * _.inRange(-3, -2, -6);
  13176. * // => true
  13177. */
  13178. function inRange(number, start, end) {
  13179. start = toFinite(start);
  13180. if (end === undefined) {
  13181. end = start;
  13182. start = 0;
  13183. } else {
  13184. end = toFinite(end);
  13185. }
  13186. number = toNumber(number);
  13187. return baseInRange(number, start, end);
  13188. }
  13189. /**
  13190. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13191. * If only one argument is provided a number between `0` and the given number
  13192. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13193. * floats, a floating-point number is returned instead of an integer.
  13194. *
  13195. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13196. * floating-point values which can produce unexpected results.
  13197. *
  13198. * @static
  13199. * @memberOf _
  13200. * @since 0.7.0
  13201. * @category Number
  13202. * @param {number} [lower=0] The lower bound.
  13203. * @param {number} [upper=1] The upper bound.
  13204. * @param {boolean} [floating] Specify returning a floating-point number.
  13205. * @returns {number} Returns the random number.
  13206. * @example
  13207. *
  13208. * _.random(0, 5);
  13209. * // => an integer between 0 and 5
  13210. *
  13211. * _.random(5);
  13212. * // => also an integer between 0 and 5
  13213. *
  13214. * _.random(5, true);
  13215. * // => a floating-point number between 0 and 5
  13216. *
  13217. * _.random(1.2, 5.2);
  13218. * // => a floating-point number between 1.2 and 5.2
  13219. */
  13220. function random(lower, upper, floating) {
  13221. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13222. upper = floating = undefined;
  13223. }
  13224. if (floating === undefined) {
  13225. if (typeof upper == 'boolean') {
  13226. floating = upper;
  13227. upper = undefined;
  13228. }
  13229. else if (typeof lower == 'boolean') {
  13230. floating = lower;
  13231. lower = undefined;
  13232. }
  13233. }
  13234. if (lower === undefined && upper === undefined) {
  13235. lower = 0;
  13236. upper = 1;
  13237. }
  13238. else {
  13239. lower = toFinite(lower);
  13240. if (upper === undefined) {
  13241. upper = lower;
  13242. lower = 0;
  13243. } else {
  13244. upper = toFinite(upper);
  13245. }
  13246. }
  13247. if (lower > upper) {
  13248. var temp = lower;
  13249. lower = upper;
  13250. upper = temp;
  13251. }
  13252. if (floating || lower % 1 || upper % 1) {
  13253. var rand = nativeRandom();
  13254. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13255. }
  13256. return baseRandom(lower, upper);
  13257. }
  13258. /*------------------------------------------------------------------------*/
  13259. /**
  13260. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13261. *
  13262. * @static
  13263. * @memberOf _
  13264. * @since 3.0.0
  13265. * @category String
  13266. * @param {string} [string=''] The string to convert.
  13267. * @returns {string} Returns the camel cased string.
  13268. * @example
  13269. *
  13270. * _.camelCase('Foo Bar');
  13271. * // => 'fooBar'
  13272. *
  13273. * _.camelCase('--foo-bar--');
  13274. * // => 'fooBar'
  13275. *
  13276. * _.camelCase('__FOO_BAR__');
  13277. * // => 'fooBar'
  13278. */
  13279. var camelCase = createCompounder(function(result, word, index) {
  13280. word = word.toLowerCase();
  13281. return result + (index ? capitalize(word) : word);
  13282. });
  13283. /**
  13284. * Converts the first character of `string` to upper case and the remaining
  13285. * to lower case.
  13286. *
  13287. * @static
  13288. * @memberOf _
  13289. * @since 3.0.0
  13290. * @category String
  13291. * @param {string} [string=''] The string to capitalize.
  13292. * @returns {string} Returns the capitalized string.
  13293. * @example
  13294. *
  13295. * _.capitalize('FRED');
  13296. * // => 'Fred'
  13297. */
  13298. function capitalize(string) {
  13299. return upperFirst(toString(string).toLowerCase());
  13300. }
  13301. /**
  13302. * Deburrs `string` by converting
  13303. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13304. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13305. * letters to basic Latin letters and removing
  13306. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13307. *
  13308. * @static
  13309. * @memberOf _
  13310. * @since 3.0.0
  13311. * @category String
  13312. * @param {string} [string=''] The string to deburr.
  13313. * @returns {string} Returns the deburred string.
  13314. * @example
  13315. *
  13316. * _.deburr('déjà vu');
  13317. * // => 'deja vu'
  13318. */
  13319. function deburr(string) {
  13320. string = toString(string);
  13321. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13322. }
  13323. /**
  13324. * Checks if `string` ends with the given target string.
  13325. *
  13326. * @static
  13327. * @memberOf _
  13328. * @since 3.0.0
  13329. * @category String
  13330. * @param {string} [string=''] The string to inspect.
  13331. * @param {string} [target] The string to search for.
  13332. * @param {number} [position=string.length] The position to search up to.
  13333. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13334. * else `false`.
  13335. * @example
  13336. *
  13337. * _.endsWith('abc', 'c');
  13338. * // => true
  13339. *
  13340. * _.endsWith('abc', 'b');
  13341. * // => false
  13342. *
  13343. * _.endsWith('abc', 'b', 2);
  13344. * // => true
  13345. */
  13346. function endsWith(string, target, position) {
  13347. string = toString(string);
  13348. target = baseToString(target);
  13349. var length = string.length;
  13350. position = position === undefined
  13351. ? length
  13352. : baseClamp(toInteger(position), 0, length);
  13353. var end = position;
  13354. position -= target.length;
  13355. return position >= 0 && string.slice(position, end) == target;
  13356. }
  13357. /**
  13358. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13359. * corresponding HTML entities.
  13360. *
  13361. * **Note:** No other characters are escaped. To escape additional
  13362. * characters use a third-party library like [_he_](https://mths.be/he).
  13363. *
  13364. * Though the ">" character is escaped for symmetry, characters like
  13365. * ">" and "/" don't need escaping in HTML and have no special meaning
  13366. * unless they're part of a tag or unquoted attribute value. See
  13367. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13368. * (under "semi-related fun fact") for more details.
  13369. *
  13370. * When working with HTML you should always
  13371. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13372. * XSS vectors.
  13373. *
  13374. * @static
  13375. * @since 0.1.0
  13376. * @memberOf _
  13377. * @category String
  13378. * @param {string} [string=''] The string to escape.
  13379. * @returns {string} Returns the escaped string.
  13380. * @example
  13381. *
  13382. * _.escape('fred, barney, & pebbles');
  13383. * // => 'fred, barney, &amp; pebbles'
  13384. */
  13385. function escape(string) {
  13386. string = toString(string);
  13387. return (string && reHasUnescapedHtml.test(string))
  13388. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13389. : string;
  13390. }
  13391. /**
  13392. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13393. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13394. *
  13395. * @static
  13396. * @memberOf _
  13397. * @since 3.0.0
  13398. * @category String
  13399. * @param {string} [string=''] The string to escape.
  13400. * @returns {string} Returns the escaped string.
  13401. * @example
  13402. *
  13403. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13404. * // => '\[lodash\]\(https://lodash\.com/\)'
  13405. */
  13406. function escapeRegExp(string) {
  13407. string = toString(string);
  13408. return (string && reHasRegExpChar.test(string))
  13409. ? string.replace(reRegExpChar, '\\$&')
  13410. : string;
  13411. }
  13412. /**
  13413. * Converts `string` to
  13414. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13415. *
  13416. * @static
  13417. * @memberOf _
  13418. * @since 3.0.0
  13419. * @category String
  13420. * @param {string} [string=''] The string to convert.
  13421. * @returns {string} Returns the kebab cased string.
  13422. * @example
  13423. *
  13424. * _.kebabCase('Foo Bar');
  13425. * // => 'foo-bar'
  13426. *
  13427. * _.kebabCase('fooBar');
  13428. * // => 'foo-bar'
  13429. *
  13430. * _.kebabCase('__FOO_BAR__');
  13431. * // => 'foo-bar'
  13432. */
  13433. var kebabCase = createCompounder(function(result, word, index) {
  13434. return result + (index ? '-' : '') + word.toLowerCase();
  13435. });
  13436. /**
  13437. * Converts `string`, as space separated words, to lower case.
  13438. *
  13439. * @static
  13440. * @memberOf _
  13441. * @since 4.0.0
  13442. * @category String
  13443. * @param {string} [string=''] The string to convert.
  13444. * @returns {string} Returns the lower cased string.
  13445. * @example
  13446. *
  13447. * _.lowerCase('--Foo-Bar--');
  13448. * // => 'foo bar'
  13449. *
  13450. * _.lowerCase('fooBar');
  13451. * // => 'foo bar'
  13452. *
  13453. * _.lowerCase('__FOO_BAR__');
  13454. * // => 'foo bar'
  13455. */
  13456. var lowerCase = createCompounder(function(result, word, index) {
  13457. return result + (index ? ' ' : '') + word.toLowerCase();
  13458. });
  13459. /**
  13460. * Converts the first character of `string` to lower case.
  13461. *
  13462. * @static
  13463. * @memberOf _
  13464. * @since 4.0.0
  13465. * @category String
  13466. * @param {string} [string=''] The string to convert.
  13467. * @returns {string} Returns the converted string.
  13468. * @example
  13469. *
  13470. * _.lowerFirst('Fred');
  13471. * // => 'fred'
  13472. *
  13473. * _.lowerFirst('FRED');
  13474. * // => 'fRED'
  13475. */
  13476. var lowerFirst = createCaseFirst('toLowerCase');
  13477. /**
  13478. * Pads `string` on the left and right sides if it's shorter than `length`.
  13479. * Padding characters are truncated if they can't be evenly divided by `length`.
  13480. *
  13481. * @static
  13482. * @memberOf _
  13483. * @since 3.0.0
  13484. * @category String
  13485. * @param {string} [string=''] The string to pad.
  13486. * @param {number} [length=0] The padding length.
  13487. * @param {string} [chars=' '] The string used as padding.
  13488. * @returns {string} Returns the padded string.
  13489. * @example
  13490. *
  13491. * _.pad('abc', 8);
  13492. * // => ' abc '
  13493. *
  13494. * _.pad('abc', 8, '_-');
  13495. * // => '_-abc_-_'
  13496. *
  13497. * _.pad('abc', 3);
  13498. * // => 'abc'
  13499. */
  13500. function pad(string, length, chars) {
  13501. string = toString(string);
  13502. length = toInteger(length);
  13503. var strLength = length ? stringSize(string) : 0;
  13504. if (!length || strLength >= length) {
  13505. return string;
  13506. }
  13507. var mid = (length - strLength) / 2;
  13508. return (
  13509. createPadding(nativeFloor(mid), chars) +
  13510. string +
  13511. createPadding(nativeCeil(mid), chars)
  13512. );
  13513. }
  13514. /**
  13515. * Pads `string` on the right side if it's shorter than `length`. Padding
  13516. * characters are truncated if they exceed `length`.
  13517. *
  13518. * @static
  13519. * @memberOf _
  13520. * @since 4.0.0
  13521. * @category String
  13522. * @param {string} [string=''] The string to pad.
  13523. * @param {number} [length=0] The padding length.
  13524. * @param {string} [chars=' '] The string used as padding.
  13525. * @returns {string} Returns the padded string.
  13526. * @example
  13527. *
  13528. * _.padEnd('abc', 6);
  13529. * // => 'abc '
  13530. *
  13531. * _.padEnd('abc', 6, '_-');
  13532. * // => 'abc_-_'
  13533. *
  13534. * _.padEnd('abc', 3);
  13535. * // => 'abc'
  13536. */
  13537. function padEnd(string, length, chars) {
  13538. string = toString(string);
  13539. length = toInteger(length);
  13540. var strLength = length ? stringSize(string) : 0;
  13541. return (length && strLength < length)
  13542. ? (string + createPadding(length - strLength, chars))
  13543. : string;
  13544. }
  13545. /**
  13546. * Pads `string` on the left side if it's shorter than `length`. Padding
  13547. * characters are truncated if they exceed `length`.
  13548. *
  13549. * @static
  13550. * @memberOf _
  13551. * @since 4.0.0
  13552. * @category String
  13553. * @param {string} [string=''] The string to pad.
  13554. * @param {number} [length=0] The padding length.
  13555. * @param {string} [chars=' '] The string used as padding.
  13556. * @returns {string} Returns the padded string.
  13557. * @example
  13558. *
  13559. * _.padStart('abc', 6);
  13560. * // => ' abc'
  13561. *
  13562. * _.padStart('abc', 6, '_-');
  13563. * // => '_-_abc'
  13564. *
  13565. * _.padStart('abc', 3);
  13566. * // => 'abc'
  13567. */
  13568. function padStart(string, length, chars) {
  13569. string = toString(string);
  13570. length = toInteger(length);
  13571. var strLength = length ? stringSize(string) : 0;
  13572. return (length && strLength < length)
  13573. ? (createPadding(length - strLength, chars) + string)
  13574. : string;
  13575. }
  13576. /**
  13577. * Converts `string` to an integer of the specified radix. If `radix` is
  13578. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13579. * hexadecimal, in which case a `radix` of `16` is used.
  13580. *
  13581. * **Note:** This method aligns with the
  13582. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13583. *
  13584. * @static
  13585. * @memberOf _
  13586. * @since 1.1.0
  13587. * @category String
  13588. * @param {string} string The string to convert.
  13589. * @param {number} [radix=10] The radix to interpret `value` by.
  13590. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13591. * @returns {number} Returns the converted integer.
  13592. * @example
  13593. *
  13594. * _.parseInt('08');
  13595. * // => 8
  13596. *
  13597. * _.map(['6', '08', '10'], _.parseInt);
  13598. * // => [6, 8, 10]
  13599. */
  13600. function parseInt(string, radix, guard) {
  13601. if (guard || radix == null) {
  13602. radix = 0;
  13603. } else if (radix) {
  13604. radix = +radix;
  13605. }
  13606. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13607. }
  13608. /**
  13609. * Repeats the given string `n` times.
  13610. *
  13611. * @static
  13612. * @memberOf _
  13613. * @since 3.0.0
  13614. * @category String
  13615. * @param {string} [string=''] The string to repeat.
  13616. * @param {number} [n=1] The number of times to repeat the string.
  13617. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13618. * @returns {string} Returns the repeated string.
  13619. * @example
  13620. *
  13621. * _.repeat('*', 3);
  13622. * // => '***'
  13623. *
  13624. * _.repeat('abc', 2);
  13625. * // => 'abcabc'
  13626. *
  13627. * _.repeat('abc', 0);
  13628. * // => ''
  13629. */
  13630. function repeat(string, n, guard) {
  13631. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13632. n = 1;
  13633. } else {
  13634. n = toInteger(n);
  13635. }
  13636. return baseRepeat(toString(string), n);
  13637. }
  13638. /**
  13639. * Replaces matches for `pattern` in `string` with `replacement`.
  13640. *
  13641. * **Note:** This method is based on
  13642. * [`String#replace`](https://mdn.io/String/replace).
  13643. *
  13644. * @static
  13645. * @memberOf _
  13646. * @since 4.0.0
  13647. * @category String
  13648. * @param {string} [string=''] The string to modify.
  13649. * @param {RegExp|string} pattern The pattern to replace.
  13650. * @param {Function|string} replacement The match replacement.
  13651. * @returns {string} Returns the modified string.
  13652. * @example
  13653. *
  13654. * _.replace('Hi Fred', 'Fred', 'Barney');
  13655. * // => 'Hi Barney'
  13656. */
  13657. function replace() {
  13658. var args = arguments,
  13659. string = toString(args[0]);
  13660. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13661. }
  13662. /**
  13663. * Converts `string` to
  13664. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13665. *
  13666. * @static
  13667. * @memberOf _
  13668. * @since 3.0.0
  13669. * @category String
  13670. * @param {string} [string=''] The string to convert.
  13671. * @returns {string} Returns the snake cased string.
  13672. * @example
  13673. *
  13674. * _.snakeCase('Foo Bar');
  13675. * // => 'foo_bar'
  13676. *
  13677. * _.snakeCase('fooBar');
  13678. * // => 'foo_bar'
  13679. *
  13680. * _.snakeCase('--FOO-BAR--');
  13681. * // => 'foo_bar'
  13682. */
  13683. var snakeCase = createCompounder(function(result, word, index) {
  13684. return result + (index ? '_' : '') + word.toLowerCase();
  13685. });
  13686. /**
  13687. * Splits `string` by `separator`.
  13688. *
  13689. * **Note:** This method is based on
  13690. * [`String#split`](https://mdn.io/String/split).
  13691. *
  13692. * @static
  13693. * @memberOf _
  13694. * @since 4.0.0
  13695. * @category String
  13696. * @param {string} [string=''] The string to split.
  13697. * @param {RegExp|string} separator The separator pattern to split by.
  13698. * @param {number} [limit] The length to truncate results to.
  13699. * @returns {Array} Returns the string segments.
  13700. * @example
  13701. *
  13702. * _.split('a-b-c', '-', 2);
  13703. * // => ['a', 'b']
  13704. */
  13705. function split(string, separator, limit) {
  13706. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13707. separator = limit = undefined;
  13708. }
  13709. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13710. if (!limit) {
  13711. return [];
  13712. }
  13713. string = toString(string);
  13714. if (string && (
  13715. typeof separator == 'string' ||
  13716. (separator != null && !isRegExp(separator))
  13717. )) {
  13718. separator = baseToString(separator);
  13719. if (!separator && hasUnicode(string)) {
  13720. return castSlice(stringToArray(string), 0, limit);
  13721. }
  13722. }
  13723. return string.split(separator, limit);
  13724. }
  13725. /**
  13726. * Converts `string` to
  13727. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13728. *
  13729. * @static
  13730. * @memberOf _
  13731. * @since 3.1.0
  13732. * @category String
  13733. * @param {string} [string=''] The string to convert.
  13734. * @returns {string} Returns the start cased string.
  13735. * @example
  13736. *
  13737. * _.startCase('--foo-bar--');
  13738. * // => 'Foo Bar'
  13739. *
  13740. * _.startCase('fooBar');
  13741. * // => 'Foo Bar'
  13742. *
  13743. * _.startCase('__FOO_BAR__');
  13744. * // => 'FOO BAR'
  13745. */
  13746. var startCase = createCompounder(function(result, word, index) {
  13747. return result + (index ? ' ' : '') + upperFirst(word);
  13748. });
  13749. /**
  13750. * Checks if `string` starts with the given target string.
  13751. *
  13752. * @static
  13753. * @memberOf _
  13754. * @since 3.0.0
  13755. * @category String
  13756. * @param {string} [string=''] The string to inspect.
  13757. * @param {string} [target] The string to search for.
  13758. * @param {number} [position=0] The position to search from.
  13759. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13760. * else `false`.
  13761. * @example
  13762. *
  13763. * _.startsWith('abc', 'a');
  13764. * // => true
  13765. *
  13766. * _.startsWith('abc', 'b');
  13767. * // => false
  13768. *
  13769. * _.startsWith('abc', 'b', 1);
  13770. * // => true
  13771. */
  13772. function startsWith(string, target, position) {
  13773. string = toString(string);
  13774. position = position == null
  13775. ? 0
  13776. : baseClamp(toInteger(position), 0, string.length);
  13777. target = baseToString(target);
  13778. return string.slice(position, position + target.length) == target;
  13779. }
  13780. /**
  13781. * Creates a compiled template function that can interpolate data properties
  13782. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13783. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13784. * properties may be accessed as free variables in the template. If a setting
  13785. * object is given, it takes precedence over `_.templateSettings` values.
  13786. *
  13787. * **Note:** In the development build `_.template` utilizes
  13788. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13789. * for easier debugging.
  13790. *
  13791. * For more information on precompiling templates see
  13792. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13793. *
  13794. * For more information on Chrome extension sandboxes see
  13795. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13796. *
  13797. * @static
  13798. * @since 0.1.0
  13799. * @memberOf _
  13800. * @category String
  13801. * @param {string} [string=''] The template string.
  13802. * @param {Object} [options={}] The options object.
  13803. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13804. * The HTML "escape" delimiter.
  13805. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13806. * The "evaluate" delimiter.
  13807. * @param {Object} [options.imports=_.templateSettings.imports]
  13808. * An object to import into the template as free variables.
  13809. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13810. * The "interpolate" delimiter.
  13811. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13812. * The sourceURL of the compiled template.
  13813. * @param {string} [options.variable='obj']
  13814. * The data object variable name.
  13815. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13816. * @returns {Function} Returns the compiled template function.
  13817. * @example
  13818. *
  13819. * // Use the "interpolate" delimiter to create a compiled template.
  13820. * var compiled = _.template('hello <%= user %>!');
  13821. * compiled({ 'user': 'fred' });
  13822. * // => 'hello fred!'
  13823. *
  13824. * // Use the HTML "escape" delimiter to escape data property values.
  13825. * var compiled = _.template('<b><%- value %></b>');
  13826. * compiled({ 'value': '<script>' });
  13827. * // => '<b>&lt;script&gt;</b>'
  13828. *
  13829. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13830. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13831. * compiled({ 'users': ['fred', 'barney'] });
  13832. * // => '<li>fred</li><li>barney</li>'
  13833. *
  13834. * // Use the internal `print` function in "evaluate" delimiters.
  13835. * var compiled = _.template('<% print("hello " + user); %>!');
  13836. * compiled({ 'user': 'barney' });
  13837. * // => 'hello barney!'
  13838. *
  13839. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13840. * // Disable support by replacing the "interpolate" delimiter.
  13841. * var compiled = _.template('hello ${ user }!');
  13842. * compiled({ 'user': 'pebbles' });
  13843. * // => 'hello pebbles!'
  13844. *
  13845. * // Use backslashes to treat delimiters as plain text.
  13846. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13847. * compiled({ 'value': 'ignored' });
  13848. * // => '<%- value %>'
  13849. *
  13850. * // Use the `imports` option to import `jQuery` as `jq`.
  13851. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13852. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13853. * compiled({ 'users': ['fred', 'barney'] });
  13854. * // => '<li>fred</li><li>barney</li>'
  13855. *
  13856. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13857. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13858. * compiled(data);
  13859. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13860. *
  13861. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13862. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13863. * compiled.source;
  13864. * // => function(data) {
  13865. * // var __t, __p = '';
  13866. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13867. * // return __p;
  13868. * // }
  13869. *
  13870. * // Use custom template delimiters.
  13871. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13872. * var compiled = _.template('hello {{ user }}!');
  13873. * compiled({ 'user': 'mustache' });
  13874. * // => 'hello mustache!'
  13875. *
  13876. * // Use the `source` property to inline compiled templates for meaningful
  13877. * // line numbers in error messages and stack traces.
  13878. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13879. * var JST = {\
  13880. * "main": ' + _.template(mainText).source + '\
  13881. * };\
  13882. * ');
  13883. */
  13884. function template(string, options, guard) {
  13885. // Based on John Resig's `tmpl` implementation
  13886. // (http://ejohn.org/blog/javascript-micro-templating/)
  13887. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13888. var settings = lodash.templateSettings;
  13889. if (guard && isIterateeCall(string, options, guard)) {
  13890. options = undefined;
  13891. }
  13892. string = toString(string);
  13893. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13894. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13895. importsKeys = keys(imports),
  13896. importsValues = baseValues(imports, importsKeys);
  13897. var isEscaping,
  13898. isEvaluating,
  13899. index = 0,
  13900. interpolate = options.interpolate || reNoMatch,
  13901. source = "__p += '";
  13902. // Compile the regexp to match each delimiter.
  13903. var reDelimiters = RegExp(
  13904. (options.escape || reNoMatch).source + '|' +
  13905. interpolate.source + '|' +
  13906. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13907. (options.evaluate || reNoMatch).source + '|$'
  13908. , 'g');
  13909. // Use a sourceURL for easier debugging.
  13910. // The sourceURL gets injected into the source that's eval-ed, so be careful
  13911. // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  13912. // and escape the comment, thus injecting code that gets evaled.
  13913. var sourceURL = '//# sourceURL=' +
  13914. (hasOwnProperty.call(options, 'sourceURL')
  13915. ? (options.sourceURL + '').replace(/\s/g, ' ')
  13916. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13917. ) + '\n';
  13918. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13919. interpolateValue || (interpolateValue = esTemplateValue);
  13920. // Escape characters that can't be included in string literals.
  13921. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13922. // Replace delimiters with snippets.
  13923. if (escapeValue) {
  13924. isEscaping = true;
  13925. source += "' +\n__e(" + escapeValue + ") +\n'";
  13926. }
  13927. if (evaluateValue) {
  13928. isEvaluating = true;
  13929. source += "';\n" + evaluateValue + ";\n__p += '";
  13930. }
  13931. if (interpolateValue) {
  13932. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13933. }
  13934. index = offset + match.length;
  13935. // The JS engine embedded in Adobe products needs `match` returned in
  13936. // order to produce the correct `offset` value.
  13937. return match;
  13938. });
  13939. source += "';\n";
  13940. // If `variable` is not specified wrap a with-statement around the generated
  13941. // code to add the data object to the top of the scope chain.
  13942. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  13943. if (!variable) {
  13944. source = 'with (obj) {\n' + source + '\n}\n';
  13945. }
  13946. // Cleanup code by stripping empty strings.
  13947. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13948. .replace(reEmptyStringMiddle, '$1')
  13949. .replace(reEmptyStringTrailing, '$1;');
  13950. // Frame code as the function body.
  13951. source = 'function(' + (variable || 'obj') + ') {\n' +
  13952. (variable
  13953. ? ''
  13954. : 'obj || (obj = {});\n'
  13955. ) +
  13956. "var __t, __p = ''" +
  13957. (isEscaping
  13958. ? ', __e = _.escape'
  13959. : ''
  13960. ) +
  13961. (isEvaluating
  13962. ? ', __j = Array.prototype.join;\n' +
  13963. "function print() { __p += __j.call(arguments, '') }\n"
  13964. : ';\n'
  13965. ) +
  13966. source +
  13967. 'return __p\n}';
  13968. var result = attempt(function() {
  13969. return Function(importsKeys, sourceURL + 'return ' + source)
  13970. .apply(undefined, importsValues);
  13971. });
  13972. // Provide the compiled function's source by its `toString` method or
  13973. // the `source` property as a convenience for inlining compiled templates.
  13974. result.source = source;
  13975. if (isError(result)) {
  13976. throw result;
  13977. }
  13978. return result;
  13979. }
  13980. /**
  13981. * Converts `string`, as a whole, to lower case just like
  13982. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13983. *
  13984. * @static
  13985. * @memberOf _
  13986. * @since 4.0.0
  13987. * @category String
  13988. * @param {string} [string=''] The string to convert.
  13989. * @returns {string} Returns the lower cased string.
  13990. * @example
  13991. *
  13992. * _.toLower('--Foo-Bar--');
  13993. * // => '--foo-bar--'
  13994. *
  13995. * _.toLower('fooBar');
  13996. * // => 'foobar'
  13997. *
  13998. * _.toLower('__FOO_BAR__');
  13999. * // => '__foo_bar__'
  14000. */
  14001. function toLower(value) {
  14002. return toString(value).toLowerCase();
  14003. }
  14004. /**
  14005. * Converts `string`, as a whole, to upper case just like
  14006. * [String#toUpperCase](https://mdn.io/toUpperCase).
  14007. *
  14008. * @static
  14009. * @memberOf _
  14010. * @since 4.0.0
  14011. * @category String
  14012. * @param {string} [string=''] The string to convert.
  14013. * @returns {string} Returns the upper cased string.
  14014. * @example
  14015. *
  14016. * _.toUpper('--foo-bar--');
  14017. * // => '--FOO-BAR--'
  14018. *
  14019. * _.toUpper('fooBar');
  14020. * // => 'FOOBAR'
  14021. *
  14022. * _.toUpper('__foo_bar__');
  14023. * // => '__FOO_BAR__'
  14024. */
  14025. function toUpper(value) {
  14026. return toString(value).toUpperCase();
  14027. }
  14028. /**
  14029. * Removes leading and trailing whitespace or specified characters from `string`.
  14030. *
  14031. * @static
  14032. * @memberOf _
  14033. * @since 3.0.0
  14034. * @category String
  14035. * @param {string} [string=''] The string to trim.
  14036. * @param {string} [chars=whitespace] The characters to trim.
  14037. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14038. * @returns {string} Returns the trimmed string.
  14039. * @example
  14040. *
  14041. * _.trim(' abc ');
  14042. * // => 'abc'
  14043. *
  14044. * _.trim('-_-abc-_-', '_-');
  14045. * // => 'abc'
  14046. *
  14047. * _.map([' foo ', ' bar '], _.trim);
  14048. * // => ['foo', 'bar']
  14049. */
  14050. function trim(string, chars, guard) {
  14051. string = toString(string);
  14052. if (string && (guard || chars === undefined)) {
  14053. return string.replace(reTrim, '');
  14054. }
  14055. if (!string || !(chars = baseToString(chars))) {
  14056. return string;
  14057. }
  14058. var strSymbols = stringToArray(string),
  14059. chrSymbols = stringToArray(chars),
  14060. start = charsStartIndex(strSymbols, chrSymbols),
  14061. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14062. return castSlice(strSymbols, start, end).join('');
  14063. }
  14064. /**
  14065. * Removes trailing whitespace or specified characters from `string`.
  14066. *
  14067. * @static
  14068. * @memberOf _
  14069. * @since 4.0.0
  14070. * @category String
  14071. * @param {string} [string=''] The string to trim.
  14072. * @param {string} [chars=whitespace] The characters to trim.
  14073. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14074. * @returns {string} Returns the trimmed string.
  14075. * @example
  14076. *
  14077. * _.trimEnd(' abc ');
  14078. * // => ' abc'
  14079. *
  14080. * _.trimEnd('-_-abc-_-', '_-');
  14081. * // => '-_-abc'
  14082. */
  14083. function trimEnd(string, chars, guard) {
  14084. string = toString(string);
  14085. if (string && (guard || chars === undefined)) {
  14086. return string.replace(reTrimEnd, '');
  14087. }
  14088. if (!string || !(chars = baseToString(chars))) {
  14089. return string;
  14090. }
  14091. var strSymbols = stringToArray(string),
  14092. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14093. return castSlice(strSymbols, 0, end).join('');
  14094. }
  14095. /**
  14096. * Removes leading whitespace or specified characters from `string`.
  14097. *
  14098. * @static
  14099. * @memberOf _
  14100. * @since 4.0.0
  14101. * @category String
  14102. * @param {string} [string=''] The string to trim.
  14103. * @param {string} [chars=whitespace] The characters to trim.
  14104. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14105. * @returns {string} Returns the trimmed string.
  14106. * @example
  14107. *
  14108. * _.trimStart(' abc ');
  14109. * // => 'abc '
  14110. *
  14111. * _.trimStart('-_-abc-_-', '_-');
  14112. * // => 'abc-_-'
  14113. */
  14114. function trimStart(string, chars, guard) {
  14115. string = toString(string);
  14116. if (string && (guard || chars === undefined)) {
  14117. return string.replace(reTrimStart, '');
  14118. }
  14119. if (!string || !(chars = baseToString(chars))) {
  14120. return string;
  14121. }
  14122. var strSymbols = stringToArray(string),
  14123. start = charsStartIndex(strSymbols, stringToArray(chars));
  14124. return castSlice(strSymbols, start).join('');
  14125. }
  14126. /**
  14127. * Truncates `string` if it's longer than the given maximum string length.
  14128. * The last characters of the truncated string are replaced with the omission
  14129. * string which defaults to "...".
  14130. *
  14131. * @static
  14132. * @memberOf _
  14133. * @since 4.0.0
  14134. * @category String
  14135. * @param {string} [string=''] The string to truncate.
  14136. * @param {Object} [options={}] The options object.
  14137. * @param {number} [options.length=30] The maximum string length.
  14138. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14139. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14140. * @returns {string} Returns the truncated string.
  14141. * @example
  14142. *
  14143. * _.truncate('hi-diddly-ho there, neighborino');
  14144. * // => 'hi-diddly-ho there, neighbo...'
  14145. *
  14146. * _.truncate('hi-diddly-ho there, neighborino', {
  14147. * 'length': 24,
  14148. * 'separator': ' '
  14149. * });
  14150. * // => 'hi-diddly-ho there,...'
  14151. *
  14152. * _.truncate('hi-diddly-ho there, neighborino', {
  14153. * 'length': 24,
  14154. * 'separator': /,? +/
  14155. * });
  14156. * // => 'hi-diddly-ho there...'
  14157. *
  14158. * _.truncate('hi-diddly-ho there, neighborino', {
  14159. * 'omission': ' [...]'
  14160. * });
  14161. * // => 'hi-diddly-ho there, neig [...]'
  14162. */
  14163. function truncate(string, options) {
  14164. var length = DEFAULT_TRUNC_LENGTH,
  14165. omission = DEFAULT_TRUNC_OMISSION;
  14166. if (isObject(options)) {
  14167. var separator = 'separator' in options ? options.separator : separator;
  14168. length = 'length' in options ? toInteger(options.length) : length;
  14169. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14170. }
  14171. string = toString(string);
  14172. var strLength = string.length;
  14173. if (hasUnicode(string)) {
  14174. var strSymbols = stringToArray(string);
  14175. strLength = strSymbols.length;
  14176. }
  14177. if (length >= strLength) {
  14178. return string;
  14179. }
  14180. var end = length - stringSize(omission);
  14181. if (end < 1) {
  14182. return omission;
  14183. }
  14184. var result = strSymbols
  14185. ? castSlice(strSymbols, 0, end).join('')
  14186. : string.slice(0, end);
  14187. if (separator === undefined) {
  14188. return result + omission;
  14189. }
  14190. if (strSymbols) {
  14191. end += (result.length - end);
  14192. }
  14193. if (isRegExp(separator)) {
  14194. if (string.slice(end).search(separator)) {
  14195. var match,
  14196. substring = result;
  14197. if (!separator.global) {
  14198. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14199. }
  14200. separator.lastIndex = 0;
  14201. while ((match = separator.exec(substring))) {
  14202. var newEnd = match.index;
  14203. }
  14204. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14205. }
  14206. } else if (string.indexOf(baseToString(separator), end) != end) {
  14207. var index = result.lastIndexOf(separator);
  14208. if (index > -1) {
  14209. result = result.slice(0, index);
  14210. }
  14211. }
  14212. return result + omission;
  14213. }
  14214. /**
  14215. * The inverse of `_.escape`; this method converts the HTML entities
  14216. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14217. * their corresponding characters.
  14218. *
  14219. * **Note:** No other HTML entities are unescaped. To unescape additional
  14220. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14221. *
  14222. * @static
  14223. * @memberOf _
  14224. * @since 0.6.0
  14225. * @category String
  14226. * @param {string} [string=''] The string to unescape.
  14227. * @returns {string} Returns the unescaped string.
  14228. * @example
  14229. *
  14230. * _.unescape('fred, barney, &amp; pebbles');
  14231. * // => 'fred, barney, & pebbles'
  14232. */
  14233. function unescape(string) {
  14234. string = toString(string);
  14235. return (string && reHasEscapedHtml.test(string))
  14236. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14237. : string;
  14238. }
  14239. /**
  14240. * Converts `string`, as space separated words, to upper case.
  14241. *
  14242. * @static
  14243. * @memberOf _
  14244. * @since 4.0.0
  14245. * @category String
  14246. * @param {string} [string=''] The string to convert.
  14247. * @returns {string} Returns the upper cased string.
  14248. * @example
  14249. *
  14250. * _.upperCase('--foo-bar');
  14251. * // => 'FOO BAR'
  14252. *
  14253. * _.upperCase('fooBar');
  14254. * // => 'FOO BAR'
  14255. *
  14256. * _.upperCase('__foo_bar__');
  14257. * // => 'FOO BAR'
  14258. */
  14259. var upperCase = createCompounder(function(result, word, index) {
  14260. return result + (index ? ' ' : '') + word.toUpperCase();
  14261. });
  14262. /**
  14263. * Converts the first character of `string` to upper case.
  14264. *
  14265. * @static
  14266. * @memberOf _
  14267. * @since 4.0.0
  14268. * @category String
  14269. * @param {string} [string=''] The string to convert.
  14270. * @returns {string} Returns the converted string.
  14271. * @example
  14272. *
  14273. * _.upperFirst('fred');
  14274. * // => 'Fred'
  14275. *
  14276. * _.upperFirst('FRED');
  14277. * // => 'FRED'
  14278. */
  14279. var upperFirst = createCaseFirst('toUpperCase');
  14280. /**
  14281. * Splits `string` into an array of its words.
  14282. *
  14283. * @static
  14284. * @memberOf _
  14285. * @since 3.0.0
  14286. * @category String
  14287. * @param {string} [string=''] The string to inspect.
  14288. * @param {RegExp|string} [pattern] The pattern to match words.
  14289. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14290. * @returns {Array} Returns the words of `string`.
  14291. * @example
  14292. *
  14293. * _.words('fred, barney, & pebbles');
  14294. * // => ['fred', 'barney', 'pebbles']
  14295. *
  14296. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14297. * // => ['fred', 'barney', '&', 'pebbles']
  14298. */
  14299. function words(string, pattern, guard) {
  14300. string = toString(string);
  14301. pattern = guard ? undefined : pattern;
  14302. if (pattern === undefined) {
  14303. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14304. }
  14305. return string.match(pattern) || [];
  14306. }
  14307. /*------------------------------------------------------------------------*/
  14308. /**
  14309. * Attempts to invoke `func`, returning either the result or the caught error
  14310. * object. Any additional arguments are provided to `func` when it's invoked.
  14311. *
  14312. * @static
  14313. * @memberOf _
  14314. * @since 3.0.0
  14315. * @category Util
  14316. * @param {Function} func The function to attempt.
  14317. * @param {...*} [args] The arguments to invoke `func` with.
  14318. * @returns {*} Returns the `func` result or error object.
  14319. * @example
  14320. *
  14321. * // Avoid throwing errors for invalid selectors.
  14322. * var elements = _.attempt(function(selector) {
  14323. * return document.querySelectorAll(selector);
  14324. * }, '>_>');
  14325. *
  14326. * if (_.isError(elements)) {
  14327. * elements = [];
  14328. * }
  14329. */
  14330. var attempt = baseRest(function(func, args) {
  14331. try {
  14332. return apply(func, undefined, args);
  14333. } catch (e) {
  14334. return isError(e) ? e : new Error(e);
  14335. }
  14336. });
  14337. /**
  14338. * Binds methods of an object to the object itself, overwriting the existing
  14339. * method.
  14340. *
  14341. * **Note:** This method doesn't set the "length" property of bound functions.
  14342. *
  14343. * @static
  14344. * @since 0.1.0
  14345. * @memberOf _
  14346. * @category Util
  14347. * @param {Object} object The object to bind and assign the bound methods to.
  14348. * @param {...(string|string[])} methodNames The object method names to bind.
  14349. * @returns {Object} Returns `object`.
  14350. * @example
  14351. *
  14352. * var view = {
  14353. * 'label': 'docs',
  14354. * 'click': function() {
  14355. * console.log('clicked ' + this.label);
  14356. * }
  14357. * };
  14358. *
  14359. * _.bindAll(view, ['click']);
  14360. * jQuery(element).on('click', view.click);
  14361. * // => Logs 'clicked docs' when clicked.
  14362. */
  14363. var bindAll = flatRest(function(object, methodNames) {
  14364. arrayEach(methodNames, function(key) {
  14365. key = toKey(key);
  14366. baseAssignValue(object, key, bind(object[key], object));
  14367. });
  14368. return object;
  14369. });
  14370. /**
  14371. * Creates a function that iterates over `pairs` and invokes the corresponding
  14372. * function of the first predicate to return truthy. The predicate-function
  14373. * pairs are invoked with the `this` binding and arguments of the created
  14374. * function.
  14375. *
  14376. * @static
  14377. * @memberOf _
  14378. * @since 4.0.0
  14379. * @category Util
  14380. * @param {Array} pairs The predicate-function pairs.
  14381. * @returns {Function} Returns the new composite function.
  14382. * @example
  14383. *
  14384. * var func = _.cond([
  14385. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14386. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14387. * [_.stubTrue, _.constant('no match')]
  14388. * ]);
  14389. *
  14390. * func({ 'a': 1, 'b': 2 });
  14391. * // => 'matches A'
  14392. *
  14393. * func({ 'a': 0, 'b': 1 });
  14394. * // => 'matches B'
  14395. *
  14396. * func({ 'a': '1', 'b': '2' });
  14397. * // => 'no match'
  14398. */
  14399. function cond(pairs) {
  14400. var length = pairs == null ? 0 : pairs.length,
  14401. toIteratee = getIteratee();
  14402. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14403. if (typeof pair[1] != 'function') {
  14404. throw new TypeError(FUNC_ERROR_TEXT);
  14405. }
  14406. return [toIteratee(pair[0]), pair[1]];
  14407. });
  14408. return baseRest(function(args) {
  14409. var index = -1;
  14410. while (++index < length) {
  14411. var pair = pairs[index];
  14412. if (apply(pair[0], this, args)) {
  14413. return apply(pair[1], this, args);
  14414. }
  14415. }
  14416. });
  14417. }
  14418. /**
  14419. * Creates a function that invokes the predicate properties of `source` with
  14420. * the corresponding property values of a given object, returning `true` if
  14421. * all predicates return truthy, else `false`.
  14422. *
  14423. * **Note:** The created function is equivalent to `_.conformsTo` with
  14424. * `source` partially applied.
  14425. *
  14426. * @static
  14427. * @memberOf _
  14428. * @since 4.0.0
  14429. * @category Util
  14430. * @param {Object} source The object of property predicates to conform to.
  14431. * @returns {Function} Returns the new spec function.
  14432. * @example
  14433. *
  14434. * var objects = [
  14435. * { 'a': 2, 'b': 1 },
  14436. * { 'a': 1, 'b': 2 }
  14437. * ];
  14438. *
  14439. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14440. * // => [{ 'a': 1, 'b': 2 }]
  14441. */
  14442. function conforms(source) {
  14443. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14444. }
  14445. /**
  14446. * Creates a function that returns `value`.
  14447. *
  14448. * @static
  14449. * @memberOf _
  14450. * @since 2.4.0
  14451. * @category Util
  14452. * @param {*} value The value to return from the new function.
  14453. * @returns {Function} Returns the new constant function.
  14454. * @example
  14455. *
  14456. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14457. *
  14458. * console.log(objects);
  14459. * // => [{ 'a': 1 }, { 'a': 1 }]
  14460. *
  14461. * console.log(objects[0] === objects[1]);
  14462. * // => true
  14463. */
  14464. function constant(value) {
  14465. return function() {
  14466. return value;
  14467. };
  14468. }
  14469. /**
  14470. * Checks `value` to determine whether a default value should be returned in
  14471. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14472. * or `undefined`.
  14473. *
  14474. * @static
  14475. * @memberOf _
  14476. * @since 4.14.0
  14477. * @category Util
  14478. * @param {*} value The value to check.
  14479. * @param {*} defaultValue The default value.
  14480. * @returns {*} Returns the resolved value.
  14481. * @example
  14482. *
  14483. * _.defaultTo(1, 10);
  14484. * // => 1
  14485. *
  14486. * _.defaultTo(undefined, 10);
  14487. * // => 10
  14488. */
  14489. function defaultTo(value, defaultValue) {
  14490. return (value == null || value !== value) ? defaultValue : value;
  14491. }
  14492. /**
  14493. * Creates a function that returns the result of invoking the given functions
  14494. * with the `this` binding of the created function, where each successive
  14495. * invocation is supplied the return value of the previous.
  14496. *
  14497. * @static
  14498. * @memberOf _
  14499. * @since 3.0.0
  14500. * @category Util
  14501. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14502. * @returns {Function} Returns the new composite function.
  14503. * @see _.flowRight
  14504. * @example
  14505. *
  14506. * function square(n) {
  14507. * return n * n;
  14508. * }
  14509. *
  14510. * var addSquare = _.flow([_.add, square]);
  14511. * addSquare(1, 2);
  14512. * // => 9
  14513. */
  14514. var flow = createFlow();
  14515. /**
  14516. * This method is like `_.flow` except that it creates a function that
  14517. * invokes the given functions from right to left.
  14518. *
  14519. * @static
  14520. * @since 3.0.0
  14521. * @memberOf _
  14522. * @category Util
  14523. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14524. * @returns {Function} Returns the new composite function.
  14525. * @see _.flow
  14526. * @example
  14527. *
  14528. * function square(n) {
  14529. * return n * n;
  14530. * }
  14531. *
  14532. * var addSquare = _.flowRight([square, _.add]);
  14533. * addSquare(1, 2);
  14534. * // => 9
  14535. */
  14536. var flowRight = createFlow(true);
  14537. /**
  14538. * This method returns the first argument it receives.
  14539. *
  14540. * @static
  14541. * @since 0.1.0
  14542. * @memberOf _
  14543. * @category Util
  14544. * @param {*} value Any value.
  14545. * @returns {*} Returns `value`.
  14546. * @example
  14547. *
  14548. * var object = { 'a': 1 };
  14549. *
  14550. * console.log(_.identity(object) === object);
  14551. * // => true
  14552. */
  14553. function identity(value) {
  14554. return value;
  14555. }
  14556. /**
  14557. * Creates a function that invokes `func` with the arguments of the created
  14558. * function. If `func` is a property name, the created function returns the
  14559. * property value for a given element. If `func` is an array or object, the
  14560. * created function returns `true` for elements that contain the equivalent
  14561. * source properties, otherwise it returns `false`.
  14562. *
  14563. * @static
  14564. * @since 4.0.0
  14565. * @memberOf _
  14566. * @category Util
  14567. * @param {*} [func=_.identity] The value to convert to a callback.
  14568. * @returns {Function} Returns the callback.
  14569. * @example
  14570. *
  14571. * var users = [
  14572. * { 'user': 'barney', 'age': 36, 'active': true },
  14573. * { 'user': 'fred', 'age': 40, 'active': false }
  14574. * ];
  14575. *
  14576. * // The `_.matches` iteratee shorthand.
  14577. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14578. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14579. *
  14580. * // The `_.matchesProperty` iteratee shorthand.
  14581. * _.filter(users, _.iteratee(['user', 'fred']));
  14582. * // => [{ 'user': 'fred', 'age': 40 }]
  14583. *
  14584. * // The `_.property` iteratee shorthand.
  14585. * _.map(users, _.iteratee('user'));
  14586. * // => ['barney', 'fred']
  14587. *
  14588. * // Create custom iteratee shorthands.
  14589. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14590. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14591. * return func.test(string);
  14592. * };
  14593. * });
  14594. *
  14595. * _.filter(['abc', 'def'], /ef/);
  14596. * // => ['def']
  14597. */
  14598. function iteratee(func) {
  14599. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14600. }
  14601. /**
  14602. * Creates a function that performs a partial deep comparison between a given
  14603. * object and `source`, returning `true` if the given object has equivalent
  14604. * property values, else `false`.
  14605. *
  14606. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14607. * partially applied.
  14608. *
  14609. * Partial comparisons will match empty array and empty object `source`
  14610. * values against any array or object value, respectively. See `_.isEqual`
  14611. * for a list of supported value comparisons.
  14612. *
  14613. * **Note:** Multiple values can be checked by combining several matchers
  14614. * using `_.overSome`
  14615. *
  14616. * @static
  14617. * @memberOf _
  14618. * @since 3.0.0
  14619. * @category Util
  14620. * @param {Object} source The object of property values to match.
  14621. * @returns {Function} Returns the new spec function.
  14622. * @example
  14623. *
  14624. * var objects = [
  14625. * { 'a': 1, 'b': 2, 'c': 3 },
  14626. * { 'a': 4, 'b': 5, 'c': 6 }
  14627. * ];
  14628. *
  14629. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14630. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14631. *
  14632. * // Checking for several possible values
  14633. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  14634. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14635. */
  14636. function matches(source) {
  14637. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14638. }
  14639. /**
  14640. * Creates a function that performs a partial deep comparison between the
  14641. * value at `path` of a given object to `srcValue`, returning `true` if the
  14642. * object value is equivalent, else `false`.
  14643. *
  14644. * **Note:** Partial comparisons will match empty array and empty object
  14645. * `srcValue` values against any array or object value, respectively. See
  14646. * `_.isEqual` for a list of supported value comparisons.
  14647. *
  14648. * **Note:** Multiple values can be checked by combining several matchers
  14649. * using `_.overSome`
  14650. *
  14651. * @static
  14652. * @memberOf _
  14653. * @since 3.2.0
  14654. * @category Util
  14655. * @param {Array|string} path The path of the property to get.
  14656. * @param {*} srcValue The value to match.
  14657. * @returns {Function} Returns the new spec function.
  14658. * @example
  14659. *
  14660. * var objects = [
  14661. * { 'a': 1, 'b': 2, 'c': 3 },
  14662. * { 'a': 4, 'b': 5, 'c': 6 }
  14663. * ];
  14664. *
  14665. * _.find(objects, _.matchesProperty('a', 4));
  14666. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14667. *
  14668. * // Checking for several possible values
  14669. * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
  14670. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14671. */
  14672. function matchesProperty(path, srcValue) {
  14673. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14674. }
  14675. /**
  14676. * Creates a function that invokes the method at `path` of a given object.
  14677. * Any additional arguments are provided to the invoked method.
  14678. *
  14679. * @static
  14680. * @memberOf _
  14681. * @since 3.7.0
  14682. * @category Util
  14683. * @param {Array|string} path The path of the method to invoke.
  14684. * @param {...*} [args] The arguments to invoke the method with.
  14685. * @returns {Function} Returns the new invoker function.
  14686. * @example
  14687. *
  14688. * var objects = [
  14689. * { 'a': { 'b': _.constant(2) } },
  14690. * { 'a': { 'b': _.constant(1) } }
  14691. * ];
  14692. *
  14693. * _.map(objects, _.method('a.b'));
  14694. * // => [2, 1]
  14695. *
  14696. * _.map(objects, _.method(['a', 'b']));
  14697. * // => [2, 1]
  14698. */
  14699. var method = baseRest(function(path, args) {
  14700. return function(object) {
  14701. return baseInvoke(object, path, args);
  14702. };
  14703. });
  14704. /**
  14705. * The opposite of `_.method`; this method creates a function that invokes
  14706. * the method at a given path of `object`. Any additional arguments are
  14707. * provided to the invoked method.
  14708. *
  14709. * @static
  14710. * @memberOf _
  14711. * @since 3.7.0
  14712. * @category Util
  14713. * @param {Object} object The object to query.
  14714. * @param {...*} [args] The arguments to invoke the method with.
  14715. * @returns {Function} Returns the new invoker function.
  14716. * @example
  14717. *
  14718. * var array = _.times(3, _.constant),
  14719. * object = { 'a': array, 'b': array, 'c': array };
  14720. *
  14721. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14722. * // => [2, 0]
  14723. *
  14724. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14725. * // => [2, 0]
  14726. */
  14727. var methodOf = baseRest(function(object, args) {
  14728. return function(path) {
  14729. return baseInvoke(object, path, args);
  14730. };
  14731. });
  14732. /**
  14733. * Adds all own enumerable string keyed function properties of a source
  14734. * object to the destination object. If `object` is a function, then methods
  14735. * are added to its prototype as well.
  14736. *
  14737. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14738. * avoid conflicts caused by modifying the original.
  14739. *
  14740. * @static
  14741. * @since 0.1.0
  14742. * @memberOf _
  14743. * @category Util
  14744. * @param {Function|Object} [object=lodash] The destination object.
  14745. * @param {Object} source The object of functions to add.
  14746. * @param {Object} [options={}] The options object.
  14747. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14748. * @returns {Function|Object} Returns `object`.
  14749. * @example
  14750. *
  14751. * function vowels(string) {
  14752. * return _.filter(string, function(v) {
  14753. * return /[aeiou]/i.test(v);
  14754. * });
  14755. * }
  14756. *
  14757. * _.mixin({ 'vowels': vowels });
  14758. * _.vowels('fred');
  14759. * // => ['e']
  14760. *
  14761. * _('fred').vowels().value();
  14762. * // => ['e']
  14763. *
  14764. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14765. * _('fred').vowels();
  14766. * // => ['e']
  14767. */
  14768. function mixin(object, source, options) {
  14769. var props = keys(source),
  14770. methodNames = baseFunctions(source, props);
  14771. if (options == null &&
  14772. !(isObject(source) && (methodNames.length || !props.length))) {
  14773. options = source;
  14774. source = object;
  14775. object = this;
  14776. methodNames = baseFunctions(source, keys(source));
  14777. }
  14778. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14779. isFunc = isFunction(object);
  14780. arrayEach(methodNames, function(methodName) {
  14781. var func = source[methodName];
  14782. object[methodName] = func;
  14783. if (isFunc) {
  14784. object.prototype[methodName] = function() {
  14785. var chainAll = this.__chain__;
  14786. if (chain || chainAll) {
  14787. var result = object(this.__wrapped__),
  14788. actions = result.__actions__ = copyArray(this.__actions__);
  14789. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14790. result.__chain__ = chainAll;
  14791. return result;
  14792. }
  14793. return func.apply(object, arrayPush([this.value()], arguments));
  14794. };
  14795. }
  14796. });
  14797. return object;
  14798. }
  14799. /**
  14800. * Reverts the `_` variable to its previous value and returns a reference to
  14801. * the `lodash` function.
  14802. *
  14803. * @static
  14804. * @since 0.1.0
  14805. * @memberOf _
  14806. * @category Util
  14807. * @returns {Function} Returns the `lodash` function.
  14808. * @example
  14809. *
  14810. * var lodash = _.noConflict();
  14811. */
  14812. function noConflict() {
  14813. if (root._ === this) {
  14814. root._ = oldDash;
  14815. }
  14816. return this;
  14817. }
  14818. /**
  14819. * This method returns `undefined`.
  14820. *
  14821. * @static
  14822. * @memberOf _
  14823. * @since 2.3.0
  14824. * @category Util
  14825. * @example
  14826. *
  14827. * _.times(2, _.noop);
  14828. * // => [undefined, undefined]
  14829. */
  14830. function noop() {
  14831. // No operation performed.
  14832. }
  14833. /**
  14834. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14835. * the nth argument from the end is returned.
  14836. *
  14837. * @static
  14838. * @memberOf _
  14839. * @since 4.0.0
  14840. * @category Util
  14841. * @param {number} [n=0] The index of the argument to return.
  14842. * @returns {Function} Returns the new pass-thru function.
  14843. * @example
  14844. *
  14845. * var func = _.nthArg(1);
  14846. * func('a', 'b', 'c', 'd');
  14847. * // => 'b'
  14848. *
  14849. * var func = _.nthArg(-2);
  14850. * func('a', 'b', 'c', 'd');
  14851. * // => 'c'
  14852. */
  14853. function nthArg(n) {
  14854. n = toInteger(n);
  14855. return baseRest(function(args) {
  14856. return baseNth(args, n);
  14857. });
  14858. }
  14859. /**
  14860. * Creates a function that invokes `iteratees` with the arguments it receives
  14861. * and returns their results.
  14862. *
  14863. * @static
  14864. * @memberOf _
  14865. * @since 4.0.0
  14866. * @category Util
  14867. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14868. * The iteratees to invoke.
  14869. * @returns {Function} Returns the new function.
  14870. * @example
  14871. *
  14872. * var func = _.over([Math.max, Math.min]);
  14873. *
  14874. * func(1, 2, 3, 4);
  14875. * // => [4, 1]
  14876. */
  14877. var over = createOver(arrayMap);
  14878. /**
  14879. * Creates a function that checks if **all** of the `predicates` return
  14880. * truthy when invoked with the arguments it receives.
  14881. *
  14882. * Following shorthands are possible for providing predicates.
  14883. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14884. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14885. *
  14886. * @static
  14887. * @memberOf _
  14888. * @since 4.0.0
  14889. * @category Util
  14890. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14891. * The predicates to check.
  14892. * @returns {Function} Returns the new function.
  14893. * @example
  14894. *
  14895. * var func = _.overEvery([Boolean, isFinite]);
  14896. *
  14897. * func('1');
  14898. * // => true
  14899. *
  14900. * func(null);
  14901. * // => false
  14902. *
  14903. * func(NaN);
  14904. * // => false
  14905. */
  14906. var overEvery = createOver(arrayEvery);
  14907. /**
  14908. * Creates a function that checks if **any** of the `predicates` return
  14909. * truthy when invoked with the arguments it receives.
  14910. *
  14911. * Following shorthands are possible for providing predicates.
  14912. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14913. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14914. *
  14915. * @static
  14916. * @memberOf _
  14917. * @since 4.0.0
  14918. * @category Util
  14919. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14920. * The predicates to check.
  14921. * @returns {Function} Returns the new function.
  14922. * @example
  14923. *
  14924. * var func = _.overSome([Boolean, isFinite]);
  14925. *
  14926. * func('1');
  14927. * // => true
  14928. *
  14929. * func(null);
  14930. * // => true
  14931. *
  14932. * func(NaN);
  14933. * // => false
  14934. *
  14935. * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
  14936. * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
  14937. */
  14938. var overSome = createOver(arraySome);
  14939. /**
  14940. * Creates a function that returns the value at `path` of a given object.
  14941. *
  14942. * @static
  14943. * @memberOf _
  14944. * @since 2.4.0
  14945. * @category Util
  14946. * @param {Array|string} path The path of the property to get.
  14947. * @returns {Function} Returns the new accessor function.
  14948. * @example
  14949. *
  14950. * var objects = [
  14951. * { 'a': { 'b': 2 } },
  14952. * { 'a': { 'b': 1 } }
  14953. * ];
  14954. *
  14955. * _.map(objects, _.property('a.b'));
  14956. * // => [2, 1]
  14957. *
  14958. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14959. * // => [1, 2]
  14960. */
  14961. function property(path) {
  14962. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14963. }
  14964. /**
  14965. * The opposite of `_.property`; this method creates a function that returns
  14966. * the value at a given path of `object`.
  14967. *
  14968. * @static
  14969. * @memberOf _
  14970. * @since 3.0.0
  14971. * @category Util
  14972. * @param {Object} object The object to query.
  14973. * @returns {Function} Returns the new accessor function.
  14974. * @example
  14975. *
  14976. * var array = [0, 1, 2],
  14977. * object = { 'a': array, 'b': array, 'c': array };
  14978. *
  14979. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14980. * // => [2, 0]
  14981. *
  14982. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14983. * // => [2, 0]
  14984. */
  14985. function propertyOf(object) {
  14986. return function(path) {
  14987. return object == null ? undefined : baseGet(object, path);
  14988. };
  14989. }
  14990. /**
  14991. * Creates an array of numbers (positive and/or negative) progressing from
  14992. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14993. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14994. * it's set to `start` with `start` then set to `0`.
  14995. *
  14996. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14997. * floating-point values which can produce unexpected results.
  14998. *
  14999. * @static
  15000. * @since 0.1.0
  15001. * @memberOf _
  15002. * @category Util
  15003. * @param {number} [start=0] The start of the range.
  15004. * @param {number} end The end of the range.
  15005. * @param {number} [step=1] The value to increment or decrement by.
  15006. * @returns {Array} Returns the range of numbers.
  15007. * @see _.inRange, _.rangeRight
  15008. * @example
  15009. *
  15010. * _.range(4);
  15011. * // => [0, 1, 2, 3]
  15012. *
  15013. * _.range(-4);
  15014. * // => [0, -1, -2, -3]
  15015. *
  15016. * _.range(1, 5);
  15017. * // => [1, 2, 3, 4]
  15018. *
  15019. * _.range(0, 20, 5);
  15020. * // => [0, 5, 10, 15]
  15021. *
  15022. * _.range(0, -4, -1);
  15023. * // => [0, -1, -2, -3]
  15024. *
  15025. * _.range(1, 4, 0);
  15026. * // => [1, 1, 1]
  15027. *
  15028. * _.range(0);
  15029. * // => []
  15030. */
  15031. var range = createRange();
  15032. /**
  15033. * This method is like `_.range` except that it populates values in
  15034. * descending order.
  15035. *
  15036. * @static
  15037. * @memberOf _
  15038. * @since 4.0.0
  15039. * @category Util
  15040. * @param {number} [start=0] The start of the range.
  15041. * @param {number} end The end of the range.
  15042. * @param {number} [step=1] The value to increment or decrement by.
  15043. * @returns {Array} Returns the range of numbers.
  15044. * @see _.inRange, _.range
  15045. * @example
  15046. *
  15047. * _.rangeRight(4);
  15048. * // => [3, 2, 1, 0]
  15049. *
  15050. * _.rangeRight(-4);
  15051. * // => [-3, -2, -1, 0]
  15052. *
  15053. * _.rangeRight(1, 5);
  15054. * // => [4, 3, 2, 1]
  15055. *
  15056. * _.rangeRight(0, 20, 5);
  15057. * // => [15, 10, 5, 0]
  15058. *
  15059. * _.rangeRight(0, -4, -1);
  15060. * // => [-3, -2, -1, 0]
  15061. *
  15062. * _.rangeRight(1, 4, 0);
  15063. * // => [1, 1, 1]
  15064. *
  15065. * _.rangeRight(0);
  15066. * // => []
  15067. */
  15068. var rangeRight = createRange(true);
  15069. /**
  15070. * This method returns a new empty array.
  15071. *
  15072. * @static
  15073. * @memberOf _
  15074. * @since 4.13.0
  15075. * @category Util
  15076. * @returns {Array} Returns the new empty array.
  15077. * @example
  15078. *
  15079. * var arrays = _.times(2, _.stubArray);
  15080. *
  15081. * console.log(arrays);
  15082. * // => [[], []]
  15083. *
  15084. * console.log(arrays[0] === arrays[1]);
  15085. * // => false
  15086. */
  15087. function stubArray() {
  15088. return [];
  15089. }
  15090. /**
  15091. * This method returns `false`.
  15092. *
  15093. * @static
  15094. * @memberOf _
  15095. * @since 4.13.0
  15096. * @category Util
  15097. * @returns {boolean} Returns `false`.
  15098. * @example
  15099. *
  15100. * _.times(2, _.stubFalse);
  15101. * // => [false, false]
  15102. */
  15103. function stubFalse() {
  15104. return false;
  15105. }
  15106. /**
  15107. * This method returns a new empty object.
  15108. *
  15109. * @static
  15110. * @memberOf _
  15111. * @since 4.13.0
  15112. * @category Util
  15113. * @returns {Object} Returns the new empty object.
  15114. * @example
  15115. *
  15116. * var objects = _.times(2, _.stubObject);
  15117. *
  15118. * console.log(objects);
  15119. * // => [{}, {}]
  15120. *
  15121. * console.log(objects[0] === objects[1]);
  15122. * // => false
  15123. */
  15124. function stubObject() {
  15125. return {};
  15126. }
  15127. /**
  15128. * This method returns an empty string.
  15129. *
  15130. * @static
  15131. * @memberOf _
  15132. * @since 4.13.0
  15133. * @category Util
  15134. * @returns {string} Returns the empty string.
  15135. * @example
  15136. *
  15137. * _.times(2, _.stubString);
  15138. * // => ['', '']
  15139. */
  15140. function stubString() {
  15141. return '';
  15142. }
  15143. /**
  15144. * This method returns `true`.
  15145. *
  15146. * @static
  15147. * @memberOf _
  15148. * @since 4.13.0
  15149. * @category Util
  15150. * @returns {boolean} Returns `true`.
  15151. * @example
  15152. *
  15153. * _.times(2, _.stubTrue);
  15154. * // => [true, true]
  15155. */
  15156. function stubTrue() {
  15157. return true;
  15158. }
  15159. /**
  15160. * Invokes the iteratee `n` times, returning an array of the results of
  15161. * each invocation. The iteratee is invoked with one argument; (index).
  15162. *
  15163. * @static
  15164. * @since 0.1.0
  15165. * @memberOf _
  15166. * @category Util
  15167. * @param {number} n The number of times to invoke `iteratee`.
  15168. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15169. * @returns {Array} Returns the array of results.
  15170. * @example
  15171. *
  15172. * _.times(3, String);
  15173. * // => ['0', '1', '2']
  15174. *
  15175. * _.times(4, _.constant(0));
  15176. * // => [0, 0, 0, 0]
  15177. */
  15178. function times(n, iteratee) {
  15179. n = toInteger(n);
  15180. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15181. return [];
  15182. }
  15183. var index = MAX_ARRAY_LENGTH,
  15184. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15185. iteratee = getIteratee(iteratee);
  15186. n -= MAX_ARRAY_LENGTH;
  15187. var result = baseTimes(length, iteratee);
  15188. while (++index < n) {
  15189. iteratee(index);
  15190. }
  15191. return result;
  15192. }
  15193. /**
  15194. * Converts `value` to a property path array.
  15195. *
  15196. * @static
  15197. * @memberOf _
  15198. * @since 4.0.0
  15199. * @category Util
  15200. * @param {*} value The value to convert.
  15201. * @returns {Array} Returns the new property path array.
  15202. * @example
  15203. *
  15204. * _.toPath('a.b.c');
  15205. * // => ['a', 'b', 'c']
  15206. *
  15207. * _.toPath('a[0].b.c');
  15208. * // => ['a', '0', 'b', 'c']
  15209. */
  15210. function toPath(value) {
  15211. if (isArray(value)) {
  15212. return arrayMap(value, toKey);
  15213. }
  15214. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15215. }
  15216. /**
  15217. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15218. *
  15219. * @static
  15220. * @since 0.1.0
  15221. * @memberOf _
  15222. * @category Util
  15223. * @param {string} [prefix=''] The value to prefix the ID with.
  15224. * @returns {string} Returns the unique ID.
  15225. * @example
  15226. *
  15227. * _.uniqueId('contact_');
  15228. * // => 'contact_104'
  15229. *
  15230. * _.uniqueId();
  15231. * // => '105'
  15232. */
  15233. function uniqueId(prefix) {
  15234. var id = ++idCounter;
  15235. return toString(prefix) + id;
  15236. }
  15237. /*------------------------------------------------------------------------*/
  15238. /**
  15239. * Adds two numbers.
  15240. *
  15241. * @static
  15242. * @memberOf _
  15243. * @since 3.4.0
  15244. * @category Math
  15245. * @param {number} augend The first number in an addition.
  15246. * @param {number} addend The second number in an addition.
  15247. * @returns {number} Returns the total.
  15248. * @example
  15249. *
  15250. * _.add(6, 4);
  15251. * // => 10
  15252. */
  15253. var add = createMathOperation(function(augend, addend) {
  15254. return augend + addend;
  15255. }, 0);
  15256. /**
  15257. * Computes `number` rounded up to `precision`.
  15258. *
  15259. * @static
  15260. * @memberOf _
  15261. * @since 3.10.0
  15262. * @category Math
  15263. * @param {number} number The number to round up.
  15264. * @param {number} [precision=0] The precision to round up to.
  15265. * @returns {number} Returns the rounded up number.
  15266. * @example
  15267. *
  15268. * _.ceil(4.006);
  15269. * // => 5
  15270. *
  15271. * _.ceil(6.004, 2);
  15272. * // => 6.01
  15273. *
  15274. * _.ceil(6040, -2);
  15275. * // => 6100
  15276. */
  15277. var ceil = createRound('ceil');
  15278. /**
  15279. * Divide two numbers.
  15280. *
  15281. * @static
  15282. * @memberOf _
  15283. * @since 4.7.0
  15284. * @category Math
  15285. * @param {number} dividend The first number in a division.
  15286. * @param {number} divisor The second number in a division.
  15287. * @returns {number} Returns the quotient.
  15288. * @example
  15289. *
  15290. * _.divide(6, 4);
  15291. * // => 1.5
  15292. */
  15293. var divide = createMathOperation(function(dividend, divisor) {
  15294. return dividend / divisor;
  15295. }, 1);
  15296. /**
  15297. * Computes `number` rounded down to `precision`.
  15298. *
  15299. * @static
  15300. * @memberOf _
  15301. * @since 3.10.0
  15302. * @category Math
  15303. * @param {number} number The number to round down.
  15304. * @param {number} [precision=0] The precision to round down to.
  15305. * @returns {number} Returns the rounded down number.
  15306. * @example
  15307. *
  15308. * _.floor(4.006);
  15309. * // => 4
  15310. *
  15311. * _.floor(0.046, 2);
  15312. * // => 0.04
  15313. *
  15314. * _.floor(4060, -2);
  15315. * // => 4000
  15316. */
  15317. var floor = createRound('floor');
  15318. /**
  15319. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15320. * `undefined` is returned.
  15321. *
  15322. * @static
  15323. * @since 0.1.0
  15324. * @memberOf _
  15325. * @category Math
  15326. * @param {Array} array The array to iterate over.
  15327. * @returns {*} Returns the maximum value.
  15328. * @example
  15329. *
  15330. * _.max([4, 2, 8, 6]);
  15331. * // => 8
  15332. *
  15333. * _.max([]);
  15334. * // => undefined
  15335. */
  15336. function max(array) {
  15337. return (array && array.length)
  15338. ? baseExtremum(array, identity, baseGt)
  15339. : undefined;
  15340. }
  15341. /**
  15342. * This method is like `_.max` except that it accepts `iteratee` which is
  15343. * invoked for each element in `array` to generate the criterion by which
  15344. * the value is ranked. The iteratee is invoked with one argument: (value).
  15345. *
  15346. * @static
  15347. * @memberOf _
  15348. * @since 4.0.0
  15349. * @category Math
  15350. * @param {Array} array The array to iterate over.
  15351. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15352. * @returns {*} Returns the maximum value.
  15353. * @example
  15354. *
  15355. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15356. *
  15357. * _.maxBy(objects, function(o) { return o.n; });
  15358. * // => { 'n': 2 }
  15359. *
  15360. * // The `_.property` iteratee shorthand.
  15361. * _.maxBy(objects, 'n');
  15362. * // => { 'n': 2 }
  15363. */
  15364. function maxBy(array, iteratee) {
  15365. return (array && array.length)
  15366. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15367. : undefined;
  15368. }
  15369. /**
  15370. * Computes the mean of the values in `array`.
  15371. *
  15372. * @static
  15373. * @memberOf _
  15374. * @since 4.0.0
  15375. * @category Math
  15376. * @param {Array} array The array to iterate over.
  15377. * @returns {number} Returns the mean.
  15378. * @example
  15379. *
  15380. * _.mean([4, 2, 8, 6]);
  15381. * // => 5
  15382. */
  15383. function mean(array) {
  15384. return baseMean(array, identity);
  15385. }
  15386. /**
  15387. * This method is like `_.mean` except that it accepts `iteratee` which is
  15388. * invoked for each element in `array` to generate the value to be averaged.
  15389. * The iteratee is invoked with one argument: (value).
  15390. *
  15391. * @static
  15392. * @memberOf _
  15393. * @since 4.7.0
  15394. * @category Math
  15395. * @param {Array} array The array to iterate over.
  15396. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15397. * @returns {number} Returns the mean.
  15398. * @example
  15399. *
  15400. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15401. *
  15402. * _.meanBy(objects, function(o) { return o.n; });
  15403. * // => 5
  15404. *
  15405. * // The `_.property` iteratee shorthand.
  15406. * _.meanBy(objects, 'n');
  15407. * // => 5
  15408. */
  15409. function meanBy(array, iteratee) {
  15410. return baseMean(array, getIteratee(iteratee, 2));
  15411. }
  15412. /**
  15413. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15414. * `undefined` is returned.
  15415. *
  15416. * @static
  15417. * @since 0.1.0
  15418. * @memberOf _
  15419. * @category Math
  15420. * @param {Array} array The array to iterate over.
  15421. * @returns {*} Returns the minimum value.
  15422. * @example
  15423. *
  15424. * _.min([4, 2, 8, 6]);
  15425. * // => 2
  15426. *
  15427. * _.min([]);
  15428. * // => undefined
  15429. */
  15430. function min(array) {
  15431. return (array && array.length)
  15432. ? baseExtremum(array, identity, baseLt)
  15433. : undefined;
  15434. }
  15435. /**
  15436. * This method is like `_.min` except that it accepts `iteratee` which is
  15437. * invoked for each element in `array` to generate the criterion by which
  15438. * the value is ranked. The iteratee is invoked with one argument: (value).
  15439. *
  15440. * @static
  15441. * @memberOf _
  15442. * @since 4.0.0
  15443. * @category Math
  15444. * @param {Array} array The array to iterate over.
  15445. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15446. * @returns {*} Returns the minimum value.
  15447. * @example
  15448. *
  15449. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15450. *
  15451. * _.minBy(objects, function(o) { return o.n; });
  15452. * // => { 'n': 1 }
  15453. *
  15454. * // The `_.property` iteratee shorthand.
  15455. * _.minBy(objects, 'n');
  15456. * // => { 'n': 1 }
  15457. */
  15458. function minBy(array, iteratee) {
  15459. return (array && array.length)
  15460. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15461. : undefined;
  15462. }
  15463. /**
  15464. * Multiply two numbers.
  15465. *
  15466. * @static
  15467. * @memberOf _
  15468. * @since 4.7.0
  15469. * @category Math
  15470. * @param {number} multiplier The first number in a multiplication.
  15471. * @param {number} multiplicand The second number in a multiplication.
  15472. * @returns {number} Returns the product.
  15473. * @example
  15474. *
  15475. * _.multiply(6, 4);
  15476. * // => 24
  15477. */
  15478. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15479. return multiplier * multiplicand;
  15480. }, 1);
  15481. /**
  15482. * Computes `number` rounded to `precision`.
  15483. *
  15484. * @static
  15485. * @memberOf _
  15486. * @since 3.10.0
  15487. * @category Math
  15488. * @param {number} number The number to round.
  15489. * @param {number} [precision=0] The precision to round to.
  15490. * @returns {number} Returns the rounded number.
  15491. * @example
  15492. *
  15493. * _.round(4.006);
  15494. * // => 4
  15495. *
  15496. * _.round(4.006, 2);
  15497. * // => 4.01
  15498. *
  15499. * _.round(4060, -2);
  15500. * // => 4100
  15501. */
  15502. var round = createRound('round');
  15503. /**
  15504. * Subtract two numbers.
  15505. *
  15506. * @static
  15507. * @memberOf _
  15508. * @since 4.0.0
  15509. * @category Math
  15510. * @param {number} minuend The first number in a subtraction.
  15511. * @param {number} subtrahend The second number in a subtraction.
  15512. * @returns {number} Returns the difference.
  15513. * @example
  15514. *
  15515. * _.subtract(6, 4);
  15516. * // => 2
  15517. */
  15518. var subtract = createMathOperation(function(minuend, subtrahend) {
  15519. return minuend - subtrahend;
  15520. }, 0);
  15521. /**
  15522. * Computes the sum of the values in `array`.
  15523. *
  15524. * @static
  15525. * @memberOf _
  15526. * @since 3.4.0
  15527. * @category Math
  15528. * @param {Array} array The array to iterate over.
  15529. * @returns {number} Returns the sum.
  15530. * @example
  15531. *
  15532. * _.sum([4, 2, 8, 6]);
  15533. * // => 20
  15534. */
  15535. function sum(array) {
  15536. return (array && array.length)
  15537. ? baseSum(array, identity)
  15538. : 0;
  15539. }
  15540. /**
  15541. * This method is like `_.sum` except that it accepts `iteratee` which is
  15542. * invoked for each element in `array` to generate the value to be summed.
  15543. * The iteratee is invoked with one argument: (value).
  15544. *
  15545. * @static
  15546. * @memberOf _
  15547. * @since 4.0.0
  15548. * @category Math
  15549. * @param {Array} array The array to iterate over.
  15550. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15551. * @returns {number} Returns the sum.
  15552. * @example
  15553. *
  15554. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15555. *
  15556. * _.sumBy(objects, function(o) { return o.n; });
  15557. * // => 20
  15558. *
  15559. * // The `_.property` iteratee shorthand.
  15560. * _.sumBy(objects, 'n');
  15561. * // => 20
  15562. */
  15563. function sumBy(array, iteratee) {
  15564. return (array && array.length)
  15565. ? baseSum(array, getIteratee(iteratee, 2))
  15566. : 0;
  15567. }
  15568. /*------------------------------------------------------------------------*/
  15569. // Add methods that return wrapped values in chain sequences.
  15570. lodash.after = after;
  15571. lodash.ary = ary;
  15572. lodash.assign = assign;
  15573. lodash.assignIn = assignIn;
  15574. lodash.assignInWith = assignInWith;
  15575. lodash.assignWith = assignWith;
  15576. lodash.at = at;
  15577. lodash.before = before;
  15578. lodash.bind = bind;
  15579. lodash.bindAll = bindAll;
  15580. lodash.bindKey = bindKey;
  15581. lodash.castArray = castArray;
  15582. lodash.chain = chain;
  15583. lodash.chunk = chunk;
  15584. lodash.compact = compact;
  15585. lodash.concat = concat;
  15586. lodash.cond = cond;
  15587. lodash.conforms = conforms;
  15588. lodash.constant = constant;
  15589. lodash.countBy = countBy;
  15590. lodash.create = create;
  15591. lodash.curry = curry;
  15592. lodash.curryRight = curryRight;
  15593. lodash.debounce = debounce;
  15594. lodash.defaults = defaults;
  15595. lodash.defaultsDeep = defaultsDeep;
  15596. lodash.defer = defer;
  15597. lodash.delay = delay;
  15598. lodash.difference = difference;
  15599. lodash.differenceBy = differenceBy;
  15600. lodash.differenceWith = differenceWith;
  15601. lodash.drop = drop;
  15602. lodash.dropRight = dropRight;
  15603. lodash.dropRightWhile = dropRightWhile;
  15604. lodash.dropWhile = dropWhile;
  15605. lodash.fill = fill;
  15606. lodash.filter = filter;
  15607. lodash.flatMap = flatMap;
  15608. lodash.flatMapDeep = flatMapDeep;
  15609. lodash.flatMapDepth = flatMapDepth;
  15610. lodash.flatten = flatten;
  15611. lodash.flattenDeep = flattenDeep;
  15612. lodash.flattenDepth = flattenDepth;
  15613. lodash.flip = flip;
  15614. lodash.flow = flow;
  15615. lodash.flowRight = flowRight;
  15616. lodash.fromPairs = fromPairs;
  15617. lodash.functions = functions;
  15618. lodash.functionsIn = functionsIn;
  15619. lodash.groupBy = groupBy;
  15620. lodash.initial = initial;
  15621. lodash.intersection = intersection;
  15622. lodash.intersectionBy = intersectionBy;
  15623. lodash.intersectionWith = intersectionWith;
  15624. lodash.invert = invert;
  15625. lodash.invertBy = invertBy;
  15626. lodash.invokeMap = invokeMap;
  15627. lodash.iteratee = iteratee;
  15628. lodash.keyBy = keyBy;
  15629. lodash.keys = keys;
  15630. lodash.keysIn = keysIn;
  15631. lodash.map = map;
  15632. lodash.mapKeys = mapKeys;
  15633. lodash.mapValues = mapValues;
  15634. lodash.matches = matches;
  15635. lodash.matchesProperty = matchesProperty;
  15636. lodash.memoize = memoize;
  15637. lodash.merge = merge;
  15638. lodash.mergeWith = mergeWith;
  15639. lodash.method = method;
  15640. lodash.methodOf = methodOf;
  15641. lodash.mixin = mixin;
  15642. lodash.negate = negate;
  15643. lodash.nthArg = nthArg;
  15644. lodash.omit = omit;
  15645. lodash.omitBy = omitBy;
  15646. lodash.once = once;
  15647. lodash.orderBy = orderBy;
  15648. lodash.over = over;
  15649. lodash.overArgs = overArgs;
  15650. lodash.overEvery = overEvery;
  15651. lodash.overSome = overSome;
  15652. lodash.partial = partial;
  15653. lodash.partialRight = partialRight;
  15654. lodash.partition = partition;
  15655. lodash.pick = pick;
  15656. lodash.pickBy = pickBy;
  15657. lodash.property = property;
  15658. lodash.propertyOf = propertyOf;
  15659. lodash.pull = pull;
  15660. lodash.pullAll = pullAll;
  15661. lodash.pullAllBy = pullAllBy;
  15662. lodash.pullAllWith = pullAllWith;
  15663. lodash.pullAt = pullAt;
  15664. lodash.range = range;
  15665. lodash.rangeRight = rangeRight;
  15666. lodash.rearg = rearg;
  15667. lodash.reject = reject;
  15668. lodash.remove = remove;
  15669. lodash.rest = rest;
  15670. lodash.reverse = reverse;
  15671. lodash.sampleSize = sampleSize;
  15672. lodash.set = set;
  15673. lodash.setWith = setWith;
  15674. lodash.shuffle = shuffle;
  15675. lodash.slice = slice;
  15676. lodash.sortBy = sortBy;
  15677. lodash.sortedUniq = sortedUniq;
  15678. lodash.sortedUniqBy = sortedUniqBy;
  15679. lodash.split = split;
  15680. lodash.spread = spread;
  15681. lodash.tail = tail;
  15682. lodash.take = take;
  15683. lodash.takeRight = takeRight;
  15684. lodash.takeRightWhile = takeRightWhile;
  15685. lodash.takeWhile = takeWhile;
  15686. lodash.tap = tap;
  15687. lodash.throttle = throttle;
  15688. lodash.thru = thru;
  15689. lodash.toArray = toArray;
  15690. lodash.toPairs = toPairs;
  15691. lodash.toPairsIn = toPairsIn;
  15692. lodash.toPath = toPath;
  15693. lodash.toPlainObject = toPlainObject;
  15694. lodash.transform = transform;
  15695. lodash.unary = unary;
  15696. lodash.union = union;
  15697. lodash.unionBy = unionBy;
  15698. lodash.unionWith = unionWith;
  15699. lodash.uniq = uniq;
  15700. lodash.uniqBy = uniqBy;
  15701. lodash.uniqWith = uniqWith;
  15702. lodash.unset = unset;
  15703. lodash.unzip = unzip;
  15704. lodash.unzipWith = unzipWith;
  15705. lodash.update = update;
  15706. lodash.updateWith = updateWith;
  15707. lodash.values = values;
  15708. lodash.valuesIn = valuesIn;
  15709. lodash.without = without;
  15710. lodash.words = words;
  15711. lodash.wrap = wrap;
  15712. lodash.xor = xor;
  15713. lodash.xorBy = xorBy;
  15714. lodash.xorWith = xorWith;
  15715. lodash.zip = zip;
  15716. lodash.zipObject = zipObject;
  15717. lodash.zipObjectDeep = zipObjectDeep;
  15718. lodash.zipWith = zipWith;
  15719. // Add aliases.
  15720. lodash.entries = toPairs;
  15721. lodash.entriesIn = toPairsIn;
  15722. lodash.extend = assignIn;
  15723. lodash.extendWith = assignInWith;
  15724. // Add methods to `lodash.prototype`.
  15725. mixin(lodash, lodash);
  15726. /*------------------------------------------------------------------------*/
  15727. // Add methods that return unwrapped values in chain sequences.
  15728. lodash.add = add;
  15729. lodash.attempt = attempt;
  15730. lodash.camelCase = camelCase;
  15731. lodash.capitalize = capitalize;
  15732. lodash.ceil = ceil;
  15733. lodash.clamp = clamp;
  15734. lodash.clone = clone;
  15735. lodash.cloneDeep = cloneDeep;
  15736. lodash.cloneDeepWith = cloneDeepWith;
  15737. lodash.cloneWith = cloneWith;
  15738. lodash.conformsTo = conformsTo;
  15739. lodash.deburr = deburr;
  15740. lodash.defaultTo = defaultTo;
  15741. lodash.divide = divide;
  15742. lodash.endsWith = endsWith;
  15743. lodash.eq = eq;
  15744. lodash.escape = escape;
  15745. lodash.escapeRegExp = escapeRegExp;
  15746. lodash.every = every;
  15747. lodash.find = find;
  15748. lodash.findIndex = findIndex;
  15749. lodash.findKey = findKey;
  15750. lodash.findLast = findLast;
  15751. lodash.findLastIndex = findLastIndex;
  15752. lodash.findLastKey = findLastKey;
  15753. lodash.floor = floor;
  15754. lodash.forEach = forEach;
  15755. lodash.forEachRight = forEachRight;
  15756. lodash.forIn = forIn;
  15757. lodash.forInRight = forInRight;
  15758. lodash.forOwn = forOwn;
  15759. lodash.forOwnRight = forOwnRight;
  15760. lodash.get = get;
  15761. lodash.gt = gt;
  15762. lodash.gte = gte;
  15763. lodash.has = has;
  15764. lodash.hasIn = hasIn;
  15765. lodash.head = head;
  15766. lodash.identity = identity;
  15767. lodash.includes = includes;
  15768. lodash.indexOf = indexOf;
  15769. lodash.inRange = inRange;
  15770. lodash.invoke = invoke;
  15771. lodash.isArguments = isArguments;
  15772. lodash.isArray = isArray;
  15773. lodash.isArrayBuffer = isArrayBuffer;
  15774. lodash.isArrayLike = isArrayLike;
  15775. lodash.isArrayLikeObject = isArrayLikeObject;
  15776. lodash.isBoolean = isBoolean;
  15777. lodash.isBuffer = isBuffer;
  15778. lodash.isDate = isDate;
  15779. lodash.isElement = isElement;
  15780. lodash.isEmpty = isEmpty;
  15781. lodash.isEqual = isEqual;
  15782. lodash.isEqualWith = isEqualWith;
  15783. lodash.isError = isError;
  15784. lodash.isFinite = isFinite;
  15785. lodash.isFunction = isFunction;
  15786. lodash.isInteger = isInteger;
  15787. lodash.isLength = isLength;
  15788. lodash.isMap = isMap;
  15789. lodash.isMatch = isMatch;
  15790. lodash.isMatchWith = isMatchWith;
  15791. lodash.isNaN = isNaN;
  15792. lodash.isNative = isNative;
  15793. lodash.isNil = isNil;
  15794. lodash.isNull = isNull;
  15795. lodash.isNumber = isNumber;
  15796. lodash.isObject = isObject;
  15797. lodash.isObjectLike = isObjectLike;
  15798. lodash.isPlainObject = isPlainObject;
  15799. lodash.isRegExp = isRegExp;
  15800. lodash.isSafeInteger = isSafeInteger;
  15801. lodash.isSet = isSet;
  15802. lodash.isString = isString;
  15803. lodash.isSymbol = isSymbol;
  15804. lodash.isTypedArray = isTypedArray;
  15805. lodash.isUndefined = isUndefined;
  15806. lodash.isWeakMap = isWeakMap;
  15807. lodash.isWeakSet = isWeakSet;
  15808. lodash.join = join;
  15809. lodash.kebabCase = kebabCase;
  15810. lodash.last = last;
  15811. lodash.lastIndexOf = lastIndexOf;
  15812. lodash.lowerCase = lowerCase;
  15813. lodash.lowerFirst = lowerFirst;
  15814. lodash.lt = lt;
  15815. lodash.lte = lte;
  15816. lodash.max = max;
  15817. lodash.maxBy = maxBy;
  15818. lodash.mean = mean;
  15819. lodash.meanBy = meanBy;
  15820. lodash.min = min;
  15821. lodash.minBy = minBy;
  15822. lodash.stubArray = stubArray;
  15823. lodash.stubFalse = stubFalse;
  15824. lodash.stubObject = stubObject;
  15825. lodash.stubString = stubString;
  15826. lodash.stubTrue = stubTrue;
  15827. lodash.multiply = multiply;
  15828. lodash.nth = nth;
  15829. lodash.noConflict = noConflict;
  15830. lodash.noop = noop;
  15831. lodash.now = now;
  15832. lodash.pad = pad;
  15833. lodash.padEnd = padEnd;
  15834. lodash.padStart = padStart;
  15835. lodash.parseInt = parseInt;
  15836. lodash.random = random;
  15837. lodash.reduce = reduce;
  15838. lodash.reduceRight = reduceRight;
  15839. lodash.repeat = repeat;
  15840. lodash.replace = replace;
  15841. lodash.result = result;
  15842. lodash.round = round;
  15843. lodash.runInContext = runInContext;
  15844. lodash.sample = sample;
  15845. lodash.size = size;
  15846. lodash.snakeCase = snakeCase;
  15847. lodash.some = some;
  15848. lodash.sortedIndex = sortedIndex;
  15849. lodash.sortedIndexBy = sortedIndexBy;
  15850. lodash.sortedIndexOf = sortedIndexOf;
  15851. lodash.sortedLastIndex = sortedLastIndex;
  15852. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15853. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15854. lodash.startCase = startCase;
  15855. lodash.startsWith = startsWith;
  15856. lodash.subtract = subtract;
  15857. lodash.sum = sum;
  15858. lodash.sumBy = sumBy;
  15859. lodash.template = template;
  15860. lodash.times = times;
  15861. lodash.toFinite = toFinite;
  15862. lodash.toInteger = toInteger;
  15863. lodash.toLength = toLength;
  15864. lodash.toLower = toLower;
  15865. lodash.toNumber = toNumber;
  15866. lodash.toSafeInteger = toSafeInteger;
  15867. lodash.toString = toString;
  15868. lodash.toUpper = toUpper;
  15869. lodash.trim = trim;
  15870. lodash.trimEnd = trimEnd;
  15871. lodash.trimStart = trimStart;
  15872. lodash.truncate = truncate;
  15873. lodash.unescape = unescape;
  15874. lodash.uniqueId = uniqueId;
  15875. lodash.upperCase = upperCase;
  15876. lodash.upperFirst = upperFirst;
  15877. // Add aliases.
  15878. lodash.each = forEach;
  15879. lodash.eachRight = forEachRight;
  15880. lodash.first = head;
  15881. mixin(lodash, (function() {
  15882. var source = {};
  15883. baseForOwn(lodash, function(func, methodName) {
  15884. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15885. source[methodName] = func;
  15886. }
  15887. });
  15888. return source;
  15889. }()), { 'chain': false });
  15890. /*------------------------------------------------------------------------*/
  15891. /**
  15892. * The semantic version number.
  15893. *
  15894. * @static
  15895. * @memberOf _
  15896. * @type {string}
  15897. */
  15898. lodash.VERSION = VERSION;
  15899. // Assign default placeholders.
  15900. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15901. lodash[methodName].placeholder = lodash;
  15902. });
  15903. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15904. arrayEach(['drop', 'take'], function(methodName, index) {
  15905. LazyWrapper.prototype[methodName] = function(n) {
  15906. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15907. var result = (this.__filtered__ && !index)
  15908. ? new LazyWrapper(this)
  15909. : this.clone();
  15910. if (result.__filtered__) {
  15911. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15912. } else {
  15913. result.__views__.push({
  15914. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15915. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15916. });
  15917. }
  15918. return result;
  15919. };
  15920. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15921. return this.reverse()[methodName](n).reverse();
  15922. };
  15923. });
  15924. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15925. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15926. var type = index + 1,
  15927. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15928. LazyWrapper.prototype[methodName] = function(iteratee) {
  15929. var result = this.clone();
  15930. result.__iteratees__.push({
  15931. 'iteratee': getIteratee(iteratee, 3),
  15932. 'type': type
  15933. });
  15934. result.__filtered__ = result.__filtered__ || isFilter;
  15935. return result;
  15936. };
  15937. });
  15938. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15939. arrayEach(['head', 'last'], function(methodName, index) {
  15940. var takeName = 'take' + (index ? 'Right' : '');
  15941. LazyWrapper.prototype[methodName] = function() {
  15942. return this[takeName](1).value()[0];
  15943. };
  15944. });
  15945. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15946. arrayEach(['initial', 'tail'], function(methodName, index) {
  15947. var dropName = 'drop' + (index ? '' : 'Right');
  15948. LazyWrapper.prototype[methodName] = function() {
  15949. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15950. };
  15951. });
  15952. LazyWrapper.prototype.compact = function() {
  15953. return this.filter(identity);
  15954. };
  15955. LazyWrapper.prototype.find = function(predicate) {
  15956. return this.filter(predicate).head();
  15957. };
  15958. LazyWrapper.prototype.findLast = function(predicate) {
  15959. return this.reverse().find(predicate);
  15960. };
  15961. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15962. if (typeof path == 'function') {
  15963. return new LazyWrapper(this);
  15964. }
  15965. return this.map(function(value) {
  15966. return baseInvoke(value, path, args);
  15967. });
  15968. });
  15969. LazyWrapper.prototype.reject = function(predicate) {
  15970. return this.filter(negate(getIteratee(predicate)));
  15971. };
  15972. LazyWrapper.prototype.slice = function(start, end) {
  15973. start = toInteger(start);
  15974. var result = this;
  15975. if (result.__filtered__ && (start > 0 || end < 0)) {
  15976. return new LazyWrapper(result);
  15977. }
  15978. if (start < 0) {
  15979. result = result.takeRight(-start);
  15980. } else if (start) {
  15981. result = result.drop(start);
  15982. }
  15983. if (end !== undefined) {
  15984. end = toInteger(end);
  15985. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15986. }
  15987. return result;
  15988. };
  15989. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15990. return this.reverse().takeWhile(predicate).reverse();
  15991. };
  15992. LazyWrapper.prototype.toArray = function() {
  15993. return this.take(MAX_ARRAY_LENGTH);
  15994. };
  15995. // Add `LazyWrapper` methods to `lodash.prototype`.
  15996. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15997. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15998. isTaker = /^(?:head|last)$/.test(methodName),
  15999. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  16000. retUnwrapped = isTaker || /^find/.test(methodName);
  16001. if (!lodashFunc) {
  16002. return;
  16003. }
  16004. lodash.prototype[methodName] = function() {
  16005. var value = this.__wrapped__,
  16006. args = isTaker ? [1] : arguments,
  16007. isLazy = value instanceof LazyWrapper,
  16008. iteratee = args[0],
  16009. useLazy = isLazy || isArray(value);
  16010. var interceptor = function(value) {
  16011. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  16012. return (isTaker && chainAll) ? result[0] : result;
  16013. };
  16014. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  16015. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  16016. isLazy = useLazy = false;
  16017. }
  16018. var chainAll = this.__chain__,
  16019. isHybrid = !!this.__actions__.length,
  16020. isUnwrapped = retUnwrapped && !chainAll,
  16021. onlyLazy = isLazy && !isHybrid;
  16022. if (!retUnwrapped && useLazy) {
  16023. value = onlyLazy ? value : new LazyWrapper(this);
  16024. var result = func.apply(value, args);
  16025. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  16026. return new LodashWrapper(result, chainAll);
  16027. }
  16028. if (isUnwrapped && onlyLazy) {
  16029. return func.apply(this, args);
  16030. }
  16031. result = this.thru(interceptor);
  16032. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  16033. };
  16034. });
  16035. // Add `Array` methods to `lodash.prototype`.
  16036. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  16037. var func = arrayProto[methodName],
  16038. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  16039. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  16040. lodash.prototype[methodName] = function() {
  16041. var args = arguments;
  16042. if (retUnwrapped && !this.__chain__) {
  16043. var value = this.value();
  16044. return func.apply(isArray(value) ? value : [], args);
  16045. }
  16046. return this[chainName](function(value) {
  16047. return func.apply(isArray(value) ? value : [], args);
  16048. });
  16049. };
  16050. });
  16051. // Map minified method names to their real names.
  16052. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16053. var lodashFunc = lodash[methodName];
  16054. if (lodashFunc) {
  16055. var key = lodashFunc.name + '';
  16056. if (!hasOwnProperty.call(realNames, key)) {
  16057. realNames[key] = [];
  16058. }
  16059. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  16060. }
  16061. });
  16062. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16063. 'name': 'wrapper',
  16064. 'func': undefined
  16065. }];
  16066. // Add methods to `LazyWrapper`.
  16067. LazyWrapper.prototype.clone = lazyClone;
  16068. LazyWrapper.prototype.reverse = lazyReverse;
  16069. LazyWrapper.prototype.value = lazyValue;
  16070. // Add chain sequence methods to the `lodash` wrapper.
  16071. lodash.prototype.at = wrapperAt;
  16072. lodash.prototype.chain = wrapperChain;
  16073. lodash.prototype.commit = wrapperCommit;
  16074. lodash.prototype.next = wrapperNext;
  16075. lodash.prototype.plant = wrapperPlant;
  16076. lodash.prototype.reverse = wrapperReverse;
  16077. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16078. // Add lazy aliases.
  16079. lodash.prototype.first = lodash.prototype.head;
  16080. if (symIterator) {
  16081. lodash.prototype[symIterator] = wrapperToIterator;
  16082. }
  16083. return lodash;
  16084. });
  16085. /*--------------------------------------------------------------------------*/
  16086. // Export lodash.
  16087. var _ = runInContext();
  16088. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16089. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16090. // Expose Lodash on the global object to prevent errors when Lodash is
  16091. // loaded by a script tag in the presence of an AMD loader.
  16092. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16093. // Use `_.noConflict` to remove Lodash from the global object.
  16094. root._ = _;
  16095. // Define as an anonymous module so, through path mapping, it can be
  16096. // referenced as the "underscore" module.
  16097. define(function() {
  16098. return _;
  16099. });
  16100. }
  16101. // Check for `exports` after `define` in case a build optimizer adds it.
  16102. else if (freeModule) {
  16103. // Export for Node.js.
  16104. (freeModule.exports = _)._ = _;
  16105. // Export for CommonJS support.
  16106. freeExports._ = _;
  16107. }
  16108. else {
  16109. // Export to the global object.
  16110. root._ = _;
  16111. }
  16112. }.call(this));