PageRenderTime 118ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/lodash/lodash.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 15698 lines | 14574 code | 93 blank | 1031 comment | 91 complexity | a08a27a72d5c5e36583e6aef1e72642b MD5 | raw file
Possible License(s): Apache-2.0, JSON, BSD-3-Clause, 0BSD, MIT, CC-BY-SA-3.0
  1. /**
  2. * @license
  3. * Lodash <https://lodash.com/>
  4. * Copyright JS Foundation and other contributors <https://js.foundation/>
  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.5';
  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. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  377. } catch (e) {}
  378. }());
  379. /* Node.js helper references. */
  380. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  381. nodeIsDate = nodeUtil && nodeUtil.isDate,
  382. nodeIsMap = nodeUtil && nodeUtil.isMap,
  383. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  384. nodeIsSet = nodeUtil && nodeUtil.isSet,
  385. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  386. /*--------------------------------------------------------------------------*/
  387. /**
  388. * A faster alternative to `Function#apply`, this function invokes `func`
  389. * with the `this` binding of `thisArg` and the arguments of `args`.
  390. *
  391. * @private
  392. * @param {Function} func The function to invoke.
  393. * @param {*} thisArg The `this` binding of `func`.
  394. * @param {Array} args The arguments to invoke `func` with.
  395. * @returns {*} Returns the result of `func`.
  396. */
  397. function apply(func, thisArg, args) {
  398. switch (args.length) {
  399. case 0: return func.call(thisArg);
  400. case 1: return func.call(thisArg, args[0]);
  401. case 2: return func.call(thisArg, args[0], args[1]);
  402. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  403. }
  404. return func.apply(thisArg, args);
  405. }
  406. /**
  407. * A specialized version of `baseAggregator` for arrays.
  408. *
  409. * @private
  410. * @param {Array} [array] The array to iterate over.
  411. * @param {Function} setter The function to set `accumulator` values.
  412. * @param {Function} iteratee The iteratee to transform keys.
  413. * @param {Object} accumulator The initial aggregated object.
  414. * @returns {Function} Returns `accumulator`.
  415. */
  416. function arrayAggregator(array, setter, iteratee, accumulator) {
  417. var index = -1,
  418. length = array == null ? 0 : array.length;
  419. while (++index < length) {
  420. var value = array[index];
  421. setter(accumulator, value, iteratee(value), array);
  422. }
  423. return accumulator;
  424. }
  425. /**
  426. * A specialized version of `_.forEach` for arrays without support for
  427. * iteratee shorthands.
  428. *
  429. * @private
  430. * @param {Array} [array] The array to iterate over.
  431. * @param {Function} iteratee The function invoked per iteration.
  432. * @returns {Array} Returns `array`.
  433. */
  434. function arrayEach(array, iteratee) {
  435. var index = -1,
  436. length = array == null ? 0 : array.length;
  437. while (++index < length) {
  438. if (iteratee(array[index], index, array) === false) {
  439. break;
  440. }
  441. }
  442. return array;
  443. }
  444. /**
  445. * A specialized version of `_.forEachRight` for arrays without support for
  446. * iteratee shorthands.
  447. *
  448. * @private
  449. * @param {Array} [array] The array to iterate over.
  450. * @param {Function} iteratee The function invoked per iteration.
  451. * @returns {Array} Returns `array`.
  452. */
  453. function arrayEachRight(array, iteratee) {
  454. var length = array == null ? 0 : array.length;
  455. while (length--) {
  456. if (iteratee(array[length], length, array) === false) {
  457. break;
  458. }
  459. }
  460. return array;
  461. }
  462. /**
  463. * A specialized version of `_.every` for arrays without support for
  464. * iteratee shorthands.
  465. *
  466. * @private
  467. * @param {Array} [array] The array to iterate over.
  468. * @param {Function} predicate The function invoked per iteration.
  469. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  470. * else `false`.
  471. */
  472. function arrayEvery(array, predicate) {
  473. var index = -1,
  474. length = array == null ? 0 : array.length;
  475. while (++index < length) {
  476. if (!predicate(array[index], index, array)) {
  477. return false;
  478. }
  479. }
  480. return true;
  481. }
  482. /**
  483. * A specialized version of `_.filter` for arrays without support for
  484. * iteratee shorthands.
  485. *
  486. * @private
  487. * @param {Array} [array] The array to iterate over.
  488. * @param {Function} predicate The function invoked per iteration.
  489. * @returns {Array} Returns the new filtered array.
  490. */
  491. function arrayFilter(array, predicate) {
  492. var index = -1,
  493. length = array == null ? 0 : array.length,
  494. resIndex = 0,
  495. result = [];
  496. while (++index < length) {
  497. var value = array[index];
  498. if (predicate(value, index, array)) {
  499. result[resIndex++] = value;
  500. }
  501. }
  502. return result;
  503. }
  504. /**
  505. * A specialized version of `_.includes` for arrays without support for
  506. * specifying an index to search from.
  507. *
  508. * @private
  509. * @param {Array} [array] The array to inspect.
  510. * @param {*} target The value to search for.
  511. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  512. */
  513. function arrayIncludes(array, value) {
  514. var length = array == null ? 0 : array.length;
  515. return !!length && baseIndexOf(array, value, 0) > -1;
  516. }
  517. /**
  518. * This function is like `arrayIncludes` except that it accepts a comparator.
  519. *
  520. * @private
  521. * @param {Array} [array] The array to inspect.
  522. * @param {*} target The value to search for.
  523. * @param {Function} comparator The comparator invoked per element.
  524. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  525. */
  526. function arrayIncludesWith(array, value, comparator) {
  527. var index = -1,
  528. length = array == null ? 0 : array.length;
  529. while (++index < length) {
  530. if (comparator(value, array[index])) {
  531. return true;
  532. }
  533. }
  534. return false;
  535. }
  536. /**
  537. * A specialized version of `_.map` for arrays without support for iteratee
  538. * shorthands.
  539. *
  540. * @private
  541. * @param {Array} [array] The array to iterate over.
  542. * @param {Function} iteratee The function invoked per iteration.
  543. * @returns {Array} Returns the new mapped array.
  544. */
  545. function arrayMap(array, iteratee) {
  546. var index = -1,
  547. length = array == null ? 0 : array.length,
  548. result = Array(length);
  549. while (++index < length) {
  550. result[index] = iteratee(array[index], index, array);
  551. }
  552. return result;
  553. }
  554. /**
  555. * Appends the elements of `values` to `array`.
  556. *
  557. * @private
  558. * @param {Array} array The array to modify.
  559. * @param {Array} values The values to append.
  560. * @returns {Array} Returns `array`.
  561. */
  562. function arrayPush(array, values) {
  563. var index = -1,
  564. length = values.length,
  565. offset = array.length;
  566. while (++index < length) {
  567. array[offset + index] = values[index];
  568. }
  569. return array;
  570. }
  571. /**
  572. * A specialized version of `_.reduce` for arrays without support for
  573. * iteratee shorthands.
  574. *
  575. * @private
  576. * @param {Array} [array] The array to iterate over.
  577. * @param {Function} iteratee The function invoked per iteration.
  578. * @param {*} [accumulator] The initial value.
  579. * @param {boolean} [initAccum] Specify using the first element of `array` as
  580. * the initial value.
  581. * @returns {*} Returns the accumulated value.
  582. */
  583. function arrayReduce(array, iteratee, accumulator, initAccum) {
  584. var index = -1,
  585. length = array == null ? 0 : array.length;
  586. if (initAccum && length) {
  587. accumulator = array[++index];
  588. }
  589. while (++index < length) {
  590. accumulator = iteratee(accumulator, array[index], index, array);
  591. }
  592. return accumulator;
  593. }
  594. /**
  595. * A specialized version of `_.reduceRight` for arrays without support for
  596. * iteratee shorthands.
  597. *
  598. * @private
  599. * @param {Array} [array] The array to iterate over.
  600. * @param {Function} iteratee The function invoked per iteration.
  601. * @param {*} [accumulator] The initial value.
  602. * @param {boolean} [initAccum] Specify using the last element of `array` as
  603. * the initial value.
  604. * @returns {*} Returns the accumulated value.
  605. */
  606. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  607. var length = array == null ? 0 : array.length;
  608. if (initAccum && length) {
  609. accumulator = array[--length];
  610. }
  611. while (length--) {
  612. accumulator = iteratee(accumulator, array[length], length, array);
  613. }
  614. return accumulator;
  615. }
  616. /**
  617. * A specialized version of `_.some` for arrays without support for iteratee
  618. * shorthands.
  619. *
  620. * @private
  621. * @param {Array} [array] The array to iterate over.
  622. * @param {Function} predicate The function invoked per iteration.
  623. * @returns {boolean} Returns `true` if any element passes the predicate check,
  624. * else `false`.
  625. */
  626. function arraySome(array, predicate) {
  627. var index = -1,
  628. length = array == null ? 0 : array.length;
  629. while (++index < length) {
  630. if (predicate(array[index], index, array)) {
  631. return true;
  632. }
  633. }
  634. return false;
  635. }
  636. /**
  637. * Gets the size of an ASCII `string`.
  638. *
  639. * @private
  640. * @param {string} string The string inspect.
  641. * @returns {number} Returns the string size.
  642. */
  643. var asciiSize = baseProperty('length');
  644. /**
  645. * Converts an ASCII `string` to an array.
  646. *
  647. * @private
  648. * @param {string} string The string to convert.
  649. * @returns {Array} Returns the converted array.
  650. */
  651. function asciiToArray(string) {
  652. return string.split('');
  653. }
  654. /**
  655. * Splits an ASCII `string` into an array of its words.
  656. *
  657. * @private
  658. * @param {string} The string to inspect.
  659. * @returns {Array} Returns the words of `string`.
  660. */
  661. function asciiWords(string) {
  662. return string.match(reAsciiWord) || [];
  663. }
  664. /**
  665. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  666. * without support for iteratee shorthands, which iterates over `collection`
  667. * using `eachFunc`.
  668. *
  669. * @private
  670. * @param {Array|Object} collection The collection to inspect.
  671. * @param {Function} predicate The function invoked per iteration.
  672. * @param {Function} eachFunc The function to iterate over `collection`.
  673. * @returns {*} Returns the found element or its key, else `undefined`.
  674. */
  675. function baseFindKey(collection, predicate, eachFunc) {
  676. var result;
  677. eachFunc(collection, function(value, key, collection) {
  678. if (predicate(value, key, collection)) {
  679. result = key;
  680. return false;
  681. }
  682. });
  683. return result;
  684. }
  685. /**
  686. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  687. * support for iteratee shorthands.
  688. *
  689. * @private
  690. * @param {Array} array The array to inspect.
  691. * @param {Function} predicate The function invoked per iteration.
  692. * @param {number} fromIndex The index to search from.
  693. * @param {boolean} [fromRight] Specify iterating from right to left.
  694. * @returns {number} Returns the index of the matched value, else `-1`.
  695. */
  696. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  697. var length = array.length,
  698. index = fromIndex + (fromRight ? 1 : -1);
  699. while ((fromRight ? index-- : ++index < length)) {
  700. if (predicate(array[index], index, array)) {
  701. return index;
  702. }
  703. }
  704. return -1;
  705. }
  706. /**
  707. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  708. *
  709. * @private
  710. * @param {Array} array The array to inspect.
  711. * @param {*} value The value to search for.
  712. * @param {number} fromIndex The index to search from.
  713. * @returns {number} Returns the index of the matched value, else `-1`.
  714. */
  715. function baseIndexOf(array, value, fromIndex) {
  716. return value === value
  717. ? strictIndexOf(array, value, fromIndex)
  718. : baseFindIndex(array, baseIsNaN, fromIndex);
  719. }
  720. /**
  721. * This function is like `baseIndexOf` except that it accepts a comparator.
  722. *
  723. * @private
  724. * @param {Array} array The array to inspect.
  725. * @param {*} value The value to search for.
  726. * @param {number} fromIndex The index to search from.
  727. * @param {Function} comparator The comparator invoked per element.
  728. * @returns {number} Returns the index of the matched value, else `-1`.
  729. */
  730. function baseIndexOfWith(array, value, fromIndex, comparator) {
  731. var index = fromIndex - 1,
  732. length = array.length;
  733. while (++index < length) {
  734. if (comparator(array[index], value)) {
  735. return index;
  736. }
  737. }
  738. return -1;
  739. }
  740. /**
  741. * The base implementation of `_.isNaN` without support for number objects.
  742. *
  743. * @private
  744. * @param {*} value The value to check.
  745. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  746. */
  747. function baseIsNaN(value) {
  748. return value !== value;
  749. }
  750. /**
  751. * The base implementation of `_.mean` and `_.meanBy` without support for
  752. * iteratee shorthands.
  753. *
  754. * @private
  755. * @param {Array} array The array to iterate over.
  756. * @param {Function} iteratee The function invoked per iteration.
  757. * @returns {number} Returns the mean.
  758. */
  759. function baseMean(array, iteratee) {
  760. var length = array == null ? 0 : array.length;
  761. return length ? (baseSum(array, iteratee) / length) : NAN;
  762. }
  763. /**
  764. * The base implementation of `_.property` without support for deep paths.
  765. *
  766. * @private
  767. * @param {string} key The key of the property to get.
  768. * @returns {Function} Returns the new accessor function.
  769. */
  770. function baseProperty(key) {
  771. return function(object) {
  772. return object == null ? undefined : object[key];
  773. };
  774. }
  775. /**
  776. * The base implementation of `_.propertyOf` without support for deep paths.
  777. *
  778. * @private
  779. * @param {Object} object The object to query.
  780. * @returns {Function} Returns the new accessor function.
  781. */
  782. function basePropertyOf(object) {
  783. return function(key) {
  784. return object == null ? undefined : object[key];
  785. };
  786. }
  787. /**
  788. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  789. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  790. *
  791. * @private
  792. * @param {Array|Object} collection The collection to iterate over.
  793. * @param {Function} iteratee The function invoked per iteration.
  794. * @param {*} accumulator The initial value.
  795. * @param {boolean} initAccum Specify using the first or last element of
  796. * `collection` as the initial value.
  797. * @param {Function} eachFunc The function to iterate over `collection`.
  798. * @returns {*} Returns the accumulated value.
  799. */
  800. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  801. eachFunc(collection, function(value, index, collection) {
  802. accumulator = initAccum
  803. ? (initAccum = false, value)
  804. : iteratee(accumulator, value, index, collection);
  805. });
  806. return accumulator;
  807. }
  808. /**
  809. * The base implementation of `_.sortBy` which uses `comparer` to define the
  810. * sort order of `array` and replaces criteria objects with their corresponding
  811. * values.
  812. *
  813. * @private
  814. * @param {Array} array The array to sort.
  815. * @param {Function} comparer The function to define sort order.
  816. * @returns {Array} Returns `array`.
  817. */
  818. function baseSortBy(array, comparer) {
  819. var length = array.length;
  820. array.sort(comparer);
  821. while (length--) {
  822. array[length] = array[length].value;
  823. }
  824. return array;
  825. }
  826. /**
  827. * The base implementation of `_.sum` and `_.sumBy` without support for
  828. * iteratee shorthands.
  829. *
  830. * @private
  831. * @param {Array} array The array to iterate over.
  832. * @param {Function} iteratee The function invoked per iteration.
  833. * @returns {number} Returns the sum.
  834. */
  835. function baseSum(array, iteratee) {
  836. var result,
  837. index = -1,
  838. length = array.length;
  839. while (++index < length) {
  840. var current = iteratee(array[index]);
  841. if (current !== undefined) {
  842. result = result === undefined ? current : (result + current);
  843. }
  844. }
  845. return result;
  846. }
  847. /**
  848. * The base implementation of `_.times` without support for iteratee shorthands
  849. * or max array length checks.
  850. *
  851. * @private
  852. * @param {number} n The number of times to invoke `iteratee`.
  853. * @param {Function} iteratee The function invoked per iteration.
  854. * @returns {Array} Returns the array of results.
  855. */
  856. function baseTimes(n, iteratee) {
  857. var index = -1,
  858. result = Array(n);
  859. while (++index < n) {
  860. result[index] = iteratee(index);
  861. }
  862. return result;
  863. }
  864. /**
  865. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  866. * of key-value pairs for `object` corresponding to the property names of `props`.
  867. *
  868. * @private
  869. * @param {Object} object The object to query.
  870. * @param {Array} props The property names to get values for.
  871. * @returns {Object} Returns the key-value pairs.
  872. */
  873. function baseToPairs(object, props) {
  874. return arrayMap(props, function(key) {
  875. return [key, object[key]];
  876. });
  877. }
  878. /**
  879. * The base implementation of `_.unary` without support for storing metadata.
  880. *
  881. * @private
  882. * @param {Function} func The function to cap arguments for.
  883. * @returns {Function} Returns the new capped function.
  884. */
  885. function baseUnary(func) {
  886. return function(value) {
  887. return func(value);
  888. };
  889. }
  890. /**
  891. * The base implementation of `_.values` and `_.valuesIn` which creates an
  892. * array of `object` property values corresponding to the property names
  893. * of `props`.
  894. *
  895. * @private
  896. * @param {Object} object The object to query.
  897. * @param {Array} props The property names to get values for.
  898. * @returns {Object} Returns the array of property values.
  899. */
  900. function baseValues(object, props) {
  901. return arrayMap(props, function(key) {
  902. return object[key];
  903. });
  904. }
  905. /**
  906. * Checks if a `cache` value for `key` exists.
  907. *
  908. * @private
  909. * @param {Object} cache The cache to query.
  910. * @param {string} key The key of the entry to check.
  911. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  912. */
  913. function cacheHas(cache, key) {
  914. return cache.has(key);
  915. }
  916. /**
  917. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  918. * that is not found in the character symbols.
  919. *
  920. * @private
  921. * @param {Array} strSymbols The string symbols to inspect.
  922. * @param {Array} chrSymbols The character symbols to find.
  923. * @returns {number} Returns the index of the first unmatched string symbol.
  924. */
  925. function charsStartIndex(strSymbols, chrSymbols) {
  926. var index = -1,
  927. length = strSymbols.length;
  928. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  929. return index;
  930. }
  931. /**
  932. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  933. * that is not found in the character symbols.
  934. *
  935. * @private
  936. * @param {Array} strSymbols The string symbols to inspect.
  937. * @param {Array} chrSymbols The character symbols to find.
  938. * @returns {number} Returns the index of the last unmatched string symbol.
  939. */
  940. function charsEndIndex(strSymbols, chrSymbols) {
  941. var index = strSymbols.length;
  942. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  943. return index;
  944. }
  945. /**
  946. * Gets the number of `placeholder` occurrences in `array`.
  947. *
  948. * @private
  949. * @param {Array} array The array to inspect.
  950. * @param {*} placeholder The placeholder to search for.
  951. * @returns {number} Returns the placeholder count.
  952. */
  953. function countHolders(array, placeholder) {
  954. var length = array.length,
  955. result = 0;
  956. while (length--) {
  957. if (array[length] === placeholder) {
  958. ++result;
  959. }
  960. }
  961. return result;
  962. }
  963. /**
  964. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  965. * letters to basic Latin letters.
  966. *
  967. * @private
  968. * @param {string} letter The matched letter to deburr.
  969. * @returns {string} Returns the deburred letter.
  970. */
  971. var deburrLetter = basePropertyOf(deburredLetters);
  972. /**
  973. * Used by `_.escape` to convert characters to HTML entities.
  974. *
  975. * @private
  976. * @param {string} chr The matched character to escape.
  977. * @returns {string} Returns the escaped character.
  978. */
  979. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  980. /**
  981. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  982. *
  983. * @private
  984. * @param {string} chr The matched character to escape.
  985. * @returns {string} Returns the escaped character.
  986. */
  987. function escapeStringChar(chr) {
  988. return '\\' + stringEscapes[chr];
  989. }
  990. /**
  991. * Gets the value at `key` of `object`.
  992. *
  993. * @private
  994. * @param {Object} [object] The object to query.
  995. * @param {string} key The key of the property to get.
  996. * @returns {*} Returns the property value.
  997. */
  998. function getValue(object, key) {
  999. return object == null ? undefined : object[key];
  1000. }
  1001. /**
  1002. * Checks if `string` contains Unicode symbols.
  1003. *
  1004. * @private
  1005. * @param {string} string The string to inspect.
  1006. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1007. */
  1008. function hasUnicode(string) {
  1009. return reHasUnicode.test(string);
  1010. }
  1011. /**
  1012. * Checks if `string` contains a word composed of Unicode symbols.
  1013. *
  1014. * @private
  1015. * @param {string} string The string to inspect.
  1016. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1017. */
  1018. function hasUnicodeWord(string) {
  1019. return reHasUnicodeWord.test(string);
  1020. }
  1021. /**
  1022. * Converts `iterator` to an array.
  1023. *
  1024. * @private
  1025. * @param {Object} iterator The iterator to convert.
  1026. * @returns {Array} Returns the converted array.
  1027. */
  1028. function iteratorToArray(iterator) {
  1029. var data,
  1030. result = [];
  1031. while (!(data = iterator.next()).done) {
  1032. result.push(data.value);
  1033. }
  1034. return result;
  1035. }
  1036. /**
  1037. * Converts `map` to its key-value pairs.
  1038. *
  1039. * @private
  1040. * @param {Object} map The map to convert.
  1041. * @returns {Array} Returns the key-value pairs.
  1042. */
  1043. function mapToArray(map) {
  1044. var index = -1,
  1045. result = Array(map.size);
  1046. map.forEach(function(value, key) {
  1047. result[++index] = [key, value];
  1048. });
  1049. return result;
  1050. }
  1051. /**
  1052. * Creates a unary function that invokes `func` with its argument transformed.
  1053. *
  1054. * @private
  1055. * @param {Function} func The function to wrap.
  1056. * @param {Function} transform The argument transform.
  1057. * @returns {Function} Returns the new function.
  1058. */
  1059. function overArg(func, transform) {
  1060. return function(arg) {
  1061. return func(transform(arg));
  1062. };
  1063. }
  1064. /**
  1065. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1066. * and returns an array of their indexes.
  1067. *
  1068. * @private
  1069. * @param {Array} array The array to modify.
  1070. * @param {*} placeholder The placeholder to replace.
  1071. * @returns {Array} Returns the new array of placeholder indexes.
  1072. */
  1073. function replaceHolders(array, placeholder) {
  1074. var index = -1,
  1075. length = array.length,
  1076. resIndex = 0,
  1077. result = [];
  1078. while (++index < length) {
  1079. var value = array[index];
  1080. if (value === placeholder || value === PLACEHOLDER) {
  1081. array[index] = PLACEHOLDER;
  1082. result[resIndex++] = index;
  1083. }
  1084. }
  1085. return result;
  1086. }
  1087. /**
  1088. * Gets the value at `key`, unless `key` is "__proto__".
  1089. *
  1090. * @private
  1091. * @param {Object} object The object to query.
  1092. * @param {string} key The key of the property to get.
  1093. * @returns {*} Returns the property value.
  1094. */
  1095. function safeGet(object, key) {
  1096. return key == '__proto__'
  1097. ? undefined
  1098. : object[key];
  1099. }
  1100. /**
  1101. * Converts `set` to an array of its values.
  1102. *
  1103. * @private
  1104. * @param {Object} set The set to convert.
  1105. * @returns {Array} Returns the values.
  1106. */
  1107. function setToArray(set) {
  1108. var index = -1,
  1109. result = Array(set.size);
  1110. set.forEach(function(value) {
  1111. result[++index] = value;
  1112. });
  1113. return result;
  1114. }
  1115. /**
  1116. * Converts `set` to its value-value pairs.
  1117. *
  1118. * @private
  1119. * @param {Object} set The set to convert.
  1120. * @returns {Array} Returns the value-value pairs.
  1121. */
  1122. function setToPairs(set) {
  1123. var index = -1,
  1124. result = Array(set.size);
  1125. set.forEach(function(value) {
  1126. result[++index] = [value, value];
  1127. });
  1128. return result;
  1129. }
  1130. /**
  1131. * A specialized version of `_.indexOf` which performs strict equality
  1132. * comparisons of values, i.e. `===`.
  1133. *
  1134. * @private
  1135. * @param {Array} array The array to inspect.
  1136. * @param {*} value The value to search for.
  1137. * @param {number} fromIndex The index to search from.
  1138. * @returns {number} Returns the index of the matched value, else `-1`.
  1139. */
  1140. function strictIndexOf(array, value, fromIndex) {
  1141. var index = fromIndex - 1,
  1142. length = array.length;
  1143. while (++index < length) {
  1144. if (array[index] === value) {
  1145. return index;
  1146. }
  1147. }
  1148. return -1;
  1149. }
  1150. /**
  1151. * A specialized version of `_.lastIndexOf` which performs strict equality
  1152. * comparisons of values, i.e. `===`.
  1153. *
  1154. * @private
  1155. * @param {Array} array The array to inspect.
  1156. * @param {*} value The value to search for.
  1157. * @param {number} fromIndex The index to search from.
  1158. * @returns {number} Returns the index of the matched value, else `-1`.
  1159. */
  1160. function strictLastIndexOf(array, value, fromIndex) {
  1161. var index = fromIndex + 1;
  1162. while (index--) {
  1163. if (array[index] === value) {
  1164. return index;
  1165. }
  1166. }
  1167. return index;
  1168. }
  1169. /**
  1170. * Gets the number of symbols in `string`.
  1171. *
  1172. * @private
  1173. * @param {string} string The string to inspect.
  1174. * @returns {number} Returns the string size.
  1175. */
  1176. function stringSize(string) {
  1177. return hasUnicode(string)
  1178. ? unicodeSize(string)
  1179. : asciiSize(string);
  1180. }
  1181. /**
  1182. * Converts `string` to an array.
  1183. *
  1184. * @private
  1185. * @param {string} string The string to convert.
  1186. * @returns {Array} Returns the converted array.
  1187. */
  1188. function stringToArray(string) {
  1189. return hasUnicode(string)
  1190. ? unicodeToArray(string)
  1191. : asciiToArray(string);
  1192. }
  1193. /**
  1194. * Used by `_.unescape` to convert HTML entities to characters.
  1195. *
  1196. * @private
  1197. * @param {string} chr The matched character to unescape.
  1198. * @returns {string} Returns the unescaped character.
  1199. */
  1200. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1201. /**
  1202. * Gets the size of a Unicode `string`.
  1203. *
  1204. * @private
  1205. * @param {string} string The string inspect.
  1206. * @returns {number} Returns the string size.
  1207. */
  1208. function unicodeSize(string) {
  1209. var result = reUnicode.lastIndex = 0;
  1210. while (reUnicode.test(string)) {
  1211. ++result;
  1212. }
  1213. return result;
  1214. }
  1215. /**
  1216. * Converts a Unicode `string` to an array.
  1217. *
  1218. * @private
  1219. * @param {string} string The string to convert.
  1220. * @returns {Array} Returns the converted array.
  1221. */
  1222. function unicodeToArray(string) {
  1223. return string.match(reUnicode) || [];
  1224. }
  1225. /**
  1226. * Splits a Unicode `string` into an array of its words.
  1227. *
  1228. * @private
  1229. * @param {string} The string to inspect.
  1230. * @returns {Array} Returns the words of `string`.
  1231. */
  1232. function unicodeWords(string) {
  1233. return string.match(reUnicodeWord) || [];
  1234. }
  1235. /*--------------------------------------------------------------------------*/
  1236. /**
  1237. * Create a new pristine `lodash` function using the `context` object.
  1238. *
  1239. * @static
  1240. * @memberOf _
  1241. * @since 1.1.0
  1242. * @category Util
  1243. * @param {Object} [context=root] The context object.
  1244. * @returns {Function} Returns a new `lodash` function.
  1245. * @example
  1246. *
  1247. * _.mixin({ 'foo': _.constant('foo') });
  1248. *
  1249. * var lodash = _.runInContext();
  1250. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1251. *
  1252. * _.isFunction(_.foo);
  1253. * // => true
  1254. * _.isFunction(_.bar);
  1255. * // => false
  1256. *
  1257. * lodash.isFunction(lodash.foo);
  1258. * // => false
  1259. * lodash.isFunction(lodash.bar);
  1260. * // => true
  1261. *
  1262. * // Create a suped-up `defer` in Node.js.
  1263. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1264. */
  1265. var runInContext = (function runInContext(context) {
  1266. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1267. /** Built-in constructor references. */
  1268. var Array = context.Array,
  1269. Date = context.Date,
  1270. Error = context.Error,
  1271. Function = context.Function,
  1272. Math = context.Math,
  1273. Object = context.Object,
  1274. RegExp = context.RegExp,
  1275. String = context.String,
  1276. TypeError = context.TypeError;
  1277. /** Used for built-in method references. */
  1278. var arrayProto = Array.prototype,
  1279. funcProto = Function.prototype,
  1280. objectProto = Object.prototype;
  1281. /** Used to detect overreaching core-js shims. */
  1282. var coreJsData = context['__core-js_shared__'];
  1283. /** Used to resolve the decompiled source of functions. */
  1284. var funcToString = funcProto.toString;
  1285. /** Used to check objects for own properties. */
  1286. var hasOwnProperty = objectProto.hasOwnProperty;
  1287. /** Used to generate unique IDs. */
  1288. var idCounter = 0;
  1289. /** Used to detect methods masquerading as native. */
  1290. var maskSrcKey = (function() {
  1291. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1292. return uid ? ('Symbol(src)_1.' + uid) : '';
  1293. }());
  1294. /**
  1295. * Used to resolve the
  1296. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1297. * of values.
  1298. */
  1299. var nativeObjectToString = objectProto.toString;
  1300. /** Used to infer the `Object` constructor. */
  1301. var objectCtorString = funcToString.call(Object);
  1302. /** Used to restore the original `_` reference in `_.noConflict`. */
  1303. var oldDash = root._;
  1304. /** Used to detect if a method is native. */
  1305. var reIsNative = RegExp('^' +
  1306. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1307. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1308. );
  1309. /** Built-in value references. */
  1310. var Buffer = moduleExports ? context.Buffer : undefined,
  1311. Symbol = context.Symbol,
  1312. Uint8Array = context.Uint8Array,
  1313. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1314. getPrototype = overArg(Object.getPrototypeOf, Object),
  1315. objectCreate = Object.create,
  1316. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1317. splice = arrayProto.splice,
  1318. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1319. symIterator = Symbol ? Symbol.iterator : undefined,
  1320. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1321. var defineProperty = (function() {
  1322. try {
  1323. var func = getNative(Object, 'defineProperty');
  1324. func({}, '', {});
  1325. return func;
  1326. } catch (e) {}
  1327. }());
  1328. /** Mocked built-ins. */
  1329. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1330. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1331. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1332. /* Built-in method references for those with the same name as other `lodash` methods. */
  1333. var nativeCeil = Math.ceil,
  1334. nativeFloor = Math.floor,
  1335. nativeGetSymbols = Object.getOwnPropertySymbols,
  1336. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1337. nativeIsFinite = context.isFinite,
  1338. nativeJoin = arrayProto.join,
  1339. nativeKeys = overArg(Object.keys, Object),
  1340. nativeMax = Math.max,
  1341. nativeMin = Math.min,
  1342. nativeNow = Date.now,
  1343. nativeParseInt = context.parseInt,
  1344. nativeRandom = Math.random,
  1345. nativeReverse = arrayProto.reverse;
  1346. /* Built-in method references that are verified to be native. */
  1347. var DataView = getNative(context, 'DataView'),
  1348. Map = getNative(context, 'Map'),
  1349. Promise = getNative(context, 'Promise'),
  1350. Set = getNative(context, 'Set'),
  1351. WeakMap = getNative(context, 'WeakMap'),
  1352. nativeCreate = getNative(Object, 'create');
  1353. /** Used to store function metadata. */
  1354. var metaMap = WeakMap && new WeakMap;
  1355. /** Used to lookup unminified function names. */
  1356. var realNames = {};
  1357. /** Used to detect maps, sets, and weakmaps. */
  1358. var dataViewCtorString = toSource(DataView),
  1359. mapCtorString = toSource(Map),
  1360. promiseCtorString = toSource(Promise),
  1361. setCtorString = toSource(Set),
  1362. weakMapCtorString = toSource(WeakMap);
  1363. /** Used to convert symbols to primitives and strings. */
  1364. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1365. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1366. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1367. /*------------------------------------------------------------------------*/
  1368. /**
  1369. * Creates a `lodash` object which wraps `value` to enable implicit method
  1370. * chain sequences. Methods that operate on and return arrays, collections,
  1371. * and functions can be chained together. Methods that retrieve a single value
  1372. * or may return a primitive value will automatically end the chain sequence
  1373. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1374. * with `_#value`.
  1375. *
  1376. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1377. * enabled using `_.chain`.
  1378. *
  1379. * The execution of chained methods is lazy, that is, it's deferred until
  1380. * `_#value` is implicitly or explicitly called.
  1381. *
  1382. * Lazy evaluation allows several methods to support shortcut fusion.
  1383. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1384. * the creation of intermediate arrays and can greatly reduce the number of
  1385. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1386. * fusion if the section is applied to an array and iteratees accept only
  1387. * one argument. The heuristic for whether a section qualifies for shortcut
  1388. * fusion is subject to change.
  1389. *
  1390. * Chaining is supported in custom builds as long as the `_#value` method is
  1391. * directly or indirectly included in the build.
  1392. *
  1393. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1394. *
  1395. * The wrapper `Array` methods are:
  1396. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1397. *
  1398. * The wrapper `String` methods are:
  1399. * `replace` and `split`
  1400. *
  1401. * The wrapper methods that support shortcut fusion are:
  1402. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1403. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1404. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1405. *
  1406. * The chainable wrapper methods are:
  1407. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1408. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1409. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1410. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1411. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1412. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1413. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1414. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1415. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1416. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1417. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1418. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1419. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1420. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1421. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1422. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1423. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1424. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1425. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1426. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1427. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1428. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1429. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1430. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1431. *
  1432. * The wrapper methods that are **not** chainable by default are:
  1433. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1434. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1435. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1436. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1437. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1438. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1439. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1440. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1441. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1442. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1443. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1444. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1445. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1446. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1447. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1448. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1449. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1450. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1451. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1452. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1453. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1454. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1455. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1456. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1457. * `upperFirst`, `value`, and `words`
  1458. *
  1459. * @name _
  1460. * @constructor
  1461. * @category Seq
  1462. * @param {*} value The value to wrap in a `lodash` instance.
  1463. * @returns {Object} Returns the new `lodash` wrapper instance.
  1464. * @example
  1465. *
  1466. * function square(n) {
  1467. * return n * n;
  1468. * }
  1469. *
  1470. * var wrapped = _([1, 2, 3]);
  1471. *
  1472. * // Returns an unwrapped value.
  1473. * wrapped.reduce(_.add);
  1474. * // => 6
  1475. *
  1476. * // Returns a wrapped value.
  1477. * var squares = wrapped.map(square);
  1478. *
  1479. * _.isArray(squares);
  1480. * // => false
  1481. *
  1482. * _.isArray(squares.value());
  1483. * // => true
  1484. */
  1485. function lodash(value) {
  1486. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1487. if (value instanceof LodashWrapper) {
  1488. return value;
  1489. }
  1490. if (hasOwnProperty.call(value, '__wrapped__')) {
  1491. return wrapperClone(value);
  1492. }
  1493. }
  1494. return new LodashWrapper(value);
  1495. }
  1496. /**
  1497. * The base implementation of `_.create` without support for assigning
  1498. * properties to the created object.
  1499. *
  1500. * @private
  1501. * @param {Object} proto The object to inherit from.
  1502. * @returns {Object} Returns the new object.
  1503. */
  1504. var baseCreate = (function() {
  1505. function object() {}
  1506. return function(proto) {
  1507. if (!isObject(proto)) {
  1508. return {};
  1509. }
  1510. if (objectCreate) {
  1511. return objectCreate(proto);
  1512. }
  1513. object.prototype = proto;
  1514. var result = new object;
  1515. object.prototype = undefined;
  1516. return result;
  1517. };
  1518. }());
  1519. /**
  1520. * The function whose prototype chain sequence wrappers inherit from.
  1521. *
  1522. * @private
  1523. */
  1524. function baseLodash() {
  1525. // No operation performed.
  1526. }
  1527. /**
  1528. * The base constructor for creating `lodash` wrapper objects.
  1529. *
  1530. * @private
  1531. * @param {*} value The value to wrap.
  1532. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1533. */
  1534. function LodashWrapper(value, chainAll) {
  1535. this.__wrapped__ = value;
  1536. this.__actions__ = [];
  1537. this.__chain__ = !!chainAll;
  1538. this.__index__ = 0;
  1539. this.__values__ = undefined;
  1540. }
  1541. /**
  1542. * By default, the template delimiters used by lodash are like those in
  1543. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1544. * following template settings to use alternative delimiters.
  1545. *
  1546. * @static
  1547. * @memberOf _
  1548. * @type {Object}
  1549. */
  1550. lodash.templateSettings = {
  1551. /**
  1552. * Used to detect `data` property values to be HTML-escaped.
  1553. *
  1554. * @memberOf _.templateSettings
  1555. * @type {RegExp}
  1556. */
  1557. 'escape': reEscape,
  1558. /**
  1559. * Used to detect code to be evaluated.
  1560. *
  1561. * @memberOf _.templateSettings
  1562. * @type {RegExp}
  1563. */
  1564. 'evaluate': reEvaluate,
  1565. /**
  1566. * Used to detect `data` property values to inject.
  1567. *
  1568. * @memberOf _.templateSettings
  1569. * @type {RegExp}
  1570. */
  1571. 'interpolate': reInterpolate,
  1572. /**
  1573. * Used to reference the data object in the template text.
  1574. *
  1575. * @memberOf _.templateSettings
  1576. * @type {string}
  1577. */
  1578. 'variable': '',
  1579. /**
  1580. * Used to import variables into the compiled template.
  1581. *
  1582. * @memberOf _.templateSettings
  1583. * @type {Object}
  1584. */
  1585. 'imports': {
  1586. /**
  1587. * A reference to the `lodash` function.
  1588. *
  1589. * @memberOf _.templateSettings.imports
  1590. * @type {Function}
  1591. */
  1592. '_': lodash
  1593. }
  1594. };
  1595. // Ensure wrappers are instances of `baseLodash`.
  1596. lodash.prototype = baseLodash.prototype;
  1597. lodash.prototype.constructor = lodash;
  1598. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1599. LodashWrapper.prototype.constructor = LodashWrapper;
  1600. /*------------------------------------------------------------------------*/
  1601. /**
  1602. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1603. *
  1604. * @private
  1605. * @constructor
  1606. * @param {*} value The value to wrap.
  1607. */
  1608. function LazyWrapper(value) {
  1609. this.__wrapped__ = value;
  1610. this.__actions__ = [];
  1611. this.__dir__ = 1;
  1612. this.__filtered__ = false;
  1613. this.__iteratees__ = [];
  1614. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1615. this.__views__ = [];
  1616. }
  1617. /**
  1618. * Creates a clone of the lazy wrapper object.
  1619. *
  1620. * @private
  1621. * @name clone
  1622. * @memberOf LazyWrapper
  1623. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1624. */
  1625. function lazyClone() {
  1626. var result = new LazyWrapper(this.__wrapped__);
  1627. result.__actions__ = copyArray(this.__actions__);
  1628. result.__dir__ = this.__dir__;
  1629. result.__filtered__ = this.__filtered__;
  1630. result.__iteratees__ = copyArray(this.__iteratees__);
  1631. result.__takeCount__ = this.__takeCount__;
  1632. result.__views__ = copyArray(this.__views__);
  1633. return result;
  1634. }
  1635. /**
  1636. * Reverses the direction of lazy iteration.
  1637. *
  1638. * @private
  1639. * @name reverse
  1640. * @memberOf LazyWrapper
  1641. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1642. */
  1643. function lazyReverse() {
  1644. if (this.__filtered__) {
  1645. var result = new LazyWrapper(this);
  1646. result.__dir__ = -1;
  1647. result.__filtered__ = true;
  1648. } else {
  1649. result = this.clone();
  1650. result.__dir__ *= -1;
  1651. }
  1652. return result;
  1653. }
  1654. /**
  1655. * Extracts the unwrapped value from its lazy wrapper.
  1656. *
  1657. * @private
  1658. * @name value
  1659. * @memberOf LazyWrapper
  1660. * @returns {*} Returns the unwrapped value.
  1661. */
  1662. function lazyValue() {
  1663. var array = this.__wrapped__.value(),
  1664. dir = this.__dir__,
  1665. isArr = isArray(array),
  1666. isRight = dir < 0,
  1667. arrLength = isArr ? array.length : 0,
  1668. view = getView(0, arrLength, this.__views__),
  1669. start = view.start,
  1670. end = view.end,
  1671. length = end - start,
  1672. index = isRight ? end : (start - 1),
  1673. iteratees = this.__iteratees__,
  1674. iterLength = iteratees.length,
  1675. resIndex = 0,
  1676. takeCount = nativeMin(length, this.__takeCount__);
  1677. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1678. return baseWrapperValue(array, this.__actions__);
  1679. }
  1680. var result = [];
  1681. outer:
  1682. while (length-- && resIndex < takeCount) {
  1683. index += dir;
  1684. var iterIndex = -1,
  1685. value = array[index];
  1686. while (++iterIndex < iterLength) {
  1687. var data = iteratees[iterIndex],
  1688. iteratee = data.iteratee,
  1689. type = data.type,
  1690. computed = iteratee(value);
  1691. if (type == LAZY_MAP_FLAG) {
  1692. value = computed;
  1693. } else if (!computed) {
  1694. if (type == LAZY_FILTER_FLAG) {
  1695. continue outer;
  1696. } else {
  1697. break outer;
  1698. }
  1699. }
  1700. }
  1701. result[resIndex++] = value;
  1702. }
  1703. return result;
  1704. }
  1705. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1706. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1707. LazyWrapper.prototype.constructor = LazyWrapper;
  1708. /*------------------------------------------------------------------------*/
  1709. /**
  1710. * Creates a hash object.
  1711. *
  1712. * @private
  1713. * @constructor
  1714. * @param {Array} [entries] The key-value pairs to cache.
  1715. */
  1716. function Hash(entries) {
  1717. var index = -1,
  1718. length = entries == null ? 0 : entries.length;
  1719. this.clear();
  1720. while (++index < length) {
  1721. var entry = entries[index];
  1722. this.set(entry[0], entry[1]);
  1723. }
  1724. }
  1725. /**
  1726. * Removes all key-value entries from the hash.
  1727. *
  1728. * @private
  1729. * @name clear
  1730. * @memberOf Hash
  1731. */
  1732. function hashClear() {
  1733. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1734. this.size = 0;
  1735. }
  1736. /**
  1737. * Removes `key` and its value from the hash.
  1738. *
  1739. * @private
  1740. * @name delete
  1741. * @memberOf Hash
  1742. * @param {Object} hash The hash to modify.
  1743. * @param {string} key The key of the value to remove.
  1744. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1745. */
  1746. function hashDelete(key) {
  1747. var result = this.has(key) && delete this.__data__[key];
  1748. this.size -= result ? 1 : 0;
  1749. return result;
  1750. }
  1751. /**
  1752. * Gets the hash value for `key`.
  1753. *
  1754. * @private
  1755. * @name get
  1756. * @memberOf Hash
  1757. * @param {string} key The key of the value to get.
  1758. * @returns {*} Returns the entry value.
  1759. */
  1760. function hashGet(key) {
  1761. var data = this.__data__;
  1762. if (nativeCreate) {
  1763. var result = data[key];
  1764. return result === HASH_UNDEFINED ? undefined : result;
  1765. }
  1766. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1767. }
  1768. /**
  1769. * Checks if a hash value for `key` exists.
  1770. *
  1771. * @private
  1772. * @name has
  1773. * @memberOf Hash
  1774. * @param {string} key The key of the entry to check.
  1775. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1776. */
  1777. function hashHas(key) {
  1778. var data = this.__data__;
  1779. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1780. }
  1781. /**
  1782. * Sets the hash `key` to `value`.
  1783. *
  1784. * @private
  1785. * @name set
  1786. * @memberOf Hash
  1787. * @param {string} key The key of the value to set.
  1788. * @param {*} value The value to set.
  1789. * @returns {Object} Returns the hash instance.
  1790. */
  1791. function hashSet(key, value) {
  1792. var data = this.__data__;
  1793. this.size += this.has(key) ? 0 : 1;
  1794. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1795. return this;
  1796. }
  1797. // Add methods to `Hash`.
  1798. Hash.prototype.clear = hashClear;
  1799. Hash.prototype['delete'] = hashDelete;
  1800. Hash.prototype.get = hashGet;
  1801. Hash.prototype.has = hashHas;
  1802. Hash.prototype.set = hashSet;
  1803. /*------------------------------------------------------------------------*/
  1804. /**
  1805. * Creates an list cache object.
  1806. *
  1807. * @private
  1808. * @constructor
  1809. * @param {Array} [entries] The key-value pairs to cache.
  1810. */
  1811. function ListCache(entries) {
  1812. var index = -1,
  1813. length = entries == null ? 0 : entries.length;
  1814. this.clear();
  1815. while (++index < length) {
  1816. var entry = entries[index];
  1817. this.set(entry[0], entry[1]);
  1818. }
  1819. }
  1820. /**
  1821. * Removes all key-value entries from the list cache.
  1822. *
  1823. * @private
  1824. * @name clear
  1825. * @memberOf ListCache
  1826. */
  1827. function listCacheClear() {
  1828. this.__data__ = [];
  1829. this.size = 0;
  1830. }
  1831. /**
  1832. * Removes `key` and its value from the list cache.
  1833. *
  1834. * @private
  1835. * @name delete
  1836. * @memberOf ListCache
  1837. * @param {string} key The key of the value to remove.
  1838. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1839. */
  1840. function listCacheDelete(key) {
  1841. var data = this.__data__,
  1842. index = assocIndexOf(data, key);
  1843. if (index < 0) {
  1844. return false;
  1845. }
  1846. var lastIndex = data.length - 1;
  1847. if (index == lastIndex) {
  1848. data.pop();
  1849. } else {
  1850. splice.call(data, index, 1);
  1851. }
  1852. --this.size;
  1853. return true;
  1854. }
  1855. /**
  1856. * Gets the list cache value for `key`.
  1857. *
  1858. * @private
  1859. * @name get
  1860. * @memberOf ListCache
  1861. * @param {string} key The key of the value to get.
  1862. * @returns {*} Returns the entry value.
  1863. */
  1864. function listCacheGet(key) {
  1865. var data = this.__data__,
  1866. index = assocIndexOf(data, key);
  1867. return index < 0 ? undefined : data[index][1];
  1868. }
  1869. /**
  1870. * Checks if a list cache value for `key` exists.
  1871. *
  1872. * @private
  1873. * @name has
  1874. * @memberOf ListCache
  1875. * @param {string} key The key of the entry to check.
  1876. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1877. */
  1878. function listCacheHas(key) {
  1879. return assocIndexOf(this.__data__, key) > -1;
  1880. }
  1881. /**
  1882. * Sets the list cache `key` to `value`.
  1883. *
  1884. * @private
  1885. * @name set
  1886. * @memberOf ListCache
  1887. * @param {string} key The key of the value to set.
  1888. * @param {*} value The value to set.
  1889. * @returns {Object} Returns the list cache instance.
  1890. */
  1891. function listCacheSet(key, value) {
  1892. var data = this.__data__,
  1893. index = assocIndexOf(data, key);
  1894. if (index < 0) {
  1895. ++this.size;
  1896. data.push([key, value]);
  1897. } else {
  1898. data[index][1] = value;
  1899. }
  1900. return this;
  1901. }
  1902. // Add methods to `ListCache`.
  1903. ListCache.prototype.clear = listCacheClear;
  1904. ListCache.prototype['delete'] = listCacheDelete;
  1905. ListCache.prototype.get = listCacheGet;
  1906. ListCache.prototype.has = listCacheHas;
  1907. ListCache.prototype.set = listCacheSet;
  1908. /*------------------------------------------------------------------------*/
  1909. /**
  1910. * Creates a map cache object to store key-value pairs.
  1911. *
  1912. * @private
  1913. * @constructor
  1914. * @param {Array} [entries] The key-value pairs to cache.
  1915. */
  1916. function MapCache(entries) {
  1917. var index = -1,
  1918. length = entries == null ? 0 : entries.length;
  1919. this.clear();
  1920. while (++index < length) {
  1921. var entry = entries[index];
  1922. this.set(entry[0], entry[1]);
  1923. }
  1924. }
  1925. /**
  1926. * Removes all key-value entries from the map.
  1927. *
  1928. * @private
  1929. * @name clear
  1930. * @memberOf MapCache
  1931. */
  1932. function mapCacheClear() {
  1933. this.size = 0;
  1934. this.__data__ = {
  1935. 'hash': new Hash,
  1936. 'map': new (Map || ListCache),
  1937. 'string': new Hash
  1938. };
  1939. }
  1940. /**
  1941. * Removes `key` and its value from the map.
  1942. *
  1943. * @private
  1944. * @name delete
  1945. * @memberOf MapCache
  1946. * @param {string} key The key of the value to remove.
  1947. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1948. */
  1949. function mapCacheDelete(key) {
  1950. var result = getMapData(this, key)['delete'](key);
  1951. this.size -= result ? 1 : 0;
  1952. return result;
  1953. }
  1954. /**
  1955. * Gets the map value for `key`.
  1956. *
  1957. * @private
  1958. * @name get
  1959. * @memberOf MapCache
  1960. * @param {string} key The key of the value to get.
  1961. * @returns {*} Returns the entry value.
  1962. */
  1963. function mapCacheGet(key) {
  1964. return getMapData(this, key).get(key);
  1965. }
  1966. /**
  1967. * Checks if a map value for `key` exists.
  1968. *
  1969. * @private
  1970. * @name has
  1971. * @memberOf MapCache
  1972. * @param {string} key The key of the entry to check.
  1973. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1974. */
  1975. function mapCacheHas(key) {
  1976. return getMapData(this, key).has(key);
  1977. }
  1978. /**
  1979. * Sets the map `key` to `value`.
  1980. *
  1981. * @private
  1982. * @name set
  1983. * @memberOf MapCache
  1984. * @param {string} key The key of the value to set.
  1985. * @param {*} value The value to set.
  1986. * @returns {Object} Returns the map cache instance.
  1987. */
  1988. function mapCacheSet(key, value) {
  1989. var data = getMapData(this, key),
  1990. size = data.size;
  1991. data.set(key, value);
  1992. this.size += data.size == size ? 0 : 1;
  1993. return this;
  1994. }
  1995. // Add methods to `MapCache`.
  1996. MapCache.prototype.clear = mapCacheClear;
  1997. MapCache.prototype['delete'] = mapCacheDelete;
  1998. MapCache.prototype.get = mapCacheGet;
  1999. MapCache.prototype.has = mapCacheHas;
  2000. MapCache.prototype.set = mapCacheSet;
  2001. /*------------------------------------------------------------------------*/
  2002. /**
  2003. *
  2004. * Creates an array cache object to store unique values.
  2005. *
  2006. * @private
  2007. * @constructor
  2008. * @param {Array} [values] The values to cache.
  2009. */
  2010. function SetCache(values) {
  2011. var index = -1,
  2012. length = values == null ? 0 : values.length;
  2013. this.__data__ = new MapCache;
  2014. while (++index < length) {
  2015. this.add(values[index]);
  2016. }
  2017. }
  2018. /**
  2019. * Adds `value` to the array cache.
  2020. *
  2021. * @private
  2022. * @name add
  2023. * @memberOf SetCache
  2024. * @alias push
  2025. * @param {*} value The value to cache.
  2026. * @returns {Object} Returns the cache instance.
  2027. */
  2028. function setCacheAdd(value) {
  2029. this.__data__.set(value, HASH_UNDEFINED);
  2030. return this;
  2031. }
  2032. /**
  2033. * Checks if `value` is in the array cache.
  2034. *
  2035. * @private
  2036. * @name has
  2037. * @memberOf SetCache
  2038. * @param {*} value The value to search for.
  2039. * @returns {number} Returns `true` if `value` is found, else `false`.
  2040. */
  2041. function setCacheHas(value) {
  2042. return this.__data__.has(value);
  2043. }
  2044. // Add methods to `SetCache`.
  2045. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2046. SetCache.prototype.has = setCacheHas;
  2047. /*------------------------------------------------------------------------*/
  2048. /**
  2049. * Creates a stack cache object to store key-value pairs.
  2050. *
  2051. * @private
  2052. * @constructor
  2053. * @param {Array} [entries] The key-value pairs to cache.
  2054. */
  2055. function Stack(entries) {
  2056. var data = this.__data__ = new ListCache(entries);
  2057. this.size = data.size;
  2058. }
  2059. /**
  2060. * Removes all key-value entries from the stack.
  2061. *
  2062. * @private
  2063. * @name clear
  2064. * @memberOf Stack
  2065. */
  2066. function stackClear() {
  2067. this.__data__ = new ListCache;
  2068. this.size = 0;
  2069. }
  2070. /**
  2071. * Removes `key` and its value from the stack.
  2072. *
  2073. * @private
  2074. * @name delete
  2075. * @memberOf Stack
  2076. * @param {string} key The key of the value to remove.
  2077. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2078. */
  2079. function stackDelete(key) {
  2080. var data = this.__data__,
  2081. result = data['delete'](key);
  2082. this.size = data.size;
  2083. return result;
  2084. }
  2085. /**
  2086. * Gets the stack value for `key`.
  2087. *
  2088. * @private
  2089. * @name get
  2090. * @memberOf Stack
  2091. * @param {string} key The key of the value to get.
  2092. * @returns {*} Returns the entry value.
  2093. */
  2094. function stackGet(key) {
  2095. return this.__data__.get(key);
  2096. }
  2097. /**
  2098. * Checks if a stack value for `key` exists.
  2099. *
  2100. * @private
  2101. * @name has
  2102. * @memberOf Stack
  2103. * @param {string} key The key of the entry to check.
  2104. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2105. */
  2106. function stackHas(key) {
  2107. return this.__data__.has(key);
  2108. }
  2109. /**
  2110. * Sets the stack `key` to `value`.
  2111. *
  2112. * @private
  2113. * @name set
  2114. * @memberOf Stack
  2115. * @param {string} key The key of the value to set.
  2116. * @param {*} value The value to set.
  2117. * @returns {Object} Returns the stack cache instance.
  2118. */
  2119. function stackSet(key, value) {
  2120. var data = this.__data__;
  2121. if (data instanceof ListCache) {
  2122. var pairs = data.__data__;
  2123. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2124. pairs.push([key, value]);
  2125. this.size = ++data.size;
  2126. return this;
  2127. }
  2128. data = this.__data__ = new MapCache(pairs);
  2129. }
  2130. data.set(key, value);
  2131. this.size = data.size;
  2132. return this;
  2133. }
  2134. // Add methods to `Stack`.
  2135. Stack.prototype.clear = stackClear;
  2136. Stack.prototype['delete'] = stackDelete;
  2137. Stack.prototype.get = stackGet;
  2138. Stack.prototype.has = stackHas;
  2139. Stack.prototype.set = stackSet;
  2140. /*------------------------------------------------------------------------*/
  2141. /**
  2142. * Creates an array of the enumerable property names of the array-like `value`.
  2143. *
  2144. * @private
  2145. * @param {*} value The value to query.
  2146. * @param {boolean} inherited Specify returning inherited property names.
  2147. * @returns {Array} Returns the array of property names.
  2148. */
  2149. function arrayLikeKeys(value, inherited) {
  2150. var isArr = isArray(value),
  2151. isArg = !isArr && isArguments(value),
  2152. isBuff = !isArr && !isArg && isBuffer(value),
  2153. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2154. skipIndexes = isArr || isArg || isBuff || isType,
  2155. result = skipIndexes ? baseTimes(value.length, String) : [],
  2156. length = result.length;
  2157. for (var key in value) {
  2158. if ((inherited || hasOwnProperty.call(value, key)) &&
  2159. !(skipIndexes && (
  2160. // Safari 9 has enumerable `arguments.length` in strict mode.
  2161. key == 'length' ||
  2162. // Node.js 0.10 has enumerable non-index properties on buffers.
  2163. (isBuff && (key == 'offset' || key == 'parent')) ||
  2164. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2165. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2166. // Skip index properties.
  2167. isIndex(key, length)
  2168. ))) {
  2169. result.push(key);
  2170. }
  2171. }
  2172. return result;
  2173. }
  2174. /**
  2175. * A specialized version of `_.sample` for arrays.
  2176. *
  2177. * @private
  2178. * @param {Array} array The array to sample.
  2179. * @returns {*} Returns the random element.
  2180. */
  2181. function arraySample(array) {
  2182. var length = array.length;
  2183. return length ? array[baseRandom(0, length - 1)] : undefined;
  2184. }
  2185. /**
  2186. * A specialized version of `_.sampleSize` for arrays.
  2187. *
  2188. * @private
  2189. * @param {Array} array The array to sample.
  2190. * @param {number} n The number of elements to sample.
  2191. * @returns {Array} Returns the random elements.
  2192. */
  2193. function arraySampleSize(array, n) {
  2194. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2195. }
  2196. /**
  2197. * A specialized version of `_.shuffle` for arrays.
  2198. *
  2199. * @private
  2200. * @param {Array} array The array to shuffle.
  2201. * @returns {Array} Returns the new shuffled array.
  2202. */
  2203. function arrayShuffle(array) {
  2204. return shuffleSelf(copyArray(array));
  2205. }
  2206. /**
  2207. * This function is like `assignValue` except that it doesn't assign
  2208. * `undefined` values.
  2209. *
  2210. * @private
  2211. * @param {Object} object The object to modify.
  2212. * @param {string} key The key of the property to assign.
  2213. * @param {*} value The value to assign.
  2214. */
  2215. function assignMergeValue(object, key, value) {
  2216. if ((value !== undefined && !eq(object[key], value)) ||
  2217. (value === undefined && !(key in object))) {
  2218. baseAssignValue(object, key, value);
  2219. }
  2220. }
  2221. /**
  2222. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2223. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2224. * for equality comparisons.
  2225. *
  2226. * @private
  2227. * @param {Object} object The object to modify.
  2228. * @param {string} key The key of the property to assign.
  2229. * @param {*} value The value to assign.
  2230. */
  2231. function assignValue(object, key, value) {
  2232. var objValue = object[key];
  2233. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2234. (value === undefined && !(key in object))) {
  2235. baseAssignValue(object, key, value);
  2236. }
  2237. }
  2238. /**
  2239. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2240. *
  2241. * @private
  2242. * @param {Array} array The array to inspect.
  2243. * @param {*} key The key to search for.
  2244. * @returns {number} Returns the index of the matched value, else `-1`.
  2245. */
  2246. function assocIndexOf(array, key) {
  2247. var length = array.length;
  2248. while (length--) {
  2249. if (eq(array[length][0], key)) {
  2250. return length;
  2251. }
  2252. }
  2253. return -1;
  2254. }
  2255. /**
  2256. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2257. * by `iteratee` and values set by `setter`.
  2258. *
  2259. * @private
  2260. * @param {Array|Object} collection The collection to iterate over.
  2261. * @param {Function} setter The function to set `accumulator` values.
  2262. * @param {Function} iteratee The iteratee to transform keys.
  2263. * @param {Object} accumulator The initial aggregated object.
  2264. * @returns {Function} Returns `accumulator`.
  2265. */
  2266. function baseAggregator(collection, setter, iteratee, accumulator) {
  2267. baseEach(collection, function(value, key, collection) {
  2268. setter(accumulator, value, iteratee(value), collection);
  2269. });
  2270. return accumulator;
  2271. }
  2272. /**
  2273. * The base implementation of `_.assign` without support for multiple sources
  2274. * or `customizer` functions.
  2275. *
  2276. * @private
  2277. * @param {Object} object The destination object.
  2278. * @param {Object} source The source object.
  2279. * @returns {Object} Returns `object`.
  2280. */
  2281. function baseAssign(object, source) {
  2282. return object && copyObject(source, keys(source), object);
  2283. }
  2284. /**
  2285. * The base implementation of `_.assignIn` without support for multiple sources
  2286. * or `customizer` functions.
  2287. *
  2288. * @private
  2289. * @param {Object} object The destination object.
  2290. * @param {Object} source The source object.
  2291. * @returns {Object} Returns `object`.
  2292. */
  2293. function baseAssignIn(object, source) {
  2294. return object && copyObject(source, keysIn(source), object);
  2295. }
  2296. /**
  2297. * The base implementation of `assignValue` and `assignMergeValue` without
  2298. * value checks.
  2299. *
  2300. * @private
  2301. * @param {Object} object The object to modify.
  2302. * @param {string} key The key of the property to assign.
  2303. * @param {*} value The value to assign.
  2304. */
  2305. function baseAssignValue(object, key, value) {
  2306. if (key == '__proto__' && defineProperty) {
  2307. defineProperty(object, key, {
  2308. 'configurable': true,
  2309. 'enumerable': true,
  2310. 'value': value,
  2311. 'writable': true
  2312. });
  2313. } else {
  2314. object[key] = value;
  2315. }
  2316. }
  2317. /**
  2318. * The base implementation of `_.at` without support for individual paths.
  2319. *
  2320. * @private
  2321. * @param {Object} object The object to iterate over.
  2322. * @param {string[]} paths The property paths to pick.
  2323. * @returns {Array} Returns the picked elements.
  2324. */
  2325. function baseAt(object, paths) {
  2326. var index = -1,
  2327. length = paths.length,
  2328. result = Array(length),
  2329. skip = object == null;
  2330. while (++index < length) {
  2331. result[index] = skip ? undefined : get(object, paths[index]);
  2332. }
  2333. return result;
  2334. }
  2335. /**
  2336. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2337. *
  2338. * @private
  2339. * @param {number} number The number to clamp.
  2340. * @param {number} [lower] The lower bound.
  2341. * @param {number} upper The upper bound.
  2342. * @returns {number} Returns the clamped number.
  2343. */
  2344. function baseClamp(number, lower, upper) {
  2345. if (number === number) {
  2346. if (upper !== undefined) {
  2347. number = number <= upper ? number : upper;
  2348. }
  2349. if (lower !== undefined) {
  2350. number = number >= lower ? number : lower;
  2351. }
  2352. }
  2353. return number;
  2354. }
  2355. /**
  2356. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2357. * traversed objects.
  2358. *
  2359. * @private
  2360. * @param {*} value The value to clone.
  2361. * @param {boolean} bitmask The bitmask flags.
  2362. * 1 - Deep clone
  2363. * 2 - Flatten inherited properties
  2364. * 4 - Clone symbols
  2365. * @param {Function} [customizer] The function to customize cloning.
  2366. * @param {string} [key] The key of `value`.
  2367. * @param {Object} [object] The parent object of `value`.
  2368. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2369. * @returns {*} Returns the cloned value.
  2370. */
  2371. function baseClone(value, bitmask, customizer, key, object, stack) {
  2372. var result,
  2373. isDeep = bitmask & CLONE_DEEP_FLAG,
  2374. isFlat = bitmask & CLONE_FLAT_FLAG,
  2375. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2376. if (customizer) {
  2377. result = object ? customizer(value, key, object, stack) : customizer(value);
  2378. }
  2379. if (result !== undefined) {
  2380. return result;
  2381. }
  2382. if (!isObject(value)) {
  2383. return value;
  2384. }
  2385. var isArr = isArray(value);
  2386. if (isArr) {
  2387. result = initCloneArray(value);
  2388. if (!isDeep) {
  2389. return copyArray(value, result);
  2390. }
  2391. } else {
  2392. var tag = getTag(value),
  2393. isFunc = tag == funcTag || tag == genTag;
  2394. if (isBuffer(value)) {
  2395. return cloneBuffer(value, isDeep);
  2396. }
  2397. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2398. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2399. if (!isDeep) {
  2400. return isFlat
  2401. ? copySymbolsIn(value, baseAssignIn(result, value))
  2402. : copySymbols(value, baseAssign(result, value));
  2403. }
  2404. } else {
  2405. if (!cloneableTags[tag]) {
  2406. return object ? value : {};
  2407. }
  2408. result = initCloneByTag(value, tag, isDeep);
  2409. }
  2410. }
  2411. // Check for circular references and return its corresponding clone.
  2412. stack || (stack = new Stack);
  2413. var stacked = stack.get(value);
  2414. if (stacked) {
  2415. return stacked;
  2416. }
  2417. stack.set(value, result);
  2418. if (isSet(value)) {
  2419. value.forEach(function(subValue) {
  2420. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2421. });
  2422. return result;
  2423. }
  2424. if (isMap(value)) {
  2425. value.forEach(function(subValue, key) {
  2426. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2427. });
  2428. return result;
  2429. }
  2430. var keysFunc = isFull
  2431. ? (isFlat ? getAllKeysIn : getAllKeys)
  2432. : (isFlat ? keysIn : keys);
  2433. var props = isArr ? undefined : keysFunc(value);
  2434. arrayEach(props || value, function(subValue, key) {
  2435. if (props) {
  2436. key = subValue;
  2437. subValue = value[key];
  2438. }
  2439. // Recursively populate clone (susceptible to call stack limits).
  2440. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2441. });
  2442. return result;
  2443. }
  2444. /**
  2445. * The base implementation of `_.conforms` which doesn't clone `source`.
  2446. *
  2447. * @private
  2448. * @param {Object} source The object of property predicates to conform to.
  2449. * @returns {Function} Returns the new spec function.
  2450. */
  2451. function baseConforms(source) {
  2452. var props = keys(source);
  2453. return function(object) {
  2454. return baseConformsTo(object, source, props);
  2455. };
  2456. }
  2457. /**
  2458. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2459. *
  2460. * @private
  2461. * @param {Object} object The object to inspect.
  2462. * @param {Object} source The object of property predicates to conform to.
  2463. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2464. */
  2465. function baseConformsTo(object, source, props) {
  2466. var length = props.length;
  2467. if (object == null) {
  2468. return !length;
  2469. }
  2470. object = Object(object);
  2471. while (length--) {
  2472. var key = props[length],
  2473. predicate = source[key],
  2474. value = object[key];
  2475. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2476. return false;
  2477. }
  2478. }
  2479. return true;
  2480. }
  2481. /**
  2482. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2483. * to provide to `func`.
  2484. *
  2485. * @private
  2486. * @param {Function} func The function to delay.
  2487. * @param {number} wait The number of milliseconds to delay invocation.
  2488. * @param {Array} args The arguments to provide to `func`.
  2489. * @returns {number|Object} Returns the timer id or timeout object.
  2490. */
  2491. function baseDelay(func, wait, args) {
  2492. if (typeof func != 'function') {
  2493. throw new TypeError(FUNC_ERROR_TEXT);
  2494. }
  2495. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2496. }
  2497. /**
  2498. * The base implementation of methods like `_.difference` without support
  2499. * for excluding multiple arrays or iteratee shorthands.
  2500. *
  2501. * @private
  2502. * @param {Array} array The array to inspect.
  2503. * @param {Array} values The values to exclude.
  2504. * @param {Function} [iteratee] The iteratee invoked per element.
  2505. * @param {Function} [comparator] The comparator invoked per element.
  2506. * @returns {Array} Returns the new array of filtered values.
  2507. */
  2508. function baseDifference(array, values, iteratee, comparator) {
  2509. var index = -1,
  2510. includes = arrayIncludes,
  2511. isCommon = true,
  2512. length = array.length,
  2513. result = [],
  2514. valuesLength = values.length;
  2515. if (!length) {
  2516. return result;
  2517. }
  2518. if (iteratee) {
  2519. values = arrayMap(values, baseUnary(iteratee));
  2520. }
  2521. if (comparator) {
  2522. includes = arrayIncludesWith;
  2523. isCommon = false;
  2524. }
  2525. else if (values.length >= LARGE_ARRAY_SIZE) {
  2526. includes = cacheHas;
  2527. isCommon = false;
  2528. values = new SetCache(values);
  2529. }
  2530. outer:
  2531. while (++index < length) {
  2532. var value = array[index],
  2533. computed = iteratee == null ? value : iteratee(value);
  2534. value = (comparator || value !== 0) ? value : 0;
  2535. if (isCommon && computed === computed) {
  2536. var valuesIndex = valuesLength;
  2537. while (valuesIndex--) {
  2538. if (values[valuesIndex] === computed) {
  2539. continue outer;
  2540. }
  2541. }
  2542. result.push(value);
  2543. }
  2544. else if (!includes(values, computed, comparator)) {
  2545. result.push(value);
  2546. }
  2547. }
  2548. return result;
  2549. }
  2550. /**
  2551. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2552. *
  2553. * @private
  2554. * @param {Array|Object} collection The collection to iterate over.
  2555. * @param {Function} iteratee The function invoked per iteration.
  2556. * @returns {Array|Object} Returns `collection`.
  2557. */
  2558. var baseEach = createBaseEach(baseForOwn);
  2559. /**
  2560. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2561. *
  2562. * @private
  2563. * @param {Array|Object} collection The collection to iterate over.
  2564. * @param {Function} iteratee The function invoked per iteration.
  2565. * @returns {Array|Object} Returns `collection`.
  2566. */
  2567. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2568. /**
  2569. * The base implementation of `_.every` without support for iteratee shorthands.
  2570. *
  2571. * @private
  2572. * @param {Array|Object} collection The collection to iterate over.
  2573. * @param {Function} predicate The function invoked per iteration.
  2574. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2575. * else `false`
  2576. */
  2577. function baseEvery(collection, predicate) {
  2578. var result = true;
  2579. baseEach(collection, function(value, index, collection) {
  2580. result = !!predicate(value, index, collection);
  2581. return result;
  2582. });
  2583. return result;
  2584. }
  2585. /**
  2586. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2587. * `comparator` to determine the extremum value.
  2588. *
  2589. * @private
  2590. * @param {Array} array The array to iterate over.
  2591. * @param {Function} iteratee The iteratee invoked per iteration.
  2592. * @param {Function} comparator The comparator used to compare values.
  2593. * @returns {*} Returns the extremum value.
  2594. */
  2595. function baseExtremum(array, iteratee, comparator) {
  2596. var index = -1,
  2597. length = array.length;
  2598. while (++index < length) {
  2599. var value = array[index],
  2600. current = iteratee(value);
  2601. if (current != null && (computed === undefined
  2602. ? (current === current && !isSymbol(current))
  2603. : comparator(current, computed)
  2604. )) {
  2605. var computed = current,
  2606. result = value;
  2607. }
  2608. }
  2609. return result;
  2610. }
  2611. /**
  2612. * The base implementation of `_.fill` without an iteratee call guard.
  2613. *
  2614. * @private
  2615. * @param {Array} array The array to fill.
  2616. * @param {*} value The value to fill `array` with.
  2617. * @param {number} [start=0] The start position.
  2618. * @param {number} [end=array.length] The end position.
  2619. * @returns {Array} Returns `array`.
  2620. */
  2621. function baseFill(array, value, start, end) {
  2622. var length = array.length;
  2623. start = toInteger(start);
  2624. if (start < 0) {
  2625. start = -start > length ? 0 : (length + start);
  2626. }
  2627. end = (end === undefined || end > length) ? length : toInteger(end);
  2628. if (end < 0) {
  2629. end += length;
  2630. }
  2631. end = start > end ? 0 : toLength(end);
  2632. while (start < end) {
  2633. array[start++] = value;
  2634. }
  2635. return array;
  2636. }
  2637. /**
  2638. * The base implementation of `_.filter` without support for iteratee shorthands.
  2639. *
  2640. * @private
  2641. * @param {Array|Object} collection The collection to iterate over.
  2642. * @param {Function} predicate The function invoked per iteration.
  2643. * @returns {Array} Returns the new filtered array.
  2644. */
  2645. function baseFilter(collection, predicate) {
  2646. var result = [];
  2647. baseEach(collection, function(value, index, collection) {
  2648. if (predicate(value, index, collection)) {
  2649. result.push(value);
  2650. }
  2651. });
  2652. return result;
  2653. }
  2654. /**
  2655. * The base implementation of `_.flatten` with support for restricting flattening.
  2656. *
  2657. * @private
  2658. * @param {Array} array The array to flatten.
  2659. * @param {number} depth The maximum recursion depth.
  2660. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2661. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2662. * @param {Array} [result=[]] The initial result value.
  2663. * @returns {Array} Returns the new flattened array.
  2664. */
  2665. function baseFlatten(array, depth, predicate, isStrict, result) {
  2666. var index = -1,
  2667. length = array.length;
  2668. predicate || (predicate = isFlattenable);
  2669. result || (result = []);
  2670. while (++index < length) {
  2671. var value = array[index];
  2672. if (depth > 0 && predicate(value)) {
  2673. if (depth > 1) {
  2674. // Recursively flatten arrays (susceptible to call stack limits).
  2675. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2676. } else {
  2677. arrayPush(result, value);
  2678. }
  2679. } else if (!isStrict) {
  2680. result[result.length] = value;
  2681. }
  2682. }
  2683. return result;
  2684. }
  2685. /**
  2686. * The base implementation of `baseForOwn` which iterates over `object`
  2687. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2688. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2689. *
  2690. * @private
  2691. * @param {Object} object The object to iterate over.
  2692. * @param {Function} iteratee The function invoked per iteration.
  2693. * @param {Function} keysFunc The function to get the keys of `object`.
  2694. * @returns {Object} Returns `object`.
  2695. */
  2696. var baseFor = createBaseFor();
  2697. /**
  2698. * This function is like `baseFor` except that it iterates over properties
  2699. * in the opposite order.
  2700. *
  2701. * @private
  2702. * @param {Object} object The object to iterate over.
  2703. * @param {Function} iteratee The function invoked per iteration.
  2704. * @param {Function} keysFunc The function to get the keys of `object`.
  2705. * @returns {Object} Returns `object`.
  2706. */
  2707. var baseForRight = createBaseFor(true);
  2708. /**
  2709. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2710. *
  2711. * @private
  2712. * @param {Object} object The object to iterate over.
  2713. * @param {Function} iteratee The function invoked per iteration.
  2714. * @returns {Object} Returns `object`.
  2715. */
  2716. function baseForOwn(object, iteratee) {
  2717. return object && baseFor(object, iteratee, keys);
  2718. }
  2719. /**
  2720. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2721. *
  2722. * @private
  2723. * @param {Object} object The object to iterate over.
  2724. * @param {Function} iteratee The function invoked per iteration.
  2725. * @returns {Object} Returns `object`.
  2726. */
  2727. function baseForOwnRight(object, iteratee) {
  2728. return object && baseForRight(object, iteratee, keys);
  2729. }
  2730. /**
  2731. * The base implementation of `_.functions` which creates an array of
  2732. * `object` function property names filtered from `props`.
  2733. *
  2734. * @private
  2735. * @param {Object} object The object to inspect.
  2736. * @param {Array} props The property names to filter.
  2737. * @returns {Array} Returns the function names.
  2738. */
  2739. function baseFunctions(object, props) {
  2740. return arrayFilter(props, function(key) {
  2741. return isFunction(object[key]);
  2742. });
  2743. }
  2744. /**
  2745. * The base implementation of `_.get` without support for default values.
  2746. *
  2747. * @private
  2748. * @param {Object} object The object to query.
  2749. * @param {Array|string} path The path of the property to get.
  2750. * @returns {*} Returns the resolved value.
  2751. */
  2752. function baseGet(object, path) {
  2753. path = castPath(path, object);
  2754. var index = 0,
  2755. length = path.length;
  2756. while (object != null && index < length) {
  2757. object = object[toKey(path[index++])];
  2758. }
  2759. return (index && index == length) ? object : undefined;
  2760. }
  2761. /**
  2762. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2763. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2764. * symbols of `object`.
  2765. *
  2766. * @private
  2767. * @param {Object} object The object to query.
  2768. * @param {Function} keysFunc The function to get the keys of `object`.
  2769. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2770. * @returns {Array} Returns the array of property names and symbols.
  2771. */
  2772. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2773. var result = keysFunc(object);
  2774. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2775. }
  2776. /**
  2777. * The base implementation of `getTag` without fallbacks for buggy environments.
  2778. *
  2779. * @private
  2780. * @param {*} value The value to query.
  2781. * @returns {string} Returns the `toStringTag`.
  2782. */
  2783. function baseGetTag(value) {
  2784. if (value == null) {
  2785. return value === undefined ? undefinedTag : nullTag;
  2786. }
  2787. return (symToStringTag && symToStringTag in Object(value))
  2788. ? getRawTag(value)
  2789. : objectToString(value);
  2790. }
  2791. /**
  2792. * The base implementation of `_.gt` which doesn't coerce arguments.
  2793. *
  2794. * @private
  2795. * @param {*} value The value to compare.
  2796. * @param {*} other The other value to compare.
  2797. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2798. * else `false`.
  2799. */
  2800. function baseGt(value, other) {
  2801. return value > other;
  2802. }
  2803. /**
  2804. * The base implementation of `_.has` without support for deep paths.
  2805. *
  2806. * @private
  2807. * @param {Object} [object] The object to query.
  2808. * @param {Array|string} key The key to check.
  2809. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2810. */
  2811. function baseHas(object, key) {
  2812. return object != null && hasOwnProperty.call(object, key);
  2813. }
  2814. /**
  2815. * The base implementation of `_.hasIn` without support for deep paths.
  2816. *
  2817. * @private
  2818. * @param {Object} [object] The object to query.
  2819. * @param {Array|string} key The key to check.
  2820. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2821. */
  2822. function baseHasIn(object, key) {
  2823. return object != null && key in Object(object);
  2824. }
  2825. /**
  2826. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2827. *
  2828. * @private
  2829. * @param {number} number The number to check.
  2830. * @param {number} start The start of the range.
  2831. * @param {number} end The end of the range.
  2832. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2833. */
  2834. function baseInRange(number, start, end) {
  2835. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2836. }
  2837. /**
  2838. * The base implementation of methods like `_.intersection`, without support
  2839. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2840. *
  2841. * @private
  2842. * @param {Array} arrays The arrays to inspect.
  2843. * @param {Function} [iteratee] The iteratee invoked per element.
  2844. * @param {Function} [comparator] The comparator invoked per element.
  2845. * @returns {Array} Returns the new array of shared values.
  2846. */
  2847. function baseIntersection(arrays, iteratee, comparator) {
  2848. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2849. length = arrays[0].length,
  2850. othLength = arrays.length,
  2851. othIndex = othLength,
  2852. caches = Array(othLength),
  2853. maxLength = Infinity,
  2854. result = [];
  2855. while (othIndex--) {
  2856. var array = arrays[othIndex];
  2857. if (othIndex && iteratee) {
  2858. array = arrayMap(array, baseUnary(iteratee));
  2859. }
  2860. maxLength = nativeMin(array.length, maxLength);
  2861. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2862. ? new SetCache(othIndex && array)
  2863. : undefined;
  2864. }
  2865. array = arrays[0];
  2866. var index = -1,
  2867. seen = caches[0];
  2868. outer:
  2869. while (++index < length && result.length < maxLength) {
  2870. var value = array[index],
  2871. computed = iteratee ? iteratee(value) : value;
  2872. value = (comparator || value !== 0) ? value : 0;
  2873. if (!(seen
  2874. ? cacheHas(seen, computed)
  2875. : includes(result, computed, comparator)
  2876. )) {
  2877. othIndex = othLength;
  2878. while (--othIndex) {
  2879. var cache = caches[othIndex];
  2880. if (!(cache
  2881. ? cacheHas(cache, computed)
  2882. : includes(arrays[othIndex], computed, comparator))
  2883. ) {
  2884. continue outer;
  2885. }
  2886. }
  2887. if (seen) {
  2888. seen.push(computed);
  2889. }
  2890. result.push(value);
  2891. }
  2892. }
  2893. return result;
  2894. }
  2895. /**
  2896. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2897. * `object` with values transformed by `iteratee` and set by `setter`.
  2898. *
  2899. * @private
  2900. * @param {Object} object The object to iterate over.
  2901. * @param {Function} setter The function to set `accumulator` values.
  2902. * @param {Function} iteratee The iteratee to transform values.
  2903. * @param {Object} accumulator The initial inverted object.
  2904. * @returns {Function} Returns `accumulator`.
  2905. */
  2906. function baseInverter(object, setter, iteratee, accumulator) {
  2907. baseForOwn(object, function(value, key, object) {
  2908. setter(accumulator, iteratee(value), key, object);
  2909. });
  2910. return accumulator;
  2911. }
  2912. /**
  2913. * The base implementation of `_.invoke` without support for individual
  2914. * method arguments.
  2915. *
  2916. * @private
  2917. * @param {Object} object The object to query.
  2918. * @param {Array|string} path The path of the method to invoke.
  2919. * @param {Array} args The arguments to invoke the method with.
  2920. * @returns {*} Returns the result of the invoked method.
  2921. */
  2922. function baseInvoke(object, path, args) {
  2923. path = castPath(path, object);
  2924. object = parent(object, path);
  2925. var func = object == null ? object : object[toKey(last(path))];
  2926. return func == null ? undefined : apply(func, object, args);
  2927. }
  2928. /**
  2929. * The base implementation of `_.isArguments`.
  2930. *
  2931. * @private
  2932. * @param {*} value The value to check.
  2933. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2934. */
  2935. function baseIsArguments(value) {
  2936. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2937. }
  2938. /**
  2939. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2940. *
  2941. * @private
  2942. * @param {*} value The value to check.
  2943. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2944. */
  2945. function baseIsArrayBuffer(value) {
  2946. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2947. }
  2948. /**
  2949. * The base implementation of `_.isDate` without Node.js optimizations.
  2950. *
  2951. * @private
  2952. * @param {*} value The value to check.
  2953. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2954. */
  2955. function baseIsDate(value) {
  2956. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2957. }
  2958. /**
  2959. * The base implementation of `_.isEqual` which supports partial comparisons
  2960. * and tracks traversed objects.
  2961. *
  2962. * @private
  2963. * @param {*} value The value to compare.
  2964. * @param {*} other The other value to compare.
  2965. * @param {boolean} bitmask The bitmask flags.
  2966. * 1 - Unordered comparison
  2967. * 2 - Partial comparison
  2968. * @param {Function} [customizer] The function to customize comparisons.
  2969. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2970. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2971. */
  2972. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2973. if (value === other) {
  2974. return true;
  2975. }
  2976. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2977. return value !== value && other !== other;
  2978. }
  2979. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2980. }
  2981. /**
  2982. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2983. * deep comparisons and tracks traversed objects enabling objects with circular
  2984. * references to be compared.
  2985. *
  2986. * @private
  2987. * @param {Object} object The object to compare.
  2988. * @param {Object} other The other object to compare.
  2989. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2990. * @param {Function} customizer The function to customize comparisons.
  2991. * @param {Function} equalFunc The function to determine equivalents of values.
  2992. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2993. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2994. */
  2995. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  2996. var objIsArr = isArray(object),
  2997. othIsArr = isArray(other),
  2998. objTag = objIsArr ? arrayTag : getTag(object),
  2999. othTag = othIsArr ? arrayTag : getTag(other);
  3000. objTag = objTag == argsTag ? objectTag : objTag;
  3001. othTag = othTag == argsTag ? objectTag : othTag;
  3002. var objIsObj = objTag == objectTag,
  3003. othIsObj = othTag == objectTag,
  3004. isSameTag = objTag == othTag;
  3005. if (isSameTag && isBuffer(object)) {
  3006. if (!isBuffer(other)) {
  3007. return false;
  3008. }
  3009. objIsArr = true;
  3010. objIsObj = false;
  3011. }
  3012. if (isSameTag && !objIsObj) {
  3013. stack || (stack = new Stack);
  3014. return (objIsArr || isTypedArray(object))
  3015. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3016. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3017. }
  3018. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3019. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3020. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3021. if (objIsWrapped || othIsWrapped) {
  3022. var objUnwrapped = objIsWrapped ? object.value() : object,
  3023. othUnwrapped = othIsWrapped ? other.value() : other;
  3024. stack || (stack = new Stack);
  3025. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3026. }
  3027. }
  3028. if (!isSameTag) {
  3029. return false;
  3030. }
  3031. stack || (stack = new Stack);
  3032. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3033. }
  3034. /**
  3035. * The base implementation of `_.isMap` without Node.js optimizations.
  3036. *
  3037. * @private
  3038. * @param {*} value The value to check.
  3039. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3040. */
  3041. function baseIsMap(value) {
  3042. return isObjectLike(value) && getTag(value) == mapTag;
  3043. }
  3044. /**
  3045. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3046. *
  3047. * @private
  3048. * @param {Object} object The object to inspect.
  3049. * @param {Object} source The object of property values to match.
  3050. * @param {Array} matchData The property names, values, and compare flags to match.
  3051. * @param {Function} [customizer] The function to customize comparisons.
  3052. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3053. */
  3054. function baseIsMatch(object, source, matchData, customizer) {
  3055. var index = matchData.length,
  3056. length = index,
  3057. noCustomizer = !customizer;
  3058. if (object == null) {
  3059. return !length;
  3060. }
  3061. object = Object(object);
  3062. while (index--) {
  3063. var data = matchData[index];
  3064. if ((noCustomizer && data[2])
  3065. ? data[1] !== object[data[0]]
  3066. : !(data[0] in object)
  3067. ) {
  3068. return false;
  3069. }
  3070. }
  3071. while (++index < length) {
  3072. data = matchData[index];
  3073. var key = data[0],
  3074. objValue = object[key],
  3075. srcValue = data[1];
  3076. if (noCustomizer && data[2]) {
  3077. if (objValue === undefined && !(key in object)) {
  3078. return false;
  3079. }
  3080. } else {
  3081. var stack = new Stack;
  3082. if (customizer) {
  3083. var result = customizer(objValue, srcValue, key, object, source, stack);
  3084. }
  3085. if (!(result === undefined
  3086. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3087. : result
  3088. )) {
  3089. return false;
  3090. }
  3091. }
  3092. }
  3093. return true;
  3094. }
  3095. /**
  3096. * The base implementation of `_.isNative` without bad shim checks.
  3097. *
  3098. * @private
  3099. * @param {*} value The value to check.
  3100. * @returns {boolean} Returns `true` if `value` is a native function,
  3101. * else `false`.
  3102. */
  3103. function baseIsNative(value) {
  3104. if (!isObject(value) || isMasked(value)) {
  3105. return false;
  3106. }
  3107. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3108. return pattern.test(toSource(value));
  3109. }
  3110. /**
  3111. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3112. *
  3113. * @private
  3114. * @param {*} value The value to check.
  3115. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3116. */
  3117. function baseIsRegExp(value) {
  3118. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3119. }
  3120. /**
  3121. * The base implementation of `_.isSet` without Node.js optimizations.
  3122. *
  3123. * @private
  3124. * @param {*} value The value to check.
  3125. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3126. */
  3127. function baseIsSet(value) {
  3128. return isObjectLike(value) && getTag(value) == setTag;
  3129. }
  3130. /**
  3131. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3132. *
  3133. * @private
  3134. * @param {*} value The value to check.
  3135. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3136. */
  3137. function baseIsTypedArray(value) {
  3138. return isObjectLike(value) &&
  3139. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3140. }
  3141. /**
  3142. * The base implementation of `_.iteratee`.
  3143. *
  3144. * @private
  3145. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3146. * @returns {Function} Returns the iteratee.
  3147. */
  3148. function baseIteratee(value) {
  3149. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3150. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3151. if (typeof value == 'function') {
  3152. return value;
  3153. }
  3154. if (value == null) {
  3155. return identity;
  3156. }
  3157. if (typeof value == 'object') {
  3158. return isArray(value)
  3159. ? baseMatchesProperty(value[0], value[1])
  3160. : baseMatches(value);
  3161. }
  3162. return property(value);
  3163. }
  3164. /**
  3165. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3166. *
  3167. * @private
  3168. * @param {Object} object The object to query.
  3169. * @returns {Array} Returns the array of property names.
  3170. */
  3171. function baseKeys(object) {
  3172. if (!isPrototype(object)) {
  3173. return nativeKeys(object);
  3174. }
  3175. var result = [];
  3176. for (var key in Object(object)) {
  3177. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3178. result.push(key);
  3179. }
  3180. }
  3181. return result;
  3182. }
  3183. /**
  3184. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3185. *
  3186. * @private
  3187. * @param {Object} object The object to query.
  3188. * @returns {Array} Returns the array of property names.
  3189. */
  3190. function baseKeysIn(object) {
  3191. if (!isObject(object)) {
  3192. return nativeKeysIn(object);
  3193. }
  3194. var isProto = isPrototype(object),
  3195. result = [];
  3196. for (var key in object) {
  3197. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3198. result.push(key);
  3199. }
  3200. }
  3201. return result;
  3202. }
  3203. /**
  3204. * The base implementation of `_.lt` which doesn't coerce arguments.
  3205. *
  3206. * @private
  3207. * @param {*} value The value to compare.
  3208. * @param {*} other The other value to compare.
  3209. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3210. * else `false`.
  3211. */
  3212. function baseLt(value, other) {
  3213. return value < other;
  3214. }
  3215. /**
  3216. * The base implementation of `_.map` without support for iteratee shorthands.
  3217. *
  3218. * @private
  3219. * @param {Array|Object} collection The collection to iterate over.
  3220. * @param {Function} iteratee The function invoked per iteration.
  3221. * @returns {Array} Returns the new mapped array.
  3222. */
  3223. function baseMap(collection, iteratee) {
  3224. var index = -1,
  3225. result = isArrayLike(collection) ? Array(collection.length) : [];
  3226. baseEach(collection, function(value, key, collection) {
  3227. result[++index] = iteratee(value, key, collection);
  3228. });
  3229. return result;
  3230. }
  3231. /**
  3232. * The base implementation of `_.matches` which doesn't clone `source`.
  3233. *
  3234. * @private
  3235. * @param {Object} source The object of property values to match.
  3236. * @returns {Function} Returns the new spec function.
  3237. */
  3238. function baseMatches(source) {
  3239. var matchData = getMatchData(source);
  3240. if (matchData.length == 1 && matchData[0][2]) {
  3241. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3242. }
  3243. return function(object) {
  3244. return object === source || baseIsMatch(object, source, matchData);
  3245. };
  3246. }
  3247. /**
  3248. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3249. *
  3250. * @private
  3251. * @param {string} path The path of the property to get.
  3252. * @param {*} srcValue The value to match.
  3253. * @returns {Function} Returns the new spec function.
  3254. */
  3255. function baseMatchesProperty(path, srcValue) {
  3256. if (isKey(path) && isStrictComparable(srcValue)) {
  3257. return matchesStrictComparable(toKey(path), srcValue);
  3258. }
  3259. return function(object) {
  3260. var objValue = get(object, path);
  3261. return (objValue === undefined && objValue === srcValue)
  3262. ? hasIn(object, path)
  3263. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3264. };
  3265. }
  3266. /**
  3267. * The base implementation of `_.merge` without support for multiple sources.
  3268. *
  3269. * @private
  3270. * @param {Object} object The destination object.
  3271. * @param {Object} source The source object.
  3272. * @param {number} srcIndex The index of `source`.
  3273. * @param {Function} [customizer] The function to customize merged values.
  3274. * @param {Object} [stack] Tracks traversed source values and their merged
  3275. * counterparts.
  3276. */
  3277. function baseMerge(object, source, srcIndex, customizer, stack) {
  3278. if (object === source) {
  3279. return;
  3280. }
  3281. baseFor(source, function(srcValue, key) {
  3282. if (isObject(srcValue)) {
  3283. stack || (stack = new Stack);
  3284. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3285. }
  3286. else {
  3287. var newValue = customizer
  3288. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3289. : undefined;
  3290. if (newValue === undefined) {
  3291. newValue = srcValue;
  3292. }
  3293. assignMergeValue(object, key, newValue);
  3294. }
  3295. }, keysIn);
  3296. }
  3297. /**
  3298. * A specialized version of `baseMerge` for arrays and objects which performs
  3299. * deep merges and tracks traversed objects enabling objects with circular
  3300. * references to be merged.
  3301. *
  3302. * @private
  3303. * @param {Object} object The destination object.
  3304. * @param {Object} source The source object.
  3305. * @param {string} key The key of the value to merge.
  3306. * @param {number} srcIndex The index of `source`.
  3307. * @param {Function} mergeFunc The function to merge values.
  3308. * @param {Function} [customizer] The function to customize assigned values.
  3309. * @param {Object} [stack] Tracks traversed source values and their merged
  3310. * counterparts.
  3311. */
  3312. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3313. var objValue = safeGet(object, key),
  3314. srcValue = safeGet(source, key),
  3315. stacked = stack.get(srcValue);
  3316. if (stacked) {
  3317. assignMergeValue(object, key, stacked);
  3318. return;
  3319. }
  3320. var newValue = customizer
  3321. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3322. : undefined;
  3323. var isCommon = newValue === undefined;
  3324. if (isCommon) {
  3325. var isArr = isArray(srcValue),
  3326. isBuff = !isArr && isBuffer(srcValue),
  3327. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3328. newValue = srcValue;
  3329. if (isArr || isBuff || isTyped) {
  3330. if (isArray(objValue)) {
  3331. newValue = objValue;
  3332. }
  3333. else if (isArrayLikeObject(objValue)) {
  3334. newValue = copyArray(objValue);
  3335. }
  3336. else if (isBuff) {
  3337. isCommon = false;
  3338. newValue = cloneBuffer(srcValue, true);
  3339. }
  3340. else if (isTyped) {
  3341. isCommon = false;
  3342. newValue = cloneTypedArray(srcValue, true);
  3343. }
  3344. else {
  3345. newValue = [];
  3346. }
  3347. }
  3348. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3349. newValue = objValue;
  3350. if (isArguments(objValue)) {
  3351. newValue = toPlainObject(objValue);
  3352. }
  3353. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  3354. newValue = initCloneObject(srcValue);
  3355. }
  3356. }
  3357. else {
  3358. isCommon = false;
  3359. }
  3360. }
  3361. if (isCommon) {
  3362. // Recursively merge objects and arrays (susceptible to call stack limits).
  3363. stack.set(srcValue, newValue);
  3364. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3365. stack['delete'](srcValue);
  3366. }
  3367. assignMergeValue(object, key, newValue);
  3368. }
  3369. /**
  3370. * The base implementation of `_.nth` which doesn't coerce arguments.
  3371. *
  3372. * @private
  3373. * @param {Array} array The array to query.
  3374. * @param {number} n The index of the element to return.
  3375. * @returns {*} Returns the nth element of `array`.
  3376. */
  3377. function baseNth(array, n) {
  3378. var length = array.length;
  3379. if (!length) {
  3380. return;
  3381. }
  3382. n += n < 0 ? length : 0;
  3383. return isIndex(n, length) ? array[n] : undefined;
  3384. }
  3385. /**
  3386. * The base implementation of `_.orderBy` without param guards.
  3387. *
  3388. * @private
  3389. * @param {Array|Object} collection The collection to iterate over.
  3390. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3391. * @param {string[]} orders The sort orders of `iteratees`.
  3392. * @returns {Array} Returns the new sorted array.
  3393. */
  3394. function baseOrderBy(collection, iteratees, orders) {
  3395. var index = -1;
  3396. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3397. var result = baseMap(collection, function(value, key, collection) {
  3398. var criteria = arrayMap(iteratees, function(iteratee) {
  3399. return iteratee(value);
  3400. });
  3401. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3402. });
  3403. return baseSortBy(result, function(object, other) {
  3404. return compareMultiple(object, other, orders);
  3405. });
  3406. }
  3407. /**
  3408. * The base implementation of `_.pick` without support for individual
  3409. * property identifiers.
  3410. *
  3411. * @private
  3412. * @param {Object} object The source object.
  3413. * @param {string[]} paths The property paths to pick.
  3414. * @returns {Object} Returns the new object.
  3415. */
  3416. function basePick(object, paths) {
  3417. return basePickBy(object, paths, function(value, path) {
  3418. return hasIn(object, path);
  3419. });
  3420. }
  3421. /**
  3422. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3423. *
  3424. * @private
  3425. * @param {Object} object The source object.
  3426. * @param {string[]} paths The property paths to pick.
  3427. * @param {Function} predicate The function invoked per property.
  3428. * @returns {Object} Returns the new object.
  3429. */
  3430. function basePickBy(object, paths, predicate) {
  3431. var index = -1,
  3432. length = paths.length,
  3433. result = {};
  3434. while (++index < length) {
  3435. var path = paths[index],
  3436. value = baseGet(object, path);
  3437. if (predicate(value, path)) {
  3438. baseSet(result, castPath(path, object), value);
  3439. }
  3440. }
  3441. return result;
  3442. }
  3443. /**
  3444. * A specialized version of `baseProperty` which supports deep paths.
  3445. *
  3446. * @private
  3447. * @param {Array|string} path The path of the property to get.
  3448. * @returns {Function} Returns the new accessor function.
  3449. */
  3450. function basePropertyDeep(path) {
  3451. return function(object) {
  3452. return baseGet(object, path);
  3453. };
  3454. }
  3455. /**
  3456. * The base implementation of `_.pullAllBy` without support for iteratee
  3457. * shorthands.
  3458. *
  3459. * @private
  3460. * @param {Array} array The array to modify.
  3461. * @param {Array} values The values to remove.
  3462. * @param {Function} [iteratee] The iteratee invoked per element.
  3463. * @param {Function} [comparator] The comparator invoked per element.
  3464. * @returns {Array} Returns `array`.
  3465. */
  3466. function basePullAll(array, values, iteratee, comparator) {
  3467. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3468. index = -1,
  3469. length = values.length,
  3470. seen = array;
  3471. if (array === values) {
  3472. values = copyArray(values);
  3473. }
  3474. if (iteratee) {
  3475. seen = arrayMap(array, baseUnary(iteratee));
  3476. }
  3477. while (++index < length) {
  3478. var fromIndex = 0,
  3479. value = values[index],
  3480. computed = iteratee ? iteratee(value) : value;
  3481. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3482. if (seen !== array) {
  3483. splice.call(seen, fromIndex, 1);
  3484. }
  3485. splice.call(array, fromIndex, 1);
  3486. }
  3487. }
  3488. return array;
  3489. }
  3490. /**
  3491. * The base implementation of `_.pullAt` without support for individual
  3492. * indexes or capturing the removed elements.
  3493. *
  3494. * @private
  3495. * @param {Array} array The array to modify.
  3496. * @param {number[]} indexes The indexes of elements to remove.
  3497. * @returns {Array} Returns `array`.
  3498. */
  3499. function basePullAt(array, indexes) {
  3500. var length = array ? indexes.length : 0,
  3501. lastIndex = length - 1;
  3502. while (length--) {
  3503. var index = indexes[length];
  3504. if (length == lastIndex || index !== previous) {
  3505. var previous = index;
  3506. if (isIndex(index)) {
  3507. splice.call(array, index, 1);
  3508. } else {
  3509. baseUnset(array, index);
  3510. }
  3511. }
  3512. }
  3513. return array;
  3514. }
  3515. /**
  3516. * The base implementation of `_.random` without support for returning
  3517. * floating-point numbers.
  3518. *
  3519. * @private
  3520. * @param {number} lower The lower bound.
  3521. * @param {number} upper The upper bound.
  3522. * @returns {number} Returns the random number.
  3523. */
  3524. function baseRandom(lower, upper) {
  3525. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3526. }
  3527. /**
  3528. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3529. * coerce arguments.
  3530. *
  3531. * @private
  3532. * @param {number} start The start of the range.
  3533. * @param {number} end The end of the range.
  3534. * @param {number} step The value to increment or decrement by.
  3535. * @param {boolean} [fromRight] Specify iterating from right to left.
  3536. * @returns {Array} Returns the range of numbers.
  3537. */
  3538. function baseRange(start, end, step, fromRight) {
  3539. var index = -1,
  3540. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3541. result = Array(length);
  3542. while (length--) {
  3543. result[fromRight ? length : ++index] = start;
  3544. start += step;
  3545. }
  3546. return result;
  3547. }
  3548. /**
  3549. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3550. *
  3551. * @private
  3552. * @param {string} string The string to repeat.
  3553. * @param {number} n The number of times to repeat the string.
  3554. * @returns {string} Returns the repeated string.
  3555. */
  3556. function baseRepeat(string, n) {
  3557. var result = '';
  3558. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3559. return result;
  3560. }
  3561. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3562. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3563. do {
  3564. if (n % 2) {
  3565. result += string;
  3566. }
  3567. n = nativeFloor(n / 2);
  3568. if (n) {
  3569. string += string;
  3570. }
  3571. } while (n);
  3572. return result;
  3573. }
  3574. /**
  3575. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3576. *
  3577. * @private
  3578. * @param {Function} func The function to apply a rest parameter to.
  3579. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3580. * @returns {Function} Returns the new function.
  3581. */
  3582. function baseRest(func, start) {
  3583. return setToString(overRest(func, start, identity), func + '');
  3584. }
  3585. /**
  3586. * The base implementation of `_.sample`.
  3587. *
  3588. * @private
  3589. * @param {Array|Object} collection The collection to sample.
  3590. * @returns {*} Returns the random element.
  3591. */
  3592. function baseSample(collection) {
  3593. return arraySample(values(collection));
  3594. }
  3595. /**
  3596. * The base implementation of `_.sampleSize` without param guards.
  3597. *
  3598. * @private
  3599. * @param {Array|Object} collection The collection to sample.
  3600. * @param {number} n The number of elements to sample.
  3601. * @returns {Array} Returns the random elements.
  3602. */
  3603. function baseSampleSize(collection, n) {
  3604. var array = values(collection);
  3605. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3606. }
  3607. /**
  3608. * The base implementation of `_.set`.
  3609. *
  3610. * @private
  3611. * @param {Object} object The object to modify.
  3612. * @param {Array|string} path The path of the property to set.
  3613. * @param {*} value The value to set.
  3614. * @param {Function} [customizer] The function to customize path creation.
  3615. * @returns {Object} Returns `object`.
  3616. */
  3617. function baseSet(object, path, value, customizer) {
  3618. if (!isObject(object)) {
  3619. return object;
  3620. }
  3621. path = castPath(path, object);
  3622. var index = -1,
  3623. length = path.length,
  3624. lastIndex = length - 1,
  3625. nested = object;
  3626. while (nested != null && ++index < length) {
  3627. var key = toKey(path[index]),
  3628. newValue = value;
  3629. if (index != lastIndex) {
  3630. var objValue = nested[key];
  3631. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3632. if (newValue === undefined) {
  3633. newValue = isObject(objValue)
  3634. ? objValue
  3635. : (isIndex(path[index + 1]) ? [] : {});
  3636. }
  3637. }
  3638. assignValue(nested, key, newValue);
  3639. nested = nested[key];
  3640. }
  3641. return object;
  3642. }
  3643. /**
  3644. * The base implementation of `setData` without support for hot loop shorting.
  3645. *
  3646. * @private
  3647. * @param {Function} func The function to associate metadata with.
  3648. * @param {*} data The metadata.
  3649. * @returns {Function} Returns `func`.
  3650. */
  3651. var baseSetData = !metaMap ? identity : function(func, data) {
  3652. metaMap.set(func, data);
  3653. return func;
  3654. };
  3655. /**
  3656. * The base implementation of `setToString` without support for hot loop shorting.
  3657. *
  3658. * @private
  3659. * @param {Function} func The function to modify.
  3660. * @param {Function} string The `toString` result.
  3661. * @returns {Function} Returns `func`.
  3662. */
  3663. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3664. return defineProperty(func, 'toString', {
  3665. 'configurable': true,
  3666. 'enumerable': false,
  3667. 'value': constant(string),
  3668. 'writable': true
  3669. });
  3670. };
  3671. /**
  3672. * The base implementation of `_.shuffle`.
  3673. *
  3674. * @private
  3675. * @param {Array|Object} collection The collection to shuffle.
  3676. * @returns {Array} Returns the new shuffled array.
  3677. */
  3678. function baseShuffle(collection) {
  3679. return shuffleSelf(values(collection));
  3680. }
  3681. /**
  3682. * The base implementation of `_.slice` without an iteratee call guard.
  3683. *
  3684. * @private
  3685. * @param {Array} array The array to slice.
  3686. * @param {number} [start=0] The start position.
  3687. * @param {number} [end=array.length] The end position.
  3688. * @returns {Array} Returns the slice of `array`.
  3689. */
  3690. function baseSlice(array, start, end) {
  3691. var index = -1,
  3692. length = array.length;
  3693. if (start < 0) {
  3694. start = -start > length ? 0 : (length + start);
  3695. }
  3696. end = end > length ? length : end;
  3697. if (end < 0) {
  3698. end += length;
  3699. }
  3700. length = start > end ? 0 : ((end - start) >>> 0);
  3701. start >>>= 0;
  3702. var result = Array(length);
  3703. while (++index < length) {
  3704. result[index] = array[index + start];
  3705. }
  3706. return result;
  3707. }
  3708. /**
  3709. * The base implementation of `_.some` without support for iteratee shorthands.
  3710. *
  3711. * @private
  3712. * @param {Array|Object} collection The collection to iterate over.
  3713. * @param {Function} predicate The function invoked per iteration.
  3714. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3715. * else `false`.
  3716. */
  3717. function baseSome(collection, predicate) {
  3718. var result;
  3719. baseEach(collection, function(value, index, collection) {
  3720. result = predicate(value, index, collection);
  3721. return !result;
  3722. });
  3723. return !!result;
  3724. }
  3725. /**
  3726. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3727. * performs a binary search of `array` to determine the index at which `value`
  3728. * should be inserted into `array` in order to maintain its sort order.
  3729. *
  3730. * @private
  3731. * @param {Array} array The sorted array to inspect.
  3732. * @param {*} value The value to evaluate.
  3733. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3734. * @returns {number} Returns the index at which `value` should be inserted
  3735. * into `array`.
  3736. */
  3737. function baseSortedIndex(array, value, retHighest) {
  3738. var low = 0,
  3739. high = array == null ? low : array.length;
  3740. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3741. while (low < high) {
  3742. var mid = (low + high) >>> 1,
  3743. computed = array[mid];
  3744. if (computed !== null && !isSymbol(computed) &&
  3745. (retHighest ? (computed <= value) : (computed < value))) {
  3746. low = mid + 1;
  3747. } else {
  3748. high = mid;
  3749. }
  3750. }
  3751. return high;
  3752. }
  3753. return baseSortedIndexBy(array, value, identity, retHighest);
  3754. }
  3755. /**
  3756. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3757. * which invokes `iteratee` for `value` and each element of `array` to compute
  3758. * their sort ranking. The iteratee is invoked with one argument; (value).
  3759. *
  3760. * @private
  3761. * @param {Array} array The sorted array to inspect.
  3762. * @param {*} value The value to evaluate.
  3763. * @param {Function} iteratee The iteratee invoked per element.
  3764. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3765. * @returns {number} Returns the index at which `value` should be inserted
  3766. * into `array`.
  3767. */
  3768. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3769. value = iteratee(value);
  3770. var low = 0,
  3771. high = array == null ? 0 : array.length,
  3772. valIsNaN = value !== value,
  3773. valIsNull = value === null,
  3774. valIsSymbol = isSymbol(value),
  3775. valIsUndefined = value === undefined;
  3776. while (low < high) {
  3777. var mid = nativeFloor((low + high) / 2),
  3778. computed = iteratee(array[mid]),
  3779. othIsDefined = computed !== undefined,
  3780. othIsNull = computed === null,
  3781. othIsReflexive = computed === computed,
  3782. othIsSymbol = isSymbol(computed);
  3783. if (valIsNaN) {
  3784. var setLow = retHighest || othIsReflexive;
  3785. } else if (valIsUndefined) {
  3786. setLow = othIsReflexive && (retHighest || othIsDefined);
  3787. } else if (valIsNull) {
  3788. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3789. } else if (valIsSymbol) {
  3790. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3791. } else if (othIsNull || othIsSymbol) {
  3792. setLow = false;
  3793. } else {
  3794. setLow = retHighest ? (computed <= value) : (computed < value);
  3795. }
  3796. if (setLow) {
  3797. low = mid + 1;
  3798. } else {
  3799. high = mid;
  3800. }
  3801. }
  3802. return nativeMin(high, MAX_ARRAY_INDEX);
  3803. }
  3804. /**
  3805. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3806. * support for iteratee shorthands.
  3807. *
  3808. * @private
  3809. * @param {Array} array The array to inspect.
  3810. * @param {Function} [iteratee] The iteratee invoked per element.
  3811. * @returns {Array} Returns the new duplicate free array.
  3812. */
  3813. function baseSortedUniq(array, iteratee) {
  3814. var index = -1,
  3815. length = array.length,
  3816. resIndex = 0,
  3817. result = [];
  3818. while (++index < length) {
  3819. var value = array[index],
  3820. computed = iteratee ? iteratee(value) : value;
  3821. if (!index || !eq(computed, seen)) {
  3822. var seen = computed;
  3823. result[resIndex++] = value === 0 ? 0 : value;
  3824. }
  3825. }
  3826. return result;
  3827. }
  3828. /**
  3829. * The base implementation of `_.toNumber` which doesn't ensure correct
  3830. * conversions of binary, hexadecimal, or octal string values.
  3831. *
  3832. * @private
  3833. * @param {*} value The value to process.
  3834. * @returns {number} Returns the number.
  3835. */
  3836. function baseToNumber(value) {
  3837. if (typeof value == 'number') {
  3838. return value;
  3839. }
  3840. if (isSymbol(value)) {
  3841. return NAN;
  3842. }
  3843. return +value;
  3844. }
  3845. /**
  3846. * The base implementation of `_.toString` which doesn't convert nullish
  3847. * values to empty strings.
  3848. *
  3849. * @private
  3850. * @param {*} value The value to process.
  3851. * @returns {string} Returns the string.
  3852. */
  3853. function baseToString(value) {
  3854. // Exit early for strings to avoid a performance hit in some environments.
  3855. if (typeof value == 'string') {
  3856. return value;
  3857. }
  3858. if (isArray(value)) {
  3859. // Recursively convert values (susceptible to call stack limits).
  3860. return arrayMap(value, baseToString) + '';
  3861. }
  3862. if (isSymbol(value)) {
  3863. return symbolToString ? symbolToString.call(value) : '';
  3864. }
  3865. var result = (value + '');
  3866. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3867. }
  3868. /**
  3869. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3870. *
  3871. * @private
  3872. * @param {Array} array The array to inspect.
  3873. * @param {Function} [iteratee] The iteratee invoked per element.
  3874. * @param {Function} [comparator] The comparator invoked per element.
  3875. * @returns {Array} Returns the new duplicate free array.
  3876. */
  3877. function baseUniq(array, iteratee, comparator) {
  3878. var index = -1,
  3879. includes = arrayIncludes,
  3880. length = array.length,
  3881. isCommon = true,
  3882. result = [],
  3883. seen = result;
  3884. if (comparator) {
  3885. isCommon = false;
  3886. includes = arrayIncludesWith;
  3887. }
  3888. else if (length >= LARGE_ARRAY_SIZE) {
  3889. var set = iteratee ? null : createSet(array);
  3890. if (set) {
  3891. return setToArray(set);
  3892. }
  3893. isCommon = false;
  3894. includes = cacheHas;
  3895. seen = new SetCache;
  3896. }
  3897. else {
  3898. seen = iteratee ? [] : result;
  3899. }
  3900. outer:
  3901. while (++index < length) {
  3902. var value = array[index],
  3903. computed = iteratee ? iteratee(value) : value;
  3904. value = (comparator || value !== 0) ? value : 0;
  3905. if (isCommon && computed === computed) {
  3906. var seenIndex = seen.length;
  3907. while (seenIndex--) {
  3908. if (seen[seenIndex] === computed) {
  3909. continue outer;
  3910. }
  3911. }
  3912. if (iteratee) {
  3913. seen.push(computed);
  3914. }
  3915. result.push(value);
  3916. }
  3917. else if (!includes(seen, computed, comparator)) {
  3918. if (seen !== result) {
  3919. seen.push(computed);
  3920. }
  3921. result.push(value);
  3922. }
  3923. }
  3924. return result;
  3925. }
  3926. /**
  3927. * The base implementation of `_.unset`.
  3928. *
  3929. * @private
  3930. * @param {Object} object The object to modify.
  3931. * @param {Array|string} path The property path to unset.
  3932. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3933. */
  3934. function baseUnset(object, path) {
  3935. path = castPath(path, object);
  3936. object = parent(object, path);
  3937. return object == null || delete object[toKey(last(path))];
  3938. }
  3939. /**
  3940. * The base implementation of `_.update`.
  3941. *
  3942. * @private
  3943. * @param {Object} object The object to modify.
  3944. * @param {Array|string} path The path of the property to update.
  3945. * @param {Function} updater The function to produce the updated value.
  3946. * @param {Function} [customizer] The function to customize path creation.
  3947. * @returns {Object} Returns `object`.
  3948. */
  3949. function baseUpdate(object, path, updater, customizer) {
  3950. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3951. }
  3952. /**
  3953. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3954. * without support for iteratee shorthands.
  3955. *
  3956. * @private
  3957. * @param {Array} array The array to query.
  3958. * @param {Function} predicate The function invoked per iteration.
  3959. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3960. * @param {boolean} [fromRight] Specify iterating from right to left.
  3961. * @returns {Array} Returns the slice of `array`.
  3962. */
  3963. function baseWhile(array, predicate, isDrop, fromRight) {
  3964. var length = array.length,
  3965. index = fromRight ? length : -1;
  3966. while ((fromRight ? index-- : ++index < length) &&
  3967. predicate(array[index], index, array)) {}
  3968. return isDrop
  3969. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3970. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3971. }
  3972. /**
  3973. * The base implementation of `wrapperValue` which returns the result of
  3974. * performing a sequence of actions on the unwrapped `value`, where each
  3975. * successive action is supplied the return value of the previous.
  3976. *
  3977. * @private
  3978. * @param {*} value The unwrapped value.
  3979. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3980. * @returns {*} Returns the resolved value.
  3981. */
  3982. function baseWrapperValue(value, actions) {
  3983. var result = value;
  3984. if (result instanceof LazyWrapper) {
  3985. result = result.value();
  3986. }
  3987. return arrayReduce(actions, function(result, action) {
  3988. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3989. }, result);
  3990. }
  3991. /**
  3992. * The base implementation of methods like `_.xor`, without support for
  3993. * iteratee shorthands, that accepts an array of arrays to inspect.
  3994. *
  3995. * @private
  3996. * @param {Array} arrays The arrays to inspect.
  3997. * @param {Function} [iteratee] The iteratee invoked per element.
  3998. * @param {Function} [comparator] The comparator invoked per element.
  3999. * @returns {Array} Returns the new array of values.
  4000. */
  4001. function baseXor(arrays, iteratee, comparator) {
  4002. var length = arrays.length;
  4003. if (length < 2) {
  4004. return length ? baseUniq(arrays[0]) : [];
  4005. }
  4006. var index = -1,
  4007. result = Array(length);
  4008. while (++index < length) {
  4009. var array = arrays[index],
  4010. othIndex = -1;
  4011. while (++othIndex < length) {
  4012. if (othIndex != index) {
  4013. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4014. }
  4015. }
  4016. }
  4017. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4018. }
  4019. /**
  4020. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4021. *
  4022. * @private
  4023. * @param {Array} props The property identifiers.
  4024. * @param {Array} values The property values.
  4025. * @param {Function} assignFunc The function to assign values.
  4026. * @returns {Object} Returns the new object.
  4027. */
  4028. function baseZipObject(props, values, assignFunc) {
  4029. var index = -1,
  4030. length = props.length,
  4031. valsLength = values.length,
  4032. result = {};
  4033. while (++index < length) {
  4034. var value = index < valsLength ? values[index] : undefined;
  4035. assignFunc(result, props[index], value);
  4036. }
  4037. return result;
  4038. }
  4039. /**
  4040. * Casts `value` to an empty array if it's not an array like object.
  4041. *
  4042. * @private
  4043. * @param {*} value The value to inspect.
  4044. * @returns {Array|Object} Returns the cast array-like object.
  4045. */
  4046. function castArrayLikeObject(value) {
  4047. return isArrayLikeObject(value) ? value : [];
  4048. }
  4049. /**
  4050. * Casts `value` to `identity` if it's not a function.
  4051. *
  4052. * @private
  4053. * @param {*} value The value to inspect.
  4054. * @returns {Function} Returns cast function.
  4055. */
  4056. function castFunction(value) {
  4057. return typeof value == 'function' ? value : identity;
  4058. }
  4059. /**
  4060. * Casts `value` to a path array if it's not one.
  4061. *
  4062. * @private
  4063. * @param {*} value The value to inspect.
  4064. * @param {Object} [object] The object to query keys on.
  4065. * @returns {Array} Returns the cast property path array.
  4066. */
  4067. function castPath(value, object) {
  4068. if (isArray(value)) {
  4069. return value;
  4070. }
  4071. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4072. }
  4073. /**
  4074. * A `baseRest` alias which can be replaced with `identity` by module
  4075. * replacement plugins.
  4076. *
  4077. * @private
  4078. * @type {Function}
  4079. * @param {Function} func The function to apply a rest parameter to.
  4080. * @returns {Function} Returns the new function.
  4081. */
  4082. var castRest = baseRest;
  4083. /**
  4084. * Casts `array` to a slice if it's needed.
  4085. *
  4086. * @private
  4087. * @param {Array} array The array to inspect.
  4088. * @param {number} start The start position.
  4089. * @param {number} [end=array.length] The end position.
  4090. * @returns {Array} Returns the cast slice.
  4091. */
  4092. function castSlice(array, start, end) {
  4093. var length = array.length;
  4094. end = end === undefined ? length : end;
  4095. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4096. }
  4097. /**
  4098. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4099. *
  4100. * @private
  4101. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4102. */
  4103. var clearTimeout = ctxClearTimeout || function(id) {
  4104. return root.clearTimeout(id);
  4105. };
  4106. /**
  4107. * Creates a clone of `buffer`.
  4108. *
  4109. * @private
  4110. * @param {Buffer} buffer The buffer to clone.
  4111. * @param {boolean} [isDeep] Specify a deep clone.
  4112. * @returns {Buffer} Returns the cloned buffer.
  4113. */
  4114. function cloneBuffer(buffer, isDeep) {
  4115. if (isDeep) {
  4116. return buffer.slice();
  4117. }
  4118. var length = buffer.length,
  4119. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4120. buffer.copy(result);
  4121. return result;
  4122. }
  4123. /**
  4124. * Creates a clone of `arrayBuffer`.
  4125. *
  4126. * @private
  4127. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4128. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4129. */
  4130. function cloneArrayBuffer(arrayBuffer) {
  4131. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4132. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4133. return result;
  4134. }
  4135. /**
  4136. * Creates a clone of `dataView`.
  4137. *
  4138. * @private
  4139. * @param {Object} dataView The data view to clone.
  4140. * @param {boolean} [isDeep] Specify a deep clone.
  4141. * @returns {Object} Returns the cloned data view.
  4142. */
  4143. function cloneDataView(dataView, isDeep) {
  4144. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4145. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4146. }
  4147. /**
  4148. * Creates a clone of `regexp`.
  4149. *
  4150. * @private
  4151. * @param {Object} regexp The regexp to clone.
  4152. * @returns {Object} Returns the cloned regexp.
  4153. */
  4154. function cloneRegExp(regexp) {
  4155. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4156. result.lastIndex = regexp.lastIndex;
  4157. return result;
  4158. }
  4159. /**
  4160. * Creates a clone of the `symbol` object.
  4161. *
  4162. * @private
  4163. * @param {Object} symbol The symbol object to clone.
  4164. * @returns {Object} Returns the cloned symbol object.
  4165. */
  4166. function cloneSymbol(symbol) {
  4167. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4168. }
  4169. /**
  4170. * Creates a clone of `typedArray`.
  4171. *
  4172. * @private
  4173. * @param {Object} typedArray The typed array to clone.
  4174. * @param {boolean} [isDeep] Specify a deep clone.
  4175. * @returns {Object} Returns the cloned typed array.
  4176. */
  4177. function cloneTypedArray(typedArray, isDeep) {
  4178. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4179. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4180. }
  4181. /**
  4182. * Compares values to sort them in ascending order.
  4183. *
  4184. * @private
  4185. * @param {*} value The value to compare.
  4186. * @param {*} other The other value to compare.
  4187. * @returns {number} Returns the sort order indicator for `value`.
  4188. */
  4189. function compareAscending(value, other) {
  4190. if (value !== other) {
  4191. var valIsDefined = value !== undefined,
  4192. valIsNull = value === null,
  4193. valIsReflexive = value === value,
  4194. valIsSymbol = isSymbol(value);
  4195. var othIsDefined = other !== undefined,
  4196. othIsNull = other === null,
  4197. othIsReflexive = other === other,
  4198. othIsSymbol = isSymbol(other);
  4199. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4200. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4201. (valIsNull && othIsDefined && othIsReflexive) ||
  4202. (!valIsDefined && othIsReflexive) ||
  4203. !valIsReflexive) {
  4204. return 1;
  4205. }
  4206. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4207. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4208. (othIsNull && valIsDefined && valIsReflexive) ||
  4209. (!othIsDefined && valIsReflexive) ||
  4210. !othIsReflexive) {
  4211. return -1;
  4212. }
  4213. }
  4214. return 0;
  4215. }
  4216. /**
  4217. * Used by `_.orderBy` to compare multiple properties of a value to another
  4218. * and stable sort them.
  4219. *
  4220. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4221. * specify an order of "desc" for descending or "asc" for ascending sort order
  4222. * of corresponding values.
  4223. *
  4224. * @private
  4225. * @param {Object} object The object to compare.
  4226. * @param {Object} other The other object to compare.
  4227. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4228. * @returns {number} Returns the sort order indicator for `object`.
  4229. */
  4230. function compareMultiple(object, other, orders) {
  4231. var index = -1,
  4232. objCriteria = object.criteria,
  4233. othCriteria = other.criteria,
  4234. length = objCriteria.length,
  4235. ordersLength = orders.length;
  4236. while (++index < length) {
  4237. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4238. if (result) {
  4239. if (index >= ordersLength) {
  4240. return result;
  4241. }
  4242. var order = orders[index];
  4243. return result * (order == 'desc' ? -1 : 1);
  4244. }
  4245. }
  4246. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4247. // that causes it, under certain circumstances, to provide the same value for
  4248. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4249. // for more details.
  4250. //
  4251. // This also ensures a stable sort in V8 and other engines.
  4252. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4253. return object.index - other.index;
  4254. }
  4255. /**
  4256. * Creates an array that is the composition of partially applied arguments,
  4257. * placeholders, and provided arguments into a single array of arguments.
  4258. *
  4259. * @private
  4260. * @param {Array} args The provided arguments.
  4261. * @param {Array} partials The arguments to prepend to those provided.
  4262. * @param {Array} holders The `partials` placeholder indexes.
  4263. * @params {boolean} [isCurried] Specify composing for a curried function.
  4264. * @returns {Array} Returns the new array of composed arguments.
  4265. */
  4266. function composeArgs(args, partials, holders, isCurried) {
  4267. var argsIndex = -1,
  4268. argsLength = args.length,
  4269. holdersLength = holders.length,
  4270. leftIndex = -1,
  4271. leftLength = partials.length,
  4272. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4273. result = Array(leftLength + rangeLength),
  4274. isUncurried = !isCurried;
  4275. while (++leftIndex < leftLength) {
  4276. result[leftIndex] = partials[leftIndex];
  4277. }
  4278. while (++argsIndex < holdersLength) {
  4279. if (isUncurried || argsIndex < argsLength) {
  4280. result[holders[argsIndex]] = args[argsIndex];
  4281. }
  4282. }
  4283. while (rangeLength--) {
  4284. result[leftIndex++] = args[argsIndex++];
  4285. }
  4286. return result;
  4287. }
  4288. /**
  4289. * This function is like `composeArgs` except that the arguments composition
  4290. * is tailored for `_.partialRight`.
  4291. *
  4292. * @private
  4293. * @param {Array} args The provided arguments.
  4294. * @param {Array} partials The arguments to append to those provided.
  4295. * @param {Array} holders The `partials` placeholder indexes.
  4296. * @params {boolean} [isCurried] Specify composing for a curried function.
  4297. * @returns {Array} Returns the new array of composed arguments.
  4298. */
  4299. function composeArgsRight(args, partials, holders, isCurried) {
  4300. var argsIndex = -1,
  4301. argsLength = args.length,
  4302. holdersIndex = -1,
  4303. holdersLength = holders.length,
  4304. rightIndex = -1,
  4305. rightLength = partials.length,
  4306. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4307. result = Array(rangeLength + rightLength),
  4308. isUncurried = !isCurried;
  4309. while (++argsIndex < rangeLength) {
  4310. result[argsIndex] = args[argsIndex];
  4311. }
  4312. var offset = argsIndex;
  4313. while (++rightIndex < rightLength) {
  4314. result[offset + rightIndex] = partials[rightIndex];
  4315. }
  4316. while (++holdersIndex < holdersLength) {
  4317. if (isUncurried || argsIndex < argsLength) {
  4318. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4319. }
  4320. }
  4321. return result;
  4322. }
  4323. /**
  4324. * Copies the values of `source` to `array`.
  4325. *
  4326. * @private
  4327. * @param {Array} source The array to copy values from.
  4328. * @param {Array} [array=[]] The array to copy values to.
  4329. * @returns {Array} Returns `array`.
  4330. */
  4331. function copyArray(source, array) {
  4332. var index = -1,
  4333. length = source.length;
  4334. array || (array = Array(length));
  4335. while (++index < length) {
  4336. array[index] = source[index];
  4337. }
  4338. return array;
  4339. }
  4340. /**
  4341. * Copies properties of `source` to `object`.
  4342. *
  4343. * @private
  4344. * @param {Object} source The object to copy properties from.
  4345. * @param {Array} props The property identifiers to copy.
  4346. * @param {Object} [object={}] The object to copy properties to.
  4347. * @param {Function} [customizer] The function to customize copied values.
  4348. * @returns {Object} Returns `object`.
  4349. */
  4350. function copyObject(source, props, object, customizer) {
  4351. var isNew = !object;
  4352. object || (object = {});
  4353. var index = -1,
  4354. length = props.length;
  4355. while (++index < length) {
  4356. var key = props[index];
  4357. var newValue = customizer
  4358. ? customizer(object[key], source[key], key, object, source)
  4359. : undefined;
  4360. if (newValue === undefined) {
  4361. newValue = source[key];
  4362. }
  4363. if (isNew) {
  4364. baseAssignValue(object, key, newValue);
  4365. } else {
  4366. assignValue(object, key, newValue);
  4367. }
  4368. }
  4369. return object;
  4370. }
  4371. /**
  4372. * Copies own symbols of `source` to `object`.
  4373. *
  4374. * @private
  4375. * @param {Object} source The object to copy symbols from.
  4376. * @param {Object} [object={}] The object to copy symbols to.
  4377. * @returns {Object} Returns `object`.
  4378. */
  4379. function copySymbols(source, object) {
  4380. return copyObject(source, getSymbols(source), object);
  4381. }
  4382. /**
  4383. * Copies own and inherited symbols of `source` to `object`.
  4384. *
  4385. * @private
  4386. * @param {Object} source The object to copy symbols from.
  4387. * @param {Object} [object={}] The object to copy symbols to.
  4388. * @returns {Object} Returns `object`.
  4389. */
  4390. function copySymbolsIn(source, object) {
  4391. return copyObject(source, getSymbolsIn(source), object);
  4392. }
  4393. /**
  4394. * Creates a function like `_.groupBy`.
  4395. *
  4396. * @private
  4397. * @param {Function} setter The function to set accumulator values.
  4398. * @param {Function} [initializer] The accumulator object initializer.
  4399. * @returns {Function} Returns the new aggregator function.
  4400. */
  4401. function createAggregator(setter, initializer) {
  4402. return function(collection, iteratee) {
  4403. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4404. accumulator = initializer ? initializer() : {};
  4405. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4406. };
  4407. }
  4408. /**
  4409. * Creates a function like `_.assign`.
  4410. *
  4411. * @private
  4412. * @param {Function} assigner The function to assign values.
  4413. * @returns {Function} Returns the new assigner function.
  4414. */
  4415. function createAssigner(assigner) {
  4416. return baseRest(function(object, sources) {
  4417. var index = -1,
  4418. length = sources.length,
  4419. customizer = length > 1 ? sources[length - 1] : undefined,
  4420. guard = length > 2 ? sources[2] : undefined;
  4421. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4422. ? (length--, customizer)
  4423. : undefined;
  4424. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4425. customizer = length < 3 ? undefined : customizer;
  4426. length = 1;
  4427. }
  4428. object = Object(object);
  4429. while (++index < length) {
  4430. var source = sources[index];
  4431. if (source) {
  4432. assigner(object, source, index, customizer);
  4433. }
  4434. }
  4435. return object;
  4436. });
  4437. }
  4438. /**
  4439. * Creates a `baseEach` or `baseEachRight` function.
  4440. *
  4441. * @private
  4442. * @param {Function} eachFunc The function to iterate over a collection.
  4443. * @param {boolean} [fromRight] Specify iterating from right to left.
  4444. * @returns {Function} Returns the new base function.
  4445. */
  4446. function createBaseEach(eachFunc, fromRight) {
  4447. return function(collection, iteratee) {
  4448. if (collection == null) {
  4449. return collection;
  4450. }
  4451. if (!isArrayLike(collection)) {
  4452. return eachFunc(collection, iteratee);
  4453. }
  4454. var length = collection.length,
  4455. index = fromRight ? length : -1,
  4456. iterable = Object(collection);
  4457. while ((fromRight ? index-- : ++index < length)) {
  4458. if (iteratee(iterable[index], index, iterable) === false) {
  4459. break;
  4460. }
  4461. }
  4462. return collection;
  4463. };
  4464. }
  4465. /**
  4466. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4467. *
  4468. * @private
  4469. * @param {boolean} [fromRight] Specify iterating from right to left.
  4470. * @returns {Function} Returns the new base function.
  4471. */
  4472. function createBaseFor(fromRight) {
  4473. return function(object, iteratee, keysFunc) {
  4474. var index = -1,
  4475. iterable = Object(object),
  4476. props = keysFunc(object),
  4477. length = props.length;
  4478. while (length--) {
  4479. var key = props[fromRight ? length : ++index];
  4480. if (iteratee(iterable[key], key, iterable) === false) {
  4481. break;
  4482. }
  4483. }
  4484. return object;
  4485. };
  4486. }
  4487. /**
  4488. * Creates a function that wraps `func` to invoke it with the optional `this`
  4489. * binding of `thisArg`.
  4490. *
  4491. * @private
  4492. * @param {Function} func The function to wrap.
  4493. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4494. * @param {*} [thisArg] The `this` binding of `func`.
  4495. * @returns {Function} Returns the new wrapped function.
  4496. */
  4497. function createBind(func, bitmask, thisArg) {
  4498. var isBind = bitmask & WRAP_BIND_FLAG,
  4499. Ctor = createCtor(func);
  4500. function wrapper() {
  4501. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4502. return fn.apply(isBind ? thisArg : this, arguments);
  4503. }
  4504. return wrapper;
  4505. }
  4506. /**
  4507. * Creates a function like `_.lowerFirst`.
  4508. *
  4509. * @private
  4510. * @param {string} methodName The name of the `String` case method to use.
  4511. * @returns {Function} Returns the new case function.
  4512. */
  4513. function createCaseFirst(methodName) {
  4514. return function(string) {
  4515. string = toString(string);
  4516. var strSymbols = hasUnicode(string)
  4517. ? stringToArray(string)
  4518. : undefined;
  4519. var chr = strSymbols
  4520. ? strSymbols[0]
  4521. : string.charAt(0);
  4522. var trailing = strSymbols
  4523. ? castSlice(strSymbols, 1).join('')
  4524. : string.slice(1);
  4525. return chr[methodName]() + trailing;
  4526. };
  4527. }
  4528. /**
  4529. * Creates a function like `_.camelCase`.
  4530. *
  4531. * @private
  4532. * @param {Function} callback The function to combine each word.
  4533. * @returns {Function} Returns the new compounder function.
  4534. */
  4535. function createCompounder(callback) {
  4536. return function(string) {
  4537. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4538. };
  4539. }
  4540. /**
  4541. * Creates a function that produces an instance of `Ctor` regardless of
  4542. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4543. *
  4544. * @private
  4545. * @param {Function} Ctor The constructor to wrap.
  4546. * @returns {Function} Returns the new wrapped function.
  4547. */
  4548. function createCtor(Ctor) {
  4549. return function() {
  4550. // Use a `switch` statement to work with class constructors. See
  4551. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4552. // for more details.
  4553. var args = arguments;
  4554. switch (args.length) {
  4555. case 0: return new Ctor;
  4556. case 1: return new Ctor(args[0]);
  4557. case 2: return new Ctor(args[0], args[1]);
  4558. case 3: return new Ctor(args[0], args[1], args[2]);
  4559. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4560. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4561. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4562. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4563. }
  4564. var thisBinding = baseCreate(Ctor.prototype),
  4565. result = Ctor.apply(thisBinding, args);
  4566. // Mimic the constructor's `return` behavior.
  4567. // See https://es5.github.io/#x13.2.2 for more details.
  4568. return isObject(result) ? result : thisBinding;
  4569. };
  4570. }
  4571. /**
  4572. * Creates a function that wraps `func` to enable currying.
  4573. *
  4574. * @private
  4575. * @param {Function} func The function to wrap.
  4576. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4577. * @param {number} arity The arity of `func`.
  4578. * @returns {Function} Returns the new wrapped function.
  4579. */
  4580. function createCurry(func, bitmask, arity) {
  4581. var Ctor = createCtor(func);
  4582. function wrapper() {
  4583. var length = arguments.length,
  4584. args = Array(length),
  4585. index = length,
  4586. placeholder = getHolder(wrapper);
  4587. while (index--) {
  4588. args[index] = arguments[index];
  4589. }
  4590. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4591. ? []
  4592. : replaceHolders(args, placeholder);
  4593. length -= holders.length;
  4594. if (length < arity) {
  4595. return createRecurry(
  4596. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4597. args, holders, undefined, undefined, arity - length);
  4598. }
  4599. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4600. return apply(fn, this, args);
  4601. }
  4602. return wrapper;
  4603. }
  4604. /**
  4605. * Creates a `_.find` or `_.findLast` function.
  4606. *
  4607. * @private
  4608. * @param {Function} findIndexFunc The function to find the collection index.
  4609. * @returns {Function} Returns the new find function.
  4610. */
  4611. function createFind(findIndexFunc) {
  4612. return function(collection, predicate, fromIndex) {
  4613. var iterable = Object(collection);
  4614. if (!isArrayLike(collection)) {
  4615. var iteratee = getIteratee(predicate, 3);
  4616. collection = keys(collection);
  4617. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4618. }
  4619. var index = findIndexFunc(collection, predicate, fromIndex);
  4620. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4621. };
  4622. }
  4623. /**
  4624. * Creates a `_.flow` or `_.flowRight` function.
  4625. *
  4626. * @private
  4627. * @param {boolean} [fromRight] Specify iterating from right to left.
  4628. * @returns {Function} Returns the new flow function.
  4629. */
  4630. function createFlow(fromRight) {
  4631. return flatRest(function(funcs) {
  4632. var length = funcs.length,
  4633. index = length,
  4634. prereq = LodashWrapper.prototype.thru;
  4635. if (fromRight) {
  4636. funcs.reverse();
  4637. }
  4638. while (index--) {
  4639. var func = funcs[index];
  4640. if (typeof func != 'function') {
  4641. throw new TypeError(FUNC_ERROR_TEXT);
  4642. }
  4643. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4644. var wrapper = new LodashWrapper([], true);
  4645. }
  4646. }
  4647. index = wrapper ? index : length;
  4648. while (++index < length) {
  4649. func = funcs[index];
  4650. var funcName = getFuncName(func),
  4651. data = funcName == 'wrapper' ? getData(func) : undefined;
  4652. if (data && isLaziable(data[0]) &&
  4653. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4654. !data[4].length && data[9] == 1
  4655. ) {
  4656. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4657. } else {
  4658. wrapper = (func.length == 1 && isLaziable(func))
  4659. ? wrapper[funcName]()
  4660. : wrapper.thru(func);
  4661. }
  4662. }
  4663. return function() {
  4664. var args = arguments,
  4665. value = args[0];
  4666. if (wrapper && args.length == 1 && isArray(value)) {
  4667. return wrapper.plant(value).value();
  4668. }
  4669. var index = 0,
  4670. result = length ? funcs[index].apply(this, args) : value;
  4671. while (++index < length) {
  4672. result = funcs[index].call(this, result);
  4673. }
  4674. return result;
  4675. };
  4676. });
  4677. }
  4678. /**
  4679. * Creates a function that wraps `func` to invoke it with optional `this`
  4680. * binding of `thisArg`, partial application, and currying.
  4681. *
  4682. * @private
  4683. * @param {Function|string} func The function or method name to wrap.
  4684. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4685. * @param {*} [thisArg] The `this` binding of `func`.
  4686. * @param {Array} [partials] The arguments to prepend to those provided to
  4687. * the new function.
  4688. * @param {Array} [holders] The `partials` placeholder indexes.
  4689. * @param {Array} [partialsRight] The arguments to append to those provided
  4690. * to the new function.
  4691. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4692. * @param {Array} [argPos] The argument positions of the new function.
  4693. * @param {number} [ary] The arity cap of `func`.
  4694. * @param {number} [arity] The arity of `func`.
  4695. * @returns {Function} Returns the new wrapped function.
  4696. */
  4697. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4698. var isAry = bitmask & WRAP_ARY_FLAG,
  4699. isBind = bitmask & WRAP_BIND_FLAG,
  4700. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4701. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4702. isFlip = bitmask & WRAP_FLIP_FLAG,
  4703. Ctor = isBindKey ? undefined : createCtor(func);
  4704. function wrapper() {
  4705. var length = arguments.length,
  4706. args = Array(length),
  4707. index = length;
  4708. while (index--) {
  4709. args[index] = arguments[index];
  4710. }
  4711. if (isCurried) {
  4712. var placeholder = getHolder(wrapper),
  4713. holdersCount = countHolders(args, placeholder);
  4714. }
  4715. if (partials) {
  4716. args = composeArgs(args, partials, holders, isCurried);
  4717. }
  4718. if (partialsRight) {
  4719. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4720. }
  4721. length -= holdersCount;
  4722. if (isCurried && length < arity) {
  4723. var newHolders = replaceHolders(args, placeholder);
  4724. return createRecurry(
  4725. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4726. args, newHolders, argPos, ary, arity - length
  4727. );
  4728. }
  4729. var thisBinding = isBind ? thisArg : this,
  4730. fn = isBindKey ? thisBinding[func] : func;
  4731. length = args.length;
  4732. if (argPos) {
  4733. args = reorder(args, argPos);
  4734. } else if (isFlip && length > 1) {
  4735. args.reverse();
  4736. }
  4737. if (isAry && ary < length) {
  4738. args.length = ary;
  4739. }
  4740. if (this && this !== root && this instanceof wrapper) {
  4741. fn = Ctor || createCtor(fn);
  4742. }
  4743. return fn.apply(thisBinding, args);
  4744. }
  4745. return wrapper;
  4746. }
  4747. /**
  4748. * Creates a function like `_.invertBy`.
  4749. *
  4750. * @private
  4751. * @param {Function} setter The function to set accumulator values.
  4752. * @param {Function} toIteratee The function to resolve iteratees.
  4753. * @returns {Function} Returns the new inverter function.
  4754. */
  4755. function createInverter(setter, toIteratee) {
  4756. return function(object, iteratee) {
  4757. return baseInverter(object, setter, toIteratee(iteratee), {});
  4758. };
  4759. }
  4760. /**
  4761. * Creates a function that performs a mathematical operation on two values.
  4762. *
  4763. * @private
  4764. * @param {Function} operator The function to perform the operation.
  4765. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4766. * @returns {Function} Returns the new mathematical operation function.
  4767. */
  4768. function createMathOperation(operator, defaultValue) {
  4769. return function(value, other) {
  4770. var result;
  4771. if (value === undefined && other === undefined) {
  4772. return defaultValue;
  4773. }
  4774. if (value !== undefined) {
  4775. result = value;
  4776. }
  4777. if (other !== undefined) {
  4778. if (result === undefined) {
  4779. return other;
  4780. }
  4781. if (typeof value == 'string' || typeof other == 'string') {
  4782. value = baseToString(value);
  4783. other = baseToString(other);
  4784. } else {
  4785. value = baseToNumber(value);
  4786. other = baseToNumber(other);
  4787. }
  4788. result = operator(value, other);
  4789. }
  4790. return result;
  4791. };
  4792. }
  4793. /**
  4794. * Creates a function like `_.over`.
  4795. *
  4796. * @private
  4797. * @param {Function} arrayFunc The function to iterate over iteratees.
  4798. * @returns {Function} Returns the new over function.
  4799. */
  4800. function createOver(arrayFunc) {
  4801. return flatRest(function(iteratees) {
  4802. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4803. return baseRest(function(args) {
  4804. var thisArg = this;
  4805. return arrayFunc(iteratees, function(iteratee) {
  4806. return apply(iteratee, thisArg, args);
  4807. });
  4808. });
  4809. });
  4810. }
  4811. /**
  4812. * Creates the padding for `string` based on `length`. The `chars` string
  4813. * is truncated if the number of characters exceeds `length`.
  4814. *
  4815. * @private
  4816. * @param {number} length The padding length.
  4817. * @param {string} [chars=' '] The string used as padding.
  4818. * @returns {string} Returns the padding for `string`.
  4819. */
  4820. function createPadding(length, chars) {
  4821. chars = chars === undefined ? ' ' : baseToString(chars);
  4822. var charsLength = chars.length;
  4823. if (charsLength < 2) {
  4824. return charsLength ? baseRepeat(chars, length) : chars;
  4825. }
  4826. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4827. return hasUnicode(chars)
  4828. ? castSlice(stringToArray(result), 0, length).join('')
  4829. : result.slice(0, length);
  4830. }
  4831. /**
  4832. * Creates a function that wraps `func` to invoke it with the `this` binding
  4833. * of `thisArg` and `partials` prepended to the arguments it receives.
  4834. *
  4835. * @private
  4836. * @param {Function} func The function to wrap.
  4837. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4838. * @param {*} thisArg The `this` binding of `func`.
  4839. * @param {Array} partials The arguments to prepend to those provided to
  4840. * the new function.
  4841. * @returns {Function} Returns the new wrapped function.
  4842. */
  4843. function createPartial(func, bitmask, thisArg, partials) {
  4844. var isBind = bitmask & WRAP_BIND_FLAG,
  4845. Ctor = createCtor(func);
  4846. function wrapper() {
  4847. var argsIndex = -1,
  4848. argsLength = arguments.length,
  4849. leftIndex = -1,
  4850. leftLength = partials.length,
  4851. args = Array(leftLength + argsLength),
  4852. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4853. while (++leftIndex < leftLength) {
  4854. args[leftIndex] = partials[leftIndex];
  4855. }
  4856. while (argsLength--) {
  4857. args[leftIndex++] = arguments[++argsIndex];
  4858. }
  4859. return apply(fn, isBind ? thisArg : this, args);
  4860. }
  4861. return wrapper;
  4862. }
  4863. /**
  4864. * Creates a `_.range` or `_.rangeRight` function.
  4865. *
  4866. * @private
  4867. * @param {boolean} [fromRight] Specify iterating from right to left.
  4868. * @returns {Function} Returns the new range function.
  4869. */
  4870. function createRange(fromRight) {
  4871. return function(start, end, step) {
  4872. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4873. end = step = undefined;
  4874. }
  4875. // Ensure the sign of `-0` is preserved.
  4876. start = toFinite(start);
  4877. if (end === undefined) {
  4878. end = start;
  4879. start = 0;
  4880. } else {
  4881. end = toFinite(end);
  4882. }
  4883. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4884. return baseRange(start, end, step, fromRight);
  4885. };
  4886. }
  4887. /**
  4888. * Creates a function that performs a relational operation on two values.
  4889. *
  4890. * @private
  4891. * @param {Function} operator The function to perform the operation.
  4892. * @returns {Function} Returns the new relational operation function.
  4893. */
  4894. function createRelationalOperation(operator) {
  4895. return function(value, other) {
  4896. if (!(typeof value == 'string' && typeof other == 'string')) {
  4897. value = toNumber(value);
  4898. other = toNumber(other);
  4899. }
  4900. return operator(value, other);
  4901. };
  4902. }
  4903. /**
  4904. * Creates a function that wraps `func` to continue currying.
  4905. *
  4906. * @private
  4907. * @param {Function} func The function to wrap.
  4908. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4909. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4910. * @param {*} placeholder The placeholder value.
  4911. * @param {*} [thisArg] The `this` binding of `func`.
  4912. * @param {Array} [partials] The arguments to prepend to those provided to
  4913. * the new function.
  4914. * @param {Array} [holders] The `partials` placeholder indexes.
  4915. * @param {Array} [argPos] The argument positions of the new function.
  4916. * @param {number} [ary] The arity cap of `func`.
  4917. * @param {number} [arity] The arity of `func`.
  4918. * @returns {Function} Returns the new wrapped function.
  4919. */
  4920. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4921. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4922. newHolders = isCurry ? holders : undefined,
  4923. newHoldersRight = isCurry ? undefined : holders,
  4924. newPartials = isCurry ? partials : undefined,
  4925. newPartialsRight = isCurry ? undefined : partials;
  4926. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4927. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4928. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4929. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4930. }
  4931. var newData = [
  4932. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4933. newHoldersRight, argPos, ary, arity
  4934. ];
  4935. var result = wrapFunc.apply(undefined, newData);
  4936. if (isLaziable(func)) {
  4937. setData(result, newData);
  4938. }
  4939. result.placeholder = placeholder;
  4940. return setWrapToString(result, func, bitmask);
  4941. }
  4942. /**
  4943. * Creates a function like `_.round`.
  4944. *
  4945. * @private
  4946. * @param {string} methodName The name of the `Math` method to use when rounding.
  4947. * @returns {Function} Returns the new round function.
  4948. */
  4949. function createRound(methodName) {
  4950. var func = Math[methodName];
  4951. return function(number, precision) {
  4952. number = toNumber(number);
  4953. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4954. if (precision) {
  4955. // Shift with exponential notation to avoid floating-point issues.
  4956. // See [MDN](https://mdn.io/round#Examples) for more details.
  4957. var pair = (toString(number) + 'e').split('e'),
  4958. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4959. pair = (toString(value) + 'e').split('e');
  4960. return +(pair[0] + 'e' + (+pair[1] - precision));
  4961. }
  4962. return func(number);
  4963. };
  4964. }
  4965. /**
  4966. * Creates a set object of `values`.
  4967. *
  4968. * @private
  4969. * @param {Array} values The values to add to the set.
  4970. * @returns {Object} Returns the new set.
  4971. */
  4972. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4973. return new Set(values);
  4974. };
  4975. /**
  4976. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4977. *
  4978. * @private
  4979. * @param {Function} keysFunc The function to get the keys of a given object.
  4980. * @returns {Function} Returns the new pairs function.
  4981. */
  4982. function createToPairs(keysFunc) {
  4983. return function(object) {
  4984. var tag = getTag(object);
  4985. if (tag == mapTag) {
  4986. return mapToArray(object);
  4987. }
  4988. if (tag == setTag) {
  4989. return setToPairs(object);
  4990. }
  4991. return baseToPairs(object, keysFunc(object));
  4992. };
  4993. }
  4994. /**
  4995. * Creates a function that either curries or invokes `func` with optional
  4996. * `this` binding and partially applied arguments.
  4997. *
  4998. * @private
  4999. * @param {Function|string} func The function or method name to wrap.
  5000. * @param {number} bitmask The bitmask flags.
  5001. * 1 - `_.bind`
  5002. * 2 - `_.bindKey`
  5003. * 4 - `_.curry` or `_.curryRight` of a bound function
  5004. * 8 - `_.curry`
  5005. * 16 - `_.curryRight`
  5006. * 32 - `_.partial`
  5007. * 64 - `_.partialRight`
  5008. * 128 - `_.rearg`
  5009. * 256 - `_.ary`
  5010. * 512 - `_.flip`
  5011. * @param {*} [thisArg] The `this` binding of `func`.
  5012. * @param {Array} [partials] The arguments to be partially applied.
  5013. * @param {Array} [holders] The `partials` placeholder indexes.
  5014. * @param {Array} [argPos] The argument positions of the new function.
  5015. * @param {number} [ary] The arity cap of `func`.
  5016. * @param {number} [arity] The arity of `func`.
  5017. * @returns {Function} Returns the new wrapped function.
  5018. */
  5019. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5020. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5021. if (!isBindKey && typeof func != 'function') {
  5022. throw new TypeError(FUNC_ERROR_TEXT);
  5023. }
  5024. var length = partials ? partials.length : 0;
  5025. if (!length) {
  5026. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5027. partials = holders = undefined;
  5028. }
  5029. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5030. arity = arity === undefined ? arity : toInteger(arity);
  5031. length -= holders ? holders.length : 0;
  5032. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5033. var partialsRight = partials,
  5034. holdersRight = holders;
  5035. partials = holders = undefined;
  5036. }
  5037. var data = isBindKey ? undefined : getData(func);
  5038. var newData = [
  5039. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5040. argPos, ary, arity
  5041. ];
  5042. if (data) {
  5043. mergeData(newData, data);
  5044. }
  5045. func = newData[0];
  5046. bitmask = newData[1];
  5047. thisArg = newData[2];
  5048. partials = newData[3];
  5049. holders = newData[4];
  5050. arity = newData[9] = newData[9] === undefined
  5051. ? (isBindKey ? 0 : func.length)
  5052. : nativeMax(newData[9] - length, 0);
  5053. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5054. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5055. }
  5056. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5057. var result = createBind(func, bitmask, thisArg);
  5058. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5059. result = createCurry(func, bitmask, arity);
  5060. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5061. result = createPartial(func, bitmask, thisArg, partials);
  5062. } else {
  5063. result = createHybrid.apply(undefined, newData);
  5064. }
  5065. var setter = data ? baseSetData : setData;
  5066. return setWrapToString(setter(result, newData), func, bitmask);
  5067. }
  5068. /**
  5069. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5070. * of source objects to the destination object for all destination properties
  5071. * that resolve to `undefined`.
  5072. *
  5073. * @private
  5074. * @param {*} objValue The destination value.
  5075. * @param {*} srcValue The source value.
  5076. * @param {string} key The key of the property to assign.
  5077. * @param {Object} object The parent object of `objValue`.
  5078. * @returns {*} Returns the value to assign.
  5079. */
  5080. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5081. if (objValue === undefined ||
  5082. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5083. return srcValue;
  5084. }
  5085. return objValue;
  5086. }
  5087. /**
  5088. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5089. * objects into destination objects that are passed thru.
  5090. *
  5091. * @private
  5092. * @param {*} objValue The destination value.
  5093. * @param {*} srcValue The source value.
  5094. * @param {string} key The key of the property to merge.
  5095. * @param {Object} object The parent object of `objValue`.
  5096. * @param {Object} source The parent object of `srcValue`.
  5097. * @param {Object} [stack] Tracks traversed source values and their merged
  5098. * counterparts.
  5099. * @returns {*} Returns the value to assign.
  5100. */
  5101. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5102. if (isObject(objValue) && isObject(srcValue)) {
  5103. // Recursively merge objects and arrays (susceptible to call stack limits).
  5104. stack.set(srcValue, objValue);
  5105. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5106. stack['delete'](srcValue);
  5107. }
  5108. return objValue;
  5109. }
  5110. /**
  5111. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5112. * objects.
  5113. *
  5114. * @private
  5115. * @param {*} value The value to inspect.
  5116. * @param {string} key The key of the property to inspect.
  5117. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5118. */
  5119. function customOmitClone(value) {
  5120. return isPlainObject(value) ? undefined : value;
  5121. }
  5122. /**
  5123. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5124. * partial deep comparisons.
  5125. *
  5126. * @private
  5127. * @param {Array} array The array to compare.
  5128. * @param {Array} other The other array to compare.
  5129. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5130. * @param {Function} customizer The function to customize comparisons.
  5131. * @param {Function} equalFunc The function to determine equivalents of values.
  5132. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5133. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5134. */
  5135. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5136. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5137. arrLength = array.length,
  5138. othLength = other.length;
  5139. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5140. return false;
  5141. }
  5142. // Assume cyclic values are equal.
  5143. var stacked = stack.get(array);
  5144. if (stacked && stack.get(other)) {
  5145. return stacked == other;
  5146. }
  5147. var index = -1,
  5148. result = true,
  5149. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5150. stack.set(array, other);
  5151. stack.set(other, array);
  5152. // Ignore non-index properties.
  5153. while (++index < arrLength) {
  5154. var arrValue = array[index],
  5155. othValue = other[index];
  5156. if (customizer) {
  5157. var compared = isPartial
  5158. ? customizer(othValue, arrValue, index, other, array, stack)
  5159. : customizer(arrValue, othValue, index, array, other, stack);
  5160. }
  5161. if (compared !== undefined) {
  5162. if (compared) {
  5163. continue;
  5164. }
  5165. result = false;
  5166. break;
  5167. }
  5168. // Recursively compare arrays (susceptible to call stack limits).
  5169. if (seen) {
  5170. if (!arraySome(other, function(othValue, othIndex) {
  5171. if (!cacheHas(seen, othIndex) &&
  5172. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5173. return seen.push(othIndex);
  5174. }
  5175. })) {
  5176. result = false;
  5177. break;
  5178. }
  5179. } else if (!(
  5180. arrValue === othValue ||
  5181. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5182. )) {
  5183. result = false;
  5184. break;
  5185. }
  5186. }
  5187. stack['delete'](array);
  5188. stack['delete'](other);
  5189. return result;
  5190. }
  5191. /**
  5192. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5193. * the same `toStringTag`.
  5194. *
  5195. * **Note:** This function only supports comparing values with tags of
  5196. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5197. *
  5198. * @private
  5199. * @param {Object} object The object to compare.
  5200. * @param {Object} other The other object to compare.
  5201. * @param {string} tag The `toStringTag` of the objects to compare.
  5202. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5203. * @param {Function} customizer The function to customize comparisons.
  5204. * @param {Function} equalFunc The function to determine equivalents of values.
  5205. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5206. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5207. */
  5208. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5209. switch (tag) {
  5210. case dataViewTag:
  5211. if ((object.byteLength != other.byteLength) ||
  5212. (object.byteOffset != other.byteOffset)) {
  5213. return false;
  5214. }
  5215. object = object.buffer;
  5216. other = other.buffer;
  5217. case arrayBufferTag:
  5218. if ((object.byteLength != other.byteLength) ||
  5219. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5220. return false;
  5221. }
  5222. return true;
  5223. case boolTag:
  5224. case dateTag:
  5225. case numberTag:
  5226. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5227. // Invalid dates are coerced to `NaN`.
  5228. return eq(+object, +other);
  5229. case errorTag:
  5230. return object.name == other.name && object.message == other.message;
  5231. case regexpTag:
  5232. case stringTag:
  5233. // Coerce regexes to strings and treat strings, primitives and objects,
  5234. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5235. // for more details.
  5236. return object == (other + '');
  5237. case mapTag:
  5238. var convert = mapToArray;
  5239. case setTag:
  5240. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5241. convert || (convert = setToArray);
  5242. if (object.size != other.size && !isPartial) {
  5243. return false;
  5244. }
  5245. // Assume cyclic values are equal.
  5246. var stacked = stack.get(object);
  5247. if (stacked) {
  5248. return stacked == other;
  5249. }
  5250. bitmask |= COMPARE_UNORDERED_FLAG;
  5251. // Recursively compare objects (susceptible to call stack limits).
  5252. stack.set(object, other);
  5253. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5254. stack['delete'](object);
  5255. return result;
  5256. case symbolTag:
  5257. if (symbolValueOf) {
  5258. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5259. }
  5260. }
  5261. return false;
  5262. }
  5263. /**
  5264. * A specialized version of `baseIsEqualDeep` for objects with support for
  5265. * partial deep comparisons.
  5266. *
  5267. * @private
  5268. * @param {Object} object The object to compare.
  5269. * @param {Object} other The other object to compare.
  5270. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5271. * @param {Function} customizer The function to customize comparisons.
  5272. * @param {Function} equalFunc The function to determine equivalents of values.
  5273. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5274. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5275. */
  5276. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5277. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5278. objProps = getAllKeys(object),
  5279. objLength = objProps.length,
  5280. othProps = getAllKeys(other),
  5281. othLength = othProps.length;
  5282. if (objLength != othLength && !isPartial) {
  5283. return false;
  5284. }
  5285. var index = objLength;
  5286. while (index--) {
  5287. var key = objProps[index];
  5288. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5289. return false;
  5290. }
  5291. }
  5292. // Assume cyclic values are equal.
  5293. var stacked = stack.get(object);
  5294. if (stacked && stack.get(other)) {
  5295. return stacked == other;
  5296. }
  5297. var result = true;
  5298. stack.set(object, other);
  5299. stack.set(other, object);
  5300. var skipCtor = isPartial;
  5301. while (++index < objLength) {
  5302. key = objProps[index];
  5303. var objValue = object[key],
  5304. othValue = other[key];
  5305. if (customizer) {
  5306. var compared = isPartial
  5307. ? customizer(othValue, objValue, key, other, object, stack)
  5308. : customizer(objValue, othValue, key, object, other, stack);
  5309. }
  5310. // Recursively compare objects (susceptible to call stack limits).
  5311. if (!(compared === undefined
  5312. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5313. : compared
  5314. )) {
  5315. result = false;
  5316. break;
  5317. }
  5318. skipCtor || (skipCtor = key == 'constructor');
  5319. }
  5320. if (result && !skipCtor) {
  5321. var objCtor = object.constructor,
  5322. othCtor = other.constructor;
  5323. // Non `Object` object instances with different constructors are not equal.
  5324. if (objCtor != othCtor &&
  5325. ('constructor' in object && 'constructor' in other) &&
  5326. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5327. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5328. result = false;
  5329. }
  5330. }
  5331. stack['delete'](object);
  5332. stack['delete'](other);
  5333. return result;
  5334. }
  5335. /**
  5336. * A specialized version of `baseRest` which flattens the rest array.
  5337. *
  5338. * @private
  5339. * @param {Function} func The function to apply a rest parameter to.
  5340. * @returns {Function} Returns the new function.
  5341. */
  5342. function flatRest(func) {
  5343. return setToString(overRest(func, undefined, flatten), func + '');
  5344. }
  5345. /**
  5346. * Creates an array of own enumerable property names and symbols of `object`.
  5347. *
  5348. * @private
  5349. * @param {Object} object The object to query.
  5350. * @returns {Array} Returns the array of property names and symbols.
  5351. */
  5352. function getAllKeys(object) {
  5353. return baseGetAllKeys(object, keys, getSymbols);
  5354. }
  5355. /**
  5356. * Creates an array of own and inherited enumerable property names and
  5357. * symbols of `object`.
  5358. *
  5359. * @private
  5360. * @param {Object} object The object to query.
  5361. * @returns {Array} Returns the array of property names and symbols.
  5362. */
  5363. function getAllKeysIn(object) {
  5364. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5365. }
  5366. /**
  5367. * Gets metadata for `func`.
  5368. *
  5369. * @private
  5370. * @param {Function} func The function to query.
  5371. * @returns {*} Returns the metadata for `func`.
  5372. */
  5373. var getData = !metaMap ? noop : function(func) {
  5374. return metaMap.get(func);
  5375. };
  5376. /**
  5377. * Gets the name of `func`.
  5378. *
  5379. * @private
  5380. * @param {Function} func The function to query.
  5381. * @returns {string} Returns the function name.
  5382. */
  5383. function getFuncName(func) {
  5384. var result = (func.name + ''),
  5385. array = realNames[result],
  5386. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5387. while (length--) {
  5388. var data = array[length],
  5389. otherFunc = data.func;
  5390. if (otherFunc == null || otherFunc == func) {
  5391. return data.name;
  5392. }
  5393. }
  5394. return result;
  5395. }
  5396. /**
  5397. * Gets the argument placeholder value for `func`.
  5398. *
  5399. * @private
  5400. * @param {Function} func The function to inspect.
  5401. * @returns {*} Returns the placeholder value.
  5402. */
  5403. function getHolder(func) {
  5404. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5405. return object.placeholder;
  5406. }
  5407. /**
  5408. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5409. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5410. * If arguments are provided, the chosen function is invoked with them and
  5411. * its result is returned.
  5412. *
  5413. * @private
  5414. * @param {*} [value] The value to convert to an iteratee.
  5415. * @param {number} [arity] The arity of the created iteratee.
  5416. * @returns {Function} Returns the chosen function or its result.
  5417. */
  5418. function getIteratee() {
  5419. var result = lodash.iteratee || iteratee;
  5420. result = result === iteratee ? baseIteratee : result;
  5421. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5422. }
  5423. /**
  5424. * Gets the data for `map`.
  5425. *
  5426. * @private
  5427. * @param {Object} map The map to query.
  5428. * @param {string} key The reference key.
  5429. * @returns {*} Returns the map data.
  5430. */
  5431. function getMapData(map, key) {
  5432. var data = map.__data__;
  5433. return isKeyable(key)
  5434. ? data[typeof key == 'string' ? 'string' : 'hash']
  5435. : data.map;
  5436. }
  5437. /**
  5438. * Gets the property names, values, and compare flags of `object`.
  5439. *
  5440. * @private
  5441. * @param {Object} object The object to query.
  5442. * @returns {Array} Returns the match data of `object`.
  5443. */
  5444. function getMatchData(object) {
  5445. var result = keys(object),
  5446. length = result.length;
  5447. while (length--) {
  5448. var key = result[length],
  5449. value = object[key];
  5450. result[length] = [key, value, isStrictComparable(value)];
  5451. }
  5452. return result;
  5453. }
  5454. /**
  5455. * Gets the native function at `key` of `object`.
  5456. *
  5457. * @private
  5458. * @param {Object} object The object to query.
  5459. * @param {string} key The key of the method to get.
  5460. * @returns {*} Returns the function if it's native, else `undefined`.
  5461. */
  5462. function getNative(object, key) {
  5463. var value = getValue(object, key);
  5464. return baseIsNative(value) ? value : undefined;
  5465. }
  5466. /**
  5467. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5468. *
  5469. * @private
  5470. * @param {*} value The value to query.
  5471. * @returns {string} Returns the raw `toStringTag`.
  5472. */
  5473. function getRawTag(value) {
  5474. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5475. tag = value[symToStringTag];
  5476. try {
  5477. value[symToStringTag] = undefined;
  5478. var unmasked = true;
  5479. } catch (e) {}
  5480. var result = nativeObjectToString.call(value);
  5481. if (unmasked) {
  5482. if (isOwn) {
  5483. value[symToStringTag] = tag;
  5484. } else {
  5485. delete value[symToStringTag];
  5486. }
  5487. }
  5488. return result;
  5489. }
  5490. /**
  5491. * Creates an array of the own enumerable symbols of `object`.
  5492. *
  5493. * @private
  5494. * @param {Object} object The object to query.
  5495. * @returns {Array} Returns the array of symbols.
  5496. */
  5497. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5498. if (object == null) {
  5499. return [];
  5500. }
  5501. object = Object(object);
  5502. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5503. return propertyIsEnumerable.call(object, symbol);
  5504. });
  5505. };
  5506. /**
  5507. * Creates an array of the own and inherited enumerable symbols of `object`.
  5508. *
  5509. * @private
  5510. * @param {Object} object The object to query.
  5511. * @returns {Array} Returns the array of symbols.
  5512. */
  5513. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5514. var result = [];
  5515. while (object) {
  5516. arrayPush(result, getSymbols(object));
  5517. object = getPrototype(object);
  5518. }
  5519. return result;
  5520. };
  5521. /**
  5522. * Gets the `toStringTag` of `value`.
  5523. *
  5524. * @private
  5525. * @param {*} value The value to query.
  5526. * @returns {string} Returns the `toStringTag`.
  5527. */
  5528. var getTag = baseGetTag;
  5529. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5530. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5531. (Map && getTag(new Map) != mapTag) ||
  5532. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5533. (Set && getTag(new Set) != setTag) ||
  5534. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5535. getTag = function(value) {
  5536. var result = baseGetTag(value),
  5537. Ctor = result == objectTag ? value.constructor : undefined,
  5538. ctorString = Ctor ? toSource(Ctor) : '';
  5539. if (ctorString) {
  5540. switch (ctorString) {
  5541. case dataViewCtorString: return dataViewTag;
  5542. case mapCtorString: return mapTag;
  5543. case promiseCtorString: return promiseTag;
  5544. case setCtorString: return setTag;
  5545. case weakMapCtorString: return weakMapTag;
  5546. }
  5547. }
  5548. return result;
  5549. };
  5550. }
  5551. /**
  5552. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5553. *
  5554. * @private
  5555. * @param {number} start The start of the view.
  5556. * @param {number} end The end of the view.
  5557. * @param {Array} transforms The transformations to apply to the view.
  5558. * @returns {Object} Returns an object containing the `start` and `end`
  5559. * positions of the view.
  5560. */
  5561. function getView(start, end, transforms) {
  5562. var index = -1,
  5563. length = transforms.length;
  5564. while (++index < length) {
  5565. var data = transforms[index],
  5566. size = data.size;
  5567. switch (data.type) {
  5568. case 'drop': start += size; break;
  5569. case 'dropRight': end -= size; break;
  5570. case 'take': end = nativeMin(end, start + size); break;
  5571. case 'takeRight': start = nativeMax(start, end - size); break;
  5572. }
  5573. }
  5574. return { 'start': start, 'end': end };
  5575. }
  5576. /**
  5577. * Extracts wrapper details from the `source` body comment.
  5578. *
  5579. * @private
  5580. * @param {string} source The source to inspect.
  5581. * @returns {Array} Returns the wrapper details.
  5582. */
  5583. function getWrapDetails(source) {
  5584. var match = source.match(reWrapDetails);
  5585. return match ? match[1].split(reSplitDetails) : [];
  5586. }
  5587. /**
  5588. * Checks if `path` exists on `object`.
  5589. *
  5590. * @private
  5591. * @param {Object} object The object to query.
  5592. * @param {Array|string} path The path to check.
  5593. * @param {Function} hasFunc The function to check properties.
  5594. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5595. */
  5596. function hasPath(object, path, hasFunc) {
  5597. path = castPath(path, object);
  5598. var index = -1,
  5599. length = path.length,
  5600. result = false;
  5601. while (++index < length) {
  5602. var key = toKey(path[index]);
  5603. if (!(result = object != null && hasFunc(object, key))) {
  5604. break;
  5605. }
  5606. object = object[key];
  5607. }
  5608. if (result || ++index != length) {
  5609. return result;
  5610. }
  5611. length = object == null ? 0 : object.length;
  5612. return !!length && isLength(length) && isIndex(key, length) &&
  5613. (isArray(object) || isArguments(object));
  5614. }
  5615. /**
  5616. * Initializes an array clone.
  5617. *
  5618. * @private
  5619. * @param {Array} array The array to clone.
  5620. * @returns {Array} Returns the initialized clone.
  5621. */
  5622. function initCloneArray(array) {
  5623. var length = array.length,
  5624. result = new array.constructor(length);
  5625. // Add properties assigned by `RegExp#exec`.
  5626. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5627. result.index = array.index;
  5628. result.input = array.input;
  5629. }
  5630. return result;
  5631. }
  5632. /**
  5633. * Initializes an object clone.
  5634. *
  5635. * @private
  5636. * @param {Object} object The object to clone.
  5637. * @returns {Object} Returns the initialized clone.
  5638. */
  5639. function initCloneObject(object) {
  5640. return (typeof object.constructor == 'function' && !isPrototype(object))
  5641. ? baseCreate(getPrototype(object))
  5642. : {};
  5643. }
  5644. /**
  5645. * Initializes an object clone based on its `toStringTag`.
  5646. *
  5647. * **Note:** This function only supports cloning values with tags of
  5648. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5649. *
  5650. * @private
  5651. * @param {Object} object The object to clone.
  5652. * @param {string} tag The `toStringTag` of the object to clone.
  5653. * @param {boolean} [isDeep] Specify a deep clone.
  5654. * @returns {Object} Returns the initialized clone.
  5655. */
  5656. function initCloneByTag(object, tag, isDeep) {
  5657. var Ctor = object.constructor;
  5658. switch (tag) {
  5659. case arrayBufferTag:
  5660. return cloneArrayBuffer(object);
  5661. case boolTag:
  5662. case dateTag:
  5663. return new Ctor(+object);
  5664. case dataViewTag:
  5665. return cloneDataView(object, isDeep);
  5666. case float32Tag: case float64Tag:
  5667. case int8Tag: case int16Tag: case int32Tag:
  5668. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5669. return cloneTypedArray(object, isDeep);
  5670. case mapTag:
  5671. return new Ctor;
  5672. case numberTag:
  5673. case stringTag:
  5674. return new Ctor(object);
  5675. case regexpTag:
  5676. return cloneRegExp(object);
  5677. case setTag:
  5678. return new Ctor;
  5679. case symbolTag:
  5680. return cloneSymbol(object);
  5681. }
  5682. }
  5683. /**
  5684. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5685. *
  5686. * @private
  5687. * @param {string} source The source to modify.
  5688. * @returns {Array} details The details to insert.
  5689. * @returns {string} Returns the modified source.
  5690. */
  5691. function insertWrapDetails(source, details) {
  5692. var length = details.length;
  5693. if (!length) {
  5694. return source;
  5695. }
  5696. var lastIndex = length - 1;
  5697. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5698. details = details.join(length > 2 ? ', ' : ' ');
  5699. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5700. }
  5701. /**
  5702. * Checks if `value` is a flattenable `arguments` object or array.
  5703. *
  5704. * @private
  5705. * @param {*} value The value to check.
  5706. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5707. */
  5708. function isFlattenable(value) {
  5709. return isArray(value) || isArguments(value) ||
  5710. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5711. }
  5712. /**
  5713. * Checks if `value` is a valid array-like index.
  5714. *
  5715. * @private
  5716. * @param {*} value The value to check.
  5717. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5718. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5719. */
  5720. function isIndex(value, length) {
  5721. var type = typeof value;
  5722. length = length == null ? MAX_SAFE_INTEGER : length;
  5723. return !!length &&
  5724. (type == 'number' ||
  5725. (type != 'symbol' && reIsUint.test(value))) &&
  5726. (value > -1 && value % 1 == 0 && value < length);
  5727. }
  5728. /**
  5729. * Checks if the given arguments are from an iteratee call.
  5730. *
  5731. * @private
  5732. * @param {*} value The potential iteratee value argument.
  5733. * @param {*} index The potential iteratee index or key argument.
  5734. * @param {*} object The potential iteratee object argument.
  5735. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5736. * else `false`.
  5737. */
  5738. function isIterateeCall(value, index, object) {
  5739. if (!isObject(object)) {
  5740. return false;
  5741. }
  5742. var type = typeof index;
  5743. if (type == 'number'
  5744. ? (isArrayLike(object) && isIndex(index, object.length))
  5745. : (type == 'string' && index in object)
  5746. ) {
  5747. return eq(object[index], value);
  5748. }
  5749. return false;
  5750. }
  5751. /**
  5752. * Checks if `value` is a property name and not a property path.
  5753. *
  5754. * @private
  5755. * @param {*} value The value to check.
  5756. * @param {Object} [object] The object to query keys on.
  5757. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5758. */
  5759. function isKey(value, object) {
  5760. if (isArray(value)) {
  5761. return false;
  5762. }
  5763. var type = typeof value;
  5764. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5765. value == null || isSymbol(value)) {
  5766. return true;
  5767. }
  5768. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5769. (object != null && value in Object(object));
  5770. }
  5771. /**
  5772. * Checks if `value` is suitable for use as unique object key.
  5773. *
  5774. * @private
  5775. * @param {*} value The value to check.
  5776. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5777. */
  5778. function isKeyable(value) {
  5779. var type = typeof value;
  5780. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5781. ? (value !== '__proto__')
  5782. : (value === null);
  5783. }
  5784. /**
  5785. * Checks if `func` has a lazy counterpart.
  5786. *
  5787. * @private
  5788. * @param {Function} func The function to check.
  5789. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5790. * else `false`.
  5791. */
  5792. function isLaziable(func) {
  5793. var funcName = getFuncName(func),
  5794. other = lodash[funcName];
  5795. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5796. return false;
  5797. }
  5798. if (func === other) {
  5799. return true;
  5800. }
  5801. var data = getData(other);
  5802. return !!data && func === data[0];
  5803. }
  5804. /**
  5805. * Checks if `func` has its source masked.
  5806. *
  5807. * @private
  5808. * @param {Function} func The function to check.
  5809. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5810. */
  5811. function isMasked(func) {
  5812. return !!maskSrcKey && (maskSrcKey in func);
  5813. }
  5814. /**
  5815. * Checks if `func` is capable of being masked.
  5816. *
  5817. * @private
  5818. * @param {*} value The value to check.
  5819. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5820. */
  5821. var isMaskable = coreJsData ? isFunction : stubFalse;
  5822. /**
  5823. * Checks if `value` is likely a prototype object.
  5824. *
  5825. * @private
  5826. * @param {*} value The value to check.
  5827. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5828. */
  5829. function isPrototype(value) {
  5830. var Ctor = value && value.constructor,
  5831. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5832. return value === proto;
  5833. }
  5834. /**
  5835. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5836. *
  5837. * @private
  5838. * @param {*} value The value to check.
  5839. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5840. * equality comparisons, else `false`.
  5841. */
  5842. function isStrictComparable(value) {
  5843. return value === value && !isObject(value);
  5844. }
  5845. /**
  5846. * A specialized version of `matchesProperty` for source values suitable
  5847. * for strict equality comparisons, i.e. `===`.
  5848. *
  5849. * @private
  5850. * @param {string} key The key of the property to get.
  5851. * @param {*} srcValue The value to match.
  5852. * @returns {Function} Returns the new spec function.
  5853. */
  5854. function matchesStrictComparable(key, srcValue) {
  5855. return function(object) {
  5856. if (object == null) {
  5857. return false;
  5858. }
  5859. return object[key] === srcValue &&
  5860. (srcValue !== undefined || (key in Object(object)));
  5861. };
  5862. }
  5863. /**
  5864. * A specialized version of `_.memoize` which clears the memoized function's
  5865. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5866. *
  5867. * @private
  5868. * @param {Function} func The function to have its output memoized.
  5869. * @returns {Function} Returns the new memoized function.
  5870. */
  5871. function memoizeCapped(func) {
  5872. var result = memoize(func, function(key) {
  5873. if (cache.size === MAX_MEMOIZE_SIZE) {
  5874. cache.clear();
  5875. }
  5876. return key;
  5877. });
  5878. var cache = result.cache;
  5879. return result;
  5880. }
  5881. /**
  5882. * Merges the function metadata of `source` into `data`.
  5883. *
  5884. * Merging metadata reduces the number of wrappers used to invoke a function.
  5885. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5886. * may be applied regardless of execution order. Methods like `_.ary` and
  5887. * `_.rearg` modify function arguments, making the order in which they are
  5888. * executed important, preventing the merging of metadata. However, we make
  5889. * an exception for a safe combined case where curried functions have `_.ary`
  5890. * and or `_.rearg` applied.
  5891. *
  5892. * @private
  5893. * @param {Array} data The destination metadata.
  5894. * @param {Array} source The source metadata.
  5895. * @returns {Array} Returns `data`.
  5896. */
  5897. function mergeData(data, source) {
  5898. var bitmask = data[1],
  5899. srcBitmask = source[1],
  5900. newBitmask = bitmask | srcBitmask,
  5901. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5902. var isCombo =
  5903. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5904. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5905. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5906. // Exit early if metadata can't be merged.
  5907. if (!(isCommon || isCombo)) {
  5908. return data;
  5909. }
  5910. // Use source `thisArg` if available.
  5911. if (srcBitmask & WRAP_BIND_FLAG) {
  5912. data[2] = source[2];
  5913. // Set when currying a bound function.
  5914. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5915. }
  5916. // Compose partial arguments.
  5917. var value = source[3];
  5918. if (value) {
  5919. var partials = data[3];
  5920. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5921. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5922. }
  5923. // Compose partial right arguments.
  5924. value = source[5];
  5925. if (value) {
  5926. partials = data[5];
  5927. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5928. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5929. }
  5930. // Use source `argPos` if available.
  5931. value = source[7];
  5932. if (value) {
  5933. data[7] = value;
  5934. }
  5935. // Use source `ary` if it's smaller.
  5936. if (srcBitmask & WRAP_ARY_FLAG) {
  5937. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5938. }
  5939. // Use source `arity` if one is not provided.
  5940. if (data[9] == null) {
  5941. data[9] = source[9];
  5942. }
  5943. // Use source `func` and merge bitmasks.
  5944. data[0] = source[0];
  5945. data[1] = newBitmask;
  5946. return data;
  5947. }
  5948. /**
  5949. * This function is like
  5950. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5951. * except that it includes inherited enumerable properties.
  5952. *
  5953. * @private
  5954. * @param {Object} object The object to query.
  5955. * @returns {Array} Returns the array of property names.
  5956. */
  5957. function nativeKeysIn(object) {
  5958. var result = [];
  5959. if (object != null) {
  5960. for (var key in Object(object)) {
  5961. result.push(key);
  5962. }
  5963. }
  5964. return result;
  5965. }
  5966. /**
  5967. * Converts `value` to a string using `Object.prototype.toString`.
  5968. *
  5969. * @private
  5970. * @param {*} value The value to convert.
  5971. * @returns {string} Returns the converted string.
  5972. */
  5973. function objectToString(value) {
  5974. return nativeObjectToString.call(value);
  5975. }
  5976. /**
  5977. * A specialized version of `baseRest` which transforms the rest array.
  5978. *
  5979. * @private
  5980. * @param {Function} func The function to apply a rest parameter to.
  5981. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5982. * @param {Function} transform The rest array transform.
  5983. * @returns {Function} Returns the new function.
  5984. */
  5985. function overRest(func, start, transform) {
  5986. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5987. return function() {
  5988. var args = arguments,
  5989. index = -1,
  5990. length = nativeMax(args.length - start, 0),
  5991. array = Array(length);
  5992. while (++index < length) {
  5993. array[index] = args[start + index];
  5994. }
  5995. index = -1;
  5996. var otherArgs = Array(start + 1);
  5997. while (++index < start) {
  5998. otherArgs[index] = args[index];
  5999. }
  6000. otherArgs[start] = transform(array);
  6001. return apply(func, this, otherArgs);
  6002. };
  6003. }
  6004. /**
  6005. * Gets the parent value at `path` of `object`.
  6006. *
  6007. * @private
  6008. * @param {Object} object The object to query.
  6009. * @param {Array} path The path to get the parent value of.
  6010. * @returns {*} Returns the parent value.
  6011. */
  6012. function parent(object, path) {
  6013. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6014. }
  6015. /**
  6016. * Reorder `array` according to the specified indexes where the element at
  6017. * the first index is assigned as the first element, the element at
  6018. * the second index is assigned as the second element, and so on.
  6019. *
  6020. * @private
  6021. * @param {Array} array The array to reorder.
  6022. * @param {Array} indexes The arranged array indexes.
  6023. * @returns {Array} Returns `array`.
  6024. */
  6025. function reorder(array, indexes) {
  6026. var arrLength = array.length,
  6027. length = nativeMin(indexes.length, arrLength),
  6028. oldArray = copyArray(array);
  6029. while (length--) {
  6030. var index = indexes[length];
  6031. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6032. }
  6033. return array;
  6034. }
  6035. /**
  6036. * Sets metadata for `func`.
  6037. *
  6038. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6039. * period of time, it will trip its breaker and transition to an identity
  6040. * function to avoid garbage collection pauses in V8. See
  6041. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6042. * for more details.
  6043. *
  6044. * @private
  6045. * @param {Function} func The function to associate metadata with.
  6046. * @param {*} data The metadata.
  6047. * @returns {Function} Returns `func`.
  6048. */
  6049. var setData = shortOut(baseSetData);
  6050. /**
  6051. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6052. *
  6053. * @private
  6054. * @param {Function} func The function to delay.
  6055. * @param {number} wait The number of milliseconds to delay invocation.
  6056. * @returns {number|Object} Returns the timer id or timeout object.
  6057. */
  6058. var setTimeout = ctxSetTimeout || function(func, wait) {
  6059. return root.setTimeout(func, wait);
  6060. };
  6061. /**
  6062. * Sets the `toString` method of `func` to return `string`.
  6063. *
  6064. * @private
  6065. * @param {Function} func The function to modify.
  6066. * @param {Function} string The `toString` result.
  6067. * @returns {Function} Returns `func`.
  6068. */
  6069. var setToString = shortOut(baseSetToString);
  6070. /**
  6071. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6072. * with wrapper details in a comment at the top of the source body.
  6073. *
  6074. * @private
  6075. * @param {Function} wrapper The function to modify.
  6076. * @param {Function} reference The reference function.
  6077. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6078. * @returns {Function} Returns `wrapper`.
  6079. */
  6080. function setWrapToString(wrapper, reference, bitmask) {
  6081. var source = (reference + '');
  6082. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6083. }
  6084. /**
  6085. * Creates a function that'll short out and invoke `identity` instead
  6086. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6087. * milliseconds.
  6088. *
  6089. * @private
  6090. * @param {Function} func The function to restrict.
  6091. * @returns {Function} Returns the new shortable function.
  6092. */
  6093. function shortOut(func) {
  6094. var count = 0,
  6095. lastCalled = 0;
  6096. return function() {
  6097. var stamp = nativeNow(),
  6098. remaining = HOT_SPAN - (stamp - lastCalled);
  6099. lastCalled = stamp;
  6100. if (remaining > 0) {
  6101. if (++count >= HOT_COUNT) {
  6102. return arguments[0];
  6103. }
  6104. } else {
  6105. count = 0;
  6106. }
  6107. return func.apply(undefined, arguments);
  6108. };
  6109. }
  6110. /**
  6111. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6112. *
  6113. * @private
  6114. * @param {Array} array The array to shuffle.
  6115. * @param {number} [size=array.length] The size of `array`.
  6116. * @returns {Array} Returns `array`.
  6117. */
  6118. function shuffleSelf(array, size) {
  6119. var index = -1,
  6120. length = array.length,
  6121. lastIndex = length - 1;
  6122. size = size === undefined ? length : size;
  6123. while (++index < size) {
  6124. var rand = baseRandom(index, lastIndex),
  6125. value = array[rand];
  6126. array[rand] = array[index];
  6127. array[index] = value;
  6128. }
  6129. array.length = size;
  6130. return array;
  6131. }
  6132. /**
  6133. * Converts `string` to a property path array.
  6134. *
  6135. * @private
  6136. * @param {string} string The string to convert.
  6137. * @returns {Array} Returns the property path array.
  6138. */
  6139. var stringToPath = memoizeCapped(function(string) {
  6140. var result = [];
  6141. if (string.charCodeAt(0) === 46 /* . */) {
  6142. result.push('');
  6143. }
  6144. string.replace(rePropName, function(match, number, quote, subString) {
  6145. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6146. });
  6147. return result;
  6148. });
  6149. /**
  6150. * Converts `value` to a string key if it's not a string or symbol.
  6151. *
  6152. * @private
  6153. * @param {*} value The value to inspect.
  6154. * @returns {string|symbol} Returns the key.
  6155. */
  6156. function toKey(value) {
  6157. if (typeof value == 'string' || isSymbol(value)) {
  6158. return value;
  6159. }
  6160. var result = (value + '');
  6161. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6162. }
  6163. /**
  6164. * Converts `func` to its source code.
  6165. *
  6166. * @private
  6167. * @param {Function} func The function to convert.
  6168. * @returns {string} Returns the source code.
  6169. */
  6170. function toSource(func) {
  6171. if (func != null) {
  6172. try {
  6173. return funcToString.call(func);
  6174. } catch (e) {}
  6175. try {
  6176. return (func + '');
  6177. } catch (e) {}
  6178. }
  6179. return '';
  6180. }
  6181. /**
  6182. * Updates wrapper `details` based on `bitmask` flags.
  6183. *
  6184. * @private
  6185. * @returns {Array} details The details to modify.
  6186. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6187. * @returns {Array} Returns `details`.
  6188. */
  6189. function updateWrapDetails(details, bitmask) {
  6190. arrayEach(wrapFlags, function(pair) {
  6191. var value = '_.' + pair[0];
  6192. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6193. details.push(value);
  6194. }
  6195. });
  6196. return details.sort();
  6197. }
  6198. /**
  6199. * Creates a clone of `wrapper`.
  6200. *
  6201. * @private
  6202. * @param {Object} wrapper The wrapper to clone.
  6203. * @returns {Object} Returns the cloned wrapper.
  6204. */
  6205. function wrapperClone(wrapper) {
  6206. if (wrapper instanceof LazyWrapper) {
  6207. return wrapper.clone();
  6208. }
  6209. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6210. result.__actions__ = copyArray(wrapper.__actions__);
  6211. result.__index__ = wrapper.__index__;
  6212. result.__values__ = wrapper.__values__;
  6213. return result;
  6214. }
  6215. /*------------------------------------------------------------------------*/
  6216. /**
  6217. * Creates an array of elements split into groups the length of `size`.
  6218. * If `array` can't be split evenly, the final chunk will be the remaining
  6219. * elements.
  6220. *
  6221. * @static
  6222. * @memberOf _
  6223. * @since 3.0.0
  6224. * @category Array
  6225. * @param {Array} array The array to process.
  6226. * @param {number} [size=1] The length of each chunk
  6227. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6228. * @returns {Array} Returns the new array of chunks.
  6229. * @example
  6230. *
  6231. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6232. * // => [['a', 'b'], ['c', 'd']]
  6233. *
  6234. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6235. * // => [['a', 'b', 'c'], ['d']]
  6236. */
  6237. function chunk(array, size, guard) {
  6238. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6239. size = 1;
  6240. } else {
  6241. size = nativeMax(toInteger(size), 0);
  6242. }
  6243. var length = array == null ? 0 : array.length;
  6244. if (!length || size < 1) {
  6245. return [];
  6246. }
  6247. var index = 0,
  6248. resIndex = 0,
  6249. result = Array(nativeCeil(length / size));
  6250. while (index < length) {
  6251. result[resIndex++] = baseSlice(array, index, (index += size));
  6252. }
  6253. return result;
  6254. }
  6255. /**
  6256. * Creates an array with all falsey values removed. The values `false`, `null`,
  6257. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6258. *
  6259. * @static
  6260. * @memberOf _
  6261. * @since 0.1.0
  6262. * @category Array
  6263. * @param {Array} array The array to compact.
  6264. * @returns {Array} Returns the new array of filtered values.
  6265. * @example
  6266. *
  6267. * _.compact([0, 1, false, 2, '', 3]);
  6268. * // => [1, 2, 3]
  6269. */
  6270. function compact(array) {
  6271. var index = -1,
  6272. length = array == null ? 0 : array.length,
  6273. resIndex = 0,
  6274. result = [];
  6275. while (++index < length) {
  6276. var value = array[index];
  6277. if (value) {
  6278. result[resIndex++] = value;
  6279. }
  6280. }
  6281. return result;
  6282. }
  6283. /**
  6284. * Creates a new array concatenating `array` with any additional arrays
  6285. * and/or values.
  6286. *
  6287. * @static
  6288. * @memberOf _
  6289. * @since 4.0.0
  6290. * @category Array
  6291. * @param {Array} array The array to concatenate.
  6292. * @param {...*} [values] The values to concatenate.
  6293. * @returns {Array} Returns the new concatenated array.
  6294. * @example
  6295. *
  6296. * var array = [1];
  6297. * var other = _.concat(array, 2, [3], [[4]]);
  6298. *
  6299. * console.log(other);
  6300. * // => [1, 2, 3, [4]]
  6301. *
  6302. * console.log(array);
  6303. * // => [1]
  6304. */
  6305. function concat() {
  6306. var length = arguments.length;
  6307. if (!length) {
  6308. return [];
  6309. }
  6310. var args = Array(length - 1),
  6311. array = arguments[0],
  6312. index = length;
  6313. while (index--) {
  6314. args[index - 1] = arguments[index];
  6315. }
  6316. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6317. }
  6318. /**
  6319. * Creates an array of `array` values not included in the other given arrays
  6320. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6321. * for equality comparisons. The order and references of result values are
  6322. * determined by the first array.
  6323. *
  6324. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6325. *
  6326. * @static
  6327. * @memberOf _
  6328. * @since 0.1.0
  6329. * @category Array
  6330. * @param {Array} array The array to inspect.
  6331. * @param {...Array} [values] The values to exclude.
  6332. * @returns {Array} Returns the new array of filtered values.
  6333. * @see _.without, _.xor
  6334. * @example
  6335. *
  6336. * _.difference([2, 1], [2, 3]);
  6337. * // => [1]
  6338. */
  6339. var difference = baseRest(function(array, values) {
  6340. return isArrayLikeObject(array)
  6341. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6342. : [];
  6343. });
  6344. /**
  6345. * This method is like `_.difference` except that it accepts `iteratee` which
  6346. * is invoked for each element of `array` and `values` to generate the criterion
  6347. * by which they're compared. The order and references of result values are
  6348. * determined by the first array. The iteratee is invoked with one argument:
  6349. * (value).
  6350. *
  6351. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6352. *
  6353. * @static
  6354. * @memberOf _
  6355. * @since 4.0.0
  6356. * @category Array
  6357. * @param {Array} array The array to inspect.
  6358. * @param {...Array} [values] The values to exclude.
  6359. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6360. * @returns {Array} Returns the new array of filtered values.
  6361. * @example
  6362. *
  6363. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6364. * // => [1.2]
  6365. *
  6366. * // The `_.property` iteratee shorthand.
  6367. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6368. * // => [{ 'x': 2 }]
  6369. */
  6370. var differenceBy = baseRest(function(array, values) {
  6371. var iteratee = last(values);
  6372. if (isArrayLikeObject(iteratee)) {
  6373. iteratee = undefined;
  6374. }
  6375. return isArrayLikeObject(array)
  6376. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6377. : [];
  6378. });
  6379. /**
  6380. * This method is like `_.difference` except that it accepts `comparator`
  6381. * which is invoked to compare elements of `array` to `values`. The order and
  6382. * references of result values are determined by the first array. The comparator
  6383. * is invoked with two arguments: (arrVal, othVal).
  6384. *
  6385. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6386. *
  6387. * @static
  6388. * @memberOf _
  6389. * @since 4.0.0
  6390. * @category Array
  6391. * @param {Array} array The array to inspect.
  6392. * @param {...Array} [values] The values to exclude.
  6393. * @param {Function} [comparator] The comparator invoked per element.
  6394. * @returns {Array} Returns the new array of filtered values.
  6395. * @example
  6396. *
  6397. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6398. *
  6399. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6400. * // => [{ 'x': 2, 'y': 1 }]
  6401. */
  6402. var differenceWith = baseRest(function(array, values) {
  6403. var comparator = last(values);
  6404. if (isArrayLikeObject(comparator)) {
  6405. comparator = undefined;
  6406. }
  6407. return isArrayLikeObject(array)
  6408. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6409. : [];
  6410. });
  6411. /**
  6412. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6413. *
  6414. * @static
  6415. * @memberOf _
  6416. * @since 0.5.0
  6417. * @category Array
  6418. * @param {Array} array The array to query.
  6419. * @param {number} [n=1] The number of elements to drop.
  6420. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6421. * @returns {Array} Returns the slice of `array`.
  6422. * @example
  6423. *
  6424. * _.drop([1, 2, 3]);
  6425. * // => [2, 3]
  6426. *
  6427. * _.drop([1, 2, 3], 2);
  6428. * // => [3]
  6429. *
  6430. * _.drop([1, 2, 3], 5);
  6431. * // => []
  6432. *
  6433. * _.drop([1, 2, 3], 0);
  6434. * // => [1, 2, 3]
  6435. */
  6436. function drop(array, n, guard) {
  6437. var length = array == null ? 0 : array.length;
  6438. if (!length) {
  6439. return [];
  6440. }
  6441. n = (guard || n === undefined) ? 1 : toInteger(n);
  6442. return baseSlice(array, n < 0 ? 0 : n, length);
  6443. }
  6444. /**
  6445. * Creates a slice of `array` with `n` elements dropped from the end.
  6446. *
  6447. * @static
  6448. * @memberOf _
  6449. * @since 3.0.0
  6450. * @category Array
  6451. * @param {Array} array The array to query.
  6452. * @param {number} [n=1] The number of elements to drop.
  6453. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6454. * @returns {Array} Returns the slice of `array`.
  6455. * @example
  6456. *
  6457. * _.dropRight([1, 2, 3]);
  6458. * // => [1, 2]
  6459. *
  6460. * _.dropRight([1, 2, 3], 2);
  6461. * // => [1]
  6462. *
  6463. * _.dropRight([1, 2, 3], 5);
  6464. * // => []
  6465. *
  6466. * _.dropRight([1, 2, 3], 0);
  6467. * // => [1, 2, 3]
  6468. */
  6469. function dropRight(array, n, guard) {
  6470. var length = array == null ? 0 : array.length;
  6471. if (!length) {
  6472. return [];
  6473. }
  6474. n = (guard || n === undefined) ? 1 : toInteger(n);
  6475. n = length - n;
  6476. return baseSlice(array, 0, n < 0 ? 0 : n);
  6477. }
  6478. /**
  6479. * Creates a slice of `array` excluding elements dropped from the end.
  6480. * Elements are dropped until `predicate` returns falsey. The predicate is
  6481. * invoked with three arguments: (value, index, array).
  6482. *
  6483. * @static
  6484. * @memberOf _
  6485. * @since 3.0.0
  6486. * @category Array
  6487. * @param {Array} array The array to query.
  6488. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6489. * @returns {Array} Returns the slice of `array`.
  6490. * @example
  6491. *
  6492. * var users = [
  6493. * { 'user': 'barney', 'active': true },
  6494. * { 'user': 'fred', 'active': false },
  6495. * { 'user': 'pebbles', 'active': false }
  6496. * ];
  6497. *
  6498. * _.dropRightWhile(users, function(o) { return !o.active; });
  6499. * // => objects for ['barney']
  6500. *
  6501. * // The `_.matches` iteratee shorthand.
  6502. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6503. * // => objects for ['barney', 'fred']
  6504. *
  6505. * // The `_.matchesProperty` iteratee shorthand.
  6506. * _.dropRightWhile(users, ['active', false]);
  6507. * // => objects for ['barney']
  6508. *
  6509. * // The `_.property` iteratee shorthand.
  6510. * _.dropRightWhile(users, 'active');
  6511. * // => objects for ['barney', 'fred', 'pebbles']
  6512. */
  6513. function dropRightWhile(array, predicate) {
  6514. return (array && array.length)
  6515. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6516. : [];
  6517. }
  6518. /**
  6519. * Creates a slice of `array` excluding elements dropped from the beginning.
  6520. * Elements are dropped until `predicate` returns falsey. The predicate is
  6521. * invoked with three arguments: (value, index, array).
  6522. *
  6523. * @static
  6524. * @memberOf _
  6525. * @since 3.0.0
  6526. * @category Array
  6527. * @param {Array} array The array to query.
  6528. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6529. * @returns {Array} Returns the slice of `array`.
  6530. * @example
  6531. *
  6532. * var users = [
  6533. * { 'user': 'barney', 'active': false },
  6534. * { 'user': 'fred', 'active': false },
  6535. * { 'user': 'pebbles', 'active': true }
  6536. * ];
  6537. *
  6538. * _.dropWhile(users, function(o) { return !o.active; });
  6539. * // => objects for ['pebbles']
  6540. *
  6541. * // The `_.matches` iteratee shorthand.
  6542. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6543. * // => objects for ['fred', 'pebbles']
  6544. *
  6545. * // The `_.matchesProperty` iteratee shorthand.
  6546. * _.dropWhile(users, ['active', false]);
  6547. * // => objects for ['pebbles']
  6548. *
  6549. * // The `_.property` iteratee shorthand.
  6550. * _.dropWhile(users, 'active');
  6551. * // => objects for ['barney', 'fred', 'pebbles']
  6552. */
  6553. function dropWhile(array, predicate) {
  6554. return (array && array.length)
  6555. ? baseWhile(array, getIteratee(predicate, 3), true)
  6556. : [];
  6557. }
  6558. /**
  6559. * Fills elements of `array` with `value` from `start` up to, but not
  6560. * including, `end`.
  6561. *
  6562. * **Note:** This method mutates `array`.
  6563. *
  6564. * @static
  6565. * @memberOf _
  6566. * @since 3.2.0
  6567. * @category Array
  6568. * @param {Array} array The array to fill.
  6569. * @param {*} value The value to fill `array` with.
  6570. * @param {number} [start=0] The start position.
  6571. * @param {number} [end=array.length] The end position.
  6572. * @returns {Array} Returns `array`.
  6573. * @example
  6574. *
  6575. * var array = [1, 2, 3];
  6576. *
  6577. * _.fill(array, 'a');
  6578. * console.log(array);
  6579. * // => ['a', 'a', 'a']
  6580. *
  6581. * _.fill(Array(3), 2);
  6582. * // => [2, 2, 2]
  6583. *
  6584. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6585. * // => [4, '*', '*', 10]
  6586. */
  6587. function fill(array, value, start, end) {
  6588. var length = array == null ? 0 : array.length;
  6589. if (!length) {
  6590. return [];
  6591. }
  6592. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6593. start = 0;
  6594. end = length;
  6595. }
  6596. return baseFill(array, value, start, end);
  6597. }
  6598. /**
  6599. * This method is like `_.find` except that it returns the index of the first
  6600. * element `predicate` returns truthy for instead of the element itself.
  6601. *
  6602. * @static
  6603. * @memberOf _
  6604. * @since 1.1.0
  6605. * @category Array
  6606. * @param {Array} array The array to inspect.
  6607. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6608. * @param {number} [fromIndex=0] The index to search from.
  6609. * @returns {number} Returns the index of the found element, else `-1`.
  6610. * @example
  6611. *
  6612. * var users = [
  6613. * { 'user': 'barney', 'active': false },
  6614. * { 'user': 'fred', 'active': false },
  6615. * { 'user': 'pebbles', 'active': true }
  6616. * ];
  6617. *
  6618. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6619. * // => 0
  6620. *
  6621. * // The `_.matches` iteratee shorthand.
  6622. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6623. * // => 1
  6624. *
  6625. * // The `_.matchesProperty` iteratee shorthand.
  6626. * _.findIndex(users, ['active', false]);
  6627. * // => 0
  6628. *
  6629. * // The `_.property` iteratee shorthand.
  6630. * _.findIndex(users, 'active');
  6631. * // => 2
  6632. */
  6633. function findIndex(array, predicate, fromIndex) {
  6634. var length = array == null ? 0 : array.length;
  6635. if (!length) {
  6636. return -1;
  6637. }
  6638. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6639. if (index < 0) {
  6640. index = nativeMax(length + index, 0);
  6641. }
  6642. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6643. }
  6644. /**
  6645. * This method is like `_.findIndex` except that it iterates over elements
  6646. * of `collection` from right to left.
  6647. *
  6648. * @static
  6649. * @memberOf _
  6650. * @since 2.0.0
  6651. * @category Array
  6652. * @param {Array} array The array to inspect.
  6653. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6654. * @param {number} [fromIndex=array.length-1] The index to search from.
  6655. * @returns {number} Returns the index of the found element, else `-1`.
  6656. * @example
  6657. *
  6658. * var users = [
  6659. * { 'user': 'barney', 'active': true },
  6660. * { 'user': 'fred', 'active': false },
  6661. * { 'user': 'pebbles', 'active': false }
  6662. * ];
  6663. *
  6664. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6665. * // => 2
  6666. *
  6667. * // The `_.matches` iteratee shorthand.
  6668. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6669. * // => 0
  6670. *
  6671. * // The `_.matchesProperty` iteratee shorthand.
  6672. * _.findLastIndex(users, ['active', false]);
  6673. * // => 2
  6674. *
  6675. * // The `_.property` iteratee shorthand.
  6676. * _.findLastIndex(users, 'active');
  6677. * // => 0
  6678. */
  6679. function findLastIndex(array, predicate, fromIndex) {
  6680. var length = array == null ? 0 : array.length;
  6681. if (!length) {
  6682. return -1;
  6683. }
  6684. var index = length - 1;
  6685. if (fromIndex !== undefined) {
  6686. index = toInteger(fromIndex);
  6687. index = fromIndex < 0
  6688. ? nativeMax(length + index, 0)
  6689. : nativeMin(index, length - 1);
  6690. }
  6691. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6692. }
  6693. /**
  6694. * Flattens `array` a single level deep.
  6695. *
  6696. * @static
  6697. * @memberOf _
  6698. * @since 0.1.0
  6699. * @category Array
  6700. * @param {Array} array The array to flatten.
  6701. * @returns {Array} Returns the new flattened array.
  6702. * @example
  6703. *
  6704. * _.flatten([1, [2, [3, [4]], 5]]);
  6705. * // => [1, 2, [3, [4]], 5]
  6706. */
  6707. function flatten(array) {
  6708. var length = array == null ? 0 : array.length;
  6709. return length ? baseFlatten(array, 1) : [];
  6710. }
  6711. /**
  6712. * Recursively flattens `array`.
  6713. *
  6714. * @static
  6715. * @memberOf _
  6716. * @since 3.0.0
  6717. * @category Array
  6718. * @param {Array} array The array to flatten.
  6719. * @returns {Array} Returns the new flattened array.
  6720. * @example
  6721. *
  6722. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6723. * // => [1, 2, 3, 4, 5]
  6724. */
  6725. function flattenDeep(array) {
  6726. var length = array == null ? 0 : array.length;
  6727. return length ? baseFlatten(array, INFINITY) : [];
  6728. }
  6729. /**
  6730. * Recursively flatten `array` up to `depth` times.
  6731. *
  6732. * @static
  6733. * @memberOf _
  6734. * @since 4.4.0
  6735. * @category Array
  6736. * @param {Array} array The array to flatten.
  6737. * @param {number} [depth=1] The maximum recursion depth.
  6738. * @returns {Array} Returns the new flattened array.
  6739. * @example
  6740. *
  6741. * var array = [1, [2, [3, [4]], 5]];
  6742. *
  6743. * _.flattenDepth(array, 1);
  6744. * // => [1, 2, [3, [4]], 5]
  6745. *
  6746. * _.flattenDepth(array, 2);
  6747. * // => [1, 2, 3, [4], 5]
  6748. */
  6749. function flattenDepth(array, depth) {
  6750. var length = array == null ? 0 : array.length;
  6751. if (!length) {
  6752. return [];
  6753. }
  6754. depth = depth === undefined ? 1 : toInteger(depth);
  6755. return baseFlatten(array, depth);
  6756. }
  6757. /**
  6758. * The inverse of `_.toPairs`; this method returns an object composed
  6759. * from key-value `pairs`.
  6760. *
  6761. * @static
  6762. * @memberOf _
  6763. * @since 4.0.0
  6764. * @category Array
  6765. * @param {Array} pairs The key-value pairs.
  6766. * @returns {Object} Returns the new object.
  6767. * @example
  6768. *
  6769. * _.fromPairs([['a', 1], ['b', 2]]);
  6770. * // => { 'a': 1, 'b': 2 }
  6771. */
  6772. function fromPairs(pairs) {
  6773. var index = -1,
  6774. length = pairs == null ? 0 : pairs.length,
  6775. result = {};
  6776. while (++index < length) {
  6777. var pair = pairs[index];
  6778. result[pair[0]] = pair[1];
  6779. }
  6780. return result;
  6781. }
  6782. /**
  6783. * Gets the first element of `array`.
  6784. *
  6785. * @static
  6786. * @memberOf _
  6787. * @since 0.1.0
  6788. * @alias first
  6789. * @category Array
  6790. * @param {Array} array The array to query.
  6791. * @returns {*} Returns the first element of `array`.
  6792. * @example
  6793. *
  6794. * _.head([1, 2, 3]);
  6795. * // => 1
  6796. *
  6797. * _.head([]);
  6798. * // => undefined
  6799. */
  6800. function head(array) {
  6801. return (array && array.length) ? array[0] : undefined;
  6802. }
  6803. /**
  6804. * Gets the index at which the first occurrence of `value` is found in `array`
  6805. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6806. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6807. * offset from the end of `array`.
  6808. *
  6809. * @static
  6810. * @memberOf _
  6811. * @since 0.1.0
  6812. * @category Array
  6813. * @param {Array} array The array to inspect.
  6814. * @param {*} value The value to search for.
  6815. * @param {number} [fromIndex=0] The index to search from.
  6816. * @returns {number} Returns the index of the matched value, else `-1`.
  6817. * @example
  6818. *
  6819. * _.indexOf([1, 2, 1, 2], 2);
  6820. * // => 1
  6821. *
  6822. * // Search from the `fromIndex`.
  6823. * _.indexOf([1, 2, 1, 2], 2, 2);
  6824. * // => 3
  6825. */
  6826. function indexOf(array, value, fromIndex) {
  6827. var length = array == null ? 0 : array.length;
  6828. if (!length) {
  6829. return -1;
  6830. }
  6831. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6832. if (index < 0) {
  6833. index = nativeMax(length + index, 0);
  6834. }
  6835. return baseIndexOf(array, value, index);
  6836. }
  6837. /**
  6838. * Gets all but the last element of `array`.
  6839. *
  6840. * @static
  6841. * @memberOf _
  6842. * @since 0.1.0
  6843. * @category Array
  6844. * @param {Array} array The array to query.
  6845. * @returns {Array} Returns the slice of `array`.
  6846. * @example
  6847. *
  6848. * _.initial([1, 2, 3]);
  6849. * // => [1, 2]
  6850. */
  6851. function initial(array) {
  6852. var length = array == null ? 0 : array.length;
  6853. return length ? baseSlice(array, 0, -1) : [];
  6854. }
  6855. /**
  6856. * Creates an array of unique values that are included in all given arrays
  6857. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6858. * for equality comparisons. The order and references of result values are
  6859. * determined by the first array.
  6860. *
  6861. * @static
  6862. * @memberOf _
  6863. * @since 0.1.0
  6864. * @category Array
  6865. * @param {...Array} [arrays] The arrays to inspect.
  6866. * @returns {Array} Returns the new array of intersecting values.
  6867. * @example
  6868. *
  6869. * _.intersection([2, 1], [2, 3]);
  6870. * // => [2]
  6871. */
  6872. var intersection = baseRest(function(arrays) {
  6873. var mapped = arrayMap(arrays, castArrayLikeObject);
  6874. return (mapped.length && mapped[0] === arrays[0])
  6875. ? baseIntersection(mapped)
  6876. : [];
  6877. });
  6878. /**
  6879. * This method is like `_.intersection` except that it accepts `iteratee`
  6880. * which is invoked for each element of each `arrays` to generate the criterion
  6881. * by which they're compared. The order and references of result values are
  6882. * determined by the first array. The iteratee is invoked with one argument:
  6883. * (value).
  6884. *
  6885. * @static
  6886. * @memberOf _
  6887. * @since 4.0.0
  6888. * @category Array
  6889. * @param {...Array} [arrays] The arrays to inspect.
  6890. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6891. * @returns {Array} Returns the new array of intersecting values.
  6892. * @example
  6893. *
  6894. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6895. * // => [2.1]
  6896. *
  6897. * // The `_.property` iteratee shorthand.
  6898. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6899. * // => [{ 'x': 1 }]
  6900. */
  6901. var intersectionBy = baseRest(function(arrays) {
  6902. var iteratee = last(arrays),
  6903. mapped = arrayMap(arrays, castArrayLikeObject);
  6904. if (iteratee === last(mapped)) {
  6905. iteratee = undefined;
  6906. } else {
  6907. mapped.pop();
  6908. }
  6909. return (mapped.length && mapped[0] === arrays[0])
  6910. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6911. : [];
  6912. });
  6913. /**
  6914. * This method is like `_.intersection` except that it accepts `comparator`
  6915. * which is invoked to compare elements of `arrays`. The order and references
  6916. * of result values are determined by the first array. The comparator is
  6917. * invoked with two arguments: (arrVal, othVal).
  6918. *
  6919. * @static
  6920. * @memberOf _
  6921. * @since 4.0.0
  6922. * @category Array
  6923. * @param {...Array} [arrays] The arrays to inspect.
  6924. * @param {Function} [comparator] The comparator invoked per element.
  6925. * @returns {Array} Returns the new array of intersecting values.
  6926. * @example
  6927. *
  6928. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6929. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6930. *
  6931. * _.intersectionWith(objects, others, _.isEqual);
  6932. * // => [{ 'x': 1, 'y': 2 }]
  6933. */
  6934. var intersectionWith = baseRest(function(arrays) {
  6935. var comparator = last(arrays),
  6936. mapped = arrayMap(arrays, castArrayLikeObject);
  6937. comparator = typeof comparator == 'function' ? comparator : undefined;
  6938. if (comparator) {
  6939. mapped.pop();
  6940. }
  6941. return (mapped.length && mapped[0] === arrays[0])
  6942. ? baseIntersection(mapped, undefined, comparator)
  6943. : [];
  6944. });
  6945. /**
  6946. * Converts all elements in `array` into a string separated by `separator`.
  6947. *
  6948. * @static
  6949. * @memberOf _
  6950. * @since 4.0.0
  6951. * @category Array
  6952. * @param {Array} array The array to convert.
  6953. * @param {string} [separator=','] The element separator.
  6954. * @returns {string} Returns the joined string.
  6955. * @example
  6956. *
  6957. * _.join(['a', 'b', 'c'], '~');
  6958. * // => 'a~b~c'
  6959. */
  6960. function join(array, separator) {
  6961. return array == null ? '' : nativeJoin.call(array, separator);
  6962. }
  6963. /**
  6964. * Gets the last element of `array`.
  6965. *
  6966. * @static
  6967. * @memberOf _
  6968. * @since 0.1.0
  6969. * @category Array
  6970. * @param {Array} array The array to query.
  6971. * @returns {*} Returns the last element of `array`.
  6972. * @example
  6973. *
  6974. * _.last([1, 2, 3]);
  6975. * // => 3
  6976. */
  6977. function last(array) {
  6978. var length = array == null ? 0 : array.length;
  6979. return length ? array[length - 1] : undefined;
  6980. }
  6981. /**
  6982. * This method is like `_.indexOf` except that it iterates over elements of
  6983. * `array` from right to left.
  6984. *
  6985. * @static
  6986. * @memberOf _
  6987. * @since 0.1.0
  6988. * @category Array
  6989. * @param {Array} array The array to inspect.
  6990. * @param {*} value The value to search for.
  6991. * @param {number} [fromIndex=array.length-1] The index to search from.
  6992. * @returns {number} Returns the index of the matched value, else `-1`.
  6993. * @example
  6994. *
  6995. * _.lastIndexOf([1, 2, 1, 2], 2);
  6996. * // => 3
  6997. *
  6998. * // Search from the `fromIndex`.
  6999. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7000. * // => 1
  7001. */
  7002. function lastIndexOf(array, value, fromIndex) {
  7003. var length = array == null ? 0 : array.length;
  7004. if (!length) {
  7005. return -1;
  7006. }
  7007. var index = length;
  7008. if (fromIndex !== undefined) {
  7009. index = toInteger(fromIndex);
  7010. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7011. }
  7012. return value === value
  7013. ? strictLastIndexOf(array, value, index)
  7014. : baseFindIndex(array, baseIsNaN, index, true);
  7015. }
  7016. /**
  7017. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7018. * element from the end is returned.
  7019. *
  7020. * @static
  7021. * @memberOf _
  7022. * @since 4.11.0
  7023. * @category Array
  7024. * @param {Array} array The array to query.
  7025. * @param {number} [n=0] The index of the element to return.
  7026. * @returns {*} Returns the nth element of `array`.
  7027. * @example
  7028. *
  7029. * var array = ['a', 'b', 'c', 'd'];
  7030. *
  7031. * _.nth(array, 1);
  7032. * // => 'b'
  7033. *
  7034. * _.nth(array, -2);
  7035. * // => 'c';
  7036. */
  7037. function nth(array, n) {
  7038. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7039. }
  7040. /**
  7041. * Removes all given values from `array` using
  7042. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7043. * for equality comparisons.
  7044. *
  7045. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7046. * to remove elements from an array by predicate.
  7047. *
  7048. * @static
  7049. * @memberOf _
  7050. * @since 2.0.0
  7051. * @category Array
  7052. * @param {Array} array The array to modify.
  7053. * @param {...*} [values] The values to remove.
  7054. * @returns {Array} Returns `array`.
  7055. * @example
  7056. *
  7057. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7058. *
  7059. * _.pull(array, 'a', 'c');
  7060. * console.log(array);
  7061. * // => ['b', 'b']
  7062. */
  7063. var pull = baseRest(pullAll);
  7064. /**
  7065. * This method is like `_.pull` except that it accepts an array of values to remove.
  7066. *
  7067. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7068. *
  7069. * @static
  7070. * @memberOf _
  7071. * @since 4.0.0
  7072. * @category Array
  7073. * @param {Array} array The array to modify.
  7074. * @param {Array} values The values to remove.
  7075. * @returns {Array} Returns `array`.
  7076. * @example
  7077. *
  7078. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7079. *
  7080. * _.pullAll(array, ['a', 'c']);
  7081. * console.log(array);
  7082. * // => ['b', 'b']
  7083. */
  7084. function pullAll(array, values) {
  7085. return (array && array.length && values && values.length)
  7086. ? basePullAll(array, values)
  7087. : array;
  7088. }
  7089. /**
  7090. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7091. * invoked for each element of `array` and `values` to generate the criterion
  7092. * by which they're compared. The iteratee is invoked with one argument: (value).
  7093. *
  7094. * **Note:** Unlike `_.differenceBy`, 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. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7103. * @returns {Array} Returns `array`.
  7104. * @example
  7105. *
  7106. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7107. *
  7108. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7109. * console.log(array);
  7110. * // => [{ 'x': 2 }]
  7111. */
  7112. function pullAllBy(array, values, iteratee) {
  7113. return (array && array.length && values && values.length)
  7114. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7115. : array;
  7116. }
  7117. /**
  7118. * This method is like `_.pullAll` except that it accepts `comparator` which
  7119. * is invoked to compare elements of `array` to `values`. The comparator is
  7120. * invoked with two arguments: (arrVal, othVal).
  7121. *
  7122. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7123. *
  7124. * @static
  7125. * @memberOf _
  7126. * @since 4.6.0
  7127. * @category Array
  7128. * @param {Array} array The array to modify.
  7129. * @param {Array} values The values to remove.
  7130. * @param {Function} [comparator] The comparator invoked per element.
  7131. * @returns {Array} Returns `array`.
  7132. * @example
  7133. *
  7134. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7135. *
  7136. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7137. * console.log(array);
  7138. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7139. */
  7140. function pullAllWith(array, values, comparator) {
  7141. return (array && array.length && values && values.length)
  7142. ? basePullAll(array, values, undefined, comparator)
  7143. : array;
  7144. }
  7145. /**
  7146. * Removes elements from `array` corresponding to `indexes` and returns an
  7147. * array of removed elements.
  7148. *
  7149. * **Note:** Unlike `_.at`, this method mutates `array`.
  7150. *
  7151. * @static
  7152. * @memberOf _
  7153. * @since 3.0.0
  7154. * @category Array
  7155. * @param {Array} array The array to modify.
  7156. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7157. * @returns {Array} Returns the new array of removed elements.
  7158. * @example
  7159. *
  7160. * var array = ['a', 'b', 'c', 'd'];
  7161. * var pulled = _.pullAt(array, [1, 3]);
  7162. *
  7163. * console.log(array);
  7164. * // => ['a', 'c']
  7165. *
  7166. * console.log(pulled);
  7167. * // => ['b', 'd']
  7168. */
  7169. var pullAt = flatRest(function(array, indexes) {
  7170. var length = array == null ? 0 : array.length,
  7171. result = baseAt(array, indexes);
  7172. basePullAt(array, arrayMap(indexes, function(index) {
  7173. return isIndex(index, length) ? +index : index;
  7174. }).sort(compareAscending));
  7175. return result;
  7176. });
  7177. /**
  7178. * Removes all elements from `array` that `predicate` returns truthy for
  7179. * and returns an array of the removed elements. The predicate is invoked
  7180. * with three arguments: (value, index, array).
  7181. *
  7182. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7183. * to pull elements from an array by value.
  7184. *
  7185. * @static
  7186. * @memberOf _
  7187. * @since 2.0.0
  7188. * @category Array
  7189. * @param {Array} array The array to modify.
  7190. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7191. * @returns {Array} Returns the new array of removed elements.
  7192. * @example
  7193. *
  7194. * var array = [1, 2, 3, 4];
  7195. * var evens = _.remove(array, function(n) {
  7196. * return n % 2 == 0;
  7197. * });
  7198. *
  7199. * console.log(array);
  7200. * // => [1, 3]
  7201. *
  7202. * console.log(evens);
  7203. * // => [2, 4]
  7204. */
  7205. function remove(array, predicate) {
  7206. var result = [];
  7207. if (!(array && array.length)) {
  7208. return result;
  7209. }
  7210. var index = -1,
  7211. indexes = [],
  7212. length = array.length;
  7213. predicate = getIteratee(predicate, 3);
  7214. while (++index < length) {
  7215. var value = array[index];
  7216. if (predicate(value, index, array)) {
  7217. result.push(value);
  7218. indexes.push(index);
  7219. }
  7220. }
  7221. basePullAt(array, indexes);
  7222. return result;
  7223. }
  7224. /**
  7225. * Reverses `array` so that the first element becomes the last, the second
  7226. * element becomes the second to last, and so on.
  7227. *
  7228. * **Note:** This method mutates `array` and is based on
  7229. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7230. *
  7231. * @static
  7232. * @memberOf _
  7233. * @since 4.0.0
  7234. * @category Array
  7235. * @param {Array} array The array to modify.
  7236. * @returns {Array} Returns `array`.
  7237. * @example
  7238. *
  7239. * var array = [1, 2, 3];
  7240. *
  7241. * _.reverse(array);
  7242. * // => [3, 2, 1]
  7243. *
  7244. * console.log(array);
  7245. * // => [3, 2, 1]
  7246. */
  7247. function reverse(array) {
  7248. return array == null ? array : nativeReverse.call(array);
  7249. }
  7250. /**
  7251. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7252. *
  7253. * **Note:** This method is used instead of
  7254. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7255. * returned.
  7256. *
  7257. * @static
  7258. * @memberOf _
  7259. * @since 3.0.0
  7260. * @category Array
  7261. * @param {Array} array The array to slice.
  7262. * @param {number} [start=0] The start position.
  7263. * @param {number} [end=array.length] The end position.
  7264. * @returns {Array} Returns the slice of `array`.
  7265. */
  7266. function slice(array, start, end) {
  7267. var length = array == null ? 0 : array.length;
  7268. if (!length) {
  7269. return [];
  7270. }
  7271. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7272. start = 0;
  7273. end = length;
  7274. }
  7275. else {
  7276. start = start == null ? 0 : toInteger(start);
  7277. end = end === undefined ? length : toInteger(end);
  7278. }
  7279. return baseSlice(array, start, end);
  7280. }
  7281. /**
  7282. * Uses a binary search to determine the lowest index at which `value`
  7283. * should be inserted into `array` in order to maintain its sort order.
  7284. *
  7285. * @static
  7286. * @memberOf _
  7287. * @since 0.1.0
  7288. * @category Array
  7289. * @param {Array} array The sorted array to inspect.
  7290. * @param {*} value The value to evaluate.
  7291. * @returns {number} Returns the index at which `value` should be inserted
  7292. * into `array`.
  7293. * @example
  7294. *
  7295. * _.sortedIndex([30, 50], 40);
  7296. * // => 1
  7297. */
  7298. function sortedIndex(array, value) {
  7299. return baseSortedIndex(array, value);
  7300. }
  7301. /**
  7302. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7303. * which is invoked for `value` and each element of `array` to compute their
  7304. * sort ranking. The iteratee is invoked with one argument: (value).
  7305. *
  7306. * @static
  7307. * @memberOf _
  7308. * @since 4.0.0
  7309. * @category Array
  7310. * @param {Array} array The sorted array to inspect.
  7311. * @param {*} value The value to evaluate.
  7312. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7313. * @returns {number} Returns the index at which `value` should be inserted
  7314. * into `array`.
  7315. * @example
  7316. *
  7317. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7318. *
  7319. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7320. * // => 0
  7321. *
  7322. * // The `_.property` iteratee shorthand.
  7323. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7324. * // => 0
  7325. */
  7326. function sortedIndexBy(array, value, iteratee) {
  7327. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7328. }
  7329. /**
  7330. * This method is like `_.indexOf` except that it performs a binary
  7331. * search on a sorted `array`.
  7332. *
  7333. * @static
  7334. * @memberOf _
  7335. * @since 4.0.0
  7336. * @category Array
  7337. * @param {Array} array The array to inspect.
  7338. * @param {*} value The value to search for.
  7339. * @returns {number} Returns the index of the matched value, else `-1`.
  7340. * @example
  7341. *
  7342. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7343. * // => 1
  7344. */
  7345. function sortedIndexOf(array, value) {
  7346. var length = array == null ? 0 : array.length;
  7347. if (length) {
  7348. var index = baseSortedIndex(array, value);
  7349. if (index < length && eq(array[index], value)) {
  7350. return index;
  7351. }
  7352. }
  7353. return -1;
  7354. }
  7355. /**
  7356. * This method is like `_.sortedIndex` except that it returns the highest
  7357. * index at which `value` should be inserted into `array` in order to
  7358. * maintain its sort order.
  7359. *
  7360. * @static
  7361. * @memberOf _
  7362. * @since 3.0.0
  7363. * @category Array
  7364. * @param {Array} array The sorted array to inspect.
  7365. * @param {*} value The value to evaluate.
  7366. * @returns {number} Returns the index at which `value` should be inserted
  7367. * into `array`.
  7368. * @example
  7369. *
  7370. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7371. * // => 4
  7372. */
  7373. function sortedLastIndex(array, value) {
  7374. return baseSortedIndex(array, value, true);
  7375. }
  7376. /**
  7377. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7378. * which is invoked for `value` and each element of `array` to compute their
  7379. * sort ranking. The iteratee is invoked with one argument: (value).
  7380. *
  7381. * @static
  7382. * @memberOf _
  7383. * @since 4.0.0
  7384. * @category Array
  7385. * @param {Array} array The sorted array to inspect.
  7386. * @param {*} value The value to evaluate.
  7387. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7388. * @returns {number} Returns the index at which `value` should be inserted
  7389. * into `array`.
  7390. * @example
  7391. *
  7392. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7393. *
  7394. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7395. * // => 1
  7396. *
  7397. * // The `_.property` iteratee shorthand.
  7398. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7399. * // => 1
  7400. */
  7401. function sortedLastIndexBy(array, value, iteratee) {
  7402. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7403. }
  7404. /**
  7405. * This method is like `_.lastIndexOf` except that it performs a binary
  7406. * search on a sorted `array`.
  7407. *
  7408. * @static
  7409. * @memberOf _
  7410. * @since 4.0.0
  7411. * @category Array
  7412. * @param {Array} array The array to inspect.
  7413. * @param {*} value The value to search for.
  7414. * @returns {number} Returns the index of the matched value, else `-1`.
  7415. * @example
  7416. *
  7417. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7418. * // => 3
  7419. */
  7420. function sortedLastIndexOf(array, value) {
  7421. var length = array == null ? 0 : array.length;
  7422. if (length) {
  7423. var index = baseSortedIndex(array, value, true) - 1;
  7424. if (eq(array[index], value)) {
  7425. return index;
  7426. }
  7427. }
  7428. return -1;
  7429. }
  7430. /**
  7431. * This method is like `_.uniq` except that it's designed and optimized
  7432. * for sorted arrays.
  7433. *
  7434. * @static
  7435. * @memberOf _
  7436. * @since 4.0.0
  7437. * @category Array
  7438. * @param {Array} array The array to inspect.
  7439. * @returns {Array} Returns the new duplicate free array.
  7440. * @example
  7441. *
  7442. * _.sortedUniq([1, 1, 2]);
  7443. * // => [1, 2]
  7444. */
  7445. function sortedUniq(array) {
  7446. return (array && array.length)
  7447. ? baseSortedUniq(array)
  7448. : [];
  7449. }
  7450. /**
  7451. * This method is like `_.uniqBy` except that it's designed and optimized
  7452. * for sorted arrays.
  7453. *
  7454. * @static
  7455. * @memberOf _
  7456. * @since 4.0.0
  7457. * @category Array
  7458. * @param {Array} array The array to inspect.
  7459. * @param {Function} [iteratee] The iteratee invoked per element.
  7460. * @returns {Array} Returns the new duplicate free array.
  7461. * @example
  7462. *
  7463. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7464. * // => [1.1, 2.3]
  7465. */
  7466. function sortedUniqBy(array, iteratee) {
  7467. return (array && array.length)
  7468. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7469. : [];
  7470. }
  7471. /**
  7472. * Gets all but the first element of `array`.
  7473. *
  7474. * @static
  7475. * @memberOf _
  7476. * @since 4.0.0
  7477. * @category Array
  7478. * @param {Array} array The array to query.
  7479. * @returns {Array} Returns the slice of `array`.
  7480. * @example
  7481. *
  7482. * _.tail([1, 2, 3]);
  7483. * // => [2, 3]
  7484. */
  7485. function tail(array) {
  7486. var length = array == null ? 0 : array.length;
  7487. return length ? baseSlice(array, 1, length) : [];
  7488. }
  7489. /**
  7490. * Creates a slice of `array` with `n` elements taken from the beginning.
  7491. *
  7492. * @static
  7493. * @memberOf _
  7494. * @since 0.1.0
  7495. * @category Array
  7496. * @param {Array} array The array to query.
  7497. * @param {number} [n=1] The number of elements to take.
  7498. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7499. * @returns {Array} Returns the slice of `array`.
  7500. * @example
  7501. *
  7502. * _.take([1, 2, 3]);
  7503. * // => [1]
  7504. *
  7505. * _.take([1, 2, 3], 2);
  7506. * // => [1, 2]
  7507. *
  7508. * _.take([1, 2, 3], 5);
  7509. * // => [1, 2, 3]
  7510. *
  7511. * _.take([1, 2, 3], 0);
  7512. * // => []
  7513. */
  7514. function take(array, n, guard) {
  7515. if (!(array && array.length)) {
  7516. return [];
  7517. }
  7518. n = (guard || n === undefined) ? 1 : toInteger(n);
  7519. return baseSlice(array, 0, n < 0 ? 0 : n);
  7520. }
  7521. /**
  7522. * Creates a slice of `array` with `n` elements taken from the end.
  7523. *
  7524. * @static
  7525. * @memberOf _
  7526. * @since 3.0.0
  7527. * @category Array
  7528. * @param {Array} array The array to query.
  7529. * @param {number} [n=1] The number of elements to take.
  7530. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7531. * @returns {Array} Returns the slice of `array`.
  7532. * @example
  7533. *
  7534. * _.takeRight([1, 2, 3]);
  7535. * // => [3]
  7536. *
  7537. * _.takeRight([1, 2, 3], 2);
  7538. * // => [2, 3]
  7539. *
  7540. * _.takeRight([1, 2, 3], 5);
  7541. * // => [1, 2, 3]
  7542. *
  7543. * _.takeRight([1, 2, 3], 0);
  7544. * // => []
  7545. */
  7546. function takeRight(array, n, guard) {
  7547. var length = array == null ? 0 : array.length;
  7548. if (!length) {
  7549. return [];
  7550. }
  7551. n = (guard || n === undefined) ? 1 : toInteger(n);
  7552. n = length - n;
  7553. return baseSlice(array, n < 0 ? 0 : n, length);
  7554. }
  7555. /**
  7556. * Creates a slice of `array` with elements taken from the end. Elements are
  7557. * taken until `predicate` returns falsey. The predicate is invoked with
  7558. * three arguments: (value, index, array).
  7559. *
  7560. * @static
  7561. * @memberOf _
  7562. * @since 3.0.0
  7563. * @category Array
  7564. * @param {Array} array The array to query.
  7565. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7566. * @returns {Array} Returns the slice of `array`.
  7567. * @example
  7568. *
  7569. * var users = [
  7570. * { 'user': 'barney', 'active': true },
  7571. * { 'user': 'fred', 'active': false },
  7572. * { 'user': 'pebbles', 'active': false }
  7573. * ];
  7574. *
  7575. * _.takeRightWhile(users, function(o) { return !o.active; });
  7576. * // => objects for ['fred', 'pebbles']
  7577. *
  7578. * // The `_.matches` iteratee shorthand.
  7579. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7580. * // => objects for ['pebbles']
  7581. *
  7582. * // The `_.matchesProperty` iteratee shorthand.
  7583. * _.takeRightWhile(users, ['active', false]);
  7584. * // => objects for ['fred', 'pebbles']
  7585. *
  7586. * // The `_.property` iteratee shorthand.
  7587. * _.takeRightWhile(users, 'active');
  7588. * // => []
  7589. */
  7590. function takeRightWhile(array, predicate) {
  7591. return (array && array.length)
  7592. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7593. : [];
  7594. }
  7595. /**
  7596. * Creates a slice of `array` with elements taken from the beginning. Elements
  7597. * are taken until `predicate` returns falsey. The predicate is invoked with
  7598. * three arguments: (value, index, array).
  7599. *
  7600. * @static
  7601. * @memberOf _
  7602. * @since 3.0.0
  7603. * @category Array
  7604. * @param {Array} array The array to query.
  7605. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7606. * @returns {Array} Returns the slice of `array`.
  7607. * @example
  7608. *
  7609. * var users = [
  7610. * { 'user': 'barney', 'active': false },
  7611. * { 'user': 'fred', 'active': false },
  7612. * { 'user': 'pebbles', 'active': true }
  7613. * ];
  7614. *
  7615. * _.takeWhile(users, function(o) { return !o.active; });
  7616. * // => objects for ['barney', 'fred']
  7617. *
  7618. * // The `_.matches` iteratee shorthand.
  7619. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7620. * // => objects for ['barney']
  7621. *
  7622. * // The `_.matchesProperty` iteratee shorthand.
  7623. * _.takeWhile(users, ['active', false]);
  7624. * // => objects for ['barney', 'fred']
  7625. *
  7626. * // The `_.property` iteratee shorthand.
  7627. * _.takeWhile(users, 'active');
  7628. * // => []
  7629. */
  7630. function takeWhile(array, predicate) {
  7631. return (array && array.length)
  7632. ? baseWhile(array, getIteratee(predicate, 3))
  7633. : [];
  7634. }
  7635. /**
  7636. * Creates an array of unique values, in order, from all given arrays using
  7637. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7638. * for equality comparisons.
  7639. *
  7640. * @static
  7641. * @memberOf _
  7642. * @since 0.1.0
  7643. * @category Array
  7644. * @param {...Array} [arrays] The arrays to inspect.
  7645. * @returns {Array} Returns the new array of combined values.
  7646. * @example
  7647. *
  7648. * _.union([2], [1, 2]);
  7649. * // => [2, 1]
  7650. */
  7651. var union = baseRest(function(arrays) {
  7652. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7653. });
  7654. /**
  7655. * This method is like `_.union` except that it accepts `iteratee` which is
  7656. * invoked for each element of each `arrays` to generate the criterion by
  7657. * which uniqueness is computed. Result values are chosen from the first
  7658. * array in which the value occurs. The iteratee is invoked with one argument:
  7659. * (value).
  7660. *
  7661. * @static
  7662. * @memberOf _
  7663. * @since 4.0.0
  7664. * @category Array
  7665. * @param {...Array} [arrays] The arrays to inspect.
  7666. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7667. * @returns {Array} Returns the new array of combined values.
  7668. * @example
  7669. *
  7670. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7671. * // => [2.1, 1.2]
  7672. *
  7673. * // The `_.property` iteratee shorthand.
  7674. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7675. * // => [{ 'x': 1 }, { 'x': 2 }]
  7676. */
  7677. var unionBy = baseRest(function(arrays) {
  7678. var iteratee = last(arrays);
  7679. if (isArrayLikeObject(iteratee)) {
  7680. iteratee = undefined;
  7681. }
  7682. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7683. });
  7684. /**
  7685. * This method is like `_.union` except that it accepts `comparator` which
  7686. * is invoked to compare elements of `arrays`. Result values are chosen from
  7687. * the first array in which the value occurs. The comparator is invoked
  7688. * with two arguments: (arrVal, othVal).
  7689. *
  7690. * @static
  7691. * @memberOf _
  7692. * @since 4.0.0
  7693. * @category Array
  7694. * @param {...Array} [arrays] The arrays to inspect.
  7695. * @param {Function} [comparator] The comparator invoked per element.
  7696. * @returns {Array} Returns the new array of combined values.
  7697. * @example
  7698. *
  7699. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7700. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7701. *
  7702. * _.unionWith(objects, others, _.isEqual);
  7703. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7704. */
  7705. var unionWith = baseRest(function(arrays) {
  7706. var comparator = last(arrays);
  7707. comparator = typeof comparator == 'function' ? comparator : undefined;
  7708. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7709. });
  7710. /**
  7711. * Creates a duplicate-free version of an array, using
  7712. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7713. * for equality comparisons, in which only the first occurrence of each element
  7714. * is kept. The order of result values is determined by the order they occur
  7715. * in the array.
  7716. *
  7717. * @static
  7718. * @memberOf _
  7719. * @since 0.1.0
  7720. * @category Array
  7721. * @param {Array} array The array to inspect.
  7722. * @returns {Array} Returns the new duplicate free array.
  7723. * @example
  7724. *
  7725. * _.uniq([2, 1, 2]);
  7726. * // => [2, 1]
  7727. */
  7728. function uniq(array) {
  7729. return (array && array.length) ? baseUniq(array) : [];
  7730. }
  7731. /**
  7732. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7733. * invoked for each element in `array` to generate the criterion by which
  7734. * uniqueness is computed. The order of result values is determined by the
  7735. * order they occur in the array. The iteratee is invoked with one argument:
  7736. * (value).
  7737. *
  7738. * @static
  7739. * @memberOf _
  7740. * @since 4.0.0
  7741. * @category Array
  7742. * @param {Array} array The array to inspect.
  7743. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7744. * @returns {Array} Returns the new duplicate free array.
  7745. * @example
  7746. *
  7747. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7748. * // => [2.1, 1.2]
  7749. *
  7750. * // The `_.property` iteratee shorthand.
  7751. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7752. * // => [{ 'x': 1 }, { 'x': 2 }]
  7753. */
  7754. function uniqBy(array, iteratee) {
  7755. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7756. }
  7757. /**
  7758. * This method is like `_.uniq` except that it accepts `comparator` which
  7759. * is invoked to compare elements of `array`. The order of result values is
  7760. * determined by the order they occur in the array.The comparator is invoked
  7761. * with two arguments: (arrVal, othVal).
  7762. *
  7763. * @static
  7764. * @memberOf _
  7765. * @since 4.0.0
  7766. * @category Array
  7767. * @param {Array} array The array to inspect.
  7768. * @param {Function} [comparator] The comparator invoked per element.
  7769. * @returns {Array} Returns the new duplicate free array.
  7770. * @example
  7771. *
  7772. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7773. *
  7774. * _.uniqWith(objects, _.isEqual);
  7775. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7776. */
  7777. function uniqWith(array, comparator) {
  7778. comparator = typeof comparator == 'function' ? comparator : undefined;
  7779. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7780. }
  7781. /**
  7782. * This method is like `_.zip` except that it accepts an array of grouped
  7783. * elements and creates an array regrouping the elements to their pre-zip
  7784. * configuration.
  7785. *
  7786. * @static
  7787. * @memberOf _
  7788. * @since 1.2.0
  7789. * @category Array
  7790. * @param {Array} array The array of grouped elements to process.
  7791. * @returns {Array} Returns the new array of regrouped elements.
  7792. * @example
  7793. *
  7794. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7795. * // => [['a', 1, true], ['b', 2, false]]
  7796. *
  7797. * _.unzip(zipped);
  7798. * // => [['a', 'b'], [1, 2], [true, false]]
  7799. */
  7800. function unzip(array) {
  7801. if (!(array && array.length)) {
  7802. return [];
  7803. }
  7804. var length = 0;
  7805. array = arrayFilter(array, function(group) {
  7806. if (isArrayLikeObject(group)) {
  7807. length = nativeMax(group.length, length);
  7808. return true;
  7809. }
  7810. });
  7811. return baseTimes(length, function(index) {
  7812. return arrayMap(array, baseProperty(index));
  7813. });
  7814. }
  7815. /**
  7816. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7817. * how regrouped values should be combined. The iteratee is invoked with the
  7818. * elements of each group: (...group).
  7819. *
  7820. * @static
  7821. * @memberOf _
  7822. * @since 3.8.0
  7823. * @category Array
  7824. * @param {Array} array The array of grouped elements to process.
  7825. * @param {Function} [iteratee=_.identity] The function to combine
  7826. * regrouped values.
  7827. * @returns {Array} Returns the new array of regrouped elements.
  7828. * @example
  7829. *
  7830. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7831. * // => [[1, 10, 100], [2, 20, 200]]
  7832. *
  7833. * _.unzipWith(zipped, _.add);
  7834. * // => [3, 30, 300]
  7835. */
  7836. function unzipWith(array, iteratee) {
  7837. if (!(array && array.length)) {
  7838. return [];
  7839. }
  7840. var result = unzip(array);
  7841. if (iteratee == null) {
  7842. return result;
  7843. }
  7844. return arrayMap(result, function(group) {
  7845. return apply(iteratee, undefined, group);
  7846. });
  7847. }
  7848. /**
  7849. * Creates an array excluding all given values using
  7850. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7851. * for equality comparisons.
  7852. *
  7853. * **Note:** Unlike `_.pull`, this method returns a new array.
  7854. *
  7855. * @static
  7856. * @memberOf _
  7857. * @since 0.1.0
  7858. * @category Array
  7859. * @param {Array} array The array to inspect.
  7860. * @param {...*} [values] The values to exclude.
  7861. * @returns {Array} Returns the new array of filtered values.
  7862. * @see _.difference, _.xor
  7863. * @example
  7864. *
  7865. * _.without([2, 1, 2, 3], 1, 2);
  7866. * // => [3]
  7867. */
  7868. var without = baseRest(function(array, values) {
  7869. return isArrayLikeObject(array)
  7870. ? baseDifference(array, values)
  7871. : [];
  7872. });
  7873. /**
  7874. * Creates an array of unique values that is the
  7875. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7876. * of the given arrays. The order of result values is determined by the order
  7877. * they occur in the arrays.
  7878. *
  7879. * @static
  7880. * @memberOf _
  7881. * @since 2.4.0
  7882. * @category Array
  7883. * @param {...Array} [arrays] The arrays to inspect.
  7884. * @returns {Array} Returns the new array of filtered values.
  7885. * @see _.difference, _.without
  7886. * @example
  7887. *
  7888. * _.xor([2, 1], [2, 3]);
  7889. * // => [1, 3]
  7890. */
  7891. var xor = baseRest(function(arrays) {
  7892. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7893. });
  7894. /**
  7895. * This method is like `_.xor` except that it accepts `iteratee` which is
  7896. * invoked for each element of each `arrays` to generate the criterion by
  7897. * which by which they're compared. The order of result values is determined
  7898. * by the order they occur in the arrays. The iteratee is invoked with one
  7899. * argument: (value).
  7900. *
  7901. * @static
  7902. * @memberOf _
  7903. * @since 4.0.0
  7904. * @category Array
  7905. * @param {...Array} [arrays] The arrays to inspect.
  7906. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7907. * @returns {Array} Returns the new array of filtered values.
  7908. * @example
  7909. *
  7910. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7911. * // => [1.2, 3.4]
  7912. *
  7913. * // The `_.property` iteratee shorthand.
  7914. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7915. * // => [{ 'x': 2 }]
  7916. */
  7917. var xorBy = baseRest(function(arrays) {
  7918. var iteratee = last(arrays);
  7919. if (isArrayLikeObject(iteratee)) {
  7920. iteratee = undefined;
  7921. }
  7922. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7923. });
  7924. /**
  7925. * This method is like `_.xor` except that it accepts `comparator` which is
  7926. * invoked to compare elements of `arrays`. The order of result values is
  7927. * determined by the order they occur in the arrays. The comparator is invoked
  7928. * with two arguments: (arrVal, othVal).
  7929. *
  7930. * @static
  7931. * @memberOf _
  7932. * @since 4.0.0
  7933. * @category Array
  7934. * @param {...Array} [arrays] The arrays to inspect.
  7935. * @param {Function} [comparator] The comparator invoked per element.
  7936. * @returns {Array} Returns the new array of filtered values.
  7937. * @example
  7938. *
  7939. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7940. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7941. *
  7942. * _.xorWith(objects, others, _.isEqual);
  7943. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7944. */
  7945. var xorWith = baseRest(function(arrays) {
  7946. var comparator = last(arrays);
  7947. comparator = typeof comparator == 'function' ? comparator : undefined;
  7948. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7949. });
  7950. /**
  7951. * Creates an array of grouped elements, the first of which contains the
  7952. * first elements of the given arrays, the second of which contains the
  7953. * second elements of the given arrays, and so on.
  7954. *
  7955. * @static
  7956. * @memberOf _
  7957. * @since 0.1.0
  7958. * @category Array
  7959. * @param {...Array} [arrays] The arrays to process.
  7960. * @returns {Array} Returns the new array of grouped elements.
  7961. * @example
  7962. *
  7963. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7964. * // => [['a', 1, true], ['b', 2, false]]
  7965. */
  7966. var zip = baseRest(unzip);
  7967. /**
  7968. * This method is like `_.fromPairs` except that it accepts two arrays,
  7969. * one of property identifiers and one of corresponding values.
  7970. *
  7971. * @static
  7972. * @memberOf _
  7973. * @since 0.4.0
  7974. * @category Array
  7975. * @param {Array} [props=[]] The property identifiers.
  7976. * @param {Array} [values=[]] The property values.
  7977. * @returns {Object} Returns the new object.
  7978. * @example
  7979. *
  7980. * _.zipObject(['a', 'b'], [1, 2]);
  7981. * // => { 'a': 1, 'b': 2 }
  7982. */
  7983. function zipObject(props, values) {
  7984. return baseZipObject(props || [], values || [], assignValue);
  7985. }
  7986. /**
  7987. * This method is like `_.zipObject` except that it supports property paths.
  7988. *
  7989. * @static
  7990. * @memberOf _
  7991. * @since 4.1.0
  7992. * @category Array
  7993. * @param {Array} [props=[]] The property identifiers.
  7994. * @param {Array} [values=[]] The property values.
  7995. * @returns {Object} Returns the new object.
  7996. * @example
  7997. *
  7998. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  7999. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8000. */
  8001. function zipObjectDeep(props, values) {
  8002. return baseZipObject(props || [], values || [], baseSet);
  8003. }
  8004. /**
  8005. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8006. * how grouped values should be combined. The iteratee is invoked with the
  8007. * elements of each group: (...group).
  8008. *
  8009. * @static
  8010. * @memberOf _
  8011. * @since 3.8.0
  8012. * @category Array
  8013. * @param {...Array} [arrays] The arrays to process.
  8014. * @param {Function} [iteratee=_.identity] The function to combine
  8015. * grouped values.
  8016. * @returns {Array} Returns the new array of grouped elements.
  8017. * @example
  8018. *
  8019. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8020. * return a + b + c;
  8021. * });
  8022. * // => [111, 222]
  8023. */
  8024. var zipWith = baseRest(function(arrays) {
  8025. var length = arrays.length,
  8026. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8027. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8028. return unzipWith(arrays, iteratee);
  8029. });
  8030. /*------------------------------------------------------------------------*/
  8031. /**
  8032. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8033. * chain sequences enabled. The result of such sequences must be unwrapped
  8034. * with `_#value`.
  8035. *
  8036. * @static
  8037. * @memberOf _
  8038. * @since 1.3.0
  8039. * @category Seq
  8040. * @param {*} value The value to wrap.
  8041. * @returns {Object} Returns the new `lodash` wrapper instance.
  8042. * @example
  8043. *
  8044. * var users = [
  8045. * { 'user': 'barney', 'age': 36 },
  8046. * { 'user': 'fred', 'age': 40 },
  8047. * { 'user': 'pebbles', 'age': 1 }
  8048. * ];
  8049. *
  8050. * var youngest = _
  8051. * .chain(users)
  8052. * .sortBy('age')
  8053. * .map(function(o) {
  8054. * return o.user + ' is ' + o.age;
  8055. * })
  8056. * .head()
  8057. * .value();
  8058. * // => 'pebbles is 1'
  8059. */
  8060. function chain(value) {
  8061. var result = lodash(value);
  8062. result.__chain__ = true;
  8063. return result;
  8064. }
  8065. /**
  8066. * This method invokes `interceptor` and returns `value`. The interceptor
  8067. * is invoked with one argument; (value). The purpose of this method is to
  8068. * "tap into" a method chain sequence in order to modify intermediate results.
  8069. *
  8070. * @static
  8071. * @memberOf _
  8072. * @since 0.1.0
  8073. * @category Seq
  8074. * @param {*} value The value to provide to `interceptor`.
  8075. * @param {Function} interceptor The function to invoke.
  8076. * @returns {*} Returns `value`.
  8077. * @example
  8078. *
  8079. * _([1, 2, 3])
  8080. * .tap(function(array) {
  8081. * // Mutate input array.
  8082. * array.pop();
  8083. * })
  8084. * .reverse()
  8085. * .value();
  8086. * // => [2, 1]
  8087. */
  8088. function tap(value, interceptor) {
  8089. interceptor(value);
  8090. return value;
  8091. }
  8092. /**
  8093. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8094. * The purpose of this method is to "pass thru" values replacing intermediate
  8095. * results in a method chain sequence.
  8096. *
  8097. * @static
  8098. * @memberOf _
  8099. * @since 3.0.0
  8100. * @category Seq
  8101. * @param {*} value The value to provide to `interceptor`.
  8102. * @param {Function} interceptor The function to invoke.
  8103. * @returns {*} Returns the result of `interceptor`.
  8104. * @example
  8105. *
  8106. * _(' abc ')
  8107. * .chain()
  8108. * .trim()
  8109. * .thru(function(value) {
  8110. * return [value];
  8111. * })
  8112. * .value();
  8113. * // => ['abc']
  8114. */
  8115. function thru(value, interceptor) {
  8116. return interceptor(value);
  8117. }
  8118. /**
  8119. * This method is the wrapper version of `_.at`.
  8120. *
  8121. * @name at
  8122. * @memberOf _
  8123. * @since 1.0.0
  8124. * @category Seq
  8125. * @param {...(string|string[])} [paths] The property paths to pick.
  8126. * @returns {Object} Returns the new `lodash` wrapper instance.
  8127. * @example
  8128. *
  8129. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8130. *
  8131. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8132. * // => [3, 4]
  8133. */
  8134. var wrapperAt = flatRest(function(paths) {
  8135. var length = paths.length,
  8136. start = length ? paths[0] : 0,
  8137. value = this.__wrapped__,
  8138. interceptor = function(object) { return baseAt(object, paths); };
  8139. if (length > 1 || this.__actions__.length ||
  8140. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8141. return this.thru(interceptor);
  8142. }
  8143. value = value.slice(start, +start + (length ? 1 : 0));
  8144. value.__actions__.push({
  8145. 'func': thru,
  8146. 'args': [interceptor],
  8147. 'thisArg': undefined
  8148. });
  8149. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8150. if (length && !array.length) {
  8151. array.push(undefined);
  8152. }
  8153. return array;
  8154. });
  8155. });
  8156. /**
  8157. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8158. *
  8159. * @name chain
  8160. * @memberOf _
  8161. * @since 0.1.0
  8162. * @category Seq
  8163. * @returns {Object} Returns the new `lodash` wrapper instance.
  8164. * @example
  8165. *
  8166. * var users = [
  8167. * { 'user': 'barney', 'age': 36 },
  8168. * { 'user': 'fred', 'age': 40 }
  8169. * ];
  8170. *
  8171. * // A sequence without explicit chaining.
  8172. * _(users).head();
  8173. * // => { 'user': 'barney', 'age': 36 }
  8174. *
  8175. * // A sequence with explicit chaining.
  8176. * _(users)
  8177. * .chain()
  8178. * .head()
  8179. * .pick('user')
  8180. * .value();
  8181. * // => { 'user': 'barney' }
  8182. */
  8183. function wrapperChain() {
  8184. return chain(this);
  8185. }
  8186. /**
  8187. * Executes the chain sequence and returns the wrapped result.
  8188. *
  8189. * @name commit
  8190. * @memberOf _
  8191. * @since 3.2.0
  8192. * @category Seq
  8193. * @returns {Object} Returns the new `lodash` wrapper instance.
  8194. * @example
  8195. *
  8196. * var array = [1, 2];
  8197. * var wrapped = _(array).push(3);
  8198. *
  8199. * console.log(array);
  8200. * // => [1, 2]
  8201. *
  8202. * wrapped = wrapped.commit();
  8203. * console.log(array);
  8204. * // => [1, 2, 3]
  8205. *
  8206. * wrapped.last();
  8207. * // => 3
  8208. *
  8209. * console.log(array);
  8210. * // => [1, 2, 3]
  8211. */
  8212. function wrapperCommit() {
  8213. return new LodashWrapper(this.value(), this.__chain__);
  8214. }
  8215. /**
  8216. * Gets the next value on a wrapped object following the
  8217. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8218. *
  8219. * @name next
  8220. * @memberOf _
  8221. * @since 4.0.0
  8222. * @category Seq
  8223. * @returns {Object} Returns the next iterator value.
  8224. * @example
  8225. *
  8226. * var wrapped = _([1, 2]);
  8227. *
  8228. * wrapped.next();
  8229. * // => { 'done': false, 'value': 1 }
  8230. *
  8231. * wrapped.next();
  8232. * // => { 'done': false, 'value': 2 }
  8233. *
  8234. * wrapped.next();
  8235. * // => { 'done': true, 'value': undefined }
  8236. */
  8237. function wrapperNext() {
  8238. if (this.__values__ === undefined) {
  8239. this.__values__ = toArray(this.value());
  8240. }
  8241. var done = this.__index__ >= this.__values__.length,
  8242. value = done ? undefined : this.__values__[this.__index__++];
  8243. return { 'done': done, 'value': value };
  8244. }
  8245. /**
  8246. * Enables the wrapper to be iterable.
  8247. *
  8248. * @name Symbol.iterator
  8249. * @memberOf _
  8250. * @since 4.0.0
  8251. * @category Seq
  8252. * @returns {Object} Returns the wrapper object.
  8253. * @example
  8254. *
  8255. * var wrapped = _([1, 2]);
  8256. *
  8257. * wrapped[Symbol.iterator]() === wrapped;
  8258. * // => true
  8259. *
  8260. * Array.from(wrapped);
  8261. * // => [1, 2]
  8262. */
  8263. function wrapperToIterator() {
  8264. return this;
  8265. }
  8266. /**
  8267. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8268. *
  8269. * @name plant
  8270. * @memberOf _
  8271. * @since 3.2.0
  8272. * @category Seq
  8273. * @param {*} value The value to plant.
  8274. * @returns {Object} Returns the new `lodash` wrapper instance.
  8275. * @example
  8276. *
  8277. * function square(n) {
  8278. * return n * n;
  8279. * }
  8280. *
  8281. * var wrapped = _([1, 2]).map(square);
  8282. * var other = wrapped.plant([3, 4]);
  8283. *
  8284. * other.value();
  8285. * // => [9, 16]
  8286. *
  8287. * wrapped.value();
  8288. * // => [1, 4]
  8289. */
  8290. function wrapperPlant(value) {
  8291. var result,
  8292. parent = this;
  8293. while (parent instanceof baseLodash) {
  8294. var clone = wrapperClone(parent);
  8295. clone.__index__ = 0;
  8296. clone.__values__ = undefined;
  8297. if (result) {
  8298. previous.__wrapped__ = clone;
  8299. } else {
  8300. result = clone;
  8301. }
  8302. var previous = clone;
  8303. parent = parent.__wrapped__;
  8304. }
  8305. previous.__wrapped__ = value;
  8306. return result;
  8307. }
  8308. /**
  8309. * This method is the wrapper version of `_.reverse`.
  8310. *
  8311. * **Note:** This method mutates the wrapped array.
  8312. *
  8313. * @name reverse
  8314. * @memberOf _
  8315. * @since 0.1.0
  8316. * @category Seq
  8317. * @returns {Object} Returns the new `lodash` wrapper instance.
  8318. * @example
  8319. *
  8320. * var array = [1, 2, 3];
  8321. *
  8322. * _(array).reverse().value()
  8323. * // => [3, 2, 1]
  8324. *
  8325. * console.log(array);
  8326. * // => [3, 2, 1]
  8327. */
  8328. function wrapperReverse() {
  8329. var value = this.__wrapped__;
  8330. if (value instanceof LazyWrapper) {
  8331. var wrapped = value;
  8332. if (this.__actions__.length) {
  8333. wrapped = new LazyWrapper(this);
  8334. }
  8335. wrapped = wrapped.reverse();
  8336. wrapped.__actions__.push({
  8337. 'func': thru,
  8338. 'args': [reverse],
  8339. 'thisArg': undefined
  8340. });
  8341. return new LodashWrapper(wrapped, this.__chain__);
  8342. }
  8343. return this.thru(reverse);
  8344. }
  8345. /**
  8346. * Executes the chain sequence to resolve the unwrapped value.
  8347. *
  8348. * @name value
  8349. * @memberOf _
  8350. * @since 0.1.0
  8351. * @alias toJSON, valueOf
  8352. * @category Seq
  8353. * @returns {*} Returns the resolved unwrapped value.
  8354. * @example
  8355. *
  8356. * _([1, 2, 3]).value();
  8357. * // => [1, 2, 3]
  8358. */
  8359. function wrapperValue() {
  8360. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8361. }
  8362. /*------------------------------------------------------------------------*/
  8363. /**
  8364. * Creates an object composed of keys generated from the results of running
  8365. * each element of `collection` thru `iteratee`. The corresponding value of
  8366. * each key is the number of times the key was returned by `iteratee`. The
  8367. * iteratee is invoked with one argument: (value).
  8368. *
  8369. * @static
  8370. * @memberOf _
  8371. * @since 0.5.0
  8372. * @category Collection
  8373. * @param {Array|Object} collection The collection to iterate over.
  8374. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8375. * @returns {Object} Returns the composed aggregate object.
  8376. * @example
  8377. *
  8378. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8379. * // => { '4': 1, '6': 2 }
  8380. *
  8381. * // The `_.property` iteratee shorthand.
  8382. * _.countBy(['one', 'two', 'three'], 'length');
  8383. * // => { '3': 2, '5': 1 }
  8384. */
  8385. var countBy = createAggregator(function(result, value, key) {
  8386. if (hasOwnProperty.call(result, key)) {
  8387. ++result[key];
  8388. } else {
  8389. baseAssignValue(result, key, 1);
  8390. }
  8391. });
  8392. /**
  8393. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8394. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8395. * invoked with three arguments: (value, index|key, collection).
  8396. *
  8397. * **Note:** This method returns `true` for
  8398. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8399. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8400. * elements of empty collections.
  8401. *
  8402. * @static
  8403. * @memberOf _
  8404. * @since 0.1.0
  8405. * @category Collection
  8406. * @param {Array|Object} collection The collection to iterate over.
  8407. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8408. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8409. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8410. * else `false`.
  8411. * @example
  8412. *
  8413. * _.every([true, 1, null, 'yes'], Boolean);
  8414. * // => false
  8415. *
  8416. * var users = [
  8417. * { 'user': 'barney', 'age': 36, 'active': false },
  8418. * { 'user': 'fred', 'age': 40, 'active': false }
  8419. * ];
  8420. *
  8421. * // The `_.matches` iteratee shorthand.
  8422. * _.every(users, { 'user': 'barney', 'active': false });
  8423. * // => false
  8424. *
  8425. * // The `_.matchesProperty` iteratee shorthand.
  8426. * _.every(users, ['active', false]);
  8427. * // => true
  8428. *
  8429. * // The `_.property` iteratee shorthand.
  8430. * _.every(users, 'active');
  8431. * // => false
  8432. */
  8433. function every(collection, predicate, guard) {
  8434. var func = isArray(collection) ? arrayEvery : baseEvery;
  8435. if (guard && isIterateeCall(collection, predicate, guard)) {
  8436. predicate = undefined;
  8437. }
  8438. return func(collection, getIteratee(predicate, 3));
  8439. }
  8440. /**
  8441. * Iterates over elements of `collection`, returning an array of all elements
  8442. * `predicate` returns truthy for. The predicate is invoked with three
  8443. * arguments: (value, index|key, collection).
  8444. *
  8445. * **Note:** Unlike `_.remove`, this method returns a new array.
  8446. *
  8447. * @static
  8448. * @memberOf _
  8449. * @since 0.1.0
  8450. * @category Collection
  8451. * @param {Array|Object} collection The collection to iterate over.
  8452. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8453. * @returns {Array} Returns the new filtered array.
  8454. * @see _.reject
  8455. * @example
  8456. *
  8457. * var users = [
  8458. * { 'user': 'barney', 'age': 36, 'active': true },
  8459. * { 'user': 'fred', 'age': 40, 'active': false }
  8460. * ];
  8461. *
  8462. * _.filter(users, function(o) { return !o.active; });
  8463. * // => objects for ['fred']
  8464. *
  8465. * // The `_.matches` iteratee shorthand.
  8466. * _.filter(users, { 'age': 36, 'active': true });
  8467. * // => objects for ['barney']
  8468. *
  8469. * // The `_.matchesProperty` iteratee shorthand.
  8470. * _.filter(users, ['active', false]);
  8471. * // => objects for ['fred']
  8472. *
  8473. * // The `_.property` iteratee shorthand.
  8474. * _.filter(users, 'active');
  8475. * // => objects for ['barney']
  8476. */
  8477. function filter(collection, predicate) {
  8478. var func = isArray(collection) ? arrayFilter : baseFilter;
  8479. return func(collection, getIteratee(predicate, 3));
  8480. }
  8481. /**
  8482. * Iterates over elements of `collection`, returning the first element
  8483. * `predicate` returns truthy for. The predicate is invoked with three
  8484. * arguments: (value, index|key, collection).
  8485. *
  8486. * @static
  8487. * @memberOf _
  8488. * @since 0.1.0
  8489. * @category Collection
  8490. * @param {Array|Object} collection The collection to inspect.
  8491. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8492. * @param {number} [fromIndex=0] The index to search from.
  8493. * @returns {*} Returns the matched element, else `undefined`.
  8494. * @example
  8495. *
  8496. * var users = [
  8497. * { 'user': 'barney', 'age': 36, 'active': true },
  8498. * { 'user': 'fred', 'age': 40, 'active': false },
  8499. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8500. * ];
  8501. *
  8502. * _.find(users, function(o) { return o.age < 40; });
  8503. * // => object for 'barney'
  8504. *
  8505. * // The `_.matches` iteratee shorthand.
  8506. * _.find(users, { 'age': 1, 'active': true });
  8507. * // => object for 'pebbles'
  8508. *
  8509. * // The `_.matchesProperty` iteratee shorthand.
  8510. * _.find(users, ['active', false]);
  8511. * // => object for 'fred'
  8512. *
  8513. * // The `_.property` iteratee shorthand.
  8514. * _.find(users, 'active');
  8515. * // => object for 'barney'
  8516. */
  8517. var find = createFind(findIndex);
  8518. /**
  8519. * This method is like `_.find` except that it iterates over elements of
  8520. * `collection` from right to left.
  8521. *
  8522. * @static
  8523. * @memberOf _
  8524. * @since 2.0.0
  8525. * @category Collection
  8526. * @param {Array|Object} collection The collection to inspect.
  8527. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8528. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8529. * @returns {*} Returns the matched element, else `undefined`.
  8530. * @example
  8531. *
  8532. * _.findLast([1, 2, 3, 4], function(n) {
  8533. * return n % 2 == 1;
  8534. * });
  8535. * // => 3
  8536. */
  8537. var findLast = createFind(findLastIndex);
  8538. /**
  8539. * Creates a flattened array of values by running each element in `collection`
  8540. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8541. * with three arguments: (value, index|key, collection).
  8542. *
  8543. * @static
  8544. * @memberOf _
  8545. * @since 4.0.0
  8546. * @category Collection
  8547. * @param {Array|Object} collection The collection to iterate over.
  8548. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8549. * @returns {Array} Returns the new flattened array.
  8550. * @example
  8551. *
  8552. * function duplicate(n) {
  8553. * return [n, n];
  8554. * }
  8555. *
  8556. * _.flatMap([1, 2], duplicate);
  8557. * // => [1, 1, 2, 2]
  8558. */
  8559. function flatMap(collection, iteratee) {
  8560. return baseFlatten(map(collection, iteratee), 1);
  8561. }
  8562. /**
  8563. * This method is like `_.flatMap` except that it recursively flattens the
  8564. * mapped results.
  8565. *
  8566. * @static
  8567. * @memberOf _
  8568. * @since 4.7.0
  8569. * @category Collection
  8570. * @param {Array|Object} collection The collection to iterate over.
  8571. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8572. * @returns {Array} Returns the new flattened array.
  8573. * @example
  8574. *
  8575. * function duplicate(n) {
  8576. * return [[[n, n]]];
  8577. * }
  8578. *
  8579. * _.flatMapDeep([1, 2], duplicate);
  8580. * // => [1, 1, 2, 2]
  8581. */
  8582. function flatMapDeep(collection, iteratee) {
  8583. return baseFlatten(map(collection, iteratee), INFINITY);
  8584. }
  8585. /**
  8586. * This method is like `_.flatMap` except that it recursively flattens the
  8587. * mapped results up to `depth` times.
  8588. *
  8589. * @static
  8590. * @memberOf _
  8591. * @since 4.7.0
  8592. * @category Collection
  8593. * @param {Array|Object} collection The collection to iterate over.
  8594. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8595. * @param {number} [depth=1] The maximum recursion depth.
  8596. * @returns {Array} Returns the new flattened array.
  8597. * @example
  8598. *
  8599. * function duplicate(n) {
  8600. * return [[[n, n]]];
  8601. * }
  8602. *
  8603. * _.flatMapDepth([1, 2], duplicate, 2);
  8604. * // => [[1, 1], [2, 2]]
  8605. */
  8606. function flatMapDepth(collection, iteratee, depth) {
  8607. depth = depth === undefined ? 1 : toInteger(depth);
  8608. return baseFlatten(map(collection, iteratee), depth);
  8609. }
  8610. /**
  8611. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8612. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8613. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8614. *
  8615. * **Note:** As with other "Collections" methods, objects with a "length"
  8616. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8617. * or `_.forOwn` for object iteration.
  8618. *
  8619. * @static
  8620. * @memberOf _
  8621. * @since 0.1.0
  8622. * @alias each
  8623. * @category Collection
  8624. * @param {Array|Object} collection The collection to iterate over.
  8625. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8626. * @returns {Array|Object} Returns `collection`.
  8627. * @see _.forEachRight
  8628. * @example
  8629. *
  8630. * _.forEach([1, 2], function(value) {
  8631. * console.log(value);
  8632. * });
  8633. * // => Logs `1` then `2`.
  8634. *
  8635. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8636. * console.log(key);
  8637. * });
  8638. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8639. */
  8640. function forEach(collection, iteratee) {
  8641. var func = isArray(collection) ? arrayEach : baseEach;
  8642. return func(collection, getIteratee(iteratee, 3));
  8643. }
  8644. /**
  8645. * This method is like `_.forEach` except that it iterates over elements of
  8646. * `collection` from right to left.
  8647. *
  8648. * @static
  8649. * @memberOf _
  8650. * @since 2.0.0
  8651. * @alias eachRight
  8652. * @category Collection
  8653. * @param {Array|Object} collection The collection to iterate over.
  8654. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8655. * @returns {Array|Object} Returns `collection`.
  8656. * @see _.forEach
  8657. * @example
  8658. *
  8659. * _.forEachRight([1, 2], function(value) {
  8660. * console.log(value);
  8661. * });
  8662. * // => Logs `2` then `1`.
  8663. */
  8664. function forEachRight(collection, iteratee) {
  8665. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8666. return func(collection, getIteratee(iteratee, 3));
  8667. }
  8668. /**
  8669. * Creates an object composed of keys generated from the results of running
  8670. * each element of `collection` thru `iteratee`. The order of grouped values
  8671. * is determined by the order they occur in `collection`. The corresponding
  8672. * value of each key is an array of elements responsible for generating the
  8673. * key. The iteratee is invoked with one argument: (value).
  8674. *
  8675. * @static
  8676. * @memberOf _
  8677. * @since 0.1.0
  8678. * @category Collection
  8679. * @param {Array|Object} collection The collection to iterate over.
  8680. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8681. * @returns {Object} Returns the composed aggregate object.
  8682. * @example
  8683. *
  8684. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8685. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8686. *
  8687. * // The `_.property` iteratee shorthand.
  8688. * _.groupBy(['one', 'two', 'three'], 'length');
  8689. * // => { '3': ['one', 'two'], '5': ['three'] }
  8690. */
  8691. var groupBy = createAggregator(function(result, value, key) {
  8692. if (hasOwnProperty.call(result, key)) {
  8693. result[key].push(value);
  8694. } else {
  8695. baseAssignValue(result, key, [value]);
  8696. }
  8697. });
  8698. /**
  8699. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8700. * checked for a substring of `value`, otherwise
  8701. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8702. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8703. * the offset from the end of `collection`.
  8704. *
  8705. * @static
  8706. * @memberOf _
  8707. * @since 0.1.0
  8708. * @category Collection
  8709. * @param {Array|Object|string} collection The collection to inspect.
  8710. * @param {*} value The value to search for.
  8711. * @param {number} [fromIndex=0] The index to search from.
  8712. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8713. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8714. * @example
  8715. *
  8716. * _.includes([1, 2, 3], 1);
  8717. * // => true
  8718. *
  8719. * _.includes([1, 2, 3], 1, 2);
  8720. * // => false
  8721. *
  8722. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8723. * // => true
  8724. *
  8725. * _.includes('abcd', 'bc');
  8726. * // => true
  8727. */
  8728. function includes(collection, value, fromIndex, guard) {
  8729. collection = isArrayLike(collection) ? collection : values(collection);
  8730. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8731. var length = collection.length;
  8732. if (fromIndex < 0) {
  8733. fromIndex = nativeMax(length + fromIndex, 0);
  8734. }
  8735. return isString(collection)
  8736. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8737. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8738. }
  8739. /**
  8740. * Invokes the method at `path` of each element in `collection`, returning
  8741. * an array of the results of each invoked method. Any additional arguments
  8742. * are provided to each invoked method. If `path` is a function, it's invoked
  8743. * for, and `this` bound to, each element in `collection`.
  8744. *
  8745. * @static
  8746. * @memberOf _
  8747. * @since 4.0.0
  8748. * @category Collection
  8749. * @param {Array|Object} collection The collection to iterate over.
  8750. * @param {Array|Function|string} path The path of the method to invoke or
  8751. * the function invoked per iteration.
  8752. * @param {...*} [args] The arguments to invoke each method with.
  8753. * @returns {Array} Returns the array of results.
  8754. * @example
  8755. *
  8756. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8757. * // => [[1, 5, 7], [1, 2, 3]]
  8758. *
  8759. * _.invokeMap([123, 456], String.prototype.split, '');
  8760. * // => [['1', '2', '3'], ['4', '5', '6']]
  8761. */
  8762. var invokeMap = baseRest(function(collection, path, args) {
  8763. var index = -1,
  8764. isFunc = typeof path == 'function',
  8765. result = isArrayLike(collection) ? Array(collection.length) : [];
  8766. baseEach(collection, function(value) {
  8767. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8768. });
  8769. return result;
  8770. });
  8771. /**
  8772. * Creates an object composed of keys generated from the results of running
  8773. * each element of `collection` thru `iteratee`. The corresponding value of
  8774. * each key is the last element responsible for generating the key. The
  8775. * iteratee is invoked with one argument: (value).
  8776. *
  8777. * @static
  8778. * @memberOf _
  8779. * @since 4.0.0
  8780. * @category Collection
  8781. * @param {Array|Object} collection The collection to iterate over.
  8782. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8783. * @returns {Object} Returns the composed aggregate object.
  8784. * @example
  8785. *
  8786. * var array = [
  8787. * { 'dir': 'left', 'code': 97 },
  8788. * { 'dir': 'right', 'code': 100 }
  8789. * ];
  8790. *
  8791. * _.keyBy(array, function(o) {
  8792. * return String.fromCharCode(o.code);
  8793. * });
  8794. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8795. *
  8796. * _.keyBy(array, 'dir');
  8797. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8798. */
  8799. var keyBy = createAggregator(function(result, value, key) {
  8800. baseAssignValue(result, key, value);
  8801. });
  8802. /**
  8803. * Creates an array of values by running each element in `collection` thru
  8804. * `iteratee`. The iteratee is invoked with three arguments:
  8805. * (value, index|key, collection).
  8806. *
  8807. * Many lodash methods are guarded to work as iteratees for methods like
  8808. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8809. *
  8810. * The guarded methods are:
  8811. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8812. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8813. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8814. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8815. *
  8816. * @static
  8817. * @memberOf _
  8818. * @since 0.1.0
  8819. * @category Collection
  8820. * @param {Array|Object} collection The collection to iterate over.
  8821. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8822. * @returns {Array} Returns the new mapped array.
  8823. * @example
  8824. *
  8825. * function square(n) {
  8826. * return n * n;
  8827. * }
  8828. *
  8829. * _.map([4, 8], square);
  8830. * // => [16, 64]
  8831. *
  8832. * _.map({ 'a': 4, 'b': 8 }, square);
  8833. * // => [16, 64] (iteration order is not guaranteed)
  8834. *
  8835. * var users = [
  8836. * { 'user': 'barney' },
  8837. * { 'user': 'fred' }
  8838. * ];
  8839. *
  8840. * // The `_.property` iteratee shorthand.
  8841. * _.map(users, 'user');
  8842. * // => ['barney', 'fred']
  8843. */
  8844. function map(collection, iteratee) {
  8845. var func = isArray(collection) ? arrayMap : baseMap;
  8846. return func(collection, getIteratee(iteratee, 3));
  8847. }
  8848. /**
  8849. * This method is like `_.sortBy` except that it allows specifying the sort
  8850. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8851. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8852. * descending or "asc" for ascending sort order of corresponding values.
  8853. *
  8854. * @static
  8855. * @memberOf _
  8856. * @since 4.0.0
  8857. * @category Collection
  8858. * @param {Array|Object} collection The collection to iterate over.
  8859. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8860. * The iteratees to sort by.
  8861. * @param {string[]} [orders] The sort orders of `iteratees`.
  8862. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8863. * @returns {Array} Returns the new sorted array.
  8864. * @example
  8865. *
  8866. * var users = [
  8867. * { 'user': 'fred', 'age': 48 },
  8868. * { 'user': 'barney', 'age': 34 },
  8869. * { 'user': 'fred', 'age': 40 },
  8870. * { 'user': 'barney', 'age': 36 }
  8871. * ];
  8872. *
  8873. * // Sort by `user` in ascending order and by `age` in descending order.
  8874. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8875. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8876. */
  8877. function orderBy(collection, iteratees, orders, guard) {
  8878. if (collection == null) {
  8879. return [];
  8880. }
  8881. if (!isArray(iteratees)) {
  8882. iteratees = iteratees == null ? [] : [iteratees];
  8883. }
  8884. orders = guard ? undefined : orders;
  8885. if (!isArray(orders)) {
  8886. orders = orders == null ? [] : [orders];
  8887. }
  8888. return baseOrderBy(collection, iteratees, orders);
  8889. }
  8890. /**
  8891. * Creates an array of elements split into two groups, the first of which
  8892. * contains elements `predicate` returns truthy for, the second of which
  8893. * contains elements `predicate` returns falsey for. The predicate is
  8894. * invoked with one argument: (value).
  8895. *
  8896. * @static
  8897. * @memberOf _
  8898. * @since 3.0.0
  8899. * @category Collection
  8900. * @param {Array|Object} collection The collection to iterate over.
  8901. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8902. * @returns {Array} Returns the array of grouped elements.
  8903. * @example
  8904. *
  8905. * var users = [
  8906. * { 'user': 'barney', 'age': 36, 'active': false },
  8907. * { 'user': 'fred', 'age': 40, 'active': true },
  8908. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8909. * ];
  8910. *
  8911. * _.partition(users, function(o) { return o.active; });
  8912. * // => objects for [['fred'], ['barney', 'pebbles']]
  8913. *
  8914. * // The `_.matches` iteratee shorthand.
  8915. * _.partition(users, { 'age': 1, 'active': false });
  8916. * // => objects for [['pebbles'], ['barney', 'fred']]
  8917. *
  8918. * // The `_.matchesProperty` iteratee shorthand.
  8919. * _.partition(users, ['active', false]);
  8920. * // => objects for [['barney', 'pebbles'], ['fred']]
  8921. *
  8922. * // The `_.property` iteratee shorthand.
  8923. * _.partition(users, 'active');
  8924. * // => objects for [['fred'], ['barney', 'pebbles']]
  8925. */
  8926. var partition = createAggregator(function(result, value, key) {
  8927. result[key ? 0 : 1].push(value);
  8928. }, function() { return [[], []]; });
  8929. /**
  8930. * Reduces `collection` to a value which is the accumulated result of running
  8931. * each element in `collection` thru `iteratee`, where each successive
  8932. * invocation is supplied the return value of the previous. If `accumulator`
  8933. * is not given, the first element of `collection` is used as the initial
  8934. * value. The iteratee is invoked with four arguments:
  8935. * (accumulator, value, index|key, collection).
  8936. *
  8937. * Many lodash methods are guarded to work as iteratees for methods like
  8938. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8939. *
  8940. * The guarded methods are:
  8941. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8942. * and `sortBy`
  8943. *
  8944. * @static
  8945. * @memberOf _
  8946. * @since 0.1.0
  8947. * @category Collection
  8948. * @param {Array|Object} collection The collection to iterate over.
  8949. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8950. * @param {*} [accumulator] The initial value.
  8951. * @returns {*} Returns the accumulated value.
  8952. * @see _.reduceRight
  8953. * @example
  8954. *
  8955. * _.reduce([1, 2], function(sum, n) {
  8956. * return sum + n;
  8957. * }, 0);
  8958. * // => 3
  8959. *
  8960. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8961. * (result[value] || (result[value] = [])).push(key);
  8962. * return result;
  8963. * }, {});
  8964. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8965. */
  8966. function reduce(collection, iteratee, accumulator) {
  8967. var func = isArray(collection) ? arrayReduce : baseReduce,
  8968. initAccum = arguments.length < 3;
  8969. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8970. }
  8971. /**
  8972. * This method is like `_.reduce` except that it iterates over elements of
  8973. * `collection` from right to left.
  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 _.reduce
  8984. * @example
  8985. *
  8986. * var array = [[0, 1], [2, 3], [4, 5]];
  8987. *
  8988. * _.reduceRight(array, function(flattened, other) {
  8989. * return flattened.concat(other);
  8990. * }, []);
  8991. * // => [4, 5, 2, 3, 0, 1]
  8992. */
  8993. function reduceRight(collection, iteratee, accumulator) {
  8994. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  8995. initAccum = arguments.length < 3;
  8996. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  8997. }
  8998. /**
  8999. * The opposite of `_.filter`; this method returns the elements of `collection`
  9000. * that `predicate` does **not** return truthy for.
  9001. *
  9002. * @static
  9003. * @memberOf _
  9004. * @since 0.1.0
  9005. * @category Collection
  9006. * @param {Array|Object} collection The collection to iterate over.
  9007. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9008. * @returns {Array} Returns the new filtered array.
  9009. * @see _.filter
  9010. * @example
  9011. *
  9012. * var users = [
  9013. * { 'user': 'barney', 'age': 36, 'active': false },
  9014. * { 'user': 'fred', 'age': 40, 'active': true }
  9015. * ];
  9016. *
  9017. * _.reject(users, function(o) { return !o.active; });
  9018. * // => objects for ['fred']
  9019. *
  9020. * // The `_.matches` iteratee shorthand.
  9021. * _.reject(users, { 'age': 40, 'active': true });
  9022. * // => objects for ['barney']
  9023. *
  9024. * // The `_.matchesProperty` iteratee shorthand.
  9025. * _.reject(users, ['active', false]);
  9026. * // => objects for ['fred']
  9027. *
  9028. * // The `_.property` iteratee shorthand.
  9029. * _.reject(users, 'active');
  9030. * // => objects for ['barney']
  9031. */
  9032. function reject(collection, predicate) {
  9033. var func = isArray(collection) ? arrayFilter : baseFilter;
  9034. return func(collection, negate(getIteratee(predicate, 3)));
  9035. }
  9036. /**
  9037. * Gets a random element from `collection`.
  9038. *
  9039. * @static
  9040. * @memberOf _
  9041. * @since 2.0.0
  9042. * @category Collection
  9043. * @param {Array|Object} collection The collection to sample.
  9044. * @returns {*} Returns the random element.
  9045. * @example
  9046. *
  9047. * _.sample([1, 2, 3, 4]);
  9048. * // => 2
  9049. */
  9050. function sample(collection) {
  9051. var func = isArray(collection) ? arraySample : baseSample;
  9052. return func(collection);
  9053. }
  9054. /**
  9055. * Gets `n` random elements at unique keys from `collection` up to the
  9056. * size of `collection`.
  9057. *
  9058. * @static
  9059. * @memberOf _
  9060. * @since 4.0.0
  9061. * @category Collection
  9062. * @param {Array|Object} collection The collection to sample.
  9063. * @param {number} [n=1] The number of elements to sample.
  9064. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9065. * @returns {Array} Returns the random elements.
  9066. * @example
  9067. *
  9068. * _.sampleSize([1, 2, 3], 2);
  9069. * // => [3, 1]
  9070. *
  9071. * _.sampleSize([1, 2, 3], 4);
  9072. * // => [2, 3, 1]
  9073. */
  9074. function sampleSize(collection, n, guard) {
  9075. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9076. n = 1;
  9077. } else {
  9078. n = toInteger(n);
  9079. }
  9080. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9081. return func(collection, n);
  9082. }
  9083. /**
  9084. * Creates an array of shuffled values, using a version of the
  9085. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9086. *
  9087. * @static
  9088. * @memberOf _
  9089. * @since 0.1.0
  9090. * @category Collection
  9091. * @param {Array|Object} collection The collection to shuffle.
  9092. * @returns {Array} Returns the new shuffled array.
  9093. * @example
  9094. *
  9095. * _.shuffle([1, 2, 3, 4]);
  9096. * // => [4, 1, 3, 2]
  9097. */
  9098. function shuffle(collection) {
  9099. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9100. return func(collection);
  9101. }
  9102. /**
  9103. * Gets the size of `collection` by returning its length for array-like
  9104. * values or the number of own enumerable string keyed properties for objects.
  9105. *
  9106. * @static
  9107. * @memberOf _
  9108. * @since 0.1.0
  9109. * @category Collection
  9110. * @param {Array|Object|string} collection The collection to inspect.
  9111. * @returns {number} Returns the collection size.
  9112. * @example
  9113. *
  9114. * _.size([1, 2, 3]);
  9115. * // => 3
  9116. *
  9117. * _.size({ 'a': 1, 'b': 2 });
  9118. * // => 2
  9119. *
  9120. * _.size('pebbles');
  9121. * // => 7
  9122. */
  9123. function size(collection) {
  9124. if (collection == null) {
  9125. return 0;
  9126. }
  9127. if (isArrayLike(collection)) {
  9128. return isString(collection) ? stringSize(collection) : collection.length;
  9129. }
  9130. var tag = getTag(collection);
  9131. if (tag == mapTag || tag == setTag) {
  9132. return collection.size;
  9133. }
  9134. return baseKeys(collection).length;
  9135. }
  9136. /**
  9137. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9138. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9139. * invoked with three arguments: (value, index|key, collection).
  9140. *
  9141. * @static
  9142. * @memberOf _
  9143. * @since 0.1.0
  9144. * @category Collection
  9145. * @param {Array|Object} collection The collection to iterate over.
  9146. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9147. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9148. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9149. * else `false`.
  9150. * @example
  9151. *
  9152. * _.some([null, 0, 'yes', false], Boolean);
  9153. * // => true
  9154. *
  9155. * var users = [
  9156. * { 'user': 'barney', 'active': true },
  9157. * { 'user': 'fred', 'active': false }
  9158. * ];
  9159. *
  9160. * // The `_.matches` iteratee shorthand.
  9161. * _.some(users, { 'user': 'barney', 'active': false });
  9162. * // => false
  9163. *
  9164. * // The `_.matchesProperty` iteratee shorthand.
  9165. * _.some(users, ['active', false]);
  9166. * // => true
  9167. *
  9168. * // The `_.property` iteratee shorthand.
  9169. * _.some(users, 'active');
  9170. * // => true
  9171. */
  9172. function some(collection, predicate, guard) {
  9173. var func = isArray(collection) ? arraySome : baseSome;
  9174. if (guard && isIterateeCall(collection, predicate, guard)) {
  9175. predicate = undefined;
  9176. }
  9177. return func(collection, getIteratee(predicate, 3));
  9178. }
  9179. /**
  9180. * Creates an array of elements, sorted in ascending order by the results of
  9181. * running each element in a collection thru each iteratee. This method
  9182. * performs a stable sort, that is, it preserves the original sort order of
  9183. * equal elements. The iteratees are invoked with one argument: (value).
  9184. *
  9185. * @static
  9186. * @memberOf _
  9187. * @since 0.1.0
  9188. * @category Collection
  9189. * @param {Array|Object} collection The collection to iterate over.
  9190. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9191. * The iteratees to sort by.
  9192. * @returns {Array} Returns the new sorted array.
  9193. * @example
  9194. *
  9195. * var users = [
  9196. * { 'user': 'fred', 'age': 48 },
  9197. * { 'user': 'barney', 'age': 36 },
  9198. * { 'user': 'fred', 'age': 40 },
  9199. * { 'user': 'barney', 'age': 34 }
  9200. * ];
  9201. *
  9202. * _.sortBy(users, [function(o) { return o.user; }]);
  9203. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9204. *
  9205. * _.sortBy(users, ['user', 'age']);
  9206. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9207. */
  9208. var sortBy = baseRest(function(collection, iteratees) {
  9209. if (collection == null) {
  9210. return [];
  9211. }
  9212. var length = iteratees.length;
  9213. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9214. iteratees = [];
  9215. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9216. iteratees = [iteratees[0]];
  9217. }
  9218. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9219. });
  9220. /*------------------------------------------------------------------------*/
  9221. /**
  9222. * Gets the timestamp of the number of milliseconds that have elapsed since
  9223. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9224. *
  9225. * @static
  9226. * @memberOf _
  9227. * @since 2.4.0
  9228. * @category Date
  9229. * @returns {number} Returns the timestamp.
  9230. * @example
  9231. *
  9232. * _.defer(function(stamp) {
  9233. * console.log(_.now() - stamp);
  9234. * }, _.now());
  9235. * // => Logs the number of milliseconds it took for the deferred invocation.
  9236. */
  9237. var now = ctxNow || function() {
  9238. return root.Date.now();
  9239. };
  9240. /*------------------------------------------------------------------------*/
  9241. /**
  9242. * The opposite of `_.before`; this method creates a function that invokes
  9243. * `func` once it's called `n` or more times.
  9244. *
  9245. * @static
  9246. * @memberOf _
  9247. * @since 0.1.0
  9248. * @category Function
  9249. * @param {number} n The number of calls before `func` is invoked.
  9250. * @param {Function} func The function to restrict.
  9251. * @returns {Function} Returns the new restricted function.
  9252. * @example
  9253. *
  9254. * var saves = ['profile', 'settings'];
  9255. *
  9256. * var done = _.after(saves.length, function() {
  9257. * console.log('done saving!');
  9258. * });
  9259. *
  9260. * _.forEach(saves, function(type) {
  9261. * asyncSave({ 'type': type, 'complete': done });
  9262. * });
  9263. * // => Logs 'done saving!' after the two async saves have completed.
  9264. */
  9265. function after(n, func) {
  9266. if (typeof func != 'function') {
  9267. throw new TypeError(FUNC_ERROR_TEXT);
  9268. }
  9269. n = toInteger(n);
  9270. return function() {
  9271. if (--n < 1) {
  9272. return func.apply(this, arguments);
  9273. }
  9274. };
  9275. }
  9276. /**
  9277. * Creates a function that invokes `func`, with up to `n` arguments,
  9278. * ignoring any additional arguments.
  9279. *
  9280. * @static
  9281. * @memberOf _
  9282. * @since 3.0.0
  9283. * @category Function
  9284. * @param {Function} func The function to cap arguments for.
  9285. * @param {number} [n=func.length] The arity cap.
  9286. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9287. * @returns {Function} Returns the new capped function.
  9288. * @example
  9289. *
  9290. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9291. * // => [6, 8, 10]
  9292. */
  9293. function ary(func, n, guard) {
  9294. n = guard ? undefined : n;
  9295. n = (func && n == null) ? func.length : n;
  9296. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9297. }
  9298. /**
  9299. * Creates a function that invokes `func`, with the `this` binding and arguments
  9300. * of the created function, while it's called less than `n` times. Subsequent
  9301. * calls to the created function return the result of the last `func` invocation.
  9302. *
  9303. * @static
  9304. * @memberOf _
  9305. * @since 3.0.0
  9306. * @category Function
  9307. * @param {number} n The number of calls at which `func` is no longer invoked.
  9308. * @param {Function} func The function to restrict.
  9309. * @returns {Function} Returns the new restricted function.
  9310. * @example
  9311. *
  9312. * jQuery(element).on('click', _.before(5, addContactToList));
  9313. * // => Allows adding up to 4 contacts to the list.
  9314. */
  9315. function before(n, func) {
  9316. var result;
  9317. if (typeof func != 'function') {
  9318. throw new TypeError(FUNC_ERROR_TEXT);
  9319. }
  9320. n = toInteger(n);
  9321. return function() {
  9322. if (--n > 0) {
  9323. result = func.apply(this, arguments);
  9324. }
  9325. if (n <= 1) {
  9326. func = undefined;
  9327. }
  9328. return result;
  9329. };
  9330. }
  9331. /**
  9332. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9333. * and `partials` prepended to the arguments it receives.
  9334. *
  9335. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9336. * may be used as a placeholder for partially applied arguments.
  9337. *
  9338. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9339. * property of bound functions.
  9340. *
  9341. * @static
  9342. * @memberOf _
  9343. * @since 0.1.0
  9344. * @category Function
  9345. * @param {Function} func The function to bind.
  9346. * @param {*} thisArg The `this` binding of `func`.
  9347. * @param {...*} [partials] The arguments to be partially applied.
  9348. * @returns {Function} Returns the new bound function.
  9349. * @example
  9350. *
  9351. * function greet(greeting, punctuation) {
  9352. * return greeting + ' ' + this.user + punctuation;
  9353. * }
  9354. *
  9355. * var object = { 'user': 'fred' };
  9356. *
  9357. * var bound = _.bind(greet, object, 'hi');
  9358. * bound('!');
  9359. * // => 'hi fred!'
  9360. *
  9361. * // Bound with placeholders.
  9362. * var bound = _.bind(greet, object, _, '!');
  9363. * bound('hi');
  9364. * // => 'hi fred!'
  9365. */
  9366. var bind = baseRest(function(func, thisArg, partials) {
  9367. var bitmask = WRAP_BIND_FLAG;
  9368. if (partials.length) {
  9369. var holders = replaceHolders(partials, getHolder(bind));
  9370. bitmask |= WRAP_PARTIAL_FLAG;
  9371. }
  9372. return createWrap(func, bitmask, thisArg, partials, holders);
  9373. });
  9374. /**
  9375. * Creates a function that invokes the method at `object[key]` with `partials`
  9376. * prepended to the arguments it receives.
  9377. *
  9378. * This method differs from `_.bind` by allowing bound functions to reference
  9379. * methods that may be redefined or don't yet exist. See
  9380. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9381. * for more details.
  9382. *
  9383. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9384. * builds, may be used as a placeholder for partially applied arguments.
  9385. *
  9386. * @static
  9387. * @memberOf _
  9388. * @since 0.10.0
  9389. * @category Function
  9390. * @param {Object} object The object to invoke the method on.
  9391. * @param {string} key The key of the method.
  9392. * @param {...*} [partials] The arguments to be partially applied.
  9393. * @returns {Function} Returns the new bound function.
  9394. * @example
  9395. *
  9396. * var object = {
  9397. * 'user': 'fred',
  9398. * 'greet': function(greeting, punctuation) {
  9399. * return greeting + ' ' + this.user + punctuation;
  9400. * }
  9401. * };
  9402. *
  9403. * var bound = _.bindKey(object, 'greet', 'hi');
  9404. * bound('!');
  9405. * // => 'hi fred!'
  9406. *
  9407. * object.greet = function(greeting, punctuation) {
  9408. * return greeting + 'ya ' + this.user + punctuation;
  9409. * };
  9410. *
  9411. * bound('!');
  9412. * // => 'hiya fred!'
  9413. *
  9414. * // Bound with placeholders.
  9415. * var bound = _.bindKey(object, 'greet', _, '!');
  9416. * bound('hi');
  9417. * // => 'hiya fred!'
  9418. */
  9419. var bindKey = baseRest(function(object, key, partials) {
  9420. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9421. if (partials.length) {
  9422. var holders = replaceHolders(partials, getHolder(bindKey));
  9423. bitmask |= WRAP_PARTIAL_FLAG;
  9424. }
  9425. return createWrap(key, bitmask, object, partials, holders);
  9426. });
  9427. /**
  9428. * Creates a function that accepts arguments of `func` and either invokes
  9429. * `func` returning its result, if at least `arity` number of arguments have
  9430. * been provided, or returns a function that accepts the remaining `func`
  9431. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9432. * is not sufficient.
  9433. *
  9434. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9435. * may be used as a placeholder for provided arguments.
  9436. *
  9437. * **Note:** This method doesn't set the "length" property of curried functions.
  9438. *
  9439. * @static
  9440. * @memberOf _
  9441. * @since 2.0.0
  9442. * @category Function
  9443. * @param {Function} func The function to curry.
  9444. * @param {number} [arity=func.length] The arity of `func`.
  9445. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9446. * @returns {Function} Returns the new curried function.
  9447. * @example
  9448. *
  9449. * var abc = function(a, b, c) {
  9450. * return [a, b, c];
  9451. * };
  9452. *
  9453. * var curried = _.curry(abc);
  9454. *
  9455. * curried(1)(2)(3);
  9456. * // => [1, 2, 3]
  9457. *
  9458. * curried(1, 2)(3);
  9459. * // => [1, 2, 3]
  9460. *
  9461. * curried(1, 2, 3);
  9462. * // => [1, 2, 3]
  9463. *
  9464. * // Curried with placeholders.
  9465. * curried(1)(_, 3)(2);
  9466. * // => [1, 2, 3]
  9467. */
  9468. function curry(func, arity, guard) {
  9469. arity = guard ? undefined : arity;
  9470. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9471. result.placeholder = curry.placeholder;
  9472. return result;
  9473. }
  9474. /**
  9475. * This method is like `_.curry` except that arguments are applied to `func`
  9476. * in the manner of `_.partialRight` instead of `_.partial`.
  9477. *
  9478. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9479. * builds, may be used as a placeholder for provided arguments.
  9480. *
  9481. * **Note:** This method doesn't set the "length" property of curried functions.
  9482. *
  9483. * @static
  9484. * @memberOf _
  9485. * @since 3.0.0
  9486. * @category Function
  9487. * @param {Function} func The function to curry.
  9488. * @param {number} [arity=func.length] The arity of `func`.
  9489. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9490. * @returns {Function} Returns the new curried function.
  9491. * @example
  9492. *
  9493. * var abc = function(a, b, c) {
  9494. * return [a, b, c];
  9495. * };
  9496. *
  9497. * var curried = _.curryRight(abc);
  9498. *
  9499. * curried(3)(2)(1);
  9500. * // => [1, 2, 3]
  9501. *
  9502. * curried(2, 3)(1);
  9503. * // => [1, 2, 3]
  9504. *
  9505. * curried(1, 2, 3);
  9506. * // => [1, 2, 3]
  9507. *
  9508. * // Curried with placeholders.
  9509. * curried(3)(1, _)(2);
  9510. * // => [1, 2, 3]
  9511. */
  9512. function curryRight(func, arity, guard) {
  9513. arity = guard ? undefined : arity;
  9514. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9515. result.placeholder = curryRight.placeholder;
  9516. return result;
  9517. }
  9518. /**
  9519. * Creates a debounced function that delays invoking `func` until after `wait`
  9520. * milliseconds have elapsed since the last time the debounced function was
  9521. * invoked. The debounced function comes with a `cancel` method to cancel
  9522. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9523. * Provide `options` to indicate whether `func` should be invoked on the
  9524. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9525. * with the last arguments provided to the debounced function. Subsequent
  9526. * calls to the debounced function return the result of the last `func`
  9527. * invocation.
  9528. *
  9529. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9530. * invoked on the trailing edge of the timeout only if the debounced function
  9531. * is invoked more than once during the `wait` timeout.
  9532. *
  9533. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9534. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9535. *
  9536. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9537. * for details over the differences between `_.debounce` and `_.throttle`.
  9538. *
  9539. * @static
  9540. * @memberOf _
  9541. * @since 0.1.0
  9542. * @category Function
  9543. * @param {Function} func The function to debounce.
  9544. * @param {number} [wait=0] The number of milliseconds to delay.
  9545. * @param {Object} [options={}] The options object.
  9546. * @param {boolean} [options.leading=false]
  9547. * Specify invoking on the leading edge of the timeout.
  9548. * @param {number} [options.maxWait]
  9549. * The maximum time `func` is allowed to be delayed before it's invoked.
  9550. * @param {boolean} [options.trailing=true]
  9551. * Specify invoking on the trailing edge of the timeout.
  9552. * @returns {Function} Returns the new debounced function.
  9553. * @example
  9554. *
  9555. * // Avoid costly calculations while the window size is in flux.
  9556. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9557. *
  9558. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9559. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9560. * 'leading': true,
  9561. * 'trailing': false
  9562. * }));
  9563. *
  9564. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9565. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9566. * var source = new EventSource('/stream');
  9567. * jQuery(source).on('message', debounced);
  9568. *
  9569. * // Cancel the trailing debounced invocation.
  9570. * jQuery(window).on('popstate', debounced.cancel);
  9571. */
  9572. function debounce(func, wait, options) {
  9573. var lastArgs,
  9574. lastThis,
  9575. maxWait,
  9576. result,
  9577. timerId,
  9578. lastCallTime,
  9579. lastInvokeTime = 0,
  9580. leading = false,
  9581. maxing = false,
  9582. trailing = true;
  9583. if (typeof func != 'function') {
  9584. throw new TypeError(FUNC_ERROR_TEXT);
  9585. }
  9586. wait = toNumber(wait) || 0;
  9587. if (isObject(options)) {
  9588. leading = !!options.leading;
  9589. maxing = 'maxWait' in options;
  9590. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9591. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9592. }
  9593. function invokeFunc(time) {
  9594. var args = lastArgs,
  9595. thisArg = lastThis;
  9596. lastArgs = lastThis = undefined;
  9597. lastInvokeTime = time;
  9598. result = func.apply(thisArg, args);
  9599. return result;
  9600. }
  9601. function leadingEdge(time) {
  9602. // Reset any `maxWait` timer.
  9603. lastInvokeTime = time;
  9604. // Start the timer for the trailing edge.
  9605. timerId = setTimeout(timerExpired, wait);
  9606. // Invoke the leading edge.
  9607. return leading ? invokeFunc(time) : result;
  9608. }
  9609. function remainingWait(time) {
  9610. var timeSinceLastCall = time - lastCallTime,
  9611. timeSinceLastInvoke = time - lastInvokeTime,
  9612. timeWaiting = wait - timeSinceLastCall;
  9613. return maxing
  9614. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9615. : timeWaiting;
  9616. }
  9617. function shouldInvoke(time) {
  9618. var timeSinceLastCall = time - lastCallTime,
  9619. timeSinceLastInvoke = time - lastInvokeTime;
  9620. // Either this is the first call, activity has stopped and we're at the
  9621. // trailing edge, the system time has gone backwards and we're treating
  9622. // it as the trailing edge, or we've hit the `maxWait` limit.
  9623. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9624. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9625. }
  9626. function timerExpired() {
  9627. var time = now();
  9628. if (shouldInvoke(time)) {
  9629. return trailingEdge(time);
  9630. }
  9631. // Restart the timer.
  9632. timerId = setTimeout(timerExpired, remainingWait(time));
  9633. }
  9634. function trailingEdge(time) {
  9635. timerId = undefined;
  9636. // Only invoke if we have `lastArgs` which means `func` has been
  9637. // debounced at least once.
  9638. if (trailing && lastArgs) {
  9639. return invokeFunc(time);
  9640. }
  9641. lastArgs = lastThis = undefined;
  9642. return result;
  9643. }
  9644. function cancel() {
  9645. if (timerId !== undefined) {
  9646. clearTimeout(timerId);
  9647. }
  9648. lastInvokeTime = 0;
  9649. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9650. }
  9651. function flush() {
  9652. return timerId === undefined ? result : trailingEdge(now());
  9653. }
  9654. function debounced() {
  9655. var time = now(),
  9656. isInvoking = shouldInvoke(time);
  9657. lastArgs = arguments;
  9658. lastThis = this;
  9659. lastCallTime = time;
  9660. if (isInvoking) {
  9661. if (timerId === undefined) {
  9662. return leadingEdge(lastCallTime);
  9663. }
  9664. if (maxing) {
  9665. // Handle invocations in a tight loop.
  9666. timerId = setTimeout(timerExpired, wait);
  9667. return invokeFunc(lastCallTime);
  9668. }
  9669. }
  9670. if (timerId === undefined) {
  9671. timerId = setTimeout(timerExpired, wait);
  9672. }
  9673. return result;
  9674. }
  9675. debounced.cancel = cancel;
  9676. debounced.flush = flush;
  9677. return debounced;
  9678. }
  9679. /**
  9680. * Defers invoking the `func` until the current call stack has cleared. Any
  9681. * additional arguments are provided to `func` when it's invoked.
  9682. *
  9683. * @static
  9684. * @memberOf _
  9685. * @since 0.1.0
  9686. * @category Function
  9687. * @param {Function} func The function to defer.
  9688. * @param {...*} [args] The arguments to invoke `func` with.
  9689. * @returns {number} Returns the timer id.
  9690. * @example
  9691. *
  9692. * _.defer(function(text) {
  9693. * console.log(text);
  9694. * }, 'deferred');
  9695. * // => Logs 'deferred' after one millisecond.
  9696. */
  9697. var defer = baseRest(function(func, args) {
  9698. return baseDelay(func, 1, args);
  9699. });
  9700. /**
  9701. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9702. * provided to `func` when it's invoked.
  9703. *
  9704. * @static
  9705. * @memberOf _
  9706. * @since 0.1.0
  9707. * @category Function
  9708. * @param {Function} func The function to delay.
  9709. * @param {number} wait The number of milliseconds to delay invocation.
  9710. * @param {...*} [args] The arguments to invoke `func` with.
  9711. * @returns {number} Returns the timer id.
  9712. * @example
  9713. *
  9714. * _.delay(function(text) {
  9715. * console.log(text);
  9716. * }, 1000, 'later');
  9717. * // => Logs 'later' after one second.
  9718. */
  9719. var delay = baseRest(function(func, wait, args) {
  9720. return baseDelay(func, toNumber(wait) || 0, args);
  9721. });
  9722. /**
  9723. * Creates a function that invokes `func` with arguments reversed.
  9724. *
  9725. * @static
  9726. * @memberOf _
  9727. * @since 4.0.0
  9728. * @category Function
  9729. * @param {Function} func The function to flip arguments for.
  9730. * @returns {Function} Returns the new flipped function.
  9731. * @example
  9732. *
  9733. * var flipped = _.flip(function() {
  9734. * return _.toArray(arguments);
  9735. * });
  9736. *
  9737. * flipped('a', 'b', 'c', 'd');
  9738. * // => ['d', 'c', 'b', 'a']
  9739. */
  9740. function flip(func) {
  9741. return createWrap(func, WRAP_FLIP_FLAG);
  9742. }
  9743. /**
  9744. * Creates a function that memoizes the result of `func`. If `resolver` is
  9745. * provided, it determines the cache key for storing the result based on the
  9746. * arguments provided to the memoized function. By default, the first argument
  9747. * provided to the memoized function is used as the map cache key. The `func`
  9748. * is invoked with the `this` binding of the memoized function.
  9749. *
  9750. * **Note:** The cache is exposed as the `cache` property on the memoized
  9751. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9752. * constructor with one whose instances implement the
  9753. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9754. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9755. *
  9756. * @static
  9757. * @memberOf _
  9758. * @since 0.1.0
  9759. * @category Function
  9760. * @param {Function} func The function to have its output memoized.
  9761. * @param {Function} [resolver] The function to resolve the cache key.
  9762. * @returns {Function} Returns the new memoized function.
  9763. * @example
  9764. *
  9765. * var object = { 'a': 1, 'b': 2 };
  9766. * var other = { 'c': 3, 'd': 4 };
  9767. *
  9768. * var values = _.memoize(_.values);
  9769. * values(object);
  9770. * // => [1, 2]
  9771. *
  9772. * values(other);
  9773. * // => [3, 4]
  9774. *
  9775. * object.a = 2;
  9776. * values(object);
  9777. * // => [1, 2]
  9778. *
  9779. * // Modify the result cache.
  9780. * values.cache.set(object, ['a', 'b']);
  9781. * values(object);
  9782. * // => ['a', 'b']
  9783. *
  9784. * // Replace `_.memoize.Cache`.
  9785. * _.memoize.Cache = WeakMap;
  9786. */
  9787. function memoize(func, resolver) {
  9788. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9789. throw new TypeError(FUNC_ERROR_TEXT);
  9790. }
  9791. var memoized = function() {
  9792. var args = arguments,
  9793. key = resolver ? resolver.apply(this, args) : args[0],
  9794. cache = memoized.cache;
  9795. if (cache.has(key)) {
  9796. return cache.get(key);
  9797. }
  9798. var result = func.apply(this, args);
  9799. memoized.cache = cache.set(key, result) || cache;
  9800. return result;
  9801. };
  9802. memoized.cache = new (memoize.Cache || MapCache);
  9803. return memoized;
  9804. }
  9805. // Expose `MapCache`.
  9806. memoize.Cache = MapCache;
  9807. /**
  9808. * Creates a function that negates the result of the predicate `func`. The
  9809. * `func` predicate is invoked with the `this` binding and arguments of the
  9810. * created function.
  9811. *
  9812. * @static
  9813. * @memberOf _
  9814. * @since 3.0.0
  9815. * @category Function
  9816. * @param {Function} predicate The predicate to negate.
  9817. * @returns {Function} Returns the new negated function.
  9818. * @example
  9819. *
  9820. * function isEven(n) {
  9821. * return n % 2 == 0;
  9822. * }
  9823. *
  9824. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9825. * // => [1, 3, 5]
  9826. */
  9827. function negate(predicate) {
  9828. if (typeof predicate != 'function') {
  9829. throw new TypeError(FUNC_ERROR_TEXT);
  9830. }
  9831. return function() {
  9832. var args = arguments;
  9833. switch (args.length) {
  9834. case 0: return !predicate.call(this);
  9835. case 1: return !predicate.call(this, args[0]);
  9836. case 2: return !predicate.call(this, args[0], args[1]);
  9837. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9838. }
  9839. return !predicate.apply(this, args);
  9840. };
  9841. }
  9842. /**
  9843. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9844. * to the function return the value of the first invocation. The `func` is
  9845. * invoked with the `this` binding and arguments of the created function.
  9846. *
  9847. * @static
  9848. * @memberOf _
  9849. * @since 0.1.0
  9850. * @category Function
  9851. * @param {Function} func The function to restrict.
  9852. * @returns {Function} Returns the new restricted function.
  9853. * @example
  9854. *
  9855. * var initialize = _.once(createApplication);
  9856. * initialize();
  9857. * initialize();
  9858. * // => `createApplication` is invoked once
  9859. */
  9860. function once(func) {
  9861. return before(2, func);
  9862. }
  9863. /**
  9864. * Creates a function that invokes `func` with its arguments transformed.
  9865. *
  9866. * @static
  9867. * @since 4.0.0
  9868. * @memberOf _
  9869. * @category Function
  9870. * @param {Function} func The function to wrap.
  9871. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9872. * The argument transforms.
  9873. * @returns {Function} Returns the new function.
  9874. * @example
  9875. *
  9876. * function doubled(n) {
  9877. * return n * 2;
  9878. * }
  9879. *
  9880. * function square(n) {
  9881. * return n * n;
  9882. * }
  9883. *
  9884. * var func = _.overArgs(function(x, y) {
  9885. * return [x, y];
  9886. * }, [square, doubled]);
  9887. *
  9888. * func(9, 3);
  9889. * // => [81, 6]
  9890. *
  9891. * func(10, 5);
  9892. * // => [100, 10]
  9893. */
  9894. var overArgs = castRest(function(func, transforms) {
  9895. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9896. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9897. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9898. var funcsLength = transforms.length;
  9899. return baseRest(function(args) {
  9900. var index = -1,
  9901. length = nativeMin(args.length, funcsLength);
  9902. while (++index < length) {
  9903. args[index] = transforms[index].call(this, args[index]);
  9904. }
  9905. return apply(func, this, args);
  9906. });
  9907. });
  9908. /**
  9909. * Creates a function that invokes `func` with `partials` prepended to the
  9910. * arguments it receives. This method is like `_.bind` except it does **not**
  9911. * alter the `this` binding.
  9912. *
  9913. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9914. * builds, may be used as a placeholder for partially applied arguments.
  9915. *
  9916. * **Note:** This method doesn't set the "length" property of partially
  9917. * applied functions.
  9918. *
  9919. * @static
  9920. * @memberOf _
  9921. * @since 0.2.0
  9922. * @category Function
  9923. * @param {Function} func The function to partially apply arguments to.
  9924. * @param {...*} [partials] The arguments to be partially applied.
  9925. * @returns {Function} Returns the new partially applied function.
  9926. * @example
  9927. *
  9928. * function greet(greeting, name) {
  9929. * return greeting + ' ' + name;
  9930. * }
  9931. *
  9932. * var sayHelloTo = _.partial(greet, 'hello');
  9933. * sayHelloTo('fred');
  9934. * // => 'hello fred'
  9935. *
  9936. * // Partially applied with placeholders.
  9937. * var greetFred = _.partial(greet, _, 'fred');
  9938. * greetFred('hi');
  9939. * // => 'hi fred'
  9940. */
  9941. var partial = baseRest(function(func, partials) {
  9942. var holders = replaceHolders(partials, getHolder(partial));
  9943. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9944. });
  9945. /**
  9946. * This method is like `_.partial` except that partially applied arguments
  9947. * are appended to the arguments it receives.
  9948. *
  9949. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9950. * builds, may be used as a placeholder for partially applied arguments.
  9951. *
  9952. * **Note:** This method doesn't set the "length" property of partially
  9953. * applied functions.
  9954. *
  9955. * @static
  9956. * @memberOf _
  9957. * @since 1.0.0
  9958. * @category Function
  9959. * @param {Function} func The function to partially apply arguments to.
  9960. * @param {...*} [partials] The arguments to be partially applied.
  9961. * @returns {Function} Returns the new partially applied function.
  9962. * @example
  9963. *
  9964. * function greet(greeting, name) {
  9965. * return greeting + ' ' + name;
  9966. * }
  9967. *
  9968. * var greetFred = _.partialRight(greet, 'fred');
  9969. * greetFred('hi');
  9970. * // => 'hi fred'
  9971. *
  9972. * // Partially applied with placeholders.
  9973. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9974. * sayHelloTo('fred');
  9975. * // => 'hello fred'
  9976. */
  9977. var partialRight = baseRest(function(func, partials) {
  9978. var holders = replaceHolders(partials, getHolder(partialRight));
  9979. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9980. });
  9981. /**
  9982. * Creates a function that invokes `func` with arguments arranged according
  9983. * to the specified `indexes` where the argument value at the first index is
  9984. * provided as the first argument, the argument value at the second index is
  9985. * provided as the second argument, and so on.
  9986. *
  9987. * @static
  9988. * @memberOf _
  9989. * @since 3.0.0
  9990. * @category Function
  9991. * @param {Function} func The function to rearrange arguments for.
  9992. * @param {...(number|number[])} indexes The arranged argument indexes.
  9993. * @returns {Function} Returns the new function.
  9994. * @example
  9995. *
  9996. * var rearged = _.rearg(function(a, b, c) {
  9997. * return [a, b, c];
  9998. * }, [2, 0, 1]);
  9999. *
  10000. * rearged('b', 'c', 'a')
  10001. * // => ['a', 'b', 'c']
  10002. */
  10003. var rearg = flatRest(function(func, indexes) {
  10004. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10005. });
  10006. /**
  10007. * Creates a function that invokes `func` with the `this` binding of the
  10008. * created function and arguments from `start` and beyond provided as
  10009. * an array.
  10010. *
  10011. * **Note:** This method is based on the
  10012. * [rest parameter](https://mdn.io/rest_parameters).
  10013. *
  10014. * @static
  10015. * @memberOf _
  10016. * @since 4.0.0
  10017. * @category Function
  10018. * @param {Function} func The function to apply a rest parameter to.
  10019. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10020. * @returns {Function} Returns the new function.
  10021. * @example
  10022. *
  10023. * var say = _.rest(function(what, names) {
  10024. * return what + ' ' + _.initial(names).join(', ') +
  10025. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10026. * });
  10027. *
  10028. * say('hello', 'fred', 'barney', 'pebbles');
  10029. * // => 'hello fred, barney, & pebbles'
  10030. */
  10031. function rest(func, start) {
  10032. if (typeof func != 'function') {
  10033. throw new TypeError(FUNC_ERROR_TEXT);
  10034. }
  10035. start = start === undefined ? start : toInteger(start);
  10036. return baseRest(func, start);
  10037. }
  10038. /**
  10039. * Creates a function that invokes `func` with the `this` binding of the
  10040. * create function and an array of arguments much like
  10041. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10042. *
  10043. * **Note:** This method is based on the
  10044. * [spread operator](https://mdn.io/spread_operator).
  10045. *
  10046. * @static
  10047. * @memberOf _
  10048. * @since 3.2.0
  10049. * @category Function
  10050. * @param {Function} func The function to spread arguments over.
  10051. * @param {number} [start=0] The start position of the spread.
  10052. * @returns {Function} Returns the new function.
  10053. * @example
  10054. *
  10055. * var say = _.spread(function(who, what) {
  10056. * return who + ' says ' + what;
  10057. * });
  10058. *
  10059. * say(['fred', 'hello']);
  10060. * // => 'fred says hello'
  10061. *
  10062. * var numbers = Promise.all([
  10063. * Promise.resolve(40),
  10064. * Promise.resolve(36)
  10065. * ]);
  10066. *
  10067. * numbers.then(_.spread(function(x, y) {
  10068. * return x + y;
  10069. * }));
  10070. * // => a Promise of 76
  10071. */
  10072. function spread(func, start) {
  10073. if (typeof func != 'function') {
  10074. throw new TypeError(FUNC_ERROR_TEXT);
  10075. }
  10076. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10077. return baseRest(function(args) {
  10078. var array = args[start],
  10079. otherArgs = castSlice(args, 0, start);
  10080. if (array) {
  10081. arrayPush(otherArgs, array);
  10082. }
  10083. return apply(func, this, otherArgs);
  10084. });
  10085. }
  10086. /**
  10087. * Creates a throttled function that only invokes `func` at most once per
  10088. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10089. * method to cancel delayed `func` invocations and a `flush` method to
  10090. * immediately invoke them. Provide `options` to indicate whether `func`
  10091. * should be invoked on the leading and/or trailing edge of the `wait`
  10092. * timeout. The `func` is invoked with the last arguments provided to the
  10093. * throttled function. Subsequent calls to the throttled function return the
  10094. * result of the last `func` invocation.
  10095. *
  10096. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10097. * invoked on the trailing edge of the timeout only if the throttled function
  10098. * is invoked more than once during the `wait` timeout.
  10099. *
  10100. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10101. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10102. *
  10103. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10104. * for details over the differences between `_.throttle` and `_.debounce`.
  10105. *
  10106. * @static
  10107. * @memberOf _
  10108. * @since 0.1.0
  10109. * @category Function
  10110. * @param {Function} func The function to throttle.
  10111. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10112. * @param {Object} [options={}] The options object.
  10113. * @param {boolean} [options.leading=true]
  10114. * Specify invoking on the leading edge of the timeout.
  10115. * @param {boolean} [options.trailing=true]
  10116. * Specify invoking on the trailing edge of the timeout.
  10117. * @returns {Function} Returns the new throttled function.
  10118. * @example
  10119. *
  10120. * // Avoid excessively updating the position while scrolling.
  10121. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10122. *
  10123. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10124. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10125. * jQuery(element).on('click', throttled);
  10126. *
  10127. * // Cancel the trailing throttled invocation.
  10128. * jQuery(window).on('popstate', throttled.cancel);
  10129. */
  10130. function throttle(func, wait, options) {
  10131. var leading = true,
  10132. trailing = true;
  10133. if (typeof func != 'function') {
  10134. throw new TypeError(FUNC_ERROR_TEXT);
  10135. }
  10136. if (isObject(options)) {
  10137. leading = 'leading' in options ? !!options.leading : leading;
  10138. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10139. }
  10140. return debounce(func, wait, {
  10141. 'leading': leading,
  10142. 'maxWait': wait,
  10143. 'trailing': trailing
  10144. });
  10145. }
  10146. /**
  10147. * Creates a function that accepts up to one argument, ignoring any
  10148. * additional arguments.
  10149. *
  10150. * @static
  10151. * @memberOf _
  10152. * @since 4.0.0
  10153. * @category Function
  10154. * @param {Function} func The function to cap arguments for.
  10155. * @returns {Function} Returns the new capped function.
  10156. * @example
  10157. *
  10158. * _.map(['6', '8', '10'], _.unary(parseInt));
  10159. * // => [6, 8, 10]
  10160. */
  10161. function unary(func) {
  10162. return ary(func, 1);
  10163. }
  10164. /**
  10165. * Creates a function that provides `value` to `wrapper` as its first
  10166. * argument. Any additional arguments provided to the function are appended
  10167. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10168. * binding of the created function.
  10169. *
  10170. * @static
  10171. * @memberOf _
  10172. * @since 0.1.0
  10173. * @category Function
  10174. * @param {*} value The value to wrap.
  10175. * @param {Function} [wrapper=identity] The wrapper function.
  10176. * @returns {Function} Returns the new function.
  10177. * @example
  10178. *
  10179. * var p = _.wrap(_.escape, function(func, text) {
  10180. * return '<p>' + func(text) + '</p>';
  10181. * });
  10182. *
  10183. * p('fred, barney, & pebbles');
  10184. * // => '<p>fred, barney, &amp; pebbles</p>'
  10185. */
  10186. function wrap(value, wrapper) {
  10187. return partial(castFunction(wrapper), value);
  10188. }
  10189. /*------------------------------------------------------------------------*/
  10190. /**
  10191. * Casts `value` as an array if it's not one.
  10192. *
  10193. * @static
  10194. * @memberOf _
  10195. * @since 4.4.0
  10196. * @category Lang
  10197. * @param {*} value The value to inspect.
  10198. * @returns {Array} Returns the cast array.
  10199. * @example
  10200. *
  10201. * _.castArray(1);
  10202. * // => [1]
  10203. *
  10204. * _.castArray({ 'a': 1 });
  10205. * // => [{ 'a': 1 }]
  10206. *
  10207. * _.castArray('abc');
  10208. * // => ['abc']
  10209. *
  10210. * _.castArray(null);
  10211. * // => [null]
  10212. *
  10213. * _.castArray(undefined);
  10214. * // => [undefined]
  10215. *
  10216. * _.castArray();
  10217. * // => []
  10218. *
  10219. * var array = [1, 2, 3];
  10220. * console.log(_.castArray(array) === array);
  10221. * // => true
  10222. */
  10223. function castArray() {
  10224. if (!arguments.length) {
  10225. return [];
  10226. }
  10227. var value = arguments[0];
  10228. return isArray(value) ? value : [value];
  10229. }
  10230. /**
  10231. * Creates a shallow clone of `value`.
  10232. *
  10233. * **Note:** This method is loosely based on the
  10234. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10235. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10236. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10237. * arrays. The own enumerable properties of `arguments` objects are cloned
  10238. * as plain objects. An empty object is returned for uncloneable values such
  10239. * as error objects, functions, DOM nodes, and WeakMaps.
  10240. *
  10241. * @static
  10242. * @memberOf _
  10243. * @since 0.1.0
  10244. * @category Lang
  10245. * @param {*} value The value to clone.
  10246. * @returns {*} Returns the cloned value.
  10247. * @see _.cloneDeep
  10248. * @example
  10249. *
  10250. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10251. *
  10252. * var shallow = _.clone(objects);
  10253. * console.log(shallow[0] === objects[0]);
  10254. * // => true
  10255. */
  10256. function clone(value) {
  10257. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10258. }
  10259. /**
  10260. * This method is like `_.clone` except that it accepts `customizer` which
  10261. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10262. * cloning is handled by the method instead. The `customizer` is invoked with
  10263. * up to four arguments; (value [, index|key, object, stack]).
  10264. *
  10265. * @static
  10266. * @memberOf _
  10267. * @since 4.0.0
  10268. * @category Lang
  10269. * @param {*} value The value to clone.
  10270. * @param {Function} [customizer] The function to customize cloning.
  10271. * @returns {*} Returns the cloned value.
  10272. * @see _.cloneDeepWith
  10273. * @example
  10274. *
  10275. * function customizer(value) {
  10276. * if (_.isElement(value)) {
  10277. * return value.cloneNode(false);
  10278. * }
  10279. * }
  10280. *
  10281. * var el = _.cloneWith(document.body, customizer);
  10282. *
  10283. * console.log(el === document.body);
  10284. * // => false
  10285. * console.log(el.nodeName);
  10286. * // => 'BODY'
  10287. * console.log(el.childNodes.length);
  10288. * // => 0
  10289. */
  10290. function cloneWith(value, customizer) {
  10291. customizer = typeof customizer == 'function' ? customizer : undefined;
  10292. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10293. }
  10294. /**
  10295. * This method is like `_.clone` except that it recursively clones `value`.
  10296. *
  10297. * @static
  10298. * @memberOf _
  10299. * @since 1.0.0
  10300. * @category Lang
  10301. * @param {*} value The value to recursively clone.
  10302. * @returns {*} Returns the deep cloned value.
  10303. * @see _.clone
  10304. * @example
  10305. *
  10306. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10307. *
  10308. * var deep = _.cloneDeep(objects);
  10309. * console.log(deep[0] === objects[0]);
  10310. * // => false
  10311. */
  10312. function cloneDeep(value) {
  10313. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10314. }
  10315. /**
  10316. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10317. *
  10318. * @static
  10319. * @memberOf _
  10320. * @since 4.0.0
  10321. * @category Lang
  10322. * @param {*} value The value to recursively clone.
  10323. * @param {Function} [customizer] The function to customize cloning.
  10324. * @returns {*} Returns the deep cloned value.
  10325. * @see _.cloneWith
  10326. * @example
  10327. *
  10328. * function customizer(value) {
  10329. * if (_.isElement(value)) {
  10330. * return value.cloneNode(true);
  10331. * }
  10332. * }
  10333. *
  10334. * var el = _.cloneDeepWith(document.body, customizer);
  10335. *
  10336. * console.log(el === document.body);
  10337. * // => false
  10338. * console.log(el.nodeName);
  10339. * // => 'BODY'
  10340. * console.log(el.childNodes.length);
  10341. * // => 20
  10342. */
  10343. function cloneDeepWith(value, customizer) {
  10344. customizer = typeof customizer == 'function' ? customizer : undefined;
  10345. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10346. }
  10347. /**
  10348. * Checks if `object` conforms to `source` by invoking the predicate
  10349. * properties of `source` with the corresponding property values of `object`.
  10350. *
  10351. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10352. * partially applied.
  10353. *
  10354. * @static
  10355. * @memberOf _
  10356. * @since 4.14.0
  10357. * @category Lang
  10358. * @param {Object} object The object to inspect.
  10359. * @param {Object} source The object of property predicates to conform to.
  10360. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10361. * @example
  10362. *
  10363. * var object = { 'a': 1, 'b': 2 };
  10364. *
  10365. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10366. * // => true
  10367. *
  10368. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10369. * // => false
  10370. */
  10371. function conformsTo(object, source) {
  10372. return source == null || baseConformsTo(object, source, keys(source));
  10373. }
  10374. /**
  10375. * Performs a
  10376. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10377. * comparison between two values to determine if they are equivalent.
  10378. *
  10379. * @static
  10380. * @memberOf _
  10381. * @since 4.0.0
  10382. * @category Lang
  10383. * @param {*} value The value to compare.
  10384. * @param {*} other The other value to compare.
  10385. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10386. * @example
  10387. *
  10388. * var object = { 'a': 1 };
  10389. * var other = { 'a': 1 };
  10390. *
  10391. * _.eq(object, object);
  10392. * // => true
  10393. *
  10394. * _.eq(object, other);
  10395. * // => false
  10396. *
  10397. * _.eq('a', 'a');
  10398. * // => true
  10399. *
  10400. * _.eq('a', Object('a'));
  10401. * // => false
  10402. *
  10403. * _.eq(NaN, NaN);
  10404. * // => true
  10405. */
  10406. function eq(value, other) {
  10407. return value === other || (value !== value && other !== other);
  10408. }
  10409. /**
  10410. * Checks if `value` is greater than `other`.
  10411. *
  10412. * @static
  10413. * @memberOf _
  10414. * @since 3.9.0
  10415. * @category Lang
  10416. * @param {*} value The value to compare.
  10417. * @param {*} other The other value to compare.
  10418. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10419. * else `false`.
  10420. * @see _.lt
  10421. * @example
  10422. *
  10423. * _.gt(3, 1);
  10424. * // => true
  10425. *
  10426. * _.gt(3, 3);
  10427. * // => false
  10428. *
  10429. * _.gt(1, 3);
  10430. * // => false
  10431. */
  10432. var gt = createRelationalOperation(baseGt);
  10433. /**
  10434. * Checks if `value` is greater than or equal to `other`.
  10435. *
  10436. * @static
  10437. * @memberOf _
  10438. * @since 3.9.0
  10439. * @category Lang
  10440. * @param {*} value The value to compare.
  10441. * @param {*} other The other value to compare.
  10442. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10443. * `other`, else `false`.
  10444. * @see _.lte
  10445. * @example
  10446. *
  10447. * _.gte(3, 1);
  10448. * // => true
  10449. *
  10450. * _.gte(3, 3);
  10451. * // => true
  10452. *
  10453. * _.gte(1, 3);
  10454. * // => false
  10455. */
  10456. var gte = createRelationalOperation(function(value, other) {
  10457. return value >= other;
  10458. });
  10459. /**
  10460. * Checks if `value` is likely an `arguments` object.
  10461. *
  10462. * @static
  10463. * @memberOf _
  10464. * @since 0.1.0
  10465. * @category Lang
  10466. * @param {*} value The value to check.
  10467. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10468. * else `false`.
  10469. * @example
  10470. *
  10471. * _.isArguments(function() { return arguments; }());
  10472. * // => true
  10473. *
  10474. * _.isArguments([1, 2, 3]);
  10475. * // => false
  10476. */
  10477. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10478. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10479. !propertyIsEnumerable.call(value, 'callee');
  10480. };
  10481. /**
  10482. * Checks if `value` is classified as an `Array` object.
  10483. *
  10484. * @static
  10485. * @memberOf _
  10486. * @since 0.1.0
  10487. * @category Lang
  10488. * @param {*} value The value to check.
  10489. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10490. * @example
  10491. *
  10492. * _.isArray([1, 2, 3]);
  10493. * // => true
  10494. *
  10495. * _.isArray(document.body.children);
  10496. * // => false
  10497. *
  10498. * _.isArray('abc');
  10499. * // => false
  10500. *
  10501. * _.isArray(_.noop);
  10502. * // => false
  10503. */
  10504. var isArray = Array.isArray;
  10505. /**
  10506. * Checks if `value` is classified as an `ArrayBuffer` object.
  10507. *
  10508. * @static
  10509. * @memberOf _
  10510. * @since 4.3.0
  10511. * @category Lang
  10512. * @param {*} value The value to check.
  10513. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10514. * @example
  10515. *
  10516. * _.isArrayBuffer(new ArrayBuffer(2));
  10517. * // => true
  10518. *
  10519. * _.isArrayBuffer(new Array(2));
  10520. * // => false
  10521. */
  10522. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10523. /**
  10524. * Checks if `value` is array-like. A value is considered array-like if it's
  10525. * not a function and has a `value.length` that's an integer greater than or
  10526. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10527. *
  10528. * @static
  10529. * @memberOf _
  10530. * @since 4.0.0
  10531. * @category Lang
  10532. * @param {*} value The value to check.
  10533. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10534. * @example
  10535. *
  10536. * _.isArrayLike([1, 2, 3]);
  10537. * // => true
  10538. *
  10539. * _.isArrayLike(document.body.children);
  10540. * // => true
  10541. *
  10542. * _.isArrayLike('abc');
  10543. * // => true
  10544. *
  10545. * _.isArrayLike(_.noop);
  10546. * // => false
  10547. */
  10548. function isArrayLike(value) {
  10549. return value != null && isLength(value.length) && !isFunction(value);
  10550. }
  10551. /**
  10552. * This method is like `_.isArrayLike` except that it also checks if `value`
  10553. * is an object.
  10554. *
  10555. * @static
  10556. * @memberOf _
  10557. * @since 4.0.0
  10558. * @category Lang
  10559. * @param {*} value The value to check.
  10560. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10561. * else `false`.
  10562. * @example
  10563. *
  10564. * _.isArrayLikeObject([1, 2, 3]);
  10565. * // => true
  10566. *
  10567. * _.isArrayLikeObject(document.body.children);
  10568. * // => true
  10569. *
  10570. * _.isArrayLikeObject('abc');
  10571. * // => false
  10572. *
  10573. * _.isArrayLikeObject(_.noop);
  10574. * // => false
  10575. */
  10576. function isArrayLikeObject(value) {
  10577. return isObjectLike(value) && isArrayLike(value);
  10578. }
  10579. /**
  10580. * Checks if `value` is classified as a boolean primitive or object.
  10581. *
  10582. * @static
  10583. * @memberOf _
  10584. * @since 0.1.0
  10585. * @category Lang
  10586. * @param {*} value The value to check.
  10587. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10588. * @example
  10589. *
  10590. * _.isBoolean(false);
  10591. * // => true
  10592. *
  10593. * _.isBoolean(null);
  10594. * // => false
  10595. */
  10596. function isBoolean(value) {
  10597. return value === true || value === false ||
  10598. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10599. }
  10600. /**
  10601. * Checks if `value` is a buffer.
  10602. *
  10603. * @static
  10604. * @memberOf _
  10605. * @since 4.3.0
  10606. * @category Lang
  10607. * @param {*} value The value to check.
  10608. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10609. * @example
  10610. *
  10611. * _.isBuffer(new Buffer(2));
  10612. * // => true
  10613. *
  10614. * _.isBuffer(new Uint8Array(2));
  10615. * // => false
  10616. */
  10617. var isBuffer = nativeIsBuffer || stubFalse;
  10618. /**
  10619. * Checks if `value` is classified as a `Date` object.
  10620. *
  10621. * @static
  10622. * @memberOf _
  10623. * @since 0.1.0
  10624. * @category Lang
  10625. * @param {*} value The value to check.
  10626. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10627. * @example
  10628. *
  10629. * _.isDate(new Date);
  10630. * // => true
  10631. *
  10632. * _.isDate('Mon April 23 2012');
  10633. * // => false
  10634. */
  10635. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10636. /**
  10637. * Checks if `value` is likely a DOM element.
  10638. *
  10639. * @static
  10640. * @memberOf _
  10641. * @since 0.1.0
  10642. * @category Lang
  10643. * @param {*} value The value to check.
  10644. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10645. * @example
  10646. *
  10647. * _.isElement(document.body);
  10648. * // => true
  10649. *
  10650. * _.isElement('<body>');
  10651. * // => false
  10652. */
  10653. function isElement(value) {
  10654. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10655. }
  10656. /**
  10657. * Checks if `value` is an empty object, collection, map, or set.
  10658. *
  10659. * Objects are considered empty if they have no own enumerable string keyed
  10660. * properties.
  10661. *
  10662. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10663. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10664. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10665. *
  10666. * @static
  10667. * @memberOf _
  10668. * @since 0.1.0
  10669. * @category Lang
  10670. * @param {*} value The value to check.
  10671. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10672. * @example
  10673. *
  10674. * _.isEmpty(null);
  10675. * // => true
  10676. *
  10677. * _.isEmpty(true);
  10678. * // => true
  10679. *
  10680. * _.isEmpty(1);
  10681. * // => true
  10682. *
  10683. * _.isEmpty([1, 2, 3]);
  10684. * // => false
  10685. *
  10686. * _.isEmpty({ 'a': 1 });
  10687. * // => false
  10688. */
  10689. function isEmpty(value) {
  10690. if (value == null) {
  10691. return true;
  10692. }
  10693. if (isArrayLike(value) &&
  10694. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10695. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10696. return !value.length;
  10697. }
  10698. var tag = getTag(value);
  10699. if (tag == mapTag || tag == setTag) {
  10700. return !value.size;
  10701. }
  10702. if (isPrototype(value)) {
  10703. return !baseKeys(value).length;
  10704. }
  10705. for (var key in value) {
  10706. if (hasOwnProperty.call(value, key)) {
  10707. return false;
  10708. }
  10709. }
  10710. return true;
  10711. }
  10712. /**
  10713. * Performs a deep comparison between two values to determine if they are
  10714. * equivalent.
  10715. *
  10716. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10717. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10718. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10719. * by their own, not inherited, enumerable properties. Functions and DOM
  10720. * nodes are compared by strict equality, i.e. `===`.
  10721. *
  10722. * @static
  10723. * @memberOf _
  10724. * @since 0.1.0
  10725. * @category Lang
  10726. * @param {*} value The value to compare.
  10727. * @param {*} other The other value to compare.
  10728. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10729. * @example
  10730. *
  10731. * var object = { 'a': 1 };
  10732. * var other = { 'a': 1 };
  10733. *
  10734. * _.isEqual(object, other);
  10735. * // => true
  10736. *
  10737. * object === other;
  10738. * // => false
  10739. */
  10740. function isEqual(value, other) {
  10741. return baseIsEqual(value, other);
  10742. }
  10743. /**
  10744. * This method is like `_.isEqual` except that it accepts `customizer` which
  10745. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10746. * are handled by the method instead. The `customizer` is invoked with up to
  10747. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10748. *
  10749. * @static
  10750. * @memberOf _
  10751. * @since 4.0.0
  10752. * @category Lang
  10753. * @param {*} value The value to compare.
  10754. * @param {*} other The other value to compare.
  10755. * @param {Function} [customizer] The function to customize comparisons.
  10756. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10757. * @example
  10758. *
  10759. * function isGreeting(value) {
  10760. * return /^h(?:i|ello)$/.test(value);
  10761. * }
  10762. *
  10763. * function customizer(objValue, othValue) {
  10764. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10765. * return true;
  10766. * }
  10767. * }
  10768. *
  10769. * var array = ['hello', 'goodbye'];
  10770. * var other = ['hi', 'goodbye'];
  10771. *
  10772. * _.isEqualWith(array, other, customizer);
  10773. * // => true
  10774. */
  10775. function isEqualWith(value, other, customizer) {
  10776. customizer = typeof customizer == 'function' ? customizer : undefined;
  10777. var result = customizer ? customizer(value, other) : undefined;
  10778. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10779. }
  10780. /**
  10781. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10782. * `SyntaxError`, `TypeError`, or `URIError` object.
  10783. *
  10784. * @static
  10785. * @memberOf _
  10786. * @since 3.0.0
  10787. * @category Lang
  10788. * @param {*} value The value to check.
  10789. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10790. * @example
  10791. *
  10792. * _.isError(new Error);
  10793. * // => true
  10794. *
  10795. * _.isError(Error);
  10796. * // => false
  10797. */
  10798. function isError(value) {
  10799. if (!isObjectLike(value)) {
  10800. return false;
  10801. }
  10802. var tag = baseGetTag(value);
  10803. return tag == errorTag || tag == domExcTag ||
  10804. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10805. }
  10806. /**
  10807. * Checks if `value` is a finite primitive number.
  10808. *
  10809. * **Note:** This method is based on
  10810. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10811. *
  10812. * @static
  10813. * @memberOf _
  10814. * @since 0.1.0
  10815. * @category Lang
  10816. * @param {*} value The value to check.
  10817. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10818. * @example
  10819. *
  10820. * _.isFinite(3);
  10821. * // => true
  10822. *
  10823. * _.isFinite(Number.MIN_VALUE);
  10824. * // => true
  10825. *
  10826. * _.isFinite(Infinity);
  10827. * // => false
  10828. *
  10829. * _.isFinite('3');
  10830. * // => false
  10831. */
  10832. function isFinite(value) {
  10833. return typeof value == 'number' && nativeIsFinite(value);
  10834. }
  10835. /**
  10836. * Checks if `value` is classified as a `Function` object.
  10837. *
  10838. * @static
  10839. * @memberOf _
  10840. * @since 0.1.0
  10841. * @category Lang
  10842. * @param {*} value The value to check.
  10843. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10844. * @example
  10845. *
  10846. * _.isFunction(_);
  10847. * // => true
  10848. *
  10849. * _.isFunction(/abc/);
  10850. * // => false
  10851. */
  10852. function isFunction(value) {
  10853. if (!isObject(value)) {
  10854. return false;
  10855. }
  10856. // The use of `Object#toString` avoids issues with the `typeof` operator
  10857. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10858. var tag = baseGetTag(value);
  10859. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10860. }
  10861. /**
  10862. * Checks if `value` is an integer.
  10863. *
  10864. * **Note:** This method is based on
  10865. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10866. *
  10867. * @static
  10868. * @memberOf _
  10869. * @since 4.0.0
  10870. * @category Lang
  10871. * @param {*} value The value to check.
  10872. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10873. * @example
  10874. *
  10875. * _.isInteger(3);
  10876. * // => true
  10877. *
  10878. * _.isInteger(Number.MIN_VALUE);
  10879. * // => false
  10880. *
  10881. * _.isInteger(Infinity);
  10882. * // => false
  10883. *
  10884. * _.isInteger('3');
  10885. * // => false
  10886. */
  10887. function isInteger(value) {
  10888. return typeof value == 'number' && value == toInteger(value);
  10889. }
  10890. /**
  10891. * Checks if `value` is a valid array-like length.
  10892. *
  10893. * **Note:** This method is loosely based on
  10894. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10895. *
  10896. * @static
  10897. * @memberOf _
  10898. * @since 4.0.0
  10899. * @category Lang
  10900. * @param {*} value The value to check.
  10901. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10902. * @example
  10903. *
  10904. * _.isLength(3);
  10905. * // => true
  10906. *
  10907. * _.isLength(Number.MIN_VALUE);
  10908. * // => false
  10909. *
  10910. * _.isLength(Infinity);
  10911. * // => false
  10912. *
  10913. * _.isLength('3');
  10914. * // => false
  10915. */
  10916. function isLength(value) {
  10917. return typeof value == 'number' &&
  10918. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10919. }
  10920. /**
  10921. * Checks if `value` is the
  10922. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10923. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10924. *
  10925. * @static
  10926. * @memberOf _
  10927. * @since 0.1.0
  10928. * @category Lang
  10929. * @param {*} value The value to check.
  10930. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10931. * @example
  10932. *
  10933. * _.isObject({});
  10934. * // => true
  10935. *
  10936. * _.isObject([1, 2, 3]);
  10937. * // => true
  10938. *
  10939. * _.isObject(_.noop);
  10940. * // => true
  10941. *
  10942. * _.isObject(null);
  10943. * // => false
  10944. */
  10945. function isObject(value) {
  10946. var type = typeof value;
  10947. return value != null && (type == 'object' || type == 'function');
  10948. }
  10949. /**
  10950. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10951. * and has a `typeof` result of "object".
  10952. *
  10953. * @static
  10954. * @memberOf _
  10955. * @since 4.0.0
  10956. * @category Lang
  10957. * @param {*} value The value to check.
  10958. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10959. * @example
  10960. *
  10961. * _.isObjectLike({});
  10962. * // => true
  10963. *
  10964. * _.isObjectLike([1, 2, 3]);
  10965. * // => true
  10966. *
  10967. * _.isObjectLike(_.noop);
  10968. * // => false
  10969. *
  10970. * _.isObjectLike(null);
  10971. * // => false
  10972. */
  10973. function isObjectLike(value) {
  10974. return value != null && typeof value == 'object';
  10975. }
  10976. /**
  10977. * Checks if `value` is classified as a `Map` object.
  10978. *
  10979. * @static
  10980. * @memberOf _
  10981. * @since 4.3.0
  10982. * @category Lang
  10983. * @param {*} value The value to check.
  10984. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  10985. * @example
  10986. *
  10987. * _.isMap(new Map);
  10988. * // => true
  10989. *
  10990. * _.isMap(new WeakMap);
  10991. * // => false
  10992. */
  10993. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  10994. /**
  10995. * Performs a partial deep comparison between `object` and `source` to
  10996. * determine if `object` contains equivalent property values.
  10997. *
  10998. * **Note:** This method is equivalent to `_.matches` when `source` is
  10999. * partially applied.
  11000. *
  11001. * Partial comparisons will match empty array and empty object `source`
  11002. * values against any array or object value, respectively. See `_.isEqual`
  11003. * for a list of supported value comparisons.
  11004. *
  11005. * @static
  11006. * @memberOf _
  11007. * @since 3.0.0
  11008. * @category Lang
  11009. * @param {Object} object The object to inspect.
  11010. * @param {Object} source The object of property values to match.
  11011. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11012. * @example
  11013. *
  11014. * var object = { 'a': 1, 'b': 2 };
  11015. *
  11016. * _.isMatch(object, { 'b': 2 });
  11017. * // => true
  11018. *
  11019. * _.isMatch(object, { 'b': 1 });
  11020. * // => false
  11021. */
  11022. function isMatch(object, source) {
  11023. return object === source || baseIsMatch(object, source, getMatchData(source));
  11024. }
  11025. /**
  11026. * This method is like `_.isMatch` except that it accepts `customizer` which
  11027. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11028. * are handled by the method instead. The `customizer` is invoked with five
  11029. * arguments: (objValue, srcValue, index|key, object, source).
  11030. *
  11031. * @static
  11032. * @memberOf _
  11033. * @since 4.0.0
  11034. * @category Lang
  11035. * @param {Object} object The object to inspect.
  11036. * @param {Object} source The object of property values to match.
  11037. * @param {Function} [customizer] The function to customize comparisons.
  11038. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11039. * @example
  11040. *
  11041. * function isGreeting(value) {
  11042. * return /^h(?:i|ello)$/.test(value);
  11043. * }
  11044. *
  11045. * function customizer(objValue, srcValue) {
  11046. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11047. * return true;
  11048. * }
  11049. * }
  11050. *
  11051. * var object = { 'greeting': 'hello' };
  11052. * var source = { 'greeting': 'hi' };
  11053. *
  11054. * _.isMatchWith(object, source, customizer);
  11055. * // => true
  11056. */
  11057. function isMatchWith(object, source, customizer) {
  11058. customizer = typeof customizer == 'function' ? customizer : undefined;
  11059. return baseIsMatch(object, source, getMatchData(source), customizer);
  11060. }
  11061. /**
  11062. * Checks if `value` is `NaN`.
  11063. *
  11064. * **Note:** This method is based on
  11065. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11066. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11067. * `undefined` and other non-number values.
  11068. *
  11069. * @static
  11070. * @memberOf _
  11071. * @since 0.1.0
  11072. * @category Lang
  11073. * @param {*} value The value to check.
  11074. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11075. * @example
  11076. *
  11077. * _.isNaN(NaN);
  11078. * // => true
  11079. *
  11080. * _.isNaN(new Number(NaN));
  11081. * // => true
  11082. *
  11083. * isNaN(undefined);
  11084. * // => true
  11085. *
  11086. * _.isNaN(undefined);
  11087. * // => false
  11088. */
  11089. function isNaN(value) {
  11090. // An `NaN` primitive is the only value that is not equal to itself.
  11091. // Perform the `toStringTag` check first to avoid errors with some
  11092. // ActiveX objects in IE.
  11093. return isNumber(value) && value != +value;
  11094. }
  11095. /**
  11096. * Checks if `value` is a pristine native function.
  11097. *
  11098. * **Note:** This method can't reliably detect native functions in the presence
  11099. * of the core-js package because core-js circumvents this kind of detection.
  11100. * Despite multiple requests, the core-js maintainer has made it clear: any
  11101. * attempt to fix the detection will be obstructed. As a result, we're left
  11102. * with little choice but to throw an error. Unfortunately, this also affects
  11103. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11104. * which rely on core-js.
  11105. *
  11106. * @static
  11107. * @memberOf _
  11108. * @since 3.0.0
  11109. * @category Lang
  11110. * @param {*} value The value to check.
  11111. * @returns {boolean} Returns `true` if `value` is a native function,
  11112. * else `false`.
  11113. * @example
  11114. *
  11115. * _.isNative(Array.prototype.push);
  11116. * // => true
  11117. *
  11118. * _.isNative(_);
  11119. * // => false
  11120. */
  11121. function isNative(value) {
  11122. if (isMaskable(value)) {
  11123. throw new Error(CORE_ERROR_TEXT);
  11124. }
  11125. return baseIsNative(value);
  11126. }
  11127. /**
  11128. * Checks if `value` is `null`.
  11129. *
  11130. * @static
  11131. * @memberOf _
  11132. * @since 0.1.0
  11133. * @category Lang
  11134. * @param {*} value The value to check.
  11135. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11136. * @example
  11137. *
  11138. * _.isNull(null);
  11139. * // => true
  11140. *
  11141. * _.isNull(void 0);
  11142. * // => false
  11143. */
  11144. function isNull(value) {
  11145. return value === null;
  11146. }
  11147. /**
  11148. * Checks if `value` is `null` or `undefined`.
  11149. *
  11150. * @static
  11151. * @memberOf _
  11152. * @since 4.0.0
  11153. * @category Lang
  11154. * @param {*} value The value to check.
  11155. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11156. * @example
  11157. *
  11158. * _.isNil(null);
  11159. * // => true
  11160. *
  11161. * _.isNil(void 0);
  11162. * // => true
  11163. *
  11164. * _.isNil(NaN);
  11165. * // => false
  11166. */
  11167. function isNil(value) {
  11168. return value == null;
  11169. }
  11170. /**
  11171. * Checks if `value` is classified as a `Number` primitive or object.
  11172. *
  11173. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11174. * classified as numbers, use the `_.isFinite` method.
  11175. *
  11176. * @static
  11177. * @memberOf _
  11178. * @since 0.1.0
  11179. * @category Lang
  11180. * @param {*} value The value to check.
  11181. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11182. * @example
  11183. *
  11184. * _.isNumber(3);
  11185. * // => true
  11186. *
  11187. * _.isNumber(Number.MIN_VALUE);
  11188. * // => true
  11189. *
  11190. * _.isNumber(Infinity);
  11191. * // => true
  11192. *
  11193. * _.isNumber('3');
  11194. * // => false
  11195. */
  11196. function isNumber(value) {
  11197. return typeof value == 'number' ||
  11198. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11199. }
  11200. /**
  11201. * Checks if `value` is a plain object, that is, an object created by the
  11202. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11203. *
  11204. * @static
  11205. * @memberOf _
  11206. * @since 0.8.0
  11207. * @category Lang
  11208. * @param {*} value The value to check.
  11209. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11210. * @example
  11211. *
  11212. * function Foo() {
  11213. * this.a = 1;
  11214. * }
  11215. *
  11216. * _.isPlainObject(new Foo);
  11217. * // => false
  11218. *
  11219. * _.isPlainObject([1, 2, 3]);
  11220. * // => false
  11221. *
  11222. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11223. * // => true
  11224. *
  11225. * _.isPlainObject(Object.create(null));
  11226. * // => true
  11227. */
  11228. function isPlainObject(value) {
  11229. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11230. return false;
  11231. }
  11232. var proto = getPrototype(value);
  11233. if (proto === null) {
  11234. return true;
  11235. }
  11236. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11237. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11238. funcToString.call(Ctor) == objectCtorString;
  11239. }
  11240. /**
  11241. * Checks if `value` is classified as a `RegExp` object.
  11242. *
  11243. * @static
  11244. * @memberOf _
  11245. * @since 0.1.0
  11246. * @category Lang
  11247. * @param {*} value The value to check.
  11248. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11249. * @example
  11250. *
  11251. * _.isRegExp(/abc/);
  11252. * // => true
  11253. *
  11254. * _.isRegExp('/abc/');
  11255. * // => false
  11256. */
  11257. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11258. /**
  11259. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11260. * double precision number which isn't the result of a rounded unsafe integer.
  11261. *
  11262. * **Note:** This method is based on
  11263. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11264. *
  11265. * @static
  11266. * @memberOf _
  11267. * @since 4.0.0
  11268. * @category Lang
  11269. * @param {*} value The value to check.
  11270. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11271. * @example
  11272. *
  11273. * _.isSafeInteger(3);
  11274. * // => true
  11275. *
  11276. * _.isSafeInteger(Number.MIN_VALUE);
  11277. * // => false
  11278. *
  11279. * _.isSafeInteger(Infinity);
  11280. * // => false
  11281. *
  11282. * _.isSafeInteger('3');
  11283. * // => false
  11284. */
  11285. function isSafeInteger(value) {
  11286. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11287. }
  11288. /**
  11289. * Checks if `value` is classified as a `Set` object.
  11290. *
  11291. * @static
  11292. * @memberOf _
  11293. * @since 4.3.0
  11294. * @category Lang
  11295. * @param {*} value The value to check.
  11296. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11297. * @example
  11298. *
  11299. * _.isSet(new Set);
  11300. * // => true
  11301. *
  11302. * _.isSet(new WeakSet);
  11303. * // => false
  11304. */
  11305. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11306. /**
  11307. * Checks if `value` is classified as a `String` primitive or object.
  11308. *
  11309. * @static
  11310. * @since 0.1.0
  11311. * @memberOf _
  11312. * @category Lang
  11313. * @param {*} value The value to check.
  11314. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11315. * @example
  11316. *
  11317. * _.isString('abc');
  11318. * // => true
  11319. *
  11320. * _.isString(1);
  11321. * // => false
  11322. */
  11323. function isString(value) {
  11324. return typeof value == 'string' ||
  11325. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11326. }
  11327. /**
  11328. * Checks if `value` is classified as a `Symbol` primitive or object.
  11329. *
  11330. * @static
  11331. * @memberOf _
  11332. * @since 4.0.0
  11333. * @category Lang
  11334. * @param {*} value The value to check.
  11335. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11336. * @example
  11337. *
  11338. * _.isSymbol(Symbol.iterator);
  11339. * // => true
  11340. *
  11341. * _.isSymbol('abc');
  11342. * // => false
  11343. */
  11344. function isSymbol(value) {
  11345. return typeof value == 'symbol' ||
  11346. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11347. }
  11348. /**
  11349. * Checks if `value` is classified as a typed array.
  11350. *
  11351. * @static
  11352. * @memberOf _
  11353. * @since 3.0.0
  11354. * @category Lang
  11355. * @param {*} value The value to check.
  11356. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11357. * @example
  11358. *
  11359. * _.isTypedArray(new Uint8Array);
  11360. * // => true
  11361. *
  11362. * _.isTypedArray([]);
  11363. * // => false
  11364. */
  11365. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11366. /**
  11367. * Checks if `value` is `undefined`.
  11368. *
  11369. * @static
  11370. * @since 0.1.0
  11371. * @memberOf _
  11372. * @category Lang
  11373. * @param {*} value The value to check.
  11374. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11375. * @example
  11376. *
  11377. * _.isUndefined(void 0);
  11378. * // => true
  11379. *
  11380. * _.isUndefined(null);
  11381. * // => false
  11382. */
  11383. function isUndefined(value) {
  11384. return value === undefined;
  11385. }
  11386. /**
  11387. * Checks if `value` is classified as a `WeakMap` object.
  11388. *
  11389. * @static
  11390. * @memberOf _
  11391. * @since 4.3.0
  11392. * @category Lang
  11393. * @param {*} value The value to check.
  11394. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11395. * @example
  11396. *
  11397. * _.isWeakMap(new WeakMap);
  11398. * // => true
  11399. *
  11400. * _.isWeakMap(new Map);
  11401. * // => false
  11402. */
  11403. function isWeakMap(value) {
  11404. return isObjectLike(value) && getTag(value) == weakMapTag;
  11405. }
  11406. /**
  11407. * Checks if `value` is classified as a `WeakSet` object.
  11408. *
  11409. * @static
  11410. * @memberOf _
  11411. * @since 4.3.0
  11412. * @category Lang
  11413. * @param {*} value The value to check.
  11414. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11415. * @example
  11416. *
  11417. * _.isWeakSet(new WeakSet);
  11418. * // => true
  11419. *
  11420. * _.isWeakSet(new Set);
  11421. * // => false
  11422. */
  11423. function isWeakSet(value) {
  11424. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11425. }
  11426. /**
  11427. * Checks if `value` is less than `other`.
  11428. *
  11429. * @static
  11430. * @memberOf _
  11431. * @since 3.9.0
  11432. * @category Lang
  11433. * @param {*} value The value to compare.
  11434. * @param {*} other The other value to compare.
  11435. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11436. * else `false`.
  11437. * @see _.gt
  11438. * @example
  11439. *
  11440. * _.lt(1, 3);
  11441. * // => true
  11442. *
  11443. * _.lt(3, 3);
  11444. * // => false
  11445. *
  11446. * _.lt(3, 1);
  11447. * // => false
  11448. */
  11449. var lt = createRelationalOperation(baseLt);
  11450. /**
  11451. * Checks if `value` is less than or equal to `other`.
  11452. *
  11453. * @static
  11454. * @memberOf _
  11455. * @since 3.9.0
  11456. * @category Lang
  11457. * @param {*} value The value to compare.
  11458. * @param {*} other The other value to compare.
  11459. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11460. * `other`, else `false`.
  11461. * @see _.gte
  11462. * @example
  11463. *
  11464. * _.lte(1, 3);
  11465. * // => true
  11466. *
  11467. * _.lte(3, 3);
  11468. * // => true
  11469. *
  11470. * _.lte(3, 1);
  11471. * // => false
  11472. */
  11473. var lte = createRelationalOperation(function(value, other) {
  11474. return value <= other;
  11475. });
  11476. /**
  11477. * Converts `value` to an array.
  11478. *
  11479. * @static
  11480. * @since 0.1.0
  11481. * @memberOf _
  11482. * @category Lang
  11483. * @param {*} value The value to convert.
  11484. * @returns {Array} Returns the converted array.
  11485. * @example
  11486. *
  11487. * _.toArray({ 'a': 1, 'b': 2 });
  11488. * // => [1, 2]
  11489. *
  11490. * _.toArray('abc');
  11491. * // => ['a', 'b', 'c']
  11492. *
  11493. * _.toArray(1);
  11494. * // => []
  11495. *
  11496. * _.toArray(null);
  11497. * // => []
  11498. */
  11499. function toArray(value) {
  11500. if (!value) {
  11501. return [];
  11502. }
  11503. if (isArrayLike(value)) {
  11504. return isString(value) ? stringToArray(value) : copyArray(value);
  11505. }
  11506. if (symIterator && value[symIterator]) {
  11507. return iteratorToArray(value[symIterator]());
  11508. }
  11509. var tag = getTag(value),
  11510. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11511. return func(value);
  11512. }
  11513. /**
  11514. * Converts `value` to a finite number.
  11515. *
  11516. * @static
  11517. * @memberOf _
  11518. * @since 4.12.0
  11519. * @category Lang
  11520. * @param {*} value The value to convert.
  11521. * @returns {number} Returns the converted number.
  11522. * @example
  11523. *
  11524. * _.toFinite(3.2);
  11525. * // => 3.2
  11526. *
  11527. * _.toFinite(Number.MIN_VALUE);
  11528. * // => 5e-324
  11529. *
  11530. * _.toFinite(Infinity);
  11531. * // => 1.7976931348623157e+308
  11532. *
  11533. * _.toFinite('3.2');
  11534. * // => 3.2
  11535. */
  11536. function toFinite(value) {
  11537. if (!value) {
  11538. return value === 0 ? value : 0;
  11539. }
  11540. value = toNumber(value);
  11541. if (value === INFINITY || value === -INFINITY) {
  11542. var sign = (value < 0 ? -1 : 1);
  11543. return sign * MAX_INTEGER;
  11544. }
  11545. return value === value ? value : 0;
  11546. }
  11547. /**
  11548. * Converts `value` to an integer.
  11549. *
  11550. * **Note:** This method is loosely based on
  11551. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11552. *
  11553. * @static
  11554. * @memberOf _
  11555. * @since 4.0.0
  11556. * @category Lang
  11557. * @param {*} value The value to convert.
  11558. * @returns {number} Returns the converted integer.
  11559. * @example
  11560. *
  11561. * _.toInteger(3.2);
  11562. * // => 3
  11563. *
  11564. * _.toInteger(Number.MIN_VALUE);
  11565. * // => 0
  11566. *
  11567. * _.toInteger(Infinity);
  11568. * // => 1.7976931348623157e+308
  11569. *
  11570. * _.toInteger('3.2');
  11571. * // => 3
  11572. */
  11573. function toInteger(value) {
  11574. var result = toFinite(value),
  11575. remainder = result % 1;
  11576. return result === result ? (remainder ? result - remainder : result) : 0;
  11577. }
  11578. /**
  11579. * Converts `value` to an integer suitable for use as the length of an
  11580. * array-like object.
  11581. *
  11582. * **Note:** This method is based on
  11583. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  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. * _.toLength(3.2);
  11594. * // => 3
  11595. *
  11596. * _.toLength(Number.MIN_VALUE);
  11597. * // => 0
  11598. *
  11599. * _.toLength(Infinity);
  11600. * // => 4294967295
  11601. *
  11602. * _.toLength('3.2');
  11603. * // => 3
  11604. */
  11605. function toLength(value) {
  11606. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11607. }
  11608. /**
  11609. * Converts `value` to a number.
  11610. *
  11611. * @static
  11612. * @memberOf _
  11613. * @since 4.0.0
  11614. * @category Lang
  11615. * @param {*} value The value to process.
  11616. * @returns {number} Returns the number.
  11617. * @example
  11618. *
  11619. * _.toNumber(3.2);
  11620. * // => 3.2
  11621. *
  11622. * _.toNumber(Number.MIN_VALUE);
  11623. * // => 5e-324
  11624. *
  11625. * _.toNumber(Infinity);
  11626. * // => Infinity
  11627. *
  11628. * _.toNumber('3.2');
  11629. * // => 3.2
  11630. */
  11631. function toNumber(value) {
  11632. if (typeof value == 'number') {
  11633. return value;
  11634. }
  11635. if (isSymbol(value)) {
  11636. return NAN;
  11637. }
  11638. if (isObject(value)) {
  11639. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11640. value = isObject(other) ? (other + '') : other;
  11641. }
  11642. if (typeof value != 'string') {
  11643. return value === 0 ? value : +value;
  11644. }
  11645. value = value.replace(reTrim, '');
  11646. var isBinary = reIsBinary.test(value);
  11647. return (isBinary || reIsOctal.test(value))
  11648. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11649. : (reIsBadHex.test(value) ? NAN : +value);
  11650. }
  11651. /**
  11652. * Converts `value` to a plain object flattening inherited enumerable string
  11653. * keyed properties of `value` to own properties of the plain object.
  11654. *
  11655. * @static
  11656. * @memberOf _
  11657. * @since 3.0.0
  11658. * @category Lang
  11659. * @param {*} value The value to convert.
  11660. * @returns {Object} Returns the converted plain object.
  11661. * @example
  11662. *
  11663. * function Foo() {
  11664. * this.b = 2;
  11665. * }
  11666. *
  11667. * Foo.prototype.c = 3;
  11668. *
  11669. * _.assign({ 'a': 1 }, new Foo);
  11670. * // => { 'a': 1, 'b': 2 }
  11671. *
  11672. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11673. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11674. */
  11675. function toPlainObject(value) {
  11676. return copyObject(value, keysIn(value));
  11677. }
  11678. /**
  11679. * Converts `value` to a safe integer. A safe integer can be compared and
  11680. * represented correctly.
  11681. *
  11682. * @static
  11683. * @memberOf _
  11684. * @since 4.0.0
  11685. * @category Lang
  11686. * @param {*} value The value to convert.
  11687. * @returns {number} Returns the converted integer.
  11688. * @example
  11689. *
  11690. * _.toSafeInteger(3.2);
  11691. * // => 3
  11692. *
  11693. * _.toSafeInteger(Number.MIN_VALUE);
  11694. * // => 0
  11695. *
  11696. * _.toSafeInteger(Infinity);
  11697. * // => 9007199254740991
  11698. *
  11699. * _.toSafeInteger('3.2');
  11700. * // => 3
  11701. */
  11702. function toSafeInteger(value) {
  11703. return value
  11704. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11705. : (value === 0 ? value : 0);
  11706. }
  11707. /**
  11708. * Converts `value` to a string. An empty string is returned for `null`
  11709. * and `undefined` values. The sign of `-0` is preserved.
  11710. *
  11711. * @static
  11712. * @memberOf _
  11713. * @since 4.0.0
  11714. * @category Lang
  11715. * @param {*} value The value to convert.
  11716. * @returns {string} Returns the converted string.
  11717. * @example
  11718. *
  11719. * _.toString(null);
  11720. * // => ''
  11721. *
  11722. * _.toString(-0);
  11723. * // => '-0'
  11724. *
  11725. * _.toString([1, 2, 3]);
  11726. * // => '1,2,3'
  11727. */
  11728. function toString(value) {
  11729. return value == null ? '' : baseToString(value);
  11730. }
  11731. /*------------------------------------------------------------------------*/
  11732. /**
  11733. * Assigns own enumerable string keyed properties of source objects to the
  11734. * destination object. Source objects are applied from left to right.
  11735. * Subsequent sources overwrite property assignments of previous sources.
  11736. *
  11737. * **Note:** This method mutates `object` and is loosely based on
  11738. * [`Object.assign`](https://mdn.io/Object/assign).
  11739. *
  11740. * @static
  11741. * @memberOf _
  11742. * @since 0.10.0
  11743. * @category Object
  11744. * @param {Object} object The destination object.
  11745. * @param {...Object} [sources] The source objects.
  11746. * @returns {Object} Returns `object`.
  11747. * @see _.assignIn
  11748. * @example
  11749. *
  11750. * function Foo() {
  11751. * this.a = 1;
  11752. * }
  11753. *
  11754. * function Bar() {
  11755. * this.c = 3;
  11756. * }
  11757. *
  11758. * Foo.prototype.b = 2;
  11759. * Bar.prototype.d = 4;
  11760. *
  11761. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11762. * // => { 'a': 1, 'c': 3 }
  11763. */
  11764. var assign = createAssigner(function(object, source) {
  11765. if (isPrototype(source) || isArrayLike(source)) {
  11766. copyObject(source, keys(source), object);
  11767. return;
  11768. }
  11769. for (var key in source) {
  11770. if (hasOwnProperty.call(source, key)) {
  11771. assignValue(object, key, source[key]);
  11772. }
  11773. }
  11774. });
  11775. /**
  11776. * This method is like `_.assign` except that it iterates over own and
  11777. * inherited source properties.
  11778. *
  11779. * **Note:** This method mutates `object`.
  11780. *
  11781. * @static
  11782. * @memberOf _
  11783. * @since 4.0.0
  11784. * @alias extend
  11785. * @category Object
  11786. * @param {Object} object The destination object.
  11787. * @param {...Object} [sources] The source objects.
  11788. * @returns {Object} Returns `object`.
  11789. * @see _.assign
  11790. * @example
  11791. *
  11792. * function Foo() {
  11793. * this.a = 1;
  11794. * }
  11795. *
  11796. * function Bar() {
  11797. * this.c = 3;
  11798. * }
  11799. *
  11800. * Foo.prototype.b = 2;
  11801. * Bar.prototype.d = 4;
  11802. *
  11803. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11804. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11805. */
  11806. var assignIn = createAssigner(function(object, source) {
  11807. copyObject(source, keysIn(source), object);
  11808. });
  11809. /**
  11810. * This method is like `_.assignIn` except that it accepts `customizer`
  11811. * which is invoked to produce the assigned values. If `customizer` returns
  11812. * `undefined`, assignment is handled by the method instead. The `customizer`
  11813. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11814. *
  11815. * **Note:** This method mutates `object`.
  11816. *
  11817. * @static
  11818. * @memberOf _
  11819. * @since 4.0.0
  11820. * @alias extendWith
  11821. * @category Object
  11822. * @param {Object} object The destination object.
  11823. * @param {...Object} sources The source objects.
  11824. * @param {Function} [customizer] The function to customize assigned values.
  11825. * @returns {Object} Returns `object`.
  11826. * @see _.assignWith
  11827. * @example
  11828. *
  11829. * function customizer(objValue, srcValue) {
  11830. * return _.isUndefined(objValue) ? srcValue : objValue;
  11831. * }
  11832. *
  11833. * var defaults = _.partialRight(_.assignInWith, customizer);
  11834. *
  11835. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11836. * // => { 'a': 1, 'b': 2 }
  11837. */
  11838. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11839. copyObject(source, keysIn(source), object, customizer);
  11840. });
  11841. /**
  11842. * This method is like `_.assign` 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. * @category Object
  11853. * @param {Object} object The destination object.
  11854. * @param {...Object} sources The source objects.
  11855. * @param {Function} [customizer] The function to customize assigned values.
  11856. * @returns {Object} Returns `object`.
  11857. * @see _.assignInWith
  11858. * @example
  11859. *
  11860. * function customizer(objValue, srcValue) {
  11861. * return _.isUndefined(objValue) ? srcValue : objValue;
  11862. * }
  11863. *
  11864. * var defaults = _.partialRight(_.assignWith, customizer);
  11865. *
  11866. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11867. * // => { 'a': 1, 'b': 2 }
  11868. */
  11869. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11870. copyObject(source, keys(source), object, customizer);
  11871. });
  11872. /**
  11873. * Creates an array of values corresponding to `paths` of `object`.
  11874. *
  11875. * @static
  11876. * @memberOf _
  11877. * @since 1.0.0
  11878. * @category Object
  11879. * @param {Object} object The object to iterate over.
  11880. * @param {...(string|string[])} [paths] The property paths to pick.
  11881. * @returns {Array} Returns the picked values.
  11882. * @example
  11883. *
  11884. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11885. *
  11886. * _.at(object, ['a[0].b.c', 'a[1]']);
  11887. * // => [3, 4]
  11888. */
  11889. var at = flatRest(baseAt);
  11890. /**
  11891. * Creates an object that inherits from the `prototype` object. If a
  11892. * `properties` object is given, its own enumerable string keyed properties
  11893. * are assigned to the created object.
  11894. *
  11895. * @static
  11896. * @memberOf _
  11897. * @since 2.3.0
  11898. * @category Object
  11899. * @param {Object} prototype The object to inherit from.
  11900. * @param {Object} [properties] The properties to assign to the object.
  11901. * @returns {Object} Returns the new object.
  11902. * @example
  11903. *
  11904. * function Shape() {
  11905. * this.x = 0;
  11906. * this.y = 0;
  11907. * }
  11908. *
  11909. * function Circle() {
  11910. * Shape.call(this);
  11911. * }
  11912. *
  11913. * Circle.prototype = _.create(Shape.prototype, {
  11914. * 'constructor': Circle
  11915. * });
  11916. *
  11917. * var circle = new Circle;
  11918. * circle instanceof Circle;
  11919. * // => true
  11920. *
  11921. * circle instanceof Shape;
  11922. * // => true
  11923. */
  11924. function create(prototype, properties) {
  11925. var result = baseCreate(prototype);
  11926. return properties == null ? result : baseAssign(result, properties);
  11927. }
  11928. /**
  11929. * Assigns own and inherited enumerable string keyed properties of source
  11930. * objects to the destination object for all destination properties that
  11931. * resolve to `undefined`. Source objects are applied from left to right.
  11932. * Once a property is set, additional values of the same property are ignored.
  11933. *
  11934. * **Note:** This method mutates `object`.
  11935. *
  11936. * @static
  11937. * @since 0.1.0
  11938. * @memberOf _
  11939. * @category Object
  11940. * @param {Object} object The destination object.
  11941. * @param {...Object} [sources] The source objects.
  11942. * @returns {Object} Returns `object`.
  11943. * @see _.defaultsDeep
  11944. * @example
  11945. *
  11946. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11947. * // => { 'a': 1, 'b': 2 }
  11948. */
  11949. var defaults = baseRest(function(object, sources) {
  11950. object = Object(object);
  11951. var index = -1;
  11952. var length = sources.length;
  11953. var guard = length > 2 ? sources[2] : undefined;
  11954. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  11955. length = 1;
  11956. }
  11957. while (++index < length) {
  11958. var source = sources[index];
  11959. var props = keysIn(source);
  11960. var propsIndex = -1;
  11961. var propsLength = props.length;
  11962. while (++propsIndex < propsLength) {
  11963. var key = props[propsIndex];
  11964. var value = object[key];
  11965. if (value === undefined ||
  11966. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  11967. object[key] = source[key];
  11968. }
  11969. }
  11970. }
  11971. return object;
  11972. });
  11973. /**
  11974. * This method is like `_.defaults` except that it recursively assigns
  11975. * default properties.
  11976. *
  11977. * **Note:** This method mutates `object`.
  11978. *
  11979. * @static
  11980. * @memberOf _
  11981. * @since 3.10.0
  11982. * @category Object
  11983. * @param {Object} object The destination object.
  11984. * @param {...Object} [sources] The source objects.
  11985. * @returns {Object} Returns `object`.
  11986. * @see _.defaults
  11987. * @example
  11988. *
  11989. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11990. * // => { 'a': { 'b': 2, 'c': 3 } }
  11991. */
  11992. var defaultsDeep = baseRest(function(args) {
  11993. args.push(undefined, customDefaultsMerge);
  11994. return apply(mergeWith, undefined, args);
  11995. });
  11996. /**
  11997. * This method is like `_.find` except that it returns the key of the first
  11998. * element `predicate` returns truthy for instead of the element itself.
  11999. *
  12000. * @static
  12001. * @memberOf _
  12002. * @since 1.1.0
  12003. * @category Object
  12004. * @param {Object} object The object to inspect.
  12005. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12006. * @returns {string|undefined} Returns the key of the matched element,
  12007. * else `undefined`.
  12008. * @example
  12009. *
  12010. * var users = {
  12011. * 'barney': { 'age': 36, 'active': true },
  12012. * 'fred': { 'age': 40, 'active': false },
  12013. * 'pebbles': { 'age': 1, 'active': true }
  12014. * };
  12015. *
  12016. * _.findKey(users, function(o) { return o.age < 40; });
  12017. * // => 'barney' (iteration order is not guaranteed)
  12018. *
  12019. * // The `_.matches` iteratee shorthand.
  12020. * _.findKey(users, { 'age': 1, 'active': true });
  12021. * // => 'pebbles'
  12022. *
  12023. * // The `_.matchesProperty` iteratee shorthand.
  12024. * _.findKey(users, ['active', false]);
  12025. * // => 'fred'
  12026. *
  12027. * // The `_.property` iteratee shorthand.
  12028. * _.findKey(users, 'active');
  12029. * // => 'barney'
  12030. */
  12031. function findKey(object, predicate) {
  12032. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12033. }
  12034. /**
  12035. * This method is like `_.findKey` except that it iterates over elements of
  12036. * a collection in the opposite order.
  12037. *
  12038. * @static
  12039. * @memberOf _
  12040. * @since 2.0.0
  12041. * @category Object
  12042. * @param {Object} object The object to inspect.
  12043. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12044. * @returns {string|undefined} Returns the key of the matched element,
  12045. * else `undefined`.
  12046. * @example
  12047. *
  12048. * var users = {
  12049. * 'barney': { 'age': 36, 'active': true },
  12050. * 'fred': { 'age': 40, 'active': false },
  12051. * 'pebbles': { 'age': 1, 'active': true }
  12052. * };
  12053. *
  12054. * _.findLastKey(users, function(o) { return o.age < 40; });
  12055. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12056. *
  12057. * // The `_.matches` iteratee shorthand.
  12058. * _.findLastKey(users, { 'age': 36, 'active': true });
  12059. * // => 'barney'
  12060. *
  12061. * // The `_.matchesProperty` iteratee shorthand.
  12062. * _.findLastKey(users, ['active', false]);
  12063. * // => 'fred'
  12064. *
  12065. * // The `_.property` iteratee shorthand.
  12066. * _.findLastKey(users, 'active');
  12067. * // => 'pebbles'
  12068. */
  12069. function findLastKey(object, predicate) {
  12070. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12071. }
  12072. /**
  12073. * Iterates over own and inherited enumerable string keyed properties of an
  12074. * object and invokes `iteratee` for each property. The iteratee is invoked
  12075. * with three arguments: (value, key, object). Iteratee functions may exit
  12076. * iteration early by explicitly returning `false`.
  12077. *
  12078. * @static
  12079. * @memberOf _
  12080. * @since 0.3.0
  12081. * @category Object
  12082. * @param {Object} object The object to iterate over.
  12083. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12084. * @returns {Object} Returns `object`.
  12085. * @see _.forInRight
  12086. * @example
  12087. *
  12088. * function Foo() {
  12089. * this.a = 1;
  12090. * this.b = 2;
  12091. * }
  12092. *
  12093. * Foo.prototype.c = 3;
  12094. *
  12095. * _.forIn(new Foo, function(value, key) {
  12096. * console.log(key);
  12097. * });
  12098. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12099. */
  12100. function forIn(object, iteratee) {
  12101. return object == null
  12102. ? object
  12103. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12104. }
  12105. /**
  12106. * This method is like `_.forIn` except that it iterates over properties of
  12107. * `object` in the opposite order.
  12108. *
  12109. * @static
  12110. * @memberOf _
  12111. * @since 2.0.0
  12112. * @category Object
  12113. * @param {Object} object The object to iterate over.
  12114. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12115. * @returns {Object} Returns `object`.
  12116. * @see _.forIn
  12117. * @example
  12118. *
  12119. * function Foo() {
  12120. * this.a = 1;
  12121. * this.b = 2;
  12122. * }
  12123. *
  12124. * Foo.prototype.c = 3;
  12125. *
  12126. * _.forInRight(new Foo, function(value, key) {
  12127. * console.log(key);
  12128. * });
  12129. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12130. */
  12131. function forInRight(object, iteratee) {
  12132. return object == null
  12133. ? object
  12134. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12135. }
  12136. /**
  12137. * Iterates over own enumerable string keyed properties of an object and
  12138. * invokes `iteratee` for each property. The iteratee is invoked with three
  12139. * arguments: (value, key, object). Iteratee functions may exit iteration
  12140. * early by explicitly returning `false`.
  12141. *
  12142. * @static
  12143. * @memberOf _
  12144. * @since 0.3.0
  12145. * @category Object
  12146. * @param {Object} object The object to iterate over.
  12147. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12148. * @returns {Object} Returns `object`.
  12149. * @see _.forOwnRight
  12150. * @example
  12151. *
  12152. * function Foo() {
  12153. * this.a = 1;
  12154. * this.b = 2;
  12155. * }
  12156. *
  12157. * Foo.prototype.c = 3;
  12158. *
  12159. * _.forOwn(new Foo, function(value, key) {
  12160. * console.log(key);
  12161. * });
  12162. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12163. */
  12164. function forOwn(object, iteratee) {
  12165. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12166. }
  12167. /**
  12168. * This method is like `_.forOwn` except that it iterates over properties of
  12169. * `object` in the opposite order.
  12170. *
  12171. * @static
  12172. * @memberOf _
  12173. * @since 2.0.0
  12174. * @category Object
  12175. * @param {Object} object The object to iterate over.
  12176. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12177. * @returns {Object} Returns `object`.
  12178. * @see _.forOwn
  12179. * @example
  12180. *
  12181. * function Foo() {
  12182. * this.a = 1;
  12183. * this.b = 2;
  12184. * }
  12185. *
  12186. * Foo.prototype.c = 3;
  12187. *
  12188. * _.forOwnRight(new Foo, function(value, key) {
  12189. * console.log(key);
  12190. * });
  12191. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12192. */
  12193. function forOwnRight(object, iteratee) {
  12194. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12195. }
  12196. /**
  12197. * Creates an array of function property names from own enumerable properties
  12198. * of `object`.
  12199. *
  12200. * @static
  12201. * @since 0.1.0
  12202. * @memberOf _
  12203. * @category Object
  12204. * @param {Object} object The object to inspect.
  12205. * @returns {Array} Returns the function names.
  12206. * @see _.functionsIn
  12207. * @example
  12208. *
  12209. * function Foo() {
  12210. * this.a = _.constant('a');
  12211. * this.b = _.constant('b');
  12212. * }
  12213. *
  12214. * Foo.prototype.c = _.constant('c');
  12215. *
  12216. * _.functions(new Foo);
  12217. * // => ['a', 'b']
  12218. */
  12219. function functions(object) {
  12220. return object == null ? [] : baseFunctions(object, keys(object));
  12221. }
  12222. /**
  12223. * Creates an array of function property names from own and inherited
  12224. * enumerable properties of `object`.
  12225. *
  12226. * @static
  12227. * @memberOf _
  12228. * @since 4.0.0
  12229. * @category Object
  12230. * @param {Object} object The object to inspect.
  12231. * @returns {Array} Returns the function names.
  12232. * @see _.functions
  12233. * @example
  12234. *
  12235. * function Foo() {
  12236. * this.a = _.constant('a');
  12237. * this.b = _.constant('b');
  12238. * }
  12239. *
  12240. * Foo.prototype.c = _.constant('c');
  12241. *
  12242. * _.functionsIn(new Foo);
  12243. * // => ['a', 'b', 'c']
  12244. */
  12245. function functionsIn(object) {
  12246. return object == null ? [] : baseFunctions(object, keysIn(object));
  12247. }
  12248. /**
  12249. * Gets the value at `path` of `object`. If the resolved value is
  12250. * `undefined`, the `defaultValue` is returned in its place.
  12251. *
  12252. * @static
  12253. * @memberOf _
  12254. * @since 3.7.0
  12255. * @category Object
  12256. * @param {Object} object The object to query.
  12257. * @param {Array|string} path The path of the property to get.
  12258. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12259. * @returns {*} Returns the resolved value.
  12260. * @example
  12261. *
  12262. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12263. *
  12264. * _.get(object, 'a[0].b.c');
  12265. * // => 3
  12266. *
  12267. * _.get(object, ['a', '0', 'b', 'c']);
  12268. * // => 3
  12269. *
  12270. * _.get(object, 'a.b.c', 'default');
  12271. * // => 'default'
  12272. */
  12273. function get(object, path, defaultValue) {
  12274. var result = object == null ? undefined : baseGet(object, path);
  12275. return result === undefined ? defaultValue : result;
  12276. }
  12277. /**
  12278. * Checks if `path` is a direct property of `object`.
  12279. *
  12280. * @static
  12281. * @since 0.1.0
  12282. * @memberOf _
  12283. * @category Object
  12284. * @param {Object} object The object to query.
  12285. * @param {Array|string} path The path to check.
  12286. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12287. * @example
  12288. *
  12289. * var object = { 'a': { 'b': 2 } };
  12290. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12291. *
  12292. * _.has(object, 'a');
  12293. * // => true
  12294. *
  12295. * _.has(object, 'a.b');
  12296. * // => true
  12297. *
  12298. * _.has(object, ['a', 'b']);
  12299. * // => true
  12300. *
  12301. * _.has(other, 'a');
  12302. * // => false
  12303. */
  12304. function has(object, path) {
  12305. return object != null && hasPath(object, path, baseHas);
  12306. }
  12307. /**
  12308. * Checks if `path` is a direct or inherited property of `object`.
  12309. *
  12310. * @static
  12311. * @memberOf _
  12312. * @since 4.0.0
  12313. * @category Object
  12314. * @param {Object} object The object to query.
  12315. * @param {Array|string} path The path to check.
  12316. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12317. * @example
  12318. *
  12319. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12320. *
  12321. * _.hasIn(object, 'a');
  12322. * // => true
  12323. *
  12324. * _.hasIn(object, 'a.b');
  12325. * // => true
  12326. *
  12327. * _.hasIn(object, ['a', 'b']);
  12328. * // => true
  12329. *
  12330. * _.hasIn(object, 'b');
  12331. * // => false
  12332. */
  12333. function hasIn(object, path) {
  12334. return object != null && hasPath(object, path, baseHasIn);
  12335. }
  12336. /**
  12337. * Creates an object composed of the inverted keys and values of `object`.
  12338. * If `object` contains duplicate values, subsequent values overwrite
  12339. * property assignments of previous values.
  12340. *
  12341. * @static
  12342. * @memberOf _
  12343. * @since 0.7.0
  12344. * @category Object
  12345. * @param {Object} object The object to invert.
  12346. * @returns {Object} Returns the new inverted object.
  12347. * @example
  12348. *
  12349. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12350. *
  12351. * _.invert(object);
  12352. * // => { '1': 'c', '2': 'b' }
  12353. */
  12354. var invert = createInverter(function(result, value, key) {
  12355. if (value != null &&
  12356. typeof value.toString != 'function') {
  12357. value = nativeObjectToString.call(value);
  12358. }
  12359. result[value] = key;
  12360. }, constant(identity));
  12361. /**
  12362. * This method is like `_.invert` except that the inverted object is generated
  12363. * from the results of running each element of `object` thru `iteratee`. The
  12364. * corresponding inverted value of each inverted key is an array of keys
  12365. * responsible for generating the inverted value. The iteratee is invoked
  12366. * with one argument: (value).
  12367. *
  12368. * @static
  12369. * @memberOf _
  12370. * @since 4.1.0
  12371. * @category Object
  12372. * @param {Object} object The object to invert.
  12373. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12374. * @returns {Object} Returns the new inverted object.
  12375. * @example
  12376. *
  12377. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12378. *
  12379. * _.invertBy(object);
  12380. * // => { '1': ['a', 'c'], '2': ['b'] }
  12381. *
  12382. * _.invertBy(object, function(value) {
  12383. * return 'group' + value;
  12384. * });
  12385. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12386. */
  12387. var invertBy = createInverter(function(result, value, key) {
  12388. if (value != null &&
  12389. typeof value.toString != 'function') {
  12390. value = nativeObjectToString.call(value);
  12391. }
  12392. if (hasOwnProperty.call(result, value)) {
  12393. result[value].push(key);
  12394. } else {
  12395. result[value] = [key];
  12396. }
  12397. }, getIteratee);
  12398. /**
  12399. * Invokes the method at `path` of `object`.
  12400. *
  12401. * @static
  12402. * @memberOf _
  12403. * @since 4.0.0
  12404. * @category Object
  12405. * @param {Object} object The object to query.
  12406. * @param {Array|string} path The path of the method to invoke.
  12407. * @param {...*} [args] The arguments to invoke the method with.
  12408. * @returns {*} Returns the result of the invoked method.
  12409. * @example
  12410. *
  12411. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12412. *
  12413. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12414. * // => [2, 3]
  12415. */
  12416. var invoke = baseRest(baseInvoke);
  12417. /**
  12418. * Creates an array of the own enumerable property names of `object`.
  12419. *
  12420. * **Note:** Non-object values are coerced to objects. See the
  12421. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12422. * for more details.
  12423. *
  12424. * @static
  12425. * @since 0.1.0
  12426. * @memberOf _
  12427. * @category Object
  12428. * @param {Object} object The object to query.
  12429. * @returns {Array} Returns the array of property names.
  12430. * @example
  12431. *
  12432. * function Foo() {
  12433. * this.a = 1;
  12434. * this.b = 2;
  12435. * }
  12436. *
  12437. * Foo.prototype.c = 3;
  12438. *
  12439. * _.keys(new Foo);
  12440. * // => ['a', 'b'] (iteration order is not guaranteed)
  12441. *
  12442. * _.keys('hi');
  12443. * // => ['0', '1']
  12444. */
  12445. function keys(object) {
  12446. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12447. }
  12448. /**
  12449. * Creates an array of the own and inherited enumerable property names of `object`.
  12450. *
  12451. * **Note:** Non-object values are coerced to objects.
  12452. *
  12453. * @static
  12454. * @memberOf _
  12455. * @since 3.0.0
  12456. * @category Object
  12457. * @param {Object} object The object to query.
  12458. * @returns {Array} Returns the array of property names.
  12459. * @example
  12460. *
  12461. * function Foo() {
  12462. * this.a = 1;
  12463. * this.b = 2;
  12464. * }
  12465. *
  12466. * Foo.prototype.c = 3;
  12467. *
  12468. * _.keysIn(new Foo);
  12469. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12470. */
  12471. function keysIn(object) {
  12472. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12473. }
  12474. /**
  12475. * The opposite of `_.mapValues`; this method creates an object with the
  12476. * same values as `object` and keys generated by running each own enumerable
  12477. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12478. * with three arguments: (value, key, object).
  12479. *
  12480. * @static
  12481. * @memberOf _
  12482. * @since 3.8.0
  12483. * @category Object
  12484. * @param {Object} object The object to iterate over.
  12485. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12486. * @returns {Object} Returns the new mapped object.
  12487. * @see _.mapValues
  12488. * @example
  12489. *
  12490. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12491. * return key + value;
  12492. * });
  12493. * // => { 'a1': 1, 'b2': 2 }
  12494. */
  12495. function mapKeys(object, iteratee) {
  12496. var result = {};
  12497. iteratee = getIteratee(iteratee, 3);
  12498. baseForOwn(object, function(value, key, object) {
  12499. baseAssignValue(result, iteratee(value, key, object), value);
  12500. });
  12501. return result;
  12502. }
  12503. /**
  12504. * Creates an object with the same keys as `object` and values generated
  12505. * by running each own enumerable string keyed property of `object` thru
  12506. * `iteratee`. The iteratee is invoked with three arguments:
  12507. * (value, key, object).
  12508. *
  12509. * @static
  12510. * @memberOf _
  12511. * @since 2.4.0
  12512. * @category Object
  12513. * @param {Object} object The object to iterate over.
  12514. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12515. * @returns {Object} Returns the new mapped object.
  12516. * @see _.mapKeys
  12517. * @example
  12518. *
  12519. * var users = {
  12520. * 'fred': { 'user': 'fred', 'age': 40 },
  12521. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12522. * };
  12523. *
  12524. * _.mapValues(users, function(o) { return o.age; });
  12525. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12526. *
  12527. * // The `_.property` iteratee shorthand.
  12528. * _.mapValues(users, 'age');
  12529. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12530. */
  12531. function mapValues(object, iteratee) {
  12532. var result = {};
  12533. iteratee = getIteratee(iteratee, 3);
  12534. baseForOwn(object, function(value, key, object) {
  12535. baseAssignValue(result, key, iteratee(value, key, object));
  12536. });
  12537. return result;
  12538. }
  12539. /**
  12540. * This method is like `_.assign` except that it recursively merges own and
  12541. * inherited enumerable string keyed properties of source objects into the
  12542. * destination object. Source properties that resolve to `undefined` are
  12543. * skipped if a destination value exists. Array and plain object properties
  12544. * are merged recursively. Other objects and value types are overridden by
  12545. * assignment. Source objects are applied from left to right. Subsequent
  12546. * sources overwrite property assignments of previous sources.
  12547. *
  12548. * **Note:** This method mutates `object`.
  12549. *
  12550. * @static
  12551. * @memberOf _
  12552. * @since 0.5.0
  12553. * @category Object
  12554. * @param {Object} object The destination object.
  12555. * @param {...Object} [sources] The source objects.
  12556. * @returns {Object} Returns `object`.
  12557. * @example
  12558. *
  12559. * var object = {
  12560. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12561. * };
  12562. *
  12563. * var other = {
  12564. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12565. * };
  12566. *
  12567. * _.merge(object, other);
  12568. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12569. */
  12570. var merge = createAssigner(function(object, source, srcIndex) {
  12571. baseMerge(object, source, srcIndex);
  12572. });
  12573. /**
  12574. * This method is like `_.merge` except that it accepts `customizer` which
  12575. * is invoked to produce the merged values of the destination and source
  12576. * properties. If `customizer` returns `undefined`, merging is handled by the
  12577. * method instead. The `customizer` is invoked with six arguments:
  12578. * (objValue, srcValue, key, object, source, stack).
  12579. *
  12580. * **Note:** This method mutates `object`.
  12581. *
  12582. * @static
  12583. * @memberOf _
  12584. * @since 4.0.0
  12585. * @category Object
  12586. * @param {Object} object The destination object.
  12587. * @param {...Object} sources The source objects.
  12588. * @param {Function} customizer The function to customize assigned values.
  12589. * @returns {Object} Returns `object`.
  12590. * @example
  12591. *
  12592. * function customizer(objValue, srcValue) {
  12593. * if (_.isArray(objValue)) {
  12594. * return objValue.concat(srcValue);
  12595. * }
  12596. * }
  12597. *
  12598. * var object = { 'a': [1], 'b': [2] };
  12599. * var other = { 'a': [3], 'b': [4] };
  12600. *
  12601. * _.mergeWith(object, other, customizer);
  12602. * // => { 'a': [1, 3], 'b': [2, 4] }
  12603. */
  12604. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12605. baseMerge(object, source, srcIndex, customizer);
  12606. });
  12607. /**
  12608. * The opposite of `_.pick`; this method creates an object composed of the
  12609. * own and inherited enumerable property paths of `object` that are not omitted.
  12610. *
  12611. * **Note:** This method is considerably slower than `_.pick`.
  12612. *
  12613. * @static
  12614. * @since 0.1.0
  12615. * @memberOf _
  12616. * @category Object
  12617. * @param {Object} object The source object.
  12618. * @param {...(string|string[])} [paths] The property paths to omit.
  12619. * @returns {Object} Returns the new object.
  12620. * @example
  12621. *
  12622. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12623. *
  12624. * _.omit(object, ['a', 'c']);
  12625. * // => { 'b': '2' }
  12626. */
  12627. var omit = flatRest(function(object, paths) {
  12628. var result = {};
  12629. if (object == null) {
  12630. return result;
  12631. }
  12632. var isDeep = false;
  12633. paths = arrayMap(paths, function(path) {
  12634. path = castPath(path, object);
  12635. isDeep || (isDeep = path.length > 1);
  12636. return path;
  12637. });
  12638. copyObject(object, getAllKeysIn(object), result);
  12639. if (isDeep) {
  12640. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12641. }
  12642. var length = paths.length;
  12643. while (length--) {
  12644. baseUnset(result, paths[length]);
  12645. }
  12646. return result;
  12647. });
  12648. /**
  12649. * The opposite of `_.pickBy`; this method creates an object composed of
  12650. * the own and inherited enumerable string keyed properties of `object` that
  12651. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12652. * arguments: (value, key).
  12653. *
  12654. * @static
  12655. * @memberOf _
  12656. * @since 4.0.0
  12657. * @category Object
  12658. * @param {Object} object The source object.
  12659. * @param {Function} [predicate=_.identity] The function invoked per property.
  12660. * @returns {Object} Returns the new object.
  12661. * @example
  12662. *
  12663. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12664. *
  12665. * _.omitBy(object, _.isNumber);
  12666. * // => { 'b': '2' }
  12667. */
  12668. function omitBy(object, predicate) {
  12669. return pickBy(object, negate(getIteratee(predicate)));
  12670. }
  12671. /**
  12672. * Creates an object composed of the picked `object` properties.
  12673. *
  12674. * @static
  12675. * @since 0.1.0
  12676. * @memberOf _
  12677. * @category Object
  12678. * @param {Object} object The source object.
  12679. * @param {...(string|string[])} [paths] The property paths to pick.
  12680. * @returns {Object} Returns the new object.
  12681. * @example
  12682. *
  12683. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12684. *
  12685. * _.pick(object, ['a', 'c']);
  12686. * // => { 'a': 1, 'c': 3 }
  12687. */
  12688. var pick = flatRest(function(object, paths) {
  12689. return object == null ? {} : basePick(object, paths);
  12690. });
  12691. /**
  12692. * Creates an object composed of the `object` properties `predicate` returns
  12693. * truthy for. The predicate is invoked with two arguments: (value, key).
  12694. *
  12695. * @static
  12696. * @memberOf _
  12697. * @since 4.0.0
  12698. * @category Object
  12699. * @param {Object} object The source object.
  12700. * @param {Function} [predicate=_.identity] The function invoked per property.
  12701. * @returns {Object} Returns the new object.
  12702. * @example
  12703. *
  12704. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12705. *
  12706. * _.pickBy(object, _.isNumber);
  12707. * // => { 'a': 1, 'c': 3 }
  12708. */
  12709. function pickBy(object, predicate) {
  12710. if (object == null) {
  12711. return {};
  12712. }
  12713. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12714. return [prop];
  12715. });
  12716. predicate = getIteratee(predicate);
  12717. return basePickBy(object, props, function(value, path) {
  12718. return predicate(value, path[0]);
  12719. });
  12720. }
  12721. /**
  12722. * This method is like `_.get` except that if the resolved value is a
  12723. * function it's invoked with the `this` binding of its parent object and
  12724. * its result is returned.
  12725. *
  12726. * @static
  12727. * @since 0.1.0
  12728. * @memberOf _
  12729. * @category Object
  12730. * @param {Object} object The object to query.
  12731. * @param {Array|string} path The path of the property to resolve.
  12732. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12733. * @returns {*} Returns the resolved value.
  12734. * @example
  12735. *
  12736. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12737. *
  12738. * _.result(object, 'a[0].b.c1');
  12739. * // => 3
  12740. *
  12741. * _.result(object, 'a[0].b.c2');
  12742. * // => 4
  12743. *
  12744. * _.result(object, 'a[0].b.c3', 'default');
  12745. * // => 'default'
  12746. *
  12747. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12748. * // => 'default'
  12749. */
  12750. function result(object, path, defaultValue) {
  12751. path = castPath(path, object);
  12752. var index = -1,
  12753. length = path.length;
  12754. // Ensure the loop is entered when path is empty.
  12755. if (!length) {
  12756. length = 1;
  12757. object = undefined;
  12758. }
  12759. while (++index < length) {
  12760. var value = object == null ? undefined : object[toKey(path[index])];
  12761. if (value === undefined) {
  12762. index = length;
  12763. value = defaultValue;
  12764. }
  12765. object = isFunction(value) ? value.call(object) : value;
  12766. }
  12767. return object;
  12768. }
  12769. /**
  12770. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12771. * it's created. Arrays are created for missing index properties while objects
  12772. * are created for all other missing properties. Use `_.setWith` to customize
  12773. * `path` creation.
  12774. *
  12775. * **Note:** This method mutates `object`.
  12776. *
  12777. * @static
  12778. * @memberOf _
  12779. * @since 3.7.0
  12780. * @category Object
  12781. * @param {Object} object The object to modify.
  12782. * @param {Array|string} path The path of the property to set.
  12783. * @param {*} value The value to set.
  12784. * @returns {Object} Returns `object`.
  12785. * @example
  12786. *
  12787. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12788. *
  12789. * _.set(object, 'a[0].b.c', 4);
  12790. * console.log(object.a[0].b.c);
  12791. * // => 4
  12792. *
  12793. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12794. * console.log(object.x[0].y.z);
  12795. * // => 5
  12796. */
  12797. function set(object, path, value) {
  12798. return object == null ? object : baseSet(object, path, value);
  12799. }
  12800. /**
  12801. * This method is like `_.set` except that it accepts `customizer` which is
  12802. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12803. * path creation is handled by the method instead. The `customizer` is invoked
  12804. * with three arguments: (nsValue, key, nsObject).
  12805. *
  12806. * **Note:** This method mutates `object`.
  12807. *
  12808. * @static
  12809. * @memberOf _
  12810. * @since 4.0.0
  12811. * @category Object
  12812. * @param {Object} object The object to modify.
  12813. * @param {Array|string} path The path of the property to set.
  12814. * @param {*} value The value to set.
  12815. * @param {Function} [customizer] The function to customize assigned values.
  12816. * @returns {Object} Returns `object`.
  12817. * @example
  12818. *
  12819. * var object = {};
  12820. *
  12821. * _.setWith(object, '[0][1]', 'a', Object);
  12822. * // => { '0': { '1': 'a' } }
  12823. */
  12824. function setWith(object, path, value, customizer) {
  12825. customizer = typeof customizer == 'function' ? customizer : undefined;
  12826. return object == null ? object : baseSet(object, path, value, customizer);
  12827. }
  12828. /**
  12829. * Creates an array of own enumerable string keyed-value pairs for `object`
  12830. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12831. * entries are returned.
  12832. *
  12833. * @static
  12834. * @memberOf _
  12835. * @since 4.0.0
  12836. * @alias entries
  12837. * @category Object
  12838. * @param {Object} object The object to query.
  12839. * @returns {Array} Returns the key-value pairs.
  12840. * @example
  12841. *
  12842. * function Foo() {
  12843. * this.a = 1;
  12844. * this.b = 2;
  12845. * }
  12846. *
  12847. * Foo.prototype.c = 3;
  12848. *
  12849. * _.toPairs(new Foo);
  12850. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12851. */
  12852. var toPairs = createToPairs(keys);
  12853. /**
  12854. * Creates an array of own and inherited enumerable string keyed-value pairs
  12855. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12856. * or set, its entries are returned.
  12857. *
  12858. * @static
  12859. * @memberOf _
  12860. * @since 4.0.0
  12861. * @alias entriesIn
  12862. * @category Object
  12863. * @param {Object} object The object to query.
  12864. * @returns {Array} Returns the key-value pairs.
  12865. * @example
  12866. *
  12867. * function Foo() {
  12868. * this.a = 1;
  12869. * this.b = 2;
  12870. * }
  12871. *
  12872. * Foo.prototype.c = 3;
  12873. *
  12874. * _.toPairsIn(new Foo);
  12875. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12876. */
  12877. var toPairsIn = createToPairs(keysIn);
  12878. /**
  12879. * An alternative to `_.reduce`; this method transforms `object` to a new
  12880. * `accumulator` object which is the result of running each of its own
  12881. * enumerable string keyed properties thru `iteratee`, with each invocation
  12882. * potentially mutating the `accumulator` object. If `accumulator` is not
  12883. * provided, a new object with the same `[[Prototype]]` will be used. The
  12884. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12885. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12886. *
  12887. * @static
  12888. * @memberOf _
  12889. * @since 1.3.0
  12890. * @category Object
  12891. * @param {Object} object The object to iterate over.
  12892. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12893. * @param {*} [accumulator] The custom accumulator value.
  12894. * @returns {*} Returns the accumulated value.
  12895. * @example
  12896. *
  12897. * _.transform([2, 3, 4], function(result, n) {
  12898. * result.push(n *= n);
  12899. * return n % 2 == 0;
  12900. * }, []);
  12901. * // => [4, 9]
  12902. *
  12903. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12904. * (result[value] || (result[value] = [])).push(key);
  12905. * }, {});
  12906. * // => { '1': ['a', 'c'], '2': ['b'] }
  12907. */
  12908. function transform(object, iteratee, accumulator) {
  12909. var isArr = isArray(object),
  12910. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12911. iteratee = getIteratee(iteratee, 4);
  12912. if (accumulator == null) {
  12913. var Ctor = object && object.constructor;
  12914. if (isArrLike) {
  12915. accumulator = isArr ? new Ctor : [];
  12916. }
  12917. else if (isObject(object)) {
  12918. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12919. }
  12920. else {
  12921. accumulator = {};
  12922. }
  12923. }
  12924. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12925. return iteratee(accumulator, value, index, object);
  12926. });
  12927. return accumulator;
  12928. }
  12929. /**
  12930. * Removes the property at `path` of `object`.
  12931. *
  12932. * **Note:** This method mutates `object`.
  12933. *
  12934. * @static
  12935. * @memberOf _
  12936. * @since 4.0.0
  12937. * @category Object
  12938. * @param {Object} object The object to modify.
  12939. * @param {Array|string} path The path of the property to unset.
  12940. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12941. * @example
  12942. *
  12943. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12944. * _.unset(object, 'a[0].b.c');
  12945. * // => true
  12946. *
  12947. * console.log(object);
  12948. * // => { 'a': [{ 'b': {} }] };
  12949. *
  12950. * _.unset(object, ['a', '0', 'b', 'c']);
  12951. * // => true
  12952. *
  12953. * console.log(object);
  12954. * // => { 'a': [{ 'b': {} }] };
  12955. */
  12956. function unset(object, path) {
  12957. return object == null ? true : baseUnset(object, path);
  12958. }
  12959. /**
  12960. * This method is like `_.set` except that accepts `updater` to produce the
  12961. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12962. * is invoked with one argument: (value).
  12963. *
  12964. * **Note:** This method mutates `object`.
  12965. *
  12966. * @static
  12967. * @memberOf _
  12968. * @since 4.6.0
  12969. * @category Object
  12970. * @param {Object} object The object to modify.
  12971. * @param {Array|string} path The path of the property to set.
  12972. * @param {Function} updater The function to produce the updated value.
  12973. * @returns {Object} Returns `object`.
  12974. * @example
  12975. *
  12976. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12977. *
  12978. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12979. * console.log(object.a[0].b.c);
  12980. * // => 9
  12981. *
  12982. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12983. * console.log(object.x[0].y.z);
  12984. * // => 0
  12985. */
  12986. function update(object, path, updater) {
  12987. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12988. }
  12989. /**
  12990. * This method is like `_.update` except that it accepts `customizer` which is
  12991. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12992. * path creation is handled by the method instead. The `customizer` is invoked
  12993. * with three arguments: (nsValue, key, nsObject).
  12994. *
  12995. * **Note:** This method mutates `object`.
  12996. *
  12997. * @static
  12998. * @memberOf _
  12999. * @since 4.6.0
  13000. * @category Object
  13001. * @param {Object} object The object to modify.
  13002. * @param {Array|string} path The path of the property to set.
  13003. * @param {Function} updater The function to produce the updated value.
  13004. * @param {Function} [customizer] The function to customize assigned values.
  13005. * @returns {Object} Returns `object`.
  13006. * @example
  13007. *
  13008. * var object = {};
  13009. *
  13010. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13011. * // => { '0': { '1': 'a' } }
  13012. */
  13013. function updateWith(object, path, updater, customizer) {
  13014. customizer = typeof customizer == 'function' ? customizer : undefined;
  13015. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13016. }
  13017. /**
  13018. * Creates an array of the own enumerable string keyed property values of `object`.
  13019. *
  13020. * **Note:** Non-object values are coerced to objects.
  13021. *
  13022. * @static
  13023. * @since 0.1.0
  13024. * @memberOf _
  13025. * @category Object
  13026. * @param {Object} object The object to query.
  13027. * @returns {Array} Returns the array of property values.
  13028. * @example
  13029. *
  13030. * function Foo() {
  13031. * this.a = 1;
  13032. * this.b = 2;
  13033. * }
  13034. *
  13035. * Foo.prototype.c = 3;
  13036. *
  13037. * _.values(new Foo);
  13038. * // => [1, 2] (iteration order is not guaranteed)
  13039. *
  13040. * _.values('hi');
  13041. * // => ['h', 'i']
  13042. */
  13043. function values(object) {
  13044. return object == null ? [] : baseValues(object, keys(object));
  13045. }
  13046. /**
  13047. * Creates an array of the own and inherited enumerable string keyed property
  13048. * values of `object`.
  13049. *
  13050. * **Note:** Non-object values are coerced to objects.
  13051. *
  13052. * @static
  13053. * @memberOf _
  13054. * @since 3.0.0
  13055. * @category Object
  13056. * @param {Object} object The object to query.
  13057. * @returns {Array} Returns the array of property values.
  13058. * @example
  13059. *
  13060. * function Foo() {
  13061. * this.a = 1;
  13062. * this.b = 2;
  13063. * }
  13064. *
  13065. * Foo.prototype.c = 3;
  13066. *
  13067. * _.valuesIn(new Foo);
  13068. * // => [1, 2, 3] (iteration order is not guaranteed)
  13069. */
  13070. function valuesIn(object) {
  13071. return object == null ? [] : baseValues(object, keysIn(object));
  13072. }
  13073. /*------------------------------------------------------------------------*/
  13074. /**
  13075. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13076. *
  13077. * @static
  13078. * @memberOf _
  13079. * @since 4.0.0
  13080. * @category Number
  13081. * @param {number} number The number to clamp.
  13082. * @param {number} [lower] The lower bound.
  13083. * @param {number} upper The upper bound.
  13084. * @returns {number} Returns the clamped number.
  13085. * @example
  13086. *
  13087. * _.clamp(-10, -5, 5);
  13088. * // => -5
  13089. *
  13090. * _.clamp(10, -5, 5);
  13091. * // => 5
  13092. */
  13093. function clamp(number, lower, upper) {
  13094. if (upper === undefined) {
  13095. upper = lower;
  13096. lower = undefined;
  13097. }
  13098. if (upper !== undefined) {
  13099. upper = toNumber(upper);
  13100. upper = upper === upper ? upper : 0;
  13101. }
  13102. if (lower !== undefined) {
  13103. lower = toNumber(lower);
  13104. lower = lower === lower ? lower : 0;
  13105. }
  13106. return baseClamp(toNumber(number), lower, upper);
  13107. }
  13108. /**
  13109. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13110. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13111. * If `start` is greater than `end` the params are swapped to support
  13112. * negative ranges.
  13113. *
  13114. * @static
  13115. * @memberOf _
  13116. * @since 3.3.0
  13117. * @category Number
  13118. * @param {number} number The number to check.
  13119. * @param {number} [start=0] The start of the range.
  13120. * @param {number} end The end of the range.
  13121. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13122. * @see _.range, _.rangeRight
  13123. * @example
  13124. *
  13125. * _.inRange(3, 2, 4);
  13126. * // => true
  13127. *
  13128. * _.inRange(4, 8);
  13129. * // => true
  13130. *
  13131. * _.inRange(4, 2);
  13132. * // => false
  13133. *
  13134. * _.inRange(2, 2);
  13135. * // => false
  13136. *
  13137. * _.inRange(1.2, 2);
  13138. * // => true
  13139. *
  13140. * _.inRange(5.2, 4);
  13141. * // => false
  13142. *
  13143. * _.inRange(-3, -2, -6);
  13144. * // => true
  13145. */
  13146. function inRange(number, start, end) {
  13147. start = toFinite(start);
  13148. if (end === undefined) {
  13149. end = start;
  13150. start = 0;
  13151. } else {
  13152. end = toFinite(end);
  13153. }
  13154. number = toNumber(number);
  13155. return baseInRange(number, start, end);
  13156. }
  13157. /**
  13158. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13159. * If only one argument is provided a number between `0` and the given number
  13160. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13161. * floats, a floating-point number is returned instead of an integer.
  13162. *
  13163. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13164. * floating-point values which can produce unexpected results.
  13165. *
  13166. * @static
  13167. * @memberOf _
  13168. * @since 0.7.0
  13169. * @category Number
  13170. * @param {number} [lower=0] The lower bound.
  13171. * @param {number} [upper=1] The upper bound.
  13172. * @param {boolean} [floating] Specify returning a floating-point number.
  13173. * @returns {number} Returns the random number.
  13174. * @example
  13175. *
  13176. * _.random(0, 5);
  13177. * // => an integer between 0 and 5
  13178. *
  13179. * _.random(5);
  13180. * // => also an integer between 0 and 5
  13181. *
  13182. * _.random(5, true);
  13183. * // => a floating-point number between 0 and 5
  13184. *
  13185. * _.random(1.2, 5.2);
  13186. * // => a floating-point number between 1.2 and 5.2
  13187. */
  13188. function random(lower, upper, floating) {
  13189. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13190. upper = floating = undefined;
  13191. }
  13192. if (floating === undefined) {
  13193. if (typeof upper == 'boolean') {
  13194. floating = upper;
  13195. upper = undefined;
  13196. }
  13197. else if (typeof lower == 'boolean') {
  13198. floating = lower;
  13199. lower = undefined;
  13200. }
  13201. }
  13202. if (lower === undefined && upper === undefined) {
  13203. lower = 0;
  13204. upper = 1;
  13205. }
  13206. else {
  13207. lower = toFinite(lower);
  13208. if (upper === undefined) {
  13209. upper = lower;
  13210. lower = 0;
  13211. } else {
  13212. upper = toFinite(upper);
  13213. }
  13214. }
  13215. if (lower > upper) {
  13216. var temp = lower;
  13217. lower = upper;
  13218. upper = temp;
  13219. }
  13220. if (floating || lower % 1 || upper % 1) {
  13221. var rand = nativeRandom();
  13222. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13223. }
  13224. return baseRandom(lower, upper);
  13225. }
  13226. /*------------------------------------------------------------------------*/
  13227. /**
  13228. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13229. *
  13230. * @static
  13231. * @memberOf _
  13232. * @since 3.0.0
  13233. * @category String
  13234. * @param {string} [string=''] The string to convert.
  13235. * @returns {string} Returns the camel cased string.
  13236. * @example
  13237. *
  13238. * _.camelCase('Foo Bar');
  13239. * // => 'fooBar'
  13240. *
  13241. * _.camelCase('--foo-bar--');
  13242. * // => 'fooBar'
  13243. *
  13244. * _.camelCase('__FOO_BAR__');
  13245. * // => 'fooBar'
  13246. */
  13247. var camelCase = createCompounder(function(result, word, index) {
  13248. word = word.toLowerCase();
  13249. return result + (index ? capitalize(word) : word);
  13250. });
  13251. /**
  13252. * Converts the first character of `string` to upper case and the remaining
  13253. * to lower case.
  13254. *
  13255. * @static
  13256. * @memberOf _
  13257. * @since 3.0.0
  13258. * @category String
  13259. * @param {string} [string=''] The string to capitalize.
  13260. * @returns {string} Returns the capitalized string.
  13261. * @example
  13262. *
  13263. * _.capitalize('FRED');
  13264. * // => 'Fred'
  13265. */
  13266. function capitalize(string) {
  13267. return upperFirst(toString(string).toLowerCase());
  13268. }
  13269. /**
  13270. * Deburrs `string` by converting
  13271. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13272. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13273. * letters to basic Latin letters and removing
  13274. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13275. *
  13276. * @static
  13277. * @memberOf _
  13278. * @since 3.0.0
  13279. * @category String
  13280. * @param {string} [string=''] The string to deburr.
  13281. * @returns {string} Returns the deburred string.
  13282. * @example
  13283. *
  13284. * _.deburr('déjà vu');
  13285. * // => 'deja vu'
  13286. */
  13287. function deburr(string) {
  13288. string = toString(string);
  13289. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13290. }
  13291. /**
  13292. * Checks if `string` ends with the given target string.
  13293. *
  13294. * @static
  13295. * @memberOf _
  13296. * @since 3.0.0
  13297. * @category String
  13298. * @param {string} [string=''] The string to inspect.
  13299. * @param {string} [target] The string to search for.
  13300. * @param {number} [position=string.length] The position to search up to.
  13301. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13302. * else `false`.
  13303. * @example
  13304. *
  13305. * _.endsWith('abc', 'c');
  13306. * // => true
  13307. *
  13308. * _.endsWith('abc', 'b');
  13309. * // => false
  13310. *
  13311. * _.endsWith('abc', 'b', 2);
  13312. * // => true
  13313. */
  13314. function endsWith(string, target, position) {
  13315. string = toString(string);
  13316. target = baseToString(target);
  13317. var length = string.length;
  13318. position = position === undefined
  13319. ? length
  13320. : baseClamp(toInteger(position), 0, length);
  13321. var end = position;
  13322. position -= target.length;
  13323. return position >= 0 && string.slice(position, end) == target;
  13324. }
  13325. /**
  13326. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13327. * corresponding HTML entities.
  13328. *
  13329. * **Note:** No other characters are escaped. To escape additional
  13330. * characters use a third-party library like [_he_](https://mths.be/he).
  13331. *
  13332. * Though the ">" character is escaped for symmetry, characters like
  13333. * ">" and "/" don't need escaping in HTML and have no special meaning
  13334. * unless they're part of a tag or unquoted attribute value. See
  13335. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13336. * (under "semi-related fun fact") for more details.
  13337. *
  13338. * When working with HTML you should always
  13339. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13340. * XSS vectors.
  13341. *
  13342. * @static
  13343. * @since 0.1.0
  13344. * @memberOf _
  13345. * @category String
  13346. * @param {string} [string=''] The string to escape.
  13347. * @returns {string} Returns the escaped string.
  13348. * @example
  13349. *
  13350. * _.escape('fred, barney, & pebbles');
  13351. * // => 'fred, barney, &amp; pebbles'
  13352. */
  13353. function escape(string) {
  13354. string = toString(string);
  13355. return (string && reHasUnescapedHtml.test(string))
  13356. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13357. : string;
  13358. }
  13359. /**
  13360. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13361. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13362. *
  13363. * @static
  13364. * @memberOf _
  13365. * @since 3.0.0
  13366. * @category String
  13367. * @param {string} [string=''] The string to escape.
  13368. * @returns {string} Returns the escaped string.
  13369. * @example
  13370. *
  13371. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13372. * // => '\[lodash\]\(https://lodash\.com/\)'
  13373. */
  13374. function escapeRegExp(string) {
  13375. string = toString(string);
  13376. return (string && reHasRegExpChar.test(string))
  13377. ? string.replace(reRegExpChar, '\\$&')
  13378. : string;
  13379. }
  13380. /**
  13381. * Converts `string` to
  13382. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13383. *
  13384. * @static
  13385. * @memberOf _
  13386. * @since 3.0.0
  13387. * @category String
  13388. * @param {string} [string=''] The string to convert.
  13389. * @returns {string} Returns the kebab cased string.
  13390. * @example
  13391. *
  13392. * _.kebabCase('Foo Bar');
  13393. * // => 'foo-bar'
  13394. *
  13395. * _.kebabCase('fooBar');
  13396. * // => 'foo-bar'
  13397. *
  13398. * _.kebabCase('__FOO_BAR__');
  13399. * // => 'foo-bar'
  13400. */
  13401. var kebabCase = createCompounder(function(result, word, index) {
  13402. return result + (index ? '-' : '') + word.toLowerCase();
  13403. });
  13404. /**
  13405. * Converts `string`, as space separated words, to lower case.
  13406. *
  13407. * @static
  13408. * @memberOf _
  13409. * @since 4.0.0
  13410. * @category String
  13411. * @param {string} [string=''] The string to convert.
  13412. * @returns {string} Returns the lower cased string.
  13413. * @example
  13414. *
  13415. * _.lowerCase('--Foo-Bar--');
  13416. * // => 'foo bar'
  13417. *
  13418. * _.lowerCase('fooBar');
  13419. * // => 'foo bar'
  13420. *
  13421. * _.lowerCase('__FOO_BAR__');
  13422. * // => 'foo bar'
  13423. */
  13424. var lowerCase = createCompounder(function(result, word, index) {
  13425. return result + (index ? ' ' : '') + word.toLowerCase();
  13426. });
  13427. /**
  13428. * Converts the first character of `string` to lower case.
  13429. *
  13430. * @static
  13431. * @memberOf _
  13432. * @since 4.0.0
  13433. * @category String
  13434. * @param {string} [string=''] The string to convert.
  13435. * @returns {string} Returns the converted string.
  13436. * @example
  13437. *
  13438. * _.lowerFirst('Fred');
  13439. * // => 'fred'
  13440. *
  13441. * _.lowerFirst('FRED');
  13442. * // => 'fRED'
  13443. */
  13444. var lowerFirst = createCaseFirst('toLowerCase');
  13445. /**
  13446. * Pads `string` on the left and right sides if it's shorter than `length`.
  13447. * Padding characters are truncated if they can't be evenly divided by `length`.
  13448. *
  13449. * @static
  13450. * @memberOf _
  13451. * @since 3.0.0
  13452. * @category String
  13453. * @param {string} [string=''] The string to pad.
  13454. * @param {number} [length=0] The padding length.
  13455. * @param {string} [chars=' '] The string used as padding.
  13456. * @returns {string} Returns the padded string.
  13457. * @example
  13458. *
  13459. * _.pad('abc', 8);
  13460. * // => ' abc '
  13461. *
  13462. * _.pad('abc', 8, '_-');
  13463. * // => '_-abc_-_'
  13464. *
  13465. * _.pad('abc', 3);
  13466. * // => 'abc'
  13467. */
  13468. function pad(string, length, chars) {
  13469. string = toString(string);
  13470. length = toInteger(length);
  13471. var strLength = length ? stringSize(string) : 0;
  13472. if (!length || strLength >= length) {
  13473. return string;
  13474. }
  13475. var mid = (length - strLength) / 2;
  13476. return (
  13477. createPadding(nativeFloor(mid), chars) +
  13478. string +
  13479. createPadding(nativeCeil(mid), chars)
  13480. );
  13481. }
  13482. /**
  13483. * Pads `string` on the right side if it's shorter than `length`. Padding
  13484. * characters are truncated if they exceed `length`.
  13485. *
  13486. * @static
  13487. * @memberOf _
  13488. * @since 4.0.0
  13489. * @category String
  13490. * @param {string} [string=''] The string to pad.
  13491. * @param {number} [length=0] The padding length.
  13492. * @param {string} [chars=' '] The string used as padding.
  13493. * @returns {string} Returns the padded string.
  13494. * @example
  13495. *
  13496. * _.padEnd('abc', 6);
  13497. * // => 'abc '
  13498. *
  13499. * _.padEnd('abc', 6, '_-');
  13500. * // => 'abc_-_'
  13501. *
  13502. * _.padEnd('abc', 3);
  13503. * // => 'abc'
  13504. */
  13505. function padEnd(string, length, chars) {
  13506. string = toString(string);
  13507. length = toInteger(length);
  13508. var strLength = length ? stringSize(string) : 0;
  13509. return (length && strLength < length)
  13510. ? (string + createPadding(length - strLength, chars))
  13511. : string;
  13512. }
  13513. /**
  13514. * Pads `string` on the left side if it's shorter than `length`. Padding
  13515. * characters are truncated if they exceed `length`.
  13516. *
  13517. * @static
  13518. * @memberOf _
  13519. * @since 4.0.0
  13520. * @category String
  13521. * @param {string} [string=''] The string to pad.
  13522. * @param {number} [length=0] The padding length.
  13523. * @param {string} [chars=' '] The string used as padding.
  13524. * @returns {string} Returns the padded string.
  13525. * @example
  13526. *
  13527. * _.padStart('abc', 6);
  13528. * // => ' abc'
  13529. *
  13530. * _.padStart('abc', 6, '_-');
  13531. * // => '_-_abc'
  13532. *
  13533. * _.padStart('abc', 3);
  13534. * // => 'abc'
  13535. */
  13536. function padStart(string, length, chars) {
  13537. string = toString(string);
  13538. length = toInteger(length);
  13539. var strLength = length ? stringSize(string) : 0;
  13540. return (length && strLength < length)
  13541. ? (createPadding(length - strLength, chars) + string)
  13542. : string;
  13543. }
  13544. /**
  13545. * Converts `string` to an integer of the specified radix. If `radix` is
  13546. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13547. * hexadecimal, in which case a `radix` of `16` is used.
  13548. *
  13549. * **Note:** This method aligns with the
  13550. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13551. *
  13552. * @static
  13553. * @memberOf _
  13554. * @since 1.1.0
  13555. * @category String
  13556. * @param {string} string The string to convert.
  13557. * @param {number} [radix=10] The radix to interpret `value` by.
  13558. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13559. * @returns {number} Returns the converted integer.
  13560. * @example
  13561. *
  13562. * _.parseInt('08');
  13563. * // => 8
  13564. *
  13565. * _.map(['6', '08', '10'], _.parseInt);
  13566. * // => [6, 8, 10]
  13567. */
  13568. function parseInt(string, radix, guard) {
  13569. if (guard || radix == null) {
  13570. radix = 0;
  13571. } else if (radix) {
  13572. radix = +radix;
  13573. }
  13574. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13575. }
  13576. /**
  13577. * Repeats the given string `n` times.
  13578. *
  13579. * @static
  13580. * @memberOf _
  13581. * @since 3.0.0
  13582. * @category String
  13583. * @param {string} [string=''] The string to repeat.
  13584. * @param {number} [n=1] The number of times to repeat the string.
  13585. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13586. * @returns {string} Returns the repeated string.
  13587. * @example
  13588. *
  13589. * _.repeat('*', 3);
  13590. * // => '***'
  13591. *
  13592. * _.repeat('abc', 2);
  13593. * // => 'abcabc'
  13594. *
  13595. * _.repeat('abc', 0);
  13596. * // => ''
  13597. */
  13598. function repeat(string, n, guard) {
  13599. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13600. n = 1;
  13601. } else {
  13602. n = toInteger(n);
  13603. }
  13604. return baseRepeat(toString(string), n);
  13605. }
  13606. /**
  13607. * Replaces matches for `pattern` in `string` with `replacement`.
  13608. *
  13609. * **Note:** This method is based on
  13610. * [`String#replace`](https://mdn.io/String/replace).
  13611. *
  13612. * @static
  13613. * @memberOf _
  13614. * @since 4.0.0
  13615. * @category String
  13616. * @param {string} [string=''] The string to modify.
  13617. * @param {RegExp|string} pattern The pattern to replace.
  13618. * @param {Function|string} replacement The match replacement.
  13619. * @returns {string} Returns the modified string.
  13620. * @example
  13621. *
  13622. * _.replace('Hi Fred', 'Fred', 'Barney');
  13623. * // => 'Hi Barney'
  13624. */
  13625. function replace() {
  13626. var args = arguments,
  13627. string = toString(args[0]);
  13628. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13629. }
  13630. /**
  13631. * Converts `string` to
  13632. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13633. *
  13634. * @static
  13635. * @memberOf _
  13636. * @since 3.0.0
  13637. * @category String
  13638. * @param {string} [string=''] The string to convert.
  13639. * @returns {string} Returns the snake cased string.
  13640. * @example
  13641. *
  13642. * _.snakeCase('Foo Bar');
  13643. * // => 'foo_bar'
  13644. *
  13645. * _.snakeCase('fooBar');
  13646. * // => 'foo_bar'
  13647. *
  13648. * _.snakeCase('--FOO-BAR--');
  13649. * // => 'foo_bar'
  13650. */
  13651. var snakeCase = createCompounder(function(result, word, index) {
  13652. return result + (index ? '_' : '') + word.toLowerCase();
  13653. });
  13654. /**
  13655. * Splits `string` by `separator`.
  13656. *
  13657. * **Note:** This method is based on
  13658. * [`String#split`](https://mdn.io/String/split).
  13659. *
  13660. * @static
  13661. * @memberOf _
  13662. * @since 4.0.0
  13663. * @category String
  13664. * @param {string} [string=''] The string to split.
  13665. * @param {RegExp|string} separator The separator pattern to split by.
  13666. * @param {number} [limit] The length to truncate results to.
  13667. * @returns {Array} Returns the string segments.
  13668. * @example
  13669. *
  13670. * _.split('a-b-c', '-', 2);
  13671. * // => ['a', 'b']
  13672. */
  13673. function split(string, separator, limit) {
  13674. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13675. separator = limit = undefined;
  13676. }
  13677. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13678. if (!limit) {
  13679. return [];
  13680. }
  13681. string = toString(string);
  13682. if (string && (
  13683. typeof separator == 'string' ||
  13684. (separator != null && !isRegExp(separator))
  13685. )) {
  13686. separator = baseToString(separator);
  13687. if (!separator && hasUnicode(string)) {
  13688. return castSlice(stringToArray(string), 0, limit);
  13689. }
  13690. }
  13691. return string.split(separator, limit);
  13692. }
  13693. /**
  13694. * Converts `string` to
  13695. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13696. *
  13697. * @static
  13698. * @memberOf _
  13699. * @since 3.1.0
  13700. * @category String
  13701. * @param {string} [string=''] The string to convert.
  13702. * @returns {string} Returns the start cased string.
  13703. * @example
  13704. *
  13705. * _.startCase('--foo-bar--');
  13706. * // => 'Foo Bar'
  13707. *
  13708. * _.startCase('fooBar');
  13709. * // => 'Foo Bar'
  13710. *
  13711. * _.startCase('__FOO_BAR__');
  13712. * // => 'FOO BAR'
  13713. */
  13714. var startCase = createCompounder(function(result, word, index) {
  13715. return result + (index ? ' ' : '') + upperFirst(word);
  13716. });
  13717. /**
  13718. * Checks if `string` starts with the given target string.
  13719. *
  13720. * @static
  13721. * @memberOf _
  13722. * @since 3.0.0
  13723. * @category String
  13724. * @param {string} [string=''] The string to inspect.
  13725. * @param {string} [target] The string to search for.
  13726. * @param {number} [position=0] The position to search from.
  13727. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13728. * else `false`.
  13729. * @example
  13730. *
  13731. * _.startsWith('abc', 'a');
  13732. * // => true
  13733. *
  13734. * _.startsWith('abc', 'b');
  13735. * // => false
  13736. *
  13737. * _.startsWith('abc', 'b', 1);
  13738. * // => true
  13739. */
  13740. function startsWith(string, target, position) {
  13741. string = toString(string);
  13742. position = position == null
  13743. ? 0
  13744. : baseClamp(toInteger(position), 0, string.length);
  13745. target = baseToString(target);
  13746. return string.slice(position, position + target.length) == target;
  13747. }
  13748. /**
  13749. * Creates a compiled template function that can interpolate data properties
  13750. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13751. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13752. * properties may be accessed as free variables in the template. If a setting
  13753. * object is given, it takes precedence over `_.templateSettings` values.
  13754. *
  13755. * **Note:** In the development build `_.template` utilizes
  13756. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13757. * for easier debugging.
  13758. *
  13759. * For more information on precompiling templates see
  13760. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13761. *
  13762. * For more information on Chrome extension sandboxes see
  13763. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13764. *
  13765. * @static
  13766. * @since 0.1.0
  13767. * @memberOf _
  13768. * @category String
  13769. * @param {string} [string=''] The template string.
  13770. * @param {Object} [options={}] The options object.
  13771. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13772. * The HTML "escape" delimiter.
  13773. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13774. * The "evaluate" delimiter.
  13775. * @param {Object} [options.imports=_.templateSettings.imports]
  13776. * An object to import into the template as free variables.
  13777. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13778. * The "interpolate" delimiter.
  13779. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13780. * The sourceURL of the compiled template.
  13781. * @param {string} [options.variable='obj']
  13782. * The data object variable name.
  13783. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13784. * @returns {Function} Returns the compiled template function.
  13785. * @example
  13786. *
  13787. * // Use the "interpolate" delimiter to create a compiled template.
  13788. * var compiled = _.template('hello <%= user %>!');
  13789. * compiled({ 'user': 'fred' });
  13790. * // => 'hello fred!'
  13791. *
  13792. * // Use the HTML "escape" delimiter to escape data property values.
  13793. * var compiled = _.template('<b><%- value %></b>');
  13794. * compiled({ 'value': '<script>' });
  13795. * // => '<b>&lt;script&gt;</b>'
  13796. *
  13797. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13798. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13799. * compiled({ 'users': ['fred', 'barney'] });
  13800. * // => '<li>fred</li><li>barney</li>'
  13801. *
  13802. * // Use the internal `print` function in "evaluate" delimiters.
  13803. * var compiled = _.template('<% print("hello " + user); %>!');
  13804. * compiled({ 'user': 'barney' });
  13805. * // => 'hello barney!'
  13806. *
  13807. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13808. * // Disable support by replacing the "interpolate" delimiter.
  13809. * var compiled = _.template('hello ${ user }!');
  13810. * compiled({ 'user': 'pebbles' });
  13811. * // => 'hello pebbles!'
  13812. *
  13813. * // Use backslashes to treat delimiters as plain text.
  13814. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13815. * compiled({ 'value': 'ignored' });
  13816. * // => '<%- value %>'
  13817. *
  13818. * // Use the `imports` option to import `jQuery` as `jq`.
  13819. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13820. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13821. * compiled({ 'users': ['fred', 'barney'] });
  13822. * // => '<li>fred</li><li>barney</li>'
  13823. *
  13824. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13825. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13826. * compiled(data);
  13827. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13828. *
  13829. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13830. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13831. * compiled.source;
  13832. * // => function(data) {
  13833. * // var __t, __p = '';
  13834. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13835. * // return __p;
  13836. * // }
  13837. *
  13838. * // Use custom template delimiters.
  13839. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13840. * var compiled = _.template('hello {{ user }}!');
  13841. * compiled({ 'user': 'mustache' });
  13842. * // => 'hello mustache!'
  13843. *
  13844. * // Use the `source` property to inline compiled templates for meaningful
  13845. * // line numbers in error messages and stack traces.
  13846. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13847. * var JST = {\
  13848. * "main": ' + _.template(mainText).source + '\
  13849. * };\
  13850. * ');
  13851. */
  13852. function template(string, options, guard) {
  13853. // Based on John Resig's `tmpl` implementation
  13854. // (http://ejohn.org/blog/javascript-micro-templating/)
  13855. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13856. var settings = lodash.templateSettings;
  13857. if (guard && isIterateeCall(string, options, guard)) {
  13858. options = undefined;
  13859. }
  13860. string = toString(string);
  13861. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13862. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13863. importsKeys = keys(imports),
  13864. importsValues = baseValues(imports, importsKeys);
  13865. var isEscaping,
  13866. isEvaluating,
  13867. index = 0,
  13868. interpolate = options.interpolate || reNoMatch,
  13869. source = "__p += '";
  13870. // Compile the regexp to match each delimiter.
  13871. var reDelimiters = RegExp(
  13872. (options.escape || reNoMatch).source + '|' +
  13873. interpolate.source + '|' +
  13874. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13875. (options.evaluate || reNoMatch).source + '|$'
  13876. , 'g');
  13877. // Use a sourceURL for easier debugging.
  13878. var sourceURL = '//# sourceURL=' +
  13879. ('sourceURL' in options
  13880. ? options.sourceURL
  13881. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13882. ) + '\n';
  13883. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13884. interpolateValue || (interpolateValue = esTemplateValue);
  13885. // Escape characters that can't be included in string literals.
  13886. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13887. // Replace delimiters with snippets.
  13888. if (escapeValue) {
  13889. isEscaping = true;
  13890. source += "' +\n__e(" + escapeValue + ") +\n'";
  13891. }
  13892. if (evaluateValue) {
  13893. isEvaluating = true;
  13894. source += "';\n" + evaluateValue + ";\n__p += '";
  13895. }
  13896. if (interpolateValue) {
  13897. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13898. }
  13899. index = offset + match.length;
  13900. // The JS engine embedded in Adobe products needs `match` returned in
  13901. // order to produce the correct `offset` value.
  13902. return match;
  13903. });
  13904. source += "';\n";
  13905. // If `variable` is not specified wrap a with-statement around the generated
  13906. // code to add the data object to the top of the scope chain.
  13907. var variable = options.variable;
  13908. if (!variable) {
  13909. source = 'with (obj) {\n' + source + '\n}\n';
  13910. }
  13911. // Cleanup code by stripping empty strings.
  13912. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13913. .replace(reEmptyStringMiddle, '$1')
  13914. .replace(reEmptyStringTrailing, '$1;');
  13915. // Frame code as the function body.
  13916. source = 'function(' + (variable || 'obj') + ') {\n' +
  13917. (variable
  13918. ? ''
  13919. : 'obj || (obj = {});\n'
  13920. ) +
  13921. "var __t, __p = ''" +
  13922. (isEscaping
  13923. ? ', __e = _.escape'
  13924. : ''
  13925. ) +
  13926. (isEvaluating
  13927. ? ', __j = Array.prototype.join;\n' +
  13928. "function print() { __p += __j.call(arguments, '') }\n"
  13929. : ';\n'
  13930. ) +
  13931. source +
  13932. 'return __p\n}';
  13933. var result = attempt(function() {
  13934. return Function(importsKeys, sourceURL + 'return ' + source)
  13935. .apply(undefined, importsValues);
  13936. });
  13937. // Provide the compiled function's source by its `toString` method or
  13938. // the `source` property as a convenience for inlining compiled templates.
  13939. result.source = source;
  13940. if (isError(result)) {
  13941. throw result;
  13942. }
  13943. return result;
  13944. }
  13945. /**
  13946. * Converts `string`, as a whole, to lower case just like
  13947. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13948. *
  13949. * @static
  13950. * @memberOf _
  13951. * @since 4.0.0
  13952. * @category String
  13953. * @param {string} [string=''] The string to convert.
  13954. * @returns {string} Returns the lower cased string.
  13955. * @example
  13956. *
  13957. * _.toLower('--Foo-Bar--');
  13958. * // => '--foo-bar--'
  13959. *
  13960. * _.toLower('fooBar');
  13961. * // => 'foobar'
  13962. *
  13963. * _.toLower('__FOO_BAR__');
  13964. * // => '__foo_bar__'
  13965. */
  13966. function toLower(value) {
  13967. return toString(value).toLowerCase();
  13968. }
  13969. /**
  13970. * Converts `string`, as a whole, to upper case just like
  13971. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13972. *
  13973. * @static
  13974. * @memberOf _
  13975. * @since 4.0.0
  13976. * @category String
  13977. * @param {string} [string=''] The string to convert.
  13978. * @returns {string} Returns the upper cased string.
  13979. * @example
  13980. *
  13981. * _.toUpper('--foo-bar--');
  13982. * // => '--FOO-BAR--'
  13983. *
  13984. * _.toUpper('fooBar');
  13985. * // => 'FOOBAR'
  13986. *
  13987. * _.toUpper('__foo_bar__');
  13988. * // => '__FOO_BAR__'
  13989. */
  13990. function toUpper(value) {
  13991. return toString(value).toUpperCase();
  13992. }
  13993. /**
  13994. * Removes leading and trailing whitespace or specified characters from `string`.
  13995. *
  13996. * @static
  13997. * @memberOf _
  13998. * @since 3.0.0
  13999. * @category String
  14000. * @param {string} [string=''] The string to trim.
  14001. * @param {string} [chars=whitespace] The characters to trim.
  14002. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14003. * @returns {string} Returns the trimmed string.
  14004. * @example
  14005. *
  14006. * _.trim(' abc ');
  14007. * // => 'abc'
  14008. *
  14009. * _.trim('-_-abc-_-', '_-');
  14010. * // => 'abc'
  14011. *
  14012. * _.map([' foo ', ' bar '], _.trim);
  14013. * // => ['foo', 'bar']
  14014. */
  14015. function trim(string, chars, guard) {
  14016. string = toString(string);
  14017. if (string && (guard || chars === undefined)) {
  14018. return string.replace(reTrim, '');
  14019. }
  14020. if (!string || !(chars = baseToString(chars))) {
  14021. return string;
  14022. }
  14023. var strSymbols = stringToArray(string),
  14024. chrSymbols = stringToArray(chars),
  14025. start = charsStartIndex(strSymbols, chrSymbols),
  14026. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14027. return castSlice(strSymbols, start, end).join('');
  14028. }
  14029. /**
  14030. * Removes trailing whitespace or specified characters from `string`.
  14031. *
  14032. * @static
  14033. * @memberOf _
  14034. * @since 4.0.0
  14035. * @category String
  14036. * @param {string} [string=''] The string to trim.
  14037. * @param {string} [chars=whitespace] The characters to trim.
  14038. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14039. * @returns {string} Returns the trimmed string.
  14040. * @example
  14041. *
  14042. * _.trimEnd(' abc ');
  14043. * // => ' abc'
  14044. *
  14045. * _.trimEnd('-_-abc-_-', '_-');
  14046. * // => '-_-abc'
  14047. */
  14048. function trimEnd(string, chars, guard) {
  14049. string = toString(string);
  14050. if (string && (guard || chars === undefined)) {
  14051. return string.replace(reTrimEnd, '');
  14052. }
  14053. if (!string || !(chars = baseToString(chars))) {
  14054. return string;
  14055. }
  14056. var strSymbols = stringToArray(string),
  14057. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14058. return castSlice(strSymbols, 0, end).join('');
  14059. }
  14060. /**
  14061. * Removes leading whitespace or specified characters from `string`.
  14062. *
  14063. * @static
  14064. * @memberOf _
  14065. * @since 4.0.0
  14066. * @category String
  14067. * @param {string} [string=''] The string to trim.
  14068. * @param {string} [chars=whitespace] The characters to trim.
  14069. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14070. * @returns {string} Returns the trimmed string.
  14071. * @example
  14072. *
  14073. * _.trimStart(' abc ');
  14074. * // => 'abc '
  14075. *
  14076. * _.trimStart('-_-abc-_-', '_-');
  14077. * // => 'abc-_-'
  14078. */
  14079. function trimStart(string, chars, guard) {
  14080. string = toString(string);
  14081. if (string && (guard || chars === undefined)) {
  14082. return string.replace(reTrimStart, '');
  14083. }
  14084. if (!string || !(chars = baseToString(chars))) {
  14085. return string;
  14086. }
  14087. var strSymbols = stringToArray(string),
  14088. start = charsStartIndex(strSymbols, stringToArray(chars));
  14089. return castSlice(strSymbols, start).join('');
  14090. }
  14091. /**
  14092. * Truncates `string` if it's longer than the given maximum string length.
  14093. * The last characters of the truncated string are replaced with the omission
  14094. * string which defaults to "...".
  14095. *
  14096. * @static
  14097. * @memberOf _
  14098. * @since 4.0.0
  14099. * @category String
  14100. * @param {string} [string=''] The string to truncate.
  14101. * @param {Object} [options={}] The options object.
  14102. * @param {number} [options.length=30] The maximum string length.
  14103. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14104. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14105. * @returns {string} Returns the truncated string.
  14106. * @example
  14107. *
  14108. * _.truncate('hi-diddly-ho there, neighborino');
  14109. * // => 'hi-diddly-ho there, neighbo...'
  14110. *
  14111. * _.truncate('hi-diddly-ho there, neighborino', {
  14112. * 'length': 24,
  14113. * 'separator': ' '
  14114. * });
  14115. * // => 'hi-diddly-ho there,...'
  14116. *
  14117. * _.truncate('hi-diddly-ho there, neighborino', {
  14118. * 'length': 24,
  14119. * 'separator': /,? +/
  14120. * });
  14121. * // => 'hi-diddly-ho there...'
  14122. *
  14123. * _.truncate('hi-diddly-ho there, neighborino', {
  14124. * 'omission': ' [...]'
  14125. * });
  14126. * // => 'hi-diddly-ho there, neig [...]'
  14127. */
  14128. function truncate(string, options) {
  14129. var length = DEFAULT_TRUNC_LENGTH,
  14130. omission = DEFAULT_TRUNC_OMISSION;
  14131. if (isObject(options)) {
  14132. var separator = 'separator' in options ? options.separator : separator;
  14133. length = 'length' in options ? toInteger(options.length) : length;
  14134. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14135. }
  14136. string = toString(string);
  14137. var strLength = string.length;
  14138. if (hasUnicode(string)) {
  14139. var strSymbols = stringToArray(string);
  14140. strLength = strSymbols.length;
  14141. }
  14142. if (length >= strLength) {
  14143. return string;
  14144. }
  14145. var end = length - stringSize(omission);
  14146. if (end < 1) {
  14147. return omission;
  14148. }
  14149. var result = strSymbols
  14150. ? castSlice(strSymbols, 0, end).join('')
  14151. : string.slice(0, end);
  14152. if (separator === undefined) {
  14153. return result + omission;
  14154. }
  14155. if (strSymbols) {
  14156. end += (result.length - end);
  14157. }
  14158. if (isRegExp(separator)) {
  14159. if (string.slice(end).search(separator)) {
  14160. var match,
  14161. substring = result;
  14162. if (!separator.global) {
  14163. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14164. }
  14165. separator.lastIndex = 0;
  14166. while ((match = separator.exec(substring))) {
  14167. var newEnd = match.index;
  14168. }
  14169. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14170. }
  14171. } else if (string.indexOf(baseToString(separator), end) != end) {
  14172. var index = result.lastIndexOf(separator);
  14173. if (index > -1) {
  14174. result = result.slice(0, index);
  14175. }
  14176. }
  14177. return result + omission;
  14178. }
  14179. /**
  14180. * The inverse of `_.escape`; this method converts the HTML entities
  14181. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14182. * their corresponding characters.
  14183. *
  14184. * **Note:** No other HTML entities are unescaped. To unescape additional
  14185. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14186. *
  14187. * @static
  14188. * @memberOf _
  14189. * @since 0.6.0
  14190. * @category String
  14191. * @param {string} [string=''] The string to unescape.
  14192. * @returns {string} Returns the unescaped string.
  14193. * @example
  14194. *
  14195. * _.unescape('fred, barney, &amp; pebbles');
  14196. * // => 'fred, barney, & pebbles'
  14197. */
  14198. function unescape(string) {
  14199. string = toString(string);
  14200. return (string && reHasEscapedHtml.test(string))
  14201. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14202. : string;
  14203. }
  14204. /**
  14205. * Converts `string`, as space separated words, to upper case.
  14206. *
  14207. * @static
  14208. * @memberOf _
  14209. * @since 4.0.0
  14210. * @category String
  14211. * @param {string} [string=''] The string to convert.
  14212. * @returns {string} Returns the upper cased string.
  14213. * @example
  14214. *
  14215. * _.upperCase('--foo-bar');
  14216. * // => 'FOO BAR'
  14217. *
  14218. * _.upperCase('fooBar');
  14219. * // => 'FOO BAR'
  14220. *
  14221. * _.upperCase('__foo_bar__');
  14222. * // => 'FOO BAR'
  14223. */
  14224. var upperCase = createCompounder(function(result, word, index) {
  14225. return result + (index ? ' ' : '') + word.toUpperCase();
  14226. });
  14227. /**
  14228. * Converts the first character of `string` to upper case.
  14229. *
  14230. * @static
  14231. * @memberOf _
  14232. * @since 4.0.0
  14233. * @category String
  14234. * @param {string} [string=''] The string to convert.
  14235. * @returns {string} Returns the converted string.
  14236. * @example
  14237. *
  14238. * _.upperFirst('fred');
  14239. * // => 'Fred'
  14240. *
  14241. * _.upperFirst('FRED');
  14242. * // => 'FRED'
  14243. */
  14244. var upperFirst = createCaseFirst('toUpperCase');
  14245. /**
  14246. * Splits `string` into an array of its words.
  14247. *
  14248. * @static
  14249. * @memberOf _
  14250. * @since 3.0.0
  14251. * @category String
  14252. * @param {string} [string=''] The string to inspect.
  14253. * @param {RegExp|string} [pattern] The pattern to match words.
  14254. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14255. * @returns {Array} Returns the words of `string`.
  14256. * @example
  14257. *
  14258. * _.words('fred, barney, & pebbles');
  14259. * // => ['fred', 'barney', 'pebbles']
  14260. *
  14261. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14262. * // => ['fred', 'barney', '&', 'pebbles']
  14263. */
  14264. function words(string, pattern, guard) {
  14265. string = toString(string);
  14266. pattern = guard ? undefined : pattern;
  14267. if (pattern === undefined) {
  14268. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14269. }
  14270. return string.match(pattern) || [];
  14271. }
  14272. /*------------------------------------------------------------------------*/
  14273. /**
  14274. * Attempts to invoke `func`, returning either the result or the caught error
  14275. * object. Any additional arguments are provided to `func` when it's invoked.
  14276. *
  14277. * @static
  14278. * @memberOf _
  14279. * @since 3.0.0
  14280. * @category Util
  14281. * @param {Function} func The function to attempt.
  14282. * @param {...*} [args] The arguments to invoke `func` with.
  14283. * @returns {*} Returns the `func` result or error object.
  14284. * @example
  14285. *
  14286. * // Avoid throwing errors for invalid selectors.
  14287. * var elements = _.attempt(function(selector) {
  14288. * return document.querySelectorAll(selector);
  14289. * }, '>_>');
  14290. *
  14291. * if (_.isError(elements)) {
  14292. * elements = [];
  14293. * }
  14294. */
  14295. var attempt = baseRest(function(func, args) {
  14296. try {
  14297. return apply(func, undefined, args);
  14298. } catch (e) {
  14299. return isError(e) ? e : new Error(e);
  14300. }
  14301. });
  14302. /**
  14303. * Binds methods of an object to the object itself, overwriting the existing
  14304. * method.
  14305. *
  14306. * **Note:** This method doesn't set the "length" property of bound functions.
  14307. *
  14308. * @static
  14309. * @since 0.1.0
  14310. * @memberOf _
  14311. * @category Util
  14312. * @param {Object} object The object to bind and assign the bound methods to.
  14313. * @param {...(string|string[])} methodNames The object method names to bind.
  14314. * @returns {Object} Returns `object`.
  14315. * @example
  14316. *
  14317. * var view = {
  14318. * 'label': 'docs',
  14319. * 'click': function() {
  14320. * console.log('clicked ' + this.label);
  14321. * }
  14322. * };
  14323. *
  14324. * _.bindAll(view, ['click']);
  14325. * jQuery(element).on('click', view.click);
  14326. * // => Logs 'clicked docs' when clicked.
  14327. */
  14328. var bindAll = flatRest(function(object, methodNames) {
  14329. arrayEach(methodNames, function(key) {
  14330. key = toKey(key);
  14331. baseAssignValue(object, key, bind(object[key], object));
  14332. });
  14333. return object;
  14334. });
  14335. /**
  14336. * Creates a function that iterates over `pairs` and invokes the corresponding
  14337. * function of the first predicate to return truthy. The predicate-function
  14338. * pairs are invoked with the `this` binding and arguments of the created
  14339. * function.
  14340. *
  14341. * @static
  14342. * @memberOf _
  14343. * @since 4.0.0
  14344. * @category Util
  14345. * @param {Array} pairs The predicate-function pairs.
  14346. * @returns {Function} Returns the new composite function.
  14347. * @example
  14348. *
  14349. * var func = _.cond([
  14350. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14351. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14352. * [_.stubTrue, _.constant('no match')]
  14353. * ]);
  14354. *
  14355. * func({ 'a': 1, 'b': 2 });
  14356. * // => 'matches A'
  14357. *
  14358. * func({ 'a': 0, 'b': 1 });
  14359. * // => 'matches B'
  14360. *
  14361. * func({ 'a': '1', 'b': '2' });
  14362. * // => 'no match'
  14363. */
  14364. function cond(pairs) {
  14365. var length = pairs == null ? 0 : pairs.length,
  14366. toIteratee = getIteratee();
  14367. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14368. if (typeof pair[1] != 'function') {
  14369. throw new TypeError(FUNC_ERROR_TEXT);
  14370. }
  14371. return [toIteratee(pair[0]), pair[1]];
  14372. });
  14373. return baseRest(function(args) {
  14374. var index = -1;
  14375. while (++index < length) {
  14376. var pair = pairs[index];
  14377. if (apply(pair[0], this, args)) {
  14378. return apply(pair[1], this, args);
  14379. }
  14380. }
  14381. });
  14382. }
  14383. /**
  14384. * Creates a function that invokes the predicate properties of `source` with
  14385. * the corresponding property values of a given object, returning `true` if
  14386. * all predicates return truthy, else `false`.
  14387. *
  14388. * **Note:** The created function is equivalent to `_.conformsTo` with
  14389. * `source` partially applied.
  14390. *
  14391. * @static
  14392. * @memberOf _
  14393. * @since 4.0.0
  14394. * @category Util
  14395. * @param {Object} source The object of property predicates to conform to.
  14396. * @returns {Function} Returns the new spec function.
  14397. * @example
  14398. *
  14399. * var objects = [
  14400. * { 'a': 2, 'b': 1 },
  14401. * { 'a': 1, 'b': 2 }
  14402. * ];
  14403. *
  14404. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14405. * // => [{ 'a': 1, 'b': 2 }]
  14406. */
  14407. function conforms(source) {
  14408. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14409. }
  14410. /**
  14411. * Creates a function that returns `value`.
  14412. *
  14413. * @static
  14414. * @memberOf _
  14415. * @since 2.4.0
  14416. * @category Util
  14417. * @param {*} value The value to return from the new function.
  14418. * @returns {Function} Returns the new constant function.
  14419. * @example
  14420. *
  14421. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14422. *
  14423. * console.log(objects);
  14424. * // => [{ 'a': 1 }, { 'a': 1 }]
  14425. *
  14426. * console.log(objects[0] === objects[1]);
  14427. * // => true
  14428. */
  14429. function constant(value) {
  14430. return function() {
  14431. return value;
  14432. };
  14433. }
  14434. /**
  14435. * Checks `value` to determine whether a default value should be returned in
  14436. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14437. * or `undefined`.
  14438. *
  14439. * @static
  14440. * @memberOf _
  14441. * @since 4.14.0
  14442. * @category Util
  14443. * @param {*} value The value to check.
  14444. * @param {*} defaultValue The default value.
  14445. * @returns {*} Returns the resolved value.
  14446. * @example
  14447. *
  14448. * _.defaultTo(1, 10);
  14449. * // => 1
  14450. *
  14451. * _.defaultTo(undefined, 10);
  14452. * // => 10
  14453. */
  14454. function defaultTo(value, defaultValue) {
  14455. return (value == null || value !== value) ? defaultValue : value;
  14456. }
  14457. /**
  14458. * Creates a function that returns the result of invoking the given functions
  14459. * with the `this` binding of the created function, where each successive
  14460. * invocation is supplied the return value of the previous.
  14461. *
  14462. * @static
  14463. * @memberOf _
  14464. * @since 3.0.0
  14465. * @category Util
  14466. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14467. * @returns {Function} Returns the new composite function.
  14468. * @see _.flowRight
  14469. * @example
  14470. *
  14471. * function square(n) {
  14472. * return n * n;
  14473. * }
  14474. *
  14475. * var addSquare = _.flow([_.add, square]);
  14476. * addSquare(1, 2);
  14477. * // => 9
  14478. */
  14479. var flow = createFlow();
  14480. /**
  14481. * This method is like `_.flow` except that it creates a function that
  14482. * invokes the given functions from right to left.
  14483. *
  14484. * @static
  14485. * @since 3.0.0
  14486. * @memberOf _
  14487. * @category Util
  14488. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14489. * @returns {Function} Returns the new composite function.
  14490. * @see _.flow
  14491. * @example
  14492. *
  14493. * function square(n) {
  14494. * return n * n;
  14495. * }
  14496. *
  14497. * var addSquare = _.flowRight([square, _.add]);
  14498. * addSquare(1, 2);
  14499. * // => 9
  14500. */
  14501. var flowRight = createFlow(true);
  14502. /**
  14503. * This method returns the first argument it receives.
  14504. *
  14505. * @static
  14506. * @since 0.1.0
  14507. * @memberOf _
  14508. * @category Util
  14509. * @param {*} value Any value.
  14510. * @returns {*} Returns `value`.
  14511. * @example
  14512. *
  14513. * var object = { 'a': 1 };
  14514. *
  14515. * console.log(_.identity(object) === object);
  14516. * // => true
  14517. */
  14518. function identity(value) {
  14519. return value;
  14520. }
  14521. /**
  14522. * Creates a function that invokes `func` with the arguments of the created
  14523. * function. If `func` is a property name, the created function returns the
  14524. * property value for a given element. If `func` is an array or object, the
  14525. * created function returns `true` for elements that contain the equivalent
  14526. * source properties, otherwise it returns `false`.
  14527. *
  14528. * @static
  14529. * @since 4.0.0
  14530. * @memberOf _
  14531. * @category Util
  14532. * @param {*} [func=_.identity] The value to convert to a callback.
  14533. * @returns {Function} Returns the callback.
  14534. * @example
  14535. *
  14536. * var users = [
  14537. * { 'user': 'barney', 'age': 36, 'active': true },
  14538. * { 'user': 'fred', 'age': 40, 'active': false }
  14539. * ];
  14540. *
  14541. * // The `_.matches` iteratee shorthand.
  14542. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14543. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14544. *
  14545. * // The `_.matchesProperty` iteratee shorthand.
  14546. * _.filter(users, _.iteratee(['user', 'fred']));
  14547. * // => [{ 'user': 'fred', 'age': 40 }]
  14548. *
  14549. * // The `_.property` iteratee shorthand.
  14550. * _.map(users, _.iteratee('user'));
  14551. * // => ['barney', 'fred']
  14552. *
  14553. * // Create custom iteratee shorthands.
  14554. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14555. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14556. * return func.test(string);
  14557. * };
  14558. * });
  14559. *
  14560. * _.filter(['abc', 'def'], /ef/);
  14561. * // => ['def']
  14562. */
  14563. function iteratee(func) {
  14564. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14565. }
  14566. /**
  14567. * Creates a function that performs a partial deep comparison between a given
  14568. * object and `source`, returning `true` if the given object has equivalent
  14569. * property values, else `false`.
  14570. *
  14571. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14572. * partially applied.
  14573. *
  14574. * Partial comparisons will match empty array and empty object `source`
  14575. * values against any array or object value, respectively. See `_.isEqual`
  14576. * for a list of supported value comparisons.
  14577. *
  14578. * @static
  14579. * @memberOf _
  14580. * @since 3.0.0
  14581. * @category Util
  14582. * @param {Object} source The object of property values to match.
  14583. * @returns {Function} Returns the new spec function.
  14584. * @example
  14585. *
  14586. * var objects = [
  14587. * { 'a': 1, 'b': 2, 'c': 3 },
  14588. * { 'a': 4, 'b': 5, 'c': 6 }
  14589. * ];
  14590. *
  14591. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14592. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14593. */
  14594. function matches(source) {
  14595. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14596. }
  14597. /**
  14598. * Creates a function that performs a partial deep comparison between the
  14599. * value at `path` of a given object to `srcValue`, returning `true` if the
  14600. * object value is equivalent, else `false`.
  14601. *
  14602. * **Note:** Partial comparisons will match empty array and empty object
  14603. * `srcValue` values against any array or object value, respectively. See
  14604. * `_.isEqual` for a list of supported value comparisons.
  14605. *
  14606. * @static
  14607. * @memberOf _
  14608. * @since 3.2.0
  14609. * @category Util
  14610. * @param {Array|string} path The path of the property to get.
  14611. * @param {*} srcValue The value to match.
  14612. * @returns {Function} Returns the new spec function.
  14613. * @example
  14614. *
  14615. * var objects = [
  14616. * { 'a': 1, 'b': 2, 'c': 3 },
  14617. * { 'a': 4, 'b': 5, 'c': 6 }
  14618. * ];
  14619. *
  14620. * _.find(objects, _.matchesProperty('a', 4));
  14621. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14622. */
  14623. function matchesProperty(path, srcValue) {
  14624. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14625. }
  14626. /**
  14627. * Creates a function that invokes the method at `path` of a given object.
  14628. * Any additional arguments are provided to the invoked method.
  14629. *
  14630. * @static
  14631. * @memberOf _
  14632. * @since 3.7.0
  14633. * @category Util
  14634. * @param {Array|string} path The path of the method to invoke.
  14635. * @param {...*} [args] The arguments to invoke the method with.
  14636. * @returns {Function} Returns the new invoker function.
  14637. * @example
  14638. *
  14639. * var objects = [
  14640. * { 'a': { 'b': _.constant(2) } },
  14641. * { 'a': { 'b': _.constant(1) } }
  14642. * ];
  14643. *
  14644. * _.map(objects, _.method('a.b'));
  14645. * // => [2, 1]
  14646. *
  14647. * _.map(objects, _.method(['a', 'b']));
  14648. * // => [2, 1]
  14649. */
  14650. var method = baseRest(function(path, args) {
  14651. return function(object) {
  14652. return baseInvoke(object, path, args);
  14653. };
  14654. });
  14655. /**
  14656. * The opposite of `_.method`; this method creates a function that invokes
  14657. * the method at a given path of `object`. Any additional arguments are
  14658. * provided to the invoked method.
  14659. *
  14660. * @static
  14661. * @memberOf _
  14662. * @since 3.7.0
  14663. * @category Util
  14664. * @param {Object} object The object to query.
  14665. * @param {...*} [args] The arguments to invoke the method with.
  14666. * @returns {Function} Returns the new invoker function.
  14667. * @example
  14668. *
  14669. * var array = _.times(3, _.constant),
  14670. * object = { 'a': array, 'b': array, 'c': array };
  14671. *
  14672. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14673. * // => [2, 0]
  14674. *
  14675. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14676. * // => [2, 0]
  14677. */
  14678. var methodOf = baseRest(function(object, args) {
  14679. return function(path) {
  14680. return baseInvoke(object, path, args);
  14681. };
  14682. });
  14683. /**
  14684. * Adds all own enumerable string keyed function properties of a source
  14685. * object to the destination object. If `object` is a function, then methods
  14686. * are added to its prototype as well.
  14687. *
  14688. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14689. * avoid conflicts caused by modifying the original.
  14690. *
  14691. * @static
  14692. * @since 0.1.0
  14693. * @memberOf _
  14694. * @category Util
  14695. * @param {Function|Object} [object=lodash] The destination object.
  14696. * @param {Object} source The object of functions to add.
  14697. * @param {Object} [options={}] The options object.
  14698. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14699. * @returns {Function|Object} Returns `object`.
  14700. * @example
  14701. *
  14702. * function vowels(string) {
  14703. * return _.filter(string, function(v) {
  14704. * return /[aeiou]/i.test(v);
  14705. * });
  14706. * }
  14707. *
  14708. * _.mixin({ 'vowels': vowels });
  14709. * _.vowels('fred');
  14710. * // => ['e']
  14711. *
  14712. * _('fred').vowels().value();
  14713. * // => ['e']
  14714. *
  14715. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14716. * _('fred').vowels();
  14717. * // => ['e']
  14718. */
  14719. function mixin(object, source, options) {
  14720. var props = keys(source),
  14721. methodNames = baseFunctions(source, props);
  14722. if (options == null &&
  14723. !(isObject(source) && (methodNames.length || !props.length))) {
  14724. options = source;
  14725. source = object;
  14726. object = this;
  14727. methodNames = baseFunctions(source, keys(source));
  14728. }
  14729. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14730. isFunc = isFunction(object);
  14731. arrayEach(methodNames, function(methodName) {
  14732. var func = source[methodName];
  14733. object[methodName] = func;
  14734. if (isFunc) {
  14735. object.prototype[methodName] = function() {
  14736. var chainAll = this.__chain__;
  14737. if (chain ||