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.2';
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 = castPath(path, object);
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 path = castPath(path, object);
3246 object = parent(object, path);
3247 var func = object == null ? object : object[toKey(last(path))];
3248 return func == null ? undefined : apply(func, object, args);
3249 }
3250
3251 /**
3252 * The base implementation of `_.isArguments`.
3253 *
3254 * @private
3255 * @param {*} value The value to check.
3256 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
3257 */
3258 function baseIsArguments(value) {
3259 return isObjectLike(value) && baseGetTag(value) == argsTag;
3260 }
3261
3262 /**
3263 * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
3264 *
3265 * @private
3266 * @param {*} value The value to check.
3267 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
3268 */
3269 function baseIsArrayBuffer(value) {
3270 return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
3271 }
3272
3273 /**
3274 * The base implementation of `_.isDate` without Node.js optimizations.
3275 *
3276 * @private
3277 * @param {*} value The value to check.
3278 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
3279 */
3280 function baseIsDate(value) {
3281 return isObjectLike(value) && baseGetTag(value) == dateTag;
3282 }
3283
3284 /**
3285 * The base implementation of `_.isEqual` which supports partial comparisons
3286 * and tracks traversed objects.
3287 *
3288 * @private
3289 * @param {*} value The value to compare.
3290 * @param {*} other The other value to compare.
3291 * @param {boolean} bitmask The bitmask flags.
3292 * 1 - Unordered comparison
3293 * 2 - Partial comparison
3294 * @param {Function} [customizer] The function to customize comparisons.
3295 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
3296 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3297 */
3298 function baseIsEqual(value, other, bitmask, customizer, stack) {
3299 if (value === other) {
3300 return true;
3301 }
3302 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
3303 return value !== value && other !== other;
3304 }
3305 return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
3306 }
3307
3308 /**
3309 * A specialized version of `baseIsEqual` for arrays and objects which performs
3310 * deep comparisons and tracks traversed objects enabling objects with circular
3311 * references to be compared.
3312 *
3313 * @private
3314 * @param {Object} object The object to compare.
3315 * @param {Object} other The other object to compare.
3316 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
3317 * @param {Function} customizer The function to customize comparisons.
3318 * @param {Function} equalFunc The function to determine equivalents of values.
3319 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
3320 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3321 */
3322 function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
3323 var objIsArr = isArray(object),
3324 othIsArr = isArray(other),
3325 objTag = arrayTag,
3326 othTag = arrayTag;
3327
3328 if (!objIsArr) {
3329 objTag = getTag(object);
3330 objTag = objTag == argsTag ? objectTag : objTag;
3331 }
3332 if (!othIsArr) {
3333 othTag = getTag(other);
3334 othTag = othTag == argsTag ? objectTag : othTag;
3335 }
3336 var objIsObj = objTag == objectTag,
3337 othIsObj = othTag == objectTag,
3338 isSameTag = objTag == othTag;
3339
3340 if (isSameTag && isBuffer(object)) {
3341 if (!isBuffer(other)) {
3342 return false;
3343 }
3344 objIsArr = true;
3345 objIsObj = false;
3346 }
3347 if (isSameTag && !objIsObj) {
3348 stack || (stack = new Stack);
3349 return (objIsArr || isTypedArray(object))
3350 ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
3351 : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
3352 }
3353 if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
3354 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
3355 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
3356
3357 if (objIsWrapped || othIsWrapped) {
3358 var objUnwrapped = objIsWrapped ? object.value() : object,
3359 othUnwrapped = othIsWrapped ? other.value() : other;
3360
3361 stack || (stack = new Stack);
3362 return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
3363 }
3364 }
3365 if (!isSameTag) {
3366 return false;
3367 }
3368 stack || (stack = new Stack);
3369 return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
3370 }
3371
3372 /**
3373 * The base implementation of `_.isMap` without Node.js optimizations.
3374 *
3375 * @private
3376 * @param {*} value The value to check.
3377 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
3378 */
3379 function baseIsMap(value) {
3380 return isObjectLike(value) && getTag(value) == mapTag;
3381 }
3382
3383 /**
3384 * The base implementation of `_.isMatch` without support for iteratee shorthands.
3385 *
3386 * @private
3387 * @param {Object} object The object to inspect.
3388 * @param {Object} source The object of property values to match.
3389 * @param {Array} matchData The property names, values, and compare flags to match.
3390 * @param {Function} [customizer] The function to customize comparisons.
3391 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
3392 */
3393 function baseIsMatch(object, source, matchData, customizer) {
3394 var index = matchData.length,
3395 length = index,
3396 noCustomizer = !customizer;
3397
3398 if (object == null) {
3399 return !length;
3400 }
3401 object = Object(object);
3402 while (index--) {
3403 var data = matchData[index];
3404 if ((noCustomizer && data[2])
3405 ? data[1] !== object[data[0]]
3406 : !(data[0] in object)
3407 ) {
3408 return false;
3409 }
3410 }
3411 while (++index < length) {
3412 data = matchData[index];
3413 var key = data[0],
3414 objValue = object[key],
3415 srcValue = data[1];
3416
3417 if (noCustomizer && data[2]) {
3418 if (objValue === undefined && !(key in object)) {
3419 return false;
3420 }
3421 } else {
3422 var stack = new Stack;
3423 if (customizer) {
3424 var result = customizer(objValue, srcValue, key, object, source, stack);
3425 }
3426 if (!(result === undefined
3427 ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
3428 : result
3429 )) {
3430 return false;
3431 }
3432 }
3433 }
3434 return true;
3435 }
3436
3437 /**
3438 * The base implementation of `_.isNative` without bad shim checks.
3439 *
3440 * @private
3441 * @param {*} value The value to check.
3442 * @returns {boolean} Returns `true` if `value` is a native function,
3443 * else `false`.
3444 */
3445 function baseIsNative(value) {
3446 if (!isObject(value) || isMasked(value)) {
3447 return false;
3448 }
3449 var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3450 return pattern.test(toSource(value));
3451 }
3452
3453 /**
3454 * The base implementation of `_.isRegExp` without Node.js optimizations.
3455 *
3456 * @private
3457 * @param {*} value The value to check.
3458 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
3459 */
3460 function baseIsRegExp(value) {
3461 return isObjectLike(value) && baseGetTag(value) == regexpTag;
3462 }
3463
3464 /**
3465 * The base implementation of `_.isSet` without Node.js optimizations.
3466 *
3467 * @private
3468 * @param {*} value The value to check.
3469 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
3470 */
3471 function baseIsSet(value) {
3472 return isObjectLike(value) && getTag(value) == setTag;
3473 }
3474
3475 /**
3476 * The base implementation of `_.isTypedArray` without Node.js optimizations.
3477 *
3478 * @private
3479 * @param {*} value The value to check.
3480 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
3481 */
3482 function baseIsTypedArray(value) {
3483 return isObjectLike(value) &&
3484 isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
3485 }
3486
3487 /**
3488 * The base implementation of `_.iteratee`.
3489 *
3490 * @private
3491 * @param {*} [value=_.identity] The value to convert to an iteratee.
3492 * @returns {Function} Returns the iteratee.
3493 */
3494 function baseIteratee(value) {
3495 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
3496 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
3497 if (typeof value == 'function') {
3498 return value;
3499 }
3500 if (value == null) {
3501 return identity;
3502 }
3503 if (typeof value == 'object') {
3504 return isArray(value)
3505 ? baseMatchesProperty(value[0], value[1])
3506 : baseMatches(value);
3507 }
3508 return property(value);
3509 }
3510
3511 /**
3512 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
3513 *
3514 * @private
3515 * @param {Object} object The object to query.
3516 * @returns {Array} Returns the array of property names.
3517 */
3518 function baseKeys(object) {
3519 if (!isPrototype(object)) {
3520 return nativeKeys(object);
3521 }
3522 var result = [];
3523 for (var key in Object(object)) {
3524 if (hasOwnProperty.call(object, key) && key != 'constructor') {
3525 result.push(key);
3526 }
3527 }
3528 return result;
3529 }
3530
3531 /**
3532 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
3533 *
3534 * @private
3535 * @param {Object} object The object to query.
3536 * @returns {Array} Returns the array of property names.
3537 */
3538 function baseKeysIn(object) {
3539 if (!isObject(object)) {
3540 return nativeKeysIn(object);
3541 }
3542 var isProto = isPrototype(object),
3543 result = [];
3544
3545 for (var key in object) {
3546 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3547 result.push(key);
3548 }
3549 }
3550 return result;
3551 }
3552
3553 /**
3554 * The base implementation of `_.lt` which doesn't coerce arguments.
3555 *
3556 * @private
3557 * @param {*} value The value to compare.
3558 * @param {*} other The other value to compare.
3559 * @returns {boolean} Returns `true` if `value` is less than `other`,
3560 * else `false`.
3561 */
3562 function baseLt(value, other) {
3563 return value < other;
3564 }
3565
3566 /**
3567 * The base implementation of `_.map` without support for iteratee shorthands.
3568 *
3569 * @private
3570 * @param {Array|Object} collection The collection to iterate over.
3571 * @param {Function} iteratee The function invoked per iteration.
3572 * @returns {Array} Returns the new mapped array.
3573 */
3574 function baseMap(collection, iteratee) {
3575 var index = -1,
3576 result = isArrayLike(collection) ? Array(collection.length) : [];
3577
3578 baseEach(collection, function(value, key, collection) {
3579 result[++index] = iteratee(value, key, collection);
3580 });
3581 return result;
3582 }
3583
3584 /**
3585 * The base implementation of `_.matches` which doesn't clone `source`.
3586 *
3587 * @private
3588 * @param {Object} source The object of property values to match.
3589 * @returns {Function} Returns the new spec function.
3590 */
3591 function baseMatches(source) {
3592 var matchData = getMatchData(source);
3593 if (matchData.length == 1 && matchData[0][2]) {
3594 return matchesStrictComparable(matchData[0][0], matchData[0][1]);
3595 }
3596 return function(object) {
3597 return object === source || baseIsMatch(object, source, matchData);
3598 };
3599 }
3600
3601 /**
3602 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3603 *
3604 * @private
3605 * @param {string} path The path of the property to get.
3606 * @param {*} srcValue The value to match.
3607 * @returns {Function} Returns the new spec function.
3608 */
3609 function baseMatchesProperty(path, srcValue) {
3610 if (isKey(path) && isStrictComparable(srcValue)) {
3611 return matchesStrictComparable(toKey(path), srcValue);
3612 }
3613 return function(object) {
3614 var objValue = get(object, path);
3615 return (objValue === undefined && objValue === srcValue)
3616 ? hasIn(object, path)
3617 : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
3618 };
3619 }
3620
3621 /**
3622 * The base implementation of `_.merge` without support for multiple sources.
3623 *
3624 * @private
3625 * @param {Object} object The destination object.
3626 * @param {Object} source The source object.
3627 * @param {number} srcIndex The index of `source`.
3628 * @param {Function} [customizer] The function to customize merged values.
3629 * @param {Object} [stack] Tracks traversed source values and their merged
3630 * counterparts.
3631 */
3632 function baseMerge(object, source, srcIndex, customizer, stack) {
3633 if (object === source) {
3634 return;
3635 }
3636 baseFor(source, function(srcValue, key) {
3637 if (isObject(srcValue)) {
3638 stack || (stack = new Stack);
3639 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3640 }
3641 else {
3642 var newValue = customizer
3643 ? customizer(object[key], srcValue, (key + ''), object, source, stack)
3644 : undefined;
3645
3646 if (newValue === undefined) {
3647 newValue = srcValue;
3648 }
3649 assignMergeValue(object, key, newValue);
3650 }
3651 }, keysIn);
3652 }
3653
3654 /**
3655 * A specialized version of `baseMerge` for arrays and objects which performs
3656 * deep merges and tracks traversed objects enabling objects with circular
3657 * references to be merged.
3658 *
3659 * @private
3660 * @param {Object} object The destination object.
3661 * @param {Object} source The source object.
3662 * @param {string} key The key of the value to merge.
3663 * @param {number} srcIndex The index of `source`.
3664 * @param {Function} mergeFunc The function to merge values.
3665 * @param {Function} [customizer] The function to customize assigned values.
3666 * @param {Object} [stack] Tracks traversed source values and their merged
3667 * counterparts.
3668 */
3669 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3670 var objValue = object[key],
3671 srcValue = source[key],
3672 stacked = stack.get(srcValue);
3673
3674 if (stacked) {
3675 assignMergeValue(object, key, stacked);
3676 return;
3677 }
3678 var newValue = customizer
3679 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3680 : undefined;
3681
3682 var isCommon = newValue === undefined;
3683
3684 if (isCommon) {
3685 var isArr = isArray(srcValue),
3686 isBuff = !isArr && isBuffer(srcValue),
3687 isTyped = !isArr && !isBuff && isTypedArray(srcValue);
3688
3689 newValue = srcValue;
3690 if (isArr || isBuff || isTyped) {
3691 if (isArray(objValue)) {
3692 newValue = objValue;
3693 }
3694 else if (isArrayLikeObject(objValue)) {
3695 newValue = copyArray(objValue);
3696 }
3697 else if (isBuff) {
3698 isCommon = false;
3699 newValue = cloneBuffer(srcValue, true);
3700 }
3701 else if (isTyped) {
3702 isCommon = false;
3703 newValue = cloneTypedArray(srcValue, true);
3704 }
3705 else {
3706 newValue = [];
3707 }
3708 }
3709 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3710 newValue = objValue;
3711 if (isArguments(objValue)) {
3712 newValue = toPlainObject(objValue);
3713 }
3714 else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
3715 newValue = initCloneObject(srcValue);
3716 }
3717 }
3718 else {
3719 isCommon = false;
3720 }
3721 }
3722 if (isCommon) {
3723 // Recursively merge objects and arrays (susceptible to call stack limits).
3724 stack.set(srcValue, newValue);
3725 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3726 stack['delete'](srcValue);
3727 }
3728 assignMergeValue(object, key, newValue);
3729 }
3730
3731 /**
3732 * The base implementation of `_.nth` which doesn't coerce arguments.
3733 *
3734 * @private
3735 * @param {Array} array The array to query.
3736 * @param {number} n The index of the element to return.
3737 * @returns {*} Returns the nth element of `array`.
3738 */
3739 function baseNth(array, n) {
3740 var length = array.length;
3741 if (!length) {
3742 return;
3743 }
3744 n += n < 0 ? length : 0;
3745 return isIndex(n, length) ? array[n] : undefined;
3746 }
3747
3748 /**
3749 * The base implementation of `_.orderBy` without param guards.
3750 *
3751 * @private
3752 * @param {Array|Object} collection The collection to iterate over.
3753 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3754 * @param {string[]} orders The sort orders of `iteratees`.
3755 * @returns {Array} Returns the new sorted array.
3756 */
3757 function baseOrderBy(collection, iteratees, orders) {
3758 var index = -1;
3759 iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
3760
3761 var result = baseMap(collection, function(value, key, collection) {
3762 var criteria = arrayMap(iteratees, function(iteratee) {
3763 return iteratee(value);
3764 });
3765 return { 'criteria': criteria, 'index': ++index, 'value': value };
3766 });
3767
3768 return baseSortBy(result, function(object, other) {
3769 return compareMultiple(object, other, orders);
3770 });
3771 }
3772
3773 /**
3774 * The base implementation of `_.pick` without support for individual
3775 * property identifiers.
3776 *
3777 * @private
3778 * @param {Object} object The source object.
3779 * @param {string[]} paths The property paths to pick.
3780 * @returns {Object} Returns the new object.
3781 */
3782 function basePick(object, paths) {
3783 object = Object(object);
3784 return basePickBy(object, paths, function(value, path) {
3785 return hasIn(object, path);
3786 });
3787 }
3788
3789 /**
3790 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3791 *
3792 * @private
3793 * @param {Object} object The source object.
3794 * @param {string[]} paths The property paths to pick.
3795 * @param {Function} predicate The function invoked per property.
3796 * @returns {Object} Returns the new object.
3797 */
3798 function basePickBy(object, paths, predicate) {
3799 var index = -1,
3800 length = paths.length,
3801 result = {};
3802
3803 while (++index < length) {
3804 var path = paths[index],
3805 value = baseGet(object, path);
3806
3807 if (predicate(value, path)) {
3808 baseSet(result, castPath(path, object), value);
3809 }
3810 }
3811 return result;
3812 }
3813
3814 /**
3815 * A specialized version of `baseProperty` which supports deep paths.
3816 *
3817 * @private
3818 * @param {Array|string} path The path of the property to get.
3819 * @returns {Function} Returns the new accessor function.
3820 */
3821 function basePropertyDeep(path) {
3822 return function(object) {
3823 return baseGet(object, path);
3824 };
3825 }
3826
3827 /**
3828 * The base implementation of `_.pullAllBy` without support for iteratee
3829 * shorthands.
3830 *
3831 * @private
3832 * @param {Array} array The array to modify.
3833 * @param {Array} values The values to remove.
3834 * @param {Function} [iteratee] The iteratee invoked per element.
3835 * @param {Function} [comparator] The comparator invoked per element.
3836 * @returns {Array} Returns `array`.
3837 */
3838 function basePullAll(array, values, iteratee, comparator) {
3839 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
3840 index = -1,
3841 length = values.length,
3842 seen = array;
3843
3844 if (array === values) {
3845 values = copyArray(values);
3846 }
3847 if (iteratee) {
3848 seen = arrayMap(array, baseUnary(iteratee));
3849 }
3850 while (++index < length) {
3851 var fromIndex = 0,
3852 value = values[index],
3853 computed = iteratee ? iteratee(value) : value;
3854
3855 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
3856 if (seen !== array) {
3857 splice.call(seen, fromIndex, 1);
3858 }
3859 splice.call(array, fromIndex, 1);
3860 }
3861 }
3862 return array;
3863 }
3864
3865 /**
3866 * The base implementation of `_.pullAt` without support for individual
3867 * indexes or capturing the removed elements.
3868 *
3869 * @private
3870 * @param {Array} array The array to modify.
3871 * @param {number[]} indexes The indexes of elements to remove.
3872 * @returns {Array} Returns `array`.
3873 */
3874 function basePullAt(array, indexes) {
3875 var length = array ? indexes.length : 0,
3876 lastIndex = length - 1;
3877
3878 while (length--) {
3879 var index = indexes[length];
3880 if (length == lastIndex || index !== previous) {
3881 var previous = index;
3882 if (isIndex(index)) {
3883 splice.call(array, index, 1);
3884 } else {
3885 baseUnset(array, index);
3886 }
3887 }
3888 }
3889 return array;
3890 }
3891
3892 /**
3893 * The base implementation of `_.random` without support for returning
3894 * floating-point numbers.
3895 *
3896 * @private
3897 * @param {number} lower The lower bound.
3898 * @param {number} upper The upper bound.
3899 * @returns {number} Returns the random number.
3900 */
3901 function baseRandom(lower, upper) {
3902 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3903 }
3904
3905 /**
3906 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3907 * coerce arguments.
3908 *
3909 * @private
3910 * @param {number} start The start of the range.
3911 * @param {number} end The end of the range.
3912 * @param {number} step The value to increment or decrement by.
3913 * @param {boolean} [fromRight] Specify iterating from right to left.
3914 * @returns {Array} Returns the range of numbers.
3915 */
3916 function baseRange(start, end, step, fromRight) {
3917 var index = -1,
3918 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3919 result = Array(length);
3920
3921 while (length--) {
3922 result[fromRight ? length : ++index] = start;
3923 start += step;
3924 }
3925 return result;
3926 }
3927
3928 /**
3929 * The base implementation of `_.repeat` which doesn't coerce arguments.
3930 *
3931 * @private
3932 * @param {string} string The string to repeat.
3933 * @param {number} n The number of times to repeat the string.
3934 * @returns {string} Returns the repeated string.
3935 */
3936 function baseRepeat(string, n) {
3937 var result = '';
3938 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
3939 return result;
3940 }
3941 // Leverage the exponentiation by squaring algorithm for a faster repeat.
3942 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
3943 do {
3944 if (n % 2) {
3945 result += string;
3946 }
3947 n = nativeFloor(n / 2);
3948 if (n) {
3949 string += string;
3950 }
3951 } while (n);
3952
3953 return result;
3954 }
3955
3956 /**
3957 * The base implementation of `_.rest` which doesn't validate or coerce arguments.
3958 *
3959 * @private
3960 * @param {Function} func The function to apply a rest parameter to.
3961 * @param {number} [start=func.length-1] The start position of the rest parameter.
3962 * @returns {Function} Returns the new function.
3963 */
3964 function baseRest(func, start) {
3965 return setToString(overRest(func, start, identity), func + '');
3966 }
3967
3968 /**
3969 * The base implementation of `_.sample`.
3970 *
3971 * @private
3972 * @param {Array|Object} collection The collection to sample.
3973 * @returns {*} Returns the random element.
3974 */
3975 function baseSample(collection) {
3976 return arraySample(values(collection));
3977 }
3978
3979 /**
3980 * The base implementation of `_.sampleSize` without param guards.
3981 *
3982 * @private
3983 * @param {Array|Object} collection The collection to sample.
3984 * @param {number} n The number of elements to sample.
3985 * @returns {Array} Returns the random elements.
3986 */
3987 function baseSampleSize(collection, n) {
3988 var array = values(collection);
3989 return shuffleSelf(array, baseClamp(n, 0, array.length));
3990 }
3991
3992 /**
3993 * The base implementation of `_.set`.
3994 *
3995 * @private
3996 * @param {Object} object The object to modify.
3997 * @param {Array|string} path The path of the property to set.
3998 * @param {*} value The value to set.
3999 * @param {Function} [customizer] The function to customize path creation.
4000 * @returns {Object} Returns `object`.
4001 */
4002 function baseSet(object, path, value, customizer) {
4003 if (!isObject(object)) {
4004 return object;
4005 }
4006 path = castPath(path, object);
4007
4008 var index = -1,
4009 length = path.length,
4010 lastIndex = length - 1,
4011 nested = object;
4012
4013 while (nested != null && ++index < length) {
4014 var key = toKey(path[index]),
4015 newValue = value;
4016
4017 if (index != lastIndex) {
4018 var objValue = nested[key];
4019 newValue = customizer ? customizer(objValue, key, nested) : undefined;
4020 if (newValue === undefined) {
4021 newValue = isObject(objValue)
4022 ? objValue
4023 : (isIndex(path[index + 1]) ? [] : {});
4024 }
4025 }
4026 assignValue(nested, key, newValue);
4027 nested = nested[key];
4028 }
4029 return object;
4030 }
4031
4032 /**
4033 * The base implementation of `setData` without support for hot loop shorting.
4034 *
4035 * @private
4036 * @param {Function} func The function to associate metadata with.
4037 * @param {*} data The metadata.
4038 * @returns {Function} Returns `func`.
4039 */
4040 var baseSetData = !metaMap ? identity : function(func, data) {
4041 metaMap.set(func, data);
4042 return func;
4043 };
4044
4045 /**
4046 * The base implementation of `setToString` without support for hot loop shorting.
4047 *
4048 * @private
4049 * @param {Function} func The function to modify.
4050 * @param {Function} string The `toString` result.
4051 * @returns {Function} Returns `func`.
4052 */
4053 var baseSetToString = !defineProperty ? identity : function(func, string) {
4054 return defineProperty(func, 'toString', {
4055 'configurable': true,
4056 'enumerable': false,
4057 'value': constant(string),
4058 'writable': true
4059 });
4060 };
4061
4062 /**
4063 * The base implementation of `_.shuffle`.
4064 *
4065 * @private
4066 * @param {Array|Object} collection The collection to shuffle.
4067 * @returns {Array} Returns the new shuffled array.
4068 */
4069 function baseShuffle(collection) {
4070 return shuffleSelf(values(collection));
4071 }
4072
4073 /**
4074 * The base implementation of `_.slice` without an iteratee call guard.
4075 *
4076 * @private
4077 * @param {Array} array The array to slice.
4078 * @param {number} [start=0] The start position.
4079 * @param {number} [end=array.length] The end position.
4080 * @returns {Array} Returns the slice of `array`.
4081 */
4082 function baseSlice(array, start, end) {
4083 var index = -1,
4084 length = array.length;
4085
4086 if (start < 0) {
4087 start = -start > length ? 0 : (length + start);
4088 }
4089 end = end > length ? length : end;
4090 if (end < 0) {
4091 end += length;
4092 }
4093 length = start > end ? 0 : ((end - start) >>> 0);
4094 start >>>= 0;
4095
4096 var result = Array(length);
4097 while (++index < length) {
4098 result[index] = array[index + start];
4099 }
4100 return result;
4101 }
4102
4103 /**
4104 * The base implementation of `_.some` without support for iteratee shorthands.
4105 *
4106 * @private
4107 * @param {Array|Object} collection The collection to iterate over.
4108 * @param {Function} predicate The function invoked per iteration.
4109 * @returns {boolean} Returns `true` if any element passes the predicate check,
4110 * else `false`.
4111 */
4112 function baseSome(collection, predicate) {
4113 var result;
4114
4115 baseEach(collection, function(value, index, collection) {
4116 result = predicate(value, index, collection);
4117 return !result;
4118 });
4119 return !!result;
4120 }
4121
4122 /**
4123 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
4124 * performs a binary search of `array` to determine the index at which `value`
4125 * should be inserted into `array` in order to maintain its sort order.
4126 *
4127 * @private
4128 * @param {Array} array The sorted array to inspect.
4129 * @param {*} value The value to evaluate.
4130 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4131 * @returns {number} Returns the index at which `value` should be inserted
4132 * into `array`.
4133 */
4134 function baseSortedIndex(array, value, retHighest) {
4135 var low = 0,
4136 high = array == null ? low : array.length;
4137
4138 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
4139 while (low < high) {
4140 var mid = (low + high) >>> 1,
4141 computed = array[mid];
4142
4143 if (computed !== null && !isSymbol(computed) &&
4144 (retHighest ? (computed <= value) : (computed < value))) {
4145 low = mid + 1;
4146 } else {
4147 high = mid;
4148 }
4149 }
4150 return high;
4151 }
4152 return baseSortedIndexBy(array, value, identity, retHighest);
4153 }
4154
4155 /**
4156 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
4157 * which invokes `iteratee` for `value` and each element of `array` to compute
4158 * their sort ranking. The iteratee is invoked with one argument; (value).
4159 *
4160 * @private
4161 * @param {Array} array The sorted array to inspect.
4162 * @param {*} value The value to evaluate.
4163 * @param {Function} iteratee The iteratee invoked per element.
4164 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4165 * @returns {number} Returns the index at which `value` should be inserted
4166 * into `array`.
4167 */
4168 function baseSortedIndexBy(array, value, iteratee, retHighest) {
4169 value = iteratee(value);
4170
4171 var low = 0,
4172 high = array == null ? 0 : array.length,
4173 valIsNaN = value !== value,
4174 valIsNull = value === null,
4175 valIsSymbol = isSymbol(value),
4176 valIsUndefined = value === undefined;
4177
4178 while (low < high) {
4179 var mid = nativeFloor((low + high) / 2),
4180 computed = iteratee(array[mid]),
4181 othIsDefined = computed !== undefined,
4182 othIsNull = computed === null,
4183 othIsReflexive = computed === computed,
4184 othIsSymbol = isSymbol(computed);
4185
4186 if (valIsNaN) {
4187 var setLow = retHighest || othIsReflexive;
4188 } else if (valIsUndefined) {
4189 setLow = othIsReflexive && (retHighest || othIsDefined);
4190 } else if (valIsNull) {
4191 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
4192 } else if (valIsSymbol) {
4193 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
4194 } else if (othIsNull || othIsSymbol) {
4195 setLow = false;
4196 } else {
4197 setLow = retHighest ? (computed <= value) : (computed < value);
4198 }
4199 if (setLow) {
4200 low = mid + 1;
4201 } else {
4202 high = mid;
4203 }
4204 }
4205 return nativeMin(high, MAX_ARRAY_INDEX);
4206 }
4207
4208 /**
4209 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
4210 * support for iteratee shorthands.
4211 *
4212 * @private
4213 * @param {Array} array The array to inspect.
4214 * @param {Function} [iteratee] The iteratee invoked per element.
4215 * @returns {Array} Returns the new duplicate free array.
4216 */
4217 function baseSortedUniq(array, iteratee) {
4218 var index = -1,
4219 length = array.length,
4220 resIndex = 0,
4221 result = [];
4222
4223 while (++index < length) {
4224 var value = array[index],
4225 computed = iteratee ? iteratee(value) : value;
4226
4227 if (!index || !eq(computed, seen)) {
4228 var seen = computed;
4229 result[resIndex++] = value === 0 ? 0 : value;
4230 }
4231 }
4232 return result;
4233 }
4234
4235 /**
4236 * The base implementation of `_.toNumber` which doesn't ensure correct
4237 * conversions of binary, hexadecimal, or octal string values.
4238 *
4239 * @private
4240 * @param {*} value The value to process.
4241 * @returns {number} Returns the number.
4242 */
4243 function baseToNumber(value) {
4244 if (typeof value == 'number') {
4245 return value;
4246 }
4247 if (isSymbol(value)) {
4248 return NAN;
4249 }
4250 return +value;
4251 }
4252
4253 /**
4254 * The base implementation of `_.toString` which doesn't convert nullish
4255 * values to empty strings.
4256 *
4257 * @private
4258 * @param {*} value The value to process.
4259 * @returns {string} Returns the string.
4260 */
4261 function baseToString(value) {
4262 // Exit early for strings to avoid a performance hit in some environments.
4263 if (typeof value == 'string') {
4264 return value;
4265 }
4266 if (isArray(value)) {
4267 // Recursively convert values (susceptible to call stack limits).
4268 return arrayMap(value, baseToString) + '';
4269 }
4270 if (isSymbol(value)) {
4271 return symbolToString ? symbolToString.call(value) : '';
4272 }
4273 var result = (value + '');
4274 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
4275 }
4276
4277 /**
4278 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
4279 *
4280 * @private
4281 * @param {Array} array The array to inspect.
4282 * @param {Function} [iteratee] The iteratee invoked per element.
4283 * @param {Function} [comparator] The comparator invoked per element.
4284 * @returns {Array} Returns the new duplicate free array.
4285 */
4286 function baseUniq(array, iteratee, comparator) {
4287 var index = -1,
4288 includes = arrayIncludes,
4289 length = array.length,
4290 isCommon = true,
4291 result = [],
4292 seen = result;
4293
4294 if (comparator) {
4295 isCommon = false;
4296 includes = arrayIncludesWith;
4297 }
4298 else if (length >= LARGE_ARRAY_SIZE) {
4299 var set = iteratee ? null : createSet(array);
4300 if (set) {
4301 return setToArray(set);
4302 }
4303 isCommon = false;
4304 includes = cacheHas;
4305 seen = new SetCache;
4306 }
4307 else {
4308 seen = iteratee ? [] : result;
4309 }
4310 outer:
4311 while (++index < length) {
4312 var value = array[index],
4313 computed = iteratee ? iteratee(value) : value;
4314
4315 value = (comparator || value !== 0) ? value : 0;
4316 if (isCommon && computed === computed) {
4317 var seenIndex = seen.length;
4318 while (seenIndex--) {
4319 if (seen[seenIndex] === computed) {
4320 continue outer;
4321 }
4322 }
4323 if (iteratee) {
4324 seen.push(computed);
4325 }
4326 result.push(value);
4327 }
4328 else if (!includes(seen, computed, comparator)) {
4329 if (seen !== result) {
4330 seen.push(computed);
4331 }
4332 result.push(value);
4333 }
4334 }
4335 return result;
4336 }
4337
4338 /**
4339 * The base implementation of `_.unset`.
4340 *
4341 * @private
4342 * @param {Object} object The object to modify.
4343 * @param {Array|string} path The property path to unset.
4344 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
4345 */
4346 function baseUnset(object, path) {
4347 path = castPath(path, object);
4348 object = parent(object, path);
4349 return object == null || delete object[toKey(last(path))];
4350 }
4351
4352 /**
4353 * The base implementation of `_.update`.
4354 *
4355 * @private
4356 * @param {Object} object The object to modify.
4357 * @param {Array|string} path The path of the property to update.
4358 * @param {Function} updater The function to produce the updated value.
4359 * @param {Function} [customizer] The function to customize path creation.
4360 * @returns {Object} Returns `object`.
4361 */
4362 function baseUpdate(object, path, updater, customizer) {
4363 return baseSet(object, path, updater(baseGet(object, path)), customizer);
4364 }
4365
4366 /**
4367 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
4368 * without support for iteratee shorthands.
4369 *
4370 * @private
4371 * @param {Array} array The array to query.
4372 * @param {Function} predicate The function invoked per iteration.
4373 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
4374 * @param {boolean} [fromRight] Specify iterating from right to left.
4375 * @returns {Array} Returns the slice of `array`.
4376 */
4377 function baseWhile(array, predicate, isDrop, fromRight) {
4378 var length = array.length,
4379 index = fromRight ? length : -1;
4380
4381 while ((fromRight ? index-- : ++index < length) &&
4382 predicate(array[index], index, array)) {}
4383
4384 return isDrop
4385 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
4386 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
4387 }
4388
4389 /**
4390 * The base implementation of `wrapperValue` which returns the result of
4391 * performing a sequence of actions on the unwrapped `value`, where each
4392 * successive action is supplied the return value of the previous.
4393 *
4394 * @private
4395 * @param {*} value The unwrapped value.
4396 * @param {Array} actions Actions to perform to resolve the unwrapped value.
4397 * @returns {*} Returns the resolved value.
4398 */
4399 function baseWrapperValue(value, actions) {
4400 var result = value;
4401 if (result instanceof LazyWrapper) {
4402 result = result.value();
4403 }
4404 return arrayReduce(actions, function(result, action) {
4405 return action.func.apply(action.thisArg, arrayPush([result], action.args));
4406 }, result);
4407 }
4408
4409 /**
4410 * The base implementation of methods like `_.xor`, without support for
4411 * iteratee shorthands, that accepts an array of arrays to inspect.
4412 *
4413 * @private
4414 * @param {Array} arrays The arrays to inspect.
4415 * @param {Function} [iteratee] The iteratee invoked per element.
4416 * @param {Function} [comparator] The comparator invoked per element.
4417 * @returns {Array} Returns the new array of values.
4418 */
4419 function baseXor(arrays, iteratee, comparator) {
4420 var length = arrays.length;
4421 if (length < 2) {
4422 return length ? baseUniq(arrays[0]) : [];
4423 }
4424 var index = -1,
4425 result = Array(length);
4426
4427 while (++index < length) {
4428 var array = arrays[index],
4429 othIndex = -1;
4430
4431 while (++othIndex < length) {
4432 if (othIndex != index) {
4433 result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
4434 }
4435 }
4436 }
4437 return baseUniq(baseFlatten(result, 1), iteratee, comparator);
4438 }
4439
4440 /**
4441 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
4442 *
4443 * @private
4444 * @param {Array} props The property identifiers.
4445 * @param {Array} values The property values.
4446 * @param {Function} assignFunc The function to assign values.
4447 * @returns {Object} Returns the new object.
4448 */
4449 function baseZipObject(props, values, assignFunc) {
4450 var index = -1,
4451 length = props.length,
4452 valsLength = values.length,
4453 result = {};
4454
4455 while (++index < length) {
4456 var value = index < valsLength ? values[index] : undefined;
4457 assignFunc(result, props[index], value);
4458 }
4459 return result;
4460 }
4461
4462 /**
4463 * Casts `value` to an empty array if it's not an array like object.
4464 *
4465 * @private
4466 * @param {*} value The value to inspect.
4467 * @returns {Array|Object} Returns the cast array-like object.
4468 */
4469 function castArrayLikeObject(value) {
4470 return isArrayLikeObject(value) ? value : [];
4471 }
4472
4473 /**
4474 * Casts `value` to `identity` if it's not a function.
4475 *
4476 * @private
4477 * @param {*} value The value to inspect.
4478 * @returns {Function} Returns cast function.
4479 */
4480 function castFunction(value) {
4481 return typeof value == 'function' ? value : identity;
4482 }
4483
4484 /**
4485 * Casts `value` to a path array if it's not one.
4486 *
4487 * @private
4488 * @param {*} value The value to inspect.
4489 * @param {Object} [object] The object to query keys on.
4490 * @returns {Array} Returns the cast property path array.
4491 */
4492 function castPath(value, object) {
4493 if (isArray(value)) {
4494 return value;
4495 }
4496 return isKey(value, object) ? [value] : stringToPath(toString(value));
4497 }
4498
4499 /**
4500 * A `baseRest` alias which can be replaced with `identity` by module
4501 * replacement plugins.
4502 *
4503 * @private
4504 * @type {Function}
4505 * @param {Function} func The function to apply a rest parameter to.
4506 * @returns {Function} Returns the new function.
4507 */
4508 var castRest = baseRest;
4509
4510 /**
4511 * Casts `array` to a slice if it's needed.
4512 *
4513 * @private
4514 * @param {Array} array The array to inspect.
4515 * @param {number} start The start position.
4516 * @param {number} [end=array.length] The end position.
4517 * @returns {Array} Returns the cast slice.
4518 */
4519 function castSlice(array, start, end) {
4520 var length = array.length;
4521 end = end === undefined ? length : end;
4522 return (!start && end >= length) ? array : baseSlice(array, start, end);
4523 }
4524
4525 /**
4526 * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
4527 *
4528 * @private
4529 * @param {number|Object} id The timer id or timeout object of the timer to clear.
4530 */
4531 var clearTimeout = ctxClearTimeout || function(id) {
4532 return root.clearTimeout(id);
4533 };
4534
4535 /**
4536 * Creates a clone of `buffer`.
4537 *
4538 * @private
4539 * @param {Buffer} buffer The buffer to clone.
4540 * @param {boolean} [isDeep] Specify a deep clone.
4541 * @returns {Buffer} Returns the cloned buffer.
4542 */
4543 function cloneBuffer(buffer, isDeep) {
4544 if (isDeep) {
4545 return buffer.slice();
4546 }
4547 var length = buffer.length,
4548 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
4549
4550 buffer.copy(result);
4551 return result;
4552 }
4553
4554 /**
4555 * Creates a clone of `arrayBuffer`.
4556 *
4557 * @private
4558 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
4559 * @returns {ArrayBuffer} Returns the cloned array buffer.
4560 */
4561 function cloneArrayBuffer(arrayBuffer) {
4562 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
4563 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
4564 return result;
4565 }
4566
4567 /**
4568 * Creates a clone of `dataView`.
4569 *
4570 * @private
4571 * @param {Object} dataView The data view to clone.
4572 * @param {boolean} [isDeep] Specify a deep clone.
4573 * @returns {Object} Returns the cloned data view.
4574 */
4575 function cloneDataView(dataView, isDeep) {
4576 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
4577 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
4578 }
4579
4580 /**
4581 * Creates a clone of `map`.
4582 *
4583 * @private
4584 * @param {Object} map The map to clone.
4585 * @param {Function} cloneFunc The function to clone values.
4586 * @param {boolean} [isDeep] Specify a deep clone.
4587 * @returns {Object} Returns the cloned map.
4588 */
4589 function cloneMap(map, isDeep, cloneFunc) {
4590 var array = isDeep ? cloneFunc(mapToArray(map), CLONE_DEEP_FLAG) : mapToArray(map);
4591 return arrayReduce(array, addMapEntry, new map.constructor);
4592 }
4593
4594 /**
4595 * Creates a clone of `regexp`.
4596 *
4597 * @private
4598 * @param {Object} regexp The regexp to clone.
4599 * @returns {Object} Returns the cloned regexp.
4600 */
4601 function cloneRegExp(regexp) {
4602 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
4603 result.lastIndex = regexp.lastIndex;
4604 return result;
4605 }
4606
4607 /**
4608 * Creates a clone of `set`.
4609 *
4610 * @private
4611 * @param {Object} set The set to clone.
4612 * @param {Function} cloneFunc The function to clone values.
4613 * @param {boolean} [isDeep] Specify a deep clone.
4614 * @returns {Object} Returns the cloned set.
4615 */
4616 function cloneSet(set, isDeep, cloneFunc) {
4617 var array = isDeep ? cloneFunc(setToArray(set), CLONE_DEEP_FLAG) : setToArray(set);
4618 return arrayReduce(array, addSetEntry, new set.constructor);
4619 }
4620
4621 /**
4622 * Creates a clone of the `symbol` object.
4623 *
4624 * @private
4625 * @param {Object} symbol The symbol object to clone.
4626 * @returns {Object} Returns the cloned symbol object.
4627 */
4628 function cloneSymbol(symbol) {
4629 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
4630 }
4631
4632 /**
4633 * Creates a clone of `typedArray`.
4634 *
4635 * @private
4636 * @param {Object} typedArray The typed array to clone.
4637 * @param {boolean} [isDeep] Specify a deep clone.
4638 * @returns {Object} Returns the cloned typed array.
4639 */
4640 function cloneTypedArray(typedArray, isDeep) {
4641 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
4642 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
4643 }
4644
4645 /**
4646 * Compares values to sort them in ascending order.
4647 *
4648 * @private
4649 * @param {*} value The value to compare.
4650 * @param {*} other The other value to compare.
4651 * @returns {number} Returns the sort order indicator for `value`.
4652 */
4653 function compareAscending(value, other) {
4654 if (value !== other) {
4655 var valIsDefined = value !== undefined,
4656 valIsNull = value === null,
4657 valIsReflexive = value === value,
4658 valIsSymbol = isSymbol(value);
4659
4660 var othIsDefined = other !== undefined,
4661 othIsNull = other === null,
4662 othIsReflexive = other === other,
4663 othIsSymbol = isSymbol(other);
4664
4665 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
4666 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
4667 (valIsNull && othIsDefined && othIsReflexive) ||
4668 (!valIsDefined && othIsReflexive) ||
4669 !valIsReflexive) {
4670 return 1;
4671 }
4672 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
4673 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
4674 (othIsNull && valIsDefined && valIsReflexive) ||
4675 (!othIsDefined && valIsReflexive) ||
4676 !othIsReflexive) {
4677 return -1;
4678 }
4679 }
4680 return 0;
4681 }
4682
4683 /**
4684 * Used by `_.orderBy` to compare multiple properties of a value to another
4685 * and stable sort them.
4686 *
4687 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
4688 * specify an order of "desc" for descending or "asc" for ascending sort order
4689 * of corresponding values.
4690 *
4691 * @private
4692 * @param {Object} object The object to compare.
4693 * @param {Object} other The other object to compare.
4694 * @param {boolean[]|string[]} orders The order to sort by for each property.
4695 * @returns {number} Returns the sort order indicator for `object`.
4696 */
4697 function compareMultiple(object, other, orders) {
4698 var index = -1,
4699 objCriteria = object.criteria,
4700 othCriteria = other.criteria,
4701 length = objCriteria.length,
4702 ordersLength = orders.length;
4703
4704 while (++index < length) {
4705 var result = compareAscending(objCriteria[index], othCriteria[index]);
4706 if (result) {
4707 if (index >= ordersLength) {
4708 return result;
4709 }
4710 var order = orders[index];
4711 return result * (order == 'desc' ? -1 : 1);
4712 }
4713 }
4714 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
4715 // that causes it, under certain circumstances, to provide the same value for
4716 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
4717 // for more details.
4718 //
4719 // This also ensures a stable sort in V8 and other engines.
4720 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
4721 return object.index - other.index;
4722 }
4723
4724 /**
4725 * Creates an array that is the composition of partially applied arguments,
4726 * placeholders, and provided arguments into a single array of arguments.
4727 *
4728 * @private
4729 * @param {Array} args The provided arguments.
4730 * @param {Array} partials The arguments to prepend to those provided.
4731 * @param {Array} holders The `partials` placeholder indexes.
4732 * @params {boolean} [isCurried] Specify composing for a curried function.
4733 * @returns {Array} Returns the new array of composed arguments.
4734 */
4735 function composeArgs(args, partials, holders, isCurried) {
4736 var argsIndex = -1,
4737 argsLength = args.length,
4738 holdersLength = holders.length,
4739 leftIndex = -1,
4740 leftLength = partials.length,
4741 rangeLength = nativeMax(argsLength - holdersLength, 0),
4742 result = Array(leftLength + rangeLength),
4743 isUncurried = !isCurried;
4744
4745 while (++leftIndex < leftLength) {
4746 result[leftIndex] = partials[leftIndex];
4747 }
4748 while (++argsIndex < holdersLength) {
4749 if (isUncurried || argsIndex < argsLength) {
4750 result[holders[argsIndex]] = args[argsIndex];
4751 }
4752 }
4753 while (rangeLength--) {
4754 result[leftIndex++] = args[argsIndex++];
4755 }
4756 return result;
4757 }
4758
4759 /**
4760 * This function is like `composeArgs` except that the arguments composition
4761 * is tailored for `_.partialRight`.
4762 *
4763 * @private
4764 * @param {Array} args The provided arguments.
4765 * @param {Array} partials The arguments to append to those provided.
4766 * @param {Array} holders The `partials` placeholder indexes.
4767 * @params {boolean} [isCurried] Specify composing for a curried function.
4768 * @returns {Array} Returns the new array of composed arguments.
4769 */
4770 function composeArgsRight(args, partials, holders, isCurried) {
4771 var argsIndex = -1,
4772 argsLength = args.length,
4773 holdersIndex = -1,
4774 holdersLength = holders.length,
4775 rightIndex = -1,
4776 rightLength = partials.length,
4777 rangeLength = nativeMax(argsLength - holdersLength, 0),
4778 result = Array(rangeLength + rightLength),
4779 isUncurried = !isCurried;
4780
4781 while (++argsIndex < rangeLength) {
4782 result[argsIndex] = args[argsIndex];
4783 }
4784 var offset = argsIndex;
4785 while (++rightIndex < rightLength) {
4786 result[offset + rightIndex] = partials[rightIndex];
4787 }
4788 while (++holdersIndex < holdersLength) {
4789 if (isUncurried || argsIndex < argsLength) {
4790 result[offset + holders[holdersIndex]] = args[argsIndex++];
4791 }
4792 }
4793 return result;
4794 }
4795
4796 /**
4797 * Copies the values of `source` to `array`.
4798 *
4799 * @private
4800 * @param {Array} source The array to copy values from.
4801 * @param {Array} [array=[]] The array to copy values to.
4802 * @returns {Array} Returns `array`.
4803 */
4804 function copyArray(source, array) {
4805 var index = -1,
4806 length = source.length;
4807
4808 array || (array = Array(length));
4809 while (++index < length) {
4810 array[index] = source[index];
4811 }
4812 return array;
4813 }
4814
4815 /**
4816 * Copies properties of `source` to `object`.
4817 *
4818 * @private
4819 * @param {Object} source The object to copy properties from.
4820 * @param {Array} props The property identifiers to copy.
4821 * @param {Object} [object={}] The object to copy properties to.
4822 * @param {Function} [customizer] The function to customize copied values.
4823 * @returns {Object} Returns `object`.
4824 */
4825 function copyObject(source, props, object, customizer) {
4826 var isNew = !object;
4827 object || (object = {});
4828
4829 var index = -1,
4830 length = props.length;
4831
4832 while (++index < length) {
4833 var key = props[index];
4834
4835 var newValue = customizer
4836 ? customizer(object[key], source[key], key, object, source)
4837 : undefined;
4838
4839 if (newValue === undefined) {
4840 newValue = source[key];
4841 }
4842 if (isNew) {
4843 baseAssignValue(object, key, newValue);
4844 } else {
4845 assignValue(object, key, newValue);
4846 }
4847 }
4848 return object;
4849 }
4850
4851 /**
4852 * Copies own symbols of `source` to `object`.
4853 *
4854 * @private
4855 * @param {Object} source The object to copy symbols from.
4856 * @param {Object} [object={}] The object to copy symbols to.
4857 * @returns {Object} Returns `object`.
4858 */
4859 function copySymbols(source, object) {
4860 return copyObject(source, getSymbols(source), object);
4861 }
4862
4863 /**
4864 * Copies own and inherited symbols of `source` to `object`.
4865 *
4866 * @private
4867 * @param {Object} source The object to copy symbols from.
4868 * @param {Object} [object={}] The object to copy symbols to.
4869 * @returns {Object} Returns `object`.
4870 */
4871 function copySymbolsIn(source, object) {
4872 return copyObject(source, getSymbolsIn(source), object);
4873 }
4874
4875 /**
4876 * Creates a function like `_.groupBy`.
4877 *
4878 * @private
4879 * @param {Function} setter The function to set accumulator values.
4880 * @param {Function} [initializer] The accumulator object initializer.
4881 * @returns {Function} Returns the new aggregator function.
4882 */
4883 function createAggregator(setter, initializer) {
4884 return function(collection, iteratee) {
4885 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4886 accumulator = initializer ? initializer() : {};
4887
4888 return func(collection, setter, getIteratee(iteratee, 2), accumulator);
4889 };
4890 }
4891
4892 /**
4893 * Creates a function like `_.assign`.
4894 *
4895 * @private
4896 * @param {Function} assigner The function to assign values.
4897 * @returns {Function} Returns the new assigner function.
4898 */
4899 function createAssigner(assigner) {
4900 return baseRest(function(object, sources) {
4901 var index = -1,
4902 length = sources.length,
4903 customizer = length > 1 ? sources[length - 1] : undefined,
4904 guard = length > 2 ? sources[2] : undefined;
4905
4906 customizer = (assigner.length > 3 && typeof customizer == 'function')
4907 ? (length--, customizer)
4908 : undefined;
4909
4910 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
4911 customizer = length < 3 ? undefined : customizer;
4912 length = 1;
4913 }
4914 object = Object(object);
4915 while (++index < length) {
4916 var source = sources[index];
4917 if (source) {
4918 assigner(object, source, index, customizer);
4919 }
4920 }
4921 return object;
4922 });
4923 }
4924
4925 /**
4926 * Creates a `baseEach` or `baseEachRight` function.
4927 *
4928 * @private
4929 * @param {Function} eachFunc The function to iterate over a collection.
4930 * @param {boolean} [fromRight] Specify iterating from right to left.
4931 * @returns {Function} Returns the new base function.
4932 */
4933 function createBaseEach(eachFunc, fromRight) {
4934 return function(collection, iteratee) {
4935 if (collection == null) {
4936 return collection;
4937 }
4938 if (!isArrayLike(collection)) {
4939 return eachFunc(collection, iteratee);
4940 }
4941 var length = collection.length,
4942 index = fromRight ? length : -1,
4943 iterable = Object(collection);
4944
4945 while ((fromRight ? index-- : ++index < length)) {
4946 if (iteratee(iterable[index], index, iterable) === false) {
4947 break;
4948 }
4949 }
4950 return collection;
4951 };
4952 }
4953
4954 /**
4955 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
4956 *
4957 * @private
4958 * @param {boolean} [fromRight] Specify iterating from right to left.
4959 * @returns {Function} Returns the new base function.
4960 */
4961 function createBaseFor(fromRight) {
4962 return function(object, iteratee, keysFunc) {
4963 var index = -1,
4964 iterable = Object(object),
4965 props = keysFunc(object),
4966 length = props.length;
4967
4968 while (length--) {
4969 var key = props[fromRight ? length : ++index];
4970 if (iteratee(iterable[key], key, iterable) === false) {
4971 break;
4972 }
4973 }
4974 return object;
4975 };
4976 }
4977
4978 /**
4979 * Creates a function that wraps `func` to invoke it with the optional `this`
4980 * binding of `thisArg`.
4981 *
4982 * @private
4983 * @param {Function} func The function to wrap.
4984 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
4985 * @param {*} [thisArg] The `this` binding of `func`.
4986 * @returns {Function} Returns the new wrapped function.
4987 */
4988 function createBind(func, bitmask, thisArg) {
4989 var isBind = bitmask & WRAP_BIND_FLAG,
4990 Ctor = createCtor(func);
4991
4992 function wrapper() {
4993 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4994 return fn.apply(isBind ? thisArg : this, arguments);
4995 }
4996 return wrapper;
4997 }
4998
4999 /**
5000 * Creates a function like `_.lowerFirst`.
5001 *
5002 * @private
5003 * @param {string} methodName The name of the `String` case method to use.
5004 * @returns {Function} Returns the new case function.
5005 */
5006 function createCaseFirst(methodName) {
5007 return function(string) {
5008 string = toString(string);
5009
5010 var strSymbols = hasUnicode(string)
5011 ? stringToArray(string)
5012 : undefined;
5013
5014 var chr = strSymbols
5015 ? strSymbols[0]
5016 : string.charAt(0);
5017
5018 var trailing = strSymbols
5019 ? castSlice(strSymbols, 1).join('')
5020 : string.slice(1);
5021
5022 return chr[methodName]() + trailing;
5023 };
5024 }
5025
5026 /**
5027 * Creates a function like `_.camelCase`.
5028 *
5029 * @private
5030 * @param {Function} callback The function to combine each word.
5031 * @returns {Function} Returns the new compounder function.
5032 */
5033 function createCompounder(callback) {
5034 return function(string) {
5035 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
5036 };
5037 }
5038
5039 /**
5040 * Creates a function that produces an instance of `Ctor` regardless of
5041 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
5042 *
5043 * @private
5044 * @param {Function} Ctor The constructor to wrap.
5045 * @returns {Function} Returns the new wrapped function.
5046 */
5047 function createCtor(Ctor) {
5048 return function() {
5049 // Use a `switch` statement to work with class constructors. See
5050 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
5051 // for more details.
5052 var args = arguments;
5053 switch (args.length) {
5054 case 0: return new Ctor;
5055 case 1: return new Ctor(args[0]);
5056 case 2: return new Ctor(args[0], args[1]);
5057 case 3: return new Ctor(args[0], args[1], args[2]);
5058 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
5059 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
5060 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
5061 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
5062 }
5063 var thisBinding = baseCreate(Ctor.prototype),
5064 result = Ctor.apply(thisBinding, args);
5065
5066 // Mimic the constructor's `return` behavior.
5067 // See https://es5.github.io/#x13.2.2 for more details.
5068 return isObject(result) ? result : thisBinding;
5069 };
5070 }
5071
5072 /**
5073 * Creates a function that wraps `func` to enable currying.
5074 *
5075 * @private
5076 * @param {Function} func The function to wrap.
5077 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5078 * @param {number} arity The arity of `func`.
5079 * @returns {Function} Returns the new wrapped function.
5080 */
5081 function createCurry(func, bitmask, arity) {
5082 var Ctor = createCtor(func);
5083
5084 function wrapper() {
5085 var length = arguments.length,
5086 args = Array(length),
5087 index = length,
5088 placeholder = getHolder(wrapper);
5089
5090 while (index--) {
5091 args[index] = arguments[index];
5092 }
5093 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
5094 ? []
5095 : replaceHolders(args, placeholder);
5096
5097 length -= holders.length;
5098 if (length < arity) {
5099 return createRecurry(
5100 func, bitmask, createHybrid, wrapper.placeholder, undefined,
5101 args, holders, undefined, undefined, arity - length);
5102 }
5103 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5104 return apply(fn, this, args);
5105 }
5106 return wrapper;
5107 }
5108
5109 /**
5110 * Creates a `_.find` or `_.findLast` function.
5111 *
5112 * @private
5113 * @param {Function} findIndexFunc The function to find the collection index.
5114 * @returns {Function} Returns the new find function.
5115 */
5116 function createFind(findIndexFunc) {
5117 return function(collection, predicate, fromIndex) {
5118 var iterable = Object(collection);
5119 if (!isArrayLike(collection)) {
5120 var iteratee = getIteratee(predicate, 3);
5121 collection = keys(collection);
5122 predicate = function(key) { return iteratee(iterable[key], key, iterable); };
5123 }
5124 var index = findIndexFunc(collection, predicate, fromIndex);
5125 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
5126 };
5127 }
5128
5129 /**
5130 * Creates a `_.flow` or `_.flowRight` function.
5131 *
5132 * @private
5133 * @param {boolean} [fromRight] Specify iterating from right to left.
5134 * @returns {Function} Returns the new flow function.
5135 */
5136 function createFlow(fromRight) {
5137 return flatRest(function(funcs) {
5138 var length = funcs.length,
5139 index = length,
5140 prereq = LodashWrapper.prototype.thru;
5141
5142 if (fromRight) {
5143 funcs.reverse();
5144 }
5145 while (index--) {
5146 var func = funcs[index];
5147 if (typeof func != 'function') {
5148 throw new TypeError(FUNC_ERROR_TEXT);
5149 }
5150 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
5151 var wrapper = new LodashWrapper([], true);
5152 }
5153 }
5154 index = wrapper ? index : length;
5155 while (++index < length) {
5156 func = funcs[index];
5157
5158 var funcName = getFuncName(func),
5159 data = funcName == 'wrapper' ? getData(func) : undefined;
5160
5161 if (data && isLaziable(data[0]) &&
5162 data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
5163 !data[4].length && data[9] == 1
5164 ) {
5165 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
5166 } else {
5167 wrapper = (func.length == 1 && isLaziable(func))
5168 ? wrapper[funcName]()
5169 : wrapper.thru(func);
5170 }
5171 }
5172 return function() {
5173 var args = arguments,
5174 value = args[0];
5175
5176 if (wrapper && args.length == 1 &&
5177 isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
5178 return wrapper.plant(value).value();
5179 }
5180 var index = 0,
5181 result = length ? funcs[index].apply(this, args) : value;
5182
5183 while (++index < length) {
5184 result = funcs[index].call(this, result);
5185 }
5186 return result;
5187 };
5188 });
5189 }
5190
5191 /**
5192 * Creates a function that wraps `func` to invoke it with optional `this`
5193 * binding of `thisArg`, partial application, and currying.
5194 *
5195 * @private
5196 * @param {Function|string} func The function or method name to wrap.
5197 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5198 * @param {*} [thisArg] The `this` binding of `func`.
5199 * @param {Array} [partials] The arguments to prepend to those provided to
5200 * the new function.
5201 * @param {Array} [holders] The `partials` placeholder indexes.
5202 * @param {Array} [partialsRight] The arguments to append to those provided
5203 * to the new function.
5204 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
5205 * @param {Array} [argPos] The argument positions of the new function.
5206 * @param {number} [ary] The arity cap of `func`.
5207 * @param {number} [arity] The arity of `func`.
5208 * @returns {Function} Returns the new wrapped function.
5209 */
5210 function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
5211 var isAry = bitmask & WRAP_ARY_FLAG,
5212 isBind = bitmask & WRAP_BIND_FLAG,
5213 isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
5214 isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
5215 isFlip = bitmask & WRAP_FLIP_FLAG,
5216 Ctor = isBindKey ? undefined : createCtor(func);
5217
5218 function wrapper() {
5219 var length = arguments.length,
5220 args = Array(length),
5221 index = length;
5222
5223 while (index--) {
5224 args[index] = arguments[index];
5225 }
5226 if (isCurried) {
5227 var placeholder = getHolder(wrapper),
5228 holdersCount = countHolders(args, placeholder);
5229 }
5230 if (partials) {
5231 args = composeArgs(args, partials, holders, isCurried);
5232 }
5233 if (partialsRight) {
5234 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
5235 }
5236 length -= holdersCount;
5237 if (isCurried && length < arity) {
5238 var newHolders = replaceHolders(args, placeholder);
5239 return createRecurry(
5240 func, bitmask, createHybrid, wrapper.placeholder, thisArg,
5241 args, newHolders, argPos, ary, arity - length
5242 );
5243 }
5244 var thisBinding = isBind ? thisArg : this,
5245 fn = isBindKey ? thisBinding[func] : func;
5246
5247 length = args.length;
5248 if (argPos) {
5249 args = reorder(args, argPos);
5250 } else if (isFlip && length > 1) {
5251 args.reverse();
5252 }
5253 if (isAry && ary < length) {
5254 args.length = ary;
5255 }
5256 if (this && this !== root && this instanceof wrapper) {
5257 fn = Ctor || createCtor(fn);
5258 }
5259 return fn.apply(thisBinding, args);
5260 }
5261 return wrapper;
5262 }
5263
5264 /**
5265 * Creates a function like `_.invertBy`.
5266 *
5267 * @private
5268 * @param {Function} setter The function to set accumulator values.
5269 * @param {Function} toIteratee The function to resolve iteratees.
5270 * @returns {Function} Returns the new inverter function.
5271 */
5272 function createInverter(setter, toIteratee) {
5273 return function(object, iteratee) {
5274 return baseInverter(object, setter, toIteratee(iteratee), {});
5275 };
5276 }
5277
5278 /**
5279 * Creates a function that performs a mathematical operation on two values.
5280 *
5281 * @private
5282 * @param {Function} operator The function to perform the operation.
5283 * @param {number} [defaultValue] The value used for `undefined` arguments.
5284 * @returns {Function} Returns the new mathematical operation function.
5285 */
5286 function createMathOperation(operator, defaultValue) {
5287 return function(value, other) {
5288 var result;
5289 if (value === undefined && other === undefined) {
5290 return defaultValue;
5291 }
5292 if (value !== undefined) {
5293 result = value;
5294 }
5295 if (other !== undefined) {
5296 if (result === undefined) {
5297 return other;
5298 }
5299 if (typeof value == 'string' || typeof other == 'string') {
5300 value = baseToString(value);
5301 other = baseToString(other);
5302 } else {
5303 value = baseToNumber(value);
5304 other = baseToNumber(other);
5305 }
5306 result = operator(value, other);
5307 }
5308 return result;
5309 };
5310 }
5311
5312 /**
5313 * Creates a function like `_.over`.
5314 *
5315 * @private
5316 * @param {Function} arrayFunc The function to iterate over iteratees.
5317 * @returns {Function} Returns the new over function.
5318 */
5319 function createOver(arrayFunc) {
5320 return flatRest(function(iteratees) {
5321 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
5322 return baseRest(function(args) {
5323 var thisArg = this;
5324 return arrayFunc(iteratees, function(iteratee) {
5325 return apply(iteratee, thisArg, args);
5326 });
5327 });
5328 });
5329 }
5330
5331 /**
5332 * Creates the padding for `string` based on `length`. The `chars` string
5333 * is truncated if the number of characters exceeds `length`.
5334 *
5335 * @private
5336 * @param {number} length The padding length.
5337 * @param {string} [chars=' '] The string used as padding.
5338 * @returns {string} Returns the padding for `string`.
5339 */
5340 function createPadding(length, chars) {
5341 chars = chars === undefined ? ' ' : baseToString(chars);
5342
5343 var charsLength = chars.length;
5344 if (charsLength < 2) {
5345 return charsLength ? baseRepeat(chars, length) : chars;
5346 }
5347 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
5348 return hasUnicode(chars)
5349 ? castSlice(stringToArray(result), 0, length).join('')
5350 : result.slice(0, length);
5351 }
5352
5353 /**
5354 * Creates a function that wraps `func` to invoke it with the `this` binding
5355 * of `thisArg` and `partials` prepended to the arguments it receives.
5356 *
5357 * @private
5358 * @param {Function} func The function to wrap.
5359 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5360 * @param {*} thisArg The `this` binding of `func`.
5361 * @param {Array} partials The arguments to prepend to those provided to
5362 * the new function.
5363 * @returns {Function} Returns the new wrapped function.
5364 */
5365 function createPartial(func, bitmask, thisArg, partials) {
5366 var isBind = bitmask & WRAP_BIND_FLAG,
5367 Ctor = createCtor(func);
5368
5369 function wrapper() {
5370 var argsIndex = -1,
5371 argsLength = arguments.length,
5372 leftIndex = -1,
5373 leftLength = partials.length,
5374 args = Array(leftLength + argsLength),
5375 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5376
5377 while (++leftIndex < leftLength) {
5378 args[leftIndex] = partials[leftIndex];
5379 }
5380 while (argsLength--) {
5381 args[leftIndex++] = arguments[++argsIndex];
5382 }
5383 return apply(fn, isBind ? thisArg : this, args);
5384 }
5385 return wrapper;
5386 }
5387
5388 /**
5389 * Creates a `_.range` or `_.rangeRight` function.
5390 *
5391 * @private
5392 * @param {boolean} [fromRight] Specify iterating from right to left.
5393 * @returns {Function} Returns the new range function.
5394 */
5395 function createRange(fromRight) {
5396 return function(start, end, step) {
5397 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
5398 end = step = undefined;
5399 }
5400 // Ensure the sign of `-0` is preserved.
5401 start = toFinite(start);
5402 if (end === undefined) {
5403 end = start;
5404 start = 0;
5405 } else {
5406 end = toFinite(end);
5407 }
5408 step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
5409 return baseRange(start, end, step, fromRight);
5410 };
5411 }
5412
5413 /**
5414 * Creates a function that performs a relational operation on two values.
5415 *
5416 * @private
5417 * @param {Function} operator The function to perform the operation.
5418 * @returns {Function} Returns the new relational operation function.
5419 */
5420 function createRelationalOperation(operator) {
5421 return function(value, other) {
5422 if (!(typeof value == 'string' && typeof other == 'string')) {
5423 value = toNumber(value);
5424 other = toNumber(other);
5425 }
5426 return operator(value, other);
5427 };
5428 }
5429
5430 /**
5431 * Creates a function that wraps `func` to continue currying.
5432 *
5433 * @private
5434 * @param {Function} func The function to wrap.
5435 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5436 * @param {Function} wrapFunc The function to create the `func` wrapper.
5437 * @param {*} placeholder The placeholder value.
5438 * @param {*} [thisArg] The `this` binding of `func`.
5439 * @param {Array} [partials] The arguments to prepend to those provided to
5440 * the new function.
5441 * @param {Array} [holders] The `partials` placeholder indexes.
5442 * @param {Array} [argPos] The argument positions of the new function.
5443 * @param {number} [ary] The arity cap of `func`.
5444 * @param {number} [arity] The arity of `func`.
5445 * @returns {Function} Returns the new wrapped function.
5446 */
5447 function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
5448 var isCurry = bitmask & WRAP_CURRY_FLAG,
5449 newHolders = isCurry ? holders : undefined,
5450 newHoldersRight = isCurry ? undefined : holders,
5451 newPartials = isCurry ? partials : undefined,
5452 newPartialsRight = isCurry ? undefined : partials;
5453
5454 bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
5455 bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
5456
5457 if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
5458 bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
5459 }
5460 var newData = [
5461 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
5462 newHoldersRight, argPos, ary, arity
5463 ];
5464
5465 var result = wrapFunc.apply(undefined, newData);
5466 if (isLaziable(func)) {
5467 setData(result, newData);
5468 }
5469 result.placeholder = placeholder;
5470 return setWrapToString(result, func, bitmask);
5471 }
5472
5473 /**
5474 * Creates a function like `_.round`.
5475 *
5476 * @private
5477 * @param {string} methodName The name of the `Math` method to use when rounding.
5478 * @returns {Function} Returns the new round function.
5479 */
5480 function createRound(methodName) {
5481 var func = Math[methodName];
5482 return function(number, precision) {
5483 number = toNumber(number);
5484 precision = nativeMin(toInteger(precision), 292);
5485 if (precision) {
5486 // Shift with exponential notation to avoid floating-point issues.
5487 // See [MDN](https://mdn.io/round#Examples) for more details.
5488 var pair = (toString(number) + 'e').split('e'),
5489 value = func(pair[0] + 'e' + (+pair[1] + precision));
5490
5491 pair = (toString(value) + 'e').split('e');
5492 return +(pair[0] + 'e' + (+pair[1] - precision));
5493 }
5494 return func(number);
5495 };
5496 }
5497
5498 /**
5499 * Creates a set object of `values`.
5500 *
5501 * @private
5502 * @param {Array} values The values to add to the set.
5503 * @returns {Object} Returns the new set.
5504 */
5505 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
5506 return new Set(values);
5507 };
5508
5509 /**
5510 * Creates a `_.toPairs` or `_.toPairsIn` function.
5511 *
5512 * @private
5513 * @param {Function} keysFunc The function to get the keys of a given object.
5514 * @returns {Function} Returns the new pairs function.
5515 */
5516 function createToPairs(keysFunc) {
5517 return function(object) {
5518 var tag = getTag(object);
5519 if (tag == mapTag) {
5520 return mapToArray(object);
5521 }
5522 if (tag == setTag) {
5523 return setToPairs(object);
5524 }
5525 return baseToPairs(object, keysFunc(object));
5526 };
5527 }
5528
5529 /**
5530 * Creates a function that either curries or invokes `func` with optional
5531 * `this` binding and partially applied arguments.
5532 *
5533 * @private
5534 * @param {Function|string} func The function or method name to wrap.
5535 * @param {number} bitmask The bitmask flags.
5536 * 1 - `_.bind`
5537 * 2 - `_.bindKey`
5538 * 4 - `_.curry` or `_.curryRight` of a bound function
5539 * 8 - `_.curry`
5540 * 16 - `_.curryRight`
5541 * 32 - `_.partial`
5542 * 64 - `_.partialRight`
5543 * 128 - `_.rearg`
5544 * 256 - `_.ary`
5545 * 512 - `_.flip`
5546 * @param {*} [thisArg] The `this` binding of `func`.
5547 * @param {Array} [partials] The arguments to be partially applied.
5548 * @param {Array} [holders] The `partials` placeholder indexes.
5549 * @param {Array} [argPos] The argument positions of the new function.
5550 * @param {number} [ary] The arity cap of `func`.
5551 * @param {number} [arity] The arity of `func`.
5552 * @returns {Function} Returns the new wrapped function.
5553 */
5554 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
5555 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
5556 if (!isBindKey && typeof func != 'function') {
5557 throw new TypeError(FUNC_ERROR_TEXT);
5558 }
5559 var length = partials ? partials.length : 0;
5560 if (!length) {
5561 bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
5562 partials = holders = undefined;
5563 }
5564 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
5565 arity = arity === undefined ? arity : toInteger(arity);
5566 length -= holders ? holders.length : 0;
5567
5568 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
5569 var partialsRight = partials,
5570 holdersRight = holders;
5571
5572 partials = holders = undefined;
5573 }
5574 var data = isBindKey ? undefined : getData(func);
5575
5576 var newData = [
5577 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
5578 argPos, ary, arity
5579 ];
5580
5581 if (data) {
5582 mergeData(newData, data);
5583 }
5584 func = newData[0];
5585 bitmask = newData[1];
5586 thisArg = newData[2];
5587 partials = newData[3];
5588 holders = newData[4];
5589 arity = newData[9] = newData[9] == null
5590 ? (isBindKey ? 0 : func.length)
5591 : nativeMax(newData[9] - length, 0);
5592
5593 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
5594 bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
5595 }
5596 if (!bitmask || bitmask == WRAP_BIND_FLAG) {
5597 var result = createBind(func, bitmask, thisArg);
5598 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
5599 result = createCurry(func, bitmask, arity);
5600 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
5601 result = createPartial(func, bitmask, thisArg, partials);
5602 } else {
5603 result = createHybrid.apply(undefined, newData);
5604 }
5605 var setter = data ? baseSetData : setData;
5606 return setWrapToString(setter(result, newData), func, bitmask);
5607 }
5608
5609 /**
5610 * A specialized version of `baseIsEqualDeep` for arrays with support for
5611 * partial deep comparisons.
5612 *
5613 * @private
5614 * @param {Array} array The array to compare.
5615 * @param {Array} other The other array to compare.
5616 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5617 * @param {Function} customizer The function to customize comparisons.
5618 * @param {Function} equalFunc The function to determine equivalents of values.
5619 * @param {Object} stack Tracks traversed `array` and `other` objects.
5620 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
5621 */
5622 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
5623 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5624 arrLength = array.length,
5625 othLength = other.length;
5626
5627 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
5628 return false;
5629 }
5630 // Assume cyclic values are equal.
5631 var stacked = stack.get(array);
5632 if (stacked && stack.get(other)) {
5633 return stacked == other;
5634 }
5635 var index = -1,
5636 result = true,
5637 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
5638
5639 stack.set(array, other);
5640 stack.set(other, array);
5641
5642 // Ignore non-index properties.
5643 while (++index < arrLength) {
5644 var arrValue = array[index],
5645 othValue = other[index];
5646
5647 if (customizer) {
5648 var compared = isPartial
5649 ? customizer(othValue, arrValue, index, other, array, stack)
5650 : customizer(arrValue, othValue, index, array, other, stack);
5651 }
5652 if (compared !== undefined) {
5653 if (compared) {
5654 continue;
5655 }
5656 result = false;
5657 break;
5658 }
5659 // Recursively compare arrays (susceptible to call stack limits).
5660 if (seen) {
5661 if (!arraySome(other, function(othValue, othIndex) {
5662 if (!cacheHas(seen, othIndex) &&
5663 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
5664 return seen.push(othIndex);
5665 }
5666 })) {
5667 result = false;
5668 break;
5669 }
5670 } else if (!(
5671 arrValue === othValue ||
5672 equalFunc(arrValue, othValue, bitmask, customizer, stack)
5673 )) {
5674 result = false;
5675 break;
5676 }
5677 }
5678 stack['delete'](array);
5679 stack['delete'](other);
5680 return result;
5681 }
5682
5683 /**
5684 * A specialized version of `baseIsEqualDeep` for comparing objects of
5685 * the same `toStringTag`.
5686 *
5687 * **Note:** This function only supports comparing values with tags of
5688 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5689 *
5690 * @private
5691 * @param {Object} object The object to compare.
5692 * @param {Object} other The other object to compare.
5693 * @param {string} tag The `toStringTag` of the objects to compare.
5694 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5695 * @param {Function} customizer The function to customize comparisons.
5696 * @param {Function} equalFunc The function to determine equivalents of values.
5697 * @param {Object} stack Tracks traversed `object` and `other` objects.
5698 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5699 */
5700 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
5701 switch (tag) {
5702 case dataViewTag:
5703 if ((object.byteLength != other.byteLength) ||
5704 (object.byteOffset != other.byteOffset)) {
5705 return false;
5706 }
5707 object = object.buffer;
5708 other = other.buffer;
5709
5710 case arrayBufferTag:
5711 if ((object.byteLength != other.byteLength) ||
5712 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
5713 return false;
5714 }
5715 return true;
5716
5717 case boolTag:
5718 case dateTag:
5719 case numberTag:
5720 // Coerce booleans to `1` or `0` and dates to milliseconds.
5721 // Invalid dates are coerced to `NaN`.
5722 return eq(+object, +other);
5723
5724 case errorTag:
5725 return object.name == other.name && object.message == other.message;
5726
5727 case regexpTag:
5728 case stringTag:
5729 // Coerce regexes to strings and treat strings, primitives and objects,
5730 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
5731 // for more details.
5732 return object == (other + '');
5733
5734 case mapTag:
5735 var convert = mapToArray;
5736
5737 case setTag:
5738 var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
5739 convert || (convert = setToArray);
5740
5741 if (object.size != other.size && !isPartial) {
5742 return false;
5743 }
5744 // Assume cyclic values are equal.
5745 var stacked = stack.get(object);
5746 if (stacked) {
5747 return stacked == other;
5748 }
5749 bitmask |= COMPARE_UNORDERED_FLAG;
5750
5751 // Recursively compare objects (susceptible to call stack limits).
5752 stack.set(object, other);
5753 var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
5754 stack['delete'](object);
5755 return result;
5756
5757 case symbolTag:
5758 if (symbolValueOf) {
5759 return symbolValueOf.call(object) == symbolValueOf.call(other);
5760 }
5761 }
5762 return false;
5763 }
5764
5765 /**
5766 * A specialized version of `baseIsEqualDeep` for objects with support for
5767 * partial deep comparisons.
5768 *
5769 * @private
5770 * @param {Object} object The object to compare.
5771 * @param {Object} other The other object to compare.
5772 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5773 * @param {Function} customizer The function to customize comparisons.
5774 * @param {Function} equalFunc The function to determine equivalents of values.
5775 * @param {Object} stack Tracks traversed `object` and `other` objects.
5776 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5777 */
5778 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
5779 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5780 objProps = keys(object),
5781 objLength = objProps.length,
5782 othProps = keys(other),
5783 othLength = othProps.length;
5784
5785 if (objLength != othLength && !isPartial) {
5786 return false;
5787 }
5788 var index = objLength;
5789 while (index--) {
5790 var key = objProps[index];
5791 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
5792 return false;
5793 }
5794 }
5795 // Assume cyclic values are equal.
5796 var stacked = stack.get(object);
5797 if (stacked && stack.get(other)) {
5798 return stacked == other;
5799 }
5800 var result = true;
5801 stack.set(object, other);
5802 stack.set(other, object);
5803
5804 var skipCtor = isPartial;
5805 while (++index < objLength) {
5806 key = objProps[index];
5807 var objValue = object[key],
5808 othValue = other[key];
5809
5810 if (customizer) {
5811 var compared = isPartial
5812 ? customizer(othValue, objValue, key, other, object, stack)
5813 : customizer(objValue, othValue, key, object, other, stack);
5814 }
5815 // Recursively compare objects (susceptible to call stack limits).
5816 if (!(compared === undefined
5817 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
5818 : compared
5819 )) {
5820 result = false;
5821 break;
5822 }
5823 skipCtor || (skipCtor = key == 'constructor');
5824 }
5825 if (result && !skipCtor) {
5826 var objCtor = object.constructor,
5827 othCtor = other.constructor;
5828
5829 // Non `Object` object instances with different constructors are not equal.
5830 if (objCtor != othCtor &&
5831 ('constructor' in object && 'constructor' in other) &&
5832 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
5833 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
5834 result = false;
5835 }
5836 }
5837 stack['delete'](object);
5838 stack['delete'](other);
5839 return result;
5840 }
5841
5842 /**
5843 * A specialized version of `baseRest` which flattens the rest array.
5844 *
5845 * @private
5846 * @param {Function} func The function to apply a rest parameter to.
5847 * @returns {Function} Returns the new function.
5848 */
5849 function flatRest(func) {
5850 return setToString(overRest(func, undefined, flatten), func + '');
5851 }
5852
5853 /**
5854 * Creates an array of own enumerable property names and symbols of `object`.
5855 *
5856 * @private
5857 * @param {Object} object The object to query.
5858 * @returns {Array} Returns the array of property names and symbols.
5859 */
5860 function getAllKeys(object) {
5861 return baseGetAllKeys(object, keys, getSymbols);
5862 }
5863
5864 /**
5865 * Creates an array of own and inherited enumerable property names and
5866 * symbols of `object`.
5867 *
5868 * @private
5869 * @param {Object} object The object to query.
5870 * @returns {Array} Returns the array of property names and symbols.
5871 */
5872 function getAllKeysIn(object) {
5873 return baseGetAllKeys(object, keysIn, getSymbolsIn);
5874 }
5875
5876 /**
5877 * Gets metadata for `func`.
5878 *
5879 * @private
5880 * @param {Function} func The function to query.
5881 * @returns {*} Returns the metadata for `func`.
5882 */
5883 var getData = !metaMap ? noop : function(func) {
5884 return metaMap.get(func);
5885 };
5886
5887 /**
5888 * Gets the name of `func`.
5889 *
5890 * @private
5891 * @param {Function} func The function to query.
5892 * @returns {string} Returns the function name.
5893 */
5894 function getFuncName(func) {
5895 var result = (func.name + ''),
5896 array = realNames[result],
5897 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
5898
5899 while (length--) {
5900 var data = array[length],
5901 otherFunc = data.func;
5902 if (otherFunc == null || otherFunc == func) {
5903 return data.name;
5904 }
5905 }
5906 return result;
5907 }
5908
5909 /**
5910 * Gets the argument placeholder value for `func`.
5911 *
5912 * @private
5913 * @param {Function} func The function to inspect.
5914 * @returns {*} Returns the placeholder value.
5915 */
5916 function getHolder(func) {
5917 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
5918 return object.placeholder;
5919 }
5920
5921 /**
5922 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
5923 * this function returns the custom method, otherwise it returns `baseIteratee`.
5924 * If arguments are provided, the chosen function is invoked with them and
5925 * its result is returned.
5926 *
5927 * @private
5928 * @param {*} [value] The value to convert to an iteratee.
5929 * @param {number} [arity] The arity of the created iteratee.
5930 * @returns {Function} Returns the chosen function or its result.
5931 */
5932 function getIteratee() {
5933 var result = lodash.iteratee || iteratee;
5934 result = result === iteratee ? baseIteratee : result;
5935 return arguments.length ? result(arguments[0], arguments[1]) : result;
5936 }
5937
5938 /**
5939 * Gets the data for `map`.
5940 *
5941 * @private
5942 * @param {Object} map The map to query.
5943 * @param {string} key The reference key.
5944 * @returns {*} Returns the map data.
5945 */
5946 function getMapData(map, key) {
5947 var data = map.__data__;
5948 return isKeyable(key)
5949 ? data[typeof key == 'string' ? 'string' : 'hash']
5950 : data.map;
5951 }
5952
5953 /**
5954 * Gets the property names, values, and compare flags of `object`.
5955 *
5956 * @private
5957 * @param {Object} object The object to query.
5958 * @returns {Array} Returns the match data of `object`.
5959 */
5960 function getMatchData(object) {
5961 var result = keys(object),
5962 length = result.length;
5963
5964 while (length--) {
5965 var key = result[length],
5966 value = object[key];
5967
5968 result[length] = [key, value, isStrictComparable(value)];
5969 }
5970 return result;
5971 }
5972
5973 /**
5974 * Gets the native function at `key` of `object`.
5975 *
5976 * @private
5977 * @param {Object} object The object to query.
5978 * @param {string} key The key of the method to get.
5979 * @returns {*} Returns the function if it's native, else `undefined`.
5980 */
5981 function getNative(object, key) {
5982 var value = getValue(object, key);
5983 return baseIsNative(value) ? value : undefined;
5984 }
5985
5986 /**
5987 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
5988 *
5989 * @private
5990 * @param {*} value The value to query.
5991 * @returns {string} Returns the raw `toStringTag`.
5992 */
5993 function getRawTag(value) {
5994 var isOwn = hasOwnProperty.call(value, symToStringTag),
5995 tag = value[symToStringTag];
5996
5997 try {
5998 value[symToStringTag] = undefined;
5999 var unmasked = true;
6000 } catch (e) {}
6001
6002 var result = nativeObjectToString.call(value);
6003 if (unmasked) {
6004 if (isOwn) {
6005 value[symToStringTag] = tag;
6006 } else {
6007 delete value[symToStringTag];
6008 }
6009 }
6010 return result;
6011 }
6012
6013 /**
6014 * Creates an array of the own enumerable symbols of `object`.
6015 *
6016 * @private
6017 * @param {Object} object The object to query.
6018 * @returns {Array} Returns the array of symbols.
6019 */
6020 var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
6021
6022 /**
6023 * Creates an array of the own and inherited enumerable symbols of `object`.
6024 *
6025 * @private
6026 * @param {Object} object The object to query.
6027 * @returns {Array} Returns the array of symbols.
6028 */
6029 var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
6030 var result = [];
6031 while (object) {
6032 arrayPush(result, getSymbols(object));
6033 object = getPrototype(object);
6034 }
6035 return result;
6036 };
6037
6038 /**
6039 * Gets the `toStringTag` of `value`.
6040 *
6041 * @private
6042 * @param {*} value The value to query.
6043 * @returns {string} Returns the `toStringTag`.
6044 */
6045 var getTag = baseGetTag;
6046
6047 // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
6048 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
6049 (Map && getTag(new Map) != mapTag) ||
6050 (Promise && getTag(Promise.resolve()) != promiseTag) ||
6051 (Set && getTag(new Set) != setTag) ||
6052 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
6053 getTag = function(value) {
6054 var result = baseGetTag(value),
6055 Ctor = result == objectTag ? value.constructor : undefined,
6056 ctorString = Ctor ? toSource(Ctor) : '';
6057
6058 if (ctorString) {
6059 switch (ctorString) {
6060 case dataViewCtorString: return dataViewTag;
6061 case mapCtorString: return mapTag;
6062 case promiseCtorString: return promiseTag;
6063 case setCtorString: return setTag;
6064 case weakMapCtorString: return weakMapTag;
6065 }
6066 }
6067 return result;
6068 };
6069 }
6070
6071 /**
6072 * Gets the view, applying any `transforms` to the `start` and `end` positions.
6073 *
6074 * @private
6075 * @param {number} start The start of the view.
6076 * @param {number} end The end of the view.
6077 * @param {Array} transforms The transformations to apply to the view.
6078 * @returns {Object} Returns an object containing the `start` and `end`
6079 * positions of the view.
6080 */
6081 function getView(start, end, transforms) {
6082 var index = -1,
6083 length = transforms.length;
6084
6085 while (++index < length) {
6086 var data = transforms[index],
6087 size = data.size;
6088
6089 switch (data.type) {
6090 case 'drop': start += size; break;
6091 case 'dropRight': end -= size; break;
6092 case 'take': end = nativeMin(end, start + size); break;
6093 case 'takeRight': start = nativeMax(start, end - size); break;
6094 }
6095 }
6096 return { 'start': start, 'end': end };
6097 }
6098
6099 /**
6100 * Extracts wrapper details from the `source` body comment.
6101 *
6102 * @private
6103 * @param {string} source The source to inspect.
6104 * @returns {Array} Returns the wrapper details.
6105 */
6106 function getWrapDetails(source) {
6107 var match = source.match(reWrapDetails);
6108 return match ? match[1].split(reSplitDetails) : [];
6109 }
6110
6111 /**
6112 * Checks if `path` exists on `object`.
6113 *
6114 * @private
6115 * @param {Object} object The object to query.
6116 * @param {Array|string} path The path to check.
6117 * @param {Function} hasFunc The function to check properties.
6118 * @returns {boolean} Returns `true` if `path` exists, else `false`.
6119 */
6120 function hasPath(object, path, hasFunc) {
6121 path = castPath(path, object);
6122
6123 var index = -1,
6124 length = path.length,
6125 result = false;
6126
6127 while (++index < length) {
6128 var key = toKey(path[index]);
6129 if (!(result = object != null && hasFunc(object, key))) {
6130 break;
6131 }
6132 object = object[key];
6133 }
6134 if (result || ++index != length) {
6135 return result;
6136 }
6137 length = object == null ? 0 : object.length;
6138 return !!length && isLength(length) && isIndex(key, length) &&
6139 (isArray(object) || isArguments(object));
6140 }
6141
6142 /**
6143 * Initializes an array clone.
6144 *
6145 * @private
6146 * @param {Array} array The array to clone.
6147 * @returns {Array} Returns the initialized clone.
6148 */
6149 function initCloneArray(array) {
6150 var length = array.length,
6151 result = array.constructor(length);
6152
6153 // Add properties assigned by `RegExp#exec`.
6154 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
6155 result.index = array.index;
6156 result.input = array.input;
6157 }
6158 return result;
6159 }
6160
6161 /**
6162 * Initializes an object clone.
6163 *
6164 * @private
6165 * @param {Object} object The object to clone.
6166 * @returns {Object} Returns the initialized clone.
6167 */
6168 function initCloneObject(object) {
6169 return (typeof object.constructor == 'function' && !isPrototype(object))
6170 ? baseCreate(getPrototype(object))
6171 : {};
6172 }
6173
6174 /**
6175 * Initializes an object clone based on its `toStringTag`.
6176 *
6177 * **Note:** This function only supports cloning values with tags of
6178 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
6179 *
6180 * @private
6181 * @param {Object} object The object to clone.
6182 * @param {string} tag The `toStringTag` of the object to clone.
6183 * @param {Function} cloneFunc The function to clone values.
6184 * @param {boolean} [isDeep] Specify a deep clone.
6185 * @returns {Object} Returns the initialized clone.
6186 */
6187 function initCloneByTag(object, tag, cloneFunc, isDeep) {
6188 var Ctor = object.constructor;
6189 switch (tag) {
6190 case arrayBufferTag:
6191 return cloneArrayBuffer(object);
6192
6193 case boolTag:
6194 case dateTag:
6195 return new Ctor(+object);
6196
6197 case dataViewTag:
6198 return cloneDataView(object, isDeep);
6199
6200 case float32Tag: case float64Tag:
6201 case int8Tag: case int16Tag: case int32Tag:
6202 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
6203 return cloneTypedArray(object, isDeep);
6204
6205 case mapTag:
6206 return cloneMap(object, isDeep, cloneFunc);
6207
6208 case numberTag:
6209 case stringTag:
6210 return new Ctor(object);
6211
6212 case regexpTag:
6213 return cloneRegExp(object);
6214
6215 case setTag:
6216 return cloneSet(object, isDeep, cloneFunc);
6217
6218 case symbolTag:
6219 return cloneSymbol(object);
6220 }
6221 }
6222
6223 /**
6224 * Inserts wrapper `details` in a comment at the top of the `source` body.
6225 *
6226 * @private
6227 * @param {string} source The source to modify.
6228 * @returns {Array} details The details to insert.
6229 * @returns {string} Returns the modified source.
6230 */
6231 function insertWrapDetails(source, details) {
6232 var length = details.length;
6233 if (!length) {
6234 return source;
6235 }
6236 var lastIndex = length - 1;
6237 details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
6238 details = details.join(length > 2 ? ', ' : ' ');
6239 return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
6240 }
6241
6242 /**
6243 * Checks if `value` is a flattenable `arguments` object or array.
6244 *
6245 * @private
6246 * @param {*} value The value to check.
6247 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
6248 */
6249 function isFlattenable(value) {
6250 return isArray(value) || isArguments(value) ||
6251 !!(spreadableSymbol && value && value[spreadableSymbol]);
6252 }
6253
6254 /**
6255 * Checks if `value` is a valid array-like index.
6256 *
6257 * @private
6258 * @param {*} value The value to check.
6259 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
6260 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
6261 */
6262 function isIndex(value, length) {
6263 length = length == null ? MAX_SAFE_INTEGER : length;
6264 return !!length &&
6265 (typeof value == 'number' || reIsUint.test(value)) &&
6266 (value > -1 && value % 1 == 0 && value < length);
6267 }
6268
6269 /**
6270 * Checks if the given arguments are from an iteratee call.
6271 *
6272 * @private
6273 * @param {*} value The potential iteratee value argument.
6274 * @param {*} index The potential iteratee index or key argument.
6275 * @param {*} object The potential iteratee object argument.
6276 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
6277 * else `false`.
6278 */
6279 function isIterateeCall(value, index, object) {
6280 if (!isObject(object)) {
6281 return false;
6282 }
6283 var type = typeof index;
6284 if (type == 'number'
6285 ? (isArrayLike(object) && isIndex(index, object.length))
6286 : (type == 'string' && index in object)
6287 ) {
6288 return eq(object[index], value);
6289 }
6290 return false;
6291 }
6292
6293 /**
6294 * Checks if `value` is a property name and not a property path.
6295 *
6296 * @private
6297 * @param {*} value The value to check.
6298 * @param {Object} [object] The object to query keys on.
6299 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
6300 */
6301 function isKey(value, object) {
6302 if (isArray(value)) {
6303 return false;
6304 }
6305 var type = typeof value;
6306 if (type == 'number' || type == 'symbol' || type == 'boolean' ||
6307 value == null || isSymbol(value)) {
6308 return true;
6309 }
6310 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
6311 (object != null && value in Object(object));
6312 }
6313
6314 /**
6315 * Checks if `value` is suitable for use as unique object key.
6316 *
6317 * @private
6318 * @param {*} value The value to check.
6319 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
6320 */
6321 function isKeyable(value) {
6322 var type = typeof value;
6323 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
6324 ? (value !== '__proto__')
6325 : (value === null);
6326 }
6327
6328 /**
6329 * Checks if `func` has a lazy counterpart.
6330 *
6331 * @private
6332 * @param {Function} func The function to check.
6333 * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
6334 * else `false`.
6335 */
6336 function isLaziable(func) {
6337 var funcName = getFuncName(func),
6338 other = lodash[funcName];
6339
6340 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
6341 return false;
6342 }
6343 if (func === other) {
6344 return true;
6345 }
6346 var data = getData(other);
6347 return !!data && func === data[0];
6348 }
6349
6350 /**
6351 * Checks if `func` has its source masked.
6352 *
6353 * @private
6354 * @param {Function} func The function to check.
6355 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
6356 */
6357 function isMasked(func) {
6358 return !!maskSrcKey && (maskSrcKey in func);
6359 }
6360
6361 /**
6362 * Checks if `func` is capable of being masked.
6363 *
6364 * @private
6365 * @param {*} value The value to check.
6366 * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
6367 */
6368 var isMaskable = coreJsData ? isFunction : stubFalse;
6369
6370 /**
6371 * Checks if `value` is likely a prototype object.
6372 *
6373 * @private
6374 * @param {*} value The value to check.
6375 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
6376 */
6377 function isPrototype(value) {
6378 var Ctor = value && value.constructor,
6379 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
6380
6381 return value === proto;
6382 }
6383
6384 /**
6385 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
6386 *
6387 * @private
6388 * @param {*} value The value to check.
6389 * @returns {boolean} Returns `true` if `value` if suitable for strict
6390 * equality comparisons, else `false`.
6391 */
6392 function isStrictComparable(value) {
6393 return value === value && !isObject(value);
6394 }
6395
6396 /**
6397 * A specialized version of `matchesProperty` for source values suitable
6398 * for strict equality comparisons, i.e. `===`.
6399 *
6400 * @private
6401 * @param {string} key The key of the property to get.
6402 * @param {*} srcValue The value to match.
6403 * @returns {Function} Returns the new spec function.
6404 */
6405 function matchesStrictComparable(key, srcValue) {
6406 return function(object) {
6407 if (object == null) {
6408 return false;
6409 }
6410 return object[key] === srcValue &&
6411 (srcValue !== undefined || (key in Object(object)));
6412 };
6413 }
6414
6415 /**
6416 * A specialized version of `_.memoize` which clears the memoized function's
6417 * cache when it exceeds `MAX_MEMOIZE_SIZE`.
6418 *
6419 * @private
6420 * @param {Function} func The function to have its output memoized.
6421 * @returns {Function} Returns the new memoized function.
6422 */
6423 function memoizeCapped(func) {
6424 var result = memoize(func, function(key) {
6425 if (cache.size === MAX_MEMOIZE_SIZE) {
6426 cache.clear();
6427 }
6428 return key;
6429 });
6430
6431 var cache = result.cache;
6432 return result;
6433 }
6434
6435 /**
6436 * Merges the function metadata of `source` into `data`.
6437 *
6438 * Merging metadata reduces the number of wrappers used to invoke a function.
6439 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
6440 * may be applied regardless of execution order. Methods like `_.ary` and
6441 * `_.rearg` modify function arguments, making the order in which they are
6442 * executed important, preventing the merging of metadata. However, we make
6443 * an exception for a safe combined case where curried functions have `_.ary`
6444 * and or `_.rearg` applied.
6445 *
6446 * @private
6447 * @param {Array} data The destination metadata.
6448 * @param {Array} source The source metadata.
6449 * @returns {Array} Returns `data`.
6450 */
6451 function mergeData(data, source) {
6452 var bitmask = data[1],
6453 srcBitmask = source[1],
6454 newBitmask = bitmask | srcBitmask,
6455 isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
6456
6457 var isCombo =
6458 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
6459 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
6460 ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
6461
6462 // Exit early if metadata can't be merged.
6463 if (!(isCommon || isCombo)) {
6464 return data;
6465 }
6466 // Use source `thisArg` if available.
6467 if (srcBitmask & WRAP_BIND_FLAG) {
6468 data[2] = source[2];
6469 // Set when currying a bound function.
6470 newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
6471 }
6472 // Compose partial arguments.
6473 var value = source[3];
6474 if (value) {
6475 var partials = data[3];
6476 data[3] = partials ? composeArgs(partials, value, source[4]) : value;
6477 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
6478 }
6479 // Compose partial right arguments.
6480 value = source[5];
6481 if (value) {
6482 partials = data[5];
6483 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
6484 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
6485 }
6486 // Use source `argPos` if available.
6487 value = source[7];
6488 if (value) {
6489 data[7] = value;
6490 }
6491 // Use source `ary` if it's smaller.
6492 if (srcBitmask & WRAP_ARY_FLAG) {
6493 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
6494 }
6495 // Use source `arity` if one is not provided.
6496 if (data[9] == null) {
6497 data[9] = source[9];
6498 }
6499 // Use source `func` and merge bitmasks.
6500 data[0] = source[0];
6501 data[1] = newBitmask;
6502
6503 return data;
6504 }
6505
6506 /**
6507 * Used by `_.defaultsDeep` to customize its `_.merge` use.
6508 *
6509 * @private
6510 * @param {*} objValue The destination value.
6511 * @param {*} srcValue The source value.
6512 * @param {string} key The key of the property to merge.
6513 * @param {Object} object The parent object of `objValue`.
6514 * @param {Object} source The parent object of `srcValue`.
6515 * @param {Object} [stack] Tracks traversed source values and their merged
6516 * counterparts.
6517 * @returns {*} Returns the value to assign.
6518 */
6519 function mergeDefaults(objValue, srcValue, key, object, source, stack) {
6520 if (isObject(objValue) && isObject(srcValue)) {
6521 // Recursively merge objects and arrays (susceptible to call stack limits).
6522 stack.set(srcValue, objValue);
6523 baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
6524 stack['delete'](srcValue);
6525 }
6526 return objValue;
6527 }
6528
6529 /**
6530 * This function is like
6531 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
6532 * except that it includes inherited enumerable properties.
6533 *
6534 * @private
6535 * @param {Object} object The object to query.
6536 * @returns {Array} Returns the array of property names.
6537 */
6538 function nativeKeysIn(object) {
6539 var result = [];
6540 if (object != null) {
6541 for (var key in Object(object)) {
6542 result.push(key);
6543 }
6544 }
6545 return result;
6546 }
6547
6548 /**
6549 * Converts `value` to a string using `Object.prototype.toString`.
6550 *
6551 * @private
6552 * @param {*} value The value to convert.
6553 * @returns {string} Returns the converted string.
6554 */
6555 function objectToString(value) {
6556 return nativeObjectToString.call(value);
6557 }
6558
6559 /**
6560 * A specialized version of `baseRest` which transforms the rest array.
6561 *
6562 * @private
6563 * @param {Function} func The function to apply a rest parameter to.
6564 * @param {number} [start=func.length-1] The start position of the rest parameter.
6565 * @param {Function} transform The rest array transform.
6566 * @returns {Function} Returns the new function.
6567 */
6568 function overRest(func, start, transform) {
6569 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
6570 return function() {
6571 var args = arguments,
6572 index = -1,
6573 length = nativeMax(args.length - start, 0),
6574 array = Array(length);
6575
6576 while (++index < length) {
6577 array[index] = args[start + index];
6578 }
6579 index = -1;
6580 var otherArgs = Array(start + 1);
6581 while (++index < start) {
6582 otherArgs[index] = args[index];
6583 }
6584 otherArgs[start] = transform(array);
6585 return apply(func, this, otherArgs);
6586 };
6587 }
6588
6589 /**
6590 * Gets the parent value at `path` of `object`.
6591 *
6592 * @private
6593 * @param {Object} object The object to query.
6594 * @param {Array} path The path to get the parent value of.
6595 * @returns {*} Returns the parent value.
6596 */
6597 function parent(object, path) {
6598 return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
6599 }
6600
6601 /**
6602 * Reorder `array` according to the specified indexes where the element at
6603 * the first index is assigned as the first element, the element at
6604 * the second index is assigned as the second element, and so on.
6605 *
6606 * @private
6607 * @param {Array} array The array to reorder.
6608 * @param {Array} indexes The arranged array indexes.
6609 * @returns {Array} Returns `array`.
6610 */
6611 function reorder(array, indexes) {
6612 var arrLength = array.length,
6613 length = nativeMin(indexes.length, arrLength),
6614 oldArray = copyArray(array);
6615
6616 while (length--) {
6617 var index = indexes[length];
6618 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
6619 }
6620 return array;
6621 }
6622
6623 /**
6624 * Sets metadata for `func`.
6625 *
6626 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
6627 * period of time, it will trip its breaker and transition to an identity
6628 * function to avoid garbage collection pauses in V8. See
6629 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
6630 * for more details.
6631 *
6632 * @private
6633 * @param {Function} func The function to associate metadata with.
6634 * @param {*} data The metadata.
6635 * @returns {Function} Returns `func`.
6636 */
6637 var setData = shortOut(baseSetData);
6638
6639 /**
6640 * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
6641 *
6642 * @private
6643 * @param {Function} func The function to delay.
6644 * @param {number} wait The number of milliseconds to delay invocation.
6645 * @returns {number|Object} Returns the timer id or timeout object.
6646 */
6647 var setTimeout = ctxSetTimeout || function(func, wait) {
6648 return root.setTimeout(func, wait);
6649 };
6650
6651 /**
6652 * Sets the `toString` method of `func` to return `string`.
6653 *
6654 * @private
6655 * @param {Function} func The function to modify.
6656 * @param {Function} string The `toString` result.
6657 * @returns {Function} Returns `func`.
6658 */
6659 var setToString = shortOut(baseSetToString);
6660
6661 /**
6662 * Sets the `toString` method of `wrapper` to mimic the source of `reference`
6663 * with wrapper details in a comment at the top of the source body.
6664 *
6665 * @private
6666 * @param {Function} wrapper The function to modify.
6667 * @param {Function} reference The reference function.
6668 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6669 * @returns {Function} Returns `wrapper`.
6670 */
6671 function setWrapToString(wrapper, reference, bitmask) {
6672 var source = (reference + '');
6673 return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
6674 }
6675
6676 /**
6677 * Creates a function that'll short out and invoke `identity` instead
6678 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
6679 * milliseconds.
6680 *
6681 * @private
6682 * @param {Function} func The function to restrict.
6683 * @returns {Function} Returns the new shortable function.
6684 */
6685 function shortOut(func) {
6686 var count = 0,
6687 lastCalled = 0;
6688
6689 return function() {
6690 var stamp = nativeNow(),
6691 remaining = HOT_SPAN - (stamp - lastCalled);
6692
6693 lastCalled = stamp;
6694 if (remaining > 0) {
6695 if (++count >= HOT_COUNT) {
6696 return arguments[0];
6697 }
6698 } else {
6699 count = 0;
6700 }
6701 return func.apply(undefined, arguments);
6702 };
6703 }
6704
6705 /**
6706 * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
6707 *
6708 * @private
6709 * @param {Array} array The array to shuffle.
6710 * @param {number} [size=array.length] The size of `array`.
6711 * @returns {Array} Returns `array`.
6712 */
6713 function shuffleSelf(array, size) {
6714 var index = -1,
6715 length = array.length,
6716 lastIndex = length - 1;
6717
6718 size = size === undefined ? length : size;
6719 while (++index < size) {
6720 var rand = baseRandom(index, lastIndex),
6721 value = array[rand];
6722
6723 array[rand] = array[index];
6724 array[index] = value;
6725 }
6726 array.length = size;
6727 return array;
6728 }
6729
6730 /**
6731 * Converts `string` to a property path array.
6732 *
6733 * @private
6734 * @param {string} string The string to convert.
6735 * @returns {Array} Returns the property path array.
6736 */
6737 var stringToPath = memoizeCapped(function(string) {
6738 var result = [];
6739 if (reLeadingDot.test(string)) {
6740 result.push('');
6741 }
6742 string.replace(rePropName, function(match, number, quote, string) {
6743 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
6744 });
6745 return result;
6746 });
6747
6748 /**
6749 * Converts `value` to a string key if it's not a string or symbol.
6750 *
6751 * @private
6752 * @param {*} value The value to inspect.
6753 * @returns {string|symbol} Returns the key.
6754 */
6755 function toKey(value) {
6756 if (typeof value == 'string' || isSymbol(value)) {
6757 return value;
6758 }
6759 var result = (value + '');
6760 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
6761 }
6762
6763 /**
6764 * Converts `func` to its source code.
6765 *
6766 * @private
6767 * @param {Function} func The function to convert.
6768 * @returns {string} Returns the source code.
6769 */
6770 function toSource(func) {
6771 if (func != null) {
6772 try {
6773 return funcToString.call(func);
6774 } catch (e) {}
6775 try {
6776 return (func + '');
6777 } catch (e) {}
6778 }
6779 return '';
6780 }
6781
6782 /**
6783 * Updates wrapper `details` based on `bitmask` flags.
6784 *
6785 * @private
6786 * @returns {Array} details The details to modify.
6787 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6788 * @returns {Array} Returns `details`.
6789 */
6790 function updateWrapDetails(details, bitmask) {
6791 arrayEach(wrapFlags, function(pair) {
6792 var value = '_.' + pair[0];
6793 if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
6794 details.push(value);
6795 }
6796 });
6797 return details.sort();
6798 }
6799
6800 /**
6801 * Creates a clone of `wrapper`.
6802 *
6803 * @private
6804 * @param {Object} wrapper The wrapper to clone.
6805 * @returns {Object} Returns the cloned wrapper.
6806 */
6807 function wrapperClone(wrapper) {
6808 if (wrapper instanceof LazyWrapper) {
6809 return wrapper.clone();
6810 }
6811 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
6812 result.__actions__ = copyArray(wrapper.__actions__);
6813 result.__index__ = wrapper.__index__;
6814 result.__values__ = wrapper.__values__;
6815 return result;
6816 }
6817
6818 /*------------------------------------------------------------------------*/
6819
6820 /**
6821 * Creates an array of elements split into groups the length of `size`.
6822 * If `array` can't be split evenly, the final chunk will be the remaining
6823 * elements.
6824 *
6825 * @static
6826 * @memberOf _
6827 * @since 3.0.0
6828 * @category Array
6829 * @param {Array} array The array to process.
6830 * @param {number} [size=1] The length of each chunk
6831 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6832 * @returns {Array} Returns the new array of chunks.
6833 * @example
6834 *
6835 * _.chunk(['a', 'b', 'c', 'd'], 2);
6836 * // => [['a', 'b'], ['c', 'd']]
6837 *
6838 * _.chunk(['a', 'b', 'c', 'd'], 3);
6839 * // => [['a', 'b', 'c'], ['d']]
6840 */
6841 function chunk(array, size, guard) {
6842 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
6843 size = 1;
6844 } else {
6845 size = nativeMax(toInteger(size), 0);
6846 }
6847 var length = array == null ? 0 : array.length;
6848 if (!length || size < 1) {
6849 return [];
6850 }
6851 var index = 0,
6852 resIndex = 0,
6853 result = Array(nativeCeil(length / size));
6854
6855 while (index < length) {
6856 result[resIndex++] = baseSlice(array, index, (index += size));
6857 }
6858 return result;
6859 }
6860
6861 /**
6862 * Creates an array with all falsey values removed. The values `false`, `null`,
6863 * `0`, `""`, `undefined`, and `NaN` are falsey.
6864 *
6865 * @static
6866 * @memberOf _
6867 * @since 0.1.0
6868 * @category Array
6869 * @param {Array} array The array to compact.
6870 * @returns {Array} Returns the new array of filtered values.
6871 * @example
6872 *
6873 * _.compact([0, 1, false, 2, '', 3]);
6874 * // => [1, 2, 3]
6875 */
6876 function compact(array) {
6877 var index = -1,
6878 length = array == null ? 0 : array.length,
6879 resIndex = 0,
6880 result = [];
6881
6882 while (++index < length) {
6883 var value = array[index];
6884 if (value) {
6885 result[resIndex++] = value;
6886 }
6887 }
6888 return result;
6889 }
6890
6891 /**
6892 * Creates a new array concatenating `array` with any additional arrays
6893 * and/or values.
6894 *
6895 * @static
6896 * @memberOf _
6897 * @since 4.0.0
6898 * @category Array
6899 * @param {Array} array The array to concatenate.
6900 * @param {...*} [values] The values to concatenate.
6901 * @returns {Array} Returns the new concatenated array.
6902 * @example
6903 *
6904 * var array = [1];
6905 * var other = _.concat(array, 2, [3], [[4]]);
6906 *
6907 * console.log(other);
6908 * // => [1, 2, 3, [4]]
6909 *
6910 * console.log(array);
6911 * // => [1]
6912 */
6913 function concat() {
6914 var length = arguments.length;
6915 if (!length) {
6916 return [];
6917 }
6918 var args = Array(length - 1),
6919 array = arguments[0],
6920 index = length;
6921
6922 while (index--) {
6923 args[index - 1] = arguments[index];
6924 }
6925 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
6926 }
6927
6928 /**
6929 * Creates an array of `array` values not included in the other given arrays
6930 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
6931 * for equality comparisons. The order and references of result values are
6932 * determined by the first array.
6933 *
6934 * **Note:** Unlike `_.pullAll`, this method returns a new array.
6935 *
6936 * @static
6937 * @memberOf _
6938 * @since 0.1.0
6939 * @category Array
6940 * @param {Array} array The array to inspect.
6941 * @param {...Array} [values] The values to exclude.
6942 * @returns {Array} Returns the new array of filtered values.
6943 * @see _.without, _.xor
6944 * @example
6945 *
6946 * _.difference([2, 1], [2, 3]);
6947 * // => [1]
6948 */
6949 var difference = baseRest(function(array, values) {
6950 return isArrayLikeObject(array)
6951 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
6952 : [];
6953 });
6954
6955 /**
6956 * This method is like `_.difference` except that it accepts `iteratee` which
6957 * is invoked for each element of `array` and `values` to generate the criterion
6958 * by which they're compared. The order and references of result values are
6959 * determined by the first array. The iteratee is invoked with one argument:
6960 * (value).
6961 *
6962 * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
6963 *
6964 * @static
6965 * @memberOf _
6966 * @since 4.0.0
6967 * @category Array
6968 * @param {Array} array The array to inspect.
6969 * @param {...Array} [values] The values to exclude.
6970 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
6971 * @returns {Array} Returns the new array of filtered values.
6972 * @example
6973 *
6974 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
6975 * // => [1.2]
6976 *
6977 * // The `_.property` iteratee shorthand.
6978 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
6979 * // => [{ 'x': 2 }]
6980 */
6981 var differenceBy = baseRest(function(array, values) {
6982 var iteratee = last(values);
6983 if (isArrayLikeObject(iteratee)) {
6984 iteratee = undefined;
6985 }
6986 return isArrayLikeObject(array)
6987 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
6988 : [];
6989 });
6990
6991 /**
6992 * This method is like `_.difference` except that it accepts `comparator`
6993 * which is invoked to compare elements of `array` to `values`. The order and
6994 * references of result values are determined by the first array. The comparator
6995 * is invoked with two arguments: (arrVal, othVal).
6996 *
6997 * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
6998 *
6999 * @static
7000 * @memberOf _
7001 * @since 4.0.0
7002 * @category Array
7003 * @param {Array} array The array to inspect.
7004 * @param {...Array} [values] The values to exclude.
7005 * @param {Function} [comparator] The comparator invoked per element.
7006 * @returns {Array} Returns the new array of filtered values.
7007 * @example
7008 *
7009 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7010 *
7011 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
7012 * // => [{ 'x': 2, 'y': 1 }]
7013 */
7014 var differenceWith = baseRest(function(array, values) {
7015 var comparator = last(values);
7016 if (isArrayLikeObject(comparator)) {
7017 comparator = undefined;
7018 }
7019 return isArrayLikeObject(array)
7020 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
7021 : [];
7022 });
7023
7024 /**
7025 * Creates a slice of `array` with `n` elements dropped from the beginning.
7026 *
7027 * @static
7028 * @memberOf _
7029 * @since 0.5.0
7030 * @category Array
7031 * @param {Array} array The array to query.
7032 * @param {number} [n=1] The number of elements to drop.
7033 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7034 * @returns {Array} Returns the slice of `array`.
7035 * @example
7036 *
7037 * _.drop([1, 2, 3]);
7038 * // => [2, 3]
7039 *
7040 * _.drop([1, 2, 3], 2);
7041 * // => [3]
7042 *
7043 * _.drop([1, 2, 3], 5);
7044 * // => []
7045 *
7046 * _.drop([1, 2, 3], 0);
7047 * // => [1, 2, 3]
7048 */
7049 function drop(array, n, guard) {
7050 var length = array == null ? 0 : array.length;
7051 if (!length) {
7052 return [];
7053 }
7054 n = (guard || n === undefined) ? 1 : toInteger(n);
7055 return baseSlice(array, n < 0 ? 0 : n, length);
7056 }
7057
7058 /**
7059 * Creates a slice of `array` with `n` elements dropped from the end.
7060 *
7061 * @static
7062 * @memberOf _
7063 * @since 3.0.0
7064 * @category Array
7065 * @param {Array} array The array to query.
7066 * @param {number} [n=1] The number of elements to drop.
7067 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7068 * @returns {Array} Returns the slice of `array`.
7069 * @example
7070 *
7071 * _.dropRight([1, 2, 3]);
7072 * // => [1, 2]
7073 *
7074 * _.dropRight([1, 2, 3], 2);
7075 * // => [1]
7076 *
7077 * _.dropRight([1, 2, 3], 5);
7078 * // => []
7079 *
7080 * _.dropRight([1, 2, 3], 0);
7081 * // => [1, 2, 3]
7082 */
7083 function dropRight(array, n, guard) {
7084 var length = array == null ? 0 : array.length;
7085 if (!length) {
7086 return [];
7087 }
7088 n = (guard || n === undefined) ? 1 : toInteger(n);
7089 n = length - n;
7090 return baseSlice(array, 0, n < 0 ? 0 : n);
7091 }
7092
7093 /**
7094 * Creates a slice of `array` excluding elements dropped from the end.
7095 * Elements are dropped until `predicate` returns falsey. The predicate is
7096 * invoked with three arguments: (value, index, array).
7097 *
7098 * @static
7099 * @memberOf _
7100 * @since 3.0.0
7101 * @category Array
7102 * @param {Array} array The array to query.
7103 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7104 * @returns {Array} Returns the slice of `array`.
7105 * @example
7106 *
7107 * var users = [
7108 * { 'user': 'barney', 'active': true },
7109 * { 'user': 'fred', 'active': false },
7110 * { 'user': 'pebbles', 'active': false }
7111 * ];
7112 *
7113 * _.dropRightWhile(users, function(o) { return !o.active; });
7114 * // => objects for ['barney']
7115 *
7116 * // The `_.matches` iteratee shorthand.
7117 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
7118 * // => objects for ['barney', 'fred']
7119 *
7120 * // The `_.matchesProperty` iteratee shorthand.
7121 * _.dropRightWhile(users, ['active', false]);
7122 * // => objects for ['barney']
7123 *
7124 * // The `_.property` iteratee shorthand.
7125 * _.dropRightWhile(users, 'active');
7126 * // => objects for ['barney', 'fred', 'pebbles']
7127 */
7128 function dropRightWhile(array, predicate) {
7129 return (array && array.length)
7130 ? baseWhile(array, getIteratee(predicate, 3), true, true)
7131 : [];
7132 }
7133
7134 /**
7135 * Creates a slice of `array` excluding elements dropped from the beginning.
7136 * Elements are dropped until `predicate` returns falsey. The predicate is
7137 * invoked with three arguments: (value, index, array).
7138 *
7139 * @static
7140 * @memberOf _
7141 * @since 3.0.0
7142 * @category Array
7143 * @param {Array} array The array to query.
7144 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7145 * @returns {Array} Returns the slice of `array`.
7146 * @example
7147 *
7148 * var users = [
7149 * { 'user': 'barney', 'active': false },
7150 * { 'user': 'fred', 'active': false },
7151 * { 'user': 'pebbles', 'active': true }
7152 * ];
7153 *
7154 * _.dropWhile(users, function(o) { return !o.active; });
7155 * // => objects for ['pebbles']
7156 *
7157 * // The `_.matches` iteratee shorthand.
7158 * _.dropWhile(users, { 'user': 'barney', 'active': false });
7159 * // => objects for ['fred', 'pebbles']
7160 *
7161 * // The `_.matchesProperty` iteratee shorthand.
7162 * _.dropWhile(users, ['active', false]);
7163 * // => objects for ['pebbles']
7164 *
7165 * // The `_.property` iteratee shorthand.
7166 * _.dropWhile(users, 'active');
7167 * // => objects for ['barney', 'fred', 'pebbles']
7168 */
7169 function dropWhile(array, predicate) {
7170 return (array && array.length)
7171 ? baseWhile(array, getIteratee(predicate, 3), true)
7172 : [];
7173 }
7174
7175 /**
7176 * Fills elements of `array` with `value` from `start` up to, but not
7177 * including, `end`.
7178 *
7179 * **Note:** This method mutates `array`.
7180 *
7181 * @static
7182 * @memberOf _
7183 * @since 3.2.0
7184 * @category Array
7185 * @param {Array} array The array to fill.
7186 * @param {*} value The value to fill `array` with.
7187 * @param {number} [start=0] The start position.
7188 * @param {number} [end=array.length] The end position.
7189 * @returns {Array} Returns `array`.
7190 * @example
7191 *
7192 * var array = [1, 2, 3];
7193 *
7194 * _.fill(array, 'a');
7195 * console.log(array);
7196 * // => ['a', 'a', 'a']
7197 *
7198 * _.fill(Array(3), 2);
7199 * // => [2, 2, 2]
7200 *
7201 * _.fill([4, 6, 8, 10], '*', 1, 3);
7202 * // => [4, '*', '*', 10]
7203 */
7204 function fill(array, value, start, end) {
7205 var length = array == null ? 0 : array.length;
7206 if (!length) {
7207 return [];
7208 }
7209 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
7210 start = 0;
7211 end = length;
7212 }
7213 return baseFill(array, value, start, end);
7214 }
7215
7216 /**
7217 * This method is like `_.find` except that it returns the index of the first
7218 * element `predicate` returns truthy for instead of the element itself.
7219 *
7220 * @static
7221 * @memberOf _
7222 * @since 1.1.0
7223 * @category Array
7224 * @param {Array} array The array to inspect.
7225 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7226 * @param {number} [fromIndex=0] The index to search from.
7227 * @returns {number} Returns the index of the found element, else `-1`.
7228 * @example
7229 *
7230 * var users = [
7231 * { 'user': 'barney', 'active': false },
7232 * { 'user': 'fred', 'active': false },
7233 * { 'user': 'pebbles', 'active': true }
7234 * ];
7235 *
7236 * _.findIndex(users, function(o) { return o.user == 'barney'; });
7237 * // => 0
7238 *
7239 * // The `_.matches` iteratee shorthand.
7240 * _.findIndex(users, { 'user': 'fred', 'active': false });
7241 * // => 1
7242 *
7243 * // The `_.matchesProperty` iteratee shorthand.
7244 * _.findIndex(users, ['active', false]);
7245 * // => 0
7246 *
7247 * // The `_.property` iteratee shorthand.
7248 * _.findIndex(users, 'active');
7249 * // => 2
7250 */
7251 function findIndex(array, predicate, fromIndex) {
7252 var length = array == null ? 0 : array.length;
7253 if (!length) {
7254 return -1;
7255 }
7256 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7257 if (index < 0) {
7258 index = nativeMax(length + index, 0);
7259 }
7260 return baseFindIndex(array, getIteratee(predicate, 3), index);
7261 }
7262
7263 /**
7264 * This method is like `_.findIndex` except that it iterates over elements
7265 * of `collection` from right to left.
7266 *
7267 * @static
7268 * @memberOf _
7269 * @since 2.0.0
7270 * @category Array
7271 * @param {Array} array The array to inspect.
7272 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7273 * @param {number} [fromIndex=array.length-1] The index to search from.
7274 * @returns {number} Returns the index of the found element, else `-1`.
7275 * @example
7276 *
7277 * var users = [
7278 * { 'user': 'barney', 'active': true },
7279 * { 'user': 'fred', 'active': false },
7280 * { 'user': 'pebbles', 'active': false }
7281 * ];
7282 *
7283 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
7284 * // => 2
7285 *
7286 * // The `_.matches` iteratee shorthand.
7287 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
7288 * // => 0
7289 *
7290 * // The `_.matchesProperty` iteratee shorthand.
7291 * _.findLastIndex(users, ['active', false]);
7292 * // => 2
7293 *
7294 * // The `_.property` iteratee shorthand.
7295 * _.findLastIndex(users, 'active');
7296 * // => 0
7297 */
7298 function findLastIndex(array, predicate, fromIndex) {
7299 var length = array == null ? 0 : array.length;
7300 if (!length) {
7301 return -1;
7302 }
7303 var index = length - 1;
7304 if (fromIndex !== undefined) {
7305 index = toInteger(fromIndex);
7306 index = fromIndex < 0
7307 ? nativeMax(length + index, 0)
7308 : nativeMin(index, length - 1);
7309 }
7310 return baseFindIndex(array, getIteratee(predicate, 3), index, true);
7311 }
7312
7313 /**
7314 * Flattens `array` a single level deep.
7315 *
7316 * @static
7317 * @memberOf _
7318 * @since 0.1.0
7319 * @category Array
7320 * @param {Array} array The array to flatten.
7321 * @returns {Array} Returns the new flattened array.
7322 * @example
7323 *
7324 * _.flatten([1, [2, [3, [4]], 5]]);
7325 * // => [1, 2, [3, [4]], 5]
7326 */
7327 function flatten(array) {
7328 var length = array == null ? 0 : array.length;
7329 return length ? baseFlatten(array, 1) : [];
7330 }
7331
7332 /**
7333 * Recursively flattens `array`.
7334 *
7335 * @static
7336 * @memberOf _
7337 * @since 3.0.0
7338 * @category Array
7339 * @param {Array} array The array to flatten.
7340 * @returns {Array} Returns the new flattened array.
7341 * @example
7342 *
7343 * _.flattenDeep([1, [2, [3, [4]], 5]]);
7344 * // => [1, 2, 3, 4, 5]
7345 */
7346 function flattenDeep(array) {
7347 var length = array == null ? 0 : array.length;
7348 return length ? baseFlatten(array, INFINITY) : [];
7349 }
7350
7351 /**
7352 * Recursively flatten `array` up to `depth` times.
7353 *
7354 * @static
7355 * @memberOf _
7356 * @since 4.4.0
7357 * @category Array
7358 * @param {Array} array The array to flatten.
7359 * @param {number} [depth=1] The maximum recursion depth.
7360 * @returns {Array} Returns the new flattened array.
7361 * @example
7362 *
7363 * var array = [1, [2, [3, [4]], 5]];
7364 *
7365 * _.flattenDepth(array, 1);
7366 * // => [1, 2, [3, [4]], 5]
7367 *
7368 * _.flattenDepth(array, 2);
7369 * // => [1, 2, 3, [4], 5]
7370 */
7371 function flattenDepth(array, depth) {
7372 var length = array == null ? 0 : array.length;
7373 if (!length) {
7374 return [];
7375 }
7376 depth = depth === undefined ? 1 : toInteger(depth);
7377 return baseFlatten(array, depth);
7378 }
7379
7380 /**
7381 * The inverse of `_.toPairs`; this method returns an object composed
7382 * from key-value `pairs`.
7383 *
7384 * @static
7385 * @memberOf _
7386 * @since 4.0.0
7387 * @category Array
7388 * @param {Array} pairs The key-value pairs.
7389 * @returns {Object} Returns the new object.
7390 * @example
7391 *
7392 * _.fromPairs([['a', 1], ['b', 2]]);
7393 * // => { 'a': 1, 'b': 2 }
7394 */
7395 function fromPairs(pairs) {
7396 var index = -1,
7397 length = pairs == null ? 0 : pairs.length,
7398 result = {};
7399
7400 while (++index < length) {
7401 var pair = pairs[index];
7402 result[pair[0]] = pair[1];
7403 }
7404 return result;
7405 }
7406
7407 /**
7408 * Gets the first element of `array`.
7409 *
7410 * @static
7411 * @memberOf _
7412 * @since 0.1.0
7413 * @alias first
7414 * @category Array
7415 * @param {Array} array The array to query.
7416 * @returns {*} Returns the first element of `array`.
7417 * @example
7418 *
7419 * _.head([1, 2, 3]);
7420 * // => 1
7421 *
7422 * _.head([]);
7423 * // => undefined
7424 */
7425 function head(array) {
7426 return (array && array.length) ? array[0] : undefined;
7427 }
7428
7429 /**
7430 * Gets the index at which the first occurrence of `value` is found in `array`
7431 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7432 * for equality comparisons. If `fromIndex` is negative, it's used as the
7433 * offset from the end of `array`.
7434 *
7435 * @static
7436 * @memberOf _
7437 * @since 0.1.0
7438 * @category Array
7439 * @param {Array} array The array to inspect.
7440 * @param {*} value The value to search for.
7441 * @param {number} [fromIndex=0] The index to search from.
7442 * @returns {number} Returns the index of the matched value, else `-1`.
7443 * @example
7444 *
7445 * _.indexOf([1, 2, 1, 2], 2);
7446 * // => 1
7447 *
7448 * // Search from the `fromIndex`.
7449 * _.indexOf([1, 2, 1, 2], 2, 2);
7450 * // => 3
7451 */
7452 function indexOf(array, value, fromIndex) {
7453 var length = array == null ? 0 : array.length;
7454 if (!length) {
7455 return -1;
7456 }
7457 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7458 if (index < 0) {
7459 index = nativeMax(length + index, 0);
7460 }
7461 return baseIndexOf(array, value, index);
7462 }
7463
7464 /**
7465 * Gets all but the last element of `array`.
7466 *
7467 * @static
7468 * @memberOf _
7469 * @since 0.1.0
7470 * @category Array
7471 * @param {Array} array The array to query.
7472 * @returns {Array} Returns the slice of `array`.
7473 * @example
7474 *
7475 * _.initial([1, 2, 3]);
7476 * // => [1, 2]
7477 */
7478 function initial(array) {
7479 var length = array == null ? 0 : array.length;
7480 return length ? baseSlice(array, 0, -1) : [];
7481 }
7482
7483 /**
7484 * Creates an array of unique values that are included in all given arrays
7485 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7486 * for equality comparisons. The order and references of result values are
7487 * determined by the first array.
7488 *
7489 * @static
7490 * @memberOf _
7491 * @since 0.1.0
7492 * @category Array
7493 * @param {...Array} [arrays] The arrays to inspect.
7494 * @returns {Array} Returns the new array of intersecting values.
7495 * @example
7496 *
7497 * _.intersection([2, 1], [2, 3]);
7498 * // => [2]
7499 */
7500 var intersection = baseRest(function(arrays) {
7501 var mapped = arrayMap(arrays, castArrayLikeObject);
7502 return (mapped.length && mapped[0] === arrays[0])
7503 ? baseIntersection(mapped)
7504 : [];
7505 });
7506
7507 /**
7508 * This method is like `_.intersection` except that it accepts `iteratee`
7509 * which is invoked for each element of each `arrays` to generate the criterion
7510 * by which they're compared. The order and references of result values are
7511 * determined by the first array. The iteratee is invoked with one argument:
7512 * (value).
7513 *
7514 * @static
7515 * @memberOf _
7516 * @since 4.0.0
7517 * @category Array
7518 * @param {...Array} [arrays] The arrays to inspect.
7519 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7520 * @returns {Array} Returns the new array of intersecting values.
7521 * @example
7522 *
7523 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7524 * // => [2.1]
7525 *
7526 * // The `_.property` iteratee shorthand.
7527 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7528 * // => [{ 'x': 1 }]
7529 */
7530 var intersectionBy = baseRest(function(arrays) {
7531 var iteratee = last(arrays),
7532 mapped = arrayMap(arrays, castArrayLikeObject);
7533
7534 if (iteratee === last(mapped)) {
7535 iteratee = undefined;
7536 } else {
7537 mapped.pop();
7538 }
7539 return (mapped.length && mapped[0] === arrays[0])
7540 ? baseIntersection(mapped, getIteratee(iteratee, 2))
7541 : [];
7542 });
7543
7544 /**
7545 * This method is like `_.intersection` except that it accepts `comparator`
7546 * which is invoked to compare elements of `arrays`. The order and references
7547 * of result values are determined by the first array. The comparator is
7548 * invoked with two arguments: (arrVal, othVal).
7549 *
7550 * @static
7551 * @memberOf _
7552 * @since 4.0.0
7553 * @category Array
7554 * @param {...Array} [arrays] The arrays to inspect.
7555 * @param {Function} [comparator] The comparator invoked per element.
7556 * @returns {Array} Returns the new array of intersecting values.
7557 * @example
7558 *
7559 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7560 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7561 *
7562 * _.intersectionWith(objects, others, _.isEqual);
7563 * // => [{ 'x': 1, 'y': 2 }]
7564 */
7565 var intersectionWith = baseRest(function(arrays) {
7566 var comparator = last(arrays),
7567 mapped = arrayMap(arrays, castArrayLikeObject);
7568
7569 comparator = typeof comparator == 'function' ? comparator : undefined;
7570 if (comparator) {
7571 mapped.pop();
7572 }
7573 return (mapped.length && mapped[0] === arrays[0])
7574 ? baseIntersection(mapped, undefined, comparator)
7575 : [];
7576 });
7577
7578 /**
7579 * Converts all elements in `array` into a string separated by `separator`.
7580 *
7581 * @static
7582 * @memberOf _
7583 * @since 4.0.0
7584 * @category Array
7585 * @param {Array} array The array to convert.
7586 * @param {string} [separator=','] The element separator.
7587 * @returns {string} Returns the joined string.
7588 * @example
7589 *
7590 * _.join(['a', 'b', 'c'], '~');
7591 * // => 'a~b~c'
7592 */
7593 function join(array, separator) {
7594 return array == null ? '' : nativeJoin.call(array, separator);
7595 }
7596
7597 /**
7598 * Gets the last element of `array`.
7599 *
7600 * @static
7601 * @memberOf _
7602 * @since 0.1.0
7603 * @category Array
7604 * @param {Array} array The array to query.
7605 * @returns {*} Returns the last element of `array`.
7606 * @example
7607 *
7608 * _.last([1, 2, 3]);
7609 * // => 3
7610 */
7611 function last(array) {
7612 var length = array == null ? 0 : array.length;
7613 return length ? array[length - 1] : undefined;
7614 }
7615
7616 /**
7617 * This method is like `_.indexOf` except that it iterates over elements of
7618 * `array` from right to left.
7619 *
7620 * @static
7621 * @memberOf _
7622 * @since 0.1.0
7623 * @category Array
7624 * @param {Array} array The array to inspect.
7625 * @param {*} value The value to search for.
7626 * @param {number} [fromIndex=array.length-1] The index to search from.
7627 * @returns {number} Returns the index of the matched value, else `-1`.
7628 * @example
7629 *
7630 * _.lastIndexOf([1, 2, 1, 2], 2);
7631 * // => 3
7632 *
7633 * // Search from the `fromIndex`.
7634 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
7635 * // => 1
7636 */
7637 function lastIndexOf(array, value, fromIndex) {
7638 var length = array == null ? 0 : array.length;
7639 if (!length) {
7640 return -1;
7641 }
7642 var index = length;
7643 if (fromIndex !== undefined) {
7644 index = toInteger(fromIndex);
7645 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
7646 }
7647 return value === value
7648 ? strictLastIndexOf(array, value, index)
7649 : baseFindIndex(array, baseIsNaN, index, true);
7650 }
7651
7652 /**
7653 * Gets the element at index `n` of `array`. If `n` is negative, the nth
7654 * element from the end is returned.
7655 *
7656 * @static
7657 * @memberOf _
7658 * @since 4.11.0
7659 * @category Array
7660 * @param {Array} array The array to query.
7661 * @param {number} [n=0] The index of the element to return.
7662 * @returns {*} Returns the nth element of `array`.
7663 * @example
7664 *
7665 * var array = ['a', 'b', 'c', 'd'];
7666 *
7667 * _.nth(array, 1);
7668 * // => 'b'
7669 *
7670 * _.nth(array, -2);
7671 * // => 'c';
7672 */
7673 function nth(array, n) {
7674 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
7675 }
7676
7677 /**
7678 * Removes all given values from `array` using
7679 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7680 * for equality comparisons.
7681 *
7682 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
7683 * to remove elements from an array by predicate.
7684 *
7685 * @static
7686 * @memberOf _
7687 * @since 2.0.0
7688 * @category Array
7689 * @param {Array} array The array to modify.
7690 * @param {...*} [values] The values to remove.
7691 * @returns {Array} Returns `array`.
7692 * @example
7693 *
7694 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7695 *
7696 * _.pull(array, 'a', 'c');
7697 * console.log(array);
7698 * // => ['b', 'b']
7699 */
7700 var pull = baseRest(pullAll);
7701
7702 /**
7703 * This method is like `_.pull` except that it accepts an array of values to remove.
7704 *
7705 * **Note:** Unlike `_.difference`, this method mutates `array`.
7706 *
7707 * @static
7708 * @memberOf _
7709 * @since 4.0.0
7710 * @category Array
7711 * @param {Array} array The array to modify.
7712 * @param {Array} values The values to remove.
7713 * @returns {Array} Returns `array`.
7714 * @example
7715 *
7716 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7717 *
7718 * _.pullAll(array, ['a', 'c']);
7719 * console.log(array);
7720 * // => ['b', 'b']
7721 */
7722 function pullAll(array, values) {
7723 return (array && array.length && values && values.length)
7724 ? basePullAll(array, values)
7725 : array;
7726 }
7727
7728 /**
7729 * This method is like `_.pullAll` except that it accepts `iteratee` which is
7730 * invoked for each element of `array` and `values` to generate the criterion
7731 * by which they're compared. The iteratee is invoked with one argument: (value).
7732 *
7733 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
7734 *
7735 * @static
7736 * @memberOf _
7737 * @since 4.0.0
7738 * @category Array
7739 * @param {Array} array The array to modify.
7740 * @param {Array} values The values to remove.
7741 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7742 * @returns {Array} Returns `array`.
7743 * @example
7744 *
7745 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
7746 *
7747 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
7748 * console.log(array);
7749 * // => [{ 'x': 2 }]
7750 */
7751 function pullAllBy(array, values, iteratee) {
7752 return (array && array.length && values && values.length)
7753 ? basePullAll(array, values, getIteratee(iteratee, 2))
7754 : array;
7755 }
7756
7757 /**
7758 * This method is like `_.pullAll` except that it accepts `comparator` which
7759 * is invoked to compare elements of `array` to `values`. The comparator is
7760 * invoked with two arguments: (arrVal, othVal).
7761 *
7762 * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
7763 *
7764 * @static
7765 * @memberOf _
7766 * @since 4.6.0
7767 * @category Array
7768 * @param {Array} array The array to modify.
7769 * @param {Array} values The values to remove.
7770 * @param {Function} [comparator] The comparator invoked per element.
7771 * @returns {Array} Returns `array`.
7772 * @example
7773 *
7774 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
7775 *
7776 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
7777 * console.log(array);
7778 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
7779 */
7780 function pullAllWith(array, values, comparator) {
7781 return (array && array.length && values && values.length)
7782 ? basePullAll(array, values, undefined, comparator)
7783 : array;
7784 }
7785
7786 /**
7787 * Removes elements from `array` corresponding to `indexes` and returns an
7788 * array of removed elements.
7789 *
7790 * **Note:** Unlike `_.at`, this method mutates `array`.
7791 *
7792 * @static
7793 * @memberOf _
7794 * @since 3.0.0
7795 * @category Array
7796 * @param {Array} array The array to modify.
7797 * @param {...(number|number[])} [indexes] The indexes of elements to remove.
7798 * @returns {Array} Returns the new array of removed elements.
7799 * @example
7800 *
7801 * var array = ['a', 'b', 'c', 'd'];
7802 * var pulled = _.pullAt(array, [1, 3]);
7803 *
7804 * console.log(array);
7805 * // => ['a', 'c']
7806 *
7807 * console.log(pulled);
7808 * // => ['b', 'd']
7809 */
7810 var pullAt = flatRest(function(array, indexes) {
7811 var length = array == null ? 0 : array.length,
7812 result = baseAt(array, indexes);
7813
7814 basePullAt(array, arrayMap(indexes, function(index) {
7815 return isIndex(index, length) ? +index : index;
7816 }).sort(compareAscending));
7817
7818 return result;
7819 });
7820
7821 /**
7822 * Removes all elements from `array` that `predicate` returns truthy for
7823 * and returns an array of the removed elements. The predicate is invoked
7824 * with three arguments: (value, index, array).
7825 *
7826 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
7827 * to pull elements from an array by value.
7828 *
7829 * @static
7830 * @memberOf _
7831 * @since 2.0.0
7832 * @category Array
7833 * @param {Array} array The array to modify.
7834 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7835 * @returns {Array} Returns the new array of removed elements.
7836 * @example
7837 *
7838 * var array = [1, 2, 3, 4];
7839 * var evens = _.remove(array, function(n) {
7840 * return n % 2 == 0;
7841 * });
7842 *
7843 * console.log(array);
7844 * // => [1, 3]
7845 *
7846 * console.log(evens);
7847 * // => [2, 4]
7848 */
7849 function remove(array, predicate) {
7850 var result = [];
7851 if (!(array && array.length)) {
7852 return result;
7853 }
7854 var index = -1,
7855 indexes = [],
7856 length = array.length;
7857
7858 predicate = getIteratee(predicate, 3);
7859 while (++index < length) {
7860 var value = array[index];
7861 if (predicate(value, index, array)) {
7862 result.push(value);
7863 indexes.push(index);
7864 }
7865 }
7866 basePullAt(array, indexes);
7867 return result;
7868 }
7869
7870 /**
7871 * Reverses `array` so that the first element becomes the last, the second
7872 * element becomes the second to last, and so on.
7873 *
7874 * **Note:** This method mutates `array` and is based on
7875 * [`Array#reverse`](https://mdn.io/Array/reverse).
7876 *
7877 * @static
7878 * @memberOf _
7879 * @since 4.0.0
7880 * @category Array
7881 * @param {Array} array The array to modify.
7882 * @returns {Array} Returns `array`.
7883 * @example
7884 *
7885 * var array = [1, 2, 3];
7886 *
7887 * _.reverse(array);
7888 * // => [3, 2, 1]
7889 *
7890 * console.log(array);
7891 * // => [3, 2, 1]
7892 */
7893 function reverse(array) {
7894 return array == null ? array : nativeReverse.call(array);
7895 }
7896
7897 /**
7898 * Creates a slice of `array` from `start` up to, but not including, `end`.
7899 *
7900 * **Note:** This method is used instead of
7901 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
7902 * returned.
7903 *
7904 * @static
7905 * @memberOf _
7906 * @since 3.0.0
7907 * @category Array
7908 * @param {Array} array The array to slice.
7909 * @param {number} [start=0] The start position.
7910 * @param {number} [end=array.length] The end position.
7911 * @returns {Array} Returns the slice of `array`.
7912 */
7913 function slice(array, start, end) {
7914 var length = array == null ? 0 : array.length;
7915 if (!length) {
7916 return [];
7917 }
7918 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
7919 start = 0;
7920 end = length;
7921 }
7922 else {
7923 start = start == null ? 0 : toInteger(start);
7924 end = end === undefined ? length : toInteger(end);
7925 }
7926 return baseSlice(array, start, end);
7927 }
7928
7929 /**
7930 * Uses a binary search to determine the lowest index at which `value`
7931 * should be inserted into `array` in order to maintain its sort order.
7932 *
7933 * @static
7934 * @memberOf _
7935 * @since 0.1.0
7936 * @category Array
7937 * @param {Array} array The sorted array to inspect.
7938 * @param {*} value The value to evaluate.
7939 * @returns {number} Returns the index at which `value` should be inserted
7940 * into `array`.
7941 * @example
7942 *
7943 * _.sortedIndex([30, 50], 40);
7944 * // => 1
7945 */
7946 function sortedIndex(array, value) {
7947 return baseSortedIndex(array, value);
7948 }
7949
7950 /**
7951 * This method is like `_.sortedIndex` except that it accepts `iteratee`
7952 * which is invoked for `value` and each element of `array` to compute their
7953 * sort ranking. The iteratee is invoked with one argument: (value).
7954 *
7955 * @static
7956 * @memberOf _
7957 * @since 4.0.0
7958 * @category Array
7959 * @param {Array} array The sorted array to inspect.
7960 * @param {*} value The value to evaluate.
7961 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7962 * @returns {number} Returns the index at which `value` should be inserted
7963 * into `array`.
7964 * @example
7965 *
7966 * var objects = [{ 'x': 4 }, { 'x': 5 }];
7967 *
7968 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
7969 * // => 0
7970 *
7971 * // The `_.property` iteratee shorthand.
7972 * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
7973 * // => 0
7974 */
7975 function sortedIndexBy(array, value, iteratee) {
7976 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
7977 }
7978
7979 /**
7980 * This method is like `_.indexOf` except that it performs a binary
7981 * search on a sorted `array`.
7982 *
7983 * @static
7984 * @memberOf _
7985 * @since 4.0.0
7986 * @category Array
7987 * @param {Array} array The array to inspect.
7988 * @param {*} value The value to search for.
7989 * @returns {number} Returns the index of the matched value, else `-1`.
7990 * @example
7991 *
7992 * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
7993 * // => 1
7994 */
7995 function sortedIndexOf(array, value) {
7996 var length = array == null ? 0 : array.length;
7997 if (length) {
7998 var index = baseSortedIndex(array, value);
7999 if (index < length && eq(array[index], value)) {
8000 return index;
8001 }
8002 }
8003 return -1;
8004 }
8005
8006 /**
8007 * This method is like `_.sortedIndex` except that it returns the highest
8008 * index at which `value` should be inserted into `array` in order to
8009 * maintain its sort order.
8010 *
8011 * @static
8012 * @memberOf _
8013 * @since 3.0.0
8014 * @category Array
8015 * @param {Array} array The sorted array to inspect.
8016 * @param {*} value The value to evaluate.
8017 * @returns {number} Returns the index at which `value` should be inserted
8018 * into `array`.
8019 * @example
8020 *
8021 * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
8022 * // => 4
8023 */
8024 function sortedLastIndex(array, value) {
8025 return baseSortedIndex(array, value, true);
8026 }
8027
8028 /**
8029 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
8030 * which is invoked for `value` and each element of `array` to compute their
8031 * sort ranking. The iteratee is invoked with one argument: (value).
8032 *
8033 * @static
8034 * @memberOf _
8035 * @since 4.0.0
8036 * @category Array
8037 * @param {Array} array The sorted array to inspect.
8038 * @param {*} value The value to evaluate.
8039 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8040 * @returns {number} Returns the index at which `value` should be inserted
8041 * into `array`.
8042 * @example
8043 *
8044 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8045 *
8046 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8047 * // => 1
8048 *
8049 * // The `_.property` iteratee shorthand.
8050 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
8051 * // => 1
8052 */
8053 function sortedLastIndexBy(array, value, iteratee) {
8054 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
8055 }
8056
8057 /**
8058 * This method is like `_.lastIndexOf` except that it performs a binary
8059 * search on a sorted `array`.
8060 *
8061 * @static
8062 * @memberOf _
8063 * @since 4.0.0
8064 * @category Array
8065 * @param {Array} array The array to inspect.
8066 * @param {*} value The value to search for.
8067 * @returns {number} Returns the index of the matched value, else `-1`.
8068 * @example
8069 *
8070 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
8071 * // => 3
8072 */
8073 function sortedLastIndexOf(array, value) {
8074 var length = array == null ? 0 : array.length;
8075 if (length) {
8076 var index = baseSortedIndex(array, value, true) - 1;
8077 if (eq(array[index], value)) {
8078 return index;
8079 }
8080 }
8081 return -1;
8082 }
8083
8084 /**
8085 * This method is like `_.uniq` except that it's designed and optimized
8086 * for sorted arrays.
8087 *
8088 * @static
8089 * @memberOf _
8090 * @since 4.0.0
8091 * @category Array
8092 * @param {Array} array The array to inspect.
8093 * @returns {Array} Returns the new duplicate free array.
8094 * @example
8095 *
8096 * _.sortedUniq([1, 1, 2]);
8097 * // => [1, 2]
8098 */
8099 function sortedUniq(array) {
8100 return (array && array.length)
8101 ? baseSortedUniq(array)
8102 : [];
8103 }
8104
8105 /**
8106 * This method is like `_.uniqBy` except that it's designed and optimized
8107 * for sorted arrays.
8108 *
8109 * @static
8110 * @memberOf _
8111 * @since 4.0.0
8112 * @category Array
8113 * @param {Array} array The array to inspect.
8114 * @param {Function} [iteratee] The iteratee invoked per element.
8115 * @returns {Array} Returns the new duplicate free array.
8116 * @example
8117 *
8118 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
8119 * // => [1.1, 2.3]
8120 */
8121 function sortedUniqBy(array, iteratee) {
8122 return (array && array.length)
8123 ? baseSortedUniq(array, getIteratee(iteratee, 2))
8124 : [];
8125 }
8126
8127 /**
8128 * Gets all but the first element of `array`.
8129 *
8130 * @static
8131 * @memberOf _
8132 * @since 4.0.0
8133 * @category Array
8134 * @param {Array} array The array to query.
8135 * @returns {Array} Returns the slice of `array`.
8136 * @example
8137 *
8138 * _.tail([1, 2, 3]);
8139 * // => [2, 3]
8140 */
8141 function tail(array) {
8142 var length = array == null ? 0 : array.length;
8143 return length ? baseSlice(array, 1, length) : [];
8144 }
8145
8146 /**
8147 * Creates a slice of `array` with `n` elements taken from the beginning.
8148 *
8149 * @static
8150 * @memberOf _
8151 * @since 0.1.0
8152 * @category Array
8153 * @param {Array} array The array to query.
8154 * @param {number} [n=1] The number of elements to take.
8155 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8156 * @returns {Array} Returns the slice of `array`.
8157 * @example
8158 *
8159 * _.take([1, 2, 3]);
8160 * // => [1]
8161 *
8162 * _.take([1, 2, 3], 2);
8163 * // => [1, 2]
8164 *
8165 * _.take([1, 2, 3], 5);
8166 * // => [1, 2, 3]
8167 *
8168 * _.take([1, 2, 3], 0);
8169 * // => []
8170 */
8171 function take(array, n, guard) {
8172 if (!(array && array.length)) {
8173 return [];
8174 }
8175 n = (guard || n === undefined) ? 1 : toInteger(n);
8176 return baseSlice(array, 0, n < 0 ? 0 : n);
8177 }
8178
8179 /**
8180 * Creates a slice of `array` with `n` elements taken from the end.
8181 *
8182 * @static
8183 * @memberOf _
8184 * @since 3.0.0
8185 * @category Array
8186 * @param {Array} array The array to query.
8187 * @param {number} [n=1] The number of elements to take.
8188 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8189 * @returns {Array} Returns the slice of `array`.
8190 * @example
8191 *
8192 * _.takeRight([1, 2, 3]);
8193 * // => [3]
8194 *
8195 * _.takeRight([1, 2, 3], 2);
8196 * // => [2, 3]
8197 *
8198 * _.takeRight([1, 2, 3], 5);
8199 * // => [1, 2, 3]
8200 *
8201 * _.takeRight([1, 2, 3], 0);
8202 * // => []
8203 */
8204 function takeRight(array, n, guard) {
8205 var length = array == null ? 0 : array.length;
8206 if (!length) {
8207 return [];
8208 }
8209 n = (guard || n === undefined) ? 1 : toInteger(n);
8210 n = length - n;
8211 return baseSlice(array, n < 0 ? 0 : n, length);
8212 }
8213
8214 /**
8215 * Creates a slice of `array` with elements taken from the end. Elements are
8216 * taken until `predicate` returns falsey. The predicate is invoked with
8217 * three arguments: (value, index, array).
8218 *
8219 * @static
8220 * @memberOf _
8221 * @since 3.0.0
8222 * @category Array
8223 * @param {Array} array The array to query.
8224 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8225 * @returns {Array} Returns the slice of `array`.
8226 * @example
8227 *
8228 * var users = [
8229 * { 'user': 'barney', 'active': true },
8230 * { 'user': 'fred', 'active': false },
8231 * { 'user': 'pebbles', 'active': false }
8232 * ];
8233 *
8234 * _.takeRightWhile(users, function(o) { return !o.active; });
8235 * // => objects for ['fred', 'pebbles']
8236 *
8237 * // The `_.matches` iteratee shorthand.
8238 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
8239 * // => objects for ['pebbles']
8240 *
8241 * // The `_.matchesProperty` iteratee shorthand.
8242 * _.takeRightWhile(users, ['active', false]);
8243 * // => objects for ['fred', 'pebbles']
8244 *
8245 * // The `_.property` iteratee shorthand.
8246 * _.takeRightWhile(users, 'active');
8247 * // => []
8248 */
8249 function takeRightWhile(array, predicate) {
8250 return (array && array.length)
8251 ? baseWhile(array, getIteratee(predicate, 3), false, true)
8252 : [];
8253 }
8254
8255 /**
8256 * Creates a slice of `array` with elements taken from the beginning. Elements
8257 * are taken until `predicate` returns falsey. The predicate is invoked with
8258 * three arguments: (value, index, array).
8259 *
8260 * @static
8261 * @memberOf _
8262 * @since 3.0.0
8263 * @category Array
8264 * @param {Array} array The array to query.
8265 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8266 * @returns {Array} Returns the slice of `array`.
8267 * @example
8268 *
8269 * var users = [
8270 * { 'user': 'barney', 'active': false },
8271 * { 'user': 'fred', 'active': false},
8272 * { 'user': 'pebbles', 'active': true }
8273 * ];
8274 *
8275 * _.takeWhile(users, function(o) { return !o.active; });
8276 * // => objects for ['barney', 'fred']
8277 *
8278 * // The `_.matches` iteratee shorthand.
8279 * _.takeWhile(users, { 'user': 'barney', 'active': false });
8280 * // => objects for ['barney']
8281 *
8282 * // The `_.matchesProperty` iteratee shorthand.
8283 * _.takeWhile(users, ['active', false]);
8284 * // => objects for ['barney', 'fred']
8285 *
8286 * // The `_.property` iteratee shorthand.
8287 * _.takeWhile(users, 'active');
8288 * // => []
8289 */
8290 function takeWhile(array, predicate) {
8291 return (array && array.length)
8292 ? baseWhile(array, getIteratee(predicate, 3))
8293 : [];
8294 }
8295
8296 /**
8297 * Creates an array of unique values, in order, from all given arrays using
8298 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8299 * for equality comparisons.
8300 *
8301 * @static
8302 * @memberOf _
8303 * @since 0.1.0
8304 * @category Array
8305 * @param {...Array} [arrays] The arrays to inspect.
8306 * @returns {Array} Returns the new array of combined values.
8307 * @example
8308 *
8309 * _.union([2], [1, 2]);
8310 * // => [2, 1]
8311 */
8312 var union = baseRest(function(arrays) {
8313 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
8314 });
8315
8316 /**
8317 * This method is like `_.union` except that it accepts `iteratee` which is
8318 * invoked for each element of each `arrays` to generate the criterion by
8319 * which uniqueness is computed. Result values are chosen from the first
8320 * array in which the value occurs. The iteratee is invoked with one argument:
8321 * (value).
8322 *
8323 * @static
8324 * @memberOf _
8325 * @since 4.0.0
8326 * @category Array
8327 * @param {...Array} [arrays] The arrays to inspect.
8328 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8329 * @returns {Array} Returns the new array of combined values.
8330 * @example
8331 *
8332 * _.unionBy([2.1], [1.2, 2.3], Math.floor);
8333 * // => [2.1, 1.2]
8334 *
8335 * // The `_.property` iteratee shorthand.
8336 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8337 * // => [{ 'x': 1 }, { 'x': 2 }]
8338 */
8339 var unionBy = baseRest(function(arrays) {
8340 var iteratee = last(arrays);
8341 if (isArrayLikeObject(iteratee)) {
8342 iteratee = undefined;
8343 }
8344 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
8345 });
8346
8347 /**
8348 * This method is like `_.union` except that it accepts `comparator` which
8349 * is invoked to compare elements of `arrays`. Result values are chosen from
8350 * the first array in which the value occurs. The comparator is invoked
8351 * with two arguments: (arrVal, othVal).
8352 *
8353 * @static
8354 * @memberOf _
8355 * @since 4.0.0
8356 * @category Array
8357 * @param {...Array} [arrays] The arrays to inspect.
8358 * @param {Function} [comparator] The comparator invoked per element.
8359 * @returns {Array} Returns the new array of combined values.
8360 * @example
8361 *
8362 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8363 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8364 *
8365 * _.unionWith(objects, others, _.isEqual);
8366 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8367 */
8368 var unionWith = baseRest(function(arrays) {
8369 var comparator = last(arrays);
8370 comparator = typeof comparator == 'function' ? comparator : undefined;
8371 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
8372 });
8373
8374 /**
8375 * Creates a duplicate-free version of an array, using
8376 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8377 * for equality comparisons, in which only the first occurrence of each element
8378 * is kept. The order of result values is determined by the order they occur
8379 * in the array.
8380 *
8381 * @static
8382 * @memberOf _
8383 * @since 0.1.0
8384 * @category Array
8385 * @param {Array} array The array to inspect.
8386 * @returns {Array} Returns the new duplicate free array.
8387 * @example
8388 *
8389 * _.uniq([2, 1, 2]);
8390 * // => [2, 1]
8391 */
8392 function uniq(array) {
8393 return (array && array.length) ? baseUniq(array) : [];
8394 }
8395
8396 /**
8397 * This method is like `_.uniq` except that it accepts `iteratee` which is
8398 * invoked for each element in `array` to generate the criterion by which
8399 * uniqueness is computed. The order of result values is determined by the
8400 * order they occur in the array. The iteratee is invoked with one argument:
8401 * (value).
8402 *
8403 * @static
8404 * @memberOf _
8405 * @since 4.0.0
8406 * @category Array
8407 * @param {Array} array The array to inspect.
8408 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8409 * @returns {Array} Returns the new duplicate free array.
8410 * @example
8411 *
8412 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
8413 * // => [2.1, 1.2]
8414 *
8415 * // The `_.property` iteratee shorthand.
8416 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
8417 * // => [{ 'x': 1 }, { 'x': 2 }]
8418 */
8419 function uniqBy(array, iteratee) {
8420 return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
8421 }
8422
8423 /**
8424 * This method is like `_.uniq` except that it accepts `comparator` which
8425 * is invoked to compare elements of `array`. The order of result values is
8426 * determined by the order they occur in the array.The comparator is invoked
8427 * with two arguments: (arrVal, othVal).
8428 *
8429 * @static
8430 * @memberOf _
8431 * @since 4.0.0
8432 * @category Array
8433 * @param {Array} array The array to inspect.
8434 * @param {Function} [comparator] The comparator invoked per element.
8435 * @returns {Array} Returns the new duplicate free array.
8436 * @example
8437 *
8438 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
8439 *
8440 * _.uniqWith(objects, _.isEqual);
8441 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
8442 */
8443 function uniqWith(array, comparator) {
8444 comparator = typeof comparator == 'function' ? comparator : undefined;
8445 return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
8446 }
8447
8448 /**
8449 * This method is like `_.zip` except that it accepts an array of grouped
8450 * elements and creates an array regrouping the elements to their pre-zip
8451 * configuration.
8452 *
8453 * @static
8454 * @memberOf _
8455 * @since 1.2.0
8456 * @category Array
8457 * @param {Array} array The array of grouped elements to process.
8458 * @returns {Array} Returns the new array of regrouped elements.
8459 * @example
8460 *
8461 * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
8462 * // => [['a', 1, true], ['b', 2, false]]
8463 *
8464 * _.unzip(zipped);
8465 * // => [['a', 'b'], [1, 2], [true, false]]
8466 */
8467 function unzip(array) {
8468 if (!(array && array.length)) {
8469 return [];
8470 }
8471 var length = 0;
8472 array = arrayFilter(array, function(group) {
8473 if (isArrayLikeObject(group)) {
8474 length = nativeMax(group.length, length);
8475 return true;
8476 }
8477 });
8478 return baseTimes(length, function(index) {
8479 return arrayMap(array, baseProperty(index));
8480 });
8481 }
8482
8483 /**
8484 * This method is like `_.unzip` except that it accepts `iteratee` to specify
8485 * how regrouped values should be combined. The iteratee is invoked with the
8486 * elements of each group: (...group).
8487 *
8488 * @static
8489 * @memberOf _
8490 * @since 3.8.0
8491 * @category Array
8492 * @param {Array} array The array of grouped elements to process.
8493 * @param {Function} [iteratee=_.identity] The function to combine
8494 * regrouped values.
8495 * @returns {Array} Returns the new array of regrouped elements.
8496 * @example
8497 *
8498 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
8499 * // => [[1, 10, 100], [2, 20, 200]]
8500 *
8501 * _.unzipWith(zipped, _.add);
8502 * // => [3, 30, 300]
8503 */
8504 function unzipWith(array, iteratee) {
8505 if (!(array && array.length)) {
8506 return [];
8507 }
8508 var result = unzip(array);
8509 if (iteratee == null) {
8510 return result;
8511 }
8512 return arrayMap(result, function(group) {
8513 return apply(iteratee, undefined, group);
8514 });
8515 }
8516
8517 /**
8518 * Creates an array excluding all given values using
8519 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8520 * for equality comparisons.
8521 *
8522 * **Note:** Unlike `_.pull`, this method returns a new array.
8523 *
8524 * @static
8525 * @memberOf _
8526 * @since 0.1.0
8527 * @category Array
8528 * @param {Array} array The array to inspect.
8529 * @param {...*} [values] The values to exclude.
8530 * @returns {Array} Returns the new array of filtered values.
8531 * @see _.difference, _.xor
8532 * @example
8533 *
8534 * _.without([2, 1, 2, 3], 1, 2);
8535 * // => [3]
8536 */
8537 var without = baseRest(function(array, values) {
8538 return isArrayLikeObject(array)
8539 ? baseDifference(array, values)
8540 : [];
8541 });
8542
8543 /**
8544 * Creates an array of unique values that is the
8545 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
8546 * of the given arrays. The order of result values is determined by the order
8547 * they occur in the arrays.
8548 *
8549 * @static
8550 * @memberOf _
8551 * @since 2.4.0
8552 * @category Array
8553 * @param {...Array} [arrays] The arrays to inspect.
8554 * @returns {Array} Returns the new array of filtered values.
8555 * @see _.difference, _.without
8556 * @example
8557 *
8558 * _.xor([2, 1], [2, 3]);
8559 * // => [1, 3]
8560 */
8561 var xor = baseRest(function(arrays) {
8562 return baseXor(arrayFilter(arrays, isArrayLikeObject));
8563 });
8564
8565 /**
8566 * This method is like `_.xor` except that it accepts `iteratee` which is
8567 * invoked for each element of each `arrays` to generate the criterion by
8568 * which by which they're compared. The order of result values is determined
8569 * by the order they occur in the arrays. The iteratee is invoked with one
8570 * argument: (value).
8571 *
8572 * @static
8573 * @memberOf _
8574 * @since 4.0.0
8575 * @category Array
8576 * @param {...Array} [arrays] The arrays to inspect.
8577 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8578 * @returns {Array} Returns the new array of filtered values.
8579 * @example
8580 *
8581 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
8582 * // => [1.2, 3.4]
8583 *
8584 * // The `_.property` iteratee shorthand.
8585 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8586 * // => [{ 'x': 2 }]
8587 */
8588 var xorBy = baseRest(function(arrays) {
8589 var iteratee = last(arrays);
8590 if (isArrayLikeObject(iteratee)) {
8591 iteratee = undefined;
8592 }
8593 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
8594 });
8595
8596 /**
8597 * This method is like `_.xor` except that it accepts `comparator` which is
8598 * invoked to compare elements of `arrays`. The order of result values is
8599 * determined by the order they occur in the arrays. The comparator is invoked
8600 * with two arguments: (arrVal, othVal).
8601 *
8602 * @static
8603 * @memberOf _
8604 * @since 4.0.0
8605 * @category Array
8606 * @param {...Array} [arrays] The arrays to inspect.
8607 * @param {Function} [comparator] The comparator invoked per element.
8608 * @returns {Array} Returns the new array of filtered values.
8609 * @example
8610 *
8611 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8612 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8613 *
8614 * _.xorWith(objects, others, _.isEqual);
8615 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8616 */
8617 var xorWith = baseRest(function(arrays) {
8618 var comparator = last(arrays);
8619 comparator = typeof comparator == 'function' ? comparator : undefined;
8620 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
8621 });
8622
8623 /**
8624 * Creates an array of grouped elements, the first of which contains the
8625 * first elements of the given arrays, the second of which contains the
8626 * second elements of the given arrays, and so on.
8627 *
8628 * @static
8629 * @memberOf _
8630 * @since 0.1.0
8631 * @category Array
8632 * @param {...Array} [arrays] The arrays to process.
8633 * @returns {Array} Returns the new array of grouped elements.
8634 * @example
8635 *
8636 * _.zip(['a', 'b'], [1, 2], [true, false]);
8637 * // => [['a', 1, true], ['b', 2, false]]
8638 */
8639 var zip = baseRest(unzip);
8640
8641 /**
8642 * This method is like `_.fromPairs` except that it accepts two arrays,
8643 * one of property identifiers and one of corresponding values.
8644 *
8645 * @static
8646 * @memberOf _
8647 * @since 0.4.0
8648 * @category Array
8649 * @param {Array} [props=[]] The property identifiers.
8650 * @param {Array} [values=[]] The property values.
8651 * @returns {Object} Returns the new object.
8652 * @example
8653 *
8654 * _.zipObject(['a', 'b'], [1, 2]);
8655 * // => { 'a': 1, 'b': 2 }
8656 */
8657 function zipObject(props, values) {
8658 return baseZipObject(props || [], values || [], assignValue);
8659 }
8660
8661 /**
8662 * This method is like `_.zipObject` except that it supports property paths.
8663 *
8664 * @static
8665 * @memberOf _
8666 * @since 4.1.0
8667 * @category Array
8668 * @param {Array} [props=[]] The property identifiers.
8669 * @param {Array} [values=[]] The property values.
8670 * @returns {Object} Returns the new object.
8671 * @example
8672 *
8673 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
8674 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
8675 */
8676 function zipObjectDeep(props, values) {
8677 return baseZipObject(props || [], values || [], baseSet);
8678 }
8679
8680 /**
8681 * This method is like `_.zip` except that it accepts `iteratee` to specify
8682 * how grouped values should be combined. The iteratee is invoked with the
8683 * elements of each group: (...group).
8684 *
8685 * @static
8686 * @memberOf _
8687 * @since 3.8.0
8688 * @category Array
8689 * @param {...Array} [arrays] The arrays to process.
8690 * @param {Function} [iteratee=_.identity] The function to combine
8691 * grouped values.
8692 * @returns {Array} Returns the new array of grouped elements.
8693 * @example
8694 *
8695 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
8696 * return a + b + c;
8697 * });
8698 * // => [111, 222]
8699 */
8700 var zipWith = baseRest(function(arrays) {
8701 var length = arrays.length,
8702 iteratee = length > 1 ? arrays[length - 1] : undefined;
8703
8704 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
8705 return unzipWith(arrays, iteratee);
8706 });
8707
8708 /*------------------------------------------------------------------------*/
8709
8710 /**
8711 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
8712 * chain sequences enabled. The result of such sequences must be unwrapped
8713 * with `_#value`.
8714 *
8715 * @static
8716 * @memberOf _
8717 * @since 1.3.0
8718 * @category Seq
8719 * @param {*} value The value to wrap.
8720 * @returns {Object} Returns the new `lodash` wrapper instance.
8721 * @example
8722 *
8723 * var users = [
8724 * { 'user': 'barney', 'age': 36 },
8725 * { 'user': 'fred', 'age': 40 },
8726 * { 'user': 'pebbles', 'age': 1 }
8727 * ];
8728 *
8729 * var youngest = _
8730 * .chain(users)
8731 * .sortBy('age')
8732 * .map(function(o) {
8733 * return o.user + ' is ' + o.age;
8734 * })
8735 * .head()
8736 * .value();
8737 * // => 'pebbles is 1'
8738 */
8739 function chain(value) {
8740 var result = lodash(value);
8741 result.__chain__ = true;
8742 return result;
8743 }
8744
8745 /**
8746 * This method invokes `interceptor` and returns `value`. The interceptor
8747 * is invoked with one argument; (value). The purpose of this method is to
8748 * "tap into" a method chain sequence in order to modify intermediate results.
8749 *
8750 * @static
8751 * @memberOf _
8752 * @since 0.1.0
8753 * @category Seq
8754 * @param {*} value The value to provide to `interceptor`.
8755 * @param {Function} interceptor The function to invoke.
8756 * @returns {*} Returns `value`.
8757 * @example
8758 *
8759 * _([1, 2, 3])
8760 * .tap(function(array) {
8761 * // Mutate input array.
8762 * array.pop();
8763 * })
8764 * .reverse()
8765 * .value();
8766 * // => [2, 1]
8767 */
8768 function tap(value, interceptor) {
8769 interceptor(value);
8770 return value;
8771 }
8772
8773 /**
8774 * This method is like `_.tap` except that it returns the result of `interceptor`.
8775 * The purpose of this method is to "pass thru" values replacing intermediate
8776 * results in a method chain sequence.
8777 *
8778 * @static
8779 * @memberOf _
8780 * @since 3.0.0
8781 * @category Seq
8782 * @param {*} value The value to provide to `interceptor`.
8783 * @param {Function} interceptor The function to invoke.
8784 * @returns {*} Returns the result of `interceptor`.
8785 * @example
8786 *
8787 * _(' abc ')
8788 * .chain()
8789 * .trim()
8790 * .thru(function(value) {
8791 * return [value];
8792 * })
8793 * .value();
8794 * // => ['abc']
8795 */
8796 function thru(value, interceptor) {
8797 return interceptor(value);
8798 }
8799
8800 /**
8801 * This method is the wrapper version of `_.at`.
8802 *
8803 * @name at
8804 * @memberOf _
8805 * @since 1.0.0
8806 * @category Seq
8807 * @param {...(string|string[])} [paths] The property paths to pick.
8808 * @returns {Object} Returns the new `lodash` wrapper instance.
8809 * @example
8810 *
8811 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
8812 *
8813 * _(object).at(['a[0].b.c', 'a[1]']).value();
8814 * // => [3, 4]
8815 */
8816 var wrapperAt = flatRest(function(paths) {
8817 var length = paths.length,
8818 start = length ? paths[0] : 0,
8819 value = this.__wrapped__,
8820 interceptor = function(object) { return baseAt(object, paths); };
8821
8822 if (length > 1 || this.__actions__.length ||
8823 !(value instanceof LazyWrapper) || !isIndex(start)) {
8824 return this.thru(interceptor);
8825 }
8826 value = value.slice(start, +start + (length ? 1 : 0));
8827 value.__actions__.push({
8828 'func': thru,
8829 'args': [interceptor],
8830 'thisArg': undefined
8831 });
8832 return new LodashWrapper(value, this.__chain__).thru(function(array) {
8833 if (length && !array.length) {
8834 array.push(undefined);
8835 }
8836 return array;
8837 });
8838 });
8839
8840 /**
8841 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
8842 *
8843 * @name chain
8844 * @memberOf _
8845 * @since 0.1.0
8846 * @category Seq
8847 * @returns {Object} Returns the new `lodash` wrapper instance.
8848 * @example
8849 *
8850 * var users = [
8851 * { 'user': 'barney', 'age': 36 },
8852 * { 'user': 'fred', 'age': 40 }
8853 * ];
8854 *
8855 * // A sequence without explicit chaining.
8856 * _(users).head();
8857 * // => { 'user': 'barney', 'age': 36 }
8858 *
8859 * // A sequence with explicit chaining.
8860 * _(users)
8861 * .chain()
8862 * .head()
8863 * .pick('user')
8864 * .value();
8865 * // => { 'user': 'barney' }
8866 */
8867 function wrapperChain() {
8868 return chain(this);
8869 }
8870
8871 /**
8872 * Executes the chain sequence and returns the wrapped result.
8873 *
8874 * @name commit
8875 * @memberOf _
8876 * @since 3.2.0
8877 * @category Seq
8878 * @returns {Object} Returns the new `lodash` wrapper instance.
8879 * @example
8880 *
8881 * var array = [1, 2];
8882 * var wrapped = _(array).push(3);
8883 *
8884 * console.log(array);
8885 * // => [1, 2]
8886 *
8887 * wrapped = wrapped.commit();
8888 * console.log(array);
8889 * // => [1, 2, 3]
8890 *
8891 * wrapped.last();
8892 * // => 3
8893 *
8894 * console.log(array);
8895 * // => [1, 2, 3]
8896 */
8897 function wrapperCommit() {
8898 return new LodashWrapper(this.value(), this.__chain__);
8899 }
8900
8901 /**
8902 * Gets the next value on a wrapped object following the
8903 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
8904 *
8905 * @name next
8906 * @memberOf _
8907 * @since 4.0.0
8908 * @category Seq
8909 * @returns {Object} Returns the next iterator value.
8910 * @example
8911 *
8912 * var wrapped = _([1, 2]);
8913 *
8914 * wrapped.next();
8915 * // => { 'done': false, 'value': 1 }
8916 *
8917 * wrapped.next();
8918 * // => { 'done': false, 'value': 2 }
8919 *
8920 * wrapped.next();
8921 * // => { 'done': true, 'value': undefined }
8922 */
8923 function wrapperNext() {
8924 if (this.__values__ === undefined) {
8925 this.__values__ = toArray(this.value());
8926 }
8927 var done = this.__index__ >= this.__values__.length,
8928 value = done ? undefined : this.__values__[this.__index__++];
8929
8930 return { 'done': done, 'value': value };
8931 }
8932
8933 /**
8934 * Enables the wrapper to be iterable.
8935 *
8936 * @name Symbol.iterator
8937 * @memberOf _
8938 * @since 4.0.0
8939 * @category Seq
8940 * @returns {Object} Returns the wrapper object.
8941 * @example
8942 *
8943 * var wrapped = _([1, 2]);
8944 *
8945 * wrapped[Symbol.iterator]() === wrapped;
8946 * // => true
8947 *
8948 * Array.from(wrapped);
8949 * // => [1, 2]
8950 */
8951 function wrapperToIterator() {
8952 return this;
8953 }
8954
8955 /**
8956 * Creates a clone of the chain sequence planting `value` as the wrapped value.
8957 *
8958 * @name plant
8959 * @memberOf _
8960 * @since 3.2.0
8961 * @category Seq
8962 * @param {*} value The value to plant.
8963 * @returns {Object} Returns the new `lodash` wrapper instance.
8964 * @example
8965 *
8966 * function square(n) {
8967 * return n * n;
8968 * }
8969 *
8970 * var wrapped = _([1, 2]).map(square);
8971 * var other = wrapped.plant([3, 4]);
8972 *
8973 * other.value();
8974 * // => [9, 16]
8975 *
8976 * wrapped.value();
8977 * // => [1, 4]
8978 */
8979 function wrapperPlant(value) {
8980 var result,
8981 parent = this;
8982
8983 while (parent instanceof baseLodash) {
8984 var clone = wrapperClone(parent);
8985 clone.__index__ = 0;
8986 clone.__values__ = undefined;
8987 if (result) {
8988 previous.__wrapped__ = clone;
8989 } else {
8990 result = clone;
8991 }
8992 var previous = clone;
8993 parent = parent.__wrapped__;
8994 }
8995 previous.__wrapped__ = value;
8996 return result;
8997 }
8998
8999 /**
9000 * This method is the wrapper version of `_.reverse`.
9001 *
9002 * **Note:** This method mutates the wrapped array.
9003 *
9004 * @name reverse
9005 * @memberOf _
9006 * @since 0.1.0
9007 * @category Seq
9008 * @returns {Object} Returns the new `lodash` wrapper instance.
9009 * @example
9010 *
9011 * var array = [1, 2, 3];
9012 *
9013 * _(array).reverse().value()
9014 * // => [3, 2, 1]
9015 *
9016 * console.log(array);
9017 * // => [3, 2, 1]
9018 */
9019 function wrapperReverse() {
9020 var value = this.__wrapped__;
9021 if (value instanceof LazyWrapper) {
9022 var wrapped = value;
9023 if (this.__actions__.length) {
9024 wrapped = new LazyWrapper(this);
9025 }
9026 wrapped = wrapped.reverse();
9027 wrapped.__actions__.push({
9028 'func': thru,
9029 'args': [reverse],
9030 'thisArg': undefined
9031 });
9032 return new LodashWrapper(wrapped, this.__chain__);
9033 }
9034 return this.thru(reverse);
9035 }
9036
9037 /**
9038 * Executes the chain sequence to resolve the unwrapped value.
9039 *
9040 * @name value
9041 * @memberOf _
9042 * @since 0.1.0
9043 * @alias toJSON, valueOf
9044 * @category Seq
9045 * @returns {*} Returns the resolved unwrapped value.
9046 * @example
9047 *
9048 * _([1, 2, 3]).value();
9049 * // => [1, 2, 3]
9050 */
9051 function wrapperValue() {
9052 return baseWrapperValue(this.__wrapped__, this.__actions__);
9053 }
9054
9055 /*------------------------------------------------------------------------*/
9056
9057 /**
9058 * Creates an object composed of keys generated from the results of running
9059 * each element of `collection` thru `iteratee`. The corresponding value of
9060 * each key is the number of times the key was returned by `iteratee`. The
9061 * iteratee is invoked with one argument: (value).
9062 *
9063 * @static
9064 * @memberOf _
9065 * @since 0.5.0
9066 * @category Collection
9067 * @param {Array|Object} collection The collection to iterate over.
9068 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9069 * @returns {Object} Returns the composed aggregate object.
9070 * @example
9071 *
9072 * _.countBy([6.1, 4.2, 6.3], Math.floor);
9073 * // => { '4': 1, '6': 2 }
9074 *
9075 * // The `_.property` iteratee shorthand.
9076 * _.countBy(['one', 'two', 'three'], 'length');
9077 * // => { '3': 2, '5': 1 }
9078 */
9079 var countBy = createAggregator(function(result, value, key) {
9080 if (hasOwnProperty.call(result, key)) {
9081 ++result[key];
9082 } else {
9083 baseAssignValue(result, key, 1);
9084 }
9085 });
9086
9087 /**
9088 * Checks if `predicate` returns truthy for **all** elements of `collection`.
9089 * Iteration is stopped once `predicate` returns falsey. The predicate is
9090 * invoked with three arguments: (value, index|key, collection).
9091 *
9092 * **Note:** This method returns `true` for
9093 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
9094 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
9095 * elements of empty collections.
9096 *
9097 * @static
9098 * @memberOf _
9099 * @since 0.1.0
9100 * @category Collection
9101 * @param {Array|Object} collection The collection to iterate over.
9102 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9103 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9104 * @returns {boolean} Returns `true` if all elements pass the predicate check,
9105 * else `false`.
9106 * @example
9107 *
9108 * _.every([true, 1, null, 'yes'], Boolean);
9109 * // => false
9110 *
9111 * var users = [
9112 * { 'user': 'barney', 'age': 36, 'active': false },
9113 * { 'user': 'fred', 'age': 40, 'active': false }
9114 * ];
9115 *
9116 * // The `_.matches` iteratee shorthand.
9117 * _.every(users, { 'user': 'barney', 'active': false });
9118 * // => false
9119 *
9120 * // The `_.matchesProperty` iteratee shorthand.
9121 * _.every(users, ['active', false]);
9122 * // => true
9123 *
9124 * // The `_.property` iteratee shorthand.
9125 * _.every(users, 'active');
9126 * // => false
9127 */
9128 function every(collection, predicate, guard) {
9129 var func = isArray(collection) ? arrayEvery : baseEvery;
9130 if (guard && isIterateeCall(collection, predicate, guard)) {
9131 predicate = undefined;
9132 }
9133 return func(collection, getIteratee(predicate, 3));
9134 }
9135
9136 /**
9137 * Iterates over elements of `collection`, returning an array of all elements
9138 * `predicate` returns truthy for. The predicate is invoked with three
9139 * arguments: (value, index|key, collection).
9140 *
9141 * **Note:** Unlike `_.remove`, this method returns a new array.
9142 *
9143 * @static
9144 * @memberOf _
9145 * @since 0.1.0
9146 * @category Collection
9147 * @param {Array|Object} collection The collection to iterate over.
9148 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9149 * @returns {Array} Returns the new filtered array.
9150 * @see _.reject
9151 * @example
9152 *
9153 * var users = [
9154 * { 'user': 'barney', 'age': 36, 'active': true },
9155 * { 'user': 'fred', 'age': 40, 'active': false }
9156 * ];
9157 *
9158 * _.filter(users, function(o) { return !o.active; });
9159 * // => objects for ['fred']
9160 *
9161 * // The `_.matches` iteratee shorthand.
9162 * _.filter(users, { 'age': 36, 'active': true });
9163 * // => objects for ['barney']
9164 *
9165 * // The `_.matchesProperty` iteratee shorthand.
9166 * _.filter(users, ['active', false]);
9167 * // => objects for ['fred']
9168 *
9169 * // The `_.property` iteratee shorthand.
9170 * _.filter(users, 'active');
9171 * // => objects for ['barney']
9172 */
9173 function filter(collection, predicate) {
9174 var func = isArray(collection) ? arrayFilter : baseFilter;
9175 return func(collection, getIteratee(predicate, 3));
9176 }
9177
9178 /**
9179 * Iterates over elements of `collection`, returning the first element
9180 * `predicate` returns truthy for. The predicate is invoked with three
9181 * arguments: (value, index|key, collection).
9182 *
9183 * @static
9184 * @memberOf _
9185 * @since 0.1.0
9186 * @category Collection
9187 * @param {Array|Object} collection The collection to inspect.
9188 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9189 * @param {number} [fromIndex=0] The index to search from.
9190 * @returns {*} Returns the matched element, else `undefined`.
9191 * @example
9192 *
9193 * var users = [
9194 * { 'user': 'barney', 'age': 36, 'active': true },
9195 * { 'user': 'fred', 'age': 40, 'active': false },
9196 * { 'user': 'pebbles', 'age': 1, 'active': true }
9197 * ];
9198 *
9199 * _.find(users, function(o) { return o.age < 40; });
9200 * // => object for 'barney'
9201 *
9202 * // The `_.matches` iteratee shorthand.
9203 * _.find(users, { 'age': 1, 'active': true });
9204 * // => object for 'pebbles'
9205 *
9206 * // The `_.matchesProperty` iteratee shorthand.
9207 * _.find(users, ['active', false]);
9208 * // => object for 'fred'
9209 *
9210 * // The `_.property` iteratee shorthand.
9211 * _.find(users, 'active');
9212 * // => object for 'barney'
9213 */
9214 var find = createFind(findIndex);
9215
9216 /**
9217 * This method is like `_.find` except that it iterates over elements of
9218 * `collection` from right to left.
9219 *
9220 * @static
9221 * @memberOf _
9222 * @since 2.0.0
9223 * @category Collection
9224 * @param {Array|Object} collection The collection to inspect.
9225 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9226 * @param {number} [fromIndex=collection.length-1] The index to search from.
9227 * @returns {*} Returns the matched element, else `undefined`.
9228 * @example
9229 *
9230 * _.findLast([1, 2, 3, 4], function(n) {
9231 * return n % 2 == 1;
9232 * });
9233 * // => 3
9234 */
9235 var findLast = createFind(findLastIndex);
9236
9237 /**
9238 * Creates a flattened array of values by running each element in `collection`
9239 * thru `iteratee` and flattening the mapped results. The iteratee is invoked
9240 * with three arguments: (value, index|key, collection).
9241 *
9242 * @static
9243 * @memberOf _
9244 * @since 4.0.0
9245 * @category Collection
9246 * @param {Array|Object} collection The collection to iterate over.
9247 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9248 * @returns {Array} Returns the new flattened array.
9249 * @example
9250 *
9251 * function duplicate(n) {
9252 * return [n, n];
9253 * }
9254 *
9255 * _.flatMap([1, 2], duplicate);
9256 * // => [1, 1, 2, 2]
9257 */
9258 function flatMap(collection, iteratee) {
9259 return baseFlatten(map(collection, iteratee), 1);
9260 }
9261
9262 /**
9263 * This method is like `_.flatMap` except that it recursively flattens the
9264 * mapped results.
9265 *
9266 * @static
9267 * @memberOf _
9268 * @since 4.7.0
9269 * @category Collection
9270 * @param {Array|Object} collection The collection to iterate over.
9271 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9272 * @returns {Array} Returns the new flattened array.
9273 * @example
9274 *
9275 * function duplicate(n) {
9276 * return [[[n, n]]];
9277 * }
9278 *
9279 * _.flatMapDeep([1, 2], duplicate);
9280 * // => [1, 1, 2, 2]
9281 */
9282 function flatMapDeep(collection, iteratee) {
9283 return baseFlatten(map(collection, iteratee), INFINITY);
9284 }
9285
9286 /**
9287 * This method is like `_.flatMap` except that it recursively flattens the
9288 * mapped results up to `depth` times.
9289 *
9290 * @static
9291 * @memberOf _
9292 * @since 4.7.0
9293 * @category Collection
9294 * @param {Array|Object} collection The collection to iterate over.
9295 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9296 * @param {number} [depth=1] The maximum recursion depth.
9297 * @returns {Array} Returns the new flattened array.
9298 * @example
9299 *
9300 * function duplicate(n) {
9301 * return [[[n, n]]];
9302 * }
9303 *
9304 * _.flatMapDepth([1, 2], duplicate, 2);
9305 * // => [[1, 1], [2, 2]]
9306 */
9307 function flatMapDepth(collection, iteratee, depth) {
9308 depth = depth === undefined ? 1 : toInteger(depth);
9309 return baseFlatten(map(collection, iteratee), depth);
9310 }
9311
9312 /**
9313 * Iterates over elements of `collection` and invokes `iteratee` for each element.
9314 * The iteratee is invoked with three arguments: (value, index|key, collection).
9315 * Iteratee functions may exit iteration early by explicitly returning `false`.
9316 *
9317 * **Note:** As with other "Collections" methods, objects with a "length"
9318 * property are iterated like arrays. To avoid this behavior use `_.forIn`
9319 * or `_.forOwn` for object iteration.
9320 *
9321 * @static
9322 * @memberOf _
9323 * @since 0.1.0
9324 * @alias each
9325 * @category Collection
9326 * @param {Array|Object} collection The collection to iterate over.
9327 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9328 * @returns {Array|Object} Returns `collection`.
9329 * @see _.forEachRight
9330 * @example
9331 *
9332 * _.forEach([1, 2], function(value) {
9333 * console.log(value);
9334 * });
9335 * // => Logs `1` then `2`.
9336 *
9337 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
9338 * console.log(key);
9339 * });
9340 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
9341 */
9342 function forEach(collection, iteratee) {
9343 var func = isArray(collection) ? arrayEach : baseEach;
9344 return func(collection, getIteratee(iteratee, 3));
9345 }
9346
9347 /**
9348 * This method is like `_.forEach` except that it iterates over elements of
9349 * `collection` from right to left.
9350 *
9351 * @static
9352 * @memberOf _
9353 * @since 2.0.0
9354 * @alias eachRight
9355 * @category Collection
9356 * @param {Array|Object} collection The collection to iterate over.
9357 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9358 * @returns {Array|Object} Returns `collection`.
9359 * @see _.forEach
9360 * @example
9361 *
9362 * _.forEachRight([1, 2], function(value) {
9363 * console.log(value);
9364 * });
9365 * // => Logs `2` then `1`.
9366 */
9367 function forEachRight(collection, iteratee) {
9368 var func = isArray(collection) ? arrayEachRight : baseEachRight;
9369 return func(collection, getIteratee(iteratee, 3));
9370 }
9371
9372 /**
9373 * Creates an object composed of keys generated from the results of running
9374 * each element of `collection` thru `iteratee`. The order of grouped values
9375 * is determined by the order they occur in `collection`. The corresponding
9376 * value of each key is an array of elements responsible for generating the
9377 * key. The iteratee is invoked with one argument: (value).
9378 *
9379 * @static
9380 * @memberOf _
9381 * @since 0.1.0
9382 * @category Collection
9383 * @param {Array|Object} collection The collection to iterate over.
9384 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9385 * @returns {Object} Returns the composed aggregate object.
9386 * @example
9387 *
9388 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
9389 * // => { '4': [4.2], '6': [6.1, 6.3] }
9390 *
9391 * // The `_.property` iteratee shorthand.
9392 * _.groupBy(['one', 'two', 'three'], 'length');
9393 * // => { '3': ['one', 'two'], '5': ['three'] }
9394 */
9395 var groupBy = createAggregator(function(result, value, key) {
9396 if (hasOwnProperty.call(result, key)) {
9397 result[key].push(value);
9398 } else {
9399 baseAssignValue(result, key, [value]);
9400 }
9401 });
9402
9403 /**
9404 * Checks if `value` is in `collection`. If `collection` is a string, it's
9405 * checked for a substring of `value`, otherwise
9406 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
9407 * is used for equality comparisons. If `fromIndex` is negative, it's used as
9408 * the offset from the end of `collection`.
9409 *
9410 * @static
9411 * @memberOf _
9412 * @since 0.1.0
9413 * @category Collection
9414 * @param {Array|Object|string} collection The collection to inspect.
9415 * @param {*} value The value to search for.
9416 * @param {number} [fromIndex=0] The index to search from.
9417 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9418 * @returns {boolean} Returns `true` if `value` is found, else `false`.
9419 * @example
9420 *
9421 * _.includes([1, 2, 3], 1);
9422 * // => true
9423 *
9424 * _.includes([1, 2, 3], 1, 2);
9425 * // => false
9426 *
9427 * _.includes({ 'a': 1, 'b': 2 }, 1);
9428 * // => true
9429 *
9430 * _.includes('abcd', 'bc');
9431 * // => true
9432 */
9433 function includes(collection, value, fromIndex, guard) {
9434 collection = isArrayLike(collection) ? collection : values(collection);
9435 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
9436
9437 var length = collection.length;
9438 if (fromIndex < 0) {
9439 fromIndex = nativeMax(length + fromIndex, 0);
9440 }
9441 return isString(collection)
9442 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
9443 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
9444 }
9445
9446 /**
9447 * Invokes the method at `path` of each element in `collection`, returning
9448 * an array of the results of each invoked method. Any additional arguments
9449 * are provided to each invoked method. If `path` is a function, it's invoked
9450 * for, and `this` bound to, each element in `collection`.
9451 *
9452 * @static
9453 * @memberOf _
9454 * @since 4.0.0
9455 * @category Collection
9456 * @param {Array|Object} collection The collection to iterate over.
9457 * @param {Array|Function|string} path The path of the method to invoke or
9458 * the function invoked per iteration.
9459 * @param {...*} [args] The arguments to invoke each method with.
9460 * @returns {Array} Returns the array of results.
9461 * @example
9462 *
9463 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
9464 * // => [[1, 5, 7], [1, 2, 3]]
9465 *
9466 * _.invokeMap([123, 456], String.prototype.split, '');
9467 * // => [['1', '2', '3'], ['4', '5', '6']]
9468 */
9469 var invokeMap = baseRest(function(collection, path, args) {
9470 var index = -1,
9471 isFunc = typeof path == 'function',
9472 result = isArrayLike(collection) ? Array(collection.length) : [];
9473
9474 baseEach(collection, function(value) {
9475 result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
9476 });
9477 return result;
9478 });
9479
9480 /**
9481 * Creates an object composed of keys generated from the results of running
9482 * each element of `collection` thru `iteratee`. The corresponding value of
9483 * each key is the last element responsible for generating the key. The
9484 * iteratee is invoked with one argument: (value).
9485 *
9486 * @static
9487 * @memberOf _
9488 * @since 4.0.0
9489 * @category Collection
9490 * @param {Array|Object} collection The collection to iterate over.
9491 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9492 * @returns {Object} Returns the composed aggregate object.
9493 * @example
9494 *
9495 * var array = [
9496 * { 'dir': 'left', 'code': 97 },
9497 * { 'dir': 'right', 'code': 100 }
9498 * ];
9499 *
9500 * _.keyBy(array, function(o) {
9501 * return String.fromCharCode(o.code);
9502 * });
9503 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
9504 *
9505 * _.keyBy(array, 'dir');
9506 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
9507 */
9508 var keyBy = createAggregator(function(result, value, key) {
9509 baseAssignValue(result, key, value);
9510 });
9511
9512 /**
9513 * Creates an array of values by running each element in `collection` thru
9514 * `iteratee`. The iteratee is invoked with three arguments:
9515 * (value, index|key, collection).
9516 *
9517 * Many lodash methods are guarded to work as iteratees for methods like
9518 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
9519 *
9520 * The guarded methods are:
9521 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
9522 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
9523 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
9524 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
9525 *
9526 * @static
9527 * @memberOf _
9528 * @since 0.1.0
9529 * @category Collection
9530 * @param {Array|Object} collection The collection to iterate over.
9531 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9532 * @returns {Array} Returns the new mapped array.
9533 * @example
9534 *
9535 * function square(n) {
9536 * return n * n;
9537 * }
9538 *
9539 * _.map([4, 8], square);
9540 * // => [16, 64]
9541 *
9542 * _.map({ 'a': 4, 'b': 8 }, square);
9543 * // => [16, 64] (iteration order is not guaranteed)
9544 *
9545 * var users = [
9546 * { 'user': 'barney' },
9547 * { 'user': 'fred' }
9548 * ];
9549 *
9550 * // The `_.property` iteratee shorthand.
9551 * _.map(users, 'user');
9552 * // => ['barney', 'fred']
9553 */
9554 function map(collection, iteratee) {
9555 var func = isArray(collection) ? arrayMap : baseMap;
9556 return func(collection, getIteratee(iteratee, 3));
9557 }
9558
9559 /**
9560 * This method is like `_.sortBy` except that it allows specifying the sort
9561 * orders of the iteratees to sort by. If `orders` is unspecified, all values
9562 * are sorted in ascending order. Otherwise, specify an order of "desc" for
9563 * descending or "asc" for ascending sort order of corresponding values.
9564 *
9565 * @static
9566 * @memberOf _
9567 * @since 4.0.0
9568 * @category Collection
9569 * @param {Array|Object} collection The collection to iterate over.
9570 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
9571 * The iteratees to sort by.
9572 * @param {string[]} [orders] The sort orders of `iteratees`.
9573 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9574 * @returns {Array} Returns the new sorted array.
9575 * @example
9576 *
9577 * var users = [
9578 * { 'user': 'fred', 'age': 48 },
9579 * { 'user': 'barney', 'age': 34 },
9580 * { 'user': 'fred', 'age': 40 },
9581 * { 'user': 'barney', 'age': 36 }
9582 * ];
9583 *
9584 * // Sort by `user` in ascending order and by `age` in descending order.
9585 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
9586 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9587 */
9588 function orderBy(collection, iteratees, orders, guard) {
9589 if (collection == null) {
9590 return [];
9591 }
9592 if (!isArray(iteratees)) {
9593 iteratees = iteratees == null ? [] : [iteratees];
9594 }
9595 orders = guard ? undefined : orders;
9596 if (!isArray(orders)) {
9597 orders = orders == null ? [] : [orders];
9598 }
9599 return baseOrderBy(collection, iteratees, orders);
9600 }
9601
9602 /**
9603 * Creates an array of elements split into two groups, the first of which
9604 * contains elements `predicate` returns truthy for, the second of which
9605 * contains elements `predicate` returns falsey for. The predicate is
9606 * invoked with one argument: (value).
9607 *
9608 * @static
9609 * @memberOf _
9610 * @since 3.0.0
9611 * @category Collection
9612 * @param {Array|Object} collection The collection to iterate over.
9613 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9614 * @returns {Array} Returns the array of grouped elements.
9615 * @example
9616 *
9617 * var users = [
9618 * { 'user': 'barney', 'age': 36, 'active': false },
9619 * { 'user': 'fred', 'age': 40, 'active': true },
9620 * { 'user': 'pebbles', 'age': 1, 'active': false }
9621 * ];
9622 *
9623 * _.partition(users, function(o) { return o.active; });
9624 * // => objects for [['fred'], ['barney', 'pebbles']]
9625 *
9626 * // The `_.matches` iteratee shorthand.
9627 * _.partition(users, { 'age': 1, 'active': false });
9628 * // => objects for [['pebbles'], ['barney', 'fred']]
9629 *
9630 * // The `_.matchesProperty` iteratee shorthand.
9631 * _.partition(users, ['active', false]);
9632 * // => objects for [['barney', 'pebbles'], ['fred']]
9633 *
9634 * // The `_.property` iteratee shorthand.
9635 * _.partition(users, 'active');
9636 * // => objects for [['fred'], ['barney', 'pebbles']]
9637 */
9638 var partition = createAggregator(function(result, value, key) {
9639 result[key ? 0 : 1].push(value);
9640 }, function() { return [[], []]; });
9641
9642 /**
9643 * Reduces `collection` to a value which is the accumulated result of running
9644 * each element in `collection` thru `iteratee`, where each successive
9645 * invocation is supplied the return value of the previous. If `accumulator`
9646 * is not given, the first element of `collection` is used as the initial
9647 * value. The iteratee is invoked with four arguments:
9648 * (accumulator, value, index|key, collection).
9649 *
9650 * Many lodash methods are guarded to work as iteratees for methods like
9651 * `_.reduce`, `_.reduceRight`, and `_.transform`.
9652 *
9653 * The guarded methods are:
9654 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
9655 * and `sortBy`
9656 *
9657 * @static
9658 * @memberOf _
9659 * @since 0.1.0
9660 * @category Collection
9661 * @param {Array|Object} collection The collection to iterate over.
9662 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9663 * @param {*} [accumulator] The initial value.
9664 * @returns {*} Returns the accumulated value.
9665 * @see _.reduceRight
9666 * @example
9667 *
9668 * _.reduce([1, 2], function(sum, n) {
9669 * return sum + n;
9670 * }, 0);
9671 * // => 3
9672 *
9673 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
9674 * (result[value] || (result[value] = [])).push(key);
9675 * return result;
9676 * }, {});
9677 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
9678 */
9679 function reduce(collection, iteratee, accumulator) {
9680 var func = isArray(collection) ? arrayReduce : baseReduce,
9681 initAccum = arguments.length < 3;
9682
9683 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
9684 }
9685
9686 /**
9687 * This method is like `_.reduce` except that it iterates over elements of
9688 * `collection` from right to left.
9689 *
9690 * @static
9691 * @memberOf _
9692 * @since 0.1.0
9693 * @category Collection
9694 * @param {Array|Object} collection The collection to iterate over.
9695 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9696 * @param {*} [accumulator] The initial value.
9697 * @returns {*} Returns the accumulated value.
9698 * @see _.reduce
9699 * @example
9700 *
9701 * var array = [[0, 1], [2, 3], [4, 5]];
9702 *
9703 * _.reduceRight(array, function(flattened, other) {
9704 * return flattened.concat(other);
9705 * }, []);
9706 * // => [4, 5, 2, 3, 0, 1]
9707 */
9708 function reduceRight(collection, iteratee, accumulator) {
9709 var func = isArray(collection) ? arrayReduceRight : baseReduce,
9710 initAccum = arguments.length < 3;
9711
9712 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
9713 }
9714
9715 /**
9716 * The opposite of `_.filter`; this method returns the elements of `collection`
9717 * that `predicate` does **not** return truthy for.
9718 *
9719 * @static
9720 * @memberOf _
9721 * @since 0.1.0
9722 * @category Collection
9723 * @param {Array|Object} collection The collection to iterate over.
9724 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9725 * @returns {Array} Returns the new filtered array.
9726 * @see _.filter
9727 * @example
9728 *
9729 * var users = [
9730 * { 'user': 'barney', 'age': 36, 'active': false },
9731 * { 'user': 'fred', 'age': 40, 'active': true }
9732 * ];
9733 *
9734 * _.reject(users, function(o) { return !o.active; });
9735 * // => objects for ['fred']
9736 *
9737 * // The `_.matches` iteratee shorthand.
9738 * _.reject(users, { 'age': 40, 'active': true });
9739 * // => objects for ['barney']
9740 *
9741 * // The `_.matchesProperty` iteratee shorthand.
9742 * _.reject(users, ['active', false]);
9743 * // => objects for ['fred']
9744 *
9745 * // The `_.property` iteratee shorthand.
9746 * _.reject(users, 'active');
9747 * // => objects for ['barney']
9748 */
9749 function reject(collection, predicate) {
9750 var func = isArray(collection) ? arrayFilter : baseFilter;
9751 return func(collection, negate(getIteratee(predicate, 3)));
9752 }
9753
9754 /**
9755 * Gets a random element from `collection`.
9756 *
9757 * @static
9758 * @memberOf _
9759 * @since 2.0.0
9760 * @category Collection
9761 * @param {Array|Object} collection The collection to sample.
9762 * @returns {*} Returns the random element.
9763 * @example
9764 *
9765 * _.sample([1, 2, 3, 4]);
9766 * // => 2
9767 */
9768 function sample(collection) {
9769 var func = isArray(collection) ? arraySample : baseSample;
9770 return func(collection);
9771 }
9772
9773 /**
9774 * Gets `n` random elements at unique keys from `collection` up to the
9775 * size of `collection`.
9776 *
9777 * @static
9778 * @memberOf _
9779 * @since 4.0.0
9780 * @category Collection
9781 * @param {Array|Object} collection The collection to sample.
9782 * @param {number} [n=1] The number of elements to sample.
9783 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9784 * @returns {Array} Returns the random elements.
9785 * @example
9786 *
9787 * _.sampleSize([1, 2, 3], 2);
9788 * // => [3, 1]
9789 *
9790 * _.sampleSize([1, 2, 3], 4);
9791 * // => [2, 3, 1]
9792 */
9793 function sampleSize(collection, n, guard) {
9794 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
9795 n = 1;
9796 } else {
9797 n = toInteger(n);
9798 }
9799 var func = isArray(collection) ? arraySampleSize : baseSampleSize;
9800 return func(collection, n);
9801 }
9802
9803 /**
9804 * Creates an array of shuffled values, using a version of the
9805 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
9806 *
9807 * @static
9808 * @memberOf _
9809 * @since 0.1.0
9810 * @category Collection
9811 * @param {Array|Object} collection The collection to shuffle.
9812 * @returns {Array} Returns the new shuffled array.
9813 * @example
9814 *
9815 * _.shuffle([1, 2, 3, 4]);
9816 * // => [4, 1, 3, 2]
9817 */
9818 function shuffle(collection) {
9819 var func = isArray(collection) ? arrayShuffle : baseShuffle;
9820 return func(collection);
9821 }
9822
9823 /**
9824 * Gets the size of `collection` by returning its length for array-like
9825 * values or the number of own enumerable string keyed properties for objects.
9826 *
9827 * @static
9828 * @memberOf _
9829 * @since 0.1.0
9830 * @category Collection
9831 * @param {Array|Object|string} collection The collection to inspect.
9832 * @returns {number} Returns the collection size.
9833 * @example
9834 *
9835 * _.size([1, 2, 3]);
9836 * // => 3
9837 *
9838 * _.size({ 'a': 1, 'b': 2 });
9839 * // => 2
9840 *
9841 * _.size('pebbles');
9842 * // => 7
9843 */
9844 function size(collection) {
9845 if (collection == null) {
9846 return 0;
9847 }
9848 if (isArrayLike(collection)) {
9849 return isString(collection) ? stringSize(collection) : collection.length;
9850 }
9851 var tag = getTag(collection);
9852 if (tag == mapTag || tag == setTag) {
9853 return collection.size;
9854 }
9855 return baseKeys(collection).length;
9856 }
9857
9858 /**
9859 * Checks if `predicate` returns truthy for **any** element of `collection`.
9860 * Iteration is stopped once `predicate` returns truthy. The predicate is
9861 * invoked with three arguments: (value, index|key, collection).
9862 *
9863 * @static
9864 * @memberOf _
9865 * @since 0.1.0
9866 * @category Collection
9867 * @param {Array|Object} collection The collection to iterate over.
9868 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9869 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9870 * @returns {boolean} Returns `true` if any element passes the predicate check,
9871 * else `false`.
9872 * @example
9873 *
9874 * _.some([null, 0, 'yes', false], Boolean);
9875 * // => true
9876 *
9877 * var users = [
9878 * { 'user': 'barney', 'active': true },
9879 * { 'user': 'fred', 'active': false }
9880 * ];
9881 *
9882 * // The `_.matches` iteratee shorthand.
9883 * _.some(users, { 'user': 'barney', 'active': false });
9884 * // => false
9885 *
9886 * // The `_.matchesProperty` iteratee shorthand.
9887 * _.some(users, ['active', false]);
9888 * // => true
9889 *
9890 * // The `_.property` iteratee shorthand.
9891 * _.some(users, 'active');
9892 * // => true
9893 */
9894 function some(collection, predicate, guard) {
9895 var func = isArray(collection) ? arraySome : baseSome;
9896 if (guard && isIterateeCall(collection, predicate, guard)) {
9897 predicate = undefined;
9898 }
9899 return func(collection, getIteratee(predicate, 3));
9900 }
9901
9902 /**
9903 * Creates an array of elements, sorted in ascending order by the results of
9904 * running each element in a collection thru each iteratee. This method
9905 * performs a stable sort, that is, it preserves the original sort order of
9906 * equal elements. The iteratees are invoked with one argument: (value).
9907 *
9908 * @static
9909 * @memberOf _
9910 * @since 0.1.0
9911 * @category Collection
9912 * @param {Array|Object} collection The collection to iterate over.
9913 * @param {...(Function|Function[])} [iteratees=[_.identity]]
9914 * The iteratees to sort by.
9915 * @returns {Array} Returns the new sorted array.
9916 * @example
9917 *
9918 * var users = [
9919 * { 'user': 'fred', 'age': 48 },
9920 * { 'user': 'barney', 'age': 36 },
9921 * { 'user': 'fred', 'age': 40 },
9922 * { 'user': 'barney', 'age': 34 }
9923 * ];
9924 *
9925 * _.sortBy(users, [function(o) { return o.user; }]);
9926 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9927 *
9928 * _.sortBy(users, ['user', 'age']);
9929 * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
9930 */
9931 var sortBy = baseRest(function(collection, iteratees) {
9932 if (collection == null) {
9933 return [];
9934 }
9935 var length = iteratees.length;
9936 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
9937 iteratees = [];
9938 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
9939 iteratees = [iteratees[0]];
9940 }
9941 return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
9942 });
9943
9944 /*------------------------------------------------------------------------*/
9945
9946 /**
9947 * Gets the timestamp of the number of milliseconds that have elapsed since
9948 * the Unix epoch (1 January 1970 00:00:00 UTC).
9949 *
9950 * @static
9951 * @memberOf _
9952 * @since 2.4.0
9953 * @category Date
9954 * @returns {number} Returns the timestamp.
9955 * @example
9956 *
9957 * _.defer(function(stamp) {
9958 * console.log(_.now() - stamp);
9959 * }, _.now());
9960 * // => Logs the number of milliseconds it took for the deferred invocation.
9961 */
9962 var now = ctxNow || function() {
9963 return root.Date.now();
9964 };
9965
9966 /*------------------------------------------------------------------------*/
9967
9968 /**
9969 * The opposite of `_.before`; this method creates a function that invokes
9970 * `func` once it's called `n` or more times.
9971 *
9972 * @static
9973 * @memberOf _
9974 * @since 0.1.0
9975 * @category Function
9976 * @param {number} n The number of calls before `func` is invoked.
9977 * @param {Function} func The function to restrict.
9978 * @returns {Function} Returns the new restricted function.
9979 * @example
9980 *
9981 * var saves = ['profile', 'settings'];
9982 *
9983 * var done = _.after(saves.length, function() {
9984 * console.log('done saving!');
9985 * });
9986 *
9987 * _.forEach(saves, function(type) {
9988 * asyncSave({ 'type': type, 'complete': done });
9989 * });
9990 * // => Logs 'done saving!' after the two async saves have completed.
9991 */
9992 function after(n, func) {
9993 if (typeof func != 'function') {
9994 throw new TypeError(FUNC_ERROR_TEXT);
9995 }
9996 n = toInteger(n);
9997 return function() {
9998 if (--n < 1) {
9999 return func.apply(this, arguments);
10000 }
10001 };
10002 }
10003
10004 /**
10005 * Creates a function that invokes `func`, with up to `n` arguments,
10006 * ignoring any additional arguments.
10007 *
10008 * @static
10009 * @memberOf _
10010 * @since 3.0.0
10011 * @category Function
10012 * @param {Function} func The function to cap arguments for.
10013 * @param {number} [n=func.length] The arity cap.
10014 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10015 * @returns {Function} Returns the new capped function.
10016 * @example
10017 *
10018 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
10019 * // => [6, 8, 10]
10020 */
10021 function ary(func, n, guard) {
10022 n = guard ? undefined : n;
10023 n = (func && n == null) ? func.length : n;
10024 return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
10025 }
10026
10027 /**
10028 * Creates a function that invokes `func`, with the `this` binding and arguments
10029 * of the created function, while it's called less than `n` times. Subsequent
10030 * calls to the created function return the result of the last `func` invocation.
10031 *
10032 * @static
10033 * @memberOf _
10034 * @since 3.0.0
10035 * @category Function
10036 * @param {number} n The number of calls at which `func` is no longer invoked.
10037 * @param {Function} func The function to restrict.
10038 * @returns {Function} Returns the new restricted function.
10039 * @example
10040 *
10041 * jQuery(element).on('click', _.before(5, addContactToList));
10042 * // => Allows adding up to 4 contacts to the list.
10043 */
10044 function before(n, func) {
10045 var result;
10046 if (typeof func != 'function') {
10047 throw new TypeError(FUNC_ERROR_TEXT);
10048 }
10049 n = toInteger(n);
10050 return function() {
10051 if (--n > 0) {
10052 result = func.apply(this, arguments);
10053 }
10054 if (n <= 1) {
10055 func = undefined;
10056 }
10057 return result;
10058 };
10059 }
10060
10061 /**
10062 * Creates a function that invokes `func` with the `this` binding of `thisArg`
10063 * and `partials` prepended to the arguments it receives.
10064 *
10065 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
10066 * may be used as a placeholder for partially applied arguments.
10067 *
10068 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
10069 * property of bound functions.
10070 *
10071 * @static
10072 * @memberOf _
10073 * @since 0.1.0
10074 * @category Function
10075 * @param {Function} func The function to bind.
10076 * @param {*} thisArg The `this` binding of `func`.
10077 * @param {...*} [partials] The arguments to be partially applied.
10078 * @returns {Function} Returns the new bound function.
10079 * @example
10080 *
10081 * function greet(greeting, punctuation) {
10082 * return greeting + ' ' + this.user + punctuation;
10083 * }
10084 *
10085 * var object = { 'user': 'fred' };
10086 *
10087 * var bound = _.bind(greet, object, 'hi');
10088 * bound('!');
10089 * // => 'hi fred!'
10090 *
10091 * // Bound with placeholders.
10092 * var bound = _.bind(greet, object, _, '!');
10093 * bound('hi');
10094 * // => 'hi fred!'
10095 */
10096 var bind = baseRest(function(func, thisArg, partials) {
10097 var bitmask = WRAP_BIND_FLAG;
10098 if (partials.length) {
10099 var holders = replaceHolders(partials, getHolder(bind));
10100 bitmask |= WRAP_PARTIAL_FLAG;
10101 }
10102 return createWrap(func, bitmask, thisArg, partials, holders);
10103 });
10104
10105 /**
10106 * Creates a function that invokes the method at `object[key]` with `partials`
10107 * prepended to the arguments it receives.
10108 *
10109 * This method differs from `_.bind` by allowing bound functions to reference
10110 * methods that may be redefined or don't yet exist. See
10111 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
10112 * for more details.
10113 *
10114 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
10115 * builds, may be used as a placeholder for partially applied arguments.
10116 *
10117 * @static
10118 * @memberOf _
10119 * @since 0.10.0
10120 * @category Function
10121 * @param {Object} object The object to invoke the method on.
10122 * @param {string} key The key of the method.
10123 * @param {...*} [partials] The arguments to be partially applied.
10124 * @returns {Function} Returns the new bound function.
10125 * @example
10126 *
10127 * var object = {
10128 * 'user': 'fred',
10129 * 'greet': function(greeting, punctuation) {
10130 * return greeting + ' ' + this.user + punctuation;
10131 * }
10132 * };
10133 *
10134 * var bound = _.bindKey(object, 'greet', 'hi');
10135 * bound('!');
10136 * // => 'hi fred!'
10137 *
10138 * object.greet = function(greeting, punctuation) {
10139 * return greeting + 'ya ' + this.user + punctuation;
10140 * };
10141 *
10142 * bound('!');
10143 * // => 'hiya fred!'
10144 *
10145 * // Bound with placeholders.
10146 * var bound = _.bindKey(object, 'greet', _, '!');
10147 * bound('hi');
10148 * // => 'hiya fred!'
10149 */
10150 var bindKey = baseRest(function(object, key, partials) {
10151 var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
10152 if (partials.length) {
10153 var holders = replaceHolders(partials, getHolder(bindKey));
10154 bitmask |= WRAP_PARTIAL_FLAG;
10155 }
10156 return createWrap(key, bitmask, object, partials, holders);
10157 });
10158
10159 /**
10160 * Creates a function that accepts arguments of `func` and either invokes
10161 * `func` returning its result, if at least `arity` number of arguments have
10162 * been provided, or returns a function that accepts the remaining `func`
10163 * arguments, and so on. The arity of `func` may be specified if `func.length`
10164 * is not sufficient.
10165 *
10166 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
10167 * may be used as a placeholder for provided arguments.
10168 *
10169 * **Note:** This method doesn't set the "length" property of curried functions.
10170 *
10171 * @static
10172 * @memberOf _
10173 * @since 2.0.0
10174 * @category Function
10175 * @param {Function} func The function to curry.
10176 * @param {number} [arity=func.length] The arity of `func`.
10177 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10178 * @returns {Function} Returns the new curried function.
10179 * @example
10180 *
10181 * var abc = function(a, b, c) {
10182 * return [a, b, c];
10183 * };
10184 *
10185 * var curried = _.curry(abc);
10186 *
10187 * curried(1)(2)(3);
10188 * // => [1, 2, 3]
10189 *
10190 * curried(1, 2)(3);
10191 * // => [1, 2, 3]
10192 *
10193 * curried(1, 2, 3);
10194 * // => [1, 2, 3]
10195 *
10196 * // Curried with placeholders.
10197 * curried(1)(_, 3)(2);
10198 * // => [1, 2, 3]
10199 */
10200 function curry(func, arity, guard) {
10201 arity = guard ? undefined : arity;
10202 var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10203 result.placeholder = curry.placeholder;
10204 return result;
10205 }
10206
10207 /**
10208 * This method is like `_.curry` except that arguments are applied to `func`
10209 * in the manner of `_.partialRight` instead of `_.partial`.
10210 *
10211 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
10212 * builds, may be used as a placeholder for provided arguments.
10213 *
10214 * **Note:** This method doesn't set the "length" property of curried functions.
10215 *
10216 * @static
10217 * @memberOf _
10218 * @since 3.0.0
10219 * @category Function
10220 * @param {Function} func The function to curry.
10221 * @param {number} [arity=func.length] The arity of `func`.
10222 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10223 * @returns {Function} Returns the new curried function.
10224 * @example
10225 *
10226 * var abc = function(a, b, c) {
10227 * return [a, b, c];
10228 * };
10229 *
10230 * var curried = _.curryRight(abc);
10231 *
10232 * curried(3)(2)(1);
10233 * // => [1, 2, 3]
10234 *
10235 * curried(2, 3)(1);
10236 * // => [1, 2, 3]
10237 *
10238 * curried(1, 2, 3);
10239 * // => [1, 2, 3]
10240 *
10241 * // Curried with placeholders.
10242 * curried(3)(1, _)(2);
10243 * // => [1, 2, 3]
10244 */
10245 function curryRight(func, arity, guard) {
10246 arity = guard ? undefined : arity;
10247 var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10248 result.placeholder = curryRight.placeholder;
10249 return result;
10250 }
10251
10252 /**
10253 * Creates a debounced function that delays invoking `func` until after `wait`
10254 * milliseconds have elapsed since the last time the debounced function was
10255 * invoked. The debounced function comes with a `cancel` method to cancel
10256 * delayed `func` invocations and a `flush` method to immediately invoke them.
10257 * Provide `options` to indicate whether `func` should be invoked on the
10258 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
10259 * with the last arguments provided to the debounced function. Subsequent
10260 * calls to the debounced function return the result of the last `func`
10261 * invocation.
10262 *
10263 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10264 * invoked on the trailing edge of the timeout only if the debounced function
10265 * is invoked more than once during the `wait` timeout.
10266 *
10267 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10268 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10269 *
10270 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10271 * for details over the differences between `_.debounce` and `_.throttle`.
10272 *
10273 * @static
10274 * @memberOf _
10275 * @since 0.1.0
10276 * @category Function
10277 * @param {Function} func The function to debounce.
10278 * @param {number} [wait=0] The number of milliseconds to delay.
10279 * @param {Object} [options={}] The options object.
10280 * @param {boolean} [options.leading=false]
10281 * Specify invoking on the leading edge of the timeout.
10282 * @param {number} [options.maxWait]
10283 * The maximum time `func` is allowed to be delayed before it's invoked.
10284 * @param {boolean} [options.trailing=true]
10285 * Specify invoking on the trailing edge of the timeout.
10286 * @returns {Function} Returns the new debounced function.
10287 * @example
10288 *
10289 * // Avoid costly calculations while the window size is in flux.
10290 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
10291 *
10292 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
10293 * jQuery(element).on('click', _.debounce(sendMail, 300, {
10294 * 'leading': true,
10295 * 'trailing': false
10296 * }));
10297 *
10298 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
10299 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
10300 * var source = new EventSource('/stream');
10301 * jQuery(source).on('message', debounced);
10302 *
10303 * // Cancel the trailing debounced invocation.
10304 * jQuery(window).on('popstate', debounced.cancel);
10305 */
10306 function debounce(func, wait, options) {
10307 var lastArgs,
10308 lastThis,
10309 maxWait,
10310 result,
10311 timerId,
10312 lastCallTime,
10313 lastInvokeTime = 0,
10314 leading = false,
10315 maxing = false,
10316 trailing = true;
10317
10318 if (typeof func != 'function') {
10319 throw new TypeError(FUNC_ERROR_TEXT);
10320 }
10321 wait = toNumber(wait) || 0;
10322 if (isObject(options)) {
10323 leading = !!options.leading;
10324 maxing = 'maxWait' in options;
10325 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
10326 trailing = 'trailing' in options ? !!options.trailing : trailing;
10327 }
10328
10329 function invokeFunc(time) {
10330 var args = lastArgs,
10331 thisArg = lastThis;
10332
10333 lastArgs = lastThis = undefined;
10334 lastInvokeTime = time;
10335 result = func.apply(thisArg, args);
10336 return result;
10337 }
10338
10339 function leadingEdge(time) {
10340 // Reset any `maxWait` timer.
10341 lastInvokeTime = time;
10342 // Start the timer for the trailing edge.
10343 timerId = setTimeout(timerExpired, wait);
10344 // Invoke the leading edge.
10345 return leading ? invokeFunc(time) : result;
10346 }
10347
10348 function remainingWait(time) {
10349 var timeSinceLastCall = time - lastCallTime,
10350 timeSinceLastInvoke = time - lastInvokeTime,
10351 result = wait - timeSinceLastCall;
10352
10353 return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
10354 }
10355
10356 function shouldInvoke(time) {
10357 var timeSinceLastCall = time - lastCallTime,
10358 timeSinceLastInvoke = time - lastInvokeTime;
10359
10360 // Either this is the first call, activity has stopped and we're at the
10361 // trailing edge, the system time has gone backwards and we're treating
10362 // it as the trailing edge, or we've hit the `maxWait` limit.
10363 return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
10364 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
10365 }
10366
10367 function timerExpired() {
10368 var time = now();
10369 if (shouldInvoke(time)) {
10370 return trailingEdge(time);
10371 }
10372 // Restart the timer.
10373 timerId = setTimeout(timerExpired, remainingWait(time));
10374 }
10375
10376 function trailingEdge(time) {
10377 timerId = undefined;
10378
10379 // Only invoke if we have `lastArgs` which means `func` has been
10380 // debounced at least once.
10381 if (trailing && lastArgs) {
10382 return invokeFunc(time);
10383 }
10384 lastArgs = lastThis = undefined;
10385 return result;
10386 }
10387
10388 function cancel() {
10389 if (timerId !== undefined) {
10390 clearTimeout(timerId);
10391 }
10392 lastInvokeTime = 0;
10393 lastArgs = lastCallTime = lastThis = timerId = undefined;
10394 }
10395
10396 function flush() {
10397 return timerId === undefined ? result : trailingEdge(now());
10398 }
10399
10400 function debounced() {
10401 var time = now(),
10402 isInvoking = shouldInvoke(time);
10403
10404 lastArgs = arguments;
10405 lastThis = this;
10406 lastCallTime = time;
10407
10408 if (isInvoking) {
10409 if (timerId === undefined) {
10410 return leadingEdge(lastCallTime);
10411 }
10412 if (maxing) {
10413 // Handle invocations in a tight loop.
10414 timerId = setTimeout(timerExpired, wait);
10415 return invokeFunc(lastCallTime);
10416 }
10417 }
10418 if (timerId === undefined) {
10419 timerId = setTimeout(timerExpired, wait);
10420 }
10421 return result;
10422 }
10423 debounced.cancel = cancel;
10424 debounced.flush = flush;
10425 return debounced;
10426 }
10427
10428 /**
10429 * Defers invoking the `func` until the current call stack has cleared. Any
10430 * additional arguments are provided to `func` when it's invoked.
10431 *
10432 * @static
10433 * @memberOf _
10434 * @since 0.1.0
10435 * @category Function
10436 * @param {Function} func The function to defer.
10437 * @param {...*} [args] The arguments to invoke `func` with.
10438 * @returns {number} Returns the timer id.
10439 * @example
10440 *
10441 * _.defer(function(text) {
10442 * console.log(text);
10443 * }, 'deferred');
10444 * // => Logs 'deferred' after one millisecond.
10445 */
10446 var defer = baseRest(function(func, args) {
10447 return baseDelay(func, 1, args);
10448 });
10449
10450 /**
10451 * Invokes `func` after `wait` milliseconds. Any additional arguments are
10452 * provided to `func` when it's invoked.
10453 *
10454 * @static
10455 * @memberOf _
10456 * @since 0.1.0
10457 * @category Function
10458 * @param {Function} func The function to delay.
10459 * @param {number} wait The number of milliseconds to delay invocation.
10460 * @param {...*} [args] The arguments to invoke `func` with.
10461 * @returns {number} Returns the timer id.
10462 * @example
10463 *
10464 * _.delay(function(text) {
10465 * console.log(text);
10466 * }, 1000, 'later');
10467 * // => Logs 'later' after one second.
10468 */
10469 var delay = baseRest(function(func, wait, args) {
10470 return baseDelay(func, toNumber(wait) || 0, args);
10471 });
10472
10473 /**
10474 * Creates a function that invokes `func` with arguments reversed.
10475 *
10476 * @static
10477 * @memberOf _
10478 * @since 4.0.0
10479 * @category Function
10480 * @param {Function} func The function to flip arguments for.
10481 * @returns {Function} Returns the new flipped function.
10482 * @example
10483 *
10484 * var flipped = _.flip(function() {
10485 * return _.toArray(arguments);
10486 * });
10487 *
10488 * flipped('a', 'b', 'c', 'd');
10489 * // => ['d', 'c', 'b', 'a']
10490 */
10491 function flip(func) {
10492 return createWrap(func, WRAP_FLIP_FLAG);
10493 }
10494
10495 /**
10496 * Creates a function that memoizes the result of `func`. If `resolver` is
10497 * provided, it determines the cache key for storing the result based on the
10498 * arguments provided to the memoized function. By default, the first argument
10499 * provided to the memoized function is used as the map cache key. The `func`
10500 * is invoked with the `this` binding of the memoized function.
10501 *
10502 * **Note:** The cache is exposed as the `cache` property on the memoized
10503 * function. Its creation may be customized by replacing the `_.memoize.Cache`
10504 * constructor with one whose instances implement the
10505 * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
10506 * method interface of `clear`, `delete`, `get`, `has`, and `set`.
10507 *
10508 * @static
10509 * @memberOf _
10510 * @since 0.1.0
10511 * @category Function
10512 * @param {Function} func The function to have its output memoized.
10513 * @param {Function} [resolver] The function to resolve the cache key.
10514 * @returns {Function} Returns the new memoized function.
10515 * @example
10516 *
10517 * var object = { 'a': 1, 'b': 2 };
10518 * var other = { 'c': 3, 'd': 4 };
10519 *
10520 * var values = _.memoize(_.values);
10521 * values(object);
10522 * // => [1, 2]
10523 *
10524 * values(other);
10525 * // => [3, 4]
10526 *
10527 * object.a = 2;
10528 * values(object);
10529 * // => [1, 2]
10530 *
10531 * // Modify the result cache.
10532 * values.cache.set(object, ['a', 'b']);
10533 * values(object);
10534 * // => ['a', 'b']
10535 *
10536 * // Replace `_.memoize.Cache`.
10537 * _.memoize.Cache = WeakMap;
10538 */
10539 function memoize(func, resolver) {
10540 if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
10541 throw new TypeError(FUNC_ERROR_TEXT);
10542 }
10543 var memoized = function() {
10544 var args = arguments,
10545 key = resolver ? resolver.apply(this, args) : args[0],
10546 cache = memoized.cache;
10547
10548 if (cache.has(key)) {
10549 return cache.get(key);
10550 }
10551 var result = func.apply(this, args);
10552 memoized.cache = cache.set(key, result) || cache;
10553 return result;
10554 };
10555 memoized.cache = new (memoize.Cache || MapCache);
10556 return memoized;
10557 }
10558
10559 // Expose `MapCache`.
10560 memoize.Cache = MapCache;
10561
10562 /**
10563 * Creates a function that negates the result of the predicate `func`. The
10564 * `func` predicate is invoked with the `this` binding and arguments of the
10565 * created function.
10566 *
10567 * @static
10568 * @memberOf _
10569 * @since 3.0.0
10570 * @category Function
10571 * @param {Function} predicate The predicate to negate.
10572 * @returns {Function} Returns the new negated function.
10573 * @example
10574 *
10575 * function isEven(n) {
10576 * return n % 2 == 0;
10577 * }
10578 *
10579 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
10580 * // => [1, 3, 5]
10581 */
10582 function negate(predicate) {
10583 if (typeof predicate != 'function') {
10584 throw new TypeError(FUNC_ERROR_TEXT);
10585 }
10586 return function() {
10587 var args = arguments;
10588 switch (args.length) {
10589 case 0: return !predicate.call(this);
10590 case 1: return !predicate.call(this, args[0]);
10591 case 2: return !predicate.call(this, args[0], args[1]);
10592 case 3: return !predicate.call(this, args[0], args[1], args[2]);
10593 }
10594 return !predicate.apply(this, args);
10595 };
10596 }
10597
10598 /**
10599 * Creates a function that is restricted to invoking `func` once. Repeat calls
10600 * to the function return the value of the first invocation. The `func` is
10601 * invoked with the `this` binding and arguments of the created function.
10602 *
10603 * @static
10604 * @memberOf _
10605 * @since 0.1.0
10606 * @category Function
10607 * @param {Function} func The function to restrict.
10608 * @returns {Function} Returns the new restricted function.
10609 * @example
10610 *
10611 * var initialize = _.once(createApplication);
10612 * initialize();
10613 * initialize();
10614 * // => `createApplication` is invoked once
10615 */
10616 function once(func) {
10617 return before(2, func);
10618 }
10619
10620 /**
10621 * Creates a function that invokes `func` with its arguments transformed.
10622 *
10623 * @static
10624 * @since 4.0.0
10625 * @memberOf _
10626 * @category Function
10627 * @param {Function} func The function to wrap.
10628 * @param {...(Function|Function[])} [transforms=[_.identity]]
10629 * The argument transforms.
10630 * @returns {Function} Returns the new function.
10631 * @example
10632 *
10633 * function doubled(n) {
10634 * return n * 2;
10635 * }
10636 *
10637 * function square(n) {
10638 * return n * n;
10639 * }
10640 *
10641 * var func = _.overArgs(function(x, y) {
10642 * return [x, y];
10643 * }, [square, doubled]);
10644 *
10645 * func(9, 3);
10646 * // => [81, 6]
10647 *
10648 * func(10, 5);
10649 * // => [100, 10]
10650 */
10651 var overArgs = castRest(function(func, transforms) {
10652 transforms = (transforms.length == 1 && isArray(transforms[0]))
10653 ? arrayMap(transforms[0], baseUnary(getIteratee()))
10654 : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
10655
10656 var funcsLength = transforms.length;
10657 return baseRest(function(args) {
10658 var index = -1,
10659 length = nativeMin(args.length, funcsLength);
10660
10661 while (++index < length) {
10662 args[index] = transforms[index].call(this, args[index]);
10663 }
10664 return apply(func, this, args);
10665 });
10666 });
10667
10668 /**
10669 * Creates a function that invokes `func` with `partials` prepended to the
10670 * arguments it receives. This method is like `_.bind` except it does **not**
10671 * alter the `this` binding.
10672 *
10673 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
10674 * builds, may be used as a placeholder for partially applied arguments.
10675 *
10676 * **Note:** This method doesn't set the "length" property of partially
10677 * applied functions.
10678 *
10679 * @static
10680 * @memberOf _
10681 * @since 0.2.0
10682 * @category Function
10683 * @param {Function} func The function to partially apply arguments to.
10684 * @param {...*} [partials] The arguments to be partially applied.
10685 * @returns {Function} Returns the new partially applied function.
10686 * @example
10687 *
10688 * function greet(greeting, name) {
10689 * return greeting + ' ' + name;
10690 * }
10691 *
10692 * var sayHelloTo = _.partial(greet, 'hello');
10693 * sayHelloTo('fred');
10694 * // => 'hello fred'
10695 *
10696 * // Partially applied with placeholders.
10697 * var greetFred = _.partial(greet, _, 'fred');
10698 * greetFred('hi');
10699 * // => 'hi fred'
10700 */
10701 var partial = baseRest(function(func, partials) {
10702 var holders = replaceHolders(partials, getHolder(partial));
10703 return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
10704 });
10705
10706 /**
10707 * This method is like `_.partial` except that partially applied arguments
10708 * are appended to the arguments it receives.
10709 *
10710 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
10711 * builds, may be used as a placeholder for partially applied arguments.
10712 *
10713 * **Note:** This method doesn't set the "length" property of partially
10714 * applied functions.
10715 *
10716 * @static
10717 * @memberOf _
10718 * @since 1.0.0
10719 * @category Function
10720 * @param {Function} func The function to partially apply arguments to.
10721 * @param {...*} [partials] The arguments to be partially applied.
10722 * @returns {Function} Returns the new partially applied function.
10723 * @example
10724 *
10725 * function greet(greeting, name) {
10726 * return greeting + ' ' + name;
10727 * }
10728 *
10729 * var greetFred = _.partialRight(greet, 'fred');
10730 * greetFred('hi');
10731 * // => 'hi fred'
10732 *
10733 * // Partially applied with placeholders.
10734 * var sayHelloTo = _.partialRight(greet, 'hello', _);
10735 * sayHelloTo('fred');
10736 * // => 'hello fred'
10737 */
10738 var partialRight = baseRest(function(func, partials) {
10739 var holders = replaceHolders(partials, getHolder(partialRight));
10740 return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
10741 });
10742
10743 /**
10744 * Creates a function that invokes `func` with arguments arranged according
10745 * to the specified `indexes` where the argument value at the first index is
10746 * provided as the first argument, the argument value at the second index is
10747 * provided as the second argument, and so on.
10748 *
10749 * @static
10750 * @memberOf _
10751 * @since 3.0.0
10752 * @category Function
10753 * @param {Function} func The function to rearrange arguments for.
10754 * @param {...(number|number[])} indexes The arranged argument indexes.
10755 * @returns {Function} Returns the new function.
10756 * @example
10757 *
10758 * var rearged = _.rearg(function(a, b, c) {
10759 * return [a, b, c];
10760 * }, [2, 0, 1]);
10761 *
10762 * rearged('b', 'c', 'a')
10763 * // => ['a', 'b', 'c']
10764 */
10765 var rearg = flatRest(function(func, indexes) {
10766 return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
10767 });
10768
10769 /**
10770 * Creates a function that invokes `func` with the `this` binding of the
10771 * created function and arguments from `start` and beyond provided as
10772 * an array.
10773 *
10774 * **Note:** This method is based on the
10775 * [rest parameter](https://mdn.io/rest_parameters).
10776 *
10777 * @static
10778 * @memberOf _
10779 * @since 4.0.0
10780 * @category Function
10781 * @param {Function} func The function to apply a rest parameter to.
10782 * @param {number} [start=func.length-1] The start position of the rest parameter.
10783 * @returns {Function} Returns the new function.
10784 * @example
10785 *
10786 * var say = _.rest(function(what, names) {
10787 * return what + ' ' + _.initial(names).join(', ') +
10788 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
10789 * });
10790 *
10791 * say('hello', 'fred', 'barney', 'pebbles');
10792 * // => 'hello fred, barney, & pebbles'
10793 */
10794 function rest(func, start) {
10795 if (typeof func != 'function') {
10796 throw new TypeError(FUNC_ERROR_TEXT);
10797 }
10798 start = start === undefined ? start : toInteger(start);
10799 return baseRest(func, start);
10800 }
10801
10802 /**
10803 * Creates a function that invokes `func` with the `this` binding of the
10804 * create function and an array of arguments much like
10805 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
10806 *
10807 * **Note:** This method is based on the
10808 * [spread operator](https://mdn.io/spread_operator).
10809 *
10810 * @static
10811 * @memberOf _
10812 * @since 3.2.0
10813 * @category Function
10814 * @param {Function} func The function to spread arguments over.
10815 * @param {number} [start=0] The start position of the spread.
10816 * @returns {Function} Returns the new function.
10817 * @example
10818 *
10819 * var say = _.spread(function(who, what) {
10820 * return who + ' says ' + what;
10821 * });
10822 *
10823 * say(['fred', 'hello']);
10824 * // => 'fred says hello'
10825 *
10826 * var numbers = Promise.all([
10827 * Promise.resolve(40),
10828 * Promise.resolve(36)
10829 * ]);
10830 *
10831 * numbers.then(_.spread(function(x, y) {
10832 * return x + y;
10833 * }));
10834 * // => a Promise of 76
10835 */
10836 function spread(func, start) {
10837 if (typeof func != 'function') {
10838 throw new TypeError(FUNC_ERROR_TEXT);
10839 }
10840 start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
10841 return baseRest(function(args) {
10842 var array = args[start],
10843 otherArgs = castSlice(args, 0, start);
10844
10845 if (array) {
10846 arrayPush(otherArgs, array);
10847 }
10848 return apply(func, this, otherArgs);
10849 });
10850 }
10851
10852 /**
10853 * Creates a throttled function that only invokes `func` at most once per
10854 * every `wait` milliseconds. The throttled function comes with a `cancel`
10855 * method to cancel delayed `func` invocations and a `flush` method to
10856 * immediately invoke them. Provide `options` to indicate whether `func`
10857 * should be invoked on the leading and/or trailing edge of the `wait`
10858 * timeout. The `func` is invoked with the last arguments provided to the
10859 * throttled function. Subsequent calls to the throttled function return the
10860 * result of the last `func` invocation.
10861 *
10862 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10863 * invoked on the trailing edge of the timeout only if the throttled function
10864 * is invoked more than once during the `wait` timeout.
10865 *
10866 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10867 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10868 *
10869 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10870 * for details over the differences between `_.throttle` and `_.debounce`.
10871 *
10872 * @static
10873 * @memberOf _
10874 * @since 0.1.0
10875 * @category Function
10876 * @param {Function} func The function to throttle.
10877 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
10878 * @param {Object} [options={}] The options object.
10879 * @param {boolean} [options.leading=true]
10880 * Specify invoking on the leading edge of the timeout.
10881 * @param {boolean} [options.trailing=true]
10882 * Specify invoking on the trailing edge of the timeout.
10883 * @returns {Function} Returns the new throttled function.
10884 * @example
10885 *
10886 * // Avoid excessively updating the position while scrolling.
10887 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
10888 *
10889 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
10890 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
10891 * jQuery(element).on('click', throttled);
10892 *
10893 * // Cancel the trailing throttled invocation.
10894 * jQuery(window).on('popstate', throttled.cancel);
10895 */
10896 function throttle(func, wait, options) {
10897 var leading = true,
10898 trailing = true;
10899
10900 if (typeof func != 'function') {
10901 throw new TypeError(FUNC_ERROR_TEXT);
10902 }
10903 if (isObject(options)) {
10904 leading = 'leading' in options ? !!options.leading : leading;
10905 trailing = 'trailing' in options ? !!options.trailing : trailing;
10906 }
10907 return debounce(func, wait, {
10908 'leading': leading,
10909 'maxWait': wait,
10910 'trailing': trailing
10911 });
10912 }
10913
10914 /**
10915 * Creates a function that accepts up to one argument, ignoring any
10916 * additional arguments.
10917 *
10918 * @static
10919 * @memberOf _
10920 * @since 4.0.0
10921 * @category Function
10922 * @param {Function} func The function to cap arguments for.
10923 * @returns {Function} Returns the new capped function.
10924 * @example
10925 *
10926 * _.map(['6', '8', '10'], _.unary(parseInt));
10927 * // => [6, 8, 10]
10928 */
10929 function unary(func) {
10930 return ary(func, 1);
10931 }
10932
10933 /**
10934 * Creates a function that provides `value` to `wrapper` as its first
10935 * argument. Any additional arguments provided to the function are appended
10936 * to those provided to the `wrapper`. The wrapper is invoked with the `this`
10937 * binding of the created function.
10938 *
10939 * @static
10940 * @memberOf _
10941 * @since 0.1.0
10942 * @category Function
10943 * @param {*} value The value to wrap.
10944 * @param {Function} [wrapper=identity] The wrapper function.
10945 * @returns {Function} Returns the new function.
10946 * @example
10947 *
10948 * var p = _.wrap(_.escape, function(func, text) {
10949 * return '<p>' + func(text) + '</p>';
10950 * });
10951 *
10952 * p('fred, barney, & pebbles');
10953 * // => '<p>fred, barney, &amp; pebbles</p>'
10954 */
10955 function wrap(value, wrapper) {
10956 return partial(castFunction(wrapper), value);
10957 }
10958
10959 /*------------------------------------------------------------------------*/
10960
10961 /**
10962 * Casts `value` as an array if it's not one.
10963 *
10964 * @static
10965 * @memberOf _
10966 * @since 4.4.0
10967 * @category Lang
10968 * @param {*} value The value to inspect.
10969 * @returns {Array} Returns the cast array.
10970 * @example
10971 *
10972 * _.castArray(1);
10973 * // => [1]
10974 *
10975 * _.castArray({ 'a': 1 });
10976 * // => [{ 'a': 1 }]
10977 *
10978 * _.castArray('abc');
10979 * // => ['abc']
10980 *
10981 * _.castArray(null);
10982 * // => [null]
10983 *
10984 * _.castArray(undefined);
10985 * // => [undefined]
10986 *
10987 * _.castArray();
10988 * // => []
10989 *
10990 * var array = [1, 2, 3];
10991 * console.log(_.castArray(array) === array);
10992 * // => true
10993 */
10994 function castArray() {
10995 if (!arguments.length) {
10996 return [];
10997 }
10998 var value = arguments[0];
10999 return isArray(value) ? value : [value];
11000 }
11001
11002 /**
11003 * Creates a shallow clone of `value`.
11004 *
11005 * **Note:** This method is loosely based on the
11006 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
11007 * and supports cloning arrays, array buffers, booleans, date objects, maps,
11008 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
11009 * arrays. The own enumerable properties of `arguments` objects are cloned
11010 * as plain objects. An empty object is returned for uncloneable values such
11011 * as error objects, functions, DOM nodes, and WeakMaps.
11012 *
11013 * @static
11014 * @memberOf _
11015 * @since 0.1.0
11016 * @category Lang
11017 * @param {*} value The value to clone.
11018 * @returns {*} Returns the cloned value.
11019 * @see _.cloneDeep
11020 * @example
11021 *
11022 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11023 *
11024 * var shallow = _.clone(objects);
11025 * console.log(shallow[0] === objects[0]);
11026 * // => true
11027 */
11028 function clone(value) {
11029 return baseClone(value, CLONE_SYMBOLS_FLAG);
11030 }
11031
11032 /**
11033 * This method is like `_.clone` except that it accepts `customizer` which
11034 * is invoked to produce the cloned value. If `customizer` returns `undefined`,
11035 * cloning is handled by the method instead. The `customizer` is invoked with
11036 * up to four arguments; (value [, index|key, object, stack]).
11037 *
11038 * @static
11039 * @memberOf _
11040 * @since 4.0.0
11041 * @category Lang
11042 * @param {*} value The value to clone.
11043 * @param {Function} [customizer] The function to customize cloning.
11044 * @returns {*} Returns the cloned value.
11045 * @see _.cloneDeepWith
11046 * @example
11047 *
11048 * function customizer(value) {
11049 * if (_.isElement(value)) {
11050 * return value.cloneNode(false);
11051 * }
11052 * }
11053 *
11054 * var el = _.cloneWith(document.body, customizer);
11055 *
11056 * console.log(el === document.body);
11057 * // => false
11058 * console.log(el.nodeName);
11059 * // => 'BODY'
11060 * console.log(el.childNodes.length);
11061 * // => 0
11062 */
11063 function cloneWith(value, customizer) {
11064 customizer = typeof customizer == 'function' ? customizer : undefined;
11065 return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
11066 }
11067
11068 /**
11069 * This method is like `_.clone` except that it recursively clones `value`.
11070 *
11071 * @static
11072 * @memberOf _
11073 * @since 1.0.0
11074 * @category Lang
11075 * @param {*} value The value to recursively clone.
11076 * @returns {*} Returns the deep cloned value.
11077 * @see _.clone
11078 * @example
11079 *
11080 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11081 *
11082 * var deep = _.cloneDeep(objects);
11083 * console.log(deep[0] === objects[0]);
11084 * // => false
11085 */
11086 function cloneDeep(value) {
11087 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
11088 }
11089
11090 /**
11091 * This method is like `_.cloneWith` except that it recursively clones `value`.
11092 *
11093 * @static
11094 * @memberOf _
11095 * @since 4.0.0
11096 * @category Lang
11097 * @param {*} value The value to recursively clone.
11098 * @param {Function} [customizer] The function to customize cloning.
11099 * @returns {*} Returns the deep cloned value.
11100 * @see _.cloneWith
11101 * @example
11102 *
11103 * function customizer(value) {
11104 * if (_.isElement(value)) {
11105 * return value.cloneNode(true);
11106 * }
11107 * }
11108 *
11109 * var el = _.cloneDeepWith(document.body, customizer);
11110 *
11111 * console.log(el === document.body);
11112 * // => false
11113 * console.log(el.nodeName);
11114 * // => 'BODY'
11115 * console.log(el.childNodes.length);
11116 * // => 20
11117 */
11118 function cloneDeepWith(value, customizer) {
11119 customizer = typeof customizer == 'function' ? customizer : undefined;
11120 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
11121 }
11122
11123 /**
11124 * Checks if `object` conforms to `source` by invoking the predicate
11125 * properties of `source` with the corresponding property values of `object`.
11126 *
11127 * **Note:** This method is equivalent to `_.conforms` when `source` is
11128 * partially applied.
11129 *
11130 * @static
11131 * @memberOf _
11132 * @since 4.14.0
11133 * @category Lang
11134 * @param {Object} object The object to inspect.
11135 * @param {Object} source The object of property predicates to conform to.
11136 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
11137 * @example
11138 *
11139 * var object = { 'a': 1, 'b': 2 };
11140 *
11141 * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
11142 * // => true
11143 *
11144 * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
11145 * // => false
11146 */
11147 function conformsTo(object, source) {
11148 return source == null || baseConformsTo(object, source, keys(source));
11149 }
11150
11151 /**
11152 * Performs a
11153 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
11154 * comparison between two values to determine if they are equivalent.
11155 *
11156 * @static
11157 * @memberOf _
11158 * @since 4.0.0
11159 * @category Lang
11160 * @param {*} value The value to compare.
11161 * @param {*} other The other value to compare.
11162 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11163 * @example
11164 *
11165 * var object = { 'a': 1 };
11166 * var other = { 'a': 1 };
11167 *
11168 * _.eq(object, object);
11169 * // => true
11170 *
11171 * _.eq(object, other);
11172 * // => false
11173 *
11174 * _.eq('a', 'a');
11175 * // => true
11176 *
11177 * _.eq('a', Object('a'));
11178 * // => false
11179 *
11180 * _.eq(NaN, NaN);
11181 * // => true
11182 */
11183 function eq(value, other) {
11184 return value === other || (value !== value && other !== other);
11185 }
11186
11187 /**
11188 * Checks if `value` is greater than `other`.
11189 *
11190 * @static
11191 * @memberOf _
11192 * @since 3.9.0
11193 * @category Lang
11194 * @param {*} value The value to compare.
11195 * @param {*} other The other value to compare.
11196 * @returns {boolean} Returns `true` if `value` is greater than `other`,
11197 * else `false`.
11198 * @see _.lt
11199 * @example
11200 *
11201 * _.gt(3, 1);
11202 * // => true
11203 *
11204 * _.gt(3, 3);
11205 * // => false
11206 *
11207 * _.gt(1, 3);
11208 * // => false
11209 */
11210 var gt = createRelationalOperation(baseGt);
11211
11212 /**
11213 * Checks if `value` is greater than or equal to `other`.
11214 *
11215 * @static
11216 * @memberOf _
11217 * @since 3.9.0
11218 * @category Lang
11219 * @param {*} value The value to compare.
11220 * @param {*} other The other value to compare.
11221 * @returns {boolean} Returns `true` if `value` is greater than or equal to
11222 * `other`, else `false`.
11223 * @see _.lte
11224 * @example
11225 *
11226 * _.gte(3, 1);
11227 * // => true
11228 *
11229 * _.gte(3, 3);
11230 * // => true
11231 *
11232 * _.gte(1, 3);
11233 * // => false
11234 */
11235 var gte = createRelationalOperation(function(value, other) {
11236 return value >= other;
11237 });
11238
11239 /**
11240 * Checks if `value` is likely an `arguments` object.
11241 *
11242 * @static
11243 * @memberOf _
11244 * @since 0.1.0
11245 * @category Lang
11246 * @param {*} value The value to check.
11247 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
11248 * else `false`.
11249 * @example
11250 *
11251 * _.isArguments(function() { return arguments; }());
11252 * // => true
11253 *
11254 * _.isArguments([1, 2, 3]);
11255 * // => false
11256 */
11257 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
11258 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
11259 !propertyIsEnumerable.call(value, 'callee');
11260 };
11261
11262 /**
11263 * Checks if `value` is classified as an `Array` object.
11264 *
11265 * @static
11266 * @memberOf _
11267 * @since 0.1.0
11268 * @category Lang
11269 * @param {*} value The value to check.
11270 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
11271 * @example
11272 *
11273 * _.isArray([1, 2, 3]);
11274 * // => true
11275 *
11276 * _.isArray(document.body.children);
11277 * // => false
11278 *
11279 * _.isArray('abc');
11280 * // => false
11281 *
11282 * _.isArray(_.noop);
11283 * // => false
11284 */
11285 var isArray = Array.isArray;
11286
11287 /**
11288 * Checks if `value` is classified as an `ArrayBuffer` object.
11289 *
11290 * @static
11291 * @memberOf _
11292 * @since 4.3.0
11293 * @category Lang
11294 * @param {*} value The value to check.
11295 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
11296 * @example
11297 *
11298 * _.isArrayBuffer(new ArrayBuffer(2));
11299 * // => true
11300 *
11301 * _.isArrayBuffer(new Array(2));
11302 * // => false
11303 */
11304 var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
11305
11306 /**
11307 * Checks if `value` is array-like. A value is considered array-like if it's
11308 * not a function and has a `value.length` that's an integer greater than or
11309 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
11310 *
11311 * @static
11312 * @memberOf _
11313 * @since 4.0.0
11314 * @category Lang
11315 * @param {*} value The value to check.
11316 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11317 * @example
11318 *
11319 * _.isArrayLike([1, 2, 3]);
11320 * // => true
11321 *
11322 * _.isArrayLike(document.body.children);
11323 * // => true
11324 *
11325 * _.isArrayLike('abc');
11326 * // => true
11327 *
11328 * _.isArrayLike(_.noop);
11329 * // => false
11330 */
11331 function isArrayLike(value) {
11332 return value != null && isLength(value.length) && !isFunction(value);
11333 }
11334
11335 /**
11336 * This method is like `_.isArrayLike` except that it also checks if `value`
11337 * is an object.
11338 *
11339 * @static
11340 * @memberOf _
11341 * @since 4.0.0
11342 * @category Lang
11343 * @param {*} value The value to check.
11344 * @returns {boolean} Returns `true` if `value` is an array-like object,
11345 * else `false`.
11346 * @example
11347 *
11348 * _.isArrayLikeObject([1, 2, 3]);
11349 * // => true
11350 *
11351 * _.isArrayLikeObject(document.body.children);
11352 * // => true
11353 *
11354 * _.isArrayLikeObject('abc');
11355 * // => false
11356 *
11357 * _.isArrayLikeObject(_.noop);
11358 * // => false
11359 */
11360 function isArrayLikeObject(value) {
11361 return isObjectLike(value) && isArrayLike(value);
11362 }
11363
11364 /**
11365 * Checks if `value` is classified as a boolean primitive or object.
11366 *
11367 * @static
11368 * @memberOf _
11369 * @since 0.1.0
11370 * @category Lang
11371 * @param {*} value The value to check.
11372 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
11373 * @example
11374 *
11375 * _.isBoolean(false);
11376 * // => true
11377 *
11378 * _.isBoolean(null);
11379 * // => false
11380 */
11381 function isBoolean(value) {
11382 return value === true || value === false ||
11383 (isObjectLike(value) && baseGetTag(value) == boolTag);
11384 }
11385
11386 /**
11387 * Checks if `value` is a buffer.
11388 *
11389 * @static
11390 * @memberOf _
11391 * @since 4.3.0
11392 * @category Lang
11393 * @param {*} value The value to check.
11394 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
11395 * @example
11396 *
11397 * _.isBuffer(new Buffer(2));
11398 * // => true
11399 *
11400 * _.isBuffer(new Uint8Array(2));
11401 * // => false
11402 */
11403 var isBuffer = nativeIsBuffer || stubFalse;
11404
11405 /**
11406 * Checks if `value` is classified as a `Date` object.
11407 *
11408 * @static
11409 * @memberOf _
11410 * @since 0.1.0
11411 * @category Lang
11412 * @param {*} value The value to check.
11413 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
11414 * @example
11415 *
11416 * _.isDate(new Date);
11417 * // => true
11418 *
11419 * _.isDate('Mon April 23 2012');
11420 * // => false
11421 */
11422 var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
11423
11424 /**
11425 * Checks if `value` is likely a DOM element.
11426 *
11427 * @static
11428 * @memberOf _
11429 * @since 0.1.0
11430 * @category Lang
11431 * @param {*} value The value to check.
11432 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
11433 * @example
11434 *
11435 * _.isElement(document.body);
11436 * // => true
11437 *
11438 * _.isElement('<body>');
11439 * // => false
11440 */
11441 function isElement(value) {
11442 return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
11443 }
11444
11445 /**
11446 * Checks if `value` is an empty object, collection, map, or set.
11447 *
11448 * Objects are considered empty if they have no own enumerable string keyed
11449 * properties.
11450 *
11451 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
11452 * jQuery-like collections are considered empty if they have a `length` of `0`.
11453 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
11454 *
11455 * @static
11456 * @memberOf _
11457 * @since 0.1.0
11458 * @category Lang
11459 * @param {*} value The value to check.
11460 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
11461 * @example
11462 *
11463 * _.isEmpty(null);
11464 * // => true
11465 *
11466 * _.isEmpty(true);
11467 * // => true
11468 *
11469 * _.isEmpty(1);
11470 * // => true
11471 *
11472 * _.isEmpty([1, 2, 3]);
11473 * // => false
11474 *
11475 * _.isEmpty({ 'a': 1 });
11476 * // => false
11477 */
11478 function isEmpty(value) {
11479 if (value == null) {
11480 return true;
11481 }
11482 if (isArrayLike(value) &&
11483 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
11484 isBuffer(value) || isTypedArray(value) || isArguments(value))) {
11485 return !value.length;
11486 }
11487 var tag = getTag(value);
11488 if (tag == mapTag || tag == setTag) {
11489 return !value.size;
11490 }
11491 if (isPrototype(value)) {
11492 return !baseKeys(value).length;
11493 }
11494 for (var key in value) {
11495 if (hasOwnProperty.call(value, key)) {
11496 return false;
11497 }
11498 }
11499 return true;
11500 }
11501
11502 /**
11503 * Performs a deep comparison between two values to determine if they are
11504 * equivalent.
11505 *
11506 * **Note:** This method supports comparing arrays, array buffers, booleans,
11507 * date objects, error objects, maps, numbers, `Object` objects, regexes,
11508 * sets, strings, symbols, and typed arrays. `Object` objects are compared
11509 * by their own, not inherited, enumerable properties. Functions and DOM
11510 * nodes are **not** supported.
11511 *
11512 * @static
11513 * @memberOf _
11514 * @since 0.1.0
11515 * @category Lang
11516 * @param {*} value The value to compare.
11517 * @param {*} other The other value to compare.
11518 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11519 * @example
11520 *
11521 * var object = { 'a': 1 };
11522 * var other = { 'a': 1 };
11523 *
11524 * _.isEqual(object, other);
11525 * // => true
11526 *
11527 * object === other;
11528 * // => false
11529 */
11530 function isEqual(value, other) {
11531 return baseIsEqual(value, other);
11532 }
11533
11534 /**
11535 * This method is like `_.isEqual` except that it accepts `customizer` which
11536 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11537 * are handled by the method instead. The `customizer` is invoked with up to
11538 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
11539 *
11540 * @static
11541 * @memberOf _
11542 * @since 4.0.0
11543 * @category Lang
11544 * @param {*} value The value to compare.
11545 * @param {*} other The other value to compare.
11546 * @param {Function} [customizer] The function to customize comparisons.
11547 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11548 * @example
11549 *
11550 * function isGreeting(value) {
11551 * return /^h(?:i|ello)$/.test(value);
11552 * }
11553 *
11554 * function customizer(objValue, othValue) {
11555 * if (isGreeting(objValue) && isGreeting(othValue)) {
11556 * return true;
11557 * }
11558 * }
11559 *
11560 * var array = ['hello', 'goodbye'];
11561 * var other = ['hi', 'goodbye'];
11562 *
11563 * _.isEqualWith(array, other, customizer);
11564 * // => true
11565 */
11566 function isEqualWith(value, other, customizer) {
11567 customizer = typeof customizer == 'function' ? customizer : undefined;
11568 var result = customizer ? customizer(value, other) : undefined;
11569 return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
11570 }
11571
11572 /**
11573 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
11574 * `SyntaxError`, `TypeError`, or `URIError` object.
11575 *
11576 * @static
11577 * @memberOf _
11578 * @since 3.0.0
11579 * @category Lang
11580 * @param {*} value The value to check.
11581 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
11582 * @example
11583 *
11584 * _.isError(new Error);
11585 * // => true
11586 *
11587 * _.isError(Error);
11588 * // => false
11589 */
11590 function isError(value) {
11591 if (!isObjectLike(value)) {
11592 return false;
11593 }
11594 var tag = baseGetTag(value);
11595 return tag == errorTag || tag == domExcTag ||
11596 (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
11597 }
11598
11599 /**
11600 * Checks if `value` is a finite primitive number.
11601 *
11602 * **Note:** This method is based on
11603 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
11604 *
11605 * @static
11606 * @memberOf _
11607 * @since 0.1.0
11608 * @category Lang
11609 * @param {*} value The value to check.
11610 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
11611 * @example
11612 *
11613 * _.isFinite(3);
11614 * // => true
11615 *
11616 * _.isFinite(Number.MIN_VALUE);
11617 * // => true
11618 *
11619 * _.isFinite(Infinity);
11620 * // => false
11621 *
11622 * _.isFinite('3');
11623 * // => false
11624 */
11625 function isFinite(value) {
11626 return typeof value == 'number' && nativeIsFinite(value);
11627 }
11628
11629 /**
11630 * Checks if `value` is classified as a `Function` object.
11631 *
11632 * @static
11633 * @memberOf _
11634 * @since 0.1.0
11635 * @category Lang
11636 * @param {*} value The value to check.
11637 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
11638 * @example
11639 *
11640 * _.isFunction(_);
11641 * // => true
11642 *
11643 * _.isFunction(/abc/);
11644 * // => false
11645 */
11646 function isFunction(value) {
11647 if (!isObject(value)) {
11648 return false;
11649 }
11650 // The use of `Object#toString` avoids issues with the `typeof` operator
11651 // in Safari 9 which returns 'object' for typed arrays and other constructors.
11652 var tag = baseGetTag(value);
11653 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
11654 }
11655
11656 /**
11657 * Checks if `value` is an integer.
11658 *
11659 * **Note:** This method is based on
11660 * [`Number.isInteger`](https://mdn.io/Number/isInteger).
11661 *
11662 * @static
11663 * @memberOf _
11664 * @since 4.0.0
11665 * @category Lang
11666 * @param {*} value The value to check.
11667 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
11668 * @example
11669 *
11670 * _.isInteger(3);
11671 * // => true
11672 *
11673 * _.isInteger(Number.MIN_VALUE);
11674 * // => false
11675 *
11676 * _.isInteger(Infinity);
11677 * // => false
11678 *
11679 * _.isInteger('3');
11680 * // => false
11681 */
11682 function isInteger(value) {
11683 return typeof value == 'number' && value == toInteger(value);
11684 }
11685
11686 /**
11687 * Checks if `value` is a valid array-like length.
11688 *
11689 * **Note:** This method is loosely based on
11690 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
11691 *
11692 * @static
11693 * @memberOf _
11694 * @since 4.0.0
11695 * @category Lang
11696 * @param {*} value The value to check.
11697 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11698 * @example
11699 *
11700 * _.isLength(3);
11701 * // => true
11702 *
11703 * _.isLength(Number.MIN_VALUE);
11704 * // => false
11705 *
11706 * _.isLength(Infinity);
11707 * // => false
11708 *
11709 * _.isLength('3');
11710 * // => false
11711 */
11712 function isLength(value) {
11713 return typeof value == 'number' &&
11714 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11715 }
11716
11717 /**
11718 * Checks if `value` is the
11719 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
11720 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11721 *
11722 * @static
11723 * @memberOf _
11724 * @since 0.1.0
11725 * @category Lang
11726 * @param {*} value The value to check.
11727 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11728 * @example
11729 *
11730 * _.isObject({});
11731 * // => true
11732 *
11733 * _.isObject([1, 2, 3]);
11734 * // => true
11735 *
11736 * _.isObject(_.noop);
11737 * // => true
11738 *
11739 * _.isObject(null);
11740 * // => false
11741 */
11742 function isObject(value) {
11743 var type = typeof value;
11744 return value != null && (type == 'object' || type == 'function');
11745 }
11746
11747 /**
11748 * Checks if `value` is object-like. A value is object-like if it's not `null`
11749 * and has a `typeof` result of "object".
11750 *
11751 * @static
11752 * @memberOf _
11753 * @since 4.0.0
11754 * @category Lang
11755 * @param {*} value The value to check.
11756 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11757 * @example
11758 *
11759 * _.isObjectLike({});
11760 * // => true
11761 *
11762 * _.isObjectLike([1, 2, 3]);
11763 * // => true
11764 *
11765 * _.isObjectLike(_.noop);
11766 * // => false
11767 *
11768 * _.isObjectLike(null);
11769 * // => false
11770 */
11771 function isObjectLike(value) {
11772 return value != null && typeof value == 'object';
11773 }
11774
11775 /**
11776 * Checks if `value` is classified as a `Map` object.
11777 *
11778 * @static
11779 * @memberOf _
11780 * @since 4.3.0
11781 * @category Lang
11782 * @param {*} value The value to check.
11783 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
11784 * @example
11785 *
11786 * _.isMap(new Map);
11787 * // => true
11788 *
11789 * _.isMap(new WeakMap);
11790 * // => false
11791 */
11792 var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
11793
11794 /**
11795 * Performs a partial deep comparison between `object` and `source` to
11796 * determine if `object` contains equivalent property values.
11797 *
11798 * **Note:** This method is equivalent to `_.matches` when `source` is
11799 * partially applied.
11800 *
11801 * Partial comparisons will match empty array and empty object `source`
11802 * values against any array or object value, respectively. See `_.isEqual`
11803 * for a list of supported value comparisons.
11804 *
11805 * @static
11806 * @memberOf _
11807 * @since 3.0.0
11808 * @category Lang
11809 * @param {Object} object The object to inspect.
11810 * @param {Object} source The object of property values to match.
11811 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11812 * @example
11813 *
11814 * var object = { 'a': 1, 'b': 2 };
11815 *
11816 * _.isMatch(object, { 'b': 2 });
11817 * // => true
11818 *
11819 * _.isMatch(object, { 'b': 1 });
11820 * // => false
11821 */
11822 function isMatch(object, source) {
11823 return object === source || baseIsMatch(object, source, getMatchData(source));
11824 }
11825
11826 /**
11827 * This method is like `_.isMatch` except that it accepts `customizer` which
11828 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11829 * are handled by the method instead. The `customizer` is invoked with five
11830 * arguments: (objValue, srcValue, index|key, object, source).
11831 *
11832 * @static
11833 * @memberOf _
11834 * @since 4.0.0
11835 * @category Lang
11836 * @param {Object} object The object to inspect.
11837 * @param {Object} source The object of property values to match.
11838 * @param {Function} [customizer] The function to customize comparisons.
11839 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11840 * @example
11841 *
11842 * function isGreeting(value) {
11843 * return /^h(?:i|ello)$/.test(value);
11844 * }
11845 *
11846 * function customizer(objValue, srcValue) {
11847 * if (isGreeting(objValue) && isGreeting(srcValue)) {
11848 * return true;
11849 * }
11850 * }
11851 *
11852 * var object = { 'greeting': 'hello' };
11853 * var source = { 'greeting': 'hi' };
11854 *
11855 * _.isMatchWith(object, source, customizer);
11856 * // => true
11857 */
11858 function isMatchWith(object, source, customizer) {
11859 customizer = typeof customizer == 'function' ? customizer : undefined;
11860 return baseIsMatch(object, source, getMatchData(source), customizer);
11861 }
11862
11863 /**
11864 * Checks if `value` is `NaN`.
11865 *
11866 * **Note:** This method is based on
11867 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
11868 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
11869 * `undefined` and other non-number values.
11870 *
11871 * @static
11872 * @memberOf _
11873 * @since 0.1.0
11874 * @category Lang
11875 * @param {*} value The value to check.
11876 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
11877 * @example
11878 *
11879 * _.isNaN(NaN);
11880 * // => true
11881 *
11882 * _.isNaN(new Number(NaN));
11883 * // => true
11884 *
11885 * isNaN(undefined);
11886 * // => true
11887 *
11888 * _.isNaN(undefined);
11889 * // => false
11890 */
11891 function isNaN(value) {
11892 // An `NaN` primitive is the only value that is not equal to itself.
11893 // Perform the `toStringTag` check first to avoid errors with some
11894 // ActiveX objects in IE.
11895 return isNumber(value) && value != +value;
11896 }
11897
11898 /**
11899 * Checks if `value` is a pristine native function.
11900 *
11901 * **Note:** This method can't reliably detect native functions in the presence
11902 * of the core-js package because core-js circumvents this kind of detection.
11903 * Despite multiple requests, the core-js maintainer has made it clear: any
11904 * attempt to fix the detection will be obstructed. As a result, we're left
11905 * with little choice but to throw an error. Unfortunately, this also affects
11906 * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
11907 * which rely on core-js.
11908 *
11909 * @static
11910 * @memberOf _
11911 * @since 3.0.0
11912 * @category Lang
11913 * @param {*} value The value to check.
11914 * @returns {boolean} Returns `true` if `value` is a native function,
11915 * else `false`.
11916 * @example
11917 *
11918 * _.isNative(Array.prototype.push);
11919 * // => true
11920 *
11921 * _.isNative(_);
11922 * // => false
11923 */
11924 function isNative(value) {
11925 if (isMaskable(value)) {
11926 throw new Error(CORE_ERROR_TEXT);
11927 }
11928 return baseIsNative(value);
11929 }
11930
11931 /**
11932 * Checks if `value` is `null`.
11933 *
11934 * @static
11935 * @memberOf _
11936 * @since 0.1.0
11937 * @category Lang
11938 * @param {*} value The value to check.
11939 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
11940 * @example
11941 *
11942 * _.isNull(null);
11943 * // => true
11944 *
11945 * _.isNull(void 0);
11946 * // => false
11947 */
11948 function isNull(value) {
11949 return value === null;
11950 }
11951
11952 /**
11953 * Checks if `value` is `null` or `undefined`.
11954 *
11955 * @static
11956 * @memberOf _
11957 * @since 4.0.0
11958 * @category Lang
11959 * @param {*} value The value to check.
11960 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
11961 * @example
11962 *
11963 * _.isNil(null);
11964 * // => true
11965 *
11966 * _.isNil(void 0);
11967 * // => true
11968 *
11969 * _.isNil(NaN);
11970 * // => false
11971 */
11972 function isNil(value) {
11973 return value == null;
11974 }
11975
11976 /**
11977 * Checks if `value` is classified as a `Number` primitive or object.
11978 *
11979 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
11980 * classified as numbers, use the `_.isFinite` method.
11981 *
11982 * @static
11983 * @memberOf _
11984 * @since 0.1.0
11985 * @category Lang
11986 * @param {*} value The value to check.
11987 * @returns {boolean} Returns `true` if `value` is a number, else `false`.
11988 * @example
11989 *
11990 * _.isNumber(3);
11991 * // => true
11992 *
11993 * _.isNumber(Number.MIN_VALUE);
11994 * // => true
11995 *
11996 * _.isNumber(Infinity);
11997 * // => true
11998 *
11999 * _.isNumber('3');
12000 * // => false
12001 */
12002 function isNumber(value) {
12003 return typeof value == 'number' ||
12004 (isObjectLike(value) && baseGetTag(value) == numberTag);
12005 }
12006
12007 /**
12008 * Checks if `value` is a plain object, that is, an object created by the
12009 * `Object` constructor or one with a `[[Prototype]]` of `null`.
12010 *
12011 * @static
12012 * @memberOf _
12013 * @since 0.8.0
12014 * @category Lang
12015 * @param {*} value The value to check.
12016 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12017 * @example
12018 *
12019 * function Foo() {
12020 * this.a = 1;
12021 * }
12022 *
12023 * _.isPlainObject(new Foo);
12024 * // => false
12025 *
12026 * _.isPlainObject([1, 2, 3]);
12027 * // => false
12028 *
12029 * _.isPlainObject({ 'x': 0, 'y': 0 });
12030 * // => true
12031 *
12032 * _.isPlainObject(Object.create(null));
12033 * // => true
12034 */
12035 function isPlainObject(value) {
12036 if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
12037 return false;
12038 }
12039 var proto = getPrototype(value);
12040 if (proto === null) {
12041 return true;
12042 }
12043 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
12044 return typeof Ctor == 'function' && Ctor instanceof Ctor &&
12045 funcToString.call(Ctor) == objectCtorString;
12046 }
12047
12048 /**
12049 * Checks if `value` is classified as a `RegExp` object.
12050 *
12051 * @static
12052 * @memberOf _
12053 * @since 0.1.0
12054 * @category Lang
12055 * @param {*} value The value to check.
12056 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
12057 * @example
12058 *
12059 * _.isRegExp(/abc/);
12060 * // => true
12061 *
12062 * _.isRegExp('/abc/');
12063 * // => false
12064 */
12065 var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
12066
12067 /**
12068 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
12069 * double precision number which isn't the result of a rounded unsafe integer.
12070 *
12071 * **Note:** This method is based on
12072 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
12073 *
12074 * @static
12075 * @memberOf _
12076 * @since 4.0.0
12077 * @category Lang
12078 * @param {*} value The value to check.
12079 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
12080 * @example
12081 *
12082 * _.isSafeInteger(3);
12083 * // => true
12084 *
12085 * _.isSafeInteger(Number.MIN_VALUE);
12086 * // => false
12087 *
12088 * _.isSafeInteger(Infinity);
12089 * // => false
12090 *
12091 * _.isSafeInteger('3');
12092 * // => false
12093 */
12094 function isSafeInteger(value) {
12095 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
12096 }
12097
12098 /**
12099 * Checks if `value` is classified as a `Set` object.
12100 *
12101 * @static
12102 * @memberOf _
12103 * @since 4.3.0
12104 * @category Lang
12105 * @param {*} value The value to check.
12106 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
12107 * @example
12108 *
12109 * _.isSet(new Set);
12110 * // => true
12111 *
12112 * _.isSet(new WeakSet);
12113 * // => false
12114 */
12115 var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
12116
12117 /**
12118 * Checks if `value` is classified as a `String` primitive or object.
12119 *
12120 * @static
12121 * @since 0.1.0
12122 * @memberOf _
12123 * @category Lang
12124 * @param {*} value The value to check.
12125 * @returns {boolean} Returns `true` if `value` is a string, else `false`.
12126 * @example
12127 *
12128 * _.isString('abc');
12129 * // => true
12130 *
12131 * _.isString(1);
12132 * // => false
12133 */
12134 function isString(value) {
12135 return typeof value == 'string' ||
12136 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
12137 }
12138
12139 /**
12140 * Checks if `value` is classified as a `Symbol` primitive or object.
12141 *
12142 * @static
12143 * @memberOf _
12144 * @since 4.0.0
12145 * @category Lang
12146 * @param {*} value The value to check.
12147 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
12148 * @example
12149 *
12150 * _.isSymbol(Symbol.iterator);
12151 * // => true
12152 *
12153 * _.isSymbol('abc');
12154 * // => false
12155 */
12156 function isSymbol(value) {
12157 return typeof value == 'symbol' ||
12158 (isObjectLike(value) && baseGetTag(value) == symbolTag);
12159 }
12160
12161 /**
12162 * Checks if `value` is classified as a typed array.
12163 *
12164 * @static
12165 * @memberOf _
12166 * @since 3.0.0
12167 * @category Lang
12168 * @param {*} value The value to check.
12169 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
12170 * @example
12171 *
12172 * _.isTypedArray(new Uint8Array);
12173 * // => true
12174 *
12175 * _.isTypedArray([]);
12176 * // => false
12177 */
12178 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
12179
12180 /**
12181 * Checks if `value` is `undefined`.
12182 *
12183 * @static
12184 * @since 0.1.0
12185 * @memberOf _
12186 * @category Lang
12187 * @param {*} value The value to check.
12188 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
12189 * @example
12190 *
12191 * _.isUndefined(void 0);
12192 * // => true
12193 *
12194 * _.isUndefined(null);
12195 * // => false
12196 */
12197 function isUndefined(value) {
12198 return value === undefined;
12199 }
12200
12201 /**
12202 * Checks if `value` is classified as a `WeakMap` object.
12203 *
12204 * @static
12205 * @memberOf _
12206 * @since 4.3.0
12207 * @category Lang
12208 * @param {*} value The value to check.
12209 * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
12210 * @example
12211 *
12212 * _.isWeakMap(new WeakMap);
12213 * // => true
12214 *
12215 * _.isWeakMap(new Map);
12216 * // => false
12217 */
12218 function isWeakMap(value) {
12219 return isObjectLike(value) && getTag(value) == weakMapTag;
12220 }
12221
12222 /**
12223 * Checks if `value` is classified as a `WeakSet` object.
12224 *
12225 * @static
12226 * @memberOf _
12227 * @since 4.3.0
12228 * @category Lang
12229 * @param {*} value The value to check.
12230 * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
12231 * @example
12232 *
12233 * _.isWeakSet(new WeakSet);
12234 * // => true
12235 *
12236 * _.isWeakSet(new Set);
12237 * // => false
12238 */
12239 function isWeakSet(value) {
12240 return isObjectLike(value) && baseGetTag(value) == weakSetTag;
12241 }
12242
12243 /**
12244 * Checks if `value` is less than `other`.
12245 *
12246 * @static
12247 * @memberOf _
12248 * @since 3.9.0
12249 * @category Lang
12250 * @param {*} value The value to compare.
12251 * @param {*} other The other value to compare.
12252 * @returns {boolean} Returns `true` if `value` is less than `other`,
12253 * else `false`.
12254 * @see _.gt
12255 * @example
12256 *
12257 * _.lt(1, 3);
12258 * // => true
12259 *
12260 * _.lt(3, 3);
12261 * // => false
12262 *
12263 * _.lt(3, 1);
12264 * // => false
12265 */
12266 var lt = createRelationalOperation(baseLt);
12267
12268 /**
12269 * Checks if `value` is less than or equal to `other`.
12270 *
12271 * @static
12272 * @memberOf _
12273 * @since 3.9.0
12274 * @category Lang
12275 * @param {*} value The value to compare.
12276 * @param {*} other The other value to compare.
12277 * @returns {boolean} Returns `true` if `value` is less than or equal to
12278 * `other`, else `false`.
12279 * @see _.gte
12280 * @example
12281 *
12282 * _.lte(1, 3);
12283 * // => true
12284 *
12285 * _.lte(3, 3);
12286 * // => true
12287 *
12288 * _.lte(3, 1);
12289 * // => false
12290 */
12291 var lte = createRelationalOperation(function(value, other) {
12292 return value <= other;
12293 });
12294
12295 /**
12296 * Converts `value` to an array.
12297 *
12298 * @static
12299 * @since 0.1.0
12300 * @memberOf _
12301 * @category Lang
12302 * @param {*} value The value to convert.
12303 * @returns {Array} Returns the converted array.
12304 * @example
12305 *
12306 * _.toArray({ 'a': 1, 'b': 2 });
12307 * // => [1, 2]
12308 *
12309 * _.toArray('abc');
12310 * // => ['a', 'b', 'c']
12311 *
12312 * _.toArray(1);
12313 * // => []
12314 *
12315 * _.toArray(null);
12316 * // => []
12317 */
12318 function toArray(value) {
12319 if (!value) {
12320 return [];
12321 }
12322 if (isArrayLike(value)) {
12323 return isString(value) ? stringToArray(value) : copyArray(value);
12324 }
12325 if (symIterator && value[symIterator]) {
12326 return iteratorToArray(value[symIterator]());
12327 }
12328 var tag = getTag(value),
12329 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
12330
12331 return func(value);
12332 }
12333
12334 /**
12335 * Converts `value` to a finite number.
12336 *
12337 * @static
12338 * @memberOf _
12339 * @since 4.12.0
12340 * @category Lang
12341 * @param {*} value The value to convert.
12342 * @returns {number} Returns the converted number.
12343 * @example
12344 *
12345 * _.toFinite(3.2);
12346 * // => 3.2
12347 *
12348 * _.toFinite(Number.MIN_VALUE);
12349 * // => 5e-324
12350 *
12351 * _.toFinite(Infinity);
12352 * // => 1.7976931348623157e+308
12353 *
12354 * _.toFinite('3.2');
12355 * // => 3.2
12356 */
12357 function toFinite(value) {
12358 if (!value) {
12359 return value === 0 ? value : 0;
12360 }
12361 value = toNumber(value);
12362 if (value === INFINITY || value === -INFINITY) {
12363 var sign = (value < 0 ? -1 : 1);
12364 return sign * MAX_INTEGER;
12365 }
12366 return value === value ? value : 0;
12367 }
12368
12369 /**
12370 * Converts `value` to an integer.
12371 *
12372 * **Note:** This method is loosely based on
12373 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
12374 *
12375 * @static
12376 * @memberOf _
12377 * @since 4.0.0
12378 * @category Lang
12379 * @param {*} value The value to convert.
12380 * @returns {number} Returns the converted integer.
12381 * @example
12382 *
12383 * _.toInteger(3.2);
12384 * // => 3
12385 *
12386 * _.toInteger(Number.MIN_VALUE);
12387 * // => 0
12388 *
12389 * _.toInteger(Infinity);
12390 * // => 1.7976931348623157e+308
12391 *
12392 * _.toInteger('3.2');
12393 * // => 3
12394 */
12395 function toInteger(value) {
12396 var result = toFinite(value),
12397 remainder = result % 1;
12398
12399 return result === result ? (remainder ? result - remainder : result) : 0;
12400 }
12401
12402 /**
12403 * Converts `value` to an integer suitable for use as the length of an
12404 * array-like object.
12405 *
12406 * **Note:** This method is based on
12407 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
12408 *
12409 * @static
12410 * @memberOf _
12411 * @since 4.0.0
12412 * @category Lang
12413 * @param {*} value The value to convert.
12414 * @returns {number} Returns the converted integer.
12415 * @example
12416 *
12417 * _.toLength(3.2);
12418 * // => 3
12419 *
12420 * _.toLength(Number.MIN_VALUE);
12421 * // => 0
12422 *
12423 * _.toLength(Infinity);
12424 * // => 4294967295
12425 *
12426 * _.toLength('3.2');
12427 * // => 3
12428 */
12429 function toLength(value) {
12430 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
12431 }
12432
12433 /**
12434 * Converts `value` to a number.
12435 *
12436 * @static
12437 * @memberOf _
12438 * @since 4.0.0
12439 * @category Lang
12440 * @param {*} value The value to process.
12441 * @returns {number} Returns the number.
12442 * @example
12443 *
12444 * _.toNumber(3.2);
12445 * // => 3.2
12446 *
12447 * _.toNumber(Number.MIN_VALUE);
12448 * // => 5e-324
12449 *
12450 * _.toNumber(Infinity);
12451 * // => Infinity
12452 *
12453 * _.toNumber('3.2');
12454 * // => 3.2
12455 */
12456 function toNumber(value) {
12457 if (typeof value == 'number') {
12458 return value;
12459 }
12460 if (isSymbol(value)) {
12461 return NAN;
12462 }
12463 if (isObject(value)) {
12464 var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
12465 value = isObject(other) ? (other + '') : other;
12466 }
12467 if (typeof value != 'string') {
12468 return value === 0 ? value : +value;
12469 }
12470 value = value.replace(reTrim, '');
12471 var isBinary = reIsBinary.test(value);
12472 return (isBinary || reIsOctal.test(value))
12473 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
12474 : (reIsBadHex.test(value) ? NAN : +value);
12475 }
12476
12477 /**
12478 * Converts `value` to a plain object flattening inherited enumerable string
12479 * keyed properties of `value` to own properties of the plain object.
12480 *
12481 * @static
12482 * @memberOf _
12483 * @since 3.0.0
12484 * @category Lang
12485 * @param {*} value The value to convert.
12486 * @returns {Object} Returns the converted plain object.
12487 * @example
12488 *
12489 * function Foo() {
12490 * this.b = 2;
12491 * }
12492 *
12493 * Foo.prototype.c = 3;
12494 *
12495 * _.assign({ 'a': 1 }, new Foo);
12496 * // => { 'a': 1, 'b': 2 }
12497 *
12498 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
12499 * // => { 'a': 1, 'b': 2, 'c': 3 }
12500 */
12501 function toPlainObject(value) {
12502 return copyObject(value, keysIn(value));
12503 }
12504
12505 /**
12506 * Converts `value` to a safe integer. A safe integer can be compared and
12507 * represented correctly.
12508 *
12509 * @static
12510 * @memberOf _
12511 * @since 4.0.0
12512 * @category Lang
12513 * @param {*} value The value to convert.
12514 * @returns {number} Returns the converted integer.
12515 * @example
12516 *
12517 * _.toSafeInteger(3.2);
12518 * // => 3
12519 *
12520 * _.toSafeInteger(Number.MIN_VALUE);
12521 * // => 0
12522 *
12523 * _.toSafeInteger(Infinity);
12524 * // => 9007199254740991
12525 *
12526 * _.toSafeInteger('3.2');
12527 * // => 3
12528 */
12529 function toSafeInteger(value) {
12530 return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
12531 }
12532
12533 /**
12534 * Converts `value` to a string. An empty string is returned for `null`
12535 * and `undefined` values. The sign of `-0` is preserved.
12536 *
12537 * @static
12538 * @memberOf _
12539 * @since 4.0.0
12540 * @category Lang
12541 * @param {*} value The value to convert.
12542 * @returns {string} Returns the converted string.
12543 * @example
12544 *
12545 * _.toString(null);
12546 * // => ''
12547 *
12548 * _.toString(-0);
12549 * // => '-0'
12550 *
12551 * _.toString([1, 2, 3]);
12552 * // => '1,2,3'
12553 */
12554 function toString(value) {
12555 return value == null ? '' : baseToString(value);
12556 }
12557
12558 /*------------------------------------------------------------------------*/
12559
12560 /**
12561 * Assigns own enumerable string keyed properties of source objects to the
12562 * destination object. Source objects are applied from left to right.
12563 * Subsequent sources overwrite property assignments of previous sources.
12564 *
12565 * **Note:** This method mutates `object` and is loosely based on
12566 * [`Object.assign`](https://mdn.io/Object/assign).
12567 *
12568 * @static
12569 * @memberOf _
12570 * @since 0.10.0
12571 * @category Object
12572 * @param {Object} object The destination object.
12573 * @param {...Object} [sources] The source objects.
12574 * @returns {Object} Returns `object`.
12575 * @see _.assignIn
12576 * @example
12577 *
12578 * function Foo() {
12579 * this.a = 1;
12580 * }
12581 *
12582 * function Bar() {
12583 * this.c = 3;
12584 * }
12585 *
12586 * Foo.prototype.b = 2;
12587 * Bar.prototype.d = 4;
12588 *
12589 * _.assign({ 'a': 0 }, new Foo, new Bar);
12590 * // => { 'a': 1, 'c': 3 }
12591 */
12592 var assign = createAssigner(function(object, source) {
12593 if (isPrototype(source) || isArrayLike(source)) {
12594 copyObject(source, keys(source), object);
12595 return;
12596 }
12597 for (var key in source) {
12598 if (hasOwnProperty.call(source, key)) {
12599 assignValue(object, key, source[key]);
12600 }
12601 }
12602 });
12603
12604 /**
12605 * This method is like `_.assign` except that it iterates over own and
12606 * inherited source properties.
12607 *
12608 * **Note:** This method mutates `object`.
12609 *
12610 * @static
12611 * @memberOf _
12612 * @since 4.0.0
12613 * @alias extend
12614 * @category Object
12615 * @param {Object} object The destination object.
12616 * @param {...Object} [sources] The source objects.
12617 * @returns {Object} Returns `object`.
12618 * @see _.assign
12619 * @example
12620 *
12621 * function Foo() {
12622 * this.a = 1;
12623 * }
12624 *
12625 * function Bar() {
12626 * this.c = 3;
12627 * }
12628 *
12629 * Foo.prototype.b = 2;
12630 * Bar.prototype.d = 4;
12631 *
12632 * _.assignIn({ 'a': 0 }, new Foo, new Bar);
12633 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
12634 */
12635 var assignIn = createAssigner(function(object, source) {
12636 copyObject(source, keysIn(source), object);
12637 });
12638
12639 /**
12640 * This method is like `_.assignIn` except that it accepts `customizer`
12641 * which is invoked to produce the assigned values. If `customizer` returns
12642 * `undefined`, assignment is handled by the method instead. The `customizer`
12643 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12644 *
12645 * **Note:** This method mutates `object`.
12646 *
12647 * @static
12648 * @memberOf _
12649 * @since 4.0.0
12650 * @alias extendWith
12651 * @category Object
12652 * @param {Object} object The destination object.
12653 * @param {...Object} sources The source objects.
12654 * @param {Function} [customizer] The function to customize assigned values.
12655 * @returns {Object} Returns `object`.
12656 * @see _.assignWith
12657 * @example
12658 *
12659 * function customizer(objValue, srcValue) {
12660 * return _.isUndefined(objValue) ? srcValue : objValue;
12661 * }
12662 *
12663 * var defaults = _.partialRight(_.assignInWith, customizer);
12664 *
12665 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12666 * // => { 'a': 1, 'b': 2 }
12667 */
12668 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
12669 copyObject(source, keysIn(source), object, customizer);
12670 });
12671
12672 /**
12673 * This method is like `_.assign` except that it accepts `customizer`
12674 * which is invoked to produce the assigned values. If `customizer` returns
12675 * `undefined`, assignment is handled by the method instead. The `customizer`
12676 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12677 *
12678 * **Note:** This method mutates `object`.
12679 *
12680 * @static
12681 * @memberOf _
12682 * @since 4.0.0
12683 * @category Object
12684 * @param {Object} object The destination object.
12685 * @param {...Object} sources The source objects.
12686 * @param {Function} [customizer] The function to customize assigned values.
12687 * @returns {Object} Returns `object`.
12688 * @see _.assignInWith
12689 * @example
12690 *
12691 * function customizer(objValue, srcValue) {
12692 * return _.isUndefined(objValue) ? srcValue : objValue;
12693 * }
12694 *
12695 * var defaults = _.partialRight(_.assignWith, customizer);
12696 *
12697 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12698 * // => { 'a': 1, 'b': 2 }
12699 */
12700 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
12701 copyObject(source, keys(source), object, customizer);
12702 });
12703
12704 /**
12705 * Creates an array of values corresponding to `paths` of `object`.
12706 *
12707 * @static
12708 * @memberOf _
12709 * @since 1.0.0
12710 * @category Object
12711 * @param {Object} object The object to iterate over.
12712 * @param {...(string|string[])} [paths] The property paths to pick.
12713 * @returns {Array} Returns the picked values.
12714 * @example
12715 *
12716 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
12717 *
12718 * _.at(object, ['a[0].b.c', 'a[1]']);
12719 * // => [3, 4]
12720 */
12721 var at = flatRest(baseAt);
12722
12723 /**
12724 * Creates an object that inherits from the `prototype` object. If a
12725 * `properties` object is given, its own enumerable string keyed properties
12726 * are assigned to the created object.
12727 *
12728 * @static
12729 * @memberOf _
12730 * @since 2.3.0
12731 * @category Object
12732 * @param {Object} prototype The object to inherit from.
12733 * @param {Object} [properties] The properties to assign to the object.
12734 * @returns {Object} Returns the new object.
12735 * @example
12736 *
12737 * function Shape() {
12738 * this.x = 0;
12739 * this.y = 0;
12740 * }
12741 *
12742 * function Circle() {
12743 * Shape.call(this);
12744 * }
12745 *
12746 * Circle.prototype = _.create(Shape.prototype, {
12747 * 'constructor': Circle
12748 * });
12749 *
12750 * var circle = new Circle;
12751 * circle instanceof Circle;
12752 * // => true
12753 *
12754 * circle instanceof Shape;
12755 * // => true
12756 */
12757 function create(prototype, properties) {
12758 var result = baseCreate(prototype);
12759 return properties == null ? result : baseAssign(result, properties);
12760 }
12761
12762 /**
12763 * Assigns own and inherited enumerable string keyed properties of source
12764 * objects to the destination object for all destination properties that
12765 * resolve to `undefined`. Source objects are applied from left to right.
12766 * Once a property is set, additional values of the same property are ignored.
12767 *
12768 * **Note:** This method mutates `object`.
12769 *
12770 * @static
12771 * @since 0.1.0
12772 * @memberOf _
12773 * @category Object
12774 * @param {Object} object The destination object.
12775 * @param {...Object} [sources] The source objects.
12776 * @returns {Object} Returns `object`.
12777 * @see _.defaultsDeep
12778 * @example
12779 *
12780 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12781 * // => { 'a': 1, 'b': 2 }
12782 */
12783 var defaults = baseRest(function(args) {
12784 args.push(undefined, assignInDefaults);
12785 return apply(assignInWith, undefined, args);
12786 });
12787
12788 /**
12789 * This method is like `_.defaults` except that it recursively assigns
12790 * default properties.
12791 *
12792 * **Note:** This method mutates `object`.
12793 *
12794 * @static
12795 * @memberOf _
12796 * @since 3.10.0
12797 * @category Object
12798 * @param {Object} object The destination object.
12799 * @param {...Object} [sources] The source objects.
12800 * @returns {Object} Returns `object`.
12801 * @see _.defaults
12802 * @example
12803 *
12804 * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
12805 * // => { 'a': { 'b': 2, 'c': 3 } }
12806 */
12807 var defaultsDeep = baseRest(function(args) {
12808 args.push(undefined, mergeDefaults);
12809 return apply(mergeWith, undefined, args);
12810 });
12811
12812 /**
12813 * This method is like `_.find` except that it returns the key of the first
12814 * element `predicate` returns truthy for instead of the element itself.
12815 *
12816 * @static
12817 * @memberOf _
12818 * @since 1.1.0
12819 * @category Object
12820 * @param {Object} object The object to inspect.
12821 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12822 * @returns {string|undefined} Returns the key of the matched element,
12823 * else `undefined`.
12824 * @example
12825 *
12826 * var users = {
12827 * 'barney': { 'age': 36, 'active': true },
12828 * 'fred': { 'age': 40, 'active': false },
12829 * 'pebbles': { 'age': 1, 'active': true }
12830 * };
12831 *
12832 * _.findKey(users, function(o) { return o.age < 40; });
12833 * // => 'barney' (iteration order is not guaranteed)
12834 *
12835 * // The `_.matches` iteratee shorthand.
12836 * _.findKey(users, { 'age': 1, 'active': true });
12837 * // => 'pebbles'
12838 *
12839 * // The `_.matchesProperty` iteratee shorthand.
12840 * _.findKey(users, ['active', false]);
12841 * // => 'fred'
12842 *
12843 * // The `_.property` iteratee shorthand.
12844 * _.findKey(users, 'active');
12845 * // => 'barney'
12846 */
12847 function findKey(object, predicate) {
12848 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
12849 }
12850
12851 /**
12852 * This method is like `_.findKey` except that it iterates over elements of
12853 * a collection in the opposite order.
12854 *
12855 * @static
12856 * @memberOf _
12857 * @since 2.0.0
12858 * @category Object
12859 * @param {Object} object The object to inspect.
12860 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12861 * @returns {string|undefined} Returns the key of the matched element,
12862 * else `undefined`.
12863 * @example
12864 *
12865 * var users = {
12866 * 'barney': { 'age': 36, 'active': true },
12867 * 'fred': { 'age': 40, 'active': false },
12868 * 'pebbles': { 'age': 1, 'active': true }
12869 * };
12870 *
12871 * _.findLastKey(users, function(o) { return o.age < 40; });
12872 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
12873 *
12874 * // The `_.matches` iteratee shorthand.
12875 * _.findLastKey(users, { 'age': 36, 'active': true });
12876 * // => 'barney'
12877 *
12878 * // The `_.matchesProperty` iteratee shorthand.
12879 * _.findLastKey(users, ['active', false]);
12880 * // => 'fred'
12881 *
12882 * // The `_.property` iteratee shorthand.
12883 * _.findLastKey(users, 'active');
12884 * // => 'pebbles'
12885 */
12886 function findLastKey(object, predicate) {
12887 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
12888 }
12889
12890 /**
12891 * Iterates over own and inherited enumerable string keyed properties of an
12892 * object and invokes `iteratee` for each property. The iteratee is invoked
12893 * with three arguments: (value, key, object). Iteratee functions may exit
12894 * iteration early by explicitly returning `false`.
12895 *
12896 * @static
12897 * @memberOf _
12898 * @since 0.3.0
12899 * @category Object
12900 * @param {Object} object The object to iterate over.
12901 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12902 * @returns {Object} Returns `object`.
12903 * @see _.forInRight
12904 * @example
12905 *
12906 * function Foo() {
12907 * this.a = 1;
12908 * this.b = 2;
12909 * }
12910 *
12911 * Foo.prototype.c = 3;
12912 *
12913 * _.forIn(new Foo, function(value, key) {
12914 * console.log(key);
12915 * });
12916 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
12917 */
12918 function forIn(object, iteratee) {
12919 return object == null
12920 ? object
12921 : baseFor(object, getIteratee(iteratee, 3), keysIn);
12922 }
12923
12924 /**
12925 * This method is like `_.forIn` except that it iterates over properties of
12926 * `object` in the opposite order.
12927 *
12928 * @static
12929 * @memberOf _
12930 * @since 2.0.0
12931 * @category Object
12932 * @param {Object} object The object to iterate over.
12933 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12934 * @returns {Object} Returns `object`.
12935 * @see _.forIn
12936 * @example
12937 *
12938 * function Foo() {
12939 * this.a = 1;
12940 * this.b = 2;
12941 * }
12942 *
12943 * Foo.prototype.c = 3;
12944 *
12945 * _.forInRight(new Foo, function(value, key) {
12946 * console.log(key);
12947 * });
12948 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
12949 */
12950 function forInRight(object, iteratee) {
12951 return object == null
12952 ? object
12953 : baseForRight(object, getIteratee(iteratee, 3), keysIn);
12954 }
12955
12956 /**
12957 * Iterates over own enumerable string keyed properties of an object and
12958 * invokes `iteratee` for each property. The iteratee is invoked with three
12959 * arguments: (value, key, object). Iteratee functions may exit iteration
12960 * early by explicitly returning `false`.
12961 *
12962 * @static
12963 * @memberOf _
12964 * @since 0.3.0
12965 * @category Object
12966 * @param {Object} object The object to iterate over.
12967 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12968 * @returns {Object} Returns `object`.
12969 * @see _.forOwnRight
12970 * @example
12971 *
12972 * function Foo() {
12973 * this.a = 1;
12974 * this.b = 2;
12975 * }
12976 *
12977 * Foo.prototype.c = 3;
12978 *
12979 * _.forOwn(new Foo, function(value, key) {
12980 * console.log(key);
12981 * });
12982 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
12983 */
12984 function forOwn(object, iteratee) {
12985 return object && baseForOwn(object, getIteratee(iteratee, 3));
12986 }
12987
12988 /**
12989 * This method is like `_.forOwn` except that it iterates over properties of
12990 * `object` in the opposite order.
12991 *
12992 * @static
12993 * @memberOf _
12994 * @since 2.0.0
12995 * @category Object
12996 * @param {Object} object The object to iterate over.
12997 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12998 * @returns {Object} Returns `object`.
12999 * @see _.forOwn
13000 * @example
13001 *
13002 * function Foo() {
13003 * this.a = 1;
13004 * this.b = 2;
13005 * }
13006 *
13007 * Foo.prototype.c = 3;
13008 *
13009 * _.forOwnRight(new Foo, function(value, key) {
13010 * console.log(key);
13011 * });
13012 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
13013 */
13014 function forOwnRight(object, iteratee) {
13015 return object && baseForOwnRight(object, getIteratee(iteratee, 3));
13016 }
13017
13018 /**
13019 * Creates an array of function property names from own enumerable properties
13020 * of `object`.
13021 *
13022 * @static
13023 * @since 0.1.0
13024 * @memberOf _
13025 * @category Object
13026 * @param {Object} object The object to inspect.
13027 * @returns {Array} Returns the function names.
13028 * @see _.functionsIn
13029 * @example
13030 *
13031 * function Foo() {
13032 * this.a = _.constant('a');
13033 * this.b = _.constant('b');
13034 * }
13035 *
13036 * Foo.prototype.c = _.constant('c');
13037 *
13038 * _.functions(new Foo);
13039 * // => ['a', 'b']
13040 */
13041 function functions(object) {
13042 return object == null ? [] : baseFunctions(object, keys(object));
13043 }
13044
13045 /**
13046 * Creates an array of function property names from own and inherited
13047 * enumerable properties of `object`.
13048 *
13049 * @static
13050 * @memberOf _
13051 * @since 4.0.0
13052 * @category Object
13053 * @param {Object} object The object to inspect.
13054 * @returns {Array} Returns the function names.
13055 * @see _.functions
13056 * @example
13057 *
13058 * function Foo() {
13059 * this.a = _.constant('a');
13060 * this.b = _.constant('b');
13061 * }
13062 *
13063 * Foo.prototype.c = _.constant('c');
13064 *
13065 * _.functionsIn(new Foo);
13066 * // => ['a', 'b', 'c']
13067 */
13068 function functionsIn(object) {
13069 return object == null ? [] : baseFunctions(object, keysIn(object));
13070 }
13071
13072 /**
13073 * Gets the value at `path` of `object`. If the resolved value is
13074 * `undefined`, the `defaultValue` is returned in its place.
13075 *
13076 * @static
13077 * @memberOf _
13078 * @since 3.7.0
13079 * @category Object
13080 * @param {Object} object The object to query.
13081 * @param {Array|string} path The path of the property to get.
13082 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13083 * @returns {*} Returns the resolved value.
13084 * @example
13085 *
13086 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13087 *
13088 * _.get(object, 'a[0].b.c');
13089 * // => 3
13090 *
13091 * _.get(object, ['a', '0', 'b', 'c']);
13092 * // => 3
13093 *
13094 * _.get(object, 'a.b.c', 'default');
13095 * // => 'default'
13096 */
13097 function get(object, path, defaultValue) {
13098 var result = object == null ? undefined : baseGet(object, path);
13099 return result === undefined ? defaultValue : result;
13100 }
13101
13102 /**
13103 * Checks if `path` is a direct property of `object`.
13104 *
13105 * @static
13106 * @since 0.1.0
13107 * @memberOf _
13108 * @category Object
13109 * @param {Object} object The object to query.
13110 * @param {Array|string} path The path to check.
13111 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13112 * @example
13113 *
13114 * var object = { 'a': { 'b': 2 } };
13115 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
13116 *
13117 * _.has(object, 'a');
13118 * // => true
13119 *
13120 * _.has(object, 'a.b');
13121 * // => true
13122 *
13123 * _.has(object, ['a', 'b']);
13124 * // => true
13125 *
13126 * _.has(other, 'a');
13127 * // => false
13128 */
13129 function has(object, path) {
13130 return object != null && hasPath(object, path, baseHas);
13131 }
13132
13133 /**
13134 * Checks if `path` is a direct or inherited property of `object`.
13135 *
13136 * @static
13137 * @memberOf _
13138 * @since 4.0.0
13139 * @category Object
13140 * @param {Object} object The object to query.
13141 * @param {Array|string} path The path to check.
13142 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13143 * @example
13144 *
13145 * var object = _.create({ 'a': _.create({ 'b': 2 }) });
13146 *
13147 * _.hasIn(object, 'a');
13148 * // => true
13149 *
13150 * _.hasIn(object, 'a.b');
13151 * // => true
13152 *
13153 * _.hasIn(object, ['a', 'b']);
13154 * // => true
13155 *
13156 * _.hasIn(object, 'b');
13157 * // => false
13158 */
13159 function hasIn(object, path) {
13160 return object != null && hasPath(object, path, baseHasIn);
13161 }
13162
13163 /**
13164 * Creates an object composed of the inverted keys and values of `object`.
13165 * If `object` contains duplicate values, subsequent values overwrite
13166 * property assignments of previous values.
13167 *
13168 * @static
13169 * @memberOf _
13170 * @since 0.7.0
13171 * @category Object
13172 * @param {Object} object The object to invert.
13173 * @returns {Object} Returns the new inverted object.
13174 * @example
13175 *
13176 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13177 *
13178 * _.invert(object);
13179 * // => { '1': 'c', '2': 'b' }
13180 */
13181 var invert = createInverter(function(result, value, key) {
13182 result[value] = key;
13183 }, constant(identity));
13184
13185 /**
13186 * This method is like `_.invert` except that the inverted object is generated
13187 * from the results of running each element of `object` thru `iteratee`. The
13188 * corresponding inverted value of each inverted key is an array of keys
13189 * responsible for generating the inverted value. The iteratee is invoked
13190 * with one argument: (value).
13191 *
13192 * @static
13193 * @memberOf _
13194 * @since 4.1.0
13195 * @category Object
13196 * @param {Object} object The object to invert.
13197 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
13198 * @returns {Object} Returns the new inverted object.
13199 * @example
13200 *
13201 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13202 *
13203 * _.invertBy(object);
13204 * // => { '1': ['a', 'c'], '2': ['b'] }
13205 *
13206 * _.invertBy(object, function(value) {
13207 * return 'group' + value;
13208 * });
13209 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
13210 */
13211 var invertBy = createInverter(function(result, value, key) {
13212 if (hasOwnProperty.call(result, value)) {
13213 result[value].push(key);
13214 } else {
13215 result[value] = [key];
13216 }
13217 }, getIteratee);
13218
13219 /**
13220 * Invokes the method at `path` of `object`.
13221 *
13222 * @static
13223 * @memberOf _
13224 * @since 4.0.0
13225 * @category Object
13226 * @param {Object} object The object to query.
13227 * @param {Array|string} path The path of the method to invoke.
13228 * @param {...*} [args] The arguments to invoke the method with.
13229 * @returns {*} Returns the result of the invoked method.
13230 * @example
13231 *
13232 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
13233 *
13234 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
13235 * // => [2, 3]
13236 */
13237 var invoke = baseRest(baseInvoke);
13238
13239 /**
13240 * Creates an array of the own enumerable property names of `object`.
13241 *
13242 * **Note:** Non-object values are coerced to objects. See the
13243 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
13244 * for more details.
13245 *
13246 * @static
13247 * @since 0.1.0
13248 * @memberOf _
13249 * @category Object
13250 * @param {Object} object The object to query.
13251 * @returns {Array} Returns the array of property names.
13252 * @example
13253 *
13254 * function Foo() {
13255 * this.a = 1;
13256 * this.b = 2;
13257 * }
13258 *
13259 * Foo.prototype.c = 3;
13260 *
13261 * _.keys(new Foo);
13262 * // => ['a', 'b'] (iteration order is not guaranteed)
13263 *
13264 * _.keys('hi');
13265 * // => ['0', '1']
13266 */
13267 function keys(object) {
13268 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
13269 }
13270
13271 /**
13272 * Creates an array of the own and inherited enumerable property names of `object`.
13273 *
13274 * **Note:** Non-object values are coerced to objects.
13275 *
13276 * @static
13277 * @memberOf _
13278 * @since 3.0.0
13279 * @category Object
13280 * @param {Object} object The object to query.
13281 * @returns {Array} Returns the array of property names.
13282 * @example
13283 *
13284 * function Foo() {
13285 * this.a = 1;
13286 * this.b = 2;
13287 * }
13288 *
13289 * Foo.prototype.c = 3;
13290 *
13291 * _.keysIn(new Foo);
13292 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
13293 */
13294 function keysIn(object) {
13295 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
13296 }
13297
13298 /**
13299 * The opposite of `_.mapValues`; this method creates an object with the
13300 * same values as `object` and keys generated by running each own enumerable
13301 * string keyed property of `object` thru `iteratee`. The iteratee is invoked
13302 * with three arguments: (value, key, object).
13303 *
13304 * @static
13305 * @memberOf _
13306 * @since 3.8.0
13307 * @category Object
13308 * @param {Object} object The object to iterate over.
13309 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13310 * @returns {Object} Returns the new mapped object.
13311 * @see _.mapValues
13312 * @example
13313 *
13314 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
13315 * return key + value;
13316 * });
13317 * // => { 'a1': 1, 'b2': 2 }
13318 */
13319 function mapKeys(object, iteratee) {
13320 var result = {};
13321 iteratee = getIteratee(iteratee, 3);
13322
13323 baseForOwn(object, function(value, key, object) {
13324 baseAssignValue(result, iteratee(value, key, object), value);
13325 });
13326 return result;
13327 }
13328
13329 /**
13330 * Creates an object with the same keys as `object` and values generated
13331 * by running each own enumerable string keyed property of `object` thru
13332 * `iteratee`. The iteratee is invoked with three arguments:
13333 * (value, key, object).
13334 *
13335 * @static
13336 * @memberOf _
13337 * @since 2.4.0
13338 * @category Object
13339 * @param {Object} object The object to iterate over.
13340 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13341 * @returns {Object} Returns the new mapped object.
13342 * @see _.mapKeys
13343 * @example
13344 *
13345 * var users = {
13346 * 'fred': { 'user': 'fred', 'age': 40 },
13347 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
13348 * };
13349 *
13350 * _.mapValues(users, function(o) { return o.age; });
13351 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13352 *
13353 * // The `_.property` iteratee shorthand.
13354 * _.mapValues(users, 'age');
13355 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13356 */
13357 function mapValues(object, iteratee) {
13358 var result = {};
13359 iteratee = getIteratee(iteratee, 3);
13360
13361 baseForOwn(object, function(value, key, object) {
13362 baseAssignValue(result, key, iteratee(value, key, object));
13363 });
13364 return result;
13365 }
13366
13367 /**
13368 * This method is like `_.assign` except that it recursively merges own and
13369 * inherited enumerable string keyed properties of source objects into the
13370 * destination object. Source properties that resolve to `undefined` are
13371 * skipped if a destination value exists. Array and plain object properties
13372 * are merged recursively. Other objects and value types are overridden by
13373 * assignment. Source objects are applied from left to right. Subsequent
13374 * sources overwrite property assignments of previous sources.
13375 *
13376 * **Note:** This method mutates `object`.
13377 *
13378 * @static
13379 * @memberOf _
13380 * @since 0.5.0
13381 * @category Object
13382 * @param {Object} object The destination object.
13383 * @param {...Object} [sources] The source objects.
13384 * @returns {Object} Returns `object`.
13385 * @example
13386 *
13387 * var object = {
13388 * 'a': [{ 'b': 2 }, { 'd': 4 }]
13389 * };
13390 *
13391 * var other = {
13392 * 'a': [{ 'c': 3 }, { 'e': 5 }]
13393 * };
13394 *
13395 * _.merge(object, other);
13396 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
13397 */
13398 var merge = createAssigner(function(object, source, srcIndex) {
13399 baseMerge(object, source, srcIndex);
13400 });
13401
13402 /**
13403 * This method is like `_.merge` except that it accepts `customizer` which
13404 * is invoked to produce the merged values of the destination and source
13405 * properties. If `customizer` returns `undefined`, merging is handled by the
13406 * method instead. The `customizer` is invoked with six arguments:
13407 * (objValue, srcValue, key, object, source, stack).
13408 *
13409 * **Note:** This method mutates `object`.
13410 *
13411 * @static
13412 * @memberOf _
13413 * @since 4.0.0
13414 * @category Object
13415 * @param {Object} object The destination object.
13416 * @param {...Object} sources The source objects.
13417 * @param {Function} customizer The function to customize assigned values.
13418 * @returns {Object} Returns `object`.
13419 * @example
13420 *
13421 * function customizer(objValue, srcValue) {
13422 * if (_.isArray(objValue)) {
13423 * return objValue.concat(srcValue);
13424 * }
13425 * }
13426 *
13427 * var object = { 'a': [1], 'b': [2] };
13428 * var other = { 'a': [3], 'b': [4] };
13429 *
13430 * _.mergeWith(object, other, customizer);
13431 * // => { 'a': [1, 3], 'b': [2, 4] }
13432 */
13433 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
13434 baseMerge(object, source, srcIndex, customizer);
13435 });
13436
13437 /**
13438 * The opposite of `_.pick`; this method creates an object composed of the
13439 * own and inherited enumerable property paths of `object` that are not omitted.
13440 *
13441 * **Note:** This method is considerably slower than `_.pick`.
13442 *
13443 * @static
13444 * @since 0.1.0
13445 * @memberOf _
13446 * @category Object
13447 * @param {Object} object The source object.
13448 * @param {...(string|string[])} [paths] The property paths to omit.
13449 * @returns {Object} Returns the new object.
13450 * @example
13451 *
13452 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13453 *
13454 * _.omit(object, ['a', 'c']);
13455 * // => { 'b': '2' }
13456 */
13457 var omit = flatRest(function(object, paths) {
13458 var result = {};
13459 if (object == null) {
13460 return result;
13461 }
13462 var isDeep = false;
13463 paths = arrayMap(paths, function(path) {
13464 path = castPath(path, object);
13465 isDeep || (isDeep = path.length > 1);
13466 return path;
13467 });
13468 copyObject(object, getAllKeysIn(object), result);
13469 if (isDeep) {
13470 result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG);
13471 }
13472 var length = paths.length;
13473 while (length--) {
13474 baseUnset(result, paths[length]);
13475 }
13476 return result;
13477 });
13478
13479 /**
13480 * The opposite of `_.pickBy`; this method creates an object composed of
13481 * the own and inherited enumerable string keyed properties of `object` that
13482 * `predicate` doesn't return truthy for. The predicate is invoked with two
13483 * arguments: (value, key).
13484 *
13485 * @static
13486 * @memberOf _
13487 * @since 4.0.0
13488 * @category Object
13489 * @param {Object} object The source object.
13490 * @param {Function} [predicate=_.identity] The function invoked per property.
13491 * @returns {Object} Returns the new object.
13492 * @example
13493 *
13494 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13495 *
13496 * _.omitBy(object, _.isNumber);
13497 * // => { 'b': '2' }
13498 */
13499 function omitBy(object, predicate) {
13500 return pickBy(object, negate(getIteratee(predicate)));
13501 }
13502
13503 /**
13504 * Creates an object composed of the picked `object` properties.
13505 *
13506 * @static
13507 * @since 0.1.0
13508 * @memberOf _
13509 * @category Object
13510 * @param {Object} object The source object.
13511 * @param {...(string|string[])} [paths] The property paths to pick.
13512 * @returns {Object} Returns the new object.
13513 * @example
13514 *
13515 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13516 *
13517 * _.pick(object, ['a', 'c']);
13518 * // => { 'a': 1, 'c': 3 }
13519 */
13520 var pick = flatRest(function(object, paths) {
13521 return object == null ? {} : basePick(object, paths);
13522 });
13523
13524 /**
13525 * Creates an object composed of the `object` properties `predicate` returns
13526 * truthy for. The predicate is invoked with two arguments: (value, key).
13527 *
13528 * @static
13529 * @memberOf _
13530 * @since 4.0.0
13531 * @category Object
13532 * @param {Object} object The source object.
13533 * @param {Function} [predicate=_.identity] The function invoked per property.
13534 * @returns {Object} Returns the new object.
13535 * @example
13536 *
13537 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13538 *
13539 * _.pickBy(object, _.isNumber);
13540 * // => { 'a': 1, 'c': 3 }
13541 */
13542 function pickBy(object, predicate) {
13543 if (object == null) {
13544 return {};
13545 }
13546 var props = arrayMap(getAllKeysIn(object), function(prop) {
13547 return [prop];
13548 });
13549 predicate = getIteratee(predicate);
13550 return basePickBy(object, props, function(value, path) {
13551 return predicate(value, path[0]);
13552 });
13553 }
13554
13555 /**
13556 * This method is like `_.get` except that if the resolved value is a
13557 * function it's invoked with the `this` binding of its parent object and
13558 * its result is returned.
13559 *
13560 * @static
13561 * @since 0.1.0
13562 * @memberOf _
13563 * @category Object
13564 * @param {Object} object The object to query.
13565 * @param {Array|string} path The path of the property to resolve.
13566 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13567 * @returns {*} Returns the resolved value.
13568 * @example
13569 *
13570 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
13571 *
13572 * _.result(object, 'a[0].b.c1');
13573 * // => 3
13574 *
13575 * _.result(object, 'a[0].b.c2');
13576 * // => 4
13577 *
13578 * _.result(object, 'a[0].b.c3', 'default');
13579 * // => 'default'
13580 *
13581 * _.result(object, 'a[0].b.c3', _.constant('default'));
13582 * // => 'default'
13583 */
13584 function result(object, path, defaultValue) {
13585 path = castPath(path, object);
13586
13587 var index = -1,
13588 length = path.length;
13589
13590 // Ensure the loop is entered when path is empty.
13591 if (!length) {
13592 length = 1;
13593 object = undefined;
13594 }
13595 while (++index < length) {
13596 var value = object == null ? undefined : object[toKey(path[index])];
13597 if (value === undefined) {
13598 index = length;
13599 value = defaultValue;
13600 }
13601 object = isFunction(value) ? value.call(object) : value;
13602 }
13603 return object;
13604 }
13605
13606 /**
13607 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
13608 * it's created. Arrays are created for missing index properties while objects
13609 * are created for all other missing properties. Use `_.setWith` to customize
13610 * `path` creation.
13611 *
13612 * **Note:** This method mutates `object`.
13613 *
13614 * @static
13615 * @memberOf _
13616 * @since 3.7.0
13617 * @category Object
13618 * @param {Object} object The object to modify.
13619 * @param {Array|string} path The path of the property to set.
13620 * @param {*} value The value to set.
13621 * @returns {Object} Returns `object`.
13622 * @example
13623 *
13624 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13625 *
13626 * _.set(object, 'a[0].b.c', 4);
13627 * console.log(object.a[0].b.c);
13628 * // => 4
13629 *
13630 * _.set(object, ['x', '0', 'y', 'z'], 5);
13631 * console.log(object.x[0].y.z);
13632 * // => 5
13633 */
13634 function set(object, path, value) {
13635 return object == null ? object : baseSet(object, path, value);
13636 }
13637
13638 /**
13639 * This method is like `_.set` except that it accepts `customizer` which is
13640 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13641 * path creation is handled by the method instead. The `customizer` is invoked
13642 * with three arguments: (nsValue, key, nsObject).
13643 *
13644 * **Note:** This method mutates `object`.
13645 *
13646 * @static
13647 * @memberOf _
13648 * @since 4.0.0
13649 * @category Object
13650 * @param {Object} object The object to modify.
13651 * @param {Array|string} path The path of the property to set.
13652 * @param {*} value The value to set.
13653 * @param {Function} [customizer] The function to customize assigned values.
13654 * @returns {Object} Returns `object`.
13655 * @example
13656 *
13657 * var object = {};
13658 *
13659 * _.setWith(object, '[0][1]', 'a', Object);
13660 * // => { '0': { '1': 'a' } }
13661 */
13662 function setWith(object, path, value, customizer) {
13663 customizer = typeof customizer == 'function' ? customizer : undefined;
13664 return object == null ? object : baseSet(object, path, value, customizer);
13665 }
13666
13667 /**
13668 * Creates an array of own enumerable string keyed-value pairs for `object`
13669 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
13670 * entries are returned.
13671 *
13672 * @static
13673 * @memberOf _
13674 * @since 4.0.0
13675 * @alias entries
13676 * @category Object
13677 * @param {Object} object The object to query.
13678 * @returns {Array} Returns the key-value pairs.
13679 * @example
13680 *
13681 * function Foo() {
13682 * this.a = 1;
13683 * this.b = 2;
13684 * }
13685 *
13686 * Foo.prototype.c = 3;
13687 *
13688 * _.toPairs(new Foo);
13689 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
13690 */
13691 var toPairs = createToPairs(keys);
13692
13693 /**
13694 * Creates an array of own and inherited enumerable string keyed-value pairs
13695 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
13696 * or set, its entries are returned.
13697 *
13698 * @static
13699 * @memberOf _
13700 * @since 4.0.0
13701 * @alias entriesIn
13702 * @category Object
13703 * @param {Object} object The object to query.
13704 * @returns {Array} Returns the key-value pairs.
13705 * @example
13706 *
13707 * function Foo() {
13708 * this.a = 1;
13709 * this.b = 2;
13710 * }
13711 *
13712 * Foo.prototype.c = 3;
13713 *
13714 * _.toPairsIn(new Foo);
13715 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
13716 */
13717 var toPairsIn = createToPairs(keysIn);
13718
13719 /**
13720 * An alternative to `_.reduce`; this method transforms `object` to a new
13721 * `accumulator` object which is the result of running each of its own
13722 * enumerable string keyed properties thru `iteratee`, with each invocation
13723 * potentially mutating the `accumulator` object. If `accumulator` is not
13724 * provided, a new object with the same `[[Prototype]]` will be used. The
13725 * iteratee is invoked with four arguments: (accumulator, value, key, object).
13726 * Iteratee functions may exit iteration early by explicitly returning `false`.
13727 *
13728 * @static
13729 * @memberOf _
13730 * @since 1.3.0
13731 * @category Object
13732 * @param {Object} object The object to iterate over.
13733 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13734 * @param {*} [accumulator] The custom accumulator value.
13735 * @returns {*} Returns the accumulated value.
13736 * @example
13737 *
13738 * _.transform([2, 3, 4], function(result, n) {
13739 * result.push(n *= n);
13740 * return n % 2 == 0;
13741 * }, []);
13742 * // => [4, 9]
13743 *
13744 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
13745 * (result[value] || (result[value] = [])).push(key);
13746 * }, {});
13747 * // => { '1': ['a', 'c'], '2': ['b'] }
13748 */
13749 function transform(object, iteratee, accumulator) {
13750 var isArr = isArray(object),
13751 isArrLike = isArr || isBuffer(object) || isTypedArray(object);
13752
13753 iteratee = getIteratee(iteratee, 4);
13754 if (accumulator == null) {
13755 var Ctor = object && object.constructor;
13756 if (isArrLike) {
13757 accumulator = isArr ? new Ctor : [];
13758 }
13759 else if (isObject(object)) {
13760 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
13761 }
13762 else {
13763 accumulator = {};
13764 }
13765 }
13766 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
13767 return iteratee(accumulator, value, index, object);
13768 });
13769 return accumulator;
13770 }
13771
13772 /**
13773 * Removes the property at `path` of `object`.
13774 *
13775 * **Note:** This method mutates `object`.
13776 *
13777 * @static
13778 * @memberOf _
13779 * @since 4.0.0
13780 * @category Object
13781 * @param {Object} object The object to modify.
13782 * @param {Array|string} path The path of the property to unset.
13783 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
13784 * @example
13785 *
13786 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
13787 * _.unset(object, 'a[0].b.c');
13788 * // => true
13789 *
13790 * console.log(object);
13791 * // => { 'a': [{ 'b': {} }] };
13792 *
13793 * _.unset(object, ['a', '0', 'b', 'c']);
13794 * // => true
13795 *
13796 * console.log(object);
13797 * // => { 'a': [{ 'b': {} }] };
13798 */
13799 function unset(object, path) {
13800 return object == null ? true : baseUnset(object, path);
13801 }
13802
13803 /**
13804 * This method is like `_.set` except that accepts `updater` to produce the
13805 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
13806 * is invoked with one argument: (value).
13807 *
13808 * **Note:** This method mutates `object`.
13809 *
13810 * @static
13811 * @memberOf _
13812 * @since 4.6.0
13813 * @category Object
13814 * @param {Object} object The object to modify.
13815 * @param {Array|string} path The path of the property to set.
13816 * @param {Function} updater The function to produce the updated value.
13817 * @returns {Object} Returns `object`.
13818 * @example
13819 *
13820 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13821 *
13822 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
13823 * console.log(object.a[0].b.c);
13824 * // => 9
13825 *
13826 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
13827 * console.log(object.x[0].y.z);
13828 * // => 0
13829 */
13830 function update(object, path, updater) {
13831 return object == null ? object : baseUpdate(object, path, castFunction(updater));
13832 }
13833
13834 /**
13835 * This method is like `_.update` except that it accepts `customizer` which is
13836 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13837 * path creation is handled by the method instead. The `customizer` is invoked
13838 * with three arguments: (nsValue, key, nsObject).
13839 *
13840 * **Note:** This method mutates `object`.
13841 *
13842 * @static
13843 * @memberOf _
13844 * @since 4.6.0
13845 * @category Object
13846 * @param {Object} object The object to modify.
13847 * @param {Array|string} path The path of the property to set.
13848 * @param {Function} updater The function to produce the updated value.
13849 * @param {Function} [customizer] The function to customize assigned values.
13850 * @returns {Object} Returns `object`.
13851 * @example
13852 *
13853 * var object = {};
13854 *
13855 * _.updateWith(object, '[0][1]', _.constant('a'), Object);
13856 * // => { '0': { '1': 'a' } }
13857 */
13858 function updateWith(object, path, updater, customizer) {
13859 customizer = typeof customizer == 'function' ? customizer : undefined;
13860 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
13861 }
13862
13863 /**
13864 * Creates an array of the own enumerable string keyed property values of `object`.
13865 *
13866 * **Note:** Non-object values are coerced to objects.
13867 *
13868 * @static
13869 * @since 0.1.0
13870 * @memberOf _
13871 * @category Object
13872 * @param {Object} object The object to query.
13873 * @returns {Array} Returns the array of property values.
13874 * @example
13875 *
13876 * function Foo() {
13877 * this.a = 1;
13878 * this.b = 2;
13879 * }
13880 *
13881 * Foo.prototype.c = 3;
13882 *
13883 * _.values(new Foo);
13884 * // => [1, 2] (iteration order is not guaranteed)
13885 *
13886 * _.values('hi');
13887 * // => ['h', 'i']
13888 */
13889 function values(object) {
13890 return object == null ? [] : baseValues(object, keys(object));
13891 }
13892
13893 /**
13894 * Creates an array of the own and inherited enumerable string keyed property
13895 * values of `object`.
13896 *
13897 * **Note:** Non-object values are coerced to objects.
13898 *
13899 * @static
13900 * @memberOf _
13901 * @since 3.0.0
13902 * @category Object
13903 * @param {Object} object The object to query.
13904 * @returns {Array} Returns the array of property values.
13905 * @example
13906 *
13907 * function Foo() {
13908 * this.a = 1;
13909 * this.b = 2;
13910 * }
13911 *
13912 * Foo.prototype.c = 3;
13913 *
13914 * _.valuesIn(new Foo);
13915 * // => [1, 2, 3] (iteration order is not guaranteed)
13916 */
13917 function valuesIn(object) {
13918 return object == null ? [] : baseValues(object, keysIn(object));
13919 }
13920
13921 /*------------------------------------------------------------------------*/
13922
13923 /**
13924 * Clamps `number` within the inclusive `lower` and `upper` bounds.
13925 *
13926 * @static
13927 * @memberOf _
13928 * @since 4.0.0
13929 * @category Number
13930 * @param {number} number The number to clamp.
13931 * @param {number} [lower] The lower bound.
13932 * @param {number} upper The upper bound.
13933 * @returns {number} Returns the clamped number.
13934 * @example
13935 *
13936 * _.clamp(-10, -5, 5);
13937 * // => -5
13938 *
13939 * _.clamp(10, -5, 5);
13940 * // => 5
13941 */
13942 function clamp(number, lower, upper) {
13943 if (upper === undefined) {
13944 upper = lower;
13945 lower = undefined;
13946 }
13947 if (upper !== undefined) {
13948 upper = toNumber(upper);
13949 upper = upper === upper ? upper : 0;
13950 }
13951 if (lower !== undefined) {
13952 lower = toNumber(lower);
13953 lower = lower === lower ? lower : 0;
13954 }
13955 return baseClamp(toNumber(number), lower, upper);
13956 }
13957
13958 /**
13959 * Checks if `n` is between `start` and up to, but not including, `end`. If
13960 * `end` is not specified, it's set to `start` with `start` then set to `0`.
13961 * If `start` is greater than `end` the params are swapped to support
13962 * negative ranges.
13963 *
13964 * @static
13965 * @memberOf _
13966 * @since 3.3.0
13967 * @category Number
13968 * @param {number} number The number to check.
13969 * @param {number} [start=0] The start of the range.
13970 * @param {number} end The end of the range.
13971 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
13972 * @see _.range, _.rangeRight
13973 * @example
13974 *
13975 * _.inRange(3, 2, 4);
13976 * // => true
13977 *
13978 * _.inRange(4, 8);
13979 * // => true
13980 *
13981 * _.inRange(4, 2);
13982 * // => false
13983 *
13984 * _.inRange(2, 2);
13985 * // => false
13986 *
13987 * _.inRange(1.2, 2);
13988 * // => true
13989 *
13990 * _.inRange(5.2, 4);
13991 * // => false
13992 *
13993 * _.inRange(-3, -2, -6);
13994 * // => true
13995 */
13996 function inRange(number, start, end) {
13997 start = toFinite(start);
13998 if (end === undefined) {
13999 end = start;
14000 start = 0;
14001 } else {
14002 end = toFinite(end);
14003 }
14004 number = toNumber(number);
14005 return baseInRange(number, start, end);
14006 }
14007
14008 /**
14009 * Produces a random number between the inclusive `lower` and `upper` bounds.
14010 * If only one argument is provided a number between `0` and the given number
14011 * is returned. If `floating` is `true`, or either `lower` or `upper` are
14012 * floats, a floating-point number is returned instead of an integer.
14013 *
14014 * **Note:** JavaScript follows the IEEE-754 standard for resolving
14015 * floating-point values which can produce unexpected results.
14016 *
14017 * @static
14018 * @memberOf _
14019 * @since 0.7.0
14020 * @category Number
14021 * @param {number} [lower=0] The lower bound.
14022 * @param {number} [upper=1] The upper bound.
14023 * @param {boolean} [floating] Specify returning a floating-point number.
14024 * @returns {number} Returns the random number.
14025 * @example
14026 *
14027 * _.random(0, 5);
14028 * // => an integer between 0 and 5
14029 *
14030 * _.random(5);
14031 * // => also an integer between 0 and 5
14032 *
14033 * _.random(5, true);
14034 * // => a floating-point number between 0 and 5
14035 *
14036 * _.random(1.2, 5.2);
14037 * // => a floating-point number between 1.2 and 5.2
14038 */
14039 function random(lower, upper, floating) {
14040 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
14041 upper = floating = undefined;
14042 }
14043 if (floating === undefined) {
14044 if (typeof upper == 'boolean') {
14045 floating = upper;
14046 upper = undefined;
14047 }
14048 else if (typeof lower == 'boolean') {
14049 floating = lower;
14050 lower = undefined;
14051 }
14052 }
14053 if (lower === undefined && upper === undefined) {
14054 lower = 0;
14055 upper = 1;
14056 }
14057 else {
14058 lower = toFinite(lower);
14059 if (upper === undefined) {
14060 upper = lower;
14061 lower = 0;
14062 } else {
14063 upper = toFinite(upper);
14064 }
14065 }
14066 if (lower > upper) {
14067 var temp = lower;
14068 lower = upper;
14069 upper = temp;
14070 }
14071 if (floating || lower % 1 || upper % 1) {
14072 var rand = nativeRandom();
14073 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
14074 }
14075 return baseRandom(lower, upper);
14076 }
14077
14078 /*------------------------------------------------------------------------*/
14079
14080 /**
14081 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
14082 *
14083 * @static
14084 * @memberOf _
14085 * @since 3.0.0
14086 * @category String
14087 * @param {string} [string=''] The string to convert.
14088 * @returns {string} Returns the camel cased string.
14089 * @example
14090 *
14091 * _.camelCase('Foo Bar');
14092 * // => 'fooBar'
14093 *
14094 * _.camelCase('--foo-bar--');
14095 * // => 'fooBar'
14096 *
14097 * _.camelCase('__FOO_BAR__');
14098 * // => 'fooBar'
14099 */
14100 var camelCase = createCompounder(function(result, word, index) {
14101 word = word.toLowerCase();
14102 return result + (index ? capitalize(word) : word);
14103 });
14104
14105 /**
14106 * Converts the first character of `string` to upper case and the remaining
14107 * to lower case.
14108 *
14109 * @static
14110 * @memberOf _
14111 * @since 3.0.0
14112 * @category String
14113 * @param {string} [string=''] The string to capitalize.
14114 * @returns {string} Returns the capitalized string.
14115 * @example
14116 *
14117 * _.capitalize('FRED');
14118 * // => 'Fred'
14119 */
14120 function capitalize(string) {
14121 return upperFirst(toString(string).toLowerCase());
14122 }
14123
14124 /**
14125 * Deburrs `string` by converting
14126 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
14127 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
14128 * letters to basic Latin letters and removing
14129 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
14130 *
14131 * @static
14132 * @memberOf _
14133 * @since 3.0.0
14134 * @category String
14135 * @param {string} [string=''] The string to deburr.
14136 * @returns {string} Returns the deburred string.
14137 * @example
14138 *
14139 * _.deburr('déjà vu');
14140 * // => 'deja vu'
14141 */
14142 function deburr(string) {
14143 string = toString(string);
14144 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
14145 }
14146
14147 /**
14148 * Checks if `string` ends with the given target string.
14149 *
14150 * @static
14151 * @memberOf _
14152 * @since 3.0.0
14153 * @category String
14154 * @param {string} [string=''] The string to inspect.
14155 * @param {string} [target] The string to search for.
14156 * @param {number} [position=string.length] The position to search up to.
14157 * @returns {boolean} Returns `true` if `string` ends with `target`,
14158 * else `false`.
14159 * @example
14160 *
14161 * _.endsWith('abc', 'c');
14162 * // => true
14163 *
14164 * _.endsWith('abc', 'b');
14165 * // => false
14166 *
14167 * _.endsWith('abc', 'b', 2);
14168 * // => true
14169 */
14170 function endsWith(string, target, position) {
14171 string = toString(string);
14172 target = baseToString(target);
14173
14174 var length = string.length;
14175 position = position === undefined
14176 ? length
14177 : baseClamp(toInteger(position), 0, length);
14178
14179 var end = position;
14180 position -= target.length;
14181 return position >= 0 && string.slice(position, end) == target;
14182 }
14183
14184 /**
14185 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
14186 * corresponding HTML entities.
14187 *
14188 * **Note:** No other characters are escaped. To escape additional
14189 * characters use a third-party library like [_he_](https://mths.be/he).
14190 *
14191 * Though the ">" character is escaped for symmetry, characters like
14192 * ">" and "/" don't need escaping in HTML and have no special meaning
14193 * unless they're part of a tag or unquoted attribute value. See
14194 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
14195 * (under "semi-related fun fact") for more details.
14196 *
14197 * When working with HTML you should always
14198 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
14199 * XSS vectors.
14200 *
14201 * @static
14202 * @since 0.1.0
14203 * @memberOf _
14204 * @category String
14205 * @param {string} [string=''] The string to escape.
14206 * @returns {string} Returns the escaped string.
14207 * @example
14208 *
14209 * _.escape('fred, barney, & pebbles');
14210 * // => 'fred, barney, &amp; pebbles'
14211 */
14212 function escape(string) {
14213 string = toString(string);
14214 return (string && reHasUnescapedHtml.test(string))
14215 ? string.replace(reUnescapedHtml, escapeHtmlChar)
14216 : string;
14217 }
14218
14219 /**
14220 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
14221 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
14222 *
14223 * @static
14224 * @memberOf _
14225 * @since 3.0.0
14226 * @category String
14227 * @param {string} [string=''] The string to escape.
14228 * @returns {string} Returns the escaped string.
14229 * @example
14230 *
14231 * _.escapeRegExp('[lodash](https://lodash.com/)');
14232 * // => '\[lodash\]\(https://lodash\.com/\)'
14233 */
14234 function escapeRegExp(string) {
14235 string = toString(string);
14236 return (string && reHasRegExpChar.test(string))
14237 ? string.replace(reRegExpChar, '\\$&')
14238 : string;
14239 }
14240
14241 /**
14242 * Converts `string` to
14243 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
14244 *
14245 * @static
14246 * @memberOf _
14247 * @since 3.0.0
14248 * @category String
14249 * @param {string} [string=''] The string to convert.
14250 * @returns {string} Returns the kebab cased string.
14251 * @example
14252 *
14253 * _.kebabCase('Foo Bar');
14254 * // => 'foo-bar'
14255 *
14256 * _.kebabCase('fooBar');
14257 * // => 'foo-bar'
14258 *
14259 * _.kebabCase('__FOO_BAR__');
14260 * // => 'foo-bar'
14261 */
14262 var kebabCase = createCompounder(function(result, word, index) {
14263 return result + (index ? '-' : '') + word.toLowerCase();
14264 });
14265
14266 /**
14267 * Converts `string`, as space separated words, to lower case.
14268 *
14269 * @static
14270 * @memberOf _
14271 * @since 4.0.0
14272 * @category String
14273 * @param {string} [string=''] The string to convert.
14274 * @returns {string} Returns the lower cased string.
14275 * @example
14276 *
14277 * _.lowerCase('--Foo-Bar--');
14278 * // => 'foo bar'
14279 *
14280 * _.lowerCase('fooBar');
14281 * // => 'foo bar'
14282 *
14283 * _.lowerCase('__FOO_BAR__');
14284 * // => 'foo bar'
14285 */
14286 var lowerCase = createCompounder(function(result, word, index) {
14287 return result + (index ? ' ' : '') + word.toLowerCase();
14288 });
14289
14290 /**
14291 * Converts the first character of `string` to lower case.
14292 *
14293 * @static
14294 * @memberOf _
14295 * @since 4.0.0
14296 * @category String
14297 * @param {string} [string=''] The string to convert.
14298 * @returns {string} Returns the converted string.
14299 * @example
14300 *
14301 * _.lowerFirst('Fred');
14302 * // => 'fred'
14303 *
14304 * _.lowerFirst('FRED');
14305 * // => 'fRED'
14306 */
14307 var lowerFirst = createCaseFirst('toLowerCase');
14308
14309 /**
14310 * Pads `string` on the left and right sides if it's shorter than `length`.
14311 * Padding characters are truncated if they can't be evenly divided by `length`.
14312 *
14313 * @static
14314 * @memberOf _
14315 * @since 3.0.0
14316 * @category String
14317 * @param {string} [string=''] The string to pad.
14318 * @param {number} [length=0] The padding length.
14319 * @param {string} [chars=' '] The string used as padding.
14320 * @returns {string} Returns the padded string.
14321 * @example
14322 *
14323 * _.pad('abc', 8);
14324 * // => ' abc '
14325 *
14326 * _.pad('abc', 8, '_-');
14327 * // => '_-abc_-_'
14328 *
14329 * _.pad('abc', 3);
14330 * // => 'abc'
14331 */
14332 function pad(string, length, chars) {
14333 string = toString(string);
14334 length = toInteger(length);
14335
14336 var strLength = length ? stringSize(string) : 0;
14337 if (!length || strLength >= length) {
14338 return string;
14339 }
14340 var mid = (length - strLength) / 2;
14341 return (
14342 createPadding(nativeFloor(mid), chars) +
14343 string +
14344 createPadding(nativeCeil(mid), chars)
14345 );
14346 }
14347
14348 /**
14349 * Pads `string` on the right side if it's shorter than `length`. Padding
14350 * characters are truncated if they exceed `length`.
14351 *
14352 * @static
14353 * @memberOf _
14354 * @since 4.0.0
14355 * @category String
14356 * @param {string} [string=''] The string to pad.
14357 * @param {number} [length=0] The padding length.
14358 * @param {string} [chars=' '] The string used as padding.
14359 * @returns {string} Returns the padded string.
14360 * @example
14361 *
14362 * _.padEnd('abc', 6);
14363 * // => 'abc '
14364 *
14365 * _.padEnd('abc', 6, '_-');
14366 * // => 'abc_-_'
14367 *
14368 * _.padEnd('abc', 3);
14369 * // => 'abc'
14370 */
14371 function padEnd(string, length, chars) {
14372 string = toString(string);
14373 length = toInteger(length);
14374
14375 var strLength = length ? stringSize(string) : 0;
14376 return (length && strLength < length)
14377 ? (string + createPadding(length - strLength, chars))
14378 : string;
14379 }
14380
14381 /**
14382 * Pads `string` on the left side if it's shorter than `length`. Padding
14383 * characters are truncated if they exceed `length`.
14384 *
14385 * @static
14386 * @memberOf _
14387 * @since 4.0.0
14388 * @category String
14389 * @param {string} [string=''] The string to pad.
14390 * @param {number} [length=0] The padding length.
14391 * @param {string} [chars=' '] The string used as padding.
14392 * @returns {string} Returns the padded string.
14393 * @example
14394 *
14395 * _.padStart('abc', 6);
14396 * // => ' abc'
14397 *
14398 * _.padStart('abc', 6, '_-');
14399 * // => '_-_abc'
14400 *
14401 * _.padStart('abc', 3);
14402 * // => 'abc'
14403 */
14404 function padStart(string, length, chars) {
14405 string = toString(string);
14406 length = toInteger(length);
14407
14408 var strLength = length ? stringSize(string) : 0;
14409 return (length && strLength < length)
14410 ? (createPadding(length - strLength, chars) + string)
14411 : string;
14412 }
14413
14414 /**
14415 * Converts `string` to an integer of the specified radix. If `radix` is
14416 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
14417 * hexadecimal, in which case a `radix` of `16` is used.
14418 *
14419 * **Note:** This method aligns with the
14420 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
14421 *
14422 * @static
14423 * @memberOf _
14424 * @since 1.1.0
14425 * @category String
14426 * @param {string} string The string to convert.
14427 * @param {number} [radix=10] The radix to interpret `value` by.
14428 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14429 * @returns {number} Returns the converted integer.
14430 * @example
14431 *
14432 * _.parseInt('08');
14433 * // => 8
14434 *
14435 * _.map(['6', '08', '10'], _.parseInt);
14436 * // => [6, 8, 10]
14437 */
14438 function parseInt(string, radix, guard) {
14439 if (guard || radix == null) {
14440 radix = 0;
14441 } else if (radix) {
14442 radix = +radix;
14443 }
14444 return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
14445 }
14446
14447 /**
14448 * Repeats the given string `n` times.
14449 *
14450 * @static
14451 * @memberOf _
14452 * @since 3.0.0
14453 * @category String
14454 * @param {string} [string=''] The string to repeat.
14455 * @param {number} [n=1] The number of times to repeat the string.
14456 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14457 * @returns {string} Returns the repeated string.
14458 * @example
14459 *
14460 * _.repeat('*', 3);
14461 * // => '***'
14462 *
14463 * _.repeat('abc', 2);
14464 * // => 'abcabc'
14465 *
14466 * _.repeat('abc', 0);
14467 * // => ''
14468 */
14469 function repeat(string, n, guard) {
14470 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
14471 n = 1;
14472 } else {
14473 n = toInteger(n);
14474 }
14475 return baseRepeat(toString(string), n);
14476 }
14477
14478 /**
14479 * Replaces matches for `pattern` in `string` with `replacement`.
14480 *
14481 * **Note:** This method is based on
14482 * [`String#replace`](https://mdn.io/String/replace).
14483 *
14484 * @static
14485 * @memberOf _
14486 * @since 4.0.0
14487 * @category String
14488 * @param {string} [string=''] The string to modify.
14489 * @param {RegExp|string} pattern The pattern to replace.
14490 * @param {Function|string} replacement The match replacement.
14491 * @returns {string} Returns the modified string.
14492 * @example
14493 *
14494 * _.replace('Hi Fred', 'Fred', 'Barney');
14495 * // => 'Hi Barney'
14496 */
14497 function replace() {
14498 var args = arguments,
14499 string = toString(args[0]);
14500
14501 return args.length < 3 ? string : string.replace(args[1], args[2]);
14502 }
14503
14504 /**
14505 * Converts `string` to
14506 * [snake case](https://en.wikipedia.org/wiki/Snake_case).
14507 *
14508 * @static
14509 * @memberOf _
14510 * @since 3.0.0
14511 * @category String
14512 * @param {string} [string=''] The string to convert.
14513 * @returns {string} Returns the snake cased string.
14514 * @example
14515 *
14516 * _.snakeCase('Foo Bar');
14517 * // => 'foo_bar'
14518 *
14519 * _.snakeCase('fooBar');
14520 * // => 'foo_bar'
14521 *
14522 * _.snakeCase('--FOO-BAR--');
14523 * // => 'foo_bar'
14524 */
14525 var snakeCase = createCompounder(function(result, word, index) {
14526 return result + (index ? '_' : '') + word.toLowerCase();
14527 });
14528
14529 /**
14530 * Splits `string` by `separator`.
14531 *
14532 * **Note:** This method is based on
14533 * [`String#split`](https://mdn.io/String/split).
14534 *
14535 * @static
14536 * @memberOf _
14537 * @since 4.0.0
14538 * @category String
14539 * @param {string} [string=''] The string to split.
14540 * @param {RegExp|string} separator The separator pattern to split by.
14541 * @param {number} [limit] The length to truncate results to.
14542 * @returns {Array} Returns the string segments.
14543 * @example
14544 *
14545 * _.split('a-b-c', '-', 2);
14546 * // => ['a', 'b']
14547 */
14548 function split(string, separator, limit) {
14549 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
14550 separator = limit = undefined;
14551 }
14552 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
14553 if (!limit) {
14554 return [];
14555 }
14556 string = toString(string);
14557 if (string && (
14558 typeof separator == 'string' ||
14559 (separator != null && !isRegExp(separator))
14560 )) {
14561 separator = baseToString(separator);
14562 if (!separator && hasUnicode(string)) {
14563 return castSlice(stringToArray(string), 0, limit);
14564 }
14565 }
14566 return string.split(separator, limit);
14567 }
14568
14569 /**
14570 * Converts `string` to
14571 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
14572 *
14573 * @static
14574 * @memberOf _
14575 * @since 3.1.0
14576 * @category String
14577 * @param {string} [string=''] The string to convert.
14578 * @returns {string} Returns the start cased string.
14579 * @example
14580 *
14581 * _.startCase('--foo-bar--');
14582 * // => 'Foo Bar'
14583 *
14584 * _.startCase('fooBar');
14585 * // => 'Foo Bar'
14586 *
14587 * _.startCase('__FOO_BAR__');
14588 * // => 'FOO BAR'
14589 */
14590 var startCase = createCompounder(function(result, word, index) {
14591 return result + (index ? ' ' : '') + upperFirst(word);
14592 });
14593
14594 /**
14595 * Checks if `string` starts with the given target string.
14596 *
14597 * @static
14598 * @memberOf _
14599 * @since 3.0.0
14600 * @category String
14601 * @param {string} [string=''] The string to inspect.
14602 * @param {string} [target] The string to search for.
14603 * @param {number} [position=0] The position to search from.
14604 * @returns {boolean} Returns `true` if `string` starts with `target`,
14605 * else `false`.
14606 * @example
14607 *
14608 * _.startsWith('abc', 'a');
14609 * // => true
14610 *
14611 * _.startsWith('abc', 'b');
14612 * // => false
14613 *
14614 * _.startsWith('abc', 'b', 1);
14615 * // => true
14616 */
14617 function startsWith(string, target, position) {
14618 string = toString(string);
14619 position = baseClamp(toInteger(position), 0, string.length);
14620 target = baseToString(target);
14621 return string.slice(position, position + target.length) == target;
14622 }
14623
14624 /**
14625 * Creates a compiled template function that can interpolate data properties
14626 * in "interpolate" delimiters, HTML-escape interpolated data properties in
14627 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
14628 * properties may be accessed as free variables in the template. If a setting
14629 * object is given, it takes precedence over `_.templateSettings` values.
14630 *
14631 * **Note:** In the development build `_.template` utilizes
14632 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
14633 * for easier debugging.
14634 *
14635 * For more information on precompiling templates see
14636 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
14637 *
14638 * For more information on Chrome extension sandboxes see
14639 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
14640 *
14641 * @static
14642 * @since 0.1.0
14643 * @memberOf _
14644 * @category String
14645 * @param {string} [string=''] The template string.
14646 * @param {Object} [options={}] The options object.
14647 * @param {RegExp} [options.escape=_.templateSettings.escape]
14648 * The HTML "escape" delimiter.
14649 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
14650 * The "evaluate" delimiter.
14651 * @param {Object} [options.imports=_.templateSettings.imports]
14652 * An object to import into the template as free variables.
14653 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
14654 * The "interpolate" delimiter.
14655 * @param {string} [options.sourceURL='lodash.templateSources[n]']
14656 * The sourceURL of the compiled template.
14657 * @param {string} [options.variable='obj']
14658 * The data object variable name.
14659 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14660 * @returns {Function} Returns the compiled template function.
14661 * @example
14662 *
14663 * // Use the "interpolate" delimiter to create a compiled template.
14664 * var compiled = _.template('hello <%= user %>!');
14665 * compiled({ 'user': 'fred' });
14666 * // => 'hello fred!'
14667 *
14668 * // Use the HTML "escape" delimiter to escape data property values.
14669 * var compiled = _.template('<b><%- value %></b>');
14670 * compiled({ 'value': '<script>' });
14671 * // => '<b>&lt;script&gt;</b>'
14672 *
14673 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
14674 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
14675 * compiled({ 'users': ['fred', 'barney'] });
14676 * // => '<li>fred</li><li>barney</li>'
14677 *
14678 * // Use the internal `print` function in "evaluate" delimiters.
14679 * var compiled = _.template('<% print("hello " + user); %>!');
14680 * compiled({ 'user': 'barney' });
14681 * // => 'hello barney!'
14682 *
14683 * // Use the ES template literal delimiter as an "interpolate" delimiter.
14684 * // Disable support by replacing the "interpolate" delimiter.
14685 * var compiled = _.template('hello ${ user }!');
14686 * compiled({ 'user': 'pebbles' });
14687 * // => 'hello pebbles!'
14688 *
14689 * // Use backslashes to treat delimiters as plain text.
14690 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
14691 * compiled({ 'value': 'ignored' });
14692 * // => '<%- value %>'
14693 *
14694 * // Use the `imports` option to import `jQuery` as `jq`.
14695 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
14696 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
14697 * compiled({ 'users': ['fred', 'barney'] });
14698 * // => '<li>fred</li><li>barney</li>'
14699 *
14700 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
14701 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
14702 * compiled(data);
14703 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
14704 *
14705 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
14706 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
14707 * compiled.source;
14708 * // => function(data) {
14709 * // var __t, __p = '';
14710 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
14711 * // return __p;
14712 * // }
14713 *
14714 * // Use custom template delimiters.
14715 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
14716 * var compiled = _.template('hello {{ user }}!');
14717 * compiled({ 'user': 'mustache' });
14718 * // => 'hello mustache!'
14719 *
14720 * // Use the `source` property to inline compiled templates for meaningful
14721 * // line numbers in error messages and stack traces.
14722 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
14723 * var JST = {\
14724 * "main": ' + _.template(mainText).source + '\
14725 * };\
14726 * ');
14727 */
14728 function template(string, options, guard) {
14729 // Based on John Resig's `tmpl` implementation
14730 // (http://ejohn.org/blog/javascript-micro-templating/)
14731 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
14732 var settings = lodash.templateSettings;
14733
14734 if (guard && isIterateeCall(string, options, guard)) {
14735 options = undefined;
14736 }
14737 string = toString(string);
14738 options = assignInWith({}, options, settings, assignInDefaults);
14739
14740 var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
14741 importsKeys = keys(imports),
14742 importsValues = baseValues(imports, importsKeys);
14743
14744 var isEscaping,
14745 isEvaluating,
14746 index = 0,
14747 interpolate = options.interpolate || reNoMatch,
14748 source = "__p += '";
14749
14750 // Compile the regexp to match each delimiter.
14751 var reDelimiters = RegExp(
14752 (options.escape || reNoMatch).source + '|' +
14753 interpolate.source + '|' +
14754 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
14755 (options.evaluate || reNoMatch).source + '|$'
14756 , 'g');
14757
14758 // Use a sourceURL for easier debugging.
14759 var sourceURL = '//# sourceURL=' +
14760 ('sourceURL' in options
14761 ? options.sourceURL
14762 : ('lodash.templateSources[' + (++templateCounter) + ']')
14763 ) + '\n';
14764
14765 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
14766 interpolateValue || (interpolateValue = esTemplateValue);
14767
14768 // Escape characters that can't be included in string literals.
14769 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
14770
14771 // Replace delimiters with snippets.
14772 if (escapeValue) {
14773 isEscaping = true;
14774 source += "' +\n__e(" + escapeValue + ") +\n'";
14775 }
14776 if (evaluateValue) {
14777 isEvaluating = true;
14778 source += "';\n" + evaluateValue + ";\n__p += '";
14779 }
14780 if (interpolateValue) {
14781 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
14782 }
14783 index = offset + match.length;
14784
14785 // The JS engine embedded in Adobe products needs `match` returned in
14786 // order to produce the correct `offset` value.
14787 return match;
14788 });
14789
14790 source += "';\n";
14791
14792 // If `variable` is not specified wrap a with-statement around the generated
14793 // code to add the data object to the top of the scope chain.
14794 var variable = options.variable;
14795 if (!variable) {
14796 source = 'with (obj) {\n' + source + '\n}\n';
14797 }
14798 // Cleanup code by stripping empty strings.
14799 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
14800 .replace(reEmptyStringMiddle, '$1')
14801 .replace(reEmptyStringTrailing, '$1;');
14802
14803 // Frame code as the function body.
14804 source = 'function(' + (variable || 'obj') + ') {\n' +
14805 (variable
14806 ? ''
14807 : 'obj || (obj = {});\n'
14808 ) +
14809 "var __t, __p = ''" +
14810 (isEscaping
14811 ? ', __e = _.escape'
14812 : ''
14813 ) +
14814 (isEvaluating
14815 ? ', __j = Array.prototype.join;\n' +
14816 "function print() { __p += __j.call(arguments, '') }\n"
14817 : ';\n'
14818 ) +
14819 source +
14820 'return __p\n}';
14821
14822 var result = attempt(function() {
14823 return Function(importsKeys, sourceURL + 'return ' + source)
14824 .apply(undefined, importsValues);
14825 });
14826
14827 // Provide the compiled function's source by its `toString` method or
14828 // the `source` property as a convenience for inlining compiled templates.
14829 result.source = source;
14830 if (isError(result)) {
14831 throw result;
14832 }
14833 return result;
14834 }
14835
14836 /**
14837 * Converts `string`, as a whole, to lower case just like
14838 * [String#toLowerCase](https://mdn.io/toLowerCase).
14839 *
14840 * @static
14841 * @memberOf _
14842 * @since 4.0.0
14843 * @category String
14844 * @param {string} [string=''] The string to convert.
14845 * @returns {string} Returns the lower cased string.
14846 * @example
14847 *
14848 * _.toLower('--Foo-Bar--');
14849 * // => '--foo-bar--'
14850 *
14851 * _.toLower('fooBar');
14852 * // => 'foobar'
14853 *
14854 * _.toLower('__FOO_BAR__');
14855 * // => '__foo_bar__'
14856 */
14857 function toLower(value) {
14858 return toString(value).toLowerCase();
14859 }
14860
14861 /**
14862 * Converts `string`, as a whole, to upper case just like
14863 * [String#toUpperCase](https://mdn.io/toUpperCase).
14864 *
14865 * @static
14866 * @memberOf _
14867 * @since 4.0.0
14868 * @category String
14869 * @param {string} [string=''] The string to convert.
14870 * @returns {string} Returns the upper cased string.
14871 * @example
14872 *
14873 * _.toUpper('--foo-bar--');
14874 * // => '--FOO-BAR--'
14875 *
14876 * _.toUpper('fooBar');
14877 * // => 'FOOBAR'
14878 *
14879 * _.toUpper('__foo_bar__');
14880 * // => '__FOO_BAR__'
14881 */
14882 function toUpper(value) {
14883 return toString(value).toUpperCase();
14884 }
14885
14886 /**
14887 * Removes leading and trailing whitespace or specified characters from `string`.
14888 *
14889 * @static
14890 * @memberOf _
14891 * @since 3.0.0
14892 * @category String
14893 * @param {string} [string=''] The string to trim.
14894 * @param {string} [chars=whitespace] The characters to trim.
14895 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14896 * @returns {string} Returns the trimmed string.
14897 * @example
14898 *
14899 * _.trim(' abc ');
14900 * // => 'abc'
14901 *
14902 * _.trim('-_-abc-_-', '_-');
14903 * // => 'abc'
14904 *
14905 * _.map([' foo ', ' bar '], _.trim);
14906 * // => ['foo', 'bar']
14907 */
14908 function trim(string, chars, guard) {
14909 string = toString(string);
14910 if (string && (guard || chars === undefined)) {
14911 return string.replace(reTrim, '');
14912 }
14913 if (!string || !(chars = baseToString(chars))) {
14914 return string;
14915 }
14916 var strSymbols = stringToArray(string),
14917 chrSymbols = stringToArray(chars),
14918 start = charsStartIndex(strSymbols, chrSymbols),
14919 end = charsEndIndex(strSymbols, chrSymbols) + 1;
14920
14921 return castSlice(strSymbols, start, end).join('');
14922 }
14923
14924 /**
14925 * Removes trailing whitespace or specified characters from `string`.
14926 *
14927 * @static
14928 * @memberOf _
14929 * @since 4.0.0
14930 * @category String
14931 * @param {string} [string=''] The string to trim.
14932 * @param {string} [chars=whitespace] The characters to trim.
14933 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14934 * @returns {string} Returns the trimmed string.
14935 * @example
14936 *
14937 * _.trimEnd(' abc ');
14938 * // => ' abc'
14939 *
14940 * _.trimEnd('-_-abc-_-', '_-');
14941 * // => '-_-abc'
14942 */
14943 function trimEnd(string, chars, guard) {
14944 string = toString(string);
14945 if (string && (guard || chars === undefined)) {
14946 return string.replace(reTrimEnd, '');
14947 }
14948 if (!string || !(chars = baseToString(chars))) {
14949 return string;
14950 }
14951 var strSymbols = stringToArray(string),
14952 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
14953
14954 return castSlice(strSymbols, 0, end).join('');
14955 }
14956
14957 /**
14958 * Removes leading whitespace or specified characters from `string`.
14959 *
14960 * @static
14961 * @memberOf _
14962 * @since 4.0.0
14963 * @category String
14964 * @param {string} [string=''] The string to trim.
14965 * @param {string} [chars=whitespace] The characters to trim.
14966 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14967 * @returns {string} Returns the trimmed string.
14968 * @example
14969 *
14970 * _.trimStart(' abc ');
14971 * // => 'abc '
14972 *
14973 * _.trimStart('-_-abc-_-', '_-');
14974 * // => 'abc-_-'
14975 */
14976 function trimStart(string, chars, guard) {
14977 string = toString(string);
14978 if (string && (guard || chars === undefined)) {
14979 return string.replace(reTrimStart, '');
14980 }
14981 if (!string || !(chars = baseToString(chars))) {
14982 return string;
14983 }
14984 var strSymbols = stringToArray(string),
14985 start = charsStartIndex(strSymbols, stringToArray(chars));
14986
14987 return castSlice(strSymbols, start).join('');
14988 }
14989
14990 /**
14991 * Truncates `string` if it's longer than the given maximum string length.
14992 * The last characters of the truncated string are replaced with the omission
14993 * string which defaults to "...".
14994 *
14995 * @static
14996 * @memberOf _
14997 * @since 4.0.0
14998 * @category String
14999 * @param {string} [string=''] The string to truncate.
15000 * @param {Object} [options={}] The options object.
15001 * @param {number} [options.length=30] The maximum string length.
15002 * @param {string} [options.omission='...'] The string to indicate text is omitted.
15003 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
15004 * @returns {string} Returns the truncated string.
15005 * @example
15006 *
15007 * _.truncate('hi-diddly-ho there, neighborino');
15008 * // => 'hi-diddly-ho there, neighbo...'
15009 *
15010 * _.truncate('hi-diddly-ho there, neighborino', {
15011 * 'length': 24,
15012 * 'separator': ' '
15013 * });
15014 * // => 'hi-diddly-ho there,...'
15015 *
15016 * _.truncate('hi-diddly-ho there, neighborino', {
15017 * 'length': 24,
15018 * 'separator': /,? +/
15019 * });
15020 * // => 'hi-diddly-ho there...'
15021 *
15022 * _.truncate('hi-diddly-ho there, neighborino', {
15023 * 'omission': ' [...]'
15024 * });
15025 * // => 'hi-diddly-ho there, neig [...]'
15026 */
15027 function truncate(string, options) {
15028 var length = DEFAULT_TRUNC_LENGTH,
15029 omission = DEFAULT_TRUNC_OMISSION;
15030
15031 if (isObject(options)) {
15032 var separator = 'separator' in options ? options.separator : separator;
15033 length = 'length' in options ? toInteger(options.length) : length;
15034 omission = 'omission' in options ? baseToString(options.omission) : omission;
15035 }
15036 string = toString(string);
15037
15038 var strLength = string.length;
15039 if (hasUnicode(string)) {
15040 var strSymbols = stringToArray(string);
15041 strLength = strSymbols.length;
15042 }
15043 if (length >= strLength) {
15044 return string;
15045 }
15046 var end = length - stringSize(omission);
15047 if (end < 1) {
15048 return omission;
15049 }
15050 var result = strSymbols
15051 ? castSlice(strSymbols, 0, end).join('')
15052 : string.slice(0, end);
15053
15054 if (separator === undefined) {
15055 return result + omission;
15056 }
15057 if (strSymbols) {
15058 end += (result.length - end);
15059 }
15060 if (isRegExp(separator)) {
15061 if (string.slice(end).search(separator)) {
15062 var match,
15063 substring = result;
15064
15065 if (!separator.global) {
15066 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
15067 }
15068 separator.lastIndex = 0;
15069 while ((match = separator.exec(substring))) {
15070 var newEnd = match.index;
15071 }
15072 result = result.slice(0, newEnd === undefined ? end : newEnd);
15073 }
15074 } else if (string.indexOf(baseToString(separator), end) != end) {
15075 var index = result.lastIndexOf(separator);
15076 if (index > -1) {
15077 result = result.slice(0, index);
15078 }
15079 }
15080 return result + omission;
15081 }
15082
15083 /**
15084 * The inverse of `_.escape`; this method converts the HTML entities
15085 * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
15086 * their corresponding characters.
15087 *
15088 * **Note:** No other HTML entities are unescaped. To unescape additional
15089 * HTML entities use a third-party library like [_he_](https://mths.be/he).
15090 *
15091 * @static
15092 * @memberOf _
15093 * @since 0.6.0
15094 * @category String
15095 * @param {string} [string=''] The string to unescape.
15096 * @returns {string} Returns the unescaped string.
15097 * @example
15098 *
15099 * _.unescape('fred, barney, &amp; pebbles');
15100 * // => 'fred, barney, & pebbles'
15101 */
15102 function unescape(string) {
15103 string = toString(string);
15104 return (string && reHasEscapedHtml.test(string))
15105 ? string.replace(reEscapedHtml, unescapeHtmlChar)
15106 : string;
15107 }
15108
15109 /**
15110 * Converts `string`, as space separated words, to upper case.
15111 *
15112 * @static
15113 * @memberOf _
15114 * @since 4.0.0
15115 * @category String
15116 * @param {string} [string=''] The string to convert.
15117 * @returns {string} Returns the upper cased string.
15118 * @example
15119 *
15120 * _.upperCase('--foo-bar');
15121 * // => 'FOO BAR'
15122 *
15123 * _.upperCase('fooBar');
15124 * // => 'FOO BAR'
15125 *
15126 * _.upperCase('__foo_bar__');
15127 * // => 'FOO BAR'
15128 */
15129 var upperCase = createCompounder(function(result, word, index) {
15130 return result + (index ? ' ' : '') + word.toUpperCase();
15131 });
15132
15133 /**
15134 * Converts the first character of `string` to upper case.
15135 *
15136 * @static
15137 * @memberOf _
15138 * @since 4.0.0
15139 * @category String
15140 * @param {string} [string=''] The string to convert.
15141 * @returns {string} Returns the converted string.
15142 * @example
15143 *
15144 * _.upperFirst('fred');
15145 * // => 'Fred'
15146 *
15147 * _.upperFirst('FRED');
15148 * // => 'FRED'
15149 */
15150 var upperFirst = createCaseFirst('toUpperCase');
15151
15152 /**
15153 * Splits `string` into an array of its words.
15154 *
15155 * @static
15156 * @memberOf _
15157 * @since 3.0.0
15158 * @category String
15159 * @param {string} [string=''] The string to inspect.
15160 * @param {RegExp|string} [pattern] The pattern to match words.
15161 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15162 * @returns {Array} Returns the words of `string`.
15163 * @example
15164 *
15165 * _.words('fred, barney, & pebbles');
15166 * // => ['fred', 'barney', 'pebbles']
15167 *
15168 * _.words('fred, barney, & pebbles', /[^, ]+/g);
15169 * // => ['fred', 'barney', '&', 'pebbles']
15170 */
15171 function words(string, pattern, guard) {
15172 string = toString(string);
15173 pattern = guard ? undefined : pattern;
15174
15175 if (pattern === undefined) {
15176 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
15177 }
15178 return string.match(pattern) || [];
15179 }
15180
15181 /*------------------------------------------------------------------------*/
15182
15183 /**
15184 * Attempts to invoke `func`, returning either the result or the caught error
15185 * object. Any additional arguments are provided to `func` when it's invoked.
15186 *
15187 * @static
15188 * @memberOf _
15189 * @since 3.0.0
15190 * @category Util
15191 * @param {Function} func The function to attempt.
15192 * @param {...*} [args] The arguments to invoke `func` with.
15193 * @returns {*} Returns the `func` result or error object.
15194 * @example
15195 *
15196 * // Avoid throwing errors for invalid selectors.
15197 * var elements = _.attempt(function(selector) {
15198 * return document.querySelectorAll(selector);
15199 * }, '>_>');
15200 *
15201 * if (_.isError(elements)) {
15202 * elements = [];
15203 * }
15204 */
15205 var attempt = baseRest(function(func, args) {
15206 try {
15207 return apply(func, undefined, args);
15208 } catch (e) {
15209 return isError(e) ? e : new Error(e);
15210 }
15211 });
15212
15213 /**
15214 * Binds methods of an object to the object itself, overwriting the existing
15215 * method.
15216 *
15217 * **Note:** This method doesn't set the "length" property of bound functions.
15218 *
15219 * @static
15220 * @since 0.1.0
15221 * @memberOf _
15222 * @category Util
15223 * @param {Object} object The object to bind and assign the bound methods to.
15224 * @param {...(string|string[])} methodNames The object method names to bind.
15225 * @returns {Object} Returns `object`.
15226 * @example
15227 *
15228 * var view = {
15229 * 'label': 'docs',
15230 * 'click': function() {
15231 * console.log('clicked ' + this.label);
15232 * }
15233 * };
15234 *
15235 * _.bindAll(view, ['click']);
15236 * jQuery(element).on('click', view.click);
15237 * // => Logs 'clicked docs' when clicked.
15238 */
15239 var bindAll = flatRest(function(object, methodNames) {
15240 arrayEach(methodNames, function(key) {
15241 key = toKey(key);
15242 baseAssignValue(object, key, bind(object[key], object));
15243 });
15244 return object;
15245 });
15246
15247 /**
15248 * Creates a function that iterates over `pairs` and invokes the corresponding
15249 * function of the first predicate to return truthy. The predicate-function
15250 * pairs are invoked with the `this` binding and arguments of the created
15251 * function.
15252 *
15253 * @static
15254 * @memberOf _
15255 * @since 4.0.0
15256 * @category Util
15257 * @param {Array} pairs The predicate-function pairs.
15258 * @returns {Function} Returns the new composite function.
15259 * @example
15260 *
15261 * var func = _.cond([
15262 * [_.matches({ 'a': 1 }), _.constant('matches A')],
15263 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
15264 * [_.stubTrue, _.constant('no match')]
15265 * ]);
15266 *
15267 * func({ 'a': 1, 'b': 2 });
15268 * // => 'matches A'
15269 *
15270 * func({ 'a': 0, 'b': 1 });
15271 * // => 'matches B'
15272 *
15273 * func({ 'a': '1', 'b': '2' });
15274 * // => 'no match'
15275 */
15276 function cond(pairs) {
15277 var length = pairs == null ? 0 : pairs.length,
15278 toIteratee = getIteratee();
15279
15280 pairs = !length ? [] : arrayMap(pairs, function(pair) {
15281 if (typeof pair[1] != 'function') {
15282 throw new TypeError(FUNC_ERROR_TEXT);
15283 }
15284 return [toIteratee(pair[0]), pair[1]];
15285 });
15286
15287 return baseRest(function(args) {
15288 var index = -1;
15289 while (++index < length) {
15290 var pair = pairs[index];
15291 if (apply(pair[0], this, args)) {
15292 return apply(pair[1], this, args);
15293 }
15294 }
15295 });
15296 }
15297
15298 /**
15299 * Creates a function that invokes the predicate properties of `source` with
15300 * the corresponding property values of a given object, returning `true` if
15301 * all predicates return truthy, else `false`.
15302 *
15303 * **Note:** The created function is equivalent to `_.conformsTo` with
15304 * `source` partially applied.
15305 *
15306 * @static
15307 * @memberOf _
15308 * @since 4.0.0
15309 * @category Util
15310 * @param {Object} source The object of property predicates to conform to.
15311 * @returns {Function} Returns the new spec function.
15312 * @example
15313 *
15314 * var objects = [
15315 * { 'a': 2, 'b': 1 },
15316 * { 'a': 1, 'b': 2 }
15317 * ];
15318 *
15319 * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
15320 * // => [{ 'a': 1, 'b': 2 }]
15321 */
15322 function conforms(source) {
15323 return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
15324 }
15325
15326 /**
15327 * Creates a function that returns `value`.
15328 *
15329 * @static
15330 * @memberOf _
15331 * @since 2.4.0
15332 * @category Util
15333 * @param {*} value The value to return from the new function.
15334 * @returns {Function} Returns the new constant function.
15335 * @example
15336 *
15337 * var objects = _.times(2, _.constant({ 'a': 1 }));
15338 *
15339 * console.log(objects);
15340 * // => [{ 'a': 1 }, { 'a': 1 }]
15341 *
15342 * console.log(objects[0] === objects[1]);
15343 * // => true
15344 */
15345 function constant(value) {
15346 return function() {
15347 return value;
15348 };
15349 }
15350
15351 /**
15352 * Checks `value` to determine whether a default value should be returned in
15353 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
15354 * or `undefined`.
15355 *
15356 * @static
15357 * @memberOf _
15358 * @since 4.14.0
15359 * @category Util
15360 * @param {*} value The value to check.
15361 * @param {*} defaultValue The default value.
15362 * @returns {*} Returns the resolved value.
15363 * @example
15364 *
15365 * _.defaultTo(1, 10);
15366 * // => 1
15367 *
15368 * _.defaultTo(undefined, 10);
15369 * // => 10
15370 */
15371 function defaultTo(value, defaultValue) {
15372 return (value == null || value !== value) ? defaultValue : value;
15373 }
15374
15375 /**
15376 * Creates a function that returns the result of invoking the given functions
15377 * with the `this` binding of the created function, where each successive
15378 * invocation is supplied the return value of the previous.
15379 *
15380 * @static
15381 * @memberOf _
15382 * @since 3.0.0
15383 * @category Util
15384 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15385 * @returns {Function} Returns the new composite function.
15386 * @see _.flowRight
15387 * @example
15388 *
15389 * function square(n) {
15390 * return n * n;
15391 * }
15392 *
15393 * var addSquare = _.flow([_.add, square]);
15394 * addSquare(1, 2);
15395 * // => 9
15396 */
15397 var flow = createFlow();
15398
15399 /**
15400 * This method is like `_.flow` except that it creates a function that
15401 * invokes the given functions from right to left.
15402 *
15403 * @static
15404 * @since 3.0.0
15405 * @memberOf _
15406 * @category Util
15407 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15408 * @returns {Function} Returns the new composite function.
15409 * @see _.flow
15410 * @example
15411 *
15412 * function square(n) {
15413 * return n * n;
15414 * }
15415 *
15416 * var addSquare = _.flowRight([square, _.add]);
15417 * addSquare(1, 2);
15418 * // => 9
15419 */
15420 var flowRight = createFlow(true);
15421
15422 /**
15423 * This method returns the first argument it receives.
15424 *
15425 * @static
15426 * @since 0.1.0
15427 * @memberOf _
15428 * @category Util
15429 * @param {*} value Any value.
15430 * @returns {*} Returns `value`.
15431 * @example
15432 *
15433 * var object = { 'a': 1 };
15434 *
15435 * console.log(_.identity(object) === object);
15436 * // => true
15437 */
15438 function identity(value) {
15439 return value;
15440 }
15441
15442 /**
15443 * Creates a function that invokes `func` with the arguments of the created
15444 * function. If `func` is a property name, the created function returns the
15445 * property value for a given element. If `func` is an array or object, the
15446 * created function returns `true` for elements that contain the equivalent
15447 * source properties, otherwise it returns `false`.
15448 *
15449 * @static
15450 * @since 4.0.0
15451 * @memberOf _
15452 * @category Util
15453 * @param {*} [func=_.identity] The value to convert to a callback.
15454 * @returns {Function} Returns the callback.
15455 * @example
15456 *
15457 * var users = [
15458 * { 'user': 'barney', 'age': 36, 'active': true },
15459 * { 'user': 'fred', 'age': 40, 'active': false }
15460 * ];
15461 *
15462 * // The `_.matches` iteratee shorthand.
15463 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
15464 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
15465 *
15466 * // The `_.matchesProperty` iteratee shorthand.
15467 * _.filter(users, _.iteratee(['user', 'fred']));
15468 * // => [{ 'user': 'fred', 'age': 40 }]
15469 *
15470 * // The `_.property` iteratee shorthand.
15471 * _.map(users, _.iteratee('user'));
15472 * // => ['barney', 'fred']
15473 *
15474 * // Create custom iteratee shorthands.
15475 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
15476 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
15477 * return func.test(string);
15478 * };
15479 * });
15480 *
15481 * _.filter(['abc', 'def'], /ef/);
15482 * // => ['def']
15483 */
15484 function iteratee(func) {
15485 return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
15486 }
15487
15488 /**
15489 * Creates a function that performs a partial deep comparison between a given
15490 * object and `source`, returning `true` if the given object has equivalent
15491 * property values, else `false`.
15492 *
15493 * **Note:** The created function is equivalent to `_.isMatch` with `source`
15494 * partially applied.
15495 *
15496 * Partial comparisons will match empty array and empty object `source`
15497 * values against any array or object value, respectively. See `_.isEqual`
15498 * for a list of supported value comparisons.
15499 *
15500 * @static
15501 * @memberOf _
15502 * @since 3.0.0
15503 * @category Util
15504 * @param {Object} source The object of property values to match.
15505 * @returns {Function} Returns the new spec function.
15506 * @example
15507 *
15508 * var objects = [
15509 * { 'a': 1, 'b': 2, 'c': 3 },
15510 * { 'a': 4, 'b': 5, 'c': 6 }
15511 * ];
15512 *
15513 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
15514 * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
15515 */
15516 function matches(source) {
15517 return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
15518 }
15519
15520 /**
15521 * Creates a function that performs a partial deep comparison between the
15522 * value at `path` of a given object to `srcValue`, returning `true` if the
15523 * object value is equivalent, else `false`.
15524 *
15525 * **Note:** Partial comparisons will match empty array and empty object
15526 * `srcValue` values against any array or object value, respectively. See
15527 * `_.isEqual` for a list of supported value comparisons.
15528 *
15529 * @static
15530 * @memberOf _
15531 * @since 3.2.0
15532 * @category Util
15533 * @param {Array|string} path The path of the property to get.
15534 * @param {*} srcValue The value to match.
15535 * @returns {Function} Returns the new spec function.
15536 * @example
15537 *
15538 * var objects = [
15539 * { 'a': 1, 'b': 2, 'c': 3 },
15540 * { 'a': 4, 'b': 5, 'c': 6 }
15541 * ];
15542 *
15543 * _.find(objects, _.matchesProperty('a', 4));
15544 * // => { 'a': 4, 'b': 5, 'c': 6 }
15545 */
15546 function matchesProperty(path, srcValue) {
15547 return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
15548 }
15549
15550 /**
15551 * Creates a function that invokes the method at `path` of a given object.
15552 * Any additional arguments are provided to the invoked method.
15553 *
15554 * @static
15555 * @memberOf _
15556 * @since 3.7.0
15557 * @category Util
15558 * @param {Array|string} path The path of the method to invoke.
15559 * @param {...*} [args] The arguments to invoke the method with.
15560 * @returns {Function} Returns the new invoker function.
15561 * @example
15562 *
15563 * var objects = [
15564 * { 'a': { 'b': _.constant(2) } },
15565 * { 'a': { 'b': _.constant(1) } }
15566 * ];
15567 *
15568 * _.map(objects, _.method('a.b'));
15569 * // => [2, 1]
15570 *
15571 * _.map(objects, _.method(['a', 'b']));
15572 * // => [2, 1]
15573 */
15574 var method = baseRest(function(path, args) {
15575 return function(object) {
15576 return baseInvoke(object, path, args);
15577 };
15578 });
15579
15580 /**
15581 * The opposite of `_.method`; this method creates a function that invokes
15582 * the method at a given path of `object`. Any additional arguments are
15583 * provided to the invoked method.
15584 *
15585 * @static
15586 * @memberOf _
15587 * @since 3.7.0
15588 * @category Util
15589 * @param {Object} object The object to query.
15590 * @param {...*} [args] The arguments to invoke the method with.
15591 * @returns {Function} Returns the new invoker function.
15592 * @example
15593 *
15594 * var array = _.times(3, _.constant),
15595 * object = { 'a': array, 'b': array, 'c': array };
15596 *
15597 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
15598 * // => [2, 0]
15599 *
15600 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
15601 * // => [2, 0]
15602 */
15603 var methodOf = baseRest(function(object, args) {
15604 return function(path) {
15605 return baseInvoke(object, path, args);
15606 };
15607 });
15608
15609 /**
15610 * Adds all own enumerable string keyed function properties of a source
15611 * object to the destination object. If `object` is a function, then methods
15612 * are added to its prototype as well.
15613 *
15614 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
15615 * avoid conflicts caused by modifying the original.
15616 *
15617 * @static
15618 * @since 0.1.0
15619 * @memberOf _
15620 * @category Util
15621 * @param {Function|Object} [object=lodash] The destination object.
15622 * @param {Object} source The object of functions to add.
15623 * @param {Object} [options={}] The options object.
15624 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
15625 * @returns {Function|Object} Returns `object`.
15626 * @example
15627 *
15628 * function vowels(string) {
15629 * return _.filter(string, function(v) {
15630 * return /[aeiou]/i.test(v);
15631 * });
15632 * }
15633 *
15634 * _.mixin({ 'vowels': vowels });
15635 * _.vowels('fred');
15636 * // => ['e']
15637 *
15638 * _('fred').vowels().value();
15639 * // => ['e']
15640 *
15641 * _.mixin({ 'vowels': vowels }, { 'chain': false });
15642 * _('fred').vowels();
15643 * // => ['e']
15644 */
15645 function mixin(object, source, options) {
15646 var props = keys(source),
15647 methodNames = baseFunctions(source, props);
15648
15649 if (options == null &&
15650 !(isObject(source) && (methodNames.length || !props.length))) {
15651 options = source;
15652 source = object;
15653 object = this;
15654 methodNames = baseFunctions(source, keys(source));
15655 }
15656 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
15657 isFunc = isFunction(object);
15658
15659 arrayEach(methodNames, function(methodName) {
15660 var func = source[methodName];
15661 object[methodName] = func;
15662 if (isFunc) {
15663 object.prototype[methodName] = function() {
15664 var chainAll = this.__chain__;
15665 if (chain || chainAll) {
15666 var result = object(this.__wrapped__),
15667 actions = result.__actions__ = copyArray(this.__actions__);
15668
15669 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
15670 result.__chain__ = chainAll;
15671 return result;
15672 }
15673 return func.apply(object, arrayPush([this.value()], arguments));
15674 };
15675 }
15676 });
15677
15678 return object;
15679 }
15680
15681 /**
15682 * Reverts the `_` variable to its previous value and returns a reference to
15683 * the `lodash` function.
15684 *
15685 * @static
15686 * @since 0.1.0
15687 * @memberOf _
15688 * @category Util
15689 * @returns {Function} Returns the `lodash` function.
15690 * @example
15691 *
15692 * var lodash = _.noConflict();
15693 */
15694 function noConflict() {
15695 if (root._ === this) {
15696 root._ = oldDash;
15697 }
15698 return this;
15699 }
15700
15701 /**
15702 * This method returns `undefined`.
15703 *
15704 * @static
15705 * @memberOf _
15706 * @since 2.3.0
15707 * @category Util
15708 * @example
15709 *
15710 * _.times(2, _.noop);
15711 * // => [undefined, undefined]
15712 */
15713 function noop() {
15714 // No operation performed.
15715 }
15716
15717 /**
15718 * Creates a function that gets the argument at index `n`. If `n` is negative,
15719 * the nth argument from the end is returned.
15720 *
15721 * @static
15722 * @memberOf _
15723 * @since 4.0.0
15724 * @category Util
15725 * @param {number} [n=0] The index of the argument to return.
15726 * @returns {Function} Returns the new pass-thru function.
15727 * @example
15728 *
15729 * var func = _.nthArg(1);
15730 * func('a', 'b', 'c', 'd');
15731 * // => 'b'
15732 *
15733 * var func = _.nthArg(-2);
15734 * func('a', 'b', 'c', 'd');
15735 * // => 'c'
15736 */
15737 function nthArg(n) {
15738 n = toInteger(n);
15739 return baseRest(function(args) {
15740 return baseNth(args, n);
15741 });
15742 }
15743
15744 /**
15745 * Creates a function that invokes `iteratees` with the arguments it receives
15746 * and returns their results.
15747 *
15748 * @static
15749 * @memberOf _
15750 * @since 4.0.0
15751 * @category Util
15752 * @param {...(Function|Function[])} [iteratees=[_.identity]]
15753 * The iteratees to invoke.
15754 * @returns {Function} Returns the new function.
15755 * @example
15756 *
15757 * var func = _.over([Math.max, Math.min]);
15758 *
15759 * func(1, 2, 3, 4);
15760 * // => [4, 1]
15761 */
15762 var over = createOver(arrayMap);
15763
15764 /**
15765 * Creates a function that checks if **all** of the `predicates` return
15766 * truthy when invoked with the arguments it receives.
15767 *
15768 * @static
15769 * @memberOf _
15770 * @since 4.0.0
15771 * @category Util
15772 * @param {...(Function|Function[])} [predicates=[_.identity]]
15773 * The predicates to check.
15774 * @returns {Function} Returns the new function.
15775 * @example
15776 *
15777 * var func = _.overEvery([Boolean, isFinite]);
15778 *
15779 * func('1');
15780 * // => true
15781 *
15782 * func(null);
15783 * // => false
15784 *
15785 * func(NaN);
15786 * // => false
15787 */
15788 var overEvery = createOver(arrayEvery);
15789
15790 /**
15791 * Creates a function that checks if **any** of the `predicates` return
15792 * truthy when invoked with the arguments it receives.
15793 *
15794 * @static
15795 * @memberOf _
15796 * @since 4.0.0
15797 * @category Util
15798 * @param {...(Function|Function[])} [predicates=[_.identity]]
15799 * The predicates to check.
15800 * @returns {Function} Returns the new function.
15801 * @example
15802 *
15803 * var func = _.overSome([Boolean, isFinite]);
15804 *
15805 * func('1');
15806 * // => true
15807 *
15808 * func(null);
15809 * // => true
15810 *
15811 * func(NaN);
15812 * // => false
15813 */
15814 var overSome = createOver(arraySome);
15815
15816 /**
15817 * Creates a function that returns the value at `path` of a given object.
15818 *
15819 * @static
15820 * @memberOf _
15821 * @since 2.4.0
15822 * @category Util
15823 * @param {Array|string} path The path of the property to get.
15824 * @returns {Function} Returns the new accessor function.
15825 * @example
15826 *
15827 * var objects = [
15828 * { 'a': { 'b': 2 } },
15829 * { 'a': { 'b': 1 } }
15830 * ];
15831 *
15832 * _.map(objects, _.property('a.b'));
15833 * // => [2, 1]
15834 *
15835 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
15836 * // => [1, 2]
15837 */
15838 function property(path) {
15839 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
15840 }
15841
15842 /**
15843 * The opposite of `_.property`; this method creates a function that returns
15844 * the value at a given path of `object`.
15845 *
15846 * @static
15847 * @memberOf _
15848 * @since 3.0.0
15849 * @category Util
15850 * @param {Object} object The object to query.
15851 * @returns {Function} Returns the new accessor function.
15852 * @example
15853 *
15854 * var array = [0, 1, 2],
15855 * object = { 'a': array, 'b': array, 'c': array };
15856 *
15857 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
15858 * // => [2, 0]
15859 *
15860 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
15861 * // => [2, 0]
15862 */
15863 function propertyOf(object) {
15864 return function(path) {
15865 return object == null ? undefined : baseGet(object, path);
15866 };
15867 }
15868
15869 /**
15870 * Creates an array of numbers (positive and/or negative) progressing from
15871 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
15872 * `start` is specified without an `end` or `step`. If `end` is not specified,
15873 * it's set to `start` with `start` then set to `0`.
15874 *
15875 * **Note:** JavaScript follows the IEEE-754 standard for resolving
15876 * floating-point values which can produce unexpected results.
15877 *
15878 * @static
15879 * @since 0.1.0
15880 * @memberOf _
15881 * @category Util
15882 * @param {number} [start=0] The start of the range.
15883 * @param {number} end The end of the range.
15884 * @param {number} [step=1] The value to increment or decrement by.
15885 * @returns {Array} Returns the range of numbers.
15886 * @see _.inRange, _.rangeRight
15887 * @example
15888 *
15889 * _.range(4);
15890 * // => [0, 1, 2, 3]
15891 *
15892 * _.range(-4);
15893 * // => [0, -1, -2, -3]
15894 *
15895 * _.range(1, 5);
15896 * // => [1, 2, 3, 4]
15897 *
15898 * _.range(0, 20, 5);
15899 * // => [0, 5, 10, 15]
15900 *
15901 * _.range(0, -4, -1);
15902 * // => [0, -1, -2, -3]
15903 *
15904 * _.range(1, 4, 0);
15905 * // => [1, 1, 1]
15906 *
15907 * _.range(0);
15908 * // => []
15909 */
15910 var range = createRange();
15911
15912 /**
15913 * This method is like `_.range` except that it populates values in
15914 * descending order.
15915 *
15916 * @static
15917 * @memberOf _
15918 * @since 4.0.0
15919 * @category Util
15920 * @param {number} [start=0] The start of the range.
15921 * @param {number} end The end of the range.
15922 * @param {number} [step=1] The value to increment or decrement by.
15923 * @returns {Array} Returns the range of numbers.
15924 * @see _.inRange, _.range
15925 * @example
15926 *
15927 * _.rangeRight(4);
15928 * // => [3, 2, 1, 0]
15929 *
15930 * _.rangeRight(-4);
15931 * // => [-3, -2, -1, 0]
15932 *
15933 * _.rangeRight(1, 5);
15934 * // => [4, 3, 2, 1]
15935 *
15936 * _.rangeRight(0, 20, 5);
15937 * // => [15, 10, 5, 0]
15938 *
15939 * _.rangeRight(0, -4, -1);
15940 * // => [-3, -2, -1, 0]
15941 *
15942 * _.rangeRight(1, 4, 0);
15943 * // => [1, 1, 1]
15944 *
15945 * _.rangeRight(0);
15946 * // => []
15947 */
15948 var rangeRight = createRange(true);
15949
15950 /**
15951 * This method returns a new empty array.
15952 *
15953 * @static
15954 * @memberOf _
15955 * @since 4.13.0
15956 * @category Util
15957 * @returns {Array} Returns the new empty array.
15958 * @example
15959 *
15960 * var arrays = _.times(2, _.stubArray);
15961 *
15962 * console.log(arrays);
15963 * // => [[], []]
15964 *
15965 * console.log(arrays[0] === arrays[1]);
15966 * // => false
15967 */
15968 function stubArray() {
15969 return [];
15970 }
15971
15972 /**
15973 * This method returns `false`.
15974 *
15975 * @static
15976 * @memberOf _
15977 * @since 4.13.0
15978 * @category Util
15979 * @returns {boolean} Returns `false`.
15980 * @example
15981 *
15982 * _.times(2, _.stubFalse);
15983 * // => [false, false]
15984 */
15985 function stubFalse() {
15986 return false;
15987 }
15988
15989 /**
15990 * This method returns a new empty object.
15991 *
15992 * @static
15993 * @memberOf _
15994 * @since 4.13.0
15995 * @category Util
15996 * @returns {Object} Returns the new empty object.
15997 * @example
15998 *
15999 * var objects = _.times(2, _.stubObject);
16000 *
16001 * console.log(objects);
16002 * // => [{}, {}]
16003 *
16004 * console.log(objects[0] === objects[1]);
16005 * // => false
16006 */
16007 function stubObject() {
16008 return {};
16009 }
16010
16011 /**
16012 * This method returns an empty string.
16013 *
16014 * @static
16015 * @memberOf _
16016 * @since 4.13.0
16017 * @category Util
16018 * @returns {string} Returns the empty string.
16019 * @example
16020 *
16021 * _.times(2, _.stubString);
16022 * // => ['', '']
16023 */
16024 function stubString() {
16025 return '';
16026 }
16027
16028 /**
16029 * This method returns `true`.
16030 *
16031 * @static
16032 * @memberOf _
16033 * @since 4.13.0
16034 * @category Util
16035 * @returns {boolean} Returns `true`.
16036 * @example
16037 *
16038 * _.times(2, _.stubTrue);
16039 * // => [true, true]
16040 */
16041 function stubTrue() {
16042 return true;
16043 }
16044
16045 /**
16046 * Invokes the iteratee `n` times, returning an array of the results of
16047 * each invocation. The iteratee is invoked with one argument; (index).
16048 *
16049 * @static
16050 * @since 0.1.0
16051 * @memberOf _
16052 * @category Util
16053 * @param {number} n The number of times to invoke `iteratee`.
16054 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
16055 * @returns {Array} Returns the array of results.
16056 * @example
16057 *
16058 * _.times(3, String);
16059 * // => ['0', '1', '2']
16060 *
16061 * _.times(4, _.constant(0));
16062 * // => [0, 0, 0, 0]
16063 */
16064 function times(n, iteratee) {
16065 n = toInteger(n);
16066 if (n < 1 || n > MAX_SAFE_INTEGER) {
16067 return [];
16068 }
16069 var index = MAX_ARRAY_LENGTH,
16070 length = nativeMin(n, MAX_ARRAY_LENGTH);
16071
16072 iteratee = getIteratee(iteratee);
16073 n -= MAX_ARRAY_LENGTH;
16074
16075 var result = baseTimes(length, iteratee);
16076 while (++index < n) {
16077 iteratee(index);
16078 }
16079 return result;
16080 }
16081
16082 /**
16083 * Converts `value` to a property path array.
16084 *
16085 * @static
16086 * @memberOf _
16087 * @since 4.0.0
16088 * @category Util
16089 * @param {*} value The value to convert.
16090 * @returns {Array} Returns the new property path array.
16091 * @example
16092 *
16093 * _.toPath('a.b.c');
16094 * // => ['a', 'b', 'c']
16095 *
16096 * _.toPath('a[0].b.c');
16097 * // => ['a', '0', 'b', 'c']
16098 */
16099 function toPath(value) {
16100 if (isArray(value)) {
16101 return arrayMap(value, toKey);
16102 }
16103 return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
16104 }
16105
16106 /**
16107 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
16108 *
16109 * @static
16110 * @since 0.1.0
16111 * @memberOf _
16112 * @category Util
16113 * @param {string} [prefix=''] The value to prefix the ID with.
16114 * @returns {string} Returns the unique ID.
16115 * @example
16116 *
16117 * _.uniqueId('contact_');
16118 * // => 'contact_104'
16119 *
16120 * _.uniqueId();
16121 * // => '105'
16122 */
16123 function uniqueId(prefix) {
16124 var id = ++idCounter;
16125 return toString(prefix) + id;
16126 }
16127
16128 /*------------------------------------------------------------------------*/
16129
16130 /**
16131 * Adds two numbers.
16132 *
16133 * @static
16134 * @memberOf _
16135 * @since 3.4.0
16136 * @category Math
16137 * @param {number} augend The first number in an addition.
16138 * @param {number} addend The second number in an addition.
16139 * @returns {number} Returns the total.
16140 * @example
16141 *
16142 * _.add(6, 4);
16143 * // => 10
16144 */
16145 var add = createMathOperation(function(augend, addend) {
16146 return augend + addend;
16147 }, 0);
16148
16149 /**
16150 * Computes `number` rounded up to `precision`.
16151 *
16152 * @static
16153 * @memberOf _
16154 * @since 3.10.0
16155 * @category Math
16156 * @param {number} number The number to round up.
16157 * @param {number} [precision=0] The precision to round up to.
16158 * @returns {number} Returns the rounded up number.
16159 * @example
16160 *
16161 * _.ceil(4.006);
16162 * // => 5
16163 *
16164 * _.ceil(6.004, 2);
16165 * // => 6.01
16166 *
16167 * _.ceil(6040, -2);
16168 * // => 6100
16169 */
16170 var ceil = createRound('ceil');
16171
16172 /**
16173 * Divide two numbers.
16174 *
16175 * @static
16176 * @memberOf _
16177 * @since 4.7.0
16178 * @category Math
16179 * @param {number} dividend The first number in a division.
16180 * @param {number} divisor The second number in a division.
16181 * @returns {number} Returns the quotient.
16182 * @example
16183 *
16184 * _.divide(6, 4);
16185 * // => 1.5
16186 */
16187 var divide = createMathOperation(function(dividend, divisor) {
16188 return dividend / divisor;
16189 }, 1);
16190
16191 /**
16192 * Computes `number` rounded down to `precision`.
16193 *
16194 * @static
16195 * @memberOf _
16196 * @since 3.10.0
16197 * @category Math
16198 * @param {number} number The number to round down.
16199 * @param {number} [precision=0] The precision to round down to.
16200 * @returns {number} Returns the rounded down number.
16201 * @example
16202 *
16203 * _.floor(4.006);
16204 * // => 4
16205 *
16206 * _.floor(0.046, 2);
16207 * // => 0.04
16208 *
16209 * _.floor(4060, -2);
16210 * // => 4000
16211 */
16212 var floor = createRound('floor');
16213
16214 /**
16215 * Computes the maximum value of `array`. If `array` is empty or falsey,
16216 * `undefined` is returned.
16217 *
16218 * @static
16219 * @since 0.1.0
16220 * @memberOf _
16221 * @category Math
16222 * @param {Array} array The array to iterate over.
16223 * @returns {*} Returns the maximum value.
16224 * @example
16225 *
16226 * _.max([4, 2, 8, 6]);
16227 * // => 8
16228 *
16229 * _.max([]);
16230 * // => undefined
16231 */
16232 function max(array) {
16233 return (array && array.length)
16234 ? baseExtremum(array, identity, baseGt)
16235 : undefined;
16236 }
16237
16238 /**
16239 * This method is like `_.max` except that it accepts `iteratee` which is
16240 * invoked for each element in `array` to generate the criterion by which
16241 * the value is ranked. The iteratee is invoked with one argument: (value).
16242 *
16243 * @static
16244 * @memberOf _
16245 * @since 4.0.0
16246 * @category Math
16247 * @param {Array} array The array to iterate over.
16248 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16249 * @returns {*} Returns the maximum value.
16250 * @example
16251 *
16252 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16253 *
16254 * _.maxBy(objects, function(o) { return o.n; });
16255 * // => { 'n': 2 }
16256 *
16257 * // The `_.property` iteratee shorthand.
16258 * _.maxBy(objects, 'n');
16259 * // => { 'n': 2 }
16260 */
16261 function maxBy(array, iteratee) {
16262 return (array && array.length)
16263 ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
16264 : undefined;
16265 }
16266
16267 /**
16268 * Computes the mean of the values in `array`.
16269 *
16270 * @static
16271 * @memberOf _
16272 * @since 4.0.0
16273 * @category Math
16274 * @param {Array} array The array to iterate over.
16275 * @returns {number} Returns the mean.
16276 * @example
16277 *
16278 * _.mean([4, 2, 8, 6]);
16279 * // => 5
16280 */
16281 function mean(array) {
16282 return baseMean(array, identity);
16283 }
16284
16285 /**
16286 * This method is like `_.mean` except that it accepts `iteratee` which is
16287 * invoked for each element in `array` to generate the value to be averaged.
16288 * The iteratee is invoked with one argument: (value).
16289 *
16290 * @static
16291 * @memberOf _
16292 * @since 4.7.0
16293 * @category Math
16294 * @param {Array} array The array to iterate over.
16295 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16296 * @returns {number} Returns the mean.
16297 * @example
16298 *
16299 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16300 *
16301 * _.meanBy(objects, function(o) { return o.n; });
16302 * // => 5
16303 *
16304 * // The `_.property` iteratee shorthand.
16305 * _.meanBy(objects, 'n');
16306 * // => 5
16307 */
16308 function meanBy(array, iteratee) {
16309 return baseMean(array, getIteratee(iteratee, 2));
16310 }
16311
16312 /**
16313 * Computes the minimum value of `array`. If `array` is empty or falsey,
16314 * `undefined` is returned.
16315 *
16316 * @static
16317 * @since 0.1.0
16318 * @memberOf _
16319 * @category Math
16320 * @param {Array} array The array to iterate over.
16321 * @returns {*} Returns the minimum value.
16322 * @example
16323 *
16324 * _.min([4, 2, 8, 6]);
16325 * // => 2
16326 *
16327 * _.min([]);
16328 * // => undefined
16329 */
16330 function min(array) {
16331 return (array && array.length)
16332 ? baseExtremum(array, identity, baseLt)
16333 : undefined;
16334 }
16335
16336 /**
16337 * This method is like `_.min` except that it accepts `iteratee` which is
16338 * invoked for each element in `array` to generate the criterion by which
16339 * the value is ranked. The iteratee is invoked with one argument: (value).
16340 *
16341 * @static
16342 * @memberOf _
16343 * @since 4.0.0
16344 * @category Math
16345 * @param {Array} array The array to iterate over.
16346 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16347 * @returns {*} Returns the minimum value.
16348 * @example
16349 *
16350 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16351 *
16352 * _.minBy(objects, function(o) { return o.n; });
16353 * // => { 'n': 1 }
16354 *
16355 * // The `_.property` iteratee shorthand.
16356 * _.minBy(objects, 'n');
16357 * // => { 'n': 1 }
16358 */
16359 function minBy(array, iteratee) {
16360 return (array && array.length)
16361 ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
16362 : undefined;
16363 }
16364
16365 /**
16366 * Multiply two numbers.
16367 *
16368 * @static
16369 * @memberOf _
16370 * @since 4.7.0
16371 * @category Math
16372 * @param {number} multiplier The first number in a multiplication.
16373 * @param {number} multiplicand The second number in a multiplication.
16374 * @returns {number} Returns the product.
16375 * @example
16376 *
16377 * _.multiply(6, 4);
16378 * // => 24
16379 */
16380 var multiply = createMathOperation(function(multiplier, multiplicand) {
16381 return multiplier * multiplicand;
16382 }, 1);
16383
16384 /**
16385 * Computes `number` rounded to `precision`.
16386 *
16387 * @static
16388 * @memberOf _
16389 * @since 3.10.0
16390 * @category Math
16391 * @param {number} number The number to round.
16392 * @param {number} [precision=0] The precision to round to.
16393 * @returns {number} Returns the rounded number.
16394 * @example
16395 *
16396 * _.round(4.006);
16397 * // => 4
16398 *
16399 * _.round(4.006, 2);
16400 * // => 4.01
16401 *
16402 * _.round(4060, -2);
16403 * // => 4100
16404 */
16405 var round = createRound('round');
16406
16407 /**
16408 * Subtract two numbers.
16409 *
16410 * @static
16411 * @memberOf _
16412 * @since 4.0.0
16413 * @category Math
16414 * @param {number} minuend The first number in a subtraction.
16415 * @param {number} subtrahend The second number in a subtraction.
16416 * @returns {number} Returns the difference.
16417 * @example
16418 *
16419 * _.subtract(6, 4);
16420 * // => 2
16421 */
16422 var subtract = createMathOperation(function(minuend, subtrahend) {
16423 return minuend - subtrahend;
16424 }, 0);
16425
16426 /**
16427 * Computes the sum of the values in `array`.
16428 *
16429 * @static
16430 * @memberOf _
16431 * @since 3.4.0
16432 * @category Math
16433 * @param {Array} array The array to iterate over.
16434 * @returns {number} Returns the sum.
16435 * @example
16436 *
16437 * _.sum([4, 2, 8, 6]);
16438 * // => 20
16439 */
16440 function sum(array) {
16441 return (array && array.length)
16442 ? baseSum(array, identity)
16443 : 0;
16444 }
16445
16446 /**
16447 * This method is like `_.sum` except that it accepts `iteratee` which is
16448 * invoked for each element in `array` to generate the value to be summed.
16449 * The iteratee is invoked with one argument: (value).
16450 *
16451 * @static
16452 * @memberOf _
16453 * @since 4.0.0
16454 * @category Math
16455 * @param {Array} array The array to iterate over.
16456 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16457 * @returns {number} Returns the sum.
16458 * @example
16459 *
16460 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16461 *
16462 * _.sumBy(objects, function(o) { return o.n; });
16463 * // => 20
16464 *
16465 * // The `_.property` iteratee shorthand.
16466 * _.sumBy(objects, 'n');
16467 * // => 20
16468 */
16469 function sumBy(array, iteratee) {
16470 return (array && array.length)
16471 ? baseSum(array, getIteratee(iteratee, 2))
16472 : 0;
16473 }
16474
16475 /*------------------------------------------------------------------------*/
16476
16477 // Add methods that return wrapped values in chain sequences.
16478 lodash.after = after;
16479 lodash.ary = ary;
16480 lodash.assign = assign;
16481 lodash.assignIn = assignIn;
16482 lodash.assignInWith = assignInWith;
16483 lodash.assignWith = assignWith;
16484 lodash.at = at;
16485 lodash.before = before;
16486 lodash.bind = bind;
16487 lodash.bindAll = bindAll;
16488 lodash.bindKey = bindKey;
16489 lodash.castArray = castArray;
16490 lodash.chain = chain;
16491 lodash.chunk = chunk;
16492 lodash.compact = compact;
16493 lodash.concat = concat;
16494 lodash.cond = cond;
16495 lodash.conforms = conforms;
16496 lodash.constant = constant;
16497 lodash.countBy = countBy;
16498 lodash.create = create;
16499 lodash.curry = curry;
16500 lodash.curryRight = curryRight;
16501 lodash.debounce = debounce;
16502 lodash.defaults = defaults;
16503 lodash.defaultsDeep = defaultsDeep;
16504 lodash.defer = defer;
16505 lodash.delay = delay;
16506 lodash.difference = difference;
16507 lodash.differenceBy = differenceBy;
16508 lodash.differenceWith = differenceWith;
16509 lodash.drop = drop;
16510 lodash.dropRight = dropRight;
16511 lodash.dropRightWhile = dropRightWhile;
16512 lodash.dropWhile = dropWhile;
16513 lodash.fill = fill;
16514 lodash.filter = filter;
16515 lodash.flatMap = flatMap;
16516 lodash.flatMapDeep = flatMapDeep;
16517 lodash.flatMapDepth = flatMapDepth;
16518 lodash.flatten = flatten;
16519 lodash.flattenDeep = flattenDeep;
16520 lodash.flattenDepth = flattenDepth;
16521 lodash.flip = flip;
16522 lodash.flow = flow;
16523 lodash.flowRight = flowRight;
16524 lodash.fromPairs = fromPairs;
16525 lodash.functions = functions;
16526 lodash.functionsIn = functionsIn;
16527 lodash.groupBy = groupBy;
16528 lodash.initial = initial;
16529 lodash.intersection = intersection;
16530 lodash.intersectionBy = intersectionBy;
16531 lodash.intersectionWith = intersectionWith;
16532 lodash.invert = invert;
16533 lodash.invertBy = invertBy;
16534 lodash.invokeMap = invokeMap;
16535 lodash.iteratee = iteratee;
16536 lodash.keyBy = keyBy;
16537 lodash.keys = keys;
16538 lodash.keysIn = keysIn;
16539 lodash.map = map;
16540 lodash.mapKeys = mapKeys;
16541 lodash.mapValues = mapValues;
16542 lodash.matches = matches;
16543 lodash.matchesProperty = matchesProperty;
16544 lodash.memoize = memoize;
16545 lodash.merge = merge;
16546 lodash.mergeWith = mergeWith;
16547 lodash.method = method;
16548 lodash.methodOf = methodOf;
16549 lodash.mixin = mixin;
16550 lodash.negate = negate;
16551 lodash.nthArg = nthArg;
16552 lodash.omit = omit;
16553 lodash.omitBy = omitBy;
16554 lodash.once = once;
16555 lodash.orderBy = orderBy;
16556 lodash.over = over;
16557 lodash.overArgs = overArgs;
16558 lodash.overEvery = overEvery;
16559 lodash.overSome = overSome;
16560 lodash.partial = partial;
16561 lodash.partialRight = partialRight;
16562 lodash.partition = partition;
16563 lodash.pick = pick;
16564 lodash.pickBy = pickBy;
16565 lodash.property = property;
16566 lodash.propertyOf = propertyOf;
16567 lodash.pull = pull;
16568 lodash.pullAll = pullAll;
16569 lodash.pullAllBy = pullAllBy;
16570 lodash.pullAllWith = pullAllWith;
16571 lodash.pullAt = pullAt;
16572 lodash.range = range;
16573 lodash.rangeRight = rangeRight;
16574 lodash.rearg = rearg;
16575 lodash.reject = reject;
16576 lodash.remove = remove;
16577 lodash.rest = rest;
16578 lodash.reverse = reverse;
16579 lodash.sampleSize = sampleSize;
16580 lodash.set = set;
16581 lodash.setWith = setWith;
16582 lodash.shuffle = shuffle;
16583 lodash.slice = slice;
16584 lodash.sortBy = sortBy;
16585 lodash.sortedUniq = sortedUniq;
16586 lodash.sortedUniqBy = sortedUniqBy;
16587 lodash.split = split;
16588 lodash.spread = spread;
16589 lodash.tail = tail;
16590 lodash.take = take;
16591 lodash.takeRight = takeRight;
16592 lodash.takeRightWhile = takeRightWhile;
16593 lodash.takeWhile = takeWhile;
16594 lodash.tap = tap;
16595 lodash.throttle = throttle;
16596 lodash.thru = thru;
16597 lodash.toArray = toArray;
16598 lodash.toPairs = toPairs;
16599 lodash.toPairsIn = toPairsIn;
16600 lodash.toPath = toPath;
16601 lodash.toPlainObject = toPlainObject;
16602 lodash.transform = transform;
16603 lodash.unary = unary;
16604 lodash.union = union;
16605 lodash.unionBy = unionBy;
16606 lodash.unionWith = unionWith;
16607 lodash.uniq = uniq;
16608 lodash.uniqBy = uniqBy;
16609 lodash.uniqWith = uniqWith;
16610 lodash.unset = unset;
16611 lodash.unzip = unzip;
16612 lodash.unzipWith = unzipWith;
16613 lodash.update = update;
16614 lodash.updateWith = updateWith;
16615 lodash.values = values;
16616 lodash.valuesIn = valuesIn;
16617 lodash.without = without;
16618 lodash.words = words;
16619 lodash.wrap = wrap;
16620 lodash.xor = xor;
16621 lodash.xorBy = xorBy;
16622 lodash.xorWith = xorWith;
16623 lodash.zip = zip;
16624 lodash.zipObject = zipObject;
16625 lodash.zipObjectDeep = zipObjectDeep;
16626 lodash.zipWith = zipWith;
16627
16628 // Add aliases.
16629 lodash.entries = toPairs;
16630 lodash.entriesIn = toPairsIn;
16631 lodash.extend = assignIn;
16632 lodash.extendWith = assignInWith;
16633
16634 // Add methods to `lodash.prototype`.
16635 mixin(lodash, lodash);
16636
16637 /*------------------------------------------------------------------------*/
16638
16639 // Add methods that return unwrapped values in chain sequences.
16640 lodash.add = add;
16641 lodash.attempt = attempt;
16642 lodash.camelCase = camelCase;
16643 lodash.capitalize = capitalize;
16644 lodash.ceil = ceil;
16645 lodash.clamp = clamp;
16646 lodash.clone = clone;
16647 lodash.cloneDeep = cloneDeep;
16648 lodash.cloneDeepWith = cloneDeepWith;
16649 lodash.cloneWith = cloneWith;
16650 lodash.conformsTo = conformsTo;
16651 lodash.deburr = deburr;
16652 lodash.defaultTo = defaultTo;
16653 lodash.divide = divide;
16654 lodash.endsWith = endsWith;
16655 lodash.eq = eq;
16656 lodash.escape = escape;
16657 lodash.escapeRegExp = escapeRegExp;
16658 lodash.every = every;
16659 lodash.find = find;
16660 lodash.findIndex = findIndex;
16661 lodash.findKey = findKey;
16662 lodash.findLast = findLast;
16663 lodash.findLastIndex = findLastIndex;
16664 lodash.findLastKey = findLastKey;
16665 lodash.floor = floor;
16666 lodash.forEach = forEach;
16667 lodash.forEachRight = forEachRight;
16668 lodash.forIn = forIn;
16669 lodash.forInRight = forInRight;
16670 lodash.forOwn = forOwn;
16671 lodash.forOwnRight = forOwnRight;
16672 lodash.get = get;
16673 lodash.gt = gt;
16674 lodash.gte = gte;
16675 lodash.has = has;
16676 lodash.hasIn = hasIn;
16677 lodash.head = head;
16678 lodash.identity = identity;
16679 lodash.includes = includes;
16680 lodash.indexOf = indexOf;
16681 lodash.inRange = inRange;
16682 lodash.invoke = invoke;
16683 lodash.isArguments = isArguments;
16684 lodash.isArray = isArray;
16685 lodash.isArrayBuffer = isArrayBuffer;
16686 lodash.isArrayLike = isArrayLike;
16687 lodash.isArrayLikeObject = isArrayLikeObject;
16688 lodash.isBoolean = isBoolean;
16689 lodash.isBuffer = isBuffer;
16690 lodash.isDate = isDate;
16691 lodash.isElement = isElement;
16692 lodash.isEmpty = isEmpty;
16693 lodash.isEqual = isEqual;
16694 lodash.isEqualWith = isEqualWith;
16695 lodash.isError = isError;
16696 lodash.isFinite = isFinite;
16697 lodash.isFunction = isFunction;
16698 lodash.isInteger = isInteger;
16699 lodash.isLength = isLength;
16700 lodash.isMap = isMap;
16701 lodash.isMatch = isMatch;
16702 lodash.isMatchWith = isMatchWith;
16703 lodash.isNaN = isNaN;
16704 lodash.isNative = isNative;
16705 lodash.isNil = isNil;
16706 lodash.isNull = isNull;
16707 lodash.isNumber = isNumber;
16708 lodash.isObject = isObject;
16709 lodash.isObjectLike = isObjectLike;
16710 lodash.isPlainObject = isPlainObject;
16711 lodash.isRegExp = isRegExp;
16712 lodash.isSafeInteger = isSafeInteger;
16713 lodash.isSet = isSet;
16714 lodash.isString = isString;
16715 lodash.isSymbol = isSymbol;
16716 lodash.isTypedArray = isTypedArray;
16717 lodash.isUndefined = isUndefined;
16718 lodash.isWeakMap = isWeakMap;
16719 lodash.isWeakSet = isWeakSet;
16720 lodash.join = join;
16721 lodash.kebabCase = kebabCase;
16722 lodash.last = last;
16723 lodash.lastIndexOf = lastIndexOf;
16724 lodash.lowerCase = lowerCase;
16725 lodash.lowerFirst = lowerFirst;
16726 lodash.lt = lt;
16727 lodash.lte = lte;
16728 lodash.max = max;
16729 lodash.maxBy = maxBy;
16730 lodash.mean = mean;
16731 lodash.meanBy = meanBy;
16732 lodash.min = min;
16733 lodash.minBy = minBy;
16734 lodash.stubArray = stubArray;
16735 lodash.stubFalse = stubFalse;
16736 lodash.stubObject = stubObject;
16737 lodash.stubString = stubString;
16738 lodash.stubTrue = stubTrue;
16739 lodash.multiply = multiply;
16740 lodash.nth = nth;
16741 lodash.noConflict = noConflict;
16742 lodash.noop = noop;
16743 lodash.now = now;
16744 lodash.pad = pad;
16745 lodash.padEnd = padEnd;
16746 lodash.padStart = padStart;
16747 lodash.parseInt = parseInt;
16748 lodash.random = random;
16749 lodash.reduce = reduce;
16750 lodash.reduceRight = reduceRight;
16751 lodash.repeat = repeat;
16752 lodash.replace = replace;
16753 lodash.result = result;
16754 lodash.round = round;
16755 lodash.runInContext = runInContext;
16756 lodash.sample = sample;
16757 lodash.size = size;
16758 lodash.snakeCase = snakeCase;
16759 lodash.some = some;
16760 lodash.sortedIndex = sortedIndex;
16761 lodash.sortedIndexBy = sortedIndexBy;
16762 lodash.sortedIndexOf = sortedIndexOf;
16763 lodash.sortedLastIndex = sortedLastIndex;
16764 lodash.sortedLastIndexBy = sortedLastIndexBy;
16765 lodash.sortedLastIndexOf = sortedLastIndexOf;
16766 lodash.startCase = startCase;
16767 lodash.startsWith = startsWith;
16768 lodash.subtract = subtract;
16769 lodash.sum = sum;
16770 lodash.sumBy = sumBy;
16771 lodash.template = template;
16772 lodash.times = times;
16773 lodash.toFinite = toFinite;
16774 lodash.toInteger = toInteger;
16775 lodash.toLength = toLength;
16776 lodash.toLower = toLower;
16777 lodash.toNumber = toNumber;
16778 lodash.toSafeInteger = toSafeInteger;
16779 lodash.toString = toString;
16780 lodash.toUpper = toUpper;
16781 lodash.trim = trim;
16782 lodash.trimEnd = trimEnd;
16783 lodash.trimStart = trimStart;
16784 lodash.truncate = truncate;
16785 lodash.unescape = unescape;
16786 lodash.uniqueId = uniqueId;
16787 lodash.upperCase = upperCase;
16788 lodash.upperFirst = upperFirst;
16789
16790 // Add aliases.
16791 lodash.each = forEach;
16792 lodash.eachRight = forEachRight;
16793 lodash.first = head;
16794
16795 mixin(lodash, (function() {
16796 var source = {};
16797 baseForOwn(lodash, function(func, methodName) {
16798 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
16799 source[methodName] = func;
16800 }
16801 });
16802 return source;
16803 }()), { 'chain': false });
16804
16805 /*------------------------------------------------------------------------*/
16806
16807 /**
16808 * The semantic version number.
16809 *
16810 * @static
16811 * @memberOf _
16812 * @type {string}
16813 */
16814 lodash.VERSION = VERSION;
16815
16816 // Assign default placeholders.
16817 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
16818 lodash[methodName].placeholder = lodash;
16819 });
16820
16821 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
16822 arrayEach(['drop', 'take'], function(methodName, index) {
16823 LazyWrapper.prototype[methodName] = function(n) {
16824 var filtered = this.__filtered__;
16825 if (filtered && !index) {
16826 return new LazyWrapper(this);
16827 }
16828 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
16829
16830 var result = this.clone();
16831 if (filtered) {
16832 result.__takeCount__ = nativeMin(n, result.__takeCount__);
16833 } else {
16834 result.__views__.push({
16835 'size': nativeMin(n, MAX_ARRAY_LENGTH),
16836 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
16837 });
16838 }
16839 return result;
16840 };
16841
16842 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
16843 return this.reverse()[methodName](n).reverse();
16844 };
16845 });
16846
16847 // Add `LazyWrapper` methods that accept an `iteratee` value.
16848 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
16849 var type = index + 1,
16850 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
16851
16852 LazyWrapper.prototype[methodName] = function(iteratee) {
16853 var result = this.clone();
16854 result.__iteratees__.push({
16855 'iteratee': getIteratee(iteratee, 3),
16856 'type': type
16857 });
16858 result.__filtered__ = result.__filtered__ || isFilter;
16859 return result;
16860 };
16861 });
16862
16863 // Add `LazyWrapper` methods for `_.head` and `_.last`.
16864 arrayEach(['head', 'last'], function(methodName, index) {
16865 var takeName = 'take' + (index ? 'Right' : '');
16866
16867 LazyWrapper.prototype[methodName] = function() {
16868 return this[takeName](1).value()[0];
16869 };
16870 });
16871
16872 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
16873 arrayEach(['initial', 'tail'], function(methodName, index) {
16874 var dropName = 'drop' + (index ? '' : 'Right');
16875
16876 LazyWrapper.prototype[methodName] = function() {
16877 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
16878 };
16879 });
16880
16881 LazyWrapper.prototype.compact = function() {
16882 return this.filter(identity);
16883 };
16884
16885 LazyWrapper.prototype.find = function(predicate) {
16886 return this.filter(predicate).head();
16887 };
16888
16889 LazyWrapper.prototype.findLast = function(predicate) {
16890 return this.reverse().find(predicate);
16891 };
16892
16893 LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
16894 if (typeof path == 'function') {
16895 return new LazyWrapper(this);
16896 }
16897 return this.map(function(value) {
16898 return baseInvoke(value, path, args);
16899 });
16900 });
16901
16902 LazyWrapper.prototype.reject = function(predicate) {
16903 return this.filter(negate(getIteratee(predicate)));
16904 };
16905
16906 LazyWrapper.prototype.slice = function(start, end) {
16907 start = toInteger(start);
16908
16909 var result = this;
16910 if (result.__filtered__ && (start > 0 || end < 0)) {
16911 return new LazyWrapper(result);
16912 }
16913 if (start < 0) {
16914 result = result.takeRight(-start);
16915 } else if (start) {
16916 result = result.drop(start);
16917 }
16918 if (end !== undefined) {
16919 end = toInteger(end);
16920 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
16921 }
16922 return result;
16923 };
16924
16925 LazyWrapper.prototype.takeRightWhile = function(predicate) {
16926 return this.reverse().takeWhile(predicate).reverse();
16927 };
16928
16929 LazyWrapper.prototype.toArray = function() {
16930 return this.take(MAX_ARRAY_LENGTH);
16931 };
16932
16933 // Add `LazyWrapper` methods to `lodash.prototype`.
16934 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16935 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
16936 isTaker = /^(?:head|last)$/.test(methodName),
16937 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
16938 retUnwrapped = isTaker || /^find/.test(methodName);
16939
16940 if (!lodashFunc) {
16941 return;
16942 }
16943 lodash.prototype[methodName] = function() {
16944 var value = this.__wrapped__,
16945 args = isTaker ? [1] : arguments,
16946 isLazy = value instanceof LazyWrapper,
16947 iteratee = args[0],
16948 useLazy = isLazy || isArray(value);
16949
16950 var interceptor = function(value) {
16951 var result = lodashFunc.apply(lodash, arrayPush([value], args));
16952 return (isTaker && chainAll) ? result[0] : result;
16953 };
16954
16955 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
16956 // Avoid lazy use if the iteratee has a "length" value other than `1`.
16957 isLazy = useLazy = false;
16958 }
16959 var chainAll = this.__chain__,
16960 isHybrid = !!this.__actions__.length,
16961 isUnwrapped = retUnwrapped && !chainAll,
16962 onlyLazy = isLazy && !isHybrid;
16963
16964 if (!retUnwrapped && useLazy) {
16965 value = onlyLazy ? value : new LazyWrapper(this);
16966 var result = func.apply(value, args);
16967 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
16968 return new LodashWrapper(result, chainAll);
16969 }
16970 if (isUnwrapped && onlyLazy) {
16971 return func.apply(this, args);
16972 }
16973 result = this.thru(interceptor);
16974 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
16975 };
16976 });
16977
16978 // Add `Array` methods to `lodash.prototype`.
16979 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
16980 var func = arrayProto[methodName],
16981 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
16982 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
16983
16984 lodash.prototype[methodName] = function() {
16985 var args = arguments;
16986 if (retUnwrapped && !this.__chain__) {
16987 var value = this.value();
16988 return func.apply(isArray(value) ? value : [], args);
16989 }
16990 return this[chainName](function(value) {
16991 return func.apply(isArray(value) ? value : [], args);
16992 });
16993 };
16994 });
16995
16996 // Map minified method names to their real names.
16997 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16998 var lodashFunc = lodash[methodName];
16999 if (lodashFunc) {
17000 var key = (lodashFunc.name + ''),
17001 names = realNames[key] || (realNames[key] = []);
17002
17003 names.push({ 'name': methodName, 'func': lodashFunc });
17004 }
17005 });
17006
17007 realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
17008 'name': 'wrapper',
17009 'func': undefined
17010 }];
17011
17012 // Add methods to `LazyWrapper`.
17013 LazyWrapper.prototype.clone = lazyClone;
17014 LazyWrapper.prototype.reverse = lazyReverse;
17015 LazyWrapper.prototype.value = lazyValue;
17016
17017 // Add chain sequence methods to the `lodash` wrapper.
17018 lodash.prototype.at = wrapperAt;
17019 lodash.prototype.chain = wrapperChain;
17020 lodash.prototype.commit = wrapperCommit;
17021 lodash.prototype.next = wrapperNext;
17022 lodash.prototype.plant = wrapperPlant;
17023 lodash.prototype.reverse = wrapperReverse;
17024 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
17025
17026 // Add lazy aliases.
17027 lodash.prototype.first = lodash.prototype.head;
17028
17029 if (symIterator) {
17030 lodash.prototype[symIterator] = wrapperToIterator;
17031 }
17032 return lodash;
17033 });
17034
17035 /*--------------------------------------------------------------------------*/
17036
17037 // Export lodash.
17038 var _ = runInContext();
17039
17040 // Some AMD build optimizers, like r.js, check for condition patterns like:
17041 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
17042 // Expose Lodash on the global object to prevent errors when Lodash is
17043 // loaded by a script tag in the presence of an AMD loader.
17044 // See http://requirejs.org/docs/errors.html#mismatch for more details.
17045 // Use `_.noConflict` to remove Lodash from the global object.
17046 root._ = _;
17047
17048 // Define as an anonymous module so, through path mapping, it can be
17049 // referenced as the "underscore" module.
17050 define(function() {
17051 return _;
17052 });
17053 }
17054 // Check for `exports` after `define` in case a build optimizer adds it.
17055 else if (freeModule) {
17056 // Export for Node.js.
17057 (freeModule.exports = _)._ = _;
17058 // Export for CommonJS support.
17059 freeExports._ = _;
17060 }
17061 else {
17062 // Export to the global object.
17063 root._ = _;
17064 }
17065}.call(this));