3 * Lodash <https://lodash.com/>
4 * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
5 * Released under MIT license <https://lodash.com/license>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
14 /** Used as the semantic version number. */
15 var VERSION = '4.17.21';
17 /** Used as the size to enable large array optimizations. */
18 var LARGE_ARRAY_SIZE = 200;
20 /** Error message constants. */
21 var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
22 FUNC_ERROR_TEXT = 'Expected a function',
23 INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
25 /** Used to stand-in for `undefined` hash values. */
26 var HASH_UNDEFINED = '__lodash_hash_undefined__';
28 /** Used as the maximum memoize cache size. */
29 var MAX_MEMOIZE_SIZE = 500;
31 /** Used as the internal argument placeholder. */
32 var PLACEHOLDER = '__lodash_placeholder__';
34 /** Used to compose bitmasks for cloning. */
35 var CLONE_DEEP_FLAG = 1,
37 CLONE_SYMBOLS_FLAG = 4;
39 /** Used to compose bitmasks for value comparisons. */
40 var COMPARE_PARTIAL_FLAG = 1,
41 COMPARE_UNORDERED_FLAG = 2;
43 /** Used to compose bitmasks for function metadata. */
44 var WRAP_BIND_FLAG = 1,
45 WRAP_BIND_KEY_FLAG = 2,
46 WRAP_CURRY_BOUND_FLAG = 4,
48 WRAP_CURRY_RIGHT_FLAG = 16,
49 WRAP_PARTIAL_FLAG = 32,
50 WRAP_PARTIAL_RIGHT_FLAG = 64,
52 WRAP_REARG_FLAG = 256,
55 /** Used as default options for `_.truncate`. */
56 var DEFAULT_TRUNC_LENGTH = 30,
57 DEFAULT_TRUNC_OMISSION = '...';
59 /** Used to detect hot functions by number of calls within a span of milliseconds. */
63 /** Used to indicate the type of lazy iteratees. */
64 var LAZY_FILTER_FLAG = 1,
68 /** Used as references for various `Number` constants. */
70 MAX_SAFE_INTEGER = 9007199254740991,
71 MAX_INTEGER = 1.7976931348623157e+308,
74 /** Used as references for the maximum length and index of an array. */
75 var MAX_ARRAY_LENGTH = 4294967295,
76 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
77 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
79 /** Used to associate wrap methods with their bit flags. */
81 ['ary', WRAP_ARY_FLAG],
82 ['bind', WRAP_BIND_FLAG],
83 ['bindKey', WRAP_BIND_KEY_FLAG],
84 ['curry', WRAP_CURRY_FLAG],
85 ['curryRight', WRAP_CURRY_RIGHT_FLAG],
86 ['flip', WRAP_FLIP_FLAG],
87 ['partial', WRAP_PARTIAL_FLAG],
88 ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
89 ['rearg', WRAP_REARG_FLAG]
92 /** `Object#toString` result references. */
93 var argsTag = '[object Arguments]',
94 arrayTag = '[object Array]',
95 asyncTag = '[object AsyncFunction]',
96 boolTag = '[object Boolean]',
97 dateTag = '[object Date]',
98 domExcTag = '[object DOMException]',
99 errorTag = '[object Error]',
100 funcTag = '[object Function]',
101 genTag = '[object GeneratorFunction]',
102 mapTag = '[object Map]',
103 numberTag = '[object Number]',
104 nullTag = '[object Null]',
105 objectTag = '[object Object]',
106 promiseTag = '[object Promise]',
107 proxyTag = '[object Proxy]',
108 regexpTag = '[object RegExp]',
109 setTag = '[object Set]',
110 stringTag = '[object String]',
111 symbolTag = '[object Symbol]',
112 undefinedTag = '[object Undefined]',
113 weakMapTag = '[object WeakMap]',
114 weakSetTag = '[object WeakSet]';
116 var arrayBufferTag = '[object ArrayBuffer]',
117 dataViewTag = '[object DataView]',
118 float32Tag = '[object Float32Array]',
119 float64Tag = '[object Float64Array]',
120 int8Tag = '[object Int8Array]',
121 int16Tag = '[object Int16Array]',
122 int32Tag = '[object Int32Array]',
123 uint8Tag = '[object Uint8Array]',
124 uint8ClampedTag = '[object Uint8ClampedArray]',
125 uint16Tag = '[object Uint16Array]',
126 uint32Tag = '[object Uint32Array]';
128 /** Used to match empty string literals in compiled template source. */
129 var reEmptyStringLeading = /\b__p \+= '';/g,
130 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
131 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
133 /** Used to match HTML entities and HTML characters. */
134 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
135 reUnescapedHtml = /[&<>"']/g,
136 reHasEscapedHtml = RegExp(reEscapedHtml.source),
137 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
139 /** Used to match template delimiters. */
140 var reEscape = /<%-([\s\S]+?)%>/g,
141 reEvaluate = /<%([\s\S]+?)%>/g,
142 reInterpolate = /<%=([\s\S]+?)%>/g;
144 /** Used to match property names within property paths. */
145 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
146 reIsPlainProp = /^\w*$/,
147 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
150 * Used to match `RegExp`
151 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
153 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
154 reHasRegExpChar = RegExp(reRegExpChar.source);
156 /** Used to match leading whitespace. */
157 var reTrimStart = /^\s+/;
159 /** Used to match a single whitespace character. */
160 var reWhitespace = /\s/;
162 /** Used to match wrap detail comments. */
163 var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
164 reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
165 reSplitDetails = /,? & /;
167 /** Used to match words composed of alphanumeric characters. */
168 var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
171 * Used to validate the `validate` option in `_.template` variable.
173 * Forbids characters which could potentially change the meaning of the function argument definition:
174 * - "()," (modification of function parameters)
175 * - "=" (default value)
176 * - "[]{}" (destructuring of function parameters)
177 * - "/" (beginning of a comment)
180 var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
182 /** Used to match backslashes in property paths. */
183 var reEscapeChar = /\\(\\)?/g;
187 * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
189 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
191 /** Used to match `RegExp` flags from their coerced string values. */
192 var reFlags = /\w*$/;
194 /** Used to detect bad signed hexadecimal string values. */
195 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
197 /** Used to detect binary string values. */
198 var reIsBinary = /^0b[01]+$/i;
200 /** Used to detect host constructors (Safari). */
201 var reIsHostCtor = /^\[object .+?Constructor\]$/;
203 /** Used to detect octal string values. */
204 var reIsOctal = /^0o[0-7]+$/i;
206 /** Used to detect unsigned integer values. */
207 var reIsUint = /^(?:0|[1-9]\d*)$/;
209 /** Used to match Latin Unicode letters (excluding mathematical operators). */
210 var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
212 /** Used to ensure capturing order of template delimiters. */
213 var reNoMatch = /($^)/;
215 /** Used to match unescaped characters in compiled string literals. */
216 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
218 /** Used to compose unicode character classes. */
219 var rsAstralRange = '\\ud800-\\udfff',
220 rsComboMarksRange = '\\u0300-\\u036f',
221 reComboHalfMarksRange = '\\ufe20-\\ufe2f',
222 rsComboSymbolsRange = '\\u20d0-\\u20ff',
223 rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
224 rsDingbatRange = '\\u2700-\\u27bf',
225 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
226 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
227 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
228 rsPunctuationRange = '\\u2000-\\u206f',
229 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',
230 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
231 rsVarRange = '\\ufe0e\\ufe0f',
232 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
234 /** Used to compose unicode capture groups. */
235 var rsApos = "['\u2019]",
236 rsAstral = '[' + rsAstralRange + ']',
237 rsBreak = '[' + rsBreakRange + ']',
238 rsCombo = '[' + rsComboRange + ']',
240 rsDingbat = '[' + rsDingbatRange + ']',
241 rsLower = '[' + rsLowerRange + ']',
242 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
243 rsFitz = '\\ud83c[\\udffb-\\udfff]',
244 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
245 rsNonAstral = '[^' + rsAstralRange + ']',
246 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
247 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
248 rsUpper = '[' + rsUpperRange + ']',
251 /** Used to compose unicode regexes. */
252 var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
253 rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
254 rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
255 rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
256 reOptMod = rsModifier + '?',
257 rsOptVar = '[' + rsVarRange + ']?',
258 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
259 rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
260 rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
261 rsSeq = rsOptVar + reOptMod + rsOptJoin,
262 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
263 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
265 /** Used to match apostrophes. */
266 var reApos = RegExp(rsApos, 'g');
269 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
270 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
272 var reComboMark = RegExp(rsCombo, 'g');
274 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
275 var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
277 /** Used to match complex or compound words. */
278 var reUnicodeWord = RegExp([
279 rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
280 rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
281 rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
282 rsUpper + '+' + rsOptContrUpper,
289 /** 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/). */
290 var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
292 /** Used to detect strings that need a more robust regexp to match words. */
293 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 ]/;
295 /** Used to assign default `context` object properties. */
297 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
298 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
299 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
300 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
301 '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
304 /** Used to make template sourceURLs easier to identify. */
305 var templateCounter = -1;
307 /** Used to identify `toStringTag` values of typed arrays. */
308 var typedArrayTags = {};
309 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
310 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
311 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
312 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
313 typedArrayTags[uint32Tag] = true;
314 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
315 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
316 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
317 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
318 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
319 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
320 typedArrayTags[setTag] = typedArrayTags[stringTag] =
321 typedArrayTags[weakMapTag] = false;
323 /** Used to identify `toStringTag` values supported by `_.clone`. */
324 var cloneableTags = {};
325 cloneableTags[argsTag] = cloneableTags[arrayTag] =
326 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
327 cloneableTags[boolTag] = cloneableTags[dateTag] =
328 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
329 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
330 cloneableTags[int32Tag] = cloneableTags[mapTag] =
331 cloneableTags[numberTag] = cloneableTags[objectTag] =
332 cloneableTags[regexpTag] = cloneableTags[setTag] =
333 cloneableTags[stringTag] = cloneableTags[symbolTag] =
334 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
335 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
336 cloneableTags[errorTag] = cloneableTags[funcTag] =
337 cloneableTags[weakMapTag] = false;
339 /** Used to map Latin Unicode letters to basic Latin letters. */
340 var deburredLetters = {
341 // Latin-1 Supplement block.
342 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
343 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
344 '\xc7': 'C', '\xe7': 'c',
345 '\xd0': 'D', '\xf0': 'd',
346 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
347 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
348 '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
349 '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
350 '\xd1': 'N', '\xf1': 'n',
351 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
352 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
353 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
354 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
355 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
356 '\xc6': 'Ae', '\xe6': 'ae',
357 '\xde': 'Th', '\xfe': 'th',
359 // Latin Extended-A block.
360 '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
361 '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
362 '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
363 '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
364 '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
365 '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
366 '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
367 '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
368 '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
369 '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
370 '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
371 '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
372 '\u0134': 'J', '\u0135': 'j',
373 '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
374 '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
375 '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
376 '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
377 '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
378 '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
379 '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
380 '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
381 '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
382 '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
383 '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
384 '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
385 '\u0163': 't', '\u0165': 't', '\u0167': 't',
386 '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
387 '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
388 '\u0174': 'W', '\u0175': 'w',
389 '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
390 '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
391 '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
392 '\u0132': 'IJ', '\u0133': 'ij',
393 '\u0152': 'Oe', '\u0153': 'oe',
394 '\u0149': "'n", '\u017f': 's'
397 /** Used to map characters to HTML entities. */
406 /** Used to map HTML entities to characters. */
407 var htmlUnescapes = {
415 /** Used to escape characters for inclusion in compiled string literals. */
416 var stringEscapes = {
425 /** Built-in method references without a dependency on `root`. */
426 var freeParseFloat = parseFloat,
427 freeParseInt = parseInt;
429 /** Detect free variable `global` from Node.js. */
430 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
432 /** Detect free variable `self`. */
433 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
435 /** Used as a reference to the global object. */
436 var root = freeGlobal || freeSelf || Function('return this')();
438 /** Detect free variable `exports`. */
439 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
441 /** Detect free variable `module`. */
442 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
444 /** Detect the popular CommonJS extension `module.exports`. */
445 var moduleExports = freeModule && freeModule.exports === freeExports;
447 /** Detect free variable `process` from Node.js. */
448 var freeProcess = moduleExports && freeGlobal.process;
450 /** Used to access faster Node.js helpers. */
451 var nodeUtil = (function() {
453 // Use `util.types` for Node.js 10+.
454 var types = freeModule && freeModule.require && freeModule.require('util').types;
460 // Legacy `process.binding('util')` for Node.js < 10.
461 return freeProcess && freeProcess.binding && freeProcess.binding('util');
465 /* Node.js helper references. */
466 var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
467 nodeIsDate = nodeUtil && nodeUtil.isDate,
468 nodeIsMap = nodeUtil && nodeUtil.isMap,
469 nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
470 nodeIsSet = nodeUtil && nodeUtil.isSet,
471 nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
473 /*--------------------------------------------------------------------------*/
476 * A faster alternative to `Function#apply`, this function invokes `func`
477 * with the `this` binding of `thisArg` and the arguments of `args`.
480 * @param {Function} func The function to invoke.
481 * @param {*} thisArg The `this` binding of `func`.
482 * @param {Array} args The arguments to invoke `func` with.
483 * @returns {*} Returns the result of `func`.
485 function apply(func, thisArg, args) {
486 switch (args.length) {
487 case 0: return func.call(thisArg);
488 case 1: return func.call(thisArg, args[0]);
489 case 2: return func.call(thisArg, args[0], args[1]);
490 case 3: return func.call(thisArg, args[0], args[1], args[2]);
492 return func.apply(thisArg, args);
496 * A specialized version of `baseAggregator` for arrays.
499 * @param {Array} [array] The array to iterate over.
500 * @param {Function} setter The function to set `accumulator` values.
501 * @param {Function} iteratee The iteratee to transform keys.
502 * @param {Object} accumulator The initial aggregated object.
503 * @returns {Function} Returns `accumulator`.
505 function arrayAggregator(array, setter, iteratee, accumulator) {
507 length = array == null ? 0 : array.length;
509 while (++index < length) {
510 var value = array[index];
511 setter(accumulator, value, iteratee(value), array);
517 * A specialized version of `_.forEach` for arrays without support for
518 * iteratee shorthands.
521 * @param {Array} [array] The array to iterate over.
522 * @param {Function} iteratee The function invoked per iteration.
523 * @returns {Array} Returns `array`.
525 function arrayEach(array, iteratee) {
527 length = array == null ? 0 : array.length;
529 while (++index < length) {
530 if (iteratee(array[index], index, array) === false) {
538 * A specialized version of `_.forEachRight` for arrays without support for
539 * iteratee shorthands.
542 * @param {Array} [array] The array to iterate over.
543 * @param {Function} iteratee The function invoked per iteration.
544 * @returns {Array} Returns `array`.
546 function arrayEachRight(array, iteratee) {
547 var length = array == null ? 0 : array.length;
550 if (iteratee(array[length], length, array) === false) {
558 * A specialized version of `_.every` for arrays without support for
559 * iteratee shorthands.
562 * @param {Array} [array] The array to iterate over.
563 * @param {Function} predicate The function invoked per iteration.
564 * @returns {boolean} Returns `true` if all elements pass the predicate check,
567 function arrayEvery(array, predicate) {
569 length = array == null ? 0 : array.length;
571 while (++index < length) {
572 if (!predicate(array[index], index, array)) {
580 * A specialized version of `_.filter` for arrays without support for
581 * iteratee shorthands.
584 * @param {Array} [array] The array to iterate over.
585 * @param {Function} predicate The function invoked per iteration.
586 * @returns {Array} Returns the new filtered array.
588 function arrayFilter(array, predicate) {
590 length = array == null ? 0 : array.length,
594 while (++index < length) {
595 var value = array[index];
596 if (predicate(value, index, array)) {
597 result[resIndex++] = value;
604 * A specialized version of `_.includes` for arrays without support for
605 * specifying an index to search from.
608 * @param {Array} [array] The array to inspect.
609 * @param {*} target The value to search for.
610 * @returns {boolean} Returns `true` if `target` is found, else `false`.
612 function arrayIncludes(array, value) {
613 var length = array == null ? 0 : array.length;
614 return !!length && baseIndexOf(array, value, 0) > -1;
618 * This function is like `arrayIncludes` except that it accepts a comparator.
621 * @param {Array} [array] The array to inspect.
622 * @param {*} target The value to search for.
623 * @param {Function} comparator The comparator invoked per element.
624 * @returns {boolean} Returns `true` if `target` is found, else `false`.
626 function arrayIncludesWith(array, value, comparator) {
628 length = array == null ? 0 : array.length;
630 while (++index < length) {
631 if (comparator(value, array[index])) {
639 * A specialized version of `_.map` for arrays without support for iteratee
643 * @param {Array} [array] The array to iterate over.
644 * @param {Function} iteratee The function invoked per iteration.
645 * @returns {Array} Returns the new mapped array.
647 function arrayMap(array, iteratee) {
649 length = array == null ? 0 : array.length,
650 result = Array(length);
652 while (++index < length) {
653 result[index] = iteratee(array[index], index, array);
659 * Appends the elements of `values` to `array`.
662 * @param {Array} array The array to modify.
663 * @param {Array} values The values to append.
664 * @returns {Array} Returns `array`.
666 function arrayPush(array, values) {
668 length = values.length,
669 offset = array.length;
671 while (++index < length) {
672 array[offset + index] = values[index];
678 * A specialized version of `_.reduce` for arrays without support for
679 * iteratee shorthands.
682 * @param {Array} [array] The array to iterate over.
683 * @param {Function} iteratee The function invoked per iteration.
684 * @param {*} [accumulator] The initial value.
685 * @param {boolean} [initAccum] Specify using the first element of `array` as
687 * @returns {*} Returns the accumulated value.
689 function arrayReduce(array, iteratee, accumulator, initAccum) {
691 length = array == null ? 0 : array.length;
693 if (initAccum && length) {
694 accumulator = array[++index];
696 while (++index < length) {
697 accumulator = iteratee(accumulator, array[index], index, array);
703 * A specialized version of `_.reduceRight` for arrays without support for
704 * iteratee shorthands.
707 * @param {Array} [array] The array to iterate over.
708 * @param {Function} iteratee The function invoked per iteration.
709 * @param {*} [accumulator] The initial value.
710 * @param {boolean} [initAccum] Specify using the last element of `array` as
712 * @returns {*} Returns the accumulated value.
714 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
715 var length = array == null ? 0 : array.length;
716 if (initAccum && length) {
717 accumulator = array[--length];
720 accumulator = iteratee(accumulator, array[length], length, array);
726 * A specialized version of `_.some` for arrays without support for iteratee
730 * @param {Array} [array] The array to iterate over.
731 * @param {Function} predicate The function invoked per iteration.
732 * @returns {boolean} Returns `true` if any element passes the predicate check,
735 function arraySome(array, predicate) {
737 length = array == null ? 0 : array.length;
739 while (++index < length) {
740 if (predicate(array[index], index, array)) {
748 * Gets the size of an ASCII `string`.
751 * @param {string} string The string inspect.
752 * @returns {number} Returns the string size.
754 var asciiSize = baseProperty('length');
757 * Converts an ASCII `string` to an array.
760 * @param {string} string The string to convert.
761 * @returns {Array} Returns the converted array.
763 function asciiToArray(string) {
764 return string.split('');
768 * Splits an ASCII `string` into an array of its words.
771 * @param {string} The string to inspect.
772 * @returns {Array} Returns the words of `string`.
774 function asciiWords(string) {
775 return string.match(reAsciiWord) || [];
779 * The base implementation of methods like `_.findKey` and `_.findLastKey`,
780 * without support for iteratee shorthands, which iterates over `collection`
784 * @param {Array|Object} collection The collection to inspect.
785 * @param {Function} predicate The function invoked per iteration.
786 * @param {Function} eachFunc The function to iterate over `collection`.
787 * @returns {*} Returns the found element or its key, else `undefined`.
789 function baseFindKey(collection, predicate, eachFunc) {
791 eachFunc(collection, function(value, key, collection) {
792 if (predicate(value, key, collection)) {
801 * The base implementation of `_.findIndex` and `_.findLastIndex` without
802 * support for iteratee shorthands.
805 * @param {Array} array The array to inspect.
806 * @param {Function} predicate The function invoked per iteration.
807 * @param {number} fromIndex The index to search from.
808 * @param {boolean} [fromRight] Specify iterating from right to left.
809 * @returns {number} Returns the index of the matched value, else `-1`.
811 function baseFindIndex(array, predicate, fromIndex, fromRight) {
812 var length = array.length,
813 index = fromIndex + (fromRight ? 1 : -1);
815 while ((fromRight ? index-- : ++index < length)) {
816 if (predicate(array[index], index, array)) {
824 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
827 * @param {Array} array The array to inspect.
828 * @param {*} value The value to search for.
829 * @param {number} fromIndex The index to search from.
830 * @returns {number} Returns the index of the matched value, else `-1`.
832 function baseIndexOf(array, value, fromIndex) {
833 return value === value
834 ? strictIndexOf(array, value, fromIndex)
835 : baseFindIndex(array, baseIsNaN, fromIndex);
839 * This function is like `baseIndexOf` except that it accepts a comparator.
842 * @param {Array} array The array to inspect.
843 * @param {*} value The value to search for.
844 * @param {number} fromIndex The index to search from.
845 * @param {Function} comparator The comparator invoked per element.
846 * @returns {number} Returns the index of the matched value, else `-1`.
848 function baseIndexOfWith(array, value, fromIndex, comparator) {
849 var index = fromIndex - 1,
850 length = array.length;
852 while (++index < length) {
853 if (comparator(array[index], value)) {
861 * The base implementation of `_.isNaN` without support for number objects.
864 * @param {*} value The value to check.
865 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
867 function baseIsNaN(value) {
868 return value !== value;
872 * The base implementation of `_.mean` and `_.meanBy` without support for
873 * iteratee shorthands.
876 * @param {Array} array The array to iterate over.
877 * @param {Function} iteratee The function invoked per iteration.
878 * @returns {number} Returns the mean.
880 function baseMean(array, iteratee) {
881 var length = array == null ? 0 : array.length;
882 return length ? (baseSum(array, iteratee) / length) : NAN;
886 * The base implementation of `_.property` without support for deep paths.
889 * @param {string} key The key of the property to get.
890 * @returns {Function} Returns the new accessor function.
892 function baseProperty(key) {
893 return function(object) {
894 return object == null ? undefined : object[key];
899 * The base implementation of `_.propertyOf` without support for deep paths.
902 * @param {Object} object The object to query.
903 * @returns {Function} Returns the new accessor function.
905 function basePropertyOf(object) {
906 return function(key) {
907 return object == null ? undefined : object[key];
912 * The base implementation of `_.reduce` and `_.reduceRight`, without support
913 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
916 * @param {Array|Object} collection The collection to iterate over.
917 * @param {Function} iteratee The function invoked per iteration.
918 * @param {*} accumulator The initial value.
919 * @param {boolean} initAccum Specify using the first or last element of
920 * `collection` as the initial value.
921 * @param {Function} eachFunc The function to iterate over `collection`.
922 * @returns {*} Returns the accumulated value.
924 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
925 eachFunc(collection, function(value, index, collection) {
926 accumulator = initAccum
927 ? (initAccum = false, value)
928 : iteratee(accumulator, value, index, collection);
934 * The base implementation of `_.sortBy` which uses `comparer` to define the
935 * sort order of `array` and replaces criteria objects with their corresponding
939 * @param {Array} array The array to sort.
940 * @param {Function} comparer The function to define sort order.
941 * @returns {Array} Returns `array`.
943 function baseSortBy(array, comparer) {
944 var length = array.length;
946 array.sort(comparer);
948 array[length] = array[length].value;
954 * The base implementation of `_.sum` and `_.sumBy` without support for
955 * iteratee shorthands.
958 * @param {Array} array The array to iterate over.
959 * @param {Function} iteratee The function invoked per iteration.
960 * @returns {number} Returns the sum.
962 function baseSum(array, iteratee) {
965 length = array.length;
967 while (++index < length) {
968 var current = iteratee(array[index]);
969 if (current !== undefined) {
970 result = result === undefined ? current : (result + current);
977 * The base implementation of `_.times` without support for iteratee shorthands
978 * or max array length checks.
981 * @param {number} n The number of times to invoke `iteratee`.
982 * @param {Function} iteratee The function invoked per iteration.
983 * @returns {Array} Returns the array of results.
985 function baseTimes(n, iteratee) {
989 while (++index < n) {
990 result[index] = iteratee(index);
996 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
997 * of key-value pairs for `object` corresponding to the property names of `props`.
1000 * @param {Object} object The object to query.
1001 * @param {Array} props The property names to get values for.
1002 * @returns {Object} Returns the key-value pairs.
1004 function baseToPairs(object, props) {
1005 return arrayMap(props, function(key) {
1006 return [key, object[key]];
1011 * The base implementation of `_.trim`.
1014 * @param {string} string The string to trim.
1015 * @returns {string} Returns the trimmed string.
1017 function baseTrim(string) {
1019 ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
1024 * The base implementation of `_.unary` without support for storing metadata.
1027 * @param {Function} func The function to cap arguments for.
1028 * @returns {Function} Returns the new capped function.
1030 function baseUnary(func) {
1031 return function(value) {
1037 * The base implementation of `_.values` and `_.valuesIn` which creates an
1038 * array of `object` property values corresponding to the property names
1042 * @param {Object} object The object to query.
1043 * @param {Array} props The property names to get values for.
1044 * @returns {Object} Returns the array of property values.
1046 function baseValues(object, props) {
1047 return arrayMap(props, function(key) {
1053 * Checks if a `cache` value for `key` exists.
1056 * @param {Object} cache The cache to query.
1057 * @param {string} key The key of the entry to check.
1058 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1060 function cacheHas(cache, key) {
1061 return cache.has(key);
1065 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
1066 * that is not found in the character symbols.
1069 * @param {Array} strSymbols The string symbols to inspect.
1070 * @param {Array} chrSymbols The character symbols to find.
1071 * @returns {number} Returns the index of the first unmatched string symbol.
1073 function charsStartIndex(strSymbols, chrSymbols) {
1075 length = strSymbols.length;
1077 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1082 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
1083 * that is not found in the character symbols.
1086 * @param {Array} strSymbols The string symbols to inspect.
1087 * @param {Array} chrSymbols The character symbols to find.
1088 * @returns {number} Returns the index of the last unmatched string symbol.
1090 function charsEndIndex(strSymbols, chrSymbols) {
1091 var index = strSymbols.length;
1093 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1098 * Gets the number of `placeholder` occurrences in `array`.
1101 * @param {Array} array The array to inspect.
1102 * @param {*} placeholder The placeholder to search for.
1103 * @returns {number} Returns the placeholder count.
1105 function countHolders(array, placeholder) {
1106 var length = array.length,
1110 if (array[length] === placeholder) {
1118 * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
1119 * letters to basic Latin letters.
1122 * @param {string} letter The matched letter to deburr.
1123 * @returns {string} Returns the deburred letter.
1125 var deburrLetter = basePropertyOf(deburredLetters);
1128 * Used by `_.escape` to convert characters to HTML entities.
1131 * @param {string} chr The matched character to escape.
1132 * @returns {string} Returns the escaped character.
1134 var escapeHtmlChar = basePropertyOf(htmlEscapes);
1137 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1140 * @param {string} chr The matched character to escape.
1141 * @returns {string} Returns the escaped character.
1143 function escapeStringChar(chr) {
1144 return '\\' + stringEscapes[chr];
1148 * Gets the value at `key` of `object`.
1151 * @param {Object} [object] The object to query.
1152 * @param {string} key The key of the property to get.
1153 * @returns {*} Returns the property value.
1155 function getValue(object, key) {
1156 return object == null ? undefined : object[key];
1160 * Checks if `string` contains Unicode symbols.
1163 * @param {string} string The string to inspect.
1164 * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1166 function hasUnicode(string) {
1167 return reHasUnicode.test(string);
1171 * Checks if `string` contains a word composed of Unicode symbols.
1174 * @param {string} string The string to inspect.
1175 * @returns {boolean} Returns `true` if a word is found, else `false`.
1177 function hasUnicodeWord(string) {
1178 return reHasUnicodeWord.test(string);
1182 * Converts `iterator` to an array.
1185 * @param {Object} iterator The iterator to convert.
1186 * @returns {Array} Returns the converted array.
1188 function iteratorToArray(iterator) {
1192 while (!(data = iterator.next()).done) {
1193 result.push(data.value);
1199 * Converts `map` to its key-value pairs.
1202 * @param {Object} map The map to convert.
1203 * @returns {Array} Returns the key-value pairs.
1205 function mapToArray(map) {
1207 result = Array(map.size);
1209 map.forEach(function(value, key) {
1210 result[++index] = [key, value];
1216 * Creates a unary function that invokes `func` with its argument transformed.
1219 * @param {Function} func The function to wrap.
1220 * @param {Function} transform The argument transform.
1221 * @returns {Function} Returns the new function.
1223 function overArg(func, transform) {
1224 return function(arg) {
1225 return func(transform(arg));
1230 * Replaces all `placeholder` elements in `array` with an internal placeholder
1231 * and returns an array of their indexes.
1234 * @param {Array} array The array to modify.
1235 * @param {*} placeholder The placeholder to replace.
1236 * @returns {Array} Returns the new array of placeholder indexes.
1238 function replaceHolders(array, placeholder) {
1240 length = array.length,
1244 while (++index < length) {
1245 var value = array[index];
1246 if (value === placeholder || value === PLACEHOLDER) {
1247 array[index] = PLACEHOLDER;
1248 result[resIndex++] = index;
1255 * Converts `set` to an array of its values.
1258 * @param {Object} set The set to convert.
1259 * @returns {Array} Returns the values.
1261 function setToArray(set) {
1263 result = Array(set.size);
1265 set.forEach(function(value) {
1266 result[++index] = value;
1272 * Converts `set` to its value-value pairs.
1275 * @param {Object} set The set to convert.
1276 * @returns {Array} Returns the value-value pairs.
1278 function setToPairs(set) {
1280 result = Array(set.size);
1282 set.forEach(function(value) {
1283 result[++index] = [value, value];
1289 * A specialized version of `_.indexOf` which performs strict equality
1290 * comparisons of values, i.e. `===`.
1293 * @param {Array} array The array to inspect.
1294 * @param {*} value The value to search for.
1295 * @param {number} fromIndex The index to search from.
1296 * @returns {number} Returns the index of the matched value, else `-1`.
1298 function strictIndexOf(array, value, fromIndex) {
1299 var index = fromIndex - 1,
1300 length = array.length;
1302 while (++index < length) {
1303 if (array[index] === value) {
1311 * A specialized version of `_.lastIndexOf` which performs strict equality
1312 * comparisons of values, i.e. `===`.
1315 * @param {Array} array The array to inspect.
1316 * @param {*} value The value to search for.
1317 * @param {number} fromIndex The index to search from.
1318 * @returns {number} Returns the index of the matched value, else `-1`.
1320 function strictLastIndexOf(array, value, fromIndex) {
1321 var index = fromIndex + 1;
1323 if (array[index] === value) {
1331 * Gets the number of symbols in `string`.
1334 * @param {string} string The string to inspect.
1335 * @returns {number} Returns the string size.
1337 function stringSize(string) {
1338 return hasUnicode(string)
1339 ? unicodeSize(string)
1340 : asciiSize(string);
1344 * Converts `string` to an array.
1347 * @param {string} string The string to convert.
1348 * @returns {Array} Returns the converted array.
1350 function stringToArray(string) {
1351 return hasUnicode(string)
1352 ? unicodeToArray(string)
1353 : asciiToArray(string);
1357 * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
1358 * character of `string`.
1361 * @param {string} string The string to inspect.
1362 * @returns {number} Returns the index of the last non-whitespace character.
1364 function trimmedEndIndex(string) {
1365 var index = string.length;
1367 while (index-- && reWhitespace.test(string.charAt(index))) {}
1372 * Used by `_.unescape` to convert HTML entities to characters.
1375 * @param {string} chr The matched character to unescape.
1376 * @returns {string} Returns the unescaped character.
1378 var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
1381 * Gets the size of a Unicode `string`.
1384 * @param {string} string The string inspect.
1385 * @returns {number} Returns the string size.
1387 function unicodeSize(string) {
1388 var result = reUnicode.lastIndex = 0;
1389 while (reUnicode.test(string)) {
1396 * Converts a Unicode `string` to an array.
1399 * @param {string} string The string to convert.
1400 * @returns {Array} Returns the converted array.
1402 function unicodeToArray(string) {
1403 return string.match(reUnicode) || [];
1407 * Splits a Unicode `string` into an array of its words.
1410 * @param {string} The string to inspect.
1411 * @returns {Array} Returns the words of `string`.
1413 function unicodeWords(string) {
1414 return string.match(reUnicodeWord) || [];
1417 /*--------------------------------------------------------------------------*/
1420 * Create a new pristine `lodash` function using the `context` object.
1426 * @param {Object} [context=root] The context object.
1427 * @returns {Function} Returns a new `lodash` function.
1430 * _.mixin({ 'foo': _.constant('foo') });
1432 * var lodash = _.runInContext();
1433 * lodash.mixin({ 'bar': lodash.constant('bar') });
1435 * _.isFunction(_.foo);
1437 * _.isFunction(_.bar);
1440 * lodash.isFunction(lodash.foo);
1442 * lodash.isFunction(lodash.bar);
1445 * // Create a suped-up `defer` in Node.js.
1446 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1448 var runInContext = (function runInContext(context) {
1449 context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
1451 /** Built-in constructor references. */
1452 var Array = context.Array,
1453 Date = context.Date,
1454 Error = context.Error,
1455 Function = context.Function,
1456 Math = context.Math,
1457 Object = context.Object,
1458 RegExp = context.RegExp,
1459 String = context.String,
1460 TypeError = context.TypeError;
1462 /** Used for built-in method references. */
1463 var arrayProto = Array.prototype,
1464 funcProto = Function.prototype,
1465 objectProto = Object.prototype;
1467 /** Used to detect overreaching core-js shims. */
1468 var coreJsData = context['__core-js_shared__'];
1470 /** Used to resolve the decompiled source of functions. */
1471 var funcToString = funcProto.toString;
1473 /** Used to check objects for own properties. */
1474 var hasOwnProperty = objectProto.hasOwnProperty;
1476 /** Used to generate unique IDs. */
1479 /** Used to detect methods masquerading as native. */
1480 var maskSrcKey = (function() {
1481 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
1482 return uid ? ('Symbol(src)_1.' + uid) : '';
1486 * Used to resolve the
1487 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
1490 var nativeObjectToString = objectProto.toString;
1492 /** Used to infer the `Object` constructor. */
1493 var objectCtorString = funcToString.call(Object);
1495 /** Used to restore the original `_` reference in `_.noConflict`. */
1496 var oldDash = root._;
1498 /** Used to detect if a method is native. */
1499 var reIsNative = RegExp('^' +
1500 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1501 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1504 /** Built-in value references. */
1505 var Buffer = moduleExports ? context.Buffer : undefined,
1506 Symbol = context.Symbol,
1507 Uint8Array = context.Uint8Array,
1508 allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
1509 getPrototype = overArg(Object.getPrototypeOf, Object),
1510 objectCreate = Object.create,
1511 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1512 splice = arrayProto.splice,
1513 spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
1514 symIterator = Symbol ? Symbol.iterator : undefined,
1515 symToStringTag = Symbol ? Symbol.toStringTag : undefined;
1517 var defineProperty = (function() {
1519 var func = getNative(Object, 'defineProperty');
1525 /** Mocked built-ins. */
1526 var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
1527 ctxNow = Date && Date.now !== root.Date.now && Date.now,
1528 ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1530 /* Built-in method references for those with the same name as other `lodash` methods. */
1531 var nativeCeil = Math.ceil,
1532 nativeFloor = Math.floor,
1533 nativeGetSymbols = Object.getOwnPropertySymbols,
1534 nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
1535 nativeIsFinite = context.isFinite,
1536 nativeJoin = arrayProto.join,
1537 nativeKeys = overArg(Object.keys, Object),
1538 nativeMax = Math.max,
1539 nativeMin = Math.min,
1540 nativeNow = Date.now,
1541 nativeParseInt = context.parseInt,
1542 nativeRandom = Math.random,
1543 nativeReverse = arrayProto.reverse;
1545 /* Built-in method references that are verified to be native. */
1546 var DataView = getNative(context, 'DataView'),
1547 Map = getNative(context, 'Map'),
1548 Promise = getNative(context, 'Promise'),
1549 Set = getNative(context, 'Set'),
1550 WeakMap = getNative(context, 'WeakMap'),
1551 nativeCreate = getNative(Object, 'create');
1553 /** Used to store function metadata. */
1554 var metaMap = WeakMap && new WeakMap;
1556 /** Used to lookup unminified function names. */
1559 /** Used to detect maps, sets, and weakmaps. */
1560 var dataViewCtorString = toSource(DataView),
1561 mapCtorString = toSource(Map),
1562 promiseCtorString = toSource(Promise),
1563 setCtorString = toSource(Set),
1564 weakMapCtorString = toSource(WeakMap);
1566 /** Used to convert symbols to primitives and strings. */
1567 var symbolProto = Symbol ? Symbol.prototype : undefined,
1568 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
1569 symbolToString = symbolProto ? symbolProto.toString : undefined;
1571 /*------------------------------------------------------------------------*/
1574 * Creates a `lodash` object which wraps `value` to enable implicit method
1575 * chain sequences. Methods that operate on and return arrays, collections,
1576 * and functions can be chained together. Methods that retrieve a single value
1577 * or may return a primitive value will automatically end the chain sequence
1578 * and return the unwrapped value. Otherwise, the value must be unwrapped
1581 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
1582 * enabled using `_.chain`.
1584 * The execution of chained methods is lazy, that is, it's deferred until
1585 * `_#value` is implicitly or explicitly called.
1587 * Lazy evaluation allows several methods to support shortcut fusion.
1588 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
1589 * the creation of intermediate arrays and can greatly reduce the number of
1590 * iteratee executions. Sections of a chain sequence qualify for shortcut
1591 * fusion if the section is applied to an array and iteratees accept only
1592 * one argument. The heuristic for whether a section qualifies for shortcut
1593 * fusion is subject to change.
1595 * Chaining is supported in custom builds as long as the `_#value` method is
1596 * directly or indirectly included in the build.
1598 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1600 * The wrapper `Array` methods are:
1601 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1603 * The wrapper `String` methods are:
1604 * `replace` and `split`
1606 * The wrapper methods that support shortcut fusion are:
1607 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1608 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1609 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1611 * The chainable wrapper methods are:
1612 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
1613 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
1614 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
1615 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
1616 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
1617 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
1618 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
1619 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
1620 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
1621 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
1622 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
1623 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
1624 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
1625 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
1626 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
1627 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
1628 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
1629 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
1630 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
1631 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
1632 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
1633 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
1634 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
1635 * `zipObject`, `zipObjectDeep`, and `zipWith`
1637 * The wrapper methods that are **not** chainable by default are:
1638 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1639 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
1640 * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
1641 * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
1642 * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
1643 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
1644 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
1645 * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
1646 * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
1647 * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
1648 * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
1649 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
1650 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
1651 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
1652 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
1653 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
1654 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
1655 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
1656 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
1657 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
1658 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
1659 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
1660 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
1661 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
1662 * `upperFirst`, `value`, and `words`
1667 * @param {*} value The value to wrap in a `lodash` instance.
1668 * @returns {Object} Returns the new `lodash` wrapper instance.
1671 * function square(n) {
1675 * var wrapped = _([1, 2, 3]);
1677 * // Returns an unwrapped value.
1678 * wrapped.reduce(_.add);
1681 * // Returns a wrapped value.
1682 * var squares = wrapped.map(square);
1684 * _.isArray(squares);
1687 * _.isArray(squares.value());
1690 function lodash(value) {
1691 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1692 if (value instanceof LodashWrapper) {
1695 if (hasOwnProperty.call(value, '__wrapped__')) {
1696 return wrapperClone(value);
1699 return new LodashWrapper(value);
1703 * The base implementation of `_.create` without support for assigning
1704 * properties to the created object.
1707 * @param {Object} proto The object to inherit from.
1708 * @returns {Object} Returns the new object.
1710 var baseCreate = (function() {
1711 function object() {}
1712 return function(proto) {
1713 if (!isObject(proto)) {
1717 return objectCreate(proto);
1719 object.prototype = proto;
1720 var result = new object;
1721 object.prototype = undefined;
1727 * The function whose prototype chain sequence wrappers inherit from.
1731 function baseLodash() {
1732 // No operation performed.
1736 * The base constructor for creating `lodash` wrapper objects.
1739 * @param {*} value The value to wrap.
1740 * @param {boolean} [chainAll] Enable explicit method chain sequences.
1742 function LodashWrapper(value, chainAll) {
1743 this.__wrapped__ = value;
1744 this.__actions__ = [];
1745 this.__chain__ = !!chainAll;
1747 this.__values__ = undefined;
1751 * By default, the template delimiters used by lodash are like those in
1752 * embedded Ruby (ERB) as well as ES2015 template strings. Change the
1753 * following template settings to use alternative delimiters.
1759 lodash.templateSettings = {
1762 * Used to detect `data` property values to be HTML-escaped.
1764 * @memberOf _.templateSettings
1770 * Used to detect code to be evaluated.
1772 * @memberOf _.templateSettings
1775 'evaluate': reEvaluate,
1778 * Used to detect `data` property values to inject.
1780 * @memberOf _.templateSettings
1783 'interpolate': reInterpolate,
1786 * Used to reference the data object in the template text.
1788 * @memberOf _.templateSettings
1794 * Used to import variables into the compiled template.
1796 * @memberOf _.templateSettings
1802 * A reference to the `lodash` function.
1804 * @memberOf _.templateSettings.imports
1811 // Ensure wrappers are instances of `baseLodash`.
1812 lodash.prototype = baseLodash.prototype;
1813 lodash.prototype.constructor = lodash;
1815 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
1816 LodashWrapper.prototype.constructor = LodashWrapper;
1818 /*------------------------------------------------------------------------*/
1821 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1825 * @param {*} value The value to wrap.
1827 function LazyWrapper(value) {
1828 this.__wrapped__ = value;
1829 this.__actions__ = [];
1831 this.__filtered__ = false;
1832 this.__iteratees__ = [];
1833 this.__takeCount__ = MAX_ARRAY_LENGTH;
1834 this.__views__ = [];
1838 * Creates a clone of the lazy wrapper object.
1842 * @memberOf LazyWrapper
1843 * @returns {Object} Returns the cloned `LazyWrapper` object.
1845 function lazyClone() {
1846 var result = new LazyWrapper(this.__wrapped__);
1847 result.__actions__ = copyArray(this.__actions__);
1848 result.__dir__ = this.__dir__;
1849 result.__filtered__ = this.__filtered__;
1850 result.__iteratees__ = copyArray(this.__iteratees__);
1851 result.__takeCount__ = this.__takeCount__;
1852 result.__views__ = copyArray(this.__views__);
1857 * Reverses the direction of lazy iteration.
1861 * @memberOf LazyWrapper
1862 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1864 function lazyReverse() {
1865 if (this.__filtered__) {
1866 var result = new LazyWrapper(this);
1867 result.__dir__ = -1;
1868 result.__filtered__ = true;
1870 result = this.clone();
1871 result.__dir__ *= -1;
1877 * Extracts the unwrapped value from its lazy wrapper.
1881 * @memberOf LazyWrapper
1882 * @returns {*} Returns the unwrapped value.
1884 function lazyValue() {
1885 var array = this.__wrapped__.value(),
1887 isArr = isArray(array),
1889 arrLength = isArr ? array.length : 0,
1890 view = getView(0, arrLength, this.__views__),
1893 length = end - start,
1894 index = isRight ? end : (start - 1),
1895 iteratees = this.__iteratees__,
1896 iterLength = iteratees.length,
1898 takeCount = nativeMin(length, this.__takeCount__);
1900 if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
1901 return baseWrapperValue(array, this.__actions__);
1906 while (length-- && resIndex < takeCount) {
1910 value = array[index];
1912 while (++iterIndex < iterLength) {
1913 var data = iteratees[iterIndex],
1914 iteratee = data.iteratee,
1916 computed = iteratee(value);
1918 if (type == LAZY_MAP_FLAG) {
1920 } else if (!computed) {
1921 if (type == LAZY_FILTER_FLAG) {
1928 result[resIndex++] = value;
1933 // Ensure `LazyWrapper` is an instance of `baseLodash`.
1934 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
1935 LazyWrapper.prototype.constructor = LazyWrapper;
1937 /*------------------------------------------------------------------------*/
1940 * Creates a hash object.
1944 * @param {Array} [entries] The key-value pairs to cache.
1946 function Hash(entries) {
1948 length = entries == null ? 0 : entries.length;
1951 while (++index < length) {
1952 var entry = entries[index];
1953 this.set(entry[0], entry[1]);
1958 * Removes all key-value entries from the hash.
1964 function hashClear() {
1965 this.__data__ = nativeCreate ? nativeCreate(null) : {};
1970 * Removes `key` and its value from the hash.
1975 * @param {Object} hash The hash to modify.
1976 * @param {string} key The key of the value to remove.
1977 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1979 function hashDelete(key) {
1980 var result = this.has(key) && delete this.__data__[key];
1981 this.size -= result ? 1 : 0;
1986 * Gets the hash value for `key`.
1991 * @param {string} key The key of the value to get.
1992 * @returns {*} Returns the entry value.
1994 function hashGet(key) {
1995 var data = this.__data__;
1997 var result = data[key];
1998 return result === HASH_UNDEFINED ? undefined : result;
2000 return hasOwnProperty.call(data, key) ? data[key] : undefined;
2004 * Checks if a hash value for `key` exists.
2009 * @param {string} key The key of the entry to check.
2010 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2012 function hashHas(key) {
2013 var data = this.__data__;
2014 return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
2018 * Sets the hash `key` to `value`.
2023 * @param {string} key The key of the value to set.
2024 * @param {*} value The value to set.
2025 * @returns {Object} Returns the hash instance.
2027 function hashSet(key, value) {
2028 var data = this.__data__;
2029 this.size += this.has(key) ? 0 : 1;
2030 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
2034 // Add methods to `Hash`.
2035 Hash.prototype.clear = hashClear;
2036 Hash.prototype['delete'] = hashDelete;
2037 Hash.prototype.get = hashGet;
2038 Hash.prototype.has = hashHas;
2039 Hash.prototype.set = hashSet;
2041 /*------------------------------------------------------------------------*/
2044 * Creates an list cache object.
2048 * @param {Array} [entries] The key-value pairs to cache.
2050 function ListCache(entries) {
2052 length = entries == null ? 0 : entries.length;
2055 while (++index < length) {
2056 var entry = entries[index];
2057 this.set(entry[0], entry[1]);
2062 * Removes all key-value entries from the list cache.
2066 * @memberOf ListCache
2068 function listCacheClear() {
2074 * Removes `key` and its value from the list cache.
2078 * @memberOf ListCache
2079 * @param {string} key The key of the value to remove.
2080 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2082 function listCacheDelete(key) {
2083 var data = this.__data__,
2084 index = assocIndexOf(data, key);
2089 var lastIndex = data.length - 1;
2090 if (index == lastIndex) {
2093 splice.call(data, index, 1);
2100 * Gets the list cache value for `key`.
2104 * @memberOf ListCache
2105 * @param {string} key The key of the value to get.
2106 * @returns {*} Returns the entry value.
2108 function listCacheGet(key) {
2109 var data = this.__data__,
2110 index = assocIndexOf(data, key);
2112 return index < 0 ? undefined : data[index][1];
2116 * Checks if a list cache value for `key` exists.
2120 * @memberOf ListCache
2121 * @param {string} key The key of the entry to check.
2122 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2124 function listCacheHas(key) {
2125 return assocIndexOf(this.__data__, key) > -1;
2129 * Sets the list cache `key` to `value`.
2133 * @memberOf ListCache
2134 * @param {string} key The key of the value to set.
2135 * @param {*} value The value to set.
2136 * @returns {Object} Returns the list cache instance.
2138 function listCacheSet(key, value) {
2139 var data = this.__data__,
2140 index = assocIndexOf(data, key);
2144 data.push([key, value]);
2146 data[index][1] = value;
2151 // Add methods to `ListCache`.
2152 ListCache.prototype.clear = listCacheClear;
2153 ListCache.prototype['delete'] = listCacheDelete;
2154 ListCache.prototype.get = listCacheGet;
2155 ListCache.prototype.has = listCacheHas;
2156 ListCache.prototype.set = listCacheSet;
2158 /*------------------------------------------------------------------------*/
2161 * Creates a map cache object to store key-value pairs.
2165 * @param {Array} [entries] The key-value pairs to cache.
2167 function MapCache(entries) {
2169 length = entries == null ? 0 : entries.length;
2172 while (++index < length) {
2173 var entry = entries[index];
2174 this.set(entry[0], entry[1]);
2179 * Removes all key-value entries from the map.
2183 * @memberOf MapCache
2185 function mapCacheClear() {
2189 'map': new (Map || ListCache),
2195 * Removes `key` and its value from the map.
2199 * @memberOf MapCache
2200 * @param {string} key The key of the value to remove.
2201 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2203 function mapCacheDelete(key) {
2204 var result = getMapData(this, key)['delete'](key);
2205 this.size -= result ? 1 : 0;
2210 * Gets the map value for `key`.
2214 * @memberOf MapCache
2215 * @param {string} key The key of the value to get.
2216 * @returns {*} Returns the entry value.
2218 function mapCacheGet(key) {
2219 return getMapData(this, key).get(key);
2223 * Checks if a map value for `key` exists.
2227 * @memberOf MapCache
2228 * @param {string} key The key of the entry to check.
2229 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2231 function mapCacheHas(key) {
2232 return getMapData(this, key).has(key);
2236 * Sets the map `key` to `value`.
2240 * @memberOf MapCache
2241 * @param {string} key The key of the value to set.
2242 * @param {*} value The value to set.
2243 * @returns {Object} Returns the map cache instance.
2245 function mapCacheSet(key, value) {
2246 var data = getMapData(this, key),
2249 data.set(key, value);
2250 this.size += data.size == size ? 0 : 1;
2254 // Add methods to `MapCache`.
2255 MapCache.prototype.clear = mapCacheClear;
2256 MapCache.prototype['delete'] = mapCacheDelete;
2257 MapCache.prototype.get = mapCacheGet;
2258 MapCache.prototype.has = mapCacheHas;
2259 MapCache.prototype.set = mapCacheSet;
2261 /*------------------------------------------------------------------------*/
2265 * Creates an array cache object to store unique values.
2269 * @param {Array} [values] The values to cache.
2271 function SetCache(values) {
2273 length = values == null ? 0 : values.length;
2275 this.__data__ = new MapCache;
2276 while (++index < length) {
2277 this.add(values[index]);
2282 * Adds `value` to the array cache.
2286 * @memberOf SetCache
2288 * @param {*} value The value to cache.
2289 * @returns {Object} Returns the cache instance.
2291 function setCacheAdd(value) {
2292 this.__data__.set(value, HASH_UNDEFINED);
2297 * Checks if `value` is in the array cache.
2301 * @memberOf SetCache
2302 * @param {*} value The value to search for.
2303 * @returns {number} Returns `true` if `value` is found, else `false`.
2305 function setCacheHas(value) {
2306 return this.__data__.has(value);
2309 // Add methods to `SetCache`.
2310 SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
2311 SetCache.prototype.has = setCacheHas;
2313 /*------------------------------------------------------------------------*/
2316 * Creates a stack cache object to store key-value pairs.
2320 * @param {Array} [entries] The key-value pairs to cache.
2322 function Stack(entries) {
2323 var data = this.__data__ = new ListCache(entries);
2324 this.size = data.size;
2328 * Removes all key-value entries from the stack.
2334 function stackClear() {
2335 this.__data__ = new ListCache;
2340 * Removes `key` and its value from the stack.
2345 * @param {string} key The key of the value to remove.
2346 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2348 function stackDelete(key) {
2349 var data = this.__data__,
2350 result = data['delete'](key);
2352 this.size = data.size;
2357 * Gets the stack value for `key`.
2362 * @param {string} key The key of the value to get.
2363 * @returns {*} Returns the entry value.
2365 function stackGet(key) {
2366 return this.__data__.get(key);
2370 * Checks if a stack value for `key` exists.
2375 * @param {string} key The key of the entry to check.
2376 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2378 function stackHas(key) {
2379 return this.__data__.has(key);
2383 * Sets the stack `key` to `value`.
2388 * @param {string} key The key of the value to set.
2389 * @param {*} value The value to set.
2390 * @returns {Object} Returns the stack cache instance.
2392 function stackSet(key, value) {
2393 var data = this.__data__;
2394 if (data instanceof ListCache) {
2395 var pairs = data.__data__;
2396 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
2397 pairs.push([key, value]);
2398 this.size = ++data.size;
2401 data = this.__data__ = new MapCache(pairs);
2403 data.set(key, value);
2404 this.size = data.size;
2408 // Add methods to `Stack`.
2409 Stack.prototype.clear = stackClear;
2410 Stack.prototype['delete'] = stackDelete;
2411 Stack.prototype.get = stackGet;
2412 Stack.prototype.has = stackHas;
2413 Stack.prototype.set = stackSet;
2415 /*------------------------------------------------------------------------*/
2418 * Creates an array of the enumerable property names of the array-like `value`.
2421 * @param {*} value The value to query.
2422 * @param {boolean} inherited Specify returning inherited property names.
2423 * @returns {Array} Returns the array of property names.
2425 function arrayLikeKeys(value, inherited) {
2426 var isArr = isArray(value),
2427 isArg = !isArr && isArguments(value),
2428 isBuff = !isArr && !isArg && isBuffer(value),
2429 isType = !isArr && !isArg && !isBuff && isTypedArray(value),
2430 skipIndexes = isArr || isArg || isBuff || isType,
2431 result = skipIndexes ? baseTimes(value.length, String) : [],
2432 length = result.length;
2434 for (var key in value) {
2435 if ((inherited || hasOwnProperty.call(value, key)) &&
2437 // Safari 9 has enumerable `arguments.length` in strict mode.
2439 // Node.js 0.10 has enumerable non-index properties on buffers.
2440 (isBuff && (key == 'offset' || key == 'parent')) ||
2441 // PhantomJS 2 has enumerable non-index properties on typed arrays.
2442 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
2443 // Skip index properties.
2444 isIndex(key, length)
2453 * A specialized version of `_.sample` for arrays.
2456 * @param {Array} array The array to sample.
2457 * @returns {*} Returns the random element.
2459 function arraySample(array) {
2460 var length = array.length;
2461 return length ? array[baseRandom(0, length - 1)] : undefined;
2465 * A specialized version of `_.sampleSize` for arrays.
2468 * @param {Array} array The array to sample.
2469 * @param {number} n The number of elements to sample.
2470 * @returns {Array} Returns the random elements.
2472 function arraySampleSize(array, n) {
2473 return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
2477 * A specialized version of `_.shuffle` for arrays.
2480 * @param {Array} array The array to shuffle.
2481 * @returns {Array} Returns the new shuffled array.
2483 function arrayShuffle(array) {
2484 return shuffleSelf(copyArray(array));
2488 * This function is like `assignValue` except that it doesn't assign
2489 * `undefined` values.
2492 * @param {Object} object The object to modify.
2493 * @param {string} key The key of the property to assign.
2494 * @param {*} value The value to assign.
2496 function assignMergeValue(object, key, value) {
2497 if ((value !== undefined && !eq(object[key], value)) ||
2498 (value === undefined && !(key in object))) {
2499 baseAssignValue(object, key, value);
2504 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2505 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
2506 * for equality comparisons.
2509 * @param {Object} object The object to modify.
2510 * @param {string} key The key of the property to assign.
2511 * @param {*} value The value to assign.
2513 function assignValue(object, key, value) {
2514 var objValue = object[key];
2515 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2516 (value === undefined && !(key in object))) {
2517 baseAssignValue(object, key, value);
2522 * Gets the index at which the `key` is found in `array` of key-value pairs.
2525 * @param {Array} array The array to inspect.
2526 * @param {*} key The key to search for.
2527 * @returns {number} Returns the index of the matched value, else `-1`.
2529 function assocIndexOf(array, key) {
2530 var length = array.length;
2532 if (eq(array[length][0], key)) {
2540 * Aggregates elements of `collection` on `accumulator` with keys transformed
2541 * by `iteratee` and values set by `setter`.
2544 * @param {Array|Object} collection The collection to iterate over.
2545 * @param {Function} setter The function to set `accumulator` values.
2546 * @param {Function} iteratee The iteratee to transform keys.
2547 * @param {Object} accumulator The initial aggregated object.
2548 * @returns {Function} Returns `accumulator`.
2550 function baseAggregator(collection, setter, iteratee, accumulator) {
2551 baseEach(collection, function(value, key, collection) {
2552 setter(accumulator, value, iteratee(value), collection);
2558 * The base implementation of `_.assign` without support for multiple sources
2559 * or `customizer` functions.
2562 * @param {Object} object The destination object.
2563 * @param {Object} source The source object.
2564 * @returns {Object} Returns `object`.
2566 function baseAssign(object, source) {
2567 return object && copyObject(source, keys(source), object);
2571 * The base implementation of `_.assignIn` without support for multiple sources
2572 * or `customizer` functions.
2575 * @param {Object} object The destination object.
2576 * @param {Object} source The source object.
2577 * @returns {Object} Returns `object`.
2579 function baseAssignIn(object, source) {
2580 return object && copyObject(source, keysIn(source), object);
2584 * The base implementation of `assignValue` and `assignMergeValue` without
2588 * @param {Object} object The object to modify.
2589 * @param {string} key The key of the property to assign.
2590 * @param {*} value The value to assign.
2592 function baseAssignValue(object, key, value) {
2593 if (key == '__proto__' && defineProperty) {
2594 defineProperty(object, key, {
2595 'configurable': true,
2601 object[key] = value;
2606 * The base implementation of `_.at` without support for individual paths.
2609 * @param {Object} object The object to iterate over.
2610 * @param {string[]} paths The property paths to pick.
2611 * @returns {Array} Returns the picked elements.
2613 function baseAt(object, paths) {
2615 length = paths.length,
2616 result = Array(length),
2617 skip = object == null;
2619 while (++index < length) {
2620 result[index] = skip ? undefined : get(object, paths[index]);
2626 * The base implementation of `_.clamp` which doesn't coerce arguments.
2629 * @param {number} number The number to clamp.
2630 * @param {number} [lower] The lower bound.
2631 * @param {number} upper The upper bound.
2632 * @returns {number} Returns the clamped number.
2634 function baseClamp(number, lower, upper) {
2635 if (number === number) {
2636 if (upper !== undefined) {
2637 number = number <= upper ? number : upper;
2639 if (lower !== undefined) {
2640 number = number >= lower ? number : lower;
2647 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2648 * traversed objects.
2651 * @param {*} value The value to clone.
2652 * @param {boolean} bitmask The bitmask flags.
2654 * 2 - Flatten inherited properties
2656 * @param {Function} [customizer] The function to customize cloning.
2657 * @param {string} [key] The key of `value`.
2658 * @param {Object} [object] The parent object of `value`.
2659 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2660 * @returns {*} Returns the cloned value.
2662 function baseClone(value, bitmask, customizer, key, object, stack) {
2664 isDeep = bitmask & CLONE_DEEP_FLAG,
2665 isFlat = bitmask & CLONE_FLAT_FLAG,
2666 isFull = bitmask & CLONE_SYMBOLS_FLAG;
2669 result = object ? customizer(value, key, object, stack) : customizer(value);
2671 if (result !== undefined) {
2674 if (!isObject(value)) {
2677 var isArr = isArray(value);
2679 result = initCloneArray(value);
2681 return copyArray(value, result);
2684 var tag = getTag(value),
2685 isFunc = tag == funcTag || tag == genTag;
2687 if (isBuffer(value)) {
2688 return cloneBuffer(value, isDeep);
2690 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2691 result = (isFlat || isFunc) ? {} : initCloneObject(value);
2694 ? copySymbolsIn(value, baseAssignIn(result, value))
2695 : copySymbols(value, baseAssign(result, value));
2698 if (!cloneableTags[tag]) {
2699 return object ? value : {};
2701 result = initCloneByTag(value, tag, isDeep);
2704 // Check for circular references and return its corresponding clone.
2705 stack || (stack = new Stack);
2706 var stacked = stack.get(value);
2710 stack.set(value, result);
2713 value.forEach(function(subValue) {
2714 result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
2716 } else if (isMap(value)) {
2717 value.forEach(function(subValue, key) {
2718 result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
2722 var keysFunc = isFull
2723 ? (isFlat ? getAllKeysIn : getAllKeys)
2724 : (isFlat ? keysIn : keys);
2726 var props = isArr ? undefined : keysFunc(value);
2727 arrayEach(props || value, function(subValue, key) {
2730 subValue = value[key];
2732 // Recursively populate clone (susceptible to call stack limits).
2733 assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
2739 * The base implementation of `_.conforms` which doesn't clone `source`.
2742 * @param {Object} source The object of property predicates to conform to.
2743 * @returns {Function} Returns the new spec function.
2745 function baseConforms(source) {
2746 var props = keys(source);
2747 return function(object) {
2748 return baseConformsTo(object, source, props);
2753 * The base implementation of `_.conformsTo` which accepts `props` to check.
2756 * @param {Object} object The object to inspect.
2757 * @param {Object} source The object of property predicates to conform to.
2758 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
2760 function baseConformsTo(object, source, props) {
2761 var length = props.length;
2762 if (object == null) {
2765 object = Object(object);
2767 var key = props[length],
2768 predicate = source[key],
2769 value = object[key];
2771 if ((value === undefined && !(key in object)) || !predicate(value)) {
2779 * The base implementation of `_.delay` and `_.defer` which accepts `args`
2780 * to provide to `func`.
2783 * @param {Function} func The function to delay.
2784 * @param {number} wait The number of milliseconds to delay invocation.
2785 * @param {Array} args The arguments to provide to `func`.
2786 * @returns {number|Object} Returns the timer id or timeout object.
2788 function baseDelay(func, wait, args) {
2789 if (typeof func != 'function') {
2790 throw new TypeError(FUNC_ERROR_TEXT);
2792 return setTimeout(function() { func.apply(undefined, args); }, wait);
2796 * The base implementation of methods like `_.difference` without support
2797 * for excluding multiple arrays or iteratee shorthands.
2800 * @param {Array} array The array to inspect.
2801 * @param {Array} values The values to exclude.
2802 * @param {Function} [iteratee] The iteratee invoked per element.
2803 * @param {Function} [comparator] The comparator invoked per element.
2804 * @returns {Array} Returns the new array of filtered values.
2806 function baseDifference(array, values, iteratee, comparator) {
2808 includes = arrayIncludes,
2810 length = array.length,
2812 valuesLength = values.length;
2818 values = arrayMap(values, baseUnary(iteratee));
2821 includes = arrayIncludesWith;
2824 else if (values.length >= LARGE_ARRAY_SIZE) {
2825 includes = cacheHas;
2827 values = new SetCache(values);
2830 while (++index < length) {
2831 var value = array[index],
2832 computed = iteratee == null ? value : iteratee(value);
2834 value = (comparator || value !== 0) ? value : 0;
2835 if (isCommon && computed === computed) {
2836 var valuesIndex = valuesLength;
2837 while (valuesIndex--) {
2838 if (values[valuesIndex] === computed) {
2844 else if (!includes(values, computed, comparator)) {
2852 * The base implementation of `_.forEach` without support for iteratee shorthands.
2855 * @param {Array|Object} collection The collection to iterate over.
2856 * @param {Function} iteratee The function invoked per iteration.
2857 * @returns {Array|Object} Returns `collection`.
2859 var baseEach = createBaseEach(baseForOwn);
2862 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2865 * @param {Array|Object} collection The collection to iterate over.
2866 * @param {Function} iteratee The function invoked per iteration.
2867 * @returns {Array|Object} Returns `collection`.
2869 var baseEachRight = createBaseEach(baseForOwnRight, true);
2872 * The base implementation of `_.every` without support for iteratee shorthands.
2875 * @param {Array|Object} collection The collection to iterate over.
2876 * @param {Function} predicate The function invoked per iteration.
2877 * @returns {boolean} Returns `true` if all elements pass the predicate check,
2880 function baseEvery(collection, predicate) {
2882 baseEach(collection, function(value, index, collection) {
2883 result = !!predicate(value, index, collection);
2890 * The base implementation of methods like `_.max` and `_.min` which accepts a
2891 * `comparator` to determine the extremum value.
2894 * @param {Array} array The array to iterate over.
2895 * @param {Function} iteratee The iteratee invoked per iteration.
2896 * @param {Function} comparator The comparator used to compare values.
2897 * @returns {*} Returns the extremum value.
2899 function baseExtremum(array, iteratee, comparator) {
2901 length = array.length;
2903 while (++index < length) {
2904 var value = array[index],
2905 current = iteratee(value);
2907 if (current != null && (computed === undefined
2908 ? (current === current && !isSymbol(current))
2909 : comparator(current, computed)
2911 var computed = current,
2919 * The base implementation of `_.fill` without an iteratee call guard.
2922 * @param {Array} array The array to fill.
2923 * @param {*} value The value to fill `array` with.
2924 * @param {number} [start=0] The start position.
2925 * @param {number} [end=array.length] The end position.
2926 * @returns {Array} Returns `array`.
2928 function baseFill(array, value, start, end) {
2929 var length = array.length;
2931 start = toInteger(start);
2933 start = -start > length ? 0 : (length + start);
2935 end = (end === undefined || end > length) ? length : toInteger(end);
2939 end = start > end ? 0 : toLength(end);
2940 while (start < end) {
2941 array[start++] = value;
2947 * The base implementation of `_.filter` without support for iteratee shorthands.
2950 * @param {Array|Object} collection The collection to iterate over.
2951 * @param {Function} predicate The function invoked per iteration.
2952 * @returns {Array} Returns the new filtered array.
2954 function baseFilter(collection, predicate) {
2956 baseEach(collection, function(value, index, collection) {
2957 if (predicate(value, index, collection)) {
2965 * The base implementation of `_.flatten` with support for restricting flattening.
2968 * @param {Array} array The array to flatten.
2969 * @param {number} depth The maximum recursion depth.
2970 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
2971 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
2972 * @param {Array} [result=[]] The initial result value.
2973 * @returns {Array} Returns the new flattened array.
2975 function baseFlatten(array, depth, predicate, isStrict, result) {
2977 length = array.length;
2979 predicate || (predicate = isFlattenable);
2980 result || (result = []);
2982 while (++index < length) {
2983 var value = array[index];
2984 if (depth > 0 && predicate(value)) {
2986 // Recursively flatten arrays (susceptible to call stack limits).
2987 baseFlatten(value, depth - 1, predicate, isStrict, result);
2989 arrayPush(result, value);
2991 } else if (!isStrict) {
2992 result[result.length] = value;
2999 * The base implementation of `baseForOwn` which iterates over `object`
3000 * properties returned by `keysFunc` and invokes `iteratee` for each property.
3001 * Iteratee functions may exit iteration early by explicitly returning `false`.
3004 * @param {Object} object The object to iterate over.
3005 * @param {Function} iteratee The function invoked per iteration.
3006 * @param {Function} keysFunc The function to get the keys of `object`.
3007 * @returns {Object} Returns `object`.
3009 var baseFor = createBaseFor();
3012 * This function is like `baseFor` except that it iterates over properties
3013 * in the opposite order.
3016 * @param {Object} object The object to iterate over.
3017 * @param {Function} iteratee The function invoked per iteration.
3018 * @param {Function} keysFunc The function to get the keys of `object`.
3019 * @returns {Object} Returns `object`.
3021 var baseForRight = createBaseFor(true);
3024 * The base implementation of `_.forOwn` without support for iteratee shorthands.
3027 * @param {Object} object The object to iterate over.
3028 * @param {Function} iteratee The function invoked per iteration.
3029 * @returns {Object} Returns `object`.
3031 function baseForOwn(object, iteratee) {
3032 return object && baseFor(object, iteratee, keys);
3036 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
3039 * @param {Object} object The object to iterate over.
3040 * @param {Function} iteratee The function invoked per iteration.
3041 * @returns {Object} Returns `object`.
3043 function baseForOwnRight(object, iteratee) {
3044 return object && baseForRight(object, iteratee, keys);
3048 * The base implementation of `_.functions` which creates an array of
3049 * `object` function property names filtered from `props`.
3052 * @param {Object} object The object to inspect.
3053 * @param {Array} props The property names to filter.
3054 * @returns {Array} Returns the function names.
3056 function baseFunctions(object, props) {
3057 return arrayFilter(props, function(key) {
3058 return isFunction(object[key]);
3063 * The base implementation of `_.get` without support for default values.
3066 * @param {Object} object The object to query.
3067 * @param {Array|string} path The path of the property to get.
3068 * @returns {*} Returns the resolved value.
3070 function baseGet(object, path) {
3071 path = castPath(path, object);
3074 length = path.length;
3076 while (object != null && index < length) {
3077 object = object[toKey(path[index++])];
3079 return (index && index == length) ? object : undefined;
3083 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
3084 * `keysFunc` and `symbolsFunc` to get the enumerable property names and
3085 * symbols of `object`.
3088 * @param {Object} object The object to query.
3089 * @param {Function} keysFunc The function to get the keys of `object`.
3090 * @param {Function} symbolsFunc The function to get the symbols of `object`.
3091 * @returns {Array} Returns the array of property names and symbols.
3093 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
3094 var result = keysFunc(object);
3095 return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
3099 * The base implementation of `getTag` without fallbacks for buggy environments.
3102 * @param {*} value The value to query.
3103 * @returns {string} Returns the `toStringTag`.
3105 function baseGetTag(value) {
3106 if (value == null) {
3107 return value === undefined ? undefinedTag : nullTag;
3109 return (symToStringTag && symToStringTag in Object(value))
3111 : objectToString(value);
3115 * The base implementation of `_.gt` which doesn't coerce arguments.
3118 * @param {*} value The value to compare.
3119 * @param {*} other The other value to compare.
3120 * @returns {boolean} Returns `true` if `value` is greater than `other`,
3123 function baseGt(value, other) {
3124 return value > other;
3128 * The base implementation of `_.has` without support for deep paths.
3131 * @param {Object} [object] The object to query.
3132 * @param {Array|string} key The key to check.
3133 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3135 function baseHas(object, key) {
3136 return object != null && hasOwnProperty.call(object, key);
3140 * The base implementation of `_.hasIn` without support for deep paths.
3143 * @param {Object} [object] The object to query.
3144 * @param {Array|string} key The key to check.
3145 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3147 function baseHasIn(object, key) {
3148 return object != null && key in Object(object);
3152 * The base implementation of `_.inRange` which doesn't coerce arguments.
3155 * @param {number} number The number to check.
3156 * @param {number} start The start of the range.
3157 * @param {number} end The end of the range.
3158 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
3160 function baseInRange(number, start, end) {
3161 return number >= nativeMin(start, end) && number < nativeMax(start, end);
3165 * The base implementation of methods like `_.intersection`, without support
3166 * for iteratee shorthands, that accepts an array of arrays to inspect.
3169 * @param {Array} arrays The arrays to inspect.
3170 * @param {Function} [iteratee] The iteratee invoked per element.
3171 * @param {Function} [comparator] The comparator invoked per element.
3172 * @returns {Array} Returns the new array of shared values.
3174 function baseIntersection(arrays, iteratee, comparator) {
3175 var includes = comparator ? arrayIncludesWith : arrayIncludes,
3176 length = arrays[0].length,
3177 othLength = arrays.length,
3178 othIndex = othLength,
3179 caches = Array(othLength),
3180 maxLength = Infinity,
3183 while (othIndex--) {
3184 var array = arrays[othIndex];
3185 if (othIndex && iteratee) {
3186 array = arrayMap(array, baseUnary(iteratee));
3188 maxLength = nativeMin(array.length, maxLength);
3189 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
3190 ? new SetCache(othIndex && array)
3199 while (++index < length && result.length < maxLength) {
3200 var value = array[index],
3201 computed = iteratee ? iteratee(value) : value;
3203 value = (comparator || value !== 0) ? value : 0;
3205 ? cacheHas(seen, computed)
3206 : includes(result, computed, comparator)
3208 othIndex = othLength;
3209 while (--othIndex) {
3210 var cache = caches[othIndex];
3212 ? cacheHas(cache, computed)
3213 : includes(arrays[othIndex], computed, comparator))
3219 seen.push(computed);
3228 * The base implementation of `_.invert` and `_.invertBy` which inverts
3229 * `object` with values transformed by `iteratee` and set by `setter`.
3232 * @param {Object} object The object to iterate over.
3233 * @param {Function} setter The function to set `accumulator` values.
3234 * @param {Function} iteratee The iteratee to transform values.
3235 * @param {Object} accumulator The initial inverted object.
3236 * @returns {Function} Returns `accumulator`.
3238 function baseInverter(object, setter, iteratee, accumulator) {
3239 baseForOwn(object, function(value, key, object) {
3240 setter(accumulator, iteratee(value), key, object);
3246 * The base implementation of `_.invoke` without support for individual
3250 * @param {Object} object The object to query.
3251 * @param {Array|string} path The path of the method to invoke.
3252 * @param {Array} args The arguments to invoke the method with.
3253 * @returns {*} Returns the result of the invoked method.
3255 function baseInvoke(object, path, args) {
3256 path = castPath(path, object);
3257 object = parent(object, path);
3258 var func = object == null ? object : object[toKey(last(path))];
3259 return func == null ? undefined : apply(func, object, args);
3263 * The base implementation of `_.isArguments`.
3266 * @param {*} value The value to check.
3267 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
3269 function baseIsArguments(value) {
3270 return isObjectLike(value) && baseGetTag(value) == argsTag;
3274 * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
3277 * @param {*} value The value to check.
3278 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
3280 function baseIsArrayBuffer(value) {
3281 return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
3285 * The base implementation of `_.isDate` without Node.js optimizations.
3288 * @param {*} value The value to check.
3289 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
3291 function baseIsDate(value) {
3292 return isObjectLike(value) && baseGetTag(value) == dateTag;
3296 * The base implementation of `_.isEqual` which supports partial comparisons
3297 * and tracks traversed objects.
3300 * @param {*} value The value to compare.
3301 * @param {*} other The other value to compare.
3302 * @param {boolean} bitmask The bitmask flags.
3303 * 1 - Unordered comparison
3304 * 2 - Partial comparison
3305 * @param {Function} [customizer] The function to customize comparisons.
3306 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
3307 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3309 function baseIsEqual(value, other, bitmask, customizer, stack) {
3310 if (value === other) {
3313 if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
3314 return value !== value && other !== other;
3316 return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
3320 * A specialized version of `baseIsEqual` for arrays and objects which performs
3321 * deep comparisons and tracks traversed objects enabling objects with circular
3322 * references to be compared.
3325 * @param {Object} object The object to compare.
3326 * @param {Object} other The other object to compare.
3327 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
3328 * @param {Function} customizer The function to customize comparisons.
3329 * @param {Function} equalFunc The function to determine equivalents of values.
3330 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
3331 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3333 function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
3334 var objIsArr = isArray(object),
3335 othIsArr = isArray(other),
3336 objTag = objIsArr ? arrayTag : getTag(object),
3337 othTag = othIsArr ? arrayTag : getTag(other);
3339 objTag = objTag == argsTag ? objectTag : objTag;
3340 othTag = othTag == argsTag ? objectTag : othTag;
3342 var objIsObj = objTag == objectTag,
3343 othIsObj = othTag == objectTag,
3344 isSameTag = objTag == othTag;
3346 if (isSameTag && isBuffer(object)) {
3347 if (!isBuffer(other)) {
3353 if (isSameTag && !objIsObj) {
3354 stack || (stack = new Stack);
3355 return (objIsArr || isTypedArray(object))
3356 ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
3357 : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
3359 if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
3360 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
3361 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
3363 if (objIsWrapped || othIsWrapped) {
3364 var objUnwrapped = objIsWrapped ? object.value() : object,
3365 othUnwrapped = othIsWrapped ? other.value() : other;
3367 stack || (stack = new Stack);
3368 return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
3374 stack || (stack = new Stack);
3375 return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
3379 * The base implementation of `_.isMap` without Node.js optimizations.
3382 * @param {*} value The value to check.
3383 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
3385 function baseIsMap(value) {
3386 return isObjectLike(value) && getTag(value) == mapTag;
3390 * The base implementation of `_.isMatch` without support for iteratee shorthands.
3393 * @param {Object} object The object to inspect.
3394 * @param {Object} source The object of property values to match.
3395 * @param {Array} matchData The property names, values, and compare flags to match.
3396 * @param {Function} [customizer] The function to customize comparisons.
3397 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
3399 function baseIsMatch(object, source, matchData, customizer) {
3400 var index = matchData.length,
3402 noCustomizer = !customizer;
3404 if (object == null) {
3407 object = Object(object);
3409 var data = matchData[index];
3410 if ((noCustomizer && data[2])
3411 ? data[1] !== object[data[0]]
3412 : !(data[0] in object)
3417 while (++index < length) {
3418 data = matchData[index];
3420 objValue = object[key],
3423 if (noCustomizer && data[2]) {
3424 if (objValue === undefined && !(key in object)) {
3428 var stack = new Stack;
3430 var result = customizer(objValue, srcValue, key, object, source, stack);
3432 if (!(result === undefined
3433 ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
3444 * The base implementation of `_.isNative` without bad shim checks.
3447 * @param {*} value The value to check.
3448 * @returns {boolean} Returns `true` if `value` is a native function,
3451 function baseIsNative(value) {
3452 if (!isObject(value) || isMasked(value)) {
3455 var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3456 return pattern.test(toSource(value));
3460 * The base implementation of `_.isRegExp` without Node.js optimizations.
3463 * @param {*} value The value to check.
3464 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
3466 function baseIsRegExp(value) {
3467 return isObjectLike(value) && baseGetTag(value) == regexpTag;
3471 * The base implementation of `_.isSet` without Node.js optimizations.
3474 * @param {*} value The value to check.
3475 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
3477 function baseIsSet(value) {
3478 return isObjectLike(value) && getTag(value) == setTag;
3482 * The base implementation of `_.isTypedArray` without Node.js optimizations.
3485 * @param {*} value The value to check.
3486 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
3488 function baseIsTypedArray(value) {
3489 return isObjectLike(value) &&
3490 isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
3494 * The base implementation of `_.iteratee`.
3497 * @param {*} [value=_.identity] The value to convert to an iteratee.
3498 * @returns {Function} Returns the iteratee.
3500 function baseIteratee(value) {
3501 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
3502 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
3503 if (typeof value == 'function') {
3506 if (value == null) {
3509 if (typeof value == 'object') {
3510 return isArray(value)
3511 ? baseMatchesProperty(value[0], value[1])
3512 : baseMatches(value);
3514 return property(value);
3518 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
3521 * @param {Object} object The object to query.
3522 * @returns {Array} Returns the array of property names.
3524 function baseKeys(object) {
3525 if (!isPrototype(object)) {
3526 return nativeKeys(object);
3529 for (var key in Object(object)) {
3530 if (hasOwnProperty.call(object, key) && key != 'constructor') {
3538 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
3541 * @param {Object} object The object to query.
3542 * @returns {Array} Returns the array of property names.
3544 function baseKeysIn(object) {
3545 if (!isObject(object)) {
3546 return nativeKeysIn(object);
3548 var isProto = isPrototype(object),
3551 for (var key in object) {
3552 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3560 * The base implementation of `_.lt` which doesn't coerce arguments.
3563 * @param {*} value The value to compare.
3564 * @param {*} other The other value to compare.
3565 * @returns {boolean} Returns `true` if `value` is less than `other`,
3568 function baseLt(value, other) {
3569 return value < other;
3573 * The base implementation of `_.map` without support for iteratee shorthands.
3576 * @param {Array|Object} collection The collection to iterate over.
3577 * @param {Function} iteratee The function invoked per iteration.
3578 * @returns {Array} Returns the new mapped array.
3580 function baseMap(collection, iteratee) {
3582 result = isArrayLike(collection) ? Array(collection.length) : [];
3584 baseEach(collection, function(value, key, collection) {
3585 result[++index] = iteratee(value, key, collection);
3591 * The base implementation of `_.matches` which doesn't clone `source`.
3594 * @param {Object} source The object of property values to match.
3595 * @returns {Function} Returns the new spec function.
3597 function baseMatches(source) {
3598 var matchData = getMatchData(source);
3599 if (matchData.length == 1 && matchData[0][2]) {
3600 return matchesStrictComparable(matchData[0][0], matchData[0][1]);
3602 return function(object) {
3603 return object === source || baseIsMatch(object, source, matchData);
3608 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3611 * @param {string} path The path of the property to get.
3612 * @param {*} srcValue The value to match.
3613 * @returns {Function} Returns the new spec function.
3615 function baseMatchesProperty(path, srcValue) {
3616 if (isKey(path) && isStrictComparable(srcValue)) {
3617 return matchesStrictComparable(toKey(path), srcValue);
3619 return function(object) {
3620 var objValue = get(object, path);
3621 return (objValue === undefined && objValue === srcValue)
3622 ? hasIn(object, path)
3623 : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
3628 * The base implementation of `_.merge` without support for multiple sources.
3631 * @param {Object} object The destination object.
3632 * @param {Object} source The source object.
3633 * @param {number} srcIndex The index of `source`.
3634 * @param {Function} [customizer] The function to customize merged values.
3635 * @param {Object} [stack] Tracks traversed source values and their merged
3638 function baseMerge(object, source, srcIndex, customizer, stack) {
3639 if (object === source) {
3642 baseFor(source, function(srcValue, key) {
3643 stack || (stack = new Stack);
3644 if (isObject(srcValue)) {
3645 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3648 var newValue = customizer
3649 ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
3652 if (newValue === undefined) {
3653 newValue = srcValue;
3655 assignMergeValue(object, key, newValue);
3661 * A specialized version of `baseMerge` for arrays and objects which performs
3662 * deep merges and tracks traversed objects enabling objects with circular
3663 * references to be merged.
3666 * @param {Object} object The destination object.
3667 * @param {Object} source The source object.
3668 * @param {string} key The key of the value to merge.
3669 * @param {number} srcIndex The index of `source`.
3670 * @param {Function} mergeFunc The function to merge values.
3671 * @param {Function} [customizer] The function to customize assigned values.
3672 * @param {Object} [stack] Tracks traversed source values and their merged
3675 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3676 var objValue = safeGet(object, key),
3677 srcValue = safeGet(source, key),
3678 stacked = stack.get(srcValue);
3681 assignMergeValue(object, key, stacked);
3684 var newValue = customizer
3685 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3688 var isCommon = newValue === undefined;
3691 var isArr = isArray(srcValue),
3692 isBuff = !isArr && isBuffer(srcValue),
3693 isTyped = !isArr && !isBuff && isTypedArray(srcValue);
3695 newValue = srcValue;
3696 if (isArr || isBuff || isTyped) {
3697 if (isArray(objValue)) {
3698 newValue = objValue;
3700 else if (isArrayLikeObject(objValue)) {
3701 newValue = copyArray(objValue);
3705 newValue = cloneBuffer(srcValue, true);
3709 newValue = cloneTypedArray(srcValue, true);
3715 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3716 newValue = objValue;
3717 if (isArguments(objValue)) {
3718 newValue = toPlainObject(objValue);
3720 else if (!isObject(objValue) || isFunction(objValue)) {
3721 newValue = initCloneObject(srcValue);
3729 // Recursively merge objects and arrays (susceptible to call stack limits).
3730 stack.set(srcValue, newValue);
3731 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3732 stack['delete'](srcValue);
3734 assignMergeValue(object, key, newValue);
3738 * The base implementation of `_.nth` which doesn't coerce arguments.
3741 * @param {Array} array The array to query.
3742 * @param {number} n The index of the element to return.
3743 * @returns {*} Returns the nth element of `array`.
3745 function baseNth(array, n) {
3746 var length = array.length;
3750 n += n < 0 ? length : 0;
3751 return isIndex(n, length) ? array[n] : undefined;
3755 * The base implementation of `_.orderBy` without param guards.
3758 * @param {Array|Object} collection The collection to iterate over.
3759 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3760 * @param {string[]} orders The sort orders of `iteratees`.
3761 * @returns {Array} Returns the new sorted array.
3763 function baseOrderBy(collection, iteratees, orders) {
3764 if (iteratees.length) {
3765 iteratees = arrayMap(iteratees, function(iteratee) {
3766 if (isArray(iteratee)) {
3767 return function(value) {
3768 return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
3774 iteratees = [identity];
3778 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
3780 var result = baseMap(collection, function(value, key, collection) {
3781 var criteria = arrayMap(iteratees, function(iteratee) {
3782 return iteratee(value);
3784 return { 'criteria': criteria, 'index': ++index, 'value': value };
3787 return baseSortBy(result, function(object, other) {
3788 return compareMultiple(object, other, orders);
3793 * The base implementation of `_.pick` without support for individual
3794 * property identifiers.
3797 * @param {Object} object The source object.
3798 * @param {string[]} paths The property paths to pick.
3799 * @returns {Object} Returns the new object.
3801 function basePick(object, paths) {
3802 return basePickBy(object, paths, function(value, path) {
3803 return hasIn(object, path);
3808 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3811 * @param {Object} object The source object.
3812 * @param {string[]} paths The property paths to pick.
3813 * @param {Function} predicate The function invoked per property.
3814 * @returns {Object} Returns the new object.
3816 function basePickBy(object, paths, predicate) {
3818 length = paths.length,
3821 while (++index < length) {
3822 var path = paths[index],
3823 value = baseGet(object, path);
3825 if (predicate(value, path)) {
3826 baseSet(result, castPath(path, object), value);
3833 * A specialized version of `baseProperty` which supports deep paths.
3836 * @param {Array|string} path The path of the property to get.
3837 * @returns {Function} Returns the new accessor function.
3839 function basePropertyDeep(path) {
3840 return function(object) {
3841 return baseGet(object, path);
3846 * The base implementation of `_.pullAllBy` without support for iteratee
3850 * @param {Array} array The array to modify.
3851 * @param {Array} values The values to remove.
3852 * @param {Function} [iteratee] The iteratee invoked per element.
3853 * @param {Function} [comparator] The comparator invoked per element.
3854 * @returns {Array} Returns `array`.
3856 function basePullAll(array, values, iteratee, comparator) {
3857 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
3859 length = values.length,
3862 if (array === values) {
3863 values = copyArray(values);
3866 seen = arrayMap(array, baseUnary(iteratee));
3868 while (++index < length) {
3870 value = values[index],
3871 computed = iteratee ? iteratee(value) : value;
3873 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
3874 if (seen !== array) {
3875 splice.call(seen, fromIndex, 1);
3877 splice.call(array, fromIndex, 1);
3884 * The base implementation of `_.pullAt` without support for individual
3885 * indexes or capturing the removed elements.
3888 * @param {Array} array The array to modify.
3889 * @param {number[]} indexes The indexes of elements to remove.
3890 * @returns {Array} Returns `array`.
3892 function basePullAt(array, indexes) {
3893 var length = array ? indexes.length : 0,
3894 lastIndex = length - 1;
3897 var index = indexes[length];
3898 if (length == lastIndex || index !== previous) {
3899 var previous = index;
3900 if (isIndex(index)) {
3901 splice.call(array, index, 1);
3903 baseUnset(array, index);
3911 * The base implementation of `_.random` without support for returning
3912 * floating-point numbers.
3915 * @param {number} lower The lower bound.
3916 * @param {number} upper The upper bound.
3917 * @returns {number} Returns the random number.
3919 function baseRandom(lower, upper) {
3920 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3924 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3928 * @param {number} start The start of the range.
3929 * @param {number} end The end of the range.
3930 * @param {number} step The value to increment or decrement by.
3931 * @param {boolean} [fromRight] Specify iterating from right to left.
3932 * @returns {Array} Returns the range of numbers.
3934 function baseRange(start, end, step, fromRight) {
3936 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3937 result = Array(length);
3940 result[fromRight ? length : ++index] = start;
3947 * The base implementation of `_.repeat` which doesn't coerce arguments.
3950 * @param {string} string The string to repeat.
3951 * @param {number} n The number of times to repeat the string.
3952 * @returns {string} Returns the repeated string.
3954 function baseRepeat(string, n) {
3956 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
3959 // Leverage the exponentiation by squaring algorithm for a faster repeat.
3960 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
3965 n = nativeFloor(n / 2);
3975 * The base implementation of `_.rest` which doesn't validate or coerce arguments.
3978 * @param {Function} func The function to apply a rest parameter to.
3979 * @param {number} [start=func.length-1] The start position of the rest parameter.
3980 * @returns {Function} Returns the new function.
3982 function baseRest(func, start) {
3983 return setToString(overRest(func, start, identity), func + '');
3987 * The base implementation of `_.sample`.
3990 * @param {Array|Object} collection The collection to sample.
3991 * @returns {*} Returns the random element.
3993 function baseSample(collection) {
3994 return arraySample(values(collection));
3998 * The base implementation of `_.sampleSize` without param guards.
4001 * @param {Array|Object} collection The collection to sample.
4002 * @param {number} n The number of elements to sample.
4003 * @returns {Array} Returns the random elements.
4005 function baseSampleSize(collection, n) {
4006 var array = values(collection);
4007 return shuffleSelf(array, baseClamp(n, 0, array.length));
4011 * The base implementation of `_.set`.
4014 * @param {Object} object The object to modify.
4015 * @param {Array|string} path The path of the property to set.
4016 * @param {*} value The value to set.
4017 * @param {Function} [customizer] The function to customize path creation.
4018 * @returns {Object} Returns `object`.
4020 function baseSet(object, path, value, customizer) {
4021 if (!isObject(object)) {
4024 path = castPath(path, object);
4027 length = path.length,
4028 lastIndex = length - 1,
4031 while (nested != null && ++index < length) {
4032 var key = toKey(path[index]),
4035 if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
4039 if (index != lastIndex) {
4040 var objValue = nested[key];
4041 newValue = customizer ? customizer(objValue, key, nested) : undefined;
4042 if (newValue === undefined) {
4043 newValue = isObject(objValue)
4045 : (isIndex(path[index + 1]) ? [] : {});
4048 assignValue(nested, key, newValue);
4049 nested = nested[key];
4055 * The base implementation of `setData` without support for hot loop shorting.
4058 * @param {Function} func The function to associate metadata with.
4059 * @param {*} data The metadata.
4060 * @returns {Function} Returns `func`.
4062 var baseSetData = !metaMap ? identity : function(func, data) {
4063 metaMap.set(func, data);
4068 * The base implementation of `setToString` without support for hot loop shorting.
4071 * @param {Function} func The function to modify.
4072 * @param {Function} string The `toString` result.
4073 * @returns {Function} Returns `func`.
4075 var baseSetToString = !defineProperty ? identity : function(func, string) {
4076 return defineProperty(func, 'toString', {
4077 'configurable': true,
4078 'enumerable': false,
4079 'value': constant(string),
4085 * The base implementation of `_.shuffle`.
4088 * @param {Array|Object} collection The collection to shuffle.
4089 * @returns {Array} Returns the new shuffled array.
4091 function baseShuffle(collection) {
4092 return shuffleSelf(values(collection));
4096 * The base implementation of `_.slice` without an iteratee call guard.
4099 * @param {Array} array The array to slice.
4100 * @param {number} [start=0] The start position.
4101 * @param {number} [end=array.length] The end position.
4102 * @returns {Array} Returns the slice of `array`.
4104 function baseSlice(array, start, end) {
4106 length = array.length;
4109 start = -start > length ? 0 : (length + start);
4111 end = end > length ? length : end;
4115 length = start > end ? 0 : ((end - start) >>> 0);
4118 var result = Array(length);
4119 while (++index < length) {
4120 result[index] = array[index + start];
4126 * The base implementation of `_.some` without support for iteratee shorthands.
4129 * @param {Array|Object} collection The collection to iterate over.
4130 * @param {Function} predicate The function invoked per iteration.
4131 * @returns {boolean} Returns `true` if any element passes the predicate check,
4134 function baseSome(collection, predicate) {
4137 baseEach(collection, function(value, index, collection) {
4138 result = predicate(value, index, collection);
4145 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
4146 * performs a binary search of `array` to determine the index at which `value`
4147 * should be inserted into `array` in order to maintain its sort order.
4150 * @param {Array} array The sorted array to inspect.
4151 * @param {*} value The value to evaluate.
4152 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4153 * @returns {number} Returns the index at which `value` should be inserted
4156 function baseSortedIndex(array, value, retHighest) {
4158 high = array == null ? low : array.length;
4160 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
4161 while (low < high) {
4162 var mid = (low + high) >>> 1,
4163 computed = array[mid];
4165 if (computed !== null && !isSymbol(computed) &&
4166 (retHighest ? (computed <= value) : (computed < value))) {
4174 return baseSortedIndexBy(array, value, identity, retHighest);
4178 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
4179 * which invokes `iteratee` for `value` and each element of `array` to compute
4180 * their sort ranking. The iteratee is invoked with one argument; (value).
4183 * @param {Array} array The sorted array to inspect.
4184 * @param {*} value The value to evaluate.
4185 * @param {Function} iteratee The iteratee invoked per element.
4186 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4187 * @returns {number} Returns the index at which `value` should be inserted
4190 function baseSortedIndexBy(array, value, iteratee, retHighest) {
4192 high = array == null ? 0 : array.length;
4197 value = iteratee(value);
4198 var valIsNaN = value !== value,
4199 valIsNull = value === null,
4200 valIsSymbol = isSymbol(value),
4201 valIsUndefined = value === undefined;
4203 while (low < high) {
4204 var mid = nativeFloor((low + high) / 2),
4205 computed = iteratee(array[mid]),
4206 othIsDefined = computed !== undefined,
4207 othIsNull = computed === null,
4208 othIsReflexive = computed === computed,
4209 othIsSymbol = isSymbol(computed);
4212 var setLow = retHighest || othIsReflexive;
4213 } else if (valIsUndefined) {
4214 setLow = othIsReflexive && (retHighest || othIsDefined);
4215 } else if (valIsNull) {
4216 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
4217 } else if (valIsSymbol) {
4218 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
4219 } else if (othIsNull || othIsSymbol) {
4222 setLow = retHighest ? (computed <= value) : (computed < value);
4230 return nativeMin(high, MAX_ARRAY_INDEX);
4234 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
4235 * support for iteratee shorthands.
4238 * @param {Array} array The array to inspect.
4239 * @param {Function} [iteratee] The iteratee invoked per element.
4240 * @returns {Array} Returns the new duplicate free array.
4242 function baseSortedUniq(array, iteratee) {
4244 length = array.length,
4248 while (++index < length) {
4249 var value = array[index],
4250 computed = iteratee ? iteratee(value) : value;
4252 if (!index || !eq(computed, seen)) {
4253 var seen = computed;
4254 result[resIndex++] = value === 0 ? 0 : value;
4261 * The base implementation of `_.toNumber` which doesn't ensure correct
4262 * conversions of binary, hexadecimal, or octal string values.
4265 * @param {*} value The value to process.
4266 * @returns {number} Returns the number.
4268 function baseToNumber(value) {
4269 if (typeof value == 'number') {
4272 if (isSymbol(value)) {
4279 * The base implementation of `_.toString` which doesn't convert nullish
4280 * values to empty strings.
4283 * @param {*} value The value to process.
4284 * @returns {string} Returns the string.
4286 function baseToString(value) {
4287 // Exit early for strings to avoid a performance hit in some environments.
4288 if (typeof value == 'string') {
4291 if (isArray(value)) {
4292 // Recursively convert values (susceptible to call stack limits).
4293 return arrayMap(value, baseToString) + '';
4295 if (isSymbol(value)) {
4296 return symbolToString ? symbolToString.call(value) : '';
4298 var result = (value + '');
4299 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
4303 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
4306 * @param {Array} array The array to inspect.
4307 * @param {Function} [iteratee] The iteratee invoked per element.
4308 * @param {Function} [comparator] The comparator invoked per element.
4309 * @returns {Array} Returns the new duplicate free array.
4311 function baseUniq(array, iteratee, comparator) {
4313 includes = arrayIncludes,
4314 length = array.length,
4321 includes = arrayIncludesWith;
4323 else if (length >= LARGE_ARRAY_SIZE) {
4324 var set = iteratee ? null : createSet(array);
4326 return setToArray(set);
4329 includes = cacheHas;
4330 seen = new SetCache;
4333 seen = iteratee ? [] : result;
4336 while (++index < length) {
4337 var value = array[index],
4338 computed = iteratee ? iteratee(value) : value;
4340 value = (comparator || value !== 0) ? value : 0;
4341 if (isCommon && computed === computed) {
4342 var seenIndex = seen.length;
4343 while (seenIndex--) {
4344 if (seen[seenIndex] === computed) {
4349 seen.push(computed);
4353 else if (!includes(seen, computed, comparator)) {
4354 if (seen !== result) {
4355 seen.push(computed);
4364 * The base implementation of `_.unset`.
4367 * @param {Object} object The object to modify.
4368 * @param {Array|string} path The property path to unset.
4369 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
4371 function baseUnset(object, path) {
4372 path = castPath(path, object);
4373 object = parent(object, path);
4374 return object == null || delete object[toKey(last(path))];
4378 * The base implementation of `_.update`.
4381 * @param {Object} object The object to modify.
4382 * @param {Array|string} path The path of the property to update.
4383 * @param {Function} updater The function to produce the updated value.
4384 * @param {Function} [customizer] The function to customize path creation.
4385 * @returns {Object} Returns `object`.
4387 function baseUpdate(object, path, updater, customizer) {
4388 return baseSet(object, path, updater(baseGet(object, path)), customizer);
4392 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
4393 * without support for iteratee shorthands.
4396 * @param {Array} array The array to query.
4397 * @param {Function} predicate The function invoked per iteration.
4398 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
4399 * @param {boolean} [fromRight] Specify iterating from right to left.
4400 * @returns {Array} Returns the slice of `array`.
4402 function baseWhile(array, predicate, isDrop, fromRight) {
4403 var length = array.length,
4404 index = fromRight ? length : -1;
4406 while ((fromRight ? index-- : ++index < length) &&
4407 predicate(array[index], index, array)) {}
4410 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
4411 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
4415 * The base implementation of `wrapperValue` which returns the result of
4416 * performing a sequence of actions on the unwrapped `value`, where each
4417 * successive action is supplied the return value of the previous.
4420 * @param {*} value The unwrapped value.
4421 * @param {Array} actions Actions to perform to resolve the unwrapped value.
4422 * @returns {*} Returns the resolved value.
4424 function baseWrapperValue(value, actions) {
4426 if (result instanceof LazyWrapper) {
4427 result = result.value();
4429 return arrayReduce(actions, function(result, action) {
4430 return action.func.apply(action.thisArg, arrayPush([result], action.args));
4435 * The base implementation of methods like `_.xor`, without support for
4436 * iteratee shorthands, that accepts an array of arrays to inspect.
4439 * @param {Array} arrays The arrays to inspect.
4440 * @param {Function} [iteratee] The iteratee invoked per element.
4441 * @param {Function} [comparator] The comparator invoked per element.
4442 * @returns {Array} Returns the new array of values.
4444 function baseXor(arrays, iteratee, comparator) {
4445 var length = arrays.length;
4447 return length ? baseUniq(arrays[0]) : [];
4450 result = Array(length);
4452 while (++index < length) {
4453 var array = arrays[index],
4456 while (++othIndex < length) {
4457 if (othIndex != index) {
4458 result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
4462 return baseUniq(baseFlatten(result, 1), iteratee, comparator);
4466 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
4469 * @param {Array} props The property identifiers.
4470 * @param {Array} values The property values.
4471 * @param {Function} assignFunc The function to assign values.
4472 * @returns {Object} Returns the new object.
4474 function baseZipObject(props, values, assignFunc) {
4476 length = props.length,
4477 valsLength = values.length,
4480 while (++index < length) {
4481 var value = index < valsLength ? values[index] : undefined;
4482 assignFunc(result, props[index], value);
4488 * Casts `value` to an empty array if it's not an array like object.
4491 * @param {*} value The value to inspect.
4492 * @returns {Array|Object} Returns the cast array-like object.
4494 function castArrayLikeObject(value) {
4495 return isArrayLikeObject(value) ? value : [];
4499 * Casts `value` to `identity` if it's not a function.
4502 * @param {*} value The value to inspect.
4503 * @returns {Function} Returns cast function.
4505 function castFunction(value) {
4506 return typeof value == 'function' ? value : identity;
4510 * Casts `value` to a path array if it's not one.
4513 * @param {*} value The value to inspect.
4514 * @param {Object} [object] The object to query keys on.
4515 * @returns {Array} Returns the cast property path array.
4517 function castPath(value, object) {
4518 if (isArray(value)) {
4521 return isKey(value, object) ? [value] : stringToPath(toString(value));
4525 * A `baseRest` alias which can be replaced with `identity` by module
4526 * replacement plugins.
4530 * @param {Function} func The function to apply a rest parameter to.
4531 * @returns {Function} Returns the new function.
4533 var castRest = baseRest;
4536 * Casts `array` to a slice if it's needed.
4539 * @param {Array} array The array to inspect.
4540 * @param {number} start The start position.
4541 * @param {number} [end=array.length] The end position.
4542 * @returns {Array} Returns the cast slice.
4544 function castSlice(array, start, end) {
4545 var length = array.length;
4546 end = end === undefined ? length : end;
4547 return (!start && end >= length) ? array : baseSlice(array, start, end);
4551 * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
4554 * @param {number|Object} id The timer id or timeout object of the timer to clear.
4556 var clearTimeout = ctxClearTimeout || function(id) {
4557 return root.clearTimeout(id);
4561 * Creates a clone of `buffer`.
4564 * @param {Buffer} buffer The buffer to clone.
4565 * @param {boolean} [isDeep] Specify a deep clone.
4566 * @returns {Buffer} Returns the cloned buffer.
4568 function cloneBuffer(buffer, isDeep) {
4570 return buffer.slice();
4572 var length = buffer.length,
4573 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
4575 buffer.copy(result);
4580 * Creates a clone of `arrayBuffer`.
4583 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
4584 * @returns {ArrayBuffer} Returns the cloned array buffer.
4586 function cloneArrayBuffer(arrayBuffer) {
4587 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
4588 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
4593 * Creates a clone of `dataView`.
4596 * @param {Object} dataView The data view to clone.
4597 * @param {boolean} [isDeep] Specify a deep clone.
4598 * @returns {Object} Returns the cloned data view.
4600 function cloneDataView(dataView, isDeep) {
4601 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
4602 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
4606 * Creates a clone of `regexp`.
4609 * @param {Object} regexp The regexp to clone.
4610 * @returns {Object} Returns the cloned regexp.
4612 function cloneRegExp(regexp) {
4613 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
4614 result.lastIndex = regexp.lastIndex;
4619 * Creates a clone of the `symbol` object.
4622 * @param {Object} symbol The symbol object to clone.
4623 * @returns {Object} Returns the cloned symbol object.
4625 function cloneSymbol(symbol) {
4626 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
4630 * Creates a clone of `typedArray`.
4633 * @param {Object} typedArray The typed array to clone.
4634 * @param {boolean} [isDeep] Specify a deep clone.
4635 * @returns {Object} Returns the cloned typed array.
4637 function cloneTypedArray(typedArray, isDeep) {
4638 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
4639 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
4643 * Compares values to sort them in ascending order.
4646 * @param {*} value The value to compare.
4647 * @param {*} other The other value to compare.
4648 * @returns {number} Returns the sort order indicator for `value`.
4650 function compareAscending(value, other) {
4651 if (value !== other) {
4652 var valIsDefined = value !== undefined,
4653 valIsNull = value === null,
4654 valIsReflexive = value === value,
4655 valIsSymbol = isSymbol(value);
4657 var othIsDefined = other !== undefined,
4658 othIsNull = other === null,
4659 othIsReflexive = other === other,
4660 othIsSymbol = isSymbol(other);
4662 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
4663 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
4664 (valIsNull && othIsDefined && othIsReflexive) ||
4665 (!valIsDefined && othIsReflexive) ||
4669 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
4670 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
4671 (othIsNull && valIsDefined && valIsReflexive) ||
4672 (!othIsDefined && valIsReflexive) ||
4681 * Used by `_.orderBy` to compare multiple properties of a value to another
4682 * and stable sort them.
4684 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
4685 * specify an order of "desc" for descending or "asc" for ascending sort order
4686 * of corresponding values.
4689 * @param {Object} object The object to compare.
4690 * @param {Object} other The other object to compare.
4691 * @param {boolean[]|string[]} orders The order to sort by for each property.
4692 * @returns {number} Returns the sort order indicator for `object`.
4694 function compareMultiple(object, other, orders) {
4696 objCriteria = object.criteria,
4697 othCriteria = other.criteria,
4698 length = objCriteria.length,
4699 ordersLength = orders.length;
4701 while (++index < length) {
4702 var result = compareAscending(objCriteria[index], othCriteria[index]);
4704 if (index >= ordersLength) {
4707 var order = orders[index];
4708 return result * (order == 'desc' ? -1 : 1);
4711 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
4712 // that causes it, under certain circumstances, to provide the same value for
4713 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
4714 // for more details.
4716 // This also ensures a stable sort in V8 and other engines.
4717 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
4718 return object.index - other.index;
4722 * Creates an array that is the composition of partially applied arguments,
4723 * placeholders, and provided arguments into a single array of arguments.
4726 * @param {Array} args The provided arguments.
4727 * @param {Array} partials The arguments to prepend to those provided.
4728 * @param {Array} holders The `partials` placeholder indexes.
4729 * @params {boolean} [isCurried] Specify composing for a curried function.
4730 * @returns {Array} Returns the new array of composed arguments.
4732 function composeArgs(args, partials, holders, isCurried) {
4734 argsLength = args.length,
4735 holdersLength = holders.length,
4737 leftLength = partials.length,
4738 rangeLength = nativeMax(argsLength - holdersLength, 0),
4739 result = Array(leftLength + rangeLength),
4740 isUncurried = !isCurried;
4742 while (++leftIndex < leftLength) {
4743 result[leftIndex] = partials[leftIndex];
4745 while (++argsIndex < holdersLength) {
4746 if (isUncurried || argsIndex < argsLength) {
4747 result[holders[argsIndex]] = args[argsIndex];
4750 while (rangeLength--) {
4751 result[leftIndex++] = args[argsIndex++];
4757 * This function is like `composeArgs` except that the arguments composition
4758 * is tailored for `_.partialRight`.
4761 * @param {Array} args The provided arguments.
4762 * @param {Array} partials The arguments to append to those provided.
4763 * @param {Array} holders The `partials` placeholder indexes.
4764 * @params {boolean} [isCurried] Specify composing for a curried function.
4765 * @returns {Array} Returns the new array of composed arguments.
4767 function composeArgsRight(args, partials, holders, isCurried) {
4769 argsLength = args.length,
4771 holdersLength = holders.length,
4773 rightLength = partials.length,
4774 rangeLength = nativeMax(argsLength - holdersLength, 0),
4775 result = Array(rangeLength + rightLength),
4776 isUncurried = !isCurried;
4778 while (++argsIndex < rangeLength) {
4779 result[argsIndex] = args[argsIndex];
4781 var offset = argsIndex;
4782 while (++rightIndex < rightLength) {
4783 result[offset + rightIndex] = partials[rightIndex];
4785 while (++holdersIndex < holdersLength) {
4786 if (isUncurried || argsIndex < argsLength) {
4787 result[offset + holders[holdersIndex]] = args[argsIndex++];
4794 * Copies the values of `source` to `array`.
4797 * @param {Array} source The array to copy values from.
4798 * @param {Array} [array=[]] The array to copy values to.
4799 * @returns {Array} Returns `array`.
4801 function copyArray(source, array) {
4803 length = source.length;
4805 array || (array = Array(length));
4806 while (++index < length) {
4807 array[index] = source[index];
4813 * Copies properties of `source` to `object`.
4816 * @param {Object} source The object to copy properties from.
4817 * @param {Array} props The property identifiers to copy.
4818 * @param {Object} [object={}] The object to copy properties to.
4819 * @param {Function} [customizer] The function to customize copied values.
4820 * @returns {Object} Returns `object`.
4822 function copyObject(source, props, object, customizer) {
4823 var isNew = !object;
4824 object || (object = {});
4827 length = props.length;
4829 while (++index < length) {
4830 var key = props[index];
4832 var newValue = customizer
4833 ? customizer(object[key], source[key], key, object, source)
4836 if (newValue === undefined) {
4837 newValue = source[key];
4840 baseAssignValue(object, key, newValue);
4842 assignValue(object, key, newValue);
4849 * Copies own symbols of `source` to `object`.
4852 * @param {Object} source The object to copy symbols from.
4853 * @param {Object} [object={}] The object to copy symbols to.
4854 * @returns {Object} Returns `object`.
4856 function copySymbols(source, object) {
4857 return copyObject(source, getSymbols(source), object);
4861 * Copies own and inherited symbols of `source` to `object`.
4864 * @param {Object} source The object to copy symbols from.
4865 * @param {Object} [object={}] The object to copy symbols to.
4866 * @returns {Object} Returns `object`.
4868 function copySymbolsIn(source, object) {
4869 return copyObject(source, getSymbolsIn(source), object);
4873 * Creates a function like `_.groupBy`.
4876 * @param {Function} setter The function to set accumulator values.
4877 * @param {Function} [initializer] The accumulator object initializer.
4878 * @returns {Function} Returns the new aggregator function.
4880 function createAggregator(setter, initializer) {
4881 return function(collection, iteratee) {
4882 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4883 accumulator = initializer ? initializer() : {};
4885 return func(collection, setter, getIteratee(iteratee, 2), accumulator);
4890 * Creates a function like `_.assign`.
4893 * @param {Function} assigner The function to assign values.
4894 * @returns {Function} Returns the new assigner function.
4896 function createAssigner(assigner) {
4897 return baseRest(function(object, sources) {
4899 length = sources.length,
4900 customizer = length > 1 ? sources[length - 1] : undefined,
4901 guard = length > 2 ? sources[2] : undefined;
4903 customizer = (assigner.length > 3 && typeof customizer == 'function')
4904 ? (length--, customizer)
4907 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
4908 customizer = length < 3 ? undefined : customizer;
4911 object = Object(object);
4912 while (++index < length) {
4913 var source = sources[index];
4915 assigner(object, source, index, customizer);
4923 * Creates a `baseEach` or `baseEachRight` function.
4926 * @param {Function} eachFunc The function to iterate over a collection.
4927 * @param {boolean} [fromRight] Specify iterating from right to left.
4928 * @returns {Function} Returns the new base function.
4930 function createBaseEach(eachFunc, fromRight) {
4931 return function(collection, iteratee) {
4932 if (collection == null) {
4935 if (!isArrayLike(collection)) {
4936 return eachFunc(collection, iteratee);
4938 var length = collection.length,
4939 index = fromRight ? length : -1,
4940 iterable = Object(collection);
4942 while ((fromRight ? index-- : ++index < length)) {
4943 if (iteratee(iterable[index], index, iterable) === false) {
4952 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
4955 * @param {boolean} [fromRight] Specify iterating from right to left.
4956 * @returns {Function} Returns the new base function.
4958 function createBaseFor(fromRight) {
4959 return function(object, iteratee, keysFunc) {
4961 iterable = Object(object),
4962 props = keysFunc(object),
4963 length = props.length;
4966 var key = props[fromRight ? length : ++index];
4967 if (iteratee(iterable[key], key, iterable) === false) {
4976 * Creates a function that wraps `func` to invoke it with the optional `this`
4977 * binding of `thisArg`.
4980 * @param {Function} func The function to wrap.
4981 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
4982 * @param {*} [thisArg] The `this` binding of `func`.
4983 * @returns {Function} Returns the new wrapped function.
4985 function createBind(func, bitmask, thisArg) {
4986 var isBind = bitmask & WRAP_BIND_FLAG,
4987 Ctor = createCtor(func);
4989 function wrapper() {
4990 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4991 return fn.apply(isBind ? thisArg : this, arguments);
4997 * Creates a function like `_.lowerFirst`.
5000 * @param {string} methodName The name of the `String` case method to use.
5001 * @returns {Function} Returns the new case function.
5003 function createCaseFirst(methodName) {
5004 return function(string) {
5005 string = toString(string);
5007 var strSymbols = hasUnicode(string)
5008 ? stringToArray(string)
5011 var chr = strSymbols
5015 var trailing = strSymbols
5016 ? castSlice(strSymbols, 1).join('')
5019 return chr[methodName]() + trailing;
5024 * Creates a function like `_.camelCase`.
5027 * @param {Function} callback The function to combine each word.
5028 * @returns {Function} Returns the new compounder function.
5030 function createCompounder(callback) {
5031 return function(string) {
5032 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
5037 * Creates a function that produces an instance of `Ctor` regardless of
5038 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
5041 * @param {Function} Ctor The constructor to wrap.
5042 * @returns {Function} Returns the new wrapped function.
5044 function createCtor(Ctor) {
5046 // Use a `switch` statement to work with class constructors. See
5047 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
5048 // for more details.
5049 var args = arguments;
5050 switch (args.length) {
5051 case 0: return new Ctor;
5052 case 1: return new Ctor(args[0]);
5053 case 2: return new Ctor(args[0], args[1]);
5054 case 3: return new Ctor(args[0], args[1], args[2]);
5055 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
5056 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
5057 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
5058 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
5060 var thisBinding = baseCreate(Ctor.prototype),
5061 result = Ctor.apply(thisBinding, args);
5063 // Mimic the constructor's `return` behavior.
5064 // See https://es5.github.io/#x13.2.2 for more details.
5065 return isObject(result) ? result : thisBinding;
5070 * Creates a function that wraps `func` to enable currying.
5073 * @param {Function} func The function to wrap.
5074 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5075 * @param {number} arity The arity of `func`.
5076 * @returns {Function} Returns the new wrapped function.
5078 function createCurry(func, bitmask, arity) {
5079 var Ctor = createCtor(func);
5081 function wrapper() {
5082 var length = arguments.length,
5083 args = Array(length),
5085 placeholder = getHolder(wrapper);
5088 args[index] = arguments[index];
5090 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
5092 : replaceHolders(args, placeholder);
5094 length -= holders.length;
5095 if (length < arity) {
5096 return createRecurry(
5097 func, bitmask, createHybrid, wrapper.placeholder, undefined,
5098 args, holders, undefined, undefined, arity - length);
5100 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5101 return apply(fn, this, args);
5107 * Creates a `_.find` or `_.findLast` function.
5110 * @param {Function} findIndexFunc The function to find the collection index.
5111 * @returns {Function} Returns the new find function.
5113 function createFind(findIndexFunc) {
5114 return function(collection, predicate, fromIndex) {
5115 var iterable = Object(collection);
5116 if (!isArrayLike(collection)) {
5117 var iteratee = getIteratee(predicate, 3);
5118 collection = keys(collection);
5119 predicate = function(key) { return iteratee(iterable[key], key, iterable); };
5121 var index = findIndexFunc(collection, predicate, fromIndex);
5122 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
5127 * Creates a `_.flow` or `_.flowRight` function.
5130 * @param {boolean} [fromRight] Specify iterating from right to left.
5131 * @returns {Function} Returns the new flow function.
5133 function createFlow(fromRight) {
5134 return flatRest(function(funcs) {
5135 var length = funcs.length,
5137 prereq = LodashWrapper.prototype.thru;
5143 var func = funcs[index];
5144 if (typeof func != 'function') {
5145 throw new TypeError(FUNC_ERROR_TEXT);
5147 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
5148 var wrapper = new LodashWrapper([], true);
5151 index = wrapper ? index : length;
5152 while (++index < length) {
5153 func = funcs[index];
5155 var funcName = getFuncName(func),
5156 data = funcName == 'wrapper' ? getData(func) : undefined;
5158 if (data && isLaziable(data[0]) &&
5159 data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
5160 !data[4].length && data[9] == 1
5162 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
5164 wrapper = (func.length == 1 && isLaziable(func))
5165 ? wrapper[funcName]()
5166 : wrapper.thru(func);
5170 var args = arguments,
5173 if (wrapper && args.length == 1 && isArray(value)) {
5174 return wrapper.plant(value).value();
5177 result = length ? funcs[index].apply(this, args) : value;
5179 while (++index < length) {
5180 result = funcs[index].call(this, result);
5188 * Creates a function that wraps `func` to invoke it with optional `this`
5189 * binding of `thisArg`, partial application, and currying.
5192 * @param {Function|string} func The function or method name to wrap.
5193 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5194 * @param {*} [thisArg] The `this` binding of `func`.
5195 * @param {Array} [partials] The arguments to prepend to those provided to
5197 * @param {Array} [holders] The `partials` placeholder indexes.
5198 * @param {Array} [partialsRight] The arguments to append to those provided
5199 * to the new function.
5200 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
5201 * @param {Array} [argPos] The argument positions of the new function.
5202 * @param {number} [ary] The arity cap of `func`.
5203 * @param {number} [arity] The arity of `func`.
5204 * @returns {Function} Returns the new wrapped function.
5206 function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
5207 var isAry = bitmask & WRAP_ARY_FLAG,
5208 isBind = bitmask & WRAP_BIND_FLAG,
5209 isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
5210 isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
5211 isFlip = bitmask & WRAP_FLIP_FLAG,
5212 Ctor = isBindKey ? undefined : createCtor(func);
5214 function wrapper() {
5215 var length = arguments.length,
5216 args = Array(length),
5220 args[index] = arguments[index];
5223 var placeholder = getHolder(wrapper),
5224 holdersCount = countHolders(args, placeholder);
5227 args = composeArgs(args, partials, holders, isCurried);
5229 if (partialsRight) {
5230 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
5232 length -= holdersCount;
5233 if (isCurried && length < arity) {
5234 var newHolders = replaceHolders(args, placeholder);
5235 return createRecurry(
5236 func, bitmask, createHybrid, wrapper.placeholder, thisArg,
5237 args, newHolders, argPos, ary, arity - length
5240 var thisBinding = isBind ? thisArg : this,
5241 fn = isBindKey ? thisBinding[func] : func;
5243 length = args.length;
5245 args = reorder(args, argPos);
5246 } else if (isFlip && length > 1) {
5249 if (isAry && ary < length) {
5252 if (this && this !== root && this instanceof wrapper) {
5253 fn = Ctor || createCtor(fn);
5255 return fn.apply(thisBinding, args);
5261 * Creates a function like `_.invertBy`.
5264 * @param {Function} setter The function to set accumulator values.
5265 * @param {Function} toIteratee The function to resolve iteratees.
5266 * @returns {Function} Returns the new inverter function.
5268 function createInverter(setter, toIteratee) {
5269 return function(object, iteratee) {
5270 return baseInverter(object, setter, toIteratee(iteratee), {});
5275 * Creates a function that performs a mathematical operation on two values.
5278 * @param {Function} operator The function to perform the operation.
5279 * @param {number} [defaultValue] The value used for `undefined` arguments.
5280 * @returns {Function} Returns the new mathematical operation function.
5282 function createMathOperation(operator, defaultValue) {
5283 return function(value, other) {
5285 if (value === undefined && other === undefined) {
5286 return defaultValue;
5288 if (value !== undefined) {
5291 if (other !== undefined) {
5292 if (result === undefined) {
5295 if (typeof value == 'string' || typeof other == 'string') {
5296 value = baseToString(value);
5297 other = baseToString(other);
5299 value = baseToNumber(value);
5300 other = baseToNumber(other);
5302 result = operator(value, other);
5309 * Creates a function like `_.over`.
5312 * @param {Function} arrayFunc The function to iterate over iteratees.
5313 * @returns {Function} Returns the new over function.
5315 function createOver(arrayFunc) {
5316 return flatRest(function(iteratees) {
5317 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
5318 return baseRest(function(args) {
5320 return arrayFunc(iteratees, function(iteratee) {
5321 return apply(iteratee, thisArg, args);
5328 * Creates the padding for `string` based on `length`. The `chars` string
5329 * is truncated if the number of characters exceeds `length`.
5332 * @param {number} length The padding length.
5333 * @param {string} [chars=' '] The string used as padding.
5334 * @returns {string} Returns the padding for `string`.
5336 function createPadding(length, chars) {
5337 chars = chars === undefined ? ' ' : baseToString(chars);
5339 var charsLength = chars.length;
5340 if (charsLength < 2) {
5341 return charsLength ? baseRepeat(chars, length) : chars;
5343 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
5344 return hasUnicode(chars)
5345 ? castSlice(stringToArray(result), 0, length).join('')
5346 : result.slice(0, length);
5350 * Creates a function that wraps `func` to invoke it with the `this` binding
5351 * of `thisArg` and `partials` prepended to the arguments it receives.
5354 * @param {Function} func The function to wrap.
5355 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5356 * @param {*} thisArg The `this` binding of `func`.
5357 * @param {Array} partials The arguments to prepend to those provided to
5359 * @returns {Function} Returns the new wrapped function.
5361 function createPartial(func, bitmask, thisArg, partials) {
5362 var isBind = bitmask & WRAP_BIND_FLAG,
5363 Ctor = createCtor(func);
5365 function wrapper() {
5367 argsLength = arguments.length,
5369 leftLength = partials.length,
5370 args = Array(leftLength + argsLength),
5371 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5373 while (++leftIndex < leftLength) {
5374 args[leftIndex] = partials[leftIndex];
5376 while (argsLength--) {
5377 args[leftIndex++] = arguments[++argsIndex];
5379 return apply(fn, isBind ? thisArg : this, args);
5385 * Creates a `_.range` or `_.rangeRight` function.
5388 * @param {boolean} [fromRight] Specify iterating from right to left.
5389 * @returns {Function} Returns the new range function.
5391 function createRange(fromRight) {
5392 return function(start, end, step) {
5393 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
5394 end = step = undefined;
5396 // Ensure the sign of `-0` is preserved.
5397 start = toFinite(start);
5398 if (end === undefined) {
5402 end = toFinite(end);
5404 step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
5405 return baseRange(start, end, step, fromRight);
5410 * Creates a function that performs a relational operation on two values.
5413 * @param {Function} operator The function to perform the operation.
5414 * @returns {Function} Returns the new relational operation function.
5416 function createRelationalOperation(operator) {
5417 return function(value, other) {
5418 if (!(typeof value == 'string' && typeof other == 'string')) {
5419 value = toNumber(value);
5420 other = toNumber(other);
5422 return operator(value, other);
5427 * Creates a function that wraps `func` to continue currying.
5430 * @param {Function} func The function to wrap.
5431 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5432 * @param {Function} wrapFunc The function to create the `func` wrapper.
5433 * @param {*} placeholder The placeholder value.
5434 * @param {*} [thisArg] The `this` binding of `func`.
5435 * @param {Array} [partials] The arguments to prepend to those provided to
5437 * @param {Array} [holders] The `partials` placeholder indexes.
5438 * @param {Array} [argPos] The argument positions of the new function.
5439 * @param {number} [ary] The arity cap of `func`.
5440 * @param {number} [arity] The arity of `func`.
5441 * @returns {Function} Returns the new wrapped function.
5443 function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
5444 var isCurry = bitmask & WRAP_CURRY_FLAG,
5445 newHolders = isCurry ? holders : undefined,
5446 newHoldersRight = isCurry ? undefined : holders,
5447 newPartials = isCurry ? partials : undefined,
5448 newPartialsRight = isCurry ? undefined : partials;
5450 bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
5451 bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
5453 if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
5454 bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
5457 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
5458 newHoldersRight, argPos, ary, arity
5461 var result = wrapFunc.apply(undefined, newData);
5462 if (isLaziable(func)) {
5463 setData(result, newData);
5465 result.placeholder = placeholder;
5466 return setWrapToString(result, func, bitmask);
5470 * Creates a function like `_.round`.
5473 * @param {string} methodName The name of the `Math` method to use when rounding.
5474 * @returns {Function} Returns the new round function.
5476 function createRound(methodName) {
5477 var func = Math[methodName];
5478 return function(number, precision) {
5479 number = toNumber(number);
5480 precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
5481 if (precision && nativeIsFinite(number)) {
5482 // Shift with exponential notation to avoid floating-point issues.
5483 // See [MDN](https://mdn.io/round#Examples) for more details.
5484 var pair = (toString(number) + 'e').split('e'),
5485 value = func(pair[0] + 'e' + (+pair[1] + precision));
5487 pair = (toString(value) + 'e').split('e');
5488 return +(pair[0] + 'e' + (+pair[1] - precision));
5490 return func(number);
5495 * Creates a set object of `values`.
5498 * @param {Array} values The values to add to the set.
5499 * @returns {Object} Returns the new set.
5501 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
5502 return new Set(values);
5506 * Creates a `_.toPairs` or `_.toPairsIn` function.
5509 * @param {Function} keysFunc The function to get the keys of a given object.
5510 * @returns {Function} Returns the new pairs function.
5512 function createToPairs(keysFunc) {
5513 return function(object) {
5514 var tag = getTag(object);
5515 if (tag == mapTag) {
5516 return mapToArray(object);
5518 if (tag == setTag) {
5519 return setToPairs(object);
5521 return baseToPairs(object, keysFunc(object));
5526 * Creates a function that either curries or invokes `func` with optional
5527 * `this` binding and partially applied arguments.
5530 * @param {Function|string} func The function or method name to wrap.
5531 * @param {number} bitmask The bitmask flags.
5534 * 4 - `_.curry` or `_.curryRight` of a bound function
5536 * 16 - `_.curryRight`
5538 * 64 - `_.partialRight`
5542 * @param {*} [thisArg] The `this` binding of `func`.
5543 * @param {Array} [partials] The arguments to be partially applied.
5544 * @param {Array} [holders] The `partials` placeholder indexes.
5545 * @param {Array} [argPos] The argument positions of the new function.
5546 * @param {number} [ary] The arity cap of `func`.
5547 * @param {number} [arity] The arity of `func`.
5548 * @returns {Function} Returns the new wrapped function.
5550 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
5551 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
5552 if (!isBindKey && typeof func != 'function') {
5553 throw new TypeError(FUNC_ERROR_TEXT);
5555 var length = partials ? partials.length : 0;
5557 bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
5558 partials = holders = undefined;
5560 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
5561 arity = arity === undefined ? arity : toInteger(arity);
5562 length -= holders ? holders.length : 0;
5564 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
5565 var partialsRight = partials,
5566 holdersRight = holders;
5568 partials = holders = undefined;
5570 var data = isBindKey ? undefined : getData(func);
5573 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
5578 mergeData(newData, data);
5581 bitmask = newData[1];
5582 thisArg = newData[2];
5583 partials = newData[3];
5584 holders = newData[4];
5585 arity = newData[9] = newData[9] === undefined
5586 ? (isBindKey ? 0 : func.length)
5587 : nativeMax(newData[9] - length, 0);
5589 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
5590 bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
5592 if (!bitmask || bitmask == WRAP_BIND_FLAG) {
5593 var result = createBind(func, bitmask, thisArg);
5594 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
5595 result = createCurry(func, bitmask, arity);
5596 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
5597 result = createPartial(func, bitmask, thisArg, partials);
5599 result = createHybrid.apply(undefined, newData);
5601 var setter = data ? baseSetData : setData;
5602 return setWrapToString(setter(result, newData), func, bitmask);
5606 * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
5607 * of source objects to the destination object for all destination properties
5608 * that resolve to `undefined`.
5611 * @param {*} objValue The destination value.
5612 * @param {*} srcValue The source value.
5613 * @param {string} key The key of the property to assign.
5614 * @param {Object} object The parent object of `objValue`.
5615 * @returns {*} Returns the value to assign.
5617 function customDefaultsAssignIn(objValue, srcValue, key, object) {
5618 if (objValue === undefined ||
5619 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
5626 * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
5627 * objects into destination objects that are passed thru.
5630 * @param {*} objValue The destination value.
5631 * @param {*} srcValue The source value.
5632 * @param {string} key The key of the property to merge.
5633 * @param {Object} object The parent object of `objValue`.
5634 * @param {Object} source The parent object of `srcValue`.
5635 * @param {Object} [stack] Tracks traversed source values and their merged
5637 * @returns {*} Returns the value to assign.
5639 function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
5640 if (isObject(objValue) && isObject(srcValue)) {
5641 // Recursively merge objects and arrays (susceptible to call stack limits).
5642 stack.set(srcValue, objValue);
5643 baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
5644 stack['delete'](srcValue);
5650 * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
5654 * @param {*} value The value to inspect.
5655 * @param {string} key The key of the property to inspect.
5656 * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
5658 function customOmitClone(value) {
5659 return isPlainObject(value) ? undefined : value;
5663 * A specialized version of `baseIsEqualDeep` for arrays with support for
5664 * partial deep comparisons.
5667 * @param {Array} array The array to compare.
5668 * @param {Array} other The other array to compare.
5669 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5670 * @param {Function} customizer The function to customize comparisons.
5671 * @param {Function} equalFunc The function to determine equivalents of values.
5672 * @param {Object} stack Tracks traversed `array` and `other` objects.
5673 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
5675 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
5676 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5677 arrLength = array.length,
5678 othLength = other.length;
5680 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
5683 // Check that cyclic values are equal.
5684 var arrStacked = stack.get(array);
5685 var othStacked = stack.get(other);
5686 if (arrStacked && othStacked) {
5687 return arrStacked == other && othStacked == array;
5691 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
5693 stack.set(array, other);
5694 stack.set(other, array);
5696 // Ignore non-index properties.
5697 while (++index < arrLength) {
5698 var arrValue = array[index],
5699 othValue = other[index];
5702 var compared = isPartial
5703 ? customizer(othValue, arrValue, index, other, array, stack)
5704 : customizer(arrValue, othValue, index, array, other, stack);
5706 if (compared !== undefined) {
5713 // Recursively compare arrays (susceptible to call stack limits).
5715 if (!arraySome(other, function(othValue, othIndex) {
5716 if (!cacheHas(seen, othIndex) &&
5717 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
5718 return seen.push(othIndex);
5725 arrValue === othValue ||
5726 equalFunc(arrValue, othValue, bitmask, customizer, stack)
5732 stack['delete'](array);
5733 stack['delete'](other);
5738 * A specialized version of `baseIsEqualDeep` for comparing objects of
5739 * the same `toStringTag`.
5741 * **Note:** This function only supports comparing values with tags of
5742 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5745 * @param {Object} object The object to compare.
5746 * @param {Object} other The other object to compare.
5747 * @param {string} tag The `toStringTag` of the objects to compare.
5748 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5749 * @param {Function} customizer The function to customize comparisons.
5750 * @param {Function} equalFunc The function to determine equivalents of values.
5751 * @param {Object} stack Tracks traversed `object` and `other` objects.
5752 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5754 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
5757 if ((object.byteLength != other.byteLength) ||
5758 (object.byteOffset != other.byteOffset)) {
5761 object = object.buffer;
5762 other = other.buffer;
5764 case arrayBufferTag:
5765 if ((object.byteLength != other.byteLength) ||
5766 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
5774 // Coerce booleans to `1` or `0` and dates to milliseconds.
5775 // Invalid dates are coerced to `NaN`.
5776 return eq(+object, +other);
5779 return object.name == other.name && object.message == other.message;
5783 // Coerce regexes to strings and treat strings, primitives and objects,
5784 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
5785 // for more details.
5786 return object == (other + '');
5789 var convert = mapToArray;
5792 var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
5793 convert || (convert = setToArray);
5795 if (object.size != other.size && !isPartial) {
5798 // Assume cyclic values are equal.
5799 var stacked = stack.get(object);
5801 return stacked == other;
5803 bitmask |= COMPARE_UNORDERED_FLAG;
5805 // Recursively compare objects (susceptible to call stack limits).
5806 stack.set(object, other);
5807 var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
5808 stack['delete'](object);
5812 if (symbolValueOf) {
5813 return symbolValueOf.call(object) == symbolValueOf.call(other);
5820 * A specialized version of `baseIsEqualDeep` for objects with support for
5821 * partial deep comparisons.
5824 * @param {Object} object The object to compare.
5825 * @param {Object} other The other object to compare.
5826 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5827 * @param {Function} customizer The function to customize comparisons.
5828 * @param {Function} equalFunc The function to determine equivalents of values.
5829 * @param {Object} stack Tracks traversed `object` and `other` objects.
5830 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5832 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
5833 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5834 objProps = getAllKeys(object),
5835 objLength = objProps.length,
5836 othProps = getAllKeys(other),
5837 othLength = othProps.length;
5839 if (objLength != othLength && !isPartial) {
5842 var index = objLength;
5844 var key = objProps[index];
5845 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
5849 // Check that cyclic values are equal.
5850 var objStacked = stack.get(object);
5851 var othStacked = stack.get(other);
5852 if (objStacked && othStacked) {
5853 return objStacked == other && othStacked == object;
5856 stack.set(object, other);
5857 stack.set(other, object);
5859 var skipCtor = isPartial;
5860 while (++index < objLength) {
5861 key = objProps[index];
5862 var objValue = object[key],
5863 othValue = other[key];
5866 var compared = isPartial
5867 ? customizer(othValue, objValue, key, other, object, stack)
5868 : customizer(objValue, othValue, key, object, other, stack);
5870 // Recursively compare objects (susceptible to call stack limits).
5871 if (!(compared === undefined
5872 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
5878 skipCtor || (skipCtor = key == 'constructor');
5880 if (result && !skipCtor) {
5881 var objCtor = object.constructor,
5882 othCtor = other.constructor;
5884 // Non `Object` object instances with different constructors are not equal.
5885 if (objCtor != othCtor &&
5886 ('constructor' in object && 'constructor' in other) &&
5887 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
5888 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
5892 stack['delete'](object);
5893 stack['delete'](other);
5898 * A specialized version of `baseRest` which flattens the rest array.
5901 * @param {Function} func The function to apply a rest parameter to.
5902 * @returns {Function} Returns the new function.
5904 function flatRest(func) {
5905 return setToString(overRest(func, undefined, flatten), func + '');
5909 * Creates an array of own enumerable property names and symbols of `object`.
5912 * @param {Object} object The object to query.
5913 * @returns {Array} Returns the array of property names and symbols.
5915 function getAllKeys(object) {
5916 return baseGetAllKeys(object, keys, getSymbols);
5920 * Creates an array of own and inherited enumerable property names and
5921 * symbols of `object`.
5924 * @param {Object} object The object to query.
5925 * @returns {Array} Returns the array of property names and symbols.
5927 function getAllKeysIn(object) {
5928 return baseGetAllKeys(object, keysIn, getSymbolsIn);
5932 * Gets metadata for `func`.
5935 * @param {Function} func The function to query.
5936 * @returns {*} Returns the metadata for `func`.
5938 var getData = !metaMap ? noop : function(func) {
5939 return metaMap.get(func);
5943 * Gets the name of `func`.
5946 * @param {Function} func The function to query.
5947 * @returns {string} Returns the function name.
5949 function getFuncName(func) {
5950 var result = (func.name + ''),
5951 array = realNames[result],
5952 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
5955 var data = array[length],
5956 otherFunc = data.func;
5957 if (otherFunc == null || otherFunc == func) {
5965 * Gets the argument placeholder value for `func`.
5968 * @param {Function} func The function to inspect.
5969 * @returns {*} Returns the placeholder value.
5971 function getHolder(func) {
5972 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
5973 return object.placeholder;
5977 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
5978 * this function returns the custom method, otherwise it returns `baseIteratee`.
5979 * If arguments are provided, the chosen function is invoked with them and
5980 * its result is returned.
5983 * @param {*} [value] The value to convert to an iteratee.
5984 * @param {number} [arity] The arity of the created iteratee.
5985 * @returns {Function} Returns the chosen function or its result.
5987 function getIteratee() {
5988 var result = lodash.iteratee || iteratee;
5989 result = result === iteratee ? baseIteratee : result;
5990 return arguments.length ? result(arguments[0], arguments[1]) : result;
5994 * Gets the data for `map`.
5997 * @param {Object} map The map to query.
5998 * @param {string} key The reference key.
5999 * @returns {*} Returns the map data.
6001 function getMapData(map, key) {
6002 var data = map.__data__;
6003 return isKeyable(key)
6004 ? data[typeof key == 'string' ? 'string' : 'hash']
6009 * Gets the property names, values, and compare flags of `object`.
6012 * @param {Object} object The object to query.
6013 * @returns {Array} Returns the match data of `object`.
6015 function getMatchData(object) {
6016 var result = keys(object),
6017 length = result.length;
6020 var key = result[length],
6021 value = object[key];
6023 result[length] = [key, value, isStrictComparable(value)];
6029 * Gets the native function at `key` of `object`.
6032 * @param {Object} object The object to query.
6033 * @param {string} key The key of the method to get.
6034 * @returns {*} Returns the function if it's native, else `undefined`.
6036 function getNative(object, key) {
6037 var value = getValue(object, key);
6038 return baseIsNative(value) ? value : undefined;
6042 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
6045 * @param {*} value The value to query.
6046 * @returns {string} Returns the raw `toStringTag`.
6048 function getRawTag(value) {
6049 var isOwn = hasOwnProperty.call(value, symToStringTag),
6050 tag = value[symToStringTag];
6053 value[symToStringTag] = undefined;
6054 var unmasked = true;
6057 var result = nativeObjectToString.call(value);
6060 value[symToStringTag] = tag;
6062 delete value[symToStringTag];
6069 * Creates an array of the own enumerable symbols of `object`.
6072 * @param {Object} object The object to query.
6073 * @returns {Array} Returns the array of symbols.
6075 var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
6076 if (object == null) {
6079 object = Object(object);
6080 return arrayFilter(nativeGetSymbols(object), function(symbol) {
6081 return propertyIsEnumerable.call(object, symbol);
6086 * Creates an array of the own and inherited enumerable symbols of `object`.
6089 * @param {Object} object The object to query.
6090 * @returns {Array} Returns the array of symbols.
6092 var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
6095 arrayPush(result, getSymbols(object));
6096 object = getPrototype(object);
6102 * Gets the `toStringTag` of `value`.
6105 * @param {*} value The value to query.
6106 * @returns {string} Returns the `toStringTag`.
6108 var getTag = baseGetTag;
6110 // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
6111 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
6112 (Map && getTag(new Map) != mapTag) ||
6113 (Promise && getTag(Promise.resolve()) != promiseTag) ||
6114 (Set && getTag(new Set) != setTag) ||
6115 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
6116 getTag = function(value) {
6117 var result = baseGetTag(value),
6118 Ctor = result == objectTag ? value.constructor : undefined,
6119 ctorString = Ctor ? toSource(Ctor) : '';
6122 switch (ctorString) {
6123 case dataViewCtorString: return dataViewTag;
6124 case mapCtorString: return mapTag;
6125 case promiseCtorString: return promiseTag;
6126 case setCtorString: return setTag;
6127 case weakMapCtorString: return weakMapTag;
6135 * Gets the view, applying any `transforms` to the `start` and `end` positions.
6138 * @param {number} start The start of the view.
6139 * @param {number} end The end of the view.
6140 * @param {Array} transforms The transformations to apply to the view.
6141 * @returns {Object} Returns an object containing the `start` and `end`
6142 * positions of the view.
6144 function getView(start, end, transforms) {
6146 length = transforms.length;
6148 while (++index < length) {
6149 var data = transforms[index],
6152 switch (data.type) {
6153 case 'drop': start += size; break;
6154 case 'dropRight': end -= size; break;
6155 case 'take': end = nativeMin(end, start + size); break;
6156 case 'takeRight': start = nativeMax(start, end - size); break;
6159 return { 'start': start, 'end': end };
6163 * Extracts wrapper details from the `source` body comment.
6166 * @param {string} source The source to inspect.
6167 * @returns {Array} Returns the wrapper details.
6169 function getWrapDetails(source) {
6170 var match = source.match(reWrapDetails);
6171 return match ? match[1].split(reSplitDetails) : [];
6175 * Checks if `path` exists on `object`.
6178 * @param {Object} object The object to query.
6179 * @param {Array|string} path The path to check.
6180 * @param {Function} hasFunc The function to check properties.
6181 * @returns {boolean} Returns `true` if `path` exists, else `false`.
6183 function hasPath(object, path, hasFunc) {
6184 path = castPath(path, object);
6187 length = path.length,
6190 while (++index < length) {
6191 var key = toKey(path[index]);
6192 if (!(result = object != null && hasFunc(object, key))) {
6195 object = object[key];
6197 if (result || ++index != length) {
6200 length = object == null ? 0 : object.length;
6201 return !!length && isLength(length) && isIndex(key, length) &&
6202 (isArray(object) || isArguments(object));
6206 * Initializes an array clone.
6209 * @param {Array} array The array to clone.
6210 * @returns {Array} Returns the initialized clone.
6212 function initCloneArray(array) {
6213 var length = array.length,
6214 result = new array.constructor(length);
6216 // Add properties assigned by `RegExp#exec`.
6217 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
6218 result.index = array.index;
6219 result.input = array.input;
6225 * Initializes an object clone.
6228 * @param {Object} object The object to clone.
6229 * @returns {Object} Returns the initialized clone.
6231 function initCloneObject(object) {
6232 return (typeof object.constructor == 'function' && !isPrototype(object))
6233 ? baseCreate(getPrototype(object))
6238 * Initializes an object clone based on its `toStringTag`.
6240 * **Note:** This function only supports cloning values with tags of
6241 * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
6244 * @param {Object} object The object to clone.
6245 * @param {string} tag The `toStringTag` of the object to clone.
6246 * @param {boolean} [isDeep] Specify a deep clone.
6247 * @returns {Object} Returns the initialized clone.
6249 function initCloneByTag(object, tag, isDeep) {
6250 var Ctor = object.constructor;
6252 case arrayBufferTag:
6253 return cloneArrayBuffer(object);
6257 return new Ctor(+object);
6260 return cloneDataView(object, isDeep);
6262 case float32Tag: case float64Tag:
6263 case int8Tag: case int16Tag: case int32Tag:
6264 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
6265 return cloneTypedArray(object, isDeep);
6272 return new Ctor(object);
6275 return cloneRegExp(object);
6281 return cloneSymbol(object);
6286 * Inserts wrapper `details` in a comment at the top of the `source` body.
6289 * @param {string} source The source to modify.
6290 * @returns {Array} details The details to insert.
6291 * @returns {string} Returns the modified source.
6293 function insertWrapDetails(source, details) {
6294 var length = details.length;
6298 var lastIndex = length - 1;
6299 details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
6300 details = details.join(length > 2 ? ', ' : ' ');
6301 return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
6305 * Checks if `value` is a flattenable `arguments` object or array.
6308 * @param {*} value The value to check.
6309 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
6311 function isFlattenable(value) {
6312 return isArray(value) || isArguments(value) ||
6313 !!(spreadableSymbol && value && value[spreadableSymbol]);
6317 * Checks if `value` is a valid array-like index.
6320 * @param {*} value The value to check.
6321 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
6322 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
6324 function isIndex(value, length) {
6325 var type = typeof value;
6326 length = length == null ? MAX_SAFE_INTEGER : length;
6329 (type == 'number' ||
6330 (type != 'symbol' && reIsUint.test(value))) &&
6331 (value > -1 && value % 1 == 0 && value < length);
6335 * Checks if the given arguments are from an iteratee call.
6338 * @param {*} value The potential iteratee value argument.
6339 * @param {*} index The potential iteratee index or key argument.
6340 * @param {*} object The potential iteratee object argument.
6341 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
6344 function isIterateeCall(value, index, object) {
6345 if (!isObject(object)) {
6348 var type = typeof index;
6349 if (type == 'number'
6350 ? (isArrayLike(object) && isIndex(index, object.length))
6351 : (type == 'string' && index in object)
6353 return eq(object[index], value);
6359 * Checks if `value` is a property name and not a property path.
6362 * @param {*} value The value to check.
6363 * @param {Object} [object] The object to query keys on.
6364 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
6366 function isKey(value, object) {
6367 if (isArray(value)) {
6370 var type = typeof value;
6371 if (type == 'number' || type == 'symbol' || type == 'boolean' ||
6372 value == null || isSymbol(value)) {
6375 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
6376 (object != null && value in Object(object));
6380 * Checks if `value` is suitable for use as unique object key.
6383 * @param {*} value The value to check.
6384 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
6386 function isKeyable(value) {
6387 var type = typeof value;
6388 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
6389 ? (value !== '__proto__')
6394 * Checks if `func` has a lazy counterpart.
6397 * @param {Function} func The function to check.
6398 * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
6401 function isLaziable(func) {
6402 var funcName = getFuncName(func),
6403 other = lodash[funcName];
6405 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
6408 if (func === other) {
6411 var data = getData(other);
6412 return !!data && func === data[0];
6416 * Checks if `func` has its source masked.
6419 * @param {Function} func The function to check.
6420 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
6422 function isMasked(func) {
6423 return !!maskSrcKey && (maskSrcKey in func);
6427 * Checks if `func` is capable of being masked.
6430 * @param {*} value The value to check.
6431 * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
6433 var isMaskable = coreJsData ? isFunction : stubFalse;
6436 * Checks if `value` is likely a prototype object.
6439 * @param {*} value The value to check.
6440 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
6442 function isPrototype(value) {
6443 var Ctor = value && value.constructor,
6444 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
6446 return value === proto;
6450 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
6453 * @param {*} value The value to check.
6454 * @returns {boolean} Returns `true` if `value` if suitable for strict
6455 * equality comparisons, else `false`.
6457 function isStrictComparable(value) {
6458 return value === value && !isObject(value);
6462 * A specialized version of `matchesProperty` for source values suitable
6463 * for strict equality comparisons, i.e. `===`.
6466 * @param {string} key The key of the property to get.
6467 * @param {*} srcValue The value to match.
6468 * @returns {Function} Returns the new spec function.
6470 function matchesStrictComparable(key, srcValue) {
6471 return function(object) {
6472 if (object == null) {
6475 return object[key] === srcValue &&
6476 (srcValue !== undefined || (key in Object(object)));
6481 * A specialized version of `_.memoize` which clears the memoized function's
6482 * cache when it exceeds `MAX_MEMOIZE_SIZE`.
6485 * @param {Function} func The function to have its output memoized.
6486 * @returns {Function} Returns the new memoized function.
6488 function memoizeCapped(func) {
6489 var result = memoize(func, function(key) {
6490 if (cache.size === MAX_MEMOIZE_SIZE) {
6496 var cache = result.cache;
6501 * Merges the function metadata of `source` into `data`.
6503 * Merging metadata reduces the number of wrappers used to invoke a function.
6504 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
6505 * may be applied regardless of execution order. Methods like `_.ary` and
6506 * `_.rearg` modify function arguments, making the order in which they are
6507 * executed important, preventing the merging of metadata. However, we make
6508 * an exception for a safe combined case where curried functions have `_.ary`
6509 * and or `_.rearg` applied.
6512 * @param {Array} data The destination metadata.
6513 * @param {Array} source The source metadata.
6514 * @returns {Array} Returns `data`.
6516 function mergeData(data, source) {
6517 var bitmask = data[1],
6518 srcBitmask = source[1],
6519 newBitmask = bitmask | srcBitmask,
6520 isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
6523 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
6524 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
6525 ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
6527 // Exit early if metadata can't be merged.
6528 if (!(isCommon || isCombo)) {
6531 // Use source `thisArg` if available.
6532 if (srcBitmask & WRAP_BIND_FLAG) {
6533 data[2] = source[2];
6534 // Set when currying a bound function.
6535 newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
6537 // Compose partial arguments.
6538 var value = source[3];
6540 var partials = data[3];
6541 data[3] = partials ? composeArgs(partials, value, source[4]) : value;
6542 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
6544 // Compose partial right arguments.
6548 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
6549 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
6551 // Use source `argPos` if available.
6556 // Use source `ary` if it's smaller.
6557 if (srcBitmask & WRAP_ARY_FLAG) {
6558 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
6560 // Use source `arity` if one is not provided.
6561 if (data[9] == null) {
6562 data[9] = source[9];
6564 // Use source `func` and merge bitmasks.
6565 data[0] = source[0];
6566 data[1] = newBitmask;
6572 * This function is like
6573 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
6574 * except that it includes inherited enumerable properties.
6577 * @param {Object} object The object to query.
6578 * @returns {Array} Returns the array of property names.
6580 function nativeKeysIn(object) {
6582 if (object != null) {
6583 for (var key in Object(object)) {
6591 * Converts `value` to a string using `Object.prototype.toString`.
6594 * @param {*} value The value to convert.
6595 * @returns {string} Returns the converted string.
6597 function objectToString(value) {
6598 return nativeObjectToString.call(value);
6602 * A specialized version of `baseRest` which transforms the rest array.
6605 * @param {Function} func The function to apply a rest parameter to.
6606 * @param {number} [start=func.length-1] The start position of the rest parameter.
6607 * @param {Function} transform The rest array transform.
6608 * @returns {Function} Returns the new function.
6610 function overRest(func, start, transform) {
6611 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
6613 var args = arguments,
6615 length = nativeMax(args.length - start, 0),
6616 array = Array(length);
6618 while (++index < length) {
6619 array[index] = args[start + index];
6622 var otherArgs = Array(start + 1);
6623 while (++index < start) {
6624 otherArgs[index] = args[index];
6626 otherArgs[start] = transform(array);
6627 return apply(func, this, otherArgs);
6632 * Gets the parent value at `path` of `object`.
6635 * @param {Object} object The object to query.
6636 * @param {Array} path The path to get the parent value of.
6637 * @returns {*} Returns the parent value.
6639 function parent(object, path) {
6640 return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
6644 * Reorder `array` according to the specified indexes where the element at
6645 * the first index is assigned as the first element, the element at
6646 * the second index is assigned as the second element, and so on.
6649 * @param {Array} array The array to reorder.
6650 * @param {Array} indexes The arranged array indexes.
6651 * @returns {Array} Returns `array`.
6653 function reorder(array, indexes) {
6654 var arrLength = array.length,
6655 length = nativeMin(indexes.length, arrLength),
6656 oldArray = copyArray(array);
6659 var index = indexes[length];
6660 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
6666 * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
6669 * @param {Object} object The object to query.
6670 * @param {string} key The key of the property to get.
6671 * @returns {*} Returns the property value.
6673 function safeGet(object, key) {
6674 if (key === 'constructor' && typeof object[key] === 'function') {
6678 if (key == '__proto__') {
6686 * Sets metadata for `func`.
6688 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
6689 * period of time, it will trip its breaker and transition to an identity
6690 * function to avoid garbage collection pauses in V8. See
6691 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
6695 * @param {Function} func The function to associate metadata with.
6696 * @param {*} data The metadata.
6697 * @returns {Function} Returns `func`.
6699 var setData = shortOut(baseSetData);
6702 * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
6705 * @param {Function} func The function to delay.
6706 * @param {number} wait The number of milliseconds to delay invocation.
6707 * @returns {number|Object} Returns the timer id or timeout object.
6709 var setTimeout = ctxSetTimeout || function(func, wait) {
6710 return root.setTimeout(func, wait);
6714 * Sets the `toString` method of `func` to return `string`.
6717 * @param {Function} func The function to modify.
6718 * @param {Function} string The `toString` result.
6719 * @returns {Function} Returns `func`.
6721 var setToString = shortOut(baseSetToString);
6724 * Sets the `toString` method of `wrapper` to mimic the source of `reference`
6725 * with wrapper details in a comment at the top of the source body.
6728 * @param {Function} wrapper The function to modify.
6729 * @param {Function} reference The reference function.
6730 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6731 * @returns {Function} Returns `wrapper`.
6733 function setWrapToString(wrapper, reference, bitmask) {
6734 var source = (reference + '');
6735 return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
6739 * Creates a function that'll short out and invoke `identity` instead
6740 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
6744 * @param {Function} func The function to restrict.
6745 * @returns {Function} Returns the new shortable function.
6747 function shortOut(func) {
6752 var stamp = nativeNow(),
6753 remaining = HOT_SPAN - (stamp - lastCalled);
6756 if (remaining > 0) {
6757 if (++count >= HOT_COUNT) {
6758 return arguments[0];
6763 return func.apply(undefined, arguments);
6768 * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
6771 * @param {Array} array The array to shuffle.
6772 * @param {number} [size=array.length] The size of `array`.
6773 * @returns {Array} Returns `array`.
6775 function shuffleSelf(array, size) {
6777 length = array.length,
6778 lastIndex = length - 1;
6780 size = size === undefined ? length : size;
6781 while (++index < size) {
6782 var rand = baseRandom(index, lastIndex),
6783 value = array[rand];
6785 array[rand] = array[index];
6786 array[index] = value;
6788 array.length = size;
6793 * Converts `string` to a property path array.
6796 * @param {string} string The string to convert.
6797 * @returns {Array} Returns the property path array.
6799 var stringToPath = memoizeCapped(function(string) {
6801 if (string.charCodeAt(0) === 46 /* . */) {
6804 string.replace(rePropName, function(match, number, quote, subString) {
6805 result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
6811 * Converts `value` to a string key if it's not a string or symbol.
6814 * @param {*} value The value to inspect.
6815 * @returns {string|symbol} Returns the key.
6817 function toKey(value) {
6818 if (typeof value == 'string' || isSymbol(value)) {
6821 var result = (value + '');
6822 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
6826 * Converts `func` to its source code.
6829 * @param {Function} func The function to convert.
6830 * @returns {string} Returns the source code.
6832 function toSource(func) {
6835 return funcToString.call(func);
6845 * Updates wrapper `details` based on `bitmask` flags.
6848 * @returns {Array} details The details to modify.
6849 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6850 * @returns {Array} Returns `details`.
6852 function updateWrapDetails(details, bitmask) {
6853 arrayEach(wrapFlags, function(pair) {
6854 var value = '_.' + pair[0];
6855 if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
6856 details.push(value);
6859 return details.sort();
6863 * Creates a clone of `wrapper`.
6866 * @param {Object} wrapper The wrapper to clone.
6867 * @returns {Object} Returns the cloned wrapper.
6869 function wrapperClone(wrapper) {
6870 if (wrapper instanceof LazyWrapper) {
6871 return wrapper.clone();
6873 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
6874 result.__actions__ = copyArray(wrapper.__actions__);
6875 result.__index__ = wrapper.__index__;
6876 result.__values__ = wrapper.__values__;
6880 /*------------------------------------------------------------------------*/
6883 * Creates an array of elements split into groups the length of `size`.
6884 * If `array` can't be split evenly, the final chunk will be the remaining
6891 * @param {Array} array The array to process.
6892 * @param {number} [size=1] The length of each chunk
6893 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6894 * @returns {Array} Returns the new array of chunks.
6897 * _.chunk(['a', 'b', 'c', 'd'], 2);
6898 * // => [['a', 'b'], ['c', 'd']]
6900 * _.chunk(['a', 'b', 'c', 'd'], 3);
6901 * // => [['a', 'b', 'c'], ['d']]
6903 function chunk(array, size, guard) {
6904 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
6907 size = nativeMax(toInteger(size), 0);
6909 var length = array == null ? 0 : array.length;
6910 if (!length || size < 1) {
6915 result = Array(nativeCeil(length / size));
6917 while (index < length) {
6918 result[resIndex++] = baseSlice(array, index, (index += size));
6924 * Creates an array with all falsey values removed. The values `false`, `null`,
6925 * `0`, `""`, `undefined`, and `NaN` are falsey.
6931 * @param {Array} array The array to compact.
6932 * @returns {Array} Returns the new array of filtered values.
6935 * _.compact([0, 1, false, 2, '', 3]);
6938 function compact(array) {
6940 length = array == null ? 0 : array.length,
6944 while (++index < length) {
6945 var value = array[index];
6947 result[resIndex++] = value;
6954 * Creates a new array concatenating `array` with any additional arrays
6961 * @param {Array} array The array to concatenate.
6962 * @param {...*} [values] The values to concatenate.
6963 * @returns {Array} Returns the new concatenated array.
6967 * var other = _.concat(array, 2, [3], [[4]]);
6969 * console.log(other);
6970 * // => [1, 2, 3, [4]]
6972 * console.log(array);
6976 var length = arguments.length;
6980 var args = Array(length - 1),
6981 array = arguments[0],
6985 args[index - 1] = arguments[index];
6987 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
6991 * Creates an array of `array` values not included in the other given arrays
6992 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
6993 * for equality comparisons. The order and references of result values are
6994 * determined by the first array.
6996 * **Note:** Unlike `_.pullAll`, this method returns a new array.
7002 * @param {Array} array The array to inspect.
7003 * @param {...Array} [values] The values to exclude.
7004 * @returns {Array} Returns the new array of filtered values.
7005 * @see _.without, _.xor
7008 * _.difference([2, 1], [2, 3]);
7011 var difference = baseRest(function(array, values) {
7012 return isArrayLikeObject(array)
7013 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
7018 * This method is like `_.difference` except that it accepts `iteratee` which
7019 * is invoked for each element of `array` and `values` to generate the criterion
7020 * by which they're compared. The order and references of result values are
7021 * determined by the first array. The iteratee is invoked with one argument:
7024 * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
7030 * @param {Array} array The array to inspect.
7031 * @param {...Array} [values] The values to exclude.
7032 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7033 * @returns {Array} Returns the new array of filtered values.
7036 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7039 * // The `_.property` iteratee shorthand.
7040 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
7041 * // => [{ 'x': 2 }]
7043 var differenceBy = baseRest(function(array, values) {
7044 var iteratee = last(values);
7045 if (isArrayLikeObject(iteratee)) {
7046 iteratee = undefined;
7048 return isArrayLikeObject(array)
7049 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
7054 * This method is like `_.difference` except that it accepts `comparator`
7055 * which is invoked to compare elements of `array` to `values`. The order and
7056 * references of result values are determined by the first array. The comparator
7057 * is invoked with two arguments: (arrVal, othVal).
7059 * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
7065 * @param {Array} array The array to inspect.
7066 * @param {...Array} [values] The values to exclude.
7067 * @param {Function} [comparator] The comparator invoked per element.
7068 * @returns {Array} Returns the new array of filtered values.
7071 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7073 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
7074 * // => [{ 'x': 2, 'y': 1 }]
7076 var differenceWith = baseRest(function(array, values) {
7077 var comparator = last(values);
7078 if (isArrayLikeObject(comparator)) {
7079 comparator = undefined;
7081 return isArrayLikeObject(array)
7082 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
7087 * Creates a slice of `array` with `n` elements dropped from the beginning.
7093 * @param {Array} array The array to query.
7094 * @param {number} [n=1] The number of elements to drop.
7095 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7096 * @returns {Array} Returns the slice of `array`.
7099 * _.drop([1, 2, 3]);
7102 * _.drop([1, 2, 3], 2);
7105 * _.drop([1, 2, 3], 5);
7108 * _.drop([1, 2, 3], 0);
7111 function drop(array, n, guard) {
7112 var length = array == null ? 0 : array.length;
7116 n = (guard || n === undefined) ? 1 : toInteger(n);
7117 return baseSlice(array, n < 0 ? 0 : n, length);
7121 * Creates a slice of `array` with `n` elements dropped from the end.
7127 * @param {Array} array The array to query.
7128 * @param {number} [n=1] The number of elements to drop.
7129 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7130 * @returns {Array} Returns the slice of `array`.
7133 * _.dropRight([1, 2, 3]);
7136 * _.dropRight([1, 2, 3], 2);
7139 * _.dropRight([1, 2, 3], 5);
7142 * _.dropRight([1, 2, 3], 0);
7145 function dropRight(array, n, guard) {
7146 var length = array == null ? 0 : array.length;
7150 n = (guard || n === undefined) ? 1 : toInteger(n);
7152 return baseSlice(array, 0, n < 0 ? 0 : n);
7156 * Creates a slice of `array` excluding elements dropped from the end.
7157 * Elements are dropped until `predicate` returns falsey. The predicate is
7158 * invoked with three arguments: (value, index, array).
7164 * @param {Array} array The array to query.
7165 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7166 * @returns {Array} Returns the slice of `array`.
7170 * { 'user': 'barney', 'active': true },
7171 * { 'user': 'fred', 'active': false },
7172 * { 'user': 'pebbles', 'active': false }
7175 * _.dropRightWhile(users, function(o) { return !o.active; });
7176 * // => objects for ['barney']
7178 * // The `_.matches` iteratee shorthand.
7179 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
7180 * // => objects for ['barney', 'fred']
7182 * // The `_.matchesProperty` iteratee shorthand.
7183 * _.dropRightWhile(users, ['active', false]);
7184 * // => objects for ['barney']
7186 * // The `_.property` iteratee shorthand.
7187 * _.dropRightWhile(users, 'active');
7188 * // => objects for ['barney', 'fred', 'pebbles']
7190 function dropRightWhile(array, predicate) {
7191 return (array && array.length)
7192 ? baseWhile(array, getIteratee(predicate, 3), true, true)
7197 * Creates a slice of `array` excluding elements dropped from the beginning.
7198 * Elements are dropped until `predicate` returns falsey. The predicate is
7199 * invoked with three arguments: (value, index, array).
7205 * @param {Array} array The array to query.
7206 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7207 * @returns {Array} Returns the slice of `array`.
7211 * { 'user': 'barney', 'active': false },
7212 * { 'user': 'fred', 'active': false },
7213 * { 'user': 'pebbles', 'active': true }
7216 * _.dropWhile(users, function(o) { return !o.active; });
7217 * // => objects for ['pebbles']
7219 * // The `_.matches` iteratee shorthand.
7220 * _.dropWhile(users, { 'user': 'barney', 'active': false });
7221 * // => objects for ['fred', 'pebbles']
7223 * // The `_.matchesProperty` iteratee shorthand.
7224 * _.dropWhile(users, ['active', false]);
7225 * // => objects for ['pebbles']
7227 * // The `_.property` iteratee shorthand.
7228 * _.dropWhile(users, 'active');
7229 * // => objects for ['barney', 'fred', 'pebbles']
7231 function dropWhile(array, predicate) {
7232 return (array && array.length)
7233 ? baseWhile(array, getIteratee(predicate, 3), true)
7238 * Fills elements of `array` with `value` from `start` up to, but not
7241 * **Note:** This method mutates `array`.
7247 * @param {Array} array The array to fill.
7248 * @param {*} value The value to fill `array` with.
7249 * @param {number} [start=0] The start position.
7250 * @param {number} [end=array.length] The end position.
7251 * @returns {Array} Returns `array`.
7254 * var array = [1, 2, 3];
7256 * _.fill(array, 'a');
7257 * console.log(array);
7258 * // => ['a', 'a', 'a']
7260 * _.fill(Array(3), 2);
7263 * _.fill([4, 6, 8, 10], '*', 1, 3);
7264 * // => [4, '*', '*', 10]
7266 function fill(array, value, start, end) {
7267 var length = array == null ? 0 : array.length;
7271 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
7275 return baseFill(array, value, start, end);
7279 * This method is like `_.find` except that it returns the index of the first
7280 * element `predicate` returns truthy for instead of the element itself.
7286 * @param {Array} array The array to inspect.
7287 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7288 * @param {number} [fromIndex=0] The index to search from.
7289 * @returns {number} Returns the index of the found element, else `-1`.
7293 * { 'user': 'barney', 'active': false },
7294 * { 'user': 'fred', 'active': false },
7295 * { 'user': 'pebbles', 'active': true }
7298 * _.findIndex(users, function(o) { return o.user == 'barney'; });
7301 * // The `_.matches` iteratee shorthand.
7302 * _.findIndex(users, { 'user': 'fred', 'active': false });
7305 * // The `_.matchesProperty` iteratee shorthand.
7306 * _.findIndex(users, ['active', false]);
7309 * // The `_.property` iteratee shorthand.
7310 * _.findIndex(users, 'active');
7313 function findIndex(array, predicate, fromIndex) {
7314 var length = array == null ? 0 : array.length;
7318 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7320 index = nativeMax(length + index, 0);
7322 return baseFindIndex(array, getIteratee(predicate, 3), index);
7326 * This method is like `_.findIndex` except that it iterates over elements
7327 * of `collection` from right to left.
7333 * @param {Array} array The array to inspect.
7334 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7335 * @param {number} [fromIndex=array.length-1] The index to search from.
7336 * @returns {number} Returns the index of the found element, else `-1`.
7340 * { 'user': 'barney', 'active': true },
7341 * { 'user': 'fred', 'active': false },
7342 * { 'user': 'pebbles', 'active': false }
7345 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
7348 * // The `_.matches` iteratee shorthand.
7349 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
7352 * // The `_.matchesProperty` iteratee shorthand.
7353 * _.findLastIndex(users, ['active', false]);
7356 * // The `_.property` iteratee shorthand.
7357 * _.findLastIndex(users, 'active');
7360 function findLastIndex(array, predicate, fromIndex) {
7361 var length = array == null ? 0 : array.length;
7365 var index = length - 1;
7366 if (fromIndex !== undefined) {
7367 index = toInteger(fromIndex);
7368 index = fromIndex < 0
7369 ? nativeMax(length + index, 0)
7370 : nativeMin(index, length - 1);
7372 return baseFindIndex(array, getIteratee(predicate, 3), index, true);
7376 * Flattens `array` a single level deep.
7382 * @param {Array} array The array to flatten.
7383 * @returns {Array} Returns the new flattened array.
7386 * _.flatten([1, [2, [3, [4]], 5]]);
7387 * // => [1, 2, [3, [4]], 5]
7389 function flatten(array) {
7390 var length = array == null ? 0 : array.length;
7391 return length ? baseFlatten(array, 1) : [];
7395 * Recursively flattens `array`.
7401 * @param {Array} array The array to flatten.
7402 * @returns {Array} Returns the new flattened array.
7405 * _.flattenDeep([1, [2, [3, [4]], 5]]);
7406 * // => [1, 2, 3, 4, 5]
7408 function flattenDeep(array) {
7409 var length = array == null ? 0 : array.length;
7410 return length ? baseFlatten(array, INFINITY) : [];
7414 * Recursively flatten `array` up to `depth` times.
7420 * @param {Array} array The array to flatten.
7421 * @param {number} [depth=1] The maximum recursion depth.
7422 * @returns {Array} Returns the new flattened array.
7425 * var array = [1, [2, [3, [4]], 5]];
7427 * _.flattenDepth(array, 1);
7428 * // => [1, 2, [3, [4]], 5]
7430 * _.flattenDepth(array, 2);
7431 * // => [1, 2, 3, [4], 5]
7433 function flattenDepth(array, depth) {
7434 var length = array == null ? 0 : array.length;
7438 depth = depth === undefined ? 1 : toInteger(depth);
7439 return baseFlatten(array, depth);
7443 * The inverse of `_.toPairs`; this method returns an object composed
7444 * from key-value `pairs`.
7450 * @param {Array} pairs The key-value pairs.
7451 * @returns {Object} Returns the new object.
7454 * _.fromPairs([['a', 1], ['b', 2]]);
7455 * // => { 'a': 1, 'b': 2 }
7457 function fromPairs(pairs) {
7459 length = pairs == null ? 0 : pairs.length,
7462 while (++index < length) {
7463 var pair = pairs[index];
7464 result[pair[0]] = pair[1];
7470 * Gets the first element of `array`.
7477 * @param {Array} array The array to query.
7478 * @returns {*} Returns the first element of `array`.
7481 * _.head([1, 2, 3]);
7487 function head(array) {
7488 return (array && array.length) ? array[0] : undefined;
7492 * Gets the index at which the first occurrence of `value` is found in `array`
7493 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7494 * for equality comparisons. If `fromIndex` is negative, it's used as the
7495 * offset from the end of `array`.
7501 * @param {Array} array The array to inspect.
7502 * @param {*} value The value to search for.
7503 * @param {number} [fromIndex=0] The index to search from.
7504 * @returns {number} Returns the index of the matched value, else `-1`.
7507 * _.indexOf([1, 2, 1, 2], 2);
7510 * // Search from the `fromIndex`.
7511 * _.indexOf([1, 2, 1, 2], 2, 2);
7514 function indexOf(array, value, fromIndex) {
7515 var length = array == null ? 0 : array.length;
7519 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7521 index = nativeMax(length + index, 0);
7523 return baseIndexOf(array, value, index);
7527 * Gets all but the last element of `array`.
7533 * @param {Array} array The array to query.
7534 * @returns {Array} Returns the slice of `array`.
7537 * _.initial([1, 2, 3]);
7540 function initial(array) {
7541 var length = array == null ? 0 : array.length;
7542 return length ? baseSlice(array, 0, -1) : [];
7546 * Creates an array of unique values that are included in all given arrays
7547 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7548 * for equality comparisons. The order and references of result values are
7549 * determined by the first array.
7555 * @param {...Array} [arrays] The arrays to inspect.
7556 * @returns {Array} Returns the new array of intersecting values.
7559 * _.intersection([2, 1], [2, 3]);
7562 var intersection = baseRest(function(arrays) {
7563 var mapped = arrayMap(arrays, castArrayLikeObject);
7564 return (mapped.length && mapped[0] === arrays[0])
7565 ? baseIntersection(mapped)
7570 * This method is like `_.intersection` except that it accepts `iteratee`
7571 * which is invoked for each element of each `arrays` to generate the criterion
7572 * by which they're compared. The order and references of result values are
7573 * determined by the first array. The iteratee is invoked with one argument:
7580 * @param {...Array} [arrays] The arrays to inspect.
7581 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7582 * @returns {Array} Returns the new array of intersecting values.
7585 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7588 * // The `_.property` iteratee shorthand.
7589 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7590 * // => [{ 'x': 1 }]
7592 var intersectionBy = baseRest(function(arrays) {
7593 var iteratee = last(arrays),
7594 mapped = arrayMap(arrays, castArrayLikeObject);
7596 if (iteratee === last(mapped)) {
7597 iteratee = undefined;
7601 return (mapped.length && mapped[0] === arrays[0])
7602 ? baseIntersection(mapped, getIteratee(iteratee, 2))
7607 * This method is like `_.intersection` except that it accepts `comparator`
7608 * which is invoked to compare elements of `arrays`. The order and references
7609 * of result values are determined by the first array. The comparator is
7610 * invoked with two arguments: (arrVal, othVal).
7616 * @param {...Array} [arrays] The arrays to inspect.
7617 * @param {Function} [comparator] The comparator invoked per element.
7618 * @returns {Array} Returns the new array of intersecting values.
7621 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7622 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7624 * _.intersectionWith(objects, others, _.isEqual);
7625 * // => [{ 'x': 1, 'y': 2 }]
7627 var intersectionWith = baseRest(function(arrays) {
7628 var comparator = last(arrays),
7629 mapped = arrayMap(arrays, castArrayLikeObject);
7631 comparator = typeof comparator == 'function' ? comparator : undefined;
7635 return (mapped.length && mapped[0] === arrays[0])
7636 ? baseIntersection(mapped, undefined, comparator)
7641 * Converts all elements in `array` into a string separated by `separator`.
7647 * @param {Array} array The array to convert.
7648 * @param {string} [separator=','] The element separator.
7649 * @returns {string} Returns the joined string.
7652 * _.join(['a', 'b', 'c'], '~');
7655 function join(array, separator) {
7656 return array == null ? '' : nativeJoin.call(array, separator);
7660 * Gets the last element of `array`.
7666 * @param {Array} array The array to query.
7667 * @returns {*} Returns the last element of `array`.
7670 * _.last([1, 2, 3]);
7673 function last(array) {
7674 var length = array == null ? 0 : array.length;
7675 return length ? array[length - 1] : undefined;
7679 * This method is like `_.indexOf` except that it iterates over elements of
7680 * `array` from right to left.
7686 * @param {Array} array The array to inspect.
7687 * @param {*} value The value to search for.
7688 * @param {number} [fromIndex=array.length-1] The index to search from.
7689 * @returns {number} Returns the index of the matched value, else `-1`.
7692 * _.lastIndexOf([1, 2, 1, 2], 2);
7695 * // Search from the `fromIndex`.
7696 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
7699 function lastIndexOf(array, value, fromIndex) {
7700 var length = array == null ? 0 : array.length;
7705 if (fromIndex !== undefined) {
7706 index = toInteger(fromIndex);
7707 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
7709 return value === value
7710 ? strictLastIndexOf(array, value, index)
7711 : baseFindIndex(array, baseIsNaN, index, true);
7715 * Gets the element at index `n` of `array`. If `n` is negative, the nth
7716 * element from the end is returned.
7722 * @param {Array} array The array to query.
7723 * @param {number} [n=0] The index of the element to return.
7724 * @returns {*} Returns the nth element of `array`.
7727 * var array = ['a', 'b', 'c', 'd'];
7735 function nth(array, n) {
7736 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
7740 * Removes all given values from `array` using
7741 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7742 * for equality comparisons.
7744 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
7745 * to remove elements from an array by predicate.
7751 * @param {Array} array The array to modify.
7752 * @param {...*} [values] The values to remove.
7753 * @returns {Array} Returns `array`.
7756 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7758 * _.pull(array, 'a', 'c');
7759 * console.log(array);
7762 var pull = baseRest(pullAll);
7765 * This method is like `_.pull` except that it accepts an array of values to remove.
7767 * **Note:** Unlike `_.difference`, this method mutates `array`.
7773 * @param {Array} array The array to modify.
7774 * @param {Array} values The values to remove.
7775 * @returns {Array} Returns `array`.
7778 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7780 * _.pullAll(array, ['a', 'c']);
7781 * console.log(array);
7784 function pullAll(array, values) {
7785 return (array && array.length && values && values.length)
7786 ? basePullAll(array, values)
7791 * This method is like `_.pullAll` except that it accepts `iteratee` which is
7792 * invoked for each element of `array` and `values` to generate the criterion
7793 * by which they're compared. The iteratee is invoked with one argument: (value).
7795 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
7801 * @param {Array} array The array to modify.
7802 * @param {Array} values The values to remove.
7803 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7804 * @returns {Array} Returns `array`.
7807 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
7809 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
7810 * console.log(array);
7811 * // => [{ 'x': 2 }]
7813 function pullAllBy(array, values, iteratee) {
7814 return (array && array.length && values && values.length)
7815 ? basePullAll(array, values, getIteratee(iteratee, 2))
7820 * This method is like `_.pullAll` except that it accepts `comparator` which
7821 * is invoked to compare elements of `array` to `values`. The comparator is
7822 * invoked with two arguments: (arrVal, othVal).
7824 * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
7830 * @param {Array} array The array to modify.
7831 * @param {Array} values The values to remove.
7832 * @param {Function} [comparator] The comparator invoked per element.
7833 * @returns {Array} Returns `array`.
7836 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
7838 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
7839 * console.log(array);
7840 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
7842 function pullAllWith(array, values, comparator) {
7843 return (array && array.length && values && values.length)
7844 ? basePullAll(array, values, undefined, comparator)
7849 * Removes elements from `array` corresponding to `indexes` and returns an
7850 * array of removed elements.
7852 * **Note:** Unlike `_.at`, this method mutates `array`.
7858 * @param {Array} array The array to modify.
7859 * @param {...(number|number[])} [indexes] The indexes of elements to remove.
7860 * @returns {Array} Returns the new array of removed elements.
7863 * var array = ['a', 'b', 'c', 'd'];
7864 * var pulled = _.pullAt(array, [1, 3]);
7866 * console.log(array);
7869 * console.log(pulled);
7872 var pullAt = flatRest(function(array, indexes) {
7873 var length = array == null ? 0 : array.length,
7874 result = baseAt(array, indexes);
7876 basePullAt(array, arrayMap(indexes, function(index) {
7877 return isIndex(index, length) ? +index : index;
7878 }).sort(compareAscending));
7884 * Removes all elements from `array` that `predicate` returns truthy for
7885 * and returns an array of the removed elements. The predicate is invoked
7886 * with three arguments: (value, index, array).
7888 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
7889 * to pull elements from an array by value.
7895 * @param {Array} array The array to modify.
7896 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7897 * @returns {Array} Returns the new array of removed elements.
7900 * var array = [1, 2, 3, 4];
7901 * var evens = _.remove(array, function(n) {
7902 * return n % 2 == 0;
7905 * console.log(array);
7908 * console.log(evens);
7911 function remove(array, predicate) {
7913 if (!(array && array.length)) {
7918 length = array.length;
7920 predicate = getIteratee(predicate, 3);
7921 while (++index < length) {
7922 var value = array[index];
7923 if (predicate(value, index, array)) {
7925 indexes.push(index);
7928 basePullAt(array, indexes);
7933 * Reverses `array` so that the first element becomes the last, the second
7934 * element becomes the second to last, and so on.
7936 * **Note:** This method mutates `array` and is based on
7937 * [`Array#reverse`](https://mdn.io/Array/reverse).
7943 * @param {Array} array The array to modify.
7944 * @returns {Array} Returns `array`.
7947 * var array = [1, 2, 3];
7952 * console.log(array);
7955 function reverse(array) {
7956 return array == null ? array : nativeReverse.call(array);
7960 * Creates a slice of `array` from `start` up to, but not including, `end`.
7962 * **Note:** This method is used instead of
7963 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
7970 * @param {Array} array The array to slice.
7971 * @param {number} [start=0] The start position.
7972 * @param {number} [end=array.length] The end position.
7973 * @returns {Array} Returns the slice of `array`.
7975 function slice(array, start, end) {
7976 var length = array == null ? 0 : array.length;
7980 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
7985 start = start == null ? 0 : toInteger(start);
7986 end = end === undefined ? length : toInteger(end);
7988 return baseSlice(array, start, end);
7992 * Uses a binary search to determine the lowest index at which `value`
7993 * should be inserted into `array` in order to maintain its sort order.
7999 * @param {Array} array The sorted array to inspect.
8000 * @param {*} value The value to evaluate.
8001 * @returns {number} Returns the index at which `value` should be inserted
8005 * _.sortedIndex([30, 50], 40);
8008 function sortedIndex(array, value) {
8009 return baseSortedIndex(array, value);
8013 * This method is like `_.sortedIndex` except that it accepts `iteratee`
8014 * which is invoked for `value` and each element of `array` to compute their
8015 * sort ranking. The iteratee is invoked with one argument: (value).
8021 * @param {Array} array The sorted array to inspect.
8022 * @param {*} value The value to evaluate.
8023 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8024 * @returns {number} Returns the index at which `value` should be inserted
8028 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8030 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8033 * // The `_.property` iteratee shorthand.
8034 * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
8037 function sortedIndexBy(array, value, iteratee) {
8038 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
8042 * This method is like `_.indexOf` except that it performs a binary
8043 * search on a sorted `array`.
8049 * @param {Array} array The array to inspect.
8050 * @param {*} value The value to search for.
8051 * @returns {number} Returns the index of the matched value, else `-1`.
8054 * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
8057 function sortedIndexOf(array, value) {
8058 var length = array == null ? 0 : array.length;
8060 var index = baseSortedIndex(array, value);
8061 if (index < length && eq(array[index], value)) {
8069 * This method is like `_.sortedIndex` except that it returns the highest
8070 * index at which `value` should be inserted into `array` in order to
8071 * maintain its sort order.
8077 * @param {Array} array The sorted array to inspect.
8078 * @param {*} value The value to evaluate.
8079 * @returns {number} Returns the index at which `value` should be inserted
8083 * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
8086 function sortedLastIndex(array, value) {
8087 return baseSortedIndex(array, value, true);
8091 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
8092 * which is invoked for `value` and each element of `array` to compute their
8093 * sort ranking. The iteratee is invoked with one argument: (value).
8099 * @param {Array} array The sorted array to inspect.
8100 * @param {*} value The value to evaluate.
8101 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8102 * @returns {number} Returns the index at which `value` should be inserted
8106 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8108 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8111 * // The `_.property` iteratee shorthand.
8112 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
8115 function sortedLastIndexBy(array, value, iteratee) {
8116 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
8120 * This method is like `_.lastIndexOf` except that it performs a binary
8121 * search on a sorted `array`.
8127 * @param {Array} array The array to inspect.
8128 * @param {*} value The value to search for.
8129 * @returns {number} Returns the index of the matched value, else `-1`.
8132 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
8135 function sortedLastIndexOf(array, value) {
8136 var length = array == null ? 0 : array.length;
8138 var index = baseSortedIndex(array, value, true) - 1;
8139 if (eq(array[index], value)) {
8147 * This method is like `_.uniq` except that it's designed and optimized
8148 * for sorted arrays.
8154 * @param {Array} array The array to inspect.
8155 * @returns {Array} Returns the new duplicate free array.
8158 * _.sortedUniq([1, 1, 2]);
8161 function sortedUniq(array) {
8162 return (array && array.length)
8163 ? baseSortedUniq(array)
8168 * This method is like `_.uniqBy` except that it's designed and optimized
8169 * for sorted arrays.
8175 * @param {Array} array The array to inspect.
8176 * @param {Function} [iteratee] The iteratee invoked per element.
8177 * @returns {Array} Returns the new duplicate free array.
8180 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
8183 function sortedUniqBy(array, iteratee) {
8184 return (array && array.length)
8185 ? baseSortedUniq(array, getIteratee(iteratee, 2))
8190 * Gets all but the first element of `array`.
8196 * @param {Array} array The array to query.
8197 * @returns {Array} Returns the slice of `array`.
8200 * _.tail([1, 2, 3]);
8203 function tail(array) {
8204 var length = array == null ? 0 : array.length;
8205 return length ? baseSlice(array, 1, length) : [];
8209 * Creates a slice of `array` with `n` elements taken from the beginning.
8215 * @param {Array} array The array to query.
8216 * @param {number} [n=1] The number of elements to take.
8217 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8218 * @returns {Array} Returns the slice of `array`.
8221 * _.take([1, 2, 3]);
8224 * _.take([1, 2, 3], 2);
8227 * _.take([1, 2, 3], 5);
8230 * _.take([1, 2, 3], 0);
8233 function take(array, n, guard) {
8234 if (!(array && array.length)) {
8237 n = (guard || n === undefined) ? 1 : toInteger(n);
8238 return baseSlice(array, 0, n < 0 ? 0 : n);
8242 * Creates a slice of `array` with `n` elements taken from the end.
8248 * @param {Array} array The array to query.
8249 * @param {number} [n=1] The number of elements to take.
8250 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8251 * @returns {Array} Returns the slice of `array`.
8254 * _.takeRight([1, 2, 3]);
8257 * _.takeRight([1, 2, 3], 2);
8260 * _.takeRight([1, 2, 3], 5);
8263 * _.takeRight([1, 2, 3], 0);
8266 function takeRight(array, n, guard) {
8267 var length = array == null ? 0 : array.length;
8271 n = (guard || n === undefined) ? 1 : toInteger(n);
8273 return baseSlice(array, n < 0 ? 0 : n, length);
8277 * Creates a slice of `array` with elements taken from the end. Elements are
8278 * taken until `predicate` returns falsey. The predicate is invoked with
8279 * three arguments: (value, index, array).
8285 * @param {Array} array The array to query.
8286 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8287 * @returns {Array} Returns the slice of `array`.
8291 * { 'user': 'barney', 'active': true },
8292 * { 'user': 'fred', 'active': false },
8293 * { 'user': 'pebbles', 'active': false }
8296 * _.takeRightWhile(users, function(o) { return !o.active; });
8297 * // => objects for ['fred', 'pebbles']
8299 * // The `_.matches` iteratee shorthand.
8300 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
8301 * // => objects for ['pebbles']
8303 * // The `_.matchesProperty` iteratee shorthand.
8304 * _.takeRightWhile(users, ['active', false]);
8305 * // => objects for ['fred', 'pebbles']
8307 * // The `_.property` iteratee shorthand.
8308 * _.takeRightWhile(users, 'active');
8311 function takeRightWhile(array, predicate) {
8312 return (array && array.length)
8313 ? baseWhile(array, getIteratee(predicate, 3), false, true)
8318 * Creates a slice of `array` with elements taken from the beginning. Elements
8319 * are taken until `predicate` returns falsey. The predicate is invoked with
8320 * three arguments: (value, index, array).
8326 * @param {Array} array The array to query.
8327 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8328 * @returns {Array} Returns the slice of `array`.
8332 * { 'user': 'barney', 'active': false },
8333 * { 'user': 'fred', 'active': false },
8334 * { 'user': 'pebbles', 'active': true }
8337 * _.takeWhile(users, function(o) { return !o.active; });
8338 * // => objects for ['barney', 'fred']
8340 * // The `_.matches` iteratee shorthand.
8341 * _.takeWhile(users, { 'user': 'barney', 'active': false });
8342 * // => objects for ['barney']
8344 * // The `_.matchesProperty` iteratee shorthand.
8345 * _.takeWhile(users, ['active', false]);
8346 * // => objects for ['barney', 'fred']
8348 * // The `_.property` iteratee shorthand.
8349 * _.takeWhile(users, 'active');
8352 function takeWhile(array, predicate) {
8353 return (array && array.length)
8354 ? baseWhile(array, getIteratee(predicate, 3))
8359 * Creates an array of unique values, in order, from all given arrays using
8360 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8361 * for equality comparisons.
8367 * @param {...Array} [arrays] The arrays to inspect.
8368 * @returns {Array} Returns the new array of combined values.
8371 * _.union([2], [1, 2]);
8374 var union = baseRest(function(arrays) {
8375 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
8379 * This method is like `_.union` except that it accepts `iteratee` which is
8380 * invoked for each element of each `arrays` to generate the criterion by
8381 * which uniqueness is computed. Result values are chosen from the first
8382 * array in which the value occurs. The iteratee is invoked with one argument:
8389 * @param {...Array} [arrays] The arrays to inspect.
8390 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8391 * @returns {Array} Returns the new array of combined values.
8394 * _.unionBy([2.1], [1.2, 2.3], Math.floor);
8397 * // The `_.property` iteratee shorthand.
8398 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8399 * // => [{ 'x': 1 }, { 'x': 2 }]
8401 var unionBy = baseRest(function(arrays) {
8402 var iteratee = last(arrays);
8403 if (isArrayLikeObject(iteratee)) {
8404 iteratee = undefined;
8406 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
8410 * This method is like `_.union` except that it accepts `comparator` which
8411 * is invoked to compare elements of `arrays`. Result values are chosen from
8412 * the first array in which the value occurs. The comparator is invoked
8413 * with two arguments: (arrVal, othVal).
8419 * @param {...Array} [arrays] The arrays to inspect.
8420 * @param {Function} [comparator] The comparator invoked per element.
8421 * @returns {Array} Returns the new array of combined values.
8424 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8425 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8427 * _.unionWith(objects, others, _.isEqual);
8428 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8430 var unionWith = baseRest(function(arrays) {
8431 var comparator = last(arrays);
8432 comparator = typeof comparator == 'function' ? comparator : undefined;
8433 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
8437 * Creates a duplicate-free version of an array, using
8438 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8439 * for equality comparisons, in which only the first occurrence of each element
8440 * is kept. The order of result values is determined by the order they occur
8447 * @param {Array} array The array to inspect.
8448 * @returns {Array} Returns the new duplicate free array.
8451 * _.uniq([2, 1, 2]);
8454 function uniq(array) {
8455 return (array && array.length) ? baseUniq(array) : [];
8459 * This method is like `_.uniq` except that it accepts `iteratee` which is
8460 * invoked for each element in `array` to generate the criterion by which
8461 * uniqueness is computed. The order of result values is determined by the
8462 * order they occur in the array. The iteratee is invoked with one argument:
8469 * @param {Array} array The array to inspect.
8470 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8471 * @returns {Array} Returns the new duplicate free array.
8474 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
8477 * // The `_.property` iteratee shorthand.
8478 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
8479 * // => [{ 'x': 1 }, { 'x': 2 }]
8481 function uniqBy(array, iteratee) {
8482 return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
8486 * This method is like `_.uniq` except that it accepts `comparator` which
8487 * is invoked to compare elements of `array`. The order of result values is
8488 * determined by the order they occur in the array.The comparator is invoked
8489 * with two arguments: (arrVal, othVal).
8495 * @param {Array} array The array to inspect.
8496 * @param {Function} [comparator] The comparator invoked per element.
8497 * @returns {Array} Returns the new duplicate free array.
8500 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
8502 * _.uniqWith(objects, _.isEqual);
8503 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
8505 function uniqWith(array, comparator) {
8506 comparator = typeof comparator == 'function' ? comparator : undefined;
8507 return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
8511 * This method is like `_.zip` except that it accepts an array of grouped
8512 * elements and creates an array regrouping the elements to their pre-zip
8519 * @param {Array} array The array of grouped elements to process.
8520 * @returns {Array} Returns the new array of regrouped elements.
8523 * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
8524 * // => [['a', 1, true], ['b', 2, false]]
8527 * // => [['a', 'b'], [1, 2], [true, false]]
8529 function unzip(array) {
8530 if (!(array && array.length)) {
8534 array = arrayFilter(array, function(group) {
8535 if (isArrayLikeObject(group)) {
8536 length = nativeMax(group.length, length);
8540 return baseTimes(length, function(index) {
8541 return arrayMap(array, baseProperty(index));
8546 * This method is like `_.unzip` except that it accepts `iteratee` to specify
8547 * how regrouped values should be combined. The iteratee is invoked with the
8548 * elements of each group: (...group).
8554 * @param {Array} array The array of grouped elements to process.
8555 * @param {Function} [iteratee=_.identity] The function to combine
8557 * @returns {Array} Returns the new array of regrouped elements.
8560 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
8561 * // => [[1, 10, 100], [2, 20, 200]]
8563 * _.unzipWith(zipped, _.add);
8564 * // => [3, 30, 300]
8566 function unzipWith(array, iteratee) {
8567 if (!(array && array.length)) {
8570 var result = unzip(array);
8571 if (iteratee == null) {
8574 return arrayMap(result, function(group) {
8575 return apply(iteratee, undefined, group);
8580 * Creates an array excluding all given values using
8581 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8582 * for equality comparisons.
8584 * **Note:** Unlike `_.pull`, this method returns a new array.
8590 * @param {Array} array The array to inspect.
8591 * @param {...*} [values] The values to exclude.
8592 * @returns {Array} Returns the new array of filtered values.
8593 * @see _.difference, _.xor
8596 * _.without([2, 1, 2, 3], 1, 2);
8599 var without = baseRest(function(array, values) {
8600 return isArrayLikeObject(array)
8601 ? baseDifference(array, values)
8606 * Creates an array of unique values that is the
8607 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
8608 * of the given arrays. The order of result values is determined by the order
8609 * they occur in the arrays.
8615 * @param {...Array} [arrays] The arrays to inspect.
8616 * @returns {Array} Returns the new array of filtered values.
8617 * @see _.difference, _.without
8620 * _.xor([2, 1], [2, 3]);
8623 var xor = baseRest(function(arrays) {
8624 return baseXor(arrayFilter(arrays, isArrayLikeObject));
8628 * This method is like `_.xor` except that it accepts `iteratee` which is
8629 * invoked for each element of each `arrays` to generate the criterion by
8630 * which by which they're compared. The order of result values is determined
8631 * by the order they occur in the arrays. The iteratee is invoked with one
8632 * argument: (value).
8638 * @param {...Array} [arrays] The arrays to inspect.
8639 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8640 * @returns {Array} Returns the new array of filtered values.
8643 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
8646 * // The `_.property` iteratee shorthand.
8647 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8648 * // => [{ 'x': 2 }]
8650 var xorBy = baseRest(function(arrays) {
8651 var iteratee = last(arrays);
8652 if (isArrayLikeObject(iteratee)) {
8653 iteratee = undefined;
8655 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
8659 * This method is like `_.xor` except that it accepts `comparator` which is
8660 * invoked to compare elements of `arrays`. The order of result values is
8661 * determined by the order they occur in the arrays. The comparator is invoked
8662 * with two arguments: (arrVal, othVal).
8668 * @param {...Array} [arrays] The arrays to inspect.
8669 * @param {Function} [comparator] The comparator invoked per element.
8670 * @returns {Array} Returns the new array of filtered values.
8673 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8674 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8676 * _.xorWith(objects, others, _.isEqual);
8677 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8679 var xorWith = baseRest(function(arrays) {
8680 var comparator = last(arrays);
8681 comparator = typeof comparator == 'function' ? comparator : undefined;
8682 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
8686 * Creates an array of grouped elements, the first of which contains the
8687 * first elements of the given arrays, the second of which contains the
8688 * second elements of the given arrays, and so on.
8694 * @param {...Array} [arrays] The arrays to process.
8695 * @returns {Array} Returns the new array of grouped elements.
8698 * _.zip(['a', 'b'], [1, 2], [true, false]);
8699 * // => [['a', 1, true], ['b', 2, false]]
8701 var zip = baseRest(unzip);
8704 * This method is like `_.fromPairs` except that it accepts two arrays,
8705 * one of property identifiers and one of corresponding values.
8711 * @param {Array} [props=[]] The property identifiers.
8712 * @param {Array} [values=[]] The property values.
8713 * @returns {Object} Returns the new object.
8716 * _.zipObject(['a', 'b'], [1, 2]);
8717 * // => { 'a': 1, 'b': 2 }
8719 function zipObject(props, values) {
8720 return baseZipObject(props || [], values || [], assignValue);
8724 * This method is like `_.zipObject` except that it supports property paths.
8730 * @param {Array} [props=[]] The property identifiers.
8731 * @param {Array} [values=[]] The property values.
8732 * @returns {Object} Returns the new object.
8735 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
8736 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
8738 function zipObjectDeep(props, values) {
8739 return baseZipObject(props || [], values || [], baseSet);
8743 * This method is like `_.zip` except that it accepts `iteratee` to specify
8744 * how grouped values should be combined. The iteratee is invoked with the
8745 * elements of each group: (...group).
8751 * @param {...Array} [arrays] The arrays to process.
8752 * @param {Function} [iteratee=_.identity] The function to combine
8754 * @returns {Array} Returns the new array of grouped elements.
8757 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
8762 var zipWith = baseRest(function(arrays) {
8763 var length = arrays.length,
8764 iteratee = length > 1 ? arrays[length - 1] : undefined;
8766 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
8767 return unzipWith(arrays, iteratee);
8770 /*------------------------------------------------------------------------*/
8773 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
8774 * chain sequences enabled. The result of such sequences must be unwrapped
8781 * @param {*} value The value to wrap.
8782 * @returns {Object} Returns the new `lodash` wrapper instance.
8786 * { 'user': 'barney', 'age': 36 },
8787 * { 'user': 'fred', 'age': 40 },
8788 * { 'user': 'pebbles', 'age': 1 }
8794 * .map(function(o) {
8795 * return o.user + ' is ' + o.age;
8799 * // => 'pebbles is 1'
8801 function chain(value) {
8802 var result = lodash(value);
8803 result.__chain__ = true;
8808 * This method invokes `interceptor` and returns `value`. The interceptor
8809 * is invoked with one argument; (value). The purpose of this method is to
8810 * "tap into" a method chain sequence in order to modify intermediate results.
8816 * @param {*} value The value to provide to `interceptor`.
8817 * @param {Function} interceptor The function to invoke.
8818 * @returns {*} Returns `value`.
8822 * .tap(function(array) {
8823 * // Mutate input array.
8830 function tap(value, interceptor) {
8836 * This method is like `_.tap` except that it returns the result of `interceptor`.
8837 * The purpose of this method is to "pass thru" values replacing intermediate
8838 * results in a method chain sequence.
8844 * @param {*} value The value to provide to `interceptor`.
8845 * @param {Function} interceptor The function to invoke.
8846 * @returns {*} Returns the result of `interceptor`.
8852 * .thru(function(value) {
8858 function thru(value, interceptor) {
8859 return interceptor(value);
8863 * This method is the wrapper version of `_.at`.
8869 * @param {...(string|string[])} [paths] The property paths to pick.
8870 * @returns {Object} Returns the new `lodash` wrapper instance.
8873 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
8875 * _(object).at(['a[0].b.c', 'a[1]']).value();
8878 var wrapperAt = flatRest(function(paths) {
8879 var length = paths.length,
8880 start = length ? paths[0] : 0,
8881 value = this.__wrapped__,
8882 interceptor = function(object) { return baseAt(object, paths); };
8884 if (length > 1 || this.__actions__.length ||
8885 !(value instanceof LazyWrapper) || !isIndex(start)) {
8886 return this.thru(interceptor);
8888 value = value.slice(start, +start + (length ? 1 : 0));
8889 value.__actions__.push({
8891 'args': [interceptor],
8892 'thisArg': undefined
8894 return new LodashWrapper(value, this.__chain__).thru(function(array) {
8895 if (length && !array.length) {
8896 array.push(undefined);
8903 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
8909 * @returns {Object} Returns the new `lodash` wrapper instance.
8913 * { 'user': 'barney', 'age': 36 },
8914 * { 'user': 'fred', 'age': 40 }
8917 * // A sequence without explicit chaining.
8919 * // => { 'user': 'barney', 'age': 36 }
8921 * // A sequence with explicit chaining.
8927 * // => { 'user': 'barney' }
8929 function wrapperChain() {
8934 * Executes the chain sequence and returns the wrapped result.
8940 * @returns {Object} Returns the new `lodash` wrapper instance.
8943 * var array = [1, 2];
8944 * var wrapped = _(array).push(3);
8946 * console.log(array);
8949 * wrapped = wrapped.commit();
8950 * console.log(array);
8956 * console.log(array);
8959 function wrapperCommit() {
8960 return new LodashWrapper(this.value(), this.__chain__);
8964 * Gets the next value on a wrapped object following the
8965 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
8971 * @returns {Object} Returns the next iterator value.
8974 * var wrapped = _([1, 2]);
8977 * // => { 'done': false, 'value': 1 }
8980 * // => { 'done': false, 'value': 2 }
8983 * // => { 'done': true, 'value': undefined }
8985 function wrapperNext() {
8986 if (this.__values__ === undefined) {
8987 this.__values__ = toArray(this.value());
8989 var done = this.__index__ >= this.__values__.length,
8990 value = done ? undefined : this.__values__[this.__index__++];
8992 return { 'done': done, 'value': value };
8996 * Enables the wrapper to be iterable.
8998 * @name Symbol.iterator
9002 * @returns {Object} Returns the wrapper object.
9005 * var wrapped = _([1, 2]);
9007 * wrapped[Symbol.iterator]() === wrapped;
9010 * Array.from(wrapped);
9013 function wrapperToIterator() {
9018 * Creates a clone of the chain sequence planting `value` as the wrapped value.
9024 * @param {*} value The value to plant.
9025 * @returns {Object} Returns the new `lodash` wrapper instance.
9028 * function square(n) {
9032 * var wrapped = _([1, 2]).map(square);
9033 * var other = wrapped.plant([3, 4]);
9041 function wrapperPlant(value) {
9045 while (parent instanceof baseLodash) {
9046 var clone = wrapperClone(parent);
9047 clone.__index__ = 0;
9048 clone.__values__ = undefined;
9050 previous.__wrapped__ = clone;
9054 var previous = clone;
9055 parent = parent.__wrapped__;
9057 previous.__wrapped__ = value;
9062 * This method is the wrapper version of `_.reverse`.
9064 * **Note:** This method mutates the wrapped array.
9070 * @returns {Object} Returns the new `lodash` wrapper instance.
9073 * var array = [1, 2, 3];
9075 * _(array).reverse().value()
9078 * console.log(array);
9081 function wrapperReverse() {
9082 var value = this.__wrapped__;
9083 if (value instanceof LazyWrapper) {
9084 var wrapped = value;
9085 if (this.__actions__.length) {
9086 wrapped = new LazyWrapper(this);
9088 wrapped = wrapped.reverse();
9089 wrapped.__actions__.push({
9092 'thisArg': undefined
9094 return new LodashWrapper(wrapped, this.__chain__);
9096 return this.thru(reverse);
9100 * Executes the chain sequence to resolve the unwrapped value.
9105 * @alias toJSON, valueOf
9107 * @returns {*} Returns the resolved unwrapped value.
9110 * _([1, 2, 3]).value();
9113 function wrapperValue() {
9114 return baseWrapperValue(this.__wrapped__, this.__actions__);
9117 /*------------------------------------------------------------------------*/
9120 * Creates an object composed of keys generated from the results of running
9121 * each element of `collection` thru `iteratee`. The corresponding value of
9122 * each key is the number of times the key was returned by `iteratee`. The
9123 * iteratee is invoked with one argument: (value).
9128 * @category Collection
9129 * @param {Array|Object} collection The collection to iterate over.
9130 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9131 * @returns {Object} Returns the composed aggregate object.
9134 * _.countBy([6.1, 4.2, 6.3], Math.floor);
9135 * // => { '4': 1, '6': 2 }
9137 * // The `_.property` iteratee shorthand.
9138 * _.countBy(['one', 'two', 'three'], 'length');
9139 * // => { '3': 2, '5': 1 }
9141 var countBy = createAggregator(function(result, value, key) {
9142 if (hasOwnProperty.call(result, key)) {
9145 baseAssignValue(result, key, 1);
9150 * Checks if `predicate` returns truthy for **all** elements of `collection`.
9151 * Iteration is stopped once `predicate` returns falsey. The predicate is
9152 * invoked with three arguments: (value, index|key, collection).
9154 * **Note:** This method returns `true` for
9155 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
9156 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
9157 * elements of empty collections.
9162 * @category Collection
9163 * @param {Array|Object} collection The collection to iterate over.
9164 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9165 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9166 * @returns {boolean} Returns `true` if all elements pass the predicate check,
9170 * _.every([true, 1, null, 'yes'], Boolean);
9174 * { 'user': 'barney', 'age': 36, 'active': false },
9175 * { 'user': 'fred', 'age': 40, 'active': false }
9178 * // The `_.matches` iteratee shorthand.
9179 * _.every(users, { 'user': 'barney', 'active': false });
9182 * // The `_.matchesProperty` iteratee shorthand.
9183 * _.every(users, ['active', false]);
9186 * // The `_.property` iteratee shorthand.
9187 * _.every(users, 'active');
9190 function every(collection, predicate, guard) {
9191 var func = isArray(collection) ? arrayEvery : baseEvery;
9192 if (guard && isIterateeCall(collection, predicate, guard)) {
9193 predicate = undefined;
9195 return func(collection, getIteratee(predicate, 3));
9199 * Iterates over elements of `collection`, returning an array of all elements
9200 * `predicate` returns truthy for. The predicate is invoked with three
9201 * arguments: (value, index|key, collection).
9203 * **Note:** Unlike `_.remove`, this method returns a new array.
9208 * @category Collection
9209 * @param {Array|Object} collection The collection to iterate over.
9210 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9211 * @returns {Array} Returns the new filtered array.
9216 * { 'user': 'barney', 'age': 36, 'active': true },
9217 * { 'user': 'fred', 'age': 40, 'active': false }
9220 * _.filter(users, function(o) { return !o.active; });
9221 * // => objects for ['fred']
9223 * // The `_.matches` iteratee shorthand.
9224 * _.filter(users, { 'age': 36, 'active': true });
9225 * // => objects for ['barney']
9227 * // The `_.matchesProperty` iteratee shorthand.
9228 * _.filter(users, ['active', false]);
9229 * // => objects for ['fred']
9231 * // The `_.property` iteratee shorthand.
9232 * _.filter(users, 'active');
9233 * // => objects for ['barney']
9235 * // Combining several predicates using `_.overEvery` or `_.overSome`.
9236 * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
9237 * // => objects for ['fred', 'barney']
9239 function filter(collection, predicate) {
9240 var func = isArray(collection) ? arrayFilter : baseFilter;
9241 return func(collection, getIteratee(predicate, 3));
9245 * Iterates over elements of `collection`, returning the first element
9246 * `predicate` returns truthy for. The predicate is invoked with three
9247 * arguments: (value, index|key, collection).
9252 * @category Collection
9253 * @param {Array|Object} collection The collection to inspect.
9254 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9255 * @param {number} [fromIndex=0] The index to search from.
9256 * @returns {*} Returns the matched element, else `undefined`.
9260 * { 'user': 'barney', 'age': 36, 'active': true },
9261 * { 'user': 'fred', 'age': 40, 'active': false },
9262 * { 'user': 'pebbles', 'age': 1, 'active': true }
9265 * _.find(users, function(o) { return o.age < 40; });
9266 * // => object for 'barney'
9268 * // The `_.matches` iteratee shorthand.
9269 * _.find(users, { 'age': 1, 'active': true });
9270 * // => object for 'pebbles'
9272 * // The `_.matchesProperty` iteratee shorthand.
9273 * _.find(users, ['active', false]);
9274 * // => object for 'fred'
9276 * // The `_.property` iteratee shorthand.
9277 * _.find(users, 'active');
9278 * // => object for 'barney'
9280 var find = createFind(findIndex);
9283 * This method is like `_.find` except that it iterates over elements of
9284 * `collection` from right to left.
9289 * @category Collection
9290 * @param {Array|Object} collection The collection to inspect.
9291 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9292 * @param {number} [fromIndex=collection.length-1] The index to search from.
9293 * @returns {*} Returns the matched element, else `undefined`.
9296 * _.findLast([1, 2, 3, 4], function(n) {
9297 * return n % 2 == 1;
9301 var findLast = createFind(findLastIndex);
9304 * Creates a flattened array of values by running each element in `collection`
9305 * thru `iteratee` and flattening the mapped results. The iteratee is invoked
9306 * with three arguments: (value, index|key, collection).
9311 * @category Collection
9312 * @param {Array|Object} collection The collection to iterate over.
9313 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9314 * @returns {Array} Returns the new flattened array.
9317 * function duplicate(n) {
9321 * _.flatMap([1, 2], duplicate);
9322 * // => [1, 1, 2, 2]
9324 function flatMap(collection, iteratee) {
9325 return baseFlatten(map(collection, iteratee), 1);
9329 * This method is like `_.flatMap` except that it recursively flattens the
9335 * @category Collection
9336 * @param {Array|Object} collection The collection to iterate over.
9337 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9338 * @returns {Array} Returns the new flattened array.
9341 * function duplicate(n) {
9342 * return [[[n, n]]];
9345 * _.flatMapDeep([1, 2], duplicate);
9346 * // => [1, 1, 2, 2]
9348 function flatMapDeep(collection, iteratee) {
9349 return baseFlatten(map(collection, iteratee), INFINITY);
9353 * This method is like `_.flatMap` except that it recursively flattens the
9354 * mapped results up to `depth` times.
9359 * @category Collection
9360 * @param {Array|Object} collection The collection to iterate over.
9361 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9362 * @param {number} [depth=1] The maximum recursion depth.
9363 * @returns {Array} Returns the new flattened array.
9366 * function duplicate(n) {
9367 * return [[[n, n]]];
9370 * _.flatMapDepth([1, 2], duplicate, 2);
9371 * // => [[1, 1], [2, 2]]
9373 function flatMapDepth(collection, iteratee, depth) {
9374 depth = depth === undefined ? 1 : toInteger(depth);
9375 return baseFlatten(map(collection, iteratee), depth);
9379 * Iterates over elements of `collection` and invokes `iteratee` for each element.
9380 * The iteratee is invoked with three arguments: (value, index|key, collection).
9381 * Iteratee functions may exit iteration early by explicitly returning `false`.
9383 * **Note:** As with other "Collections" methods, objects with a "length"
9384 * property are iterated like arrays. To avoid this behavior use `_.forIn`
9385 * or `_.forOwn` for object iteration.
9391 * @category Collection
9392 * @param {Array|Object} collection The collection to iterate over.
9393 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9394 * @returns {Array|Object} Returns `collection`.
9395 * @see _.forEachRight
9398 * _.forEach([1, 2], function(value) {
9399 * console.log(value);
9401 * // => Logs `1` then `2`.
9403 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
9406 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
9408 function forEach(collection, iteratee) {
9409 var func = isArray(collection) ? arrayEach : baseEach;
9410 return func(collection, getIteratee(iteratee, 3));
9414 * This method is like `_.forEach` except that it iterates over elements of
9415 * `collection` from right to left.
9421 * @category Collection
9422 * @param {Array|Object} collection The collection to iterate over.
9423 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9424 * @returns {Array|Object} Returns `collection`.
9428 * _.forEachRight([1, 2], function(value) {
9429 * console.log(value);
9431 * // => Logs `2` then `1`.
9433 function forEachRight(collection, iteratee) {
9434 var func = isArray(collection) ? arrayEachRight : baseEachRight;
9435 return func(collection, getIteratee(iteratee, 3));
9439 * Creates an object composed of keys generated from the results of running
9440 * each element of `collection` thru `iteratee`. The order of grouped values
9441 * is determined by the order they occur in `collection`. The corresponding
9442 * value of each key is an array of elements responsible for generating the
9443 * key. The iteratee is invoked with one argument: (value).
9448 * @category Collection
9449 * @param {Array|Object} collection The collection to iterate over.
9450 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9451 * @returns {Object} Returns the composed aggregate object.
9454 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
9455 * // => { '4': [4.2], '6': [6.1, 6.3] }
9457 * // The `_.property` iteratee shorthand.
9458 * _.groupBy(['one', 'two', 'three'], 'length');
9459 * // => { '3': ['one', 'two'], '5': ['three'] }
9461 var groupBy = createAggregator(function(result, value, key) {
9462 if (hasOwnProperty.call(result, key)) {
9463 result[key].push(value);
9465 baseAssignValue(result, key, [value]);
9470 * Checks if `value` is in `collection`. If `collection` is a string, it's
9471 * checked for a substring of `value`, otherwise
9472 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
9473 * is used for equality comparisons. If `fromIndex` is negative, it's used as
9474 * the offset from the end of `collection`.
9479 * @category Collection
9480 * @param {Array|Object|string} collection The collection to inspect.
9481 * @param {*} value The value to search for.
9482 * @param {number} [fromIndex=0] The index to search from.
9483 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9484 * @returns {boolean} Returns `true` if `value` is found, else `false`.
9487 * _.includes([1, 2, 3], 1);
9490 * _.includes([1, 2, 3], 1, 2);
9493 * _.includes({ 'a': 1, 'b': 2 }, 1);
9496 * _.includes('abcd', 'bc');
9499 function includes(collection, value, fromIndex, guard) {
9500 collection = isArrayLike(collection) ? collection : values(collection);
9501 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
9503 var length = collection.length;
9504 if (fromIndex < 0) {
9505 fromIndex = nativeMax(length + fromIndex, 0);
9507 return isString(collection)
9508 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
9509 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
9513 * Invokes the method at `path` of each element in `collection`, returning
9514 * an array of the results of each invoked method. Any additional arguments
9515 * are provided to each invoked method. If `path` is a function, it's invoked
9516 * for, and `this` bound to, each element in `collection`.
9521 * @category Collection
9522 * @param {Array|Object} collection The collection to iterate over.
9523 * @param {Array|Function|string} path The path of the method to invoke or
9524 * the function invoked per iteration.
9525 * @param {...*} [args] The arguments to invoke each method with.
9526 * @returns {Array} Returns the array of results.
9529 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
9530 * // => [[1, 5, 7], [1, 2, 3]]
9532 * _.invokeMap([123, 456], String.prototype.split, '');
9533 * // => [['1', '2', '3'], ['4', '5', '6']]
9535 var invokeMap = baseRest(function(collection, path, args) {
9537 isFunc = typeof path == 'function',
9538 result = isArrayLike(collection) ? Array(collection.length) : [];
9540 baseEach(collection, function(value) {
9541 result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
9547 * Creates an object composed of keys generated from the results of running
9548 * each element of `collection` thru `iteratee`. The corresponding value of
9549 * each key is the last element responsible for generating the key. The
9550 * iteratee is invoked with one argument: (value).
9555 * @category Collection
9556 * @param {Array|Object} collection The collection to iterate over.
9557 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9558 * @returns {Object} Returns the composed aggregate object.
9562 * { 'dir': 'left', 'code': 97 },
9563 * { 'dir': 'right', 'code': 100 }
9566 * _.keyBy(array, function(o) {
9567 * return String.fromCharCode(o.code);
9569 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
9571 * _.keyBy(array, 'dir');
9572 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
9574 var keyBy = createAggregator(function(result, value, key) {
9575 baseAssignValue(result, key, value);
9579 * Creates an array of values by running each element in `collection` thru
9580 * `iteratee`. The iteratee is invoked with three arguments:
9581 * (value, index|key, collection).
9583 * Many lodash methods are guarded to work as iteratees for methods like
9584 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
9586 * The guarded methods are:
9587 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
9588 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
9589 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
9590 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
9595 * @category Collection
9596 * @param {Array|Object} collection The collection to iterate over.
9597 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9598 * @returns {Array} Returns the new mapped array.
9601 * function square(n) {
9605 * _.map([4, 8], square);
9608 * _.map({ 'a': 4, 'b': 8 }, square);
9609 * // => [16, 64] (iteration order is not guaranteed)
9612 * { 'user': 'barney' },
9613 * { 'user': 'fred' }
9616 * // The `_.property` iteratee shorthand.
9617 * _.map(users, 'user');
9618 * // => ['barney', 'fred']
9620 function map(collection, iteratee) {
9621 var func = isArray(collection) ? arrayMap : baseMap;
9622 return func(collection, getIteratee(iteratee, 3));
9626 * This method is like `_.sortBy` except that it allows specifying the sort
9627 * orders of the iteratees to sort by. If `orders` is unspecified, all values
9628 * are sorted in ascending order. Otherwise, specify an order of "desc" for
9629 * descending or "asc" for ascending sort order of corresponding values.
9634 * @category Collection
9635 * @param {Array|Object} collection The collection to iterate over.
9636 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
9637 * The iteratees to sort by.
9638 * @param {string[]} [orders] The sort orders of `iteratees`.
9639 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9640 * @returns {Array} Returns the new sorted array.
9644 * { 'user': 'fred', 'age': 48 },
9645 * { 'user': 'barney', 'age': 34 },
9646 * { 'user': 'fred', 'age': 40 },
9647 * { 'user': 'barney', 'age': 36 }
9650 * // Sort by `user` in ascending order and by `age` in descending order.
9651 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
9652 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9654 function orderBy(collection, iteratees, orders, guard) {
9655 if (collection == null) {
9658 if (!isArray(iteratees)) {
9659 iteratees = iteratees == null ? [] : [iteratees];
9661 orders = guard ? undefined : orders;
9662 if (!isArray(orders)) {
9663 orders = orders == null ? [] : [orders];
9665 return baseOrderBy(collection, iteratees, orders);
9669 * Creates an array of elements split into two groups, the first of which
9670 * contains elements `predicate` returns truthy for, the second of which
9671 * contains elements `predicate` returns falsey for. The predicate is
9672 * invoked with one argument: (value).
9677 * @category Collection
9678 * @param {Array|Object} collection The collection to iterate over.
9679 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9680 * @returns {Array} Returns the array of grouped elements.
9684 * { 'user': 'barney', 'age': 36, 'active': false },
9685 * { 'user': 'fred', 'age': 40, 'active': true },
9686 * { 'user': 'pebbles', 'age': 1, 'active': false }
9689 * _.partition(users, function(o) { return o.active; });
9690 * // => objects for [['fred'], ['barney', 'pebbles']]
9692 * // The `_.matches` iteratee shorthand.
9693 * _.partition(users, { 'age': 1, 'active': false });
9694 * // => objects for [['pebbles'], ['barney', 'fred']]
9696 * // The `_.matchesProperty` iteratee shorthand.
9697 * _.partition(users, ['active', false]);
9698 * // => objects for [['barney', 'pebbles'], ['fred']]
9700 * // The `_.property` iteratee shorthand.
9701 * _.partition(users, 'active');
9702 * // => objects for [['fred'], ['barney', 'pebbles']]
9704 var partition = createAggregator(function(result, value, key) {
9705 result[key ? 0 : 1].push(value);
9706 }, function() { return [[], []]; });
9709 * Reduces `collection` to a value which is the accumulated result of running
9710 * each element in `collection` thru `iteratee`, where each successive
9711 * invocation is supplied the return value of the previous. If `accumulator`
9712 * is not given, the first element of `collection` is used as the initial
9713 * value. The iteratee is invoked with four arguments:
9714 * (accumulator, value, index|key, collection).
9716 * Many lodash methods are guarded to work as iteratees for methods like
9717 * `_.reduce`, `_.reduceRight`, and `_.transform`.
9719 * The guarded methods are:
9720 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
9726 * @category Collection
9727 * @param {Array|Object} collection The collection to iterate over.
9728 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9729 * @param {*} [accumulator] The initial value.
9730 * @returns {*} Returns the accumulated value.
9731 * @see _.reduceRight
9734 * _.reduce([1, 2], function(sum, n) {
9739 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
9740 * (result[value] || (result[value] = [])).push(key);
9743 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
9745 function reduce(collection, iteratee, accumulator) {
9746 var func = isArray(collection) ? arrayReduce : baseReduce,
9747 initAccum = arguments.length < 3;
9749 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
9753 * This method is like `_.reduce` except that it iterates over elements of
9754 * `collection` from right to left.
9759 * @category Collection
9760 * @param {Array|Object} collection The collection to iterate over.
9761 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9762 * @param {*} [accumulator] The initial value.
9763 * @returns {*} Returns the accumulated value.
9767 * var array = [[0, 1], [2, 3], [4, 5]];
9769 * _.reduceRight(array, function(flattened, other) {
9770 * return flattened.concat(other);
9772 * // => [4, 5, 2, 3, 0, 1]
9774 function reduceRight(collection, iteratee, accumulator) {
9775 var func = isArray(collection) ? arrayReduceRight : baseReduce,
9776 initAccum = arguments.length < 3;
9778 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
9782 * The opposite of `_.filter`; this method returns the elements of `collection`
9783 * that `predicate` does **not** return truthy for.
9788 * @category Collection
9789 * @param {Array|Object} collection The collection to iterate over.
9790 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9791 * @returns {Array} Returns the new filtered array.
9796 * { 'user': 'barney', 'age': 36, 'active': false },
9797 * { 'user': 'fred', 'age': 40, 'active': true }
9800 * _.reject(users, function(o) { return !o.active; });
9801 * // => objects for ['fred']
9803 * // The `_.matches` iteratee shorthand.
9804 * _.reject(users, { 'age': 40, 'active': true });
9805 * // => objects for ['barney']
9807 * // The `_.matchesProperty` iteratee shorthand.
9808 * _.reject(users, ['active', false]);
9809 * // => objects for ['fred']
9811 * // The `_.property` iteratee shorthand.
9812 * _.reject(users, 'active');
9813 * // => objects for ['barney']
9815 function reject(collection, predicate) {
9816 var func = isArray(collection) ? arrayFilter : baseFilter;
9817 return func(collection, negate(getIteratee(predicate, 3)));
9821 * Gets a random element from `collection`.
9826 * @category Collection
9827 * @param {Array|Object} collection The collection to sample.
9828 * @returns {*} Returns the random element.
9831 * _.sample([1, 2, 3, 4]);
9834 function sample(collection) {
9835 var func = isArray(collection) ? arraySample : baseSample;
9836 return func(collection);
9840 * Gets `n` random elements at unique keys from `collection` up to the
9841 * size of `collection`.
9846 * @category Collection
9847 * @param {Array|Object} collection The collection to sample.
9848 * @param {number} [n=1] The number of elements to sample.
9849 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9850 * @returns {Array} Returns the random elements.
9853 * _.sampleSize([1, 2, 3], 2);
9856 * _.sampleSize([1, 2, 3], 4);
9859 function sampleSize(collection, n, guard) {
9860 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
9865 var func = isArray(collection) ? arraySampleSize : baseSampleSize;
9866 return func(collection, n);
9870 * Creates an array of shuffled values, using a version of the
9871 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
9876 * @category Collection
9877 * @param {Array|Object} collection The collection to shuffle.
9878 * @returns {Array} Returns the new shuffled array.
9881 * _.shuffle([1, 2, 3, 4]);
9882 * // => [4, 1, 3, 2]
9884 function shuffle(collection) {
9885 var func = isArray(collection) ? arrayShuffle : baseShuffle;
9886 return func(collection);
9890 * Gets the size of `collection` by returning its length for array-like
9891 * values or the number of own enumerable string keyed properties for objects.
9896 * @category Collection
9897 * @param {Array|Object|string} collection The collection to inspect.
9898 * @returns {number} Returns the collection size.
9901 * _.size([1, 2, 3]);
9904 * _.size({ 'a': 1, 'b': 2 });
9907 * _.size('pebbles');
9910 function size(collection) {
9911 if (collection == null) {
9914 if (isArrayLike(collection)) {
9915 return isString(collection) ? stringSize(collection) : collection.length;
9917 var tag = getTag(collection);
9918 if (tag == mapTag || tag == setTag) {
9919 return collection.size;
9921 return baseKeys(collection).length;
9925 * Checks if `predicate` returns truthy for **any** element of `collection`.
9926 * Iteration is stopped once `predicate` returns truthy. The predicate is
9927 * invoked with three arguments: (value, index|key, collection).
9932 * @category Collection
9933 * @param {Array|Object} collection The collection to iterate over.
9934 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9935 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9936 * @returns {boolean} Returns `true` if any element passes the predicate check,
9940 * _.some([null, 0, 'yes', false], Boolean);
9944 * { 'user': 'barney', 'active': true },
9945 * { 'user': 'fred', 'active': false }
9948 * // The `_.matches` iteratee shorthand.
9949 * _.some(users, { 'user': 'barney', 'active': false });
9952 * // The `_.matchesProperty` iteratee shorthand.
9953 * _.some(users, ['active', false]);
9956 * // The `_.property` iteratee shorthand.
9957 * _.some(users, 'active');
9960 function some(collection, predicate, guard) {
9961 var func = isArray(collection) ? arraySome : baseSome;
9962 if (guard && isIterateeCall(collection, predicate, guard)) {
9963 predicate = undefined;
9965 return func(collection, getIteratee(predicate, 3));
9969 * Creates an array of elements, sorted in ascending order by the results of
9970 * running each element in a collection thru each iteratee. This method
9971 * performs a stable sort, that is, it preserves the original sort order of
9972 * equal elements. The iteratees are invoked with one argument: (value).
9977 * @category Collection
9978 * @param {Array|Object} collection The collection to iterate over.
9979 * @param {...(Function|Function[])} [iteratees=[_.identity]]
9980 * The iteratees to sort by.
9981 * @returns {Array} Returns the new sorted array.
9985 * { 'user': 'fred', 'age': 48 },
9986 * { 'user': 'barney', 'age': 36 },
9987 * { 'user': 'fred', 'age': 30 },
9988 * { 'user': 'barney', 'age': 34 }
9991 * _.sortBy(users, [function(o) { return o.user; }]);
9992 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
9994 * _.sortBy(users, ['user', 'age']);
9995 * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
9997 var sortBy = baseRest(function(collection, iteratees) {
9998 if (collection == null) {
10001 var length = iteratees.length;
10002 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
10004 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
10005 iteratees = [iteratees[0]];
10007 return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
10010 /*------------------------------------------------------------------------*/
10013 * Gets the timestamp of the number of milliseconds that have elapsed since
10014 * the Unix epoch (1 January 1970 00:00:00 UTC).
10020 * @returns {number} Returns the timestamp.
10023 * _.defer(function(stamp) {
10024 * console.log(_.now() - stamp);
10026 * // => Logs the number of milliseconds it took for the deferred invocation.
10028 var now = ctxNow || function() {
10029 return root.Date.now();
10032 /*------------------------------------------------------------------------*/
10035 * The opposite of `_.before`; this method creates a function that invokes
10036 * `func` once it's called `n` or more times.
10041 * @category Function
10042 * @param {number} n The number of calls before `func` is invoked.
10043 * @param {Function} func The function to restrict.
10044 * @returns {Function} Returns the new restricted function.
10047 * var saves = ['profile', 'settings'];
10049 * var done = _.after(saves.length, function() {
10050 * console.log('done saving!');
10053 * _.forEach(saves, function(type) {
10054 * asyncSave({ 'type': type, 'complete': done });
10056 * // => Logs 'done saving!' after the two async saves have completed.
10058 function after(n, func) {
10059 if (typeof func != 'function') {
10060 throw new TypeError(FUNC_ERROR_TEXT);
10063 return function() {
10065 return func.apply(this, arguments);
10071 * Creates a function that invokes `func`, with up to `n` arguments,
10072 * ignoring any additional arguments.
10077 * @category Function
10078 * @param {Function} func The function to cap arguments for.
10079 * @param {number} [n=func.length] The arity cap.
10080 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10081 * @returns {Function} Returns the new capped function.
10084 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
10087 function ary(func, n, guard) {
10088 n = guard ? undefined : n;
10089 n = (func && n == null) ? func.length : n;
10090 return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
10094 * Creates a function that invokes `func`, with the `this` binding and arguments
10095 * of the created function, while it's called less than `n` times. Subsequent
10096 * calls to the created function return the result of the last `func` invocation.
10101 * @category Function
10102 * @param {number} n The number of calls at which `func` is no longer invoked.
10103 * @param {Function} func The function to restrict.
10104 * @returns {Function} Returns the new restricted function.
10107 * jQuery(element).on('click', _.before(5, addContactToList));
10108 * // => Allows adding up to 4 contacts to the list.
10110 function before(n, func) {
10112 if (typeof func != 'function') {
10113 throw new TypeError(FUNC_ERROR_TEXT);
10116 return function() {
10118 result = func.apply(this, arguments);
10128 * Creates a function that invokes `func` with the `this` binding of `thisArg`
10129 * and `partials` prepended to the arguments it receives.
10131 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
10132 * may be used as a placeholder for partially applied arguments.
10134 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
10135 * property of bound functions.
10140 * @category Function
10141 * @param {Function} func The function to bind.
10142 * @param {*} thisArg The `this` binding of `func`.
10143 * @param {...*} [partials] The arguments to be partially applied.
10144 * @returns {Function} Returns the new bound function.
10147 * function greet(greeting, punctuation) {
10148 * return greeting + ' ' + this.user + punctuation;
10151 * var object = { 'user': 'fred' };
10153 * var bound = _.bind(greet, object, 'hi');
10157 * // Bound with placeholders.
10158 * var bound = _.bind(greet, object, _, '!');
10162 var bind = baseRest(function(func, thisArg, partials) {
10163 var bitmask = WRAP_BIND_FLAG;
10164 if (partials.length) {
10165 var holders = replaceHolders(partials, getHolder(bind));
10166 bitmask |= WRAP_PARTIAL_FLAG;
10168 return createWrap(func, bitmask, thisArg, partials, holders);
10172 * Creates a function that invokes the method at `object[key]` with `partials`
10173 * prepended to the arguments it receives.
10175 * This method differs from `_.bind` by allowing bound functions to reference
10176 * methods that may be redefined or don't yet exist. See
10177 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
10178 * for more details.
10180 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
10181 * builds, may be used as a placeholder for partially applied arguments.
10186 * @category Function
10187 * @param {Object} object The object to invoke the method on.
10188 * @param {string} key The key of the method.
10189 * @param {...*} [partials] The arguments to be partially applied.
10190 * @returns {Function} Returns the new bound function.
10195 * 'greet': function(greeting, punctuation) {
10196 * return greeting + ' ' + this.user + punctuation;
10200 * var bound = _.bindKey(object, 'greet', 'hi');
10204 * object.greet = function(greeting, punctuation) {
10205 * return greeting + 'ya ' + this.user + punctuation;
10209 * // => 'hiya fred!'
10211 * // Bound with placeholders.
10212 * var bound = _.bindKey(object, 'greet', _, '!');
10214 * // => 'hiya fred!'
10216 var bindKey = baseRest(function(object, key, partials) {
10217 var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
10218 if (partials.length) {
10219 var holders = replaceHolders(partials, getHolder(bindKey));
10220 bitmask |= WRAP_PARTIAL_FLAG;
10222 return createWrap(key, bitmask, object, partials, holders);
10226 * Creates a function that accepts arguments of `func` and either invokes
10227 * `func` returning its result, if at least `arity` number of arguments have
10228 * been provided, or returns a function that accepts the remaining `func`
10229 * arguments, and so on. The arity of `func` may be specified if `func.length`
10230 * is not sufficient.
10232 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
10233 * may be used as a placeholder for provided arguments.
10235 * **Note:** This method doesn't set the "length" property of curried functions.
10240 * @category Function
10241 * @param {Function} func The function to curry.
10242 * @param {number} [arity=func.length] The arity of `func`.
10243 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10244 * @returns {Function} Returns the new curried function.
10247 * var abc = function(a, b, c) {
10248 * return [a, b, c];
10251 * var curried = _.curry(abc);
10253 * curried(1)(2)(3);
10256 * curried(1, 2)(3);
10259 * curried(1, 2, 3);
10262 * // Curried with placeholders.
10263 * curried(1)(_, 3)(2);
10266 function curry(func, arity, guard) {
10267 arity = guard ? undefined : arity;
10268 var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10269 result.placeholder = curry.placeholder;
10274 * This method is like `_.curry` except that arguments are applied to `func`
10275 * in the manner of `_.partialRight` instead of `_.partial`.
10277 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
10278 * builds, may be used as a placeholder for provided arguments.
10280 * **Note:** This method doesn't set the "length" property of curried functions.
10285 * @category Function
10286 * @param {Function} func The function to curry.
10287 * @param {number} [arity=func.length] The arity of `func`.
10288 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10289 * @returns {Function} Returns the new curried function.
10292 * var abc = function(a, b, c) {
10293 * return [a, b, c];
10296 * var curried = _.curryRight(abc);
10298 * curried(3)(2)(1);
10301 * curried(2, 3)(1);
10304 * curried(1, 2, 3);
10307 * // Curried with placeholders.
10308 * curried(3)(1, _)(2);
10311 function curryRight(func, arity, guard) {
10312 arity = guard ? undefined : arity;
10313 var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10314 result.placeholder = curryRight.placeholder;
10319 * Creates a debounced function that delays invoking `func` until after `wait`
10320 * milliseconds have elapsed since the last time the debounced function was
10321 * invoked. The debounced function comes with a `cancel` method to cancel
10322 * delayed `func` invocations and a `flush` method to immediately invoke them.
10323 * Provide `options` to indicate whether `func` should be invoked on the
10324 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
10325 * with the last arguments provided to the debounced function. Subsequent
10326 * calls to the debounced function return the result of the last `func`
10329 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10330 * invoked on the trailing edge of the timeout only if the debounced function
10331 * is invoked more than once during the `wait` timeout.
10333 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10334 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10336 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10337 * for details over the differences between `_.debounce` and `_.throttle`.
10342 * @category Function
10343 * @param {Function} func The function to debounce.
10344 * @param {number} [wait=0] The number of milliseconds to delay.
10345 * @param {Object} [options={}] The options object.
10346 * @param {boolean} [options.leading=false]
10347 * Specify invoking on the leading edge of the timeout.
10348 * @param {number} [options.maxWait]
10349 * The maximum time `func` is allowed to be delayed before it's invoked.
10350 * @param {boolean} [options.trailing=true]
10351 * Specify invoking on the trailing edge of the timeout.
10352 * @returns {Function} Returns the new debounced function.
10355 * // Avoid costly calculations while the window size is in flux.
10356 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
10358 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
10359 * jQuery(element).on('click', _.debounce(sendMail, 300, {
10361 * 'trailing': false
10364 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
10365 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
10366 * var source = new EventSource('/stream');
10367 * jQuery(source).on('message', debounced);
10369 * // Cancel the trailing debounced invocation.
10370 * jQuery(window).on('popstate', debounced.cancel);
10372 function debounce(func, wait, options) {
10379 lastInvokeTime = 0,
10384 if (typeof func != 'function') {
10385 throw new TypeError(FUNC_ERROR_TEXT);
10387 wait = toNumber(wait) || 0;
10388 if (isObject(options)) {
10389 leading = !!options.leading;
10390 maxing = 'maxWait' in options;
10391 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
10392 trailing = 'trailing' in options ? !!options.trailing : trailing;
10395 function invokeFunc(time) {
10396 var args = lastArgs,
10397 thisArg = lastThis;
10399 lastArgs = lastThis = undefined;
10400 lastInvokeTime = time;
10401 result = func.apply(thisArg, args);
10405 function leadingEdge(time) {
10406 // Reset any `maxWait` timer.
10407 lastInvokeTime = time;
10408 // Start the timer for the trailing edge.
10409 timerId = setTimeout(timerExpired, wait);
10410 // Invoke the leading edge.
10411 return leading ? invokeFunc(time) : result;
10414 function remainingWait(time) {
10415 var timeSinceLastCall = time - lastCallTime,
10416 timeSinceLastInvoke = time - lastInvokeTime,
10417 timeWaiting = wait - timeSinceLastCall;
10420 ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
10424 function shouldInvoke(time) {
10425 var timeSinceLastCall = time - lastCallTime,
10426 timeSinceLastInvoke = time - lastInvokeTime;
10428 // Either this is the first call, activity has stopped and we're at the
10429 // trailing edge, the system time has gone backwards and we're treating
10430 // it as the trailing edge, or we've hit the `maxWait` limit.
10431 return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
10432 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
10435 function timerExpired() {
10437 if (shouldInvoke(time)) {
10438 return trailingEdge(time);
10440 // Restart the timer.
10441 timerId = setTimeout(timerExpired, remainingWait(time));
10444 function trailingEdge(time) {
10445 timerId = undefined;
10447 // Only invoke if we have `lastArgs` which means `func` has been
10448 // debounced at least once.
10449 if (trailing && lastArgs) {
10450 return invokeFunc(time);
10452 lastArgs = lastThis = undefined;
10456 function cancel() {
10457 if (timerId !== undefined) {
10458 clearTimeout(timerId);
10460 lastInvokeTime = 0;
10461 lastArgs = lastCallTime = lastThis = timerId = undefined;
10465 return timerId === undefined ? result : trailingEdge(now());
10468 function debounced() {
10470 isInvoking = shouldInvoke(time);
10472 lastArgs = arguments;
10474 lastCallTime = time;
10477 if (timerId === undefined) {
10478 return leadingEdge(lastCallTime);
10481 // Handle invocations in a tight loop.
10482 clearTimeout(timerId);
10483 timerId = setTimeout(timerExpired, wait);
10484 return invokeFunc(lastCallTime);
10487 if (timerId === undefined) {
10488 timerId = setTimeout(timerExpired, wait);
10492 debounced.cancel = cancel;
10493 debounced.flush = flush;
10498 * Defers invoking the `func` until the current call stack has cleared. Any
10499 * additional arguments are provided to `func` when it's invoked.
10504 * @category Function
10505 * @param {Function} func The function to defer.
10506 * @param {...*} [args] The arguments to invoke `func` with.
10507 * @returns {number} Returns the timer id.
10510 * _.defer(function(text) {
10511 * console.log(text);
10513 * // => Logs 'deferred' after one millisecond.
10515 var defer = baseRest(function(func, args) {
10516 return baseDelay(func, 1, args);
10520 * Invokes `func` after `wait` milliseconds. Any additional arguments are
10521 * provided to `func` when it's invoked.
10526 * @category Function
10527 * @param {Function} func The function to delay.
10528 * @param {number} wait The number of milliseconds to delay invocation.
10529 * @param {...*} [args] The arguments to invoke `func` with.
10530 * @returns {number} Returns the timer id.
10533 * _.delay(function(text) {
10534 * console.log(text);
10535 * }, 1000, 'later');
10536 * // => Logs 'later' after one second.
10538 var delay = baseRest(function(func, wait, args) {
10539 return baseDelay(func, toNumber(wait) || 0, args);
10543 * Creates a function that invokes `func` with arguments reversed.
10548 * @category Function
10549 * @param {Function} func The function to flip arguments for.
10550 * @returns {Function} Returns the new flipped function.
10553 * var flipped = _.flip(function() {
10554 * return _.toArray(arguments);
10557 * flipped('a', 'b', 'c', 'd');
10558 * // => ['d', 'c', 'b', 'a']
10560 function flip(func) {
10561 return createWrap(func, WRAP_FLIP_FLAG);
10565 * Creates a function that memoizes the result of `func`. If `resolver` is
10566 * provided, it determines the cache key for storing the result based on the
10567 * arguments provided to the memoized function. By default, the first argument
10568 * provided to the memoized function is used as the map cache key. The `func`
10569 * is invoked with the `this` binding of the memoized function.
10571 * **Note:** The cache is exposed as the `cache` property on the memoized
10572 * function. Its creation may be customized by replacing the `_.memoize.Cache`
10573 * constructor with one whose instances implement the
10574 * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
10575 * method interface of `clear`, `delete`, `get`, `has`, and `set`.
10580 * @category Function
10581 * @param {Function} func The function to have its output memoized.
10582 * @param {Function} [resolver] The function to resolve the cache key.
10583 * @returns {Function} Returns the new memoized function.
10586 * var object = { 'a': 1, 'b': 2 };
10587 * var other = { 'c': 3, 'd': 4 };
10589 * var values = _.memoize(_.values);
10600 * // Modify the result cache.
10601 * values.cache.set(object, ['a', 'b']);
10605 * // Replace `_.memoize.Cache`.
10606 * _.memoize.Cache = WeakMap;
10608 function memoize(func, resolver) {
10609 if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
10610 throw new TypeError(FUNC_ERROR_TEXT);
10612 var memoized = function() {
10613 var args = arguments,
10614 key = resolver ? resolver.apply(this, args) : args[0],
10615 cache = memoized.cache;
10617 if (cache.has(key)) {
10618 return cache.get(key);
10620 var result = func.apply(this, args);
10621 memoized.cache = cache.set(key, result) || cache;
10624 memoized.cache = new (memoize.Cache || MapCache);
10628 // Expose `MapCache`.
10629 memoize.Cache = MapCache;
10632 * Creates a function that negates the result of the predicate `func`. The
10633 * `func` predicate is invoked with the `this` binding and arguments of the
10634 * created function.
10639 * @category Function
10640 * @param {Function} predicate The predicate to negate.
10641 * @returns {Function} Returns the new negated function.
10644 * function isEven(n) {
10645 * return n % 2 == 0;
10648 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
10651 function negate(predicate) {
10652 if (typeof predicate != 'function') {
10653 throw new TypeError(FUNC_ERROR_TEXT);
10655 return function() {
10656 var args = arguments;
10657 switch (args.length) {
10658 case 0: return !predicate.call(this);
10659 case 1: return !predicate.call(this, args[0]);
10660 case 2: return !predicate.call(this, args[0], args[1]);
10661 case 3: return !predicate.call(this, args[0], args[1], args[2]);
10663 return !predicate.apply(this, args);
10668 * Creates a function that is restricted to invoking `func` once. Repeat calls
10669 * to the function return the value of the first invocation. The `func` is
10670 * invoked with the `this` binding and arguments of the created function.
10675 * @category Function
10676 * @param {Function} func The function to restrict.
10677 * @returns {Function} Returns the new restricted function.
10680 * var initialize = _.once(createApplication);
10683 * // => `createApplication` is invoked once
10685 function once(func) {
10686 return before(2, func);
10690 * Creates a function that invokes `func` with its arguments transformed.
10695 * @category Function
10696 * @param {Function} func The function to wrap.
10697 * @param {...(Function|Function[])} [transforms=[_.identity]]
10698 * The argument transforms.
10699 * @returns {Function} Returns the new function.
10702 * function doubled(n) {
10706 * function square(n) {
10710 * var func = _.overArgs(function(x, y) {
10712 * }, [square, doubled]);
10720 var overArgs = castRest(function(func, transforms) {
10721 transforms = (transforms.length == 1 && isArray(transforms[0]))
10722 ? arrayMap(transforms[0], baseUnary(getIteratee()))
10723 : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
10725 var funcsLength = transforms.length;
10726 return baseRest(function(args) {
10728 length = nativeMin(args.length, funcsLength);
10730 while (++index < length) {
10731 args[index] = transforms[index].call(this, args[index]);
10733 return apply(func, this, args);
10738 * Creates a function that invokes `func` with `partials` prepended to the
10739 * arguments it receives. This method is like `_.bind` except it does **not**
10740 * alter the `this` binding.
10742 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
10743 * builds, may be used as a placeholder for partially applied arguments.
10745 * **Note:** This method doesn't set the "length" property of partially
10746 * applied functions.
10751 * @category Function
10752 * @param {Function} func The function to partially apply arguments to.
10753 * @param {...*} [partials] The arguments to be partially applied.
10754 * @returns {Function} Returns the new partially applied function.
10757 * function greet(greeting, name) {
10758 * return greeting + ' ' + name;
10761 * var sayHelloTo = _.partial(greet, 'hello');
10762 * sayHelloTo('fred');
10763 * // => 'hello fred'
10765 * // Partially applied with placeholders.
10766 * var greetFred = _.partial(greet, _, 'fred');
10770 var partial = baseRest(function(func, partials) {
10771 var holders = replaceHolders(partials, getHolder(partial));
10772 return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
10776 * This method is like `_.partial` except that partially applied arguments
10777 * are appended to the arguments it receives.
10779 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
10780 * builds, may be used as a placeholder for partially applied arguments.
10782 * **Note:** This method doesn't set the "length" property of partially
10783 * applied functions.
10788 * @category Function
10789 * @param {Function} func The function to partially apply arguments to.
10790 * @param {...*} [partials] The arguments to be partially applied.
10791 * @returns {Function} Returns the new partially applied function.
10794 * function greet(greeting, name) {
10795 * return greeting + ' ' + name;
10798 * var greetFred = _.partialRight(greet, 'fred');
10802 * // Partially applied with placeholders.
10803 * var sayHelloTo = _.partialRight(greet, 'hello', _);
10804 * sayHelloTo('fred');
10805 * // => 'hello fred'
10807 var partialRight = baseRest(function(func, partials) {
10808 var holders = replaceHolders(partials, getHolder(partialRight));
10809 return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
10813 * Creates a function that invokes `func` with arguments arranged according
10814 * to the specified `indexes` where the argument value at the first index is
10815 * provided as the first argument, the argument value at the second index is
10816 * provided as the second argument, and so on.
10821 * @category Function
10822 * @param {Function} func The function to rearrange arguments for.
10823 * @param {...(number|number[])} indexes The arranged argument indexes.
10824 * @returns {Function} Returns the new function.
10827 * var rearged = _.rearg(function(a, b, c) {
10828 * return [a, b, c];
10831 * rearged('b', 'c', 'a')
10832 * // => ['a', 'b', 'c']
10834 var rearg = flatRest(function(func, indexes) {
10835 return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
10839 * Creates a function that invokes `func` with the `this` binding of the
10840 * created function and arguments from `start` and beyond provided as
10843 * **Note:** This method is based on the
10844 * [rest parameter](https://mdn.io/rest_parameters).
10849 * @category Function
10850 * @param {Function} func The function to apply a rest parameter to.
10851 * @param {number} [start=func.length-1] The start position of the rest parameter.
10852 * @returns {Function} Returns the new function.
10855 * var say = _.rest(function(what, names) {
10856 * return what + ' ' + _.initial(names).join(', ') +
10857 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
10860 * say('hello', 'fred', 'barney', 'pebbles');
10861 * // => 'hello fred, barney, & pebbles'
10863 function rest(func, start) {
10864 if (typeof func != 'function') {
10865 throw new TypeError(FUNC_ERROR_TEXT);
10867 start = start === undefined ? start : toInteger(start);
10868 return baseRest(func, start);
10872 * Creates a function that invokes `func` with the `this` binding of the
10873 * create function and an array of arguments much like
10874 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
10876 * **Note:** This method is based on the
10877 * [spread operator](https://mdn.io/spread_operator).
10882 * @category Function
10883 * @param {Function} func The function to spread arguments over.
10884 * @param {number} [start=0] The start position of the spread.
10885 * @returns {Function} Returns the new function.
10888 * var say = _.spread(function(who, what) {
10889 * return who + ' says ' + what;
10892 * say(['fred', 'hello']);
10893 * // => 'fred says hello'
10895 * var numbers = Promise.all([
10896 * Promise.resolve(40),
10897 * Promise.resolve(36)
10900 * numbers.then(_.spread(function(x, y) {
10903 * // => a Promise of 76
10905 function spread(func, start) {
10906 if (typeof func != 'function') {
10907 throw new TypeError(FUNC_ERROR_TEXT);
10909 start = start == null ? 0 : nativeMax(toInteger(start), 0);
10910 return baseRest(function(args) {
10911 var array = args[start],
10912 otherArgs = castSlice(args, 0, start);
10915 arrayPush(otherArgs, array);
10917 return apply(func, this, otherArgs);
10922 * Creates a throttled function that only invokes `func` at most once per
10923 * every `wait` milliseconds. The throttled function comes with a `cancel`
10924 * method to cancel delayed `func` invocations and a `flush` method to
10925 * immediately invoke them. Provide `options` to indicate whether `func`
10926 * should be invoked on the leading and/or trailing edge of the `wait`
10927 * timeout. The `func` is invoked with the last arguments provided to the
10928 * throttled function. Subsequent calls to the throttled function return the
10929 * result of the last `func` invocation.
10931 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10932 * invoked on the trailing edge of the timeout only if the throttled function
10933 * is invoked more than once during the `wait` timeout.
10935 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10936 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10938 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10939 * for details over the differences between `_.throttle` and `_.debounce`.
10944 * @category Function
10945 * @param {Function} func The function to throttle.
10946 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
10947 * @param {Object} [options={}] The options object.
10948 * @param {boolean} [options.leading=true]
10949 * Specify invoking on the leading edge of the timeout.
10950 * @param {boolean} [options.trailing=true]
10951 * Specify invoking on the trailing edge of the timeout.
10952 * @returns {Function} Returns the new throttled function.
10955 * // Avoid excessively updating the position while scrolling.
10956 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
10958 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
10959 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
10960 * jQuery(element).on('click', throttled);
10962 * // Cancel the trailing throttled invocation.
10963 * jQuery(window).on('popstate', throttled.cancel);
10965 function throttle(func, wait, options) {
10966 var leading = true,
10969 if (typeof func != 'function') {
10970 throw new TypeError(FUNC_ERROR_TEXT);
10972 if (isObject(options)) {
10973 leading = 'leading' in options ? !!options.leading : leading;
10974 trailing = 'trailing' in options ? !!options.trailing : trailing;
10976 return debounce(func, wait, {
10977 'leading': leading,
10979 'trailing': trailing
10984 * Creates a function that accepts up to one argument, ignoring any
10985 * additional arguments.
10990 * @category Function
10991 * @param {Function} func The function to cap arguments for.
10992 * @returns {Function} Returns the new capped function.
10995 * _.map(['6', '8', '10'], _.unary(parseInt));
10998 function unary(func) {
10999 return ary(func, 1);
11003 * Creates a function that provides `value` to `wrapper` as its first
11004 * argument. Any additional arguments provided to the function are appended
11005 * to those provided to the `wrapper`. The wrapper is invoked with the `this`
11006 * binding of the created function.
11011 * @category Function
11012 * @param {*} value The value to wrap.
11013 * @param {Function} [wrapper=identity] The wrapper function.
11014 * @returns {Function} Returns the new function.
11017 * var p = _.wrap(_.escape, function(func, text) {
11018 * return '<p>' + func(text) + '</p>';
11021 * p('fred, barney, & pebbles');
11022 * // => '<p>fred, barney, & pebbles</p>'
11024 function wrap(value, wrapper) {
11025 return partial(castFunction(wrapper), value);
11028 /*------------------------------------------------------------------------*/
11031 * Casts `value` as an array if it's not one.
11037 * @param {*} value The value to inspect.
11038 * @returns {Array} Returns the cast array.
11044 * _.castArray({ 'a': 1 });
11045 * // => [{ 'a': 1 }]
11047 * _.castArray('abc');
11050 * _.castArray(null);
11053 * _.castArray(undefined);
11054 * // => [undefined]
11059 * var array = [1, 2, 3];
11060 * console.log(_.castArray(array) === array);
11063 function castArray() {
11064 if (!arguments.length) {
11067 var value = arguments[0];
11068 return isArray(value) ? value : [value];
11072 * Creates a shallow clone of `value`.
11074 * **Note:** This method is loosely based on the
11075 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
11076 * and supports cloning arrays, array buffers, booleans, date objects, maps,
11077 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
11078 * arrays. The own enumerable properties of `arguments` objects are cloned
11079 * as plain objects. An empty object is returned for uncloneable values such
11080 * as error objects, functions, DOM nodes, and WeakMaps.
11086 * @param {*} value The value to clone.
11087 * @returns {*} Returns the cloned value.
11091 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11093 * var shallow = _.clone(objects);
11094 * console.log(shallow[0] === objects[0]);
11097 function clone(value) {
11098 return baseClone(value, CLONE_SYMBOLS_FLAG);
11102 * This method is like `_.clone` except that it accepts `customizer` which
11103 * is invoked to produce the cloned value. If `customizer` returns `undefined`,
11104 * cloning is handled by the method instead. The `customizer` is invoked with
11105 * up to four arguments; (value [, index|key, object, stack]).
11111 * @param {*} value The value to clone.
11112 * @param {Function} [customizer] The function to customize cloning.
11113 * @returns {*} Returns the cloned value.
11114 * @see _.cloneDeepWith
11117 * function customizer(value) {
11118 * if (_.isElement(value)) {
11119 * return value.cloneNode(false);
11123 * var el = _.cloneWith(document.body, customizer);
11125 * console.log(el === document.body);
11127 * console.log(el.nodeName);
11129 * console.log(el.childNodes.length);
11132 function cloneWith(value, customizer) {
11133 customizer = typeof customizer == 'function' ? customizer : undefined;
11134 return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
11138 * This method is like `_.clone` except that it recursively clones `value`.
11144 * @param {*} value The value to recursively clone.
11145 * @returns {*} Returns the deep cloned value.
11149 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11151 * var deep = _.cloneDeep(objects);
11152 * console.log(deep[0] === objects[0]);
11155 function cloneDeep(value) {
11156 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
11160 * This method is like `_.cloneWith` except that it recursively clones `value`.
11166 * @param {*} value The value to recursively clone.
11167 * @param {Function} [customizer] The function to customize cloning.
11168 * @returns {*} Returns the deep cloned value.
11172 * function customizer(value) {
11173 * if (_.isElement(value)) {
11174 * return value.cloneNode(true);
11178 * var el = _.cloneDeepWith(document.body, customizer);
11180 * console.log(el === document.body);
11182 * console.log(el.nodeName);
11184 * console.log(el.childNodes.length);
11187 function cloneDeepWith(value, customizer) {
11188 customizer = typeof customizer == 'function' ? customizer : undefined;
11189 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
11193 * Checks if `object` conforms to `source` by invoking the predicate
11194 * properties of `source` with the corresponding property values of `object`.
11196 * **Note:** This method is equivalent to `_.conforms` when `source` is
11197 * partially applied.
11203 * @param {Object} object The object to inspect.
11204 * @param {Object} source The object of property predicates to conform to.
11205 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
11208 * var object = { 'a': 1, 'b': 2 };
11210 * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
11213 * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
11216 function conformsTo(object, source) {
11217 return source == null || baseConformsTo(object, source, keys(source));
11222 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
11223 * comparison between two values to determine if they are equivalent.
11229 * @param {*} value The value to compare.
11230 * @param {*} other The other value to compare.
11231 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11234 * var object = { 'a': 1 };
11235 * var other = { 'a': 1 };
11237 * _.eq(object, object);
11240 * _.eq(object, other);
11246 * _.eq('a', Object('a'));
11252 function eq(value, other) {
11253 return value === other || (value !== value && other !== other);
11257 * Checks if `value` is greater than `other`.
11263 * @param {*} value The value to compare.
11264 * @param {*} other The other value to compare.
11265 * @returns {boolean} Returns `true` if `value` is greater than `other`,
11279 var gt = createRelationalOperation(baseGt);
11282 * Checks if `value` is greater than or equal to `other`.
11288 * @param {*} value The value to compare.
11289 * @param {*} other The other value to compare.
11290 * @returns {boolean} Returns `true` if `value` is greater than or equal to
11291 * `other`, else `false`.
11304 var gte = createRelationalOperation(function(value, other) {
11305 return value >= other;
11309 * Checks if `value` is likely an `arguments` object.
11315 * @param {*} value The value to check.
11316 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
11320 * _.isArguments(function() { return arguments; }());
11323 * _.isArguments([1, 2, 3]);
11326 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
11327 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
11328 !propertyIsEnumerable.call(value, 'callee');
11332 * Checks if `value` is classified as an `Array` object.
11338 * @param {*} value The value to check.
11339 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
11342 * _.isArray([1, 2, 3]);
11345 * _.isArray(document.body.children);
11348 * _.isArray('abc');
11351 * _.isArray(_.noop);
11354 var isArray = Array.isArray;
11357 * Checks if `value` is classified as an `ArrayBuffer` object.
11363 * @param {*} value The value to check.
11364 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
11367 * _.isArrayBuffer(new ArrayBuffer(2));
11370 * _.isArrayBuffer(new Array(2));
11373 var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
11376 * Checks if `value` is array-like. A value is considered array-like if it's
11377 * not a function and has a `value.length` that's an integer greater than or
11378 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
11384 * @param {*} value The value to check.
11385 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11388 * _.isArrayLike([1, 2, 3]);
11391 * _.isArrayLike(document.body.children);
11394 * _.isArrayLike('abc');
11397 * _.isArrayLike(_.noop);
11400 function isArrayLike(value) {
11401 return value != null && isLength(value.length) && !isFunction(value);
11405 * This method is like `_.isArrayLike` except that it also checks if `value`
11412 * @param {*} value The value to check.
11413 * @returns {boolean} Returns `true` if `value` is an array-like object,
11417 * _.isArrayLikeObject([1, 2, 3]);
11420 * _.isArrayLikeObject(document.body.children);
11423 * _.isArrayLikeObject('abc');
11426 * _.isArrayLikeObject(_.noop);
11429 function isArrayLikeObject(value) {
11430 return isObjectLike(value) && isArrayLike(value);
11434 * Checks if `value` is classified as a boolean primitive or object.
11440 * @param {*} value The value to check.
11441 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
11444 * _.isBoolean(false);
11447 * _.isBoolean(null);
11450 function isBoolean(value) {
11451 return value === true || value === false ||
11452 (isObjectLike(value) && baseGetTag(value) == boolTag);
11456 * Checks if `value` is a buffer.
11462 * @param {*} value The value to check.
11463 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
11466 * _.isBuffer(new Buffer(2));
11469 * _.isBuffer(new Uint8Array(2));
11472 var isBuffer = nativeIsBuffer || stubFalse;
11475 * Checks if `value` is classified as a `Date` object.
11481 * @param {*} value The value to check.
11482 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
11485 * _.isDate(new Date);
11488 * _.isDate('Mon April 23 2012');
11491 var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
11494 * Checks if `value` is likely a DOM element.
11500 * @param {*} value The value to check.
11501 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
11504 * _.isElement(document.body);
11507 * _.isElement('<body>');
11510 function isElement(value) {
11511 return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
11515 * Checks if `value` is an empty object, collection, map, or set.
11517 * Objects are considered empty if they have no own enumerable string keyed
11520 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
11521 * jQuery-like collections are considered empty if they have a `length` of `0`.
11522 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
11528 * @param {*} value The value to check.
11529 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
11541 * _.isEmpty([1, 2, 3]);
11544 * _.isEmpty({ 'a': 1 });
11547 function isEmpty(value) {
11548 if (value == null) {
11551 if (isArrayLike(value) &&
11552 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
11553 isBuffer(value) || isTypedArray(value) || isArguments(value))) {
11554 return !value.length;
11556 var tag = getTag(value);
11557 if (tag == mapTag || tag == setTag) {
11558 return !value.size;
11560 if (isPrototype(value)) {
11561 return !baseKeys(value).length;
11563 for (var key in value) {
11564 if (hasOwnProperty.call(value, key)) {
11572 * Performs a deep comparison between two values to determine if they are
11575 * **Note:** This method supports comparing arrays, array buffers, booleans,
11576 * date objects, error objects, maps, numbers, `Object` objects, regexes,
11577 * sets, strings, symbols, and typed arrays. `Object` objects are compared
11578 * by their own, not inherited, enumerable properties. Functions and DOM
11579 * nodes are compared by strict equality, i.e. `===`.
11585 * @param {*} value The value to compare.
11586 * @param {*} other The other value to compare.
11587 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11590 * var object = { 'a': 1 };
11591 * var other = { 'a': 1 };
11593 * _.isEqual(object, other);
11596 * object === other;
11599 function isEqual(value, other) {
11600 return baseIsEqual(value, other);
11604 * This method is like `_.isEqual` except that it accepts `customizer` which
11605 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11606 * are handled by the method instead. The `customizer` is invoked with up to
11607 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
11613 * @param {*} value The value to compare.
11614 * @param {*} other The other value to compare.
11615 * @param {Function} [customizer] The function to customize comparisons.
11616 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11619 * function isGreeting(value) {
11620 * return /^h(?:i|ello)$/.test(value);
11623 * function customizer(objValue, othValue) {
11624 * if (isGreeting(objValue) && isGreeting(othValue)) {
11629 * var array = ['hello', 'goodbye'];
11630 * var other = ['hi', 'goodbye'];
11632 * _.isEqualWith(array, other, customizer);
11635 function isEqualWith(value, other, customizer) {
11636 customizer = typeof customizer == 'function' ? customizer : undefined;
11637 var result = customizer ? customizer(value, other) : undefined;
11638 return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
11642 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
11643 * `SyntaxError`, `TypeError`, or `URIError` object.
11649 * @param {*} value The value to check.
11650 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
11653 * _.isError(new Error);
11656 * _.isError(Error);
11659 function isError(value) {
11660 if (!isObjectLike(value)) {
11663 var tag = baseGetTag(value);
11664 return tag == errorTag || tag == domExcTag ||
11665 (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
11669 * Checks if `value` is a finite primitive number.
11671 * **Note:** This method is based on
11672 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
11678 * @param {*} value The value to check.
11679 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
11685 * _.isFinite(Number.MIN_VALUE);
11688 * _.isFinite(Infinity);
11694 function isFinite(value) {
11695 return typeof value == 'number' && nativeIsFinite(value);
11699 * Checks if `value` is classified as a `Function` object.
11705 * @param {*} value The value to check.
11706 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
11712 * _.isFunction(/abc/);
11715 function isFunction(value) {
11716 if (!isObject(value)) {
11719 // The use of `Object#toString` avoids issues with the `typeof` operator
11720 // in Safari 9 which returns 'object' for typed arrays and other constructors.
11721 var tag = baseGetTag(value);
11722 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
11726 * Checks if `value` is an integer.
11728 * **Note:** This method is based on
11729 * [`Number.isInteger`](https://mdn.io/Number/isInteger).
11735 * @param {*} value The value to check.
11736 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
11742 * _.isInteger(Number.MIN_VALUE);
11745 * _.isInteger(Infinity);
11748 * _.isInteger('3');
11751 function isInteger(value) {
11752 return typeof value == 'number' && value == toInteger(value);
11756 * Checks if `value` is a valid array-like length.
11758 * **Note:** This method is loosely based on
11759 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
11765 * @param {*} value The value to check.
11766 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11772 * _.isLength(Number.MIN_VALUE);
11775 * _.isLength(Infinity);
11781 function isLength(value) {
11782 return typeof value == 'number' &&
11783 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11787 * Checks if `value` is the
11788 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
11789 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11795 * @param {*} value The value to check.
11796 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11802 * _.isObject([1, 2, 3]);
11805 * _.isObject(_.noop);
11808 * _.isObject(null);
11811 function isObject(value) {
11812 var type = typeof value;
11813 return value != null && (type == 'object' || type == 'function');
11817 * Checks if `value` is object-like. A value is object-like if it's not `null`
11818 * and has a `typeof` result of "object".
11824 * @param {*} value The value to check.
11825 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11828 * _.isObjectLike({});
11831 * _.isObjectLike([1, 2, 3]);
11834 * _.isObjectLike(_.noop);
11837 * _.isObjectLike(null);
11840 function isObjectLike(value) {
11841 return value != null && typeof value == 'object';
11845 * Checks if `value` is classified as a `Map` object.
11851 * @param {*} value The value to check.
11852 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
11855 * _.isMap(new Map);
11858 * _.isMap(new WeakMap);
11861 var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
11864 * Performs a partial deep comparison between `object` and `source` to
11865 * determine if `object` contains equivalent property values.
11867 * **Note:** This method is equivalent to `_.matches` when `source` is
11868 * partially applied.
11870 * Partial comparisons will match empty array and empty object `source`
11871 * values against any array or object value, respectively. See `_.isEqual`
11872 * for a list of supported value comparisons.
11878 * @param {Object} object The object to inspect.
11879 * @param {Object} source The object of property values to match.
11880 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11883 * var object = { 'a': 1, 'b': 2 };
11885 * _.isMatch(object, { 'b': 2 });
11888 * _.isMatch(object, { 'b': 1 });
11891 function isMatch(object, source) {
11892 return object === source || baseIsMatch(object, source, getMatchData(source));
11896 * This method is like `_.isMatch` except that it accepts `customizer` which
11897 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11898 * are handled by the method instead. The `customizer` is invoked with five
11899 * arguments: (objValue, srcValue, index|key, object, source).
11905 * @param {Object} object The object to inspect.
11906 * @param {Object} source The object of property values to match.
11907 * @param {Function} [customizer] The function to customize comparisons.
11908 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11911 * function isGreeting(value) {
11912 * return /^h(?:i|ello)$/.test(value);
11915 * function customizer(objValue, srcValue) {
11916 * if (isGreeting(objValue) && isGreeting(srcValue)) {
11921 * var object = { 'greeting': 'hello' };
11922 * var source = { 'greeting': 'hi' };
11924 * _.isMatchWith(object, source, customizer);
11927 function isMatchWith(object, source, customizer) {
11928 customizer = typeof customizer == 'function' ? customizer : undefined;
11929 return baseIsMatch(object, source, getMatchData(source), customizer);
11933 * Checks if `value` is `NaN`.
11935 * **Note:** This method is based on
11936 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
11937 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
11938 * `undefined` and other non-number values.
11944 * @param {*} value The value to check.
11945 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
11951 * _.isNaN(new Number(NaN));
11954 * isNaN(undefined);
11957 * _.isNaN(undefined);
11960 function isNaN(value) {
11961 // An `NaN` primitive is the only value that is not equal to itself.
11962 // Perform the `toStringTag` check first to avoid errors with some
11963 // ActiveX objects in IE.
11964 return isNumber(value) && value != +value;
11968 * Checks if `value` is a pristine native function.
11970 * **Note:** This method can't reliably detect native functions in the presence
11971 * of the core-js package because core-js circumvents this kind of detection.
11972 * Despite multiple requests, the core-js maintainer has made it clear: any
11973 * attempt to fix the detection will be obstructed. As a result, we're left
11974 * with little choice but to throw an error. Unfortunately, this also affects
11975 * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
11976 * which rely on core-js.
11982 * @param {*} value The value to check.
11983 * @returns {boolean} Returns `true` if `value` is a native function,
11987 * _.isNative(Array.prototype.push);
11993 function isNative(value) {
11994 if (isMaskable(value)) {
11995 throw new Error(CORE_ERROR_TEXT);
11997 return baseIsNative(value);
12001 * Checks if `value` is `null`.
12007 * @param {*} value The value to check.
12008 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
12014 * _.isNull(void 0);
12017 function isNull(value) {
12018 return value === null;
12022 * Checks if `value` is `null` or `undefined`.
12028 * @param {*} value The value to check.
12029 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
12041 function isNil(value) {
12042 return value == null;
12046 * Checks if `value` is classified as a `Number` primitive or object.
12048 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
12049 * classified as numbers, use the `_.isFinite` method.
12055 * @param {*} value The value to check.
12056 * @returns {boolean} Returns `true` if `value` is a number, else `false`.
12062 * _.isNumber(Number.MIN_VALUE);
12065 * _.isNumber(Infinity);
12071 function isNumber(value) {
12072 return typeof value == 'number' ||
12073 (isObjectLike(value) && baseGetTag(value) == numberTag);
12077 * Checks if `value` is a plain object, that is, an object created by the
12078 * `Object` constructor or one with a `[[Prototype]]` of `null`.
12084 * @param {*} value The value to check.
12085 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12092 * _.isPlainObject(new Foo);
12095 * _.isPlainObject([1, 2, 3]);
12098 * _.isPlainObject({ 'x': 0, 'y': 0 });
12101 * _.isPlainObject(Object.create(null));
12104 function isPlainObject(value) {
12105 if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
12108 var proto = getPrototype(value);
12109 if (proto === null) {
12112 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
12113 return typeof Ctor == 'function' && Ctor instanceof Ctor &&
12114 funcToString.call(Ctor) == objectCtorString;
12118 * Checks if `value` is classified as a `RegExp` object.
12124 * @param {*} value The value to check.
12125 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
12128 * _.isRegExp(/abc/);
12131 * _.isRegExp('/abc/');
12134 var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
12137 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
12138 * double precision number which isn't the result of a rounded unsafe integer.
12140 * **Note:** This method is based on
12141 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
12147 * @param {*} value The value to check.
12148 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
12151 * _.isSafeInteger(3);
12154 * _.isSafeInteger(Number.MIN_VALUE);
12157 * _.isSafeInteger(Infinity);
12160 * _.isSafeInteger('3');
12163 function isSafeInteger(value) {
12164 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
12168 * Checks if `value` is classified as a `Set` object.
12174 * @param {*} value The value to check.
12175 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
12178 * _.isSet(new Set);
12181 * _.isSet(new WeakSet);
12184 var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
12187 * Checks if `value` is classified as a `String` primitive or object.
12193 * @param {*} value The value to check.
12194 * @returns {boolean} Returns `true` if `value` is a string, else `false`.
12197 * _.isString('abc');
12203 function isString(value) {
12204 return typeof value == 'string' ||
12205 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
12209 * Checks if `value` is classified as a `Symbol` primitive or object.
12215 * @param {*} value The value to check.
12216 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
12219 * _.isSymbol(Symbol.iterator);
12222 * _.isSymbol('abc');
12225 function isSymbol(value) {
12226 return typeof value == 'symbol' ||
12227 (isObjectLike(value) && baseGetTag(value) == symbolTag);
12231 * Checks if `value` is classified as a typed array.
12237 * @param {*} value The value to check.
12238 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
12241 * _.isTypedArray(new Uint8Array);
12244 * _.isTypedArray([]);
12247 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
12250 * Checks if `value` is `undefined`.
12256 * @param {*} value The value to check.
12257 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
12260 * _.isUndefined(void 0);
12263 * _.isUndefined(null);
12266 function isUndefined(value) {
12267 return value === undefined;
12271 * Checks if `value` is classified as a `WeakMap` object.
12277 * @param {*} value The value to check.
12278 * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
12281 * _.isWeakMap(new WeakMap);
12284 * _.isWeakMap(new Map);
12287 function isWeakMap(value) {
12288 return isObjectLike(value) && getTag(value) == weakMapTag;
12292 * Checks if `value` is classified as a `WeakSet` object.
12298 * @param {*} value The value to check.
12299 * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
12302 * _.isWeakSet(new WeakSet);
12305 * _.isWeakSet(new Set);
12308 function isWeakSet(value) {
12309 return isObjectLike(value) && baseGetTag(value) == weakSetTag;
12313 * Checks if `value` is less than `other`.
12319 * @param {*} value The value to compare.
12320 * @param {*} other The other value to compare.
12321 * @returns {boolean} Returns `true` if `value` is less than `other`,
12335 var lt = createRelationalOperation(baseLt);
12338 * Checks if `value` is less than or equal to `other`.
12344 * @param {*} value The value to compare.
12345 * @param {*} other The other value to compare.
12346 * @returns {boolean} Returns `true` if `value` is less than or equal to
12347 * `other`, else `false`.
12360 var lte = createRelationalOperation(function(value, other) {
12361 return value <= other;
12365 * Converts `value` to an array.
12371 * @param {*} value The value to convert.
12372 * @returns {Array} Returns the converted array.
12375 * _.toArray({ 'a': 1, 'b': 2 });
12378 * _.toArray('abc');
12379 * // => ['a', 'b', 'c']
12387 function toArray(value) {
12391 if (isArrayLike(value)) {
12392 return isString(value) ? stringToArray(value) : copyArray(value);
12394 if (symIterator && value[symIterator]) {
12395 return iteratorToArray(value[symIterator]());
12397 var tag = getTag(value),
12398 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
12400 return func(value);
12404 * Converts `value` to a finite number.
12410 * @param {*} value The value to convert.
12411 * @returns {number} Returns the converted number.
12417 * _.toFinite(Number.MIN_VALUE);
12420 * _.toFinite(Infinity);
12421 * // => 1.7976931348623157e+308
12423 * _.toFinite('3.2');
12426 function toFinite(value) {
12428 return value === 0 ? value : 0;
12430 value = toNumber(value);
12431 if (value === INFINITY || value === -INFINITY) {
12432 var sign = (value < 0 ? -1 : 1);
12433 return sign * MAX_INTEGER;
12435 return value === value ? value : 0;
12439 * Converts `value` to an integer.
12441 * **Note:** This method is loosely based on
12442 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
12448 * @param {*} value The value to convert.
12449 * @returns {number} Returns the converted integer.
12452 * _.toInteger(3.2);
12455 * _.toInteger(Number.MIN_VALUE);
12458 * _.toInteger(Infinity);
12459 * // => 1.7976931348623157e+308
12461 * _.toInteger('3.2');
12464 function toInteger(value) {
12465 var result = toFinite(value),
12466 remainder = result % 1;
12468 return result === result ? (remainder ? result - remainder : result) : 0;
12472 * Converts `value` to an integer suitable for use as the length of an
12473 * array-like object.
12475 * **Note:** This method is based on
12476 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
12482 * @param {*} value The value to convert.
12483 * @returns {number} Returns the converted integer.
12489 * _.toLength(Number.MIN_VALUE);
12492 * _.toLength(Infinity);
12495 * _.toLength('3.2');
12498 function toLength(value) {
12499 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
12503 * Converts `value` to a number.
12509 * @param {*} value The value to process.
12510 * @returns {number} Returns the number.
12516 * _.toNumber(Number.MIN_VALUE);
12519 * _.toNumber(Infinity);
12522 * _.toNumber('3.2');
12525 function toNumber(value) {
12526 if (typeof value == 'number') {
12529 if (isSymbol(value)) {
12532 if (isObject(value)) {
12533 var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
12534 value = isObject(other) ? (other + '') : other;
12536 if (typeof value != 'string') {
12537 return value === 0 ? value : +value;
12539 value = baseTrim(value);
12540 var isBinary = reIsBinary.test(value);
12541 return (isBinary || reIsOctal.test(value))
12542 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
12543 : (reIsBadHex.test(value) ? NAN : +value);
12547 * Converts `value` to a plain object flattening inherited enumerable string
12548 * keyed properties of `value` to own properties of the plain object.
12554 * @param {*} value The value to convert.
12555 * @returns {Object} Returns the converted plain object.
12562 * Foo.prototype.c = 3;
12564 * _.assign({ 'a': 1 }, new Foo);
12565 * // => { 'a': 1, 'b': 2 }
12567 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
12568 * // => { 'a': 1, 'b': 2, 'c': 3 }
12570 function toPlainObject(value) {
12571 return copyObject(value, keysIn(value));
12575 * Converts `value` to a safe integer. A safe integer can be compared and
12576 * represented correctly.
12582 * @param {*} value The value to convert.
12583 * @returns {number} Returns the converted integer.
12586 * _.toSafeInteger(3.2);
12589 * _.toSafeInteger(Number.MIN_VALUE);
12592 * _.toSafeInteger(Infinity);
12593 * // => 9007199254740991
12595 * _.toSafeInteger('3.2');
12598 function toSafeInteger(value) {
12600 ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
12601 : (value === 0 ? value : 0);
12605 * Converts `value` to a string. An empty string is returned for `null`
12606 * and `undefined` values. The sign of `-0` is preserved.
12612 * @param {*} value The value to convert.
12613 * @returns {string} Returns the converted string.
12616 * _.toString(null);
12622 * _.toString([1, 2, 3]);
12625 function toString(value) {
12626 return value == null ? '' : baseToString(value);
12629 /*------------------------------------------------------------------------*/
12632 * Assigns own enumerable string keyed properties of source objects to the
12633 * destination object. Source objects are applied from left to right.
12634 * Subsequent sources overwrite property assignments of previous sources.
12636 * **Note:** This method mutates `object` and is loosely based on
12637 * [`Object.assign`](https://mdn.io/Object/assign).
12643 * @param {Object} object The destination object.
12644 * @param {...Object} [sources] The source objects.
12645 * @returns {Object} Returns `object`.
12657 * Foo.prototype.b = 2;
12658 * Bar.prototype.d = 4;
12660 * _.assign({ 'a': 0 }, new Foo, new Bar);
12661 * // => { 'a': 1, 'c': 3 }
12663 var assign = createAssigner(function(object, source) {
12664 if (isPrototype(source) || isArrayLike(source)) {
12665 copyObject(source, keys(source), object);
12668 for (var key in source) {
12669 if (hasOwnProperty.call(source, key)) {
12670 assignValue(object, key, source[key]);
12676 * This method is like `_.assign` except that it iterates over own and
12677 * inherited source properties.
12679 * **Note:** This method mutates `object`.
12686 * @param {Object} object The destination object.
12687 * @param {...Object} [sources] The source objects.
12688 * @returns {Object} Returns `object`.
12700 * Foo.prototype.b = 2;
12701 * Bar.prototype.d = 4;
12703 * _.assignIn({ 'a': 0 }, new Foo, new Bar);
12704 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
12706 var assignIn = createAssigner(function(object, source) {
12707 copyObject(source, keysIn(source), object);
12711 * This method is like `_.assignIn` except that it accepts `customizer`
12712 * which is invoked to produce the assigned values. If `customizer` returns
12713 * `undefined`, assignment is handled by the method instead. The `customizer`
12714 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12716 * **Note:** This method mutates `object`.
12721 * @alias extendWith
12723 * @param {Object} object The destination object.
12724 * @param {...Object} sources The source objects.
12725 * @param {Function} [customizer] The function to customize assigned values.
12726 * @returns {Object} Returns `object`.
12727 * @see _.assignWith
12730 * function customizer(objValue, srcValue) {
12731 * return _.isUndefined(objValue) ? srcValue : objValue;
12734 * var defaults = _.partialRight(_.assignInWith, customizer);
12736 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12737 * // => { 'a': 1, 'b': 2 }
12739 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
12740 copyObject(source, keysIn(source), object, customizer);
12744 * This method is like `_.assign` except that it accepts `customizer`
12745 * which is invoked to produce the assigned values. If `customizer` returns
12746 * `undefined`, assignment is handled by the method instead. The `customizer`
12747 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12749 * **Note:** This method mutates `object`.
12755 * @param {Object} object The destination object.
12756 * @param {...Object} sources The source objects.
12757 * @param {Function} [customizer] The function to customize assigned values.
12758 * @returns {Object} Returns `object`.
12759 * @see _.assignInWith
12762 * function customizer(objValue, srcValue) {
12763 * return _.isUndefined(objValue) ? srcValue : objValue;
12766 * var defaults = _.partialRight(_.assignWith, customizer);
12768 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12769 * // => { 'a': 1, 'b': 2 }
12771 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
12772 copyObject(source, keys(source), object, customizer);
12776 * Creates an array of values corresponding to `paths` of `object`.
12782 * @param {Object} object The object to iterate over.
12783 * @param {...(string|string[])} [paths] The property paths to pick.
12784 * @returns {Array} Returns the picked values.
12787 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
12789 * _.at(object, ['a[0].b.c', 'a[1]']);
12792 var at = flatRest(baseAt);
12795 * Creates an object that inherits from the `prototype` object. If a
12796 * `properties` object is given, its own enumerable string keyed properties
12797 * are assigned to the created object.
12803 * @param {Object} prototype The object to inherit from.
12804 * @param {Object} [properties] The properties to assign to the object.
12805 * @returns {Object} Returns the new object.
12808 * function Shape() {
12813 * function Circle() {
12814 * Shape.call(this);
12817 * Circle.prototype = _.create(Shape.prototype, {
12818 * 'constructor': Circle
12821 * var circle = new Circle;
12822 * circle instanceof Circle;
12825 * circle instanceof Shape;
12828 function create(prototype, properties) {
12829 var result = baseCreate(prototype);
12830 return properties == null ? result : baseAssign(result, properties);
12834 * Assigns own and inherited enumerable string keyed properties of source
12835 * objects to the destination object for all destination properties that
12836 * resolve to `undefined`. Source objects are applied from left to right.
12837 * Once a property is set, additional values of the same property are ignored.
12839 * **Note:** This method mutates `object`.
12845 * @param {Object} object The destination object.
12846 * @param {...Object} [sources] The source objects.
12847 * @returns {Object} Returns `object`.
12848 * @see _.defaultsDeep
12851 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12852 * // => { 'a': 1, 'b': 2 }
12854 var defaults = baseRest(function(object, sources) {
12855 object = Object(object);
12858 var length = sources.length;
12859 var guard = length > 2 ? sources[2] : undefined;
12861 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
12865 while (++index < length) {
12866 var source = sources[index];
12867 var props = keysIn(source);
12868 var propsIndex = -1;
12869 var propsLength = props.length;
12871 while (++propsIndex < propsLength) {
12872 var key = props[propsIndex];
12873 var value = object[key];
12875 if (value === undefined ||
12876 (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
12877 object[key] = source[key];
12886 * This method is like `_.defaults` except that it recursively assigns
12887 * default properties.
12889 * **Note:** This method mutates `object`.
12895 * @param {Object} object The destination object.
12896 * @param {...Object} [sources] The source objects.
12897 * @returns {Object} Returns `object`.
12901 * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
12902 * // => { 'a': { 'b': 2, 'c': 3 } }
12904 var defaultsDeep = baseRest(function(args) {
12905 args.push(undefined, customDefaultsMerge);
12906 return apply(mergeWith, undefined, args);
12910 * This method is like `_.find` except that it returns the key of the first
12911 * element `predicate` returns truthy for instead of the element itself.
12917 * @param {Object} object The object to inspect.
12918 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12919 * @returns {string|undefined} Returns the key of the matched element,
12920 * else `undefined`.
12924 * 'barney': { 'age': 36, 'active': true },
12925 * 'fred': { 'age': 40, 'active': false },
12926 * 'pebbles': { 'age': 1, 'active': true }
12929 * _.findKey(users, function(o) { return o.age < 40; });
12930 * // => 'barney' (iteration order is not guaranteed)
12932 * // The `_.matches` iteratee shorthand.
12933 * _.findKey(users, { 'age': 1, 'active': true });
12936 * // The `_.matchesProperty` iteratee shorthand.
12937 * _.findKey(users, ['active', false]);
12940 * // The `_.property` iteratee shorthand.
12941 * _.findKey(users, 'active');
12944 function findKey(object, predicate) {
12945 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
12949 * This method is like `_.findKey` except that it iterates over elements of
12950 * a collection in the opposite order.
12956 * @param {Object} object The object to inspect.
12957 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12958 * @returns {string|undefined} Returns the key of the matched element,
12959 * else `undefined`.
12963 * 'barney': { 'age': 36, 'active': true },
12964 * 'fred': { 'age': 40, 'active': false },
12965 * 'pebbles': { 'age': 1, 'active': true }
12968 * _.findLastKey(users, function(o) { return o.age < 40; });
12969 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
12971 * // The `_.matches` iteratee shorthand.
12972 * _.findLastKey(users, { 'age': 36, 'active': true });
12975 * // The `_.matchesProperty` iteratee shorthand.
12976 * _.findLastKey(users, ['active', false]);
12979 * // The `_.property` iteratee shorthand.
12980 * _.findLastKey(users, 'active');
12983 function findLastKey(object, predicate) {
12984 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
12988 * Iterates over own and inherited enumerable string keyed properties of an
12989 * object and invokes `iteratee` for each property. The iteratee is invoked
12990 * with three arguments: (value, key, object). Iteratee functions may exit
12991 * iteration early by explicitly returning `false`.
12997 * @param {Object} object The object to iterate over.
12998 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12999 * @returns {Object} Returns `object`.
13000 * @see _.forInRight
13008 * Foo.prototype.c = 3;
13010 * _.forIn(new Foo, function(value, key) {
13011 * console.log(key);
13013 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
13015 function forIn(object, iteratee) {
13016 return object == null
13018 : baseFor(object, getIteratee(iteratee, 3), keysIn);
13022 * This method is like `_.forIn` except that it iterates over properties of
13023 * `object` in the opposite order.
13029 * @param {Object} object The object to iterate over.
13030 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13031 * @returns {Object} Returns `object`.
13040 * Foo.prototype.c = 3;
13042 * _.forInRight(new Foo, function(value, key) {
13043 * console.log(key);
13045 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
13047 function forInRight(object, iteratee) {
13048 return object == null
13050 : baseForRight(object, getIteratee(iteratee, 3), keysIn);
13054 * Iterates over own enumerable string keyed properties of an object and
13055 * invokes `iteratee` for each property. The iteratee is invoked with three
13056 * arguments: (value, key, object). Iteratee functions may exit iteration
13057 * early by explicitly returning `false`.
13063 * @param {Object} object The object to iterate over.
13064 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13065 * @returns {Object} Returns `object`.
13066 * @see _.forOwnRight
13074 * Foo.prototype.c = 3;
13076 * _.forOwn(new Foo, function(value, key) {
13077 * console.log(key);
13079 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
13081 function forOwn(object, iteratee) {
13082 return object && baseForOwn(object, getIteratee(iteratee, 3));
13086 * This method is like `_.forOwn` except that it iterates over properties of
13087 * `object` in the opposite order.
13093 * @param {Object} object The object to iterate over.
13094 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13095 * @returns {Object} Returns `object`.
13104 * Foo.prototype.c = 3;
13106 * _.forOwnRight(new Foo, function(value, key) {
13107 * console.log(key);
13109 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
13111 function forOwnRight(object, iteratee) {
13112 return object && baseForOwnRight(object, getIteratee(iteratee, 3));
13116 * Creates an array of function property names from own enumerable properties
13123 * @param {Object} object The object to inspect.
13124 * @returns {Array} Returns the function names.
13125 * @see _.functionsIn
13129 * this.a = _.constant('a');
13130 * this.b = _.constant('b');
13133 * Foo.prototype.c = _.constant('c');
13135 * _.functions(new Foo);
13138 function functions(object) {
13139 return object == null ? [] : baseFunctions(object, keys(object));
13143 * Creates an array of function property names from own and inherited
13144 * enumerable properties of `object`.
13150 * @param {Object} object The object to inspect.
13151 * @returns {Array} Returns the function names.
13156 * this.a = _.constant('a');
13157 * this.b = _.constant('b');
13160 * Foo.prototype.c = _.constant('c');
13162 * _.functionsIn(new Foo);
13163 * // => ['a', 'b', 'c']
13165 function functionsIn(object) {
13166 return object == null ? [] : baseFunctions(object, keysIn(object));
13170 * Gets the value at `path` of `object`. If the resolved value is
13171 * `undefined`, the `defaultValue` is returned in its place.
13177 * @param {Object} object The object to query.
13178 * @param {Array|string} path The path of the property to get.
13179 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13180 * @returns {*} Returns the resolved value.
13183 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13185 * _.get(object, 'a[0].b.c');
13188 * _.get(object, ['a', '0', 'b', 'c']);
13191 * _.get(object, 'a.b.c', 'default');
13194 function get(object, path, defaultValue) {
13195 var result = object == null ? undefined : baseGet(object, path);
13196 return result === undefined ? defaultValue : result;
13200 * Checks if `path` is a direct property of `object`.
13206 * @param {Object} object The object to query.
13207 * @param {Array|string} path The path to check.
13208 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13211 * var object = { 'a': { 'b': 2 } };
13212 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
13214 * _.has(object, 'a');
13217 * _.has(object, 'a.b');
13220 * _.has(object, ['a', 'b']);
13223 * _.has(other, 'a');
13226 function has(object, path) {
13227 return object != null && hasPath(object, path, baseHas);
13231 * Checks if `path` is a direct or inherited property of `object`.
13237 * @param {Object} object The object to query.
13238 * @param {Array|string} path The path to check.
13239 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13242 * var object = _.create({ 'a': _.create({ 'b': 2 }) });
13244 * _.hasIn(object, 'a');
13247 * _.hasIn(object, 'a.b');
13250 * _.hasIn(object, ['a', 'b']);
13253 * _.hasIn(object, 'b');
13256 function hasIn(object, path) {
13257 return object != null && hasPath(object, path, baseHasIn);
13261 * Creates an object composed of the inverted keys and values of `object`.
13262 * If `object` contains duplicate values, subsequent values overwrite
13263 * property assignments of previous values.
13269 * @param {Object} object The object to invert.
13270 * @returns {Object} Returns the new inverted object.
13273 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13275 * _.invert(object);
13276 * // => { '1': 'c', '2': 'b' }
13278 var invert = createInverter(function(result, value, key) {
13279 if (value != null &&
13280 typeof value.toString != 'function') {
13281 value = nativeObjectToString.call(value);
13284 result[value] = key;
13285 }, constant(identity));
13288 * This method is like `_.invert` except that the inverted object is generated
13289 * from the results of running each element of `object` thru `iteratee`. The
13290 * corresponding inverted value of each inverted key is an array of keys
13291 * responsible for generating the inverted value. The iteratee is invoked
13292 * with one argument: (value).
13298 * @param {Object} object The object to invert.
13299 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
13300 * @returns {Object} Returns the new inverted object.
13303 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13305 * _.invertBy(object);
13306 * // => { '1': ['a', 'c'], '2': ['b'] }
13308 * _.invertBy(object, function(value) {
13309 * return 'group' + value;
13311 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
13313 var invertBy = createInverter(function(result, value, key) {
13314 if (value != null &&
13315 typeof value.toString != 'function') {
13316 value = nativeObjectToString.call(value);
13319 if (hasOwnProperty.call(result, value)) {
13320 result[value].push(key);
13322 result[value] = [key];
13327 * Invokes the method at `path` of `object`.
13333 * @param {Object} object The object to query.
13334 * @param {Array|string} path The path of the method to invoke.
13335 * @param {...*} [args] The arguments to invoke the method with.
13336 * @returns {*} Returns the result of the invoked method.
13339 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
13341 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
13344 var invoke = baseRest(baseInvoke);
13347 * Creates an array of the own enumerable property names of `object`.
13349 * **Note:** Non-object values are coerced to objects. See the
13350 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
13351 * for more details.
13357 * @param {Object} object The object to query.
13358 * @returns {Array} Returns the array of property names.
13366 * Foo.prototype.c = 3;
13369 * // => ['a', 'b'] (iteration order is not guaranteed)
13374 function keys(object) {
13375 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
13379 * Creates an array of the own and inherited enumerable property names of `object`.
13381 * **Note:** Non-object values are coerced to objects.
13387 * @param {Object} object The object to query.
13388 * @returns {Array} Returns the array of property names.
13396 * Foo.prototype.c = 3;
13398 * _.keysIn(new Foo);
13399 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
13401 function keysIn(object) {
13402 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
13406 * The opposite of `_.mapValues`; this method creates an object with the
13407 * same values as `object` and keys generated by running each own enumerable
13408 * string keyed property of `object` thru `iteratee`. The iteratee is invoked
13409 * with three arguments: (value, key, object).
13415 * @param {Object} object The object to iterate over.
13416 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13417 * @returns {Object} Returns the new mapped object.
13421 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
13422 * return key + value;
13424 * // => { 'a1': 1, 'b2': 2 }
13426 function mapKeys(object, iteratee) {
13428 iteratee = getIteratee(iteratee, 3);
13430 baseForOwn(object, function(value, key, object) {
13431 baseAssignValue(result, iteratee(value, key, object), value);
13437 * Creates an object with the same keys as `object` and values generated
13438 * by running each own enumerable string keyed property of `object` thru
13439 * `iteratee`. The iteratee is invoked with three arguments:
13440 * (value, key, object).
13446 * @param {Object} object The object to iterate over.
13447 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13448 * @returns {Object} Returns the new mapped object.
13453 * 'fred': { 'user': 'fred', 'age': 40 },
13454 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
13457 * _.mapValues(users, function(o) { return o.age; });
13458 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13460 * // The `_.property` iteratee shorthand.
13461 * _.mapValues(users, 'age');
13462 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13464 function mapValues(object, iteratee) {
13466 iteratee = getIteratee(iteratee, 3);
13468 baseForOwn(object, function(value, key, object) {
13469 baseAssignValue(result, key, iteratee(value, key, object));
13475 * This method is like `_.assign` except that it recursively merges own and
13476 * inherited enumerable string keyed properties of source objects into the
13477 * destination object. Source properties that resolve to `undefined` are
13478 * skipped if a destination value exists. Array and plain object properties
13479 * are merged recursively. Other objects and value types are overridden by
13480 * assignment. Source objects are applied from left to right. Subsequent
13481 * sources overwrite property assignments of previous sources.
13483 * **Note:** This method mutates `object`.
13489 * @param {Object} object The destination object.
13490 * @param {...Object} [sources] The source objects.
13491 * @returns {Object} Returns `object`.
13495 * 'a': [{ 'b': 2 }, { 'd': 4 }]
13499 * 'a': [{ 'c': 3 }, { 'e': 5 }]
13502 * _.merge(object, other);
13503 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
13505 var merge = createAssigner(function(object, source, srcIndex) {
13506 baseMerge(object, source, srcIndex);
13510 * This method is like `_.merge` except that it accepts `customizer` which
13511 * is invoked to produce the merged values of the destination and source
13512 * properties. If `customizer` returns `undefined`, merging is handled by the
13513 * method instead. The `customizer` is invoked with six arguments:
13514 * (objValue, srcValue, key, object, source, stack).
13516 * **Note:** This method mutates `object`.
13522 * @param {Object} object The destination object.
13523 * @param {...Object} sources The source objects.
13524 * @param {Function} customizer The function to customize assigned values.
13525 * @returns {Object} Returns `object`.
13528 * function customizer(objValue, srcValue) {
13529 * if (_.isArray(objValue)) {
13530 * return objValue.concat(srcValue);
13534 * var object = { 'a': [1], 'b': [2] };
13535 * var other = { 'a': [3], 'b': [4] };
13537 * _.mergeWith(object, other, customizer);
13538 * // => { 'a': [1, 3], 'b': [2, 4] }
13540 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
13541 baseMerge(object, source, srcIndex, customizer);
13545 * The opposite of `_.pick`; this method creates an object composed of the
13546 * own and inherited enumerable property paths of `object` that are not omitted.
13548 * **Note:** This method is considerably slower than `_.pick`.
13554 * @param {Object} object The source object.
13555 * @param {...(string|string[])} [paths] The property paths to omit.
13556 * @returns {Object} Returns the new object.
13559 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13561 * _.omit(object, ['a', 'c']);
13562 * // => { 'b': '2' }
13564 var omit = flatRest(function(object, paths) {
13566 if (object == null) {
13569 var isDeep = false;
13570 paths = arrayMap(paths, function(path) {
13571 path = castPath(path, object);
13572 isDeep || (isDeep = path.length > 1);
13575 copyObject(object, getAllKeysIn(object), result);
13577 result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
13579 var length = paths.length;
13581 baseUnset(result, paths[length]);
13587 * The opposite of `_.pickBy`; this method creates an object composed of
13588 * the own and inherited enumerable string keyed properties of `object` that
13589 * `predicate` doesn't return truthy for. The predicate is invoked with two
13590 * arguments: (value, key).
13596 * @param {Object} object The source object.
13597 * @param {Function} [predicate=_.identity] The function invoked per property.
13598 * @returns {Object} Returns the new object.
13601 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13603 * _.omitBy(object, _.isNumber);
13604 * // => { 'b': '2' }
13606 function omitBy(object, predicate) {
13607 return pickBy(object, negate(getIteratee(predicate)));
13611 * Creates an object composed of the picked `object` properties.
13617 * @param {Object} object The source object.
13618 * @param {...(string|string[])} [paths] The property paths to pick.
13619 * @returns {Object} Returns the new object.
13622 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13624 * _.pick(object, ['a', 'c']);
13625 * // => { 'a': 1, 'c': 3 }
13627 var pick = flatRest(function(object, paths) {
13628 return object == null ? {} : basePick(object, paths);
13632 * Creates an object composed of the `object` properties `predicate` returns
13633 * truthy for. The predicate is invoked with two arguments: (value, key).
13639 * @param {Object} object The source object.
13640 * @param {Function} [predicate=_.identity] The function invoked per property.
13641 * @returns {Object} Returns the new object.
13644 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13646 * _.pickBy(object, _.isNumber);
13647 * // => { 'a': 1, 'c': 3 }
13649 function pickBy(object, predicate) {
13650 if (object == null) {
13653 var props = arrayMap(getAllKeysIn(object), function(prop) {
13656 predicate = getIteratee(predicate);
13657 return basePickBy(object, props, function(value, path) {
13658 return predicate(value, path[0]);
13663 * This method is like `_.get` except that if the resolved value is a
13664 * function it's invoked with the `this` binding of its parent object and
13665 * its result is returned.
13671 * @param {Object} object The object to query.
13672 * @param {Array|string} path The path of the property to resolve.
13673 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13674 * @returns {*} Returns the resolved value.
13677 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
13679 * _.result(object, 'a[0].b.c1');
13682 * _.result(object, 'a[0].b.c2');
13685 * _.result(object, 'a[0].b.c3', 'default');
13688 * _.result(object, 'a[0].b.c3', _.constant('default'));
13691 function result(object, path, defaultValue) {
13692 path = castPath(path, object);
13695 length = path.length;
13697 // Ensure the loop is entered when path is empty.
13700 object = undefined;
13702 while (++index < length) {
13703 var value = object == null ? undefined : object[toKey(path[index])];
13704 if (value === undefined) {
13706 value = defaultValue;
13708 object = isFunction(value) ? value.call(object) : value;
13714 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
13715 * it's created. Arrays are created for missing index properties while objects
13716 * are created for all other missing properties. Use `_.setWith` to customize
13719 * **Note:** This method mutates `object`.
13725 * @param {Object} object The object to modify.
13726 * @param {Array|string} path The path of the property to set.
13727 * @param {*} value The value to set.
13728 * @returns {Object} Returns `object`.
13731 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13733 * _.set(object, 'a[0].b.c', 4);
13734 * console.log(object.a[0].b.c);
13737 * _.set(object, ['x', '0', 'y', 'z'], 5);
13738 * console.log(object.x[0].y.z);
13741 function set(object, path, value) {
13742 return object == null ? object : baseSet(object, path, value);
13746 * This method is like `_.set` except that it accepts `customizer` which is
13747 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13748 * path creation is handled by the method instead. The `customizer` is invoked
13749 * with three arguments: (nsValue, key, nsObject).
13751 * **Note:** This method mutates `object`.
13757 * @param {Object} object The object to modify.
13758 * @param {Array|string} path The path of the property to set.
13759 * @param {*} value The value to set.
13760 * @param {Function} [customizer] The function to customize assigned values.
13761 * @returns {Object} Returns `object`.
13766 * _.setWith(object, '[0][1]', 'a', Object);
13767 * // => { '0': { '1': 'a' } }
13769 function setWith(object, path, value, customizer) {
13770 customizer = typeof customizer == 'function' ? customizer : undefined;
13771 return object == null ? object : baseSet(object, path, value, customizer);
13775 * Creates an array of own enumerable string keyed-value pairs for `object`
13776 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
13777 * entries are returned.
13784 * @param {Object} object The object to query.
13785 * @returns {Array} Returns the key-value pairs.
13793 * Foo.prototype.c = 3;
13795 * _.toPairs(new Foo);
13796 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
13798 var toPairs = createToPairs(keys);
13801 * Creates an array of own and inherited enumerable string keyed-value pairs
13802 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
13803 * or set, its entries are returned.
13810 * @param {Object} object The object to query.
13811 * @returns {Array} Returns the key-value pairs.
13819 * Foo.prototype.c = 3;
13821 * _.toPairsIn(new Foo);
13822 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
13824 var toPairsIn = createToPairs(keysIn);
13827 * An alternative to `_.reduce`; this method transforms `object` to a new
13828 * `accumulator` object which is the result of running each of its own
13829 * enumerable string keyed properties thru `iteratee`, with each invocation
13830 * potentially mutating the `accumulator` object. If `accumulator` is not
13831 * provided, a new object with the same `[[Prototype]]` will be used. The
13832 * iteratee is invoked with four arguments: (accumulator, value, key, object).
13833 * Iteratee functions may exit iteration early by explicitly returning `false`.
13839 * @param {Object} object The object to iterate over.
13840 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13841 * @param {*} [accumulator] The custom accumulator value.
13842 * @returns {*} Returns the accumulated value.
13845 * _.transform([2, 3, 4], function(result, n) {
13846 * result.push(n *= n);
13847 * return n % 2 == 0;
13851 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
13852 * (result[value] || (result[value] = [])).push(key);
13854 * // => { '1': ['a', 'c'], '2': ['b'] }
13856 function transform(object, iteratee, accumulator) {
13857 var isArr = isArray(object),
13858 isArrLike = isArr || isBuffer(object) || isTypedArray(object);
13860 iteratee = getIteratee(iteratee, 4);
13861 if (accumulator == null) {
13862 var Ctor = object && object.constructor;
13864 accumulator = isArr ? new Ctor : [];
13866 else if (isObject(object)) {
13867 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
13873 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
13874 return iteratee(accumulator, value, index, object);
13876 return accumulator;
13880 * Removes the property at `path` of `object`.
13882 * **Note:** This method mutates `object`.
13888 * @param {Object} object The object to modify.
13889 * @param {Array|string} path The path of the property to unset.
13890 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
13893 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
13894 * _.unset(object, 'a[0].b.c');
13897 * console.log(object);
13898 * // => { 'a': [{ 'b': {} }] };
13900 * _.unset(object, ['a', '0', 'b', 'c']);
13903 * console.log(object);
13904 * // => { 'a': [{ 'b': {} }] };
13906 function unset(object, path) {
13907 return object == null ? true : baseUnset(object, path);
13911 * This method is like `_.set` except that accepts `updater` to produce the
13912 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
13913 * is invoked with one argument: (value).
13915 * **Note:** This method mutates `object`.
13921 * @param {Object} object The object to modify.
13922 * @param {Array|string} path The path of the property to set.
13923 * @param {Function} updater The function to produce the updated value.
13924 * @returns {Object} Returns `object`.
13927 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13929 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
13930 * console.log(object.a[0].b.c);
13933 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
13934 * console.log(object.x[0].y.z);
13937 function update(object, path, updater) {
13938 return object == null ? object : baseUpdate(object, path, castFunction(updater));
13942 * This method is like `_.update` except that it accepts `customizer` which is
13943 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13944 * path creation is handled by the method instead. The `customizer` is invoked
13945 * with three arguments: (nsValue, key, nsObject).
13947 * **Note:** This method mutates `object`.
13953 * @param {Object} object The object to modify.
13954 * @param {Array|string} path The path of the property to set.
13955 * @param {Function} updater The function to produce the updated value.
13956 * @param {Function} [customizer] The function to customize assigned values.
13957 * @returns {Object} Returns `object`.
13962 * _.updateWith(object, '[0][1]', _.constant('a'), Object);
13963 * // => { '0': { '1': 'a' } }
13965 function updateWith(object, path, updater, customizer) {
13966 customizer = typeof customizer == 'function' ? customizer : undefined;
13967 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
13971 * Creates an array of the own enumerable string keyed property values of `object`.
13973 * **Note:** Non-object values are coerced to objects.
13979 * @param {Object} object The object to query.
13980 * @returns {Array} Returns the array of property values.
13988 * Foo.prototype.c = 3;
13990 * _.values(new Foo);
13991 * // => [1, 2] (iteration order is not guaranteed)
13996 function values(object) {
13997 return object == null ? [] : baseValues(object, keys(object));
14001 * Creates an array of the own and inherited enumerable string keyed property
14002 * values of `object`.
14004 * **Note:** Non-object values are coerced to objects.
14010 * @param {Object} object The object to query.
14011 * @returns {Array} Returns the array of property values.
14019 * Foo.prototype.c = 3;
14021 * _.valuesIn(new Foo);
14022 * // => [1, 2, 3] (iteration order is not guaranteed)
14024 function valuesIn(object) {
14025 return object == null ? [] : baseValues(object, keysIn(object));
14028 /*------------------------------------------------------------------------*/
14031 * Clamps `number` within the inclusive `lower` and `upper` bounds.
14037 * @param {number} number The number to clamp.
14038 * @param {number} [lower] The lower bound.
14039 * @param {number} upper The upper bound.
14040 * @returns {number} Returns the clamped number.
14043 * _.clamp(-10, -5, 5);
14046 * _.clamp(10, -5, 5);
14049 function clamp(number, lower, upper) {
14050 if (upper === undefined) {
14054 if (upper !== undefined) {
14055 upper = toNumber(upper);
14056 upper = upper === upper ? upper : 0;
14058 if (lower !== undefined) {
14059 lower = toNumber(lower);
14060 lower = lower === lower ? lower : 0;
14062 return baseClamp(toNumber(number), lower, upper);
14066 * Checks if `n` is between `start` and up to, but not including, `end`. If
14067 * `end` is not specified, it's set to `start` with `start` then set to `0`.
14068 * If `start` is greater than `end` the params are swapped to support
14075 * @param {number} number The number to check.
14076 * @param {number} [start=0] The start of the range.
14077 * @param {number} end The end of the range.
14078 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
14079 * @see _.range, _.rangeRight
14082 * _.inRange(3, 2, 4);
14094 * _.inRange(1.2, 2);
14097 * _.inRange(5.2, 4);
14100 * _.inRange(-3, -2, -6);
14103 function inRange(number, start, end) {
14104 start = toFinite(start);
14105 if (end === undefined) {
14109 end = toFinite(end);
14111 number = toNumber(number);
14112 return baseInRange(number, start, end);
14116 * Produces a random number between the inclusive `lower` and `upper` bounds.
14117 * If only one argument is provided a number between `0` and the given number
14118 * is returned. If `floating` is `true`, or either `lower` or `upper` are
14119 * floats, a floating-point number is returned instead of an integer.
14121 * **Note:** JavaScript follows the IEEE-754 standard for resolving
14122 * floating-point values which can produce unexpected results.
14128 * @param {number} [lower=0] The lower bound.
14129 * @param {number} [upper=1] The upper bound.
14130 * @param {boolean} [floating] Specify returning a floating-point number.
14131 * @returns {number} Returns the random number.
14135 * // => an integer between 0 and 5
14138 * // => also an integer between 0 and 5
14140 * _.random(5, true);
14141 * // => a floating-point number between 0 and 5
14143 * _.random(1.2, 5.2);
14144 * // => a floating-point number between 1.2 and 5.2
14146 function random(lower, upper, floating) {
14147 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
14148 upper = floating = undefined;
14150 if (floating === undefined) {
14151 if (typeof upper == 'boolean') {
14155 else if (typeof lower == 'boolean') {
14160 if (lower === undefined && upper === undefined) {
14165 lower = toFinite(lower);
14166 if (upper === undefined) {
14170 upper = toFinite(upper);
14173 if (lower > upper) {
14178 if (floating || lower % 1 || upper % 1) {
14179 var rand = nativeRandom();
14180 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
14182 return baseRandom(lower, upper);
14185 /*------------------------------------------------------------------------*/
14188 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
14194 * @param {string} [string=''] The string to convert.
14195 * @returns {string} Returns the camel cased string.
14198 * _.camelCase('Foo Bar');
14201 * _.camelCase('--foo-bar--');
14204 * _.camelCase('__FOO_BAR__');
14207 var camelCase = createCompounder(function(result, word, index) {
14208 word = word.toLowerCase();
14209 return result + (index ? capitalize(word) : word);
14213 * Converts the first character of `string` to upper case and the remaining
14220 * @param {string} [string=''] The string to capitalize.
14221 * @returns {string} Returns the capitalized string.
14224 * _.capitalize('FRED');
14227 function capitalize(string) {
14228 return upperFirst(toString(string).toLowerCase());
14232 * Deburrs `string` by converting
14233 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
14234 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
14235 * letters to basic Latin letters and removing
14236 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
14242 * @param {string} [string=''] The string to deburr.
14243 * @returns {string} Returns the deburred string.
14246 * _.deburr('déjà vu');
14249 function deburr(string) {
14250 string = toString(string);
14251 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
14255 * Checks if `string` ends with the given target string.
14261 * @param {string} [string=''] The string to inspect.
14262 * @param {string} [target] The string to search for.
14263 * @param {number} [position=string.length] The position to search up to.
14264 * @returns {boolean} Returns `true` if `string` ends with `target`,
14268 * _.endsWith('abc', 'c');
14271 * _.endsWith('abc', 'b');
14274 * _.endsWith('abc', 'b', 2);
14277 function endsWith(string, target, position) {
14278 string = toString(string);
14279 target = baseToString(target);
14281 var length = string.length;
14282 position = position === undefined
14284 : baseClamp(toInteger(position), 0, length);
14286 var end = position;
14287 position -= target.length;
14288 return position >= 0 && string.slice(position, end) == target;
14292 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
14293 * corresponding HTML entities.
14295 * **Note:** No other characters are escaped. To escape additional
14296 * characters use a third-party library like [_he_](https://mths.be/he).
14298 * Though the ">" character is escaped for symmetry, characters like
14299 * ">" and "/" don't need escaping in HTML and have no special meaning
14300 * unless they're part of a tag or unquoted attribute value. See
14301 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
14302 * (under "semi-related fun fact") for more details.
14304 * When working with HTML you should always
14305 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
14312 * @param {string} [string=''] The string to escape.
14313 * @returns {string} Returns the escaped string.
14316 * _.escape('fred, barney, & pebbles');
14317 * // => 'fred, barney, & pebbles'
14319 function escape(string) {
14320 string = toString(string);
14321 return (string && reHasUnescapedHtml.test(string))
14322 ? string.replace(reUnescapedHtml, escapeHtmlChar)
14327 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
14328 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
14334 * @param {string} [string=''] The string to escape.
14335 * @returns {string} Returns the escaped string.
14338 * _.escapeRegExp('[lodash](https://lodash.com/)');
14339 * // => '\[lodash\]\(https://lodash\.com/\)'
14341 function escapeRegExp(string) {
14342 string = toString(string);
14343 return (string && reHasRegExpChar.test(string))
14344 ? string.replace(reRegExpChar, '\\$&')
14349 * Converts `string` to
14350 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
14356 * @param {string} [string=''] The string to convert.
14357 * @returns {string} Returns the kebab cased string.
14360 * _.kebabCase('Foo Bar');
14363 * _.kebabCase('fooBar');
14366 * _.kebabCase('__FOO_BAR__');
14369 var kebabCase = createCompounder(function(result, word, index) {
14370 return result + (index ? '-' : '') + word.toLowerCase();
14374 * Converts `string`, as space separated words, to lower case.
14380 * @param {string} [string=''] The string to convert.
14381 * @returns {string} Returns the lower cased string.
14384 * _.lowerCase('--Foo-Bar--');
14387 * _.lowerCase('fooBar');
14390 * _.lowerCase('__FOO_BAR__');
14393 var lowerCase = createCompounder(function(result, word, index) {
14394 return result + (index ? ' ' : '') + word.toLowerCase();
14398 * Converts the first character of `string` to lower case.
14404 * @param {string} [string=''] The string to convert.
14405 * @returns {string} Returns the converted string.
14408 * _.lowerFirst('Fred');
14411 * _.lowerFirst('FRED');
14414 var lowerFirst = createCaseFirst('toLowerCase');
14417 * Pads `string` on the left and right sides if it's shorter than `length`.
14418 * Padding characters are truncated if they can't be evenly divided by `length`.
14424 * @param {string} [string=''] The string to pad.
14425 * @param {number} [length=0] The padding length.
14426 * @param {string} [chars=' '] The string used as padding.
14427 * @returns {string} Returns the padded string.
14433 * _.pad('abc', 8, '_-');
14439 function pad(string, length, chars) {
14440 string = toString(string);
14441 length = toInteger(length);
14443 var strLength = length ? stringSize(string) : 0;
14444 if (!length || strLength >= length) {
14447 var mid = (length - strLength) / 2;
14449 createPadding(nativeFloor(mid), chars) +
14451 createPadding(nativeCeil(mid), chars)
14456 * Pads `string` on the right side if it's shorter than `length`. Padding
14457 * characters are truncated if they exceed `length`.
14463 * @param {string} [string=''] The string to pad.
14464 * @param {number} [length=0] The padding length.
14465 * @param {string} [chars=' '] The string used as padding.
14466 * @returns {string} Returns the padded string.
14469 * _.padEnd('abc', 6);
14472 * _.padEnd('abc', 6, '_-');
14475 * _.padEnd('abc', 3);
14478 function padEnd(string, length, chars) {
14479 string = toString(string);
14480 length = toInteger(length);
14482 var strLength = length ? stringSize(string) : 0;
14483 return (length && strLength < length)
14484 ? (string + createPadding(length - strLength, chars))
14489 * Pads `string` on the left side if it's shorter than `length`. Padding
14490 * characters are truncated if they exceed `length`.
14496 * @param {string} [string=''] The string to pad.
14497 * @param {number} [length=0] The padding length.
14498 * @param {string} [chars=' '] The string used as padding.
14499 * @returns {string} Returns the padded string.
14502 * _.padStart('abc', 6);
14505 * _.padStart('abc', 6, '_-');
14508 * _.padStart('abc', 3);
14511 function padStart(string, length, chars) {
14512 string = toString(string);
14513 length = toInteger(length);
14515 var strLength = length ? stringSize(string) : 0;
14516 return (length && strLength < length)
14517 ? (createPadding(length - strLength, chars) + string)
14522 * Converts `string` to an integer of the specified radix. If `radix` is
14523 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
14524 * hexadecimal, in which case a `radix` of `16` is used.
14526 * **Note:** This method aligns with the
14527 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
14533 * @param {string} string The string to convert.
14534 * @param {number} [radix=10] The radix to interpret `value` by.
14535 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14536 * @returns {number} Returns the converted integer.
14539 * _.parseInt('08');
14542 * _.map(['6', '08', '10'], _.parseInt);
14545 function parseInt(string, radix, guard) {
14546 if (guard || radix == null) {
14548 } else if (radix) {
14551 return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
14555 * Repeats the given string `n` times.
14561 * @param {string} [string=''] The string to repeat.
14562 * @param {number} [n=1] The number of times to repeat the string.
14563 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14564 * @returns {string} Returns the repeated string.
14567 * _.repeat('*', 3);
14570 * _.repeat('abc', 2);
14573 * _.repeat('abc', 0);
14576 function repeat(string, n, guard) {
14577 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
14582 return baseRepeat(toString(string), n);
14586 * Replaces matches for `pattern` in `string` with `replacement`.
14588 * **Note:** This method is based on
14589 * [`String#replace`](https://mdn.io/String/replace).
14595 * @param {string} [string=''] The string to modify.
14596 * @param {RegExp|string} pattern The pattern to replace.
14597 * @param {Function|string} replacement The match replacement.
14598 * @returns {string} Returns the modified string.
14601 * _.replace('Hi Fred', 'Fred', 'Barney');
14602 * // => 'Hi Barney'
14604 function replace() {
14605 var args = arguments,
14606 string = toString(args[0]);
14608 return args.length < 3 ? string : string.replace(args[1], args[2]);
14612 * Converts `string` to
14613 * [snake case](https://en.wikipedia.org/wiki/Snake_case).
14619 * @param {string} [string=''] The string to convert.
14620 * @returns {string} Returns the snake cased string.
14623 * _.snakeCase('Foo Bar');
14626 * _.snakeCase('fooBar');
14629 * _.snakeCase('--FOO-BAR--');
14632 var snakeCase = createCompounder(function(result, word, index) {
14633 return result + (index ? '_' : '') + word.toLowerCase();
14637 * Splits `string` by `separator`.
14639 * **Note:** This method is based on
14640 * [`String#split`](https://mdn.io/String/split).
14646 * @param {string} [string=''] The string to split.
14647 * @param {RegExp|string} separator The separator pattern to split by.
14648 * @param {number} [limit] The length to truncate results to.
14649 * @returns {Array} Returns the string segments.
14652 * _.split('a-b-c', '-', 2);
14655 function split(string, separator, limit) {
14656 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
14657 separator = limit = undefined;
14659 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
14663 string = toString(string);
14665 typeof separator == 'string' ||
14666 (separator != null && !isRegExp(separator))
14668 separator = baseToString(separator);
14669 if (!separator && hasUnicode(string)) {
14670 return castSlice(stringToArray(string), 0, limit);
14673 return string.split(separator, limit);
14677 * Converts `string` to
14678 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
14684 * @param {string} [string=''] The string to convert.
14685 * @returns {string} Returns the start cased string.
14688 * _.startCase('--foo-bar--');
14691 * _.startCase('fooBar');
14694 * _.startCase('__FOO_BAR__');
14697 var startCase = createCompounder(function(result, word, index) {
14698 return result + (index ? ' ' : '') + upperFirst(word);
14702 * Checks if `string` starts with the given target string.
14708 * @param {string} [string=''] The string to inspect.
14709 * @param {string} [target] The string to search for.
14710 * @param {number} [position=0] The position to search from.
14711 * @returns {boolean} Returns `true` if `string` starts with `target`,
14715 * _.startsWith('abc', 'a');
14718 * _.startsWith('abc', 'b');
14721 * _.startsWith('abc', 'b', 1);
14724 function startsWith(string, target, position) {
14725 string = toString(string);
14726 position = position == null
14728 : baseClamp(toInteger(position), 0, string.length);
14730 target = baseToString(target);
14731 return string.slice(position, position + target.length) == target;
14735 * Creates a compiled template function that can interpolate data properties
14736 * in "interpolate" delimiters, HTML-escape interpolated data properties in
14737 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
14738 * properties may be accessed as free variables in the template. If a setting
14739 * object is given, it takes precedence over `_.templateSettings` values.
14741 * **Note:** In the development build `_.template` utilizes
14742 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
14743 * for easier debugging.
14745 * For more information on precompiling templates see
14746 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
14748 * For more information on Chrome extension sandboxes see
14749 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
14755 * @param {string} [string=''] The template string.
14756 * @param {Object} [options={}] The options object.
14757 * @param {RegExp} [options.escape=_.templateSettings.escape]
14758 * The HTML "escape" delimiter.
14759 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
14760 * The "evaluate" delimiter.
14761 * @param {Object} [options.imports=_.templateSettings.imports]
14762 * An object to import into the template as free variables.
14763 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
14764 * The "interpolate" delimiter.
14765 * @param {string} [options.sourceURL='lodash.templateSources[n]']
14766 * The sourceURL of the compiled template.
14767 * @param {string} [options.variable='obj']
14768 * The data object variable name.
14769 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14770 * @returns {Function} Returns the compiled template function.
14773 * // Use the "interpolate" delimiter to create a compiled template.
14774 * var compiled = _.template('hello <%= user %>!');
14775 * compiled({ 'user': 'fred' });
14776 * // => 'hello fred!'
14778 * // Use the HTML "escape" delimiter to escape data property values.
14779 * var compiled = _.template('<b><%- value %></b>');
14780 * compiled({ 'value': '<script>' });
14781 * // => '<b><script></b>'
14783 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
14784 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
14785 * compiled({ 'users': ['fred', 'barney'] });
14786 * // => '<li>fred</li><li>barney</li>'
14788 * // Use the internal `print` function in "evaluate" delimiters.
14789 * var compiled = _.template('<% print("hello " + user); %>!');
14790 * compiled({ 'user': 'barney' });
14791 * // => 'hello barney!'
14793 * // Use the ES template literal delimiter as an "interpolate" delimiter.
14794 * // Disable support by replacing the "interpolate" delimiter.
14795 * var compiled = _.template('hello ${ user }!');
14796 * compiled({ 'user': 'pebbles' });
14797 * // => 'hello pebbles!'
14799 * // Use backslashes to treat delimiters as plain text.
14800 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
14801 * compiled({ 'value': 'ignored' });
14802 * // => '<%- value %>'
14804 * // Use the `imports` option to import `jQuery` as `jq`.
14805 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
14806 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
14807 * compiled({ 'users': ['fred', 'barney'] });
14808 * // => '<li>fred</li><li>barney</li>'
14810 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
14811 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
14813 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
14815 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
14816 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
14818 * // => function(data) {
14819 * // var __t, __p = '';
14820 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
14824 * // Use custom template delimiters.
14825 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
14826 * var compiled = _.template('hello {{ user }}!');
14827 * compiled({ 'user': 'mustache' });
14828 * // => 'hello mustache!'
14830 * // Use the `source` property to inline compiled templates for meaningful
14831 * // line numbers in error messages and stack traces.
14832 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
14834 * "main": ' + _.template(mainText).source + '\
14838 function template(string, options, guard) {
14839 // Based on John Resig's `tmpl` implementation
14840 // (http://ejohn.org/blog/javascript-micro-templating/)
14841 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
14842 var settings = lodash.templateSettings;
14844 if (guard && isIterateeCall(string, options, guard)) {
14845 options = undefined;
14847 string = toString(string);
14848 options = assignInWith({}, options, settings, customDefaultsAssignIn);
14850 var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
14851 importsKeys = keys(imports),
14852 importsValues = baseValues(imports, importsKeys);
14857 interpolate = options.interpolate || reNoMatch,
14858 source = "__p += '";
14860 // Compile the regexp to match each delimiter.
14861 var reDelimiters = RegExp(
14862 (options.escape || reNoMatch).source + '|' +
14863 interpolate.source + '|' +
14864 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
14865 (options.evaluate || reNoMatch).source + '|$'
14868 // Use a sourceURL for easier debugging.
14869 // The sourceURL gets injected into the source that's eval-ed, so be careful
14870 // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
14871 // and escape the comment, thus injecting code that gets evaled.
14872 var sourceURL = '//# sourceURL=' +
14873 (hasOwnProperty.call(options, 'sourceURL')
14874 ? (options.sourceURL + '').replace(/\s/g, ' ')
14875 : ('lodash.templateSources[' + (++templateCounter) + ']')
14878 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
14879 interpolateValue || (interpolateValue = esTemplateValue);
14881 // Escape characters that can't be included in string literals.
14882 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
14884 // Replace delimiters with snippets.
14887 source += "' +\n__e(" + escapeValue + ") +\n'";
14889 if (evaluateValue) {
14890 isEvaluating = true;
14891 source += "';\n" + evaluateValue + ";\n__p += '";
14893 if (interpolateValue) {
14894 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
14896 index = offset + match.length;
14898 // The JS engine embedded in Adobe products needs `match` returned in
14899 // order to produce the correct `offset` value.
14905 // If `variable` is not specified wrap a with-statement around the generated
14906 // code to add the data object to the top of the scope chain.
14907 var variable = hasOwnProperty.call(options, 'variable') && options.variable;
14909 source = 'with (obj) {\n' + source + '\n}\n';
14911 // Throw an error if a forbidden character was found in `variable`, to prevent
14912 // potential command injection attacks.
14913 else if (reForbiddenIdentifierChars.test(variable)) {
14914 throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
14917 // Cleanup code by stripping empty strings.
14918 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
14919 .replace(reEmptyStringMiddle, '$1')
14920 .replace(reEmptyStringTrailing, '$1;');
14922 // Frame code as the function body.
14923 source = 'function(' + (variable || 'obj') + ') {\n' +
14926 : 'obj || (obj = {});\n'
14928 "var __t, __p = ''" +
14930 ? ', __e = _.escape'
14934 ? ', __j = Array.prototype.join;\n' +
14935 "function print() { __p += __j.call(arguments, '') }\n"
14941 var result = attempt(function() {
14942 return Function(importsKeys, sourceURL + 'return ' + source)
14943 .apply(undefined, importsValues);
14946 // Provide the compiled function's source by its `toString` method or
14947 // the `source` property as a convenience for inlining compiled templates.
14948 result.source = source;
14949 if (isError(result)) {
14956 * Converts `string`, as a whole, to lower case just like
14957 * [String#toLowerCase](https://mdn.io/toLowerCase).
14963 * @param {string} [string=''] The string to convert.
14964 * @returns {string} Returns the lower cased string.
14967 * _.toLower('--Foo-Bar--');
14968 * // => '--foo-bar--'
14970 * _.toLower('fooBar');
14973 * _.toLower('__FOO_BAR__');
14974 * // => '__foo_bar__'
14976 function toLower(value) {
14977 return toString(value).toLowerCase();
14981 * Converts `string`, as a whole, to upper case just like
14982 * [String#toUpperCase](https://mdn.io/toUpperCase).
14988 * @param {string} [string=''] The string to convert.
14989 * @returns {string} Returns the upper cased string.
14992 * _.toUpper('--foo-bar--');
14993 * // => '--FOO-BAR--'
14995 * _.toUpper('fooBar');
14998 * _.toUpper('__foo_bar__');
14999 * // => '__FOO_BAR__'
15001 function toUpper(value) {
15002 return toString(value).toUpperCase();
15006 * Removes leading and trailing whitespace or specified characters from `string`.
15012 * @param {string} [string=''] The string to trim.
15013 * @param {string} [chars=whitespace] The characters to trim.
15014 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15015 * @returns {string} Returns the trimmed string.
15021 * _.trim('-_-abc-_-', '_-');
15024 * _.map([' foo ', ' bar '], _.trim);
15025 * // => ['foo', 'bar']
15027 function trim(string, chars, guard) {
15028 string = toString(string);
15029 if (string && (guard || chars === undefined)) {
15030 return baseTrim(string);
15032 if (!string || !(chars = baseToString(chars))) {
15035 var strSymbols = stringToArray(string),
15036 chrSymbols = stringToArray(chars),
15037 start = charsStartIndex(strSymbols, chrSymbols),
15038 end = charsEndIndex(strSymbols, chrSymbols) + 1;
15040 return castSlice(strSymbols, start, end).join('');
15044 * Removes trailing whitespace or specified characters from `string`.
15050 * @param {string} [string=''] The string to trim.
15051 * @param {string} [chars=whitespace] The characters to trim.
15052 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15053 * @returns {string} Returns the trimmed string.
15056 * _.trimEnd(' abc ');
15059 * _.trimEnd('-_-abc-_-', '_-');
15062 function trimEnd(string, chars, guard) {
15063 string = toString(string);
15064 if (string && (guard || chars === undefined)) {
15065 return string.slice(0, trimmedEndIndex(string) + 1);
15067 if (!string || !(chars = baseToString(chars))) {
15070 var strSymbols = stringToArray(string),
15071 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
15073 return castSlice(strSymbols, 0, end).join('');
15077 * Removes leading whitespace or specified characters from `string`.
15083 * @param {string} [string=''] The string to trim.
15084 * @param {string} [chars=whitespace] The characters to trim.
15085 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15086 * @returns {string} Returns the trimmed string.
15089 * _.trimStart(' abc ');
15092 * _.trimStart('-_-abc-_-', '_-');
15095 function trimStart(string, chars, guard) {
15096 string = toString(string);
15097 if (string && (guard || chars === undefined)) {
15098 return string.replace(reTrimStart, '');
15100 if (!string || !(chars = baseToString(chars))) {
15103 var strSymbols = stringToArray(string),
15104 start = charsStartIndex(strSymbols, stringToArray(chars));
15106 return castSlice(strSymbols, start).join('');
15110 * Truncates `string` if it's longer than the given maximum string length.
15111 * The last characters of the truncated string are replaced with the omission
15112 * string which defaults to "...".
15118 * @param {string} [string=''] The string to truncate.
15119 * @param {Object} [options={}] The options object.
15120 * @param {number} [options.length=30] The maximum string length.
15121 * @param {string} [options.omission='...'] The string to indicate text is omitted.
15122 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
15123 * @returns {string} Returns the truncated string.
15126 * _.truncate('hi-diddly-ho there, neighborino');
15127 * // => 'hi-diddly-ho there, neighbo...'
15129 * _.truncate('hi-diddly-ho there, neighborino', {
15133 * // => 'hi-diddly-ho there,...'
15135 * _.truncate('hi-diddly-ho there, neighborino', {
15137 * 'separator': /,? +/
15139 * // => 'hi-diddly-ho there...'
15141 * _.truncate('hi-diddly-ho there, neighborino', {
15142 * 'omission': ' [...]'
15144 * // => 'hi-diddly-ho there, neig [...]'
15146 function truncate(string, options) {
15147 var length = DEFAULT_TRUNC_LENGTH,
15148 omission = DEFAULT_TRUNC_OMISSION;
15150 if (isObject(options)) {
15151 var separator = 'separator' in options ? options.separator : separator;
15152 length = 'length' in options ? toInteger(options.length) : length;
15153 omission = 'omission' in options ? baseToString(options.omission) : omission;
15155 string = toString(string);
15157 var strLength = string.length;
15158 if (hasUnicode(string)) {
15159 var strSymbols = stringToArray(string);
15160 strLength = strSymbols.length;
15162 if (length >= strLength) {
15165 var end = length - stringSize(omission);
15169 var result = strSymbols
15170 ? castSlice(strSymbols, 0, end).join('')
15171 : string.slice(0, end);
15173 if (separator === undefined) {
15174 return result + omission;
15177 end += (result.length - end);
15179 if (isRegExp(separator)) {
15180 if (string.slice(end).search(separator)) {
15182 substring = result;
15184 if (!separator.global) {
15185 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
15187 separator.lastIndex = 0;
15188 while ((match = separator.exec(substring))) {
15189 var newEnd = match.index;
15191 result = result.slice(0, newEnd === undefined ? end : newEnd);
15193 } else if (string.indexOf(baseToString(separator), end) != end) {
15194 var index = result.lastIndexOf(separator);
15196 result = result.slice(0, index);
15199 return result + omission;
15203 * The inverse of `_.escape`; this method converts the HTML entities
15204 * `&`, `<`, `>`, `"`, and `'` in `string` to
15205 * their corresponding characters.
15207 * **Note:** No other HTML entities are unescaped. To unescape additional
15208 * HTML entities use a third-party library like [_he_](https://mths.be/he).
15214 * @param {string} [string=''] The string to unescape.
15215 * @returns {string} Returns the unescaped string.
15218 * _.unescape('fred, barney, & pebbles');
15219 * // => 'fred, barney, & pebbles'
15221 function unescape(string) {
15222 string = toString(string);
15223 return (string && reHasEscapedHtml.test(string))
15224 ? string.replace(reEscapedHtml, unescapeHtmlChar)
15229 * Converts `string`, as space separated words, to upper case.
15235 * @param {string} [string=''] The string to convert.
15236 * @returns {string} Returns the upper cased string.
15239 * _.upperCase('--foo-bar');
15242 * _.upperCase('fooBar');
15245 * _.upperCase('__foo_bar__');
15248 var upperCase = createCompounder(function(result, word, index) {
15249 return result + (index ? ' ' : '') + word.toUpperCase();
15253 * Converts the first character of `string` to upper case.
15259 * @param {string} [string=''] The string to convert.
15260 * @returns {string} Returns the converted string.
15263 * _.upperFirst('fred');
15266 * _.upperFirst('FRED');
15269 var upperFirst = createCaseFirst('toUpperCase');
15272 * Splits `string` into an array of its words.
15278 * @param {string} [string=''] The string to inspect.
15279 * @param {RegExp|string} [pattern] The pattern to match words.
15280 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15281 * @returns {Array} Returns the words of `string`.
15284 * _.words('fred, barney, & pebbles');
15285 * // => ['fred', 'barney', 'pebbles']
15287 * _.words('fred, barney, & pebbles', /[^, ]+/g);
15288 * // => ['fred', 'barney', '&', 'pebbles']
15290 function words(string, pattern, guard) {
15291 string = toString(string);
15292 pattern = guard ? undefined : pattern;
15294 if (pattern === undefined) {
15295 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
15297 return string.match(pattern) || [];
15300 /*------------------------------------------------------------------------*/
15303 * Attempts to invoke `func`, returning either the result or the caught error
15304 * object. Any additional arguments are provided to `func` when it's invoked.
15310 * @param {Function} func The function to attempt.
15311 * @param {...*} [args] The arguments to invoke `func` with.
15312 * @returns {*} Returns the `func` result or error object.
15315 * // Avoid throwing errors for invalid selectors.
15316 * var elements = _.attempt(function(selector) {
15317 * return document.querySelectorAll(selector);
15320 * if (_.isError(elements)) {
15324 var attempt = baseRest(function(func, args) {
15326 return apply(func, undefined, args);
15328 return isError(e) ? e : new Error(e);
15333 * Binds methods of an object to the object itself, overwriting the existing
15336 * **Note:** This method doesn't set the "length" property of bound functions.
15342 * @param {Object} object The object to bind and assign the bound methods to.
15343 * @param {...(string|string[])} methodNames The object method names to bind.
15344 * @returns {Object} Returns `object`.
15349 * 'click': function() {
15350 * console.log('clicked ' + this.label);
15354 * _.bindAll(view, ['click']);
15355 * jQuery(element).on('click', view.click);
15356 * // => Logs 'clicked docs' when clicked.
15358 var bindAll = flatRest(function(object, methodNames) {
15359 arrayEach(methodNames, function(key) {
15361 baseAssignValue(object, key, bind(object[key], object));
15367 * Creates a function that iterates over `pairs` and invokes the corresponding
15368 * function of the first predicate to return truthy. The predicate-function
15369 * pairs are invoked with the `this` binding and arguments of the created
15376 * @param {Array} pairs The predicate-function pairs.
15377 * @returns {Function} Returns the new composite function.
15380 * var func = _.cond([
15381 * [_.matches({ 'a': 1 }), _.constant('matches A')],
15382 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
15383 * [_.stubTrue, _.constant('no match')]
15386 * func({ 'a': 1, 'b': 2 });
15387 * // => 'matches A'
15389 * func({ 'a': 0, 'b': 1 });
15390 * // => 'matches B'
15392 * func({ 'a': '1', 'b': '2' });
15395 function cond(pairs) {
15396 var length = pairs == null ? 0 : pairs.length,
15397 toIteratee = getIteratee();
15399 pairs = !length ? [] : arrayMap(pairs, function(pair) {
15400 if (typeof pair[1] != 'function') {
15401 throw new TypeError(FUNC_ERROR_TEXT);
15403 return [toIteratee(pair[0]), pair[1]];
15406 return baseRest(function(args) {
15408 while (++index < length) {
15409 var pair = pairs[index];
15410 if (apply(pair[0], this, args)) {
15411 return apply(pair[1], this, args);
15418 * Creates a function that invokes the predicate properties of `source` with
15419 * the corresponding property values of a given object, returning `true` if
15420 * all predicates return truthy, else `false`.
15422 * **Note:** The created function is equivalent to `_.conformsTo` with
15423 * `source` partially applied.
15429 * @param {Object} source The object of property predicates to conform to.
15430 * @returns {Function} Returns the new spec function.
15434 * { 'a': 2, 'b': 1 },
15435 * { 'a': 1, 'b': 2 }
15438 * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
15439 * // => [{ 'a': 1, 'b': 2 }]
15441 function conforms(source) {
15442 return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
15446 * Creates a function that returns `value`.
15452 * @param {*} value The value to return from the new function.
15453 * @returns {Function} Returns the new constant function.
15456 * var objects = _.times(2, _.constant({ 'a': 1 }));
15458 * console.log(objects);
15459 * // => [{ 'a': 1 }, { 'a': 1 }]
15461 * console.log(objects[0] === objects[1]);
15464 function constant(value) {
15465 return function() {
15471 * Checks `value` to determine whether a default value should be returned in
15472 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
15479 * @param {*} value The value to check.
15480 * @param {*} defaultValue The default value.
15481 * @returns {*} Returns the resolved value.
15484 * _.defaultTo(1, 10);
15487 * _.defaultTo(undefined, 10);
15490 function defaultTo(value, defaultValue) {
15491 return (value == null || value !== value) ? defaultValue : value;
15495 * Creates a function that returns the result of invoking the given functions
15496 * with the `this` binding of the created function, where each successive
15497 * invocation is supplied the return value of the previous.
15503 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15504 * @returns {Function} Returns the new composite function.
15508 * function square(n) {
15512 * var addSquare = _.flow([_.add, square]);
15516 var flow = createFlow();
15519 * This method is like `_.flow` except that it creates a function that
15520 * invokes the given functions from right to left.
15526 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15527 * @returns {Function} Returns the new composite function.
15531 * function square(n) {
15535 * var addSquare = _.flowRight([square, _.add]);
15539 var flowRight = createFlow(true);
15542 * This method returns the first argument it receives.
15548 * @param {*} value Any value.
15549 * @returns {*} Returns `value`.
15552 * var object = { 'a': 1 };
15554 * console.log(_.identity(object) === object);
15557 function identity(value) {
15562 * Creates a function that invokes `func` with the arguments of the created
15563 * function. If `func` is a property name, the created function returns the
15564 * property value for a given element. If `func` is an array or object, the
15565 * created function returns `true` for elements that contain the equivalent
15566 * source properties, otherwise it returns `false`.
15572 * @param {*} [func=_.identity] The value to convert to a callback.
15573 * @returns {Function} Returns the callback.
15577 * { 'user': 'barney', 'age': 36, 'active': true },
15578 * { 'user': 'fred', 'age': 40, 'active': false }
15581 * // The `_.matches` iteratee shorthand.
15582 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
15583 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
15585 * // The `_.matchesProperty` iteratee shorthand.
15586 * _.filter(users, _.iteratee(['user', 'fred']));
15587 * // => [{ 'user': 'fred', 'age': 40 }]
15589 * // The `_.property` iteratee shorthand.
15590 * _.map(users, _.iteratee('user'));
15591 * // => ['barney', 'fred']
15593 * // Create custom iteratee shorthands.
15594 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
15595 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
15596 * return func.test(string);
15600 * _.filter(['abc', 'def'], /ef/);
15603 function iteratee(func) {
15604 return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
15608 * Creates a function that performs a partial deep comparison between a given
15609 * object and `source`, returning `true` if the given object has equivalent
15610 * property values, else `false`.
15612 * **Note:** The created function is equivalent to `_.isMatch` with `source`
15613 * partially applied.
15615 * Partial comparisons will match empty array and empty object `source`
15616 * values against any array or object value, respectively. See `_.isEqual`
15617 * for a list of supported value comparisons.
15619 * **Note:** Multiple values can be checked by combining several matchers
15620 * using `_.overSome`
15626 * @param {Object} source The object of property values to match.
15627 * @returns {Function} Returns the new spec function.
15631 * { 'a': 1, 'b': 2, 'c': 3 },
15632 * { 'a': 4, 'b': 5, 'c': 6 }
15635 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
15636 * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
15638 * // Checking for several possible values
15639 * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
15640 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
15642 function matches(source) {
15643 return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
15647 * Creates a function that performs a partial deep comparison between the
15648 * value at `path` of a given object to `srcValue`, returning `true` if the
15649 * object value is equivalent, else `false`.
15651 * **Note:** Partial comparisons will match empty array and empty object
15652 * `srcValue` values against any array or object value, respectively. See
15653 * `_.isEqual` for a list of supported value comparisons.
15655 * **Note:** Multiple values can be checked by combining several matchers
15656 * using `_.overSome`
15662 * @param {Array|string} path The path of the property to get.
15663 * @param {*} srcValue The value to match.
15664 * @returns {Function} Returns the new spec function.
15668 * { 'a': 1, 'b': 2, 'c': 3 },
15669 * { 'a': 4, 'b': 5, 'c': 6 }
15672 * _.find(objects, _.matchesProperty('a', 4));
15673 * // => { 'a': 4, 'b': 5, 'c': 6 }
15675 * // Checking for several possible values
15676 * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
15677 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
15679 function matchesProperty(path, srcValue) {
15680 return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
15684 * Creates a function that invokes the method at `path` of a given object.
15685 * Any additional arguments are provided to the invoked method.
15691 * @param {Array|string} path The path of the method to invoke.
15692 * @param {...*} [args] The arguments to invoke the method with.
15693 * @returns {Function} Returns the new invoker function.
15697 * { 'a': { 'b': _.constant(2) } },
15698 * { 'a': { 'b': _.constant(1) } }
15701 * _.map(objects, _.method('a.b'));
15704 * _.map(objects, _.method(['a', 'b']));
15707 var method = baseRest(function(path, args) {
15708 return function(object) {
15709 return baseInvoke(object, path, args);
15714 * The opposite of `_.method`; this method creates a function that invokes
15715 * the method at a given path of `object`. Any additional arguments are
15716 * provided to the invoked method.
15722 * @param {Object} object The object to query.
15723 * @param {...*} [args] The arguments to invoke the method with.
15724 * @returns {Function} Returns the new invoker function.
15727 * var array = _.times(3, _.constant),
15728 * object = { 'a': array, 'b': array, 'c': array };
15730 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
15733 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
15736 var methodOf = baseRest(function(object, args) {
15737 return function(path) {
15738 return baseInvoke(object, path, args);
15743 * Adds all own enumerable string keyed function properties of a source
15744 * object to the destination object. If `object` is a function, then methods
15745 * are added to its prototype as well.
15747 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
15748 * avoid conflicts caused by modifying the original.
15754 * @param {Function|Object} [object=lodash] The destination object.
15755 * @param {Object} source The object of functions to add.
15756 * @param {Object} [options={}] The options object.
15757 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
15758 * @returns {Function|Object} Returns `object`.
15761 * function vowels(string) {
15762 * return _.filter(string, function(v) {
15763 * return /[aeiou]/i.test(v);
15767 * _.mixin({ 'vowels': vowels });
15768 * _.vowels('fred');
15771 * _('fred').vowels().value();
15774 * _.mixin({ 'vowels': vowels }, { 'chain': false });
15775 * _('fred').vowels();
15778 function mixin(object, source, options) {
15779 var props = keys(source),
15780 methodNames = baseFunctions(source, props);
15782 if (options == null &&
15783 !(isObject(source) && (methodNames.length || !props.length))) {
15787 methodNames = baseFunctions(source, keys(source));
15789 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
15790 isFunc = isFunction(object);
15792 arrayEach(methodNames, function(methodName) {
15793 var func = source[methodName];
15794 object[methodName] = func;
15796 object.prototype[methodName] = function() {
15797 var chainAll = this.__chain__;
15798 if (chain || chainAll) {
15799 var result = object(this.__wrapped__),
15800 actions = result.__actions__ = copyArray(this.__actions__);
15802 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
15803 result.__chain__ = chainAll;
15806 return func.apply(object, arrayPush([this.value()], arguments));
15815 * Reverts the `_` variable to its previous value and returns a reference to
15816 * the `lodash` function.
15822 * @returns {Function} Returns the `lodash` function.
15825 * var lodash = _.noConflict();
15827 function noConflict() {
15828 if (root._ === this) {
15835 * This method returns `undefined`.
15843 * _.times(2, _.noop);
15844 * // => [undefined, undefined]
15847 // No operation performed.
15851 * Creates a function that gets the argument at index `n`. If `n` is negative,
15852 * the nth argument from the end is returned.
15858 * @param {number} [n=0] The index of the argument to return.
15859 * @returns {Function} Returns the new pass-thru function.
15862 * var func = _.nthArg(1);
15863 * func('a', 'b', 'c', 'd');
15866 * var func = _.nthArg(-2);
15867 * func('a', 'b', 'c', 'd');
15870 function nthArg(n) {
15872 return baseRest(function(args) {
15873 return baseNth(args, n);
15878 * Creates a function that invokes `iteratees` with the arguments it receives
15879 * and returns their results.
15885 * @param {...(Function|Function[])} [iteratees=[_.identity]]
15886 * The iteratees to invoke.
15887 * @returns {Function} Returns the new function.
15890 * var func = _.over([Math.max, Math.min]);
15892 * func(1, 2, 3, 4);
15895 var over = createOver(arrayMap);
15898 * Creates a function that checks if **all** of the `predicates` return
15899 * truthy when invoked with the arguments it receives.
15901 * Following shorthands are possible for providing predicates.
15902 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
15903 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
15909 * @param {...(Function|Function[])} [predicates=[_.identity]]
15910 * The predicates to check.
15911 * @returns {Function} Returns the new function.
15914 * var func = _.overEvery([Boolean, isFinite]);
15925 var overEvery = createOver(arrayEvery);
15928 * Creates a function that checks if **any** of the `predicates` return
15929 * truthy when invoked with the arguments it receives.
15931 * Following shorthands are possible for providing predicates.
15932 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
15933 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
15939 * @param {...(Function|Function[])} [predicates=[_.identity]]
15940 * The predicates to check.
15941 * @returns {Function} Returns the new function.
15944 * var func = _.overSome([Boolean, isFinite]);
15955 * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
15956 * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
15958 var overSome = createOver(arraySome);
15961 * Creates a function that returns the value at `path` of a given object.
15967 * @param {Array|string} path The path of the property to get.
15968 * @returns {Function} Returns the new accessor function.
15972 * { 'a': { 'b': 2 } },
15973 * { 'a': { 'b': 1 } }
15976 * _.map(objects, _.property('a.b'));
15979 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
15982 function property(path) {
15983 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
15987 * The opposite of `_.property`; this method creates a function that returns
15988 * the value at a given path of `object`.
15994 * @param {Object} object The object to query.
15995 * @returns {Function} Returns the new accessor function.
15998 * var array = [0, 1, 2],
15999 * object = { 'a': array, 'b': array, 'c': array };
16001 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
16004 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
16007 function propertyOf(object) {
16008 return function(path) {
16009 return object == null ? undefined : baseGet(object, path);
16014 * Creates an array of numbers (positive and/or negative) progressing from
16015 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
16016 * `start` is specified without an `end` or `step`. If `end` is not specified,
16017 * it's set to `start` with `start` then set to `0`.
16019 * **Note:** JavaScript follows the IEEE-754 standard for resolving
16020 * floating-point values which can produce unexpected results.
16026 * @param {number} [start=0] The start of the range.
16027 * @param {number} end The end of the range.
16028 * @param {number} [step=1] The value to increment or decrement by.
16029 * @returns {Array} Returns the range of numbers.
16030 * @see _.inRange, _.rangeRight
16034 * // => [0, 1, 2, 3]
16037 * // => [0, -1, -2, -3]
16040 * // => [1, 2, 3, 4]
16042 * _.range(0, 20, 5);
16043 * // => [0, 5, 10, 15]
16045 * _.range(0, -4, -1);
16046 * // => [0, -1, -2, -3]
16048 * _.range(1, 4, 0);
16054 var range = createRange();
16057 * This method is like `_.range` except that it populates values in
16058 * descending order.
16064 * @param {number} [start=0] The start of the range.
16065 * @param {number} end The end of the range.
16066 * @param {number} [step=1] The value to increment or decrement by.
16067 * @returns {Array} Returns the range of numbers.
16068 * @see _.inRange, _.range
16072 * // => [3, 2, 1, 0]
16074 * _.rangeRight(-4);
16075 * // => [-3, -2, -1, 0]
16077 * _.rangeRight(1, 5);
16078 * // => [4, 3, 2, 1]
16080 * _.rangeRight(0, 20, 5);
16081 * // => [15, 10, 5, 0]
16083 * _.rangeRight(0, -4, -1);
16084 * // => [-3, -2, -1, 0]
16086 * _.rangeRight(1, 4, 0);
16092 var rangeRight = createRange(true);
16095 * This method returns a new empty array.
16101 * @returns {Array} Returns the new empty array.
16104 * var arrays = _.times(2, _.stubArray);
16106 * console.log(arrays);
16109 * console.log(arrays[0] === arrays[1]);
16112 function stubArray() {
16117 * This method returns `false`.
16123 * @returns {boolean} Returns `false`.
16126 * _.times(2, _.stubFalse);
16127 * // => [false, false]
16129 function stubFalse() {
16134 * This method returns a new empty object.
16140 * @returns {Object} Returns the new empty object.
16143 * var objects = _.times(2, _.stubObject);
16145 * console.log(objects);
16148 * console.log(objects[0] === objects[1]);
16151 function stubObject() {
16156 * This method returns an empty string.
16162 * @returns {string} Returns the empty string.
16165 * _.times(2, _.stubString);
16168 function stubString() {
16173 * This method returns `true`.
16179 * @returns {boolean} Returns `true`.
16182 * _.times(2, _.stubTrue);
16183 * // => [true, true]
16185 function stubTrue() {
16190 * Invokes the iteratee `n` times, returning an array of the results of
16191 * each invocation. The iteratee is invoked with one argument; (index).
16197 * @param {number} n The number of times to invoke `iteratee`.
16198 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
16199 * @returns {Array} Returns the array of results.
16202 * _.times(3, String);
16203 * // => ['0', '1', '2']
16205 * _.times(4, _.constant(0));
16206 * // => [0, 0, 0, 0]
16208 function times(n, iteratee) {
16210 if (n < 1 || n > MAX_SAFE_INTEGER) {
16213 var index = MAX_ARRAY_LENGTH,
16214 length = nativeMin(n, MAX_ARRAY_LENGTH);
16216 iteratee = getIteratee(iteratee);
16217 n -= MAX_ARRAY_LENGTH;
16219 var result = baseTimes(length, iteratee);
16220 while (++index < n) {
16227 * Converts `value` to a property path array.
16233 * @param {*} value The value to convert.
16234 * @returns {Array} Returns the new property path array.
16237 * _.toPath('a.b.c');
16238 * // => ['a', 'b', 'c']
16240 * _.toPath('a[0].b.c');
16241 * // => ['a', '0', 'b', 'c']
16243 function toPath(value) {
16244 if (isArray(value)) {
16245 return arrayMap(value, toKey);
16247 return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
16251 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
16257 * @param {string} [prefix=''] The value to prefix the ID with.
16258 * @returns {string} Returns the unique ID.
16261 * _.uniqueId('contact_');
16262 * // => 'contact_104'
16267 function uniqueId(prefix) {
16268 var id = ++idCounter;
16269 return toString(prefix) + id;
16272 /*------------------------------------------------------------------------*/
16275 * Adds two numbers.
16281 * @param {number} augend The first number in an addition.
16282 * @param {number} addend The second number in an addition.
16283 * @returns {number} Returns the total.
16289 var add = createMathOperation(function(augend, addend) {
16290 return augend + addend;
16294 * Computes `number` rounded up to `precision`.
16300 * @param {number} number The number to round up.
16301 * @param {number} [precision=0] The precision to round up to.
16302 * @returns {number} Returns the rounded up number.
16308 * _.ceil(6.004, 2);
16311 * _.ceil(6040, -2);
16314 var ceil = createRound('ceil');
16317 * Divide two numbers.
16323 * @param {number} dividend The first number in a division.
16324 * @param {number} divisor The second number in a division.
16325 * @returns {number} Returns the quotient.
16331 var divide = createMathOperation(function(dividend, divisor) {
16332 return dividend / divisor;
16336 * Computes `number` rounded down to `precision`.
16342 * @param {number} number The number to round down.
16343 * @param {number} [precision=0] The precision to round down to.
16344 * @returns {number} Returns the rounded down number.
16350 * _.floor(0.046, 2);
16353 * _.floor(4060, -2);
16356 var floor = createRound('floor');
16359 * Computes the maximum value of `array`. If `array` is empty or falsey,
16360 * `undefined` is returned.
16366 * @param {Array} array The array to iterate over.
16367 * @returns {*} Returns the maximum value.
16370 * _.max([4, 2, 8, 6]);
16376 function max(array) {
16377 return (array && array.length)
16378 ? baseExtremum(array, identity, baseGt)
16383 * This method is like `_.max` except that it accepts `iteratee` which is
16384 * invoked for each element in `array` to generate the criterion by which
16385 * the value is ranked. The iteratee is invoked with one argument: (value).
16391 * @param {Array} array The array to iterate over.
16392 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16393 * @returns {*} Returns the maximum value.
16396 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16398 * _.maxBy(objects, function(o) { return o.n; });
16401 * // The `_.property` iteratee shorthand.
16402 * _.maxBy(objects, 'n');
16405 function maxBy(array, iteratee) {
16406 return (array && array.length)
16407 ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
16412 * Computes the mean of the values in `array`.
16418 * @param {Array} array The array to iterate over.
16419 * @returns {number} Returns the mean.
16422 * _.mean([4, 2, 8, 6]);
16425 function mean(array) {
16426 return baseMean(array, identity);
16430 * This method is like `_.mean` except that it accepts `iteratee` which is
16431 * invoked for each element in `array` to generate the value to be averaged.
16432 * The iteratee is invoked with one argument: (value).
16438 * @param {Array} array The array to iterate over.
16439 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16440 * @returns {number} Returns the mean.
16443 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16445 * _.meanBy(objects, function(o) { return o.n; });
16448 * // The `_.property` iteratee shorthand.
16449 * _.meanBy(objects, 'n');
16452 function meanBy(array, iteratee) {
16453 return baseMean(array, getIteratee(iteratee, 2));
16457 * Computes the minimum value of `array`. If `array` is empty or falsey,
16458 * `undefined` is returned.
16464 * @param {Array} array The array to iterate over.
16465 * @returns {*} Returns the minimum value.
16468 * _.min([4, 2, 8, 6]);
16474 function min(array) {
16475 return (array && array.length)
16476 ? baseExtremum(array, identity, baseLt)
16481 * This method is like `_.min` except that it accepts `iteratee` which is
16482 * invoked for each element in `array` to generate the criterion by which
16483 * the value is ranked. The iteratee is invoked with one argument: (value).
16489 * @param {Array} array The array to iterate over.
16490 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16491 * @returns {*} Returns the minimum value.
16494 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16496 * _.minBy(objects, function(o) { return o.n; });
16499 * // The `_.property` iteratee shorthand.
16500 * _.minBy(objects, 'n');
16503 function minBy(array, iteratee) {
16504 return (array && array.length)
16505 ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
16510 * Multiply two numbers.
16516 * @param {number} multiplier The first number in a multiplication.
16517 * @param {number} multiplicand The second number in a multiplication.
16518 * @returns {number} Returns the product.
16521 * _.multiply(6, 4);
16524 var multiply = createMathOperation(function(multiplier, multiplicand) {
16525 return multiplier * multiplicand;
16529 * Computes `number` rounded to `precision`.
16535 * @param {number} number The number to round.
16536 * @param {number} [precision=0] The precision to round to.
16537 * @returns {number} Returns the rounded number.
16543 * _.round(4.006, 2);
16546 * _.round(4060, -2);
16549 var round = createRound('round');
16552 * Subtract two numbers.
16558 * @param {number} minuend The first number in a subtraction.
16559 * @param {number} subtrahend The second number in a subtraction.
16560 * @returns {number} Returns the difference.
16563 * _.subtract(6, 4);
16566 var subtract = createMathOperation(function(minuend, subtrahend) {
16567 return minuend - subtrahend;
16571 * Computes the sum of the values in `array`.
16577 * @param {Array} array The array to iterate over.
16578 * @returns {number} Returns the sum.
16581 * _.sum([4, 2, 8, 6]);
16584 function sum(array) {
16585 return (array && array.length)
16586 ? baseSum(array, identity)
16591 * This method is like `_.sum` except that it accepts `iteratee` which is
16592 * invoked for each element in `array` to generate the value to be summed.
16593 * The iteratee is invoked with one argument: (value).
16599 * @param {Array} array The array to iterate over.
16600 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16601 * @returns {number} Returns the sum.
16604 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16606 * _.sumBy(objects, function(o) { return o.n; });
16609 * // The `_.property` iteratee shorthand.
16610 * _.sumBy(objects, 'n');
16613 function sumBy(array, iteratee) {
16614 return (array && array.length)
16615 ? baseSum(array, getIteratee(iteratee, 2))
16619 /*------------------------------------------------------------------------*/
16621 // Add methods that return wrapped values in chain sequences.
16622 lodash.after = after;
16624 lodash.assign = assign;
16625 lodash.assignIn = assignIn;
16626 lodash.assignInWith = assignInWith;
16627 lodash.assignWith = assignWith;
16629 lodash.before = before;
16630 lodash.bind = bind;
16631 lodash.bindAll = bindAll;
16632 lodash.bindKey = bindKey;
16633 lodash.castArray = castArray;
16634 lodash.chain = chain;
16635 lodash.chunk = chunk;
16636 lodash.compact = compact;
16637 lodash.concat = concat;
16638 lodash.cond = cond;
16639 lodash.conforms = conforms;
16640 lodash.constant = constant;
16641 lodash.countBy = countBy;
16642 lodash.create = create;
16643 lodash.curry = curry;
16644 lodash.curryRight = curryRight;
16645 lodash.debounce = debounce;
16646 lodash.defaults = defaults;
16647 lodash.defaultsDeep = defaultsDeep;
16648 lodash.defer = defer;
16649 lodash.delay = delay;
16650 lodash.difference = difference;
16651 lodash.differenceBy = differenceBy;
16652 lodash.differenceWith = differenceWith;
16653 lodash.drop = drop;
16654 lodash.dropRight = dropRight;
16655 lodash.dropRightWhile = dropRightWhile;
16656 lodash.dropWhile = dropWhile;
16657 lodash.fill = fill;
16658 lodash.filter = filter;
16659 lodash.flatMap = flatMap;
16660 lodash.flatMapDeep = flatMapDeep;
16661 lodash.flatMapDepth = flatMapDepth;
16662 lodash.flatten = flatten;
16663 lodash.flattenDeep = flattenDeep;
16664 lodash.flattenDepth = flattenDepth;
16665 lodash.flip = flip;
16666 lodash.flow = flow;
16667 lodash.flowRight = flowRight;
16668 lodash.fromPairs = fromPairs;
16669 lodash.functions = functions;
16670 lodash.functionsIn = functionsIn;
16671 lodash.groupBy = groupBy;
16672 lodash.initial = initial;
16673 lodash.intersection = intersection;
16674 lodash.intersectionBy = intersectionBy;
16675 lodash.intersectionWith = intersectionWith;
16676 lodash.invert = invert;
16677 lodash.invertBy = invertBy;
16678 lodash.invokeMap = invokeMap;
16679 lodash.iteratee = iteratee;
16680 lodash.keyBy = keyBy;
16681 lodash.keys = keys;
16682 lodash.keysIn = keysIn;
16684 lodash.mapKeys = mapKeys;
16685 lodash.mapValues = mapValues;
16686 lodash.matches = matches;
16687 lodash.matchesProperty = matchesProperty;
16688 lodash.memoize = memoize;
16689 lodash.merge = merge;
16690 lodash.mergeWith = mergeWith;
16691 lodash.method = method;
16692 lodash.methodOf = methodOf;
16693 lodash.mixin = mixin;
16694 lodash.negate = negate;
16695 lodash.nthArg = nthArg;
16696 lodash.omit = omit;
16697 lodash.omitBy = omitBy;
16698 lodash.once = once;
16699 lodash.orderBy = orderBy;
16700 lodash.over = over;
16701 lodash.overArgs = overArgs;
16702 lodash.overEvery = overEvery;
16703 lodash.overSome = overSome;
16704 lodash.partial = partial;
16705 lodash.partialRight = partialRight;
16706 lodash.partition = partition;
16707 lodash.pick = pick;
16708 lodash.pickBy = pickBy;
16709 lodash.property = property;
16710 lodash.propertyOf = propertyOf;
16711 lodash.pull = pull;
16712 lodash.pullAll = pullAll;
16713 lodash.pullAllBy = pullAllBy;
16714 lodash.pullAllWith = pullAllWith;
16715 lodash.pullAt = pullAt;
16716 lodash.range = range;
16717 lodash.rangeRight = rangeRight;
16718 lodash.rearg = rearg;
16719 lodash.reject = reject;
16720 lodash.remove = remove;
16721 lodash.rest = rest;
16722 lodash.reverse = reverse;
16723 lodash.sampleSize = sampleSize;
16725 lodash.setWith = setWith;
16726 lodash.shuffle = shuffle;
16727 lodash.slice = slice;
16728 lodash.sortBy = sortBy;
16729 lodash.sortedUniq = sortedUniq;
16730 lodash.sortedUniqBy = sortedUniqBy;
16731 lodash.split = split;
16732 lodash.spread = spread;
16733 lodash.tail = tail;
16734 lodash.take = take;
16735 lodash.takeRight = takeRight;
16736 lodash.takeRightWhile = takeRightWhile;
16737 lodash.takeWhile = takeWhile;
16739 lodash.throttle = throttle;
16740 lodash.thru = thru;
16741 lodash.toArray = toArray;
16742 lodash.toPairs = toPairs;
16743 lodash.toPairsIn = toPairsIn;
16744 lodash.toPath = toPath;
16745 lodash.toPlainObject = toPlainObject;
16746 lodash.transform = transform;
16747 lodash.unary = unary;
16748 lodash.union = union;
16749 lodash.unionBy = unionBy;
16750 lodash.unionWith = unionWith;
16751 lodash.uniq = uniq;
16752 lodash.uniqBy = uniqBy;
16753 lodash.uniqWith = uniqWith;
16754 lodash.unset = unset;
16755 lodash.unzip = unzip;
16756 lodash.unzipWith = unzipWith;
16757 lodash.update = update;
16758 lodash.updateWith = updateWith;
16759 lodash.values = values;
16760 lodash.valuesIn = valuesIn;
16761 lodash.without = without;
16762 lodash.words = words;
16763 lodash.wrap = wrap;
16765 lodash.xorBy = xorBy;
16766 lodash.xorWith = xorWith;
16768 lodash.zipObject = zipObject;
16769 lodash.zipObjectDeep = zipObjectDeep;
16770 lodash.zipWith = zipWith;
16773 lodash.entries = toPairs;
16774 lodash.entriesIn = toPairsIn;
16775 lodash.extend = assignIn;
16776 lodash.extendWith = assignInWith;
16778 // Add methods to `lodash.prototype`.
16779 mixin(lodash, lodash);
16781 /*------------------------------------------------------------------------*/
16783 // Add methods that return unwrapped values in chain sequences.
16785 lodash.attempt = attempt;
16786 lodash.camelCase = camelCase;
16787 lodash.capitalize = capitalize;
16788 lodash.ceil = ceil;
16789 lodash.clamp = clamp;
16790 lodash.clone = clone;
16791 lodash.cloneDeep = cloneDeep;
16792 lodash.cloneDeepWith = cloneDeepWith;
16793 lodash.cloneWith = cloneWith;
16794 lodash.conformsTo = conformsTo;
16795 lodash.deburr = deburr;
16796 lodash.defaultTo = defaultTo;
16797 lodash.divide = divide;
16798 lodash.endsWith = endsWith;
16800 lodash.escape = escape;
16801 lodash.escapeRegExp = escapeRegExp;
16802 lodash.every = every;
16803 lodash.find = find;
16804 lodash.findIndex = findIndex;
16805 lodash.findKey = findKey;
16806 lodash.findLast = findLast;
16807 lodash.findLastIndex = findLastIndex;
16808 lodash.findLastKey = findLastKey;
16809 lodash.floor = floor;
16810 lodash.forEach = forEach;
16811 lodash.forEachRight = forEachRight;
16812 lodash.forIn = forIn;
16813 lodash.forInRight = forInRight;
16814 lodash.forOwn = forOwn;
16815 lodash.forOwnRight = forOwnRight;
16820 lodash.hasIn = hasIn;
16821 lodash.head = head;
16822 lodash.identity = identity;
16823 lodash.includes = includes;
16824 lodash.indexOf = indexOf;
16825 lodash.inRange = inRange;
16826 lodash.invoke = invoke;
16827 lodash.isArguments = isArguments;
16828 lodash.isArray = isArray;
16829 lodash.isArrayBuffer = isArrayBuffer;
16830 lodash.isArrayLike = isArrayLike;
16831 lodash.isArrayLikeObject = isArrayLikeObject;
16832 lodash.isBoolean = isBoolean;
16833 lodash.isBuffer = isBuffer;
16834 lodash.isDate = isDate;
16835 lodash.isElement = isElement;
16836 lodash.isEmpty = isEmpty;
16837 lodash.isEqual = isEqual;
16838 lodash.isEqualWith = isEqualWith;
16839 lodash.isError = isError;
16840 lodash.isFinite = isFinite;
16841 lodash.isFunction = isFunction;
16842 lodash.isInteger = isInteger;
16843 lodash.isLength = isLength;
16844 lodash.isMap = isMap;
16845 lodash.isMatch = isMatch;
16846 lodash.isMatchWith = isMatchWith;
16847 lodash.isNaN = isNaN;
16848 lodash.isNative = isNative;
16849 lodash.isNil = isNil;
16850 lodash.isNull = isNull;
16851 lodash.isNumber = isNumber;
16852 lodash.isObject = isObject;
16853 lodash.isObjectLike = isObjectLike;
16854 lodash.isPlainObject = isPlainObject;
16855 lodash.isRegExp = isRegExp;
16856 lodash.isSafeInteger = isSafeInteger;
16857 lodash.isSet = isSet;
16858 lodash.isString = isString;
16859 lodash.isSymbol = isSymbol;
16860 lodash.isTypedArray = isTypedArray;
16861 lodash.isUndefined = isUndefined;
16862 lodash.isWeakMap = isWeakMap;
16863 lodash.isWeakSet = isWeakSet;
16864 lodash.join = join;
16865 lodash.kebabCase = kebabCase;
16866 lodash.last = last;
16867 lodash.lastIndexOf = lastIndexOf;
16868 lodash.lowerCase = lowerCase;
16869 lodash.lowerFirst = lowerFirst;
16873 lodash.maxBy = maxBy;
16874 lodash.mean = mean;
16875 lodash.meanBy = meanBy;
16877 lodash.minBy = minBy;
16878 lodash.stubArray = stubArray;
16879 lodash.stubFalse = stubFalse;
16880 lodash.stubObject = stubObject;
16881 lodash.stubString = stubString;
16882 lodash.stubTrue = stubTrue;
16883 lodash.multiply = multiply;
16885 lodash.noConflict = noConflict;
16886 lodash.noop = noop;
16889 lodash.padEnd = padEnd;
16890 lodash.padStart = padStart;
16891 lodash.parseInt = parseInt;
16892 lodash.random = random;
16893 lodash.reduce = reduce;
16894 lodash.reduceRight = reduceRight;
16895 lodash.repeat = repeat;
16896 lodash.replace = replace;
16897 lodash.result = result;
16898 lodash.round = round;
16899 lodash.runInContext = runInContext;
16900 lodash.sample = sample;
16901 lodash.size = size;
16902 lodash.snakeCase = snakeCase;
16903 lodash.some = some;
16904 lodash.sortedIndex = sortedIndex;
16905 lodash.sortedIndexBy = sortedIndexBy;
16906 lodash.sortedIndexOf = sortedIndexOf;
16907 lodash.sortedLastIndex = sortedLastIndex;
16908 lodash.sortedLastIndexBy = sortedLastIndexBy;
16909 lodash.sortedLastIndexOf = sortedLastIndexOf;
16910 lodash.startCase = startCase;
16911 lodash.startsWith = startsWith;
16912 lodash.subtract = subtract;
16914 lodash.sumBy = sumBy;
16915 lodash.template = template;
16916 lodash.times = times;
16917 lodash.toFinite = toFinite;
16918 lodash.toInteger = toInteger;
16919 lodash.toLength = toLength;
16920 lodash.toLower = toLower;
16921 lodash.toNumber = toNumber;
16922 lodash.toSafeInteger = toSafeInteger;
16923 lodash.toString = toString;
16924 lodash.toUpper = toUpper;
16925 lodash.trim = trim;
16926 lodash.trimEnd = trimEnd;
16927 lodash.trimStart = trimStart;
16928 lodash.truncate = truncate;
16929 lodash.unescape = unescape;
16930 lodash.uniqueId = uniqueId;
16931 lodash.upperCase = upperCase;
16932 lodash.upperFirst = upperFirst;
16935 lodash.each = forEach;
16936 lodash.eachRight = forEachRight;
16937 lodash.first = head;
16939 mixin(lodash, (function() {
16941 baseForOwn(lodash, function(func, methodName) {
16942 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
16943 source[methodName] = func;
16947 }()), { 'chain': false });
16949 /*------------------------------------------------------------------------*/
16952 * The semantic version number.
16958 lodash.VERSION = VERSION;
16960 // Assign default placeholders.
16961 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
16962 lodash[methodName].placeholder = lodash;
16965 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
16966 arrayEach(['drop', 'take'], function(methodName, index) {
16967 LazyWrapper.prototype[methodName] = function(n) {
16968 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
16970 var result = (this.__filtered__ && !index)
16971 ? new LazyWrapper(this)
16974 if (result.__filtered__) {
16975 result.__takeCount__ = nativeMin(n, result.__takeCount__);
16977 result.__views__.push({
16978 'size': nativeMin(n, MAX_ARRAY_LENGTH),
16979 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
16985 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
16986 return this.reverse()[methodName](n).reverse();
16990 // Add `LazyWrapper` methods that accept an `iteratee` value.
16991 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
16992 var type = index + 1,
16993 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
16995 LazyWrapper.prototype[methodName] = function(iteratee) {
16996 var result = this.clone();
16997 result.__iteratees__.push({
16998 'iteratee': getIteratee(iteratee, 3),
17001 result.__filtered__ = result.__filtered__ || isFilter;
17006 // Add `LazyWrapper` methods for `_.head` and `_.last`.
17007 arrayEach(['head', 'last'], function(methodName, index) {
17008 var takeName = 'take' + (index ? 'Right' : '');
17010 LazyWrapper.prototype[methodName] = function() {
17011 return this[takeName](1).value()[0];
17015 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
17016 arrayEach(['initial', 'tail'], function(methodName, index) {
17017 var dropName = 'drop' + (index ? '' : 'Right');
17019 LazyWrapper.prototype[methodName] = function() {
17020 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
17024 LazyWrapper.prototype.compact = function() {
17025 return this.filter(identity);
17028 LazyWrapper.prototype.find = function(predicate) {
17029 return this.filter(predicate).head();
17032 LazyWrapper.prototype.findLast = function(predicate) {
17033 return this.reverse().find(predicate);
17036 LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
17037 if (typeof path == 'function') {
17038 return new LazyWrapper(this);
17040 return this.map(function(value) {
17041 return baseInvoke(value, path, args);
17045 LazyWrapper.prototype.reject = function(predicate) {
17046 return this.filter(negate(getIteratee(predicate)));
17049 LazyWrapper.prototype.slice = function(start, end) {
17050 start = toInteger(start);
17053 if (result.__filtered__ && (start > 0 || end < 0)) {
17054 return new LazyWrapper(result);
17057 result = result.takeRight(-start);
17058 } else if (start) {
17059 result = result.drop(start);
17061 if (end !== undefined) {
17062 end = toInteger(end);
17063 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
17068 LazyWrapper.prototype.takeRightWhile = function(predicate) {
17069 return this.reverse().takeWhile(predicate).reverse();
17072 LazyWrapper.prototype.toArray = function() {
17073 return this.take(MAX_ARRAY_LENGTH);
17076 // Add `LazyWrapper` methods to `lodash.prototype`.
17077 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
17078 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
17079 isTaker = /^(?:head|last)$/.test(methodName),
17080 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
17081 retUnwrapped = isTaker || /^find/.test(methodName);
17086 lodash.prototype[methodName] = function() {
17087 var value = this.__wrapped__,
17088 args = isTaker ? [1] : arguments,
17089 isLazy = value instanceof LazyWrapper,
17090 iteratee = args[0],
17091 useLazy = isLazy || isArray(value);
17093 var interceptor = function(value) {
17094 var result = lodashFunc.apply(lodash, arrayPush([value], args));
17095 return (isTaker && chainAll) ? result[0] : result;
17098 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
17099 // Avoid lazy use if the iteratee has a "length" value other than `1`.
17100 isLazy = useLazy = false;
17102 var chainAll = this.__chain__,
17103 isHybrid = !!this.__actions__.length,
17104 isUnwrapped = retUnwrapped && !chainAll,
17105 onlyLazy = isLazy && !isHybrid;
17107 if (!retUnwrapped && useLazy) {
17108 value = onlyLazy ? value : new LazyWrapper(this);
17109 var result = func.apply(value, args);
17110 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
17111 return new LodashWrapper(result, chainAll);
17113 if (isUnwrapped && onlyLazy) {
17114 return func.apply(this, args);
17116 result = this.thru(interceptor);
17117 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
17121 // Add `Array` methods to `lodash.prototype`.
17122 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
17123 var func = arrayProto[methodName],
17124 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
17125 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
17127 lodash.prototype[methodName] = function() {
17128 var args = arguments;
17129 if (retUnwrapped && !this.__chain__) {
17130 var value = this.value();
17131 return func.apply(isArray(value) ? value : [], args);
17133 return this[chainName](function(value) {
17134 return func.apply(isArray(value) ? value : [], args);
17139 // Map minified method names to their real names.
17140 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
17141 var lodashFunc = lodash[methodName];
17143 var key = lodashFunc.name + '';
17144 if (!hasOwnProperty.call(realNames, key)) {
17145 realNames[key] = [];
17147 realNames[key].push({ 'name': methodName, 'func': lodashFunc });
17151 realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
17156 // Add methods to `LazyWrapper`.
17157 LazyWrapper.prototype.clone = lazyClone;
17158 LazyWrapper.prototype.reverse = lazyReverse;
17159 LazyWrapper.prototype.value = lazyValue;
17161 // Add chain sequence methods to the `lodash` wrapper.
17162 lodash.prototype.at = wrapperAt;
17163 lodash.prototype.chain = wrapperChain;
17164 lodash.prototype.commit = wrapperCommit;
17165 lodash.prototype.next = wrapperNext;
17166 lodash.prototype.plant = wrapperPlant;
17167 lodash.prototype.reverse = wrapperReverse;
17168 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
17170 // Add lazy aliases.
17171 lodash.prototype.first = lodash.prototype.head;
17174 lodash.prototype[symIterator] = wrapperToIterator;
17179 /*--------------------------------------------------------------------------*/
17182 var _ = runInContext();
17184 // Some AMD build optimizers, like r.js, check for condition patterns like:
17185 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
17186 // Expose Lodash on the global object to prevent errors when Lodash is
17187 // loaded by a script tag in the presence of an AMD loader.
17188 // See http://requirejs.org/docs/errors.html#mismatch for more details.
17189 // Use `_.noConflict` to remove Lodash from the global object.
17192 // Define as an anonymous module so, through path mapping, it can be
17193 // referenced as the "underscore" module.
17194 define(function() {
17198 // Check for `exports` after `define` in case a build optimizer adds it.
17199 else if (freeModule) {
17200 // Export for Node.js.
17201 (freeModule.exports = _)._ = _;
17202 // Export for CommonJS support.
17206 // Export to the global object.