UNPKG

539 kBJavaScriptView Raw
1/**
2 * @license
3 * Lodash <https://lodash.com/>
4 * Copyright JS Foundation and other contributors <https://js.foundation/>
5 * Released under MIT license <https://lodash.com/license>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 */
9;(function() {
10
11 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
12 var undefined;
13
14 /** Used as the semantic version number. */
15 var VERSION = '4.17.0';
16
17 /** Used as the size to enable large array optimizations. */
18 var LARGE_ARRAY_SIZE = 200;
19
20 /** Error message constants. */
21 var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
22 FUNC_ERROR_TEXT = 'Expected a function';
23
24 /** Used to stand-in for `undefined` hash values. */
25 var HASH_UNDEFINED = '__lodash_hash_undefined__';
26
27 /** Used as the maximum memoize cache size. */
28 var MAX_MEMOIZE_SIZE = 500;
29
30 /** Used as the internal argument placeholder. */
31 var PLACEHOLDER = '__lodash_placeholder__';
32
33 /** Used to compose bitmasks for cloning. */
34 var CLONE_DEEP_FLAG = 1,
35 CLONE_FLAT_FLAG = 2,
36 CLONE_SYMBOLS_FLAG = 4;
37
38 /** Used to compose bitmasks for value comparisons. */
39 var COMPARE_PARTIAL_FLAG = 1,
40 COMPARE_UNORDERED_FLAG = 2;
41
42 /** Used to compose bitmasks for function metadata. */
43 var WRAP_BIND_FLAG = 1,
44 WRAP_BIND_KEY_FLAG = 2,
45 WRAP_CURRY_BOUND_FLAG = 4,
46 WRAP_CURRY_FLAG = 8,
47 WRAP_CURRY_RIGHT_FLAG = 16,
48 WRAP_PARTIAL_FLAG = 32,
49 WRAP_PARTIAL_RIGHT_FLAG = 64,
50 WRAP_ARY_FLAG = 128,
51 WRAP_REARG_FLAG = 256,
52 WRAP_FLIP_FLAG = 512;
53
54 /** Used as default options for `_.truncate`. */
55 var DEFAULT_TRUNC_LENGTH = 30,
56 DEFAULT_TRUNC_OMISSION = '...';
57
58 /** Used to detect hot functions by number of calls within a span of milliseconds. */
59 var HOT_COUNT = 800,
60 HOT_SPAN = 16;
61
62 /** Used to indicate the type of lazy iteratees. */
63 var LAZY_FILTER_FLAG = 1,
64 LAZY_MAP_FLAG = 2,
65 LAZY_WHILE_FLAG = 3;
66
67 /** Used as references for various `Number` constants. */
68 var INFINITY = 1 / 0,
69 MAX_SAFE_INTEGER = 9007199254740991,
70 MAX_INTEGER = 1.7976931348623157e+308,
71 NAN = 0 / 0;
72
73 /** Used as references for the maximum length and index of an array. */
74 var MAX_ARRAY_LENGTH = 4294967295,
75 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
76 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
77
78 /** Used to associate wrap methods with their bit flags. */
79 var wrapFlags = [
80 ['ary', WRAP_ARY_FLAG],
81 ['bind', WRAP_BIND_FLAG],
82 ['bindKey', WRAP_BIND_KEY_FLAG],
83 ['curry', WRAP_CURRY_FLAG],
84 ['curryRight', WRAP_CURRY_RIGHT_FLAG],
85 ['flip', WRAP_FLIP_FLAG],
86 ['partial', WRAP_PARTIAL_FLAG],
87 ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
88 ['rearg', WRAP_REARG_FLAG]
89 ];
90
91 /** `Object#toString` result references. */
92 var argsTag = '[object Arguments]',
93 arrayTag = '[object Array]',
94 asyncTag = '[object AsyncFunction]',
95 boolTag = '[object Boolean]',
96 dateTag = '[object Date]',
97 domExcTag = '[object DOMException]',
98 errorTag = '[object Error]',
99 funcTag = '[object Function]',
100 genTag = '[object GeneratorFunction]',
101 mapTag = '[object Map]',
102 numberTag = '[object Number]',
103 nullTag = '[object Null]',
104 objectTag = '[object Object]',
105 promiseTag = '[object Promise]',
106 proxyTag = '[object Proxy]',
107 regexpTag = '[object RegExp]',
108 setTag = '[object Set]',
109 stringTag = '[object String]',
110 symbolTag = '[object Symbol]',
111 undefinedTag = '[object Undefined]',
112 weakMapTag = '[object WeakMap]',
113 weakSetTag = '[object WeakSet]';
114
115 var arrayBufferTag = '[object ArrayBuffer]',
116 dataViewTag = '[object DataView]',
117 float32Tag = '[object Float32Array]',
118 float64Tag = '[object Float64Array]',
119 int8Tag = '[object Int8Array]',
120 int16Tag = '[object Int16Array]',
121 int32Tag = '[object Int32Array]',
122 uint8Tag = '[object Uint8Array]',
123 uint8ClampedTag = '[object Uint8ClampedArray]',
124 uint16Tag = '[object Uint16Array]',
125 uint32Tag = '[object Uint32Array]';
126
127 /** Used to match empty string literals in compiled template source. */
128 var reEmptyStringLeading = /\b__p \+= '';/g,
129 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
130 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
131
132 /** Used to match HTML entities and HTML characters. */
133 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
134 reUnescapedHtml = /[&<>"']/g,
135 reHasEscapedHtml = RegExp(reEscapedHtml.source),
136 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
137
138 /** Used to match template delimiters. */
139 var reEscape = /<%-([\s\S]+?)%>/g,
140 reEvaluate = /<%([\s\S]+?)%>/g,
141 reInterpolate = /<%=([\s\S]+?)%>/g;
142
143 /** Used to match property names within property paths. */
144 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
145 reIsPlainProp = /^\w*$/,
146 reLeadingDot = /^\./,
147 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
148
149 /**
150 * Used to match `RegExp`
151 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
152 */
153 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
154 reHasRegExpChar = RegExp(reRegExpChar.source);
155
156 /** Used to match leading and trailing whitespace. */
157 var reTrim = /^\s+|\s+$/g,
158 reTrimStart = /^\s+/,
159 reTrimEnd = /\s+$/;
160
161 /** Used to match wrap detail comments. */
162 var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
163 reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
164 reSplitDetails = /,? & /;
165
166 /** Used to match words composed of alphanumeric characters. */
167 var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
168
169 /** Used to match backslashes in property paths. */
170 var reEscapeChar = /\\(\\)?/g;
171
172 /**
173 * Used to match
174 * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
175 */
176 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
177
178 /** Used to match `RegExp` flags from their coerced string values. */
179 var reFlags = /\w*$/;
180
181 /** Used to detect bad signed hexadecimal string values. */
182 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
183
184 /** Used to detect binary string values. */
185 var reIsBinary = /^0b[01]+$/i;
186
187 /** Used to detect host constructors (Safari). */
188 var reIsHostCtor = /^\[object .+?Constructor\]$/;
189
190 /** Used to detect octal string values. */
191 var reIsOctal = /^0o[0-7]+$/i;
192
193 /** Used to detect unsigned integer values. */
194 var reIsUint = /^(?:0|[1-9]\d*)$/;
195
196 /** Used to match Latin Unicode letters (excluding mathematical operators). */
197 var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
198
199 /** Used to ensure capturing order of template delimiters. */
200 var reNoMatch = /($^)/;
201
202 /** Used to match unescaped characters in compiled string literals. */
203 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
204
205 /** Used to compose unicode character classes. */
206 var rsAstralRange = '\\ud800-\\udfff',
207 rsComboMarksRange = '\\u0300-\\u036f',
208 reComboHalfMarksRange = '\\ufe20-\\ufe2f',
209 rsComboSymbolsRange = '\\u20d0-\\u20ff',
210 rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
211 rsDingbatRange = '\\u2700-\\u27bf',
212 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
213 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
214 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
215 rsPunctuationRange = '\\u2000-\\u206f',
216 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',
217 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
218 rsVarRange = '\\ufe0e\\ufe0f',
219 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
220
221 /** Used to compose unicode capture groups. */
222 var rsApos = "['\u2019]",
223 rsAstral = '[' + rsAstralRange + ']',
224 rsBreak = '[' + rsBreakRange + ']',
225 rsCombo = '[' + rsComboRange + ']',
226 rsDigits = '\\d+',
227 rsDingbat = '[' + rsDingbatRange + ']',
228 rsLower = '[' + rsLowerRange + ']',
229 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
230 rsFitz = '\\ud83c[\\udffb-\\udfff]',
231 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
232 rsNonAstral = '[^' + rsAstralRange + ']',
233 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
234 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
235 rsUpper = '[' + rsUpperRange + ']',
236 rsZWJ = '\\u200d';
237
238 /** Used to compose unicode regexes. */
239 var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
240 rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
241 rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
242 rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
243 reOptMod = rsModifier + '?',
244 rsOptVar = '[' + rsVarRange + ']?',
245 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
246 rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)',
247 rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)',
248 rsSeq = rsOptVar + reOptMod + rsOptJoin,
249 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
250 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
251
252 /** Used to match apostrophes. */
253 var reApos = RegExp(rsApos, 'g');
254
255 /**
256 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
257 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
258 */
259 var reComboMark = RegExp(rsCombo, 'g');
260
261 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
262 var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
263
264 /** Used to match complex or compound words. */
265 var reUnicodeWord = RegExp([
266 rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
267 rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
268 rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
269 rsUpper + '+' + rsOptContrUpper,
270 rsOrdUpper,
271 rsOrdLower,
272 rsDigits,
273 rsEmoji
274 ].join('|'), 'g');
275
276 /** 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/). */
277 var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
278
279 /** Used to detect strings that need a more robust regexp to match words. */
280 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 ]/;
281
282 /** Used to assign default `context` object properties. */
283 var contextProps = [
284 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
285 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
286 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
287 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
288 '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
289 ];
290
291 /** Used to make template sourceURLs easier to identify. */
292 var templateCounter = -1;
293
294 /** Used to identify `toStringTag` values of typed arrays. */
295 var typedArrayTags = {};
296 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
297 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
298 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
299 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
300 typedArrayTags[uint32Tag] = true;
301 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
302 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
303 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
304 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
305 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
306 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
307 typedArrayTags[setTag] = typedArrayTags[stringTag] =
308 typedArrayTags[weakMapTag] = false;
309
310 /** Used to identify `toStringTag` values supported by `_.clone`. */
311 var cloneableTags = {};
312 cloneableTags[argsTag] = cloneableTags[arrayTag] =
313 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
314 cloneableTags[boolTag] = cloneableTags[dateTag] =
315 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
316 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
317 cloneableTags[int32Tag] = cloneableTags[mapTag] =
318 cloneableTags[numberTag] = cloneableTags[objectTag] =
319 cloneableTags[regexpTag] = cloneableTags[setTag] =
320 cloneableTags[stringTag] = cloneableTags[symbolTag] =
321 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
322 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
323 cloneableTags[errorTag] = cloneableTags[funcTag] =
324 cloneableTags[weakMapTag] = false;
325
326 /** Used to map Latin Unicode letters to basic Latin letters. */
327 var deburredLetters = {
328 // Latin-1 Supplement block.
329 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
330 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
331 '\xc7': 'C', '\xe7': 'c',
332 '\xd0': 'D', '\xf0': 'd',
333 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
334 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
335 '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
336 '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
337 '\xd1': 'N', '\xf1': 'n',
338 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
339 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
340 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
341 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
342 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
343 '\xc6': 'Ae', '\xe6': 'ae',
344 '\xde': 'Th', '\xfe': 'th',
345 '\xdf': 'ss',
346 // Latin Extended-A block.
347 '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
348 '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
349 '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
350 '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
351 '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
352 '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
353 '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
354 '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
355 '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
356 '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
357 '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
358 '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
359 '\u0134': 'J', '\u0135': 'j',
360 '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
361 '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
362 '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
363 '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
364 '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
365 '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
366 '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
367 '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
368 '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
369 '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
370 '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
371 '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
372 '\u0163': 't', '\u0165': 't', '\u0167': 't',
373 '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
374 '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
375 '\u0174': 'W', '\u0175': 'w',
376 '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
377 '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
378 '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
379 '\u0132': 'IJ', '\u0133': 'ij',
380 '\u0152': 'Oe', '\u0153': 'oe',
381 '\u0149': "'n", '\u017f': 's'
382 };
383
384 /** Used to map characters to HTML entities. */
385 var htmlEscapes = {
386 '&': '&amp;',
387 '<': '&lt;',
388 '>': '&gt;',
389 '"': '&quot;',
390 "'": '&#39;'
391 };
392
393 /** Used to map HTML entities to characters. */
394 var htmlUnescapes = {
395 '&amp;': '&',
396 '&lt;': '<',
397 '&gt;': '>',
398 '&quot;': '"',
399 '&#39;': "'"
400 };
401
402 /** Used to escape characters for inclusion in compiled string literals. */
403 var stringEscapes = {
404 '\\': '\\',
405 "'": "'",
406 '\n': 'n',
407 '\r': 'r',
408 '\u2028': 'u2028',
409 '\u2029': 'u2029'
410 };
411
412 /** Built-in method references without a dependency on `root`. */
413 var freeParseFloat = parseFloat,
414 freeParseInt = parseInt;
415
416 /** Detect free variable `global` from Node.js. */
417 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
418
419 /** Detect free variable `self`. */
420 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
421
422 /** Used as a reference to the global object. */
423 var root = freeGlobal || freeSelf || Function('return this')();
424
425 /** Detect free variable `exports`. */
426 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
427
428 /** Detect free variable `module`. */
429 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
430
431 /** Detect the popular CommonJS extension `module.exports`. */
432 var moduleExports = freeModule && freeModule.exports === freeExports;
433
434 /** Detect free variable `process` from Node.js. */
435 var freeProcess = moduleExports && freeGlobal.process;
436
437 /** Used to access faster Node.js helpers. */
438 var nodeUtil = (function() {
439 try {
440 return freeProcess && freeProcess.binding && freeProcess.binding('util');
441 } catch (e) {}
442 }());
443
444 /* Node.js helper references. */
445 var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
446 nodeIsDate = nodeUtil && nodeUtil.isDate,
447 nodeIsMap = nodeUtil && nodeUtil.isMap,
448 nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
449 nodeIsSet = nodeUtil && nodeUtil.isSet,
450 nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
451
452 /*--------------------------------------------------------------------------*/
453
454 /**
455 * Adds the key-value `pair` to `map`.
456 *
457 * @private
458 * @param {Object} map The map to modify.
459 * @param {Array} pair The key-value pair to add.
460 * @returns {Object} Returns `map`.
461 */
462 function addMapEntry(map, pair) {
463 // Don't return `map.set` because it's not chainable in IE 11.
464 map.set(pair[0], pair[1]);
465 return map;
466 }
467
468 /**
469 * Adds `value` to `set`.
470 *
471 * @private
472 * @param {Object} set The set to modify.
473 * @param {*} value The value to add.
474 * @returns {Object} Returns `set`.
475 */
476 function addSetEntry(set, value) {
477 // Don't return `set.add` because it's not chainable in IE 11.
478 set.add(value);
479 return set;
480 }
481
482 /**
483 * A faster alternative to `Function#apply`, this function invokes `func`
484 * with the `this` binding of `thisArg` and the arguments of `args`.
485 *
486 * @private
487 * @param {Function} func The function to invoke.
488 * @param {*} thisArg The `this` binding of `func`.
489 * @param {Array} args The arguments to invoke `func` with.
490 * @returns {*} Returns the result of `func`.
491 */
492 function apply(func, thisArg, args) {
493 switch (args.length) {
494 case 0: return func.call(thisArg);
495 case 1: return func.call(thisArg, args[0]);
496 case 2: return func.call(thisArg, args[0], args[1]);
497 case 3: return func.call(thisArg, args[0], args[1], args[2]);
498 }
499 return func.apply(thisArg, args);
500 }
501
502 /**
503 * A specialized version of `baseAggregator` for arrays.
504 *
505 * @private
506 * @param {Array} [array] The array to iterate over.
507 * @param {Function} setter The function to set `accumulator` values.
508 * @param {Function} iteratee The iteratee to transform keys.
509 * @param {Object} accumulator The initial aggregated object.
510 * @returns {Function} Returns `accumulator`.
511 */
512 function arrayAggregator(array, setter, iteratee, accumulator) {
513 var index = -1,
514 length = array == null ? 0 : array.length;
515
516 while (++index < length) {
517 var value = array[index];
518 setter(accumulator, value, iteratee(value), array);
519 }
520 return accumulator;
521 }
522
523 /**
524 * A specialized version of `_.forEach` for arrays without support for
525 * iteratee shorthands.
526 *
527 * @private
528 * @param {Array} [array] The array to iterate over.
529 * @param {Function} iteratee The function invoked per iteration.
530 * @returns {Array} Returns `array`.
531 */
532 function arrayEach(array, iteratee) {
533 var index = -1,
534 length = array == null ? 0 : array.length;
535
536 while (++index < length) {
537 if (iteratee(array[index], index, array) === false) {
538 break;
539 }
540 }
541 return array;
542 }
543
544 /**
545 * A specialized version of `_.forEachRight` for arrays without support for
546 * iteratee shorthands.
547 *
548 * @private
549 * @param {Array} [array] The array to iterate over.
550 * @param {Function} iteratee The function invoked per iteration.
551 * @returns {Array} Returns `array`.
552 */
553 function arrayEachRight(array, iteratee) {
554 var length = array == null ? 0 : array.length;
555
556 while (length--) {
557 if (iteratee(array[length], length, array) === false) {
558 break;
559 }
560 }
561 return array;
562 }
563
564 /**
565 * A specialized version of `_.every` for arrays without support for
566 * iteratee shorthands.
567 *
568 * @private
569 * @param {Array} [array] The array to iterate over.
570 * @param {Function} predicate The function invoked per iteration.
571 * @returns {boolean} Returns `true` if all elements pass the predicate check,
572 * else `false`.
573 */
574 function arrayEvery(array, predicate) {
575 var index = -1,
576 length = array == null ? 0 : array.length;
577
578 while (++index < length) {
579 if (!predicate(array[index], index, array)) {
580 return false;
581 }
582 }
583 return true;
584 }
585
586 /**
587 * A specialized version of `_.filter` for arrays without support for
588 * iteratee shorthands.
589 *
590 * @private
591 * @param {Array} [array] The array to iterate over.
592 * @param {Function} predicate The function invoked per iteration.
593 * @returns {Array} Returns the new filtered array.
594 */
595 function arrayFilter(array, predicate) {
596 var index = -1,
597 length = array == null ? 0 : array.length,
598 resIndex = 0,
599 result = [];
600
601 while (++index < length) {
602 var value = array[index];
603 if (predicate(value, index, array)) {
604 result[resIndex++] = value;
605 }
606 }
607 return result;
608 }
609
610 /**
611 * A specialized version of `_.includes` for arrays without support for
612 * specifying an index to search from.
613 *
614 * @private
615 * @param {Array} [array] The array to inspect.
616 * @param {*} target The value to search for.
617 * @returns {boolean} Returns `true` if `target` is found, else `false`.
618 */
619 function arrayIncludes(array, value) {
620 var length = array == null ? 0 : array.length;
621 return !!length && baseIndexOf(array, value, 0) > -1;
622 }
623
624 /**
625 * This function is like `arrayIncludes` except that it accepts a comparator.
626 *
627 * @private
628 * @param {Array} [array] The array to inspect.
629 * @param {*} target The value to search for.
630 * @param {Function} comparator The comparator invoked per element.
631 * @returns {boolean} Returns `true` if `target` is found, else `false`.
632 */
633 function arrayIncludesWith(array, value, comparator) {
634 var index = -1,
635 length = array == null ? 0 : array.length;
636
637 while (++index < length) {
638 if (comparator(value, array[index])) {
639 return true;
640 }
641 }
642 return false;
643 }
644
645 /**
646 * A specialized version of `_.map` for arrays without support for iteratee
647 * shorthands.
648 *
649 * @private
650 * @param {Array} [array] The array to iterate over.
651 * @param {Function} iteratee The function invoked per iteration.
652 * @returns {Array} Returns the new mapped array.
653 */
654 function arrayMap(array, iteratee) {
655 var index = -1,
656 length = array == null ? 0 : array.length,
657 result = Array(length);
658
659 while (++index < length) {
660 result[index] = iteratee(array[index], index, array);
661 }
662 return result;
663 }
664
665 /**
666 * Appends the elements of `values` to `array`.
667 *
668 * @private
669 * @param {Array} array The array to modify.
670 * @param {Array} values The values to append.
671 * @returns {Array} Returns `array`.
672 */
673 function arrayPush(array, values) {
674 var index = -1,
675 length = values.length,
676 offset = array.length;
677
678 while (++index < length) {
679 array[offset + index] = values[index];
680 }
681 return array;
682 }
683
684 /**
685 * A specialized version of `_.reduce` for arrays without support for
686 * iteratee shorthands.
687 *
688 * @private
689 * @param {Array} [array] The array to iterate over.
690 * @param {Function} iteratee The function invoked per iteration.
691 * @param {*} [accumulator] The initial value.
692 * @param {boolean} [initAccum] Specify using the first element of `array` as
693 * the initial value.
694 * @returns {*} Returns the accumulated value.
695 */
696 function arrayReduce(array, iteratee, accumulator, initAccum) {
697 var index = -1,
698 length = array == null ? 0 : array.length;
699
700 if (initAccum && length) {
701 accumulator = array[++index];
702 }
703 while (++index < length) {
704 accumulator = iteratee(accumulator, array[index], index, array);
705 }
706 return accumulator;
707 }
708
709 /**
710 * A specialized version of `_.reduceRight` for arrays without support for
711 * iteratee shorthands.
712 *
713 * @private
714 * @param {Array} [array] The array to iterate over.
715 * @param {Function} iteratee The function invoked per iteration.
716 * @param {*} [accumulator] The initial value.
717 * @param {boolean} [initAccum] Specify using the last element of `array` as
718 * the initial value.
719 * @returns {*} Returns the accumulated value.
720 */
721 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
722 var length = array == null ? 0 : array.length;
723 if (initAccum && length) {
724 accumulator = array[--length];
725 }
726 while (length--) {
727 accumulator = iteratee(accumulator, array[length], length, array);
728 }
729 return accumulator;
730 }
731
732 /**
733 * A specialized version of `_.some` for arrays without support for iteratee
734 * shorthands.
735 *
736 * @private
737 * @param {Array} [array] The array to iterate over.
738 * @param {Function} predicate The function invoked per iteration.
739 * @returns {boolean} Returns `true` if any element passes the predicate check,
740 * else `false`.
741 */
742 function arraySome(array, predicate) {
743 var index = -1,
744 length = array == null ? 0 : array.length;
745
746 while (++index < length) {
747 if (predicate(array[index], index, array)) {
748 return true;
749 }
750 }
751 return false;
752 }
753
754 /**
755 * Gets the size of an ASCII `string`.
756 *
757 * @private
758 * @param {string} string The string inspect.
759 * @returns {number} Returns the string size.
760 */
761 var asciiSize = baseProperty('length');
762
763 /**
764 * Converts an ASCII `string` to an array.
765 *
766 * @private
767 * @param {string} string The string to convert.
768 * @returns {Array} Returns the converted array.
769 */
770 function asciiToArray(string) {
771 return string.split('');
772 }
773
774 /**
775 * Splits an ASCII `string` into an array of its words.
776 *
777 * @private
778 * @param {string} The string to inspect.
779 * @returns {Array} Returns the words of `string`.
780 */
781 function asciiWords(string) {
782 return string.match(reAsciiWord) || [];
783 }
784
785 /**
786 * The base implementation of methods like `_.findKey` and `_.findLastKey`,
787 * without support for iteratee shorthands, which iterates over `collection`
788 * using `eachFunc`.
789 *
790 * @private
791 * @param {Array|Object} collection The collection to inspect.
792 * @param {Function} predicate The function invoked per iteration.
793 * @param {Function} eachFunc The function to iterate over `collection`.
794 * @returns {*} Returns the found element or its key, else `undefined`.
795 */
796 function baseFindKey(collection, predicate, eachFunc) {
797 var result;
798 eachFunc(collection, function(value, key, collection) {
799 if (predicate(value, key, collection)) {
800 result = key;
801 return false;
802 }
803 });
804 return result;
805 }
806
807 /**
808 * The base implementation of `_.findIndex` and `_.findLastIndex` without
809 * support for iteratee shorthands.
810 *
811 * @private
812 * @param {Array} array The array to inspect.
813 * @param {Function} predicate The function invoked per iteration.
814 * @param {number} fromIndex The index to search from.
815 * @param {boolean} [fromRight] Specify iterating from right to left.
816 * @returns {number} Returns the index of the matched value, else `-1`.
817 */
818 function baseFindIndex(array, predicate, fromIndex, fromRight) {
819 var length = array.length,
820 index = fromIndex + (fromRight ? 1 : -1);
821
822 while ((fromRight ? index-- : ++index < length)) {
823 if (predicate(array[index], index, array)) {
824 return index;
825 }
826 }
827 return -1;
828 }
829
830 /**
831 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
832 *
833 * @private
834 * @param {Array} array The array to inspect.
835 * @param {*} value The value to search for.
836 * @param {number} fromIndex The index to search from.
837 * @returns {number} Returns the index of the matched value, else `-1`.
838 */
839 function baseIndexOf(array, value, fromIndex) {
840 return value === value
841 ? strictIndexOf(array, value, fromIndex)
842 : baseFindIndex(array, baseIsNaN, fromIndex);
843 }
844
845 /**
846 * This function is like `baseIndexOf` except that it accepts a comparator.
847 *
848 * @private
849 * @param {Array} array The array to inspect.
850 * @param {*} value The value to search for.
851 * @param {number} fromIndex The index to search from.
852 * @param {Function} comparator The comparator invoked per element.
853 * @returns {number} Returns the index of the matched value, else `-1`.
854 */
855 function baseIndexOfWith(array, value, fromIndex, comparator) {
856 var index = fromIndex - 1,
857 length = array.length;
858
859 while (++index < length) {
860 if (comparator(array[index], value)) {
861 return index;
862 }
863 }
864 return -1;
865 }
866
867 /**
868 * The base implementation of `_.isNaN` without support for number objects.
869 *
870 * @private
871 * @param {*} value The value to check.
872 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
873 */
874 function baseIsNaN(value) {
875 return value !== value;
876 }
877
878 /**
879 * The base implementation of `_.mean` and `_.meanBy` without support for
880 * iteratee shorthands.
881 *
882 * @private
883 * @param {Array} array The array to iterate over.
884 * @param {Function} iteratee The function invoked per iteration.
885 * @returns {number} Returns the mean.
886 */
887 function baseMean(array, iteratee) {
888 var length = array == null ? 0 : array.length;
889 return length ? (baseSum(array, iteratee) / length) : NAN;
890 }
891
892 /**
893 * The base implementation of `_.property` without support for deep paths.
894 *
895 * @private
896 * @param {string} key The key of the property to get.
897 * @returns {Function} Returns the new accessor function.
898 */
899 function baseProperty(key) {
900 return function(object) {
901 return object == null ? undefined : object[key];
902 };
903 }
904
905 /**
906 * The base implementation of `_.propertyOf` without support for deep paths.
907 *
908 * @private
909 * @param {Object} object The object to query.
910 * @returns {Function} Returns the new accessor function.
911 */
912 function basePropertyOf(object) {
913 return function(key) {
914 return object == null ? undefined : object[key];
915 };
916 }
917
918 /**
919 * The base implementation of `_.reduce` and `_.reduceRight`, without support
920 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
921 *
922 * @private
923 * @param {Array|Object} collection The collection to iterate over.
924 * @param {Function} iteratee The function invoked per iteration.
925 * @param {*} accumulator The initial value.
926 * @param {boolean} initAccum Specify using the first or last element of
927 * `collection` as the initial value.
928 * @param {Function} eachFunc The function to iterate over `collection`.
929 * @returns {*} Returns the accumulated value.
930 */
931 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
932 eachFunc(collection, function(value, index, collection) {
933 accumulator = initAccum
934 ? (initAccum = false, value)
935 : iteratee(accumulator, value, index, collection);
936 });
937 return accumulator;
938 }
939
940 /**
941 * The base implementation of `_.sortBy` which uses `comparer` to define the
942 * sort order of `array` and replaces criteria objects with their corresponding
943 * values.
944 *
945 * @private
946 * @param {Array} array The array to sort.
947 * @param {Function} comparer The function to define sort order.
948 * @returns {Array} Returns `array`.
949 */
950 function baseSortBy(array, comparer) {
951 var length = array.length;
952
953 array.sort(comparer);
954 while (length--) {
955 array[length] = array[length].value;
956 }
957 return array;
958 }
959
960 /**
961 * The base implementation of `_.sum` and `_.sumBy` without support for
962 * iteratee shorthands.
963 *
964 * @private
965 * @param {Array} array The array to iterate over.
966 * @param {Function} iteratee The function invoked per iteration.
967 * @returns {number} Returns the sum.
968 */
969 function baseSum(array, iteratee) {
970 var result,
971 index = -1,
972 length = array.length;
973
974 while (++index < length) {
975 var current = iteratee(array[index]);
976 if (current !== undefined) {
977 result = result === undefined ? current : (result + current);
978 }
979 }
980 return result;
981 }
982
983 /**
984 * The base implementation of `_.times` without support for iteratee shorthands
985 * or max array length checks.
986 *
987 * @private
988 * @param {number} n The number of times to invoke `iteratee`.
989 * @param {Function} iteratee The function invoked per iteration.
990 * @returns {Array} Returns the array of results.
991 */
992 function baseTimes(n, iteratee) {
993 var index = -1,
994 result = Array(n);
995
996 while (++index < n) {
997 result[index] = iteratee(index);
998 }
999 return result;
1000 }
1001
1002 /**
1003 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
1004 * of key-value pairs for `object` corresponding to the property names of `props`.
1005 *
1006 * @private
1007 * @param {Object} object The object to query.
1008 * @param {Array} props The property names to get values for.
1009 * @returns {Object} Returns the key-value pairs.
1010 */
1011 function baseToPairs(object, props) {
1012 return arrayMap(props, function(key) {
1013 return [key, object[key]];
1014 });
1015 }
1016
1017 /**
1018 * The base implementation of `_.unary` without support for storing metadata.
1019 *
1020 * @private
1021 * @param {Function} func The function to cap arguments for.
1022 * @returns {Function} Returns the new capped function.
1023 */
1024 function baseUnary(func) {
1025 return function(value) {
1026 return func(value);
1027 };
1028 }
1029
1030 /**
1031 * The base implementation of `_.values` and `_.valuesIn` which creates an
1032 * array of `object` property values corresponding to the property names
1033 * of `props`.
1034 *
1035 * @private
1036 * @param {Object} object The object to query.
1037 * @param {Array} props The property names to get values for.
1038 * @returns {Object} Returns the array of property values.
1039 */
1040 function baseValues(object, props) {
1041 return arrayMap(props, function(key) {
1042 return object[key];
1043 });
1044 }
1045
1046 /**
1047 * Checks if a `cache` value for `key` exists.
1048 *
1049 * @private
1050 * @param {Object} cache The cache to query.
1051 * @param {string} key The key of the entry to check.
1052 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1053 */
1054 function cacheHas(cache, key) {
1055 return cache.has(key);
1056 }
1057
1058 /**
1059 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
1060 * that is not found in the character symbols.
1061 *
1062 * @private
1063 * @param {Array} strSymbols The string symbols to inspect.
1064 * @param {Array} chrSymbols The character symbols to find.
1065 * @returns {number} Returns the index of the first unmatched string symbol.
1066 */
1067 function charsStartIndex(strSymbols, chrSymbols) {
1068 var index = -1,
1069 length = strSymbols.length;
1070
1071 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1072 return index;
1073 }
1074
1075 /**
1076 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
1077 * that is not found in the character symbols.
1078 *
1079 * @private
1080 * @param {Array} strSymbols The string symbols to inspect.
1081 * @param {Array} chrSymbols The character symbols to find.
1082 * @returns {number} Returns the index of the last unmatched string symbol.
1083 */
1084 function charsEndIndex(strSymbols, chrSymbols) {
1085 var index = strSymbols.length;
1086
1087 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1088 return index;
1089 }
1090
1091 /**
1092 * Gets the number of `placeholder` occurrences in `array`.
1093 *
1094 * @private
1095 * @param {Array} array The array to inspect.
1096 * @param {*} placeholder The placeholder to search for.
1097 * @returns {number} Returns the placeholder count.
1098 */
1099 function countHolders(array, placeholder) {
1100 var length = array.length,
1101 result = 0;
1102
1103 while (length--) {
1104 if (array[length] === placeholder) {
1105 ++result;
1106 }
1107 }
1108 return result;
1109 }
1110
1111 /**
1112 * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
1113 * letters to basic Latin letters.
1114 *
1115 * @private
1116 * @param {string} letter The matched letter to deburr.
1117 * @returns {string} Returns the deburred letter.
1118 */
1119 var deburrLetter = basePropertyOf(deburredLetters);
1120
1121 /**
1122 * Used by `_.escape` to convert characters to HTML entities.
1123 *
1124 * @private
1125 * @param {string} chr The matched character to escape.
1126 * @returns {string} Returns the escaped character.
1127 */
1128 var escapeHtmlChar = basePropertyOf(htmlEscapes);
1129
1130 /**
1131 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1132 *
1133 * @private
1134 * @param {string} chr The matched character to escape.
1135 * @returns {string} Returns the escaped character.
1136 */
1137 function escapeStringChar(chr) {
1138 return '\\' + stringEscapes[chr];
1139 }
1140
1141 /**
1142 * Gets the value at `key` of `object`.
1143 *
1144 * @private
1145 * @param {Object} [object] The object to query.
1146 * @param {string} key The key of the property to get.
1147 * @returns {*} Returns the property value.
1148 */
1149 function getValue(object, key) {
1150 return object == null ? undefined : object[key];
1151 }
1152
1153 /**
1154 * Checks if `string` contains Unicode symbols.
1155 *
1156 * @private
1157 * @param {string} string The string to inspect.
1158 * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1159 */
1160 function hasUnicode(string) {
1161 return reHasUnicode.test(string);
1162 }
1163
1164 /**
1165 * Checks if `string` contains a word composed of Unicode symbols.
1166 *
1167 * @private
1168 * @param {string} string The string to inspect.
1169 * @returns {boolean} Returns `true` if a word is found, else `false`.
1170 */
1171 function hasUnicodeWord(string) {
1172 return reHasUnicodeWord.test(string);
1173 }
1174
1175 /**
1176 * Converts `iterator` to an array.
1177 *
1178 * @private
1179 * @param {Object} iterator The iterator to convert.
1180 * @returns {Array} Returns the converted array.
1181 */
1182 function iteratorToArray(iterator) {
1183 var data,
1184 result = [];
1185
1186 while (!(data = iterator.next()).done) {
1187 result.push(data.value);
1188 }
1189 return result;
1190 }
1191
1192 /**
1193 * Converts `map` to its key-value pairs.
1194 *
1195 * @private
1196 * @param {Object} map The map to convert.
1197 * @returns {Array} Returns the key-value pairs.
1198 */
1199 function mapToArray(map) {
1200 var index = -1,
1201 result = Array(map.size);
1202
1203 map.forEach(function(value, key) {
1204 result[++index] = [key, value];
1205 });
1206 return result;
1207 }
1208
1209 /**
1210 * Creates a unary function that invokes `func` with its argument transformed.
1211 *
1212 * @private
1213 * @param {Function} func The function to wrap.
1214 * @param {Function} transform The argument transform.
1215 * @returns {Function} Returns the new function.
1216 */
1217 function overArg(func, transform) {
1218 return function(arg) {
1219 return func(transform(arg));
1220 };
1221 }
1222
1223 /**
1224 * Replaces all `placeholder` elements in `array` with an internal placeholder
1225 * and returns an array of their indexes.
1226 *
1227 * @private
1228 * @param {Array} array The array to modify.
1229 * @param {*} placeholder The placeholder to replace.
1230 * @returns {Array} Returns the new array of placeholder indexes.
1231 */
1232 function replaceHolders(array, placeholder) {
1233 var index = -1,
1234 length = array.length,
1235 resIndex = 0,
1236 result = [];
1237
1238 while (++index < length) {
1239 var value = array[index];
1240 if (value === placeholder || value === PLACEHOLDER) {
1241 array[index] = PLACEHOLDER;
1242 result[resIndex++] = index;
1243 }
1244 }
1245 return result;
1246 }
1247
1248 /**
1249 * Converts `set` to an array of its values.
1250 *
1251 * @private
1252 * @param {Object} set The set to convert.
1253 * @returns {Array} Returns the values.
1254 */
1255 function setToArray(set) {
1256 var index = -1,
1257 result = Array(set.size);
1258
1259 set.forEach(function(value) {
1260 result[++index] = value;
1261 });
1262 return result;
1263 }
1264
1265 /**
1266 * Converts `set` to its value-value pairs.
1267 *
1268 * @private
1269 * @param {Object} set The set to convert.
1270 * @returns {Array} Returns the value-value pairs.
1271 */
1272 function setToPairs(set) {
1273 var index = -1,
1274 result = Array(set.size);
1275
1276 set.forEach(function(value) {
1277 result[++index] = [value, value];
1278 });
1279 return result;
1280 }
1281
1282 /**
1283 * A specialized version of `_.indexOf` which performs strict equality
1284 * comparisons of values, i.e. `===`.
1285 *
1286 * @private
1287 * @param {Array} array The array to inspect.
1288 * @param {*} value The value to search for.
1289 * @param {number} fromIndex The index to search from.
1290 * @returns {number} Returns the index of the matched value, else `-1`.
1291 */
1292 function strictIndexOf(array, value, fromIndex) {
1293 var index = fromIndex - 1,
1294 length = array.length;
1295
1296 while (++index < length) {
1297 if (array[index] === value) {
1298 return index;
1299 }
1300 }
1301 return -1;
1302 }
1303
1304 /**
1305 * A specialized version of `_.lastIndexOf` which performs strict equality
1306 * comparisons of values, i.e. `===`.
1307 *
1308 * @private
1309 * @param {Array} array The array to inspect.
1310 * @param {*} value The value to search for.
1311 * @param {number} fromIndex The index to search from.
1312 * @returns {number} Returns the index of the matched value, else `-1`.
1313 */
1314 function strictLastIndexOf(array, value, fromIndex) {
1315 var index = fromIndex + 1;
1316 while (index--) {
1317 if (array[index] === value) {
1318 return index;
1319 }
1320 }
1321 return index;
1322 }
1323
1324 /**
1325 * Gets the number of symbols in `string`.
1326 *
1327 * @private
1328 * @param {string} string The string to inspect.
1329 * @returns {number} Returns the string size.
1330 */
1331 function stringSize(string) {
1332 return hasUnicode(string)
1333 ? unicodeSize(string)
1334 : asciiSize(string);
1335 }
1336
1337 /**
1338 * Converts `string` to an array.
1339 *
1340 * @private
1341 * @param {string} string The string to convert.
1342 * @returns {Array} Returns the converted array.
1343 */
1344 function stringToArray(string) {
1345 return hasUnicode(string)
1346 ? unicodeToArray(string)
1347 : asciiToArray(string);
1348 }
1349
1350 /**
1351 * Used by `_.unescape` to convert HTML entities to characters.
1352 *
1353 * @private
1354 * @param {string} chr The matched character to unescape.
1355 * @returns {string} Returns the unescaped character.
1356 */
1357 var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
1358
1359 /**
1360 * Gets the size of a Unicode `string`.
1361 *
1362 * @private
1363 * @param {string} string The string inspect.
1364 * @returns {number} Returns the string size.
1365 */
1366 function unicodeSize(string) {
1367 var result = reUnicode.lastIndex = 0;
1368 while (reUnicode.test(string)) {
1369 ++result;
1370 }
1371 return result;
1372 }
1373
1374 /**
1375 * Converts a Unicode `string` to an array.
1376 *
1377 * @private
1378 * @param {string} string The string to convert.
1379 * @returns {Array} Returns the converted array.
1380 */
1381 function unicodeToArray(string) {
1382 return string.match(reUnicode) || [];
1383 }
1384
1385 /**
1386 * Splits a Unicode `string` into an array of its words.
1387 *
1388 * @private
1389 * @param {string} The string to inspect.
1390 * @returns {Array} Returns the words of `string`.
1391 */
1392 function unicodeWords(string) {
1393 return string.match(reUnicodeWord) || [];
1394 }
1395
1396 /*--------------------------------------------------------------------------*/
1397
1398 /**
1399 * Create a new pristine `lodash` function using the `context` object.
1400 *
1401 * @static
1402 * @memberOf _
1403 * @since 1.1.0
1404 * @category Util
1405 * @param {Object} [context=root] The context object.
1406 * @returns {Function} Returns a new `lodash` function.
1407 * @example
1408 *
1409 * _.mixin({ 'foo': _.constant('foo') });
1410 *
1411 * var lodash = _.runInContext();
1412 * lodash.mixin({ 'bar': lodash.constant('bar') });
1413 *
1414 * _.isFunction(_.foo);
1415 * // => true
1416 * _.isFunction(_.bar);
1417 * // => false
1418 *
1419 * lodash.isFunction(lodash.foo);
1420 * // => false
1421 * lodash.isFunction(lodash.bar);
1422 * // => true
1423 *
1424 * // Create a suped-up `defer` in Node.js.
1425 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1426 */
1427 var runInContext = (function runInContext(context) {
1428 context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
1429
1430 /** Built-in constructor references. */
1431 var Array = context.Array,
1432 Date = context.Date,
1433 Error = context.Error,
1434 Function = context.Function,
1435 Math = context.Math,
1436 Object = context.Object,
1437 RegExp = context.RegExp,
1438 String = context.String,
1439 TypeError = context.TypeError;
1440
1441 /** Used for built-in method references. */
1442 var arrayProto = Array.prototype,
1443 funcProto = Function.prototype,
1444 objectProto = Object.prototype;
1445
1446 /** Used to detect overreaching core-js shims. */
1447 var coreJsData = context['__core-js_shared__'];
1448
1449 /** Used to resolve the decompiled source of functions. */
1450 var funcToString = funcProto.toString;
1451
1452 /** Used to check objects for own properties. */
1453 var hasOwnProperty = objectProto.hasOwnProperty;
1454
1455 /** Used to generate unique IDs. */
1456 var idCounter = 0;
1457
1458 /** Used to detect methods masquerading as native. */
1459 var maskSrcKey = (function() {
1460 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
1461 return uid ? ('Symbol(src)_1.' + uid) : '';
1462 }());
1463
1464 /**
1465 * Used to resolve the
1466 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
1467 * of values.
1468 */
1469 var nativeObjectToString = objectProto.toString;
1470
1471 /** Used to infer the `Object` constructor. */
1472 var objectCtorString = funcToString.call(Object);
1473
1474 /** Used to restore the original `_` reference in `_.noConflict`. */
1475 var oldDash = root._;
1476
1477 /** Used to detect if a method is native. */
1478 var reIsNative = RegExp('^' +
1479 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1480 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1481 );
1482
1483 /** Built-in value references. */
1484 var Buffer = moduleExports ? context.Buffer : undefined,
1485 Symbol = context.Symbol,
1486 Uint8Array = context.Uint8Array,
1487 allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
1488 getPrototype = overArg(Object.getPrototypeOf, Object),
1489 objectCreate = Object.create,
1490 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1491 splice = arrayProto.splice,
1492 spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
1493 symIterator = Symbol ? Symbol.iterator : undefined,
1494 symToStringTag = Symbol ? Symbol.toStringTag : undefined;
1495
1496 var defineProperty = (function() {
1497 try {
1498 var func = getNative(Object, 'defineProperty');
1499 func({}, '', {});
1500 return func;
1501 } catch (e) {}
1502 }());
1503
1504 /** Mocked built-ins. */
1505 var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
1506 ctxNow = Date && Date.now !== root.Date.now && Date.now,
1507 ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1508
1509 /* Built-in method references for those with the same name as other `lodash` methods. */
1510 var nativeCeil = Math.ceil,
1511 nativeFloor = Math.floor,
1512 nativeGetSymbols = Object.getOwnPropertySymbols,
1513 nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
1514 nativeIsFinite = context.isFinite,
1515 nativeJoin = arrayProto.join,
1516 nativeKeys = overArg(Object.keys, Object),
1517 nativeMax = Math.max,
1518 nativeMin = Math.min,
1519 nativeNow = Date.now,
1520 nativeParseInt = context.parseInt,
1521 nativeRandom = Math.random,
1522 nativeReverse = arrayProto.reverse;
1523
1524 /* Built-in method references that are verified to be native. */
1525 var DataView = getNative(context, 'DataView'),
1526 Map = getNative(context, 'Map'),
1527 Promise = getNative(context, 'Promise'),
1528 Set = getNative(context, 'Set'),
1529 WeakMap = getNative(context, 'WeakMap'),
1530 nativeCreate = getNative(Object, 'create');
1531
1532 /** Used to store function metadata. */
1533 var metaMap = WeakMap && new WeakMap;
1534
1535 /** Used to lookup unminified function names. */
1536 var realNames = {};
1537
1538 /** Used to detect maps, sets, and weakmaps. */
1539 var dataViewCtorString = toSource(DataView),
1540 mapCtorString = toSource(Map),
1541 promiseCtorString = toSource(Promise),
1542 setCtorString = toSource(Set),
1543 weakMapCtorString = toSource(WeakMap);
1544
1545 /** Used to convert symbols to primitives and strings. */
1546 var symbolProto = Symbol ? Symbol.prototype : undefined,
1547 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
1548 symbolToString = symbolProto ? symbolProto.toString : undefined;
1549
1550 /*------------------------------------------------------------------------*/
1551
1552 /**
1553 * Creates a `lodash` object which wraps `value` to enable implicit method
1554 * chain sequences. Methods that operate on and return arrays, collections,
1555 * and functions can be chained together. Methods that retrieve a single value
1556 * or may return a primitive value will automatically end the chain sequence
1557 * and return the unwrapped value. Otherwise, the value must be unwrapped
1558 * with `_#value`.
1559 *
1560 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
1561 * enabled using `_.chain`.
1562 *
1563 * The execution of chained methods is lazy, that is, it's deferred until
1564 * `_#value` is implicitly or explicitly called.
1565 *
1566 * Lazy evaluation allows several methods to support shortcut fusion.
1567 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
1568 * the creation of intermediate arrays and can greatly reduce the number of
1569 * iteratee executions. Sections of a chain sequence qualify for shortcut
1570 * fusion if the section is applied to an array of at least `200` elements
1571 * and any iteratees accept only one argument. The heuristic for whether a
1572 * section qualifies for shortcut fusion is subject to change.
1573 *
1574 * Chaining is supported in custom builds as long as the `_#value` method is
1575 * directly or indirectly included in the build.
1576 *
1577 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1578 *
1579 * The wrapper `Array` methods are:
1580 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1581 *
1582 * The wrapper `String` methods are:
1583 * `replace` and `split`
1584 *
1585 * The wrapper methods that support shortcut fusion are:
1586 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1587 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1588 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1589 *
1590 * The chainable wrapper methods are:
1591 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
1592 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
1593 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
1594 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
1595 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
1596 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
1597 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
1598 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
1599 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
1600 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
1601 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
1602 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
1603 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
1604 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
1605 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
1606 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
1607 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
1608 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
1609 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
1610 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
1611 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
1612 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
1613 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
1614 * `zipObject`, `zipObjectDeep`, and `zipWith`
1615 *
1616 * The wrapper methods that are **not** chainable by default are:
1617 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1618 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
1619 * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
1620 * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
1621 * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
1622 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
1623 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
1624 * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
1625 * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
1626 * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
1627 * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
1628 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
1629 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
1630 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
1631 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
1632 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
1633 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
1634 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
1635 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
1636 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
1637 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
1638 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
1639 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
1640 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
1641 * `upperFirst`, `value`, and `words`
1642 *
1643 * @name _
1644 * @constructor
1645 * @category Seq
1646 * @param {*} value The value to wrap in a `lodash` instance.
1647 * @returns {Object} Returns the new `lodash` wrapper instance.
1648 * @example
1649 *
1650 * function square(n) {
1651 * return n * n;
1652 * }
1653 *
1654 * var wrapped = _([1, 2, 3]);
1655 *
1656 * // Returns an unwrapped value.
1657 * wrapped.reduce(_.add);
1658 * // => 6
1659 *
1660 * // Returns a wrapped value.
1661 * var squares = wrapped.map(square);
1662 *
1663 * _.isArray(squares);
1664 * // => false
1665 *
1666 * _.isArray(squares.value());
1667 * // => true
1668 */
1669 function lodash(value) {
1670 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1671 if (value instanceof LodashWrapper) {
1672 return value;
1673 }
1674 if (hasOwnProperty.call(value, '__wrapped__')) {
1675 return wrapperClone(value);
1676 }
1677 }
1678 return new LodashWrapper(value);
1679 }
1680
1681 /**
1682 * The base implementation of `_.create` without support for assigning
1683 * properties to the created object.
1684 *
1685 * @private
1686 * @param {Object} proto The object to inherit from.
1687 * @returns {Object} Returns the new object.
1688 */
1689 var baseCreate = (function() {
1690 function object() {}
1691 return function(proto) {
1692 if (!isObject(proto)) {
1693 return {};
1694 }
1695 if (objectCreate) {
1696 return objectCreate(proto);
1697 }
1698 object.prototype = proto;
1699 var result = new object;
1700 object.prototype = undefined;
1701 return result;
1702 };
1703 }());
1704
1705 /**
1706 * The function whose prototype chain sequence wrappers inherit from.
1707 *
1708 * @private
1709 */
1710 function baseLodash() {
1711 // No operation performed.
1712 }
1713
1714 /**
1715 * The base constructor for creating `lodash` wrapper objects.
1716 *
1717 * @private
1718 * @param {*} value The value to wrap.
1719 * @param {boolean} [chainAll] Enable explicit method chain sequences.
1720 */
1721 function LodashWrapper(value, chainAll) {
1722 this.__wrapped__ = value;
1723 this.__actions__ = [];
1724 this.__chain__ = !!chainAll;
1725 this.__index__ = 0;
1726 this.__values__ = undefined;
1727 }
1728
1729 /**
1730 * By default, the template delimiters used by lodash are like those in
1731 * embedded Ruby (ERB). Change the following template settings to use
1732 * alternative delimiters.
1733 *
1734 * @static
1735 * @memberOf _
1736 * @type {Object}
1737 */
1738 lodash.templateSettings = {
1739
1740 /**
1741 * Used to detect `data` property values to be HTML-escaped.
1742 *
1743 * @memberOf _.templateSettings
1744 * @type {RegExp}
1745 */
1746 'escape': reEscape,
1747
1748 /**
1749 * Used to detect code to be evaluated.
1750 *
1751 * @memberOf _.templateSettings
1752 * @type {RegExp}
1753 */
1754 'evaluate': reEvaluate,
1755
1756 /**
1757 * Used to detect `data` property values to inject.
1758 *
1759 * @memberOf _.templateSettings
1760 * @type {RegExp}
1761 */
1762 'interpolate': reInterpolate,
1763
1764 /**
1765 * Used to reference the data object in the template text.
1766 *
1767 * @memberOf _.templateSettings
1768 * @type {string}
1769 */
1770 'variable': '',
1771
1772 /**
1773 * Used to import variables into the compiled template.
1774 *
1775 * @memberOf _.templateSettings
1776 * @type {Object}
1777 */
1778 'imports': {
1779
1780 /**
1781 * A reference to the `lodash` function.
1782 *
1783 * @memberOf _.templateSettings.imports
1784 * @type {Function}
1785 */
1786 '_': lodash
1787 }
1788 };
1789
1790 // Ensure wrappers are instances of `baseLodash`.
1791 lodash.prototype = baseLodash.prototype;
1792 lodash.prototype.constructor = lodash;
1793
1794 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
1795 LodashWrapper.prototype.constructor = LodashWrapper;
1796
1797 /*------------------------------------------------------------------------*/
1798
1799 /**
1800 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1801 *
1802 * @private
1803 * @constructor
1804 * @param {*} value The value to wrap.
1805 */
1806 function LazyWrapper(value) {
1807 this.__wrapped__ = value;
1808 this.__actions__ = [];
1809 this.__dir__ = 1;
1810 this.__filtered__ = false;
1811 this.__iteratees__ = [];
1812 this.__takeCount__ = MAX_ARRAY_LENGTH;
1813 this.__views__ = [];
1814 }
1815
1816 /**
1817 * Creates a clone of the lazy wrapper object.
1818 *
1819 * @private
1820 * @name clone
1821 * @memberOf LazyWrapper
1822 * @returns {Object} Returns the cloned `LazyWrapper` object.
1823 */
1824 function lazyClone() {
1825 var result = new LazyWrapper(this.__wrapped__);
1826 result.__actions__ = copyArray(this.__actions__);
1827 result.__dir__ = this.__dir__;
1828 result.__filtered__ = this.__filtered__;
1829 result.__iteratees__ = copyArray(this.__iteratees__);
1830 result.__takeCount__ = this.__takeCount__;
1831 result.__views__ = copyArray(this.__views__);
1832 return result;
1833 }
1834
1835 /**
1836 * Reverses the direction of lazy iteration.
1837 *
1838 * @private
1839 * @name reverse
1840 * @memberOf LazyWrapper
1841 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1842 */
1843 function lazyReverse() {
1844 if (this.__filtered__) {
1845 var result = new LazyWrapper(this);
1846 result.__dir__ = -1;
1847 result.__filtered__ = true;
1848 } else {
1849 result = this.clone();
1850 result.__dir__ *= -1;
1851 }
1852 return result;
1853 }
1854
1855 /**
1856 * Extracts the unwrapped value from its lazy wrapper.
1857 *
1858 * @private
1859 * @name value
1860 * @memberOf LazyWrapper
1861 * @returns {*} Returns the unwrapped value.
1862 */
1863 function lazyValue() {
1864 var array = this.__wrapped__.value(),
1865 dir = this.__dir__,
1866 isArr = isArray(array),
1867 isRight = dir < 0,
1868 arrLength = isArr ? array.length : 0,
1869 view = getView(0, arrLength, this.__views__),
1870 start = view.start,
1871 end = view.end,
1872 length = end - start,
1873 index = isRight ? end : (start - 1),
1874 iteratees = this.__iteratees__,
1875 iterLength = iteratees.length,
1876 resIndex = 0,
1877 takeCount = nativeMin(length, this.__takeCount__);
1878
1879 if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
1880 (arrLength == length && takeCount == length)) {
1881 return baseWrapperValue(array, this.__actions__);
1882 }
1883 var result = [];
1884
1885 outer:
1886 while (length-- && resIndex < takeCount) {
1887 index += dir;
1888
1889 var iterIndex = -1,
1890 value = array[index];
1891
1892 while (++iterIndex < iterLength) {
1893 var data = iteratees[iterIndex],
1894 iteratee = data.iteratee,
1895 type = data.type,
1896 computed = iteratee(value);
1897
1898 if (type == LAZY_MAP_FLAG) {
1899 value = computed;
1900 } else if (!computed) {
1901 if (type == LAZY_FILTER_FLAG) {
1902 continue outer;
1903 } else {
1904 break outer;
1905 }
1906 }
1907 }
1908 result[resIndex++] = value;
1909 }
1910 return result;
1911 }
1912
1913 // Ensure `LazyWrapper` is an instance of `baseLodash`.
1914 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
1915 LazyWrapper.prototype.constructor = LazyWrapper;
1916
1917 /*------------------------------------------------------------------------*/
1918
1919 /**
1920 * Creates a hash object.
1921 *
1922 * @private
1923 * @constructor
1924 * @param {Array} [entries] The key-value pairs to cache.
1925 */
1926 function Hash(entries) {
1927 var index = -1,
1928 length = entries == null ? 0 : entries.length;
1929
1930 this.clear();
1931 while (++index < length) {
1932 var entry = entries[index];
1933 this.set(entry[0], entry[1]);
1934 }
1935 }
1936
1937 /**
1938 * Removes all key-value entries from the hash.
1939 *
1940 * @private
1941 * @name clear
1942 * @memberOf Hash
1943 */
1944 function hashClear() {
1945 this.__data__ = nativeCreate ? nativeCreate(null) : {};
1946 this.size = 0;
1947 }
1948
1949 /**
1950 * Removes `key` and its value from the hash.
1951 *
1952 * @private
1953 * @name delete
1954 * @memberOf Hash
1955 * @param {Object} hash The hash to modify.
1956 * @param {string} key The key of the value to remove.
1957 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1958 */
1959 function hashDelete(key) {
1960 var result = this.has(key) && delete this.__data__[key];
1961 this.size -= result ? 1 : 0;
1962 return result;
1963 }
1964
1965 /**
1966 * Gets the hash value for `key`.
1967 *
1968 * @private
1969 * @name get
1970 * @memberOf Hash
1971 * @param {string} key The key of the value to get.
1972 * @returns {*} Returns the entry value.
1973 */
1974 function hashGet(key) {
1975 var data = this.__data__;
1976 if (nativeCreate) {
1977 var result = data[key];
1978 return result === HASH_UNDEFINED ? undefined : result;
1979 }
1980 return hasOwnProperty.call(data, key) ? data[key] : undefined;
1981 }
1982
1983 /**
1984 * Checks if a hash value for `key` exists.
1985 *
1986 * @private
1987 * @name has
1988 * @memberOf Hash
1989 * @param {string} key The key of the entry to check.
1990 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1991 */
1992 function hashHas(key) {
1993 var data = this.__data__;
1994 return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
1995 }
1996
1997 /**
1998 * Sets the hash `key` to `value`.
1999 *
2000 * @private
2001 * @name set
2002 * @memberOf Hash
2003 * @param {string} key The key of the value to set.
2004 * @param {*} value The value to set.
2005 * @returns {Object} Returns the hash instance.
2006 */
2007 function hashSet(key, value) {
2008 var data = this.__data__;
2009 this.size += this.has(key) ? 0 : 1;
2010 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
2011 return this;
2012 }
2013
2014 // Add methods to `Hash`.
2015 Hash.prototype.clear = hashClear;
2016 Hash.prototype['delete'] = hashDelete;
2017 Hash.prototype.get = hashGet;
2018 Hash.prototype.has = hashHas;
2019 Hash.prototype.set = hashSet;
2020
2021 /*------------------------------------------------------------------------*/
2022
2023 /**
2024 * Creates an list cache object.
2025 *
2026 * @private
2027 * @constructor
2028 * @param {Array} [entries] The key-value pairs to cache.
2029 */
2030 function ListCache(entries) {
2031 var index = -1,
2032 length = entries == null ? 0 : entries.length;
2033
2034 this.clear();
2035 while (++index < length) {
2036 var entry = entries[index];
2037 this.set(entry[0], entry[1]);
2038 }
2039 }
2040
2041 /**
2042 * Removes all key-value entries from the list cache.
2043 *
2044 * @private
2045 * @name clear
2046 * @memberOf ListCache
2047 */
2048 function listCacheClear() {
2049 this.__data__ = [];
2050 this.size = 0;
2051 }
2052
2053 /**
2054 * Removes `key` and its value from the list cache.
2055 *
2056 * @private
2057 * @name delete
2058 * @memberOf ListCache
2059 * @param {string} key The key of the value to remove.
2060 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2061 */
2062 function listCacheDelete(key) {
2063 var data = this.__data__,
2064 index = assocIndexOf(data, key);
2065
2066 if (index < 0) {
2067 return false;
2068 }
2069 var lastIndex = data.length - 1;
2070 if (index == lastIndex) {
2071 data.pop();
2072 } else {
2073 splice.call(data, index, 1);
2074 }
2075 --this.size;
2076 return true;
2077 }
2078
2079 /**
2080 * Gets the list cache value for `key`.
2081 *
2082 * @private
2083 * @name get
2084 * @memberOf ListCache
2085 * @param {string} key The key of the value to get.
2086 * @returns {*} Returns the entry value.
2087 */
2088 function listCacheGet(key) {
2089 var data = this.__data__,
2090 index = assocIndexOf(data, key);
2091
2092 return index < 0 ? undefined : data[index][1];
2093 }
2094
2095 /**
2096 * Checks if a list cache value for `key` exists.
2097 *
2098 * @private
2099 * @name has
2100 * @memberOf ListCache
2101 * @param {string} key The key of the entry to check.
2102 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2103 */
2104 function listCacheHas(key) {
2105 return assocIndexOf(this.__data__, key) > -1;
2106 }
2107
2108 /**
2109 * Sets the list cache `key` to `value`.
2110 *
2111 * @private
2112 * @name set
2113 * @memberOf ListCache
2114 * @param {string} key The key of the value to set.
2115 * @param {*} value The value to set.
2116 * @returns {Object} Returns the list cache instance.
2117 */
2118 function listCacheSet(key, value) {
2119 var data = this.__data__,
2120 index = assocIndexOf(data, key);
2121
2122 if (index < 0) {
2123 ++this.size;
2124 data.push([key, value]);
2125 } else {
2126 data[index][1] = value;
2127 }
2128 return this;
2129 }
2130
2131 // Add methods to `ListCache`.
2132 ListCache.prototype.clear = listCacheClear;
2133 ListCache.prototype['delete'] = listCacheDelete;
2134 ListCache.prototype.get = listCacheGet;
2135 ListCache.prototype.has = listCacheHas;
2136 ListCache.prototype.set = listCacheSet;
2137
2138 /*------------------------------------------------------------------------*/
2139
2140 /**
2141 * Creates a map cache object to store key-value pairs.
2142 *
2143 * @private
2144 * @constructor
2145 * @param {Array} [entries] The key-value pairs to cache.
2146 */
2147 function MapCache(entries) {
2148 var index = -1,
2149 length = entries == null ? 0 : entries.length;
2150
2151 this.clear();
2152 while (++index < length) {
2153 var entry = entries[index];
2154 this.set(entry[0], entry[1]);
2155 }
2156 }
2157
2158 /**
2159 * Removes all key-value entries from the map.
2160 *
2161 * @private
2162 * @name clear
2163 * @memberOf MapCache
2164 */
2165 function mapCacheClear() {
2166 this.size = 0;
2167 this.__data__ = {
2168 'hash': new Hash,
2169 'map': new (Map || ListCache),
2170 'string': new Hash
2171 };
2172 }
2173
2174 /**
2175 * Removes `key` and its value from the map.
2176 *
2177 * @private
2178 * @name delete
2179 * @memberOf MapCache
2180 * @param {string} key The key of the value to remove.
2181 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2182 */
2183 function mapCacheDelete(key) {
2184 var result = getMapData(this, key)['delete'](key);
2185 this.size -= result ? 1 : 0;
2186 return result;
2187 }
2188
2189 /**
2190 * Gets the map value for `key`.
2191 *
2192 * @private
2193 * @name get
2194 * @memberOf MapCache
2195 * @param {string} key The key of the value to get.
2196 * @returns {*} Returns the entry value.
2197 */
2198 function mapCacheGet(key) {
2199 return getMapData(this, key).get(key);
2200 }
2201
2202 /**
2203 * Checks if a map value for `key` exists.
2204 *
2205 * @private
2206 * @name has
2207 * @memberOf MapCache
2208 * @param {string} key The key of the entry to check.
2209 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2210 */
2211 function mapCacheHas(key) {
2212 return getMapData(this, key).has(key);
2213 }
2214
2215 /**
2216 * Sets the map `key` to `value`.
2217 *
2218 * @private
2219 * @name set
2220 * @memberOf MapCache
2221 * @param {string} key The key of the value to set.
2222 * @param {*} value The value to set.
2223 * @returns {Object} Returns the map cache instance.
2224 */
2225 function mapCacheSet(key, value) {
2226 var data = getMapData(this, key),
2227 size = data.size;
2228
2229 data.set(key, value);
2230 this.size += data.size == size ? 0 : 1;
2231 return this;
2232 }
2233
2234 // Add methods to `MapCache`.
2235 MapCache.prototype.clear = mapCacheClear;
2236 MapCache.prototype['delete'] = mapCacheDelete;
2237 MapCache.prototype.get = mapCacheGet;
2238 MapCache.prototype.has = mapCacheHas;
2239 MapCache.prototype.set = mapCacheSet;
2240
2241 /*------------------------------------------------------------------------*/
2242
2243 /**
2244 *
2245 * Creates an array cache object to store unique values.
2246 *
2247 * @private
2248 * @constructor
2249 * @param {Array} [values] The values to cache.
2250 */
2251 function SetCache(values) {
2252 var index = -1,
2253 length = values == null ? 0 : values.length;
2254
2255 this.__data__ = new MapCache;
2256 while (++index < length) {
2257 this.add(values[index]);
2258 }
2259 }
2260
2261 /**
2262 * Adds `value` to the array cache.
2263 *
2264 * @private
2265 * @name add
2266 * @memberOf SetCache
2267 * @alias push
2268 * @param {*} value The value to cache.
2269 * @returns {Object} Returns the cache instance.
2270 */
2271 function setCacheAdd(value) {
2272 this.__data__.set(value, HASH_UNDEFINED);
2273 return this;
2274 }
2275
2276 /**
2277 * Checks if `value` is in the array cache.
2278 *
2279 * @private
2280 * @name has
2281 * @memberOf SetCache
2282 * @param {*} value The value to search for.
2283 * @returns {number} Returns `true` if `value` is found, else `false`.
2284 */
2285 function setCacheHas(value) {
2286 return this.__data__.has(value);
2287 }
2288
2289 // Add methods to `SetCache`.
2290 SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
2291 SetCache.prototype.has = setCacheHas;
2292
2293 /*------------------------------------------------------------------------*/
2294
2295 /**
2296 * Creates a stack cache object to store key-value pairs.
2297 *
2298 * @private
2299 * @constructor
2300 * @param {Array} [entries] The key-value pairs to cache.
2301 */
2302 function Stack(entries) {
2303 var data = this.__data__ = new ListCache(entries);
2304 this.size = data.size;
2305 }
2306
2307 /**
2308 * Removes all key-value entries from the stack.
2309 *
2310 * @private
2311 * @name clear
2312 * @memberOf Stack
2313 */
2314 function stackClear() {
2315 this.__data__ = new ListCache;
2316 this.size = 0;
2317 }
2318
2319 /**
2320 * Removes `key` and its value from the stack.
2321 *
2322 * @private
2323 * @name delete
2324 * @memberOf Stack
2325 * @param {string} key The key of the value to remove.
2326 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2327 */
2328 function stackDelete(key) {
2329 var data = this.__data__,
2330 result = data['delete'](key);
2331
2332 this.size = data.size;
2333 return result;
2334 }
2335
2336 /**
2337 * Gets the stack value for `key`.
2338 *
2339 * @private
2340 * @name get
2341 * @memberOf Stack
2342 * @param {string} key The key of the value to get.
2343 * @returns {*} Returns the entry value.
2344 */
2345 function stackGet(key) {
2346 return this.__data__.get(key);
2347 }
2348
2349 /**
2350 * Checks if a stack value for `key` exists.
2351 *
2352 * @private
2353 * @name has
2354 * @memberOf Stack
2355 * @param {string} key The key of the entry to check.
2356 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2357 */
2358 function stackHas(key) {
2359 return this.__data__.has(key);
2360 }
2361
2362 /**
2363 * Sets the stack `key` to `value`.
2364 *
2365 * @private
2366 * @name set
2367 * @memberOf Stack
2368 * @param {string} key The key of the value to set.
2369 * @param {*} value The value to set.
2370 * @returns {Object} Returns the stack cache instance.
2371 */
2372 function stackSet(key, value) {
2373 var data = this.__data__;
2374 if (data instanceof ListCache) {
2375 var pairs = data.__data__;
2376 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
2377 pairs.push([key, value]);
2378 this.size = ++data.size;
2379 return this;
2380 }
2381 data = this.__data__ = new MapCache(pairs);
2382 }
2383 data.set(key, value);
2384 this.size = data.size;
2385 return this;
2386 }
2387
2388 // Add methods to `Stack`.
2389 Stack.prototype.clear = stackClear;
2390 Stack.prototype['delete'] = stackDelete;
2391 Stack.prototype.get = stackGet;
2392 Stack.prototype.has = stackHas;
2393 Stack.prototype.set = stackSet;
2394
2395 /*------------------------------------------------------------------------*/
2396
2397 /**
2398 * Creates an array of the enumerable property names of the array-like `value`.
2399 *
2400 * @private
2401 * @param {*} value The value to query.
2402 * @param {boolean} inherited Specify returning inherited property names.
2403 * @returns {Array} Returns the array of property names.
2404 */
2405 function arrayLikeKeys(value, inherited) {
2406 var isArr = isArray(value),
2407 isArg = !isArr && isArguments(value),
2408 isBuff = !isArr && !isArg && isBuffer(value),
2409 isType = !isArr && !isArg && !isBuff && isTypedArray(value),
2410 skipIndexes = isArr || isArg || isBuff || isType,
2411 result = skipIndexes ? baseTimes(value.length, String) : [],
2412 length = result.length;
2413
2414 for (var key in value) {
2415 if ((inherited || hasOwnProperty.call(value, key)) &&
2416 !(skipIndexes && (
2417 // Safari 9 has enumerable `arguments.length` in strict mode.
2418 key == 'length' ||
2419 // Node.js 0.10 has enumerable non-index properties on buffers.
2420 (isBuff && (key == 'offset' || key == 'parent')) ||
2421 // PhantomJS 2 has enumerable non-index properties on typed arrays.
2422 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
2423 // Skip index properties.
2424 isIndex(key, length)
2425 ))) {
2426 result.push(key);
2427 }
2428 }
2429 return result;
2430 }
2431
2432 /**
2433 * A specialized version of `_.sample` for arrays.
2434 *
2435 * @private
2436 * @param {Array} array The array to sample.
2437 * @returns {*} Returns the random element.
2438 */
2439 function arraySample(array) {
2440 var length = array.length;
2441 return length ? array[baseRandom(0, length - 1)] : undefined;
2442 }
2443
2444 /**
2445 * A specialized version of `_.sampleSize` for arrays.
2446 *
2447 * @private
2448 * @param {Array} array The array to sample.
2449 * @param {number} n The number of elements to sample.
2450 * @returns {Array} Returns the random elements.
2451 */
2452 function arraySampleSize(array, n) {
2453 return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
2454 }
2455
2456 /**
2457 * A specialized version of `_.shuffle` for arrays.
2458 *
2459 * @private
2460 * @param {Array} array The array to shuffle.
2461 * @returns {Array} Returns the new shuffled array.
2462 */
2463 function arrayShuffle(array) {
2464 return shuffleSelf(copyArray(array));
2465 }
2466
2467 /**
2468 * Used by `_.defaults` to customize its `_.assignIn` use.
2469 *
2470 * @private
2471 * @param {*} objValue The destination value.
2472 * @param {*} srcValue The source value.
2473 * @param {string} key The key of the property to assign.
2474 * @param {Object} object The parent object of `objValue`.
2475 * @returns {*} Returns the value to assign.
2476 */
2477 function assignInDefaults(objValue, srcValue, key, object) {
2478 if (objValue === undefined ||
2479 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
2480 return srcValue;
2481 }
2482 return objValue;
2483 }
2484
2485 /**
2486 * This function is like `assignValue` except that it doesn't assign
2487 * `undefined` values.
2488 *
2489 * @private
2490 * @param {Object} object The object to modify.
2491 * @param {string} key The key of the property to assign.
2492 * @param {*} value The value to assign.
2493 */
2494 function assignMergeValue(object, key, value) {
2495 if ((value !== undefined && !eq(object[key], value)) ||
2496 (value === undefined && !(key in object))) {
2497 baseAssignValue(object, key, value);
2498 }
2499 }
2500
2501 /**
2502 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2503 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
2504 * for equality comparisons.
2505 *
2506 * @private
2507 * @param {Object} object The object to modify.
2508 * @param {string} key The key of the property to assign.
2509 * @param {*} value The value to assign.
2510 */
2511 function assignValue(object, key, value) {
2512 var objValue = object[key];
2513 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2514 (value === undefined && !(key in object))) {
2515 baseAssignValue(object, key, value);
2516 }
2517 }
2518
2519 /**
2520 * Gets the index at which the `key` is found in `array` of key-value pairs.
2521 *
2522 * @private
2523 * @param {Array} array The array to inspect.
2524 * @param {*} key The key to search for.
2525 * @returns {number} Returns the index of the matched value, else `-1`.
2526 */
2527 function assocIndexOf(array, key) {
2528 var length = array.length;
2529 while (length--) {
2530 if (eq(array[length][0], key)) {
2531 return length;
2532 }
2533 }
2534 return -1;
2535 }
2536
2537 /**
2538 * Aggregates elements of `collection` on `accumulator` with keys transformed
2539 * by `iteratee` and values set by `setter`.
2540 *
2541 * @private
2542 * @param {Array|Object} collection The collection to iterate over.
2543 * @param {Function} setter The function to set `accumulator` values.
2544 * @param {Function} iteratee The iteratee to transform keys.
2545 * @param {Object} accumulator The initial aggregated object.
2546 * @returns {Function} Returns `accumulator`.
2547 */
2548 function baseAggregator(collection, setter, iteratee, accumulator) {
2549 baseEach(collection, function(value, key, collection) {
2550 setter(accumulator, value, iteratee(value), collection);
2551 });
2552 return accumulator;
2553 }
2554
2555 /**
2556 * The base implementation of `_.assign` without support for multiple sources
2557 * or `customizer` functions.
2558 *
2559 * @private
2560 * @param {Object} object The destination object.
2561 * @param {Object} source The source object.
2562 * @returns {Object} Returns `object`.
2563 */
2564 function baseAssign(object, source) {
2565 return object && copyObject(source, keys(source), object);
2566 }
2567
2568 /**
2569 * The base implementation of `_.assignIn` without support for multiple sources
2570 * or `customizer` functions.
2571 *
2572 * @private
2573 * @param {Object} object The destination object.
2574 * @param {Object} source The source object.
2575 * @returns {Object} Returns `object`.
2576 */
2577 function baseAssignIn(object, source) {
2578 return object && copyObject(source, keysIn(source), object);
2579 }
2580
2581 /**
2582 * The base implementation of `assignValue` and `assignMergeValue` without
2583 * value checks.
2584 *
2585 * @private
2586 * @param {Object} object The object to modify.
2587 * @param {string} key The key of the property to assign.
2588 * @param {*} value The value to assign.
2589 */
2590 function baseAssignValue(object, key, value) {
2591 if (key == '__proto__' && defineProperty) {
2592 defineProperty(object, key, {
2593 'configurable': true,
2594 'enumerable': true,
2595 'value': value,
2596 'writable': true
2597 });
2598 } else {
2599 object[key] = value;
2600 }
2601 }
2602
2603 /**
2604 * The base implementation of `_.at` without support for individual paths.
2605 *
2606 * @private
2607 * @param {Object} object The object to iterate over.
2608 * @param {string[]} paths The property paths to pick.
2609 * @returns {Array} Returns the picked elements.
2610 */
2611 function baseAt(object, paths) {
2612 var index = -1,
2613 length = paths.length,
2614 result = Array(length),
2615 skip = object == null;
2616
2617 while (++index < length) {
2618 result[index] = skip ? undefined : get(object, paths[index]);
2619 }
2620 return result;
2621 }
2622
2623 /**
2624 * The base implementation of `_.clamp` which doesn't coerce arguments.
2625 *
2626 * @private
2627 * @param {number} number The number to clamp.
2628 * @param {number} [lower] The lower bound.
2629 * @param {number} upper The upper bound.
2630 * @returns {number} Returns the clamped number.
2631 */
2632 function baseClamp(number, lower, upper) {
2633 if (number === number) {
2634 if (upper !== undefined) {
2635 number = number <= upper ? number : upper;
2636 }
2637 if (lower !== undefined) {
2638 number = number >= lower ? number : lower;
2639 }
2640 }
2641 return number;
2642 }
2643
2644 /**
2645 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2646 * traversed objects.
2647 *
2648 * @private
2649 * @param {*} value The value to clone.
2650 * @param {boolean} bitmask The bitmask flags.
2651 * 1 - Deep clone
2652 * 2 - Flatten inherited properties
2653 * 4 - Clone symbols
2654 * @param {Function} [customizer] The function to customize cloning.
2655 * @param {string} [key] The key of `value`.
2656 * @param {Object} [object] The parent object of `value`.
2657 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2658 * @returns {*} Returns the cloned value.
2659 */
2660 function baseClone(value, bitmask, customizer, key, object, stack) {
2661 var result,
2662 isDeep = bitmask & CLONE_DEEP_FLAG,
2663 isFlat = bitmask & CLONE_FLAT_FLAG,
2664 isFull = bitmask & CLONE_SYMBOLS_FLAG;
2665
2666 if (customizer) {
2667 result = object ? customizer(value, key, object, stack) : customizer(value);
2668 }
2669 if (result !== undefined) {
2670 return result;
2671 }
2672 if (!isObject(value)) {
2673 return value;
2674 }
2675 var isArr = isArray(value);
2676 if (isArr) {
2677 result = initCloneArray(value);
2678 if (!isDeep) {
2679 return copyArray(value, result);
2680 }
2681 } else {
2682 var tag = getTag(value),
2683 isFunc = tag == funcTag || tag == genTag;
2684
2685 if (isBuffer(value)) {
2686 return cloneBuffer(value, isDeep);
2687 }
2688 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2689 result = (isFlat || isFunc) ? {} : initCloneObject(value);
2690 if (!isDeep) {
2691 return isFlat
2692 ? copySymbolsIn(value, baseAssignIn(result, value))
2693 : copySymbols(value, baseAssign(result, value));
2694 }
2695 } else {
2696 if (!cloneableTags[tag]) {
2697 return object ? value : {};
2698 }
2699 result = initCloneByTag(value, tag, baseClone, isDeep);
2700 }
2701 }
2702 // Check for circular references and return its corresponding clone.
2703 stack || (stack = new Stack);
2704 var stacked = stack.get(value);
2705 if (stacked) {
2706 return stacked;
2707 }
2708 stack.set(value, result);
2709
2710 var keysFunc = isFull
2711 ? (isFlat ? getAllKeysIn : getAllKeys)
2712 : (isFlat ? keysIn : keys);
2713
2714 var props = isArr ? undefined : keysFunc(value);
2715 arrayEach(props || value, function(subValue, key) {
2716 if (props) {
2717 key = subValue;
2718 subValue = value[key];
2719 }
2720 // Recursively populate clone (susceptible to call stack limits).
2721 assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
2722 });
2723 return result;
2724 }
2725
2726 /**
2727 * The base implementation of `_.conforms` which doesn't clone `source`.
2728 *
2729 * @private
2730 * @param {Object} source The object of property predicates to conform to.
2731 * @returns {Function} Returns the new spec function.
2732 */
2733 function baseConforms(source) {
2734 var props = keys(source);
2735 return function(object) {
2736 return baseConformsTo(object, source, props);
2737 };
2738 }
2739
2740 /**
2741 * The base implementation of `_.conformsTo` which accepts `props` to check.
2742 *
2743 * @private
2744 * @param {Object} object The object to inspect.
2745 * @param {Object} source The object of property predicates to conform to.
2746 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
2747 */
2748 function baseConformsTo(object, source, props) {
2749 var length = props.length;
2750 if (object == null) {
2751 return !length;
2752 }
2753 object = Object(object);
2754 while (length--) {
2755 var key = props[length],
2756 predicate = source[key],
2757 value = object[key];
2758
2759 if ((value === undefined && !(key in object)) || !predicate(value)) {
2760 return false;
2761 }
2762 }
2763 return true;
2764 }
2765
2766 /**
2767 * The base implementation of `_.delay` and `_.defer` which accepts `args`
2768 * to provide to `func`.
2769 *
2770 * @private
2771 * @param {Function} func The function to delay.
2772 * @param {number} wait The number of milliseconds to delay invocation.
2773 * @param {Array} args The arguments to provide to `func`.
2774 * @returns {number|Object} Returns the timer id or timeout object.
2775 */
2776 function baseDelay(func, wait, args) {
2777 if (typeof func != 'function') {
2778 throw new TypeError(FUNC_ERROR_TEXT);
2779 }
2780 return setTimeout(function() { func.apply(undefined, args); }, wait);
2781 }
2782
2783 /**
2784 * The base implementation of methods like `_.difference` without support
2785 * for excluding multiple arrays or iteratee shorthands.
2786 *
2787 * @private
2788 * @param {Array} array The array to inspect.
2789 * @param {Array} values The values to exclude.
2790 * @param {Function} [iteratee] The iteratee invoked per element.
2791 * @param {Function} [comparator] The comparator invoked per element.
2792 * @returns {Array} Returns the new array of filtered values.
2793 */
2794 function baseDifference(array, values, iteratee, comparator) {
2795 var index = -1,
2796 includes = arrayIncludes,
2797 isCommon = true,
2798 length = array.length,
2799 result = [],
2800 valuesLength = values.length;
2801
2802 if (!length) {
2803 return result;
2804 }
2805 if (iteratee) {
2806 values = arrayMap(values, baseUnary(iteratee));
2807 }
2808 if (comparator) {
2809 includes = arrayIncludesWith;
2810 isCommon = false;
2811 }
2812 else if (values.length >= LARGE_ARRAY_SIZE) {
2813 includes = cacheHas;
2814 isCommon = false;
2815 values = new SetCache(values);
2816 }
2817 outer:
2818 while (++index < length) {
2819 var value = array[index],
2820 computed = iteratee == null ? value : iteratee(value);
2821
2822 value = (comparator || value !== 0) ? value : 0;
2823 if (isCommon && computed === computed) {
2824 var valuesIndex = valuesLength;
2825 while (valuesIndex--) {
2826 if (values[valuesIndex] === computed) {
2827 continue outer;
2828 }
2829 }
2830 result.push(value);
2831 }
2832 else if (!includes(values, computed, comparator)) {
2833 result.push(value);
2834 }
2835 }
2836 return result;
2837 }
2838
2839 /**
2840 * The base implementation of `_.forEach` without support for iteratee shorthands.
2841 *
2842 * @private
2843 * @param {Array|Object} collection The collection to iterate over.
2844 * @param {Function} iteratee The function invoked per iteration.
2845 * @returns {Array|Object} Returns `collection`.
2846 */
2847 var baseEach = createBaseEach(baseForOwn);
2848
2849 /**
2850 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2851 *
2852 * @private
2853 * @param {Array|Object} collection The collection to iterate over.
2854 * @param {Function} iteratee The function invoked per iteration.
2855 * @returns {Array|Object} Returns `collection`.
2856 */
2857 var baseEachRight = createBaseEach(baseForOwnRight, true);
2858
2859 /**
2860 * The base implementation of `_.every` without support for iteratee shorthands.
2861 *
2862 * @private
2863 * @param {Array|Object} collection The collection to iterate over.
2864 * @param {Function} predicate The function invoked per iteration.
2865 * @returns {boolean} Returns `true` if all elements pass the predicate check,
2866 * else `false`
2867 */
2868 function baseEvery(collection, predicate) {
2869 var result = true;
2870 baseEach(collection, function(value, index, collection) {
2871 result = !!predicate(value, index, collection);
2872 return result;
2873 });
2874 return result;
2875 }
2876
2877 /**
2878 * The base implementation of methods like `_.max` and `_.min` which accepts a
2879 * `comparator` to determine the extremum value.
2880 *
2881 * @private
2882 * @param {Array} array The array to iterate over.
2883 * @param {Function} iteratee The iteratee invoked per iteration.
2884 * @param {Function} comparator The comparator used to compare values.
2885 * @returns {*} Returns the extremum value.
2886 */
2887 function baseExtremum(array, iteratee, comparator) {
2888 var index = -1,
2889 length = array.length;
2890
2891 while (++index < length) {
2892 var value = array[index],
2893 current = iteratee(value);
2894
2895 if (current != null && (computed === undefined
2896 ? (current === current && !isSymbol(current))
2897 : comparator(current, computed)
2898 )) {
2899 var computed = current,
2900 result = value;
2901 }
2902 }
2903 return result;
2904 }
2905
2906 /**
2907 * The base implementation of `_.fill` without an iteratee call guard.
2908 *
2909 * @private
2910 * @param {Array} array The array to fill.
2911 * @param {*} value The value to fill `array` with.
2912 * @param {number} [start=0] The start position.
2913 * @param {number} [end=array.length] The end position.
2914 * @returns {Array} Returns `array`.
2915 */
2916 function baseFill(array, value, start, end) {
2917 var length = array.length;
2918
2919 start = toInteger(start);
2920 if (start < 0) {
2921 start = -start > length ? 0 : (length + start);
2922 }
2923 end = (end === undefined || end > length) ? length : toInteger(end);
2924 if (end < 0) {
2925 end += length;
2926 }
2927 end = start > end ? 0 : toLength(end);
2928 while (start < end) {
2929 array[start++] = value;
2930 }
2931 return array;
2932 }
2933
2934 /**
2935 * The base implementation of `_.filter` without support for iteratee shorthands.
2936 *
2937 * @private
2938 * @param {Array|Object} collection The collection to iterate over.
2939 * @param {Function} predicate The function invoked per iteration.
2940 * @returns {Array} Returns the new filtered array.
2941 */
2942 function baseFilter(collection, predicate) {
2943 var result = [];
2944 baseEach(collection, function(value, index, collection) {
2945 if (predicate(value, index, collection)) {
2946 result.push(value);
2947 }
2948 });
2949 return result;
2950 }
2951
2952 /**
2953 * The base implementation of `_.flatten` with support for restricting flattening.
2954 *
2955 * @private
2956 * @param {Array} array The array to flatten.
2957 * @param {number} depth The maximum recursion depth.
2958 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
2959 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
2960 * @param {Array} [result=[]] The initial result value.
2961 * @returns {Array} Returns the new flattened array.
2962 */
2963 function baseFlatten(array, depth, predicate, isStrict, result) {
2964 var index = -1,
2965 length = array.length;
2966
2967 predicate || (predicate = isFlattenable);
2968 result || (result = []);
2969
2970 while (++index < length) {
2971 var value = array[index];
2972 if (depth > 0 && predicate(value)) {
2973 if (depth > 1) {
2974 // Recursively flatten arrays (susceptible to call stack limits).
2975 baseFlatten(value, depth - 1, predicate, isStrict, result);
2976 } else {
2977 arrayPush(result, value);
2978 }
2979 } else if (!isStrict) {
2980 result[result.length] = value;
2981 }
2982 }
2983 return result;
2984 }
2985
2986 /**
2987 * The base implementation of `baseForOwn` which iterates over `object`
2988 * properties returned by `keysFunc` and invokes `iteratee` for each property.
2989 * Iteratee functions may exit iteration early by explicitly returning `false`.
2990 *
2991 * @private
2992 * @param {Object} object The object to iterate over.
2993 * @param {Function} iteratee The function invoked per iteration.
2994 * @param {Function} keysFunc The function to get the keys of `object`.
2995 * @returns {Object} Returns `object`.
2996 */
2997 var baseFor = createBaseFor();
2998
2999 /**
3000 * This function is like `baseFor` except that it iterates over properties
3001 * in the opposite order.
3002 *
3003 * @private
3004 * @param {Object} object The object to iterate over.
3005 * @param {Function} iteratee The function invoked per iteration.
3006 * @param {Function} keysFunc The function to get the keys of `object`.
3007 * @returns {Object} Returns `object`.
3008 */
3009 var baseForRight = createBaseFor(true);
3010
3011 /**
3012 * The base implementation of `_.forOwn` without support for iteratee shorthands.
3013 *
3014 * @private
3015 * @param {Object} object The object to iterate over.
3016 * @param {Function} iteratee The function invoked per iteration.
3017 * @returns {Object} Returns `object`.
3018 */
3019 function baseForOwn(object, iteratee) {
3020 return object && baseFor(object, iteratee, keys);
3021 }
3022
3023 /**
3024 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
3025 *
3026 * @private
3027 * @param {Object} object The object to iterate over.
3028 * @param {Function} iteratee The function invoked per iteration.
3029 * @returns {Object} Returns `object`.
3030 */
3031 function baseForOwnRight(object, iteratee) {
3032 return object && baseForRight(object, iteratee, keys);
3033 }
3034
3035 /**
3036 * The base implementation of `_.functions` which creates an array of
3037 * `object` function property names filtered from `props`.
3038 *
3039 * @private
3040 * @param {Object} object The object to inspect.
3041 * @param {Array} props The property names to filter.
3042 * @returns {Array} Returns the function names.
3043 */
3044 function baseFunctions(object, props) {
3045 return arrayFilter(props, function(key) {
3046 return isFunction(object[key]);
3047 });
3048 }
3049
3050 /**
3051 * The base implementation of `_.get` without support for default values.
3052 *
3053 * @private
3054 * @param {Object} object The object to query.
3055 * @param {Array|string} path The path of the property to get.
3056 * @returns {*} Returns the resolved value.
3057 */
3058 function baseGet(object, path) {
3059 path = isKey(path, object) ? [path] : castPath(path);
3060
3061 var index = 0,
3062 length = path.length;
3063
3064 while (object != null && index < length) {
3065 object = object[toKey(path[index++])];
3066 }
3067 return (index && index == length) ? object : undefined;
3068 }
3069
3070 /**
3071 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
3072 * `keysFunc` and `symbolsFunc` to get the enumerable property names and
3073 * symbols of `object`.
3074 *
3075 * @private
3076 * @param {Object} object The object to query.
3077 * @param {Function} keysFunc The function to get the keys of `object`.
3078 * @param {Function} symbolsFunc The function to get the symbols of `object`.
3079 * @returns {Array} Returns the array of property names and symbols.
3080 */
3081 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
3082 var result = keysFunc(object);
3083 return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
3084 }
3085
3086 /**
3087 * The base implementation of `getTag` without fallbacks for buggy environments.
3088 *
3089 * @private
3090 * @param {*} value The value to query.
3091 * @returns {string} Returns the `toStringTag`.
3092 */
3093 function baseGetTag(value) {
3094 if (value == null) {
3095 return value === undefined ? undefinedTag : nullTag;
3096 }
3097 value = Object(value);
3098 return (symToStringTag && symToStringTag in value)
3099 ? getRawTag(value)
3100 : objectToString(value);
3101 }
3102
3103 /**
3104 * The base implementation of `_.gt` which doesn't coerce arguments.
3105 *
3106 * @private
3107 * @param {*} value The value to compare.
3108 * @param {*} other The other value to compare.
3109 * @returns {boolean} Returns `true` if `value` is greater than `other`,
3110 * else `false`.
3111 */
3112 function baseGt(value, other) {
3113 return value > other;
3114 }
3115
3116 /**
3117 * The base implementation of `_.has` without support for deep paths.
3118 *
3119 * @private
3120 * @param {Object} [object] The object to query.
3121 * @param {Array|string} key The key to check.
3122 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3123 */
3124 function baseHas(object, key) {
3125 return object != null && hasOwnProperty.call(object, key);
3126 }
3127
3128 /**
3129 * The base implementation of `_.hasIn` without support for deep paths.
3130 *
3131 * @private
3132 * @param {Object} [object] The object to query.
3133 * @param {Array|string} key The key to check.
3134 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3135 */
3136 function baseHasIn(object, key) {
3137 return object != null && key in Object(object);
3138 }
3139
3140 /**
3141 * The base implementation of `_.inRange` which doesn't coerce arguments.
3142 *
3143 * @private
3144 * @param {number} number The number to check.
3145 * @param {number} start The start of the range.
3146 * @param {number} end The end of the range.
3147 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
3148 */
3149 function baseInRange(number, start, end) {
3150 return number >= nativeMin(start, end) && number < nativeMax(start, end);
3151 }
3152
3153 /**
3154 * The base implementation of methods like `_.intersection`, without support
3155 * for iteratee shorthands, that accepts an array of arrays to inspect.
3156 *
3157 * @private
3158 * @param {Array} arrays The arrays to inspect.
3159 * @param {Function} [iteratee] The iteratee invoked per element.
3160 * @param {Function} [comparator] The comparator invoked per element.
3161 * @returns {Array} Returns the new array of shared values.
3162 */
3163 function baseIntersection(arrays, iteratee, comparator) {
3164 var includes = comparator ? arrayIncludesWith : arrayIncludes,
3165 length = arrays[0].length,
3166 othLength = arrays.length,
3167 othIndex = othLength,
3168 caches = Array(othLength),
3169 maxLength = Infinity,
3170 result = [];
3171
3172 while (othIndex--) {
3173 var array = arrays[othIndex];
3174 if (othIndex && iteratee) {
3175 array = arrayMap(array, baseUnary(iteratee));
3176 }
3177 maxLength = nativeMin(array.length, maxLength);
3178 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
3179 ? new SetCache(othIndex && array)
3180 : undefined;
3181 }
3182 array = arrays[0];
3183
3184 var index = -1,
3185 seen = caches[0];
3186
3187 outer:
3188 while (++index < length && result.length < maxLength) {
3189 var value = array[index],
3190 computed = iteratee ? iteratee(value) : value;
3191
3192 value = (comparator || value !== 0) ? value : 0;
3193 if (!(seen
3194 ? cacheHas(seen, computed)
3195 : includes(result, computed, comparator)
3196 )) {
3197 othIndex = othLength;
3198 while (--othIndex) {
3199 var cache = caches[othIndex];
3200 if (!(cache
3201 ? cacheHas(cache, computed)
3202 : includes(arrays[othIndex], computed, comparator))
3203 ) {
3204 continue outer;
3205 }
3206 }
3207 if (seen) {
3208 seen.push(computed);
3209 }
3210 result.push(value);
3211 }
3212 }
3213 return result;
3214 }
3215
3216 /**
3217 * The base implementation of `_.invert` and `_.invertBy` which inverts
3218 * `object` with values transformed by `iteratee` and set by `setter`.
3219 *
3220 * @private
3221 * @param {Object} object The object to iterate over.
3222 * @param {Function} setter The function to set `accumulator` values.
3223 * @param {Function} iteratee The iteratee to transform values.
3224 * @param {Object} accumulator The initial inverted object.
3225 * @returns {Function} Returns `accumulator`.
3226 */
3227 function baseInverter(object, setter, iteratee, accumulator) {
3228 baseForOwn(object, function(value, key, object) {
3229 setter(accumulator, iteratee(value), key, object);
3230 });
3231 return accumulator;
3232 }
3233
3234 /**
3235 * The base implementation of `_.invoke` without support for individual
3236 * method arguments.
3237 *
3238 * @private
3239 * @param {Object} object The object to query.
3240 * @param {Array|string} path The path of the method to invoke.
3241 * @param {Array} args The arguments to invoke the method with.
3242 * @returns {*} Returns the result of the invoked method.
3243 */
3244 function baseInvoke(object, path, args) {
3245 if (!isKey(path, object)) {
3246 path = castPath(path);
3247 object = parent(object, path);
3248 path = last(path);
3249 }
3250 var func = object == null ? object : object[toKey(path)];
3251 return func == null ? undefined : apply(func, object, args);
3252 }
3253
3254 /**
3255 * The base implementation of `_.isArguments`.
3256 *
3257 * @private
3258 * @param {*} value The value to check.
3259 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
3260 */
3261 function baseIsArguments(value) {
3262 return isObjectLike(value) && baseGetTag(value) == argsTag;
3263 }
3264
3265 /**
3266 * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
3267 *
3268 * @private
3269 * @param {*} value The value to check.
3270 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
3271 */
3272 function baseIsArrayBuffer(value) {
3273 return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
3274 }
3275
3276 /**
3277 * The base implementation of `_.isDate` without Node.js optimizations.
3278 *
3279 * @private
3280 * @param {*} value The value to check.
3281 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
3282 */
3283 function baseIsDate(value) {
3284 return isObjectLike(value) && baseGetTag(value) == dateTag;
3285 }
3286
3287 /**
3288 * The base implementation of `_.isEqual` which supports partial comparisons
3289 * and tracks traversed objects.
3290 *
3291 * @private
3292 * @param {*} value The value to compare.
3293 * @param {*} other The other value to compare.
3294 * @param {boolean} bitmask The bitmask flags.
3295 * 1 - Unordered comparison
3296 * 2 - Partial comparison
3297 * @param {Function} [customizer] The function to customize comparisons.
3298 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
3299 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3300 */
3301 function baseIsEqual(value, other, bitmask, customizer, stack) {
3302 if (value === other) {
3303 return true;
3304 }
3305 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
3306 return value !== value && other !== other;
3307 }
3308 return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
3309 }
3310
3311 /**
3312 * A specialized version of `baseIsEqual` for arrays and objects which performs
3313 * deep comparisons and tracks traversed objects enabling objects with circular
3314 * references to be compared.
3315 *
3316 * @private
3317 * @param {Object} object The object to compare.
3318 * @param {Object} other The other object to compare.
3319 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
3320 * @param {Function} customizer The function to customize comparisons.
3321 * @param {Function} equalFunc The function to determine equivalents of values.
3322 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
3323 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3324 */
3325 function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
3326 var objIsArr = isArray(object),
3327 othIsArr = isArray(other),
3328 objTag = arrayTag,
3329 othTag = arrayTag;
3330
3331 if (!objIsArr) {
3332 objTag = getTag(object);
3333 objTag = objTag == argsTag ? objectTag : objTag;
3334 }
3335 if (!othIsArr) {
3336 othTag = getTag(other);
3337 othTag = othTag == argsTag ? objectTag : othTag;
3338 }
3339 var objIsObj = objTag == objectTag,
3340 othIsObj = othTag == objectTag,
3341 isSameTag = objTag == othTag;
3342
3343 if (isSameTag && isBuffer(object)) {
3344 if (!isBuffer(other)) {
3345 return false;
3346 }
3347 objIsArr = true;
3348 objIsObj = false;
3349 }
3350 if (isSameTag && !objIsObj) {
3351 stack || (stack = new Stack);
3352 return (objIsArr || isTypedArray(object))
3353 ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
3354 : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
3355 }
3356 if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
3357 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
3358 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
3359
3360 if (objIsWrapped || othIsWrapped) {
3361 var objUnwrapped = objIsWrapped ? object.value() : object,
3362 othUnwrapped = othIsWrapped ? other.value() : other;
3363
3364 stack || (stack = new Stack);
3365 return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
3366 }
3367 }
3368 if (!isSameTag) {
3369 return false;
3370 }
3371 stack || (stack = new Stack);
3372 return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
3373 }
3374
3375 /**
3376 * The base implementation of `_.isMap` without Node.js optimizations.
3377 *
3378 * @private
3379 * @param {*} value The value to check.
3380 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
3381 */
3382 function baseIsMap(value) {
3383 return isObjectLike(value) && getTag(value) == mapTag;
3384 }
3385
3386 /**
3387 * The base implementation of `_.isMatch` without support for iteratee shorthands.
3388 *
3389 * @private
3390 * @param {Object} object The object to inspect.
3391 * @param {Object} source The object of property values to match.
3392 * @param {Array} matchData The property names, values, and compare flags to match.
3393 * @param {Function} [customizer] The function to customize comparisons.
3394 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
3395 */
3396 function baseIsMatch(object, source, matchData, customizer) {
3397 var index = matchData.length,
3398 length = index,
3399 noCustomizer = !customizer;
3400
3401 if (object == null) {
3402 return !length;
3403 }
3404 object = Object(object);
3405 while (index--) {
3406 var data = matchData[index];
3407 if ((noCustomizer && data[2])
3408 ? data[1] !== object[data[0]]
3409 : !(data[0] in object)
3410 ) {
3411 return false;
3412 }
3413 }
3414 while (++index < length) {
3415 data = matchData[index];
3416 var key = data[0],
3417 objValue = object[key],
3418 srcValue = data[1];
3419
3420 if (noCustomizer && data[2]) {
3421 if (objValue === undefined && !(key in object)) {
3422 return false;
3423 }
3424 } else {
3425 var stack = new Stack;
3426 if (customizer) {
3427 var result = customizer(objValue, srcValue, key, object, source, stack);
3428 }
3429 if (!(result === undefined
3430 ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
3431 : result
3432 )) {
3433 return false;
3434 }
3435 }
3436 }
3437 return true;
3438 }
3439
3440 /**
3441 * The base implementation of `_.isNative` without bad shim checks.
3442 *
3443 * @private
3444 * @param {*} value The value to check.
3445 * @returns {boolean} Returns `true` if `value` is a native function,
3446 * else `false`.
3447 */
3448 function baseIsNative(value) {
3449 if (!isObject(value) || isMasked(value)) {
3450 return false;
3451 }
3452 var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3453 return pattern.test(toSource(value));
3454 }
3455
3456 /**
3457 * The base implementation of `_.isRegExp` without Node.js optimizations.
3458 *
3459 * @private
3460 * @param {*} value The value to check.
3461 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
3462 */
3463 function baseIsRegExp(value) {
3464 return isObjectLike(value) && baseGetTag(value) == regexpTag;
3465 }
3466
3467 /**
3468 * The base implementation of `_.isSet` without Node.js optimizations.
3469 *
3470 * @private
3471 * @param {*} value The value to check.
3472 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
3473 */
3474 function baseIsSet(value) {
3475 return isObjectLike(value) && getTag(value) == setTag;
3476 }
3477
3478 /**
3479 * The base implementation of `_.isTypedArray` without Node.js optimizations.
3480 *
3481 * @private
3482 * @param {*} value The value to check.
3483 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
3484 */
3485 function baseIsTypedArray(value) {
3486 return isObjectLike(value) &&
3487 isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
3488 }
3489
3490 /**
3491 * The base implementation of `_.iteratee`.
3492 *
3493 * @private
3494 * @param {*} [value=_.identity] The value to convert to an iteratee.
3495 * @returns {Function} Returns the iteratee.
3496 */
3497 function baseIteratee(value) {
3498 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
3499 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
3500 if (typeof value == 'function') {
3501 return value;
3502 }
3503 if (value == null) {
3504 return identity;
3505 }
3506 if (typeof value == 'object') {
3507 return isArray(value)
3508 ? baseMatchesProperty(value[0], value[1])
3509 : baseMatches(value);
3510 }
3511 return property(value);
3512 }
3513
3514 /**
3515 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
3516 *
3517 * @private
3518 * @param {Object} object The object to query.
3519 * @returns {Array} Returns the array of property names.
3520 */
3521 function baseKeys(object) {
3522 if (!isPrototype(object)) {
3523 return nativeKeys(object);
3524 }
3525 var result = [];
3526 for (var key in Object(object)) {
3527 if (hasOwnProperty.call(object, key) && key != 'constructor') {
3528 result.push(key);
3529 }
3530 }
3531 return result;
3532 }
3533
3534 /**
3535 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
3536 *
3537 * @private
3538 * @param {Object} object The object to query.
3539 * @returns {Array} Returns the array of property names.
3540 */
3541 function baseKeysIn(object) {
3542 if (!isObject(object)) {
3543 return nativeKeysIn(object);
3544 }
3545 var isProto = isPrototype(object),
3546 result = [];
3547
3548 for (var key in object) {
3549 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3550 result.push(key);
3551 }
3552 }
3553 return result;
3554 }
3555
3556 /**
3557 * The base implementation of `_.lt` which doesn't coerce arguments.
3558 *
3559 * @private
3560 * @param {*} value The value to compare.
3561 * @param {*} other The other value to compare.
3562 * @returns {boolean} Returns `true` if `value` is less than `other`,
3563 * else `false`.
3564 */
3565 function baseLt(value, other) {
3566 return value < other;
3567 }
3568
3569 /**
3570 * The base implementation of `_.map` without support for iteratee shorthands.
3571 *
3572 * @private
3573 * @param {Array|Object} collection The collection to iterate over.
3574 * @param {Function} iteratee The function invoked per iteration.
3575 * @returns {Array} Returns the new mapped array.
3576 */
3577 function baseMap(collection, iteratee) {
3578 var index = -1,
3579 result = isArrayLike(collection) ? Array(collection.length) : [];
3580
3581 baseEach(collection, function(value, key, collection) {
3582 result[++index] = iteratee(value, key, collection);
3583 });
3584 return result;
3585 }
3586
3587 /**
3588 * The base implementation of `_.matches` which doesn't clone `source`.
3589 *
3590 * @private
3591 * @param {Object} source The object of property values to match.
3592 * @returns {Function} Returns the new spec function.
3593 */
3594 function baseMatches(source) {
3595 var matchData = getMatchData(source);
3596 if (matchData.length == 1 && matchData[0][2]) {
3597 return matchesStrictComparable(matchData[0][0], matchData[0][1]);
3598 }
3599 return function(object) {
3600 return object === source || baseIsMatch(object, source, matchData);
3601 };
3602 }
3603
3604 /**
3605 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3606 *
3607 * @private
3608 * @param {string} path The path of the property to get.
3609 * @param {*} srcValue The value to match.
3610 * @returns {Function} Returns the new spec function.
3611 */
3612 function baseMatchesProperty(path, srcValue) {
3613 if (isKey(path) && isStrictComparable(srcValue)) {
3614 return matchesStrictComparable(toKey(path), srcValue);
3615 }
3616 return function(object) {
3617 var objValue = get(object, path);
3618 return (objValue === undefined && objValue === srcValue)
3619 ? hasIn(object, path)
3620 : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
3621 };
3622 }
3623
3624 /**
3625 * The base implementation of `_.merge` without support for multiple sources.
3626 *
3627 * @private
3628 * @param {Object} object The destination object.
3629 * @param {Object} source The source object.
3630 * @param {number} srcIndex The index of `source`.
3631 * @param {Function} [customizer] The function to customize merged values.
3632 * @param {Object} [stack] Tracks traversed source values and their merged
3633 * counterparts.
3634 */
3635 function baseMerge(object, source, srcIndex, customizer, stack) {
3636 if (object === source) {
3637 return;
3638 }
3639 baseFor(source, function(srcValue, key) {
3640 if (isObject(srcValue)) {
3641 stack || (stack = new Stack);
3642 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3643 }
3644 else {
3645 var newValue = customizer
3646 ? customizer(object[key], srcValue, (key + ''), object, source, stack)
3647 : undefined;
3648
3649 if (newValue === undefined) {
3650 newValue = srcValue;
3651 }
3652 assignMergeValue(object, key, newValue);
3653 }
3654 }, keysIn);
3655 }
3656
3657 /**
3658 * A specialized version of `baseMerge` for arrays and objects which performs
3659 * deep merges and tracks traversed objects enabling objects with circular
3660 * references to be merged.
3661 *
3662 * @private
3663 * @param {Object} object The destination object.
3664 * @param {Object} source The source object.
3665 * @param {string} key The key of the value to merge.
3666 * @param {number} srcIndex The index of `source`.
3667 * @param {Function} mergeFunc The function to merge values.
3668 * @param {Function} [customizer] The function to customize assigned values.
3669 * @param {Object} [stack] Tracks traversed source values and their merged
3670 * counterparts.
3671 */
3672 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3673 var objValue = object[key],
3674 srcValue = source[key],
3675 stacked = stack.get(srcValue);
3676
3677 if (stacked) {
3678 assignMergeValue(object, key, stacked);
3679 return;
3680 }
3681 var newValue = customizer
3682 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3683 : undefined;
3684
3685 var isCommon = newValue === undefined;
3686
3687 if (isCommon) {
3688 var isArr = isArray(srcValue),
3689 isBuff = !isArr && isBuffer(srcValue),
3690 isTyped = !isArr && !isBuff && isTypedArray(srcValue);
3691
3692 newValue = srcValue;
3693 if (isArr || isBuff || isTyped) {
3694 if (isArray(objValue)) {
3695 newValue = objValue;
3696 }
3697 else if (isArrayLikeObject(objValue)) {
3698 newValue = copyArray(objValue);
3699 }
3700 else if (isBuff) {
3701 isCommon = false;
3702 newValue = cloneBuffer(srcValue, true);
3703 }
3704 else if (isTyped) {
3705 isCommon = false;
3706 newValue = cloneTypedArray(srcValue, true);
3707 }
3708 else {
3709 newValue = [];
3710 }
3711 }
3712 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3713 newValue = objValue;
3714 if (isArguments(objValue)) {
3715 newValue = toPlainObject(objValue);
3716 }
3717 else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
3718 newValue = initCloneObject(srcValue);
3719 }
3720 }
3721 else {
3722 isCommon = false;
3723 }
3724 }
3725 if (isCommon) {
3726 // Recursively merge objects and arrays (susceptible to call stack limits).
3727 stack.set(srcValue, newValue);
3728 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3729 stack['delete'](srcValue);
3730 }
3731 assignMergeValue(object, key, newValue);
3732 }
3733
3734 /**
3735 * The base implementation of `_.nth` which doesn't coerce arguments.
3736 *
3737 * @private
3738 * @param {Array} array The array to query.
3739 * @param {number} n The index of the element to return.
3740 * @returns {*} Returns the nth element of `array`.
3741 */
3742 function baseNth(array, n) {
3743 var length = array.length;
3744 if (!length) {
3745 return;
3746 }
3747 n += n < 0 ? length : 0;
3748 return isIndex(n, length) ? array[n] : undefined;
3749 }
3750
3751 /**
3752 * The base implementation of `_.orderBy` without param guards.
3753 *
3754 * @private
3755 * @param {Array|Object} collection The collection to iterate over.
3756 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3757 * @param {string[]} orders The sort orders of `iteratees`.
3758 * @returns {Array} Returns the new sorted array.
3759 */
3760 function baseOrderBy(collection, iteratees, orders) {
3761 var index = -1;
3762 iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
3763
3764 var result = baseMap(collection, function(value, key, collection) {
3765 var criteria = arrayMap(iteratees, function(iteratee) {
3766 return iteratee(value);
3767 });
3768 return { 'criteria': criteria, 'index': ++index, 'value': value };
3769 });
3770
3771 return baseSortBy(result, function(object, other) {
3772 return compareMultiple(object, other, orders);
3773 });
3774 }
3775
3776 /**
3777 * The base implementation of `_.pick` without support for individual
3778 * property identifiers.
3779 *
3780 * @private
3781 * @param {Object} object The source object.
3782 * @param {string[]} paths The property paths to pick.
3783 * @returns {Object} Returns the new object.
3784 */
3785 function basePick(object, paths) {
3786 object = Object(object);
3787 return basePickBy(object, paths, function(value, path) {
3788 return hasIn(object, path);
3789 });
3790 }
3791
3792 /**
3793 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3794 *
3795 * @private
3796 * @param {Object} object The source object.
3797 * @param {string[]} paths The property paths to pick.
3798 * @param {Function} predicate The function invoked per property.
3799 * @returns {Object} Returns the new object.
3800 */
3801 function basePickBy(object, paths, predicate) {
3802 var index = -1,
3803 length = paths.length,
3804 result = {};
3805
3806 while (++index < length) {
3807 var path = paths[index],
3808 value = baseGet(object, path);
3809
3810 if (predicate(value, path)) {
3811 baseSet(result, path, value);
3812 }
3813 }
3814 return result;
3815 }
3816
3817 /**
3818 * A specialized version of `baseProperty` which supports deep paths.
3819 *
3820 * @private
3821 * @param {Array|string} path The path of the property to get.
3822 * @returns {Function} Returns the new accessor function.
3823 */
3824 function basePropertyDeep(path) {
3825 return function(object) {
3826 return baseGet(object, path);
3827 };
3828 }
3829
3830 /**
3831 * The base implementation of `_.pullAllBy` without support for iteratee
3832 * shorthands.
3833 *
3834 * @private
3835 * @param {Array} array The array to modify.
3836 * @param {Array} values The values to remove.
3837 * @param {Function} [iteratee] The iteratee invoked per element.
3838 * @param {Function} [comparator] The comparator invoked per element.
3839 * @returns {Array} Returns `array`.
3840 */
3841 function basePullAll(array, values, iteratee, comparator) {
3842 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
3843 index = -1,
3844 length = values.length,
3845 seen = array;
3846
3847 if (array === values) {
3848 values = copyArray(values);
3849 }
3850 if (iteratee) {
3851 seen = arrayMap(array, baseUnary(iteratee));
3852 }
3853 while (++index < length) {
3854 var fromIndex = 0,
3855 value = values[index],
3856 computed = iteratee ? iteratee(value) : value;
3857
3858 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
3859 if (seen !== array) {
3860 splice.call(seen, fromIndex, 1);
3861 }
3862 splice.call(array, fromIndex, 1);
3863 }
3864 }
3865 return array;
3866 }
3867
3868 /**
3869 * The base implementation of `_.pullAt` without support for individual
3870 * indexes or capturing the removed elements.
3871 *
3872 * @private
3873 * @param {Array} array The array to modify.
3874 * @param {number[]} indexes The indexes of elements to remove.
3875 * @returns {Array} Returns `array`.
3876 */
3877 function basePullAt(array, indexes) {
3878 var length = array ? indexes.length : 0,
3879 lastIndex = length - 1;
3880
3881 while (length--) {
3882 var index = indexes[length];
3883 if (length == lastIndex || index !== previous) {
3884 var previous = index;
3885 if (isIndex(index)) {
3886 splice.call(array, index, 1);
3887 }
3888 else if (!isKey(index, array)) {
3889 var path = castPath(index),
3890 object = parent(array, path);
3891
3892 if (object != null) {
3893 delete object[toKey(last(path))];
3894 }
3895 }
3896 else {
3897 delete array[toKey(index)];
3898 }
3899 }
3900 }
3901 return array;
3902 }
3903
3904 /**
3905 * The base implementation of `_.random` without support for returning
3906 * floating-point numbers.
3907 *
3908 * @private
3909 * @param {number} lower The lower bound.
3910 * @param {number} upper The upper bound.
3911 * @returns {number} Returns the random number.
3912 */
3913 function baseRandom(lower, upper) {
3914 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3915 }
3916
3917 /**
3918 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3919 * coerce arguments.
3920 *
3921 * @private
3922 * @param {number} start The start of the range.
3923 * @param {number} end The end of the range.
3924 * @param {number} step The value to increment or decrement by.
3925 * @param {boolean} [fromRight] Specify iterating from right to left.
3926 * @returns {Array} Returns the range of numbers.
3927 */
3928 function baseRange(start, end, step, fromRight) {
3929 var index = -1,
3930 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3931 result = Array(length);
3932
3933 while (length--) {
3934 result[fromRight ? length : ++index] = start;
3935 start += step;
3936 }
3937 return result;
3938 }
3939
3940 /**
3941 * The base implementation of `_.repeat` which doesn't coerce arguments.
3942 *
3943 * @private
3944 * @param {string} string The string to repeat.
3945 * @param {number} n The number of times to repeat the string.
3946 * @returns {string} Returns the repeated string.
3947 */
3948 function baseRepeat(string, n) {
3949 var result = '';
3950 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
3951 return result;
3952 }
3953 // Leverage the exponentiation by squaring algorithm for a faster repeat.
3954 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
3955 do {
3956 if (n % 2) {
3957 result += string;
3958 }
3959 n = nativeFloor(n / 2);
3960 if (n) {
3961 string += string;
3962 }
3963 } while (n);
3964
3965 return result;
3966 }
3967
3968 /**
3969 * The base implementation of `_.rest` which doesn't validate or coerce arguments.
3970 *
3971 * @private
3972 * @param {Function} func The function to apply a rest parameter to.
3973 * @param {number} [start=func.length-1] The start position of the rest parameter.
3974 * @returns {Function} Returns the new function.
3975 */
3976 function baseRest(func, start) {
3977 return setToString(overRest(func, start, identity), func + '');
3978 }
3979
3980 /**
3981 * The base implementation of `_.sample`.
3982 *
3983 * @private
3984 * @param {Array|Object} collection The collection to sample.
3985 * @returns {*} Returns the random element.
3986 */
3987 function baseSample(collection) {
3988 return arraySample(values(collection));
3989 }
3990
3991 /**
3992 * The base implementation of `_.sampleSize` without param guards.
3993 *
3994 * @private
3995 * @param {Array|Object} collection The collection to sample.
3996 * @param {number} n The number of elements to sample.
3997 * @returns {Array} Returns the random elements.
3998 */
3999 function baseSampleSize(collection, n) {
4000 var array = values(collection);
4001 return shuffleSelf(array, baseClamp(n, 0, array.length));
4002 }
4003
4004 /**
4005 * The base implementation of `_.set`.
4006 *
4007 * @private
4008 * @param {Object} object The object to modify.
4009 * @param {Array|string} path The path of the property to set.
4010 * @param {*} value The value to set.
4011 * @param {Function} [customizer] The function to customize path creation.
4012 * @returns {Object} Returns `object`.
4013 */
4014 function baseSet(object, path, value, customizer) {
4015 if (!isObject(object)) {
4016 return object;
4017 }
4018 path = isKey(path, object) ? [path] : castPath(path);
4019
4020 var index = -1,
4021 length = path.length,
4022 lastIndex = length - 1,
4023 nested = object;
4024
4025 while (nested != null && ++index < length) {
4026 var key = toKey(path[index]),
4027 newValue = value;
4028
4029 if (index != lastIndex) {
4030 var objValue = nested[key];
4031 newValue = customizer ? customizer(objValue, key, nested) : undefined;
4032 if (newValue === undefined) {
4033 newValue = isObject(objValue)
4034 ? objValue
4035 : (isIndex(path[index + 1]) ? [] : {});
4036 }
4037 }
4038 assignValue(nested, key, newValue);
4039 nested = nested[key];
4040 }
4041 return object;
4042 }
4043
4044 /**
4045 * The base implementation of `setData` without support for hot loop shorting.
4046 *
4047 * @private
4048 * @param {Function} func The function to associate metadata with.
4049 * @param {*} data The metadata.
4050 * @returns {Function} Returns `func`.
4051 */
4052 var baseSetData = !metaMap ? identity : function(func, data) {
4053 metaMap.set(func, data);
4054 return func;
4055 };
4056
4057 /**
4058 * The base implementation of `setToString` without support for hot loop shorting.
4059 *
4060 * @private
4061 * @param {Function} func The function to modify.
4062 * @param {Function} string The `toString` result.
4063 * @returns {Function} Returns `func`.
4064 */
4065 var baseSetToString = !defineProperty ? identity : function(func, string) {
4066 return defineProperty(func, 'toString', {
4067 'configurable': true,
4068 'enumerable': false,
4069 'value': constant(string),
4070 'writable': true
4071 });
4072 };
4073
4074 /**
4075 * The base implementation of `_.shuffle`.
4076 *
4077 * @private
4078 * @param {Array|Object} collection The collection to shuffle.
4079 * @returns {Array} Returns the new shuffled array.
4080 */
4081 function baseShuffle(collection) {
4082 return shuffleSelf(values(collection));
4083 }
4084
4085 /**
4086 * The base implementation of `_.slice` without an iteratee call guard.
4087 *
4088 * @private
4089 * @param {Array} array The array to slice.
4090 * @param {number} [start=0] The start position.
4091 * @param {number} [end=array.length] The end position.
4092 * @returns {Array} Returns the slice of `array`.
4093 */
4094 function baseSlice(array, start, end) {
4095 var index = -1,
4096 length = array.length;
4097
4098 if (start < 0) {
4099 start = -start > length ? 0 : (length + start);
4100 }
4101 end = end > length ? length : end;
4102 if (end < 0) {
4103 end += length;
4104 }
4105 length = start > end ? 0 : ((end - start) >>> 0);
4106 start >>>= 0;
4107
4108 var result = Array(length);
4109 while (++index < length) {
4110 result[index] = array[index + start];
4111 }
4112 return result;
4113 }
4114
4115 /**
4116 * The base implementation of `_.some` without support for iteratee shorthands.
4117 *
4118 * @private
4119 * @param {Array|Object} collection The collection to iterate over.
4120 * @param {Function} predicate The function invoked per iteration.
4121 * @returns {boolean} Returns `true` if any element passes the predicate check,
4122 * else `false`.
4123 */
4124 function baseSome(collection, predicate) {
4125 var result;
4126
4127 baseEach(collection, function(value, index, collection) {
4128 result = predicate(value, index, collection);
4129 return !result;
4130 });
4131 return !!result;
4132 }
4133
4134 /**
4135 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
4136 * performs a binary search of `array` to determine the index at which `value`
4137 * should be inserted into `array` in order to maintain its sort order.
4138 *
4139 * @private
4140 * @param {Array} array The sorted array to inspect.
4141 * @param {*} value The value to evaluate.
4142 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4143 * @returns {number} Returns the index at which `value` should be inserted
4144 * into `array`.
4145 */
4146 function baseSortedIndex(array, value, retHighest) {
4147 var low = 0,
4148 high = array == null ? low : array.length;
4149
4150 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
4151 while (low < high) {
4152 var mid = (low + high) >>> 1,
4153 computed = array[mid];
4154
4155 if (computed !== null && !isSymbol(computed) &&
4156 (retHighest ? (computed <= value) : (computed < value))) {
4157 low = mid + 1;
4158 } else {
4159 high = mid;
4160 }
4161 }
4162 return high;
4163 }
4164 return baseSortedIndexBy(array, value, identity, retHighest);
4165 }
4166
4167 /**
4168 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
4169 * which invokes `iteratee` for `value` and each element of `array` to compute
4170 * their sort ranking. The iteratee is invoked with one argument; (value).
4171 *
4172 * @private
4173 * @param {Array} array The sorted array to inspect.
4174 * @param {*} value The value to evaluate.
4175 * @param {Function} iteratee The iteratee invoked per element.
4176 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4177 * @returns {number} Returns the index at which `value` should be inserted
4178 * into `array`.
4179 */
4180 function baseSortedIndexBy(array, value, iteratee, retHighest) {
4181 value = iteratee(value);
4182
4183 var low = 0,
4184 high = array == null ? 0 : array.length,
4185 valIsNaN = value !== value,
4186 valIsNull = value === null,
4187 valIsSymbol = isSymbol(value),
4188 valIsUndefined = value === undefined;
4189
4190 while (low < high) {
4191 var mid = nativeFloor((low + high) / 2),
4192 computed = iteratee(array[mid]),
4193 othIsDefined = computed !== undefined,
4194 othIsNull = computed === null,
4195 othIsReflexive = computed === computed,
4196 othIsSymbol = isSymbol(computed);
4197
4198 if (valIsNaN) {
4199 var setLow = retHighest || othIsReflexive;
4200 } else if (valIsUndefined) {
4201 setLow = othIsReflexive && (retHighest || othIsDefined);
4202 } else if (valIsNull) {
4203 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
4204 } else if (valIsSymbol) {
4205 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
4206 } else if (othIsNull || othIsSymbol) {
4207 setLow = false;
4208 } else {
4209 setLow = retHighest ? (computed <= value) : (computed < value);
4210 }
4211 if (setLow) {
4212 low = mid + 1;
4213 } else {
4214 high = mid;
4215 }
4216 }
4217 return nativeMin(high, MAX_ARRAY_INDEX);
4218 }
4219
4220 /**
4221 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
4222 * support for iteratee shorthands.
4223 *
4224 * @private
4225 * @param {Array} array The array to inspect.
4226 * @param {Function} [iteratee] The iteratee invoked per element.
4227 * @returns {Array} Returns the new duplicate free array.
4228 */
4229 function baseSortedUniq(array, iteratee) {
4230 var index = -1,
4231 length = array.length,
4232 resIndex = 0,
4233 result = [];
4234
4235 while (++index < length) {
4236 var value = array[index],
4237 computed = iteratee ? iteratee(value) : value;
4238
4239 if (!index || !eq(computed, seen)) {
4240 var seen = computed;
4241 result[resIndex++] = value === 0 ? 0 : value;
4242 }
4243 }
4244 return result;
4245 }
4246
4247 /**
4248 * The base implementation of `_.toNumber` which doesn't ensure correct
4249 * conversions of binary, hexadecimal, or octal string values.
4250 *
4251 * @private
4252 * @param {*} value The value to process.
4253 * @returns {number} Returns the number.
4254 */
4255 function baseToNumber(value) {
4256 if (typeof value == 'number') {
4257 return value;
4258 }
4259 if (isSymbol(value)) {
4260 return NAN;
4261 }
4262 return +value;
4263 }
4264
4265 /**
4266 * The base implementation of `_.toString` which doesn't convert nullish
4267 * values to empty strings.
4268 *
4269 * @private
4270 * @param {*} value The value to process.
4271 * @returns {string} Returns the string.
4272 */
4273 function baseToString(value) {
4274 // Exit early for strings to avoid a performance hit in some environments.
4275 if (typeof value == 'string') {
4276 return value;
4277 }
4278 if (isArray(value)) {
4279 // Recursively convert values (susceptible to call stack limits).
4280 return arrayMap(value, baseToString) + '';
4281 }
4282 if (isSymbol(value)) {
4283 return symbolToString ? symbolToString.call(value) : '';
4284 }
4285 var result = (value + '');
4286 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
4287 }
4288
4289 /**
4290 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
4291 *
4292 * @private
4293 * @param {Array} array The array to inspect.
4294 * @param {Function} [iteratee] The iteratee invoked per element.
4295 * @param {Function} [comparator] The comparator invoked per element.
4296 * @returns {Array} Returns the new duplicate free array.
4297 */
4298 function baseUniq(array, iteratee, comparator) {
4299 var index = -1,
4300 includes = arrayIncludes,
4301 length = array.length,
4302 isCommon = true,
4303 result = [],
4304 seen = result;
4305
4306 if (comparator) {
4307 isCommon = false;
4308 includes = arrayIncludesWith;
4309 }
4310 else if (length >= LARGE_ARRAY_SIZE) {
4311 var set = iteratee ? null : createSet(array);
4312 if (set) {
4313 return setToArray(set);
4314 }
4315 isCommon = false;
4316 includes = cacheHas;
4317 seen = new SetCache;
4318 }
4319 else {
4320 seen = iteratee ? [] : result;
4321 }
4322 outer:
4323 while (++index < length) {
4324 var value = array[index],
4325 computed = iteratee ? iteratee(value) : value;
4326
4327 value = (comparator || value !== 0) ? value : 0;
4328 if (isCommon && computed === computed) {
4329 var seenIndex = seen.length;
4330 while (seenIndex--) {
4331 if (seen[seenIndex] === computed) {
4332 continue outer;
4333 }
4334 }
4335 if (iteratee) {
4336 seen.push(computed);
4337 }
4338 result.push(value);
4339 }
4340 else if (!includes(seen, computed, comparator)) {
4341 if (seen !== result) {
4342 seen.push(computed);
4343 }
4344 result.push(value);
4345 }
4346 }
4347 return result;
4348 }
4349
4350 /**
4351 * The base implementation of `_.unset`.
4352 *
4353 * @private
4354 * @param {Object} object The object to modify.
4355 * @param {Array|string} path The property path to unset.
4356 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
4357 */
4358 function baseUnset(object, path) {
4359 path = isKey(path, object) ? [path] : castPath(path);
4360 object = parent(object, path);
4361
4362 var key = toKey(last(path));
4363 return !(object != null && hasOwnProperty.call(object, key)) || delete object[key];
4364 }
4365
4366 /**
4367 * The base implementation of `_.update`.
4368 *
4369 * @private
4370 * @param {Object} object The object to modify.
4371 * @param {Array|string} path The path of the property to update.
4372 * @param {Function} updater The function to produce the updated value.
4373 * @param {Function} [customizer] The function to customize path creation.
4374 * @returns {Object} Returns `object`.
4375 */
4376 function baseUpdate(object, path, updater, customizer) {
4377 return baseSet(object, path, updater(baseGet(object, path)), customizer);
4378 }
4379
4380 /**
4381 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
4382 * without support for iteratee shorthands.
4383 *
4384 * @private
4385 * @param {Array} array The array to query.
4386 * @param {Function} predicate The function invoked per iteration.
4387 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
4388 * @param {boolean} [fromRight] Specify iterating from right to left.
4389 * @returns {Array} Returns the slice of `array`.
4390 */
4391 function baseWhile(array, predicate, isDrop, fromRight) {
4392 var length = array.length,
4393 index = fromRight ? length : -1;
4394
4395 while ((fromRight ? index-- : ++index < length) &&
4396 predicate(array[index], index, array)) {}
4397
4398 return isDrop
4399 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
4400 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
4401 }
4402
4403 /**
4404 * The base implementation of `wrapperValue` which returns the result of
4405 * performing a sequence of actions on the unwrapped `value`, where each
4406 * successive action is supplied the return value of the previous.
4407 *
4408 * @private
4409 * @param {*} value The unwrapped value.
4410 * @param {Array} actions Actions to perform to resolve the unwrapped value.
4411 * @returns {*} Returns the resolved value.
4412 */
4413 function baseWrapperValue(value, actions) {
4414 var result = value;
4415 if (result instanceof LazyWrapper) {
4416 result = result.value();
4417 }
4418 return arrayReduce(actions, function(result, action) {
4419 return action.func.apply(action.thisArg, arrayPush([result], action.args));
4420 }, result);
4421 }
4422
4423 /**
4424 * The base implementation of methods like `_.xor`, without support for
4425 * iteratee shorthands, that accepts an array of arrays to inspect.
4426 *
4427 * @private
4428 * @param {Array} arrays The arrays to inspect.
4429 * @param {Function} [iteratee] The iteratee invoked per element.
4430 * @param {Function} [comparator] The comparator invoked per element.
4431 * @returns {Array} Returns the new array of values.
4432 */
4433 function baseXor(arrays, iteratee, comparator) {
4434 var length = arrays.length;
4435 if (length < 2) {
4436 return length ? baseUniq(arrays[0]) : [];
4437 }
4438 var index = -1,
4439 result = Array(length);
4440
4441 while (++index < length) {
4442 var array = arrays[index],
4443 othIndex = -1;
4444
4445 while (++othIndex < length) {
4446 if (othIndex != index) {
4447 result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
4448 }
4449 }
4450 }
4451 return baseUniq(baseFlatten(result, 1), iteratee, comparator);
4452 }
4453
4454 /**
4455 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
4456 *
4457 * @private
4458 * @param {Array} props The property identifiers.
4459 * @param {Array} values The property values.
4460 * @param {Function} assignFunc The function to assign values.
4461 * @returns {Object} Returns the new object.
4462 */
4463 function baseZipObject(props, values, assignFunc) {
4464 var index = -1,
4465 length = props.length,
4466 valsLength = values.length,
4467 result = {};
4468
4469 while (++index < length) {
4470 var value = index < valsLength ? values[index] : undefined;
4471 assignFunc(result, props[index], value);
4472 }
4473 return result;
4474 }
4475
4476 /**
4477 * Casts `value` to an empty array if it's not an array like object.
4478 *
4479 * @private
4480 * @param {*} value The value to inspect.
4481 * @returns {Array|Object} Returns the cast array-like object.
4482 */
4483 function castArrayLikeObject(value) {
4484 return isArrayLikeObject(value) ? value : [];
4485 }
4486
4487 /**
4488 * Casts `value` to `identity` if it's not a function.
4489 *
4490 * @private
4491 * @param {*} value The value to inspect.
4492 * @returns {Function} Returns cast function.
4493 */
4494 function castFunction(value) {
4495 return typeof value == 'function' ? value : identity;
4496 }
4497
4498 /**
4499 * Casts `value` to a path array if it's not one.
4500 *
4501 * @private
4502 * @param {*} value The value to inspect.
4503 * @returns {Array} Returns the cast property path array.
4504 */
4505 function castPath(value) {
4506 return isArray(value) ? value : stringToPath(value);
4507 }
4508
4509 /**
4510 * A `baseRest` alias which can be replaced with `identity` by module
4511 * replacement plugins.
4512 *
4513 * @private
4514 * @type {Function}
4515 * @param {Function} func The function to apply a rest parameter to.
4516 * @returns {Function} Returns the new function.
4517 */
4518 var castRest = baseRest;
4519
4520 /**
4521 * Casts `array` to a slice if it's needed.
4522 *
4523 * @private
4524 * @param {Array} array The array to inspect.
4525 * @param {number} start The start position.
4526 * @param {number} [end=array.length] The end position.
4527 * @returns {Array} Returns the cast slice.
4528 */
4529 function castSlice(array, start, end) {
4530 var length = array.length;
4531 end = end === undefined ? length : end;
4532 return (!start && end >= length) ? array : baseSlice(array, start, end);
4533 }
4534
4535 /**
4536 * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
4537 *
4538 * @private
4539 * @param {number|Object} id The timer id or timeout object of the timer to clear.
4540 */
4541 var clearTimeout = ctxClearTimeout || function(id) {
4542 return root.clearTimeout(id);
4543 };
4544
4545 /**
4546 * Creates a clone of `buffer`.
4547 *
4548 * @private
4549 * @param {Buffer} buffer The buffer to clone.
4550 * @param {boolean} [isDeep] Specify a deep clone.
4551 * @returns {Buffer} Returns the cloned buffer.
4552 */
4553 function cloneBuffer(buffer, isDeep) {
4554 if (isDeep) {
4555 return buffer.slice();
4556 }
4557 var length = buffer.length,
4558 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
4559
4560 buffer.copy(result);
4561 return result;
4562 }
4563
4564 /**
4565 * Creates a clone of `arrayBuffer`.
4566 *
4567 * @private
4568 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
4569 * @returns {ArrayBuffer} Returns the cloned array buffer.
4570 */
4571 function cloneArrayBuffer(arrayBuffer) {
4572 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
4573 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
4574 return result;
4575 }
4576
4577 /**
4578 * Creates a clone of `dataView`.
4579 *
4580 * @private
4581 * @param {Object} dataView The data view to clone.
4582 * @param {boolean} [isDeep] Specify a deep clone.
4583 * @returns {Object} Returns the cloned data view.
4584 */
4585 function cloneDataView(dataView, isDeep) {
4586 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
4587 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
4588 }
4589
4590 /**
4591 * Creates a clone of `map`.
4592 *
4593 * @private
4594 * @param {Object} map The map to clone.
4595 * @param {Function} cloneFunc The function to clone values.
4596 * @param {boolean} [isDeep] Specify a deep clone.
4597 * @returns {Object} Returns the cloned map.
4598 */
4599 function cloneMap(map, isDeep, cloneFunc) {
4600 var array = isDeep ? cloneFunc(mapToArray(map), CLONE_DEEP_FLAG) : mapToArray(map);
4601 return arrayReduce(array, addMapEntry, new map.constructor);
4602 }
4603
4604 /**
4605 * Creates a clone of `regexp`.
4606 *
4607 * @private
4608 * @param {Object} regexp The regexp to clone.
4609 * @returns {Object} Returns the cloned regexp.
4610 */
4611 function cloneRegExp(regexp) {
4612 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
4613 result.lastIndex = regexp.lastIndex;
4614 return result;
4615 }
4616
4617 /**
4618 * Creates a clone of `set`.
4619 *
4620 * @private
4621 * @param {Object} set The set to clone.
4622 * @param {Function} cloneFunc The function to clone values.
4623 * @param {boolean} [isDeep] Specify a deep clone.
4624 * @returns {Object} Returns the cloned set.
4625 */
4626 function cloneSet(set, isDeep, cloneFunc) {
4627 var array = isDeep ? cloneFunc(setToArray(set), CLONE_DEEP_FLAG) : setToArray(set);
4628 return arrayReduce(array, addSetEntry, new set.constructor);
4629 }
4630
4631 /**
4632 * Creates a clone of the `symbol` object.
4633 *
4634 * @private
4635 * @param {Object} symbol The symbol object to clone.
4636 * @returns {Object} Returns the cloned symbol object.
4637 */
4638 function cloneSymbol(symbol) {
4639 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
4640 }
4641
4642 /**
4643 * Creates a clone of `typedArray`.
4644 *
4645 * @private
4646 * @param {Object} typedArray The typed array to clone.
4647 * @param {boolean} [isDeep] Specify a deep clone.
4648 * @returns {Object} Returns the cloned typed array.
4649 */
4650 function cloneTypedArray(typedArray, isDeep) {
4651 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
4652 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
4653 }
4654
4655 /**
4656 * Compares values to sort them in ascending order.
4657 *
4658 * @private
4659 * @param {*} value The value to compare.
4660 * @param {*} other The other value to compare.
4661 * @returns {number} Returns the sort order indicator for `value`.
4662 */
4663 function compareAscending(value, other) {
4664 if (value !== other) {
4665 var valIsDefined = value !== undefined,
4666 valIsNull = value === null,
4667 valIsReflexive = value === value,
4668 valIsSymbol = isSymbol(value);
4669
4670 var othIsDefined = other !== undefined,
4671 othIsNull = other === null,
4672 othIsReflexive = other === other,
4673 othIsSymbol = isSymbol(other);
4674
4675 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
4676 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
4677 (valIsNull && othIsDefined && othIsReflexive) ||
4678 (!valIsDefined && othIsReflexive) ||
4679 !valIsReflexive) {
4680 return 1;
4681 }
4682 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
4683 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
4684 (othIsNull && valIsDefined && valIsReflexive) ||
4685 (!othIsDefined && valIsReflexive) ||
4686 !othIsReflexive) {
4687 return -1;
4688 }
4689 }
4690 return 0;
4691 }
4692
4693 /**
4694 * Used by `_.orderBy` to compare multiple properties of a value to another
4695 * and stable sort them.
4696 *
4697 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
4698 * specify an order of "desc" for descending or "asc" for ascending sort order
4699 * of corresponding values.
4700 *
4701 * @private
4702 * @param {Object} object The object to compare.
4703 * @param {Object} other The other object to compare.
4704 * @param {boolean[]|string[]} orders The order to sort by for each property.
4705 * @returns {number} Returns the sort order indicator for `object`.
4706 */
4707 function compareMultiple(object, other, orders) {
4708 var index = -1,
4709 objCriteria = object.criteria,
4710 othCriteria = other.criteria,
4711 length = objCriteria.length,
4712 ordersLength = orders.length;
4713
4714 while (++index < length) {
4715 var result = compareAscending(objCriteria[index], othCriteria[index]);
4716 if (result) {
4717 if (index >= ordersLength) {
4718 return result;
4719 }
4720 var order = orders[index];
4721 return result * (order == 'desc' ? -1 : 1);
4722 }
4723 }
4724 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
4725 // that causes it, under certain circumstances, to provide the same value for
4726 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
4727 // for more details.
4728 //
4729 // This also ensures a stable sort in V8 and other engines.
4730 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
4731 return object.index - other.index;
4732 }
4733
4734 /**
4735 * Creates an array that is the composition of partially applied arguments,
4736 * placeholders, and provided arguments into a single array of arguments.
4737 *
4738 * @private
4739 * @param {Array} args The provided arguments.
4740 * @param {Array} partials The arguments to prepend to those provided.
4741 * @param {Array} holders The `partials` placeholder indexes.
4742 * @params {boolean} [isCurried] Specify composing for a curried function.
4743 * @returns {Array} Returns the new array of composed arguments.
4744 */
4745 function composeArgs(args, partials, holders, isCurried) {
4746 var argsIndex = -1,
4747 argsLength = args.length,
4748 holdersLength = holders.length,
4749 leftIndex = -1,
4750 leftLength = partials.length,
4751 rangeLength = nativeMax(argsLength - holdersLength, 0),
4752 result = Array(leftLength + rangeLength),
4753 isUncurried = !isCurried;
4754
4755 while (++leftIndex < leftLength) {
4756 result[leftIndex] = partials[leftIndex];
4757 }
4758 while (++argsIndex < holdersLength) {
4759 if (isUncurried || argsIndex < argsLength) {
4760 result[holders[argsIndex]] = args[argsIndex];
4761 }
4762 }
4763 while (rangeLength--) {
4764 result[leftIndex++] = args[argsIndex++];
4765 }
4766 return result;
4767 }
4768
4769 /**
4770 * This function is like `composeArgs` except that the arguments composition
4771 * is tailored for `_.partialRight`.
4772 *
4773 * @private
4774 * @param {Array} args The provided arguments.
4775 * @param {Array} partials The arguments to append to those provided.
4776 * @param {Array} holders The `partials` placeholder indexes.
4777 * @params {boolean} [isCurried] Specify composing for a curried function.
4778 * @returns {Array} Returns the new array of composed arguments.
4779 */
4780 function composeArgsRight(args, partials, holders, isCurried) {
4781 var argsIndex = -1,
4782 argsLength = args.length,
4783 holdersIndex = -1,
4784 holdersLength = holders.length,
4785 rightIndex = -1,
4786 rightLength = partials.length,
4787 rangeLength = nativeMax(argsLength - holdersLength, 0),
4788 result = Array(rangeLength + rightLength),
4789 isUncurried = !isCurried;
4790
4791 while (++argsIndex < rangeLength) {
4792 result[argsIndex] = args[argsIndex];
4793 }
4794 var offset = argsIndex;
4795 while (++rightIndex < rightLength) {
4796 result[offset + rightIndex] = partials[rightIndex];
4797 }
4798 while (++holdersIndex < holdersLength) {
4799 if (isUncurried || argsIndex < argsLength) {
4800 result[offset + holders[holdersIndex]] = args[argsIndex++];
4801 }
4802 }
4803 return result;
4804 }
4805
4806 /**
4807 * Copies the values of `source` to `array`.
4808 *
4809 * @private
4810 * @param {Array} source The array to copy values from.
4811 * @param {Array} [array=[]] The array to copy values to.
4812 * @returns {Array} Returns `array`.
4813 */
4814 function copyArray(source, array) {
4815 var index = -1,
4816 length = source.length;
4817
4818 array || (array = Array(length));
4819 while (++index < length) {
4820 array[index] = source[index];
4821 }
4822 return array;
4823 }
4824
4825 /**
4826 * Copies properties of `source` to `object`.
4827 *
4828 * @private
4829 * @param {Object} source The object to copy properties from.
4830 * @param {Array} props The property identifiers to copy.
4831 * @param {Object} [object={}] The object to copy properties to.
4832 * @param {Function} [customizer] The function to customize copied values.
4833 * @returns {Object} Returns `object`.
4834 */
4835 function copyObject(source, props, object, customizer) {
4836 var isNew = !object;
4837 object || (object = {});
4838
4839 var index = -1,
4840 length = props.length;
4841
4842 while (++index < length) {
4843 var key = props[index];
4844
4845 var newValue = customizer
4846 ? customizer(object[key], source[key], key, object, source)
4847 : undefined;
4848
4849 if (newValue === undefined) {
4850 newValue = source[key];
4851 }
4852 if (isNew) {
4853 baseAssignValue(object, key, newValue);
4854 } else {
4855 assignValue(object, key, newValue);
4856 }
4857 }
4858 return object;
4859 }
4860
4861 /**
4862 * Copies own symbols of `source` to `object`.
4863 *
4864 * @private
4865 * @param {Object} source The object to copy symbols from.
4866 * @param {Object} [object={}] The object to copy symbols to.
4867 * @returns {Object} Returns `object`.
4868 */
4869 function copySymbols(source, object) {
4870 return copyObject(source, getSymbols(source), object);
4871 }
4872
4873 /**
4874 * Copies own and inherited symbols of `source` to `object`.
4875 *
4876 * @private
4877 * @param {Object} source The object to copy symbols from.
4878 * @param {Object} [object={}] The object to copy symbols to.
4879 * @returns {Object} Returns `object`.
4880 */
4881 function copySymbolsIn(source, object) {
4882 return copyObject(source, getSymbolsIn(source), object);
4883 }
4884
4885 /**
4886 * Creates a function like `_.groupBy`.
4887 *
4888 * @private
4889 * @param {Function} setter The function to set accumulator values.
4890 * @param {Function} [initializer] The accumulator object initializer.
4891 * @returns {Function} Returns the new aggregator function.
4892 */
4893 function createAggregator(setter, initializer) {
4894 return function(collection, iteratee) {
4895 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4896 accumulator = initializer ? initializer() : {};
4897
4898 return func(collection, setter, getIteratee(iteratee, 2), accumulator);
4899 };
4900 }
4901
4902 /**
4903 * Creates a function like `_.assign`.
4904 *
4905 * @private
4906 * @param {Function} assigner The function to assign values.
4907 * @returns {Function} Returns the new assigner function.
4908 */
4909 function createAssigner(assigner) {
4910 return baseRest(function(object, sources) {
4911 var index = -1,
4912 length = sources.length,
4913 customizer = length > 1 ? sources[length - 1] : undefined,
4914 guard = length > 2 ? sources[2] : undefined;
4915
4916 customizer = (assigner.length > 3 && typeof customizer == 'function')
4917 ? (length--, customizer)
4918 : undefined;
4919
4920 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
4921 customizer = length < 3 ? undefined : customizer;
4922 length = 1;
4923 }
4924 object = Object(object);
4925 while (++index < length) {
4926 var source = sources[index];
4927 if (source) {
4928 assigner(object, source, index, customizer);
4929 }
4930 }
4931 return object;
4932 });
4933 }
4934
4935 /**
4936 * Creates a `baseEach` or `baseEachRight` function.
4937 *
4938 * @private
4939 * @param {Function} eachFunc The function to iterate over a collection.
4940 * @param {boolean} [fromRight] Specify iterating from right to left.
4941 * @returns {Function} Returns the new base function.
4942 */
4943 function createBaseEach(eachFunc, fromRight) {
4944 return function(collection, iteratee) {
4945 if (collection == null) {
4946 return collection;
4947 }
4948 if (!isArrayLike(collection)) {
4949 return eachFunc(collection, iteratee);
4950 }
4951 var length = collection.length,
4952 index = fromRight ? length : -1,
4953 iterable = Object(collection);
4954
4955 while ((fromRight ? index-- : ++index < length)) {
4956 if (iteratee(iterable[index], index, iterable) === false) {
4957 break;
4958 }
4959 }
4960 return collection;
4961 };
4962 }
4963
4964 /**
4965 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
4966 *
4967 * @private
4968 * @param {boolean} [fromRight] Specify iterating from right to left.
4969 * @returns {Function} Returns the new base function.
4970 */
4971 function createBaseFor(fromRight) {
4972 return function(object, iteratee, keysFunc) {
4973 var index = -1,
4974 iterable = Object(object),
4975 props = keysFunc(object),
4976 length = props.length;
4977
4978 while (length--) {
4979 var key = props[fromRight ? length : ++index];
4980 if (iteratee(iterable[key], key, iterable) === false) {
4981 break;
4982 }
4983 }
4984 return object;
4985 };
4986 }
4987
4988 /**
4989 * Creates a function that wraps `func` to invoke it with the optional `this`
4990 * binding of `thisArg`.
4991 *
4992 * @private
4993 * @param {Function} func The function to wrap.
4994 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
4995 * @param {*} [thisArg] The `this` binding of `func`.
4996 * @returns {Function} Returns the new wrapped function.
4997 */
4998 function createBind(func, bitmask, thisArg) {
4999 var isBind = bitmask & WRAP_BIND_FLAG,
5000 Ctor = createCtor(func);
5001
5002 function wrapper() {
5003 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5004 return fn.apply(isBind ? thisArg : this, arguments);
5005 }
5006 return wrapper;
5007 }
5008
5009 /**
5010 * Creates a function like `_.lowerFirst`.
5011 *
5012 * @private
5013 * @param {string} methodName The name of the `String` case method to use.
5014 * @returns {Function} Returns the new case function.
5015 */
5016 function createCaseFirst(methodName) {
5017 return function(string) {
5018 string = toString(string);
5019
5020 var strSymbols = hasUnicode(string)
5021 ? stringToArray(string)
5022 : undefined;
5023
5024 var chr = strSymbols
5025 ? strSymbols[0]
5026 : string.charAt(0);
5027
5028 var trailing = strSymbols
5029 ? castSlice(strSymbols, 1).join('')
5030 : string.slice(1);
5031
5032 return chr[methodName]() + trailing;
5033 };
5034 }
5035
5036 /**
5037 * Creates a function like `_.camelCase`.
5038 *
5039 * @private
5040 * @param {Function} callback The function to combine each word.
5041 * @returns {Function} Returns the new compounder function.
5042 */
5043 function createCompounder(callback) {
5044 return function(string) {
5045 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
5046 };
5047 }
5048
5049 /**
5050 * Creates a function that produces an instance of `Ctor` regardless of
5051 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
5052 *
5053 * @private
5054 * @param {Function} Ctor The constructor to wrap.
5055 * @returns {Function} Returns the new wrapped function.
5056 */
5057 function createCtor(Ctor) {
5058 return function() {
5059 // Use a `switch` statement to work with class constructors. See
5060 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
5061 // for more details.
5062 var args = arguments;
5063 switch (args.length) {
5064 case 0: return new Ctor;
5065 case 1: return new Ctor(args[0]);
5066 case 2: return new Ctor(args[0], args[1]);
5067 case 3: return new Ctor(args[0], args[1], args[2]);
5068 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
5069 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
5070 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
5071 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
5072 }
5073 var thisBinding = baseCreate(Ctor.prototype),
5074 result = Ctor.apply(thisBinding, args);
5075
5076 // Mimic the constructor's `return` behavior.
5077 // See https://es5.github.io/#x13.2.2 for more details.
5078 return isObject(result) ? result : thisBinding;
5079 };
5080 }
5081
5082 /**
5083 * Creates a function that wraps `func` to enable currying.
5084 *
5085 * @private
5086 * @param {Function} func The function to wrap.
5087 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5088 * @param {number} arity The arity of `func`.
5089 * @returns {Function} Returns the new wrapped function.
5090 */
5091 function createCurry(func, bitmask, arity) {
5092 var Ctor = createCtor(func);
5093
5094 function wrapper() {
5095 var length = arguments.length,
5096 args = Array(length),
5097 index = length,
5098 placeholder = getHolder(wrapper);
5099
5100 while (index--) {
5101 args[index] = arguments[index];
5102 }
5103 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
5104 ? []
5105 : replaceHolders(args, placeholder);
5106
5107 length -= holders.length;
5108 if (length < arity) {
5109 return createRecurry(
5110 func, bitmask, createHybrid, wrapper.placeholder, undefined,
5111 args, holders, undefined, undefined, arity - length);
5112 }
5113 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5114 return apply(fn, this, args);
5115 }
5116 return wrapper;
5117 }
5118
5119 /**
5120 * Creates a `_.find` or `_.findLast` function.
5121 *
5122 * @private
5123 * @param {Function} findIndexFunc The function to find the collection index.
5124 * @returns {Function} Returns the new find function.
5125 */
5126 function createFind(findIndexFunc) {
5127 return function(collection, predicate, fromIndex) {
5128 var iterable = Object(collection);
5129 if (!isArrayLike(collection)) {
5130 var iteratee = getIteratee(predicate, 3);
5131 collection = keys(collection);
5132 predicate = function(key) { return iteratee(iterable[key], key, iterable); };
5133 }
5134 var index = findIndexFunc(collection, predicate, fromIndex);
5135 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
5136 };
5137 }
5138
5139 /**
5140 * Creates a `_.flow` or `_.flowRight` function.
5141 *
5142 * @private
5143 * @param {boolean} [fromRight] Specify iterating from right to left.
5144 * @returns {Function} Returns the new flow function.
5145 */
5146 function createFlow(fromRight) {
5147 return flatRest(function(funcs) {
5148 var length = funcs.length,
5149 index = length,
5150 prereq = LodashWrapper.prototype.thru;
5151
5152 if (fromRight) {
5153 funcs.reverse();
5154 }
5155 while (index--) {
5156 var func = funcs[index];
5157 if (typeof func != 'function') {
5158 throw new TypeError(FUNC_ERROR_TEXT);
5159 }
5160 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
5161 var wrapper = new LodashWrapper([], true);
5162 }
5163 }
5164 index = wrapper ? index : length;
5165 while (++index < length) {
5166 func = funcs[index];
5167
5168 var funcName = getFuncName(func),
5169 data = funcName == 'wrapper' ? getData(func) : undefined;
5170
5171 if (data && isLaziable(data[0]) &&
5172 data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
5173 !data[4].length && data[9] == 1
5174 ) {
5175 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
5176 } else {
5177 wrapper = (func.length == 1 && isLaziable(func))
5178 ? wrapper[funcName]()
5179 : wrapper.thru(func);
5180 }
5181 }
5182 return function() {
5183 var args = arguments,
5184 value = args[0];
5185
5186 if (wrapper && args.length == 1 &&
5187 isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
5188 return wrapper.plant(value).value();
5189 }
5190 var index = 0,
5191 result = length ? funcs[index].apply(this, args) : value;
5192
5193 while (++index < length) {
5194 result = funcs[index].call(this, result);
5195 }
5196 return result;
5197 };
5198 });
5199 }
5200
5201 /**
5202 * Creates a function that wraps `func` to invoke it with optional `this`
5203 * binding of `thisArg`, partial application, and currying.
5204 *
5205 * @private
5206 * @param {Function|string} func The function or method name to wrap.
5207 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5208 * @param {*} [thisArg] The `this` binding of `func`.
5209 * @param {Array} [partials] The arguments to prepend to those provided to
5210 * the new function.
5211 * @param {Array} [holders] The `partials` placeholder indexes.
5212 * @param {Array} [partialsRight] The arguments to append to those provided
5213 * to the new function.
5214 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
5215 * @param {Array} [argPos] The argument positions of the new function.
5216 * @param {number} [ary] The arity cap of `func`.
5217 * @param {number} [arity] The arity of `func`.
5218 * @returns {Function} Returns the new wrapped function.
5219 */
5220 function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
5221 var isAry = bitmask & WRAP_ARY_FLAG,
5222 isBind = bitmask & WRAP_BIND_FLAG,
5223 isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
5224 isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
5225 isFlip = bitmask & WRAP_FLIP_FLAG,
5226 Ctor = isBindKey ? undefined : createCtor(func);
5227
5228 function wrapper() {
5229 var length = arguments.length,
5230 args = Array(length),
5231 index = length;
5232
5233 while (index--) {
5234 args[index] = arguments[index];
5235 }
5236 if (isCurried) {
5237 var placeholder = getHolder(wrapper),
5238 holdersCount = countHolders(args, placeholder);
5239 }
5240 if (partials) {
5241 args = composeArgs(args, partials, holders, isCurried);
5242 }
5243 if (partialsRight) {
5244 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
5245 }
5246 length -= holdersCount;
5247 if (isCurried && length < arity) {
5248 var newHolders = replaceHolders(args, placeholder);
5249 return createRecurry(
5250 func, bitmask, createHybrid, wrapper.placeholder, thisArg,
5251 args, newHolders, argPos, ary, arity - length
5252 );
5253 }
5254 var thisBinding = isBind ? thisArg : this,
5255 fn = isBindKey ? thisBinding[func] : func;
5256
5257 length = args.length;
5258 if (argPos) {
5259 args = reorder(args, argPos);
5260 } else if (isFlip && length > 1) {
5261 args.reverse();
5262 }
5263 if (isAry && ary < length) {
5264 args.length = ary;
5265 }
5266 if (this && this !== root && this instanceof wrapper) {
5267 fn = Ctor || createCtor(fn);
5268 }
5269 return fn.apply(thisBinding, args);
5270 }
5271 return wrapper;
5272 }
5273
5274 /**
5275 * Creates a function like `_.invertBy`.
5276 *
5277 * @private
5278 * @param {Function} setter The function to set accumulator values.
5279 * @param {Function} toIteratee The function to resolve iteratees.
5280 * @returns {Function} Returns the new inverter function.
5281 */
5282 function createInverter(setter, toIteratee) {
5283 return function(object, iteratee) {
5284 return baseInverter(object, setter, toIteratee(iteratee), {});
5285 };
5286 }
5287
5288 /**
5289 * Creates a function that performs a mathematical operation on two values.
5290 *
5291 * @private
5292 * @param {Function} operator The function to perform the operation.
5293 * @param {number} [defaultValue] The value used for `undefined` arguments.
5294 * @returns {Function} Returns the new mathematical operation function.
5295 */
5296 function createMathOperation(operator, defaultValue) {
5297 return function(value, other) {
5298 var result;
5299 if (value === undefined && other === undefined) {
5300 return defaultValue;
5301 }
5302 if (value !== undefined) {
5303 result = value;
5304 }
5305 if (other !== undefined) {
5306 if (result === undefined) {
5307 return other;
5308 }
5309 if (typeof value == 'string' || typeof other == 'string') {
5310 value = baseToString(value);
5311 other = baseToString(other);
5312 } else {
5313 value = baseToNumber(value);
5314 other = baseToNumber(other);
5315 }
5316 result = operator(value, other);
5317 }
5318 return result;
5319 };
5320 }
5321
5322 /**
5323 * Creates a function like `_.over`.
5324 *
5325 * @private
5326 * @param {Function} arrayFunc The function to iterate over iteratees.
5327 * @returns {Function} Returns the new over function.
5328 */
5329 function createOver(arrayFunc) {
5330 return flatRest(function(iteratees) {
5331 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
5332 return baseRest(function(args) {
5333 var thisArg = this;
5334 return arrayFunc(iteratees, function(iteratee) {
5335 return apply(iteratee, thisArg, args);
5336 });
5337 });
5338 });
5339 }
5340
5341 /**
5342 * Creates the padding for `string` based on `length`. The `chars` string
5343 * is truncated if the number of characters exceeds `length`.
5344 *
5345 * @private
5346 * @param {number} length The padding length.
5347 * @param {string} [chars=' '] The string used as padding.
5348 * @returns {string} Returns the padding for `string`.
5349 */
5350 function createPadding(length, chars) {
5351 chars = chars === undefined ? ' ' : baseToString(chars);
5352
5353 var charsLength = chars.length;
5354 if (charsLength < 2) {
5355 return charsLength ? baseRepeat(chars, length) : chars;
5356 }
5357 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
5358 return hasUnicode(chars)
5359 ? castSlice(stringToArray(result), 0, length).join('')
5360 : result.slice(0, length);
5361 }
5362
5363 /**
5364 * Creates a function that wraps `func` to invoke it with the `this` binding
5365 * of `thisArg` and `partials` prepended to the arguments it receives.
5366 *
5367 * @private
5368 * @param {Function} func The function to wrap.
5369 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5370 * @param {*} thisArg The `this` binding of `func`.
5371 * @param {Array} partials The arguments to prepend to those provided to
5372 * the new function.
5373 * @returns {Function} Returns the new wrapped function.
5374 */
5375 function createPartial(func, bitmask, thisArg, partials) {
5376 var isBind = bitmask & WRAP_BIND_FLAG,
5377 Ctor = createCtor(func);
5378
5379 function wrapper() {
5380 var argsIndex = -1,
5381 argsLength = arguments.length,
5382 leftIndex = -1,
5383 leftLength = partials.length,
5384 args = Array(leftLength + argsLength),
5385 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5386
5387 while (++leftIndex < leftLength) {
5388 args[leftIndex] = partials[leftIndex];
5389 }
5390 while (argsLength--) {
5391 args[leftIndex++] = arguments[++argsIndex];
5392 }
5393 return apply(fn, isBind ? thisArg : this, args);
5394 }
5395 return wrapper;
5396 }
5397
5398 /**
5399 * Creates a `_.range` or `_.rangeRight` function.
5400 *
5401 * @private
5402 * @param {boolean} [fromRight] Specify iterating from right to left.
5403 * @returns {Function} Returns the new range function.
5404 */
5405 function createRange(fromRight) {
5406 return function(start, end, step) {
5407 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
5408 end = step = undefined;
5409 }
5410 // Ensure the sign of `-0` is preserved.
5411 start = toFinite(start);
5412 if (end === undefined) {
5413 end = start;
5414 start = 0;
5415 } else {
5416 end = toFinite(end);
5417 }
5418 step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
5419 return baseRange(start, end, step, fromRight);
5420 };
5421 }
5422
5423 /**
5424 * Creates a function that performs a relational operation on two values.
5425 *
5426 * @private
5427 * @param {Function} operator The function to perform the operation.
5428 * @returns {Function} Returns the new relational operation function.
5429 */
5430 function createRelationalOperation(operator) {
5431 return function(value, other) {
5432 if (!(typeof value == 'string' && typeof other == 'string')) {
5433 value = toNumber(value);
5434 other = toNumber(other);
5435 }
5436 return operator(value, other);
5437 };
5438 }
5439
5440 /**
5441 * Creates a function that wraps `func` to continue currying.
5442 *
5443 * @private
5444 * @param {Function} func The function to wrap.
5445 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5446 * @param {Function} wrapFunc The function to create the `func` wrapper.
5447 * @param {*} placeholder The placeholder value.
5448 * @param {*} [thisArg] The `this` binding of `func`.
5449 * @param {Array} [partials] The arguments to prepend to those provided to
5450 * the new function.
5451 * @param {Array} [holders] The `partials` placeholder indexes.
5452 * @param {Array} [argPos] The argument positions of the new function.
5453 * @param {number} [ary] The arity cap of `func`.
5454 * @param {number} [arity] The arity of `func`.
5455 * @returns {Function} Returns the new wrapped function.
5456 */
5457 function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
5458 var isCurry = bitmask & WRAP_CURRY_FLAG,
5459 newHolders = isCurry ? holders : undefined,
5460 newHoldersRight = isCurry ? undefined : holders,
5461 newPartials = isCurry ? partials : undefined,
5462 newPartialsRight = isCurry ? undefined : partials;
5463
5464 bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
5465 bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
5466
5467 if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
5468 bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
5469 }
5470 var newData = [
5471 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
5472 newHoldersRight, argPos, ary, arity
5473 ];
5474
5475 var result = wrapFunc.apply(undefined, newData);
5476 if (isLaziable(func)) {
5477 setData(result, newData);
5478 }
5479 result.placeholder = placeholder;
5480 return setWrapToString(result, func, bitmask);
5481 }
5482
5483 /**
5484 * Creates a function like `_.round`.
5485 *
5486 * @private
5487 * @param {string} methodName The name of the `Math` method to use when rounding.
5488 * @returns {Function} Returns the new round function.
5489 */
5490 function createRound(methodName) {
5491 var func = Math[methodName];
5492 return function(number, precision) {
5493 number = toNumber(number);
5494 precision = nativeMin(toInteger(precision), 292);
5495 if (precision) {
5496 // Shift with exponential notation to avoid floating-point issues.
5497 // See [MDN](https://mdn.io/round#Examples) for more details.
5498 var pair = (toString(number) + 'e').split('e'),
5499 value = func(pair[0] + 'e' + (+pair[1] + precision));
5500
5501 pair = (toString(value) + 'e').split('e');
5502 return +(pair[0] + 'e' + (+pair[1] - precision));
5503 }
5504 return func(number);
5505 };
5506 }
5507
5508 /**
5509 * Creates a set object of `values`.
5510 *
5511 * @private
5512 * @param {Array} values The values to add to the set.
5513 * @returns {Object} Returns the new set.
5514 */
5515 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
5516 return new Set(values);
5517 };
5518
5519 /**
5520 * Creates a `_.toPairs` or `_.toPairsIn` function.
5521 *
5522 * @private
5523 * @param {Function} keysFunc The function to get the keys of a given object.
5524 * @returns {Function} Returns the new pairs function.
5525 */
5526 function createToPairs(keysFunc) {
5527 return function(object) {
5528 var tag = getTag(object);
5529 if (tag == mapTag) {
5530 return mapToArray(object);
5531 }
5532 if (tag == setTag) {
5533 return setToPairs(object);
5534 }
5535 return baseToPairs(object, keysFunc(object));
5536 };
5537 }
5538
5539 /**
5540 * Creates a function that either curries or invokes `func` with optional
5541 * `this` binding and partially applied arguments.
5542 *
5543 * @private
5544 * @param {Function|string} func The function or method name to wrap.
5545 * @param {number} bitmask The bitmask flags.
5546 * 1 - `_.bind`
5547 * 2 - `_.bindKey`
5548 * 4 - `_.curry` or `_.curryRight` of a bound function
5549 * 8 - `_.curry`
5550 * 16 - `_.curryRight`
5551 * 32 - `_.partial`
5552 * 64 - `_.partialRight`
5553 * 128 - `_.rearg`
5554 * 256 - `_.ary`
5555 * 512 - `_.flip`
5556 * @param {*} [thisArg] The `this` binding of `func`.
5557 * @param {Array} [partials] The arguments to be partially applied.
5558 * @param {Array} [holders] The `partials` placeholder indexes.
5559 * @param {Array} [argPos] The argument positions of the new function.
5560 * @param {number} [ary] The arity cap of `func`.
5561 * @param {number} [arity] The arity of `func`.
5562 * @returns {Function} Returns the new wrapped function.
5563 */
5564 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
5565 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
5566 if (!isBindKey && typeof func != 'function') {
5567 throw new TypeError(FUNC_ERROR_TEXT);
5568 }
5569 var length = partials ? partials.length : 0;
5570 if (!length) {
5571 bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
5572 partials = holders = undefined;
5573 }
5574 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
5575 arity = arity === undefined ? arity : toInteger(arity);
5576 length -= holders ? holders.length : 0;
5577
5578 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
5579 var partialsRight = partials,
5580 holdersRight = holders;
5581
5582 partials = holders = undefined;
5583 }
5584 var data = isBindKey ? undefined : getData(func);
5585
5586 var newData = [
5587 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
5588 argPos, ary, arity
5589 ];
5590
5591 if (data) {
5592 mergeData(newData, data);
5593 }
5594 func = newData[0];
5595 bitmask = newData[1];
5596 thisArg = newData[2];
5597 partials = newData[3];
5598 holders = newData[4];
5599 arity = newData[9] = newData[9] == null
5600 ? (isBindKey ? 0 : func.length)
5601 : nativeMax(newData[9] - length, 0);
5602
5603 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
5604 bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
5605 }
5606 if (!bitmask || bitmask == WRAP_BIND_FLAG) {
5607 var result = createBind(func, bitmask, thisArg);
5608 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
5609 result = createCurry(func, bitmask, arity);
5610 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
5611 result = createPartial(func, bitmask, thisArg, partials);
5612 } else {
5613 result = createHybrid.apply(undefined, newData);
5614 }
5615 var setter = data ? baseSetData : setData;
5616 return setWrapToString(setter(result, newData), func, bitmask);
5617 }
5618
5619 /**
5620 * A specialized version of `baseIsEqualDeep` for arrays with support for
5621 * partial deep comparisons.
5622 *
5623 * @private
5624 * @param {Array} array The array to compare.
5625 * @param {Array} other The other array to compare.
5626 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5627 * @param {Function} customizer The function to customize comparisons.
5628 * @param {Function} equalFunc The function to determine equivalents of values.
5629 * @param {Object} stack Tracks traversed `array` and `other` objects.
5630 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
5631 */
5632 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
5633 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5634 arrLength = array.length,
5635 othLength = other.length;
5636
5637 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
5638 return false;
5639 }
5640 // Assume cyclic values are equal.
5641 var stacked = stack.get(array);
5642 if (stacked && stack.get(other)) {
5643 return stacked == other;
5644 }
5645 var index = -1,
5646 result = true,
5647 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
5648
5649 stack.set(array, other);
5650 stack.set(other, array);
5651
5652 // Ignore non-index properties.
5653 while (++index < arrLength) {
5654 var arrValue = array[index],
5655 othValue = other[index];
5656
5657 if (customizer) {
5658 var compared = isPartial
5659 ? customizer(othValue, arrValue, index, other, array, stack)
5660 : customizer(arrValue, othValue, index, array, other, stack);
5661 }
5662 if (compared !== undefined) {
5663 if (compared) {
5664 continue;
5665 }
5666 result = false;
5667 break;
5668 }
5669 // Recursively compare arrays (susceptible to call stack limits).
5670 if (seen) {
5671 if (!arraySome(other, function(othValue, othIndex) {
5672 if (!cacheHas(seen, othIndex) &&
5673 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
5674 return seen.push(othIndex);
5675 }
5676 })) {
5677 result = false;
5678 break;
5679 }
5680 } else if (!(
5681 arrValue === othValue ||
5682 equalFunc(arrValue, othValue, bitmask, customizer, stack)
5683 )) {
5684 result = false;
5685 break;
5686 }
5687 }
5688 stack['delete'](array);
5689 stack['delete'](other);
5690 return result;
5691 }
5692
5693 /**
5694 * A specialized version of `baseIsEqualDeep` for comparing objects of
5695 * the same `toStringTag`.
5696 *
5697 * **Note:** This function only supports comparing values with tags of
5698 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5699 *
5700 * @private
5701 * @param {Object} object The object to compare.
5702 * @param {Object} other The other object to compare.
5703 * @param {string} tag The `toStringTag` of the objects to compare.
5704 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5705 * @param {Function} customizer The function to customize comparisons.
5706 * @param {Function} equalFunc The function to determine equivalents of values.
5707 * @param {Object} stack Tracks traversed `object` and `other` objects.
5708 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5709 */
5710 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
5711 switch (tag) {
5712 case dataViewTag:
5713 if ((object.byteLength != other.byteLength) ||
5714 (object.byteOffset != other.byteOffset)) {
5715 return false;
5716 }
5717 object = object.buffer;
5718 other = other.buffer;
5719
5720 case arrayBufferTag:
5721 if ((object.byteLength != other.byteLength) ||
5722 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
5723 return false;
5724 }
5725 return true;
5726
5727 case boolTag:
5728 case dateTag:
5729 case numberTag:
5730 // Coerce booleans to `1` or `0` and dates to milliseconds.
5731 // Invalid dates are coerced to `NaN`.
5732 return eq(+object, +other);
5733
5734 case errorTag:
5735 return object.name == other.name && object.message == other.message;
5736
5737 case regexpTag:
5738 case stringTag:
5739 // Coerce regexes to strings and treat strings, primitives and objects,
5740 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
5741 // for more details.
5742 return object == (other + '');
5743
5744 case mapTag:
5745 var convert = mapToArray;
5746
5747 case setTag:
5748 var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
5749 convert || (convert = setToArray);
5750
5751 if (object.size != other.size && !isPartial) {
5752 return false;
5753 }
5754 // Assume cyclic values are equal.
5755 var stacked = stack.get(object);
5756 if (stacked) {
5757 return stacked == other;
5758 }
5759 bitmask |= COMPARE_UNORDERED_FLAG;
5760
5761 // Recursively compare objects (susceptible to call stack limits).
5762 stack.set(object, other);
5763 var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
5764 stack['delete'](object);
5765 return result;
5766
5767 case symbolTag:
5768 if (symbolValueOf) {
5769 return symbolValueOf.call(object) == symbolValueOf.call(other);
5770 }
5771 }
5772 return false;
5773 }
5774
5775 /**
5776 * A specialized version of `baseIsEqualDeep` for objects with support for
5777 * partial deep comparisons.
5778 *
5779 * @private
5780 * @param {Object} object The object to compare.
5781 * @param {Object} other The other object to compare.
5782 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5783 * @param {Function} customizer The function to customize comparisons.
5784 * @param {Function} equalFunc The function to determine equivalents of values.
5785 * @param {Object} stack Tracks traversed `object` and `other` objects.
5786 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5787 */
5788 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
5789 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5790 objProps = keys(object),
5791 objLength = objProps.length,
5792 othProps = keys(other),
5793 othLength = othProps.length;
5794
5795 if (objLength != othLength && !isPartial) {
5796 return false;
5797 }
5798 var index = objLength;
5799 while (index--) {
5800 var key = objProps[index];
5801 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
5802 return false;
5803 }
5804 }
5805 // Assume cyclic values are equal.
5806 var stacked = stack.get(object);
5807 if (stacked && stack.get(other)) {
5808 return stacked == other;
5809 }
5810 var result = true;
5811 stack.set(object, other);
5812 stack.set(other, object);
5813
5814 var skipCtor = isPartial;
5815 while (++index < objLength) {
5816 key = objProps[index];
5817 var objValue = object[key],
5818 othValue = other[key];
5819
5820 if (customizer) {
5821 var compared = isPartial
5822 ? customizer(othValue, objValue, key, other, object, stack)
5823 : customizer(objValue, othValue, key, object, other, stack);
5824 }
5825 // Recursively compare objects (susceptible to call stack limits).
5826 if (!(compared === undefined
5827 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
5828 : compared
5829 )) {
5830 result = false;
5831 break;
5832 }
5833 skipCtor || (skipCtor = key == 'constructor');
5834 }
5835 if (result && !skipCtor) {
5836 var objCtor = object.constructor,
5837 othCtor = other.constructor;
5838
5839 // Non `Object` object instances with different constructors are not equal.
5840 if (objCtor != othCtor &&
5841 ('constructor' in object && 'constructor' in other) &&
5842 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
5843 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
5844 result = false;
5845 }
5846 }
5847 stack['delete'](object);
5848 stack['delete'](other);
5849 return result;
5850 }
5851
5852 /**
5853 * A specialized version of `baseRest` which flattens the rest array.
5854 *
5855 * @private
5856 * @param {Function} func The function to apply a rest parameter to.
5857 * @returns {Function} Returns the new function.
5858 */
5859 function flatRest(func) {
5860 return setToString(overRest(func, undefined, flatten), func + '');
5861 }
5862
5863 /**
5864 * Creates an array of own enumerable property names and symbols of `object`.
5865 *
5866 * @private
5867 * @param {Object} object The object to query.
5868 * @returns {Array} Returns the array of property names and symbols.
5869 */
5870 function getAllKeys(object) {
5871 return baseGetAllKeys(object, keys, getSymbols);
5872 }
5873
5874 /**
5875 * Creates an array of own and inherited enumerable property names and
5876 * symbols of `object`.
5877 *
5878 * @private
5879 * @param {Object} object The object to query.
5880 * @returns {Array} Returns the array of property names and symbols.
5881 */
5882 function getAllKeysIn(object) {
5883 return baseGetAllKeys(object, keysIn, getSymbolsIn);
5884 }
5885
5886 /**
5887 * Gets metadata for `func`.
5888 *
5889 * @private
5890 * @param {Function} func The function to query.
5891 * @returns {*} Returns the metadata for `func`.
5892 */
5893 var getData = !metaMap ? noop : function(func) {
5894 return metaMap.get(func);
5895 };
5896
5897 /**
5898 * Gets the name of `func`.
5899 *
5900 * @private
5901 * @param {Function} func The function to query.
5902 * @returns {string} Returns the function name.
5903 */
5904 function getFuncName(func) {
5905 var result = (func.name + ''),
5906 array = realNames[result],
5907 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
5908
5909 while (length--) {
5910 var data = array[length],
5911 otherFunc = data.func;
5912 if (otherFunc == null || otherFunc == func) {
5913 return data.name;
5914 }
5915 }
5916 return result;
5917 }
5918
5919 /**
5920 * Gets the argument placeholder value for `func`.
5921 *
5922 * @private
5923 * @param {Function} func The function to inspect.
5924 * @returns {*} Returns the placeholder value.
5925 */
5926 function getHolder(func) {
5927 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
5928 return object.placeholder;
5929 }
5930
5931 /**
5932 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
5933 * this function returns the custom method, otherwise it returns `baseIteratee`.
5934 * If arguments are provided, the chosen function is invoked with them and
5935 * its result is returned.
5936 *
5937 * @private
5938 * @param {*} [value] The value to convert to an iteratee.
5939 * @param {number} [arity] The arity of the created iteratee.
5940 * @returns {Function} Returns the chosen function or its result.
5941 */
5942 function getIteratee() {
5943 var result = lodash.iteratee || iteratee;
5944 result = result === iteratee ? baseIteratee : result;
5945 return arguments.length ? result(arguments[0], arguments[1]) : result;
5946 }
5947
5948 /**
5949 * Gets the data for `map`.
5950 *
5951 * @private
5952 * @param {Object} map The map to query.
5953 * @param {string} key The reference key.
5954 * @returns {*} Returns the map data.
5955 */
5956 function getMapData(map, key) {
5957 var data = map.__data__;
5958 return isKeyable(key)
5959 ? data[typeof key == 'string' ? 'string' : 'hash']
5960 : data.map;
5961 }
5962
5963 /**
5964 * Gets the property names, values, and compare flags of `object`.
5965 *
5966 * @private
5967 * @param {Object} object The object to query.
5968 * @returns {Array} Returns the match data of `object`.
5969 */
5970 function getMatchData(object) {
5971 var result = keys(object),
5972 length = result.length;
5973
5974 while (length--) {
5975 var key = result[length],
5976 value = object[key];
5977
5978 result[length] = [key, value, isStrictComparable(value)];
5979 }
5980 return result;
5981 }
5982
5983 /**
5984 * Gets the native function at `key` of `object`.
5985 *
5986 * @private
5987 * @param {Object} object The object to query.
5988 * @param {string} key The key of the method to get.
5989 * @returns {*} Returns the function if it's native, else `undefined`.
5990 */
5991 function getNative(object, key) {
5992 var value = getValue(object, key);
5993 return baseIsNative(value) ? value : undefined;
5994 }
5995
5996 /**
5997 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
5998 *
5999 * @private
6000 * @param {*} value The value to query.
6001 * @returns {string} Returns the raw `toStringTag`.
6002 */
6003 function getRawTag(value) {
6004 var isOwn = hasOwnProperty.call(value, symToStringTag),
6005 tag = value[symToStringTag];
6006
6007 try {
6008 value[symToStringTag] = undefined;
6009 var unmasked = true;
6010 } catch (e) {}
6011
6012 var result = nativeObjectToString.call(value);
6013 if (unmasked) {
6014 if (isOwn) {
6015 value[symToStringTag] = tag;
6016 } else {
6017 delete value[symToStringTag];
6018 }
6019 }
6020 return result;
6021 }
6022
6023 /**
6024 * Creates an array of the own enumerable symbols of `object`.
6025 *
6026 * @private
6027 * @param {Object} object The object to query.
6028 * @returns {Array} Returns the array of symbols.
6029 */
6030 var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
6031
6032 /**
6033 * Creates an array of the own and inherited enumerable symbols of `object`.
6034 *
6035 * @private
6036 * @param {Object} object The object to query.
6037 * @returns {Array} Returns the array of symbols.
6038 */
6039 var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
6040 var result = [];
6041 while (object) {
6042 arrayPush(result, getSymbols(object));
6043 object = getPrototype(object);
6044 }
6045 return result;
6046 };
6047
6048 /**
6049 * Gets the `toStringTag` of `value`.
6050 *
6051 * @private
6052 * @param {*} value The value to query.
6053 * @returns {string} Returns the `toStringTag`.
6054 */
6055 var getTag = baseGetTag;
6056
6057 // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
6058 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
6059 (Map && getTag(new Map) != mapTag) ||
6060 (Promise && getTag(Promise.resolve()) != promiseTag) ||
6061 (Set && getTag(new Set) != setTag) ||
6062 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
6063 getTag = function(value) {
6064 var result = baseGetTag(value),
6065 Ctor = result == objectTag ? value.constructor : undefined,
6066 ctorString = Ctor ? toSource(Ctor) : '';
6067
6068 if (ctorString) {
6069 switch (ctorString) {
6070 case dataViewCtorString: return dataViewTag;
6071 case mapCtorString: return mapTag;
6072 case promiseCtorString: return promiseTag;
6073 case setCtorString: return setTag;
6074 case weakMapCtorString: return weakMapTag;
6075 }
6076 }
6077 return result;
6078 };
6079 }
6080
6081 /**
6082 * Gets the view, applying any `transforms` to the `start` and `end` positions.
6083 *
6084 * @private
6085 * @param {number} start The start of the view.
6086 * @param {number} end The end of the view.
6087 * @param {Array} transforms The transformations to apply to the view.
6088 * @returns {Object} Returns an object containing the `start` and `end`
6089 * positions of the view.
6090 */
6091 function getView(start, end, transforms) {
6092 var index = -1,
6093 length = transforms.length;
6094
6095 while (++index < length) {
6096 var data = transforms[index],
6097 size = data.size;
6098
6099 switch (data.type) {
6100 case 'drop': start += size; break;
6101 case 'dropRight': end -= size; break;
6102 case 'take': end = nativeMin(end, start + size); break;
6103 case 'takeRight': start = nativeMax(start, end - size); break;
6104 }
6105 }
6106 return { 'start': start, 'end': end };
6107 }
6108
6109 /**
6110 * Extracts wrapper details from the `source` body comment.
6111 *
6112 * @private
6113 * @param {string} source The source to inspect.
6114 * @returns {Array} Returns the wrapper details.
6115 */
6116 function getWrapDetails(source) {
6117 var match = source.match(reWrapDetails);
6118 return match ? match[1].split(reSplitDetails) : [];
6119 }
6120
6121 /**
6122 * Checks if `path` exists on `object`.
6123 *
6124 * @private
6125 * @param {Object} object The object to query.
6126 * @param {Array|string} path The path to check.
6127 * @param {Function} hasFunc The function to check properties.
6128 * @returns {boolean} Returns `true` if `path` exists, else `false`.
6129 */
6130 function hasPath(object, path, hasFunc) {
6131 path = isKey(path, object) ? [path] : castPath(path);
6132
6133 var index = -1,
6134 length = path.length,
6135 result = false;
6136
6137 while (++index < length) {
6138 var key = toKey(path[index]);
6139 if (!(result = object != null && hasFunc(object, key))) {
6140 break;
6141 }
6142 object = object[key];
6143 }
6144 if (result || ++index != length) {
6145 return result;
6146 }
6147 length = object == null ? 0 : object.length;
6148 return !!length && isLength(length) && isIndex(key, length) &&
6149 (isArray(object) || isArguments(object));
6150 }
6151
6152 /**
6153 * Initializes an array clone.
6154 *
6155 * @private
6156 * @param {Array} array The array to clone.
6157 * @returns {Array} Returns the initialized clone.
6158 */
6159 function initCloneArray(array) {
6160 var length = array.length,
6161 result = array.constructor(length);
6162
6163 // Add properties assigned by `RegExp#exec`.
6164 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
6165 result.index = array.index;
6166 result.input = array.input;
6167 }
6168 return result;
6169 }
6170
6171 /**
6172 * Initializes an object clone.
6173 *
6174 * @private
6175 * @param {Object} object The object to clone.
6176 * @returns {Object} Returns the initialized clone.
6177 */
6178 function initCloneObject(object) {
6179 return (typeof object.constructor == 'function' && !isPrototype(object))
6180 ? baseCreate(getPrototype(object))
6181 : {};
6182 }
6183
6184 /**
6185 * Initializes an object clone based on its `toStringTag`.
6186 *
6187 * **Note:** This function only supports cloning values with tags of
6188 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
6189 *
6190 * @private
6191 * @param {Object} object The object to clone.
6192 * @param {string} tag The `toStringTag` of the object to clone.
6193 * @param {Function} cloneFunc The function to clone values.
6194 * @param {boolean} [isDeep] Specify a deep clone.
6195 * @returns {Object} Returns the initialized clone.
6196 */
6197 function initCloneByTag(object, tag, cloneFunc, isDeep) {
6198 var Ctor = object.constructor;
6199 switch (tag) {
6200 case arrayBufferTag:
6201 return cloneArrayBuffer(object);
6202
6203 case boolTag:
6204 case dateTag:
6205 return new Ctor(+object);
6206
6207 case dataViewTag:
6208 return cloneDataView(object, isDeep);
6209
6210 case float32Tag: case float64Tag:
6211 case int8Tag: case int16Tag: case int32Tag:
6212 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
6213 return cloneTypedArray(object, isDeep);
6214
6215 case mapTag:
6216 return cloneMap(object, isDeep, cloneFunc);
6217
6218 case numberTag:
6219 case stringTag:
6220 return new Ctor(object);
6221
6222 case regexpTag:
6223 return cloneRegExp(object);
6224
6225 case setTag:
6226 return cloneSet(object, isDeep, cloneFunc);
6227
6228 case symbolTag:
6229 return cloneSymbol(object);
6230 }
6231 }
6232
6233 /**
6234 * Inserts wrapper `details` in a comment at the top of the `source` body.
6235 *
6236 * @private
6237 * @param {string} source The source to modify.
6238 * @returns {Array} details The details to insert.
6239 * @returns {string} Returns the modified source.
6240 */
6241 function insertWrapDetails(source, details) {
6242 var length = details.length;
6243 if (!length) {
6244 return source;
6245 }
6246 var lastIndex = length - 1;
6247 details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
6248 details = details.join(length > 2 ? ', ' : ' ');
6249 return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
6250 }
6251
6252 /**
6253 * Checks if `value` is a flattenable `arguments` object or array.
6254 *
6255 * @private
6256 * @param {*} value The value to check.
6257 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
6258 */
6259 function isFlattenable(value) {
6260 return isArray(value) || isArguments(value) ||
6261 !!(spreadableSymbol && value && value[spreadableSymbol]);
6262 }
6263
6264 /**
6265 * Checks if `value` is a valid array-like index.
6266 *
6267 * @private
6268 * @param {*} value The value to check.
6269 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
6270 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
6271 */
6272 function isIndex(value, length) {
6273 length = length == null ? MAX_SAFE_INTEGER : length;
6274 return !!length &&
6275 (typeof value == 'number' || reIsUint.test(value)) &&
6276 (value > -1 && value % 1 == 0 && value < length);
6277 }
6278
6279 /**
6280 * Checks if the given arguments are from an iteratee call.
6281 *
6282 * @private
6283 * @param {*} value The potential iteratee value argument.
6284 * @param {*} index The potential iteratee index or key argument.
6285 * @param {*} object The potential iteratee object argument.
6286 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
6287 * else `false`.
6288 */
6289 function isIterateeCall(value, index, object) {
6290 if (!isObject(object)) {
6291 return false;
6292 }
6293 var type = typeof index;
6294 if (type == 'number'
6295 ? (isArrayLike(object) && isIndex(index, object.length))
6296 : (type == 'string' && index in object)
6297 ) {
6298 return eq(object[index], value);
6299 }
6300 return false;
6301 }
6302
6303 /**
6304 * Checks if `value` is a property name and not a property path.
6305 *
6306 * @private
6307 * @param {*} value The value to check.
6308 * @param {Object} [object] The object to query keys on.
6309 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
6310 */
6311 function isKey(value, object) {
6312 if (isArray(value)) {
6313 return false;
6314 }
6315 var type = typeof value;
6316 if (type == 'number' || type == 'symbol' || type == 'boolean' ||
6317 value == null || isSymbol(value)) {
6318 return true;
6319 }
6320 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
6321 (object != null && value in Object(object));
6322 }
6323
6324 /**
6325 * Checks if `value` is suitable for use as unique object key.
6326 *
6327 * @private
6328 * @param {*} value The value to check.
6329 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
6330 */
6331 function isKeyable(value) {
6332 var type = typeof value;
6333 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
6334 ? (value !== '__proto__')
6335 : (value === null);
6336 }
6337
6338 /**
6339 * Checks if `func` has a lazy counterpart.
6340 *
6341 * @private
6342 * @param {Function} func The function to check.
6343 * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
6344 * else `false`.
6345 */
6346 function isLaziable(func) {
6347 var funcName = getFuncName(func),
6348 other = lodash[funcName];
6349
6350 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
6351 return false;
6352 }
6353 if (func === other) {
6354 return true;
6355 }
6356 var data = getData(other);
6357 return !!data && func === data[0];
6358 }
6359
6360 /**
6361 * Checks if `func` has its source masked.
6362 *
6363 * @private
6364 * @param {Function} func The function to check.
6365 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
6366 */
6367 function isMasked(func) {
6368 return !!maskSrcKey && (maskSrcKey in func);
6369 }
6370
6371 /**
6372 * Checks if `func` is capable of being masked.
6373 *
6374 * @private
6375 * @param {*} value The value to check.
6376 * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
6377 */
6378 var isMaskable = coreJsData ? isFunction : stubFalse;
6379
6380 /**
6381 * Checks if `value` is likely a prototype object.
6382 *
6383 * @private
6384 * @param {*} value The value to check.
6385 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
6386 */
6387 function isPrototype(value) {
6388 var Ctor = value && value.constructor,
6389 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
6390
6391 return value === proto;
6392 }
6393
6394 /**
6395 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
6396 *
6397 * @private
6398 * @param {*} value The value to check.
6399 * @returns {boolean} Returns `true` if `value` if suitable for strict
6400 * equality comparisons, else `false`.
6401 */
6402 function isStrictComparable(value) {
6403 return value === value && !isObject(value);
6404 }
6405
6406 /**
6407 * A specialized version of `matchesProperty` for source values suitable
6408 * for strict equality comparisons, i.e. `===`.
6409 *
6410 * @private
6411 * @param {string} key The key of the property to get.
6412 * @param {*} srcValue The value to match.
6413 * @returns {Function} Returns the new spec function.
6414 */
6415 function matchesStrictComparable(key, srcValue) {
6416 return function(object) {
6417 if (object == null) {
6418 return false;
6419 }
6420 return object[key] === srcValue &&
6421 (srcValue !== undefined || (key in Object(object)));
6422 };
6423 }
6424
6425 /**
6426 * A specialized version of `_.memoize` which clears the memoized function's
6427 * cache when it exceeds `MAX_MEMOIZE_SIZE`.
6428 *
6429 * @private
6430 * @param {Function} func The function to have its output memoized.
6431 * @returns {Function} Returns the new memoized function.
6432 */
6433 function memoizeCapped(func) {
6434 var result = memoize(func, function(key) {
6435 if (cache.size === MAX_MEMOIZE_SIZE) {
6436 cache.clear();
6437 }
6438 return key;
6439 });
6440
6441 var cache = result.cache;
6442 return result;
6443 }
6444
6445 /**
6446 * Merges the function metadata of `source` into `data`.
6447 *
6448 * Merging metadata reduces the number of wrappers used to invoke a function.
6449 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
6450 * may be applied regardless of execution order. Methods like `_.ary` and
6451 * `_.rearg` modify function arguments, making the order in which they are
6452 * executed important, preventing the merging of metadata. However, we make
6453 * an exception for a safe combined case where curried functions have `_.ary`
6454 * and or `_.rearg` applied.
6455 *
6456 * @private
6457 * @param {Array} data The destination metadata.
6458 * @param {Array} source The source metadata.
6459 * @returns {Array} Returns `data`.
6460 */
6461 function mergeData(data, source) {
6462 var bitmask = data[1],
6463 srcBitmask = source[1],
6464 newBitmask = bitmask | srcBitmask,
6465 isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
6466
6467 var isCombo =
6468 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
6469 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
6470 ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
6471
6472 // Exit early if metadata can't be merged.
6473 if (!(isCommon || isCombo)) {
6474 return data;
6475 }
6476 // Use source `thisArg` if available.
6477 if (srcBitmask & WRAP_BIND_FLAG) {
6478 data[2] = source[2];
6479 // Set when currying a bound function.
6480 newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
6481 }
6482 // Compose partial arguments.
6483 var value = source[3];
6484 if (value) {
6485 var partials = data[3];
6486 data[3] = partials ? composeArgs(partials, value, source[4]) : value;
6487 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
6488 }
6489 // Compose partial right arguments.
6490 value = source[5];
6491 if (value) {
6492 partials = data[5];
6493 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
6494 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
6495 }
6496 // Use source `argPos` if available.
6497 value = source[7];
6498 if (value) {
6499 data[7] = value;
6500 }
6501 // Use source `ary` if it's smaller.
6502 if (srcBitmask & WRAP_ARY_FLAG) {
6503 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
6504 }
6505 // Use source `arity` if one is not provided.
6506 if (data[9] == null) {
6507 data[9] = source[9];
6508 }
6509 // Use source `func` and merge bitmasks.
6510 data[0] = source[0];
6511 data[1] = newBitmask;
6512
6513 return data;
6514 }
6515
6516 /**
6517 * Used by `_.defaultsDeep` to customize its `_.merge` use.
6518 *
6519 * @private
6520 * @param {*} objValue The destination value.
6521 * @param {*} srcValue The source value.
6522 * @param {string} key The key of the property to merge.
6523 * @param {Object} object The parent object of `objValue`.
6524 * @param {Object} source The parent object of `srcValue`.
6525 * @param {Object} [stack] Tracks traversed source values and their merged
6526 * counterparts.
6527 * @returns {*} Returns the value to assign.
6528 */
6529 function mergeDefaults(objValue, srcValue, key, object, source, stack) {
6530 if (isObject(objValue) && isObject(srcValue)) {
6531 // Recursively merge objects and arrays (susceptible to call stack limits).
6532 stack.set(srcValue, objValue);
6533 baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
6534 stack['delete'](srcValue);
6535 }
6536 return objValue;
6537 }
6538
6539 /**
6540 * This function is like
6541 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
6542 * except that it includes inherited enumerable properties.
6543 *
6544 * @private
6545 * @param {Object} object The object to query.
6546 * @returns {Array} Returns the array of property names.
6547 */
6548 function nativeKeysIn(object) {
6549 var result = [];
6550 if (object != null) {
6551 for (var key in Object(object)) {
6552 result.push(key);
6553 }
6554 }
6555 return result;
6556 }
6557
6558 /**
6559 * Converts `value` to a string using `Object.prototype.toString`.
6560 *
6561 * @private
6562 * @param {*} value The value to convert.
6563 * @returns {string} Returns the converted string.
6564 */
6565 function objectToString(value) {
6566 return nativeObjectToString.call(value);
6567 }
6568
6569 /**
6570 * A specialized version of `baseRest` which transforms the rest array.
6571 *
6572 * @private
6573 * @param {Function} func The function to apply a rest parameter to.
6574 * @param {number} [start=func.length-1] The start position of the rest parameter.
6575 * @param {Function} transform The rest array transform.
6576 * @returns {Function} Returns the new function.
6577 */
6578 function overRest(func, start, transform) {
6579 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
6580 return function() {
6581 var args = arguments,
6582 index = -1,
6583 length = nativeMax(args.length - start, 0),
6584 array = Array(length);
6585
6586 while (++index < length) {
6587 array[index] = args[start + index];
6588 }
6589 index = -1;
6590 var otherArgs = Array(start + 1);
6591 while (++index < start) {
6592 otherArgs[index] = args[index];
6593 }
6594 otherArgs[start] = transform(array);
6595 return apply(func, this, otherArgs);
6596 };
6597 }
6598
6599 /**
6600 * Gets the parent value at `path` of `object`.
6601 *
6602 * @private
6603 * @param {Object} object The object to query.
6604 * @param {Array} path The path to get the parent value of.
6605 * @returns {*} Returns the parent value.
6606 */
6607 function parent(object, path) {
6608 return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
6609 }
6610
6611 /**
6612 * Reorder `array` according to the specified indexes where the element at
6613 * the first index is assigned as the first element, the element at
6614 * the second index is assigned as the second element, and so on.
6615 *
6616 * @private
6617 * @param {Array} array The array to reorder.
6618 * @param {Array} indexes The arranged array indexes.
6619 * @returns {Array} Returns `array`.
6620 */
6621 function reorder(array, indexes) {
6622 var arrLength = array.length,
6623 length = nativeMin(indexes.length, arrLength),
6624 oldArray = copyArray(array);
6625
6626 while (length--) {
6627 var index = indexes[length];
6628 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
6629 }
6630 return array;
6631 }
6632
6633 /**
6634 * Sets metadata for `func`.
6635 *
6636 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
6637 * period of time, it will trip its breaker and transition to an identity
6638 * function to avoid garbage collection pauses in V8. See
6639 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
6640 * for more details.
6641 *
6642 * @private
6643 * @param {Function} func The function to associate metadata with.
6644 * @param {*} data The metadata.
6645 * @returns {Function} Returns `func`.
6646 */
6647 var setData = shortOut(baseSetData);
6648
6649 /**
6650 * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
6651 *
6652 * @private
6653 * @param {Function} func The function to delay.
6654 * @param {number} wait The number of milliseconds to delay invocation.
6655 * @returns {number|Object} Returns the timer id or timeout object.
6656 */
6657 var setTimeout = ctxSetTimeout || function(func, wait) {
6658 return root.setTimeout(func, wait);
6659 };
6660
6661 /**
6662 * Sets the `toString` method of `func` to return `string`.
6663 *
6664 * @private
6665 * @param {Function} func The function to modify.
6666 * @param {Function} string The `toString` result.
6667 * @returns {Function} Returns `func`.
6668 */
6669 var setToString = shortOut(baseSetToString);
6670
6671 /**
6672 * Sets the `toString` method of `wrapper` to mimic the source of `reference`
6673 * with wrapper details in a comment at the top of the source body.
6674 *
6675 * @private
6676 * @param {Function} wrapper The function to modify.
6677 * @param {Function} reference The reference function.
6678 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6679 * @returns {Function} Returns `wrapper`.
6680 */
6681 function setWrapToString(wrapper, reference, bitmask) {
6682 var source = (reference + '');
6683 return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
6684 }
6685
6686 /**
6687 * Creates a function that'll short out and invoke `identity` instead
6688 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
6689 * milliseconds.
6690 *
6691 * @private
6692 * @param {Function} func The function to restrict.
6693 * @returns {Function} Returns the new shortable function.
6694 */
6695 function shortOut(func) {
6696 var count = 0,
6697 lastCalled = 0;
6698
6699 return function() {
6700 var stamp = nativeNow(),
6701 remaining = HOT_SPAN - (stamp - lastCalled);
6702
6703 lastCalled = stamp;
6704 if (remaining > 0) {
6705 if (++count >= HOT_COUNT) {
6706 return arguments[0];
6707 }
6708 } else {
6709 count = 0;
6710 }
6711 return func.apply(undefined, arguments);
6712 };
6713 }
6714
6715 /**
6716 * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
6717 *
6718 * @private
6719 * @param {Array} array The array to shuffle.
6720 * @param {number} [size=array.length] The size of `array`.
6721 * @returns {Array} Returns `array`.
6722 */
6723 function shuffleSelf(array, size) {
6724 var index = -1,
6725 length = array.length,
6726 lastIndex = length - 1;
6727
6728 size = size === undefined ? length : size;
6729 while (++index < size) {
6730 var rand = baseRandom(index, lastIndex),
6731 value = array[rand];
6732
6733 array[rand] = array[index];
6734 array[index] = value;
6735 }
6736 array.length = size;
6737 return array;
6738 }
6739
6740 /**
6741 * Converts `string` to a property path array.
6742 *
6743 * @private
6744 * @param {string} string The string to convert.
6745 * @returns {Array} Returns the property path array.
6746 */
6747 var stringToPath = memoizeCapped(function(string) {
6748 string = toString(string);
6749
6750 var result = [];
6751 if (reLeadingDot.test(string)) {
6752 result.push('');
6753 }
6754 string.replace(rePropName, function(match, number, quote, string) {
6755 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
6756 });
6757 return result;
6758 });
6759
6760 /**
6761 * Converts `value` to a string key if it's not a string or symbol.
6762 *
6763 * @private
6764 * @param {*} value The value to inspect.
6765 * @returns {string|symbol} Returns the key.
6766 */
6767 function toKey(value) {
6768 if (typeof value == 'string' || isSymbol(value)) {
6769 return value;
6770 }
6771 var result = (value + '');
6772 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
6773 }
6774
6775 /**
6776 * Converts `func` to its source code.
6777 *
6778 * @private
6779 * @param {Function} func The function to convert.
6780 * @returns {string} Returns the source code.
6781 */
6782 function toSource(func) {
6783 if (func != null) {
6784 try {
6785 return funcToString.call(func);
6786 } catch (e) {}
6787 try {
6788 return (func + '');
6789 } catch (e) {}
6790 }
6791 return '';
6792 }
6793
6794 /**
6795 * Updates wrapper `details` based on `bitmask` flags.
6796 *
6797 * @private
6798 * @returns {Array} details The details to modify.
6799 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6800 * @returns {Array} Returns `details`.
6801 */
6802 function updateWrapDetails(details, bitmask) {
6803 arrayEach(wrapFlags, function(pair) {
6804 var value = '_.' + pair[0];
6805 if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
6806 details.push(value);
6807 }
6808 });
6809 return details.sort();
6810 }
6811
6812 /**
6813 * Creates a clone of `wrapper`.
6814 *
6815 * @private
6816 * @param {Object} wrapper The wrapper to clone.
6817 * @returns {Object} Returns the cloned wrapper.
6818 */
6819 function wrapperClone(wrapper) {
6820 if (wrapper instanceof LazyWrapper) {
6821 return wrapper.clone();
6822 }
6823 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
6824 result.__actions__ = copyArray(wrapper.__actions__);
6825 result.__index__ = wrapper.__index__;
6826 result.__values__ = wrapper.__values__;
6827 return result;
6828 }
6829
6830 /*------------------------------------------------------------------------*/
6831
6832 /**
6833 * Creates an array of elements split into groups the length of `size`.
6834 * If `array` can't be split evenly, the final chunk will be the remaining
6835 * elements.
6836 *
6837 * @static
6838 * @memberOf _
6839 * @since 3.0.0
6840 * @category Array
6841 * @param {Array} array The array to process.
6842 * @param {number} [size=1] The length of each chunk
6843 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6844 * @returns {Array} Returns the new array of chunks.
6845 * @example
6846 *
6847 * _.chunk(['a', 'b', 'c', 'd'], 2);
6848 * // => [['a', 'b'], ['c', 'd']]
6849 *
6850 * _.chunk(['a', 'b', 'c', 'd'], 3);
6851 * // => [['a', 'b', 'c'], ['d']]
6852 */
6853 function chunk(array, size, guard) {
6854 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
6855 size = 1;
6856 } else {
6857 size = nativeMax(toInteger(size), 0);
6858 }
6859 var length = array == null ? 0 : array.length;
6860 if (!length || size < 1) {
6861 return [];
6862 }
6863 var index = 0,
6864 resIndex = 0,
6865 result = Array(nativeCeil(length / size));
6866
6867 while (index < length) {
6868 result[resIndex++] = baseSlice(array, index, (index += size));
6869 }
6870 return result;
6871 }
6872
6873 /**
6874 * Creates an array with all falsey values removed. The values `false`, `null`,
6875 * `0`, `""`, `undefined`, and `NaN` are falsey.
6876 *
6877 * @static
6878 * @memberOf _
6879 * @since 0.1.0
6880 * @category Array
6881 * @param {Array} array The array to compact.
6882 * @returns {Array} Returns the new array of filtered values.
6883 * @example
6884 *
6885 * _.compact([0, 1, false, 2, '', 3]);
6886 * // => [1, 2, 3]
6887 */
6888 function compact(array) {
6889 var index = -1,
6890 length = array == null ? 0 : array.length,
6891 resIndex = 0,
6892 result = [];
6893
6894 while (++index < length) {
6895 var value = array[index];
6896 if (value) {
6897 result[resIndex++] = value;
6898 }
6899 }
6900 return result;
6901 }
6902
6903 /**
6904 * Creates a new array concatenating `array` with any additional arrays
6905 * and/or values.
6906 *
6907 * @static
6908 * @memberOf _
6909 * @since 4.0.0
6910 * @category Array
6911 * @param {Array} array The array to concatenate.
6912 * @param {...*} [values] The values to concatenate.
6913 * @returns {Array} Returns the new concatenated array.
6914 * @example
6915 *
6916 * var array = [1];
6917 * var other = _.concat(array, 2, [3], [[4]]);
6918 *
6919 * console.log(other);
6920 * // => [1, 2, 3, [4]]
6921 *
6922 * console.log(array);
6923 * // => [1]
6924 */
6925 function concat() {
6926 var length = arguments.length;
6927 if (!length) {
6928 return [];
6929 }
6930 var args = Array(length - 1),
6931 array = arguments[0],
6932 index = length;
6933
6934 while (index--) {
6935 args[index - 1] = arguments[index];
6936 }
6937 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
6938 }
6939
6940 /**
6941 * Creates an array of `array` values not included in the other given arrays
6942 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
6943 * for equality comparisons. The order and references of result values are
6944 * determined by the first array.
6945 *
6946 * **Note:** Unlike `_.pullAll`, this method returns a new array.
6947 *
6948 * @static
6949 * @memberOf _
6950 * @since 0.1.0
6951 * @category Array
6952 * @param {Array} array The array to inspect.
6953 * @param {...Array} [values] The values to exclude.
6954 * @returns {Array} Returns the new array of filtered values.
6955 * @see _.without, _.xor
6956 * @example
6957 *
6958 * _.difference([2, 1], [2, 3]);
6959 * // => [1]
6960 */
6961 var difference = baseRest(function(array, values) {
6962 return isArrayLikeObject(array)
6963 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
6964 : [];
6965 });
6966
6967 /**
6968 * This method is like `_.difference` except that it accepts `iteratee` which
6969 * is invoked for each element of `array` and `values` to generate the criterion
6970 * by which they're compared. The order and references of result values are
6971 * determined by the first array. The iteratee is invoked with one argument:
6972 * (value).
6973 *
6974 * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
6975 *
6976 * @static
6977 * @memberOf _
6978 * @since 4.0.0
6979 * @category Array
6980 * @param {Array} array The array to inspect.
6981 * @param {...Array} [values] The values to exclude.
6982 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
6983 * @returns {Array} Returns the new array of filtered values.
6984 * @example
6985 *
6986 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
6987 * // => [1.2]
6988 *
6989 * // The `_.property` iteratee shorthand.
6990 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
6991 * // => [{ 'x': 2 }]
6992 */
6993 var differenceBy = baseRest(function(array, values) {
6994 var iteratee = last(values);
6995 if (isArrayLikeObject(iteratee)) {
6996 iteratee = undefined;
6997 }
6998 return isArrayLikeObject(array)
6999 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
7000 : [];
7001 });
7002
7003 /**
7004 * This method is like `_.difference` except that it accepts `comparator`
7005 * which is invoked to compare elements of `array` to `values`. The order and
7006 * references of result values are determined by the first array. The comparator
7007 * is invoked with two arguments: (arrVal, othVal).
7008 *
7009 * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
7010 *
7011 * @static
7012 * @memberOf _
7013 * @since 4.0.0
7014 * @category Array
7015 * @param {Array} array The array to inspect.
7016 * @param {...Array} [values] The values to exclude.
7017 * @param {Function} [comparator] The comparator invoked per element.
7018 * @returns {Array} Returns the new array of filtered values.
7019 * @example
7020 *
7021 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7022 *
7023 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
7024 * // => [{ 'x': 2, 'y': 1 }]
7025 */
7026 var differenceWith = baseRest(function(array, values) {
7027 var comparator = last(values);
7028 if (isArrayLikeObject(comparator)) {
7029 comparator = undefined;
7030 }
7031 return isArrayLikeObject(array)
7032 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
7033 : [];
7034 });
7035
7036 /**
7037 * Creates a slice of `array` with `n` elements dropped from the beginning.
7038 *
7039 * @static
7040 * @memberOf _
7041 * @since 0.5.0
7042 * @category Array
7043 * @param {Array} array The array to query.
7044 * @param {number} [n=1] The number of elements to drop.
7045 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7046 * @returns {Array} Returns the slice of `array`.
7047 * @example
7048 *
7049 * _.drop([1, 2, 3]);
7050 * // => [2, 3]
7051 *
7052 * _.drop([1, 2, 3], 2);
7053 * // => [3]
7054 *
7055 * _.drop([1, 2, 3], 5);
7056 * // => []
7057 *
7058 * _.drop([1, 2, 3], 0);
7059 * // => [1, 2, 3]
7060 */
7061 function drop(array, n, guard) {
7062 var length = array == null ? 0 : array.length;
7063 if (!length) {
7064 return [];
7065 }
7066 n = (guard || n === undefined) ? 1 : toInteger(n);
7067 return baseSlice(array, n < 0 ? 0 : n, length);
7068 }
7069
7070 /**
7071 * Creates a slice of `array` with `n` elements dropped from the end.
7072 *
7073 * @static
7074 * @memberOf _
7075 * @since 3.0.0
7076 * @category Array
7077 * @param {Array} array The array to query.
7078 * @param {number} [n=1] The number of elements to drop.
7079 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7080 * @returns {Array} Returns the slice of `array`.
7081 * @example
7082 *
7083 * _.dropRight([1, 2, 3]);
7084 * // => [1, 2]
7085 *
7086 * _.dropRight([1, 2, 3], 2);
7087 * // => [1]
7088 *
7089 * _.dropRight([1, 2, 3], 5);
7090 * // => []
7091 *
7092 * _.dropRight([1, 2, 3], 0);
7093 * // => [1, 2, 3]
7094 */
7095 function dropRight(array, n, guard) {
7096 var length = array == null ? 0 : array.length;
7097 if (!length) {
7098 return [];
7099 }
7100 n = (guard || n === undefined) ? 1 : toInteger(n);
7101 n = length - n;
7102 return baseSlice(array, 0, n < 0 ? 0 : n);
7103 }
7104
7105 /**
7106 * Creates a slice of `array` excluding elements dropped from the end.
7107 * Elements are dropped until `predicate` returns falsey. The predicate is
7108 * invoked with three arguments: (value, index, array).
7109 *
7110 * @static
7111 * @memberOf _
7112 * @since 3.0.0
7113 * @category Array
7114 * @param {Array} array The array to query.
7115 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7116 * @returns {Array} Returns the slice of `array`.
7117 * @example
7118 *
7119 * var users = [
7120 * { 'user': 'barney', 'active': true },
7121 * { 'user': 'fred', 'active': false },
7122 * { 'user': 'pebbles', 'active': false }
7123 * ];
7124 *
7125 * _.dropRightWhile(users, function(o) { return !o.active; });
7126 * // => objects for ['barney']
7127 *
7128 * // The `_.matches` iteratee shorthand.
7129 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
7130 * // => objects for ['barney', 'fred']
7131 *
7132 * // The `_.matchesProperty` iteratee shorthand.
7133 * _.dropRightWhile(users, ['active', false]);
7134 * // => objects for ['barney']
7135 *
7136 * // The `_.property` iteratee shorthand.
7137 * _.dropRightWhile(users, 'active');
7138 * // => objects for ['barney', 'fred', 'pebbles']
7139 */
7140 function dropRightWhile(array, predicate) {
7141 return (array && array.length)
7142 ? baseWhile(array, getIteratee(predicate, 3), true, true)
7143 : [];
7144 }
7145
7146 /**
7147 * Creates a slice of `array` excluding elements dropped from the beginning.
7148 * Elements are dropped until `predicate` returns falsey. The predicate is
7149 * invoked with three arguments: (value, index, array).
7150 *
7151 * @static
7152 * @memberOf _
7153 * @since 3.0.0
7154 * @category Array
7155 * @param {Array} array The array to query.
7156 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7157 * @returns {Array} Returns the slice of `array`.
7158 * @example
7159 *
7160 * var users = [
7161 * { 'user': 'barney', 'active': false },
7162 * { 'user': 'fred', 'active': false },
7163 * { 'user': 'pebbles', 'active': true }
7164 * ];
7165 *
7166 * _.dropWhile(users, function(o) { return !o.active; });
7167 * // => objects for ['pebbles']
7168 *
7169 * // The `_.matches` iteratee shorthand.
7170 * _.dropWhile(users, { 'user': 'barney', 'active': false });
7171 * // => objects for ['fred', 'pebbles']
7172 *
7173 * // The `_.matchesProperty` iteratee shorthand.
7174 * _.dropWhile(users, ['active', false]);
7175 * // => objects for ['pebbles']
7176 *
7177 * // The `_.property` iteratee shorthand.
7178 * _.dropWhile(users, 'active');
7179 * // => objects for ['barney', 'fred', 'pebbles']
7180 */
7181 function dropWhile(array, predicate) {
7182 return (array && array.length)
7183 ? baseWhile(array, getIteratee(predicate, 3), true)
7184 : [];
7185 }
7186
7187 /**
7188 * Fills elements of `array` with `value` from `start` up to, but not
7189 * including, `end`.
7190 *
7191 * **Note:** This method mutates `array`.
7192 *
7193 * @static
7194 * @memberOf _
7195 * @since 3.2.0
7196 * @category Array
7197 * @param {Array} array The array to fill.
7198 * @param {*} value The value to fill `array` with.
7199 * @param {number} [start=0] The start position.
7200 * @param {number} [end=array.length] The end position.
7201 * @returns {Array} Returns `array`.
7202 * @example
7203 *
7204 * var array = [1, 2, 3];
7205 *
7206 * _.fill(array, 'a');
7207 * console.log(array);
7208 * // => ['a', 'a', 'a']
7209 *
7210 * _.fill(Array(3), 2);
7211 * // => [2, 2, 2]
7212 *
7213 * _.fill([4, 6, 8, 10], '*', 1, 3);
7214 * // => [4, '*', '*', 10]
7215 */
7216 function fill(array, value, start, end) {
7217 var length = array == null ? 0 : array.length;
7218 if (!length) {
7219 return [];
7220 }
7221 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
7222 start = 0;
7223 end = length;
7224 }
7225 return baseFill(array, value, start, end);
7226 }
7227
7228 /**
7229 * This method is like `_.find` except that it returns the index of the first
7230 * element `predicate` returns truthy for instead of the element itself.
7231 *
7232 * @static
7233 * @memberOf _
7234 * @since 1.1.0
7235 * @category Array
7236 * @param {Array} array The array to inspect.
7237 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7238 * @param {number} [fromIndex=0] The index to search from.
7239 * @returns {number} Returns the index of the found element, else `-1`.
7240 * @example
7241 *
7242 * var users = [
7243 * { 'user': 'barney', 'active': false },
7244 * { 'user': 'fred', 'active': false },
7245 * { 'user': 'pebbles', 'active': true }
7246 * ];
7247 *
7248 * _.findIndex(users, function(o) { return o.user == 'barney'; });
7249 * // => 0
7250 *
7251 * // The `_.matches` iteratee shorthand.
7252 * _.findIndex(users, { 'user': 'fred', 'active': false });
7253 * // => 1
7254 *
7255 * // The `_.matchesProperty` iteratee shorthand.
7256 * _.findIndex(users, ['active', false]);
7257 * // => 0
7258 *
7259 * // The `_.property` iteratee shorthand.
7260 * _.findIndex(users, 'active');
7261 * // => 2
7262 */
7263 function findIndex(array, predicate, fromIndex) {
7264 var length = array == null ? 0 : array.length;
7265 if (!length) {
7266 return -1;
7267 }
7268 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7269 if (index < 0) {
7270 index = nativeMax(length + index, 0);
7271 }
7272 return baseFindIndex(array, getIteratee(predicate, 3), index);
7273 }
7274
7275 /**
7276 * This method is like `_.findIndex` except that it iterates over elements
7277 * of `collection` from right to left.
7278 *
7279 * @static
7280 * @memberOf _
7281 * @since 2.0.0
7282 * @category Array
7283 * @param {Array} array The array to inspect.
7284 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7285 * @param {number} [fromIndex=array.length-1] The index to search from.
7286 * @returns {number} Returns the index of the found element, else `-1`.
7287 * @example
7288 *
7289 * var users = [
7290 * { 'user': 'barney', 'active': true },
7291 * { 'user': 'fred', 'active': false },
7292 * { 'user': 'pebbles', 'active': false }
7293 * ];
7294 *
7295 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
7296 * // => 2
7297 *
7298 * // The `_.matches` iteratee shorthand.
7299 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
7300 * // => 0
7301 *
7302 * // The `_.matchesProperty` iteratee shorthand.
7303 * _.findLastIndex(users, ['active', false]);
7304 * // => 2
7305 *
7306 * // The `_.property` iteratee shorthand.
7307 * _.findLastIndex(users, 'active');
7308 * // => 0
7309 */
7310 function findLastIndex(array, predicate, fromIndex) {
7311 var length = array == null ? 0 : array.length;
7312 if (!length) {
7313 return -1;
7314 }
7315 var index = length - 1;
7316 if (fromIndex !== undefined) {
7317 index = toInteger(fromIndex);
7318 index = fromIndex < 0
7319 ? nativeMax(length + index, 0)
7320 : nativeMin(index, length - 1);
7321 }
7322 return baseFindIndex(array, getIteratee(predicate, 3), index, true);
7323 }
7324
7325 /**
7326 * Flattens `array` a single level deep.
7327 *
7328 * @static
7329 * @memberOf _
7330 * @since 0.1.0
7331 * @category Array
7332 * @param {Array} array The array to flatten.
7333 * @returns {Array} Returns the new flattened array.
7334 * @example
7335 *
7336 * _.flatten([1, [2, [3, [4]], 5]]);
7337 * // => [1, 2, [3, [4]], 5]
7338 */
7339 function flatten(array) {
7340 var length = array == null ? 0 : array.length;
7341 return length ? baseFlatten(array, 1) : [];
7342 }
7343
7344 /**
7345 * Recursively flattens `array`.
7346 *
7347 * @static
7348 * @memberOf _
7349 * @since 3.0.0
7350 * @category Array
7351 * @param {Array} array The array to flatten.
7352 * @returns {Array} Returns the new flattened array.
7353 * @example
7354 *
7355 * _.flattenDeep([1, [2, [3, [4]], 5]]);
7356 * // => [1, 2, 3, 4, 5]
7357 */
7358 function flattenDeep(array) {
7359 var length = array == null ? 0 : array.length;
7360 return length ? baseFlatten(array, INFINITY) : [];
7361 }
7362
7363 /**
7364 * Recursively flatten `array` up to `depth` times.
7365 *
7366 * @static
7367 * @memberOf _
7368 * @since 4.4.0
7369 * @category Array
7370 * @param {Array} array The array to flatten.
7371 * @param {number} [depth=1] The maximum recursion depth.
7372 * @returns {Array} Returns the new flattened array.
7373 * @example
7374 *
7375 * var array = [1, [2, [3, [4]], 5]];
7376 *
7377 * _.flattenDepth(array, 1);
7378 * // => [1, 2, [3, [4]], 5]
7379 *
7380 * _.flattenDepth(array, 2);
7381 * // => [1, 2, 3, [4], 5]
7382 */
7383 function flattenDepth(array, depth) {
7384 var length = array == null ? 0 : array.length;
7385 if (!length) {
7386 return [];
7387 }
7388 depth = depth === undefined ? 1 : toInteger(depth);
7389 return baseFlatten(array, depth);
7390 }
7391
7392 /**
7393 * The inverse of `_.toPairs`; this method returns an object composed
7394 * from key-value `pairs`.
7395 *
7396 * @static
7397 * @memberOf _
7398 * @since 4.0.0
7399 * @category Array
7400 * @param {Array} pairs The key-value pairs.
7401 * @returns {Object} Returns the new object.
7402 * @example
7403 *
7404 * _.fromPairs([['a', 1], ['b', 2]]);
7405 * // => { 'a': 1, 'b': 2 }
7406 */
7407 function fromPairs(pairs) {
7408 var index = -1,
7409 length = pairs == null ? 0 : pairs.length,
7410 result = {};
7411
7412 while (++index < length) {
7413 var pair = pairs[index];
7414 result[pair[0]] = pair[1];
7415 }
7416 return result;
7417 }
7418
7419 /**
7420 * Gets the first element of `array`.
7421 *
7422 * @static
7423 * @memberOf _
7424 * @since 0.1.0
7425 * @alias first
7426 * @category Array
7427 * @param {Array} array The array to query.
7428 * @returns {*} Returns the first element of `array`.
7429 * @example
7430 *
7431 * _.head([1, 2, 3]);
7432 * // => 1
7433 *
7434 * _.head([]);
7435 * // => undefined
7436 */
7437 function head(array) {
7438 return (array && array.length) ? array[0] : undefined;
7439 }
7440
7441 /**
7442 * Gets the index at which the first occurrence of `value` is found in `array`
7443 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7444 * for equality comparisons. If `fromIndex` is negative, it's used as the
7445 * offset from the end of `array`.
7446 *
7447 * @static
7448 * @memberOf _
7449 * @since 0.1.0
7450 * @category Array
7451 * @param {Array} array The array to inspect.
7452 * @param {*} value The value to search for.
7453 * @param {number} [fromIndex=0] The index to search from.
7454 * @returns {number} Returns the index of the matched value, else `-1`.
7455 * @example
7456 *
7457 * _.indexOf([1, 2, 1, 2], 2);
7458 * // => 1
7459 *
7460 * // Search from the `fromIndex`.
7461 * _.indexOf([1, 2, 1, 2], 2, 2);
7462 * // => 3
7463 */
7464 function indexOf(array, value, fromIndex) {
7465 var length = array == null ? 0 : array.length;
7466 if (!length) {
7467 return -1;
7468 }
7469 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7470 if (index < 0) {
7471 index = nativeMax(length + index, 0);
7472 }
7473 return baseIndexOf(array, value, index);
7474 }
7475
7476 /**
7477 * Gets all but the last element of `array`.
7478 *
7479 * @static
7480 * @memberOf _
7481 * @since 0.1.0
7482 * @category Array
7483 * @param {Array} array The array to query.
7484 * @returns {Array} Returns the slice of `array`.
7485 * @example
7486 *
7487 * _.initial([1, 2, 3]);
7488 * // => [1, 2]
7489 */
7490 function initial(array) {
7491 var length = array == null ? 0 : array.length;
7492 return length ? baseSlice(array, 0, -1) : [];
7493 }
7494
7495 /**
7496 * Creates an array of unique values that are included in all given arrays
7497 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7498 * for equality comparisons. The order and references of result values are
7499 * determined by the first array.
7500 *
7501 * @static
7502 * @memberOf _
7503 * @since 0.1.0
7504 * @category Array
7505 * @param {...Array} [arrays] The arrays to inspect.
7506 * @returns {Array} Returns the new array of intersecting values.
7507 * @example
7508 *
7509 * _.intersection([2, 1], [2, 3]);
7510 * // => [2]
7511 */
7512 var intersection = baseRest(function(arrays) {
7513 var mapped = arrayMap(arrays, castArrayLikeObject);
7514 return (mapped.length && mapped[0] === arrays[0])
7515 ? baseIntersection(mapped)
7516 : [];
7517 });
7518
7519 /**
7520 * This method is like `_.intersection` except that it accepts `iteratee`
7521 * which is invoked for each element of each `arrays` to generate the criterion
7522 * by which they're compared. The order and references of result values are
7523 * determined by the first array. The iteratee is invoked with one argument:
7524 * (value).
7525 *
7526 * @static
7527 * @memberOf _
7528 * @since 4.0.0
7529 * @category Array
7530 * @param {...Array} [arrays] The arrays to inspect.
7531 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7532 * @returns {Array} Returns the new array of intersecting values.
7533 * @example
7534 *
7535 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7536 * // => [2.1]
7537 *
7538 * // The `_.property` iteratee shorthand.
7539 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7540 * // => [{ 'x': 1 }]
7541 */
7542 var intersectionBy = baseRest(function(arrays) {
7543 var iteratee = last(arrays),
7544 mapped = arrayMap(arrays, castArrayLikeObject);
7545
7546 if (iteratee === last(mapped)) {
7547 iteratee = undefined;
7548 } else {
7549 mapped.pop();
7550 }
7551 return (mapped.length && mapped[0] === arrays[0])
7552 ? baseIntersection(mapped, getIteratee(iteratee, 2))
7553 : [];
7554 });
7555
7556 /**
7557 * This method is like `_.intersection` except that it accepts `comparator`
7558 * which is invoked to compare elements of `arrays`. The order and references
7559 * of result values are determined by the first array. The comparator is
7560 * invoked with two arguments: (arrVal, othVal).
7561 *
7562 * @static
7563 * @memberOf _
7564 * @since 4.0.0
7565 * @category Array
7566 * @param {...Array} [arrays] The arrays to inspect.
7567 * @param {Function} [comparator] The comparator invoked per element.
7568 * @returns {Array} Returns the new array of intersecting values.
7569 * @example
7570 *
7571 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7572 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7573 *
7574 * _.intersectionWith(objects, others, _.isEqual);
7575 * // => [{ 'x': 1, 'y': 2 }]
7576 */
7577 var intersectionWith = baseRest(function(arrays) {
7578 var comparator = last(arrays),
7579 mapped = arrayMap(arrays, castArrayLikeObject);
7580
7581 comparator = typeof comparator == 'function' ? comparator : undefined;
7582 if (comparator) {
7583 mapped.pop();
7584 }
7585 return (mapped.length && mapped[0] === arrays[0])
7586 ? baseIntersection(mapped, undefined, comparator)
7587 : [];
7588 });
7589
7590 /**
7591 * Converts all elements in `array` into a string separated by `separator`.
7592 *
7593 * @static
7594 * @memberOf _
7595 * @since 4.0.0
7596 * @category Array
7597 * @param {Array} array The array to convert.
7598 * @param {string} [separator=','] The element separator.
7599 * @returns {string} Returns the joined string.
7600 * @example
7601 *
7602 * _.join(['a', 'b', 'c'], '~');
7603 * // => 'a~b~c'
7604 */
7605 function join(array, separator) {
7606 return array == null ? '' : nativeJoin.call(array, separator);
7607 }
7608
7609 /**
7610 * Gets the last element of `array`.
7611 *
7612 * @static
7613 * @memberOf _
7614 * @since 0.1.0
7615 * @category Array
7616 * @param {Array} array The array to query.
7617 * @returns {*} Returns the last element of `array`.
7618 * @example
7619 *
7620 * _.last([1, 2, 3]);
7621 * // => 3
7622 */
7623 function last(array) {
7624 var length = array == null ? 0 : array.length;
7625 return length ? array[length - 1] : undefined;
7626 }
7627
7628 /**
7629 * This method is like `_.indexOf` except that it iterates over elements of
7630 * `array` from right to left.
7631 *
7632 * @static
7633 * @memberOf _
7634 * @since 0.1.0
7635 * @category Array
7636 * @param {Array} array The array to inspect.
7637 * @param {*} value The value to search for.
7638 * @param {number} [fromIndex=array.length-1] The index to search from.
7639 * @returns {number} Returns the index of the matched value, else `-1`.
7640 * @example
7641 *
7642 * _.lastIndexOf([1, 2, 1, 2], 2);
7643 * // => 3
7644 *
7645 * // Search from the `fromIndex`.
7646 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
7647 * // => 1
7648 */
7649 function lastIndexOf(array, value, fromIndex) {
7650 var length = array == null ? 0 : array.length;
7651 if (!length) {
7652 return -1;
7653 }
7654 var index = length;
7655 if (fromIndex !== undefined) {
7656 index = toInteger(fromIndex);
7657 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
7658 }
7659 return value === value
7660 ? strictLastIndexOf(array, value, index)
7661 : baseFindIndex(array, baseIsNaN, index, true);
7662 }
7663
7664 /**
7665 * Gets the element at index `n` of `array`. If `n` is negative, the nth
7666 * element from the end is returned.
7667 *
7668 * @static
7669 * @memberOf _
7670 * @since 4.11.0
7671 * @category Array
7672 * @param {Array} array The array to query.
7673 * @param {number} [n=0] The index of the element to return.
7674 * @returns {*} Returns the nth element of `array`.
7675 * @example
7676 *
7677 * var array = ['a', 'b', 'c', 'd'];
7678 *
7679 * _.nth(array, 1);
7680 * // => 'b'
7681 *
7682 * _.nth(array, -2);
7683 * // => 'c';
7684 */
7685 function nth(array, n) {
7686 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
7687 }
7688
7689 /**
7690 * Removes all given values from `array` using
7691 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7692 * for equality comparisons.
7693 *
7694 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
7695 * to remove elements from an array by predicate.
7696 *
7697 * @static
7698 * @memberOf _
7699 * @since 2.0.0
7700 * @category Array
7701 * @param {Array} array The array to modify.
7702 * @param {...*} [values] The values to remove.
7703 * @returns {Array} Returns `array`.
7704 * @example
7705 *
7706 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7707 *
7708 * _.pull(array, 'a', 'c');
7709 * console.log(array);
7710 * // => ['b', 'b']
7711 */
7712 var pull = baseRest(pullAll);
7713
7714 /**
7715 * This method is like `_.pull` except that it accepts an array of values to remove.
7716 *
7717 * **Note:** Unlike `_.difference`, this method mutates `array`.
7718 *
7719 * @static
7720 * @memberOf _
7721 * @since 4.0.0
7722 * @category Array
7723 * @param {Array} array The array to modify.
7724 * @param {Array} values The values to remove.
7725 * @returns {Array} Returns `array`.
7726 * @example
7727 *
7728 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7729 *
7730 * _.pullAll(array, ['a', 'c']);
7731 * console.log(array);
7732 * // => ['b', 'b']
7733 */
7734 function pullAll(array, values) {
7735 return (array && array.length && values && values.length)
7736 ? basePullAll(array, values)
7737 : array;
7738 }
7739
7740 /**
7741 * This method is like `_.pullAll` except that it accepts `iteratee` which is
7742 * invoked for each element of `array` and `values` to generate the criterion
7743 * by which they're compared. The iteratee is invoked with one argument: (value).
7744 *
7745 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
7746 *
7747 * @static
7748 * @memberOf _
7749 * @since 4.0.0
7750 * @category Array
7751 * @param {Array} array The array to modify.
7752 * @param {Array} values The values to remove.
7753 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7754 * @returns {Array} Returns `array`.
7755 * @example
7756 *
7757 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
7758 *
7759 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
7760 * console.log(array);
7761 * // => [{ 'x': 2 }]
7762 */
7763 function pullAllBy(array, values, iteratee) {
7764 return (array && array.length && values && values.length)
7765 ? basePullAll(array, values, getIteratee(iteratee, 2))
7766 : array;
7767 }
7768
7769 /**
7770 * This method is like `_.pullAll` except that it accepts `comparator` which
7771 * is invoked to compare elements of `array` to `values`. The comparator is
7772 * invoked with two arguments: (arrVal, othVal).
7773 *
7774 * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
7775 *
7776 * @static
7777 * @memberOf _
7778 * @since 4.6.0
7779 * @category Array
7780 * @param {Array} array The array to modify.
7781 * @param {Array} values The values to remove.
7782 * @param {Function} [comparator] The comparator invoked per element.
7783 * @returns {Array} Returns `array`.
7784 * @example
7785 *
7786 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
7787 *
7788 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
7789 * console.log(array);
7790 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
7791 */
7792 function pullAllWith(array, values, comparator) {
7793 return (array && array.length && values && values.length)
7794 ? basePullAll(array, values, undefined, comparator)
7795 : array;
7796 }
7797
7798 /**
7799 * Removes elements from `array` corresponding to `indexes` and returns an
7800 * array of removed elements.
7801 *
7802 * **Note:** Unlike `_.at`, this method mutates `array`.
7803 *
7804 * @static
7805 * @memberOf _
7806 * @since 3.0.0
7807 * @category Array
7808 * @param {Array} array The array to modify.
7809 * @param {...(number|number[])} [indexes] The indexes of elements to remove.
7810 * @returns {Array} Returns the new array of removed elements.
7811 * @example
7812 *
7813 * var array = ['a', 'b', 'c', 'd'];
7814 * var pulled = _.pullAt(array, [1, 3]);
7815 *
7816 * console.log(array);
7817 * // => ['a', 'c']
7818 *
7819 * console.log(pulled);
7820 * // => ['b', 'd']
7821 */
7822 var pullAt = flatRest(function(array, indexes) {
7823 var length = array == null ? 0 : array.length,
7824 result = baseAt(array, indexes);
7825
7826 basePullAt(array, arrayMap(indexes, function(index) {
7827 return isIndex(index, length) ? +index : index;
7828 }).sort(compareAscending));
7829
7830 return result;
7831 });
7832
7833 /**
7834 * Removes all elements from `array` that `predicate` returns truthy for
7835 * and returns an array of the removed elements. The predicate is invoked
7836 * with three arguments: (value, index, array).
7837 *
7838 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
7839 * to pull elements from an array by value.
7840 *
7841 * @static
7842 * @memberOf _
7843 * @since 2.0.0
7844 * @category Array
7845 * @param {Array} array The array to modify.
7846 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7847 * @returns {Array} Returns the new array of removed elements.
7848 * @example
7849 *
7850 * var array = [1, 2, 3, 4];
7851 * var evens = _.remove(array, function(n) {
7852 * return n % 2 == 0;
7853 * });
7854 *
7855 * console.log(array);
7856 * // => [1, 3]
7857 *
7858 * console.log(evens);
7859 * // => [2, 4]
7860 */
7861 function remove(array, predicate) {
7862 var result = [];
7863 if (!(array && array.length)) {
7864 return result;
7865 }
7866 var index = -1,
7867 indexes = [],
7868 length = array.length;
7869
7870 predicate = getIteratee(predicate, 3);
7871 while (++index < length) {
7872 var value = array[index];
7873 if (predicate(value, index, array)) {
7874 result.push(value);
7875 indexes.push(index);
7876 }
7877 }
7878 basePullAt(array, indexes);
7879 return result;
7880 }
7881
7882 /**
7883 * Reverses `array` so that the first element becomes the last, the second
7884 * element becomes the second to last, and so on.
7885 *
7886 * **Note:** This method mutates `array` and is based on
7887 * [`Array#reverse`](https://mdn.io/Array/reverse).
7888 *
7889 * @static
7890 * @memberOf _
7891 * @since 4.0.0
7892 * @category Array
7893 * @param {Array} array The array to modify.
7894 * @returns {Array} Returns `array`.
7895 * @example
7896 *
7897 * var array = [1, 2, 3];
7898 *
7899 * _.reverse(array);
7900 * // => [3, 2, 1]
7901 *
7902 * console.log(array);
7903 * // => [3, 2, 1]
7904 */
7905 function reverse(array) {
7906 return array == null ? array : nativeReverse.call(array);
7907 }
7908
7909 /**
7910 * Creates a slice of `array` from `start` up to, but not including, `end`.
7911 *
7912 * **Note:** This method is used instead of
7913 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
7914 * returned.
7915 *
7916 * @static
7917 * @memberOf _
7918 * @since 3.0.0
7919 * @category Array
7920 * @param {Array} array The array to slice.
7921 * @param {number} [start=0] The start position.
7922 * @param {number} [end=array.length] The end position.
7923 * @returns {Array} Returns the slice of `array`.
7924 */
7925 function slice(array, start, end) {
7926 var length = array == null ? 0 : array.length;
7927 if (!length) {
7928 return [];
7929 }
7930 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
7931 start = 0;
7932 end = length;
7933 }
7934 else {
7935 start = start == null ? 0 : toInteger(start);
7936 end = end === undefined ? length : toInteger(end);
7937 }
7938 return baseSlice(array, start, end);
7939 }
7940
7941 /**
7942 * Uses a binary search to determine the lowest index at which `value`
7943 * should be inserted into `array` in order to maintain its sort order.
7944 *
7945 * @static
7946 * @memberOf _
7947 * @since 0.1.0
7948 * @category Array
7949 * @param {Array} array The sorted array to inspect.
7950 * @param {*} value The value to evaluate.
7951 * @returns {number} Returns the index at which `value` should be inserted
7952 * into `array`.
7953 * @example
7954 *
7955 * _.sortedIndex([30, 50], 40);
7956 * // => 1
7957 */
7958 function sortedIndex(array, value) {
7959 return baseSortedIndex(array, value);
7960 }
7961
7962 /**
7963 * This method is like `_.sortedIndex` except that it accepts `iteratee`
7964 * which is invoked for `value` and each element of `array` to compute their
7965 * sort ranking. The iteratee is invoked with one argument: (value).
7966 *
7967 * @static
7968 * @memberOf _
7969 * @since 4.0.0
7970 * @category Array
7971 * @param {Array} array The sorted array to inspect.
7972 * @param {*} value The value to evaluate.
7973 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7974 * @returns {number} Returns the index at which `value` should be inserted
7975 * into `array`.
7976 * @example
7977 *
7978 * var objects = [{ 'x': 4 }, { 'x': 5 }];
7979 *
7980 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
7981 * // => 0
7982 *
7983 * // The `_.property` iteratee shorthand.
7984 * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
7985 * // => 0
7986 */
7987 function sortedIndexBy(array, value, iteratee) {
7988 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
7989 }
7990
7991 /**
7992 * This method is like `_.indexOf` except that it performs a binary
7993 * search on a sorted `array`.
7994 *
7995 * @static
7996 * @memberOf _
7997 * @since 4.0.0
7998 * @category Array
7999 * @param {Array} array The array to inspect.
8000 * @param {*} value The value to search for.
8001 * @returns {number} Returns the index of the matched value, else `-1`.
8002 * @example
8003 *
8004 * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
8005 * // => 1
8006 */
8007 function sortedIndexOf(array, value) {
8008 var length = array == null ? 0 : array.length;
8009 if (length) {
8010 var index = baseSortedIndex(array, value);
8011 if (index < length && eq(array[index], value)) {
8012 return index;
8013 }
8014 }
8015 return -1;
8016 }
8017
8018 /**
8019 * This method is like `_.sortedIndex` except that it returns the highest
8020 * index at which `value` should be inserted into `array` in order to
8021 * maintain its sort order.
8022 *
8023 * @static
8024 * @memberOf _
8025 * @since 3.0.0
8026 * @category Array
8027 * @param {Array} array The sorted array to inspect.
8028 * @param {*} value The value to evaluate.
8029 * @returns {number} Returns the index at which `value` should be inserted
8030 * into `array`.
8031 * @example
8032 *
8033 * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
8034 * // => 4
8035 */
8036 function sortedLastIndex(array, value) {
8037 return baseSortedIndex(array, value, true);
8038 }
8039
8040 /**
8041 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
8042 * which is invoked for `value` and each element of `array` to compute their
8043 * sort ranking. The iteratee is invoked with one argument: (value).
8044 *
8045 * @static
8046 * @memberOf _
8047 * @since 4.0.0
8048 * @category Array
8049 * @param {Array} array The sorted array to inspect.
8050 * @param {*} value The value to evaluate.
8051 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8052 * @returns {number} Returns the index at which `value` should be inserted
8053 * into `array`.
8054 * @example
8055 *
8056 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8057 *
8058 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8059 * // => 1
8060 *
8061 * // The `_.property` iteratee shorthand.
8062 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
8063 * // => 1
8064 */
8065 function sortedLastIndexBy(array, value, iteratee) {
8066 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
8067 }
8068
8069 /**
8070 * This method is like `_.lastIndexOf` except that it performs a binary
8071 * search on a sorted `array`.
8072 *
8073 * @static
8074 * @memberOf _
8075 * @since 4.0.0
8076 * @category Array
8077 * @param {Array} array The array to inspect.
8078 * @param {*} value The value to search for.
8079 * @returns {number} Returns the index of the matched value, else `-1`.
8080 * @example
8081 *
8082 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
8083 * // => 3
8084 */
8085 function sortedLastIndexOf(array, value) {
8086 var length = array == null ? 0 : array.length;
8087 if (length) {
8088 var index = baseSortedIndex(array, value, true) - 1;
8089 if (eq(array[index], value)) {
8090 return index;
8091 }
8092 }
8093 return -1;
8094 }
8095
8096 /**
8097 * This method is like `_.uniq` except that it's designed and optimized
8098 * for sorted arrays.
8099 *
8100 * @static
8101 * @memberOf _
8102 * @since 4.0.0
8103 * @category Array
8104 * @param {Array} array The array to inspect.
8105 * @returns {Array} Returns the new duplicate free array.
8106 * @example
8107 *
8108 * _.sortedUniq([1, 1, 2]);
8109 * // => [1, 2]
8110 */
8111 function sortedUniq(array) {
8112 return (array && array.length)
8113 ? baseSortedUniq(array)
8114 : [];
8115 }
8116
8117 /**
8118 * This method is like `_.uniqBy` except that it's designed and optimized
8119 * for sorted arrays.
8120 *
8121 * @static
8122 * @memberOf _
8123 * @since 4.0.0
8124 * @category Array
8125 * @param {Array} array The array to inspect.
8126 * @param {Function} [iteratee] The iteratee invoked per element.
8127 * @returns {Array} Returns the new duplicate free array.
8128 * @example
8129 *
8130 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
8131 * // => [1.1, 2.3]
8132 */
8133 function sortedUniqBy(array, iteratee) {
8134 return (array && array.length)
8135 ? baseSortedUniq(array, getIteratee(iteratee, 2))
8136 : [];
8137 }
8138
8139 /**
8140 * Gets all but the first element of `array`.
8141 *
8142 * @static
8143 * @memberOf _
8144 * @since 4.0.0
8145 * @category Array
8146 * @param {Array} array The array to query.
8147 * @returns {Array} Returns the slice of `array`.
8148 * @example
8149 *
8150 * _.tail([1, 2, 3]);
8151 * // => [2, 3]
8152 */
8153 function tail(array) {
8154 var length = array == null ? 0 : array.length;
8155 return length ? baseSlice(array, 1, length) : [];
8156 }
8157
8158 /**
8159 * Creates a slice of `array` with `n` elements taken from the beginning.
8160 *
8161 * @static
8162 * @memberOf _
8163 * @since 0.1.0
8164 * @category Array
8165 * @param {Array} array The array to query.
8166 * @param {number} [n=1] The number of elements to take.
8167 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8168 * @returns {Array} Returns the slice of `array`.
8169 * @example
8170 *
8171 * _.take([1, 2, 3]);
8172 * // => [1]
8173 *
8174 * _.take([1, 2, 3], 2);
8175 * // => [1, 2]
8176 *
8177 * _.take([1, 2, 3], 5);
8178 * // => [1, 2, 3]
8179 *
8180 * _.take([1, 2, 3], 0);
8181 * // => []
8182 */
8183 function take(array, n, guard) {
8184 if (!(array && array.length)) {
8185 return [];
8186 }
8187 n = (guard || n === undefined) ? 1 : toInteger(n);
8188 return baseSlice(array, 0, n < 0 ? 0 : n);
8189 }
8190
8191 /**
8192 * Creates a slice of `array` with `n` elements taken from the end.
8193 *
8194 * @static
8195 * @memberOf _
8196 * @since 3.0.0
8197 * @category Array
8198 * @param {Array} array The array to query.
8199 * @param {number} [n=1] The number of elements to take.
8200 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8201 * @returns {Array} Returns the slice of `array`.
8202 * @example
8203 *
8204 * _.takeRight([1, 2, 3]);
8205 * // => [3]
8206 *
8207 * _.takeRight([1, 2, 3], 2);
8208 * // => [2, 3]
8209 *
8210 * _.takeRight([1, 2, 3], 5);
8211 * // => [1, 2, 3]
8212 *
8213 * _.takeRight([1, 2, 3], 0);
8214 * // => []
8215 */
8216 function takeRight(array, n, guard) {
8217 var length = array == null ? 0 : array.length;
8218 if (!length) {
8219 return [];
8220 }
8221 n = (guard || n === undefined) ? 1 : toInteger(n);
8222 n = length - n;
8223 return baseSlice(array, n < 0 ? 0 : n, length);
8224 }
8225
8226 /**
8227 * Creates a slice of `array` with elements taken from the end. Elements are
8228 * taken until `predicate` returns falsey. The predicate is invoked with
8229 * three arguments: (value, index, array).
8230 *
8231 * @static
8232 * @memberOf _
8233 * @since 3.0.0
8234 * @category Array
8235 * @param {Array} array The array to query.
8236 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8237 * @returns {Array} Returns the slice of `array`.
8238 * @example
8239 *
8240 * var users = [
8241 * { 'user': 'barney', 'active': true },
8242 * { 'user': 'fred', 'active': false },
8243 * { 'user': 'pebbles', 'active': false }
8244 * ];
8245 *
8246 * _.takeRightWhile(users, function(o) { return !o.active; });
8247 * // => objects for ['fred', 'pebbles']
8248 *
8249 * // The `_.matches` iteratee shorthand.
8250 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
8251 * // => objects for ['pebbles']
8252 *
8253 * // The `_.matchesProperty` iteratee shorthand.
8254 * _.takeRightWhile(users, ['active', false]);
8255 * // => objects for ['fred', 'pebbles']
8256 *
8257 * // The `_.property` iteratee shorthand.
8258 * _.takeRightWhile(users, 'active');
8259 * // => []
8260 */
8261 function takeRightWhile(array, predicate) {
8262 return (array && array.length)
8263 ? baseWhile(array, getIteratee(predicate, 3), false, true)
8264 : [];
8265 }
8266
8267 /**
8268 * Creates a slice of `array` with elements taken from the beginning. Elements
8269 * are taken until `predicate` returns falsey. The predicate is invoked with
8270 * three arguments: (value, index, array).
8271 *
8272 * @static
8273 * @memberOf _
8274 * @since 3.0.0
8275 * @category Array
8276 * @param {Array} array The array to query.
8277 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8278 * @returns {Array} Returns the slice of `array`.
8279 * @example
8280 *
8281 * var users = [
8282 * { 'user': 'barney', 'active': false },
8283 * { 'user': 'fred', 'active': false},
8284 * { 'user': 'pebbles', 'active': true }
8285 * ];
8286 *
8287 * _.takeWhile(users, function(o) { return !o.active; });
8288 * // => objects for ['barney', 'fred']
8289 *
8290 * // The `_.matches` iteratee shorthand.
8291 * _.takeWhile(users, { 'user': 'barney', 'active': false });
8292 * // => objects for ['barney']
8293 *
8294 * // The `_.matchesProperty` iteratee shorthand.
8295 * _.takeWhile(users, ['active', false]);
8296 * // => objects for ['barney', 'fred']
8297 *
8298 * // The `_.property` iteratee shorthand.
8299 * _.takeWhile(users, 'active');
8300 * // => []
8301 */
8302 function takeWhile(array, predicate) {
8303 return (array && array.length)
8304 ? baseWhile(array, getIteratee(predicate, 3))
8305 : [];
8306 }
8307
8308 /**
8309 * Creates an array of unique values, in order, from all given arrays using
8310 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8311 * for equality comparisons.
8312 *
8313 * @static
8314 * @memberOf _
8315 * @since 0.1.0
8316 * @category Array
8317 * @param {...Array} [arrays] The arrays to inspect.
8318 * @returns {Array} Returns the new array of combined values.
8319 * @example
8320 *
8321 * _.union([2], [1, 2]);
8322 * // => [2, 1]
8323 */
8324 var union = baseRest(function(arrays) {
8325 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
8326 });
8327
8328 /**
8329 * This method is like `_.union` except that it accepts `iteratee` which is
8330 * invoked for each element of each `arrays` to generate the criterion by
8331 * which uniqueness is computed. Result values are chosen from the first
8332 * array in which the value occurs. The iteratee is invoked with one argument:
8333 * (value).
8334 *
8335 * @static
8336 * @memberOf _
8337 * @since 4.0.0
8338 * @category Array
8339 * @param {...Array} [arrays] The arrays to inspect.
8340 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8341 * @returns {Array} Returns the new array of combined values.
8342 * @example
8343 *
8344 * _.unionBy([2.1], [1.2, 2.3], Math.floor);
8345 * // => [2.1, 1.2]
8346 *
8347 * // The `_.property` iteratee shorthand.
8348 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8349 * // => [{ 'x': 1 }, { 'x': 2 }]
8350 */
8351 var unionBy = baseRest(function(arrays) {
8352 var iteratee = last(arrays);
8353 if (isArrayLikeObject(iteratee)) {
8354 iteratee = undefined;
8355 }
8356 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
8357 });
8358
8359 /**
8360 * This method is like `_.union` except that it accepts `comparator` which
8361 * is invoked to compare elements of `arrays`. Result values are chosen from
8362 * the first array in which the value occurs. The comparator is invoked
8363 * with two arguments: (arrVal, othVal).
8364 *
8365 * @static
8366 * @memberOf _
8367 * @since 4.0.0
8368 * @category Array
8369 * @param {...Array} [arrays] The arrays to inspect.
8370 * @param {Function} [comparator] The comparator invoked per element.
8371 * @returns {Array} Returns the new array of combined values.
8372 * @example
8373 *
8374 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8375 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8376 *
8377 * _.unionWith(objects, others, _.isEqual);
8378 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8379 */
8380 var unionWith = baseRest(function(arrays) {
8381 var comparator = last(arrays);
8382 comparator = typeof comparator == 'function' ? comparator : undefined;
8383 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
8384 });
8385
8386 /**
8387 * Creates a duplicate-free version of an array, using
8388 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8389 * for equality comparisons, in which only the first occurrence of each element
8390 * is kept. The order of result values is determined by the order they occur
8391 * in the array.
8392 *
8393 * @static
8394 * @memberOf _
8395 * @since 0.1.0
8396 * @category Array
8397 * @param {Array} array The array to inspect.
8398 * @returns {Array} Returns the new duplicate free array.
8399 * @example
8400 *
8401 * _.uniq([2, 1, 2]);
8402 * // => [2, 1]
8403 */
8404 function uniq(array) {
8405 return (array && array.length) ? baseUniq(array) : [];
8406 }
8407
8408 /**
8409 * This method is like `_.uniq` except that it accepts `iteratee` which is
8410 * invoked for each element in `array` to generate the criterion by which
8411 * uniqueness is computed. The order of result values is determined by the
8412 * order they occur in the array. The iteratee is invoked with one argument:
8413 * (value).
8414 *
8415 * @static
8416 * @memberOf _
8417 * @since 4.0.0
8418 * @category Array
8419 * @param {Array} array The array to inspect.
8420 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8421 * @returns {Array} Returns the new duplicate free array.
8422 * @example
8423 *
8424 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
8425 * // => [2.1, 1.2]
8426 *
8427 * // The `_.property` iteratee shorthand.
8428 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
8429 * // => [{ 'x': 1 }, { 'x': 2 }]
8430 */
8431 function uniqBy(array, iteratee) {
8432 return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
8433 }
8434
8435 /**
8436 * This method is like `_.uniq` except that it accepts `comparator` which
8437 * is invoked to compare elements of `array`. The order of result values is
8438 * determined by the order they occur in the array.The comparator is invoked
8439 * with two arguments: (arrVal, othVal).
8440 *
8441 * @static
8442 * @memberOf _
8443 * @since 4.0.0
8444 * @category Array
8445 * @param {Array} array The array to inspect.
8446 * @param {Function} [comparator] The comparator invoked per element.
8447 * @returns {Array} Returns the new duplicate free array.
8448 * @example
8449 *
8450 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
8451 *
8452 * _.uniqWith(objects, _.isEqual);
8453 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
8454 */
8455 function uniqWith(array, comparator) {
8456 comparator = typeof comparator == 'function' ? comparator : undefined;
8457 return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
8458 }
8459
8460 /**
8461 * This method is like `_.zip` except that it accepts an array of grouped
8462 * elements and creates an array regrouping the elements to their pre-zip
8463 * configuration.
8464 *
8465 * @static
8466 * @memberOf _
8467 * @since 1.2.0
8468 * @category Array
8469 * @param {Array} array The array of grouped elements to process.
8470 * @returns {Array} Returns the new array of regrouped elements.
8471 * @example
8472 *
8473 * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
8474 * // => [['a', 1, true], ['b', 2, false]]
8475 *
8476 * _.unzip(zipped);
8477 * // => [['a', 'b'], [1, 2], [true, false]]
8478 */
8479 function unzip(array) {
8480 if (!(array && array.length)) {
8481 return [];
8482 }
8483 var length = 0;
8484 array = arrayFilter(array, function(group) {
8485 if (isArrayLikeObject(group)) {
8486 length = nativeMax(group.length, length);
8487 return true;
8488 }
8489 });
8490 return baseTimes(length, function(index) {
8491 return arrayMap(array, baseProperty(index));
8492 });
8493 }
8494
8495 /**
8496 * This method is like `_.unzip` except that it accepts `iteratee` to specify
8497 * how regrouped values should be combined. The iteratee is invoked with the
8498 * elements of each group: (...group).
8499 *
8500 * @static
8501 * @memberOf _
8502 * @since 3.8.0
8503 * @category Array
8504 * @param {Array} array The array of grouped elements to process.
8505 * @param {Function} [iteratee=_.identity] The function to combine
8506 * regrouped values.
8507 * @returns {Array} Returns the new array of regrouped elements.
8508 * @example
8509 *
8510 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
8511 * // => [[1, 10, 100], [2, 20, 200]]
8512 *
8513 * _.unzipWith(zipped, _.add);
8514 * // => [3, 30, 300]
8515 */
8516 function unzipWith(array, iteratee) {
8517 if (!(array && array.length)) {
8518 return [];
8519 }
8520 var result = unzip(array);
8521 if (iteratee == null) {
8522 return result;
8523 }
8524 return arrayMap(result, function(group) {
8525 return apply(iteratee, undefined, group);
8526 });
8527 }
8528
8529 /**
8530 * Creates an array excluding all given values using
8531 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8532 * for equality comparisons.
8533 *
8534 * **Note:** Unlike `_.pull`, this method returns a new array.
8535 *
8536 * @static
8537 * @memberOf _
8538 * @since 0.1.0
8539 * @category Array
8540 * @param {Array} array The array to inspect.
8541 * @param {...*} [values] The values to exclude.
8542 * @returns {Array} Returns the new array of filtered values.
8543 * @see _.difference, _.xor
8544 * @example
8545 *
8546 * _.without([2, 1, 2, 3], 1, 2);
8547 * // => [3]
8548 */
8549 var without = baseRest(function(array, values) {
8550 return isArrayLikeObject(array)
8551 ? baseDifference(array, values)
8552 : [];
8553 });
8554
8555 /**
8556 * Creates an array of unique values that is the
8557 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
8558 * of the given arrays. The order of result values is determined by the order
8559 * they occur in the arrays.
8560 *
8561 * @static
8562 * @memberOf _
8563 * @since 2.4.0
8564 * @category Array
8565 * @param {...Array} [arrays] The arrays to inspect.
8566 * @returns {Array} Returns the new array of filtered values.
8567 * @see _.difference, _.without
8568 * @example
8569 *
8570 * _.xor([2, 1], [2, 3]);
8571 * // => [1, 3]
8572 */
8573 var xor = baseRest(function(arrays) {
8574 return baseXor(arrayFilter(arrays, isArrayLikeObject));
8575 });
8576
8577 /**
8578 * This method is like `_.xor` except that it accepts `iteratee` which is
8579 * invoked for each element of each `arrays` to generate the criterion by
8580 * which by which they're compared. The order of result values is determined
8581 * by the order they occur in the arrays. The iteratee is invoked with one
8582 * argument: (value).
8583 *
8584 * @static
8585 * @memberOf _
8586 * @since 4.0.0
8587 * @category Array
8588 * @param {...Array} [arrays] The arrays to inspect.
8589 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8590 * @returns {Array} Returns the new array of filtered values.
8591 * @example
8592 *
8593 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
8594 * // => [1.2, 3.4]
8595 *
8596 * // The `_.property` iteratee shorthand.
8597 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8598 * // => [{ 'x': 2 }]
8599 */
8600 var xorBy = baseRest(function(arrays) {
8601 var iteratee = last(arrays);
8602 if (isArrayLikeObject(iteratee)) {
8603 iteratee = undefined;
8604 }
8605 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
8606 });
8607
8608 /**
8609 * This method is like `_.xor` except that it accepts `comparator` which is
8610 * invoked to compare elements of `arrays`. The order of result values is
8611 * determined by the order they occur in the arrays. The comparator is invoked
8612 * with two arguments: (arrVal, othVal).
8613 *
8614 * @static
8615 * @memberOf _
8616 * @since 4.0.0
8617 * @category Array
8618 * @param {...Array} [arrays] The arrays to inspect.
8619 * @param {Function} [comparator] The comparator invoked per element.
8620 * @returns {Array} Returns the new array of filtered values.
8621 * @example
8622 *
8623 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8624 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8625 *
8626 * _.xorWith(objects, others, _.isEqual);
8627 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8628 */
8629 var xorWith = baseRest(function(arrays) {
8630 var comparator = last(arrays);
8631 comparator = typeof comparator == 'function' ? comparator : undefined;
8632 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
8633 });
8634
8635 /**
8636 * Creates an array of grouped elements, the first of which contains the
8637 * first elements of the given arrays, the second of which contains the
8638 * second elements of the given arrays, and so on.
8639 *
8640 * @static
8641 * @memberOf _
8642 * @since 0.1.0
8643 * @category Array
8644 * @param {...Array} [arrays] The arrays to process.
8645 * @returns {Array} Returns the new array of grouped elements.
8646 * @example
8647 *
8648 * _.zip(['a', 'b'], [1, 2], [true, false]);
8649 * // => [['a', 1, true], ['b', 2, false]]
8650 */
8651 var zip = baseRest(unzip);
8652
8653 /**
8654 * This method is like `_.fromPairs` except that it accepts two arrays,
8655 * one of property identifiers and one of corresponding values.
8656 *
8657 * @static
8658 * @memberOf _
8659 * @since 0.4.0
8660 * @category Array
8661 * @param {Array} [props=[]] The property identifiers.
8662 * @param {Array} [values=[]] The property values.
8663 * @returns {Object} Returns the new object.
8664 * @example
8665 *
8666 * _.zipObject(['a', 'b'], [1, 2]);
8667 * // => { 'a': 1, 'b': 2 }
8668 */
8669 function zipObject(props, values) {
8670 return baseZipObject(props || [], values || [], assignValue);
8671 }
8672
8673 /**
8674 * This method is like `_.zipObject` except that it supports property paths.
8675 *
8676 * @static
8677 * @memberOf _
8678 * @since 4.1.0
8679 * @category Array
8680 * @param {Array} [props=[]] The property identifiers.
8681 * @param {Array} [values=[]] The property values.
8682 * @returns {Object} Returns the new object.
8683 * @example
8684 *
8685 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
8686 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
8687 */
8688 function zipObjectDeep(props, values) {
8689 return baseZipObject(props || [], values || [], baseSet);
8690 }
8691
8692 /**
8693 * This method is like `_.zip` except that it accepts `iteratee` to specify
8694 * how grouped values should be combined. The iteratee is invoked with the
8695 * elements of each group: (...group).
8696 *
8697 * @static
8698 * @memberOf _
8699 * @since 3.8.0
8700 * @category Array
8701 * @param {...Array} [arrays] The arrays to process.
8702 * @param {Function} [iteratee=_.identity] The function to combine
8703 * grouped values.
8704 * @returns {Array} Returns the new array of grouped elements.
8705 * @example
8706 *
8707 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
8708 * return a + b + c;
8709 * });
8710 * // => [111, 222]
8711 */
8712 var zipWith = baseRest(function(arrays) {
8713 var length = arrays.length,
8714 iteratee = length > 1 ? arrays[length - 1] : undefined;
8715
8716 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
8717 return unzipWith(arrays, iteratee);
8718 });
8719
8720 /*------------------------------------------------------------------------*/
8721
8722 /**
8723 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
8724 * chain sequences enabled. The result of such sequences must be unwrapped
8725 * with `_#value`.
8726 *
8727 * @static
8728 * @memberOf _
8729 * @since 1.3.0
8730 * @category Seq
8731 * @param {*} value The value to wrap.
8732 * @returns {Object} Returns the new `lodash` wrapper instance.
8733 * @example
8734 *
8735 * var users = [
8736 * { 'user': 'barney', 'age': 36 },
8737 * { 'user': 'fred', 'age': 40 },
8738 * { 'user': 'pebbles', 'age': 1 }
8739 * ];
8740 *
8741 * var youngest = _
8742 * .chain(users)
8743 * .sortBy('age')
8744 * .map(function(o) {
8745 * return o.user + ' is ' + o.age;
8746 * })
8747 * .head()
8748 * .value();
8749 * // => 'pebbles is 1'
8750 */
8751 function chain(value) {
8752 var result = lodash(value);
8753 result.__chain__ = true;
8754 return result;
8755 }
8756
8757 /**
8758 * This method invokes `interceptor` and returns `value`. The interceptor
8759 * is invoked with one argument; (value). The purpose of this method is to
8760 * "tap into" a method chain sequence in order to modify intermediate results.
8761 *
8762 * @static
8763 * @memberOf _
8764 * @since 0.1.0
8765 * @category Seq
8766 * @param {*} value The value to provide to `interceptor`.
8767 * @param {Function} interceptor The function to invoke.
8768 * @returns {*} Returns `value`.
8769 * @example
8770 *
8771 * _([1, 2, 3])
8772 * .tap(function(array) {
8773 * // Mutate input array.
8774 * array.pop();
8775 * })
8776 * .reverse()
8777 * .value();
8778 * // => [2, 1]
8779 */
8780 function tap(value, interceptor) {
8781 interceptor(value);
8782 return value;
8783 }
8784
8785 /**
8786 * This method is like `_.tap` except that it returns the result of `interceptor`.
8787 * The purpose of this method is to "pass thru" values replacing intermediate
8788 * results in a method chain sequence.
8789 *
8790 * @static
8791 * @memberOf _
8792 * @since 3.0.0
8793 * @category Seq
8794 * @param {*} value The value to provide to `interceptor`.
8795 * @param {Function} interceptor The function to invoke.
8796 * @returns {*} Returns the result of `interceptor`.
8797 * @example
8798 *
8799 * _(' abc ')
8800 * .chain()
8801 * .trim()
8802 * .thru(function(value) {
8803 * return [value];
8804 * })
8805 * .value();
8806 * // => ['abc']
8807 */
8808 function thru(value, interceptor) {
8809 return interceptor(value);
8810 }
8811
8812 /**
8813 * This method is the wrapper version of `_.at`.
8814 *
8815 * @name at
8816 * @memberOf _
8817 * @since 1.0.0
8818 * @category Seq
8819 * @param {...(string|string[])} [paths] The property paths to pick.
8820 * @returns {Object} Returns the new `lodash` wrapper instance.
8821 * @example
8822 *
8823 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
8824 *
8825 * _(object).at(['a[0].b.c', 'a[1]']).value();
8826 * // => [3, 4]
8827 */
8828 var wrapperAt = flatRest(function(paths) {
8829 var length = paths.length,
8830 start = length ? paths[0] : 0,
8831 value = this.__wrapped__,
8832 interceptor = function(object) { return baseAt(object, paths); };
8833
8834 if (length > 1 || this.__actions__.length ||
8835 !(value instanceof LazyWrapper) || !isIndex(start)) {
8836 return this.thru(interceptor);
8837 }
8838 value = value.slice(start, +start + (length ? 1 : 0));
8839 value.__actions__.push({
8840 'func': thru,
8841 'args': [interceptor],
8842 'thisArg': undefined
8843 });
8844 return new LodashWrapper(value, this.__chain__).thru(function(array) {
8845 if (length && !array.length) {
8846 array.push(undefined);
8847 }
8848 return array;
8849 });
8850 });
8851
8852 /**
8853 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
8854 *
8855 * @name chain
8856 * @memberOf _
8857 * @since 0.1.0
8858 * @category Seq
8859 * @returns {Object} Returns the new `lodash` wrapper instance.
8860 * @example
8861 *
8862 * var users = [
8863 * { 'user': 'barney', 'age': 36 },
8864 * { 'user': 'fred', 'age': 40 }
8865 * ];
8866 *
8867 * // A sequence without explicit chaining.
8868 * _(users).head();
8869 * // => { 'user': 'barney', 'age': 36 }
8870 *
8871 * // A sequence with explicit chaining.
8872 * _(users)
8873 * .chain()
8874 * .head()
8875 * .pick('user')
8876 * .value();
8877 * // => { 'user': 'barney' }
8878 */
8879 function wrapperChain() {
8880 return chain(this);
8881 }
8882
8883 /**
8884 * Executes the chain sequence and returns the wrapped result.
8885 *
8886 * @name commit
8887 * @memberOf _
8888 * @since 3.2.0
8889 * @category Seq
8890 * @returns {Object} Returns the new `lodash` wrapper instance.
8891 * @example
8892 *
8893 * var array = [1, 2];
8894 * var wrapped = _(array).push(3);
8895 *
8896 * console.log(array);
8897 * // => [1, 2]
8898 *
8899 * wrapped = wrapped.commit();
8900 * console.log(array);
8901 * // => [1, 2, 3]
8902 *
8903 * wrapped.last();
8904 * // => 3
8905 *
8906 * console.log(array);
8907 * // => [1, 2, 3]
8908 */
8909 function wrapperCommit() {
8910 return new LodashWrapper(this.value(), this.__chain__);
8911 }
8912
8913 /**
8914 * Gets the next value on a wrapped object following the
8915 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
8916 *
8917 * @name next
8918 * @memberOf _
8919 * @since 4.0.0
8920 * @category Seq
8921 * @returns {Object} Returns the next iterator value.
8922 * @example
8923 *
8924 * var wrapped = _([1, 2]);
8925 *
8926 * wrapped.next();
8927 * // => { 'done': false, 'value': 1 }
8928 *
8929 * wrapped.next();
8930 * // => { 'done': false, 'value': 2 }
8931 *
8932 * wrapped.next();
8933 * // => { 'done': true, 'value': undefined }
8934 */
8935 function wrapperNext() {
8936 if (this.__values__ === undefined) {
8937 this.__values__ = toArray(this.value());
8938 }
8939 var done = this.__index__ >= this.__values__.length,
8940 value = done ? undefined : this.__values__[this.__index__++];
8941
8942 return { 'done': done, 'value': value };
8943 }
8944
8945 /**
8946 * Enables the wrapper to be iterable.
8947 *
8948 * @name Symbol.iterator
8949 * @memberOf _
8950 * @since 4.0.0
8951 * @category Seq
8952 * @returns {Object} Returns the wrapper object.
8953 * @example
8954 *
8955 * var wrapped = _([1, 2]);
8956 *
8957 * wrapped[Symbol.iterator]() === wrapped;
8958 * // => true
8959 *
8960 * Array.from(wrapped);
8961 * // => [1, 2]
8962 */
8963 function wrapperToIterator() {
8964 return this;
8965 }
8966
8967 /**
8968 * Creates a clone of the chain sequence planting `value` as the wrapped value.
8969 *
8970 * @name plant
8971 * @memberOf _
8972 * @since 3.2.0
8973 * @category Seq
8974 * @param {*} value The value to plant.
8975 * @returns {Object} Returns the new `lodash` wrapper instance.
8976 * @example
8977 *
8978 * function square(n) {
8979 * return n * n;
8980 * }
8981 *
8982 * var wrapped = _([1, 2]).map(square);
8983 * var other = wrapped.plant([3, 4]);
8984 *
8985 * other.value();
8986 * // => [9, 16]
8987 *
8988 * wrapped.value();
8989 * // => [1, 4]
8990 */
8991 function wrapperPlant(value) {
8992 var result,
8993 parent = this;
8994
8995 while (parent instanceof baseLodash) {
8996 var clone = wrapperClone(parent);
8997 clone.__index__ = 0;
8998 clone.__values__ = undefined;
8999 if (result) {
9000 previous.__wrapped__ = clone;
9001 } else {
9002 result = clone;
9003 }
9004 var previous = clone;
9005 parent = parent.__wrapped__;
9006 }
9007 previous.__wrapped__ = value;
9008 return result;
9009 }
9010
9011 /**
9012 * This method is the wrapper version of `_.reverse`.
9013 *
9014 * **Note:** This method mutates the wrapped array.
9015 *
9016 * @name reverse
9017 * @memberOf _
9018 * @since 0.1.0
9019 * @category Seq
9020 * @returns {Object} Returns the new `lodash` wrapper instance.
9021 * @example
9022 *
9023 * var array = [1, 2, 3];
9024 *
9025 * _(array).reverse().value()
9026 * // => [3, 2, 1]
9027 *
9028 * console.log(array);
9029 * // => [3, 2, 1]
9030 */
9031 function wrapperReverse() {
9032 var value = this.__wrapped__;
9033 if (value instanceof LazyWrapper) {
9034 var wrapped = value;
9035 if (this.__actions__.length) {
9036 wrapped = new LazyWrapper(this);
9037 }
9038 wrapped = wrapped.reverse();
9039 wrapped.__actions__.push({
9040 'func': thru,
9041 'args': [reverse],
9042 'thisArg': undefined
9043 });
9044 return new LodashWrapper(wrapped, this.__chain__);
9045 }
9046 return this.thru(reverse);
9047 }
9048
9049 /**
9050 * Executes the chain sequence to resolve the unwrapped value.
9051 *
9052 * @name value
9053 * @memberOf _
9054 * @since 0.1.0
9055 * @alias toJSON, valueOf
9056 * @category Seq
9057 * @returns {*} Returns the resolved unwrapped value.
9058 * @example
9059 *
9060 * _([1, 2, 3]).value();
9061 * // => [1, 2, 3]
9062 */
9063 function wrapperValue() {
9064 return baseWrapperValue(this.__wrapped__, this.__actions__);
9065 }
9066
9067 /*------------------------------------------------------------------------*/
9068
9069 /**
9070 * Creates an object composed of keys generated from the results of running
9071 * each element of `collection` thru `iteratee`. The corresponding value of
9072 * each key is the number of times the key was returned by `iteratee`. The
9073 * iteratee is invoked with one argument: (value).
9074 *
9075 * @static
9076 * @memberOf _
9077 * @since 0.5.0
9078 * @category Collection
9079 * @param {Array|Object} collection The collection to iterate over.
9080 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9081 * @returns {Object} Returns the composed aggregate object.
9082 * @example
9083 *
9084 * _.countBy([6.1, 4.2, 6.3], Math.floor);
9085 * // => { '4': 1, '6': 2 }
9086 *
9087 * // The `_.property` iteratee shorthand.
9088 * _.countBy(['one', 'two', 'three'], 'length');
9089 * // => { '3': 2, '5': 1 }
9090 */
9091 var countBy = createAggregator(function(result, value, key) {
9092 if (hasOwnProperty.call(result, key)) {
9093 ++result[key];
9094 } else {
9095 baseAssignValue(result, key, 1);
9096 }
9097 });
9098
9099 /**
9100 * Checks if `predicate` returns truthy for **all** elements of `collection`.
9101 * Iteration is stopped once `predicate` returns falsey. The predicate is
9102 * invoked with three arguments: (value, index|key, collection).
9103 *
9104 * **Note:** This method returns `true` for
9105 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
9106 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
9107 * elements of empty collections.
9108 *
9109 * @static
9110 * @memberOf _
9111 * @since 0.1.0
9112 * @category Collection
9113 * @param {Array|Object} collection The collection to iterate over.
9114 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9115 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9116 * @returns {boolean} Returns `true` if all elements pass the predicate check,
9117 * else `false`.
9118 * @example
9119 *
9120 * _.every([true, 1, null, 'yes'], Boolean);
9121 * // => false
9122 *
9123 * var users = [
9124 * { 'user': 'barney', 'age': 36, 'active': false },
9125 * { 'user': 'fred', 'age': 40, 'active': false }
9126 * ];
9127 *
9128 * // The `_.matches` iteratee shorthand.
9129 * _.every(users, { 'user': 'barney', 'active': false });
9130 * // => false
9131 *
9132 * // The `_.matchesProperty` iteratee shorthand.
9133 * _.every(users, ['active', false]);
9134 * // => true
9135 *
9136 * // The `_.property` iteratee shorthand.
9137 * _.every(users, 'active');
9138 * // => false
9139 */
9140 function every(collection, predicate, guard) {
9141 var func = isArray(collection) ? arrayEvery : baseEvery;
9142 if (guard && isIterateeCall(collection, predicate, guard)) {
9143 predicate = undefined;
9144 }
9145 return func(collection, getIteratee(predicate, 3));
9146 }
9147
9148 /**
9149 * Iterates over elements of `collection`, returning an array of all elements
9150 * `predicate` returns truthy for. The predicate is invoked with three
9151 * arguments: (value, index|key, collection).
9152 *
9153 * **Note:** Unlike `_.remove`, this method returns a new array.
9154 *
9155 * @static
9156 * @memberOf _
9157 * @since 0.1.0
9158 * @category Collection
9159 * @param {Array|Object} collection The collection to iterate over.
9160 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9161 * @returns {Array} Returns the new filtered array.
9162 * @see _.reject
9163 * @example
9164 *
9165 * var users = [
9166 * { 'user': 'barney', 'age': 36, 'active': true },
9167 * { 'user': 'fred', 'age': 40, 'active': false }
9168 * ];
9169 *
9170 * _.filter(users, function(o) { return !o.active; });
9171 * // => objects for ['fred']
9172 *
9173 * // The `_.matches` iteratee shorthand.
9174 * _.filter(users, { 'age': 36, 'active': true });
9175 * // => objects for ['barney']
9176 *
9177 * // The `_.matchesProperty` iteratee shorthand.
9178 * _.filter(users, ['active', false]);
9179 * // => objects for ['fred']
9180 *
9181 * // The `_.property` iteratee shorthand.
9182 * _.filter(users, 'active');
9183 * // => objects for ['barney']
9184 */
9185 function filter(collection, predicate) {
9186 var func = isArray(collection) ? arrayFilter : baseFilter;
9187 return func(collection, getIteratee(predicate, 3));
9188 }
9189
9190 /**
9191 * Iterates over elements of `collection`, returning the first element
9192 * `predicate` returns truthy for. The predicate is invoked with three
9193 * arguments: (value, index|key, collection).
9194 *
9195 * @static
9196 * @memberOf _
9197 * @since 0.1.0
9198 * @category Collection
9199 * @param {Array|Object} collection The collection to inspect.
9200 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9201 * @param {number} [fromIndex=0] The index to search from.
9202 * @returns {*} Returns the matched element, else `undefined`.
9203 * @example
9204 *
9205 * var users = [
9206 * { 'user': 'barney', 'age': 36, 'active': true },
9207 * { 'user': 'fred', 'age': 40, 'active': false },
9208 * { 'user': 'pebbles', 'age': 1, 'active': true }
9209 * ];
9210 *
9211 * _.find(users, function(o) { return o.age < 40; });
9212 * // => object for 'barney'
9213 *
9214 * // The `_.matches` iteratee shorthand.
9215 * _.find(users, { 'age': 1, 'active': true });
9216 * // => object for 'pebbles'
9217 *
9218 * // The `_.matchesProperty` iteratee shorthand.
9219 * _.find(users, ['active', false]);
9220 * // => object for 'fred'
9221 *
9222 * // The `_.property` iteratee shorthand.
9223 * _.find(users, 'active');
9224 * // => object for 'barney'
9225 */
9226 var find = createFind(findIndex);
9227
9228 /**
9229 * This method is like `_.find` except that it iterates over elements of
9230 * `collection` from right to left.
9231 *
9232 * @static
9233 * @memberOf _
9234 * @since 2.0.0
9235 * @category Collection
9236 * @param {Array|Object} collection The collection to inspect.
9237 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9238 * @param {number} [fromIndex=collection.length-1] The index to search from.
9239 * @returns {*} Returns the matched element, else `undefined`.
9240 * @example
9241 *
9242 * _.findLast([1, 2, 3, 4], function(n) {
9243 * return n % 2 == 1;
9244 * });
9245 * // => 3
9246 */
9247 var findLast = createFind(findLastIndex);
9248
9249 /**
9250 * Creates a flattened array of values by running each element in `collection`
9251 * thru `iteratee` and flattening the mapped results. The iteratee is invoked
9252 * with three arguments: (value, index|key, collection).
9253 *
9254 * @static
9255 * @memberOf _
9256 * @since 4.0.0
9257 * @category Collection
9258 * @param {Array|Object} collection The collection to iterate over.
9259 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9260 * @returns {Array} Returns the new flattened array.
9261 * @example
9262 *
9263 * function duplicate(n) {
9264 * return [n, n];
9265 * }
9266 *
9267 * _.flatMap([1, 2], duplicate);
9268 * // => [1, 1, 2, 2]
9269 */
9270 function flatMap(collection, iteratee) {
9271 return baseFlatten(map(collection, iteratee), 1);
9272 }
9273
9274 /**
9275 * This method is like `_.flatMap` except that it recursively flattens the
9276 * mapped results.
9277 *
9278 * @static
9279 * @memberOf _
9280 * @since 4.7.0
9281 * @category Collection
9282 * @param {Array|Object} collection The collection to iterate over.
9283 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9284 * @returns {Array} Returns the new flattened array.
9285 * @example
9286 *
9287 * function duplicate(n) {
9288 * return [[[n, n]]];
9289 * }
9290 *
9291 * _.flatMapDeep([1, 2], duplicate);
9292 * // => [1, 1, 2, 2]
9293 */
9294 function flatMapDeep(collection, iteratee) {
9295 return baseFlatten(map(collection, iteratee), INFINITY);
9296 }
9297
9298 /**
9299 * This method is like `_.flatMap` except that it recursively flattens the
9300 * mapped results up to `depth` times.
9301 *
9302 * @static
9303 * @memberOf _
9304 * @since 4.7.0
9305 * @category Collection
9306 * @param {Array|Object} collection The collection to iterate over.
9307 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9308 * @param {number} [depth=1] The maximum recursion depth.
9309 * @returns {Array} Returns the new flattened array.
9310 * @example
9311 *
9312 * function duplicate(n) {
9313 * return [[[n, n]]];
9314 * }
9315 *
9316 * _.flatMapDepth([1, 2], duplicate, 2);
9317 * // => [[1, 1], [2, 2]]
9318 */
9319 function flatMapDepth(collection, iteratee, depth) {
9320 depth = depth === undefined ? 1 : toInteger(depth);
9321 return baseFlatten(map(collection, iteratee), depth);
9322 }
9323
9324 /**
9325 * Iterates over elements of `collection` and invokes `iteratee` for each element.
9326 * The iteratee is invoked with three arguments: (value, index|key, collection).
9327 * Iteratee functions may exit iteration early by explicitly returning `false`.
9328 *
9329 * **Note:** As with other "Collections" methods, objects with a "length"
9330 * property are iterated like arrays. To avoid this behavior use `_.forIn`
9331 * or `_.forOwn` for object iteration.
9332 *
9333 * @static
9334 * @memberOf _
9335 * @since 0.1.0
9336 * @alias each
9337 * @category Collection
9338 * @param {Array|Object} collection The collection to iterate over.
9339 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9340 * @returns {Array|Object} Returns `collection`.
9341 * @see _.forEachRight
9342 * @example
9343 *
9344 * _.forEach([1, 2], function(value) {
9345 * console.log(value);
9346 * });
9347 * // => Logs `1` then `2`.
9348 *
9349 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
9350 * console.log(key);
9351 * });
9352 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
9353 */
9354 function forEach(collection, iteratee) {
9355 var func = isArray(collection) ? arrayEach : baseEach;
9356 return func(collection, getIteratee(iteratee, 3));
9357 }
9358
9359 /**
9360 * This method is like `_.forEach` except that it iterates over elements of
9361 * `collection` from right to left.
9362 *
9363 * @static
9364 * @memberOf _
9365 * @since 2.0.0
9366 * @alias eachRight
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|Object} Returns `collection`.
9371 * @see _.forEach
9372 * @example
9373 *
9374 * _.forEachRight([1, 2], function(value) {
9375 * console.log(value);
9376 * });
9377 * // => Logs `2` then `1`.
9378 */
9379 function forEachRight(collection, iteratee) {
9380 var func = isArray(collection) ? arrayEachRight : baseEachRight;
9381 return func(collection, getIteratee(iteratee, 3));
9382 }
9383
9384 /**
9385 * Creates an object composed of keys generated from the results of running
9386 * each element of `collection` thru `iteratee`. The order of grouped values
9387 * is determined by the order they occur in `collection`. The corresponding
9388 * value of each key is an array of elements responsible for generating the
9389 * key. The iteratee is invoked with one argument: (value).
9390 *
9391 * @static
9392 * @memberOf _
9393 * @since 0.1.0
9394 * @category Collection
9395 * @param {Array|Object} collection The collection to iterate over.
9396 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9397 * @returns {Object} Returns the composed aggregate object.
9398 * @example
9399 *
9400 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
9401 * // => { '4': [4.2], '6': [6.1, 6.3] }
9402 *
9403 * // The `_.property` iteratee shorthand.
9404 * _.groupBy(['one', 'two', 'three'], 'length');
9405 * // => { '3': ['one', 'two'], '5': ['three'] }
9406 */
9407 var groupBy = createAggregator(function(result, value, key) {
9408 if (hasOwnProperty.call(result, key)) {
9409 result[key].push(value);
9410 } else {
9411 baseAssignValue(result, key, [value]);
9412 }
9413 });
9414
9415 /**
9416 * Checks if `value` is in `collection`. If `collection` is a string, it's
9417 * checked for a substring of `value`, otherwise
9418 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
9419 * is used for equality comparisons. If `fromIndex` is negative, it's used as
9420 * the offset from the end of `collection`.
9421 *
9422 * @static
9423 * @memberOf _
9424 * @since 0.1.0
9425 * @category Collection
9426 * @param {Array|Object|string} collection The collection to inspect.
9427 * @param {*} value The value to search for.
9428 * @param {number} [fromIndex=0] The index to search from.
9429 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9430 * @returns {boolean} Returns `true` if `value` is found, else `false`.
9431 * @example
9432 *
9433 * _.includes([1, 2, 3], 1);
9434 * // => true
9435 *
9436 * _.includes([1, 2, 3], 1, 2);
9437 * // => false
9438 *
9439 * _.includes({ 'a': 1, 'b': 2 }, 1);
9440 * // => true
9441 *
9442 * _.includes('abcd', 'bc');
9443 * // => true
9444 */
9445 function includes(collection, value, fromIndex, guard) {
9446 collection = isArrayLike(collection) ? collection : values(collection);
9447 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
9448
9449 var length = collection.length;
9450 if (fromIndex < 0) {
9451 fromIndex = nativeMax(length + fromIndex, 0);
9452 }
9453 return isString(collection)
9454 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
9455 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
9456 }
9457
9458 /**
9459 * Invokes the method at `path` of each element in `collection`, returning
9460 * an array of the results of each invoked method. Any additional arguments
9461 * are provided to each invoked method. If `path` is a function, it's invoked
9462 * for, and `this` bound to, each element in `collection`.
9463 *
9464 * @static
9465 * @memberOf _
9466 * @since 4.0.0
9467 * @category Collection
9468 * @param {Array|Object} collection The collection to iterate over.
9469 * @param {Array|Function|string} path The path of the method to invoke or
9470 * the function invoked per iteration.
9471 * @param {...*} [args] The arguments to invoke each method with.
9472 * @returns {Array} Returns the array of results.
9473 * @example
9474 *
9475 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
9476 * // => [[1, 5, 7], [1, 2, 3]]
9477 *
9478 * _.invokeMap([123, 456], String.prototype.split, '');
9479 * // => [['1', '2', '3'], ['4', '5', '6']]
9480 */
9481 var invokeMap = baseRest(function(collection, path, args) {
9482 var index = -1,
9483 isFunc = typeof path == 'function',
9484 isProp = isKey(path),
9485 result = isArrayLike(collection) ? Array(collection.length) : [];
9486
9487 baseEach(collection, function(value) {
9488 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
9489 result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
9490 });
9491 return result;
9492 });
9493
9494 /**
9495 * Creates an object composed of keys generated from the results of running
9496 * each element of `collection` thru `iteratee`. The corresponding value of
9497 * each key is the last element responsible for generating the key. The
9498 * iteratee is invoked with one argument: (value).
9499 *
9500 * @static
9501 * @memberOf _
9502 * @since 4.0.0
9503 * @category Collection
9504 * @param {Array|Object} collection The collection to iterate over.
9505 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9506 * @returns {Object} Returns the composed aggregate object.
9507 * @example
9508 *
9509 * var array = [
9510 * { 'dir': 'left', 'code': 97 },
9511 * { 'dir': 'right', 'code': 100 }
9512 * ];
9513 *
9514 * _.keyBy(array, function(o) {
9515 * return String.fromCharCode(o.code);
9516 * });
9517 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
9518 *
9519 * _.keyBy(array, 'dir');
9520 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
9521 */
9522 var keyBy = createAggregator(function(result, value, key) {
9523 baseAssignValue(result, key, value);
9524 });
9525
9526 /**
9527 * Creates an array of values by running each element in `collection` thru
9528 * `iteratee`. The iteratee is invoked with three arguments:
9529 * (value, index|key, collection).
9530 *
9531 * Many lodash methods are guarded to work as iteratees for methods like
9532 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
9533 *
9534 * The guarded methods are:
9535 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
9536 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
9537 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
9538 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
9539 *
9540 * @static
9541 * @memberOf _
9542 * @since 0.1.0
9543 * @category Collection
9544 * @param {Array|Object} collection The collection to iterate over.
9545 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9546 * @returns {Array} Returns the new mapped array.
9547 * @example
9548 *
9549 * function square(n) {
9550 * return n * n;
9551 * }
9552 *
9553 * _.map([4, 8], square);
9554 * // => [16, 64]
9555 *
9556 * _.map({ 'a': 4, 'b': 8 }, square);
9557 * // => [16, 64] (iteration order is not guaranteed)
9558 *
9559 * var users = [
9560 * { 'user': 'barney' },
9561 * { 'user': 'fred' }
9562 * ];
9563 *
9564 * // The `_.property` iteratee shorthand.
9565 * _.map(users, 'user');
9566 * // => ['barney', 'fred']
9567 */
9568 function map(collection, iteratee) {
9569 var func = isArray(collection) ? arrayMap : baseMap;
9570 return func(collection, getIteratee(iteratee, 3));
9571 }
9572
9573 /**
9574 * This method is like `_.sortBy` except that it allows specifying the sort
9575 * orders of the iteratees to sort by. If `orders` is unspecified, all values
9576 * are sorted in ascending order. Otherwise, specify an order of "desc" for
9577 * descending or "asc" for ascending sort order of corresponding values.
9578 *
9579 * @static
9580 * @memberOf _
9581 * @since 4.0.0
9582 * @category Collection
9583 * @param {Array|Object} collection The collection to iterate over.
9584 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
9585 * The iteratees to sort by.
9586 * @param {string[]} [orders] The sort orders of `iteratees`.
9587 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9588 * @returns {Array} Returns the new sorted array.
9589 * @example
9590 *
9591 * var users = [
9592 * { 'user': 'fred', 'age': 48 },
9593 * { 'user': 'barney', 'age': 34 },
9594 * { 'user': 'fred', 'age': 40 },
9595 * { 'user': 'barney', 'age': 36 }
9596 * ];
9597 *
9598 * // Sort by `user` in ascending order and by `age` in descending order.
9599 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
9600 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9601 */
9602 function orderBy(collection, iteratees, orders, guard) {
9603 if (collection == null) {
9604 return [];
9605 }
9606 if (!isArray(iteratees)) {
9607 iteratees = iteratees == null ? [] : [iteratees];
9608 }
9609 orders = guard ? undefined : orders;
9610 if (!isArray(orders)) {
9611 orders = orders == null ? [] : [orders];
9612 }
9613 return baseOrderBy(collection, iteratees, orders);
9614 }
9615
9616 /**
9617 * Creates an array of elements split into two groups, the first of which
9618 * contains elements `predicate` returns truthy for, the second of which
9619 * contains elements `predicate` returns falsey for. The predicate is
9620 * invoked with one argument: (value).
9621 *
9622 * @static
9623 * @memberOf _
9624 * @since 3.0.0
9625 * @category Collection
9626 * @param {Array|Object} collection The collection to iterate over.
9627 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9628 * @returns {Array} Returns the array of grouped elements.
9629 * @example
9630 *
9631 * var users = [
9632 * { 'user': 'barney', 'age': 36, 'active': false },
9633 * { 'user': 'fred', 'age': 40, 'active': true },
9634 * { 'user': 'pebbles', 'age': 1, 'active': false }
9635 * ];
9636 *
9637 * _.partition(users, function(o) { return o.active; });
9638 * // => objects for [['fred'], ['barney', 'pebbles']]
9639 *
9640 * // The `_.matches` iteratee shorthand.
9641 * _.partition(users, { 'age': 1, 'active': false });
9642 * // => objects for [['pebbles'], ['barney', 'fred']]
9643 *
9644 * // The `_.matchesProperty` iteratee shorthand.
9645 * _.partition(users, ['active', false]);
9646 * // => objects for [['barney', 'pebbles'], ['fred']]
9647 *
9648 * // The `_.property` iteratee shorthand.
9649 * _.partition(users, 'active');
9650 * // => objects for [['fred'], ['barney', 'pebbles']]
9651 */
9652 var partition = createAggregator(function(result, value, key) {
9653 result[key ? 0 : 1].push(value);
9654 }, function() { return [[], []]; });
9655
9656 /**
9657 * Reduces `collection` to a value which is the accumulated result of running
9658 * each element in `collection` thru `iteratee`, where each successive
9659 * invocation is supplied the return value of the previous. If `accumulator`
9660 * is not given, the first element of `collection` is used as the initial
9661 * value. The iteratee is invoked with four arguments:
9662 * (accumulator, value, index|key, collection).
9663 *
9664 * Many lodash methods are guarded to work as iteratees for methods like
9665 * `_.reduce`, `_.reduceRight`, and `_.transform`.
9666 *
9667 * The guarded methods are:
9668 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
9669 * and `sortBy`
9670 *
9671 * @static
9672 * @memberOf _
9673 * @since 0.1.0
9674 * @category Collection
9675 * @param {Array|Object} collection The collection to iterate over.
9676 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9677 * @param {*} [accumulator] The initial value.
9678 * @returns {*} Returns the accumulated value.
9679 * @see _.reduceRight
9680 * @example
9681 *
9682 * _.reduce([1, 2], function(sum, n) {
9683 * return sum + n;
9684 * }, 0);
9685 * // => 3
9686 *
9687 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
9688 * (result[value] || (result[value] = [])).push(key);
9689 * return result;
9690 * }, {});
9691 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
9692 */
9693 function reduce(collection, iteratee, accumulator) {
9694 var func = isArray(collection) ? arrayReduce : baseReduce,
9695 initAccum = arguments.length < 3;
9696
9697 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
9698 }
9699
9700 /**
9701 * This method is like `_.reduce` except that it iterates over elements of
9702 * `collection` from right to left.
9703 *
9704 * @static
9705 * @memberOf _
9706 * @since 0.1.0
9707 * @category Collection
9708 * @param {Array|Object} collection The collection to iterate over.
9709 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9710 * @param {*} [accumulator] The initial value.
9711 * @returns {*} Returns the accumulated value.
9712 * @see _.reduce
9713 * @example
9714 *
9715 * var array = [[0, 1], [2, 3], [4, 5]];
9716 *
9717 * _.reduceRight(array, function(flattened, other) {
9718 * return flattened.concat(other);
9719 * }, []);
9720 * // => [4, 5, 2, 3, 0, 1]
9721 */
9722 function reduceRight(collection, iteratee, accumulator) {
9723 var func = isArray(collection) ? arrayReduceRight : baseReduce,
9724 initAccum = arguments.length < 3;
9725
9726 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
9727 }
9728
9729 /**
9730 * The opposite of `_.filter`; this method returns the elements of `collection`
9731 * that `predicate` does **not** return truthy for.
9732 *
9733 * @static
9734 * @memberOf _
9735 * @since 0.1.0
9736 * @category Collection
9737 * @param {Array|Object} collection The collection to iterate over.
9738 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9739 * @returns {Array} Returns the new filtered array.
9740 * @see _.filter
9741 * @example
9742 *
9743 * var users = [
9744 * { 'user': 'barney', 'age': 36, 'active': false },
9745 * { 'user': 'fred', 'age': 40, 'active': true }
9746 * ];
9747 *
9748 * _.reject(users, function(o) { return !o.active; });
9749 * // => objects for ['fred']
9750 *
9751 * // The `_.matches` iteratee shorthand.
9752 * _.reject(users, { 'age': 40, 'active': true });
9753 * // => objects for ['barney']
9754 *
9755 * // The `_.matchesProperty` iteratee shorthand.
9756 * _.reject(users, ['active', false]);
9757 * // => objects for ['fred']
9758 *
9759 * // The `_.property` iteratee shorthand.
9760 * _.reject(users, 'active');
9761 * // => objects for ['barney']
9762 */
9763 function reject(collection, predicate) {
9764 var func = isArray(collection) ? arrayFilter : baseFilter;
9765 return func(collection, negate(getIteratee(predicate, 3)));
9766 }
9767
9768 /**
9769 * Gets a random element from `collection`.
9770 *
9771 * @static
9772 * @memberOf _
9773 * @since 2.0.0
9774 * @category Collection
9775 * @param {Array|Object} collection The collection to sample.
9776 * @returns {*} Returns the random element.
9777 * @example
9778 *
9779 * _.sample([1, 2, 3, 4]);
9780 * // => 2
9781 */
9782 function sample(collection) {
9783 var func = isArray(collection) ? arraySample : baseSample;
9784 return func(collection);
9785 }
9786
9787 /**
9788 * Gets `n` random elements at unique keys from `collection` up to the
9789 * size of `collection`.
9790 *
9791 * @static
9792 * @memberOf _
9793 * @since 4.0.0
9794 * @category Collection
9795 * @param {Array|Object} collection The collection to sample.
9796 * @param {number} [n=1] The number of elements to sample.
9797 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9798 * @returns {Array} Returns the random elements.
9799 * @example
9800 *
9801 * _.sampleSize([1, 2, 3], 2);
9802 * // => [3, 1]
9803 *
9804 * _.sampleSize([1, 2, 3], 4);
9805 * // => [2, 3, 1]
9806 */
9807 function sampleSize(collection, n, guard) {
9808 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
9809 n = 1;
9810 } else {
9811 n = toInteger(n);
9812 }
9813 var func = isArray(collection) ? arraySampleSize : baseSampleSize;
9814 return func(collection, n);
9815 }
9816
9817 /**
9818 * Creates an array of shuffled values, using a version of the
9819 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
9820 *
9821 * @static
9822 * @memberOf _
9823 * @since 0.1.0
9824 * @category Collection
9825 * @param {Array|Object} collection The collection to shuffle.
9826 * @returns {Array} Returns the new shuffled array.
9827 * @example
9828 *
9829 * _.shuffle([1, 2, 3, 4]);
9830 * // => [4, 1, 3, 2]
9831 */
9832 function shuffle(collection) {
9833 var func = isArray(collection) ? arrayShuffle : baseShuffle;
9834 return func(collection);
9835 }
9836
9837 /**
9838 * Gets the size of `collection` by returning its length for array-like
9839 * values or the number of own enumerable string keyed properties for objects.
9840 *
9841 * @static
9842 * @memberOf _
9843 * @since 0.1.0
9844 * @category Collection
9845 * @param {Array|Object|string} collection The collection to inspect.
9846 * @returns {number} Returns the collection size.
9847 * @example
9848 *
9849 * _.size([1, 2, 3]);
9850 * // => 3
9851 *
9852 * _.size({ 'a': 1, 'b': 2 });
9853 * // => 2
9854 *
9855 * _.size('pebbles');
9856 * // => 7
9857 */
9858 function size(collection) {
9859 if (collection == null) {
9860 return 0;
9861 }
9862 if (isArrayLike(collection)) {
9863 return isString(collection) ? stringSize(collection) : collection.length;
9864 }
9865 var tag = getTag(collection);
9866 if (tag == mapTag || tag == setTag) {
9867 return collection.size;
9868 }
9869 return baseKeys(collection).length;
9870 }
9871
9872 /**
9873 * Checks if `predicate` returns truthy for **any** element of `collection`.
9874 * Iteration is stopped once `predicate` returns truthy. The predicate is
9875 * invoked with three arguments: (value, index|key, collection).
9876 *
9877 * @static
9878 * @memberOf _
9879 * @since 0.1.0
9880 * @category Collection
9881 * @param {Array|Object} collection The collection to iterate over.
9882 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9883 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9884 * @returns {boolean} Returns `true` if any element passes the predicate check,
9885 * else `false`.
9886 * @example
9887 *
9888 * _.some([null, 0, 'yes', false], Boolean);
9889 * // => true
9890 *
9891 * var users = [
9892 * { 'user': 'barney', 'active': true },
9893 * { 'user': 'fred', 'active': false }
9894 * ];
9895 *
9896 * // The `_.matches` iteratee shorthand.
9897 * _.some(users, { 'user': 'barney', 'active': false });
9898 * // => false
9899 *
9900 * // The `_.matchesProperty` iteratee shorthand.
9901 * _.some(users, ['active', false]);
9902 * // => true
9903 *
9904 * // The `_.property` iteratee shorthand.
9905 * _.some(users, 'active');
9906 * // => true
9907 */
9908 function some(collection, predicate, guard) {
9909 var func = isArray(collection) ? arraySome : baseSome;
9910 if (guard && isIterateeCall(collection, predicate, guard)) {
9911 predicate = undefined;
9912 }
9913 return func(collection, getIteratee(predicate, 3));
9914 }
9915
9916 /**
9917 * Creates an array of elements, sorted in ascending order by the results of
9918 * running each element in a collection thru each iteratee. This method
9919 * performs a stable sort, that is, it preserves the original sort order of
9920 * equal elements. The iteratees are invoked with one argument: (value).
9921 *
9922 * @static
9923 * @memberOf _
9924 * @since 0.1.0
9925 * @category Collection
9926 * @param {Array|Object} collection The collection to iterate over.
9927 * @param {...(Function|Function[])} [iteratees=[_.identity]]
9928 * The iteratees to sort by.
9929 * @returns {Array} Returns the new sorted array.
9930 * @example
9931 *
9932 * var users = [
9933 * { 'user': 'fred', 'age': 48 },
9934 * { 'user': 'barney', 'age': 36 },
9935 * { 'user': 'fred', 'age': 40 },
9936 * { 'user': 'barney', 'age': 34 }
9937 * ];
9938 *
9939 * _.sortBy(users, [function(o) { return o.user; }]);
9940 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9941 *
9942 * _.sortBy(users, ['user', 'age']);
9943 * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
9944 */
9945 var sortBy = baseRest(function(collection, iteratees) {
9946 if (collection == null) {
9947 return [];
9948 }
9949 var length = iteratees.length;
9950 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
9951 iteratees = [];
9952 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
9953 iteratees = [iteratees[0]];
9954 }
9955 return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
9956 });
9957
9958 /*------------------------------------------------------------------------*/
9959
9960 /**
9961 * Gets the timestamp of the number of milliseconds that have elapsed since
9962 * the Unix epoch (1 January 1970 00:00:00 UTC).
9963 *
9964 * @static
9965 * @memberOf _
9966 * @since 2.4.0
9967 * @category Date
9968 * @returns {number} Returns the timestamp.
9969 * @example
9970 *
9971 * _.defer(function(stamp) {
9972 * console.log(_.now() - stamp);
9973 * }, _.now());
9974 * // => Logs the number of milliseconds it took for the deferred invocation.
9975 */
9976 var now = ctxNow || function() {
9977 return root.Date.now();
9978 };
9979
9980 /*------------------------------------------------------------------------*/
9981
9982 /**
9983 * The opposite of `_.before`; this method creates a function that invokes
9984 * `func` once it's called `n` or more times.
9985 *
9986 * @static
9987 * @memberOf _
9988 * @since 0.1.0
9989 * @category Function
9990 * @param {number} n The number of calls before `func` is invoked.
9991 * @param {Function} func The function to restrict.
9992 * @returns {Function} Returns the new restricted function.
9993 * @example
9994 *
9995 * var saves = ['profile', 'settings'];
9996 *
9997 * var done = _.after(saves.length, function() {
9998 * console.log('done saving!');
9999 * });
10000 *
10001 * _.forEach(saves, function(type) {
10002 * asyncSave({ 'type': type, 'complete': done });
10003 * });
10004 * // => Logs 'done saving!' after the two async saves have completed.
10005 */
10006 function after(n, func) {
10007 if (typeof func != 'function') {
10008 throw new TypeError(FUNC_ERROR_TEXT);
10009 }
10010 n = toInteger(n);
10011 return function() {
10012 if (--n < 1) {
10013 return func.apply(this, arguments);
10014 }
10015 };
10016 }
10017
10018 /**
10019 * Creates a function that invokes `func`, with up to `n` arguments,
10020 * ignoring any additional arguments.
10021 *
10022 * @static
10023 * @memberOf _
10024 * @since 3.0.0
10025 * @category Function
10026 * @param {Function} func The function to cap arguments for.
10027 * @param {number} [n=func.length] The arity cap.
10028 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10029 * @returns {Function} Returns the new capped function.
10030 * @example
10031 *
10032 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
10033 * // => [6, 8, 10]
10034 */
10035 function ary(func, n, guard) {
10036 n = guard ? undefined : n;
10037 n = (func && n == null) ? func.length : n;
10038 return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
10039 }
10040
10041 /**
10042 * Creates a function that invokes `func`, with the `this` binding and arguments
10043 * of the created function, while it's called less than `n` times. Subsequent
10044 * calls to the created function return the result of the last `func` invocation.
10045 *
10046 * @static
10047 * @memberOf _
10048 * @since 3.0.0
10049 * @category Function
10050 * @param {number} n The number of calls at which `func` is no longer invoked.
10051 * @param {Function} func The function to restrict.
10052 * @returns {Function} Returns the new restricted function.
10053 * @example
10054 *
10055 * jQuery(element).on('click', _.before(5, addContactToList));
10056 * // => Allows adding up to 4 contacts to the list.
10057 */
10058 function before(n, func) {
10059 var result;
10060 if (typeof func != 'function') {
10061 throw new TypeError(FUNC_ERROR_TEXT);
10062 }
10063 n = toInteger(n);
10064 return function() {
10065 if (--n > 0) {
10066 result = func.apply(this, arguments);
10067 }
10068 if (n <= 1) {
10069 func = undefined;
10070 }
10071 return result;
10072 };
10073 }
10074
10075 /**
10076 * Creates a function that invokes `func` with the `this` binding of `thisArg`
10077 * and `partials` prepended to the arguments it receives.
10078 *
10079 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
10080 * may be used as a placeholder for partially applied arguments.
10081 *
10082 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
10083 * property of bound functions.
10084 *
10085 * @static
10086 * @memberOf _
10087 * @since 0.1.0
10088 * @category Function
10089 * @param {Function} func The function to bind.
10090 * @param {*} thisArg The `this` binding of `func`.
10091 * @param {...*} [partials] The arguments to be partially applied.
10092 * @returns {Function} Returns the new bound function.
10093 * @example
10094 *
10095 * function greet(greeting, punctuation) {
10096 * return greeting + ' ' + this.user + punctuation;
10097 * }
10098 *
10099 * var object = { 'user': 'fred' };
10100 *
10101 * var bound = _.bind(greet, object, 'hi');
10102 * bound('!');
10103 * // => 'hi fred!'
10104 *
10105 * // Bound with placeholders.
10106 * var bound = _.bind(greet, object, _, '!');
10107 * bound('hi');
10108 * // => 'hi fred!'
10109 */
10110 var bind = baseRest(function(func, thisArg, partials) {
10111 var bitmask = WRAP_BIND_FLAG;
10112 if (partials.length) {
10113 var holders = replaceHolders(partials, getHolder(bind));
10114 bitmask |= WRAP_PARTIAL_FLAG;
10115 }
10116 return createWrap(func, bitmask, thisArg, partials, holders);
10117 });
10118
10119 /**
10120 * Creates a function that invokes the method at `object[key]` with `partials`
10121 * prepended to the arguments it receives.
10122 *
10123 * This method differs from `_.bind` by allowing bound functions to reference
10124 * methods that may be redefined or don't yet exist. See
10125 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
10126 * for more details.
10127 *
10128 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
10129 * builds, may be used as a placeholder for partially applied arguments.
10130 *
10131 * @static
10132 * @memberOf _
10133 * @since 0.10.0
10134 * @category Function
10135 * @param {Object} object The object to invoke the method on.
10136 * @param {string} key The key of the method.
10137 * @param {...*} [partials] The arguments to be partially applied.
10138 * @returns {Function} Returns the new bound function.
10139 * @example
10140 *
10141 * var object = {
10142 * 'user': 'fred',
10143 * 'greet': function(greeting, punctuation) {
10144 * return greeting + ' ' + this.user + punctuation;
10145 * }
10146 * };
10147 *
10148 * var bound = _.bindKey(object, 'greet', 'hi');
10149 * bound('!');
10150 * // => 'hi fred!'
10151 *
10152 * object.greet = function(greeting, punctuation) {
10153 * return greeting + 'ya ' + this.user + punctuation;
10154 * };
10155 *
10156 * bound('!');
10157 * // => 'hiya fred!'
10158 *
10159 * // Bound with placeholders.
10160 * var bound = _.bindKey(object, 'greet', _, '!');
10161 * bound('hi');
10162 * // => 'hiya fred!'
10163 */
10164 var bindKey = baseRest(function(object, key, partials) {
10165 var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
10166 if (partials.length) {
10167 var holders = replaceHolders(partials, getHolder(bindKey));
10168 bitmask |= WRAP_PARTIAL_FLAG;
10169 }
10170 return createWrap(key, bitmask, object, partials, holders);
10171 });
10172
10173 /**
10174 * Creates a function that accepts arguments of `func` and either invokes
10175 * `func` returning its result, if at least `arity` number of arguments have
10176 * been provided, or returns a function that accepts the remaining `func`
10177 * arguments, and so on. The arity of `func` may be specified if `func.length`
10178 * is not sufficient.
10179 *
10180 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
10181 * may be used as a placeholder for provided arguments.
10182 *
10183 * **Note:** This method doesn't set the "length" property of curried functions.
10184 *
10185 * @static
10186 * @memberOf _
10187 * @since 2.0.0
10188 * @category Function
10189 * @param {Function} func The function to curry.
10190 * @param {number} [arity=func.length] The arity of `func`.
10191 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10192 * @returns {Function} Returns the new curried function.
10193 * @example
10194 *
10195 * var abc = function(a, b, c) {
10196 * return [a, b, c];
10197 * };
10198 *
10199 * var curried = _.curry(abc);
10200 *
10201 * curried(1)(2)(3);
10202 * // => [1, 2, 3]
10203 *
10204 * curried(1, 2)(3);
10205 * // => [1, 2, 3]
10206 *
10207 * curried(1, 2, 3);
10208 * // => [1, 2, 3]
10209 *
10210 * // Curried with placeholders.
10211 * curried(1)(_, 3)(2);
10212 * // => [1, 2, 3]
10213 */
10214 function curry(func, arity, guard) {
10215 arity = guard ? undefined : arity;
10216 var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10217 result.placeholder = curry.placeholder;
10218 return result;
10219 }
10220
10221 /**
10222 * This method is like `_.curry` except that arguments are applied to `func`
10223 * in the manner of `_.partialRight` instead of `_.partial`.
10224 *
10225 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
10226 * builds, may be used as a placeholder for provided arguments.
10227 *
10228 * **Note:** This method doesn't set the "length" property of curried functions.
10229 *
10230 * @static
10231 * @memberOf _
10232 * @since 3.0.0
10233 * @category Function
10234 * @param {Function} func The function to curry.
10235 * @param {number} [arity=func.length] The arity of `func`.
10236 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10237 * @returns {Function} Returns the new curried function.
10238 * @example
10239 *
10240 * var abc = function(a, b, c) {
10241 * return [a, b, c];
10242 * };
10243 *
10244 * var curried = _.curryRight(abc);
10245 *
10246 * curried(3)(2)(1);
10247 * // => [1, 2, 3]
10248 *
10249 * curried(2, 3)(1);
10250 * // => [1, 2, 3]
10251 *
10252 * curried(1, 2, 3);
10253 * // => [1, 2, 3]
10254 *
10255 * // Curried with placeholders.
10256 * curried(3)(1, _)(2);
10257 * // => [1, 2, 3]
10258 */
10259 function curryRight(func, arity, guard) {
10260 arity = guard ? undefined : arity;
10261 var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10262 result.placeholder = curryRight.placeholder;
10263 return result;
10264 }
10265
10266 /**
10267 * Creates a debounced function that delays invoking `func` until after `wait`
10268 * milliseconds have elapsed since the last time the debounced function was
10269 * invoked. The debounced function comes with a `cancel` method to cancel
10270 * delayed `func` invocations and a `flush` method to immediately invoke them.
10271 * Provide `options` to indicate whether `func` should be invoked on the
10272 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
10273 * with the last arguments provided to the debounced function. Subsequent
10274 * calls to the debounced function return the result of the last `func`
10275 * invocation.
10276 *
10277 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10278 * invoked on the trailing edge of the timeout only if the debounced function
10279 * is invoked more than once during the `wait` timeout.
10280 *
10281 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10282 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10283 *
10284 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10285 * for details over the differences between `_.debounce` and `_.throttle`.
10286 *
10287 * @static
10288 * @memberOf _
10289 * @since 0.1.0
10290 * @category Function
10291 * @param {Function} func The function to debounce.
10292 * @param {number} [wait=0] The number of milliseconds to delay.
10293 * @param {Object} [options={}] The options object.
10294 * @param {boolean} [options.leading=false]
10295 * Specify invoking on the leading edge of the timeout.
10296 * @param {number} [options.maxWait]
10297 * The maximum time `func` is allowed to be delayed before it's invoked.
10298 * @param {boolean} [options.trailing=true]
10299 * Specify invoking on the trailing edge of the timeout.
10300 * @returns {Function} Returns the new debounced function.
10301 * @example
10302 *
10303 * // Avoid costly calculations while the window size is in flux.
10304 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
10305 *
10306 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
10307 * jQuery(element).on('click', _.debounce(sendMail, 300, {
10308 * 'leading': true,
10309 * 'trailing': false
10310 * }));
10311 *
10312 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
10313 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
10314 * var source = new EventSource('/stream');
10315 * jQuery(source).on('message', debounced);
10316 *
10317 * // Cancel the trailing debounced invocation.
10318 * jQuery(window).on('popstate', debounced.cancel);
10319 */
10320 function debounce(func, wait, options) {
10321 var lastArgs,
10322 lastThis,
10323 maxWait,
10324 result,
10325 timerId,
10326 lastCallTime,
10327 lastInvokeTime = 0,
10328 leading = false,
10329 maxing = false,
10330 trailing = true;
10331
10332 if (typeof func != 'function') {
10333 throw new TypeError(FUNC_ERROR_TEXT);
10334 }
10335 wait = toNumber(wait) || 0;
10336 if (isObject(options)) {
10337 leading = !!options.leading;
10338 maxing = 'maxWait' in options;
10339 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
10340 trailing = 'trailing' in options ? !!options.trailing : trailing;
10341 }
10342
10343 function invokeFunc(time) {
10344 var args = lastArgs,
10345 thisArg = lastThis;
10346
10347 lastArgs = lastThis = undefined;
10348 lastInvokeTime = time;
10349 result = func.apply(thisArg, args);
10350 return result;
10351 }
10352
10353 function leadingEdge(time) {
10354 // Reset any `maxWait` timer.
10355 lastInvokeTime = time;
10356 // Start the timer for the trailing edge.
10357 timerId = setTimeout(timerExpired, wait);
10358 // Invoke the leading edge.
10359 return leading ? invokeFunc(time) : result;
10360 }
10361
10362 function remainingWait(time) {
10363 var timeSinceLastCall = time - lastCallTime,
10364 timeSinceLastInvoke = time - lastInvokeTime,
10365 result = wait - timeSinceLastCall;
10366
10367 return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
10368 }
10369
10370 function shouldInvoke(time) {
10371 var timeSinceLastCall = time - lastCallTime,
10372 timeSinceLastInvoke = time - lastInvokeTime;
10373
10374 // Either this is the first call, activity has stopped and we're at the
10375 // trailing edge, the system time has gone backwards and we're treating
10376 // it as the trailing edge, or we've hit the `maxWait` limit.
10377 return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
10378 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
10379 }
10380
10381 function timerExpired() {
10382 var time = now();
10383 if (shouldInvoke(time)) {
10384 return trailingEdge(time);
10385 }
10386 // Restart the timer.
10387 timerId = setTimeout(timerExpired, remainingWait(time));
10388 }
10389
10390 function trailingEdge(time) {
10391 timerId = undefined;
10392
10393 // Only invoke if we have `lastArgs` which means `func` has been
10394 // debounced at least once.
10395 if (trailing && lastArgs) {
10396 return invokeFunc(time);
10397 }
10398 lastArgs = lastThis = undefined;
10399 return result;
10400 }
10401
10402 function cancel() {
10403 if (timerId !== undefined) {
10404 clearTimeout(timerId);
10405 }
10406 lastInvokeTime = 0;
10407 lastArgs = lastCallTime = lastThis = timerId = undefined;
10408 }
10409
10410 function flush() {
10411 return timerId === undefined ? result : trailingEdge(now());
10412 }
10413
10414 function debounced() {
10415 var time = now(),
10416 isInvoking = shouldInvoke(time);
10417
10418 lastArgs = arguments;
10419 lastThis = this;
10420 lastCallTime = time;
10421
10422 if (isInvoking) {
10423 if (timerId === undefined) {
10424 return leadingEdge(lastCallTime);
10425 }
10426 if (maxing) {
10427 // Handle invocations in a tight loop.
10428 timerId = setTimeout(timerExpired, wait);
10429 return invokeFunc(lastCallTime);
10430 }
10431 }
10432 if (timerId === undefined) {
10433 timerId = setTimeout(timerExpired, wait);
10434 }
10435 return result;
10436 }
10437 debounced.cancel = cancel;
10438 debounced.flush = flush;
10439 return debounced;
10440 }
10441
10442 /**
10443 * Defers invoking the `func` until the current call stack has cleared. Any
10444 * additional arguments are provided to `func` when it's invoked.
10445 *
10446 * @static
10447 * @memberOf _
10448 * @since 0.1.0
10449 * @category Function
10450 * @param {Function} func The function to defer.
10451 * @param {...*} [args] The arguments to invoke `func` with.
10452 * @returns {number} Returns the timer id.
10453 * @example
10454 *
10455 * _.defer(function(text) {
10456 * console.log(text);
10457 * }, 'deferred');
10458 * // => Logs 'deferred' after one millisecond.
10459 */
10460 var defer = baseRest(function(func, args) {
10461 return baseDelay(func, 1, args);
10462 });
10463
10464 /**
10465 * Invokes `func` after `wait` milliseconds. Any additional arguments are
10466 * provided to `func` when it's invoked.
10467 *
10468 * @static
10469 * @memberOf _
10470 * @since 0.1.0
10471 * @category Function
10472 * @param {Function} func The function to delay.
10473 * @param {number} wait The number of milliseconds to delay invocation.
10474 * @param {...*} [args] The arguments to invoke `func` with.
10475 * @returns {number} Returns the timer id.
10476 * @example
10477 *
10478 * _.delay(function(text) {
10479 * console.log(text);
10480 * }, 1000, 'later');
10481 * // => Logs 'later' after one second.
10482 */
10483 var delay = baseRest(function(func, wait, args) {
10484 return baseDelay(func, toNumber(wait) || 0, args);
10485 });
10486
10487 /**
10488 * Creates a function that invokes `func` with arguments reversed.
10489 *
10490 * @static
10491 * @memberOf _
10492 * @since 4.0.0
10493 * @category Function
10494 * @param {Function} func The function to flip arguments for.
10495 * @returns {Function} Returns the new flipped function.
10496 * @example
10497 *
10498 * var flipped = _.flip(function() {
10499 * return _.toArray(arguments);
10500 * });
10501 *
10502 * flipped('a', 'b', 'c', 'd');
10503 * // => ['d', 'c', 'b', 'a']
10504 */
10505 function flip(func) {
10506 return createWrap(func, WRAP_FLIP_FLAG);
10507 }
10508
10509 /**
10510 * Creates a function that memoizes the result of `func`. If `resolver` is
10511 * provided, it determines the cache key for storing the result based on the
10512 * arguments provided to the memoized function. By default, the first argument
10513 * provided to the memoized function is used as the map cache key. The `func`
10514 * is invoked with the `this` binding of the memoized function.
10515 *
10516 * **Note:** The cache is exposed as the `cache` property on the memoized
10517 * function. Its creation may be customized by replacing the `_.memoize.Cache`
10518 * constructor with one whose instances implement the
10519 * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
10520 * method interface of `clear`, `delete`, `get`, `has`, and `set`.
10521 *
10522 * @static
10523 * @memberOf _
10524 * @since 0.1.0
10525 * @category Function
10526 * @param {Function} func The function to have its output memoized.
10527 * @param {Function} [resolver] The function to resolve the cache key.
10528 * @returns {Function} Returns the new memoized function.
10529 * @example
10530 *
10531 * var object = { 'a': 1, 'b': 2 };
10532 * var other = { 'c': 3, 'd': 4 };
10533 *
10534 * var values = _.memoize(_.values);
10535 * values(object);
10536 * // => [1, 2]
10537 *
10538 * values(other);
10539 * // => [3, 4]
10540 *
10541 * object.a = 2;
10542 * values(object);
10543 * // => [1, 2]
10544 *
10545 * // Modify the result cache.
10546 * values.cache.set(object, ['a', 'b']);
10547 * values(object);
10548 * // => ['a', 'b']
10549 *
10550 * // Replace `_.memoize.Cache`.
10551 * _.memoize.Cache = WeakMap;
10552 */
10553 function memoize(func, resolver) {
10554 if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
10555 throw new TypeError(FUNC_ERROR_TEXT);
10556 }
10557 var memoized = function() {
10558 var args = arguments,
10559 key = resolver ? resolver.apply(this, args) : args[0],
10560 cache = memoized.cache;
10561
10562 if (cache.has(key)) {
10563 return cache.get(key);
10564 }
10565 var result = func.apply(this, args);
10566 memoized.cache = cache.set(key, result) || cache;
10567 return result;
10568 };
10569 memoized.cache = new (memoize.Cache || MapCache);
10570 return memoized;
10571 }
10572
10573 // Expose `MapCache`.
10574 memoize.Cache = MapCache;
10575
10576 /**
10577 * Creates a function that negates the result of the predicate `func`. The
10578 * `func` predicate is invoked with the `this` binding and arguments of the
10579 * created function.
10580 *
10581 * @static
10582 * @memberOf _
10583 * @since 3.0.0
10584 * @category Function
10585 * @param {Function} predicate The predicate to negate.
10586 * @returns {Function} Returns the new negated function.
10587 * @example
10588 *
10589 * function isEven(n) {
10590 * return n % 2 == 0;
10591 * }
10592 *
10593 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
10594 * // => [1, 3, 5]
10595 */
10596 function negate(predicate) {
10597 if (typeof predicate != 'function') {
10598 throw new TypeError(FUNC_ERROR_TEXT);
10599 }
10600 return function() {
10601 var args = arguments;
10602 switch (args.length) {
10603 case 0: return !predicate.call(this);
10604 case 1: return !predicate.call(this, args[0]);
10605 case 2: return !predicate.call(this, args[0], args[1]);
10606 case 3: return !predicate.call(this, args[0], args[1], args[2]);
10607 }
10608 return !predicate.apply(this, args);
10609 };
10610 }
10611
10612 /**
10613 * Creates a function that is restricted to invoking `func` once. Repeat calls
10614 * to the function return the value of the first invocation. The `func` is
10615 * invoked with the `this` binding and arguments of the created function.
10616 *
10617 * @static
10618 * @memberOf _
10619 * @since 0.1.0
10620 * @category Function
10621 * @param {Function} func The function to restrict.
10622 * @returns {Function} Returns the new restricted function.
10623 * @example
10624 *
10625 * var initialize = _.once(createApplication);
10626 * initialize();
10627 * initialize();
10628 * // => `createApplication` is invoked once
10629 */
10630 function once(func) {
10631 return before(2, func);
10632 }
10633
10634 /**
10635 * Creates a function that invokes `func` with its arguments transformed.
10636 *
10637 * @static
10638 * @since 4.0.0
10639 * @memberOf _
10640 * @category Function
10641 * @param {Function} func The function to wrap.
10642 * @param {...(Function|Function[])} [transforms=[_.identity]]
10643 * The argument transforms.
10644 * @returns {Function} Returns the new function.
10645 * @example
10646 *
10647 * function doubled(n) {
10648 * return n * 2;
10649 * }
10650 *
10651 * function square(n) {
10652 * return n * n;
10653 * }
10654 *
10655 * var func = _.overArgs(function(x, y) {
10656 * return [x, y];
10657 * }, [square, doubled]);
10658 *
10659 * func(9, 3);
10660 * // => [81, 6]
10661 *
10662 * func(10, 5);
10663 * // => [100, 10]
10664 */
10665 var overArgs = castRest(function(func, transforms) {
10666 transforms = (transforms.length == 1 && isArray(transforms[0]))
10667 ? arrayMap(transforms[0], baseUnary(getIteratee()))
10668 : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
10669
10670 var funcsLength = transforms.length;
10671 return baseRest(function(args) {
10672 var index = -1,
10673 length = nativeMin(args.length, funcsLength);
10674
10675 while (++index < length) {
10676 args[index] = transforms[index].call(this, args[index]);
10677 }
10678 return apply(func, this, args);
10679 });
10680 });
10681
10682 /**
10683 * Creates a function that invokes `func` with `partials` prepended to the
10684 * arguments it receives. This method is like `_.bind` except it does **not**
10685 * alter the `this` binding.
10686 *
10687 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
10688 * builds, may be used as a placeholder for partially applied arguments.
10689 *
10690 * **Note:** This method doesn't set the "length" property of partially
10691 * applied functions.
10692 *
10693 * @static
10694 * @memberOf _
10695 * @since 0.2.0
10696 * @category Function
10697 * @param {Function} func The function to partially apply arguments to.
10698 * @param {...*} [partials] The arguments to be partially applied.
10699 * @returns {Function} Returns the new partially applied function.
10700 * @example
10701 *
10702 * function greet(greeting, name) {
10703 * return greeting + ' ' + name;
10704 * }
10705 *
10706 * var sayHelloTo = _.partial(greet, 'hello');
10707 * sayHelloTo('fred');
10708 * // => 'hello fred'
10709 *
10710 * // Partially applied with placeholders.
10711 * var greetFred = _.partial(greet, _, 'fred');
10712 * greetFred('hi');
10713 * // => 'hi fred'
10714 */
10715 var partial = baseRest(function(func, partials) {
10716 var holders = replaceHolders(partials, getHolder(partial));
10717 return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
10718 });
10719
10720 /**
10721 * This method is like `_.partial` except that partially applied arguments
10722 * are appended to the arguments it receives.
10723 *
10724 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
10725 * builds, may be used as a placeholder for partially applied arguments.
10726 *
10727 * **Note:** This method doesn't set the "length" property of partially
10728 * applied functions.
10729 *
10730 * @static
10731 * @memberOf _
10732 * @since 1.0.0
10733 * @category Function
10734 * @param {Function} func The function to partially apply arguments to.
10735 * @param {...*} [partials] The arguments to be partially applied.
10736 * @returns {Function} Returns the new partially applied function.
10737 * @example
10738 *
10739 * function greet(greeting, name) {
10740 * return greeting + ' ' + name;
10741 * }
10742 *
10743 * var greetFred = _.partialRight(greet, 'fred');
10744 * greetFred('hi');
10745 * // => 'hi fred'
10746 *
10747 * // Partially applied with placeholders.
10748 * var sayHelloTo = _.partialRight(greet, 'hello', _);
10749 * sayHelloTo('fred');
10750 * // => 'hello fred'
10751 */
10752 var partialRight = baseRest(function(func, partials) {
10753 var holders = replaceHolders(partials, getHolder(partialRight));
10754 return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
10755 });
10756
10757 /**
10758 * Creates a function that invokes `func` with arguments arranged according
10759 * to the specified `indexes` where the argument value at the first index is
10760 * provided as the first argument, the argument value at the second index is
10761 * provided as the second argument, and so on.
10762 *
10763 * @static
10764 * @memberOf _
10765 * @since 3.0.0
10766 * @category Function
10767 * @param {Function} func The function to rearrange arguments for.
10768 * @param {...(number|number[])} indexes The arranged argument indexes.
10769 * @returns {Function} Returns the new function.
10770 * @example
10771 *
10772 * var rearged = _.rearg(function(a, b, c) {
10773 * return [a, b, c];
10774 * }, [2, 0, 1]);
10775 *
10776 * rearged('b', 'c', 'a')
10777 * // => ['a', 'b', 'c']
10778 */
10779 var rearg = flatRest(function(func, indexes) {
10780 return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
10781 });
10782
10783 /**
10784 * Creates a function that invokes `func` with the `this` binding of the
10785 * created function and arguments from `start` and beyond provided as
10786 * an array.
10787 *
10788 * **Note:** This method is based on the
10789 * [rest parameter](https://mdn.io/rest_parameters).
10790 *
10791 * @static
10792 * @memberOf _
10793 * @since 4.0.0
10794 * @category Function
10795 * @param {Function} func The function to apply a rest parameter to.
10796 * @param {number} [start=func.length-1] The start position of the rest parameter.
10797 * @returns {Function} Returns the new function.
10798 * @example
10799 *
10800 * var say = _.rest(function(what, names) {
10801 * return what + ' ' + _.initial(names).join(', ') +
10802 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
10803 * });
10804 *
10805 * say('hello', 'fred', 'barney', 'pebbles');
10806 * // => 'hello fred, barney, & pebbles'
10807 */
10808 function rest(func, start) {
10809 if (typeof func != 'function') {
10810 throw new TypeError(FUNC_ERROR_TEXT);
10811 }
10812 start = start === undefined ? start : toInteger(start);
10813 return baseRest(func, start);
10814 }
10815
10816 /**
10817 * Creates a function that invokes `func` with the `this` binding of the
10818 * create function and an array of arguments much like
10819 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
10820 *
10821 * **Note:** This method is based on the
10822 * [spread operator](https://mdn.io/spread_operator).
10823 *
10824 * @static
10825 * @memberOf _
10826 * @since 3.2.0
10827 * @category Function
10828 * @param {Function} func The function to spread arguments over.
10829 * @param {number} [start=0] The start position of the spread.
10830 * @returns {Function} Returns the new function.
10831 * @example
10832 *
10833 * var say = _.spread(function(who, what) {
10834 * return who + ' says ' + what;
10835 * });
10836 *
10837 * say(['fred', 'hello']);
10838 * // => 'fred says hello'
10839 *
10840 * var numbers = Promise.all([
10841 * Promise.resolve(40),
10842 * Promise.resolve(36)
10843 * ]);
10844 *
10845 * numbers.then(_.spread(function(x, y) {
10846 * return x + y;
10847 * }));
10848 * // => a Promise of 76
10849 */
10850 function spread(func, start) {
10851 if (typeof func != 'function') {
10852 throw new TypeError(FUNC_ERROR_TEXT);
10853 }
10854 start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
10855 return baseRest(function(args) {
10856 var array = args[start],
10857 lastIndex = args.length - 1,
10858 otherArgs = castSlice(args, 0, start);
10859
10860 if (array) {
10861 arrayPush(otherArgs, array);
10862 }
10863 if (start != lastIndex) {
10864 arrayPush(otherArgs, castSlice(args, start + 1));
10865 }
10866 return apply(func, this, otherArgs);
10867 });
10868 }
10869
10870 /**
10871 * Creates a throttled function that only invokes `func` at most once per
10872 * every `wait` milliseconds. The throttled function comes with a `cancel`
10873 * method to cancel delayed `func` invocations and a `flush` method to
10874 * immediately invoke them. Provide `options` to indicate whether `func`
10875 * should be invoked on the leading and/or trailing edge of the `wait`
10876 * timeout. The `func` is invoked with the last arguments provided to the
10877 * throttled function. Subsequent calls to the throttled function return the
10878 * result of the last `func` invocation.
10879 *
10880 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10881 * invoked on the trailing edge of the timeout only if the throttled function
10882 * is invoked more than once during the `wait` timeout.
10883 *
10884 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10885 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10886 *
10887 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10888 * for details over the differences between `_.throttle` and `_.debounce`.
10889 *
10890 * @static
10891 * @memberOf _
10892 * @since 0.1.0
10893 * @category Function
10894 * @param {Function} func The function to throttle.
10895 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
10896 * @param {Object} [options={}] The options object.
10897 * @param {boolean} [options.leading=true]
10898 * Specify invoking on the leading edge of the timeout.
10899 * @param {boolean} [options.trailing=true]
10900 * Specify invoking on the trailing edge of the timeout.
10901 * @returns {Function} Returns the new throttled function.
10902 * @example
10903 *
10904 * // Avoid excessively updating the position while scrolling.
10905 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
10906 *
10907 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
10908 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
10909 * jQuery(element).on('click', throttled);
10910 *
10911 * // Cancel the trailing throttled invocation.
10912 * jQuery(window).on('popstate', throttled.cancel);
10913 */
10914 function throttle(func, wait, options) {
10915 var leading = true,
10916 trailing = true;
10917
10918 if (typeof func != 'function') {
10919 throw new TypeError(FUNC_ERROR_TEXT);
10920 }
10921 if (isObject(options)) {
10922 leading = 'leading' in options ? !!options.leading : leading;
10923 trailing = 'trailing' in options ? !!options.trailing : trailing;
10924 }
10925 return debounce(func, wait, {
10926 'leading': leading,
10927 'maxWait': wait,
10928 'trailing': trailing
10929 });
10930 }
10931
10932 /**
10933 * Creates a function that accepts up to one argument, ignoring any
10934 * additional arguments.
10935 *
10936 * @static
10937 * @memberOf _
10938 * @since 4.0.0
10939 * @category Function
10940 * @param {Function} func The function to cap arguments for.
10941 * @returns {Function} Returns the new capped function.
10942 * @example
10943 *
10944 * _.map(['6', '8', '10'], _.unary(parseInt));
10945 * // => [6, 8, 10]
10946 */
10947 function unary(func) {
10948 return ary(func, 1);
10949 }
10950
10951 /**
10952 * Creates a function that provides `value` to `wrapper` as its first
10953 * argument. Any additional arguments provided to the function are appended
10954 * to those provided to the `wrapper`. The wrapper is invoked with the `this`
10955 * binding of the created function.
10956 *
10957 * @static
10958 * @memberOf _
10959 * @since 0.1.0
10960 * @category Function
10961 * @param {*} value The value to wrap.
10962 * @param {Function} [wrapper=identity] The wrapper function.
10963 * @returns {Function} Returns the new function.
10964 * @example
10965 *
10966 * var p = _.wrap(_.escape, function(func, text) {
10967 * return '<p>' + func(text) + '</p>';
10968 * });
10969 *
10970 * p('fred, barney, & pebbles');
10971 * // => '<p>fred, barney, &amp; pebbles</p>'
10972 */
10973 function wrap(value, wrapper) {
10974 return partial(castFunction(wrapper), value);
10975 }
10976
10977 /*------------------------------------------------------------------------*/
10978
10979 /**
10980 * Casts `value` as an array if it's not one.
10981 *
10982 * @static
10983 * @memberOf _
10984 * @since 4.4.0
10985 * @category Lang
10986 * @param {*} value The value to inspect.
10987 * @returns {Array} Returns the cast array.
10988 * @example
10989 *
10990 * _.castArray(1);
10991 * // => [1]
10992 *
10993 * _.castArray({ 'a': 1 });
10994 * // => [{ 'a': 1 }]
10995 *
10996 * _.castArray('abc');
10997 * // => ['abc']
10998 *
10999 * _.castArray(null);
11000 * // => [null]
11001 *
11002 * _.castArray(undefined);
11003 * // => [undefined]
11004 *
11005 * _.castArray();
11006 * // => []
11007 *
11008 * var array = [1, 2, 3];
11009 * console.log(_.castArray(array) === array);
11010 * // => true
11011 */
11012 function castArray() {
11013 if (!arguments.length) {
11014 return [];
11015 }
11016 var value = arguments[0];
11017 return isArray(value) ? value : [value];
11018 }
11019
11020 /**
11021 * Creates a shallow clone of `value`.
11022 *
11023 * **Note:** This method is loosely based on the
11024 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
11025 * and supports cloning arrays, array buffers, booleans, date objects, maps,
11026 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
11027 * arrays. The own enumerable properties of `arguments` objects are cloned
11028 * as plain objects. An empty object is returned for uncloneable values such
11029 * as error objects, functions, DOM nodes, and WeakMaps.
11030 *
11031 * @static
11032 * @memberOf _
11033 * @since 0.1.0
11034 * @category Lang
11035 * @param {*} value The value to clone.
11036 * @returns {*} Returns the cloned value.
11037 * @see _.cloneDeep
11038 * @example
11039 *
11040 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11041 *
11042 * var shallow = _.clone(objects);
11043 * console.log(shallow[0] === objects[0]);
11044 * // => true
11045 */
11046 function clone(value) {
11047 return baseClone(value, CLONE_SYMBOLS_FLAG);
11048 }
11049
11050 /**
11051 * This method is like `_.clone` except that it accepts `customizer` which
11052 * is invoked to produce the cloned value. If `customizer` returns `undefined`,
11053 * cloning is handled by the method instead. The `customizer` is invoked with
11054 * up to four arguments; (value [, index|key, object, stack]).
11055 *
11056 * @static
11057 * @memberOf _
11058 * @since 4.0.0
11059 * @category Lang
11060 * @param {*} value The value to clone.
11061 * @param {Function} [customizer] The function to customize cloning.
11062 * @returns {*} Returns the cloned value.
11063 * @see _.cloneDeepWith
11064 * @example
11065 *
11066 * function customizer(value) {
11067 * if (_.isElement(value)) {
11068 * return value.cloneNode(false);
11069 * }
11070 * }
11071 *
11072 * var el = _.cloneWith(document.body, customizer);
11073 *
11074 * console.log(el === document.body);
11075 * // => false
11076 * console.log(el.nodeName);
11077 * // => 'BODY'
11078 * console.log(el.childNodes.length);
11079 * // => 0
11080 */
11081 function cloneWith(value, customizer) {
11082 customizer = typeof customizer == 'function' ? customizer : undefined;
11083 return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
11084 }
11085
11086 /**
11087 * This method is like `_.clone` except that it recursively clones `value`.
11088 *
11089 * @static
11090 * @memberOf _
11091 * @since 1.0.0
11092 * @category Lang
11093 * @param {*} value The value to recursively clone.
11094 * @returns {*} Returns the deep cloned value.
11095 * @see _.clone
11096 * @example
11097 *
11098 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11099 *
11100 * var deep = _.cloneDeep(objects);
11101 * console.log(deep[0] === objects[0]);
11102 * // => false
11103 */
11104 function cloneDeep(value) {
11105 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
11106 }
11107
11108 /**
11109 * This method is like `_.cloneWith` except that it recursively clones `value`.
11110 *
11111 * @static
11112 * @memberOf _
11113 * @since 4.0.0
11114 * @category Lang
11115 * @param {*} value The value to recursively clone.
11116 * @param {Function} [customizer] The function to customize cloning.
11117 * @returns {*} Returns the deep cloned value.
11118 * @see _.cloneWith
11119 * @example
11120 *
11121 * function customizer(value) {
11122 * if (_.isElement(value)) {
11123 * return value.cloneNode(true);
11124 * }
11125 * }
11126 *
11127 * var el = _.cloneDeepWith(document.body, customizer);
11128 *
11129 * console.log(el === document.body);
11130 * // => false
11131 * console.log(el.nodeName);
11132 * // => 'BODY'
11133 * console.log(el.childNodes.length);
11134 * // => 20
11135 */
11136 function cloneDeepWith(value, customizer) {
11137 customizer = typeof customizer == 'function' ? customizer : undefined;
11138 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
11139 }
11140
11141 /**
11142 * Checks if `object` conforms to `source` by invoking the predicate
11143 * properties of `source` with the corresponding property values of `object`.
11144 *
11145 * **Note:** This method is equivalent to `_.conforms` when `source` is
11146 * partially applied.
11147 *
11148 * @static
11149 * @memberOf _
11150 * @since 4.14.0
11151 * @category Lang
11152 * @param {Object} object The object to inspect.
11153 * @param {Object} source The object of property predicates to conform to.
11154 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
11155 * @example
11156 *
11157 * var object = { 'a': 1, 'b': 2 };
11158 *
11159 * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
11160 * // => true
11161 *
11162 * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
11163 * // => false
11164 */
11165 function conformsTo(object, source) {
11166 return source == null || baseConformsTo(object, source, keys(source));
11167 }
11168
11169 /**
11170 * Performs a
11171 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
11172 * comparison between two values to determine if they are equivalent.
11173 *
11174 * @static
11175 * @memberOf _
11176 * @since 4.0.0
11177 * @category Lang
11178 * @param {*} value The value to compare.
11179 * @param {*} other The other value to compare.
11180 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11181 * @example
11182 *
11183 * var object = { 'a': 1 };
11184 * var other = { 'a': 1 };
11185 *
11186 * _.eq(object, object);
11187 * // => true
11188 *
11189 * _.eq(object, other);
11190 * // => false
11191 *
11192 * _.eq('a', 'a');
11193 * // => true
11194 *
11195 * _.eq('a', Object('a'));
11196 * // => false
11197 *
11198 * _.eq(NaN, NaN);
11199 * // => true
11200 */
11201 function eq(value, other) {
11202 return value === other || (value !== value && other !== other);
11203 }
11204
11205 /**
11206 * Checks if `value` is greater than `other`.
11207 *
11208 * @static
11209 * @memberOf _
11210 * @since 3.9.0
11211 * @category Lang
11212 * @param {*} value The value to compare.
11213 * @param {*} other The other value to compare.
11214 * @returns {boolean} Returns `true` if `value` is greater than `other`,
11215 * else `false`.
11216 * @see _.lt
11217 * @example
11218 *
11219 * _.gt(3, 1);
11220 * // => true
11221 *
11222 * _.gt(3, 3);
11223 * // => false
11224 *
11225 * _.gt(1, 3);
11226 * // => false
11227 */
11228 var gt = createRelationalOperation(baseGt);
11229
11230 /**
11231 * Checks if `value` is greater than or equal to `other`.
11232 *
11233 * @static
11234 * @memberOf _
11235 * @since 3.9.0
11236 * @category Lang
11237 * @param {*} value The value to compare.
11238 * @param {*} other The other value to compare.
11239 * @returns {boolean} Returns `true` if `value` is greater than or equal to
11240 * `other`, else `false`.
11241 * @see _.lte
11242 * @example
11243 *
11244 * _.gte(3, 1);
11245 * // => true
11246 *
11247 * _.gte(3, 3);
11248 * // => true
11249 *
11250 * _.gte(1, 3);
11251 * // => false
11252 */
11253 var gte = createRelationalOperation(function(value, other) {
11254 return value >= other;
11255 });
11256
11257 /**
11258 * Checks if `value` is likely an `arguments` object.
11259 *
11260 * @static
11261 * @memberOf _
11262 * @since 0.1.0
11263 * @category Lang
11264 * @param {*} value The value to check.
11265 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
11266 * else `false`.
11267 * @example
11268 *
11269 * _.isArguments(function() { return arguments; }());
11270 * // => true
11271 *
11272 * _.isArguments([1, 2, 3]);
11273 * // => false
11274 */
11275 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
11276 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
11277 !propertyIsEnumerable.call(value, 'callee');
11278 };
11279
11280 /**
11281 * Checks if `value` is classified as an `Array` object.
11282 *
11283 * @static
11284 * @memberOf _
11285 * @since 0.1.0
11286 * @category Lang
11287 * @param {*} value The value to check.
11288 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
11289 * @example
11290 *
11291 * _.isArray([1, 2, 3]);
11292 * // => true
11293 *
11294 * _.isArray(document.body.children);
11295 * // => false
11296 *
11297 * _.isArray('abc');
11298 * // => false
11299 *
11300 * _.isArray(_.noop);
11301 * // => false
11302 */
11303 var isArray = Array.isArray;
11304
11305 /**
11306 * Checks if `value` is classified as an `ArrayBuffer` object.
11307 *
11308 * @static
11309 * @memberOf _
11310 * @since 4.3.0
11311 * @category Lang
11312 * @param {*} value The value to check.
11313 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
11314 * @example
11315 *
11316 * _.isArrayBuffer(new ArrayBuffer(2));
11317 * // => true
11318 *
11319 * _.isArrayBuffer(new Array(2));
11320 * // => false
11321 */
11322 var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
11323
11324 /**
11325 * Checks if `value` is array-like. A value is considered array-like if it's
11326 * not a function and has a `value.length` that's an integer greater than or
11327 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
11328 *
11329 * @static
11330 * @memberOf _
11331 * @since 4.0.0
11332 * @category Lang
11333 * @param {*} value The value to check.
11334 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11335 * @example
11336 *
11337 * _.isArrayLike([1, 2, 3]);
11338 * // => true
11339 *
11340 * _.isArrayLike(document.body.children);
11341 * // => true
11342 *
11343 * _.isArrayLike('abc');
11344 * // => true
11345 *
11346 * _.isArrayLike(_.noop);
11347 * // => false
11348 */
11349 function isArrayLike(value) {
11350 return value != null && isLength(value.length) && !isFunction(value);
11351 }
11352
11353 /**
11354 * This method is like `_.isArrayLike` except that it also checks if `value`
11355 * is an object.
11356 *
11357 * @static
11358 * @memberOf _
11359 * @since 4.0.0
11360 * @category Lang
11361 * @param {*} value The value to check.
11362 * @returns {boolean} Returns `true` if `value` is an array-like object,
11363 * else `false`.
11364 * @example
11365 *
11366 * _.isArrayLikeObject([1, 2, 3]);
11367 * // => true
11368 *
11369 * _.isArrayLikeObject(document.body.children);
11370 * // => true
11371 *
11372 * _.isArrayLikeObject('abc');
11373 * // => false
11374 *
11375 * _.isArrayLikeObject(_.noop);
11376 * // => false
11377 */
11378 function isArrayLikeObject(value) {
11379 return isObjectLike(value) && isArrayLike(value);
11380 }
11381
11382 /**
11383 * Checks if `value` is classified as a boolean primitive or object.
11384 *
11385 * @static
11386 * @memberOf _
11387 * @since 0.1.0
11388 * @category Lang
11389 * @param {*} value The value to check.
11390 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
11391 * @example
11392 *
11393 * _.isBoolean(false);
11394 * // => true
11395 *
11396 * _.isBoolean(null);
11397 * // => false
11398 */
11399 function isBoolean(value) {
11400 return value === true || value === false ||
11401 (isObjectLike(value) && baseGetTag(value) == boolTag);
11402 }
11403
11404 /**
11405 * Checks if `value` is a buffer.
11406 *
11407 * @static
11408 * @memberOf _
11409 * @since 4.3.0
11410 * @category Lang
11411 * @param {*} value The value to check.
11412 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
11413 * @example
11414 *
11415 * _.isBuffer(new Buffer(2));
11416 * // => true
11417 *
11418 * _.isBuffer(new Uint8Array(2));
11419 * // => false
11420 */
11421 var isBuffer = nativeIsBuffer || stubFalse;
11422
11423 /**
11424 * Checks if `value` is classified as a `Date` object.
11425 *
11426 * @static
11427 * @memberOf _
11428 * @since 0.1.0
11429 * @category Lang
11430 * @param {*} value The value to check.
11431 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
11432 * @example
11433 *
11434 * _.isDate(new Date);
11435 * // => true
11436 *
11437 * _.isDate('Mon April 23 2012');
11438 * // => false
11439 */
11440 var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
11441
11442 /**
11443 * Checks if `value` is likely a DOM element.
11444 *
11445 * @static
11446 * @memberOf _
11447 * @since 0.1.0
11448 * @category Lang
11449 * @param {*} value The value to check.
11450 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
11451 * @example
11452 *
11453 * _.isElement(document.body);
11454 * // => true
11455 *
11456 * _.isElement('<body>');
11457 * // => false
11458 */
11459 function isElement(value) {
11460 return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
11461 }
11462
11463 /**
11464 * Checks if `value` is an empty object, collection, map, or set.
11465 *
11466 * Objects are considered empty if they have no own enumerable string keyed
11467 * properties.
11468 *
11469 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
11470 * jQuery-like collections are considered empty if they have a `length` of `0`.
11471 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
11472 *
11473 * @static
11474 * @memberOf _
11475 * @since 0.1.0
11476 * @category Lang
11477 * @param {*} value The value to check.
11478 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
11479 * @example
11480 *
11481 * _.isEmpty(null);
11482 * // => true
11483 *
11484 * _.isEmpty(true);
11485 * // => true
11486 *
11487 * _.isEmpty(1);
11488 * // => true
11489 *
11490 * _.isEmpty([1, 2, 3]);
11491 * // => false
11492 *
11493 * _.isEmpty({ 'a': 1 });
11494 * // => false
11495 */
11496 function isEmpty(value) {
11497 if (value == null) {
11498 return true;
11499 }
11500 if (isArrayLike(value) &&
11501 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
11502 isBuffer(value) || isTypedArray(value) || isArguments(value))) {
11503 return !value.length;
11504 }
11505 var tag = getTag(value);
11506 if (tag == mapTag || tag == setTag) {
11507 return !value.size;
11508 }
11509 if (isPrototype(value)) {
11510 return !baseKeys(value).length;
11511 }
11512 for (var key in value) {
11513 if (hasOwnProperty.call(value, key)) {
11514 return false;
11515 }
11516 }
11517 return true;
11518 }
11519
11520 /**
11521 * Performs a deep comparison between two values to determine if they are
11522 * equivalent.
11523 *
11524 * **Note:** This method supports comparing arrays, array buffers, booleans,
11525 * date objects, error objects, maps, numbers, `Object` objects, regexes,
11526 * sets, strings, symbols, and typed arrays. `Object` objects are compared
11527 * by their own, not inherited, enumerable properties. Functions and DOM
11528 * nodes are **not** supported.
11529 *
11530 * @static
11531 * @memberOf _
11532 * @since 0.1.0
11533 * @category Lang
11534 * @param {*} value The value to compare.
11535 * @param {*} other The other value to compare.
11536 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11537 * @example
11538 *
11539 * var object = { 'a': 1 };
11540 * var other = { 'a': 1 };
11541 *
11542 * _.isEqual(object, other);
11543 * // => true
11544 *
11545 * object === other;
11546 * // => false
11547 */
11548 function isEqual(value, other) {
11549 return baseIsEqual(value, other);
11550 }
11551
11552 /**
11553 * This method is like `_.isEqual` except that it accepts `customizer` which
11554 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11555 * are handled by the method instead. The `customizer` is invoked with up to
11556 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
11557 *
11558 * @static
11559 * @memberOf _
11560 * @since 4.0.0
11561 * @category Lang
11562 * @param {*} value The value to compare.
11563 * @param {*} other The other value to compare.
11564 * @param {Function} [customizer] The function to customize comparisons.
11565 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11566 * @example
11567 *
11568 * function isGreeting(value) {
11569 * return /^h(?:i|ello)$/.test(value);
11570 * }
11571 *
11572 * function customizer(objValue, othValue) {
11573 * if (isGreeting(objValue) && isGreeting(othValue)) {
11574 * return true;
11575 * }
11576 * }
11577 *
11578 * var array = ['hello', 'goodbye'];
11579 * var other = ['hi', 'goodbye'];
11580 *
11581 * _.isEqualWith(array, other, customizer);
11582 * // => true
11583 */
11584 function isEqualWith(value, other, customizer) {
11585 customizer = typeof customizer == 'function' ? customizer : undefined;
11586 var result = customizer ? customizer(value, other) : undefined;
11587 return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
11588 }
11589
11590 /**
11591 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
11592 * `SyntaxError`, `TypeError`, or `URIError` object.
11593 *
11594 * @static
11595 * @memberOf _
11596 * @since 3.0.0
11597 * @category Lang
11598 * @param {*} value The value to check.
11599 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
11600 * @example
11601 *
11602 * _.isError(new Error);
11603 * // => true
11604 *
11605 * _.isError(Error);
11606 * // => false
11607 */
11608 function isError(value) {
11609 if (!isObjectLike(value)) {
11610 return false;
11611 }
11612 var tag = baseGetTag(value);
11613 return tag == errorTag || tag == domExcTag ||
11614 (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
11615 }
11616
11617 /**
11618 * Checks if `value` is a finite primitive number.
11619 *
11620 * **Note:** This method is based on
11621 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
11622 *
11623 * @static
11624 * @memberOf _
11625 * @since 0.1.0
11626 * @category Lang
11627 * @param {*} value The value to check.
11628 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
11629 * @example
11630 *
11631 * _.isFinite(3);
11632 * // => true
11633 *
11634 * _.isFinite(Number.MIN_VALUE);
11635 * // => true
11636 *
11637 * _.isFinite(Infinity);
11638 * // => false
11639 *
11640 * _.isFinite('3');
11641 * // => false
11642 */
11643 function isFinite(value) {
11644 return typeof value == 'number' && nativeIsFinite(value);
11645 }
11646
11647 /**
11648 * Checks if `value` is classified as a `Function` object.
11649 *
11650 * @static
11651 * @memberOf _
11652 * @since 0.1.0
11653 * @category Lang
11654 * @param {*} value The value to check.
11655 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
11656 * @example
11657 *
11658 * _.isFunction(_);
11659 * // => true
11660 *
11661 * _.isFunction(/abc/);
11662 * // => false
11663 */
11664 function isFunction(value) {
11665 if (!isObject(value)) {
11666 return false;
11667 }
11668 // The use of `Object#toString` avoids issues with the `typeof` operator
11669 // in Safari 9 which returns 'object' for typed arrays and other constructors.
11670 var tag = baseGetTag(value);
11671 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
11672 }
11673
11674 /**
11675 * Checks if `value` is an integer.
11676 *
11677 * **Note:** This method is based on
11678 * [`Number.isInteger`](https://mdn.io/Number/isInteger).
11679 *
11680 * @static
11681 * @memberOf _
11682 * @since 4.0.0
11683 * @category Lang
11684 * @param {*} value The value to check.
11685 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
11686 * @example
11687 *
11688 * _.isInteger(3);
11689 * // => true
11690 *
11691 * _.isInteger(Number.MIN_VALUE);
11692 * // => false
11693 *
11694 * _.isInteger(Infinity);
11695 * // => false
11696 *
11697 * _.isInteger('3');
11698 * // => false
11699 */
11700 function isInteger(value) {
11701 return typeof value == 'number' && value == toInteger(value);
11702 }
11703
11704 /**
11705 * Checks if `value` is a valid array-like length.
11706 *
11707 * **Note:** This method is loosely based on
11708 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
11709 *
11710 * @static
11711 * @memberOf _
11712 * @since 4.0.0
11713 * @category Lang
11714 * @param {*} value The value to check.
11715 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11716 * @example
11717 *
11718 * _.isLength(3);
11719 * // => true
11720 *
11721 * _.isLength(Number.MIN_VALUE);
11722 * // => false
11723 *
11724 * _.isLength(Infinity);
11725 * // => false
11726 *
11727 * _.isLength('3');
11728 * // => false
11729 */
11730 function isLength(value) {
11731 return typeof value == 'number' &&
11732 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11733 }
11734
11735 /**
11736 * Checks if `value` is the
11737 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
11738 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11739 *
11740 * @static
11741 * @memberOf _
11742 * @since 0.1.0
11743 * @category Lang
11744 * @param {*} value The value to check.
11745 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11746 * @example
11747 *
11748 * _.isObject({});
11749 * // => true
11750 *
11751 * _.isObject([1, 2, 3]);
11752 * // => true
11753 *
11754 * _.isObject(_.noop);
11755 * // => true
11756 *
11757 * _.isObject(null);
11758 * // => false
11759 */
11760 function isObject(value) {
11761 var type = typeof value;
11762 return value != null && (type == 'object' || type == 'function');
11763 }
11764
11765 /**
11766 * Checks if `value` is object-like. A value is object-like if it's not `null`
11767 * and has a `typeof` result of "object".
11768 *
11769 * @static
11770 * @memberOf _
11771 * @since 4.0.0
11772 * @category Lang
11773 * @param {*} value The value to check.
11774 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11775 * @example
11776 *
11777 * _.isObjectLike({});
11778 * // => true
11779 *
11780 * _.isObjectLike([1, 2, 3]);
11781 * // => true
11782 *
11783 * _.isObjectLike(_.noop);
11784 * // => false
11785 *
11786 * _.isObjectLike(null);
11787 * // => false
11788 */
11789 function isObjectLike(value) {
11790 return value != null && typeof value == 'object';
11791 }
11792
11793 /**
11794 * Checks if `value` is classified as a `Map` object.
11795 *
11796 * @static
11797 * @memberOf _
11798 * @since 4.3.0
11799 * @category Lang
11800 * @param {*} value The value to check.
11801 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
11802 * @example
11803 *
11804 * _.isMap(new Map);
11805 * // => true
11806 *
11807 * _.isMap(new WeakMap);
11808 * // => false
11809 */
11810 var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
11811
11812 /**
11813 * Performs a partial deep comparison between `object` and `source` to
11814 * determine if `object` contains equivalent property values.
11815 *
11816 * **Note:** This method is equivalent to `_.matches` when `source` is
11817 * partially applied.
11818 *
11819 * Partial comparisons will match empty array and empty object `source`
11820 * values against any array or object value, respectively. See `_.isEqual`
11821 * for a list of supported value comparisons.
11822 *
11823 * @static
11824 * @memberOf _
11825 * @since 3.0.0
11826 * @category Lang
11827 * @param {Object} object The object to inspect.
11828 * @param {Object} source The object of property values to match.
11829 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11830 * @example
11831 *
11832 * var object = { 'a': 1, 'b': 2 };
11833 *
11834 * _.isMatch(object, { 'b': 2 });
11835 * // => true
11836 *
11837 * _.isMatch(object, { 'b': 1 });
11838 * // => false
11839 */
11840 function isMatch(object, source) {
11841 return object === source || baseIsMatch(object, source, getMatchData(source));
11842 }
11843
11844 /**
11845 * This method is like `_.isMatch` except that it accepts `customizer` which
11846 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11847 * are handled by the method instead. The `customizer` is invoked with five
11848 * arguments: (objValue, srcValue, index|key, object, source).
11849 *
11850 * @static
11851 * @memberOf _
11852 * @since 4.0.0
11853 * @category Lang
11854 * @param {Object} object The object to inspect.
11855 * @param {Object} source The object of property values to match.
11856 * @param {Function} [customizer] The function to customize comparisons.
11857 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11858 * @example
11859 *
11860 * function isGreeting(value) {
11861 * return /^h(?:i|ello)$/.test(value);
11862 * }
11863 *
11864 * function customizer(objValue, srcValue) {
11865 * if (isGreeting(objValue) && isGreeting(srcValue)) {
11866 * return true;
11867 * }
11868 * }
11869 *
11870 * var object = { 'greeting': 'hello' };
11871 * var source = { 'greeting': 'hi' };
11872 *
11873 * _.isMatchWith(object, source, customizer);
11874 * // => true
11875 */
11876 function isMatchWith(object, source, customizer) {
11877 customizer = typeof customizer == 'function' ? customizer : undefined;
11878 return baseIsMatch(object, source, getMatchData(source), customizer);
11879 }
11880
11881 /**
11882 * Checks if `value` is `NaN`.
11883 *
11884 * **Note:** This method is based on
11885 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
11886 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
11887 * `undefined` and other non-number values.
11888 *
11889 * @static
11890 * @memberOf _
11891 * @since 0.1.0
11892 * @category Lang
11893 * @param {*} value The value to check.
11894 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
11895 * @example
11896 *
11897 * _.isNaN(NaN);
11898 * // => true
11899 *
11900 * _.isNaN(new Number(NaN));
11901 * // => true
11902 *
11903 * isNaN(undefined);
11904 * // => true
11905 *
11906 * _.isNaN(undefined);
11907 * // => false
11908 */
11909 function isNaN(value) {
11910 // An `NaN` primitive is the only value that is not equal to itself.
11911 // Perform the `toStringTag` check first to avoid errors with some
11912 // ActiveX objects in IE.
11913 return isNumber(value) && value != +value;
11914 }
11915
11916 /**
11917 * Checks if `value` is a pristine native function.
11918 *
11919 * **Note:** This method can't reliably detect native functions in the presence
11920 * of the core-js package because core-js circumvents this kind of detection.
11921 * Despite multiple requests, the core-js maintainer has made it clear: any
11922 * attempt to fix the detection will be obstructed. As a result, we're left
11923 * with little choice but to throw an error. Unfortunately, this also affects
11924 * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
11925 * which rely on core-js.
11926 *
11927 * @static
11928 * @memberOf _
11929 * @since 3.0.0
11930 * @category Lang
11931 * @param {*} value The value to check.
11932 * @returns {boolean} Returns `true` if `value` is a native function,
11933 * else `false`.
11934 * @example
11935 *
11936 * _.isNative(Array.prototype.push);
11937 * // => true
11938 *
11939 * _.isNative(_);
11940 * // => false
11941 */
11942 function isNative(value) {
11943 if (isMaskable(value)) {
11944 throw new Error(CORE_ERROR_TEXT);
11945 }
11946 return baseIsNative(value);
11947 }
11948
11949 /**
11950 * Checks if `value` is `null`.
11951 *
11952 * @static
11953 * @memberOf _
11954 * @since 0.1.0
11955 * @category Lang
11956 * @param {*} value The value to check.
11957 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
11958 * @example
11959 *
11960 * _.isNull(null);
11961 * // => true
11962 *
11963 * _.isNull(void 0);
11964 * // => false
11965 */
11966 function isNull(value) {
11967 return value === null;
11968 }
11969
11970 /**
11971 * Checks if `value` is `null` or `undefined`.
11972 *
11973 * @static
11974 * @memberOf _
11975 * @since 4.0.0
11976 * @category Lang
11977 * @param {*} value The value to check.
11978 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
11979 * @example
11980 *
11981 * _.isNil(null);
11982 * // => true
11983 *
11984 * _.isNil(void 0);
11985 * // => true
11986 *
11987 * _.isNil(NaN);
11988 * // => false
11989 */
11990 function isNil(value) {
11991 return value == null;
11992 }
11993
11994 /**
11995 * Checks if `value` is classified as a `Number` primitive or object.
11996 *
11997 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
11998 * classified as numbers, use the `_.isFinite` method.
11999 *
12000 * @static
12001 * @memberOf _
12002 * @since 0.1.0
12003 * @category Lang
12004 * @param {*} value The value to check.
12005 * @returns {boolean} Returns `true` if `value` is a number, else `false`.
12006 * @example
12007 *
12008 * _.isNumber(3);
12009 * // => true
12010 *
12011 * _.isNumber(Number.MIN_VALUE);
12012 * // => true
12013 *
12014 * _.isNumber(Infinity);
12015 * // => true
12016 *
12017 * _.isNumber('3');
12018 * // => false
12019 */
12020 function isNumber(value) {
12021 return typeof value == 'number' ||
12022 (isObjectLike(value) && baseGetTag(value) == numberTag);
12023 }
12024
12025 /**
12026 * Checks if `value` is a plain object, that is, an object created by the
12027 * `Object` constructor or one with a `[[Prototype]]` of `null`.
12028 *
12029 * @static
12030 * @memberOf _
12031 * @since 0.8.0
12032 * @category Lang
12033 * @param {*} value The value to check.
12034 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12035 * @example
12036 *
12037 * function Foo() {
12038 * this.a = 1;
12039 * }
12040 *
12041 * _.isPlainObject(new Foo);
12042 * // => false
12043 *
12044 * _.isPlainObject([1, 2, 3]);
12045 * // => false
12046 *
12047 * _.isPlainObject({ 'x': 0, 'y': 0 });
12048 * // => true
12049 *
12050 * _.isPlainObject(Object.create(null));
12051 * // => true
12052 */
12053 function isPlainObject(value) {
12054 if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
12055 return false;
12056 }
12057 var proto = getPrototype(value);
12058 if (proto === null) {
12059 return true;
12060 }
12061 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
12062 return typeof Ctor == 'function' && Ctor instanceof Ctor &&
12063 funcToString.call(Ctor) == objectCtorString;
12064 }
12065
12066 /**
12067 * Checks if `value` is classified as a `RegExp` object.
12068 *
12069 * @static
12070 * @memberOf _
12071 * @since 0.1.0
12072 * @category Lang
12073 * @param {*} value The value to check.
12074 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
12075 * @example
12076 *
12077 * _.isRegExp(/abc/);
12078 * // => true
12079 *
12080 * _.isRegExp('/abc/');
12081 * // => false
12082 */
12083 var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
12084
12085 /**
12086 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
12087 * double precision number which isn't the result of a rounded unsafe integer.
12088 *
12089 * **Note:** This method is based on
12090 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
12091 *
12092 * @static
12093 * @memberOf _
12094 * @since 4.0.0
12095 * @category Lang
12096 * @param {*} value The value to check.
12097 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
12098 * @example
12099 *
12100 * _.isSafeInteger(3);
12101 * // => true
12102 *
12103 * _.isSafeInteger(Number.MIN_VALUE);
12104 * // => false
12105 *
12106 * _.isSafeInteger(Infinity);
12107 * // => false
12108 *
12109 * _.isSafeInteger('3');
12110 * // => false
12111 */
12112 function isSafeInteger(value) {
12113 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
12114 }
12115
12116 /**
12117 * Checks if `value` is classified as a `Set` object.
12118 *
12119 * @static
12120 * @memberOf _
12121 * @since 4.3.0
12122 * @category Lang
12123 * @param {*} value The value to check.
12124 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
12125 * @example
12126 *
12127 * _.isSet(new Set);
12128 * // => true
12129 *
12130 * _.isSet(new WeakSet);
12131 * // => false
12132 */
12133 var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
12134
12135 /**
12136 * Checks if `value` is classified as a `String` primitive or object.
12137 *
12138 * @static
12139 * @since 0.1.0
12140 * @memberOf _
12141 * @category Lang
12142 * @param {*} value The value to check.
12143 * @returns {boolean} Returns `true` if `value` is a string, else `false`.
12144 * @example
12145 *
12146 * _.isString('abc');
12147 * // => true
12148 *
12149 * _.isString(1);
12150 * // => false
12151 */
12152 function isString(value) {
12153 return typeof value == 'string' ||
12154 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
12155 }
12156
12157 /**
12158 * Checks if `value` is classified as a `Symbol` primitive or object.
12159 *
12160 * @static
12161 * @memberOf _
12162 * @since 4.0.0
12163 * @category Lang
12164 * @param {*} value The value to check.
12165 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
12166 * @example
12167 *
12168 * _.isSymbol(Symbol.iterator);
12169 * // => true
12170 *
12171 * _.isSymbol('abc');
12172 * // => false
12173 */
12174 function isSymbol(value) {
12175 return typeof value == 'symbol' ||
12176 (isObjectLike(value) && baseGetTag(value) == symbolTag);
12177 }
12178
12179 /**
12180 * Checks if `value` is classified as a typed array.
12181 *
12182 * @static
12183 * @memberOf _
12184 * @since 3.0.0
12185 * @category Lang
12186 * @param {*} value The value to check.
12187 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
12188 * @example
12189 *
12190 * _.isTypedArray(new Uint8Array);
12191 * // => true
12192 *
12193 * _.isTypedArray([]);
12194 * // => false
12195 */
12196 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
12197
12198 /**
12199 * Checks if `value` is `undefined`.
12200 *
12201 * @static
12202 * @since 0.1.0
12203 * @memberOf _
12204 * @category Lang
12205 * @param {*} value The value to check.
12206 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
12207 * @example
12208 *
12209 * _.isUndefined(void 0);
12210 * // => true
12211 *
12212 * _.isUndefined(null);
12213 * // => false
12214 */
12215 function isUndefined(value) {
12216 return value === undefined;
12217 }
12218
12219 /**
12220 * Checks if `value` is classified as a `WeakMap` object.
12221 *
12222 * @static
12223 * @memberOf _
12224 * @since 4.3.0
12225 * @category Lang
12226 * @param {*} value The value to check.
12227 * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
12228 * @example
12229 *
12230 * _.isWeakMap(new WeakMap);
12231 * // => true
12232 *
12233 * _.isWeakMap(new Map);
12234 * // => false
12235 */
12236 function isWeakMap(value) {
12237 return isObjectLike(value) && getTag(value) == weakMapTag;
12238 }
12239
12240 /**
12241 * Checks if `value` is classified as a `WeakSet` object.
12242 *
12243 * @static
12244 * @memberOf _
12245 * @since 4.3.0
12246 * @category Lang
12247 * @param {*} value The value to check.
12248 * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
12249 * @example
12250 *
12251 * _.isWeakSet(new WeakSet);
12252 * // => true
12253 *
12254 * _.isWeakSet(new Set);
12255 * // => false
12256 */
12257 function isWeakSet(value) {
12258 return isObjectLike(value) && baseGetTag(value) == weakSetTag;
12259 }
12260
12261 /**
12262 * Checks if `value` is less than `other`.
12263 *
12264 * @static
12265 * @memberOf _
12266 * @since 3.9.0
12267 * @category Lang
12268 * @param {*} value The value to compare.
12269 * @param {*} other The other value to compare.
12270 * @returns {boolean} Returns `true` if `value` is less than `other`,
12271 * else `false`.
12272 * @see _.gt
12273 * @example
12274 *
12275 * _.lt(1, 3);
12276 * // => true
12277 *
12278 * _.lt(3, 3);
12279 * // => false
12280 *
12281 * _.lt(3, 1);
12282 * // => false
12283 */
12284 var lt = createRelationalOperation(baseLt);
12285
12286 /**
12287 * Checks if `value` is less than or equal to `other`.
12288 *
12289 * @static
12290 * @memberOf _
12291 * @since 3.9.0
12292 * @category Lang
12293 * @param {*} value The value to compare.
12294 * @param {*} other The other value to compare.
12295 * @returns {boolean} Returns `true` if `value` is less than or equal to
12296 * `other`, else `false`.
12297 * @see _.gte
12298 * @example
12299 *
12300 * _.lte(1, 3);
12301 * // => true
12302 *
12303 * _.lte(3, 3);
12304 * // => true
12305 *
12306 * _.lte(3, 1);
12307 * // => false
12308 */
12309 var lte = createRelationalOperation(function(value, other) {
12310 return value <= other;
12311 });
12312
12313 /**
12314 * Converts `value` to an array.
12315 *
12316 * @static
12317 * @since 0.1.0
12318 * @memberOf _
12319 * @category Lang
12320 * @param {*} value The value to convert.
12321 * @returns {Array} Returns the converted array.
12322 * @example
12323 *
12324 * _.toArray({ 'a': 1, 'b': 2 });
12325 * // => [1, 2]
12326 *
12327 * _.toArray('abc');
12328 * // => ['a', 'b', 'c']
12329 *
12330 * _.toArray(1);
12331 * // => []
12332 *
12333 * _.toArray(null);
12334 * // => []
12335 */
12336 function toArray(value) {
12337 if (!value) {
12338 return [];
12339 }
12340 if (isArrayLike(value)) {
12341 return isString(value) ? stringToArray(value) : copyArray(value);
12342 }
12343 if (symIterator && value[symIterator]) {
12344 return iteratorToArray(value[symIterator]());
12345 }
12346 var tag = getTag(value),
12347 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
12348
12349 return func(value);
12350 }
12351
12352 /**
12353 * Converts `value` to a finite number.
12354 *
12355 * @static
12356 * @memberOf _
12357 * @since 4.12.0
12358 * @category Lang
12359 * @param {*} value The value to convert.
12360 * @returns {number} Returns the converted number.
12361 * @example
12362 *
12363 * _.toFinite(3.2);
12364 * // => 3.2
12365 *
12366 * _.toFinite(Number.MIN_VALUE);
12367 * // => 5e-324
12368 *
12369 * _.toFinite(Infinity);
12370 * // => 1.7976931348623157e+308
12371 *
12372 * _.toFinite('3.2');
12373 * // => 3.2
12374 */
12375 function toFinite(value) {
12376 if (!value) {
12377 return value === 0 ? value : 0;
12378 }
12379 value = toNumber(value);
12380 if (value === INFINITY || value === -INFINITY) {
12381 var sign = (value < 0 ? -1 : 1);
12382 return sign * MAX_INTEGER;
12383 }
12384 return value === value ? value : 0;
12385 }
12386
12387 /**
12388 * Converts `value` to an integer.
12389 *
12390 * **Note:** This method is loosely based on
12391 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
12392 *
12393 * @static
12394 * @memberOf _
12395 * @since 4.0.0
12396 * @category Lang
12397 * @param {*} value The value to convert.
12398 * @returns {number} Returns the converted integer.
12399 * @example
12400 *
12401 * _.toInteger(3.2);
12402 * // => 3
12403 *
12404 * _.toInteger(Number.MIN_VALUE);
12405 * // => 0
12406 *
12407 * _.toInteger(Infinity);
12408 * // => 1.7976931348623157e+308
12409 *
12410 * _.toInteger('3.2');
12411 * // => 3
12412 */
12413 function toInteger(value) {
12414 var result = toFinite(value),
12415 remainder = result % 1;
12416
12417 return result === result ? (remainder ? result - remainder : result) : 0;
12418 }
12419
12420 /**
12421 * Converts `value` to an integer suitable for use as the length of an
12422 * array-like object.
12423 *
12424 * **Note:** This method is based on
12425 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
12426 *
12427 * @static
12428 * @memberOf _
12429 * @since 4.0.0
12430 * @category Lang
12431 * @param {*} value The value to convert.
12432 * @returns {number} Returns the converted integer.
12433 * @example
12434 *
12435 * _.toLength(3.2);
12436 * // => 3
12437 *
12438 * _.toLength(Number.MIN_VALUE);
12439 * // => 0
12440 *
12441 * _.toLength(Infinity);
12442 * // => 4294967295
12443 *
12444 * _.toLength('3.2');
12445 * // => 3
12446 */
12447 function toLength(value) {
12448 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
12449 }
12450
12451 /**
12452 * Converts `value` to a number.
12453 *
12454 * @static
12455 * @memberOf _
12456 * @since 4.0.0
12457 * @category Lang
12458 * @param {*} value The value to process.
12459 * @returns {number} Returns the number.
12460 * @example
12461 *
12462 * _.toNumber(3.2);
12463 * // => 3.2
12464 *
12465 * _.toNumber(Number.MIN_VALUE);
12466 * // => 5e-324
12467 *
12468 * _.toNumber(Infinity);
12469 * // => Infinity
12470 *
12471 * _.toNumber('3.2');
12472 * // => 3.2
12473 */
12474 function toNumber(value) {
12475 if (typeof value == 'number') {
12476 return value;
12477 }
12478 if (isSymbol(value)) {
12479 return NAN;
12480 }
12481 if (isObject(value)) {
12482 var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
12483 value = isObject(other) ? (other + '') : other;
12484 }
12485 if (typeof value != 'string') {
12486 return value === 0 ? value : +value;
12487 }
12488 value = value.replace(reTrim, '');
12489 var isBinary = reIsBinary.test(value);
12490 return (isBinary || reIsOctal.test(value))
12491 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
12492 : (reIsBadHex.test(value) ? NAN : +value);
12493 }
12494
12495 /**
12496 * Converts `value` to a plain object flattening inherited enumerable string
12497 * keyed properties of `value` to own properties of the plain object.
12498 *
12499 * @static
12500 * @memberOf _
12501 * @since 3.0.0
12502 * @category Lang
12503 * @param {*} value The value to convert.
12504 * @returns {Object} Returns the converted plain object.
12505 * @example
12506 *
12507 * function Foo() {
12508 * this.b = 2;
12509 * }
12510 *
12511 * Foo.prototype.c = 3;
12512 *
12513 * _.assign({ 'a': 1 }, new Foo);
12514 * // => { 'a': 1, 'b': 2 }
12515 *
12516 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
12517 * // => { 'a': 1, 'b': 2, 'c': 3 }
12518 */
12519 function toPlainObject(value) {
12520 return copyObject(value, keysIn(value));
12521 }
12522
12523 /**
12524 * Converts `value` to a safe integer. A safe integer can be compared and
12525 * represented correctly.
12526 *
12527 * @static
12528 * @memberOf _
12529 * @since 4.0.0
12530 * @category Lang
12531 * @param {*} value The value to convert.
12532 * @returns {number} Returns the converted integer.
12533 * @example
12534 *
12535 * _.toSafeInteger(3.2);
12536 * // => 3
12537 *
12538 * _.toSafeInteger(Number.MIN_VALUE);
12539 * // => 0
12540 *
12541 * _.toSafeInteger(Infinity);
12542 * // => 9007199254740991
12543 *
12544 * _.toSafeInteger('3.2');
12545 * // => 3
12546 */
12547 function toSafeInteger(value) {
12548 return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
12549 }
12550
12551 /**
12552 * Converts `value` to a string. An empty string is returned for `null`
12553 * and `undefined` values. The sign of `-0` is preserved.
12554 *
12555 * @static
12556 * @memberOf _
12557 * @since 4.0.0
12558 * @category Lang
12559 * @param {*} value The value to convert.
12560 * @returns {string} Returns the converted string.
12561 * @example
12562 *
12563 * _.toString(null);
12564 * // => ''
12565 *
12566 * _.toString(-0);
12567 * // => '-0'
12568 *
12569 * _.toString([1, 2, 3]);
12570 * // => '1,2,3'
12571 */
12572 function toString(value) {
12573 return value == null ? '' : baseToString(value);
12574 }
12575
12576 /*------------------------------------------------------------------------*/
12577
12578 /**
12579 * Assigns own enumerable string keyed properties of source objects to the
12580 * destination object. Source objects are applied from left to right.
12581 * Subsequent sources overwrite property assignments of previous sources.
12582 *
12583 * **Note:** This method mutates `object` and is loosely based on
12584 * [`Object.assign`](https://mdn.io/Object/assign).
12585 *
12586 * @static
12587 * @memberOf _
12588 * @since 0.10.0
12589 * @category Object
12590 * @param {Object} object The destination object.
12591 * @param {...Object} [sources] The source objects.
12592 * @returns {Object} Returns `object`.
12593 * @see _.assignIn
12594 * @example
12595 *
12596 * function Foo() {
12597 * this.a = 1;
12598 * }
12599 *
12600 * function Bar() {
12601 * this.c = 3;
12602 * }
12603 *
12604 * Foo.prototype.b = 2;
12605 * Bar.prototype.d = 4;
12606 *
12607 * _.assign({ 'a': 0 }, new Foo, new Bar);
12608 * // => { 'a': 1, 'c': 3 }
12609 */
12610 var assign = createAssigner(function(object, source) {
12611 if (isPrototype(source) || isArrayLike(source)) {
12612 copyObject(source, keys(source), object);
12613 return;
12614 }
12615 for (var key in source) {
12616 if (hasOwnProperty.call(source, key)) {
12617 assignValue(object, key, source[key]);
12618 }
12619 }
12620 });
12621
12622 /**
12623 * This method is like `_.assign` except that it iterates over own and
12624 * inherited source properties.
12625 *
12626 * **Note:** This method mutates `object`.
12627 *
12628 * @static
12629 * @memberOf _
12630 * @since 4.0.0
12631 * @alias extend
12632 * @category Object
12633 * @param {Object} object The destination object.
12634 * @param {...Object} [sources] The source objects.
12635 * @returns {Object} Returns `object`.
12636 * @see _.assign
12637 * @example
12638 *
12639 * function Foo() {
12640 * this.a = 1;
12641 * }
12642 *
12643 * function Bar() {
12644 * this.c = 3;
12645 * }
12646 *
12647 * Foo.prototype.b = 2;
12648 * Bar.prototype.d = 4;
12649 *
12650 * _.assignIn({ 'a': 0 }, new Foo, new Bar);
12651 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
12652 */
12653 var assignIn = createAssigner(function(object, source) {
12654 copyObject(source, keysIn(source), object);
12655 });
12656
12657 /**
12658 * This method is like `_.assignIn` except that it accepts `customizer`
12659 * which is invoked to produce the assigned values. If `customizer` returns
12660 * `undefined`, assignment is handled by the method instead. The `customizer`
12661 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12662 *
12663 * **Note:** This method mutates `object`.
12664 *
12665 * @static
12666 * @memberOf _
12667 * @since 4.0.0
12668 * @alias extendWith
12669 * @category Object
12670 * @param {Object} object The destination object.
12671 * @param {...Object} sources The source objects.
12672 * @param {Function} [customizer] The function to customize assigned values.
12673 * @returns {Object} Returns `object`.
12674 * @see _.assignWith
12675 * @example
12676 *
12677 * function customizer(objValue, srcValue) {
12678 * return _.isUndefined(objValue) ? srcValue : objValue;
12679 * }
12680 *
12681 * var defaults = _.partialRight(_.assignInWith, customizer);
12682 *
12683 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12684 * // => { 'a': 1, 'b': 2 }
12685 */
12686 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
12687 copyObject(source, keysIn(source), object, customizer);
12688 });
12689
12690 /**
12691 * This method is like `_.assign` except that it accepts `customizer`
12692 * which is invoked to produce the assigned values. If `customizer` returns
12693 * `undefined`, assignment is handled by the method instead. The `customizer`
12694 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12695 *
12696 * **Note:** This method mutates `object`.
12697 *
12698 * @static
12699 * @memberOf _
12700 * @since 4.0.0
12701 * @category Object
12702 * @param {Object} object The destination object.
12703 * @param {...Object} sources The source objects.
12704 * @param {Function} [customizer] The function to customize assigned values.
12705 * @returns {Object} Returns `object`.
12706 * @see _.assignInWith
12707 * @example
12708 *
12709 * function customizer(objValue, srcValue) {
12710 * return _.isUndefined(objValue) ? srcValue : objValue;
12711 * }
12712 *
12713 * var defaults = _.partialRight(_.assignWith, customizer);
12714 *
12715 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12716 * // => { 'a': 1, 'b': 2 }
12717 */
12718 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
12719 copyObject(source, keys(source), object, customizer);
12720 });
12721
12722 /**
12723 * Creates an array of values corresponding to `paths` of `object`.
12724 *
12725 * @static
12726 * @memberOf _
12727 * @since 1.0.0
12728 * @category Object
12729 * @param {Object} object The object to iterate over.
12730 * @param {...(string|string[])} [paths] The property paths to pick.
12731 * @returns {Array} Returns the picked values.
12732 * @example
12733 *
12734 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
12735 *
12736 * _.at(object, ['a[0].b.c', 'a[1]']);
12737 * // => [3, 4]
12738 */
12739 var at = flatRest(baseAt);
12740
12741 /**
12742 * Creates an object that inherits from the `prototype` object. If a
12743 * `properties` object is given, its own enumerable string keyed properties
12744 * are assigned to the created object.
12745 *
12746 * @static
12747 * @memberOf _
12748 * @since 2.3.0
12749 * @category Object
12750 * @param {Object} prototype The object to inherit from.
12751 * @param {Object} [properties] The properties to assign to the object.
12752 * @returns {Object} Returns the new object.
12753 * @example
12754 *
12755 * function Shape() {
12756 * this.x = 0;
12757 * this.y = 0;
12758 * }
12759 *
12760 * function Circle() {
12761 * Shape.call(this);
12762 * }
12763 *
12764 * Circle.prototype = _.create(Shape.prototype, {
12765 * 'constructor': Circle
12766 * });
12767 *
12768 * var circle = new Circle;
12769 * circle instanceof Circle;
12770 * // => true
12771 *
12772 * circle instanceof Shape;
12773 * // => true
12774 */
12775 function create(prototype, properties) {
12776 var result = baseCreate(prototype);
12777 return properties == null ? result : baseAssign(result, properties);
12778 }
12779
12780 /**
12781 * Assigns own and inherited enumerable string keyed properties of source
12782 * objects to the destination object for all destination properties that
12783 * resolve to `undefined`. Source objects are applied from left to right.
12784 * Once a property is set, additional values of the same property are ignored.
12785 *
12786 * **Note:** This method mutates `object`.
12787 *
12788 * @static
12789 * @since 0.1.0
12790 * @memberOf _
12791 * @category Object
12792 * @param {Object} object The destination object.
12793 * @param {...Object} [sources] The source objects.
12794 * @returns {Object} Returns `object`.
12795 * @see _.defaultsDeep
12796 * @example
12797 *
12798 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12799 * // => { 'a': 1, 'b': 2 }
12800 */
12801 var defaults = baseRest(function(args) {
12802 args.push(undefined, assignInDefaults);
12803 return apply(assignInWith, undefined, args);
12804 });
12805
12806 /**
12807 * This method is like `_.defaults` except that it recursively assigns
12808 * default properties.
12809 *
12810 * **Note:** This method mutates `object`.
12811 *
12812 * @static
12813 * @memberOf _
12814 * @since 3.10.0
12815 * @category Object
12816 * @param {Object} object The destination object.
12817 * @param {...Object} [sources] The source objects.
12818 * @returns {Object} Returns `object`.
12819 * @see _.defaults
12820 * @example
12821 *
12822 * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
12823 * // => { 'a': { 'b': 2, 'c': 3 } }
12824 */
12825 var defaultsDeep = baseRest(function(args) {
12826 args.push(undefined, mergeDefaults);
12827 return apply(mergeWith, undefined, args);
12828 });
12829
12830 /**
12831 * This method is like `_.find` except that it returns the key of the first
12832 * element `predicate` returns truthy for instead of the element itself.
12833 *
12834 * @static
12835 * @memberOf _
12836 * @since 1.1.0
12837 * @category Object
12838 * @param {Object} object The object to inspect.
12839 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12840 * @returns {string|undefined} Returns the key of the matched element,
12841 * else `undefined`.
12842 * @example
12843 *
12844 * var users = {
12845 * 'barney': { 'age': 36, 'active': true },
12846 * 'fred': { 'age': 40, 'active': false },
12847 * 'pebbles': { 'age': 1, 'active': true }
12848 * };
12849 *
12850 * _.findKey(users, function(o) { return o.age < 40; });
12851 * // => 'barney' (iteration order is not guaranteed)
12852 *
12853 * // The `_.matches` iteratee shorthand.
12854 * _.findKey(users, { 'age': 1, 'active': true });
12855 * // => 'pebbles'
12856 *
12857 * // The `_.matchesProperty` iteratee shorthand.
12858 * _.findKey(users, ['active', false]);
12859 * // => 'fred'
12860 *
12861 * // The `_.property` iteratee shorthand.
12862 * _.findKey(users, 'active');
12863 * // => 'barney'
12864 */
12865 function findKey(object, predicate) {
12866 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
12867 }
12868
12869 /**
12870 * This method is like `_.findKey` except that it iterates over elements of
12871 * a collection in the opposite order.
12872 *
12873 * @static
12874 * @memberOf _
12875 * @since 2.0.0
12876 * @category Object
12877 * @param {Object} object The object to inspect.
12878 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12879 * @returns {string|undefined} Returns the key of the matched element,
12880 * else `undefined`.
12881 * @example
12882 *
12883 * var users = {
12884 * 'barney': { 'age': 36, 'active': true },
12885 * 'fred': { 'age': 40, 'active': false },
12886 * 'pebbles': { 'age': 1, 'active': true }
12887 * };
12888 *
12889 * _.findLastKey(users, function(o) { return o.age < 40; });
12890 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
12891 *
12892 * // The `_.matches` iteratee shorthand.
12893 * _.findLastKey(users, { 'age': 36, 'active': true });
12894 * // => 'barney'
12895 *
12896 * // The `_.matchesProperty` iteratee shorthand.
12897 * _.findLastKey(users, ['active', false]);
12898 * // => 'fred'
12899 *
12900 * // The `_.property` iteratee shorthand.
12901 * _.findLastKey(users, 'active');
12902 * // => 'pebbles'
12903 */
12904 function findLastKey(object, predicate) {
12905 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
12906 }
12907
12908 /**
12909 * Iterates over own and inherited enumerable string keyed properties of an
12910 * object and invokes `iteratee` for each property. The iteratee is invoked
12911 * with three arguments: (value, key, object). Iteratee functions may exit
12912 * iteration early by explicitly returning `false`.
12913 *
12914 * @static
12915 * @memberOf _
12916 * @since 0.3.0
12917 * @category Object
12918 * @param {Object} object The object to iterate over.
12919 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12920 * @returns {Object} Returns `object`.
12921 * @see _.forInRight
12922 * @example
12923 *
12924 * function Foo() {
12925 * this.a = 1;
12926 * this.b = 2;
12927 * }
12928 *
12929 * Foo.prototype.c = 3;
12930 *
12931 * _.forIn(new Foo, function(value, key) {
12932 * console.log(key);
12933 * });
12934 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
12935 */
12936 function forIn(object, iteratee) {
12937 return object == null
12938 ? object
12939 : baseFor(object, getIteratee(iteratee, 3), keysIn);
12940 }
12941
12942 /**
12943 * This method is like `_.forIn` except that it iterates over properties of
12944 * `object` in the opposite order.
12945 *
12946 * @static
12947 * @memberOf _
12948 * @since 2.0.0
12949 * @category Object
12950 * @param {Object} object The object to iterate over.
12951 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12952 * @returns {Object} Returns `object`.
12953 * @see _.forIn
12954 * @example
12955 *
12956 * function Foo() {
12957 * this.a = 1;
12958 * this.b = 2;
12959 * }
12960 *
12961 * Foo.prototype.c = 3;
12962 *
12963 * _.forInRight(new Foo, function(value, key) {
12964 * console.log(key);
12965 * });
12966 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
12967 */
12968 function forInRight(object, iteratee) {
12969 return object == null
12970 ? object
12971 : baseForRight(object, getIteratee(iteratee, 3), keysIn);
12972 }
12973
12974 /**
12975 * Iterates over own enumerable string keyed properties of an object and
12976 * invokes `iteratee` for each property. The iteratee is invoked with three
12977 * arguments: (value, key, object). Iteratee functions may exit iteration
12978 * early by explicitly returning `false`.
12979 *
12980 * @static
12981 * @memberOf _
12982 * @since 0.3.0
12983 * @category Object
12984 * @param {Object} object The object to iterate over.
12985 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12986 * @returns {Object} Returns `object`.
12987 * @see _.forOwnRight
12988 * @example
12989 *
12990 * function Foo() {
12991 * this.a = 1;
12992 * this.b = 2;
12993 * }
12994 *
12995 * Foo.prototype.c = 3;
12996 *
12997 * _.forOwn(new Foo, function(value, key) {
12998 * console.log(key);
12999 * });
13000 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
13001 */
13002 function forOwn(object, iteratee) {
13003 return object && baseForOwn(object, getIteratee(iteratee, 3));
13004 }
13005
13006 /**
13007 * This method is like `_.forOwn` except that it iterates over properties of
13008 * `object` in the opposite order.
13009 *
13010 * @static
13011 * @memberOf _
13012 * @since 2.0.0
13013 * @category Object
13014 * @param {Object} object The object to iterate over.
13015 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13016 * @returns {Object} Returns `object`.
13017 * @see _.forOwn
13018 * @example
13019 *
13020 * function Foo() {
13021 * this.a = 1;
13022 * this.b = 2;
13023 * }
13024 *
13025 * Foo.prototype.c = 3;
13026 *
13027 * _.forOwnRight(new Foo, function(value, key) {
13028 * console.log(key);
13029 * });
13030 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
13031 */
13032 function forOwnRight(object, iteratee) {
13033 return object && baseForOwnRight(object, getIteratee(iteratee, 3));
13034 }
13035
13036 /**
13037 * Creates an array of function property names from own enumerable properties
13038 * of `object`.
13039 *
13040 * @static
13041 * @since 0.1.0
13042 * @memberOf _
13043 * @category Object
13044 * @param {Object} object The object to inspect.
13045 * @returns {Array} Returns the function names.
13046 * @see _.functionsIn
13047 * @example
13048 *
13049 * function Foo() {
13050 * this.a = _.constant('a');
13051 * this.b = _.constant('b');
13052 * }
13053 *
13054 * Foo.prototype.c = _.constant('c');
13055 *
13056 * _.functions(new Foo);
13057 * // => ['a', 'b']
13058 */
13059 function functions(object) {
13060 return object == null ? [] : baseFunctions(object, keys(object));
13061 }
13062
13063 /**
13064 * Creates an array of function property names from own and inherited
13065 * enumerable properties of `object`.
13066 *
13067 * @static
13068 * @memberOf _
13069 * @since 4.0.0
13070 * @category Object
13071 * @param {Object} object The object to inspect.
13072 * @returns {Array} Returns the function names.
13073 * @see _.functions
13074 * @example
13075 *
13076 * function Foo() {
13077 * this.a = _.constant('a');
13078 * this.b = _.constant('b');
13079 * }
13080 *
13081 * Foo.prototype.c = _.constant('c');
13082 *
13083 * _.functionsIn(new Foo);
13084 * // => ['a', 'b', 'c']
13085 */
13086 function functionsIn(object) {
13087 return object == null ? [] : baseFunctions(object, keysIn(object));
13088 }
13089
13090 /**
13091 * Gets the value at `path` of `object`. If the resolved value is
13092 * `undefined`, the `defaultValue` is returned in its place.
13093 *
13094 * @static
13095 * @memberOf _
13096 * @since 3.7.0
13097 * @category Object
13098 * @param {Object} object The object to query.
13099 * @param {Array|string} path The path of the property to get.
13100 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13101 * @returns {*} Returns the resolved value.
13102 * @example
13103 *
13104 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13105 *
13106 * _.get(object, 'a[0].b.c');
13107 * // => 3
13108 *
13109 * _.get(object, ['a', '0', 'b', 'c']);
13110 * // => 3
13111 *
13112 * _.get(object, 'a.b.c', 'default');
13113 * // => 'default'
13114 */
13115 function get(object, path, defaultValue) {
13116 var result = object == null ? undefined : baseGet(object, path);
13117 return result === undefined ? defaultValue : result;
13118 }
13119
13120 /**
13121 * Checks if `path` is a direct property of `object`.
13122 *
13123 * @static
13124 * @since 0.1.0
13125 * @memberOf _
13126 * @category Object
13127 * @param {Object} object The object to query.
13128 * @param {Array|string} path The path to check.
13129 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13130 * @example
13131 *
13132 * var object = { 'a': { 'b': 2 } };
13133 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
13134 *
13135 * _.has(object, 'a');
13136 * // => true
13137 *
13138 * _.has(object, 'a.b');
13139 * // => true
13140 *
13141 * _.has(object, ['a', 'b']);
13142 * // => true
13143 *
13144 * _.has(other, 'a');
13145 * // => false
13146 */
13147 function has(object, path) {
13148 return object != null && hasPath(object, path, baseHas);
13149 }
13150
13151 /**
13152 * Checks if `path` is a direct or inherited property of `object`.
13153 *
13154 * @static
13155 * @memberOf _
13156 * @since 4.0.0
13157 * @category Object
13158 * @param {Object} object The object to query.
13159 * @param {Array|string} path The path to check.
13160 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13161 * @example
13162 *
13163 * var object = _.create({ 'a': _.create({ 'b': 2 }) });
13164 *
13165 * _.hasIn(object, 'a');
13166 * // => true
13167 *
13168 * _.hasIn(object, 'a.b');
13169 * // => true
13170 *
13171 * _.hasIn(object, ['a', 'b']);
13172 * // => true
13173 *
13174 * _.hasIn(object, 'b');
13175 * // => false
13176 */
13177 function hasIn(object, path) {
13178 return object != null && hasPath(object, path, baseHasIn);
13179 }
13180
13181 /**
13182 * Creates an object composed of the inverted keys and values of `object`.
13183 * If `object` contains duplicate values, subsequent values overwrite
13184 * property assignments of previous values.
13185 *
13186 * @static
13187 * @memberOf _
13188 * @since 0.7.0
13189 * @category Object
13190 * @param {Object} object The object to invert.
13191 * @returns {Object} Returns the new inverted object.
13192 * @example
13193 *
13194 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13195 *
13196 * _.invert(object);
13197 * // => { '1': 'c', '2': 'b' }
13198 */
13199 var invert = createInverter(function(result, value, key) {
13200 result[value] = key;
13201 }, constant(identity));
13202
13203 /**
13204 * This method is like `_.invert` except that the inverted object is generated
13205 * from the results of running each element of `object` thru `iteratee`. The
13206 * corresponding inverted value of each inverted key is an array of keys
13207 * responsible for generating the inverted value. The iteratee is invoked
13208 * with one argument: (value).
13209 *
13210 * @static
13211 * @memberOf _
13212 * @since 4.1.0
13213 * @category Object
13214 * @param {Object} object The object to invert.
13215 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
13216 * @returns {Object} Returns the new inverted object.
13217 * @example
13218 *
13219 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13220 *
13221 * _.invertBy(object);
13222 * // => { '1': ['a', 'c'], '2': ['b'] }
13223 *
13224 * _.invertBy(object, function(value) {
13225 * return 'group' + value;
13226 * });
13227 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
13228 */
13229 var invertBy = createInverter(function(result, value, key) {
13230 if (hasOwnProperty.call(result, value)) {
13231 result[value].push(key);
13232 } else {
13233 result[value] = [key];
13234 }
13235 }, getIteratee);
13236
13237 /**
13238 * Invokes the method at `path` of `object`.
13239 *
13240 * @static
13241 * @memberOf _
13242 * @since 4.0.0
13243 * @category Object
13244 * @param {Object} object The object to query.
13245 * @param {Array|string} path The path of the method to invoke.
13246 * @param {...*} [args] The arguments to invoke the method with.
13247 * @returns {*} Returns the result of the invoked method.
13248 * @example
13249 *
13250 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
13251 *
13252 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
13253 * // => [2, 3]
13254 */
13255 var invoke = baseRest(baseInvoke);
13256
13257 /**
13258 * Creates an array of the own enumerable property names of `object`.
13259 *
13260 * **Note:** Non-object values are coerced to objects. See the
13261 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
13262 * for more details.
13263 *
13264 * @static
13265 * @since 0.1.0
13266 * @memberOf _
13267 * @category Object
13268 * @param {Object} object The object to query.
13269 * @returns {Array} Returns the array of property names.
13270 * @example
13271 *
13272 * function Foo() {
13273 * this.a = 1;
13274 * this.b = 2;
13275 * }
13276 *
13277 * Foo.prototype.c = 3;
13278 *
13279 * _.keys(new Foo);
13280 * // => ['a', 'b'] (iteration order is not guaranteed)
13281 *
13282 * _.keys('hi');
13283 * // => ['0', '1']
13284 */
13285 function keys(object) {
13286 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
13287 }
13288
13289 /**
13290 * Creates an array of the own and inherited enumerable property names of `object`.
13291 *
13292 * **Note:** Non-object values are coerced to objects.
13293 *
13294 * @static
13295 * @memberOf _
13296 * @since 3.0.0
13297 * @category Object
13298 * @param {Object} object The object to query.
13299 * @returns {Array} Returns the array of property names.
13300 * @example
13301 *
13302 * function Foo() {
13303 * this.a = 1;
13304 * this.b = 2;
13305 * }
13306 *
13307 * Foo.prototype.c = 3;
13308 *
13309 * _.keysIn(new Foo);
13310 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
13311 */
13312 function keysIn(object) {
13313 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
13314 }
13315
13316 /**
13317 * The opposite of `_.mapValues`; this method creates an object with the
13318 * same values as `object` and keys generated by running each own enumerable
13319 * string keyed property of `object` thru `iteratee`. The iteratee is invoked
13320 * with three arguments: (value, key, object).
13321 *
13322 * @static
13323 * @memberOf _
13324 * @since 3.8.0
13325 * @category Object
13326 * @param {Object} object The object to iterate over.
13327 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13328 * @returns {Object} Returns the new mapped object.
13329 * @see _.mapValues
13330 * @example
13331 *
13332 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
13333 * return key + value;
13334 * });
13335 * // => { 'a1': 1, 'b2': 2 }
13336 */
13337 function mapKeys(object, iteratee) {
13338 var result = {};
13339 iteratee = getIteratee(iteratee, 3);
13340
13341 baseForOwn(object, function(value, key, object) {
13342 baseAssignValue(result, iteratee(value, key, object), value);
13343 });
13344 return result;
13345 }
13346
13347 /**
13348 * Creates an object with the same keys as `object` and values generated
13349 * by running each own enumerable string keyed property of `object` thru
13350 * `iteratee`. The iteratee is invoked with three arguments:
13351 * (value, key, object).
13352 *
13353 * @static
13354 * @memberOf _
13355 * @since 2.4.0
13356 * @category Object
13357 * @param {Object} object The object to iterate over.
13358 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13359 * @returns {Object} Returns the new mapped object.
13360 * @see _.mapKeys
13361 * @example
13362 *
13363 * var users = {
13364 * 'fred': { 'user': 'fred', 'age': 40 },
13365 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
13366 * };
13367 *
13368 * _.mapValues(users, function(o) { return o.age; });
13369 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13370 *
13371 * // The `_.property` iteratee shorthand.
13372 * _.mapValues(users, 'age');
13373 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13374 */
13375 function mapValues(object, iteratee) {
13376 var result = {};
13377 iteratee = getIteratee(iteratee, 3);
13378
13379 baseForOwn(object, function(value, key, object) {
13380 baseAssignValue(result, key, iteratee(value, key, object));
13381 });
13382 return result;
13383 }
13384
13385 /**
13386 * This method is like `_.assign` except that it recursively merges own and
13387 * inherited enumerable string keyed properties of source objects into the
13388 * destination object. Source properties that resolve to `undefined` are
13389 * skipped if a destination value exists. Array and plain object properties
13390 * are merged recursively. Other objects and value types are overridden by
13391 * assignment. Source objects are applied from left to right. Subsequent
13392 * sources overwrite property assignments of previous sources.
13393 *
13394 * **Note:** This method mutates `object`.
13395 *
13396 * @static
13397 * @memberOf _
13398 * @since 0.5.0
13399 * @category Object
13400 * @param {Object} object The destination object.
13401 * @param {...Object} [sources] The source objects.
13402 * @returns {Object} Returns `object`.
13403 * @example
13404 *
13405 * var object = {
13406 * 'a': [{ 'b': 2 }, { 'd': 4 }]
13407 * };
13408 *
13409 * var other = {
13410 * 'a': [{ 'c': 3 }, { 'e': 5 }]
13411 * };
13412 *
13413 * _.merge(object, other);
13414 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
13415 */
13416 var merge = createAssigner(function(object, source, srcIndex) {
13417 baseMerge(object, source, srcIndex);
13418 });
13419
13420 /**
13421 * This method is like `_.merge` except that it accepts `customizer` which
13422 * is invoked to produce the merged values of the destination and source
13423 * properties. If `customizer` returns `undefined`, merging is handled by the
13424 * method instead. The `customizer` is invoked with six arguments:
13425 * (objValue, srcValue, key, object, source, stack).
13426 *
13427 * **Note:** This method mutates `object`.
13428 *
13429 * @static
13430 * @memberOf _
13431 * @since 4.0.0
13432 * @category Object
13433 * @param {Object} object The destination object.
13434 * @param {...Object} sources The source objects.
13435 * @param {Function} customizer The function to customize assigned values.
13436 * @returns {Object} Returns `object`.
13437 * @example
13438 *
13439 * function customizer(objValue, srcValue) {
13440 * if (_.isArray(objValue)) {
13441 * return objValue.concat(srcValue);
13442 * }
13443 * }
13444 *
13445 * var object = { 'a': [1], 'b': [2] };
13446 * var other = { 'a': [3], 'b': [4] };
13447 *
13448 * _.mergeWith(object, other, customizer);
13449 * // => { 'a': [1, 3], 'b': [2, 4] }
13450 */
13451 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
13452 baseMerge(object, source, srcIndex, customizer);
13453 });
13454
13455 /**
13456 * The opposite of `_.pick`; this method creates an object composed of the
13457 * own and inherited enumerable property paths of `object` that are not omitted.
13458 *
13459 * **Note:** This method is considerably slower than `_.pick`.
13460 *
13461 * @static
13462 * @since 0.1.0
13463 * @memberOf _
13464 * @category Object
13465 * @param {Object} object The source object.
13466 * @param {...(string|string[])} [paths] The property paths to omit.
13467 * @returns {Object} Returns the new object.
13468 * @example
13469 *
13470 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13471 *
13472 * _.omit(object, ['a', 'c']);
13473 * // => { 'b': '2' }
13474 */
13475 var omit = flatRest(function(object, paths) {
13476 var result = {};
13477 if (object == null) {
13478 return result;
13479 }
13480 copyObject(object, getAllKeysIn(object), result);
13481 result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG);
13482
13483 var length = paths.length;
13484 while (length--) {
13485 baseUnset(result, paths[length]);
13486 }
13487 return result;
13488 });
13489
13490 /**
13491 * The opposite of `_.pickBy`; this method creates an object composed of
13492 * the own and inherited enumerable string keyed properties of `object` that
13493 * `predicate` doesn't return truthy for. The predicate is invoked with two
13494 * arguments: (value, key).
13495 *
13496 * @static
13497 * @memberOf _
13498 * @since 4.0.0
13499 * @category Object
13500 * @param {Object} object The source object.
13501 * @param {Function} [predicate=_.identity] The function invoked per property.
13502 * @returns {Object} Returns the new object.
13503 * @example
13504 *
13505 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13506 *
13507 * _.omitBy(object, _.isNumber);
13508 * // => { 'b': '2' }
13509 */
13510 function omitBy(object, predicate) {
13511 return pickBy(object, negate(getIteratee(predicate)));
13512 }
13513
13514 /**
13515 * Creates an object composed of the picked `object` properties.
13516 *
13517 * @static
13518 * @since 0.1.0
13519 * @memberOf _
13520 * @category Object
13521 * @param {Object} object The source object.
13522 * @param {...(string|string[])} [paths] The property paths to pick.
13523 * @returns {Object} Returns the new object.
13524 * @example
13525 *
13526 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13527 *
13528 * _.pick(object, ['a', 'c']);
13529 * // => { 'a': 1, 'c': 3 }
13530 */
13531 var pick = flatRest(function(object, paths) {
13532 return object == null ? {} : basePick(object, arrayMap(paths, toKey));
13533 });
13534
13535 /**
13536 * Creates an object composed of the `object` properties `predicate` returns
13537 * truthy for. The predicate is invoked with two arguments: (value, key).
13538 *
13539 * @static
13540 * @memberOf _
13541 * @since 4.0.0
13542 * @category Object
13543 * @param {Object} object The source object.
13544 * @param {Function} [predicate=_.identity] The function invoked per property.
13545 * @returns {Object} Returns the new object.
13546 * @example
13547 *
13548 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13549 *
13550 * _.pickBy(object, _.isNumber);
13551 * // => { 'a': 1, 'c': 3 }
13552 */
13553 function pickBy(object, predicate) {
13554 return object == null ? {} : basePickBy(object, getAllKeysIn(object), getIteratee(predicate));
13555 }
13556
13557 /**
13558 * This method is like `_.get` except that if the resolved value is a
13559 * function it's invoked with the `this` binding of its parent object and
13560 * its result is returned.
13561 *
13562 * @static
13563 * @since 0.1.0
13564 * @memberOf _
13565 * @category Object
13566 * @param {Object} object The object to query.
13567 * @param {Array|string} path The path of the property to resolve.
13568 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13569 * @returns {*} Returns the resolved value.
13570 * @example
13571 *
13572 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
13573 *
13574 * _.result(object, 'a[0].b.c1');
13575 * // => 3
13576 *
13577 * _.result(object, 'a[0].b.c2');
13578 * // => 4
13579 *
13580 * _.result(object, 'a[0].b.c3', 'default');
13581 * // => 'default'
13582 *
13583 * _.result(object, 'a[0].b.c3', _.constant('default'));
13584 * // => 'default'
13585 */
13586 function result(object, path, defaultValue) {
13587 path = isKey(path, object) ? [path] : castPath(path);
13588
13589 var index = -1,
13590 length = path.length;
13591
13592 // Ensure the loop is entered when path is empty.
13593 if (!length) {
13594 object = undefined;
13595 length = 1;
13596 }
13597 while (++index < length) {
13598 var value = object == null ? undefined : object[toKey(path[index])];
13599 if (value === undefined) {
13600 index = length;
13601 value = defaultValue;
13602 }
13603 object = isFunction(value) ? value.call(object) : value;
13604 }
13605 return object;
13606 }
13607
13608 /**
13609 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
13610 * it's created. Arrays are created for missing index properties while objects
13611 * are created for all other missing properties. Use `_.setWith` to customize
13612 * `path` creation.
13613 *
13614 * **Note:** This method mutates `object`.
13615 *
13616 * @static
13617 * @memberOf _
13618 * @since 3.7.0
13619 * @category Object
13620 * @param {Object} object The object to modify.
13621 * @param {Array|string} path The path of the property to set.
13622 * @param {*} value The value to set.
13623 * @returns {Object} Returns `object`.
13624 * @example
13625 *
13626 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13627 *
13628 * _.set(object, 'a[0].b.c', 4);
13629 * console.log(object.a[0].b.c);
13630 * // => 4
13631 *
13632 * _.set(object, ['x', '0', 'y', 'z'], 5);
13633 * console.log(object.x[0].y.z);
13634 * // => 5
13635 */
13636 function set(object, path, value) {
13637 return object == null ? object : baseSet(object, path, value);
13638 }
13639
13640 /**
13641 * This method is like `_.set` except that it accepts `customizer` which is
13642 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13643 * path creation is handled by the method instead. The `customizer` is invoked
13644 * with three arguments: (nsValue, key, nsObject).
13645 *
13646 * **Note:** This method mutates `object`.
13647 *
13648 * @static
13649 * @memberOf _
13650 * @since 4.0.0
13651 * @category Object
13652 * @param {Object} object The object to modify.
13653 * @param {Array|string} path The path of the property to set.
13654 * @param {*} value The value to set.
13655 * @param {Function} [customizer] The function to customize assigned values.
13656 * @returns {Object} Returns `object`.
13657 * @example
13658 *
13659 * var object = {};
13660 *
13661 * _.setWith(object, '[0][1]', 'a', Object);
13662 * // => { '0': { '1': 'a' } }
13663 */
13664 function setWith(object, path, value, customizer) {
13665 customizer = typeof customizer == 'function' ? customizer : undefined;
13666 return object == null ? object : baseSet(object, path, value, customizer);
13667 }
13668
13669 /**
13670 * Creates an array of own enumerable string keyed-value pairs for `object`
13671 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
13672 * entries are returned.
13673 *
13674 * @static
13675 * @memberOf _
13676 * @since 4.0.0
13677 * @alias entries
13678 * @category Object
13679 * @param {Object} object The object to query.
13680 * @returns {Array} Returns the key-value pairs.
13681 * @example
13682 *
13683 * function Foo() {
13684 * this.a = 1;
13685 * this.b = 2;
13686 * }
13687 *
13688 * Foo.prototype.c = 3;
13689 *
13690 * _.toPairs(new Foo);
13691 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
13692 */
13693 var toPairs = createToPairs(keys);
13694
13695 /**
13696 * Creates an array of own and inherited enumerable string keyed-value pairs
13697 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
13698 * or set, its entries are returned.
13699 *
13700 * @static
13701 * @memberOf _
13702 * @since 4.0.0
13703 * @alias entriesIn
13704 * @category Object
13705 * @param {Object} object The object to query.
13706 * @returns {Array} Returns the key-value pairs.
13707 * @example
13708 *
13709 * function Foo() {
13710 * this.a = 1;
13711 * this.b = 2;
13712 * }
13713 *
13714 * Foo.prototype.c = 3;
13715 *
13716 * _.toPairsIn(new Foo);
13717 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
13718 */
13719 var toPairsIn = createToPairs(keysIn);
13720
13721 /**
13722 * An alternative to `_.reduce`; this method transforms `object` to a new
13723 * `accumulator` object which is the result of running each of its own
13724 * enumerable string keyed properties thru `iteratee`, with each invocation
13725 * potentially mutating the `accumulator` object. If `accumulator` is not
13726 * provided, a new object with the same `[[Prototype]]` will be used. The
13727 * iteratee is invoked with four arguments: (accumulator, value, key, object).
13728 * Iteratee functions may exit iteration early by explicitly returning `false`.
13729 *
13730 * @static
13731 * @memberOf _
13732 * @since 1.3.0
13733 * @category Object
13734 * @param {Object} object The object to iterate over.
13735 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13736 * @param {*} [accumulator] The custom accumulator value.
13737 * @returns {*} Returns the accumulated value.
13738 * @example
13739 *
13740 * _.transform([2, 3, 4], function(result, n) {
13741 * result.push(n *= n);
13742 * return n % 2 == 0;
13743 * }, []);
13744 * // => [4, 9]
13745 *
13746 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
13747 * (result[value] || (result[value] = [])).push(key);
13748 * }, {});
13749 * // => { '1': ['a', 'c'], '2': ['b'] }
13750 */
13751 function transform(object, iteratee, accumulator) {
13752 var isArr = isArray(object),
13753 isArrLike = isArr || isBuffer(object) || isTypedArray(object);
13754
13755 iteratee = getIteratee(iteratee, 4);
13756 if (accumulator == null) {
13757 var Ctor = object && object.constructor;
13758 if (isArrLike) {
13759 accumulator = isArr ? new Ctor : [];
13760 }
13761 else if (isObject(object)) {
13762 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
13763 }
13764 else {
13765 accumulator = {};
13766 }
13767 }
13768 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
13769 return iteratee(accumulator, value, index, object);
13770 });
13771 return accumulator;
13772 }
13773
13774 /**
13775 * Removes the property at `path` of `object`.
13776 *
13777 * **Note:** This method mutates `object`.
13778 *
13779 * @static
13780 * @memberOf _
13781 * @since 4.0.0
13782 * @category Object
13783 * @param {Object} object The object to modify.
13784 * @param {Array|string} path The path of the property to unset.
13785 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
13786 * @example
13787 *
13788 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
13789 * _.unset(object, 'a[0].b.c');
13790 * // => true
13791 *
13792 * console.log(object);
13793 * // => { 'a': [{ 'b': {} }] };
13794 *
13795 * _.unset(object, ['a', '0', 'b', 'c']);
13796 * // => true
13797 *
13798 * console.log(object);
13799 * // => { 'a': [{ 'b': {} }] };
13800 */
13801 function unset(object, path) {
13802 return object == null ? true : baseUnset(object, path);
13803 }
13804
13805 /**
13806 * This method is like `_.set` except that accepts `updater` to produce the
13807 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
13808 * is invoked with one argument: (value).
13809 *
13810 * **Note:** This method mutates `object`.
13811 *
13812 * @static
13813 * @memberOf _
13814 * @since 4.6.0
13815 * @category Object
13816 * @param {Object} object The object to modify.
13817 * @param {Array|string} path The path of the property to set.
13818 * @param {Function} updater The function to produce the updated value.
13819 * @returns {Object} Returns `object`.
13820 * @example
13821 *
13822 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13823 *
13824 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
13825 * console.log(object.a[0].b.c);
13826 * // => 9
13827 *
13828 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
13829 * console.log(object.x[0].y.z);
13830 * // => 0
13831 */
13832 function update(object, path, updater) {
13833 return object == null ? object : baseUpdate(object, path, castFunction(updater));
13834 }
13835
13836 /**
13837 * This method is like `_.update` except that it accepts `customizer` which is
13838 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13839 * path creation is handled by the method instead. The `customizer` is invoked
13840 * with three arguments: (nsValue, key, nsObject).
13841 *
13842 * **Note:** This method mutates `object`.
13843 *
13844 * @static
13845 * @memberOf _
13846 * @since 4.6.0
13847 * @category Object
13848 * @param {Object} object The object to modify.
13849 * @param {Array|string} path The path of the property to set.
13850 * @param {Function} updater The function to produce the updated value.
13851 * @param {Function} [customizer] The function to customize assigned values.
13852 * @returns {Object} Returns `object`.
13853 * @example
13854 *
13855 * var object = {};
13856 *
13857 * _.updateWith(object, '[0][1]', _.constant('a'), Object);
13858 * // => { '0': { '1': 'a' } }
13859 */
13860 function updateWith(object, path, updater, customizer) {
13861 customizer = typeof customizer == 'function' ? customizer : undefined;
13862 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
13863 }
13864
13865 /**
13866 * Creates an array of the own enumerable string keyed property values of `object`.
13867 *
13868 * **Note:** Non-object values are coerced to objects.
13869 *
13870 * @static
13871 * @since 0.1.0
13872 * @memberOf _
13873 * @category Object
13874 * @param {Object} object The object to query.
13875 * @returns {Array} Returns the array of property values.
13876 * @example
13877 *
13878 * function Foo() {
13879 * this.a = 1;
13880 * this.b = 2;
13881 * }
13882 *
13883 * Foo.prototype.c = 3;
13884 *
13885 * _.values(new Foo);
13886 * // => [1, 2] (iteration order is not guaranteed)
13887 *
13888 * _.values('hi');
13889 * // => ['h', 'i']
13890 */
13891 function values(object) {
13892 return object == null ? [] : baseValues(object, keys(object));
13893 }
13894
13895 /**
13896 * Creates an array of the own and inherited enumerable string keyed property
13897 * values of `object`.
13898 *
13899 * **Note:** Non-object values are coerced to objects.
13900 *
13901 * @static
13902 * @memberOf _
13903 * @since 3.0.0
13904 * @category Object
13905 * @param {Object} object The object to query.
13906 * @returns {Array} Returns the array of property values.
13907 * @example
13908 *
13909 * function Foo() {
13910 * this.a = 1;
13911 * this.b = 2;
13912 * }
13913 *
13914 * Foo.prototype.c = 3;
13915 *
13916 * _.valuesIn(new Foo);
13917 * // => [1, 2, 3] (iteration order is not guaranteed)
13918 */
13919 function valuesIn(object) {
13920 return object == null ? [] : baseValues(object, keysIn(object));
13921 }
13922
13923 /*------------------------------------------------------------------------*/
13924
13925 /**
13926 * Clamps `number` within the inclusive `lower` and `upper` bounds.
13927 *
13928 * @static
13929 * @memberOf _
13930 * @since 4.0.0
13931 * @category Number
13932 * @param {number} number The number to clamp.
13933 * @param {number} [lower] The lower bound.
13934 * @param {number} upper The upper bound.
13935 * @returns {number} Returns the clamped number.
13936 * @example
13937 *
13938 * _.clamp(-10, -5, 5);
13939 * // => -5
13940 *
13941 * _.clamp(10, -5, 5);
13942 * // => 5
13943 */
13944 function clamp(number, lower, upper) {
13945 if (upper === undefined) {
13946 upper = lower;
13947 lower = undefined;
13948 }
13949 if (upper !== undefined) {
13950 upper = toNumber(upper);
13951 upper = upper === upper ? upper : 0;
13952 }
13953 if (lower !== undefined) {
13954 lower = toNumber(lower);
13955 lower = lower === lower ? lower : 0;
13956 }
13957 return baseClamp(toNumber(number), lower, upper);
13958 }
13959
13960 /**
13961 * Checks if `n` is between `start` and up to, but not including, `end`. If
13962 * `end` is not specified, it's set to `start` with `start` then set to `0`.
13963 * If `start` is greater than `end` the params are swapped to support
13964 * negative ranges.
13965 *
13966 * @static
13967 * @memberOf _
13968 * @since 3.3.0
13969 * @category Number
13970 * @param {number} number The number to check.
13971 * @param {number} [start=0] The start of the range.
13972 * @param {number} end The end of the range.
13973 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
13974 * @see _.range, _.rangeRight
13975 * @example
13976 *
13977 * _.inRange(3, 2, 4);
13978 * // => true
13979 *
13980 * _.inRange(4, 8);
13981 * // => true
13982 *
13983 * _.inRange(4, 2);
13984 * // => false
13985 *
13986 * _.inRange(2, 2);
13987 * // => false
13988 *
13989 * _.inRange(1.2, 2);
13990 * // => true
13991 *
13992 * _.inRange(5.2, 4);
13993 * // => false
13994 *
13995 * _.inRange(-3, -2, -6);
13996 * // => true
13997 */
13998 function inRange(number, start, end) {
13999 start = toFinite(start);
14000 if (end === undefined) {
14001 end = start;
14002 start = 0;
14003 } else {
14004 end = toFinite(end);
14005 }
14006 number = toNumber(number);
14007 return baseInRange(number, start, end);
14008 }
14009
14010 /**
14011 * Produces a random number between the inclusive `lower` and `upper` bounds.
14012 * If only one argument is provided a number between `0` and the given number
14013 * is returned. If `floating` is `true`, or either `lower` or `upper` are
14014 * floats, a floating-point number is returned instead of an integer.
14015 *
14016 * **Note:** JavaScript follows the IEEE-754 standard for resolving
14017 * floating-point values which can produce unexpected results.
14018 *
14019 * @static
14020 * @memberOf _
14021 * @since 0.7.0
14022 * @category Number
14023 * @param {number} [lower=0] The lower bound.
14024 * @param {number} [upper=1] The upper bound.
14025 * @param {boolean} [floating] Specify returning a floating-point number.
14026 * @returns {number} Returns the random number.
14027 * @example
14028 *
14029 * _.random(0, 5);
14030 * // => an integer between 0 and 5
14031 *
14032 * _.random(5);
14033 * // => also an integer between 0 and 5
14034 *
14035 * _.random(5, true);
14036 * // => a floating-point number between 0 and 5
14037 *
14038 * _.random(1.2, 5.2);
14039 * // => a floating-point number between 1.2 and 5.2
14040 */
14041 function random(lower, upper, floating) {
14042 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
14043 upper = floating = undefined;
14044 }
14045 if (floating === undefined) {
14046 if (typeof upper == 'boolean') {
14047 floating = upper;
14048 upper = undefined;
14049 }
14050 else if (typeof lower == 'boolean') {
14051 floating = lower;
14052 lower = undefined;
14053 }
14054 }
14055 if (lower === undefined && upper === undefined) {
14056 lower = 0;
14057 upper = 1;
14058 }
14059 else {
14060 lower = toFinite(lower);
14061 if (upper === undefined) {
14062 upper = lower;
14063 lower = 0;
14064 } else {
14065 upper = toFinite(upper);
14066 }
14067 }
14068 if (lower > upper) {
14069 var temp = lower;
14070 lower = upper;
14071 upper = temp;
14072 }
14073 if (floating || lower % 1 || upper % 1) {
14074 var rand = nativeRandom();
14075 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
14076 }
14077 return baseRandom(lower, upper);
14078 }
14079
14080 /*------------------------------------------------------------------------*/
14081
14082 /**
14083 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
14084 *
14085 * @static
14086 * @memberOf _
14087 * @since 3.0.0
14088 * @category String
14089 * @param {string} [string=''] The string to convert.
14090 * @returns {string} Returns the camel cased string.
14091 * @example
14092 *
14093 * _.camelCase('Foo Bar');
14094 * // => 'fooBar'
14095 *
14096 * _.camelCase('--foo-bar--');
14097 * // => 'fooBar'
14098 *
14099 * _.camelCase('__FOO_BAR__');
14100 * // => 'fooBar'
14101 */
14102 var camelCase = createCompounder(function(result, word, index) {
14103 word = word.toLowerCase();
14104 return result + (index ? capitalize(word) : word);
14105 });
14106
14107 /**
14108 * Converts the first character of `string` to upper case and the remaining
14109 * to lower case.
14110 *
14111 * @static
14112 * @memberOf _
14113 * @since 3.0.0
14114 * @category String
14115 * @param {string} [string=''] The string to capitalize.
14116 * @returns {string} Returns the capitalized string.
14117 * @example
14118 *
14119 * _.capitalize('FRED');
14120 * // => 'Fred'
14121 */
14122 function capitalize(string) {
14123 return upperFirst(toString(string).toLowerCase());
14124 }
14125
14126 /**
14127 * Deburrs `string` by converting
14128 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
14129 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
14130 * letters to basic Latin letters and removing
14131 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
14132 *
14133 * @static
14134 * @memberOf _
14135 * @since 3.0.0
14136 * @category String
14137 * @param {string} [string=''] The string to deburr.
14138 * @returns {string} Returns the deburred string.
14139 * @example
14140 *
14141 * _.deburr('déjà vu');
14142 * // => 'deja vu'
14143 */
14144 function deburr(string) {
14145 string = toString(string);
14146 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
14147 }
14148
14149 /**
14150 * Checks if `string` ends with the given target string.
14151 *
14152 * @static
14153 * @memberOf _
14154 * @since 3.0.0
14155 * @category String
14156 * @param {string} [string=''] The string to inspect.
14157 * @param {string} [target] The string to search for.
14158 * @param {number} [position=string.length] The position to search up to.
14159 * @returns {boolean} Returns `true` if `string` ends with `target`,
14160 * else `false`.
14161 * @example
14162 *
14163 * _.endsWith('abc', 'c');
14164 * // => true
14165 *
14166 * _.endsWith('abc', 'b');
14167 * // => false
14168 *
14169 * _.endsWith('abc', 'b', 2);
14170 * // => true
14171 */
14172 function endsWith(string, target, position) {
14173 string = toString(string);
14174 target = baseToString(target);
14175
14176 var length = string.length;
14177 position = position === undefined
14178 ? length
14179 : baseClamp(toInteger(position), 0, length);
14180
14181 var end = position;
14182 position -= target.length;
14183 return position >= 0 && string.slice(position, end) == target;
14184 }
14185
14186 /**
14187 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
14188 * corresponding HTML entities.
14189 *
14190 * **Note:** No other characters are escaped. To escape additional
14191 * characters use a third-party library like [_he_](https://mths.be/he).
14192 *
14193 * Though the ">" character is escaped for symmetry, characters like
14194 * ">" and "/" don't need escaping in HTML and have no special meaning
14195 * unless they're part of a tag or unquoted attribute value. See
14196 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
14197 * (under "semi-related fun fact") for more details.
14198 *
14199 * When working with HTML you should always
14200 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
14201 * XSS vectors.
14202 *
14203 * @static
14204 * @since 0.1.0
14205 * @memberOf _
14206 * @category String
14207 * @param {string} [string=''] The string to escape.
14208 * @returns {string} Returns the escaped string.
14209 * @example
14210 *
14211 * _.escape('fred, barney, & pebbles');
14212 * // => 'fred, barney, &amp; pebbles'
14213 */
14214 function escape(string) {
14215 string = toString(string);
14216 return (string && reHasUnescapedHtml.test(string))
14217 ? string.replace(reUnescapedHtml, escapeHtmlChar)
14218 : string;
14219 }
14220
14221 /**
14222 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
14223 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
14224 *
14225 * @static
14226 * @memberOf _
14227 * @since 3.0.0
14228 * @category String
14229 * @param {string} [string=''] The string to escape.
14230 * @returns {string} Returns the escaped string.
14231 * @example
14232 *
14233 * _.escapeRegExp('[lodash](https://lodash.com/)');
14234 * // => '\[lodash\]\(https://lodash\.com/\)'
14235 */
14236 function escapeRegExp(string) {
14237 string = toString(string);
14238 return (string && reHasRegExpChar.test(string))
14239 ? string.replace(reRegExpChar, '\\$&')
14240 : string;
14241 }
14242
14243 /**
14244 * Converts `string` to
14245 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
14246 *
14247 * @static
14248 * @memberOf _
14249 * @since 3.0.0
14250 * @category String
14251 * @param {string} [string=''] The string to convert.
14252 * @returns {string} Returns the kebab cased string.
14253 * @example
14254 *
14255 * _.kebabCase('Foo Bar');
14256 * // => 'foo-bar'
14257 *
14258 * _.kebabCase('fooBar');
14259 * // => 'foo-bar'
14260 *
14261 * _.kebabCase('__FOO_BAR__');
14262 * // => 'foo-bar'
14263 */
14264 var kebabCase = createCompounder(function(result, word, index) {
14265 return result + (index ? '-' : '') + word.toLowerCase();
14266 });
14267
14268 /**
14269 * Converts `string`, as space separated words, to lower case.
14270 *
14271 * @static
14272 * @memberOf _
14273 * @since 4.0.0
14274 * @category String
14275 * @param {string} [string=''] The string to convert.
14276 * @returns {string} Returns the lower cased string.
14277 * @example
14278 *
14279 * _.lowerCase('--Foo-Bar--');
14280 * // => 'foo bar'
14281 *
14282 * _.lowerCase('fooBar');
14283 * // => 'foo bar'
14284 *
14285 * _.lowerCase('__FOO_BAR__');
14286 * // => 'foo bar'
14287 */
14288 var lowerCase = createCompounder(function(result, word, index) {
14289 return result + (index ? ' ' : '') + word.toLowerCase();
14290 });
14291
14292 /**
14293 * Converts the first character of `string` to lower case.
14294 *
14295 * @static
14296 * @memberOf _
14297 * @since 4.0.0
14298 * @category String
14299 * @param {string} [string=''] The string to convert.
14300 * @returns {string} Returns the converted string.
14301 * @example
14302 *
14303 * _.lowerFirst('Fred');
14304 * // => 'fred'
14305 *
14306 * _.lowerFirst('FRED');
14307 * // => 'fRED'
14308 */
14309 var lowerFirst = createCaseFirst('toLowerCase');
14310
14311 /**
14312 * Pads `string` on the left and right sides if it's shorter than `length`.
14313 * Padding characters are truncated if they can't be evenly divided by `length`.
14314 *
14315 * @static
14316 * @memberOf _
14317 * @since 3.0.0
14318 * @category String
14319 * @param {string} [string=''] The string to pad.
14320 * @param {number} [length=0] The padding length.
14321 * @param {string} [chars=' '] The string used as padding.
14322 * @returns {string} Returns the padded string.
14323 * @example
14324 *
14325 * _.pad('abc', 8);
14326 * // => ' abc '
14327 *
14328 * _.pad('abc', 8, '_-');
14329 * // => '_-abc_-_'
14330 *
14331 * _.pad('abc', 3);
14332 * // => 'abc'
14333 */
14334 function pad(string, length, chars) {
14335 string = toString(string);
14336 length = toInteger(length);
14337
14338 var strLength = length ? stringSize(string) : 0;
14339 if (!length || strLength >= length) {
14340 return string;
14341 }
14342 var mid = (length - strLength) / 2;
14343 return (
14344 createPadding(nativeFloor(mid), chars) +
14345 string +
14346 createPadding(nativeCeil(mid), chars)
14347 );
14348 }
14349
14350 /**
14351 * Pads `string` on the right side if it's shorter than `length`. Padding
14352 * characters are truncated if they exceed `length`.
14353 *
14354 * @static
14355 * @memberOf _
14356 * @since 4.0.0
14357 * @category String
14358 * @param {string} [string=''] The string to pad.
14359 * @param {number} [length=0] The padding length.
14360 * @param {string} [chars=' '] The string used as padding.
14361 * @returns {string} Returns the padded string.
14362 * @example
14363 *
14364 * _.padEnd('abc', 6);
14365 * // => 'abc '
14366 *
14367 * _.padEnd('abc', 6, '_-');
14368 * // => 'abc_-_'
14369 *
14370 * _.padEnd('abc', 3);
14371 * // => 'abc'
14372 */
14373 function padEnd(string, length, chars) {
14374 string = toString(string);
14375 length = toInteger(length);
14376
14377 var strLength = length ? stringSize(string) : 0;
14378 return (length && strLength < length)
14379 ? (string + createPadding(length - strLength, chars))
14380 : string;
14381 }
14382
14383 /**
14384 * Pads `string` on the left side if it's shorter than `length`. Padding
14385 * characters are truncated if they exceed `length`.
14386 *
14387 * @static
14388 * @memberOf _
14389 * @since 4.0.0
14390 * @category String
14391 * @param {string} [string=''] The string to pad.
14392 * @param {number} [length=0] The padding length.
14393 * @param {string} [chars=' '] The string used as padding.
14394 * @returns {string} Returns the padded string.
14395 * @example
14396 *
14397 * _.padStart('abc', 6);
14398 * // => ' abc'
14399 *
14400 * _.padStart('abc', 6, '_-');
14401 * // => '_-_abc'
14402 *
14403 * _.padStart('abc', 3);
14404 * // => 'abc'
14405 */
14406 function padStart(string, length, chars) {
14407 string = toString(string);
14408 length = toInteger(length);
14409
14410 var strLength = length ? stringSize(string) : 0;
14411 return (length && strLength < length)
14412 ? (createPadding(length - strLength, chars) + string)
14413 : string;
14414 }
14415
14416 /**
14417 * Converts `string` to an integer of the specified radix. If `radix` is
14418 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
14419 * hexadecimal, in which case a `radix` of `16` is used.
14420 *
14421 * **Note:** This method aligns with the
14422 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
14423 *
14424 * @static
14425 * @memberOf _
14426 * @since 1.1.0
14427 * @category String
14428 * @param {string} string The string to convert.
14429 * @param {number} [radix=10] The radix to interpret `value` by.
14430 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14431 * @returns {number} Returns the converted integer.
14432 * @example
14433 *
14434 * _.parseInt('08');
14435 * // => 8
14436 *
14437 * _.map(['6', '08', '10'], _.parseInt);
14438 * // => [6, 8, 10]
14439 */
14440 function parseInt(string, radix, guard) {
14441 if (guard || radix == null) {
14442 radix = 0;
14443 } else if (radix) {
14444 radix = +radix;
14445 }
14446 return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
14447 }
14448
14449 /**
14450 * Repeats the given string `n` times.
14451 *
14452 * @static
14453 * @memberOf _
14454 * @since 3.0.0
14455 * @category String
14456 * @param {string} [string=''] The string to repeat.
14457 * @param {number} [n=1] The number of times to repeat the string.
14458 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14459 * @returns {string} Returns the repeated string.
14460 * @example
14461 *
14462 * _.repeat('*', 3);
14463 * // => '***'
14464 *
14465 * _.repeat('abc', 2);
14466 * // => 'abcabc'
14467 *
14468 * _.repeat('abc', 0);
14469 * // => ''
14470 */
14471 function repeat(string, n, guard) {
14472 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
14473 n = 1;
14474 } else {
14475 n = toInteger(n);
14476 }
14477 return baseRepeat(toString(string), n);
14478 }
14479
14480 /**
14481 * Replaces matches for `pattern` in `string` with `replacement`.
14482 *
14483 * **Note:** This method is based on
14484 * [`String#replace`](https://mdn.io/String/replace).
14485 *
14486 * @static
14487 * @memberOf _
14488 * @since 4.0.0
14489 * @category String
14490 * @param {string} [string=''] The string to modify.
14491 * @param {RegExp|string} pattern The pattern to replace.
14492 * @param {Function|string} replacement The match replacement.
14493 * @returns {string} Returns the modified string.
14494 * @example
14495 *
14496 * _.replace('Hi Fred', 'Fred', 'Barney');
14497 * // => 'Hi Barney'
14498 */
14499 function replace() {
14500 var args = arguments,
14501 string = toString(args[0]);
14502
14503 return args.length < 3 ? string : string.replace(args[1], args[2]);
14504 }
14505
14506 /**
14507 * Converts `string` to
14508 * [snake case](https://en.wikipedia.org/wiki/Snake_case).
14509 *
14510 * @static
14511 * @memberOf _
14512 * @since 3.0.0
14513 * @category String
14514 * @param {string} [string=''] The string to convert.
14515 * @returns {string} Returns the snake cased string.
14516 * @example
14517 *
14518 * _.snakeCase('Foo Bar');
14519 * // => 'foo_bar'
14520 *
14521 * _.snakeCase('fooBar');
14522 * // => 'foo_bar'
14523 *
14524 * _.snakeCase('--FOO-BAR--');
14525 * // => 'foo_bar'
14526 */
14527 var snakeCase = createCompounder(function(result, word, index) {
14528 return result + (index ? '_' : '') + word.toLowerCase();
14529 });
14530
14531 /**
14532 * Splits `string` by `separator`.
14533 *
14534 * **Note:** This method is based on
14535 * [`String#split`](https://mdn.io/String/split).
14536 *
14537 * @static
14538 * @memberOf _
14539 * @since 4.0.0
14540 * @category String
14541 * @param {string} [string=''] The string to split.
14542 * @param {RegExp|string} separator The separator pattern to split by.
14543 * @param {number} [limit] The length to truncate results to.
14544 * @returns {Array} Returns the string segments.
14545 * @example
14546 *
14547 * _.split('a-b-c', '-', 2);
14548 * // => ['a', 'b']
14549 */
14550 function split(string, separator, limit) {
14551 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
14552 separator = limit = undefined;
14553 }
14554 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
14555 if (!limit) {
14556 return [];
14557 }
14558 string = toString(string);
14559 if (string && (
14560 typeof separator == 'string' ||
14561 (separator != null && !isRegExp(separator))
14562 )) {
14563 separator = baseToString(separator);
14564 if (!separator && hasUnicode(string)) {
14565 return castSlice(stringToArray(string), 0, limit);
14566 }
14567 }
14568 return string.split(separator, limit);
14569 }
14570
14571 /**
14572 * Converts `string` to
14573 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
14574 *
14575 * @static
14576 * @memberOf _
14577 * @since 3.1.0
14578 * @category String
14579 * @param {string} [string=''] The string to convert.
14580 * @returns {string} Returns the start cased string.
14581 * @example
14582 *
14583 * _.startCase('--foo-bar--');
14584 * // => 'Foo Bar'
14585 *
14586 * _.startCase('fooBar');
14587 * // => 'Foo Bar'
14588 *
14589 * _.startCase('__FOO_BAR__');
14590 * // => 'FOO BAR'
14591 */
14592 var startCase = createCompounder(function(result, word, index) {
14593 return result + (index ? ' ' : '') + upperFirst(word);
14594 });
14595
14596 /**
14597 * Checks if `string` starts with the given target string.
14598 *
14599 * @static
14600 * @memberOf _
14601 * @since 3.0.0
14602 * @category String
14603 * @param {string} [string=''] The string to inspect.
14604 * @param {string} [target] The string to search for.
14605 * @param {number} [position=0] The position to search from.
14606 * @returns {boolean} Returns `true` if `string` starts with `target`,
14607 * else `false`.
14608 * @example
14609 *
14610 * _.startsWith('abc', 'a');
14611 * // => true
14612 *
14613 * _.startsWith('abc', 'b');
14614 * // => false
14615 *
14616 * _.startsWith('abc', 'b', 1);
14617 * // => true
14618 */
14619 function startsWith(string, target, position) {
14620 string = toString(string);
14621 position = baseClamp(toInteger(position), 0, string.length);
14622 target = baseToString(target);
14623 return string.slice(position, position + target.length) == target;
14624 }
14625
14626 /**
14627 * Creates a compiled template function that can interpolate data properties
14628 * in "interpolate" delimiters, HTML-escape interpolated data properties in
14629 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
14630 * properties may be accessed as free variables in the template. If a setting
14631 * object is given, it takes precedence over `_.templateSettings` values.
14632 *
14633 * **Note:** In the development build `_.template` utilizes
14634 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
14635 * for easier debugging.
14636 *
14637 * For more information on precompiling templates see
14638 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
14639 *
14640 * For more information on Chrome extension sandboxes see
14641 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
14642 *
14643 * @static
14644 * @since 0.1.0
14645 * @memberOf _
14646 * @category String
14647 * @param {string} [string=''] The template string.
14648 * @param {Object} [options={}] The options object.
14649 * @param {RegExp} [options.escape=_.templateSettings.escape]
14650 * The HTML "escape" delimiter.
14651 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
14652 * The "evaluate" delimiter.
14653 * @param {Object} [options.imports=_.templateSettings.imports]
14654 * An object to import into the template as free variables.
14655 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
14656 * The "interpolate" delimiter.
14657 * @param {string} [options.sourceURL='lodash.templateSources[n]']
14658 * The sourceURL of the compiled template.
14659 * @param {string} [options.variable='obj']
14660 * The data object variable name.
14661 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14662 * @returns {Function} Returns the compiled template function.
14663 * @example
14664 *
14665 * // Use the "interpolate" delimiter to create a compiled template.
14666 * var compiled = _.template('hello <%= user %>!');
14667 * compiled({ 'user': 'fred' });
14668 * // => 'hello fred!'
14669 *
14670 * // Use the HTML "escape" delimiter to escape data property values.
14671 * var compiled = _.template('<b><%- value %></b>');
14672 * compiled({ 'value': '<script>' });
14673 * // => '<b>&lt;script&gt;</b>'
14674 *
14675 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
14676 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
14677 * compiled({ 'users': ['fred', 'barney'] });
14678 * // => '<li>fred</li><li>barney</li>'
14679 *
14680 * // Use the internal `print` function in "evaluate" delimiters.
14681 * var compiled = _.template('<% print("hello " + user); %>!');
14682 * compiled({ 'user': 'barney' });
14683 * // => 'hello barney!'
14684 *
14685 * // Use the ES template literal delimiter as an "interpolate" delimiter.
14686 * // Disable support by replacing the "interpolate" delimiter.
14687 * var compiled = _.template('hello ${ user }!');
14688 * compiled({ 'user': 'pebbles' });
14689 * // => 'hello pebbles!'
14690 *
14691 * // Use backslashes to treat delimiters as plain text.
14692 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
14693 * compiled({ 'value': 'ignored' });
14694 * // => '<%- value %>'
14695 *
14696 * // Use the `imports` option to import `jQuery` as `jq`.
14697 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
14698 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
14699 * compiled({ 'users': ['fred', 'barney'] });
14700 * // => '<li>fred</li><li>barney</li>'
14701 *
14702 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
14703 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
14704 * compiled(data);
14705 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
14706 *
14707 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
14708 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
14709 * compiled.source;
14710 * // => function(data) {
14711 * // var __t, __p = '';
14712 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
14713 * // return __p;
14714 * // }
14715 *
14716 * // Use custom template delimiters.
14717 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
14718 * var compiled = _.template('hello {{ user }}!');
14719 * compiled({ 'user': 'mustache' });
14720 * // => 'hello mustache!'
14721 *
14722 * // Use the `source` property to inline compiled templates for meaningful
14723 * // line numbers in error messages and stack traces.
14724 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
14725 * var JST = {\
14726 * "main": ' + _.template(mainText).source + '\
14727 * };\
14728 * ');
14729 */
14730 function template(string, options, guard) {
14731 // Based on John Resig's `tmpl` implementation
14732 // (http://ejohn.org/blog/javascript-micro-templating/)
14733 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
14734 var settings = lodash.templateSettings;
14735
14736 if (guard && isIterateeCall(string, options, guard)) {
14737 options = undefined;
14738 }
14739 string = toString(string);
14740 options = assignInWith({}, options, settings, assignInDefaults);
14741
14742 var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
14743 importsKeys = keys(imports),
14744 importsValues = baseValues(imports, importsKeys);
14745
14746 var isEscaping,
14747 isEvaluating,
14748 index = 0,
14749 interpolate = options.interpolate || reNoMatch,
14750 source = "__p += '";
14751
14752 // Compile the regexp to match each delimiter.
14753 var reDelimiters = RegExp(
14754 (options.escape || reNoMatch).source + '|' +
14755 interpolate.source + '|' +
14756 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
14757 (options.evaluate || reNoMatch).source + '|$'
14758 , 'g');
14759
14760 // Use a sourceURL for easier debugging.
14761 var sourceURL = '//# sourceURL=' +
14762 ('sourceURL' in options
14763 ? options.sourceURL
14764 : ('lodash.templateSources[' + (++templateCounter) + ']')
14765 ) + '\n';
14766
14767 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
14768 interpolateValue || (interpolateValue = esTemplateValue);
14769
14770 // Escape characters that can't be included in string literals.
14771 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
14772
14773 // Replace delimiters with snippets.
14774 if (escapeValue) {
14775 isEscaping = true;
14776 source += "' +\n__e(" + escapeValue + ") +\n'";
14777 }
14778 if (evaluateValue) {
14779 isEvaluating = true;
14780 source += "';\n" + evaluateValue + ";\n__p += '";
14781 }
14782 if (interpolateValue) {
14783 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
14784 }
14785 index = offset + match.length;
14786
14787 // The JS engine embedded in Adobe products needs `match` returned in
14788 // order to produce the correct `offset` value.
14789 return match;
14790 });
14791
14792 source += "';\n";
14793
14794 // If `variable` is not specified wrap a with-statement around the generated
14795 // code to add the data object to the top of the scope chain.
14796 var variable = options.variable;
14797 if (!variable) {
14798 source = 'with (obj) {\n' + source + '\n}\n';
14799 }
14800 // Cleanup code by stripping empty strings.
14801 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
14802 .replace(reEmptyStringMiddle, '$1')
14803 .replace(reEmptyStringTrailing, '$1;');
14804
14805 // Frame code as the function body.
14806 source = 'function(' + (variable || 'obj') + ') {\n' +
14807 (variable
14808 ? ''
14809 : 'obj || (obj = {});\n'
14810 ) +
14811 "var __t, __p = ''" +
14812 (isEscaping
14813 ? ', __e = _.escape'
14814 : ''
14815 ) +
14816 (isEvaluating
14817 ? ', __j = Array.prototype.join;\n' +
14818 "function print() { __p += __j.call(arguments, '') }\n"
14819 : ';\n'
14820 ) +
14821 source +
14822 'return __p\n}';
14823
14824 var result = attempt(function() {
14825 return Function(importsKeys, sourceURL + 'return ' + source)
14826 .apply(undefined, importsValues);
14827 });
14828
14829 // Provide the compiled function's source by its `toString` method or
14830 // the `source` property as a convenience for inlining compiled templates.
14831 result.source = source;
14832 if (isError(result)) {
14833 throw result;
14834 }
14835 return result;
14836 }
14837
14838 /**
14839 * Converts `string`, as a whole, to lower case just like
14840 * [String#toLowerCase](https://mdn.io/toLowerCase).
14841 *
14842 * @static
14843 * @memberOf _
14844 * @since 4.0.0
14845 * @category String
14846 * @param {string} [string=''] The string to convert.
14847 * @returns {string} Returns the lower cased string.
14848 * @example
14849 *
14850 * _.toLower('--Foo-Bar--');
14851 * // => '--foo-bar--'
14852 *
14853 * _.toLower('fooBar');
14854 * // => 'foobar'
14855 *
14856 * _.toLower('__FOO_BAR__');
14857 * // => '__foo_bar__'
14858 */
14859 function toLower(value) {
14860 return toString(value).toLowerCase();
14861 }
14862
14863 /**
14864 * Converts `string`, as a whole, to upper case just like
14865 * [String#toUpperCase](https://mdn.io/toUpperCase).
14866 *
14867 * @static
14868 * @memberOf _
14869 * @since 4.0.0
14870 * @category String
14871 * @param {string} [string=''] The string to convert.
14872 * @returns {string} Returns the upper cased string.
14873 * @example
14874 *
14875 * _.toUpper('--foo-bar--');
14876 * // => '--FOO-BAR--'
14877 *
14878 * _.toUpper('fooBar');
14879 * // => 'FOOBAR'
14880 *
14881 * _.toUpper('__foo_bar__');
14882 * // => '__FOO_BAR__'
14883 */
14884 function toUpper(value) {
14885 return toString(value).toUpperCase();
14886 }
14887
14888 /**
14889 * Removes leading and trailing whitespace or specified characters from `string`.
14890 *
14891 * @static
14892 * @memberOf _
14893 * @since 3.0.0
14894 * @category String
14895 * @param {string} [string=''] The string to trim.
14896 * @param {string} [chars=whitespace] The characters to trim.
14897 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14898 * @returns {string} Returns the trimmed string.
14899 * @example
14900 *
14901 * _.trim(' abc ');
14902 * // => 'abc'
14903 *
14904 * _.trim('-_-abc-_-', '_-');
14905 * // => 'abc'
14906 *
14907 * _.map([' foo ', ' bar '], _.trim);
14908 * // => ['foo', 'bar']
14909 */
14910 function trim(string, chars, guard) {
14911 string = toString(string);
14912 if (string && (guard || chars === undefined)) {
14913 return string.replace(reTrim, '');
14914 }
14915 if (!string || !(chars = baseToString(chars))) {
14916 return string;
14917 }
14918 var strSymbols = stringToArray(string),
14919 chrSymbols = stringToArray(chars),
14920 start = charsStartIndex(strSymbols, chrSymbols),
14921 end = charsEndIndex(strSymbols, chrSymbols) + 1;
14922
14923 return castSlice(strSymbols, start, end).join('');
14924 }
14925
14926 /**
14927 * Removes trailing whitespace or specified characters from `string`.
14928 *
14929 * @static
14930 * @memberOf _
14931 * @since 4.0.0
14932 * @category String
14933 * @param {string} [string=''] The string to trim.
14934 * @param {string} [chars=whitespace] The characters to trim.
14935 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14936 * @returns {string} Returns the trimmed string.
14937 * @example
14938 *
14939 * _.trimEnd(' abc ');
14940 * // => ' abc'
14941 *
14942 * _.trimEnd('-_-abc-_-', '_-');
14943 * // => '-_-abc'
14944 */
14945 function trimEnd(string, chars, guard) {
14946 string = toString(string);
14947 if (string && (guard || chars === undefined)) {
14948 return string.replace(reTrimEnd, '');
14949 }
14950 if (!string || !(chars = baseToString(chars))) {
14951 return string;
14952 }
14953 var strSymbols = stringToArray(string),
14954 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
14955
14956 return castSlice(strSymbols, 0, end).join('');
14957 }
14958
14959 /**
14960 * Removes leading whitespace or specified characters from `string`.
14961 *
14962 * @static
14963 * @memberOf _
14964 * @since 4.0.0
14965 * @category String
14966 * @param {string} [string=''] The string to trim.
14967 * @param {string} [chars=whitespace] The characters to trim.
14968 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14969 * @returns {string} Returns the trimmed string.
14970 * @example
14971 *
14972 * _.trimStart(' abc ');
14973 * // => 'abc '
14974 *
14975 * _.trimStart('-_-abc-_-', '_-');
14976 * // => 'abc-_-'
14977 */
14978 function trimStart(string, chars, guard) {
14979 string = toString(string);
14980 if (string && (guard || chars === undefined)) {
14981 return string.replace(reTrimStart, '');
14982 }
14983 if (!string || !(chars = baseToString(chars))) {
14984 return string;
14985 }
14986 var strSymbols = stringToArray(string),
14987 start = charsStartIndex(strSymbols, stringToArray(chars));
14988
14989 return castSlice(strSymbols, start).join('');
14990 }
14991
14992 /**
14993 * Truncates `string` if it's longer than the given maximum string length.
14994 * The last characters of the truncated string are replaced with the omission
14995 * string which defaults to "...".
14996 *
14997 * @static
14998 * @memberOf _
14999 * @since 4.0.0
15000 * @category String
15001 * @param {string} [string=''] The string to truncate.
15002 * @param {Object} [options={}] The options object.
15003 * @param {number} [options.length=30] The maximum string length.
15004 * @param {string} [options.omission='...'] The string to indicate text is omitted.
15005 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
15006 * @returns {string} Returns the truncated string.
15007 * @example
15008 *
15009 * _.truncate('hi-diddly-ho there, neighborino');
15010 * // => 'hi-diddly-ho there, neighbo...'
15011 *
15012 * _.truncate('hi-diddly-ho there, neighborino', {
15013 * 'length': 24,
15014 * 'separator': ' '
15015 * });
15016 * // => 'hi-diddly-ho there,...'
15017 *
15018 * _.truncate('hi-diddly-ho there, neighborino', {
15019 * 'length': 24,
15020 * 'separator': /,? +/
15021 * });
15022 * // => 'hi-diddly-ho there...'
15023 *
15024 * _.truncate('hi-diddly-ho there, neighborino', {
15025 * 'omission': ' [...]'
15026 * });
15027 * // => 'hi-diddly-ho there, neig [...]'
15028 */
15029 function truncate(string, options) {
15030 var length = DEFAULT_TRUNC_LENGTH,
15031 omission = DEFAULT_TRUNC_OMISSION;
15032
15033 if (isObject(options)) {
15034 var separator = 'separator' in options ? options.separator : separator;
15035 length = 'length' in options ? toInteger(options.length) : length;
15036 omission = 'omission' in options ? baseToString(options.omission) : omission;
15037 }
15038 string = toString(string);
15039
15040 var strLength = string.length;
15041 if (hasUnicode(string)) {
15042 var strSymbols = stringToArray(string);
15043 strLength = strSymbols.length;
15044 }
15045 if (length >= strLength) {
15046 return string;
15047 }
15048 var end = length - stringSize(omission);
15049 if (end < 1) {
15050 return omission;
15051 }
15052 var result = strSymbols
15053 ? castSlice(strSymbols, 0, end).join('')
15054 : string.slice(0, end);
15055
15056 if (separator === undefined) {
15057 return result + omission;
15058 }
15059 if (strSymbols) {
15060 end += (result.length - end);
15061 }
15062 if (isRegExp(separator)) {
15063 if (string.slice(end).search(separator)) {
15064 var match,
15065 substring = result;
15066
15067 if (!separator.global) {
15068 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
15069 }
15070 separator.lastIndex = 0;
15071 while ((match = separator.exec(substring))) {
15072 var newEnd = match.index;
15073 }
15074 result = result.slice(0, newEnd === undefined ? end : newEnd);
15075 }
15076 } else if (string.indexOf(baseToString(separator), end) != end) {
15077 var index = result.lastIndexOf(separator);
15078 if (index > -1) {
15079 result = result.slice(0, index);
15080 }
15081 }
15082 return result + omission;
15083 }
15084
15085 /**
15086 * The inverse of `_.escape`; this method converts the HTML entities
15087 * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
15088 * their corresponding characters.
15089 *
15090 * **Note:** No other HTML entities are unescaped. To unescape additional
15091 * HTML entities use a third-party library like [_he_](https://mths.be/he).
15092 *
15093 * @static
15094 * @memberOf _
15095 * @since 0.6.0
15096 * @category String
15097 * @param {string} [string=''] The string to unescape.
15098 * @returns {string} Returns the unescaped string.
15099 * @example
15100 *
15101 * _.unescape('fred, barney, &amp; pebbles');
15102 * // => 'fred, barney, & pebbles'
15103 */
15104 function unescape(string) {
15105 string = toString(string);
15106 return (string && reHasEscapedHtml.test(string))
15107 ? string.replace(reEscapedHtml, unescapeHtmlChar)
15108 : string;
15109 }
15110
15111 /**
15112 * Converts `string`, as space separated words, to upper case.
15113 *
15114 * @static
15115 * @memberOf _
15116 * @since 4.0.0
15117 * @category String
15118 * @param {string} [string=''] The string to convert.
15119 * @returns {string} Returns the upper cased string.
15120 * @example
15121 *
15122 * _.upperCase('--foo-bar');
15123 * // => 'FOO BAR'
15124 *
15125 * _.upperCase('fooBar');
15126 * // => 'FOO BAR'
15127 *
15128 * _.upperCase('__foo_bar__');
15129 * // => 'FOO BAR'
15130 */
15131 var upperCase = createCompounder(function(result, word, index) {
15132 return result + (index ? ' ' : '') + word.toUpperCase();
15133 });
15134
15135 /**
15136 * Converts the first character of `string` to upper case.
15137 *
15138 * @static
15139 * @memberOf _
15140 * @since 4.0.0
15141 * @category String
15142 * @param {string} [string=''] The string to convert.
15143 * @returns {string} Returns the converted string.
15144 * @example
15145 *
15146 * _.upperFirst('fred');
15147 * // => 'Fred'
15148 *
15149 * _.upperFirst('FRED');
15150 * // => 'FRED'
15151 */
15152 var upperFirst = createCaseFirst('toUpperCase');
15153
15154 /**
15155 * Splits `string` into an array of its words.
15156 *
15157 * @static
15158 * @memberOf _
15159 * @since 3.0.0
15160 * @category String
15161 * @param {string} [string=''] The string to inspect.
15162 * @param {RegExp|string} [pattern] The pattern to match words.
15163 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15164 * @returns {Array} Returns the words of `string`.
15165 * @example
15166 *
15167 * _.words('fred, barney, & pebbles');
15168 * // => ['fred', 'barney', 'pebbles']
15169 *
15170 * _.words('fred, barney, & pebbles', /[^, ]+/g);
15171 * // => ['fred', 'barney', '&', 'pebbles']
15172 */
15173 function words(string, pattern, guard) {
15174 string = toString(string);
15175 pattern = guard ? undefined : pattern;
15176
15177 if (pattern === undefined) {
15178 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
15179 }
15180 return string.match(pattern) || [];
15181 }
15182
15183 /*------------------------------------------------------------------------*/
15184
15185 /**
15186 * Attempts to invoke `func`, returning either the result or the caught error
15187 * object. Any additional arguments are provided to `func` when it's invoked.
15188 *
15189 * @static
15190 * @memberOf _
15191 * @since 3.0.0
15192 * @category Util
15193 * @param {Function} func The function to attempt.
15194 * @param {...*} [args] The arguments to invoke `func` with.
15195 * @returns {*} Returns the `func` result or error object.
15196 * @example
15197 *
15198 * // Avoid throwing errors for invalid selectors.
15199 * var elements = _.attempt(function(selector) {
15200 * return document.querySelectorAll(selector);
15201 * }, '>_>');
15202 *
15203 * if (_.isError(elements)) {
15204 * elements = [];
15205 * }
15206 */
15207 var attempt = baseRest(function(func, args) {
15208 try {
15209 return apply(func, undefined, args);
15210 } catch (e) {
15211 return isError(e) ? e : new Error(e);
15212 }
15213 });
15214
15215 /**
15216 * Binds methods of an object to the object itself, overwriting the existing
15217 * method.
15218 *
15219 * **Note:** This method doesn't set the "length" property of bound functions.
15220 *
15221 * @static
15222 * @since 0.1.0
15223 * @memberOf _
15224 * @category Util
15225 * @param {Object} object The object to bind and assign the bound methods to.
15226 * @param {...(string|string[])} methodNames The object method names to bind.
15227 * @returns {Object} Returns `object`.
15228 * @example
15229 *
15230 * var view = {
15231 * 'label': 'docs',
15232 * 'click': function() {
15233 * console.log('clicked ' + this.label);
15234 * }
15235 * };
15236 *
15237 * _.bindAll(view, ['click']);
15238 * jQuery(element).on('click', view.click);
15239 * // => Logs 'clicked docs' when clicked.
15240 */
15241 var bindAll = flatRest(function(object, methodNames) {
15242 arrayEach(methodNames, function(key) {
15243 key = toKey(key);
15244 baseAssignValue(object, key, bind(object[key], object));
15245 });
15246 return object;
15247 });
15248
15249 /**
15250 * Creates a function that iterates over `pairs` and invokes the corresponding
15251 * function of the first predicate to return truthy. The predicate-function
15252 * pairs are invoked with the `this` binding and arguments of the created
15253 * function.
15254 *
15255 * @static
15256 * @memberOf _
15257 * @since 4.0.0
15258 * @category Util
15259 * @param {Array} pairs The predicate-function pairs.
15260 * @returns {Function} Returns the new composite function.
15261 * @example
15262 *
15263 * var func = _.cond([
15264 * [_.matches({ 'a': 1 }), _.constant('matches A')],
15265 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
15266 * [_.stubTrue, _.constant('no match')]
15267 * ]);
15268 *
15269 * func({ 'a': 1, 'b': 2 });
15270 * // => 'matches A'
15271 *
15272 * func({ 'a': 0, 'b': 1 });
15273 * // => 'matches B'
15274 *
15275 * func({ 'a': '1', 'b': '2' });
15276 * // => 'no match'
15277 */
15278 function cond(pairs) {
15279 var length = pairs == null ? 0 : pairs.length,
15280 toIteratee = getIteratee();
15281
15282 pairs = !length ? [] : arrayMap(pairs, function(pair) {
15283 if (typeof pair[1] != 'function') {
15284 throw new TypeError(FUNC_ERROR_TEXT);
15285 }
15286 return [toIteratee(pair[0]), pair[1]];
15287 });
15288
15289 return baseRest(function(args) {
15290 var index = -1;
15291 while (++index < length) {
15292 var pair = pairs[index];
15293 if (apply(pair[0], this, args)) {
15294 return apply(pair[1], this, args);
15295 }
15296 }
15297 });
15298 }
15299
15300 /**
15301 * Creates a function that invokes the predicate properties of `source` with
15302 * the corresponding property values of a given object, returning `true` if
15303 * all predicates return truthy, else `false`.
15304 *
15305 * **Note:** The created function is equivalent to `_.conformsTo` with
15306 * `source` partially applied.
15307 *
15308 * @static
15309 * @memberOf _
15310 * @since 4.0.0
15311 * @category Util
15312 * @param {Object} source The object of property predicates to conform to.
15313 * @returns {Function} Returns the new spec function.
15314 * @example
15315 *
15316 * var objects = [
15317 * { 'a': 2, 'b': 1 },
15318 * { 'a': 1, 'b': 2 }
15319 * ];
15320 *
15321 * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
15322 * // => [{ 'a': 1, 'b': 2 }]
15323 */
15324 function conforms(source) {
15325 return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
15326 }
15327
15328 /**
15329 * Creates a function that returns `value`.
15330 *
15331 * @static
15332 * @memberOf _
15333 * @since 2.4.0
15334 * @category Util
15335 * @param {*} value The value to return from the new function.
15336 * @returns {Function} Returns the new constant function.
15337 * @example
15338 *
15339 * var objects = _.times(2, _.constant({ 'a': 1 }));
15340 *
15341 * console.log(objects);
15342 * // => [{ 'a': 1 }, { 'a': 1 }]
15343 *
15344 * console.log(objects[0] === objects[1]);
15345 * // => true
15346 */
15347 function constant(value) {
15348 return function() {
15349 return value;
15350 };
15351 }
15352
15353 /**
15354 * Checks `value` to determine whether a default value should be returned in
15355 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
15356 * or `undefined`.
15357 *
15358 * @static
15359 * @memberOf _
15360 * @since 4.14.0
15361 * @category Util
15362 * @param {*} value The value to check.
15363 * @param {*} defaultValue The default value.
15364 * @returns {*} Returns the resolved value.
15365 * @example
15366 *
15367 * _.defaultTo(1, 10);
15368 * // => 1
15369 *
15370 * _.defaultTo(undefined, 10);
15371 * // => 10
15372 */
15373 function defaultTo(value, defaultValue) {
15374 return (value == null || value !== value) ? defaultValue : value;
15375 }
15376
15377 /**
15378 * Creates a function that returns the result of invoking the given functions
15379 * with the `this` binding of the created function, where each successive
15380 * invocation is supplied the return value of the previous.
15381 *
15382 * @static
15383 * @memberOf _
15384 * @since 3.0.0
15385 * @category Util
15386 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15387 * @returns {Function} Returns the new composite function.
15388 * @see _.flowRight
15389 * @example
15390 *
15391 * function square(n) {
15392 * return n * n;
15393 * }
15394 *
15395 * var addSquare = _.flow([_.add, square]);
15396 * addSquare(1, 2);
15397 * // => 9
15398 */
15399 var flow = createFlow();
15400
15401 /**
15402 * This method is like `_.flow` except that it creates a function that
15403 * invokes the given functions from right to left.
15404 *
15405 * @static
15406 * @since 3.0.0
15407 * @memberOf _
15408 * @category Util
15409 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15410 * @returns {Function} Returns the new composite function.
15411 * @see _.flow
15412 * @example
15413 *
15414 * function square(n) {
15415 * return n * n;
15416 * }
15417 *
15418 * var addSquare = _.flowRight([square, _.add]);
15419 * addSquare(1, 2);
15420 * // => 9
15421 */
15422 var flowRight = createFlow(true);
15423
15424 /**
15425 * This method returns the first argument it receives.
15426 *
15427 * @static
15428 * @since 0.1.0
15429 * @memberOf _
15430 * @category Util
15431 * @param {*} value Any value.
15432 * @returns {*} Returns `value`.
15433 * @example
15434 *
15435 * var object = { 'a': 1 };
15436 *
15437 * console.log(_.identity(object) === object);
15438 * // => true
15439 */
15440 function identity(value) {
15441 return value;
15442 }
15443
15444 /**
15445 * Creates a function that invokes `func` with the arguments of the created
15446 * function. If `func` is a property name, the created function returns the
15447 * property value for a given element. If `func` is an array or object, the
15448 * created function returns `true` for elements that contain the equivalent
15449 * source properties, otherwise it returns `false`.
15450 *
15451 * @static
15452 * @since 4.0.0
15453 * @memberOf _
15454 * @category Util
15455 * @param {*} [func=_.identity] The value to convert to a callback.
15456 * @returns {Function} Returns the callback.
15457 * @example
15458 *
15459 * var users = [
15460 * { 'user': 'barney', 'age': 36, 'active': true },
15461 * { 'user': 'fred', 'age': 40, 'active': false }
15462 * ];
15463 *
15464 * // The `_.matches` iteratee shorthand.
15465 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
15466 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
15467 *
15468 * // The `_.matchesProperty` iteratee shorthand.
15469 * _.filter(users, _.iteratee(['user', 'fred']));
15470 * // => [{ 'user': 'fred', 'age': 40 }]
15471 *
15472 * // The `_.property` iteratee shorthand.
15473 * _.map(users, _.iteratee('user'));
15474 * // => ['barney', 'fred']
15475 *
15476 * // Create custom iteratee shorthands.
15477 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
15478 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
15479 * return func.test(string);
15480 * };
15481 * });
15482 *
15483 * _.filter(['abc', 'def'], /ef/);
15484 * // => ['def']
15485 */
15486 function iteratee(func) {
15487 return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
15488 }
15489
15490 /**
15491 * Creates a function that performs a partial deep comparison between a given
15492 * object and `source`, returning `true` if the given object has equivalent
15493 * property values, else `false`.
15494 *
15495 * **Note:** The created function is equivalent to `_.isMatch` with `source`
15496 * partially applied.
15497 *
15498 * Partial comparisons will match empty array and empty object `source`
15499 * values against any array or object value, respectively. See `_.isEqual`
15500 * for a list of supported value comparisons.
15501 *
15502 * @static
15503 * @memberOf _
15504 * @since 3.0.0
15505 * @category Util
15506 * @param {Object} source The object of property values to match.
15507 * @returns {Function} Returns the new spec function.
15508 * @example
15509 *
15510 * var objects = [
15511 * { 'a': 1, 'b': 2, 'c': 3 },
15512 * { 'a': 4, 'b': 5, 'c': 6 }
15513 * ];
15514 *
15515 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
15516 * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
15517 */
15518 function matches(source) {
15519 return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
15520 }
15521
15522 /**
15523 * Creates a function that performs a partial deep comparison between the
15524 * value at `path` of a given object to `srcValue`, returning `true` if the
15525 * object value is equivalent, else `false`.
15526 *
15527 * **Note:** Partial comparisons will match empty array and empty object
15528 * `srcValue` values against any array or object value, respectively. See
15529 * `_.isEqual` for a list of supported value comparisons.
15530 *
15531 * @static
15532 * @memberOf _
15533 * @since 3.2.0
15534 * @category Util
15535 * @param {Array|string} path The path of the property to get.
15536 * @param {*} srcValue The value to match.
15537 * @returns {Function} Returns the new spec function.
15538 * @example
15539 *
15540 * var objects = [
15541 * { 'a': 1, 'b': 2, 'c': 3 },
15542 * { 'a': 4, 'b': 5, 'c': 6 }
15543 * ];
15544 *
15545 * _.find(objects, _.matchesProperty('a', 4));
15546 * // => { 'a': 4, 'b': 5, 'c': 6 }
15547 */
15548 function matchesProperty(path, srcValue) {
15549 return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
15550 }
15551
15552 /**
15553 * Creates a function that invokes the method at `path` of a given object.
15554 * Any additional arguments are provided to the invoked method.
15555 *
15556 * @static
15557 * @memberOf _
15558 * @since 3.7.0
15559 * @category Util
15560 * @param {Array|string} path The path of the method to invoke.
15561 * @param {...*} [args] The arguments to invoke the method with.
15562 * @returns {Function} Returns the new invoker function.
15563 * @example
15564 *
15565 * var objects = [
15566 * { 'a': { 'b': _.constant(2) } },
15567 * { 'a': { 'b': _.constant(1) } }
15568 * ];
15569 *
15570 * _.map(objects, _.method('a.b'));
15571 * // => [2, 1]
15572 *
15573 * _.map(objects, _.method(['a', 'b']));
15574 * // => [2, 1]
15575 */
15576 var method = baseRest(function(path, args) {
15577 return function(object) {
15578 return baseInvoke(object, path, args);
15579 };
15580 });
15581
15582 /**
15583 * The opposite of `_.method`; this method creates a function that invokes
15584 * the method at a given path of `object`. Any additional arguments are
15585 * provided to the invoked method.
15586 *
15587 * @static
15588 * @memberOf _
15589 * @since 3.7.0
15590 * @category Util
15591 * @param {Object} object The object to query.
15592 * @param {...*} [args] The arguments to invoke the method with.
15593 * @returns {Function} Returns the new invoker function.
15594 * @example
15595 *
15596 * var array = _.times(3, _.constant),
15597 * object = { 'a': array, 'b': array, 'c': array };
15598 *
15599 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
15600 * // => [2, 0]
15601 *
15602 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
15603 * // => [2, 0]
15604 */
15605 var methodOf = baseRest(function(object, args) {
15606 return function(path) {
15607 return baseInvoke(object, path, args);
15608 };
15609 });
15610
15611 /**
15612 * Adds all own enumerable string keyed function properties of a source
15613 * object to the destination object. If `object` is a function, then methods
15614 * are added to its prototype as well.
15615 *
15616 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
15617 * avoid conflicts caused by modifying the original.
15618 *
15619 * @static
15620 * @since 0.1.0
15621 * @memberOf _
15622 * @category Util
15623 * @param {Function|Object} [object=lodash] The destination object.
15624 * @param {Object} source The object of functions to add.
15625 * @param {Object} [options={}] The options object.
15626 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
15627 * @returns {Function|Object} Returns `object`.
15628 * @example
15629 *
15630 * function vowels(string) {
15631 * return _.filter(string, function(v) {
15632 * return /[aeiou]/i.test(v);
15633 * });
15634 * }
15635 *
15636 * _.mixin({ 'vowels': vowels });
15637 * _.vowels('fred');
15638 * // => ['e']
15639 *
15640 * _('fred').vowels().value();
15641 * // => ['e']
15642 *
15643 * _.mixin({ 'vowels': vowels }, { 'chain': false });
15644 * _('fred').vowels();
15645 * // => ['e']
15646 */
15647 function mixin(object, source, options) {
15648 var props = keys(source),
15649 methodNames = baseFunctions(source, props);
15650
15651 if (options == null &&
15652 !(isObject(source) && (methodNames.length || !props.length))) {
15653 options = source;
15654 source = object;
15655 object = this;
15656 methodNames = baseFunctions(source, keys(source));
15657 }
15658 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
15659 isFunc = isFunction(object);
15660
15661 arrayEach(methodNames, function(methodName) {
15662 var func = source[methodName];
15663 object[methodName] = func;
15664 if (isFunc) {
15665 object.prototype[methodName] = function() {
15666 var chainAll = this.__chain__;
15667 if (chain || chainAll) {
15668 var result = object(this.__wrapped__),
15669 actions = result.__actions__ = copyArray(this.__actions__);
15670
15671 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
15672 result.__chain__ = chainAll;
15673 return result;
15674 }
15675 return func.apply(object, arrayPush([this.value()], arguments));
15676 };
15677 }
15678 });
15679
15680 return object;
15681 }
15682
15683 /**
15684 * Reverts the `_` variable to its previous value and returns a reference to
15685 * the `lodash` function.
15686 *
15687 * @static
15688 * @since 0.1.0
15689 * @memberOf _
15690 * @category Util
15691 * @returns {Function} Returns the `lodash` function.
15692 * @example
15693 *
15694 * var lodash = _.noConflict();
15695 */
15696 function noConflict() {
15697 if (root._ === this) {
15698 root._ = oldDash;
15699 }
15700 return this;
15701 }
15702
15703 /**
15704 * This method returns `undefined`.
15705 *
15706 * @static
15707 * @memberOf _
15708 * @since 2.3.0
15709 * @category Util
15710 * @example
15711 *
15712 * _.times(2, _.noop);
15713 * // => [undefined, undefined]
15714 */
15715 function noop() {
15716 // No operation performed.
15717 }
15718
15719 /**
15720 * Creates a function that gets the argument at index `n`. If `n` is negative,
15721 * the nth argument from the end is returned.
15722 *
15723 * @static
15724 * @memberOf _
15725 * @since 4.0.0
15726 * @category Util
15727 * @param {number} [n=0] The index of the argument to return.
15728 * @returns {Function} Returns the new pass-thru function.
15729 * @example
15730 *
15731 * var func = _.nthArg(1);
15732 * func('a', 'b', 'c', 'd');
15733 * // => 'b'
15734 *
15735 * var func = _.nthArg(-2);
15736 * func('a', 'b', 'c', 'd');
15737 * // => 'c'
15738 */
15739 function nthArg(n) {
15740 n = toInteger(n);
15741 return baseRest(function(args) {
15742 return baseNth(args, n);
15743 });
15744 }
15745
15746 /**
15747 * Creates a function that invokes `iteratees` with the arguments it receives
15748 * and returns their results.
15749 *
15750 * @static
15751 * @memberOf _
15752 * @since 4.0.0
15753 * @category Util
15754 * @param {...(Function|Function[])} [iteratees=[_.identity]]
15755 * The iteratees to invoke.
15756 * @returns {Function} Returns the new function.
15757 * @example
15758 *
15759 * var func = _.over([Math.max, Math.min]);
15760 *
15761 * func(1, 2, 3, 4);
15762 * // => [4, 1]
15763 */
15764 var over = createOver(arrayMap);
15765
15766 /**
15767 * Creates a function that checks if **all** of the `predicates` return
15768 * truthy when invoked with the arguments it receives.
15769 *
15770 * @static
15771 * @memberOf _
15772 * @since 4.0.0
15773 * @category Util
15774 * @param {...(Function|Function[])} [predicates=[_.identity]]
15775 * The predicates to check.
15776 * @returns {Function} Returns the new function.
15777 * @example
15778 *
15779 * var func = _.overEvery([Boolean, isFinite]);
15780 *
15781 * func('1');
15782 * // => true
15783 *
15784 * func(null);
15785 * // => false
15786 *
15787 * func(NaN);
15788 * // => false
15789 */
15790 var overEvery = createOver(arrayEvery);
15791
15792 /**
15793 * Creates a function that checks if **any** of the `predicates` return
15794 * truthy when invoked with the arguments it receives.
15795 *
15796 * @static
15797 * @memberOf _
15798 * @since 4.0.0
15799 * @category Util
15800 * @param {...(Function|Function[])} [predicates=[_.identity]]
15801 * The predicates to check.
15802 * @returns {Function} Returns the new function.
15803 * @example
15804 *
15805 * var func = _.overSome([Boolean, isFinite]);
15806 *
15807 * func('1');
15808 * // => true
15809 *
15810 * func(null);
15811 * // => true
15812 *
15813 * func(NaN);
15814 * // => false
15815 */
15816 var overSome = createOver(arraySome);
15817
15818 /**
15819 * Creates a function that returns the value at `path` of a given object.
15820 *
15821 * @static
15822 * @memberOf _
15823 * @since 2.4.0
15824 * @category Util
15825 * @param {Array|string} path The path of the property to get.
15826 * @returns {Function} Returns the new accessor function.
15827 * @example
15828 *
15829 * var objects = [
15830 * { 'a': { 'b': 2 } },
15831 * { 'a': { 'b': 1 } }
15832 * ];
15833 *
15834 * _.map(objects, _.property('a.b'));
15835 * // => [2, 1]
15836 *
15837 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
15838 * // => [1, 2]
15839 */
15840 function property(path) {
15841 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
15842 }
15843
15844 /**
15845 * The opposite of `_.property`; this method creates a function that returns
15846 * the value at a given path of `object`.
15847 *
15848 * @static
15849 * @memberOf _
15850 * @since 3.0.0
15851 * @category Util
15852 * @param {Object} object The object to query.
15853 * @returns {Function} Returns the new accessor function.
15854 * @example
15855 *
15856 * var array = [0, 1, 2],
15857 * object = { 'a': array, 'b': array, 'c': array };
15858 *
15859 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
15860 * // => [2, 0]
15861 *
15862 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
15863 * // => [2, 0]
15864 */
15865 function propertyOf(object) {
15866 return function(path) {
15867 return object == null ? undefined : baseGet(object, path);
15868 };
15869 }
15870
15871 /**
15872 * Creates an array of numbers (positive and/or negative) progressing from
15873 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
15874 * `start` is specified without an `end` or `step`. If `end` is not specified,
15875 * it's set to `start` with `start` then set to `0`.
15876 *
15877 * **Note:** JavaScript follows the IEEE-754 standard for resolving
15878 * floating-point values which can produce unexpected results.
15879 *
15880 * @static
15881 * @since 0.1.0
15882 * @memberOf _
15883 * @category Util
15884 * @param {number} [start=0] The start of the range.
15885 * @param {number} end The end of the range.
15886 * @param {number} [step=1] The value to increment or decrement by.
15887 * @returns {Array} Returns the range of numbers.
15888 * @see _.inRange, _.rangeRight
15889 * @example
15890 *
15891 * _.range(4);
15892 * // => [0, 1, 2, 3]
15893 *
15894 * _.range(-4);
15895 * // => [0, -1, -2, -3]
15896 *
15897 * _.range(1, 5);
15898 * // => [1, 2, 3, 4]
15899 *
15900 * _.range(0, 20, 5);
15901 * // => [0, 5, 10, 15]
15902 *
15903 * _.range(0, -4, -1);
15904 * // => [0, -1, -2, -3]
15905 *
15906 * _.range(1, 4, 0);
15907 * // => [1, 1, 1]
15908 *
15909 * _.range(0);
15910 * // => []
15911 */
15912 var range = createRange();
15913
15914 /**
15915 * This method is like `_.range` except that it populates values in
15916 * descending order.
15917 *
15918 * @static
15919 * @memberOf _
15920 * @since 4.0.0
15921 * @category Util
15922 * @param {number} [start=0] The start of the range.
15923 * @param {number} end The end of the range.
15924 * @param {number} [step=1] The value to increment or decrement by.
15925 * @returns {Array} Returns the range of numbers.
15926 * @see _.inRange, _.range
15927 * @example
15928 *
15929 * _.rangeRight(4);
15930 * // => [3, 2, 1, 0]
15931 *
15932 * _.rangeRight(-4);
15933 * // => [-3, -2, -1, 0]
15934 *
15935 * _.rangeRight(1, 5);
15936 * // => [4, 3, 2, 1]
15937 *
15938 * _.rangeRight(0, 20, 5);
15939 * // => [15, 10, 5, 0]
15940 *
15941 * _.rangeRight(0, -4, -1);
15942 * // => [-3, -2, -1, 0]
15943 *
15944 * _.rangeRight(1, 4, 0);
15945 * // => [1, 1, 1]
15946 *
15947 * _.rangeRight(0);
15948 * // => []
15949 */
15950 var rangeRight = createRange(true);
15951
15952 /**
15953 * This method returns a new empty array.
15954 *
15955 * @static
15956 * @memberOf _
15957 * @since 4.13.0
15958 * @category Util
15959 * @returns {Array} Returns the new empty array.
15960 * @example
15961 *
15962 * var arrays = _.times(2, _.stubArray);
15963 *
15964 * console.log(arrays);
15965 * // => [[], []]
15966 *
15967 * console.log(arrays[0] === arrays[1]);
15968 * // => false
15969 */
15970 function stubArray() {
15971 return [];
15972 }
15973
15974 /**
15975 * This method returns `false`.
15976 *
15977 * @static
15978 * @memberOf _
15979 * @since 4.13.0
15980 * @category Util
15981 * @returns {boolean} Returns `false`.
15982 * @example
15983 *
15984 * _.times(2, _.stubFalse);
15985 * // => [false, false]
15986 */
15987 function stubFalse() {
15988 return false;
15989 }
15990
15991 /**
15992 * This method returns a new empty object.
15993 *
15994 * @static
15995 * @memberOf _
15996 * @since 4.13.0
15997 * @category Util
15998 * @returns {Object} Returns the new empty object.
15999 * @example
16000 *
16001 * var objects = _.times(2, _.stubObject);
16002 *
16003 * console.log(objects);
16004 * // => [{}, {}]
16005 *
16006 * console.log(objects[0] === objects[1]);
16007 * // => false
16008 */
16009 function stubObject() {
16010 return {};
16011 }
16012
16013 /**
16014 * This method returns an empty string.
16015 *
16016 * @static
16017 * @memberOf _
16018 * @since 4.13.0
16019 * @category Util
16020 * @returns {string} Returns the empty string.
16021 * @example
16022 *
16023 * _.times(2, _.stubString);
16024 * // => ['', '']
16025 */
16026 function stubString() {
16027 return '';
16028 }
16029
16030 /**
16031 * This method returns `true`.
16032 *
16033 * @static
16034 * @memberOf _
16035 * @since 4.13.0
16036 * @category Util
16037 * @returns {boolean} Returns `true`.
16038 * @example
16039 *
16040 * _.times(2, _.stubTrue);
16041 * // => [true, true]
16042 */
16043 function stubTrue() {
16044 return true;
16045 }
16046
16047 /**
16048 * Invokes the iteratee `n` times, returning an array of the results of
16049 * each invocation. The iteratee is invoked with one argument; (index).
16050 *
16051 * @static
16052 * @since 0.1.0
16053 * @memberOf _
16054 * @category Util
16055 * @param {number} n The number of times to invoke `iteratee`.
16056 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
16057 * @returns {Array} Returns the array of results.
16058 * @example
16059 *
16060 * _.times(3, String);
16061 * // => ['0', '1', '2']
16062 *
16063 * _.times(4, _.constant(0));
16064 * // => [0, 0, 0, 0]
16065 */
16066 function times(n, iteratee) {
16067 n = toInteger(n);
16068 if (n < 1 || n > MAX_SAFE_INTEGER) {
16069 return [];
16070 }
16071 var index = MAX_ARRAY_LENGTH,
16072 length = nativeMin(n, MAX_ARRAY_LENGTH);
16073
16074 iteratee = getIteratee(iteratee);
16075 n -= MAX_ARRAY_LENGTH;
16076
16077 var result = baseTimes(length, iteratee);
16078 while (++index < n) {
16079 iteratee(index);
16080 }
16081 return result;
16082 }
16083
16084 /**
16085 * Converts `value` to a property path array.
16086 *
16087 * @static
16088 * @memberOf _
16089 * @since 4.0.0
16090 * @category Util
16091 * @param {*} value The value to convert.
16092 * @returns {Array} Returns the new property path array.
16093 * @example
16094 *
16095 * _.toPath('a.b.c');
16096 * // => ['a', 'b', 'c']
16097 *
16098 * _.toPath('a[0].b.c');
16099 * // => ['a', '0', 'b', 'c']
16100 */
16101 function toPath(value) {
16102 if (isArray(value)) {
16103 return arrayMap(value, toKey);
16104 }
16105 return isSymbol(value) ? [value] : copyArray(stringToPath(value));
16106 }
16107
16108 /**
16109 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
16110 *
16111 * @static
16112 * @since 0.1.0
16113 * @memberOf _
16114 * @category Util
16115 * @param {string} [prefix=''] The value to prefix the ID with.
16116 * @returns {string} Returns the unique ID.
16117 * @example
16118 *
16119 * _.uniqueId('contact_');
16120 * // => 'contact_104'
16121 *
16122 * _.uniqueId();
16123 * // => '105'
16124 */
16125 function uniqueId(prefix) {
16126 var id = ++idCounter;
16127 return toString(prefix) + id;
16128 }
16129
16130 /*------------------------------------------------------------------------*/
16131
16132 /**
16133 * Adds two numbers.
16134 *
16135 * @static
16136 * @memberOf _
16137 * @since 3.4.0
16138 * @category Math
16139 * @param {number} augend The first number in an addition.
16140 * @param {number} addend The second number in an addition.
16141 * @returns {number} Returns the total.
16142 * @example
16143 *
16144 * _.add(6, 4);
16145 * // => 10
16146 */
16147 var add = createMathOperation(function(augend, addend) {
16148 return augend + addend;
16149 }, 0);
16150
16151 /**
16152 * Computes `number` rounded up to `precision`.
16153 *
16154 * @static
16155 * @memberOf _
16156 * @since 3.10.0
16157 * @category Math
16158 * @param {number} number The number to round up.
16159 * @param {number} [precision=0] The precision to round up to.
16160 * @returns {number} Returns the rounded up number.
16161 * @example
16162 *
16163 * _.ceil(4.006);
16164 * // => 5
16165 *
16166 * _.ceil(6.004, 2);
16167 * // => 6.01
16168 *
16169 * _.ceil(6040, -2);
16170 * // => 6100
16171 */
16172 var ceil = createRound('ceil');
16173
16174 /**
16175 * Divide two numbers.
16176 *
16177 * @static
16178 * @memberOf _
16179 * @since 4.7.0
16180 * @category Math
16181 * @param {number} dividend The first number in a division.
16182 * @param {number} divisor The second number in a division.
16183 * @returns {number} Returns the quotient.
16184 * @example
16185 *
16186 * _.divide(6, 4);
16187 * // => 1.5
16188 */
16189 var divide = createMathOperation(function(dividend, divisor) {
16190 return dividend / divisor;
16191 }, 1);
16192
16193 /**
16194 * Computes `number` rounded down to `precision`.
16195 *
16196 * @static
16197 * @memberOf _
16198 * @since 3.10.0
16199 * @category Math
16200 * @param {number} number The number to round down.
16201 * @param {number} [precision=0] The precision to round down to.
16202 * @returns {number} Returns the rounded down number.
16203 * @example
16204 *
16205 * _.floor(4.006);
16206 * // => 4
16207 *
16208 * _.floor(0.046, 2);
16209 * // => 0.04
16210 *
16211 * _.floor(4060, -2);
16212 * // => 4000
16213 */
16214 var floor = createRound('floor');
16215
16216 /**
16217 * Computes the maximum value of `array`. If `array` is empty or falsey,
16218 * `undefined` is returned.
16219 *
16220 * @static
16221 * @since 0.1.0
16222 * @memberOf _
16223 * @category Math
16224 * @param {Array} array The array to iterate over.
16225 * @returns {*} Returns the maximum value.
16226 * @example
16227 *
16228 * _.max([4, 2, 8, 6]);
16229 * // => 8
16230 *
16231 * _.max([]);
16232 * // => undefined
16233 */
16234 function max(array) {
16235 return (array && array.length)
16236 ? baseExtremum(array, identity, baseGt)
16237 : undefined;
16238 }
16239
16240 /**
16241 * This method is like `_.max` except that it accepts `iteratee` which is
16242 * invoked for each element in `array` to generate the criterion by which
16243 * the value is ranked. The iteratee is invoked with one argument: (value).
16244 *
16245 * @static
16246 * @memberOf _
16247 * @since 4.0.0
16248 * @category Math
16249 * @param {Array} array The array to iterate over.
16250 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16251 * @returns {*} Returns the maximum value.
16252 * @example
16253 *
16254 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16255 *
16256 * _.maxBy(objects, function(o) { return o.n; });
16257 * // => { 'n': 2 }
16258 *
16259 * // The `_.property` iteratee shorthand.
16260 * _.maxBy(objects, 'n');
16261 * // => { 'n': 2 }
16262 */
16263 function maxBy(array, iteratee) {
16264 return (array && array.length)
16265 ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
16266 : undefined;
16267 }
16268
16269 /**
16270 * Computes the mean of the values in `array`.
16271 *
16272 * @static
16273 * @memberOf _
16274 * @since 4.0.0
16275 * @category Math
16276 * @param {Array} array The array to iterate over.
16277 * @returns {number} Returns the mean.
16278 * @example
16279 *
16280 * _.mean([4, 2, 8, 6]);
16281 * // => 5
16282 */
16283 function mean(array) {
16284 return baseMean(array, identity);
16285 }
16286
16287 /**
16288 * This method is like `_.mean` except that it accepts `iteratee` which is
16289 * invoked for each element in `array` to generate the value to be averaged.
16290 * The iteratee is invoked with one argument: (value).
16291 *
16292 * @static
16293 * @memberOf _
16294 * @since 4.7.0
16295 * @category Math
16296 * @param {Array} array The array to iterate over.
16297 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16298 * @returns {number} Returns the mean.
16299 * @example
16300 *
16301 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16302 *
16303 * _.meanBy(objects, function(o) { return o.n; });
16304 * // => 5
16305 *
16306 * // The `_.property` iteratee shorthand.
16307 * _.meanBy(objects, 'n');
16308 * // => 5
16309 */
16310 function meanBy(array, iteratee) {
16311 return baseMean(array, getIteratee(iteratee, 2));
16312 }
16313
16314 /**
16315 * Computes the minimum value of `array`. If `array` is empty or falsey,
16316 * `undefined` is returned.
16317 *
16318 * @static
16319 * @since 0.1.0
16320 * @memberOf _
16321 * @category Math
16322 * @param {Array} array The array to iterate over.
16323 * @returns {*} Returns the minimum value.
16324 * @example
16325 *
16326 * _.min([4, 2, 8, 6]);
16327 * // => 2
16328 *
16329 * _.min([]);
16330 * // => undefined
16331 */
16332 function min(array) {
16333 return (array && array.length)
16334 ? baseExtremum(array, identity, baseLt)
16335 : undefined;
16336 }
16337
16338 /**
16339 * This method is like `_.min` except that it accepts `iteratee` which is
16340 * invoked for each element in `array` to generate the criterion by which
16341 * the value is ranked. The iteratee is invoked with one argument: (value).
16342 *
16343 * @static
16344 * @memberOf _
16345 * @since 4.0.0
16346 * @category Math
16347 * @param {Array} array The array to iterate over.
16348 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16349 * @returns {*} Returns the minimum value.
16350 * @example
16351 *
16352 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16353 *
16354 * _.minBy(objects, function(o) { return o.n; });
16355 * // => { 'n': 1 }
16356 *
16357 * // The `_.property` iteratee shorthand.
16358 * _.minBy(objects, 'n');
16359 * // => { 'n': 1 }
16360 */
16361 function minBy(array, iteratee) {
16362 return (array && array.length)
16363 ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
16364 : undefined;
16365 }
16366
16367 /**
16368 * Multiply two numbers.
16369 *
16370 * @static
16371 * @memberOf _
16372 * @since 4.7.0
16373 * @category Math
16374 * @param {number} multiplier The first number in a multiplication.
16375 * @param {number} multiplicand The second number in a multiplication.
16376 * @returns {number} Returns the product.
16377 * @example
16378 *
16379 * _.multiply(6, 4);
16380 * // => 24
16381 */
16382 var multiply = createMathOperation(function(multiplier, multiplicand) {
16383 return multiplier * multiplicand;
16384 }, 1);
16385
16386 /**
16387 * Computes `number` rounded to `precision`.
16388 *
16389 * @static
16390 * @memberOf _
16391 * @since 3.10.0
16392 * @category Math
16393 * @param {number} number The number to round.
16394 * @param {number} [precision=0] The precision to round to.
16395 * @returns {number} Returns the rounded number.
16396 * @example
16397 *
16398 * _.round(4.006);
16399 * // => 4
16400 *
16401 * _.round(4.006, 2);
16402 * // => 4.01
16403 *
16404 * _.round(4060, -2);
16405 * // => 4100
16406 */
16407 var round = createRound('round');
16408
16409 /**
16410 * Subtract two numbers.
16411 *
16412 * @static
16413 * @memberOf _
16414 * @since 4.0.0
16415 * @category Math
16416 * @param {number} minuend The first number in a subtraction.
16417 * @param {number} subtrahend The second number in a subtraction.
16418 * @returns {number} Returns the difference.
16419 * @example
16420 *
16421 * _.subtract(6, 4);
16422 * // => 2
16423 */
16424 var subtract = createMathOperation(function(minuend, subtrahend) {
16425 return minuend - subtrahend;
16426 }, 0);
16427
16428 /**
16429 * Computes the sum of the values in `array`.
16430 *
16431 * @static
16432 * @memberOf _
16433 * @since 3.4.0
16434 * @category Math
16435 * @param {Array} array The array to iterate over.
16436 * @returns {number} Returns the sum.
16437 * @example
16438 *
16439 * _.sum([4, 2, 8, 6]);
16440 * // => 20
16441 */
16442 function sum(array) {
16443 return (array && array.length)
16444 ? baseSum(array, identity)
16445 : 0;
16446 }
16447
16448 /**
16449 * This method is like `_.sum` except that it accepts `iteratee` which is
16450 * invoked for each element in `array` to generate the value to be summed.
16451 * The iteratee is invoked with one argument: (value).
16452 *
16453 * @static
16454 * @memberOf _
16455 * @since 4.0.0
16456 * @category Math
16457 * @param {Array} array The array to iterate over.
16458 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16459 * @returns {number} Returns the sum.
16460 * @example
16461 *
16462 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16463 *
16464 * _.sumBy(objects, function(o) { return o.n; });
16465 * // => 20
16466 *
16467 * // The `_.property` iteratee shorthand.
16468 * _.sumBy(objects, 'n');
16469 * // => 20
16470 */
16471 function sumBy(array, iteratee) {
16472 return (array && array.length)
16473 ? baseSum(array, getIteratee(iteratee, 2))
16474 : 0;
16475 }
16476
16477 /*------------------------------------------------------------------------*/
16478
16479 // Add methods that return wrapped values in chain sequences.
16480 lodash.after = after;
16481 lodash.ary = ary;
16482 lodash.assign = assign;
16483 lodash.assignIn = assignIn;
16484 lodash.assignInWith = assignInWith;
16485 lodash.assignWith = assignWith;
16486 lodash.at = at;
16487 lodash.before = before;
16488 lodash.bind = bind;
16489 lodash.bindAll = bindAll;
16490 lodash.bindKey = bindKey;
16491 lodash.castArray = castArray;
16492 lodash.chain = chain;
16493 lodash.chunk = chunk;
16494 lodash.compact = compact;
16495 lodash.concat = concat;
16496 lodash.cond = cond;
16497 lodash.conforms = conforms;
16498 lodash.constant = constant;
16499 lodash.countBy = countBy;
16500 lodash.create = create;
16501 lodash.curry = curry;
16502 lodash.curryRight = curryRight;
16503 lodash.debounce = debounce;
16504 lodash.defaults = defaults;
16505 lodash.defaultsDeep = defaultsDeep;
16506 lodash.defer = defer;
16507 lodash.delay = delay;
16508 lodash.difference = difference;
16509 lodash.differenceBy = differenceBy;
16510 lodash.differenceWith = differenceWith;
16511 lodash.drop = drop;
16512 lodash.dropRight = dropRight;
16513 lodash.dropRightWhile = dropRightWhile;
16514 lodash.dropWhile = dropWhile;
16515 lodash.fill = fill;
16516 lodash.filter = filter;
16517 lodash.flatMap = flatMap;
16518 lodash.flatMapDeep = flatMapDeep;
16519 lodash.flatMapDepth = flatMapDepth;
16520 lodash.flatten = flatten;
16521 lodash.flattenDeep = flattenDeep;
16522 lodash.flattenDepth = flattenDepth;
16523 lodash.flip = flip;
16524 lodash.flow = flow;
16525 lodash.flowRight = flowRight;
16526 lodash.fromPairs = fromPairs;
16527 lodash.functions = functions;
16528 lodash.functionsIn = functionsIn;
16529 lodash.groupBy = groupBy;
16530 lodash.initial = initial;
16531 lodash.intersection = intersection;
16532 lodash.intersectionBy = intersectionBy;
16533 lodash.intersectionWith = intersectionWith;
16534 lodash.invert = invert;
16535 lodash.invertBy = invertBy;
16536 lodash.invokeMap = invokeMap;
16537 lodash.iteratee = iteratee;
16538 lodash.keyBy = keyBy;
16539 lodash.keys = keys;
16540 lodash.keysIn = keysIn;
16541 lodash.map = map;
16542 lodash.mapKeys = mapKeys;
16543 lodash.mapValues = mapValues;
16544 lodash.matches = matches;
16545 lodash.matchesProperty = matchesProperty;
16546 lodash.memoize = memoize;
16547 lodash.merge = merge;
16548 lodash.mergeWith = mergeWith;
16549 lodash.method = method;
16550 lodash.methodOf = methodOf;
16551 lodash.mixin = mixin;
16552 lodash.negate = negate;
16553 lodash.nthArg = nthArg;
16554 lodash.omit = omit;
16555 lodash.omitBy = omitBy;
16556 lodash.once = once;
16557 lodash.orderBy = orderBy;
16558 lodash.over = over;
16559 lodash.overArgs = overArgs;
16560 lodash.overEvery = overEvery;
16561 lodash.overSome = overSome;
16562 lodash.partial = partial;
16563 lodash.partialRight = partialRight;
16564 lodash.partition = partition;
16565 lodash.pick = pick;
16566 lodash.pickBy = pickBy;
16567 lodash.property = property;
16568 lodash.propertyOf = propertyOf;
16569 lodash.pull = pull;
16570 lodash.pullAll = pullAll;
16571 lodash.pullAllBy = pullAllBy;
16572 lodash.pullAllWith = pullAllWith;
16573 lodash.pullAt = pullAt;
16574 lodash.range = range;
16575 lodash.rangeRight = rangeRight;
16576 lodash.rearg = rearg;
16577 lodash.reject = reject;
16578 lodash.remove = remove;
16579 lodash.rest = rest;
16580 lodash.reverse = reverse;
16581 lodash.sampleSize = sampleSize;
16582 lodash.set = set;
16583 lodash.setWith = setWith;
16584 lodash.shuffle = shuffle;
16585 lodash.slice = slice;
16586 lodash.sortBy = sortBy;
16587 lodash.sortedUniq = sortedUniq;
16588 lodash.sortedUniqBy = sortedUniqBy;
16589 lodash.split = split;
16590 lodash.spread = spread;
16591 lodash.tail = tail;
16592 lodash.take = take;
16593 lodash.takeRight = takeRight;
16594 lodash.takeRightWhile = takeRightWhile;
16595 lodash.takeWhile = takeWhile;
16596 lodash.tap = tap;
16597 lodash.throttle = throttle;
16598 lodash.thru = thru;
16599 lodash.toArray = toArray;
16600 lodash.toPairs = toPairs;
16601 lodash.toPairsIn = toPairsIn;
16602 lodash.toPath = toPath;
16603 lodash.toPlainObject = toPlainObject;
16604 lodash.transform = transform;
16605 lodash.unary = unary;
16606 lodash.union = union;
16607 lodash.unionBy = unionBy;
16608 lodash.unionWith = unionWith;
16609 lodash.uniq = uniq;
16610 lodash.uniqBy = uniqBy;
16611 lodash.uniqWith = uniqWith;
16612 lodash.unset = unset;
16613 lodash.unzip = unzip;
16614 lodash.unzipWith = unzipWith;
16615 lodash.update = update;
16616 lodash.updateWith = updateWith;
16617 lodash.values = values;
16618 lodash.valuesIn = valuesIn;
16619 lodash.without = without;
16620 lodash.words = words;
16621 lodash.wrap = wrap;
16622 lodash.xor = xor;
16623 lodash.xorBy = xorBy;
16624 lodash.xorWith = xorWith;
16625 lodash.zip = zip;
16626 lodash.zipObject = zipObject;
16627 lodash.zipObjectDeep = zipObjectDeep;
16628 lodash.zipWith = zipWith;
16629
16630 // Add aliases.
16631 lodash.entries = toPairs;
16632 lodash.entriesIn = toPairsIn;
16633 lodash.extend = assignIn;
16634 lodash.extendWith = assignInWith;
16635
16636 // Add methods to `lodash.prototype`.
16637 mixin(lodash, lodash);
16638
16639 /*------------------------------------------------------------------------*/
16640
16641 // Add methods that return unwrapped values in chain sequences.
16642 lodash.add = add;
16643 lodash.attempt = attempt;
16644 lodash.camelCase = camelCase;
16645 lodash.capitalize = capitalize;
16646 lodash.ceil = ceil;
16647 lodash.clamp = clamp;
16648 lodash.clone = clone;
16649 lodash.cloneDeep = cloneDeep;
16650 lodash.cloneDeepWith = cloneDeepWith;
16651 lodash.cloneWith = cloneWith;
16652 lodash.conformsTo = conformsTo;
16653 lodash.deburr = deburr;
16654 lodash.defaultTo = defaultTo;
16655 lodash.divide = divide;
16656 lodash.endsWith = endsWith;
16657 lodash.eq = eq;
16658 lodash.escape = escape;
16659 lodash.escapeRegExp = escapeRegExp;
16660 lodash.every = every;
16661 lodash.find = find;
16662 lodash.findIndex = findIndex;
16663 lodash.findKey = findKey;
16664 lodash.findLast = findLast;
16665 lodash.findLastIndex = findLastIndex;
16666 lodash.findLastKey = findLastKey;
16667 lodash.floor = floor;
16668 lodash.forEach = forEach;
16669 lodash.forEachRight = forEachRight;
16670 lodash.forIn = forIn;
16671 lodash.forInRight = forInRight;
16672 lodash.forOwn = forOwn;
16673 lodash.forOwnRight = forOwnRight;
16674 lodash.get = get;
16675 lodash.gt = gt;
16676 lodash.gte = gte;
16677 lodash.has = has;
16678 lodash.hasIn = hasIn;
16679 lodash.head = head;
16680 lodash.identity = identity;
16681 lodash.includes = includes;
16682 lodash.indexOf = indexOf;
16683 lodash.inRange = inRange;
16684 lodash.invoke = invoke;
16685 lodash.isArguments = isArguments;
16686 lodash.isArray = isArray;
16687 lodash.isArrayBuffer = isArrayBuffer;
16688 lodash.isArrayLike = isArrayLike;
16689 lodash.isArrayLikeObject = isArrayLikeObject;
16690 lodash.isBoolean = isBoolean;
16691 lodash.isBuffer = isBuffer;
16692 lodash.isDate = isDate;
16693 lodash.isElement = isElement;
16694 lodash.isEmpty = isEmpty;
16695 lodash.isEqual = isEqual;
16696 lodash.isEqualWith = isEqualWith;
16697 lodash.isError = isError;
16698 lodash.isFinite = isFinite;
16699 lodash.isFunction = isFunction;
16700 lodash.isInteger = isInteger;
16701 lodash.isLength = isLength;
16702 lodash.isMap = isMap;
16703 lodash.isMatch = isMatch;
16704 lodash.isMatchWith = isMatchWith;
16705 lodash.isNaN = isNaN;
16706 lodash.isNative = isNative;
16707 lodash.isNil = isNil;
16708 lodash.isNull = isNull;
16709 lodash.isNumber = isNumber;
16710 lodash.isObject = isObject;
16711 lodash.isObjectLike = isObjectLike;
16712 lodash.isPlainObject = isPlainObject;
16713 lodash.isRegExp = isRegExp;
16714 lodash.isSafeInteger = isSafeInteger;
16715 lodash.isSet = isSet;
16716 lodash.isString = isString;
16717 lodash.isSymbol = isSymbol;
16718 lodash.isTypedArray = isTypedArray;
16719 lodash.isUndefined = isUndefined;
16720 lodash.isWeakMap = isWeakMap;
16721 lodash.isWeakSet = isWeakSet;
16722 lodash.join = join;
16723 lodash.kebabCase = kebabCase;
16724 lodash.last = last;
16725 lodash.lastIndexOf = lastIndexOf;
16726 lodash.lowerCase = lowerCase;
16727 lodash.lowerFirst = lowerFirst;
16728 lodash.lt = lt;
16729 lodash.lte = lte;
16730 lodash.max = max;
16731 lodash.maxBy = maxBy;
16732 lodash.mean = mean;
16733 lodash.meanBy = meanBy;
16734 lodash.min = min;
16735 lodash.minBy = minBy;
16736 lodash.stubArray = stubArray;
16737 lodash.stubFalse = stubFalse;
16738 lodash.stubObject = stubObject;
16739 lodash.stubString = stubString;
16740 lodash.stubTrue = stubTrue;
16741 lodash.multiply = multiply;
16742 lodash.nth = nth;
16743 lodash.noConflict = noConflict;
16744 lodash.noop = noop;
16745 lodash.now = now;
16746 lodash.pad = pad;
16747 lodash.padEnd = padEnd;
16748 lodash.padStart = padStart;
16749 lodash.parseInt = parseInt;
16750 lodash.random = random;
16751 lodash.reduce = reduce;
16752 lodash.reduceRight = reduceRight;
16753 lodash.repeat = repeat;
16754 lodash.replace = replace;
16755 lodash.result = result;
16756 lodash.round = round;
16757 lodash.runInContext = runInContext;
16758 lodash.sample = sample;
16759 lodash.size = size;
16760 lodash.snakeCase = snakeCase;
16761 lodash.some = some;
16762 lodash.sortedIndex = sortedIndex;
16763 lodash.sortedIndexBy = sortedIndexBy;
16764 lodash.sortedIndexOf = sortedIndexOf;
16765 lodash.sortedLastIndex = sortedLastIndex;
16766 lodash.sortedLastIndexBy = sortedLastIndexBy;
16767 lodash.sortedLastIndexOf = sortedLastIndexOf;
16768 lodash.startCase = startCase;
16769 lodash.startsWith = startsWith;
16770 lodash.subtract = subtract;
16771 lodash.sum = sum;
16772 lodash.sumBy = sumBy;
16773 lodash.template = template;
16774 lodash.times = times;
16775 lodash.toFinite = toFinite;
16776 lodash.toInteger = toInteger;
16777 lodash.toLength = toLength;
16778 lodash.toLower = toLower;
16779 lodash.toNumber = toNumber;
16780 lodash.toSafeInteger = toSafeInteger;
16781 lodash.toString = toString;
16782 lodash.toUpper = toUpper;
16783 lodash.trim = trim;
16784 lodash.trimEnd = trimEnd;
16785 lodash.trimStart = trimStart;
16786 lodash.truncate = truncate;
16787 lodash.unescape = unescape;
16788 lodash.uniqueId = uniqueId;
16789 lodash.upperCase = upperCase;
16790 lodash.upperFirst = upperFirst;
16791
16792 // Add aliases.
16793 lodash.each = forEach;
16794 lodash.eachRight = forEachRight;
16795 lodash.first = head;
16796
16797 mixin(lodash, (function() {
16798 var source = {};
16799 baseForOwn(lodash, function(func, methodName) {
16800 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
16801 source[methodName] = func;
16802 }
16803 });
16804 return source;
16805 }()), { 'chain': false });
16806
16807 /*------------------------------------------------------------------------*/
16808
16809 /**
16810 * The semantic version number.
16811 *
16812 * @static
16813 * @memberOf _
16814 * @type {string}
16815 */
16816 lodash.VERSION = VERSION;
16817
16818 // Assign default placeholders.
16819 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
16820 lodash[methodName].placeholder = lodash;
16821 });
16822
16823 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
16824 arrayEach(['drop', 'take'], function(methodName, index) {
16825 LazyWrapper.prototype[methodName] = function(n) {
16826 var filtered = this.__filtered__;
16827 if (filtered && !index) {
16828 return new LazyWrapper(this);
16829 }
16830 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
16831
16832 var result = this.clone();
16833 if (filtered) {
16834 result.__takeCount__ = nativeMin(n, result.__takeCount__);
16835 } else {
16836 result.__views__.push({
16837 'size': nativeMin(n, MAX_ARRAY_LENGTH),
16838 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
16839 });
16840 }
16841 return result;
16842 };
16843
16844 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
16845 return this.reverse()[methodName](n).reverse();
16846 };
16847 });
16848
16849 // Add `LazyWrapper` methods that accept an `iteratee` value.
16850 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
16851 var type = index + 1,
16852 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
16853
16854 LazyWrapper.prototype[methodName] = function(iteratee) {
16855 var result = this.clone();
16856 result.__iteratees__.push({
16857 'iteratee': getIteratee(iteratee, 3),
16858 'type': type
16859 });
16860 result.__filtered__ = result.__filtered__ || isFilter;
16861 return result;
16862 };
16863 });
16864
16865 // Add `LazyWrapper` methods for `_.head` and `_.last`.
16866 arrayEach(['head', 'last'], function(methodName, index) {
16867 var takeName = 'take' + (index ? 'Right' : '');
16868
16869 LazyWrapper.prototype[methodName] = function() {
16870 return this[takeName](1).value()[0];
16871 };
16872 });
16873
16874 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
16875 arrayEach(['initial', 'tail'], function(methodName, index) {
16876 var dropName = 'drop' + (index ? '' : 'Right');
16877
16878 LazyWrapper.prototype[methodName] = function() {
16879 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
16880 };
16881 });
16882
16883 LazyWrapper.prototype.compact = function() {
16884 return this.filter(identity);
16885 };
16886
16887 LazyWrapper.prototype.find = function(predicate) {
16888 return this.filter(predicate).head();
16889 };
16890
16891 LazyWrapper.prototype.findLast = function(predicate) {
16892 return this.reverse().find(predicate);
16893 };
16894
16895 LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
16896 if (typeof path == 'function') {
16897 return new LazyWrapper(this);
16898 }
16899 return this.map(function(value) {
16900 return baseInvoke(value, path, args);
16901 });
16902 });
16903
16904 LazyWrapper.prototype.reject = function(predicate) {
16905 return this.filter(negate(getIteratee(predicate)));
16906 };
16907
16908 LazyWrapper.prototype.slice = function(start, end) {
16909 start = toInteger(start);
16910
16911 var result = this;
16912 if (result.__filtered__ && (start > 0 || end < 0)) {
16913 return new LazyWrapper(result);
16914 }
16915 if (start < 0) {
16916 result = result.takeRight(-start);
16917 } else if (start) {
16918 result = result.drop(start);
16919 }
16920 if (end !== undefined) {
16921 end = toInteger(end);
16922 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
16923 }
16924 return result;
16925 };
16926
16927 LazyWrapper.prototype.takeRightWhile = function(predicate) {
16928 return this.reverse().takeWhile(predicate).reverse();
16929 };
16930
16931 LazyWrapper.prototype.toArray = function() {
16932 return this.take(MAX_ARRAY_LENGTH);
16933 };
16934
16935 // Add `LazyWrapper` methods to `lodash.prototype`.
16936 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16937 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
16938 isTaker = /^(?:head|last)$/.test(methodName),
16939 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
16940 retUnwrapped = isTaker || /^find/.test(methodName);
16941
16942 if (!lodashFunc) {
16943 return;
16944 }
16945 lodash.prototype[methodName] = function() {
16946 var value = this.__wrapped__,
16947 args = isTaker ? [1] : arguments,
16948 isLazy = value instanceof LazyWrapper,
16949 iteratee = args[0],
16950 useLazy = isLazy || isArray(value);
16951
16952 var interceptor = function(value) {
16953 var result = lodashFunc.apply(lodash, arrayPush([value], args));
16954 return (isTaker && chainAll) ? result[0] : result;
16955 };
16956
16957 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
16958 // Avoid lazy use if the iteratee has a "length" value other than `1`.
16959 isLazy = useLazy = false;
16960 }
16961 var chainAll = this.__chain__,
16962 isHybrid = !!this.__actions__.length,
16963 isUnwrapped = retUnwrapped && !chainAll,
16964 onlyLazy = isLazy && !isHybrid;
16965
16966 if (!retUnwrapped && useLazy) {
16967 value = onlyLazy ? value : new LazyWrapper(this);
16968 var result = func.apply(value, args);
16969 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
16970 return new LodashWrapper(result, chainAll);
16971 }
16972 if (isUnwrapped && onlyLazy) {
16973 return func.apply(this, args);
16974 }
16975 result = this.thru(interceptor);
16976 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
16977 };
16978 });
16979
16980 // Add `Array` methods to `lodash.prototype`.
16981 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
16982 var func = arrayProto[methodName],
16983 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
16984 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
16985
16986 lodash.prototype[methodName] = function() {
16987 var args = arguments;
16988 if (retUnwrapped && !this.__chain__) {
16989 var value = this.value();
16990 return func.apply(isArray(value) ? value : [], args);
16991 }
16992 return this[chainName](function(value) {
16993 return func.apply(isArray(value) ? value : [], args);
16994 });
16995 };
16996 });
16997
16998 // Map minified method names to their real names.
16999 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
17000 var lodashFunc = lodash[methodName];
17001 if (lodashFunc) {
17002 var key = (lodashFunc.name + ''),
17003 names = realNames[key] || (realNames[key] = []);
17004
17005 names.push({ 'name': methodName, 'func': lodashFunc });
17006 }
17007 });
17008
17009 realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
17010 'name': 'wrapper',
17011 'func': undefined
17012 }];
17013
17014 // Add methods to `LazyWrapper`.
17015 LazyWrapper.prototype.clone = lazyClone;
17016 LazyWrapper.prototype.reverse = lazyReverse;
17017 LazyWrapper.prototype.value = lazyValue;
17018
17019 // Add chain sequence methods to the `lodash` wrapper.
17020 lodash.prototype.at = wrapperAt;
17021 lodash.prototype.chain = wrapperChain;
17022 lodash.prototype.commit = wrapperCommit;
17023 lodash.prototype.next = wrapperNext;
17024 lodash.prototype.plant = wrapperPlant;
17025 lodash.prototype.reverse = wrapperReverse;
17026 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
17027
17028 // Add lazy aliases.
17029 lodash.prototype.first = lodash.prototype.head;
17030
17031 if (symIterator) {
17032 lodash.prototype[symIterator] = wrapperToIterator;
17033 }
17034 return lodash;
17035 });
17036
17037 /*--------------------------------------------------------------------------*/
17038
17039 // Export lodash.
17040 var _ = runInContext();
17041
17042 // Some AMD build optimizers, like r.js, check for condition patterns like:
17043 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
17044 // Expose Lodash on the global object to prevent errors when Lodash is
17045 // loaded by a script tag in the presence of an AMD loader.
17046 // See http://requirejs.org/docs/errors.html#mismatch for more details.
17047 // Use `_.noConflict` to remove Lodash from the global object.
17048 root._ = _;
17049
17050 // Define as an anonymous module so, through path mapping, it can be
17051 // referenced as the "underscore" module.
17052 define(function() {
17053 return _;
17054 });
17055 }
17056 // Check for `exports` after `define` in case a build optimizer adds it.
17057 else if (freeModule) {
17058 // Export for Node.js.
17059 (freeModule.exports = _)._ = _;
17060 // Export for CommonJS support.
17061 freeExports._ = _;
17062 }
17063 else {
17064 // Export to the global object.
17065 root._ = _;
17066 }
17067}.call(this));