3 * lodash <https://lodash.com/>
4 * Copyright jQuery Foundation and other contributors <https://jquery.org/>
5 * Released under MIT license <https://lodash.com/license>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
14 /** Used as the semantic version number. */
15 var VERSION = '4.13.1';
17 /** Used as the size to enable large array optimizations. */
18 var LARGE_ARRAY_SIZE = 200;
20 /** Used as the `TypeError` message for "Functions" methods. */
21 var FUNC_ERROR_TEXT = 'Expected a function';
23 /** Used to stand-in for `undefined` hash values. */
24 var HASH_UNDEFINED = '__lodash_hash_undefined__';
26 /** Used as the internal argument placeholder. */
27 var PLACEHOLDER = '__lodash_placeholder__';
29 /** Used to compose bitmasks for wrapper metadata. */
34 CURRY_RIGHT_FLAG = 16,
36 PARTIAL_RIGHT_FLAG = 64,
41 /** Used to compose bitmasks for comparison styles. */
42 var UNORDERED_COMPARE_FLAG = 1,
43 PARTIAL_COMPARE_FLAG = 2;
45 /** Used as default options for `_.truncate`. */
46 var DEFAULT_TRUNC_LENGTH = 30,
47 DEFAULT_TRUNC_OMISSION = '...';
49 /** Used to detect hot functions by number of calls within a span of milliseconds. */
53 /** Used to indicate the type of lazy iteratees. */
54 var LAZY_FILTER_FLAG = 1,
58 /** Used as references for various `Number` constants. */
60 MAX_SAFE_INTEGER = 9007199254740991,
61 MAX_INTEGER = 1.7976931348623157e+308,
64 /** Used as references for the maximum length and index of an array. */
65 var MAX_ARRAY_LENGTH = 4294967295,
66 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
67 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
69 /** `Object#toString` result references. */
70 var argsTag = '[object Arguments]',
71 arrayTag = '[object Array]',
72 boolTag = '[object Boolean]',
73 dateTag = '[object Date]',
74 errorTag = '[object Error]',
75 funcTag = '[object Function]',
76 genTag = '[object GeneratorFunction]',
77 mapTag = '[object Map]',
78 numberTag = '[object Number]',
79 objectTag = '[object Object]',
80 promiseTag = '[object Promise]',
81 regexpTag = '[object RegExp]',
82 setTag = '[object Set]',
83 stringTag = '[object String]',
84 symbolTag = '[object Symbol]',
85 weakMapTag = '[object WeakMap]',
86 weakSetTag = '[object WeakSet]';
88 var arrayBufferTag = '[object ArrayBuffer]',
89 dataViewTag = '[object DataView]',
90 float32Tag = '[object Float32Array]',
91 float64Tag = '[object Float64Array]',
92 int8Tag = '[object Int8Array]',
93 int16Tag = '[object Int16Array]',
94 int32Tag = '[object Int32Array]',
95 uint8Tag = '[object Uint8Array]',
96 uint8ClampedTag = '[object Uint8ClampedArray]',
97 uint16Tag = '[object Uint16Array]',
98 uint32Tag = '[object Uint32Array]';
100 /** Used to match empty string literals in compiled template source. */
101 var reEmptyStringLeading = /\b__p \+= '';/g,
102 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
103 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
105 /** Used to match HTML entities and HTML characters. */
106 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
107 reUnescapedHtml = /[&<>"'`]/g,
108 reHasEscapedHtml = RegExp(reEscapedHtml.source),
109 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
111 /** Used to match template delimiters. */
112 var reEscape = /<%-([\s\S]+?)%>/g,
113 reEvaluate = /<%([\s\S]+?)%>/g,
114 reInterpolate = /<%=([\s\S]+?)%>/g;
116 /** Used to match property names within property paths. */
117 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
118 reIsPlainProp = /^\w*$/,
119 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(\.|\[\])(?:\4|$))/g;
122 * Used to match `RegExp`
123 * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
125 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
126 reHasRegExpChar = RegExp(reRegExpChar.source);
128 /** Used to match leading and trailing whitespace. */
129 var reTrim = /^\s+|\s+$/g,
130 reTrimStart = /^\s+/,
133 /** Used to match non-compound words composed of alphanumeric characters. */
134 var reBasicWord = /[a-zA-Z0-9]+/g;
136 /** Used to match backslashes in property paths. */
137 var reEscapeChar = /\\(\\)?/g;
141 * [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components).
143 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
145 /** Used to match `RegExp` flags from their coerced string values. */
146 var reFlags = /\w*$/;
148 /** Used to detect hexadecimal string values. */
149 var reHasHexPrefix = /^0x/i;
151 /** Used to detect bad signed hexadecimal string values. */
152 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
154 /** Used to detect binary string values. */
155 var reIsBinary = /^0b[01]+$/i;
157 /** Used to detect host constructors (Safari). */
158 var reIsHostCtor = /^\[object .+?Constructor\]$/;
160 /** Used to detect octal string values. */
161 var reIsOctal = /^0o[0-7]+$/i;
163 /** Used to detect unsigned integer values. */
164 var reIsUint = /^(?:0|[1-9]\d*)$/;
166 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
167 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
169 /** Used to ensure capturing order of template delimiters. */
170 var reNoMatch = /($^)/;
172 /** Used to match unescaped characters in compiled string literals. */
173 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
175 /** Used to compose unicode character classes. */
176 var rsAstralRange = '\\ud800-\\udfff',
177 rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
178 rsComboSymbolsRange = '\\u20d0-\\u20f0',
179 rsDingbatRange = '\\u2700-\\u27bf',
180 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
181 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
182 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
183 rsPunctuationRange = '\\u2000-\\u206f',
184 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',
185 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
186 rsVarRange = '\\ufe0e\\ufe0f',
187 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
189 /** Used to compose unicode capture groups. */
190 var rsApos = "['\u2019]",
191 rsAstral = '[' + rsAstralRange + ']',
192 rsBreak = '[' + rsBreakRange + ']',
193 rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
195 rsDingbat = '[' + rsDingbatRange + ']',
196 rsLower = '[' + rsLowerRange + ']',
197 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
198 rsFitz = '\\ud83c[\\udffb-\\udfff]',
199 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
200 rsNonAstral = '[^' + rsAstralRange + ']',
201 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
202 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
203 rsUpper = '[' + rsUpperRange + ']',
206 /** Used to compose unicode regexes. */
207 var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
208 rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
209 rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
210 rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
211 reOptMod = rsModifier + '?',
212 rsOptVar = '[' + rsVarRange + ']?',
213 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
214 rsSeq = rsOptVar + reOptMod + rsOptJoin,
215 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
216 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
218 /** Used to match apostrophes. */
219 var reApos = RegExp(rsApos, 'g');
222 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
223 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
225 var reComboMark = RegExp(rsCombo, 'g');
227 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
228 var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
230 /** Used to match complex or compound words. */
231 var reComplexWord = RegExp([
232 rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
233 rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
234 rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr,
235 rsUpper + '+' + rsOptUpperContr,
240 /** 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/). */
241 var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
243 /** Used to detect strings that need a more robust regexp to match words. */
244 var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
246 /** Used to assign default `context` object properties. */
248 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
249 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
250 'Promise', 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError',
251 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
252 '_', 'isFinite', 'parseInt', 'setTimeout'
255 /** Used to make template sourceURLs easier to identify. */
256 var templateCounter = -1;
258 /** Used to identify `toStringTag` values of typed arrays. */
259 var typedArrayTags = {};
260 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
261 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
262 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
263 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
264 typedArrayTags[uint32Tag] = true;
265 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
266 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
267 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
268 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
269 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
270 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
271 typedArrayTags[setTag] = typedArrayTags[stringTag] =
272 typedArrayTags[weakMapTag] = false;
274 /** Used to identify `toStringTag` values supported by `_.clone`. */
275 var cloneableTags = {};
276 cloneableTags[argsTag] = cloneableTags[arrayTag] =
277 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
278 cloneableTags[boolTag] = cloneableTags[dateTag] =
279 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
280 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
281 cloneableTags[int32Tag] = cloneableTags[mapTag] =
282 cloneableTags[numberTag] = cloneableTags[objectTag] =
283 cloneableTags[regexpTag] = cloneableTags[setTag] =
284 cloneableTags[stringTag] = cloneableTags[symbolTag] =
285 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
286 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
287 cloneableTags[errorTag] = cloneableTags[funcTag] =
288 cloneableTags[weakMapTag] = false;
290 /** Used to map latin-1 supplementary letters to basic latin letters. */
291 var deburredLetters = {
292 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
293 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
294 '\xc7': 'C', '\xe7': 'c',
295 '\xd0': 'D', '\xf0': 'd',
296 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
297 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
298 '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
299 '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
300 '\xd1': 'N', '\xf1': 'n',
301 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
302 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
303 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
304 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
305 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
306 '\xc6': 'Ae', '\xe6': 'ae',
307 '\xde': 'Th', '\xfe': 'th',
311 /** Used to map characters to HTML entities. */
321 /** Used to map HTML entities to characters. */
322 var htmlUnescapes = {
331 /** Used to escape characters for inclusion in compiled string literals. */
332 var stringEscapes = {
341 /** Built-in method references without a dependency on `root`. */
342 var freeParseFloat = parseFloat,
343 freeParseInt = parseInt;
345 /** Detect free variable `exports`. */
346 var freeExports = typeof exports == 'object' && exports;
348 /** Detect free variable `module`. */
349 var freeModule = freeExports && typeof module == 'object' && module;
351 /** Detect the popular CommonJS extension `module.exports`. */
352 var moduleExports = freeModule && freeModule.exports === freeExports;
354 /** Detect free variable `global` from Node.js. */
355 var freeGlobal = checkGlobal(typeof global == 'object' && global);
357 /** Detect free variable `self`. */
358 var freeSelf = checkGlobal(typeof self == 'object' && self);
360 /** Detect `this` as the global object. */
361 var thisGlobal = checkGlobal(typeof this == 'object' && this);
363 /** Used as a reference to the global object. */
364 var root = freeGlobal || freeSelf || thisGlobal || Function('return this')();
366 /*--------------------------------------------------------------------------*/
369 * Adds the key-value `pair` to `map`.
372 * @param {Object} map The map to modify.
373 * @param {Array} pair The key-value pair to add.
374 * @returns {Object} Returns `map`.
376 function addMapEntry(map, pair) {
377 // Don't return `Map#set` because it doesn't return the map instance in IE 11.
378 map.set(pair[0], pair[1]);
383 * Adds `value` to `set`.
386 * @param {Object} set The set to modify.
387 * @param {*} value The value to add.
388 * @returns {Object} Returns `set`.
390 function addSetEntry(set, value) {
396 * A faster alternative to `Function#apply`, this function invokes `func`
397 * with the `this` binding of `thisArg` and the arguments of `args`.
400 * @param {Function} func The function to invoke.
401 * @param {*} thisArg The `this` binding of `func`.
402 * @param {Array} args The arguments to invoke `func` with.
403 * @returns {*} Returns the result of `func`.
405 function apply(func, thisArg, args) {
406 var length = args.length;
408 case 0: return func.call(thisArg);
409 case 1: return func.call(thisArg, args[0]);
410 case 2: return func.call(thisArg, args[0], args[1]);
411 case 3: return func.call(thisArg, args[0], args[1], args[2]);
413 return func.apply(thisArg, args);
417 * A specialized version of `baseAggregator` for arrays.
420 * @param {Array} [array] The array to iterate over.
421 * @param {Function} setter The function to set `accumulator` values.
422 * @param {Function} iteratee The iteratee to transform keys.
423 * @param {Object} accumulator The initial aggregated object.
424 * @returns {Function} Returns `accumulator`.
426 function arrayAggregator(array, setter, iteratee, accumulator) {
428 length = array ? array.length : 0;
430 while (++index < length) {
431 var value = array[index];
432 setter(accumulator, value, iteratee(value), array);
438 * A specialized version of `_.forEach` for arrays without support for
439 * iteratee shorthands.
442 * @param {Array} [array] The array to iterate over.
443 * @param {Function} iteratee The function invoked per iteration.
444 * @returns {Array} Returns `array`.
446 function arrayEach(array, iteratee) {
448 length = array ? array.length : 0;
450 while (++index < length) {
451 if (iteratee(array[index], index, array) === false) {
459 * A specialized version of `_.forEachRight` for arrays without support for
460 * iteratee shorthands.
463 * @param {Array} [array] The array to iterate over.
464 * @param {Function} iteratee The function invoked per iteration.
465 * @returns {Array} Returns `array`.
467 function arrayEachRight(array, iteratee) {
468 var length = array ? array.length : 0;
471 if (iteratee(array[length], length, array) === false) {
479 * A specialized version of `_.every` for arrays without support for
480 * iteratee shorthands.
483 * @param {Array} [array] The array to iterate over.
484 * @param {Function} predicate The function invoked per iteration.
485 * @returns {boolean} Returns `true` if all elements pass the predicate check,
488 function arrayEvery(array, predicate) {
490 length = array ? array.length : 0;
492 while (++index < length) {
493 if (!predicate(array[index], index, array)) {
501 * A specialized version of `_.filter` for arrays without support for
502 * iteratee shorthands.
505 * @param {Array} [array] The array to iterate over.
506 * @param {Function} predicate The function invoked per iteration.
507 * @returns {Array} Returns the new filtered array.
509 function arrayFilter(array, predicate) {
511 length = array ? array.length : 0,
515 while (++index < length) {
516 var value = array[index];
517 if (predicate(value, index, array)) {
518 result[resIndex++] = value;
525 * A specialized version of `_.includes` for arrays without support for
526 * specifying an index to search from.
529 * @param {Array} [array] The array to search.
530 * @param {*} target The value to search for.
531 * @returns {boolean} Returns `true` if `target` is found, else `false`.
533 function arrayIncludes(array, value) {
534 var length = array ? array.length : 0;
535 return !!length && baseIndexOf(array, value, 0) > -1;
539 * This function is like `arrayIncludes` except that it accepts a comparator.
542 * @param {Array} [array] The array to search.
543 * @param {*} target The value to search for.
544 * @param {Function} comparator The comparator invoked per element.
545 * @returns {boolean} Returns `true` if `target` is found, else `false`.
547 function arrayIncludesWith(array, value, comparator) {
549 length = array ? array.length : 0;
551 while (++index < length) {
552 if (comparator(value, array[index])) {
560 * A specialized version of `_.map` for arrays without support for iteratee
564 * @param {Array} [array] The array to iterate over.
565 * @param {Function} iteratee The function invoked per iteration.
566 * @returns {Array} Returns the new mapped array.
568 function arrayMap(array, iteratee) {
570 length = array ? array.length : 0,
571 result = Array(length);
573 while (++index < length) {
574 result[index] = iteratee(array[index], index, array);
580 * Appends the elements of `values` to `array`.
583 * @param {Array} array The array to modify.
584 * @param {Array} values The values to append.
585 * @returns {Array} Returns `array`.
587 function arrayPush(array, values) {
589 length = values.length,
590 offset = array.length;
592 while (++index < length) {
593 array[offset + index] = values[index];
599 * A specialized version of `_.reduce` for arrays without support for
600 * iteratee shorthands.
603 * @param {Array} [array] The array to iterate over.
604 * @param {Function} iteratee The function invoked per iteration.
605 * @param {*} [accumulator] The initial value.
606 * @param {boolean} [initAccum] Specify using the first element of `array` as
608 * @returns {*} Returns the accumulated value.
610 function arrayReduce(array, iteratee, accumulator, initAccum) {
612 length = array ? array.length : 0;
614 if (initAccum && length) {
615 accumulator = array[++index];
617 while (++index < length) {
618 accumulator = iteratee(accumulator, array[index], index, array);
624 * A specialized version of `_.reduceRight` for arrays without support for
625 * iteratee shorthands.
628 * @param {Array} [array] The array to iterate over.
629 * @param {Function} iteratee The function invoked per iteration.
630 * @param {*} [accumulator] The initial value.
631 * @param {boolean} [initAccum] Specify using the last element of `array` as
633 * @returns {*} Returns the accumulated value.
635 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
636 var length = array ? array.length : 0;
637 if (initAccum && length) {
638 accumulator = array[--length];
641 accumulator = iteratee(accumulator, array[length], length, array);
647 * A specialized version of `_.some` for arrays without support for iteratee
651 * @param {Array} [array] The array to iterate over.
652 * @param {Function} predicate The function invoked per iteration.
653 * @returns {boolean} Returns `true` if any element passes the predicate check,
656 function arraySome(array, predicate) {
658 length = array ? array.length : 0;
660 while (++index < length) {
661 if (predicate(array[index], index, array)) {
669 * The base implementation of methods like `_.findKey` and `_.findLastKey`,
670 * without support for iteratee shorthands, which iterates over `collection`
674 * @param {Array|Object} collection The collection to search.
675 * @param {Function} predicate The function invoked per iteration.
676 * @param {Function} eachFunc The function to iterate over `collection`.
677 * @returns {*} Returns the found element or its key, else `undefined`.
679 function baseFindKey(collection, predicate, eachFunc) {
681 eachFunc(collection, function(value, key, collection) {
682 if (predicate(value, key, collection)) {
691 * The base implementation of `_.findIndex` and `_.findLastIndex` without
692 * support for iteratee shorthands.
695 * @param {Array} array The array to search.
696 * @param {Function} predicate The function invoked per iteration.
697 * @param {number} fromIndex The index to search from.
698 * @param {boolean} [fromRight] Specify iterating from right to left.
699 * @returns {number} Returns the index of the matched value, else `-1`.
701 function baseFindIndex(array, predicate, fromIndex, fromRight) {
702 var length = array.length,
703 index = fromIndex + (fromRight ? 1 : -1);
705 while ((fromRight ? index-- : ++index < length)) {
706 if (predicate(array[index], index, array)) {
714 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
717 * @param {Array} array The array to search.
718 * @param {*} value The value to search for.
719 * @param {number} fromIndex The index to search from.
720 * @returns {number} Returns the index of the matched value, else `-1`.
722 function baseIndexOf(array, value, fromIndex) {
723 if (value !== value) {
724 return indexOfNaN(array, fromIndex);
726 var index = fromIndex - 1,
727 length = array.length;
729 while (++index < length) {
730 if (array[index] === value) {
738 * This function is like `baseIndexOf` except that it accepts a comparator.
741 * @param {Array} array The array to search.
742 * @param {*} value The value to search for.
743 * @param {number} fromIndex The index to search from.
744 * @param {Function} comparator The comparator invoked per element.
745 * @returns {number} Returns the index of the matched value, else `-1`.
747 function baseIndexOfWith(array, value, fromIndex, comparator) {
748 var index = fromIndex - 1,
749 length = array.length;
751 while (++index < length) {
752 if (comparator(array[index], value)) {
760 * The base implementation of `_.mean` and `_.meanBy` without support for
761 * iteratee shorthands.
764 * @param {Array} array The array to iterate over.
765 * @param {Function} iteratee The function invoked per iteration.
766 * @returns {number} Returns the mean.
768 function baseMean(array, iteratee) {
769 var length = array ? array.length : 0;
770 return length ? (baseSum(array, iteratee) / length) : NAN;
774 * The base implementation of `_.reduce` and `_.reduceRight`, without support
775 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
778 * @param {Array|Object} collection The collection to iterate over.
779 * @param {Function} iteratee The function invoked per iteration.
780 * @param {*} accumulator The initial value.
781 * @param {boolean} initAccum Specify using the first or last element of
782 * `collection` as the initial value.
783 * @param {Function} eachFunc The function to iterate over `collection`.
784 * @returns {*} Returns the accumulated value.
786 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
787 eachFunc(collection, function(value, index, collection) {
788 accumulator = initAccum
789 ? (initAccum = false, value)
790 : iteratee(accumulator, value, index, collection);
796 * The base implementation of `_.sortBy` which uses `comparer` to define the
797 * sort order of `array` and replaces criteria objects with their corresponding
801 * @param {Array} array The array to sort.
802 * @param {Function} comparer The function to define sort order.
803 * @returns {Array} Returns `array`.
805 function baseSortBy(array, comparer) {
806 var length = array.length;
808 array.sort(comparer);
810 array[length] = array[length].value;
816 * The base implementation of `_.sum` and `_.sumBy` without support for
817 * iteratee shorthands.
820 * @param {Array} array The array to iterate over.
821 * @param {Function} iteratee The function invoked per iteration.
822 * @returns {number} Returns the sum.
824 function baseSum(array, iteratee) {
827 length = array.length;
829 while (++index < length) {
830 var current = iteratee(array[index]);
831 if (current !== undefined) {
832 result = result === undefined ? current : (result + current);
839 * The base implementation of `_.times` without support for iteratee shorthands
840 * or max array length checks.
843 * @param {number} n The number of times to invoke `iteratee`.
844 * @param {Function} iteratee The function invoked per iteration.
845 * @returns {Array} Returns the array of results.
847 function baseTimes(n, iteratee) {
851 while (++index < n) {
852 result[index] = iteratee(index);
858 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
859 * of key-value pairs for `object` corresponding to the property names of `props`.
862 * @param {Object} object The object to query.
863 * @param {Array} props The property names to get values for.
864 * @returns {Object} Returns the key-value pairs.
866 function baseToPairs(object, props) {
867 return arrayMap(props, function(key) {
868 return [key, object[key]];
873 * The base implementation of `_.unary` without support for storing wrapper metadata.
876 * @param {Function} func The function to cap arguments for.
877 * @returns {Function} Returns the new capped function.
879 function baseUnary(func) {
880 return function(value) {
886 * The base implementation of `_.values` and `_.valuesIn` which creates an
887 * array of `object` property values corresponding to the property names
891 * @param {Object} object The object to query.
892 * @param {Array} props The property names to get values for.
893 * @returns {Object} Returns the array of property values.
895 function baseValues(object, props) {
896 return arrayMap(props, function(key) {
902 * Checks if a cache value for `key` exists.
905 * @param {Object} cache The cache to query.
906 * @param {string} key The key of the entry to check.
907 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
909 function cacheHas(cache, key) {
910 return cache.has(key);
914 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
915 * that is not found in the character symbols.
918 * @param {Array} strSymbols The string symbols to inspect.
919 * @param {Array} chrSymbols The character symbols to find.
920 * @returns {number} Returns the index of the first unmatched string symbol.
922 function charsStartIndex(strSymbols, chrSymbols) {
924 length = strSymbols.length;
926 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
931 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
932 * that is not found in the character symbols.
935 * @param {Array} strSymbols The string symbols to inspect.
936 * @param {Array} chrSymbols The character symbols to find.
937 * @returns {number} Returns the index of the last unmatched string symbol.
939 function charsEndIndex(strSymbols, chrSymbols) {
940 var index = strSymbols.length;
942 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
947 * Checks if `value` is a global object.
950 * @param {*} value The value to check.
951 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
953 function checkGlobal(value) {
954 return (value && value.Object === Object) ? value : null;
958 * Gets the number of `placeholder` occurrences in `array`.
961 * @param {Array} array The array to inspect.
962 * @param {*} placeholder The placeholder to search for.
963 * @returns {number} Returns the placeholder count.
965 function countHolders(array, placeholder) {
966 var length = array.length,
970 if (array[length] === placeholder) {
978 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
981 * @param {string} letter The matched letter to deburr.
982 * @returns {string} Returns the deburred letter.
984 function deburrLetter(letter) {
985 return deburredLetters[letter];
989 * Used by `_.escape` to convert characters to HTML entities.
992 * @param {string} chr The matched character to escape.
993 * @returns {string} Returns the escaped character.
995 function escapeHtmlChar(chr) {
996 return htmlEscapes[chr];
1000 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1003 * @param {string} chr The matched character to escape.
1004 * @returns {string} Returns the escaped character.
1006 function escapeStringChar(chr) {
1007 return '\\' + stringEscapes[chr];
1011 * Gets the value at `key` of `object`.
1014 * @param {Object} [object] The object to query.
1015 * @param {string} key The key of the property to get.
1016 * @returns {*} Returns the property value.
1018 function getValue(object, key) {
1019 return object == null ? undefined : object[key];
1023 * Gets the index at which the first occurrence of `NaN` is found in `array`.
1026 * @param {Array} array The array to search.
1027 * @param {number} fromIndex The index to search from.
1028 * @param {boolean} [fromRight] Specify iterating from right to left.
1029 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
1031 function indexOfNaN(array, fromIndex, fromRight) {
1032 var length = array.length,
1033 index = fromIndex + (fromRight ? 1 : -1);
1035 while ((fromRight ? index-- : ++index < length)) {
1036 var other = array[index];
1037 if (other !== other) {
1045 * Checks if `value` is a host object in IE < 9.
1048 * @param {*} value The value to check.
1049 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
1051 function isHostObject(value) {
1052 // Many host objects are `Object` objects that can coerce to strings
1053 // despite having improperly defined `toString` methods.
1055 if (value != null && typeof value.toString != 'function') {
1057 result = !!(value + '');
1064 * Converts `iterator` to an array.
1067 * @param {Object} iterator The iterator to convert.
1068 * @returns {Array} Returns the converted array.
1070 function iteratorToArray(iterator) {
1074 while (!(data = iterator.next()).done) {
1075 result.push(data.value);
1081 * Converts `map` to its key-value pairs.
1084 * @param {Object} map The map to convert.
1085 * @returns {Array} Returns the key-value pairs.
1087 function mapToArray(map) {
1089 result = Array(map.size);
1091 map.forEach(function(value, key) {
1092 result[++index] = [key, value];
1098 * Replaces all `placeholder` elements in `array` with an internal placeholder
1099 * and returns an array of their indexes.
1102 * @param {Array} array The array to modify.
1103 * @param {*} placeholder The placeholder to replace.
1104 * @returns {Array} Returns the new array of placeholder indexes.
1106 function replaceHolders(array, placeholder) {
1108 length = array.length,
1112 while (++index < length) {
1113 var value = array[index];
1114 if (value === placeholder || value === PLACEHOLDER) {
1115 array[index] = PLACEHOLDER;
1116 result[resIndex++] = index;
1123 * Converts `set` to an array of its values.
1126 * @param {Object} set The set to convert.
1127 * @returns {Array} Returns the values.
1129 function setToArray(set) {
1131 result = Array(set.size);
1133 set.forEach(function(value) {
1134 result[++index] = value;
1140 * Converts `set` to its value-value pairs.
1143 * @param {Object} set The set to convert.
1144 * @returns {Array} Returns the value-value pairs.
1146 function setToPairs(set) {
1148 result = Array(set.size);
1150 set.forEach(function(value) {
1151 result[++index] = [value, value];
1157 * Gets the number of symbols in `string`.
1160 * @param {string} string The string to inspect.
1161 * @returns {number} Returns the string size.
1163 function stringSize(string) {
1164 if (!(string && reHasComplexSymbol.test(string))) {
1165 return string.length;
1167 var result = reComplexSymbol.lastIndex = 0;
1168 while (reComplexSymbol.test(string)) {
1175 * Converts `string` to an array.
1178 * @param {string} string The string to convert.
1179 * @returns {Array} Returns the converted array.
1181 function stringToArray(string) {
1182 return string.match(reComplexSymbol);
1186 * Used by `_.unescape` to convert HTML entities to characters.
1189 * @param {string} chr The matched character to unescape.
1190 * @returns {string} Returns the unescaped character.
1192 function unescapeHtmlChar(chr) {
1193 return htmlUnescapes[chr];
1196 /*--------------------------------------------------------------------------*/
1199 * Create a new pristine `lodash` function using the `context` object.
1205 * @param {Object} [context=root] The context object.
1206 * @returns {Function} Returns a new `lodash` function.
1209 * _.mixin({ 'foo': _.constant('foo') });
1211 * var lodash = _.runInContext();
1212 * lodash.mixin({ 'bar': lodash.constant('bar') });
1214 * _.isFunction(_.foo);
1216 * _.isFunction(_.bar);
1219 * lodash.isFunction(lodash.foo);
1221 * lodash.isFunction(lodash.bar);
1224 * // Use `context` to stub `Date#getTime` use in `_.now`.
1225 * var stubbed = _.runInContext({
1226 * 'Date': function() {
1227 * return { 'getTime': stubGetTime };
1231 * // Create a suped-up `defer` in Node.js.
1232 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1234 function runInContext(context) {
1235 context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
1237 /** Built-in constructor references. */
1238 var Date = context.Date,
1239 Error = context.Error,
1240 Math = context.Math,
1241 RegExp = context.RegExp,
1242 TypeError = context.TypeError;
1244 /** Used for built-in method references. */
1245 var arrayProto = context.Array.prototype,
1246 objectProto = context.Object.prototype,
1247 stringProto = context.String.prototype;
1249 /** Used to detect overreaching core-js shims. */
1250 var coreJsData = context['__core-js_shared__'];
1252 /** Used to detect methods masquerading as native. */
1253 var maskSrcKey = (function() {
1254 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
1255 return uid ? ('Symbol(src)_1.' + uid) : '';
1258 /** Used to resolve the decompiled source of functions. */
1259 var funcToString = context.Function.prototype.toString;
1261 /** Used to check objects for own properties. */
1262 var hasOwnProperty = objectProto.hasOwnProperty;
1264 /** Used to generate unique IDs. */
1267 /** Used to infer the `Object` constructor. */
1268 var objectCtorString = funcToString.call(Object);
1271 * Used to resolve the
1272 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
1275 var objectToString = objectProto.toString;
1277 /** Used to restore the original `_` reference in `_.noConflict`. */
1278 var oldDash = root._;
1280 /** Used to detect if a method is native. */
1281 var reIsNative = RegExp('^' +
1282 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1283 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1286 /** Built-in value references. */
1287 var Buffer = moduleExports ? context.Buffer : undefined,
1288 Reflect = context.Reflect,
1289 Symbol = context.Symbol,
1290 Uint8Array = context.Uint8Array,
1291 enumerate = Reflect ? Reflect.enumerate : undefined,
1292 getOwnPropertySymbols = Object.getOwnPropertySymbols,
1293 iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
1294 objectCreate = Object.create,
1295 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1296 splice = arrayProto.splice;
1298 /** Built-in method references that are mockable. */
1299 var setTimeout = function(func, wait) { return context.setTimeout.call(root, func, wait); };
1301 /* Built-in method references for those with the same name as other `lodash` methods. */
1302 var nativeCeil = Math.ceil,
1303 nativeFloor = Math.floor,
1304 nativeGetPrototype = Object.getPrototypeOf,
1305 nativeIsFinite = context.isFinite,
1306 nativeJoin = arrayProto.join,
1307 nativeKeys = Object.keys,
1308 nativeMax = Math.max,
1309 nativeMin = Math.min,
1310 nativeParseInt = context.parseInt,
1311 nativeRandom = Math.random,
1312 nativeReplace = stringProto.replace,
1313 nativeReverse = arrayProto.reverse,
1314 nativeSplit = stringProto.split;
1316 /* Built-in method references that are verified to be native. */
1317 var DataView = getNative(context, 'DataView'),
1318 Map = getNative(context, 'Map'),
1319 Promise = getNative(context, 'Promise'),
1320 Set = getNative(context, 'Set'),
1321 WeakMap = getNative(context, 'WeakMap'),
1322 nativeCreate = getNative(Object, 'create');
1324 /** Used to store function metadata. */
1325 var metaMap = WeakMap && new WeakMap;
1327 /** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */
1328 var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
1330 /** Used to lookup unminified function names. */
1333 /** Used to detect maps, sets, and weakmaps. */
1334 var dataViewCtorString = toSource(DataView),
1335 mapCtorString = toSource(Map),
1336 promiseCtorString = toSource(Promise),
1337 setCtorString = toSource(Set),
1338 weakMapCtorString = toSource(WeakMap);
1340 /** Used to convert symbols to primitives and strings. */
1341 var symbolProto = Symbol ? Symbol.prototype : undefined,
1342 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
1343 symbolToString = symbolProto ? symbolProto.toString : undefined;
1345 /*------------------------------------------------------------------------*/
1348 * Creates a `lodash` object which wraps `value` to enable implicit method
1349 * chain sequences. Methods that operate on and return arrays, collections,
1350 * and functions can be chained together. Methods that retrieve a single value
1351 * or may return a primitive value will automatically end the chain sequence
1352 * and return the unwrapped value. Otherwise, the value must be unwrapped
1355 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
1356 * enabled using `_.chain`.
1358 * The execution of chained methods is lazy, that is, it's deferred until
1359 * `_#value` is implicitly or explicitly called.
1361 * Lazy evaluation allows several methods to support shortcut fusion.
1362 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
1363 * the creation of intermediate arrays and can greatly reduce the number of
1364 * iteratee executions. Sections of a chain sequence qualify for shortcut
1365 * fusion if the section is applied to an array of at least `200` elements
1366 * and any iteratees accept only one argument. The heuristic for whether a
1367 * section qualifies for shortcut fusion is subject to change.
1369 * Chaining is supported in custom builds as long as the `_#value` method is
1370 * directly or indirectly included in the build.
1372 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1374 * The wrapper `Array` methods are:
1375 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1377 * The wrapper `String` methods are:
1378 * `replace` and `split`
1380 * The wrapper methods that support shortcut fusion are:
1381 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1382 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1383 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1385 * The chainable wrapper methods are:
1386 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
1387 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
1388 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
1389 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
1390 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
1391 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
1392 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
1393 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
1394 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
1395 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
1396 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
1397 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
1398 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
1399 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
1400 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
1401 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
1402 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
1403 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
1404 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
1405 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
1406 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
1407 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
1408 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
1409 * `zipObject`, `zipObjectDeep`, and `zipWith`
1411 * The wrapper methods that are **not** chainable by default are:
1412 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1413 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`,
1414 * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`,
1415 * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`,
1416 * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
1417 * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`,
1418 * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`,
1419 * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
1420 * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
1421 * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`,
1422 * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
1423 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
1424 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
1425 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
1426 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
1427 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
1428 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
1429 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
1430 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
1431 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
1432 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
1433 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
1434 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
1435 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
1436 * `upperFirst`, `value`, and `words`
1441 * @param {*} value The value to wrap in a `lodash` instance.
1442 * @returns {Object} Returns the new `lodash` wrapper instance.
1445 * function square(n) {
1449 * var wrapped = _([1, 2, 3]);
1451 * // Returns an unwrapped value.
1452 * wrapped.reduce(_.add);
1455 * // Returns a wrapped value.
1456 * var squares = wrapped.map(square);
1458 * _.isArray(squares);
1461 * _.isArray(squares.value());
1464 function lodash(value) {
1465 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1466 if (value instanceof LodashWrapper) {
1469 if (hasOwnProperty.call(value, '__wrapped__')) {
1470 return wrapperClone(value);
1473 return new LodashWrapper(value);
1477 * The function whose prototype chain sequence wrappers inherit from.
1481 function baseLodash() {
1482 // No operation performed.
1486 * The base constructor for creating `lodash` wrapper objects.
1489 * @param {*} value The value to wrap.
1490 * @param {boolean} [chainAll] Enable explicit method chain sequences.
1492 function LodashWrapper(value, chainAll) {
1493 this.__wrapped__ = value;
1494 this.__actions__ = [];
1495 this.__chain__ = !!chainAll;
1497 this.__values__ = undefined;
1501 * By default, the template delimiters used by lodash are like those in
1502 * embedded Ruby (ERB). Change the following template settings to use
1503 * alternative delimiters.
1509 lodash.templateSettings = {
1512 * Used to detect `data` property values to be HTML-escaped.
1514 * @memberOf _.templateSettings
1520 * Used to detect code to be evaluated.
1522 * @memberOf _.templateSettings
1525 'evaluate': reEvaluate,
1528 * Used to detect `data` property values to inject.
1530 * @memberOf _.templateSettings
1533 'interpolate': reInterpolate,
1536 * Used to reference the data object in the template text.
1538 * @memberOf _.templateSettings
1544 * Used to import variables into the compiled template.
1546 * @memberOf _.templateSettings
1552 * A reference to the `lodash` function.
1554 * @memberOf _.templateSettings.imports
1561 // Ensure wrappers are instances of `baseLodash`.
1562 lodash.prototype = baseLodash.prototype;
1563 lodash.prototype.constructor = lodash;
1565 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
1566 LodashWrapper.prototype.constructor = LodashWrapper;
1568 /*------------------------------------------------------------------------*/
1571 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1575 * @param {*} value The value to wrap.
1577 function LazyWrapper(value) {
1578 this.__wrapped__ = value;
1579 this.__actions__ = [];
1581 this.__filtered__ = false;
1582 this.__iteratees__ = [];
1583 this.__takeCount__ = MAX_ARRAY_LENGTH;
1584 this.__views__ = [];
1588 * Creates a clone of the lazy wrapper object.
1592 * @memberOf LazyWrapper
1593 * @returns {Object} Returns the cloned `LazyWrapper` object.
1595 function lazyClone() {
1596 var result = new LazyWrapper(this.__wrapped__);
1597 result.__actions__ = copyArray(this.__actions__);
1598 result.__dir__ = this.__dir__;
1599 result.__filtered__ = this.__filtered__;
1600 result.__iteratees__ = copyArray(this.__iteratees__);
1601 result.__takeCount__ = this.__takeCount__;
1602 result.__views__ = copyArray(this.__views__);
1607 * Reverses the direction of lazy iteration.
1611 * @memberOf LazyWrapper
1612 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1614 function lazyReverse() {
1615 if (this.__filtered__) {
1616 var result = new LazyWrapper(this);
1617 result.__dir__ = -1;
1618 result.__filtered__ = true;
1620 result = this.clone();
1621 result.__dir__ *= -1;
1627 * Extracts the unwrapped value from its lazy wrapper.
1631 * @memberOf LazyWrapper
1632 * @returns {*} Returns the unwrapped value.
1634 function lazyValue() {
1635 var array = this.__wrapped__.value(),
1637 isArr = isArray(array),
1639 arrLength = isArr ? array.length : 0,
1640 view = getView(0, arrLength, this.__views__),
1643 length = end - start,
1644 index = isRight ? end : (start - 1),
1645 iteratees = this.__iteratees__,
1646 iterLength = iteratees.length,
1648 takeCount = nativeMin(length, this.__takeCount__);
1650 if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
1651 (arrLength == length && takeCount == length)) {
1652 return baseWrapperValue(array, this.__actions__);
1657 while (length-- && resIndex < takeCount) {
1661 value = array[index];
1663 while (++iterIndex < iterLength) {
1664 var data = iteratees[iterIndex],
1665 iteratee = data.iteratee,
1667 computed = iteratee(value);
1669 if (type == LAZY_MAP_FLAG) {
1671 } else if (!computed) {
1672 if (type == LAZY_FILTER_FLAG) {
1679 result[resIndex++] = value;
1684 // Ensure `LazyWrapper` is an instance of `baseLodash`.
1685 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
1686 LazyWrapper.prototype.constructor = LazyWrapper;
1688 /*------------------------------------------------------------------------*/
1691 * Creates a hash object.
1695 * @param {Array} [entries] The key-value pairs to cache.
1697 function Hash(entries) {
1699 length = entries ? entries.length : 0;
1702 while (++index < length) {
1703 var entry = entries[index];
1704 this.set(entry[0], entry[1]);
1709 * Removes all key-value entries from the hash.
1715 function hashClear() {
1716 this.__data__ = nativeCreate ? nativeCreate(null) : {};
1720 * Removes `key` and its value from the hash.
1725 * @param {Object} hash The hash to modify.
1726 * @param {string} key The key of the value to remove.
1727 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1729 function hashDelete(key) {
1730 return this.has(key) && delete this.__data__[key];
1734 * Gets the hash value for `key`.
1739 * @param {string} key The key of the value to get.
1740 * @returns {*} Returns the entry value.
1742 function hashGet(key) {
1743 var data = this.__data__;
1745 var result = data[key];
1746 return result === HASH_UNDEFINED ? undefined : result;
1748 return hasOwnProperty.call(data, key) ? data[key] : undefined;
1752 * Checks if a hash value for `key` exists.
1757 * @param {string} key The key of the entry to check.
1758 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1760 function hashHas(key) {
1761 var data = this.__data__;
1762 return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
1766 * Sets the hash `key` to `value`.
1771 * @param {string} key The key of the value to set.
1772 * @param {*} value The value to set.
1773 * @returns {Object} Returns the hash instance.
1775 function hashSet(key, value) {
1776 var data = this.__data__;
1777 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
1781 // Add methods to `Hash`.
1782 Hash.prototype.clear = hashClear;
1783 Hash.prototype['delete'] = hashDelete;
1784 Hash.prototype.get = hashGet;
1785 Hash.prototype.has = hashHas;
1786 Hash.prototype.set = hashSet;
1788 /*------------------------------------------------------------------------*/
1791 * Creates an list cache object.
1795 * @param {Array} [entries] The key-value pairs to cache.
1797 function ListCache(entries) {
1799 length = entries ? entries.length : 0;
1802 while (++index < length) {
1803 var entry = entries[index];
1804 this.set(entry[0], entry[1]);
1809 * Removes all key-value entries from the list cache.
1813 * @memberOf ListCache
1815 function listCacheClear() {
1820 * Removes `key` and its value from the list cache.
1824 * @memberOf ListCache
1825 * @param {string} key The key of the value to remove.
1826 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1828 function listCacheDelete(key) {
1829 var data = this.__data__,
1830 index = assocIndexOf(data, key);
1835 var lastIndex = data.length - 1;
1836 if (index == lastIndex) {
1839 splice.call(data, index, 1);
1845 * Gets the list cache value for `key`.
1849 * @memberOf ListCache
1850 * @param {string} key The key of the value to get.
1851 * @returns {*} Returns the entry value.
1853 function listCacheGet(key) {
1854 var data = this.__data__,
1855 index = assocIndexOf(data, key);
1857 return index < 0 ? undefined : data[index][1];
1861 * Checks if a list cache value for `key` exists.
1865 * @memberOf ListCache
1866 * @param {string} key The key of the entry to check.
1867 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1869 function listCacheHas(key) {
1870 return assocIndexOf(this.__data__, key) > -1;
1874 * Sets the list cache `key` to `value`.
1878 * @memberOf ListCache
1879 * @param {string} key The key of the value to set.
1880 * @param {*} value The value to set.
1881 * @returns {Object} Returns the list cache instance.
1883 function listCacheSet(key, value) {
1884 var data = this.__data__,
1885 index = assocIndexOf(data, key);
1888 data.push([key, value]);
1890 data[index][1] = value;
1895 // Add methods to `ListCache`.
1896 ListCache.prototype.clear = listCacheClear;
1897 ListCache.prototype['delete'] = listCacheDelete;
1898 ListCache.prototype.get = listCacheGet;
1899 ListCache.prototype.has = listCacheHas;
1900 ListCache.prototype.set = listCacheSet;
1902 /*------------------------------------------------------------------------*/
1905 * Creates a map cache object to store key-value pairs.
1909 * @param {Array} [entries] The key-value pairs to cache.
1911 function MapCache(entries) {
1913 length = entries ? entries.length : 0;
1916 while (++index < length) {
1917 var entry = entries[index];
1918 this.set(entry[0], entry[1]);
1923 * Removes all key-value entries from the map.
1927 * @memberOf MapCache
1929 function mapCacheClear() {
1932 'map': new (Map || ListCache),
1938 * Removes `key` and its value from the map.
1942 * @memberOf MapCache
1943 * @param {string} key The key of the value to remove.
1944 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1946 function mapCacheDelete(key) {
1947 return getMapData(this, key)['delete'](key);
1951 * Gets the map value for `key`.
1955 * @memberOf MapCache
1956 * @param {string} key The key of the value to get.
1957 * @returns {*} Returns the entry value.
1959 function mapCacheGet(key) {
1960 return getMapData(this, key).get(key);
1964 * Checks if a map value for `key` exists.
1968 * @memberOf MapCache
1969 * @param {string} key The key of the entry to check.
1970 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1972 function mapCacheHas(key) {
1973 return getMapData(this, key).has(key);
1977 * Sets the map `key` to `value`.
1981 * @memberOf MapCache
1982 * @param {string} key The key of the value to set.
1983 * @param {*} value The value to set.
1984 * @returns {Object} Returns the map cache instance.
1986 function mapCacheSet(key, value) {
1987 getMapData(this, key).set(key, value);
1991 // Add methods to `MapCache`.
1992 MapCache.prototype.clear = mapCacheClear;
1993 MapCache.prototype['delete'] = mapCacheDelete;
1994 MapCache.prototype.get = mapCacheGet;
1995 MapCache.prototype.has = mapCacheHas;
1996 MapCache.prototype.set = mapCacheSet;
1998 /*------------------------------------------------------------------------*/
2002 * Creates an array cache object to store unique values.
2006 * @param {Array} [values] The values to cache.
2008 function SetCache(values) {
2010 length = values ? values.length : 0;
2012 this.__data__ = new MapCache;
2013 while (++index < length) {
2014 this.add(values[index]);
2019 * Adds `value` to the array cache.
2023 * @memberOf SetCache
2025 * @param {*} value The value to cache.
2026 * @returns {Object} Returns the cache instance.
2028 function setCacheAdd(value) {
2029 this.__data__.set(value, HASH_UNDEFINED);
2034 * Checks if `value` is in the array cache.
2038 * @memberOf SetCache
2039 * @param {*} value The value to search for.
2040 * @returns {number} Returns `true` if `value` is found, else `false`.
2042 function setCacheHas(value) {
2043 return this.__data__.has(value);
2046 // Add methods to `SetCache`.
2047 SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
2048 SetCache.prototype.has = setCacheHas;
2050 /*------------------------------------------------------------------------*/
2053 * Creates a stack cache object to store key-value pairs.
2057 * @param {Array} [entries] The key-value pairs to cache.
2059 function Stack(entries) {
2060 this.__data__ = new ListCache(entries);
2064 * Removes all key-value entries from the stack.
2070 function stackClear() {
2071 this.__data__ = new ListCache;
2075 * Removes `key` and its value from the stack.
2080 * @param {string} key The key of the value to remove.
2081 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2083 function stackDelete(key) {
2084 return this.__data__['delete'](key);
2088 * Gets the stack value for `key`.
2093 * @param {string} key The key of the value to get.
2094 * @returns {*} Returns the entry value.
2096 function stackGet(key) {
2097 return this.__data__.get(key);
2101 * Checks if a stack value for `key` exists.
2106 * @param {string} key The key of the entry to check.
2107 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2109 function stackHas(key) {
2110 return this.__data__.has(key);
2114 * Sets the stack `key` to `value`.
2119 * @param {string} key The key of the value to set.
2120 * @param {*} value The value to set.
2121 * @returns {Object} Returns the stack cache instance.
2123 function stackSet(key, value) {
2124 var cache = this.__data__;
2125 if (cache instanceof ListCache && cache.__data__.length == LARGE_ARRAY_SIZE) {
2126 cache = this.__data__ = new MapCache(cache.__data__);
2128 cache.set(key, value);
2132 // Add methods to `Stack`.
2133 Stack.prototype.clear = stackClear;
2134 Stack.prototype['delete'] = stackDelete;
2135 Stack.prototype.get = stackGet;
2136 Stack.prototype.has = stackHas;
2137 Stack.prototype.set = stackSet;
2139 /*------------------------------------------------------------------------*/
2142 * Used by `_.defaults` to customize its `_.assignIn` use.
2145 * @param {*} objValue The destination value.
2146 * @param {*} srcValue The source value.
2147 * @param {string} key The key of the property to assign.
2148 * @param {Object} object The parent object of `objValue`.
2149 * @returns {*} Returns the value to assign.
2151 function assignInDefaults(objValue, srcValue, key, object) {
2152 if (objValue === undefined ||
2153 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
2160 * This function is like `assignValue` except that it doesn't assign
2161 * `undefined` values.
2164 * @param {Object} object The object to modify.
2165 * @param {string} key The key of the property to assign.
2166 * @param {*} value The value to assign.
2168 function assignMergeValue(object, key, value) {
2169 if ((value !== undefined && !eq(object[key], value)) ||
2170 (typeof key == 'number' && value === undefined && !(key in object))) {
2171 object[key] = value;
2176 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2177 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2178 * for equality comparisons.
2181 * @param {Object} object The object to modify.
2182 * @param {string} key The key of the property to assign.
2183 * @param {*} value The value to assign.
2185 function assignValue(object, key, value) {
2186 var objValue = object[key];
2187 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2188 (value === undefined && !(key in object))) {
2189 object[key] = value;
2194 * Gets the index at which the `key` is found in `array` of key-value pairs.
2197 * @param {Array} array The array to search.
2198 * @param {*} key The key to search for.
2199 * @returns {number} Returns the index of the matched value, else `-1`.
2201 function assocIndexOf(array, key) {
2202 var length = array.length;
2204 if (eq(array[length][0], key)) {
2212 * Aggregates elements of `collection` on `accumulator` with keys transformed
2213 * by `iteratee` and values set by `setter`.
2216 * @param {Array|Object} collection The collection to iterate over.
2217 * @param {Function} setter The function to set `accumulator` values.
2218 * @param {Function} iteratee The iteratee to transform keys.
2219 * @param {Object} accumulator The initial aggregated object.
2220 * @returns {Function} Returns `accumulator`.
2222 function baseAggregator(collection, setter, iteratee, accumulator) {
2223 baseEach(collection, function(value, key, collection) {
2224 setter(accumulator, value, iteratee(value), collection);
2230 * The base implementation of `_.assign` without support for multiple sources
2231 * or `customizer` functions.
2234 * @param {Object} object The destination object.
2235 * @param {Object} source The source object.
2236 * @returns {Object} Returns `object`.
2238 function baseAssign(object, source) {
2239 return object && copyObject(source, keys(source), object);
2243 * The base implementation of `_.at` without support for individual paths.
2246 * @param {Object} object The object to iterate over.
2247 * @param {string[]} paths The property paths of elements to pick.
2248 * @returns {Array} Returns the picked elements.
2250 function baseAt(object, paths) {
2252 isNil = object == null,
2253 length = paths.length,
2254 result = Array(length);
2256 while (++index < length) {
2257 result[index] = isNil ? undefined : get(object, paths[index]);
2263 * The base implementation of `_.clamp` which doesn't coerce arguments to numbers.
2266 * @param {number} number The number to clamp.
2267 * @param {number} [lower] The lower bound.
2268 * @param {number} upper The upper bound.
2269 * @returns {number} Returns the clamped number.
2271 function baseClamp(number, lower, upper) {
2272 if (number === number) {
2273 if (upper !== undefined) {
2274 number = number <= upper ? number : upper;
2276 if (lower !== undefined) {
2277 number = number >= lower ? number : lower;
2284 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2285 * traversed objects.
2288 * @param {*} value The value to clone.
2289 * @param {boolean} [isDeep] Specify a deep clone.
2290 * @param {boolean} [isFull] Specify a clone including symbols.
2291 * @param {Function} [customizer] The function to customize cloning.
2292 * @param {string} [key] The key of `value`.
2293 * @param {Object} [object] The parent object of `value`.
2294 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2295 * @returns {*} Returns the cloned value.
2297 function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
2300 result = object ? customizer(value, key, object, stack) : customizer(value);
2302 if (result !== undefined) {
2305 if (!isObject(value)) {
2308 var isArr = isArray(value);
2310 result = initCloneArray(value);
2312 return copyArray(value, result);
2315 var tag = getTag(value),
2316 isFunc = tag == funcTag || tag == genTag;
2318 if (isBuffer(value)) {
2319 return cloneBuffer(value, isDeep);
2321 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2322 if (isHostObject(value)) {
2323 return object ? value : {};
2325 result = initCloneObject(isFunc ? {} : value);
2327 return copySymbols(value, baseAssign(result, value));
2330 if (!cloneableTags[tag]) {
2331 return object ? value : {};
2333 result = initCloneByTag(value, tag, baseClone, isDeep);
2336 // Check for circular references and return its corresponding clone.
2337 stack || (stack = new Stack);
2338 var stacked = stack.get(value);
2342 stack.set(value, result);
2345 var props = isFull ? getAllKeys(value) : keys(value);
2347 // Recursively populate clone (susceptible to call stack limits).
2348 arrayEach(props || value, function(subValue, key) {
2351 subValue = value[key];
2353 assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
2359 * The base implementation of `_.conforms` which doesn't clone `source`.
2362 * @param {Object} source The object of property predicates to conform to.
2363 * @returns {Function} Returns the new spec function.
2365 function baseConforms(source) {
2366 var props = keys(source),
2367 length = props.length;
2369 return function(object) {
2370 if (object == null) {
2375 var key = props[index],
2376 predicate = source[key],
2377 value = object[key];
2379 if ((value === undefined &&
2380 !(key in Object(object))) || !predicate(value)) {
2389 * The base implementation of `_.create` without support for assigning
2390 * properties to the created object.
2393 * @param {Object} prototype The object to inherit from.
2394 * @returns {Object} Returns the new object.
2396 function baseCreate(proto) {
2397 return isObject(proto) ? objectCreate(proto) : {};
2401 * The base implementation of `_.delay` and `_.defer` which accepts an array
2402 * of `func` arguments.
2405 * @param {Function} func The function to delay.
2406 * @param {number} wait The number of milliseconds to delay invocation.
2407 * @param {Object} args The arguments to provide to `func`.
2408 * @returns {number} Returns the timer id.
2410 function baseDelay(func, wait, args) {
2411 if (typeof func != 'function') {
2412 throw new TypeError(FUNC_ERROR_TEXT);
2414 return setTimeout(function() { func.apply(undefined, args); }, wait);
2418 * The base implementation of methods like `_.difference` without support
2419 * for excluding multiple arrays or iteratee shorthands.
2422 * @param {Array} array The array to inspect.
2423 * @param {Array} values The values to exclude.
2424 * @param {Function} [iteratee] The iteratee invoked per element.
2425 * @param {Function} [comparator] The comparator invoked per element.
2426 * @returns {Array} Returns the new array of filtered values.
2428 function baseDifference(array, values, iteratee, comparator) {
2430 includes = arrayIncludes,
2432 length = array.length,
2434 valuesLength = values.length;
2440 values = arrayMap(values, baseUnary(iteratee));
2443 includes = arrayIncludesWith;
2446 else if (values.length >= LARGE_ARRAY_SIZE) {
2447 includes = cacheHas;
2449 values = new SetCache(values);
2452 while (++index < length) {
2453 var value = array[index],
2454 computed = iteratee ? iteratee(value) : value;
2456 value = (comparator || value !== 0) ? value : 0;
2457 if (isCommon && computed === computed) {
2458 var valuesIndex = valuesLength;
2459 while (valuesIndex--) {
2460 if (values[valuesIndex] === computed) {
2466 else if (!includes(values, computed, comparator)) {
2474 * The base implementation of `_.forEach` without support for iteratee shorthands.
2477 * @param {Array|Object} collection The collection to iterate over.
2478 * @param {Function} iteratee The function invoked per iteration.
2479 * @returns {Array|Object} Returns `collection`.
2481 var baseEach = createBaseEach(baseForOwn);
2484 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2487 * @param {Array|Object} collection The collection to iterate over.
2488 * @param {Function} iteratee The function invoked per iteration.
2489 * @returns {Array|Object} Returns `collection`.
2491 var baseEachRight = createBaseEach(baseForOwnRight, true);
2494 * The base implementation of `_.every` without support for iteratee shorthands.
2497 * @param {Array|Object} collection The collection to iterate over.
2498 * @param {Function} predicate The function invoked per iteration.
2499 * @returns {boolean} Returns `true` if all elements pass the predicate check,
2502 function baseEvery(collection, predicate) {
2504 baseEach(collection, function(value, index, collection) {
2505 result = !!predicate(value, index, collection);
2512 * The base implementation of methods like `_.max` and `_.min` which accepts a
2513 * `comparator` to determine the extremum value.
2516 * @param {Array} array The array to iterate over.
2517 * @param {Function} iteratee The iteratee invoked per iteration.
2518 * @param {Function} comparator The comparator used to compare values.
2519 * @returns {*} Returns the extremum value.
2521 function baseExtremum(array, iteratee, comparator) {
2523 length = array.length;
2525 while (++index < length) {
2526 var value = array[index],
2527 current = iteratee(value);
2529 if (current != null && (computed === undefined
2530 ? (current === current && !isSymbol(current))
2531 : comparator(current, computed)
2533 var computed = current,
2541 * The base implementation of `_.fill` without an iteratee call guard.
2544 * @param {Array} array The array to fill.
2545 * @param {*} value The value to fill `array` with.
2546 * @param {number} [start=0] The start position.
2547 * @param {number} [end=array.length] The end position.
2548 * @returns {Array} Returns `array`.
2550 function baseFill(array, value, start, end) {
2551 var length = array.length;
2553 start = toInteger(start);
2555 start = -start > length ? 0 : (length + start);
2557 end = (end === undefined || end > length) ? length : toInteger(end);
2561 end = start > end ? 0 : toLength(end);
2562 while (start < end) {
2563 array[start++] = value;
2569 * The base implementation of `_.filter` without support for iteratee shorthands.
2572 * @param {Array|Object} collection The collection to iterate over.
2573 * @param {Function} predicate The function invoked per iteration.
2574 * @returns {Array} Returns the new filtered array.
2576 function baseFilter(collection, predicate) {
2578 baseEach(collection, function(value, index, collection) {
2579 if (predicate(value, index, collection)) {
2587 * The base implementation of `_.flatten` with support for restricting flattening.
2590 * @param {Array} array The array to flatten.
2591 * @param {number} depth The maximum recursion depth.
2592 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
2593 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
2594 * @param {Array} [result=[]] The initial result value.
2595 * @returns {Array} Returns the new flattened array.
2597 function baseFlatten(array, depth, predicate, isStrict, result) {
2599 length = array.length;
2601 predicate || (predicate = isFlattenable);
2602 result || (result = []);
2604 while (++index < length) {
2605 var value = array[index];
2606 if (depth > 0 && predicate(value)) {
2608 // Recursively flatten arrays (susceptible to call stack limits).
2609 baseFlatten(value, depth - 1, predicate, isStrict, result);
2611 arrayPush(result, value);
2613 } else if (!isStrict) {
2614 result[result.length] = value;
2621 * The base implementation of `baseForOwn` which iterates over `object`
2622 * properties returned by `keysFunc` and invokes `iteratee` for each property.
2623 * Iteratee functions may exit iteration early by explicitly returning `false`.
2626 * @param {Object} object The object to iterate over.
2627 * @param {Function} iteratee The function invoked per iteration.
2628 * @param {Function} keysFunc The function to get the keys of `object`.
2629 * @returns {Object} Returns `object`.
2631 var baseFor = createBaseFor();
2634 * This function is like `baseFor` except that it iterates over properties
2635 * in the opposite order.
2638 * @param {Object} object The object to iterate over.
2639 * @param {Function} iteratee The function invoked per iteration.
2640 * @param {Function} keysFunc The function to get the keys of `object`.
2641 * @returns {Object} Returns `object`.
2643 var baseForRight = createBaseFor(true);
2646 * The base implementation of `_.forOwn` without support for iteratee shorthands.
2649 * @param {Object} object The object to iterate over.
2650 * @param {Function} iteratee The function invoked per iteration.
2651 * @returns {Object} Returns `object`.
2653 function baseForOwn(object, iteratee) {
2654 return object && baseFor(object, iteratee, keys);
2658 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
2661 * @param {Object} object The object to iterate over.
2662 * @param {Function} iteratee The function invoked per iteration.
2663 * @returns {Object} Returns `object`.
2665 function baseForOwnRight(object, iteratee) {
2666 return object && baseForRight(object, iteratee, keys);
2670 * The base implementation of `_.functions` which creates an array of
2671 * `object` function property names filtered from `props`.
2674 * @param {Object} object The object to inspect.
2675 * @param {Array} props The property names to filter.
2676 * @returns {Array} Returns the function names.
2678 function baseFunctions(object, props) {
2679 return arrayFilter(props, function(key) {
2680 return isFunction(object[key]);
2685 * The base implementation of `_.get` without support for default values.
2688 * @param {Object} object The object to query.
2689 * @param {Array|string} path The path of the property to get.
2690 * @returns {*} Returns the resolved value.
2692 function baseGet(object, path) {
2693 path = isKey(path, object) ? [path] : castPath(path);
2696 length = path.length;
2698 while (object != null && index < length) {
2699 object = object[toKey(path[index++])];
2701 return (index && index == length) ? object : undefined;
2705 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
2706 * `keysFunc` and `symbolsFunc` to get the enumerable property names and
2707 * symbols of `object`.
2710 * @param {Object} object The object to query.
2711 * @param {Function} keysFunc The function to get the keys of `object`.
2712 * @param {Function} symbolsFunc The function to get the symbols of `object`.
2713 * @returns {Array} Returns the array of property names and symbols.
2715 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
2716 var result = keysFunc(object);
2717 return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
2721 * The base implementation of `_.gt` which doesn't coerce arguments to numbers.
2724 * @param {*} value The value to compare.
2725 * @param {*} other The other value to compare.
2726 * @returns {boolean} Returns `true` if `value` is greater than `other`,
2729 function baseGt(value, other) {
2730 return value > other;
2734 * The base implementation of `_.has` without support for deep paths.
2737 * @param {Object} [object] The object to query.
2738 * @param {Array|string} key The key to check.
2739 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2741 function baseHas(object, key) {
2742 // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
2743 // that are composed entirely of index properties, return `false` for
2744 // `hasOwnProperty` checks of them.
2745 return object != null &&
2746 (hasOwnProperty.call(object, key) ||
2747 (typeof object == 'object' && key in object && getPrototype(object) === null));
2751 * The base implementation of `_.hasIn` without support for deep paths.
2754 * @param {Object} [object] The object to query.
2755 * @param {Array|string} key The key to check.
2756 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2758 function baseHasIn(object, key) {
2759 return object != null && key in Object(object);
2763 * The base implementation of `_.inRange` which doesn't coerce arguments to numbers.
2766 * @param {number} number The number to check.
2767 * @param {number} start The start of the range.
2768 * @param {number} end The end of the range.
2769 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
2771 function baseInRange(number, start, end) {
2772 return number >= nativeMin(start, end) && number < nativeMax(start, end);
2776 * The base implementation of methods like `_.intersection`, without support
2777 * for iteratee shorthands, that accepts an array of arrays to inspect.
2780 * @param {Array} arrays The arrays to inspect.
2781 * @param {Function} [iteratee] The iteratee invoked per element.
2782 * @param {Function} [comparator] The comparator invoked per element.
2783 * @returns {Array} Returns the new array of shared values.
2785 function baseIntersection(arrays, iteratee, comparator) {
2786 var includes = comparator ? arrayIncludesWith : arrayIncludes,
2787 length = arrays[0].length,
2788 othLength = arrays.length,
2789 othIndex = othLength,
2790 caches = Array(othLength),
2791 maxLength = Infinity,
2794 while (othIndex--) {
2795 var array = arrays[othIndex];
2796 if (othIndex && iteratee) {
2797 array = arrayMap(array, baseUnary(iteratee));
2799 maxLength = nativeMin(array.length, maxLength);
2800 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
2801 ? new SetCache(othIndex && array)
2810 while (++index < length && result.length < maxLength) {
2811 var value = array[index],
2812 computed = iteratee ? iteratee(value) : value;
2814 value = (comparator || value !== 0) ? value : 0;
2816 ? cacheHas(seen, computed)
2817 : includes(result, computed, comparator)
2819 othIndex = othLength;
2820 while (--othIndex) {
2821 var cache = caches[othIndex];
2823 ? cacheHas(cache, computed)
2824 : includes(arrays[othIndex], computed, comparator))
2830 seen.push(computed);
2839 * The base implementation of `_.invert` and `_.invertBy` which inverts
2840 * `object` with values transformed by `iteratee` and set by `setter`.
2843 * @param {Object} object The object to iterate over.
2844 * @param {Function} setter The function to set `accumulator` values.
2845 * @param {Function} iteratee The iteratee to transform values.
2846 * @param {Object} accumulator The initial inverted object.
2847 * @returns {Function} Returns `accumulator`.
2849 function baseInverter(object, setter, iteratee, accumulator) {
2850 baseForOwn(object, function(value, key, object) {
2851 setter(accumulator, iteratee(value), key, object);
2857 * The base implementation of `_.invoke` without support for individual
2861 * @param {Object} object The object to query.
2862 * @param {Array|string} path The path of the method to invoke.
2863 * @param {Array} args The arguments to invoke the method with.
2864 * @returns {*} Returns the result of the invoked method.
2866 function baseInvoke(object, path, args) {
2867 if (!isKey(path, object)) {
2868 path = castPath(path);
2869 object = parent(object, path);
2872 var func = object == null ? object : object[toKey(path)];
2873 return func == null ? undefined : apply(func, object, args);
2877 * The base implementation of `_.isEqual` which supports partial comparisons
2878 * and tracks traversed objects.
2881 * @param {*} value The value to compare.
2882 * @param {*} other The other value to compare.
2883 * @param {Function} [customizer] The function to customize comparisons.
2884 * @param {boolean} [bitmask] The bitmask of comparison flags.
2885 * The bitmask may be composed of the following flags:
2886 * 1 - Unordered comparison
2887 * 2 - Partial comparison
2888 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
2889 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2891 function baseIsEqual(value, other, customizer, bitmask, stack) {
2892 if (value === other) {
2895 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
2896 return value !== value && other !== other;
2898 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
2902 * A specialized version of `baseIsEqual` for arrays and objects which performs
2903 * deep comparisons and tracks traversed objects enabling objects with circular
2904 * references to be compared.
2907 * @param {Object} object The object to compare.
2908 * @param {Object} other The other object to compare.
2909 * @param {Function} equalFunc The function to determine equivalents of values.
2910 * @param {Function} [customizer] The function to customize comparisons.
2911 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
2913 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
2914 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2916 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
2917 var objIsArr = isArray(object),
2918 othIsArr = isArray(other),
2923 objTag = getTag(object);
2924 objTag = objTag == argsTag ? objectTag : objTag;
2927 othTag = getTag(other);
2928 othTag = othTag == argsTag ? objectTag : othTag;
2930 var objIsObj = objTag == objectTag && !isHostObject(object),
2931 othIsObj = othTag == objectTag && !isHostObject(other),
2932 isSameTag = objTag == othTag;
2934 if (isSameTag && !objIsObj) {
2935 stack || (stack = new Stack);
2936 return (objIsArr || isTypedArray(object))
2937 ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
2938 : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
2940 if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
2941 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2942 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2944 if (objIsWrapped || othIsWrapped) {
2945 var objUnwrapped = objIsWrapped ? object.value() : object,
2946 othUnwrapped = othIsWrapped ? other.value() : other;
2948 stack || (stack = new Stack);
2949 return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
2955 stack || (stack = new Stack);
2956 return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
2960 * The base implementation of `_.isMatch` without support for iteratee shorthands.
2963 * @param {Object} object The object to inspect.
2964 * @param {Object} source The object of property values to match.
2965 * @param {Array} matchData The property names, values, and compare flags to match.
2966 * @param {Function} [customizer] The function to customize comparisons.
2967 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2969 function baseIsMatch(object, source, matchData, customizer) {
2970 var index = matchData.length,
2972 noCustomizer = !customizer;
2974 if (object == null) {
2977 object = Object(object);
2979 var data = matchData[index];
2980 if ((noCustomizer && data[2])
2981 ? data[1] !== object[data[0]]
2982 : !(data[0] in object)
2987 while (++index < length) {
2988 data = matchData[index];
2990 objValue = object[key],
2993 if (noCustomizer && data[2]) {
2994 if (objValue === undefined && !(key in object)) {
2998 var stack = new Stack;
3000 var result = customizer(objValue, srcValue, key, object, source, stack);
3002 if (!(result === undefined
3003 ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
3014 * The base implementation of `_.isNative` without bad shim checks.
3017 * @param {*} value The value to check.
3018 * @returns {boolean} Returns `true` if `value` is a native function,
3021 function baseIsNative(value) {
3022 if (!isObject(value) || isMasked(value)) {
3025 var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
3026 return pattern.test(toSource(value));
3030 * The base implementation of `_.iteratee`.
3033 * @param {*} [value=_.identity] The value to convert to an iteratee.
3034 * @returns {Function} Returns the iteratee.
3036 function baseIteratee(value) {
3037 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
3038 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
3039 if (typeof value == 'function') {
3042 if (value == null) {
3045 if (typeof value == 'object') {
3046 return isArray(value)
3047 ? baseMatchesProperty(value[0], value[1])
3048 : baseMatches(value);
3050 return property(value);
3054 * The base implementation of `_.keys` which doesn't skip the constructor
3055 * property of prototypes or treat sparse arrays as dense.
3058 * @param {Object} object The object to query.
3059 * @returns {Array} Returns the array of property names.
3061 function baseKeys(object) {
3062 return nativeKeys(Object(object));
3066 * The base implementation of `_.keysIn` which doesn't skip the constructor
3067 * property of prototypes or treat sparse arrays as dense.
3070 * @param {Object} object The object to query.
3071 * @returns {Array} Returns the array of property names.
3073 function baseKeysIn(object) {
3074 object = object == null ? object : Object(object);
3077 for (var key in object) {
3083 // Fallback for IE < 9 with es6-shim.
3084 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
3085 baseKeysIn = function(object) {
3086 return iteratorToArray(enumerate(object));
3091 * The base implementation of `_.lt` which doesn't coerce arguments to numbers.
3094 * @param {*} value The value to compare.
3095 * @param {*} other The other value to compare.
3096 * @returns {boolean} Returns `true` if `value` is less than `other`,
3099 function baseLt(value, other) {
3100 return value < other;
3104 * The base implementation of `_.map` without support for iteratee shorthands.
3107 * @param {Array|Object} collection The collection to iterate over.
3108 * @param {Function} iteratee The function invoked per iteration.
3109 * @returns {Array} Returns the new mapped array.
3111 function baseMap(collection, iteratee) {
3113 result = isArrayLike(collection) ? Array(collection.length) : [];
3115 baseEach(collection, function(value, key, collection) {
3116 result[++index] = iteratee(value, key, collection);
3122 * The base implementation of `_.matches` which doesn't clone `source`.
3125 * @param {Object} source The object of property values to match.
3126 * @returns {Function} Returns the new spec function.
3128 function baseMatches(source) {
3129 var matchData = getMatchData(source);
3130 if (matchData.length == 1 && matchData[0][2]) {
3131 return matchesStrictComparable(matchData[0][0], matchData[0][1]);
3133 return function(object) {
3134 return object === source || baseIsMatch(object, source, matchData);
3139 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3142 * @param {string} path The path of the property to get.
3143 * @param {*} srcValue The value to match.
3144 * @returns {Function} Returns the new spec function.
3146 function baseMatchesProperty(path, srcValue) {
3147 if (isKey(path) && isStrictComparable(srcValue)) {
3148 return matchesStrictComparable(toKey(path), srcValue);
3150 return function(object) {
3151 var objValue = get(object, path);
3152 return (objValue === undefined && objValue === srcValue)
3153 ? hasIn(object, path)
3154 : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
3159 * The base implementation of `_.merge` without support for multiple sources.
3162 * @param {Object} object The destination object.
3163 * @param {Object} source The source object.
3164 * @param {number} srcIndex The index of `source`.
3165 * @param {Function} [customizer] The function to customize merged values.
3166 * @param {Object} [stack] Tracks traversed source values and their merged
3169 function baseMerge(object, source, srcIndex, customizer, stack) {
3170 if (object === source) {
3173 if (!(isArray(source) || isTypedArray(source))) {
3174 var props = keysIn(source);
3176 arrayEach(props || source, function(srcValue, key) {
3179 srcValue = source[key];
3181 if (isObject(srcValue)) {
3182 stack || (stack = new Stack);
3183 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3186 var newValue = customizer
3187 ? customizer(object[key], srcValue, (key + ''), object, source, stack)
3190 if (newValue === undefined) {
3191 newValue = srcValue;
3193 assignMergeValue(object, key, newValue);
3199 * A specialized version of `baseMerge` for arrays and objects which performs
3200 * deep merges and tracks traversed objects enabling objects with circular
3201 * references to be merged.
3204 * @param {Object} object The destination object.
3205 * @param {Object} source The source object.
3206 * @param {string} key The key of the value to merge.
3207 * @param {number} srcIndex The index of `source`.
3208 * @param {Function} mergeFunc The function to merge values.
3209 * @param {Function} [customizer] The function to customize assigned values.
3210 * @param {Object} [stack] Tracks traversed source values and their merged
3213 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3214 var objValue = object[key],
3215 srcValue = source[key],
3216 stacked = stack.get(srcValue);
3219 assignMergeValue(object, key, stacked);
3222 var newValue = customizer
3223 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3226 var isCommon = newValue === undefined;
3229 newValue = srcValue;
3230 if (isArray(srcValue) || isTypedArray(srcValue)) {
3231 if (isArray(objValue)) {
3232 newValue = objValue;
3234 else if (isArrayLikeObject(objValue)) {
3235 newValue = copyArray(objValue);
3239 newValue = baseClone(srcValue, true);
3242 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3243 if (isArguments(objValue)) {
3244 newValue = toPlainObject(objValue);
3246 else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
3248 newValue = baseClone(srcValue, true);
3251 newValue = objValue;
3258 stack.set(srcValue, newValue);
3261 // Recursively merge objects and arrays (susceptible to call stack limits).
3262 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3264 stack['delete'](srcValue);
3265 assignMergeValue(object, key, newValue);
3269 * The base implementation of `_.nth` which doesn't coerce `n` to an integer.
3272 * @param {Array} array The array to query.
3273 * @param {number} n The index of the element to return.
3274 * @returns {*} Returns the nth element of `array`.
3276 function baseNth(array, n) {
3277 var length = array.length;
3281 n += n < 0 ? length : 0;
3282 return isIndex(n, length) ? array[n] : undefined;
3286 * The base implementation of `_.orderBy` without param guards.
3289 * @param {Array|Object} collection The collection to iterate over.
3290 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3291 * @param {string[]} orders The sort orders of `iteratees`.
3292 * @returns {Array} Returns the new sorted array.
3294 function baseOrderBy(collection, iteratees, orders) {
3296 iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
3298 var result = baseMap(collection, function(value, key, collection) {
3299 var criteria = arrayMap(iteratees, function(iteratee) {
3300 return iteratee(value);
3302 return { 'criteria': criteria, 'index': ++index, 'value': value };
3305 return baseSortBy(result, function(object, other) {
3306 return compareMultiple(object, other, orders);
3311 * The base implementation of `_.pick` without support for individual
3312 * property identifiers.
3315 * @param {Object} object The source object.
3316 * @param {string[]} props The property identifiers to pick.
3317 * @returns {Object} Returns the new object.
3319 function basePick(object, props) {
3320 object = Object(object);
3321 return arrayReduce(props, function(result, key) {
3322 if (key in object) {
3323 result[key] = object[key];
3330 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3333 * @param {Object} object The source object.
3334 * @param {Function} predicate The function invoked per property.
3335 * @returns {Object} Returns the new object.
3337 function basePickBy(object, predicate) {
3339 props = getAllKeysIn(object),
3340 length = props.length,
3343 while (++index < length) {
3344 var key = props[index],
3345 value = object[key];
3347 if (predicate(value, key)) {
3348 result[key] = value;
3355 * The base implementation of `_.property` without support for deep paths.
3358 * @param {string} key The key of the property to get.
3359 * @returns {Function} Returns the new accessor function.
3361 function baseProperty(key) {
3362 return function(object) {
3363 return object == null ? undefined : object[key];
3368 * A specialized version of `baseProperty` which supports deep paths.
3371 * @param {Array|string} path The path of the property to get.
3372 * @returns {Function} Returns the new accessor function.
3374 function basePropertyDeep(path) {
3375 return function(object) {
3376 return baseGet(object, path);
3381 * The base implementation of `_.pullAllBy` without support for iteratee
3385 * @param {Array} array The array to modify.
3386 * @param {Array} values The values to remove.
3387 * @param {Function} [iteratee] The iteratee invoked per element.
3388 * @param {Function} [comparator] The comparator invoked per element.
3389 * @returns {Array} Returns `array`.
3391 function basePullAll(array, values, iteratee, comparator) {
3392 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
3394 length = values.length,
3397 if (array === values) {
3398 values = copyArray(values);
3401 seen = arrayMap(array, baseUnary(iteratee));
3403 while (++index < length) {
3405 value = values[index],
3406 computed = iteratee ? iteratee(value) : value;
3408 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
3409 if (seen !== array) {
3410 splice.call(seen, fromIndex, 1);
3412 splice.call(array, fromIndex, 1);
3419 * The base implementation of `_.pullAt` without support for individual
3420 * indexes or capturing the removed elements.
3423 * @param {Array} array The array to modify.
3424 * @param {number[]} indexes The indexes of elements to remove.
3425 * @returns {Array} Returns `array`.
3427 function basePullAt(array, indexes) {
3428 var length = array ? indexes.length : 0,
3429 lastIndex = length - 1;
3432 var index = indexes[length];
3433 if (length == lastIndex || index !== previous) {
3434 var previous = index;
3435 if (isIndex(index)) {
3436 splice.call(array, index, 1);
3438 else if (!isKey(index, array)) {
3439 var path = castPath(index),
3440 object = parent(array, path);
3442 if (object != null) {
3443 delete object[toKey(last(path))];
3447 delete array[toKey(index)];
3455 * The base implementation of `_.random` without support for returning
3456 * floating-point numbers.
3459 * @param {number} lower The lower bound.
3460 * @param {number} upper The upper bound.
3461 * @returns {number} Returns the random number.
3463 function baseRandom(lower, upper) {
3464 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3468 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3469 * coerce arguments to numbers.
3472 * @param {number} start The start of the range.
3473 * @param {number} end The end of the range.
3474 * @param {number} step The value to increment or decrement by.
3475 * @param {boolean} [fromRight] Specify iterating from right to left.
3476 * @returns {Array} Returns the range of numbers.
3478 function baseRange(start, end, step, fromRight) {
3480 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3481 result = Array(length);
3484 result[fromRight ? length : ++index] = start;
3491 * The base implementation of `_.repeat` which doesn't coerce arguments.
3494 * @param {string} string The string to repeat.
3495 * @param {number} n The number of times to repeat the string.
3496 * @returns {string} Returns the repeated string.
3498 function baseRepeat(string, n) {
3500 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
3503 // Leverage the exponentiation by squaring algorithm for a faster repeat.
3504 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
3509 n = nativeFloor(n / 2);
3519 * The base implementation of `_.set`.
3522 * @param {Object} object The object to query.
3523 * @param {Array|string} path The path of the property to set.
3524 * @param {*} value The value to set.
3525 * @param {Function} [customizer] The function to customize path creation.
3526 * @returns {Object} Returns `object`.
3528 function baseSet(object, path, value, customizer) {
3529 path = isKey(path, object) ? [path] : castPath(path);
3532 length = path.length,
3533 lastIndex = length - 1,
3536 while (nested != null && ++index < length) {
3537 var key = toKey(path[index]);
3538 if (isObject(nested)) {
3539 var newValue = value;
3540 if (index != lastIndex) {
3541 var objValue = nested[key];
3542 newValue = customizer ? customizer(objValue, key, nested) : undefined;
3543 if (newValue === undefined) {
3544 newValue = objValue == null
3545 ? (isIndex(path[index + 1]) ? [] : {})
3549 assignValue(nested, key, newValue);
3551 nested = nested[key];
3557 * The base implementation of `setData` without support for hot loop detection.
3560 * @param {Function} func The function to associate metadata with.
3561 * @param {*} data The metadata.
3562 * @returns {Function} Returns `func`.
3564 var baseSetData = !metaMap ? identity : function(func, data) {
3565 metaMap.set(func, data);
3570 * The base implementation of `_.slice` without an iteratee call guard.
3573 * @param {Array} array The array to slice.
3574 * @param {number} [start=0] The start position.
3575 * @param {number} [end=array.length] The end position.
3576 * @returns {Array} Returns the slice of `array`.
3578 function baseSlice(array, start, end) {
3580 length = array.length;
3583 start = -start > length ? 0 : (length + start);
3585 end = end > length ? length : end;
3589 length = start > end ? 0 : ((end - start) >>> 0);
3592 var result = Array(length);
3593 while (++index < length) {
3594 result[index] = array[index + start];
3600 * The base implementation of `_.some` without support for iteratee shorthands.
3603 * @param {Array|Object} collection The collection to iterate over.
3604 * @param {Function} predicate The function invoked per iteration.
3605 * @returns {boolean} Returns `true` if any element passes the predicate check,
3608 function baseSome(collection, predicate) {
3611 baseEach(collection, function(value, index, collection) {
3612 result = predicate(value, index, collection);
3619 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
3620 * performs a binary search of `array` to determine the index at which `value`
3621 * should be inserted into `array` in order to maintain its sort order.
3624 * @param {Array} array The sorted array to inspect.
3625 * @param {*} value The value to evaluate.
3626 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3627 * @returns {number} Returns the index at which `value` should be inserted
3630 function baseSortedIndex(array, value, retHighest) {
3632 high = array ? array.length : low;
3634 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
3635 while (low < high) {
3636 var mid = (low + high) >>> 1,
3637 computed = array[mid];
3639 if (computed !== null && !isSymbol(computed) &&
3640 (retHighest ? (computed <= value) : (computed < value))) {
3648 return baseSortedIndexBy(array, value, identity, retHighest);
3652 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
3653 * which invokes `iteratee` for `value` and each element of `array` to compute
3654 * their sort ranking. The iteratee is invoked with one argument; (value).
3657 * @param {Array} array The sorted array to inspect.
3658 * @param {*} value The value to evaluate.
3659 * @param {Function} iteratee The iteratee invoked per element.
3660 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3661 * @returns {number} Returns the index at which `value` should be inserted
3664 function baseSortedIndexBy(array, value, iteratee, retHighest) {
3665 value = iteratee(value);
3668 high = array ? array.length : 0,
3669 valIsNaN = value !== value,
3670 valIsNull = value === null,
3671 valIsSymbol = isSymbol(value),
3672 valIsUndefined = value === undefined;
3674 while (low < high) {
3675 var mid = nativeFloor((low + high) / 2),
3676 computed = iteratee(array[mid]),
3677 othIsDefined = computed !== undefined,
3678 othIsNull = computed === null,
3679 othIsReflexive = computed === computed,
3680 othIsSymbol = isSymbol(computed);
3683 var setLow = retHighest || othIsReflexive;
3684 } else if (valIsUndefined) {
3685 setLow = othIsReflexive && (retHighest || othIsDefined);
3686 } else if (valIsNull) {
3687 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
3688 } else if (valIsSymbol) {
3689 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
3690 } else if (othIsNull || othIsSymbol) {
3693 setLow = retHighest ? (computed <= value) : (computed < value);
3701 return nativeMin(high, MAX_ARRAY_INDEX);
3705 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
3706 * support for iteratee shorthands.
3709 * @param {Array} array The array to inspect.
3710 * @param {Function} [iteratee] The iteratee invoked per element.
3711 * @returns {Array} Returns the new duplicate free array.
3713 function baseSortedUniq(array, iteratee) {
3715 length = array.length,
3719 while (++index < length) {
3720 var value = array[index],
3721 computed = iteratee ? iteratee(value) : value;
3723 if (!index || !eq(computed, seen)) {
3724 var seen = computed;
3725 result[resIndex++] = value === 0 ? 0 : value;
3732 * The base implementation of `_.toNumber` which doesn't ensure correct
3733 * conversions of binary, hexadecimal, or octal string values.
3736 * @param {*} value The value to process.
3737 * @returns {number} Returns the number.
3739 function baseToNumber(value) {
3740 if (typeof value == 'number') {
3743 if (isSymbol(value)) {
3750 * The base implementation of `_.toString` which doesn't convert nullish
3751 * values to empty strings.
3754 * @param {*} value The value to process.
3755 * @returns {string} Returns the string.
3757 function baseToString(value) {
3758 // Exit early for strings to avoid a performance hit in some environments.
3759 if (typeof value == 'string') {
3762 if (isSymbol(value)) {
3763 return symbolToString ? symbolToString.call(value) : '';
3765 var result = (value + '');
3766 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
3770 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
3773 * @param {Array} array The array to inspect.
3774 * @param {Function} [iteratee] The iteratee invoked per element.
3775 * @param {Function} [comparator] The comparator invoked per element.
3776 * @returns {Array} Returns the new duplicate free array.
3778 function baseUniq(array, iteratee, comparator) {
3780 includes = arrayIncludes,
3781 length = array.length,
3788 includes = arrayIncludesWith;
3790 else if (length >= LARGE_ARRAY_SIZE) {
3791 var set = iteratee ? null : createSet(array);
3793 return setToArray(set);
3796 includes = cacheHas;
3797 seen = new SetCache;
3800 seen = iteratee ? [] : result;
3803 while (++index < length) {
3804 var value = array[index],
3805 computed = iteratee ? iteratee(value) : value;
3807 value = (comparator || value !== 0) ? value : 0;
3808 if (isCommon && computed === computed) {
3809 var seenIndex = seen.length;
3810 while (seenIndex--) {
3811 if (seen[seenIndex] === computed) {
3816 seen.push(computed);
3820 else if (!includes(seen, computed, comparator)) {
3821 if (seen !== result) {
3822 seen.push(computed);
3831 * The base implementation of `_.unset`.
3834 * @param {Object} object The object to modify.
3835 * @param {Array|string} path The path of the property to unset.
3836 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
3838 function baseUnset(object, path) {
3839 path = isKey(path, object) ? [path] : castPath(path);
3840 object = parent(object, path);
3842 var key = toKey(last(path));
3843 return !(object != null && baseHas(object, key)) || delete object[key];
3847 * The base implementation of `_.update`.
3850 * @param {Object} object The object to query.
3851 * @param {Array|string} path The path of the property to update.
3852 * @param {Function} updater The function to produce the updated value.
3853 * @param {Function} [customizer] The function to customize path creation.
3854 * @returns {Object} Returns `object`.
3856 function baseUpdate(object, path, updater, customizer) {
3857 return baseSet(object, path, updater(baseGet(object, path)), customizer);
3861 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
3862 * without support for iteratee shorthands.
3865 * @param {Array} array The array to query.
3866 * @param {Function} predicate The function invoked per iteration.
3867 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
3868 * @param {boolean} [fromRight] Specify iterating from right to left.
3869 * @returns {Array} Returns the slice of `array`.
3871 function baseWhile(array, predicate, isDrop, fromRight) {
3872 var length = array.length,
3873 index = fromRight ? length : -1;
3875 while ((fromRight ? index-- : ++index < length) &&
3876 predicate(array[index], index, array)) {}
3879 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
3880 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
3884 * The base implementation of `wrapperValue` which returns the result of
3885 * performing a sequence of actions on the unwrapped `value`, where each
3886 * successive action is supplied the return value of the previous.
3889 * @param {*} value The unwrapped value.
3890 * @param {Array} actions Actions to perform to resolve the unwrapped value.
3891 * @returns {*} Returns the resolved value.
3893 function baseWrapperValue(value, actions) {
3895 if (result instanceof LazyWrapper) {
3896 result = result.value();
3898 return arrayReduce(actions, function(result, action) {
3899 return action.func.apply(action.thisArg, arrayPush([result], action.args));
3904 * The base implementation of methods like `_.xor`, without support for
3905 * iteratee shorthands, that accepts an array of arrays to inspect.
3908 * @param {Array} arrays The arrays to inspect.
3909 * @param {Function} [iteratee] The iteratee invoked per element.
3910 * @param {Function} [comparator] The comparator invoked per element.
3911 * @returns {Array} Returns the new array of values.
3913 function baseXor(arrays, iteratee, comparator) {
3915 length = arrays.length;
3917 while (++index < length) {
3920 baseDifference(result, arrays[index], iteratee, comparator),
3921 baseDifference(arrays[index], result, iteratee, comparator)
3925 return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
3929 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
3932 * @param {Array} props The property identifiers.
3933 * @param {Array} values The property values.
3934 * @param {Function} assignFunc The function to assign values.
3935 * @returns {Object} Returns the new object.
3937 function baseZipObject(props, values, assignFunc) {
3939 length = props.length,
3940 valsLength = values.length,
3943 while (++index < length) {
3944 var value = index < valsLength ? values[index] : undefined;
3945 assignFunc(result, props[index], value);
3951 * Casts `value` to an empty array if it's not an array like object.
3954 * @param {*} value The value to inspect.
3955 * @returns {Array|Object} Returns the cast array-like object.
3957 function castArrayLikeObject(value) {
3958 return isArrayLikeObject(value) ? value : [];
3962 * Casts `value` to `identity` if it's not a function.
3965 * @param {*} value The value to inspect.
3966 * @returns {Function} Returns cast function.
3968 function castFunction(value) {
3969 return typeof value == 'function' ? value : identity;
3973 * Casts `value` to a path array if it's not one.
3976 * @param {*} value The value to inspect.
3977 * @returns {Array} Returns the cast property path array.
3979 function castPath(value) {
3980 return isArray(value) ? value : stringToPath(value);
3984 * Casts `array` to a slice if it's needed.
3987 * @param {Array} array The array to inspect.
3988 * @param {number} start The start position.
3989 * @param {number} [end=array.length] The end position.
3990 * @returns {Array} Returns the cast slice.
3992 function castSlice(array, start, end) {
3993 var length = array.length;
3994 end = end === undefined ? length : end;
3995 return (!start && end >= length) ? array : baseSlice(array, start, end);
3999 * Creates a clone of `buffer`.
4002 * @param {Buffer} buffer The buffer to clone.
4003 * @param {boolean} [isDeep] Specify a deep clone.
4004 * @returns {Buffer} Returns the cloned buffer.
4006 function cloneBuffer(buffer, isDeep) {
4008 return buffer.slice();
4010 var result = new buffer.constructor(buffer.length);
4011 buffer.copy(result);
4016 * Creates a clone of `arrayBuffer`.
4019 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
4020 * @returns {ArrayBuffer} Returns the cloned array buffer.
4022 function cloneArrayBuffer(arrayBuffer) {
4023 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
4024 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
4029 * Creates a clone of `dataView`.
4032 * @param {Object} dataView The data view to clone.
4033 * @param {boolean} [isDeep] Specify a deep clone.
4034 * @returns {Object} Returns the cloned data view.
4036 function cloneDataView(dataView, isDeep) {
4037 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
4038 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
4042 * Creates a clone of `map`.
4045 * @param {Object} map The map to clone.
4046 * @param {Function} cloneFunc The function to clone values.
4047 * @param {boolean} [isDeep] Specify a deep clone.
4048 * @returns {Object} Returns the cloned map.
4050 function cloneMap(map, isDeep, cloneFunc) {
4051 var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
4052 return arrayReduce(array, addMapEntry, new map.constructor);
4056 * Creates a clone of `regexp`.
4059 * @param {Object} regexp The regexp to clone.
4060 * @returns {Object} Returns the cloned regexp.
4062 function cloneRegExp(regexp) {
4063 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
4064 result.lastIndex = regexp.lastIndex;
4069 * Creates a clone of `set`.
4072 * @param {Object} set The set to clone.
4073 * @param {Function} cloneFunc The function to clone values.
4074 * @param {boolean} [isDeep] Specify a deep clone.
4075 * @returns {Object} Returns the cloned set.
4077 function cloneSet(set, isDeep, cloneFunc) {
4078 var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
4079 return arrayReduce(array, addSetEntry, new set.constructor);
4083 * Creates a clone of the `symbol` object.
4086 * @param {Object} symbol The symbol object to clone.
4087 * @returns {Object} Returns the cloned symbol object.
4089 function cloneSymbol(symbol) {
4090 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
4094 * Creates a clone of `typedArray`.
4097 * @param {Object} typedArray The typed array to clone.
4098 * @param {boolean} [isDeep] Specify a deep clone.
4099 * @returns {Object} Returns the cloned typed array.
4101 function cloneTypedArray(typedArray, isDeep) {
4102 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
4103 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
4107 * Compares values to sort them in ascending order.
4110 * @param {*} value The value to compare.
4111 * @param {*} other The other value to compare.
4112 * @returns {number} Returns the sort order indicator for `value`.
4114 function compareAscending(value, other) {
4115 if (value !== other) {
4116 var valIsDefined = value !== undefined,
4117 valIsNull = value === null,
4118 valIsReflexive = value === value,
4119 valIsSymbol = isSymbol(value);
4121 var othIsDefined = other !== undefined,
4122 othIsNull = other === null,
4123 othIsReflexive = other === other,
4124 othIsSymbol = isSymbol(other);
4126 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
4127 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
4128 (valIsNull && othIsDefined && othIsReflexive) ||
4129 (!valIsDefined && othIsReflexive) ||
4133 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
4134 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
4135 (othIsNull && valIsDefined && valIsReflexive) ||
4136 (!othIsDefined && valIsReflexive) ||
4145 * Used by `_.orderBy` to compare multiple properties of a value to another
4146 * and stable sort them.
4148 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
4149 * specify an order of "desc" for descending or "asc" for ascending sort order
4150 * of corresponding values.
4153 * @param {Object} object The object to compare.
4154 * @param {Object} other The other object to compare.
4155 * @param {boolean[]|string[]} orders The order to sort by for each property.
4156 * @returns {number} Returns the sort order indicator for `object`.
4158 function compareMultiple(object, other, orders) {
4160 objCriteria = object.criteria,
4161 othCriteria = other.criteria,
4162 length = objCriteria.length,
4163 ordersLength = orders.length;
4165 while (++index < length) {
4166 var result = compareAscending(objCriteria[index], othCriteria[index]);
4168 if (index >= ordersLength) {
4171 var order = orders[index];
4172 return result * (order == 'desc' ? -1 : 1);
4175 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
4176 // that causes it, under certain circumstances, to provide the same value for
4177 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
4178 // for more details.
4180 // This also ensures a stable sort in V8 and other engines.
4181 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
4182 return object.index - other.index;
4186 * Creates an array that is the composition of partially applied arguments,
4187 * placeholders, and provided arguments into a single array of arguments.
4190 * @param {Array} args The provided arguments.
4191 * @param {Array} partials The arguments to prepend to those provided.
4192 * @param {Array} holders The `partials` placeholder indexes.
4193 * @params {boolean} [isCurried] Specify composing for a curried function.
4194 * @returns {Array} Returns the new array of composed arguments.
4196 function composeArgs(args, partials, holders, isCurried) {
4198 argsLength = args.length,
4199 holdersLength = holders.length,
4201 leftLength = partials.length,
4202 rangeLength = nativeMax(argsLength - holdersLength, 0),
4203 result = Array(leftLength + rangeLength),
4204 isUncurried = !isCurried;
4206 while (++leftIndex < leftLength) {
4207 result[leftIndex] = partials[leftIndex];
4209 while (++argsIndex < holdersLength) {
4210 if (isUncurried || argsIndex < argsLength) {
4211 result[holders[argsIndex]] = args[argsIndex];
4214 while (rangeLength--) {
4215 result[leftIndex++] = args[argsIndex++];
4221 * This function is like `composeArgs` except that the arguments composition
4222 * is tailored for `_.partialRight`.
4225 * @param {Array} args The provided arguments.
4226 * @param {Array} partials The arguments to append to those provided.
4227 * @param {Array} holders The `partials` placeholder indexes.
4228 * @params {boolean} [isCurried] Specify composing for a curried function.
4229 * @returns {Array} Returns the new array of composed arguments.
4231 function composeArgsRight(args, partials, holders, isCurried) {
4233 argsLength = args.length,
4235 holdersLength = holders.length,
4237 rightLength = partials.length,
4238 rangeLength = nativeMax(argsLength - holdersLength, 0),
4239 result = Array(rangeLength + rightLength),
4240 isUncurried = !isCurried;
4242 while (++argsIndex < rangeLength) {
4243 result[argsIndex] = args[argsIndex];
4245 var offset = argsIndex;
4246 while (++rightIndex < rightLength) {
4247 result[offset + rightIndex] = partials[rightIndex];
4249 while (++holdersIndex < holdersLength) {
4250 if (isUncurried || argsIndex < argsLength) {
4251 result[offset + holders[holdersIndex]] = args[argsIndex++];
4258 * Copies the values of `source` to `array`.
4261 * @param {Array} source The array to copy values from.
4262 * @param {Array} [array=[]] The array to copy values to.
4263 * @returns {Array} Returns `array`.
4265 function copyArray(source, array) {
4267 length = source.length;
4269 array || (array = Array(length));
4270 while (++index < length) {
4271 array[index] = source[index];
4277 * Copies properties of `source` to `object`.
4280 * @param {Object} source The object to copy properties from.
4281 * @param {Array} props The property identifiers to copy.
4282 * @param {Object} [object={}] The object to copy properties to.
4283 * @param {Function} [customizer] The function to customize copied values.
4284 * @returns {Object} Returns `object`.
4286 function copyObject(source, props, object, customizer) {
4287 object || (object = {});
4290 length = props.length;
4292 while (++index < length) {
4293 var key = props[index];
4295 var newValue = customizer
4296 ? customizer(object[key], source[key], key, object, source)
4299 assignValue(object, key, newValue);
4305 * Copies own symbol properties of `source` to `object`.
4308 * @param {Object} source The object to copy symbols from.
4309 * @param {Object} [object={}] The object to copy symbols to.
4310 * @returns {Object} Returns `object`.
4312 function copySymbols(source, object) {
4313 return copyObject(source, getSymbols(source), object);
4317 * Creates a function like `_.groupBy`.
4320 * @param {Function} setter The function to set accumulator values.
4321 * @param {Function} [initializer] The accumulator object initializer.
4322 * @returns {Function} Returns the new aggregator function.
4324 function createAggregator(setter, initializer) {
4325 return function(collection, iteratee) {
4326 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4327 accumulator = initializer ? initializer() : {};
4329 return func(collection, setter, getIteratee(iteratee), accumulator);
4334 * Creates a function like `_.assign`.
4337 * @param {Function} assigner The function to assign values.
4338 * @returns {Function} Returns the new assigner function.
4340 function createAssigner(assigner) {
4341 return rest(function(object, sources) {
4343 length = sources.length,
4344 customizer = length > 1 ? sources[length - 1] : undefined,
4345 guard = length > 2 ? sources[2] : undefined;
4347 customizer = (assigner.length > 3 && typeof customizer == 'function')
4348 ? (length--, customizer)
4351 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
4352 customizer = length < 3 ? undefined : customizer;
4355 object = Object(object);
4356 while (++index < length) {
4357 var source = sources[index];
4359 assigner(object, source, index, customizer);
4367 * Creates a `baseEach` or `baseEachRight` function.
4370 * @param {Function} eachFunc The function to iterate over a collection.
4371 * @param {boolean} [fromRight] Specify iterating from right to left.
4372 * @returns {Function} Returns the new base function.
4374 function createBaseEach(eachFunc, fromRight) {
4375 return function(collection, iteratee) {
4376 if (collection == null) {
4379 if (!isArrayLike(collection)) {
4380 return eachFunc(collection, iteratee);
4382 var length = collection.length,
4383 index = fromRight ? length : -1,
4384 iterable = Object(collection);
4386 while ((fromRight ? index-- : ++index < length)) {
4387 if (iteratee(iterable[index], index, iterable) === false) {
4396 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
4399 * @param {boolean} [fromRight] Specify iterating from right to left.
4400 * @returns {Function} Returns the new base function.
4402 function createBaseFor(fromRight) {
4403 return function(object, iteratee, keysFunc) {
4405 iterable = Object(object),
4406 props = keysFunc(object),
4407 length = props.length;
4410 var key = props[fromRight ? length : ++index];
4411 if (iteratee(iterable[key], key, iterable) === false) {
4420 * Creates a function that wraps `func` to invoke it with the optional `this`
4421 * binding of `thisArg`.
4424 * @param {Function} func The function to wrap.
4425 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4427 * @param {*} [thisArg] The `this` binding of `func`.
4428 * @returns {Function} Returns the new wrapped function.
4430 function createBaseWrapper(func, bitmask, thisArg) {
4431 var isBind = bitmask & BIND_FLAG,
4432 Ctor = createCtorWrapper(func);
4434 function wrapper() {
4435 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4436 return fn.apply(isBind ? thisArg : this, arguments);
4442 * Creates a function like `_.lowerFirst`.
4445 * @param {string} methodName The name of the `String` case method to use.
4446 * @returns {Function} Returns the new case function.
4448 function createCaseFirst(methodName) {
4449 return function(string) {
4450 string = toString(string);
4452 var strSymbols = reHasComplexSymbol.test(string)
4453 ? stringToArray(string)
4456 var chr = strSymbols
4460 var trailing = strSymbols
4461 ? castSlice(strSymbols, 1).join('')
4464 return chr[methodName]() + trailing;
4469 * Creates a function like `_.camelCase`.
4472 * @param {Function} callback The function to combine each word.
4473 * @returns {Function} Returns the new compounder function.
4475 function createCompounder(callback) {
4476 return function(string) {
4477 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
4482 * Creates a function that produces an instance of `Ctor` regardless of
4483 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
4486 * @param {Function} Ctor The constructor to wrap.
4487 * @returns {Function} Returns the new wrapped function.
4489 function createCtorWrapper(Ctor) {
4491 // Use a `switch` statement to work with class constructors. See
4492 // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
4493 // for more details.
4494 var args = arguments;
4495 switch (args.length) {
4496 case 0: return new Ctor;
4497 case 1: return new Ctor(args[0]);
4498 case 2: return new Ctor(args[0], args[1]);
4499 case 3: return new Ctor(args[0], args[1], args[2]);
4500 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
4501 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
4502 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
4503 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
4505 var thisBinding = baseCreate(Ctor.prototype),
4506 result = Ctor.apply(thisBinding, args);
4508 // Mimic the constructor's `return` behavior.
4509 // See https://es5.github.io/#x13.2.2 for more details.
4510 return isObject(result) ? result : thisBinding;
4515 * Creates a function that wraps `func` to enable currying.
4518 * @param {Function} func The function to wrap.
4519 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4521 * @param {number} arity The arity of `func`.
4522 * @returns {Function} Returns the new wrapped function.
4524 function createCurryWrapper(func, bitmask, arity) {
4525 var Ctor = createCtorWrapper(func);
4527 function wrapper() {
4528 var length = arguments.length,
4529 args = Array(length),
4531 placeholder = getHolder(wrapper);
4534 args[index] = arguments[index];
4536 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
4538 : replaceHolders(args, placeholder);
4540 length -= holders.length;
4541 if (length < arity) {
4542 return createRecurryWrapper(
4543 func, bitmask, createHybridWrapper, wrapper.placeholder, undefined,
4544 args, holders, undefined, undefined, arity - length);
4546 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4547 return apply(fn, this, args);
4553 * Creates a `_.find` or `_.findLast` function.
4556 * @param {Function} findIndexFunc The function to find the collection index.
4557 * @returns {Function} Returns the new find function.
4559 function createFind(findIndexFunc) {
4560 return function(collection, predicate, fromIndex) {
4561 var iterable = Object(collection);
4562 predicate = getIteratee(predicate, 3);
4563 if (!isArrayLike(collection)) {
4564 var props = keys(collection);
4566 var index = findIndexFunc(props || collection, function(value, key) {
4569 value = iterable[key];
4571 return predicate(value, key, iterable);
4573 return index > -1 ? collection[props ? props[index] : index] : undefined;
4578 * Creates a `_.flow` or `_.flowRight` function.
4581 * @param {boolean} [fromRight] Specify iterating from right to left.
4582 * @returns {Function} Returns the new flow function.
4584 function createFlow(fromRight) {
4585 return rest(function(funcs) {
4586 funcs = baseFlatten(funcs, 1);
4588 var length = funcs.length,
4590 prereq = LodashWrapper.prototype.thru;
4596 var func = funcs[index];
4597 if (typeof func != 'function') {
4598 throw new TypeError(FUNC_ERROR_TEXT);
4600 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
4601 var wrapper = new LodashWrapper([], true);
4604 index = wrapper ? index : length;
4605 while (++index < length) {
4606 func = funcs[index];
4608 var funcName = getFuncName(func),
4609 data = funcName == 'wrapper' ? getData(func) : undefined;
4611 if (data && isLaziable(data[0]) &&
4612 data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
4613 !data[4].length && data[9] == 1
4615 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
4617 wrapper = (func.length == 1 && isLaziable(func))
4618 ? wrapper[funcName]()
4619 : wrapper.thru(func);
4623 var args = arguments,
4626 if (wrapper && args.length == 1 &&
4627 isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
4628 return wrapper.plant(value).value();
4631 result = length ? funcs[index].apply(this, args) : value;
4633 while (++index < length) {
4634 result = funcs[index].call(this, result);
4642 * Creates a function that wraps `func` to invoke it with optional `this`
4643 * binding of `thisArg`, partial application, and currying.
4646 * @param {Function|string} func The function or method name to wrap.
4647 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4649 * @param {*} [thisArg] The `this` binding of `func`.
4650 * @param {Array} [partials] The arguments to prepend to those provided to
4652 * @param {Array} [holders] The `partials` placeholder indexes.
4653 * @param {Array} [partialsRight] The arguments to append to those provided
4654 * to the new function.
4655 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
4656 * @param {Array} [argPos] The argument positions of the new function.
4657 * @param {number} [ary] The arity cap of `func`.
4658 * @param {number} [arity] The arity of `func`.
4659 * @returns {Function} Returns the new wrapped function.
4661 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
4662 var isAry = bitmask & ARY_FLAG,
4663 isBind = bitmask & BIND_FLAG,
4664 isBindKey = bitmask & BIND_KEY_FLAG,
4665 isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
4666 isFlip = bitmask & FLIP_FLAG,
4667 Ctor = isBindKey ? undefined : createCtorWrapper(func);
4669 function wrapper() {
4670 var length = arguments.length,
4671 args = Array(length),
4675 args[index] = arguments[index];
4678 var placeholder = getHolder(wrapper),
4679 holdersCount = countHolders(args, placeholder);
4682 args = composeArgs(args, partials, holders, isCurried);
4684 if (partialsRight) {
4685 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
4687 length -= holdersCount;
4688 if (isCurried && length < arity) {
4689 var newHolders = replaceHolders(args, placeholder);
4690 return createRecurryWrapper(
4691 func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg,
4692 args, newHolders, argPos, ary, arity - length
4695 var thisBinding = isBind ? thisArg : this,
4696 fn = isBindKey ? thisBinding[func] : func;
4698 length = args.length;
4700 args = reorder(args, argPos);
4701 } else if (isFlip && length > 1) {
4704 if (isAry && ary < length) {
4707 if (this && this !== root && this instanceof wrapper) {
4708 fn = Ctor || createCtorWrapper(fn);
4710 return fn.apply(thisBinding, args);
4716 * Creates a function like `_.invertBy`.
4719 * @param {Function} setter The function to set accumulator values.
4720 * @param {Function} toIteratee The function to resolve iteratees.
4721 * @returns {Function} Returns the new inverter function.
4723 function createInverter(setter, toIteratee) {
4724 return function(object, iteratee) {
4725 return baseInverter(object, setter, toIteratee(iteratee), {});
4730 * Creates a function that performs a mathematical operation on two values.
4733 * @param {Function} operator The function to perform the operation.
4734 * @returns {Function} Returns the new mathematical operation function.
4736 function createMathOperation(operator) {
4737 return function(value, other) {
4739 if (value === undefined && other === undefined) {
4742 if (value !== undefined) {
4745 if (other !== undefined) {
4746 if (result === undefined) {
4749 if (typeof value == 'string' || typeof other == 'string') {
4750 value = baseToString(value);
4751 other = baseToString(other);
4753 value = baseToNumber(value);
4754 other = baseToNumber(other);
4756 result = operator(value, other);
4763 * Creates a function like `_.over`.
4766 * @param {Function} arrayFunc The function to iterate over iteratees.
4767 * @returns {Function} Returns the new over function.
4769 function createOver(arrayFunc) {
4770 return rest(function(iteratees) {
4771 iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
4772 ? arrayMap(iteratees[0], baseUnary(getIteratee()))
4773 : arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseUnary(getIteratee()));
4775 return rest(function(args) {
4777 return arrayFunc(iteratees, function(iteratee) {
4778 return apply(iteratee, thisArg, args);
4785 * Creates the padding for `string` based on `length`. The `chars` string
4786 * is truncated if the number of characters exceeds `length`.
4789 * @param {number} length The padding length.
4790 * @param {string} [chars=' '] The string used as padding.
4791 * @returns {string} Returns the padding for `string`.
4793 function createPadding(length, chars) {
4794 chars = chars === undefined ? ' ' : baseToString(chars);
4796 var charsLength = chars.length;
4797 if (charsLength < 2) {
4798 return charsLength ? baseRepeat(chars, length) : chars;
4800 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
4801 return reHasComplexSymbol.test(chars)
4802 ? castSlice(stringToArray(result), 0, length).join('')
4803 : result.slice(0, length);
4807 * Creates a function that wraps `func` to invoke it with the `this` binding
4808 * of `thisArg` and `partials` prepended to the arguments it receives.
4811 * @param {Function} func The function to wrap.
4812 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4814 * @param {*} thisArg The `this` binding of `func`.
4815 * @param {Array} partials The arguments to prepend to those provided to
4817 * @returns {Function} Returns the new wrapped function.
4819 function createPartialWrapper(func, bitmask, thisArg, partials) {
4820 var isBind = bitmask & BIND_FLAG,
4821 Ctor = createCtorWrapper(func);
4823 function wrapper() {
4825 argsLength = arguments.length,
4827 leftLength = partials.length,
4828 args = Array(leftLength + argsLength),
4829 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4831 while (++leftIndex < leftLength) {
4832 args[leftIndex] = partials[leftIndex];
4834 while (argsLength--) {
4835 args[leftIndex++] = arguments[++argsIndex];
4837 return apply(fn, isBind ? thisArg : this, args);
4843 * Creates a `_.range` or `_.rangeRight` function.
4846 * @param {boolean} [fromRight] Specify iterating from right to left.
4847 * @returns {Function} Returns the new range function.
4849 function createRange(fromRight) {
4850 return function(start, end, step) {
4851 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
4852 end = step = undefined;
4854 // Ensure the sign of `-0` is preserved.
4855 start = toNumber(start);
4856 start = start === start ? start : 0;
4857 if (end === undefined) {
4861 end = toNumber(end) || 0;
4863 step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
4864 return baseRange(start, end, step, fromRight);
4869 * Creates a function that performs a relational operation on two values.
4872 * @param {Function} operator The function to perform the operation.
4873 * @returns {Function} Returns the new relational operation function.
4875 function createRelationalOperation(operator) {
4876 return function(value, other) {
4877 if (!(typeof value == 'string' && typeof other == 'string')) {
4878 value = toNumber(value);
4879 other = toNumber(other);
4881 return operator(value, other);
4886 * Creates a function that wraps `func` to continue currying.
4889 * @param {Function} func The function to wrap.
4890 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4892 * @param {Function} wrapFunc The function to create the `func` wrapper.
4893 * @param {*} placeholder The placeholder value.
4894 * @param {*} [thisArg] The `this` binding of `func`.
4895 * @param {Array} [partials] The arguments to prepend to those provided to
4897 * @param {Array} [holders] The `partials` placeholder indexes.
4898 * @param {Array} [argPos] The argument positions of the new function.
4899 * @param {number} [ary] The arity cap of `func`.
4900 * @param {number} [arity] The arity of `func`.
4901 * @returns {Function} Returns the new wrapped function.
4903 function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
4904 var isCurry = bitmask & CURRY_FLAG,
4905 newHolders = isCurry ? holders : undefined,
4906 newHoldersRight = isCurry ? undefined : holders,
4907 newPartials = isCurry ? partials : undefined,
4908 newPartialsRight = isCurry ? undefined : partials;
4910 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
4911 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
4913 if (!(bitmask & CURRY_BOUND_FLAG)) {
4914 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
4917 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
4918 newHoldersRight, argPos, ary, arity
4921 var result = wrapFunc.apply(undefined, newData);
4922 if (isLaziable(func)) {
4923 setData(result, newData);
4925 result.placeholder = placeholder;
4930 * Creates a function like `_.round`.
4933 * @param {string} methodName The name of the `Math` method to use when rounding.
4934 * @returns {Function} Returns the new round function.
4936 function createRound(methodName) {
4937 var func = Math[methodName];
4938 return function(number, precision) {
4939 number = toNumber(number);
4940 precision = nativeMin(toInteger(precision), 292);
4942 // Shift with exponential notation to avoid floating-point issues.
4943 // See [MDN](https://mdn.io/round#Examples) for more details.
4944 var pair = (toString(number) + 'e').split('e'),
4945 value = func(pair[0] + 'e' + (+pair[1] + precision));
4947 pair = (toString(value) + 'e').split('e');
4948 return +(pair[0] + 'e' + (+pair[1] - precision));
4950 return func(number);
4955 * Creates a set of `values`.
4958 * @param {Array} values The values to add to the set.
4959 * @returns {Object} Returns the new set.
4961 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
4962 return new Set(values);
4966 * Creates a `_.toPairs` or `_.toPairsIn` function.
4969 * @param {Function} keysFunc The function to get the keys of a given object.
4970 * @returns {Function} Returns the new pairs function.
4972 function createToPairs(keysFunc) {
4973 return function(object) {
4974 var tag = getTag(object);
4975 if (tag == mapTag) {
4976 return mapToArray(object);
4978 if (tag == setTag) {
4979 return setToPairs(object);
4981 return baseToPairs(object, keysFunc(object));
4986 * Creates a function that either curries or invokes `func` with optional
4987 * `this` binding and partially applied arguments.
4990 * @param {Function|string} func The function or method name to wrap.
4991 * @param {number} bitmask The bitmask of wrapper flags.
4992 * The bitmask may be composed of the following flags:
4995 * 4 - `_.curry` or `_.curryRight` of a bound function
4997 * 16 - `_.curryRight`
4999 * 64 - `_.partialRight`
5003 * @param {*} [thisArg] The `this` binding of `func`.
5004 * @param {Array} [partials] The arguments to be partially applied.
5005 * @param {Array} [holders] The `partials` placeholder indexes.
5006 * @param {Array} [argPos] The argument positions of the new function.
5007 * @param {number} [ary] The arity cap of `func`.
5008 * @param {number} [arity] The arity of `func`.
5009 * @returns {Function} Returns the new wrapped function.
5011 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
5012 var isBindKey = bitmask & BIND_KEY_FLAG;
5013 if (!isBindKey && typeof func != 'function') {
5014 throw new TypeError(FUNC_ERROR_TEXT);
5016 var length = partials ? partials.length : 0;
5018 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
5019 partials = holders = undefined;
5021 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
5022 arity = arity === undefined ? arity : toInteger(arity);
5023 length -= holders ? holders.length : 0;
5025 if (bitmask & PARTIAL_RIGHT_FLAG) {
5026 var partialsRight = partials,
5027 holdersRight = holders;
5029 partials = holders = undefined;
5031 var data = isBindKey ? undefined : getData(func);
5034 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
5039 mergeData(newData, data);
5042 bitmask = newData[1];
5043 thisArg = newData[2];
5044 partials = newData[3];
5045 holders = newData[4];
5046 arity = newData[9] = newData[9] == null
5047 ? (isBindKey ? 0 : func.length)
5048 : nativeMax(newData[9] - length, 0);
5050 if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
5051 bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
5053 if (!bitmask || bitmask == BIND_FLAG) {
5054 var result = createBaseWrapper(func, bitmask, thisArg);
5055 } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
5056 result = createCurryWrapper(func, bitmask, arity);
5057 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
5058 result = createPartialWrapper(func, bitmask, thisArg, partials);
5060 result = createHybridWrapper.apply(undefined, newData);
5062 var setter = data ? baseSetData : setData;
5063 return setter(result, newData);
5067 * A specialized version of `baseIsEqualDeep` for arrays with support for
5068 * partial deep comparisons.
5071 * @param {Array} array The array to compare.
5072 * @param {Array} other The other array to compare.
5073 * @param {Function} equalFunc The function to determine equivalents of values.
5074 * @param {Function} customizer The function to customize comparisons.
5075 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
5077 * @param {Object} stack Tracks traversed `array` and `other` objects.
5078 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
5080 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
5081 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
5082 arrLength = array.length,
5083 othLength = other.length;
5085 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
5088 // Assume cyclic values are equal.
5089 var stacked = stack.get(array);
5091 return stacked == other;
5095 seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
5097 stack.set(array, other);
5099 // Ignore non-index properties.
5100 while (++index < arrLength) {
5101 var arrValue = array[index],
5102 othValue = other[index];
5105 var compared = isPartial
5106 ? customizer(othValue, arrValue, index, other, array, stack)
5107 : customizer(arrValue, othValue, index, array, other, stack);
5109 if (compared !== undefined) {
5116 // Recursively compare arrays (susceptible to call stack limits).
5118 if (!arraySome(other, function(othValue, othIndex) {
5119 if (!seen.has(othIndex) &&
5120 (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
5121 return seen.add(othIndex);
5128 arrValue === othValue ||
5129 equalFunc(arrValue, othValue, customizer, bitmask, stack)
5135 stack['delete'](array);
5140 * A specialized version of `baseIsEqualDeep` for comparing objects of
5141 * the same `toStringTag`.
5143 * **Note:** This function only supports comparing values with tags of
5144 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5147 * @param {Object} object The object to compare.
5148 * @param {Object} other The other object to compare.
5149 * @param {string} tag The `toStringTag` of the objects to compare.
5150 * @param {Function} equalFunc The function to determine equivalents of values.
5151 * @param {Function} customizer The function to customize comparisons.
5152 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
5154 * @param {Object} stack Tracks traversed `object` and `other` objects.
5155 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5157 function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
5160 if ((object.byteLength != other.byteLength) ||
5161 (object.byteOffset != other.byteOffset)) {
5164 object = object.buffer;
5165 other = other.buffer;
5167 case arrayBufferTag:
5168 if ((object.byteLength != other.byteLength) ||
5169 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
5176 // Coerce dates and booleans to numbers, dates to milliseconds and
5177 // booleans to `1` or `0` treating invalid dates coerced to `NaN` as
5179 return +object == +other;
5182 return object.name == other.name && object.message == other.message;
5185 // Treat `NaN` vs. `NaN` as equal.
5186 return (object != +object) ? other != +other : object == +other;
5190 // Coerce regexes to strings and treat strings, primitives and objects,
5191 // as equal. See http://www.ecma-international.org/ecma-262/6.0/#sec-regexp.prototype.tostring
5192 // for more details.
5193 return object == (other + '');
5196 var convert = mapToArray;
5199 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
5200 convert || (convert = setToArray);
5202 if (object.size != other.size && !isPartial) {
5205 // Assume cyclic values are equal.
5206 var stacked = stack.get(object);
5208 return stacked == other;
5210 bitmask |= UNORDERED_COMPARE_FLAG;
5211 stack.set(object, other);
5213 // Recursively compare objects (susceptible to call stack limits).
5214 return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
5217 if (symbolValueOf) {
5218 return symbolValueOf.call(object) == symbolValueOf.call(other);
5225 * A specialized version of `baseIsEqualDeep` for objects with support for
5226 * partial deep comparisons.
5229 * @param {Object} object The object to compare.
5230 * @param {Object} other The other object to compare.
5231 * @param {Function} equalFunc The function to determine equivalents of values.
5232 * @param {Function} customizer The function to customize comparisons.
5233 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
5235 * @param {Object} stack Tracks traversed `object` and `other` objects.
5236 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5238 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
5239 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
5240 objProps = keys(object),
5241 objLength = objProps.length,
5242 othProps = keys(other),
5243 othLength = othProps.length;
5245 if (objLength != othLength && !isPartial) {
5248 var index = objLength;
5250 var key = objProps[index];
5251 if (!(isPartial ? key in other : baseHas(other, key))) {
5255 // Assume cyclic values are equal.
5256 var stacked = stack.get(object);
5258 return stacked == other;
5261 stack.set(object, other);
5263 var skipCtor = isPartial;
5264 while (++index < objLength) {
5265 key = objProps[index];
5266 var objValue = object[key],
5267 othValue = other[key];
5270 var compared = isPartial
5271 ? customizer(othValue, objValue, key, other, object, stack)
5272 : customizer(objValue, othValue, key, object, other, stack);
5274 // Recursively compare objects (susceptible to call stack limits).
5275 if (!(compared === undefined
5276 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
5282 skipCtor || (skipCtor = key == 'constructor');
5284 if (result && !skipCtor) {
5285 var objCtor = object.constructor,
5286 othCtor = other.constructor;
5288 // Non `Object` object instances with different constructors are not equal.
5289 if (objCtor != othCtor &&
5290 ('constructor' in object && 'constructor' in other) &&
5291 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
5292 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
5296 stack['delete'](object);
5301 * Creates an array of own enumerable property names and symbols of `object`.
5304 * @param {Object} object The object to query.
5305 * @returns {Array} Returns the array of property names and symbols.
5307 function getAllKeys(object) {
5308 return baseGetAllKeys(object, keys, getSymbols);
5312 * Creates an array of own and inherited enumerable property names and
5313 * symbols of `object`.
5316 * @param {Object} object The object to query.
5317 * @returns {Array} Returns the array of property names and symbols.
5319 function getAllKeysIn(object) {
5320 return baseGetAllKeys(object, keysIn, getSymbolsIn);
5324 * Gets metadata for `func`.
5327 * @param {Function} func The function to query.
5328 * @returns {*} Returns the metadata for `func`.
5330 var getData = !metaMap ? noop : function(func) {
5331 return metaMap.get(func);
5335 * Gets the name of `func`.
5338 * @param {Function} func The function to query.
5339 * @returns {string} Returns the function name.
5341 function getFuncName(func) {
5342 var result = (func.name + ''),
5343 array = realNames[result],
5344 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
5347 var data = array[length],
5348 otherFunc = data.func;
5349 if (otherFunc == null || otherFunc == func) {
5357 * Gets the argument placeholder value for `func`.
5360 * @param {Function} func The function to inspect.
5361 * @returns {*} Returns the placeholder value.
5363 function getHolder(func) {
5364 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
5365 return object.placeholder;
5369 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
5370 * this function returns the custom method, otherwise it returns `baseIteratee`.
5371 * If arguments are provided, the chosen function is invoked with them and
5372 * its result is returned.
5375 * @param {*} [value] The value to convert to an iteratee.
5376 * @param {number} [arity] The arity of the created iteratee.
5377 * @returns {Function} Returns the chosen function or its result.
5379 function getIteratee() {
5380 var result = lodash.iteratee || iteratee;
5381 result = result === iteratee ? baseIteratee : result;
5382 return arguments.length ? result(arguments[0], arguments[1]) : result;
5386 * Gets the "length" property value of `object`.
5388 * **Note:** This function is used to avoid a
5389 * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
5390 * Safari on at least iOS 8.1-8.3 ARM64.
5393 * @param {Object} object The object to query.
5394 * @returns {*} Returns the "length" value.
5396 var getLength = baseProperty('length');
5399 * Gets the data for `map`.
5402 * @param {Object} map The map to query.
5403 * @param {string} key The reference key.
5404 * @returns {*} Returns the map data.
5406 function getMapData(map, key) {
5407 var data = map.__data__;
5408 return isKeyable(key)
5409 ? data[typeof key == 'string' ? 'string' : 'hash']
5414 * Gets the property names, values, and compare flags of `object`.
5417 * @param {Object} object The object to query.
5418 * @returns {Array} Returns the match data of `object`.
5420 function getMatchData(object) {
5421 var result = keys(object),
5422 length = result.length;
5425 var key = result[length],
5426 value = object[key];
5428 result[length] = [key, value, isStrictComparable(value)];
5434 * Gets the native function at `key` of `object`.
5437 * @param {Object} object The object to query.
5438 * @param {string} key The key of the method to get.
5439 * @returns {*} Returns the function if it's native, else `undefined`.
5441 function getNative(object, key) {
5442 var value = getValue(object, key);
5443 return baseIsNative(value) ? value : undefined;
5447 * Gets the `[[Prototype]]` of `value`.
5450 * @param {*} value The value to query.
5451 * @returns {null|Object} Returns the `[[Prototype]]`.
5453 function getPrototype(value) {
5454 return nativeGetPrototype(Object(value));
5458 * Creates an array of the own enumerable symbol properties of `object`.
5461 * @param {Object} object The object to query.
5462 * @returns {Array} Returns the array of symbols.
5464 function getSymbols(object) {
5465 // Coerce `object` to an object to avoid non-object errors in V8.
5466 // See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details.
5467 return getOwnPropertySymbols(Object(object));
5470 // Fallback for IE < 11.
5471 if (!getOwnPropertySymbols) {
5472 getSymbols = stubArray;
5476 * Creates an array of the own and inherited enumerable symbol properties
5480 * @param {Object} object The object to query.
5481 * @returns {Array} Returns the array of symbols.
5483 var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) {
5486 arrayPush(result, getSymbols(object));
5487 object = getPrototype(object);
5493 * Gets the `toStringTag` of `value`.
5496 * @param {*} value The value to query.
5497 * @returns {string} Returns the `toStringTag`.
5499 function getTag(value) {
5500 return objectToString.call(value);
5503 // Fallback for data views, maps, sets, and weak maps in IE 11,
5504 // for data views in Edge, and promises in Node.js.
5505 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
5506 (Map && getTag(new Map) != mapTag) ||
5507 (Promise && getTag(Promise.resolve()) != promiseTag) ||
5508 (Set && getTag(new Set) != setTag) ||
5509 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
5510 getTag = function(value) {
5511 var result = objectToString.call(value),
5512 Ctor = result == objectTag ? value.constructor : undefined,
5513 ctorString = Ctor ? toSource(Ctor) : undefined;
5516 switch (ctorString) {
5517 case dataViewCtorString: return dataViewTag;
5518 case mapCtorString: return mapTag;
5519 case promiseCtorString: return promiseTag;
5520 case setCtorString: return setTag;
5521 case weakMapCtorString: return weakMapTag;
5529 * Gets the view, applying any `transforms` to the `start` and `end` positions.
5532 * @param {number} start The start of the view.
5533 * @param {number} end The end of the view.
5534 * @param {Array} transforms The transformations to apply to the view.
5535 * @returns {Object} Returns an object containing the `start` and `end`
5536 * positions of the view.
5538 function getView(start, end, transforms) {
5540 length = transforms.length;
5542 while (++index < length) {
5543 var data = transforms[index],
5546 switch (data.type) {
5547 case 'drop': start += size; break;
5548 case 'dropRight': end -= size; break;
5549 case 'take': end = nativeMin(end, start + size); break;
5550 case 'takeRight': start = nativeMax(start, end - size); break;
5553 return { 'start': start, 'end': end };
5557 * Checks if `path` exists on `object`.
5560 * @param {Object} object The object to query.
5561 * @param {Array|string} path The path to check.
5562 * @param {Function} hasFunc The function to check properties.
5563 * @returns {boolean} Returns `true` if `path` exists, else `false`.
5565 function hasPath(object, path, hasFunc) {
5566 path = isKey(path, object) ? [path] : castPath(path);
5570 length = path.length;
5572 while (++index < length) {
5573 var key = toKey(path[index]);
5574 if (!(result = object != null && hasFunc(object, key))) {
5577 object = object[key];
5582 var length = object ? object.length : 0;
5583 return !!length && isLength(length) && isIndex(key, length) &&
5584 (isArray(object) || isString(object) || isArguments(object));
5588 * Initializes an array clone.
5591 * @param {Array} array The array to clone.
5592 * @returns {Array} Returns the initialized clone.
5594 function initCloneArray(array) {
5595 var length = array.length,
5596 result = array.constructor(length);
5598 // Add properties assigned by `RegExp#exec`.
5599 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
5600 result.index = array.index;
5601 result.input = array.input;
5607 * Initializes an object clone.
5610 * @param {Object} object The object to clone.
5611 * @returns {Object} Returns the initialized clone.
5613 function initCloneObject(object) {
5614 return (typeof object.constructor == 'function' && !isPrototype(object))
5615 ? baseCreate(getPrototype(object))
5620 * Initializes an object clone based on its `toStringTag`.
5622 * **Note:** This function only supports cloning values with tags of
5623 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5626 * @param {Object} object The object to clone.
5627 * @param {string} tag The `toStringTag` of the object to clone.
5628 * @param {Function} cloneFunc The function to clone values.
5629 * @param {boolean} [isDeep] Specify a deep clone.
5630 * @returns {Object} Returns the initialized clone.
5632 function initCloneByTag(object, tag, cloneFunc, isDeep) {
5633 var Ctor = object.constructor;
5635 case arrayBufferTag:
5636 return cloneArrayBuffer(object);
5640 return new Ctor(+object);
5643 return cloneDataView(object, isDeep);
5645 case float32Tag: case float64Tag:
5646 case int8Tag: case int16Tag: case int32Tag:
5647 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
5648 return cloneTypedArray(object, isDeep);
5651 return cloneMap(object, isDeep, cloneFunc);
5655 return new Ctor(object);
5658 return cloneRegExp(object);
5661 return cloneSet(object, isDeep, cloneFunc);
5664 return cloneSymbol(object);
5669 * Creates an array of index keys for `object` values of arrays,
5670 * `arguments` objects, and strings, otherwise `null` is returned.
5673 * @param {Object} object The object to query.
5674 * @returns {Array|null} Returns index keys, else `null`.
5676 function indexKeys(object) {
5677 var length = object ? object.length : undefined;
5678 if (isLength(length) &&
5679 (isArray(object) || isString(object) || isArguments(object))) {
5680 return baseTimes(length, String);
5686 * Checks if `value` is a flattenable `arguments` object or array.
5689 * @param {*} value The value to check.
5690 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
5692 function isFlattenable(value) {
5693 return isArray(value) || isArguments(value);
5697 * Checks if `value` is a flattenable array and not a `_.matchesProperty`
5698 * iteratee shorthand.
5701 * @param {*} value The value to check.
5702 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
5704 function isFlattenableIteratee(value) {
5705 return isArray(value) && !(value.length == 2 && !isFunction(value[0]));
5709 * Checks if `value` is a valid array-like index.
5712 * @param {*} value The value to check.
5713 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
5714 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
5716 function isIndex(value, length) {
5717 length = length == null ? MAX_SAFE_INTEGER : length;
5719 (typeof value == 'number' || reIsUint.test(value)) &&
5720 (value > -1 && value % 1 == 0 && value < length);
5724 * Checks if the given arguments are from an iteratee call.
5727 * @param {*} value The potential iteratee value argument.
5728 * @param {*} index The potential iteratee index or key argument.
5729 * @param {*} object The potential iteratee object argument.
5730 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
5733 function isIterateeCall(value, index, object) {
5734 if (!isObject(object)) {
5737 var type = typeof index;
5738 if (type == 'number'
5739 ? (isArrayLike(object) && isIndex(index, object.length))
5740 : (type == 'string' && index in object)
5742 return eq(object[index], value);
5748 * Checks if `value` is a property name and not a property path.
5751 * @param {*} value The value to check.
5752 * @param {Object} [object] The object to query keys on.
5753 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
5755 function isKey(value, object) {
5756 if (isArray(value)) {
5759 var type = typeof value;
5760 if (type == 'number' || type == 'symbol' || type == 'boolean' ||
5761 value == null || isSymbol(value)) {
5764 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
5765 (object != null && value in Object(object));
5769 * Checks if `value` is suitable for use as unique object key.
5772 * @param {*} value The value to check.
5773 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
5775 function isKeyable(value) {
5776 var type = typeof value;
5777 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
5778 ? (value !== '__proto__')
5783 * Checks if `func` has a lazy counterpart.
5786 * @param {Function} func The function to check.
5787 * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
5790 function isLaziable(func) {
5791 var funcName = getFuncName(func),
5792 other = lodash[funcName];
5794 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
5797 if (func === other) {
5800 var data = getData(other);
5801 return !!data && func === data[0];
5805 * Checks if `func` has its source masked.
5808 * @param {Function} func The function to check.
5809 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
5811 function isMasked(func) {
5812 return !!maskSrcKey && (maskSrcKey in func);
5816 * Checks if `func` is capable of being masked.
5819 * @param {*} value The value to check.
5820 * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
5822 var isMaskable = coreJsData ? isFunction : stubFalse;
5825 * Checks if `value` is likely a prototype object.
5828 * @param {*} value The value to check.
5829 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
5831 function isPrototype(value) {
5832 var Ctor = value && value.constructor,
5833 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
5835 return value === proto;
5839 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
5842 * @param {*} value The value to check.
5843 * @returns {boolean} Returns `true` if `value` if suitable for strict
5844 * equality comparisons, else `false`.
5846 function isStrictComparable(value) {
5847 return value === value && !isObject(value);
5851 * A specialized version of `matchesProperty` for source values suitable
5852 * for strict equality comparisons, i.e. `===`.
5855 * @param {string} key The key of the property to get.
5856 * @param {*} srcValue The value to match.
5857 * @returns {Function} Returns the new spec function.
5859 function matchesStrictComparable(key, srcValue) {
5860 return function(object) {
5861 if (object == null) {
5864 return object[key] === srcValue &&
5865 (srcValue !== undefined || (key in Object(object)));
5870 * Merges the function metadata of `source` into `data`.
5872 * Merging metadata reduces the number of wrappers used to invoke a function.
5873 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
5874 * may be applied regardless of execution order. Methods like `_.ary` and
5875 * `_.rearg` modify function arguments, making the order in which they are
5876 * executed important, preventing the merging of metadata. However, we make
5877 * an exception for a safe combined case where curried functions have `_.ary`
5878 * and or `_.rearg` applied.
5881 * @param {Array} data The destination metadata.
5882 * @param {Array} source The source metadata.
5883 * @returns {Array} Returns `data`.
5885 function mergeData(data, source) {
5886 var bitmask = data[1],
5887 srcBitmask = source[1],
5888 newBitmask = bitmask | srcBitmask,
5889 isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
5892 ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
5893 ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
5894 ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
5896 // Exit early if metadata can't be merged.
5897 if (!(isCommon || isCombo)) {
5900 // Use source `thisArg` if available.
5901 if (srcBitmask & BIND_FLAG) {
5902 data[2] = source[2];
5903 // Set when currying a bound function.
5904 newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
5906 // Compose partial arguments.
5907 var value = source[3];
5909 var partials = data[3];
5910 data[3] = partials ? composeArgs(partials, value, source[4]) : value;
5911 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
5913 // Compose partial right arguments.
5917 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
5918 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
5920 // Use source `argPos` if available.
5925 // Use source `ary` if it's smaller.
5926 if (srcBitmask & ARY_FLAG) {
5927 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
5929 // Use source `arity` if one is not provided.
5930 if (data[9] == null) {
5931 data[9] = source[9];
5933 // Use source `func` and merge bitmasks.
5934 data[0] = source[0];
5935 data[1] = newBitmask;
5941 * Used by `_.defaultsDeep` to customize its `_.merge` use.
5944 * @param {*} objValue The destination value.
5945 * @param {*} srcValue The source value.
5946 * @param {string} key The key of the property to merge.
5947 * @param {Object} object The parent object of `objValue`.
5948 * @param {Object} source The parent object of `srcValue`.
5949 * @param {Object} [stack] Tracks traversed source values and their merged
5951 * @returns {*} Returns the value to assign.
5953 function mergeDefaults(objValue, srcValue, key, object, source, stack) {
5954 if (isObject(objValue) && isObject(srcValue)) {
5955 baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue));
5961 * Gets the parent value at `path` of `object`.
5964 * @param {Object} object The object to query.
5965 * @param {Array} path The path to get the parent value of.
5966 * @returns {*} Returns the parent value.
5968 function parent(object, path) {
5969 return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
5973 * Reorder `array` according to the specified indexes where the element at
5974 * the first index is assigned as the first element, the element at
5975 * the second index is assigned as the second element, and so on.
5978 * @param {Array} array The array to reorder.
5979 * @param {Array} indexes The arranged array indexes.
5980 * @returns {Array} Returns `array`.
5982 function reorder(array, indexes) {
5983 var arrLength = array.length,
5984 length = nativeMin(indexes.length, arrLength),
5985 oldArray = copyArray(array);
5988 var index = indexes[length];
5989 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
5995 * Sets metadata for `func`.
5997 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
5998 * period of time, it will trip its breaker and transition to an identity
5999 * function to avoid garbage collection pauses in V8. See
6000 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
6004 * @param {Function} func The function to associate metadata with.
6005 * @param {*} data The metadata.
6006 * @returns {Function} Returns `func`.
6008 var setData = (function() {
6012 return function(key, value) {
6014 remaining = HOT_SPAN - (stamp - lastCalled);
6017 if (remaining > 0) {
6018 if (++count >= HOT_COUNT) {
6024 return baseSetData(key, value);
6029 * Converts `string` to a property path array.
6032 * @param {string} string The string to convert.
6033 * @returns {Array} Returns the property path array.
6035 var stringToPath = memoize(function(string) {
6037 toString(string).replace(rePropName, function(match, number, quote, string) {
6038 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
6044 * Converts `value` to a string key if it's not a string or symbol.
6047 * @param {*} value The value to inspect.
6048 * @returns {string|symbol} Returns the key.
6050 function toKey(value) {
6051 if (typeof value == 'string' || isSymbol(value)) {
6054 var result = (value + '');
6055 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
6059 * Converts `func` to its source code.
6062 * @param {Function} func The function to process.
6063 * @returns {string} Returns the source code.
6065 function toSource(func) {
6068 return funcToString.call(func);
6078 * Creates a clone of `wrapper`.
6081 * @param {Object} wrapper The wrapper to clone.
6082 * @returns {Object} Returns the cloned wrapper.
6084 function wrapperClone(wrapper) {
6085 if (wrapper instanceof LazyWrapper) {
6086 return wrapper.clone();
6088 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
6089 result.__actions__ = copyArray(wrapper.__actions__);
6090 result.__index__ = wrapper.__index__;
6091 result.__values__ = wrapper.__values__;
6095 /*------------------------------------------------------------------------*/
6098 * Creates an array of elements split into groups the length of `size`.
6099 * If `array` can't be split evenly, the final chunk will be the remaining
6106 * @param {Array} array The array to process.
6107 * @param {number} [size=1] The length of each chunk
6108 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6109 * @returns {Array} Returns the new array of chunks.
6112 * _.chunk(['a', 'b', 'c', 'd'], 2);
6113 * // => [['a', 'b'], ['c', 'd']]
6115 * _.chunk(['a', 'b', 'c', 'd'], 3);
6116 * // => [['a', 'b', 'c'], ['d']]
6118 function chunk(array, size, guard) {
6119 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
6122 size = nativeMax(toInteger(size), 0);
6124 var length = array ? array.length : 0;
6125 if (!length || size < 1) {
6130 result = Array(nativeCeil(length / size));
6132 while (index < length) {
6133 result[resIndex++] = baseSlice(array, index, (index += size));
6139 * Creates an array with all falsey values removed. The values `false`, `null`,
6140 * `0`, `""`, `undefined`, and `NaN` are falsey.
6146 * @param {Array} array The array to compact.
6147 * @returns {Array} Returns the new array of filtered values.
6150 * _.compact([0, 1, false, 2, '', 3]);
6153 function compact(array) {
6155 length = array ? array.length : 0,
6159 while (++index < length) {
6160 var value = array[index];
6162 result[resIndex++] = value;
6169 * Creates a new array concatenating `array` with any additional arrays
6176 * @param {Array} array The array to concatenate.
6177 * @param {...*} [values] The values to concatenate.
6178 * @returns {Array} Returns the new concatenated array.
6182 * var other = _.concat(array, 2, [3], [[4]]);
6184 * console.log(other);
6185 * // => [1, 2, 3, [4]]
6187 * console.log(array);
6191 var length = arguments.length,
6192 args = Array(length ? length - 1 : 0),
6193 array = arguments[0],
6197 args[index - 1] = arguments[index];
6200 ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1))
6205 * Creates an array of unique `array` values not included in the other given
6206 * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6207 * for equality comparisons. The order of result values is determined by the
6208 * order they occur in the first array.
6214 * @param {Array} array The array to inspect.
6215 * @param {...Array} [values] The values to exclude.
6216 * @returns {Array} Returns the new array of filtered values.
6217 * @see _.without, _.xor
6220 * _.difference([2, 1], [2, 3]);
6223 var difference = rest(function(array, values) {
6224 return isArrayLikeObject(array)
6225 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
6230 * This method is like `_.difference` except that it accepts `iteratee` which
6231 * is invoked for each element of `array` and `values` to generate the criterion
6232 * by which they're compared. Result values are chosen from the first array.
6233 * The iteratee is invoked with one argument: (value).
6239 * @param {Array} array The array to inspect.
6240 * @param {...Array} [values] The values to exclude.
6241 * @param {Array|Function|Object|string} [iteratee=_.identity]
6242 * The iteratee invoked per element.
6243 * @returns {Array} Returns the new array of filtered values.
6246 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
6249 * // The `_.property` iteratee shorthand.
6250 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
6251 * // => [{ 'x': 2 }]
6253 var differenceBy = rest(function(array, values) {
6254 var iteratee = last(values);
6255 if (isArrayLikeObject(iteratee)) {
6256 iteratee = undefined;
6258 return isArrayLikeObject(array)
6259 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee))
6264 * This method is like `_.difference` except that it accepts `comparator`
6265 * which is invoked to compare elements of `array` to `values`. Result values
6266 * are chosen from the first array. The comparator is invoked with two arguments:
6273 * @param {Array} array The array to inspect.
6274 * @param {...Array} [values] The values to exclude.
6275 * @param {Function} [comparator] The comparator invoked per element.
6276 * @returns {Array} Returns the new array of filtered values.
6279 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6281 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
6282 * // => [{ 'x': 2, 'y': 1 }]
6284 var differenceWith = rest(function(array, values) {
6285 var comparator = last(values);
6286 if (isArrayLikeObject(comparator)) {
6287 comparator = undefined;
6289 return isArrayLikeObject(array)
6290 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
6295 * Creates a slice of `array` with `n` elements dropped from the beginning.
6301 * @param {Array} array The array to query.
6302 * @param {number} [n=1] The number of elements to drop.
6303 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6304 * @returns {Array} Returns the slice of `array`.
6307 * _.drop([1, 2, 3]);
6310 * _.drop([1, 2, 3], 2);
6313 * _.drop([1, 2, 3], 5);
6316 * _.drop([1, 2, 3], 0);
6319 function drop(array, n, guard) {
6320 var length = array ? array.length : 0;
6324 n = (guard || n === undefined) ? 1 : toInteger(n);
6325 return baseSlice(array, n < 0 ? 0 : n, length);
6329 * Creates a slice of `array` with `n` elements dropped from the end.
6335 * @param {Array} array The array to query.
6336 * @param {number} [n=1] The number of elements to drop.
6337 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6338 * @returns {Array} Returns the slice of `array`.
6341 * _.dropRight([1, 2, 3]);
6344 * _.dropRight([1, 2, 3], 2);
6347 * _.dropRight([1, 2, 3], 5);
6350 * _.dropRight([1, 2, 3], 0);
6353 function dropRight(array, n, guard) {
6354 var length = array ? array.length : 0;
6358 n = (guard || n === undefined) ? 1 : toInteger(n);
6360 return baseSlice(array, 0, n < 0 ? 0 : n);
6364 * Creates a slice of `array` excluding elements dropped from the end.
6365 * Elements are dropped until `predicate` returns falsey. The predicate is
6366 * invoked with three arguments: (value, index, array).
6372 * @param {Array} array The array to query.
6373 * @param {Array|Function|Object|string} [predicate=_.identity]
6374 * The function invoked per iteration.
6375 * @returns {Array} Returns the slice of `array`.
6379 * { 'user': 'barney', 'active': true },
6380 * { 'user': 'fred', 'active': false },
6381 * { 'user': 'pebbles', 'active': false }
6384 * _.dropRightWhile(users, function(o) { return !o.active; });
6385 * // => objects for ['barney']
6387 * // The `_.matches` iteratee shorthand.
6388 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
6389 * // => objects for ['barney', 'fred']
6391 * // The `_.matchesProperty` iteratee shorthand.
6392 * _.dropRightWhile(users, ['active', false]);
6393 * // => objects for ['barney']
6395 * // The `_.property` iteratee shorthand.
6396 * _.dropRightWhile(users, 'active');
6397 * // => objects for ['barney', 'fred', 'pebbles']
6399 function dropRightWhile(array, predicate) {
6400 return (array && array.length)
6401 ? baseWhile(array, getIteratee(predicate, 3), true, true)
6406 * Creates a slice of `array` excluding elements dropped from the beginning.
6407 * Elements are dropped until `predicate` returns falsey. The predicate is
6408 * invoked with three arguments: (value, index, array).
6414 * @param {Array} array The array to query.
6415 * @param {Array|Function|Object|string} [predicate=_.identity]
6416 * The function invoked per iteration.
6417 * @returns {Array} Returns the slice of `array`.
6421 * { 'user': 'barney', 'active': false },
6422 * { 'user': 'fred', 'active': false },
6423 * { 'user': 'pebbles', 'active': true }
6426 * _.dropWhile(users, function(o) { return !o.active; });
6427 * // => objects for ['pebbles']
6429 * // The `_.matches` iteratee shorthand.
6430 * _.dropWhile(users, { 'user': 'barney', 'active': false });
6431 * // => objects for ['fred', 'pebbles']
6433 * // The `_.matchesProperty` iteratee shorthand.
6434 * _.dropWhile(users, ['active', false]);
6435 * // => objects for ['pebbles']
6437 * // The `_.property` iteratee shorthand.
6438 * _.dropWhile(users, 'active');
6439 * // => objects for ['barney', 'fred', 'pebbles']
6441 function dropWhile(array, predicate) {
6442 return (array && array.length)
6443 ? baseWhile(array, getIteratee(predicate, 3), true)
6448 * Fills elements of `array` with `value` from `start` up to, but not
6451 * **Note:** This method mutates `array`.
6457 * @param {Array} array The array to fill.
6458 * @param {*} value The value to fill `array` with.
6459 * @param {number} [start=0] The start position.
6460 * @param {number} [end=array.length] The end position.
6461 * @returns {Array} Returns `array`.
6464 * var array = [1, 2, 3];
6466 * _.fill(array, 'a');
6467 * console.log(array);
6468 * // => ['a', 'a', 'a']
6470 * _.fill(Array(3), 2);
6473 * _.fill([4, 6, 8, 10], '*', 1, 3);
6474 * // => [4, '*', '*', 10]
6476 function fill(array, value, start, end) {
6477 var length = array ? array.length : 0;
6481 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
6485 return baseFill(array, value, start, end);
6489 * This method is like `_.find` except that it returns the index of the first
6490 * element `predicate` returns truthy for instead of the element itself.
6496 * @param {Array} array The array to search.
6497 * @param {Array|Function|Object|string} [predicate=_.identity]
6498 * The function invoked per iteration.
6499 * @param {number} [fromIndex=0] The index to search from.
6500 * @returns {number} Returns the index of the found element, else `-1`.
6504 * { 'user': 'barney', 'active': false },
6505 * { 'user': 'fred', 'active': false },
6506 * { 'user': 'pebbles', 'active': true }
6509 * _.findIndex(users, function(o) { return o.user == 'barney'; });
6512 * // The `_.matches` iteratee shorthand.
6513 * _.findIndex(users, { 'user': 'fred', 'active': false });
6516 * // The `_.matchesProperty` iteratee shorthand.
6517 * _.findIndex(users, ['active', false]);
6520 * // The `_.property` iteratee shorthand.
6521 * _.findIndex(users, 'active');
6524 function findIndex(array, predicate, fromIndex) {
6525 var length = array ? array.length : 0;
6529 var index = fromIndex == null ? 0 : toInteger(fromIndex);
6531 index = nativeMax(length + index, 0);
6533 return baseFindIndex(array, getIteratee(predicate, 3), index);
6537 * This method is like `_.findIndex` except that it iterates over elements
6538 * of `collection` from right to left.
6544 * @param {Array} array The array to search.
6545 * @param {Array|Function|Object|string} [predicate=_.identity]
6546 * The function invoked per iteration.
6547 * @param {number} [fromIndex=array.length-1] The index to search from.
6548 * @returns {number} Returns the index of the found element, else `-1`.
6552 * { 'user': 'barney', 'active': true },
6553 * { 'user': 'fred', 'active': false },
6554 * { 'user': 'pebbles', 'active': false }
6557 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
6560 * // The `_.matches` iteratee shorthand.
6561 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
6564 * // The `_.matchesProperty` iteratee shorthand.
6565 * _.findLastIndex(users, ['active', false]);
6568 * // The `_.property` iteratee shorthand.
6569 * _.findLastIndex(users, 'active');
6572 function findLastIndex(array, predicate, fromIndex) {
6573 var length = array ? array.length : 0;
6577 var index = length - 1;
6578 if (fromIndex !== undefined) {
6579 index = toInteger(fromIndex);
6580 index = fromIndex < 0
6581 ? nativeMax(length + index, 0)
6582 : nativeMin(index, length - 1);
6584 return baseFindIndex(array, getIteratee(predicate, 3), index, true);
6588 * Flattens `array` a single level deep.
6594 * @param {Array} array The array to flatten.
6595 * @returns {Array} Returns the new flattened array.
6598 * _.flatten([1, [2, [3, [4]], 5]]);
6599 * // => [1, 2, [3, [4]], 5]
6601 function flatten(array) {
6602 var length = array ? array.length : 0;
6603 return length ? baseFlatten(array, 1) : [];
6607 * Recursively flattens `array`.
6613 * @param {Array} array The array to flatten.
6614 * @returns {Array} Returns the new flattened array.
6617 * _.flattenDeep([1, [2, [3, [4]], 5]]);
6618 * // => [1, 2, 3, 4, 5]
6620 function flattenDeep(array) {
6621 var length = array ? array.length : 0;
6622 return length ? baseFlatten(array, INFINITY) : [];
6626 * Recursively flatten `array` up to `depth` times.
6632 * @param {Array} array The array to flatten.
6633 * @param {number} [depth=1] The maximum recursion depth.
6634 * @returns {Array} Returns the new flattened array.
6637 * var array = [1, [2, [3, [4]], 5]];
6639 * _.flattenDepth(array, 1);
6640 * // => [1, 2, [3, [4]], 5]
6642 * _.flattenDepth(array, 2);
6643 * // => [1, 2, 3, [4], 5]
6645 function flattenDepth(array, depth) {
6646 var length = array ? array.length : 0;
6650 depth = depth === undefined ? 1 : toInteger(depth);
6651 return baseFlatten(array, depth);
6655 * The inverse of `_.toPairs`; this method returns an object composed
6656 * from key-value `pairs`.
6662 * @param {Array} pairs The key-value pairs.
6663 * @returns {Object} Returns the new object.
6666 * _.fromPairs([['fred', 30], ['barney', 40]]);
6667 * // => { 'fred': 30, 'barney': 40 }
6669 function fromPairs(pairs) {
6671 length = pairs ? pairs.length : 0,
6674 while (++index < length) {
6675 var pair = pairs[index];
6676 result[pair[0]] = pair[1];
6682 * Gets the first element of `array`.
6689 * @param {Array} array The array to query.
6690 * @returns {*} Returns the first element of `array`.
6693 * _.head([1, 2, 3]);
6699 function head(array) {
6700 return (array && array.length) ? array[0] : undefined;
6704 * Gets the index at which the first occurrence of `value` is found in `array`
6705 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6706 * for equality comparisons. If `fromIndex` is negative, it's used as the
6707 * offset from the end of `array`.
6713 * @param {Array} array The array to search.
6714 * @param {*} value The value to search for.
6715 * @param {number} [fromIndex=0] The index to search from.
6716 * @returns {number} Returns the index of the matched value, else `-1`.
6719 * _.indexOf([1, 2, 1, 2], 2);
6722 * // Search from the `fromIndex`.
6723 * _.indexOf([1, 2, 1, 2], 2, 2);
6726 function indexOf(array, value, fromIndex) {
6727 var length = array ? array.length : 0;
6731 var index = fromIndex == null ? 0 : toInteger(fromIndex);
6733 index = nativeMax(length + index, 0);
6735 return baseIndexOf(array, value, index);
6739 * Gets all but the last element of `array`.
6745 * @param {Array} array The array to query.
6746 * @returns {Array} Returns the slice of `array`.
6749 * _.initial([1, 2, 3]);
6752 function initial(array) {
6753 return dropRight(array, 1);
6757 * Creates an array of unique values that are included in all given arrays
6758 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6759 * for equality comparisons. The order of result values is determined by the
6760 * order they occur in the first array.
6766 * @param {...Array} [arrays] The arrays to inspect.
6767 * @returns {Array} Returns the new array of intersecting values.
6770 * _.intersection([2, 1], [2, 3]);
6773 var intersection = rest(function(arrays) {
6774 var mapped = arrayMap(arrays, castArrayLikeObject);
6775 return (mapped.length && mapped[0] === arrays[0])
6776 ? baseIntersection(mapped)
6781 * This method is like `_.intersection` except that it accepts `iteratee`
6782 * which is invoked for each element of each `arrays` to generate the criterion
6783 * by which they're compared. Result values are chosen from the first array.
6784 * The iteratee is invoked with one argument: (value).
6790 * @param {...Array} [arrays] The arrays to inspect.
6791 * @param {Array|Function|Object|string} [iteratee=_.identity]
6792 * The iteratee invoked per element.
6793 * @returns {Array} Returns the new array of intersecting values.
6796 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
6799 * // The `_.property` iteratee shorthand.
6800 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
6801 * // => [{ 'x': 1 }]
6803 var intersectionBy = rest(function(arrays) {
6804 var iteratee = last(arrays),
6805 mapped = arrayMap(arrays, castArrayLikeObject);
6807 if (iteratee === last(mapped)) {
6808 iteratee = undefined;
6812 return (mapped.length && mapped[0] === arrays[0])
6813 ? baseIntersection(mapped, getIteratee(iteratee))
6818 * This method is like `_.intersection` except that it accepts `comparator`
6819 * which is invoked to compare elements of `arrays`. Result values are chosen
6820 * from the first array. The comparator is invoked with two arguments:
6827 * @param {...Array} [arrays] The arrays to inspect.
6828 * @param {Function} [comparator] The comparator invoked per element.
6829 * @returns {Array} Returns the new array of intersecting values.
6832 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6833 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6835 * _.intersectionWith(objects, others, _.isEqual);
6836 * // => [{ 'x': 1, 'y': 2 }]
6838 var intersectionWith = rest(function(arrays) {
6839 var comparator = last(arrays),
6840 mapped = arrayMap(arrays, castArrayLikeObject);
6842 if (comparator === last(mapped)) {
6843 comparator = undefined;
6847 return (mapped.length && mapped[0] === arrays[0])
6848 ? baseIntersection(mapped, undefined, comparator)
6853 * Converts all elements in `array` into a string separated by `separator`.
6859 * @param {Array} array The array to convert.
6860 * @param {string} [separator=','] The element separator.
6861 * @returns {string} Returns the joined string.
6864 * _.join(['a', 'b', 'c'], '~');
6867 function join(array, separator) {
6868 return array ? nativeJoin.call(array, separator) : '';
6872 * Gets the last element of `array`.
6878 * @param {Array} array The array to query.
6879 * @returns {*} Returns the last element of `array`.
6882 * _.last([1, 2, 3]);
6885 function last(array) {
6886 var length = array ? array.length : 0;
6887 return length ? array[length - 1] : undefined;
6891 * This method is like `_.indexOf` except that it iterates over elements of
6892 * `array` from right to left.
6898 * @param {Array} array The array to search.
6899 * @param {*} value The value to search for.
6900 * @param {number} [fromIndex=array.length-1] The index to search from.
6901 * @returns {number} Returns the index of the matched value, else `-1`.
6904 * _.lastIndexOf([1, 2, 1, 2], 2);
6907 * // Search from the `fromIndex`.
6908 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
6911 function lastIndexOf(array, value, fromIndex) {
6912 var length = array ? array.length : 0;
6917 if (fromIndex !== undefined) {
6918 index = toInteger(fromIndex);
6921 ? nativeMax(length + index, 0)
6922 : nativeMin(index, length - 1)
6925 if (value !== value) {
6926 return indexOfNaN(array, index - 1, true);
6929 if (array[index] === value) {
6937 * Gets the element at index `n` of `array`. If `n` is negative, the nth
6938 * element from the end is returned.
6944 * @param {Array} array The array to query.
6945 * @param {number} [n=0] The index of the element to return.
6946 * @returns {*} Returns the nth element of `array`.
6949 * var array = ['a', 'b', 'c', 'd'];
6957 function nth(array, n) {
6958 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
6962 * Removes all given values from `array` using
6963 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6964 * for equality comparisons.
6966 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
6967 * to remove elements from an array by predicate.
6973 * @param {Array} array The array to modify.
6974 * @param {...*} [values] The values to remove.
6975 * @returns {Array} Returns `array`.
6978 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
6980 * _.pull(array, 'a', 'c');
6981 * console.log(array);
6984 var pull = rest(pullAll);
6987 * This method is like `_.pull` except that it accepts an array of values to remove.
6989 * **Note:** Unlike `_.difference`, this method mutates `array`.
6995 * @param {Array} array The array to modify.
6996 * @param {Array} values The values to remove.
6997 * @returns {Array} Returns `array`.
7000 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7002 * _.pullAll(array, ['a', 'c']);
7003 * console.log(array);
7006 function pullAll(array, values) {
7007 return (array && array.length && values && values.length)
7008 ? basePullAll(array, values)
7013 * This method is like `_.pullAll` except that it accepts `iteratee` which is
7014 * invoked for each element of `array` and `values` to generate the criterion
7015 * by which they're compared. The iteratee is invoked with one argument: (value).
7017 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
7023 * @param {Array} array The array to modify.
7024 * @param {Array} values The values to remove.
7025 * @param {Array|Function|Object|string} [iteratee=_.identity]
7026 * The iteratee invoked per element.
7027 * @returns {Array} Returns `array`.
7030 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
7032 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
7033 * console.log(array);
7034 * // => [{ 'x': 2 }]
7036 function pullAllBy(array, values, iteratee) {
7037 return (array && array.length && values && values.length)
7038 ? basePullAll(array, values, getIteratee(iteratee))
7043 * This method is like `_.pullAll` except that it accepts `comparator` which
7044 * is invoked to compare elements of `array` to `values`. The comparator is
7045 * invoked with two arguments: (arrVal, othVal).
7047 * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
7053 * @param {Array} array The array to modify.
7054 * @param {Array} values The values to remove.
7055 * @param {Function} [comparator] The comparator invoked per element.
7056 * @returns {Array} Returns `array`.
7059 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
7061 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
7062 * console.log(array);
7063 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
7065 function pullAllWith(array, values, comparator) {
7066 return (array && array.length && values && values.length)
7067 ? basePullAll(array, values, undefined, comparator)
7072 * Removes elements from `array` corresponding to `indexes` and returns an
7073 * array of removed elements.
7075 * **Note:** Unlike `_.at`, this method mutates `array`.
7081 * @param {Array} array The array to modify.
7082 * @param {...(number|number[])} [indexes] The indexes of elements to remove.
7083 * @returns {Array} Returns the new array of removed elements.
7086 * var array = ['a', 'b', 'c', 'd'];
7087 * var pulled = _.pullAt(array, [1, 3]);
7089 * console.log(array);
7092 * console.log(pulled);
7095 var pullAt = rest(function(array, indexes) {
7096 indexes = baseFlatten(indexes, 1);
7098 var length = array ? array.length : 0,
7099 result = baseAt(array, indexes);
7101 basePullAt(array, arrayMap(indexes, function(index) {
7102 return isIndex(index, length) ? +index : index;
7103 }).sort(compareAscending));
7109 * Removes all elements from `array` that `predicate` returns truthy for
7110 * and returns an array of the removed elements. The predicate is invoked
7111 * with three arguments: (value, index, array).
7113 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
7114 * to pull elements from an array by value.
7120 * @param {Array} array The array to modify.
7121 * @param {Array|Function|Object|string} [predicate=_.identity]
7122 * The function invoked per iteration.
7123 * @returns {Array} Returns the new array of removed elements.
7126 * var array = [1, 2, 3, 4];
7127 * var evens = _.remove(array, function(n) {
7128 * return n % 2 == 0;
7131 * console.log(array);
7134 * console.log(evens);
7137 function remove(array, predicate) {
7139 if (!(array && array.length)) {
7144 length = array.length;
7146 predicate = getIteratee(predicate, 3);
7147 while (++index < length) {
7148 var value = array[index];
7149 if (predicate(value, index, array)) {
7151 indexes.push(index);
7154 basePullAt(array, indexes);
7159 * Reverses `array` so that the first element becomes the last, the second
7160 * element becomes the second to last, and so on.
7162 * **Note:** This method mutates `array` and is based on
7163 * [`Array#reverse`](https://mdn.io/Array/reverse).
7169 * @param {Array} array The array to modify.
7170 * @returns {Array} Returns `array`.
7173 * var array = [1, 2, 3];
7178 * console.log(array);
7181 function reverse(array) {
7182 return array ? nativeReverse.call(array) : array;
7186 * Creates a slice of `array` from `start` up to, but not including, `end`.
7188 * **Note:** This method is used instead of
7189 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
7196 * @param {Array} array The array to slice.
7197 * @param {number} [start=0] The start position.
7198 * @param {number} [end=array.length] The end position.
7199 * @returns {Array} Returns the slice of `array`.
7201 function slice(array, start, end) {
7202 var length = array ? array.length : 0;
7206 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
7211 start = start == null ? 0 : toInteger(start);
7212 end = end === undefined ? length : toInteger(end);
7214 return baseSlice(array, start, end);
7218 * Uses a binary search to determine the lowest index at which `value`
7219 * should be inserted into `array` in order to maintain its sort order.
7225 * @param {Array} array The sorted array to inspect.
7226 * @param {*} value The value to evaluate.
7227 * @returns {number} Returns the index at which `value` should be inserted
7231 * _.sortedIndex([30, 50], 40);
7234 function sortedIndex(array, value) {
7235 return baseSortedIndex(array, value);
7239 * This method is like `_.sortedIndex` except that it accepts `iteratee`
7240 * which is invoked for `value` and each element of `array` to compute their
7241 * sort ranking. The iteratee is invoked with one argument: (value).
7247 * @param {Array} array The sorted array to inspect.
7248 * @param {*} value The value to evaluate.
7249 * @param {Array|Function|Object|string} [iteratee=_.identity]
7250 * The iteratee invoked per element.
7251 * @returns {number} Returns the index at which `value` should be inserted
7255 * var objects = [{ 'x': 4 }, { 'x': 5 }];
7257 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
7260 * // The `_.property` iteratee shorthand.
7261 * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
7264 function sortedIndexBy(array, value, iteratee) {
7265 return baseSortedIndexBy(array, value, getIteratee(iteratee));
7269 * This method is like `_.indexOf` except that it performs a binary
7270 * search on a sorted `array`.
7276 * @param {Array} array The array to search.
7277 * @param {*} value The value to search for.
7278 * @returns {number} Returns the index of the matched value, else `-1`.
7281 * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
7284 function sortedIndexOf(array, value) {
7285 var length = array ? array.length : 0;
7287 var index = baseSortedIndex(array, value);
7288 if (index < length && eq(array[index], value)) {
7296 * This method is like `_.sortedIndex` except that it returns the highest
7297 * index at which `value` should be inserted into `array` in order to
7298 * maintain its sort order.
7304 * @param {Array} array The sorted array to inspect.
7305 * @param {*} value The value to evaluate.
7306 * @returns {number} Returns the index at which `value` should be inserted
7310 * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
7313 function sortedLastIndex(array, value) {
7314 return baseSortedIndex(array, value, true);
7318 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
7319 * which is invoked for `value` and each element of `array` to compute their
7320 * sort ranking. The iteratee is invoked with one argument: (value).
7326 * @param {Array} array The sorted array to inspect.
7327 * @param {*} value The value to evaluate.
7328 * @param {Array|Function|Object|string} [iteratee=_.identity]
7329 * The iteratee invoked per element.
7330 * @returns {number} Returns the index at which `value` should be inserted
7334 * var objects = [{ 'x': 4 }, { 'x': 5 }];
7336 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
7339 * // The `_.property` iteratee shorthand.
7340 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
7343 function sortedLastIndexBy(array, value, iteratee) {
7344 return baseSortedIndexBy(array, value, getIteratee(iteratee), true);
7348 * This method is like `_.lastIndexOf` except that it performs a binary
7349 * search on a sorted `array`.
7355 * @param {Array} array The array to search.
7356 * @param {*} value The value to search for.
7357 * @returns {number} Returns the index of the matched value, else `-1`.
7360 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
7363 function sortedLastIndexOf(array, value) {
7364 var length = array ? array.length : 0;
7366 var index = baseSortedIndex(array, value, true) - 1;
7367 if (eq(array[index], value)) {
7375 * This method is like `_.uniq` except that it's designed and optimized
7376 * for sorted arrays.
7382 * @param {Array} array The array to inspect.
7383 * @returns {Array} Returns the new duplicate free array.
7386 * _.sortedUniq([1, 1, 2]);
7389 function sortedUniq(array) {
7390 return (array && array.length)
7391 ? baseSortedUniq(array)
7396 * This method is like `_.uniqBy` except that it's designed and optimized
7397 * for sorted arrays.
7403 * @param {Array} array The array to inspect.
7404 * @param {Function} [iteratee] The iteratee invoked per element.
7405 * @returns {Array} Returns the new duplicate free array.
7408 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
7411 function sortedUniqBy(array, iteratee) {
7412 return (array && array.length)
7413 ? baseSortedUniq(array, getIteratee(iteratee))
7418 * Gets all but the first element of `array`.
7424 * @param {Array} array The array to query.
7425 * @returns {Array} Returns the slice of `array`.
7428 * _.tail([1, 2, 3]);
7431 function tail(array) {
7432 return drop(array, 1);
7436 * Creates a slice of `array` with `n` elements taken from the beginning.
7442 * @param {Array} array The array to query.
7443 * @param {number} [n=1] The number of elements to take.
7444 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7445 * @returns {Array} Returns the slice of `array`.
7448 * _.take([1, 2, 3]);
7451 * _.take([1, 2, 3], 2);
7454 * _.take([1, 2, 3], 5);
7457 * _.take([1, 2, 3], 0);
7460 function take(array, n, guard) {
7461 if (!(array && array.length)) {
7464 n = (guard || n === undefined) ? 1 : toInteger(n);
7465 return baseSlice(array, 0, n < 0 ? 0 : n);
7469 * Creates a slice of `array` with `n` elements taken from the end.
7475 * @param {Array} array The array to query.
7476 * @param {number} [n=1] The number of elements to take.
7477 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7478 * @returns {Array} Returns the slice of `array`.
7481 * _.takeRight([1, 2, 3]);
7484 * _.takeRight([1, 2, 3], 2);
7487 * _.takeRight([1, 2, 3], 5);
7490 * _.takeRight([1, 2, 3], 0);
7493 function takeRight(array, n, guard) {
7494 var length = array ? array.length : 0;
7498 n = (guard || n === undefined) ? 1 : toInteger(n);
7500 return baseSlice(array, n < 0 ? 0 : n, length);
7504 * Creates a slice of `array` with elements taken from the end. Elements are
7505 * taken until `predicate` returns falsey. The predicate is invoked with
7506 * three arguments: (value, index, array).
7512 * @param {Array} array The array to query.
7513 * @param {Array|Function|Object|string} [predicate=_.identity]
7514 * The function invoked per iteration.
7515 * @returns {Array} Returns the slice of `array`.
7519 * { 'user': 'barney', 'active': true },
7520 * { 'user': 'fred', 'active': false },
7521 * { 'user': 'pebbles', 'active': false }
7524 * _.takeRightWhile(users, function(o) { return !o.active; });
7525 * // => objects for ['fred', 'pebbles']
7527 * // The `_.matches` iteratee shorthand.
7528 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
7529 * // => objects for ['pebbles']
7531 * // The `_.matchesProperty` iteratee shorthand.
7532 * _.takeRightWhile(users, ['active', false]);
7533 * // => objects for ['fred', 'pebbles']
7535 * // The `_.property` iteratee shorthand.
7536 * _.takeRightWhile(users, 'active');
7539 function takeRightWhile(array, predicate) {
7540 return (array && array.length)
7541 ? baseWhile(array, getIteratee(predicate, 3), false, true)
7546 * Creates a slice of `array` with elements taken from the beginning. Elements
7547 * are taken until `predicate` returns falsey. The predicate is invoked with
7548 * three arguments: (value, index, array).
7554 * @param {Array} array The array to query.
7555 * @param {Array|Function|Object|string} [predicate=_.identity]
7556 * The function invoked per iteration.
7557 * @returns {Array} Returns the slice of `array`.
7561 * { 'user': 'barney', 'active': false },
7562 * { 'user': 'fred', 'active': false},
7563 * { 'user': 'pebbles', 'active': true }
7566 * _.takeWhile(users, function(o) { return !o.active; });
7567 * // => objects for ['barney', 'fred']
7569 * // The `_.matches` iteratee shorthand.
7570 * _.takeWhile(users, { 'user': 'barney', 'active': false });
7571 * // => objects for ['barney']
7573 * // The `_.matchesProperty` iteratee shorthand.
7574 * _.takeWhile(users, ['active', false]);
7575 * // => objects for ['barney', 'fred']
7577 * // The `_.property` iteratee shorthand.
7578 * _.takeWhile(users, 'active');
7581 function takeWhile(array, predicate) {
7582 return (array && array.length)
7583 ? baseWhile(array, getIteratee(predicate, 3))
7588 * Creates an array of unique values, in order, from all given arrays using
7589 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7590 * for equality comparisons.
7596 * @param {...Array} [arrays] The arrays to inspect.
7597 * @returns {Array} Returns the new array of combined values.
7600 * _.union([2], [1, 2]);
7603 var union = rest(function(arrays) {
7604 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
7608 * This method is like `_.union` except that it accepts `iteratee` which is
7609 * invoked for each element of each `arrays` to generate the criterion by
7610 * which uniqueness is computed. The iteratee is invoked with one argument:
7617 * @param {...Array} [arrays] The arrays to inspect.
7618 * @param {Array|Function|Object|string} [iteratee=_.identity]
7619 * The iteratee invoked per element.
7620 * @returns {Array} Returns the new array of combined values.
7623 * _.unionBy([2.1], [1.2, 2.3], Math.floor);
7626 * // The `_.property` iteratee shorthand.
7627 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7628 * // => [{ 'x': 1 }, { 'x': 2 }]
7630 var unionBy = rest(function(arrays) {
7631 var iteratee = last(arrays);
7632 if (isArrayLikeObject(iteratee)) {
7633 iteratee = undefined;
7635 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee));
7639 * This method is like `_.union` except that it accepts `comparator` which
7640 * is invoked to compare elements of `arrays`. The comparator is invoked
7641 * with two arguments: (arrVal, othVal).
7647 * @param {...Array} [arrays] The arrays to inspect.
7648 * @param {Function} [comparator] The comparator invoked per element.
7649 * @returns {Array} Returns the new array of combined values.
7652 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7653 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7655 * _.unionWith(objects, others, _.isEqual);
7656 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
7658 var unionWith = rest(function(arrays) {
7659 var comparator = last(arrays);
7660 if (isArrayLikeObject(comparator)) {
7661 comparator = undefined;
7663 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
7667 * Creates a duplicate-free version of an array, using
7668 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7669 * for equality comparisons, in which only the first occurrence of each
7676 * @param {Array} array The array to inspect.
7677 * @returns {Array} Returns the new duplicate free array.
7680 * _.uniq([2, 1, 2]);
7683 function uniq(array) {
7684 return (array && array.length)
7690 * This method is like `_.uniq` except that it accepts `iteratee` which is
7691 * invoked for each element in `array` to generate the criterion by which
7692 * uniqueness is computed. The iteratee is invoked with one argument: (value).
7698 * @param {Array} array The array to inspect.
7699 * @param {Array|Function|Object|string} [iteratee=_.identity]
7700 * The iteratee invoked per element.
7701 * @returns {Array} Returns the new duplicate free array.
7704 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
7707 * // The `_.property` iteratee shorthand.
7708 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
7709 * // => [{ 'x': 1 }, { 'x': 2 }]
7711 function uniqBy(array, iteratee) {
7712 return (array && array.length)
7713 ? baseUniq(array, getIteratee(iteratee))
7718 * This method is like `_.uniq` except that it accepts `comparator` which
7719 * is invoked to compare elements of `array`. The comparator is invoked with
7720 * two arguments: (arrVal, othVal).
7726 * @param {Array} array The array to inspect.
7727 * @param {Function} [comparator] The comparator invoked per element.
7728 * @returns {Array} Returns the new duplicate free array.
7731 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
7733 * _.uniqWith(objects, _.isEqual);
7734 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
7736 function uniqWith(array, comparator) {
7737 return (array && array.length)
7738 ? baseUniq(array, undefined, comparator)
7743 * This method is like `_.zip` except that it accepts an array of grouped
7744 * elements and creates an array regrouping the elements to their pre-zip
7751 * @param {Array} array The array of grouped elements to process.
7752 * @returns {Array} Returns the new array of regrouped elements.
7755 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
7756 * // => [['fred', 30, true], ['barney', 40, false]]
7759 * // => [['fred', 'barney'], [30, 40], [true, false]]
7761 function unzip(array) {
7762 if (!(array && array.length)) {
7766 array = arrayFilter(array, function(group) {
7767 if (isArrayLikeObject(group)) {
7768 length = nativeMax(group.length, length);
7772 return baseTimes(length, function(index) {
7773 return arrayMap(array, baseProperty(index));
7778 * This method is like `_.unzip` except that it accepts `iteratee` to specify
7779 * how regrouped values should be combined. The iteratee is invoked with the
7780 * elements of each group: (...group).
7786 * @param {Array} array The array of grouped elements to process.
7787 * @param {Function} [iteratee=_.identity] The function to combine
7789 * @returns {Array} Returns the new array of regrouped elements.
7792 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
7793 * // => [[1, 10, 100], [2, 20, 200]]
7795 * _.unzipWith(zipped, _.add);
7796 * // => [3, 30, 300]
7798 function unzipWith(array, iteratee) {
7799 if (!(array && array.length)) {
7802 var result = unzip(array);
7803 if (iteratee == null) {
7806 return arrayMap(result, function(group) {
7807 return apply(iteratee, undefined, group);
7812 * Creates an array excluding all given values using
7813 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7814 * for equality comparisons.
7820 * @param {Array} array The array to inspect.
7821 * @param {...*} [values] The values to exclude.
7822 * @returns {Array} Returns the new array of filtered values.
7823 * @see _.difference, _.xor
7826 * _.without([2, 1, 2, 3], 1, 2);
7829 var without = rest(function(array, values) {
7830 return isArrayLikeObject(array)
7831 ? baseDifference(array, values)
7836 * Creates an array of unique values that is the
7837 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
7838 * of the given arrays. The order of result values is determined by the order
7839 * they occur in the arrays.
7845 * @param {...Array} [arrays] The arrays to inspect.
7846 * @returns {Array} Returns the new array of filtered values.
7847 * @see _.difference, _.without
7850 * _.xor([2, 1], [2, 3]);
7853 var xor = rest(function(arrays) {
7854 return baseXor(arrayFilter(arrays, isArrayLikeObject));
7858 * This method is like `_.xor` except that it accepts `iteratee` which is
7859 * invoked for each element of each `arrays` to generate the criterion by
7860 * which by which they're compared. The iteratee is invoked with one argument:
7867 * @param {...Array} [arrays] The arrays to inspect.
7868 * @param {Array|Function|Object|string} [iteratee=_.identity]
7869 * The iteratee invoked per element.
7870 * @returns {Array} Returns the new array of filtered values.
7873 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7876 * // The `_.property` iteratee shorthand.
7877 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7878 * // => [{ 'x': 2 }]
7880 var xorBy = rest(function(arrays) {
7881 var iteratee = last(arrays);
7882 if (isArrayLikeObject(iteratee)) {
7883 iteratee = undefined;
7885 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee));
7889 * This method is like `_.xor` except that it accepts `comparator` which is
7890 * invoked to compare elements of `arrays`. The comparator is invoked with
7891 * two arguments: (arrVal, othVal).
7897 * @param {...Array} [arrays] The arrays to inspect.
7898 * @param {Function} [comparator] The comparator invoked per element.
7899 * @returns {Array} Returns the new array of filtered values.
7902 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7903 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7905 * _.xorWith(objects, others, _.isEqual);
7906 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
7908 var xorWith = rest(function(arrays) {
7909 var comparator = last(arrays);
7910 if (isArrayLikeObject(comparator)) {
7911 comparator = undefined;
7913 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
7917 * Creates an array of grouped elements, the first of which contains the
7918 * first elements of the given arrays, the second of which contains the
7919 * second elements of the given arrays, and so on.
7925 * @param {...Array} [arrays] The arrays to process.
7926 * @returns {Array} Returns the new array of grouped elements.
7929 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
7930 * // => [['fred', 30, true], ['barney', 40, false]]
7932 var zip = rest(unzip);
7935 * This method is like `_.fromPairs` except that it accepts two arrays,
7936 * one of property identifiers and one of corresponding values.
7942 * @param {Array} [props=[]] The property identifiers.
7943 * @param {Array} [values=[]] The property values.
7944 * @returns {Object} Returns the new object.
7947 * _.zipObject(['a', 'b'], [1, 2]);
7948 * // => { 'a': 1, 'b': 2 }
7950 function zipObject(props, values) {
7951 return baseZipObject(props || [], values || [], assignValue);
7955 * This method is like `_.zipObject` except that it supports property paths.
7961 * @param {Array} [props=[]] The property identifiers.
7962 * @param {Array} [values=[]] The property values.
7963 * @returns {Object} Returns the new object.
7966 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
7967 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
7969 function zipObjectDeep(props, values) {
7970 return baseZipObject(props || [], values || [], baseSet);
7974 * This method is like `_.zip` except that it accepts `iteratee` to specify
7975 * how grouped values should be combined. The iteratee is invoked with the
7976 * elements of each group: (...group).
7982 * @param {...Array} [arrays] The arrays to process.
7983 * @param {Function} [iteratee=_.identity] The function to combine grouped values.
7984 * @returns {Array} Returns the new array of grouped elements.
7987 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
7992 var zipWith = rest(function(arrays) {
7993 var length = arrays.length,
7994 iteratee = length > 1 ? arrays[length - 1] : undefined;
7996 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
7997 return unzipWith(arrays, iteratee);
8000 /*------------------------------------------------------------------------*/
8003 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
8004 * chain sequences enabled. The result of such sequences must be unwrapped
8011 * @param {*} value The value to wrap.
8012 * @returns {Object} Returns the new `lodash` wrapper instance.
8016 * { 'user': 'barney', 'age': 36 },
8017 * { 'user': 'fred', 'age': 40 },
8018 * { 'user': 'pebbles', 'age': 1 }
8024 * .map(function(o) {
8025 * return o.user + ' is ' + o.age;
8029 * // => 'pebbles is 1'
8031 function chain(value) {
8032 var result = lodash(value);
8033 result.__chain__ = true;
8038 * This method invokes `interceptor` and returns `value`. The interceptor
8039 * is invoked with one argument; (value). The purpose of this method is to
8040 * "tap into" a method chain sequence in order to modify intermediate results.
8046 * @param {*} value The value to provide to `interceptor`.
8047 * @param {Function} interceptor The function to invoke.
8048 * @returns {*} Returns `value`.
8052 * .tap(function(array) {
8053 * // Mutate input array.
8060 function tap(value, interceptor) {
8066 * This method is like `_.tap` except that it returns the result of `interceptor`.
8067 * The purpose of this method is to "pass thru" values replacing intermediate
8068 * results in a method chain sequence.
8074 * @param {*} value The value to provide to `interceptor`.
8075 * @param {Function} interceptor The function to invoke.
8076 * @returns {*} Returns the result of `interceptor`.
8082 * .thru(function(value) {
8088 function thru(value, interceptor) {
8089 return interceptor(value);
8093 * This method is the wrapper version of `_.at`.
8099 * @param {...(string|string[])} [paths] The property paths of elements to pick.
8100 * @returns {Object} Returns the new `lodash` wrapper instance.
8103 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
8105 * _(object).at(['a[0].b.c', 'a[1]']).value();
8108 var wrapperAt = rest(function(paths) {
8109 paths = baseFlatten(paths, 1);
8110 var length = paths.length,
8111 start = length ? paths[0] : 0,
8112 value = this.__wrapped__,
8113 interceptor = function(object) { return baseAt(object, paths); };
8115 if (length > 1 || this.__actions__.length ||
8116 !(value instanceof LazyWrapper) || !isIndex(start)) {
8117 return this.thru(interceptor);
8119 value = value.slice(start, +start + (length ? 1 : 0));
8120 value.__actions__.push({
8122 'args': [interceptor],
8123 'thisArg': undefined
8125 return new LodashWrapper(value, this.__chain__).thru(function(array) {
8126 if (length && !array.length) {
8127 array.push(undefined);
8134 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
8140 * @returns {Object} Returns the new `lodash` wrapper instance.
8144 * { 'user': 'barney', 'age': 36 },
8145 * { 'user': 'fred', 'age': 40 }
8148 * // A sequence without explicit chaining.
8150 * // => { 'user': 'barney', 'age': 36 }
8152 * // A sequence with explicit chaining.
8158 * // => { 'user': 'barney' }
8160 function wrapperChain() {
8165 * Executes the chain sequence and returns the wrapped result.
8171 * @returns {Object} Returns the new `lodash` wrapper instance.
8174 * var array = [1, 2];
8175 * var wrapped = _(array).push(3);
8177 * console.log(array);
8180 * wrapped = wrapped.commit();
8181 * console.log(array);
8187 * console.log(array);
8190 function wrapperCommit() {
8191 return new LodashWrapper(this.value(), this.__chain__);
8195 * Gets the next value on a wrapped object following the
8196 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
8202 * @returns {Object} Returns the next iterator value.
8205 * var wrapped = _([1, 2]);
8208 * // => { 'done': false, 'value': 1 }
8211 * // => { 'done': false, 'value': 2 }
8214 * // => { 'done': true, 'value': undefined }
8216 function wrapperNext() {
8217 if (this.__values__ === undefined) {
8218 this.__values__ = toArray(this.value());
8220 var done = this.__index__ >= this.__values__.length,
8221 value = done ? undefined : this.__values__[this.__index__++];
8223 return { 'done': done, 'value': value };
8227 * Enables the wrapper to be iterable.
8229 * @name Symbol.iterator
8233 * @returns {Object} Returns the wrapper object.
8236 * var wrapped = _([1, 2]);
8238 * wrapped[Symbol.iterator]() === wrapped;
8241 * Array.from(wrapped);
8244 function wrapperToIterator() {
8249 * Creates a clone of the chain sequence planting `value` as the wrapped value.
8255 * @param {*} value The value to plant.
8256 * @returns {Object} Returns the new `lodash` wrapper instance.
8259 * function square(n) {
8263 * var wrapped = _([1, 2]).map(square);
8264 * var other = wrapped.plant([3, 4]);
8272 function wrapperPlant(value) {
8276 while (parent instanceof baseLodash) {
8277 var clone = wrapperClone(parent);
8278 clone.__index__ = 0;
8279 clone.__values__ = undefined;
8281 previous.__wrapped__ = clone;
8285 var previous = clone;
8286 parent = parent.__wrapped__;
8288 previous.__wrapped__ = value;
8293 * This method is the wrapper version of `_.reverse`.
8295 * **Note:** This method mutates the wrapped array.
8301 * @returns {Object} Returns the new `lodash` wrapper instance.
8304 * var array = [1, 2, 3];
8306 * _(array).reverse().value()
8309 * console.log(array);
8312 function wrapperReverse() {
8313 var value = this.__wrapped__;
8314 if (value instanceof LazyWrapper) {
8315 var wrapped = value;
8316 if (this.__actions__.length) {
8317 wrapped = new LazyWrapper(this);
8319 wrapped = wrapped.reverse();
8320 wrapped.__actions__.push({
8323 'thisArg': undefined
8325 return new LodashWrapper(wrapped, this.__chain__);
8327 return this.thru(reverse);
8331 * Executes the chain sequence to resolve the unwrapped value.
8336 * @alias toJSON, valueOf
8338 * @returns {*} Returns the resolved unwrapped value.
8341 * _([1, 2, 3]).value();
8344 function wrapperValue() {
8345 return baseWrapperValue(this.__wrapped__, this.__actions__);
8348 /*------------------------------------------------------------------------*/
8351 * Creates an object composed of keys generated from the results of running
8352 * each element of `collection` thru `iteratee`. The corresponding value of
8353 * each key is the number of times the key was returned by `iteratee`. The
8354 * iteratee is invoked with one argument: (value).
8359 * @category Collection
8360 * @param {Array|Object} collection The collection to iterate over.
8361 * @param {Array|Function|Object|string} [iteratee=_.identity]
8362 * The iteratee to transform keys.
8363 * @returns {Object} Returns the composed aggregate object.
8366 * _.countBy([6.1, 4.2, 6.3], Math.floor);
8367 * // => { '4': 1, '6': 2 }
8369 * // The `_.property` iteratee shorthand.
8370 * _.countBy(['one', 'two', 'three'], 'length');
8371 * // => { '3': 2, '5': 1 }
8373 var countBy = createAggregator(function(result, value, key) {
8374 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
8378 * Checks if `predicate` returns truthy for **all** elements of `collection`.
8379 * Iteration is stopped once `predicate` returns falsey. The predicate is
8380 * invoked with three arguments: (value, index|key, collection).
8385 * @category Collection
8386 * @param {Array|Object} collection The collection to iterate over.
8387 * @param {Array|Function|Object|string} [predicate=_.identity]
8388 * The function invoked per iteration.
8389 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8390 * @returns {boolean} Returns `true` if all elements pass the predicate check,
8394 * _.every([true, 1, null, 'yes'], Boolean);
8398 * { 'user': 'barney', 'age': 36, 'active': false },
8399 * { 'user': 'fred', 'age': 40, 'active': false }
8402 * // The `_.matches` iteratee shorthand.
8403 * _.every(users, { 'user': 'barney', 'active': false });
8406 * // The `_.matchesProperty` iteratee shorthand.
8407 * _.every(users, ['active', false]);
8410 * // The `_.property` iteratee shorthand.
8411 * _.every(users, 'active');
8414 function every(collection, predicate, guard) {
8415 var func = isArray(collection) ? arrayEvery : baseEvery;
8416 if (guard && isIterateeCall(collection, predicate, guard)) {
8417 predicate = undefined;
8419 return func(collection, getIteratee(predicate, 3));
8423 * Iterates over elements of `collection`, returning an array of all elements
8424 * `predicate` returns truthy for. The predicate is invoked with three
8425 * arguments: (value, index|key, collection).
8430 * @category Collection
8431 * @param {Array|Object} collection The collection to iterate over.
8432 * @param {Array|Function|Object|string} [predicate=_.identity]
8433 * The function invoked per iteration.
8434 * @returns {Array} Returns the new filtered array.
8439 * { 'user': 'barney', 'age': 36, 'active': true },
8440 * { 'user': 'fred', 'age': 40, 'active': false }
8443 * _.filter(users, function(o) { return !o.active; });
8444 * // => objects for ['fred']
8446 * // The `_.matches` iteratee shorthand.
8447 * _.filter(users, { 'age': 36, 'active': true });
8448 * // => objects for ['barney']
8450 * // The `_.matchesProperty` iteratee shorthand.
8451 * _.filter(users, ['active', false]);
8452 * // => objects for ['fred']
8454 * // The `_.property` iteratee shorthand.
8455 * _.filter(users, 'active');
8456 * // => objects for ['barney']
8458 function filter(collection, predicate) {
8459 var func = isArray(collection) ? arrayFilter : baseFilter;
8460 return func(collection, getIteratee(predicate, 3));
8464 * Iterates over elements of `collection`, returning the first element
8465 * `predicate` returns truthy for. The predicate is invoked with three
8466 * arguments: (value, index|key, collection).
8471 * @category Collection
8472 * @param {Array|Object} collection The collection to search.
8473 * @param {Array|Function|Object|string} [predicate=_.identity]
8474 * The function invoked per iteration.
8475 * @param {number} [fromIndex=0] The index to search from.
8476 * @returns {*} Returns the matched element, else `undefined`.
8480 * { 'user': 'barney', 'age': 36, 'active': true },
8481 * { 'user': 'fred', 'age': 40, 'active': false },
8482 * { 'user': 'pebbles', 'age': 1, 'active': true }
8485 * _.find(users, function(o) { return o.age < 40; });
8486 * // => object for 'barney'
8488 * // The `_.matches` iteratee shorthand.
8489 * _.find(users, { 'age': 1, 'active': true });
8490 * // => object for 'pebbles'
8492 * // The `_.matchesProperty` iteratee shorthand.
8493 * _.find(users, ['active', false]);
8494 * // => object for 'fred'
8496 * // The `_.property` iteratee shorthand.
8497 * _.find(users, 'active');
8498 * // => object for 'barney'
8500 var find = createFind(findIndex);
8503 * This method is like `_.find` except that it iterates over elements of
8504 * `collection` from right to left.
8509 * @category Collection
8510 * @param {Array|Object} collection The collection to search.
8511 * @param {Array|Function|Object|string} [predicate=_.identity]
8512 * The function invoked per iteration.
8513 * @param {number} [fromIndex=collection.length-1] The index to search from.
8514 * @returns {*} Returns the matched element, else `undefined`.
8517 * _.findLast([1, 2, 3, 4], function(n) {
8518 * return n % 2 == 1;
8522 var findLast = createFind(findLastIndex);
8525 * Creates a flattened array of values by running each element in `collection`
8526 * thru `iteratee` and flattening the mapped results. The iteratee is invoked
8527 * with three arguments: (value, index|key, collection).
8532 * @category Collection
8533 * @param {Array|Object} collection The collection to iterate over.
8534 * @param {Array|Function|Object|string} [iteratee=_.identity]
8535 * The function invoked per iteration.
8536 * @returns {Array} Returns the new flattened array.
8539 * function duplicate(n) {
8543 * _.flatMap([1, 2], duplicate);
8544 * // => [1, 1, 2, 2]
8546 function flatMap(collection, iteratee) {
8547 return baseFlatten(map(collection, iteratee), 1);
8551 * This method is like `_.flatMap` except that it recursively flattens the
8557 * @category Collection
8558 * @param {Array|Object} collection The collection to iterate over.
8559 * @param {Array|Function|Object|string} [iteratee=_.identity]
8560 * The function invoked per iteration.
8561 * @returns {Array} Returns the new flattened array.
8564 * function duplicate(n) {
8565 * return [[[n, n]]];
8568 * _.flatMapDeep([1, 2], duplicate);
8569 * // => [1, 1, 2, 2]
8571 function flatMapDeep(collection, iteratee) {
8572 return baseFlatten(map(collection, iteratee), INFINITY);
8576 * This method is like `_.flatMap` except that it recursively flattens the
8577 * mapped results up to `depth` times.
8582 * @category Collection
8583 * @param {Array|Object} collection The collection to iterate over.
8584 * @param {Array|Function|Object|string} [iteratee=_.identity]
8585 * The function invoked per iteration.
8586 * @param {number} [depth=1] The maximum recursion depth.
8587 * @returns {Array} Returns the new flattened array.
8590 * function duplicate(n) {
8591 * return [[[n, n]]];
8594 * _.flatMapDepth([1, 2], duplicate, 2);
8595 * // => [[1, 1], [2, 2]]
8597 function flatMapDepth(collection, iteratee, depth) {
8598 depth = depth === undefined ? 1 : toInteger(depth);
8599 return baseFlatten(map(collection, iteratee), depth);
8603 * Iterates over elements of `collection` and invokes `iteratee` for each element.
8604 * The iteratee is invoked with three arguments: (value, index|key, collection).
8605 * Iteratee functions may exit iteration early by explicitly returning `false`.
8607 * **Note:** As with other "Collections" methods, objects with a "length"
8608 * property are iterated like arrays. To avoid this behavior use `_.forIn`
8609 * or `_.forOwn` for object iteration.
8615 * @category Collection
8616 * @param {Array|Object} collection The collection to iterate over.
8617 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8618 * @returns {Array|Object} Returns `collection`.
8619 * @see _.forEachRight
8622 * _([1, 2]).forEach(function(value) {
8623 * console.log(value);
8625 * // => Logs `1` then `2`.
8627 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
8630 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
8632 function forEach(collection, iteratee) {
8633 var func = isArray(collection) ? arrayEach : baseEach;
8634 return func(collection, getIteratee(iteratee, 3));
8638 * This method is like `_.forEach` except that it iterates over elements of
8639 * `collection` from right to left.
8645 * @category Collection
8646 * @param {Array|Object} collection The collection to iterate over.
8647 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8648 * @returns {Array|Object} Returns `collection`.
8652 * _.forEachRight([1, 2], function(value) {
8653 * console.log(value);
8655 * // => Logs `2` then `1`.
8657 function forEachRight(collection, iteratee) {
8658 var func = isArray(collection) ? arrayEachRight : baseEachRight;
8659 return func(collection, getIteratee(iteratee, 3));
8663 * Creates an object composed of keys generated from the results of running
8664 * each element of `collection` thru `iteratee`. The order of grouped values
8665 * is determined by the order they occur in `collection`. The corresponding
8666 * value of each key is an array of elements responsible for generating the
8667 * key. The iteratee is invoked with one argument: (value).
8672 * @category Collection
8673 * @param {Array|Object} collection The collection to iterate over.
8674 * @param {Array|Function|Object|string} [iteratee=_.identity]
8675 * The iteratee to transform keys.
8676 * @returns {Object} Returns the composed aggregate object.
8679 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
8680 * // => { '4': [4.2], '6': [6.1, 6.3] }
8682 * // The `_.property` iteratee shorthand.
8683 * _.groupBy(['one', 'two', 'three'], 'length');
8684 * // => { '3': ['one', 'two'], '5': ['three'] }
8686 var groupBy = createAggregator(function(result, value, key) {
8687 if (hasOwnProperty.call(result, key)) {
8688 result[key].push(value);
8690 result[key] = [value];
8695 * Checks if `value` is in `collection`. If `collection` is a string, it's
8696 * checked for a substring of `value`, otherwise
8697 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
8698 * is used for equality comparisons. If `fromIndex` is negative, it's used as
8699 * the offset from the end of `collection`.
8704 * @category Collection
8705 * @param {Array|Object|string} collection The collection to search.
8706 * @param {*} value The value to search for.
8707 * @param {number} [fromIndex=0] The index to search from.
8708 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
8709 * @returns {boolean} Returns `true` if `value` is found, else `false`.
8712 * _.includes([1, 2, 3], 1);
8715 * _.includes([1, 2, 3], 1, 2);
8718 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
8721 * _.includes('pebbles', 'eb');
8724 function includes(collection, value, fromIndex, guard) {
8725 collection = isArrayLike(collection) ? collection : values(collection);
8726 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
8728 var length = collection.length;
8729 if (fromIndex < 0) {
8730 fromIndex = nativeMax(length + fromIndex, 0);
8732 return isString(collection)
8733 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
8734 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
8738 * Invokes the method at `path` of each element in `collection`, returning
8739 * an array of the results of each invoked method. Any additional arguments
8740 * are provided to each invoked method. If `methodName` is a function, it's
8741 * invoked for and `this` bound to, each element in `collection`.
8746 * @category Collection
8747 * @param {Array|Object} collection The collection to iterate over.
8748 * @param {Array|Function|string} path The path of the method to invoke or
8749 * the function invoked per iteration.
8750 * @param {...*} [args] The arguments to invoke each method with.
8751 * @returns {Array} Returns the array of results.
8754 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
8755 * // => [[1, 5, 7], [1, 2, 3]]
8757 * _.invokeMap([123, 456], String.prototype.split, '');
8758 * // => [['1', '2', '3'], ['4', '5', '6']]
8760 var invokeMap = rest(function(collection, path, args) {
8762 isFunc = typeof path == 'function',
8763 isProp = isKey(path),
8764 result = isArrayLike(collection) ? Array(collection.length) : [];
8766 baseEach(collection, function(value) {
8767 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
8768 result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
8774 * Creates an object composed of keys generated from the results of running
8775 * each element of `collection` thru `iteratee`. The corresponding value of
8776 * each key is the last element responsible for generating the key. The
8777 * iteratee is invoked with one argument: (value).
8782 * @category Collection
8783 * @param {Array|Object} collection The collection to iterate over.
8784 * @param {Array|Function|Object|string} [iteratee=_.identity]
8785 * The iteratee to transform keys.
8786 * @returns {Object} Returns the composed aggregate object.
8790 * { 'dir': 'left', 'code': 97 },
8791 * { 'dir': 'right', 'code': 100 }
8794 * _.keyBy(array, function(o) {
8795 * return String.fromCharCode(o.code);
8797 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
8799 * _.keyBy(array, 'dir');
8800 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
8802 var keyBy = createAggregator(function(result, value, key) {
8803 result[key] = value;
8807 * Creates an array of values by running each element in `collection` thru
8808 * `iteratee`. The iteratee is invoked with three arguments:
8809 * (value, index|key, collection).
8811 * Many lodash methods are guarded to work as iteratees for methods like
8812 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
8814 * The guarded methods are:
8815 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
8816 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
8817 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
8818 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
8823 * @category Collection
8824 * @param {Array|Object} collection The collection to iterate over.
8825 * @param {Array|Function|Object|string} [iteratee=_.identity]
8826 * The function invoked per iteration.
8827 * @returns {Array} Returns the new mapped array.
8830 * function square(n) {
8834 * _.map([4, 8], square);
8837 * _.map({ 'a': 4, 'b': 8 }, square);
8838 * // => [16, 64] (iteration order is not guaranteed)
8841 * { 'user': 'barney' },
8842 * { 'user': 'fred' }
8845 * // The `_.property` iteratee shorthand.
8846 * _.map(users, 'user');
8847 * // => ['barney', 'fred']
8849 function map(collection, iteratee) {
8850 var func = isArray(collection) ? arrayMap : baseMap;
8851 return func(collection, getIteratee(iteratee, 3));
8855 * This method is like `_.sortBy` except that it allows specifying the sort
8856 * orders of the iteratees to sort by. If `orders` is unspecified, all values
8857 * are sorted in ascending order. Otherwise, specify an order of "desc" for
8858 * descending or "asc" for ascending sort order of corresponding values.
8863 * @category Collection
8864 * @param {Array|Object} collection The collection to iterate over.
8865 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
8866 * The iteratees to sort by.
8867 * @param {string[]} [orders] The sort orders of `iteratees`.
8868 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
8869 * @returns {Array} Returns the new sorted array.
8873 * { 'user': 'fred', 'age': 48 },
8874 * { 'user': 'barney', 'age': 34 },
8875 * { 'user': 'fred', 'age': 40 },
8876 * { 'user': 'barney', 'age': 36 }
8879 * // Sort by `user` in ascending order and by `age` in descending order.
8880 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
8881 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
8883 function orderBy(collection, iteratees, orders, guard) {
8884 if (collection == null) {
8887 if (!isArray(iteratees)) {
8888 iteratees = iteratees == null ? [] : [iteratees];
8890 orders = guard ? undefined : orders;
8891 if (!isArray(orders)) {
8892 orders = orders == null ? [] : [orders];
8894 return baseOrderBy(collection, iteratees, orders);
8898 * Creates an array of elements split into two groups, the first of which
8899 * contains elements `predicate` returns truthy for, the second of which
8900 * contains elements `predicate` returns falsey for. The predicate is
8901 * invoked with one argument: (value).
8906 * @category Collection
8907 * @param {Array|Object} collection The collection to iterate over.
8908 * @param {Array|Function|Object|string} [predicate=_.identity]
8909 * The function invoked per iteration.
8910 * @returns {Array} Returns the array of grouped elements.
8914 * { 'user': 'barney', 'age': 36, 'active': false },
8915 * { 'user': 'fred', 'age': 40, 'active': true },
8916 * { 'user': 'pebbles', 'age': 1, 'active': false }
8919 * _.partition(users, function(o) { return o.active; });
8920 * // => objects for [['fred'], ['barney', 'pebbles']]
8922 * // The `_.matches` iteratee shorthand.
8923 * _.partition(users, { 'age': 1, 'active': false });
8924 * // => objects for [['pebbles'], ['barney', 'fred']]
8926 * // The `_.matchesProperty` iteratee shorthand.
8927 * _.partition(users, ['active', false]);
8928 * // => objects for [['barney', 'pebbles'], ['fred']]
8930 * // The `_.property` iteratee shorthand.
8931 * _.partition(users, 'active');
8932 * // => objects for [['fred'], ['barney', 'pebbles']]
8934 var partition = createAggregator(function(result, value, key) {
8935 result[key ? 0 : 1].push(value);
8936 }, function() { return [[], []]; });
8939 * Reduces `collection` to a value which is the accumulated result of running
8940 * each element in `collection` thru `iteratee`, where each successive
8941 * invocation is supplied the return value of the previous. If `accumulator`
8942 * is not given, the first element of `collection` is used as the initial
8943 * value. The iteratee is invoked with four arguments:
8944 * (accumulator, value, index|key, collection).
8946 * Many lodash methods are guarded to work as iteratees for methods like
8947 * `_.reduce`, `_.reduceRight`, and `_.transform`.
8949 * The guarded methods are:
8950 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
8956 * @category Collection
8957 * @param {Array|Object} collection The collection to iterate over.
8958 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8959 * @param {*} [accumulator] The initial value.
8960 * @returns {*} Returns the accumulated value.
8961 * @see _.reduceRight
8964 * _.reduce([1, 2], function(sum, n) {
8969 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
8970 * (result[value] || (result[value] = [])).push(key);
8973 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
8975 function reduce(collection, iteratee, accumulator) {
8976 var func = isArray(collection) ? arrayReduce : baseReduce,
8977 initAccum = arguments.length < 3;
8979 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
8983 * This method is like `_.reduce` except that it iterates over elements of
8984 * `collection` from right to left.
8989 * @category Collection
8990 * @param {Array|Object} collection The collection to iterate over.
8991 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8992 * @param {*} [accumulator] The initial value.
8993 * @returns {*} Returns the accumulated value.
8997 * var array = [[0, 1], [2, 3], [4, 5]];
8999 * _.reduceRight(array, function(flattened, other) {
9000 * return flattened.concat(other);
9002 * // => [4, 5, 2, 3, 0, 1]
9004 function reduceRight(collection, iteratee, accumulator) {
9005 var func = isArray(collection) ? arrayReduceRight : baseReduce,
9006 initAccum = arguments.length < 3;
9008 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
9012 * The opposite of `_.filter`; this method returns the elements of `collection`
9013 * that `predicate` does **not** return truthy for.
9018 * @category Collection
9019 * @param {Array|Object} collection The collection to iterate over.
9020 * @param {Array|Function|Object|string} [predicate=_.identity]
9021 * The function invoked per iteration.
9022 * @returns {Array} Returns the new filtered array.
9027 * { 'user': 'barney', 'age': 36, 'active': false },
9028 * { 'user': 'fred', 'age': 40, 'active': true }
9031 * _.reject(users, function(o) { return !o.active; });
9032 * // => objects for ['fred']
9034 * // The `_.matches` iteratee shorthand.
9035 * _.reject(users, { 'age': 40, 'active': true });
9036 * // => objects for ['barney']
9038 * // The `_.matchesProperty` iteratee shorthand.
9039 * _.reject(users, ['active', false]);
9040 * // => objects for ['fred']
9042 * // The `_.property` iteratee shorthand.
9043 * _.reject(users, 'active');
9044 * // => objects for ['barney']
9046 function reject(collection, predicate) {
9047 var func = isArray(collection) ? arrayFilter : baseFilter;
9048 predicate = getIteratee(predicate, 3);
9049 return func(collection, function(value, index, collection) {
9050 return !predicate(value, index, collection);
9055 * Gets a random element from `collection`.
9060 * @category Collection
9061 * @param {Array|Object} collection The collection to sample.
9062 * @returns {*} Returns the random element.
9065 * _.sample([1, 2, 3, 4]);
9068 function sample(collection) {
9069 var array = isArrayLike(collection) ? collection : values(collection),
9070 length = array.length;
9072 return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
9076 * Gets `n` random elements at unique keys from `collection` up to the
9077 * size of `collection`.
9082 * @category Collection
9083 * @param {Array|Object} collection The collection to sample.
9084 * @param {number} [n=1] The number of elements to sample.
9085 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9086 * @returns {Array} Returns the random elements.
9089 * _.sampleSize([1, 2, 3], 2);
9092 * _.sampleSize([1, 2, 3], 4);
9095 function sampleSize(collection, n, guard) {
9097 result = toArray(collection),
9098 length = result.length,
9099 lastIndex = length - 1;
9101 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
9104 n = baseClamp(toInteger(n), 0, length);
9106 while (++index < n) {
9107 var rand = baseRandom(index, lastIndex),
9108 value = result[rand];
9110 result[rand] = result[index];
9111 result[index] = value;
9118 * Creates an array of shuffled values, using a version of the
9119 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
9124 * @category Collection
9125 * @param {Array|Object} collection The collection to shuffle.
9126 * @returns {Array} Returns the new shuffled array.
9129 * _.shuffle([1, 2, 3, 4]);
9130 * // => [4, 1, 3, 2]
9132 function shuffle(collection) {
9133 return sampleSize(collection, MAX_ARRAY_LENGTH);
9137 * Gets the size of `collection` by returning its length for array-like
9138 * values or the number of own enumerable string keyed properties for objects.
9143 * @category Collection
9144 * @param {Array|Object} collection The collection to inspect.
9145 * @returns {number} Returns the collection size.
9148 * _.size([1, 2, 3]);
9151 * _.size({ 'a': 1, 'b': 2 });
9154 * _.size('pebbles');
9157 function size(collection) {
9158 if (collection == null) {
9161 if (isArrayLike(collection)) {
9162 var result = collection.length;
9163 return (result && isString(collection)) ? stringSize(collection) : result;
9165 if (isObjectLike(collection)) {
9166 var tag = getTag(collection);
9167 if (tag == mapTag || tag == setTag) {
9168 return collection.size;
9171 return keys(collection).length;
9175 * Checks if `predicate` returns truthy for **any** element of `collection`.
9176 * Iteration is stopped once `predicate` returns truthy. The predicate is
9177 * invoked with three arguments: (value, index|key, collection).
9182 * @category Collection
9183 * @param {Array|Object} collection The collection to iterate over.
9184 * @param {Array|Function|Object|string} [predicate=_.identity]
9185 * The function invoked per iteration.
9186 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9187 * @returns {boolean} Returns `true` if any element passes the predicate check,
9191 * _.some([null, 0, 'yes', false], Boolean);
9195 * { 'user': 'barney', 'active': true },
9196 * { 'user': 'fred', 'active': false }
9199 * // The `_.matches` iteratee shorthand.
9200 * _.some(users, { 'user': 'barney', 'active': false });
9203 * // The `_.matchesProperty` iteratee shorthand.
9204 * _.some(users, ['active', false]);
9207 * // The `_.property` iteratee shorthand.
9208 * _.some(users, 'active');
9211 function some(collection, predicate, guard) {
9212 var func = isArray(collection) ? arraySome : baseSome;
9213 if (guard && isIterateeCall(collection, predicate, guard)) {
9214 predicate = undefined;
9216 return func(collection, getIteratee(predicate, 3));
9220 * Creates an array of elements, sorted in ascending order by the results of
9221 * running each element in a collection thru each iteratee. This method
9222 * performs a stable sort, that is, it preserves the original sort order of
9223 * equal elements. The iteratees are invoked with one argument: (value).
9228 * @category Collection
9229 * @param {Array|Object} collection The collection to iterate over.
9230 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
9231 * [iteratees=[_.identity]] The iteratees to sort by.
9232 * @returns {Array} Returns the new sorted array.
9236 * { 'user': 'fred', 'age': 48 },
9237 * { 'user': 'barney', 'age': 36 },
9238 * { 'user': 'fred', 'age': 40 },
9239 * { 'user': 'barney', 'age': 34 }
9242 * _.sortBy(users, function(o) { return o.user; });
9243 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9245 * _.sortBy(users, ['user', 'age']);
9246 * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
9248 * _.sortBy(users, 'user', function(o) {
9249 * return Math.floor(o.age / 10);
9251 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9253 var sortBy = rest(function(collection, iteratees) {
9254 if (collection == null) {
9257 var length = iteratees.length;
9258 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
9260 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
9261 iteratees = [iteratees[0]];
9263 iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
9265 : baseFlatten(iteratees, 1, isFlattenableIteratee);
9267 return baseOrderBy(collection, iteratees, []);
9270 /*------------------------------------------------------------------------*/
9273 * Gets the timestamp of the number of milliseconds that have elapsed since
9274 * the Unix epoch (1 January 1970 00:00:00 UTC).
9280 * @returns {number} Returns the timestamp.
9283 * _.defer(function(stamp) {
9284 * console.log(_.now() - stamp);
9286 * // => Logs the number of milliseconds it took for the deferred invocation.
9292 /*------------------------------------------------------------------------*/
9295 * The opposite of `_.before`; this method creates a function that invokes
9296 * `func` once it's called `n` or more times.
9301 * @category Function
9302 * @param {number} n The number of calls before `func` is invoked.
9303 * @param {Function} func The function to restrict.
9304 * @returns {Function} Returns the new restricted function.
9307 * var saves = ['profile', 'settings'];
9309 * var done = _.after(saves.length, function() {
9310 * console.log('done saving!');
9313 * _.forEach(saves, function(type) {
9314 * asyncSave({ 'type': type, 'complete': done });
9316 * // => Logs 'done saving!' after the two async saves have completed.
9318 function after(n, func) {
9319 if (typeof func != 'function') {
9320 throw new TypeError(FUNC_ERROR_TEXT);
9325 return func.apply(this, arguments);
9331 * Creates a function that invokes `func`, with up to `n` arguments,
9332 * ignoring any additional arguments.
9337 * @category Function
9338 * @param {Function} func The function to cap arguments for.
9339 * @param {number} [n=func.length] The arity cap.
9340 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9341 * @returns {Function} Returns the new capped function.
9344 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
9347 function ary(func, n, guard) {
9348 n = guard ? undefined : n;
9349 n = (func && n == null) ? func.length : n;
9350 return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
9354 * Creates a function that invokes `func`, with the `this` binding and arguments
9355 * of the created function, while it's called less than `n` times. Subsequent
9356 * calls to the created function return the result of the last `func` invocation.
9361 * @category Function
9362 * @param {number} n The number of calls at which `func` is no longer invoked.
9363 * @param {Function} func The function to restrict.
9364 * @returns {Function} Returns the new restricted function.
9367 * jQuery(element).on('click', _.before(5, addContactToList));
9368 * // => allows adding up to 4 contacts to the list
9370 function before(n, func) {
9372 if (typeof func != 'function') {
9373 throw new TypeError(FUNC_ERROR_TEXT);
9378 result = func.apply(this, arguments);
9388 * Creates a function that invokes `func` with the `this` binding of `thisArg`
9389 * and `partials` prepended to the arguments it receives.
9391 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
9392 * may be used as a placeholder for partially applied arguments.
9394 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
9395 * property of bound functions.
9400 * @category Function
9401 * @param {Function} func The function to bind.
9402 * @param {*} thisArg The `this` binding of `func`.
9403 * @param {...*} [partials] The arguments to be partially applied.
9404 * @returns {Function} Returns the new bound function.
9407 * var greet = function(greeting, punctuation) {
9408 * return greeting + ' ' + this.user + punctuation;
9411 * var object = { 'user': 'fred' };
9413 * var bound = _.bind(greet, object, 'hi');
9417 * // Bound with placeholders.
9418 * var bound = _.bind(greet, object, _, '!');
9422 var bind = rest(function(func, thisArg, partials) {
9423 var bitmask = BIND_FLAG;
9424 if (partials.length) {
9425 var holders = replaceHolders(partials, getHolder(bind));
9426 bitmask |= PARTIAL_FLAG;
9428 return createWrapper(func, bitmask, thisArg, partials, holders);
9432 * Creates a function that invokes the method at `object[key]` with `partials`
9433 * prepended to the arguments it receives.
9435 * This method differs from `_.bind` by allowing bound functions to reference
9436 * methods that may be redefined or don't yet exist. See
9437 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
9440 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
9441 * builds, may be used as a placeholder for partially applied arguments.
9446 * @category Function
9447 * @param {Object} object The object to invoke the method on.
9448 * @param {string} key The key of the method.
9449 * @param {...*} [partials] The arguments to be partially applied.
9450 * @returns {Function} Returns the new bound function.
9455 * 'greet': function(greeting, punctuation) {
9456 * return greeting + ' ' + this.user + punctuation;
9460 * var bound = _.bindKey(object, 'greet', 'hi');
9464 * object.greet = function(greeting, punctuation) {
9465 * return greeting + 'ya ' + this.user + punctuation;
9469 * // => 'hiya fred!'
9471 * // Bound with placeholders.
9472 * var bound = _.bindKey(object, 'greet', _, '!');
9474 * // => 'hiya fred!'
9476 var bindKey = rest(function(object, key, partials) {
9477 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
9478 if (partials.length) {
9479 var holders = replaceHolders(partials, getHolder(bindKey));
9480 bitmask |= PARTIAL_FLAG;
9482 return createWrapper(key, bitmask, object, partials, holders);
9486 * Creates a function that accepts arguments of `func` and either invokes
9487 * `func` returning its result, if at least `arity` number of arguments have
9488 * been provided, or returns a function that accepts the remaining `func`
9489 * arguments, and so on. The arity of `func` may be specified if `func.length`
9490 * is not sufficient.
9492 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
9493 * may be used as a placeholder for provided arguments.
9495 * **Note:** This method doesn't set the "length" property of curried functions.
9500 * @category Function
9501 * @param {Function} func The function to curry.
9502 * @param {number} [arity=func.length] The arity of `func`.
9503 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9504 * @returns {Function} Returns the new curried function.
9507 * var abc = function(a, b, c) {
9511 * var curried = _.curry(abc);
9522 * // Curried with placeholders.
9523 * curried(1)(_, 3)(2);
9526 function curry(func, arity, guard) {
9527 arity = guard ? undefined : arity;
9528 var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
9529 result.placeholder = curry.placeholder;
9534 * This method is like `_.curry` except that arguments are applied to `func`
9535 * in the manner of `_.partialRight` instead of `_.partial`.
9537 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
9538 * builds, may be used as a placeholder for provided arguments.
9540 * **Note:** This method doesn't set the "length" property of curried functions.
9545 * @category Function
9546 * @param {Function} func The function to curry.
9547 * @param {number} [arity=func.length] The arity of `func`.
9548 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9549 * @returns {Function} Returns the new curried function.
9552 * var abc = function(a, b, c) {
9556 * var curried = _.curryRight(abc);
9567 * // Curried with placeholders.
9568 * curried(3)(1, _)(2);
9571 function curryRight(func, arity, guard) {
9572 arity = guard ? undefined : arity;
9573 var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
9574 result.placeholder = curryRight.placeholder;
9579 * Creates a debounced function that delays invoking `func` until after `wait`
9580 * milliseconds have elapsed since the last time the debounced function was
9581 * invoked. The debounced function comes with a `cancel` method to cancel
9582 * delayed `func` invocations and a `flush` method to immediately invoke them.
9583 * Provide an options object to indicate whether `func` should be invoked on
9584 * the leading and/or trailing edge of the `wait` timeout. The `func` is invoked
9585 * with the last arguments provided to the debounced function. Subsequent calls
9586 * to the debounced function return the result of the last `func` invocation.
9588 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
9589 * on the trailing edge of the timeout only if the debounced function is
9590 * invoked more than once during the `wait` timeout.
9592 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
9593 * for details over the differences between `_.debounce` and `_.throttle`.
9598 * @category Function
9599 * @param {Function} func The function to debounce.
9600 * @param {number} [wait=0] The number of milliseconds to delay.
9601 * @param {Object} [options={}] The options object.
9602 * @param {boolean} [options.leading=false]
9603 * Specify invoking on the leading edge of the timeout.
9604 * @param {number} [options.maxWait]
9605 * The maximum time `func` is allowed to be delayed before it's invoked.
9606 * @param {boolean} [options.trailing=true]
9607 * Specify invoking on the trailing edge of the timeout.
9608 * @returns {Function} Returns the new debounced function.
9611 * // Avoid costly calculations while the window size is in flux.
9612 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
9614 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
9615 * jQuery(element).on('click', _.debounce(sendMail, 300, {
9620 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
9621 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
9622 * var source = new EventSource('/stream');
9623 * jQuery(source).on('message', debounced);
9625 * // Cancel the trailing debounced invocation.
9626 * jQuery(window).on('popstate', debounced.cancel);
9628 function debounce(func, wait, options) {
9640 if (typeof func != 'function') {
9641 throw new TypeError(FUNC_ERROR_TEXT);
9643 wait = toNumber(wait) || 0;
9644 if (isObject(options)) {
9645 leading = !!options.leading;
9646 maxing = 'maxWait' in options;
9647 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
9648 trailing = 'trailing' in options ? !!options.trailing : trailing;
9651 function invokeFunc(time) {
9652 var args = lastArgs,
9655 lastArgs = lastThis = undefined;
9656 lastInvokeTime = time;
9657 result = func.apply(thisArg, args);
9661 function leadingEdge(time) {
9662 // Reset any `maxWait` timer.
9663 lastInvokeTime = time;
9664 // Start the timer for the trailing edge.
9665 timerId = setTimeout(timerExpired, wait);
9666 // Invoke the leading edge.
9667 return leading ? invokeFunc(time) : result;
9670 function remainingWait(time) {
9671 var timeSinceLastCall = time - lastCallTime,
9672 timeSinceLastInvoke = time - lastInvokeTime,
9673 result = wait - timeSinceLastCall;
9675 return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
9678 function shouldInvoke(time) {
9679 var timeSinceLastCall = time - lastCallTime,
9680 timeSinceLastInvoke = time - lastInvokeTime;
9682 // Either this is the first call, activity has stopped and we're at the
9683 // trailing edge, the system time has gone backwards and we're treating
9684 // it as the trailing edge, or we've hit the `maxWait` limit.
9685 return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
9686 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
9689 function timerExpired() {
9691 if (shouldInvoke(time)) {
9692 return trailingEdge(time);
9694 // Restart the timer.
9695 timerId = setTimeout(timerExpired, remainingWait(time));
9698 function trailingEdge(time) {
9699 timerId = undefined;
9701 // Only invoke if we have `lastArgs` which means `func` has been
9702 // debounced at least once.
9703 if (trailing && lastArgs) {
9704 return invokeFunc(time);
9706 lastArgs = lastThis = undefined;
9712 lastArgs = lastCallTime = lastThis = timerId = undefined;
9716 return timerId === undefined ? result : trailingEdge(now());
9719 function debounced() {
9721 isInvoking = shouldInvoke(time);
9723 lastArgs = arguments;
9725 lastCallTime = time;
9728 if (timerId === undefined) {
9729 return leadingEdge(lastCallTime);
9732 // Handle invocations in a tight loop.
9733 timerId = setTimeout(timerExpired, wait);
9734 return invokeFunc(lastCallTime);
9737 if (timerId === undefined) {
9738 timerId = setTimeout(timerExpired, wait);
9742 debounced.cancel = cancel;
9743 debounced.flush = flush;
9748 * Defers invoking the `func` until the current call stack has cleared. Any
9749 * additional arguments are provided to `func` when it's invoked.
9754 * @category Function
9755 * @param {Function} func The function to defer.
9756 * @param {...*} [args] The arguments to invoke `func` with.
9757 * @returns {number} Returns the timer id.
9760 * _.defer(function(text) {
9761 * console.log(text);
9763 * // => Logs 'deferred' after one or more milliseconds.
9765 var defer = rest(function(func, args) {
9766 return baseDelay(func, 1, args);
9770 * Invokes `func` after `wait` milliseconds. Any additional arguments are
9771 * provided to `func` when it's invoked.
9776 * @category Function
9777 * @param {Function} func The function to delay.
9778 * @param {number} wait The number of milliseconds to delay invocation.
9779 * @param {...*} [args] The arguments to invoke `func` with.
9780 * @returns {number} Returns the timer id.
9783 * _.delay(function(text) {
9784 * console.log(text);
9785 * }, 1000, 'later');
9786 * // => Logs 'later' after one second.
9788 var delay = rest(function(func, wait, args) {
9789 return baseDelay(func, toNumber(wait) || 0, args);
9793 * Creates a function that invokes `func` with arguments reversed.
9798 * @category Function
9799 * @param {Function} func The function to flip arguments for.
9800 * @returns {Function} Returns the new flipped function.
9803 * var flipped = _.flip(function() {
9804 * return _.toArray(arguments);
9807 * flipped('a', 'b', 'c', 'd');
9808 * // => ['d', 'c', 'b', 'a']
9810 function flip(func) {
9811 return createWrapper(func, FLIP_FLAG);
9815 * Creates a function that memoizes the result of `func`. If `resolver` is
9816 * provided, it determines the cache key for storing the result based on the
9817 * arguments provided to the memoized function. By default, the first argument
9818 * provided to the memoized function is used as the map cache key. The `func`
9819 * is invoked with the `this` binding of the memoized function.
9821 * **Note:** The cache is exposed as the `cache` property on the memoized
9822 * function. Its creation may be customized by replacing the `_.memoize.Cache`
9823 * constructor with one whose instances implement the
9824 * [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
9825 * method interface of `delete`, `get`, `has`, and `set`.
9830 * @category Function
9831 * @param {Function} func The function to have its output memoized.
9832 * @param {Function} [resolver] The function to resolve the cache key.
9833 * @returns {Function} Returns the new memoized function.
9836 * var object = { 'a': 1, 'b': 2 };
9837 * var other = { 'c': 3, 'd': 4 };
9839 * var values = _.memoize(_.values);
9850 * // Modify the result cache.
9851 * values.cache.set(object, ['a', 'b']);
9855 * // Replace `_.memoize.Cache`.
9856 * _.memoize.Cache = WeakMap;
9858 function memoize(func, resolver) {
9859 if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
9860 throw new TypeError(FUNC_ERROR_TEXT);
9862 var memoized = function() {
9863 var args = arguments,
9864 key = resolver ? resolver.apply(this, args) : args[0],
9865 cache = memoized.cache;
9867 if (cache.has(key)) {
9868 return cache.get(key);
9870 var result = func.apply(this, args);
9871 memoized.cache = cache.set(key, result);
9874 memoized.cache = new (memoize.Cache || MapCache);
9878 // Assign cache to `_.memoize`.
9879 memoize.Cache = MapCache;
9882 * Creates a function that negates the result of the predicate `func`. The
9883 * `func` predicate is invoked with the `this` binding and arguments of the
9889 * @category Function
9890 * @param {Function} predicate The predicate to negate.
9891 * @returns {Function} Returns the new negated function.
9894 * function isEven(n) {
9895 * return n % 2 == 0;
9898 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
9901 function negate(predicate) {
9902 if (typeof predicate != 'function') {
9903 throw new TypeError(FUNC_ERROR_TEXT);
9906 return !predicate.apply(this, arguments);
9911 * Creates a function that is restricted to invoking `func` once. Repeat calls
9912 * to the function return the value of the first invocation. The `func` is
9913 * invoked with the `this` binding and arguments of the created function.
9918 * @category Function
9919 * @param {Function} func The function to restrict.
9920 * @returns {Function} Returns the new restricted function.
9923 * var initialize = _.once(createApplication);
9926 * // `initialize` invokes `createApplication` once
9928 function once(func) {
9929 return before(2, func);
9933 * Creates a function that invokes `func` with arguments transformed by
9934 * corresponding `transforms`.
9939 * @category Function
9940 * @param {Function} func The function to wrap.
9941 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
9942 * [transforms[_.identity]] The functions to transform.
9943 * @returns {Function} Returns the new function.
9946 * function doubled(n) {
9950 * function square(n) {
9954 * var func = _.overArgs(function(x, y) {
9956 * }, [square, doubled]);
9964 var overArgs = rest(function(func, transforms) {
9965 transforms = (transforms.length == 1 && isArray(transforms[0]))
9966 ? arrayMap(transforms[0], baseUnary(getIteratee()))
9967 : arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseUnary(getIteratee()));
9969 var funcsLength = transforms.length;
9970 return rest(function(args) {
9972 length = nativeMin(args.length, funcsLength);
9974 while (++index < length) {
9975 args[index] = transforms[index].call(this, args[index]);
9977 return apply(func, this, args);
9982 * Creates a function that invokes `func` with `partials` prepended to the
9983 * arguments it receives. This method is like `_.bind` except it does **not**
9984 * alter the `this` binding.
9986 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
9987 * builds, may be used as a placeholder for partially applied arguments.
9989 * **Note:** This method doesn't set the "length" property of partially
9990 * applied functions.
9995 * @category Function
9996 * @param {Function} func The function to partially apply arguments to.
9997 * @param {...*} [partials] The arguments to be partially applied.
9998 * @returns {Function} Returns the new partially applied function.
10001 * var greet = function(greeting, name) {
10002 * return greeting + ' ' + name;
10005 * var sayHelloTo = _.partial(greet, 'hello');
10006 * sayHelloTo('fred');
10007 * // => 'hello fred'
10009 * // Partially applied with placeholders.
10010 * var greetFred = _.partial(greet, _, 'fred');
10014 var partial = rest(function(func, partials) {
10015 var holders = replaceHolders(partials, getHolder(partial));
10016 return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
10020 * This method is like `_.partial` except that partially applied arguments
10021 * are appended to the arguments it receives.
10023 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
10024 * builds, may be used as a placeholder for partially applied arguments.
10026 * **Note:** This method doesn't set the "length" property of partially
10027 * applied functions.
10032 * @category Function
10033 * @param {Function} func The function to partially apply arguments to.
10034 * @param {...*} [partials] The arguments to be partially applied.
10035 * @returns {Function} Returns the new partially applied function.
10038 * var greet = function(greeting, name) {
10039 * return greeting + ' ' + name;
10042 * var greetFred = _.partialRight(greet, 'fred');
10046 * // Partially applied with placeholders.
10047 * var sayHelloTo = _.partialRight(greet, 'hello', _);
10048 * sayHelloTo('fred');
10049 * // => 'hello fred'
10051 var partialRight = rest(function(func, partials) {
10052 var holders = replaceHolders(partials, getHolder(partialRight));
10053 return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
10057 * Creates a function that invokes `func` with arguments arranged according
10058 * to the specified `indexes` where the argument value at the first index is
10059 * provided as the first argument, the argument value at the second index is
10060 * provided as the second argument, and so on.
10065 * @category Function
10066 * @param {Function} func The function to rearrange arguments for.
10067 * @param {...(number|number[])} indexes The arranged argument indexes.
10068 * @returns {Function} Returns the new function.
10071 * var rearged = _.rearg(function(a, b, c) {
10072 * return [a, b, c];
10075 * rearged('b', 'c', 'a')
10076 * // => ['a', 'b', 'c']
10078 var rearg = rest(function(func, indexes) {
10079 return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
10083 * Creates a function that invokes `func` with the `this` binding of the
10084 * created function and arguments from `start` and beyond provided as
10087 * **Note:** This method is based on the
10088 * [rest parameter](https://mdn.io/rest_parameters).
10093 * @category Function
10094 * @param {Function} func The function to apply a rest parameter to.
10095 * @param {number} [start=func.length-1] The start position of the rest parameter.
10096 * @returns {Function} Returns the new function.
10099 * var say = _.rest(function(what, names) {
10100 * return what + ' ' + _.initial(names).join(', ') +
10101 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
10104 * say('hello', 'fred', 'barney', 'pebbles');
10105 * // => 'hello fred, barney, & pebbles'
10107 function rest(func, start) {
10108 if (typeof func != 'function') {
10109 throw new TypeError(FUNC_ERROR_TEXT);
10111 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
10112 return function() {
10113 var args = arguments,
10115 length = nativeMax(args.length - start, 0),
10116 array = Array(length);
10118 while (++index < length) {
10119 array[index] = args[start + index];
10122 case 0: return func.call(this, array);
10123 case 1: return func.call(this, args[0], array);
10124 case 2: return func.call(this, args[0], args[1], array);
10126 var otherArgs = Array(start + 1);
10128 while (++index < start) {
10129 otherArgs[index] = args[index];
10131 otherArgs[start] = array;
10132 return apply(func, this, otherArgs);
10137 * Creates a function that invokes `func` with the `this` binding of the
10138 * create function and an array of arguments much like
10139 * [`Function#apply`](http://www.ecma-international.org/ecma-262/6.0/#sec-function.prototype.apply).
10141 * **Note:** This method is based on the
10142 * [spread operator](https://mdn.io/spread_operator).
10147 * @category Function
10148 * @param {Function} func The function to spread arguments over.
10149 * @param {number} [start=0] The start position of the spread.
10150 * @returns {Function} Returns the new function.
10153 * var say = _.spread(function(who, what) {
10154 * return who + ' says ' + what;
10157 * say(['fred', 'hello']);
10158 * // => 'fred says hello'
10160 * var numbers = Promise.all([
10161 * Promise.resolve(40),
10162 * Promise.resolve(36)
10165 * numbers.then(_.spread(function(x, y) {
10168 * // => a Promise of 76
10170 function spread(func, start) {
10171 if (typeof func != 'function') {
10172 throw new TypeError(FUNC_ERROR_TEXT);
10174 start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
10175 return rest(function(args) {
10176 var array = args[start],
10177 otherArgs = castSlice(args, 0, start);
10180 arrayPush(otherArgs, array);
10182 return apply(func, this, otherArgs);
10187 * Creates a throttled function that only invokes `func` at most once per
10188 * every `wait` milliseconds. The throttled function comes with a `cancel`
10189 * method to cancel delayed `func` invocations and a `flush` method to
10190 * immediately invoke them. Provide an options object to indicate whether
10191 * `func` should be invoked on the leading and/or trailing edge of the `wait`
10192 * timeout. The `func` is invoked with the last arguments provided to the
10193 * throttled function. Subsequent calls to the throttled function return the
10194 * result of the last `func` invocation.
10196 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10197 * invoked on the trailing edge of the timeout only if the throttled function
10198 * is invoked more than once during the `wait` timeout.
10200 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10201 * for details over the differences between `_.throttle` and `_.debounce`.
10206 * @category Function
10207 * @param {Function} func The function to throttle.
10208 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
10209 * @param {Object} [options={}] The options object.
10210 * @param {boolean} [options.leading=true]
10211 * Specify invoking on the leading edge of the timeout.
10212 * @param {boolean} [options.trailing=true]
10213 * Specify invoking on the trailing edge of the timeout.
10214 * @returns {Function} Returns the new throttled function.
10217 * // Avoid excessively updating the position while scrolling.
10218 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
10220 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
10221 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
10222 * jQuery(element).on('click', throttled);
10224 * // Cancel the trailing throttled invocation.
10225 * jQuery(window).on('popstate', throttled.cancel);
10227 function throttle(func, wait, options) {
10228 var leading = true,
10231 if (typeof func != 'function') {
10232 throw new TypeError(FUNC_ERROR_TEXT);
10234 if (isObject(options)) {
10235 leading = 'leading' in options ? !!options.leading : leading;
10236 trailing = 'trailing' in options ? !!options.trailing : trailing;
10238 return debounce(func, wait, {
10239 'leading': leading,
10241 'trailing': trailing
10246 * Creates a function that accepts up to one argument, ignoring any
10247 * additional arguments.
10252 * @category Function
10253 * @param {Function} func The function to cap arguments for.
10254 * @returns {Function} Returns the new capped function.
10257 * _.map(['6', '8', '10'], _.unary(parseInt));
10260 function unary(func) {
10261 return ary(func, 1);
10265 * Creates a function that provides `value` to the wrapper function as its
10266 * first argument. Any additional arguments provided to the function are
10267 * appended to those provided to the wrapper function. The wrapper is invoked
10268 * with the `this` binding of the created function.
10273 * @category Function
10274 * @param {*} value The value to wrap.
10275 * @param {Function} [wrapper=identity] The wrapper function.
10276 * @returns {Function} Returns the new function.
10279 * var p = _.wrap(_.escape, function(func, text) {
10280 * return '<p>' + func(text) + '</p>';
10283 * p('fred, barney, & pebbles');
10284 * // => '<p>fred, barney, & pebbles</p>'
10286 function wrap(value, wrapper) {
10287 wrapper = wrapper == null ? identity : wrapper;
10288 return partial(wrapper, value);
10291 /*------------------------------------------------------------------------*/
10294 * Casts `value` as an array if it's not one.
10300 * @param {*} value The value to inspect.
10301 * @returns {Array} Returns the cast array.
10307 * _.castArray({ 'a': 1 });
10308 * // => [{ 'a': 1 }]
10310 * _.castArray('abc');
10313 * _.castArray(null);
10316 * _.castArray(undefined);
10317 * // => [undefined]
10322 * var array = [1, 2, 3];
10323 * console.log(_.castArray(array) === array);
10326 function castArray() {
10327 if (!arguments.length) {
10330 var value = arguments[0];
10331 return isArray(value) ? value : [value];
10335 * Creates a shallow clone of `value`.
10337 * **Note:** This method is loosely based on the
10338 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
10339 * and supports cloning arrays, array buffers, booleans, date objects, maps,
10340 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
10341 * arrays. The own enumerable properties of `arguments` objects are cloned
10342 * as plain objects. An empty object is returned for uncloneable values such
10343 * as error objects, functions, DOM nodes, and WeakMaps.
10349 * @param {*} value The value to clone.
10350 * @returns {*} Returns the cloned value.
10354 * var objects = [{ 'a': 1 }, { 'b': 2 }];
10356 * var shallow = _.clone(objects);
10357 * console.log(shallow[0] === objects[0]);
10360 function clone(value) {
10361 return baseClone(value, false, true);
10365 * This method is like `_.clone` except that it accepts `customizer` which
10366 * is invoked to produce the cloned value. If `customizer` returns `undefined`,
10367 * cloning is handled by the method instead. The `customizer` is invoked with
10368 * up to four arguments; (value [, index|key, object, stack]).
10374 * @param {*} value The value to clone.
10375 * @param {Function} [customizer] The function to customize cloning.
10376 * @returns {*} Returns the cloned value.
10377 * @see _.cloneDeepWith
10380 * function customizer(value) {
10381 * if (_.isElement(value)) {
10382 * return value.cloneNode(false);
10386 * var el = _.cloneWith(document.body, customizer);
10388 * console.log(el === document.body);
10390 * console.log(el.nodeName);
10392 * console.log(el.childNodes.length);
10395 function cloneWith(value, customizer) {
10396 return baseClone(value, false, true, customizer);
10400 * This method is like `_.clone` except that it recursively clones `value`.
10406 * @param {*} value The value to recursively clone.
10407 * @returns {*} Returns the deep cloned value.
10411 * var objects = [{ 'a': 1 }, { 'b': 2 }];
10413 * var deep = _.cloneDeep(objects);
10414 * console.log(deep[0] === objects[0]);
10417 function cloneDeep(value) {
10418 return baseClone(value, true, true);
10422 * This method is like `_.cloneWith` except that it recursively clones `value`.
10428 * @param {*} value The value to recursively clone.
10429 * @param {Function} [customizer] The function to customize cloning.
10430 * @returns {*} Returns the deep cloned value.
10434 * function customizer(value) {
10435 * if (_.isElement(value)) {
10436 * return value.cloneNode(true);
10440 * var el = _.cloneDeepWith(document.body, customizer);
10442 * console.log(el === document.body);
10444 * console.log(el.nodeName);
10446 * console.log(el.childNodes.length);
10449 function cloneDeepWith(value, customizer) {
10450 return baseClone(value, true, true, customizer);
10455 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
10456 * comparison between two values to determine if they are equivalent.
10462 * @param {*} value The value to compare.
10463 * @param {*} other The other value to compare.
10464 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
10467 * var object = { 'user': 'fred' };
10468 * var other = { 'user': 'fred' };
10470 * _.eq(object, object);
10473 * _.eq(object, other);
10479 * _.eq('a', Object('a'));
10485 function eq(value, other) {
10486 return value === other || (value !== value && other !== other);
10490 * Checks if `value` is greater than `other`.
10496 * @param {*} value The value to compare.
10497 * @param {*} other The other value to compare.
10498 * @returns {boolean} Returns `true` if `value` is greater than `other`,
10512 var gt = createRelationalOperation(baseGt);
10515 * Checks if `value` is greater than or equal to `other`.
10521 * @param {*} value The value to compare.
10522 * @param {*} other The other value to compare.
10523 * @returns {boolean} Returns `true` if `value` is greater than or equal to
10524 * `other`, else `false`.
10537 var gte = createRelationalOperation(function(value, other) {
10538 return value >= other;
10542 * Checks if `value` is likely an `arguments` object.
10548 * @param {*} value The value to check.
10549 * @returns {boolean} Returns `true` if `value` is correctly classified,
10553 * _.isArguments(function() { return arguments; }());
10556 * _.isArguments([1, 2, 3]);
10559 function isArguments(value) {
10560 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
10561 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
10562 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
10566 * Checks if `value` is classified as an `Array` object.
10573 * @param {*} value The value to check.
10574 * @returns {boolean} Returns `true` if `value` is correctly classified,
10578 * _.isArray([1, 2, 3]);
10581 * _.isArray(document.body.children);
10584 * _.isArray('abc');
10587 * _.isArray(_.noop);
10590 var isArray = Array.isArray;
10593 * Checks if `value` is classified as an `ArrayBuffer` object.
10599 * @param {*} value The value to check.
10600 * @returns {boolean} Returns `true` if `value` is correctly classified,
10604 * _.isArrayBuffer(new ArrayBuffer(2));
10607 * _.isArrayBuffer(new Array(2));
10610 function isArrayBuffer(value) {
10611 return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
10615 * Checks if `value` is array-like. A value is considered array-like if it's
10616 * not a function and has a `value.length` that's an integer greater than or
10617 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
10623 * @param {*} value The value to check.
10624 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
10627 * _.isArrayLike([1, 2, 3]);
10630 * _.isArrayLike(document.body.children);
10633 * _.isArrayLike('abc');
10636 * _.isArrayLike(_.noop);
10639 function isArrayLike(value) {
10640 return value != null && isLength(getLength(value)) && !isFunction(value);
10644 * This method is like `_.isArrayLike` except that it also checks if `value`
10651 * @param {*} value The value to check.
10652 * @returns {boolean} Returns `true` if `value` is an array-like object,
10656 * _.isArrayLikeObject([1, 2, 3]);
10659 * _.isArrayLikeObject(document.body.children);
10662 * _.isArrayLikeObject('abc');
10665 * _.isArrayLikeObject(_.noop);
10668 function isArrayLikeObject(value) {
10669 return isObjectLike(value) && isArrayLike(value);
10673 * Checks if `value` is classified as a boolean primitive or object.
10679 * @param {*} value The value to check.
10680 * @returns {boolean} Returns `true` if `value` is correctly classified,
10684 * _.isBoolean(false);
10687 * _.isBoolean(null);
10690 function isBoolean(value) {
10691 return value === true || value === false ||
10692 (isObjectLike(value) && objectToString.call(value) == boolTag);
10696 * Checks if `value` is a buffer.
10702 * @param {*} value The value to check.
10703 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
10706 * _.isBuffer(new Buffer(2));
10709 * _.isBuffer(new Uint8Array(2));
10712 var isBuffer = !Buffer ? stubFalse : function(value) {
10713 return value instanceof Buffer;
10717 * Checks if `value` is classified as a `Date` object.
10723 * @param {*} value The value to check.
10724 * @returns {boolean} Returns `true` if `value` is correctly classified,
10728 * _.isDate(new Date);
10731 * _.isDate('Mon April 23 2012');
10734 function isDate(value) {
10735 return isObjectLike(value) && objectToString.call(value) == dateTag;
10739 * Checks if `value` is likely a DOM element.
10745 * @param {*} value The value to check.
10746 * @returns {boolean} Returns `true` if `value` is a DOM element,
10750 * _.isElement(document.body);
10753 * _.isElement('<body>');
10756 function isElement(value) {
10757 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
10761 * Checks if `value` is an empty object, collection, map, or set.
10763 * Objects are considered empty if they have no own enumerable string keyed
10766 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
10767 * jQuery-like collections are considered empty if they have a `length` of `0`.
10768 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
10774 * @param {*} value The value to check.
10775 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
10787 * _.isEmpty([1, 2, 3]);
10790 * _.isEmpty({ 'a': 1 });
10793 function isEmpty(value) {
10794 if (isArrayLike(value) &&
10795 (isArray(value) || isString(value) || isFunction(value.splice) ||
10796 isArguments(value) || isBuffer(value))) {
10797 return !value.length;
10799 if (isObjectLike(value)) {
10800 var tag = getTag(value);
10801 if (tag == mapTag || tag == setTag) {
10802 return !value.size;
10805 for (var key in value) {
10806 if (hasOwnProperty.call(value, key)) {
10810 return !(nonEnumShadows && keys(value).length);
10814 * Performs a deep comparison between two values to determine if they are
10817 * **Note:** This method supports comparing arrays, array buffers, booleans,
10818 * date objects, error objects, maps, numbers, `Object` objects, regexes,
10819 * sets, strings, symbols, and typed arrays. `Object` objects are compared
10820 * by their own, not inherited, enumerable properties. Functions and DOM
10821 * nodes are **not** supported.
10827 * @param {*} value The value to compare.
10828 * @param {*} other The other value to compare.
10829 * @returns {boolean} Returns `true` if the values are equivalent,
10833 * var object = { 'user': 'fred' };
10834 * var other = { 'user': 'fred' };
10836 * _.isEqual(object, other);
10839 * object === other;
10842 function isEqual(value, other) {
10843 return baseIsEqual(value, other);
10847 * This method is like `_.isEqual` except that it accepts `customizer` which
10848 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
10849 * are handled by the method instead. The `customizer` is invoked with up to
10850 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
10856 * @param {*} value The value to compare.
10857 * @param {*} other The other value to compare.
10858 * @param {Function} [customizer] The function to customize comparisons.
10859 * @returns {boolean} Returns `true` if the values are equivalent,
10863 * function isGreeting(value) {
10864 * return /^h(?:i|ello)$/.test(value);
10867 * function customizer(objValue, othValue) {
10868 * if (isGreeting(objValue) && isGreeting(othValue)) {
10873 * var array = ['hello', 'goodbye'];
10874 * var other = ['hi', 'goodbye'];
10876 * _.isEqualWith(array, other, customizer);
10879 function isEqualWith(value, other, customizer) {
10880 customizer = typeof customizer == 'function' ? customizer : undefined;
10881 var result = customizer ? customizer(value, other) : undefined;
10882 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
10886 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
10887 * `SyntaxError`, `TypeError`, or `URIError` object.
10893 * @param {*} value The value to check.
10894 * @returns {boolean} Returns `true` if `value` is an error object,
10898 * _.isError(new Error);
10901 * _.isError(Error);
10904 function isError(value) {
10905 if (!isObjectLike(value)) {
10908 return (objectToString.call(value) == errorTag) ||
10909 (typeof value.message == 'string' && typeof value.name == 'string');
10913 * Checks if `value` is a finite primitive number.
10915 * **Note:** This method is based on
10916 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
10922 * @param {*} value The value to check.
10923 * @returns {boolean} Returns `true` if `value` is a finite number,
10930 * _.isFinite(Number.MIN_VALUE);
10933 * _.isFinite(Infinity);
10939 function isFinite(value) {
10940 return typeof value == 'number' && nativeIsFinite(value);
10944 * Checks if `value` is classified as a `Function` object.
10950 * @param {*} value The value to check.
10951 * @returns {boolean} Returns `true` if `value` is correctly classified,
10958 * _.isFunction(/abc/);
10961 function isFunction(value) {
10962 // The use of `Object#toString` avoids issues with the `typeof` operator
10963 // in Safari 8 which returns 'object' for typed array and weak map constructors,
10964 // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
10965 var tag = isObject(value) ? objectToString.call(value) : '';
10966 return tag == funcTag || tag == genTag;
10970 * Checks if `value` is an integer.
10972 * **Note:** This method is based on
10973 * [`Number.isInteger`](https://mdn.io/Number/isInteger).
10979 * @param {*} value The value to check.
10980 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
10986 * _.isInteger(Number.MIN_VALUE);
10989 * _.isInteger(Infinity);
10992 * _.isInteger('3');
10995 function isInteger(value) {
10996 return typeof value == 'number' && value == toInteger(value);
11000 * Checks if `value` is a valid array-like length.
11002 * **Note:** This function is loosely based on
11003 * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
11009 * @param {*} value The value to check.
11010 * @returns {boolean} Returns `true` if `value` is a valid length,
11017 * _.isLength(Number.MIN_VALUE);
11020 * _.isLength(Infinity);
11026 function isLength(value) {
11027 return typeof value == 'number' &&
11028 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11032 * Checks if `value` is the
11033 * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
11034 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11040 * @param {*} value The value to check.
11041 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11047 * _.isObject([1, 2, 3]);
11050 * _.isObject(_.noop);
11053 * _.isObject(null);
11056 function isObject(value) {
11057 var type = typeof value;
11058 return !!value && (type == 'object' || type == 'function');
11062 * Checks if `value` is object-like. A value is object-like if it's not `null`
11063 * and has a `typeof` result of "object".
11069 * @param {*} value The value to check.
11070 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11073 * _.isObjectLike({});
11076 * _.isObjectLike([1, 2, 3]);
11079 * _.isObjectLike(_.noop);
11082 * _.isObjectLike(null);
11085 function isObjectLike(value) {
11086 return !!value && typeof value == 'object';
11090 * Checks if `value` is classified as a `Map` object.
11096 * @param {*} value The value to check.
11097 * @returns {boolean} Returns `true` if `value` is correctly classified,
11101 * _.isMap(new Map);
11104 * _.isMap(new WeakMap);
11107 function isMap(value) {
11108 return isObjectLike(value) && getTag(value) == mapTag;
11112 * Performs a partial deep comparison between `object` and `source` to
11113 * determine if `object` contains equivalent property values. This method is
11114 * equivalent to a `_.matches` function when `source` is partially applied.
11116 * **Note:** This method supports comparing the same values as `_.isEqual`.
11122 * @param {Object} object The object to inspect.
11123 * @param {Object} source The object of property values to match.
11124 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11127 * var object = { 'user': 'fred', 'age': 40 };
11129 * _.isMatch(object, { 'age': 40 });
11132 * _.isMatch(object, { 'age': 36 });
11135 function isMatch(object, source) {
11136 return object === source || baseIsMatch(object, source, getMatchData(source));
11140 * This method is like `_.isMatch` except that it accepts `customizer` which
11141 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11142 * are handled by the method instead. The `customizer` is invoked with five
11143 * arguments: (objValue, srcValue, index|key, object, source).
11149 * @param {Object} object The object to inspect.
11150 * @param {Object} source The object of property values to match.
11151 * @param {Function} [customizer] The function to customize comparisons.
11152 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11155 * function isGreeting(value) {
11156 * return /^h(?:i|ello)$/.test(value);
11159 * function customizer(objValue, srcValue) {
11160 * if (isGreeting(objValue) && isGreeting(srcValue)) {
11165 * var object = { 'greeting': 'hello' };
11166 * var source = { 'greeting': 'hi' };
11168 * _.isMatchWith(object, source, customizer);
11171 function isMatchWith(object, source, customizer) {
11172 customizer = typeof customizer == 'function' ? customizer : undefined;
11173 return baseIsMatch(object, source, getMatchData(source), customizer);
11177 * Checks if `value` is `NaN`.
11179 * **Note:** This method is based on
11180 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
11181 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
11182 * `undefined` and other non-number values.
11188 * @param {*} value The value to check.
11189 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
11195 * _.isNaN(new Number(NaN));
11198 * isNaN(undefined);
11201 * _.isNaN(undefined);
11204 function isNaN(value) {
11205 // An `NaN` primitive is the only value that is not equal to itself.
11206 // Perform the `toStringTag` check first to avoid errors with some
11207 // ActiveX objects in IE.
11208 return isNumber(value) && value != +value;
11212 * Checks if `value` is a pristine native function.
11214 * **Note:** This method can't reliably detect native functions in the
11215 * presence of the `core-js` package because `core-js` circumvents this kind
11216 * of detection. Despite multiple requests, the `core-js` maintainer has made
11217 * it clear: any attempt to fix the detection will be obstructed. As a result,
11218 * we're left with little choice but to throw an error. Unfortunately, this
11219 * also affects packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
11220 * which rely on `core-js`.
11226 * @param {*} value The value to check.
11227 * @returns {boolean} Returns `true` if `value` is a native function,
11231 * _.isNative(Array.prototype.push);
11237 function isNative(value) {
11238 if (isMaskable(value)) {
11239 throw new Error('This method is not supported with `core-js`. Try https://github.com/es-shims.');
11241 return baseIsNative(value);
11245 * Checks if `value` is `null`.
11251 * @param {*} value The value to check.
11252 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
11258 * _.isNull(void 0);
11261 function isNull(value) {
11262 return value === null;
11266 * Checks if `value` is `null` or `undefined`.
11272 * @param {*} value The value to check.
11273 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
11285 function isNil(value) {
11286 return value == null;
11290 * Checks if `value` is classified as a `Number` primitive or object.
11292 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
11293 * classified as numbers, use the `_.isFinite` method.
11299 * @param {*} value The value to check.
11300 * @returns {boolean} Returns `true` if `value` is correctly classified,
11307 * _.isNumber(Number.MIN_VALUE);
11310 * _.isNumber(Infinity);
11316 function isNumber(value) {
11317 return typeof value == 'number' ||
11318 (isObjectLike(value) && objectToString.call(value) == numberTag);
11322 * Checks if `value` is a plain object, that is, an object created by the
11323 * `Object` constructor or one with a `[[Prototype]]` of `null`.
11329 * @param {*} value The value to check.
11330 * @returns {boolean} Returns `true` if `value` is a plain object,
11338 * _.isPlainObject(new Foo);
11341 * _.isPlainObject([1, 2, 3]);
11344 * _.isPlainObject({ 'x': 0, 'y': 0 });
11347 * _.isPlainObject(Object.create(null));
11350 function isPlainObject(value) {
11351 if (!isObjectLike(value) ||
11352 objectToString.call(value) != objectTag || isHostObject(value)) {
11355 var proto = getPrototype(value);
11356 if (proto === null) {
11359 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
11360 return (typeof Ctor == 'function' &&
11361 Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
11365 * Checks if `value` is classified as a `RegExp` object.
11371 * @param {*} value The value to check.
11372 * @returns {boolean} Returns `true` if `value` is correctly classified,
11376 * _.isRegExp(/abc/);
11379 * _.isRegExp('/abc/');
11382 function isRegExp(value) {
11383 return isObject(value) && objectToString.call(value) == regexpTag;
11387 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
11388 * double precision number which isn't the result of a rounded unsafe integer.
11390 * **Note:** This method is based on
11391 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
11397 * @param {*} value The value to check.
11398 * @returns {boolean} Returns `true` if `value` is a safe integer,
11402 * _.isSafeInteger(3);
11405 * _.isSafeInteger(Number.MIN_VALUE);
11408 * _.isSafeInteger(Infinity);
11411 * _.isSafeInteger('3');
11414 function isSafeInteger(value) {
11415 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
11419 * Checks if `value` is classified as a `Set` object.
11425 * @param {*} value The value to check.
11426 * @returns {boolean} Returns `true` if `value` is correctly classified,
11430 * _.isSet(new Set);
11433 * _.isSet(new WeakSet);
11436 function isSet(value) {
11437 return isObjectLike(value) && getTag(value) == setTag;
11441 * Checks if `value` is classified as a `String` primitive or object.
11447 * @param {*} value The value to check.
11448 * @returns {boolean} Returns `true` if `value` is correctly classified,
11452 * _.isString('abc');
11458 function isString(value) {
11459 return typeof value == 'string' ||
11460 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
11464 * Checks if `value` is classified as a `Symbol` primitive or object.
11470 * @param {*} value The value to check.
11471 * @returns {boolean} Returns `true` if `value` is correctly classified,
11475 * _.isSymbol(Symbol.iterator);
11478 * _.isSymbol('abc');
11481 function isSymbol(value) {
11482 return typeof value == 'symbol' ||
11483 (isObjectLike(value) && objectToString.call(value) == symbolTag);
11487 * Checks if `value` is classified as a typed array.
11493 * @param {*} value The value to check.
11494 * @returns {boolean} Returns `true` if `value` is correctly classified,
11498 * _.isTypedArray(new Uint8Array);
11501 * _.isTypedArray([]);
11504 function isTypedArray(value) {
11505 return isObjectLike(value) &&
11506 isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
11510 * Checks if `value` is `undefined`.
11516 * @param {*} value The value to check.
11517 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
11520 * _.isUndefined(void 0);
11523 * _.isUndefined(null);
11526 function isUndefined(value) {
11527 return value === undefined;
11531 * Checks if `value` is classified as a `WeakMap` object.
11537 * @param {*} value The value to check.
11538 * @returns {boolean} Returns `true` if `value` is correctly classified,
11542 * _.isWeakMap(new WeakMap);
11545 * _.isWeakMap(new Map);
11548 function isWeakMap(value) {
11549 return isObjectLike(value) && getTag(value) == weakMapTag;
11553 * Checks if `value` is classified as a `WeakSet` object.
11559 * @param {*} value The value to check.
11560 * @returns {boolean} Returns `true` if `value` is correctly classified,
11564 * _.isWeakSet(new WeakSet);
11567 * _.isWeakSet(new Set);
11570 function isWeakSet(value) {
11571 return isObjectLike(value) && objectToString.call(value) == weakSetTag;
11575 * Checks if `value` is less than `other`.
11581 * @param {*} value The value to compare.
11582 * @param {*} other The other value to compare.
11583 * @returns {boolean} Returns `true` if `value` is less than `other`,
11597 var lt = createRelationalOperation(baseLt);
11600 * Checks if `value` is less than or equal to `other`.
11606 * @param {*} value The value to compare.
11607 * @param {*} other The other value to compare.
11608 * @returns {boolean} Returns `true` if `value` is less than or equal to
11609 * `other`, else `false`.
11622 var lte = createRelationalOperation(function(value, other) {
11623 return value <= other;
11627 * Converts `value` to an array.
11633 * @param {*} value The value to convert.
11634 * @returns {Array} Returns the converted array.
11637 * _.toArray({ 'a': 1, 'b': 2 });
11640 * _.toArray('abc');
11641 * // => ['a', 'b', 'c']
11649 function toArray(value) {
11653 if (isArrayLike(value)) {
11654 return isString(value) ? stringToArray(value) : copyArray(value);
11656 if (iteratorSymbol && value[iteratorSymbol]) {
11657 return iteratorToArray(value[iteratorSymbol]());
11659 var tag = getTag(value),
11660 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
11662 return func(value);
11666 * Converts `value` to a finite number.
11672 * @param {*} value The value to convert.
11673 * @returns {number} Returns the converted number.
11679 * _.toFinite(Number.MIN_VALUE);
11682 * _.toFinite(Infinity);
11683 * // => 1.7976931348623157e+308
11685 * _.toFinite('3.2');
11688 function toFinite(value) {
11690 return value === 0 ? value : 0;
11692 value = toNumber(value);
11693 if (value === INFINITY || value === -INFINITY) {
11694 var sign = (value < 0 ? -1 : 1);
11695 return sign * MAX_INTEGER;
11697 return value === value ? value : 0;
11701 * Converts `value` to an integer.
11703 * **Note:** This method is loosely based on
11704 * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
11710 * @param {*} value The value to convert.
11711 * @returns {number} Returns the converted integer.
11714 * _.toInteger(3.2);
11717 * _.toInteger(Number.MIN_VALUE);
11720 * _.toInteger(Infinity);
11721 * // => 1.7976931348623157e+308
11723 * _.toInteger('3.2');
11726 function toInteger(value) {
11727 var result = toFinite(value),
11728 remainder = result % 1;
11730 return result === result ? (remainder ? result - remainder : result) : 0;
11734 * Converts `value` to an integer suitable for use as the length of an
11735 * array-like object.
11737 * **Note:** This method is based on
11738 * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
11744 * @param {*} value The value to convert.
11745 * @returns {number} Returns the converted integer.
11751 * _.toLength(Number.MIN_VALUE);
11754 * _.toLength(Infinity);
11757 * _.toLength('3.2');
11760 function toLength(value) {
11761 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
11765 * Converts `value` to a number.
11771 * @param {*} value The value to process.
11772 * @returns {number} Returns the number.
11778 * _.toNumber(Number.MIN_VALUE);
11781 * _.toNumber(Infinity);
11784 * _.toNumber('3.2');
11787 function toNumber(value) {
11788 if (typeof value == 'number') {
11791 if (isSymbol(value)) {
11794 if (isObject(value)) {
11795 var other = isFunction(value.valueOf) ? value.valueOf() : value;
11796 value = isObject(other) ? (other + '') : other;
11798 if (typeof value != 'string') {
11799 return value === 0 ? value : +value;
11801 value = value.replace(reTrim, '');
11802 var isBinary = reIsBinary.test(value);
11803 return (isBinary || reIsOctal.test(value))
11804 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
11805 : (reIsBadHex.test(value) ? NAN : +value);
11809 * Converts `value` to a plain object flattening inherited enumerable string
11810 * keyed properties of `value` to own properties of the plain object.
11816 * @param {*} value The value to convert.
11817 * @returns {Object} Returns the converted plain object.
11824 * Foo.prototype.c = 3;
11826 * _.assign({ 'a': 1 }, new Foo);
11827 * // => { 'a': 1, 'b': 2 }
11829 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
11830 * // => { 'a': 1, 'b': 2, 'c': 3 }
11832 function toPlainObject(value) {
11833 return copyObject(value, keysIn(value));
11837 * Converts `value` to a safe integer. A safe integer can be compared and
11838 * represented correctly.
11844 * @param {*} value The value to convert.
11845 * @returns {number} Returns the converted integer.
11848 * _.toSafeInteger(3.2);
11851 * _.toSafeInteger(Number.MIN_VALUE);
11854 * _.toSafeInteger(Infinity);
11855 * // => 9007199254740991
11857 * _.toSafeInteger('3.2');
11860 function toSafeInteger(value) {
11861 return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
11865 * Converts `value` to a string. An empty string is returned for `null`
11866 * and `undefined` values. The sign of `-0` is preserved.
11872 * @param {*} value The value to process.
11873 * @returns {string} Returns the string.
11876 * _.toString(null);
11882 * _.toString([1, 2, 3]);
11885 function toString(value) {
11886 return value == null ? '' : baseToString(value);
11889 /*------------------------------------------------------------------------*/
11892 * Assigns own enumerable string keyed properties of source objects to the
11893 * destination object. Source objects are applied from left to right.
11894 * Subsequent sources overwrite property assignments of previous sources.
11896 * **Note:** This method mutates `object` and is loosely based on
11897 * [`Object.assign`](https://mdn.io/Object/assign).
11903 * @param {Object} object The destination object.
11904 * @param {...Object} [sources] The source objects.
11905 * @returns {Object} Returns `object`.
11917 * Foo.prototype.d = 4;
11918 * Bar.prototype.f = 6;
11920 * _.assign({ 'a': 1 }, new Foo, new Bar);
11921 * // => { 'a': 1, 'c': 3, 'e': 5 }
11923 var assign = createAssigner(function(object, source) {
11924 if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
11925 copyObject(source, keys(source), object);
11928 for (var key in source) {
11929 if (hasOwnProperty.call(source, key)) {
11930 assignValue(object, key, source[key]);
11936 * This method is like `_.assign` except that it iterates over own and
11937 * inherited source properties.
11939 * **Note:** This method mutates `object`.
11946 * @param {Object} object The destination object.
11947 * @param {...Object} [sources] The source objects.
11948 * @returns {Object} Returns `object`.
11960 * Foo.prototype.c = 3;
11961 * Bar.prototype.e = 5;
11963 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
11964 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
11966 var assignIn = createAssigner(function(object, source) {
11967 if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
11968 copyObject(source, keysIn(source), object);
11971 for (var key in source) {
11972 assignValue(object, key, source[key]);
11977 * This method is like `_.assignIn` except that it accepts `customizer`
11978 * which is invoked to produce the assigned values. If `customizer` returns
11979 * `undefined`, assignment is handled by the method instead. The `customizer`
11980 * is invoked with five arguments: (objValue, srcValue, key, object, source).
11982 * **Note:** This method mutates `object`.
11987 * @alias extendWith
11989 * @param {Object} object The destination object.
11990 * @param {...Object} sources The source objects.
11991 * @param {Function} [customizer] The function to customize assigned values.
11992 * @returns {Object} Returns `object`.
11993 * @see _.assignWith
11996 * function customizer(objValue, srcValue) {
11997 * return _.isUndefined(objValue) ? srcValue : objValue;
12000 * var defaults = _.partialRight(_.assignInWith, customizer);
12002 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12003 * // => { 'a': 1, 'b': 2 }
12005 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
12006 copyObject(source, keysIn(source), object, customizer);
12010 * This method is like `_.assign` except that it accepts `customizer`
12011 * which is invoked to produce the assigned values. If `customizer` returns
12012 * `undefined`, assignment is handled by the method instead. The `customizer`
12013 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12015 * **Note:** This method mutates `object`.
12021 * @param {Object} object The destination object.
12022 * @param {...Object} sources The source objects.
12023 * @param {Function} [customizer] The function to customize assigned values.
12024 * @returns {Object} Returns `object`.
12025 * @see _.assignInWith
12028 * function customizer(objValue, srcValue) {
12029 * return _.isUndefined(objValue) ? srcValue : objValue;
12032 * var defaults = _.partialRight(_.assignWith, customizer);
12034 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12035 * // => { 'a': 1, 'b': 2 }
12037 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
12038 copyObject(source, keys(source), object, customizer);
12042 * Creates an array of values corresponding to `paths` of `object`.
12048 * @param {Object} object The object to iterate over.
12049 * @param {...(string|string[])} [paths] The property paths of elements to pick.
12050 * @returns {Array} Returns the picked values.
12053 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
12055 * _.at(object, ['a[0].b.c', 'a[1]']);
12058 var at = rest(function(object, paths) {
12059 return baseAt(object, baseFlatten(paths, 1));
12063 * Creates an object that inherits from the `prototype` object. If a
12064 * `properties` object is given, its own enumerable string keyed properties
12065 * are assigned to the created object.
12071 * @param {Object} prototype The object to inherit from.
12072 * @param {Object} [properties] The properties to assign to the object.
12073 * @returns {Object} Returns the new object.
12076 * function Shape() {
12081 * function Circle() {
12082 * Shape.call(this);
12085 * Circle.prototype = _.create(Shape.prototype, {
12086 * 'constructor': Circle
12089 * var circle = new Circle;
12090 * circle instanceof Circle;
12093 * circle instanceof Shape;
12096 function create(prototype, properties) {
12097 var result = baseCreate(prototype);
12098 return properties ? baseAssign(result, properties) : result;
12102 * Assigns own and inherited enumerable string keyed properties of source
12103 * objects to the destination object for all destination properties that
12104 * resolve to `undefined`. Source objects are applied from left to right.
12105 * Once a property is set, additional values of the same property are ignored.
12107 * **Note:** This method mutates `object`.
12113 * @param {Object} object The destination object.
12114 * @param {...Object} [sources] The source objects.
12115 * @returns {Object} Returns `object`.
12116 * @see _.defaultsDeep
12119 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
12120 * // => { 'user': 'barney', 'age': 36 }
12122 var defaults = rest(function(args) {
12123 args.push(undefined, assignInDefaults);
12124 return apply(assignInWith, undefined, args);
12128 * This method is like `_.defaults` except that it recursively assigns
12129 * default properties.
12131 * **Note:** This method mutates `object`.
12137 * @param {Object} object The destination object.
12138 * @param {...Object} [sources] The source objects.
12139 * @returns {Object} Returns `object`.
12143 * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
12144 * // => { 'user': { 'name': 'barney', 'age': 36 } }
12147 var defaultsDeep = rest(function(args) {
12148 args.push(undefined, mergeDefaults);
12149 return apply(mergeWith, undefined, args);
12153 * This method is like `_.find` except that it returns the key of the first
12154 * element `predicate` returns truthy for instead of the element itself.
12160 * @param {Object} object The object to search.
12161 * @param {Array|Function|Object|string} [predicate=_.identity]
12162 * The function invoked per iteration.
12163 * @returns {string|undefined} Returns the key of the matched element,
12164 * else `undefined`.
12168 * 'barney': { 'age': 36, 'active': true },
12169 * 'fred': { 'age': 40, 'active': false },
12170 * 'pebbles': { 'age': 1, 'active': true }
12173 * _.findKey(users, function(o) { return o.age < 40; });
12174 * // => 'barney' (iteration order is not guaranteed)
12176 * // The `_.matches` iteratee shorthand.
12177 * _.findKey(users, { 'age': 1, 'active': true });
12180 * // The `_.matchesProperty` iteratee shorthand.
12181 * _.findKey(users, ['active', false]);
12184 * // The `_.property` iteratee shorthand.
12185 * _.findKey(users, 'active');
12188 function findKey(object, predicate) {
12189 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
12193 * This method is like `_.findKey` except that it iterates over elements of
12194 * a collection in the opposite order.
12200 * @param {Object} object The object to search.
12201 * @param {Array|Function|Object|string} [predicate=_.identity]
12202 * The function invoked per iteration.
12203 * @returns {string|undefined} Returns the key of the matched element,
12204 * else `undefined`.
12208 * 'barney': { 'age': 36, 'active': true },
12209 * 'fred': { 'age': 40, 'active': false },
12210 * 'pebbles': { 'age': 1, 'active': true }
12213 * _.findLastKey(users, function(o) { return o.age < 40; });
12214 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
12216 * // The `_.matches` iteratee shorthand.
12217 * _.findLastKey(users, { 'age': 36, 'active': true });
12220 * // The `_.matchesProperty` iteratee shorthand.
12221 * _.findLastKey(users, ['active', false]);
12224 * // The `_.property` iteratee shorthand.
12225 * _.findLastKey(users, 'active');
12228 function findLastKey(object, predicate) {
12229 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
12233 * Iterates over own and inherited enumerable string keyed properties of an
12234 * object and invokes `iteratee` for each property. The iteratee is invoked
12235 * with three arguments: (value, key, object). Iteratee functions may exit
12236 * iteration early by explicitly returning `false`.
12242 * @param {Object} object The object to iterate over.
12243 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12244 * @returns {Object} Returns `object`.
12245 * @see _.forInRight
12253 * Foo.prototype.c = 3;
12255 * _.forIn(new Foo, function(value, key) {
12256 * console.log(key);
12258 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
12260 function forIn(object, iteratee) {
12261 return object == null
12263 : baseFor(object, getIteratee(iteratee, 3), keysIn);
12267 * This method is like `_.forIn` except that it iterates over properties of
12268 * `object` in the opposite order.
12274 * @param {Object} object The object to iterate over.
12275 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12276 * @returns {Object} Returns `object`.
12285 * Foo.prototype.c = 3;
12287 * _.forInRight(new Foo, function(value, key) {
12288 * console.log(key);
12290 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
12292 function forInRight(object, iteratee) {
12293 return object == null
12295 : baseForRight(object, getIteratee(iteratee, 3), keysIn);
12299 * Iterates over own enumerable string keyed properties of an object and
12300 * invokes `iteratee` for each property. The iteratee is invoked with three
12301 * arguments: (value, key, object). Iteratee functions may exit iteration
12302 * early by explicitly returning `false`.
12308 * @param {Object} object The object to iterate over.
12309 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12310 * @returns {Object} Returns `object`.
12311 * @see _.forOwnRight
12319 * Foo.prototype.c = 3;
12321 * _.forOwn(new Foo, function(value, key) {
12322 * console.log(key);
12324 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
12326 function forOwn(object, iteratee) {
12327 return object && baseForOwn(object, getIteratee(iteratee, 3));
12331 * This method is like `_.forOwn` except that it iterates over properties of
12332 * `object` in the opposite order.
12338 * @param {Object} object The object to iterate over.
12339 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12340 * @returns {Object} Returns `object`.
12349 * Foo.prototype.c = 3;
12351 * _.forOwnRight(new Foo, function(value, key) {
12352 * console.log(key);
12354 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
12356 function forOwnRight(object, iteratee) {
12357 return object && baseForOwnRight(object, getIteratee(iteratee, 3));
12361 * Creates an array of function property names from own enumerable properties
12368 * @param {Object} object The object to inspect.
12369 * @returns {Array} Returns the function names.
12370 * @see _.functionsIn
12374 * this.a = _.constant('a');
12375 * this.b = _.constant('b');
12378 * Foo.prototype.c = _.constant('c');
12380 * _.functions(new Foo);
12383 function functions(object) {
12384 return object == null ? [] : baseFunctions(object, keys(object));
12388 * Creates an array of function property names from own and inherited
12389 * enumerable properties of `object`.
12395 * @param {Object} object The object to inspect.
12396 * @returns {Array} Returns the function names.
12401 * this.a = _.constant('a');
12402 * this.b = _.constant('b');
12405 * Foo.prototype.c = _.constant('c');
12407 * _.functionsIn(new Foo);
12408 * // => ['a', 'b', 'c']
12410 function functionsIn(object) {
12411 return object == null ? [] : baseFunctions(object, keysIn(object));
12415 * Gets the value at `path` of `object`. If the resolved value is
12416 * `undefined`, the `defaultValue` is used in its place.
12422 * @param {Object} object The object to query.
12423 * @param {Array|string} path The path of the property to get.
12424 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
12425 * @returns {*} Returns the resolved value.
12428 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
12430 * _.get(object, 'a[0].b.c');
12433 * _.get(object, ['a', '0', 'b', 'c']);
12436 * _.get(object, 'a.b.c', 'default');
12439 function get(object, path, defaultValue) {
12440 var result = object == null ? undefined : baseGet(object, path);
12441 return result === undefined ? defaultValue : result;
12445 * Checks if `path` is a direct property of `object`.
12451 * @param {Object} object The object to query.
12452 * @param {Array|string} path The path to check.
12453 * @returns {boolean} Returns `true` if `path` exists, else `false`.
12456 * var object = { 'a': { 'b': 2 } };
12457 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
12459 * _.has(object, 'a');
12462 * _.has(object, 'a.b');
12465 * _.has(object, ['a', 'b']);
12468 * _.has(other, 'a');
12471 function has(object, path) {
12472 return object != null && hasPath(object, path, baseHas);
12476 * Checks if `path` is a direct or inherited property of `object`.
12482 * @param {Object} object The object to query.
12483 * @param {Array|string} path The path to check.
12484 * @returns {boolean} Returns `true` if `path` exists, else `false`.
12487 * var object = _.create({ 'a': _.create({ 'b': 2 }) });
12489 * _.hasIn(object, 'a');
12492 * _.hasIn(object, 'a.b');
12495 * _.hasIn(object, ['a', 'b']);
12498 * _.hasIn(object, 'b');
12501 function hasIn(object, path) {
12502 return object != null && hasPath(object, path, baseHasIn);
12506 * Creates an object composed of the inverted keys and values of `object`.
12507 * If `object` contains duplicate values, subsequent values overwrite
12508 * property assignments of previous values.
12514 * @param {Object} object The object to invert.
12515 * @returns {Object} Returns the new inverted object.
12518 * var object = { 'a': 1, 'b': 2, 'c': 1 };
12520 * _.invert(object);
12521 * // => { '1': 'c', '2': 'b' }
12523 var invert = createInverter(function(result, value, key) {
12524 result[value] = key;
12525 }, constant(identity));
12528 * This method is like `_.invert` except that the inverted object is generated
12529 * from the results of running each element of `object` thru `iteratee`. The
12530 * corresponding inverted value of each inverted key is an array of keys
12531 * responsible for generating the inverted value. The iteratee is invoked
12532 * with one argument: (value).
12538 * @param {Object} object The object to invert.
12539 * @param {Array|Function|Object|string} [iteratee=_.identity]
12540 * The iteratee invoked per element.
12541 * @returns {Object} Returns the new inverted object.
12544 * var object = { 'a': 1, 'b': 2, 'c': 1 };
12546 * _.invertBy(object);
12547 * // => { '1': ['a', 'c'], '2': ['b'] }
12549 * _.invertBy(object, function(value) {
12550 * return 'group' + value;
12552 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
12554 var invertBy = createInverter(function(result, value, key) {
12555 if (hasOwnProperty.call(result, value)) {
12556 result[value].push(key);
12558 result[value] = [key];
12563 * Invokes the method at `path` of `object`.
12569 * @param {Object} object The object to query.
12570 * @param {Array|string} path The path of the method to invoke.
12571 * @param {...*} [args] The arguments to invoke the method with.
12572 * @returns {*} Returns the result of the invoked method.
12575 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
12577 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
12580 var invoke = rest(baseInvoke);
12583 * Creates an array of the own enumerable property names of `object`.
12585 * **Note:** Non-object values are coerced to objects. See the
12586 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
12587 * for more details.
12593 * @param {Object} object The object to query.
12594 * @returns {Array} Returns the array of property names.
12602 * Foo.prototype.c = 3;
12605 * // => ['a', 'b'] (iteration order is not guaranteed)
12610 function keys(object) {
12611 var isProto = isPrototype(object);
12612 if (!(isProto || isArrayLike(object))) {
12613 return baseKeys(object);
12615 var indexes = indexKeys(object),
12616 skipIndexes = !!indexes,
12617 result = indexes || [],
12618 length = result.length;
12620 for (var key in object) {
12621 if (baseHas(object, key) &&
12622 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
12623 !(isProto && key == 'constructor')) {
12631 * Creates an array of the own and inherited enumerable property names of `object`.
12633 * **Note:** Non-object values are coerced to objects.
12639 * @param {Object} object The object to query.
12640 * @returns {Array} Returns the array of property names.
12648 * Foo.prototype.c = 3;
12650 * _.keysIn(new Foo);
12651 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
12653 function keysIn(object) {
12655 isProto = isPrototype(object),
12656 props = baseKeysIn(object),
12657 propsLength = props.length,
12658 indexes = indexKeys(object),
12659 skipIndexes = !!indexes,
12660 result = indexes || [],
12661 length = result.length;
12663 while (++index < propsLength) {
12664 var key = props[index];
12665 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
12666 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
12674 * The opposite of `_.mapValues`; this method creates an object with the
12675 * same values as `object` and keys generated by running each own enumerable
12676 * string keyed property of `object` thru `iteratee`. The iteratee is invoked
12677 * with three arguments: (value, key, object).
12683 * @param {Object} object The object to iterate over.
12684 * @param {Array|Function|Object|string} [iteratee=_.identity]
12685 * The function invoked per iteration.
12686 * @returns {Object} Returns the new mapped object.
12690 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
12691 * return key + value;
12693 * // => { 'a1': 1, 'b2': 2 }
12695 function mapKeys(object, iteratee) {
12697 iteratee = getIteratee(iteratee, 3);
12699 baseForOwn(object, function(value, key, object) {
12700 result[iteratee(value, key, object)] = value;
12706 * Creates an object with the same keys as `object` and values generated
12707 * by running each own enumerable string keyed property of `object` thru
12708 * `iteratee`. The iteratee is invoked with three arguments:
12709 * (value, key, object).
12715 * @param {Object} object The object to iterate over.
12716 * @param {Array|Function|Object|string} [iteratee=_.identity]
12717 * The function invoked per iteration.
12718 * @returns {Object} Returns the new mapped object.
12723 * 'fred': { 'user': 'fred', 'age': 40 },
12724 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
12727 * _.mapValues(users, function(o) { return o.age; });
12728 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
12730 * // The `_.property` iteratee shorthand.
12731 * _.mapValues(users, 'age');
12732 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
12734 function mapValues(object, iteratee) {
12736 iteratee = getIteratee(iteratee, 3);
12738 baseForOwn(object, function(value, key, object) {
12739 result[key] = iteratee(value, key, object);
12745 * This method is like `_.assign` except that it recursively merges own and
12746 * inherited enumerable string keyed properties of source objects into the
12747 * destination object. Source properties that resolve to `undefined` are
12748 * skipped if a destination value exists. Array and plain object properties
12749 * are merged recursively. Other objects and value types are overridden by
12750 * assignment. Source objects are applied from left to right. Subsequent
12751 * sources overwrite property assignments of previous sources.
12753 * **Note:** This method mutates `object`.
12759 * @param {Object} object The destination object.
12760 * @param {...Object} [sources] The source objects.
12761 * @returns {Object} Returns `object`.
12765 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
12769 * 'data': [{ 'age': 36 }, { 'age': 40 }]
12772 * _.merge(users, ages);
12773 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
12775 var merge = createAssigner(function(object, source, srcIndex) {
12776 baseMerge(object, source, srcIndex);
12780 * This method is like `_.merge` except that it accepts `customizer` which
12781 * is invoked to produce the merged values of the destination and source
12782 * properties. If `customizer` returns `undefined`, merging is handled by the
12783 * method instead. The `customizer` is invoked with seven arguments:
12784 * (objValue, srcValue, key, object, source, stack).
12786 * **Note:** This method mutates `object`.
12792 * @param {Object} object The destination object.
12793 * @param {...Object} sources The source objects.
12794 * @param {Function} customizer The function to customize assigned values.
12795 * @returns {Object} Returns `object`.
12798 * function customizer(objValue, srcValue) {
12799 * if (_.isArray(objValue)) {
12800 * return objValue.concat(srcValue);
12805 * 'fruits': ['apple'],
12806 * 'vegetables': ['beet']
12810 * 'fruits': ['banana'],
12811 * 'vegetables': ['carrot']
12814 * _.mergeWith(object, other, customizer);
12815 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
12817 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
12818 baseMerge(object, source, srcIndex, customizer);
12822 * The opposite of `_.pick`; this method creates an object composed of the
12823 * own and inherited enumerable string keyed properties of `object` that are
12830 * @param {Object} object The source object.
12831 * @param {...(string|string[])} [props] The property identifiers to omit.
12832 * @returns {Object} Returns the new object.
12835 * var object = { 'a': 1, 'b': '2', 'c': 3 };
12837 * _.omit(object, ['a', 'c']);
12838 * // => { 'b': '2' }
12840 var omit = rest(function(object, props) {
12841 if (object == null) {
12844 props = arrayMap(baseFlatten(props, 1), toKey);
12845 return basePick(object, baseDifference(getAllKeysIn(object), props));
12849 * The opposite of `_.pickBy`; this method creates an object composed of
12850 * the own and inherited enumerable string keyed properties of `object` that
12851 * `predicate` doesn't return truthy for. The predicate is invoked with two
12852 * arguments: (value, key).
12858 * @param {Object} object The source object.
12859 * @param {Array|Function|Object|string} [predicate=_.identity]
12860 * The function invoked per property.
12861 * @returns {Object} Returns the new object.
12864 * var object = { 'a': 1, 'b': '2', 'c': 3 };
12866 * _.omitBy(object, _.isNumber);
12867 * // => { 'b': '2' }
12869 function omitBy(object, predicate) {
12870 predicate = getIteratee(predicate);
12871 return basePickBy(object, function(value, key) {
12872 return !predicate(value, key);
12877 * Creates an object composed of the picked `object` properties.
12883 * @param {Object} object The source object.
12884 * @param {...(string|string[])} [props] The property identifiers to pick.
12885 * @returns {Object} Returns the new object.
12888 * var object = { 'a': 1, 'b': '2', 'c': 3 };
12890 * _.pick(object, ['a', 'c']);
12891 * // => { 'a': 1, 'c': 3 }
12893 var pick = rest(function(object, props) {
12894 return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey));
12898 * Creates an object composed of the `object` properties `predicate` returns
12899 * truthy for. The predicate is invoked with two arguments: (value, key).
12905 * @param {Object} object The source object.
12906 * @param {Array|Function|Object|string} [predicate=_.identity]
12907 * The function invoked per property.
12908 * @returns {Object} Returns the new object.
12911 * var object = { 'a': 1, 'b': '2', 'c': 3 };
12913 * _.pickBy(object, _.isNumber);
12914 * // => { 'a': 1, 'c': 3 }
12916 function pickBy(object, predicate) {
12917 return object == null ? {} : basePickBy(object, getIteratee(predicate));
12921 * This method is like `_.get` except that if the resolved value is a
12922 * function it's invoked with the `this` binding of its parent object and
12923 * its result is returned.
12929 * @param {Object} object The object to query.
12930 * @param {Array|string} path The path of the property to resolve.
12931 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
12932 * @returns {*} Returns the resolved value.
12935 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
12937 * _.result(object, 'a[0].b.c1');
12940 * _.result(object, 'a[0].b.c2');
12943 * _.result(object, 'a[0].b.c3', 'default');
12946 * _.result(object, 'a[0].b.c3', _.constant('default'));
12949 function result(object, path, defaultValue) {
12950 path = isKey(path, object) ? [path] : castPath(path);
12953 length = path.length;
12955 // Ensure the loop is entered when path is empty.
12957 object = undefined;
12960 while (++index < length) {
12961 var value = object == null ? undefined : object[toKey(path[index])];
12962 if (value === undefined) {
12964 value = defaultValue;
12966 object = isFunction(value) ? value.call(object) : value;
12972 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
12973 * it's created. Arrays are created for missing index properties while objects
12974 * are created for all other missing properties. Use `_.setWith` to customize
12977 * **Note:** This method mutates `object`.
12983 * @param {Object} object The object to modify.
12984 * @param {Array|string} path The path of the property to set.
12985 * @param {*} value The value to set.
12986 * @returns {Object} Returns `object`.
12989 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
12991 * _.set(object, 'a[0].b.c', 4);
12992 * console.log(object.a[0].b.c);
12995 * _.set(object, ['x', '0', 'y', 'z'], 5);
12996 * console.log(object.x[0].y.z);
12999 function set(object, path, value) {
13000 return object == null ? object : baseSet(object, path, value);
13004 * This method is like `_.set` except that it accepts `customizer` which is
13005 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13006 * path creation is handled by the method instead. The `customizer` is invoked
13007 * with three arguments: (nsValue, key, nsObject).
13009 * **Note:** This method mutates `object`.
13015 * @param {Object} object The object to modify.
13016 * @param {Array|string} path The path of the property to set.
13017 * @param {*} value The value to set.
13018 * @param {Function} [customizer] The function to customize assigned values.
13019 * @returns {Object} Returns `object`.
13024 * _.setWith(object, '[0][1]', 'a', Object);
13025 * // => { '0': { '1': 'a' } }
13027 function setWith(object, path, value, customizer) {
13028 customizer = typeof customizer == 'function' ? customizer : undefined;
13029 return object == null ? object : baseSet(object, path, value, customizer);
13033 * Creates an array of own enumerable string keyed-value pairs for `object`
13034 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
13035 * entries are returned.
13042 * @param {Object} object The object to query.
13043 * @returns {Array} Returns the key-value pairs.
13051 * Foo.prototype.c = 3;
13053 * _.toPairs(new Foo);
13054 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
13056 var toPairs = createToPairs(keys);
13059 * Creates an array of own and inherited enumerable string keyed-value pairs
13060 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
13061 * or set, its entries are returned.
13068 * @param {Object} object The object to query.
13069 * @returns {Array} Returns the key-value pairs.
13077 * Foo.prototype.c = 3;
13079 * _.toPairsIn(new Foo);
13080 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
13082 var toPairsIn = createToPairs(keysIn);
13085 * An alternative to `_.reduce`; this method transforms `object` to a new
13086 * `accumulator` object which is the result of running each of its own
13087 * enumerable string keyed properties thru `iteratee`, with each invocation
13088 * potentially mutating the `accumulator` object. If `accumulator` is not
13089 * provided, a new object with the same `[[Prototype]]` will be used. The
13090 * iteratee is invoked with four arguments: (accumulator, value, key, object).
13091 * Iteratee functions may exit iteration early by explicitly returning `false`.
13097 * @param {Object} object The object to iterate over.
13098 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13099 * @param {*} [accumulator] The custom accumulator value.
13100 * @returns {*} Returns the accumulated value.
13103 * _.transform([2, 3, 4], function(result, n) {
13104 * result.push(n *= n);
13105 * return n % 2 == 0;
13109 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
13110 * (result[value] || (result[value] = [])).push(key);
13112 * // => { '1': ['a', 'c'], '2': ['b'] }
13114 function transform(object, iteratee, accumulator) {
13115 var isArr = isArray(object) || isTypedArray(object);
13116 iteratee = getIteratee(iteratee, 4);
13118 if (accumulator == null) {
13119 if (isArr || isObject(object)) {
13120 var Ctor = object.constructor;
13122 accumulator = isArray(object) ? new Ctor : [];
13124 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
13130 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
13131 return iteratee(accumulator, value, index, object);
13133 return accumulator;
13137 * Removes the property at `path` of `object`.
13139 * **Note:** This method mutates `object`.
13145 * @param {Object} object The object to modify.
13146 * @param {Array|string} path The path of the property to unset.
13147 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
13150 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
13151 * _.unset(object, 'a[0].b.c');
13154 * console.log(object);
13155 * // => { 'a': [{ 'b': {} }] };
13157 * _.unset(object, ['a', '0', 'b', 'c']);
13160 * console.log(object);
13161 * // => { 'a': [{ 'b': {} }] };
13163 function unset(object, path) {
13164 return object == null ? true : baseUnset(object, path);
13168 * This method is like `_.set` except that accepts `updater` to produce the
13169 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
13170 * is invoked with one argument: (value).
13172 * **Note:** This method mutates `object`.
13178 * @param {Object} object The object to modify.
13179 * @param {Array|string} path The path of the property to set.
13180 * @param {Function} updater The function to produce the updated value.
13181 * @returns {Object} Returns `object`.
13184 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13186 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
13187 * console.log(object.a[0].b.c);
13190 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
13191 * console.log(object.x[0].y.z);
13194 function update(object, path, updater) {
13195 return object == null ? object : baseUpdate(object, path, castFunction(updater));
13199 * This method is like `_.update` except that it accepts `customizer` which is
13200 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13201 * path creation is handled by the method instead. The `customizer` is invoked
13202 * with three arguments: (nsValue, key, nsObject).
13204 * **Note:** This method mutates `object`.
13210 * @param {Object} object The object to modify.
13211 * @param {Array|string} path The path of the property to set.
13212 * @param {Function} updater The function to produce the updated value.
13213 * @param {Function} [customizer] The function to customize assigned values.
13214 * @returns {Object} Returns `object`.
13219 * _.updateWith(object, '[0][1]', _.constant('a'), Object);
13220 * // => { '0': { '1': 'a' } }
13222 function updateWith(object, path, updater, customizer) {
13223 customizer = typeof customizer == 'function' ? customizer : undefined;
13224 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
13228 * Creates an array of the own enumerable string keyed property values of `object`.
13230 * **Note:** Non-object values are coerced to objects.
13236 * @param {Object} object The object to query.
13237 * @returns {Array} Returns the array of property values.
13245 * Foo.prototype.c = 3;
13247 * _.values(new Foo);
13248 * // => [1, 2] (iteration order is not guaranteed)
13253 function values(object) {
13254 return object ? baseValues(object, keys(object)) : [];
13258 * Creates an array of the own and inherited enumerable string keyed property
13259 * values of `object`.
13261 * **Note:** Non-object values are coerced to objects.
13267 * @param {Object} object The object to query.
13268 * @returns {Array} Returns the array of property values.
13276 * Foo.prototype.c = 3;
13278 * _.valuesIn(new Foo);
13279 * // => [1, 2, 3] (iteration order is not guaranteed)
13281 function valuesIn(object) {
13282 return object == null ? [] : baseValues(object, keysIn(object));
13285 /*------------------------------------------------------------------------*/
13288 * Clamps `number` within the inclusive `lower` and `upper` bounds.
13294 * @param {number} number The number to clamp.
13295 * @param {number} [lower] The lower bound.
13296 * @param {number} upper The upper bound.
13297 * @returns {number} Returns the clamped number.
13300 * _.clamp(-10, -5, 5);
13303 * _.clamp(10, -5, 5);
13306 function clamp(number, lower, upper) {
13307 if (upper === undefined) {
13311 if (upper !== undefined) {
13312 upper = toNumber(upper);
13313 upper = upper === upper ? upper : 0;
13315 if (lower !== undefined) {
13316 lower = toNumber(lower);
13317 lower = lower === lower ? lower : 0;
13319 return baseClamp(toNumber(number), lower, upper);
13323 * Checks if `n` is between `start` and up to, but not including, `end`. If
13324 * `end` is not specified, it's set to `start` with `start` then set to `0`.
13325 * If `start` is greater than `end` the params are swapped to support
13332 * @param {number} number The number to check.
13333 * @param {number} [start=0] The start of the range.
13334 * @param {number} end The end of the range.
13335 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
13336 * @see _.range, _.rangeRight
13339 * _.inRange(3, 2, 4);
13351 * _.inRange(1.2, 2);
13354 * _.inRange(5.2, 4);
13357 * _.inRange(-3, -2, -6);
13360 function inRange(number, start, end) {
13361 start = toNumber(start) || 0;
13362 if (end === undefined) {
13366 end = toNumber(end) || 0;
13368 number = toNumber(number);
13369 return baseInRange(number, start, end);
13373 * Produces a random number between the inclusive `lower` and `upper` bounds.
13374 * If only one argument is provided a number between `0` and the given number
13375 * is returned. If `floating` is `true`, or either `lower` or `upper` are
13376 * floats, a floating-point number is returned instead of an integer.
13378 * **Note:** JavaScript follows the IEEE-754 standard for resolving
13379 * floating-point values which can produce unexpected results.
13385 * @param {number} [lower=0] The lower bound.
13386 * @param {number} [upper=1] The upper bound.
13387 * @param {boolean} [floating] Specify returning a floating-point number.
13388 * @returns {number} Returns the random number.
13392 * // => an integer between 0 and 5
13395 * // => also an integer between 0 and 5
13397 * _.random(5, true);
13398 * // => a floating-point number between 0 and 5
13400 * _.random(1.2, 5.2);
13401 * // => a floating-point number between 1.2 and 5.2
13403 function random(lower, upper, floating) {
13404 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
13405 upper = floating = undefined;
13407 if (floating === undefined) {
13408 if (typeof upper == 'boolean') {
13412 else if (typeof lower == 'boolean') {
13417 if (lower === undefined && upper === undefined) {
13422 lower = toNumber(lower) || 0;
13423 if (upper === undefined) {
13427 upper = toNumber(upper) || 0;
13430 if (lower > upper) {
13435 if (floating || lower % 1 || upper % 1) {
13436 var rand = nativeRandom();
13437 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
13439 return baseRandom(lower, upper);
13442 /*------------------------------------------------------------------------*/
13445 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
13451 * @param {string} [string=''] The string to convert.
13452 * @returns {string} Returns the camel cased string.
13455 * _.camelCase('Foo Bar');
13458 * _.camelCase('--foo-bar--');
13461 * _.camelCase('__FOO_BAR__');
13464 var camelCase = createCompounder(function(result, word, index) {
13465 word = word.toLowerCase();
13466 return result + (index ? capitalize(word) : word);
13470 * Converts the first character of `string` to upper case and the remaining
13477 * @param {string} [string=''] The string to capitalize.
13478 * @returns {string} Returns the capitalized string.
13481 * _.capitalize('FRED');
13484 function capitalize(string) {
13485 return upperFirst(toString(string).toLowerCase());
13489 * Deburrs `string` by converting
13490 * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
13491 * to basic latin letters and removing
13492 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
13498 * @param {string} [string=''] The string to deburr.
13499 * @returns {string} Returns the deburred string.
13502 * _.deburr('déjà vu');
13505 function deburr(string) {
13506 string = toString(string);
13507 return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
13511 * Checks if `string` ends with the given target string.
13517 * @param {string} [string=''] The string to search.
13518 * @param {string} [target] The string to search for.
13519 * @param {number} [position=string.length] The position to search up to.
13520 * @returns {boolean} Returns `true` if `string` ends with `target`,
13524 * _.endsWith('abc', 'c');
13527 * _.endsWith('abc', 'b');
13530 * _.endsWith('abc', 'b', 2);
13533 function endsWith(string, target, position) {
13534 string = toString(string);
13535 target = baseToString(target);
13537 var length = string.length;
13538 position = position === undefined
13540 : baseClamp(toInteger(position), 0, length);
13542 position -= target.length;
13543 return position >= 0 && string.indexOf(target, position) == position;
13547 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
13548 * their corresponding HTML entities.
13550 * **Note:** No other characters are escaped. To escape additional
13551 * characters use a third-party library like [_he_](https://mths.be/he).
13553 * Though the ">" character is escaped for symmetry, characters like
13554 * ">" and "/" don't need escaping in HTML and have no special meaning
13555 * unless they're part of a tag or unquoted attribute value. See
13556 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
13557 * (under "semi-related fun fact") for more details.
13559 * Backticks are escaped because in IE < 9, they can break out of
13560 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
13561 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
13562 * [#133](https://html5sec.org/#133) of the
13563 * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
13565 * When working with HTML you should always
13566 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
13573 * @param {string} [string=''] The string to escape.
13574 * @returns {string} Returns the escaped string.
13577 * _.escape('fred, barney, & pebbles');
13578 * // => 'fred, barney, & pebbles'
13580 function escape(string) {
13581 string = toString(string);
13582 return (string && reHasUnescapedHtml.test(string))
13583 ? string.replace(reUnescapedHtml, escapeHtmlChar)
13588 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
13589 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
13595 * @param {string} [string=''] The string to escape.
13596 * @returns {string} Returns the escaped string.
13599 * _.escapeRegExp('[lodash](https://lodash.com/)');
13600 * // => '\[lodash\]\(https://lodash\.com/\)'
13602 function escapeRegExp(string) {
13603 string = toString(string);
13604 return (string && reHasRegExpChar.test(string))
13605 ? string.replace(reRegExpChar, '\\$&')
13610 * Converts `string` to
13611 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
13617 * @param {string} [string=''] The string to convert.
13618 * @returns {string} Returns the kebab cased string.
13621 * _.kebabCase('Foo Bar');
13624 * _.kebabCase('fooBar');
13627 * _.kebabCase('__FOO_BAR__');
13630 var kebabCase = createCompounder(function(result, word, index) {
13631 return result + (index ? '-' : '') + word.toLowerCase();
13635 * Converts `string`, as space separated words, to lower case.
13641 * @param {string} [string=''] The string to convert.
13642 * @returns {string} Returns the lower cased string.
13645 * _.lowerCase('--Foo-Bar--');
13648 * _.lowerCase('fooBar');
13651 * _.lowerCase('__FOO_BAR__');
13654 var lowerCase = createCompounder(function(result, word, index) {
13655 return result + (index ? ' ' : '') + word.toLowerCase();
13659 * Converts the first character of `string` to lower case.
13665 * @param {string} [string=''] The string to convert.
13666 * @returns {string} Returns the converted string.
13669 * _.lowerFirst('Fred');
13672 * _.lowerFirst('FRED');
13675 var lowerFirst = createCaseFirst('toLowerCase');
13678 * Pads `string` on the left and right sides if it's shorter than `length`.
13679 * Padding characters are truncated if they can't be evenly divided by `length`.
13685 * @param {string} [string=''] The string to pad.
13686 * @param {number} [length=0] The padding length.
13687 * @param {string} [chars=' '] The string used as padding.
13688 * @returns {string} Returns the padded string.
13694 * _.pad('abc', 8, '_-');
13700 function pad(string, length, chars) {
13701 string = toString(string);
13702 length = toInteger(length);
13704 var strLength = length ? stringSize(string) : 0;
13705 if (!length || strLength >= length) {
13708 var mid = (length - strLength) / 2;
13710 createPadding(nativeFloor(mid), chars) +
13712 createPadding(nativeCeil(mid), chars)
13717 * Pads `string` on the right side if it's shorter than `length`. Padding
13718 * characters are truncated if they exceed `length`.
13724 * @param {string} [string=''] The string to pad.
13725 * @param {number} [length=0] The padding length.
13726 * @param {string} [chars=' '] The string used as padding.
13727 * @returns {string} Returns the padded string.
13730 * _.padEnd('abc', 6);
13733 * _.padEnd('abc', 6, '_-');
13736 * _.padEnd('abc', 3);
13739 function padEnd(string, length, chars) {
13740 string = toString(string);
13741 length = toInteger(length);
13743 var strLength = length ? stringSize(string) : 0;
13744 return (length && strLength < length)
13745 ? (string + createPadding(length - strLength, chars))
13750 * Pads `string` on the left side if it's shorter than `length`. Padding
13751 * characters are truncated if they exceed `length`.
13757 * @param {string} [string=''] The string to pad.
13758 * @param {number} [length=0] The padding length.
13759 * @param {string} [chars=' '] The string used as padding.
13760 * @returns {string} Returns the padded string.
13763 * _.padStart('abc', 6);
13766 * _.padStart('abc', 6, '_-');
13769 * _.padStart('abc', 3);
13772 function padStart(string, length, chars) {
13773 string = toString(string);
13774 length = toInteger(length);
13776 var strLength = length ? stringSize(string) : 0;
13777 return (length && strLength < length)
13778 ? (createPadding(length - strLength, chars) + string)
13783 * Converts `string` to an integer of the specified radix. If `radix` is
13784 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
13785 * hexadecimal, in which case a `radix` of `16` is used.
13787 * **Note:** This method aligns with the
13788 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
13794 * @param {string} string The string to convert.
13795 * @param {number} [radix=10] The radix to interpret `value` by.
13796 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
13797 * @returns {number} Returns the converted integer.
13800 * _.parseInt('08');
13803 * _.map(['6', '08', '10'], _.parseInt);
13806 function parseInt(string, radix, guard) {
13807 // Chrome fails to trim leading <BOM> whitespace characters.
13808 // See https://bugs.chromium.org/p/v8/issues/detail?id=3109 for more details.
13809 if (guard || radix == null) {
13811 } else if (radix) {
13814 string = toString(string).replace(reTrim, '');
13815 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
13819 * Repeats the given string `n` times.
13825 * @param {string} [string=''] The string to repeat.
13826 * @param {number} [n=1] The number of times to repeat the string.
13827 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
13828 * @returns {string} Returns the repeated string.
13831 * _.repeat('*', 3);
13834 * _.repeat('abc', 2);
13837 * _.repeat('abc', 0);
13840 function repeat(string, n, guard) {
13841 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
13846 return baseRepeat(toString(string), n);
13850 * Replaces matches for `pattern` in `string` with `replacement`.
13852 * **Note:** This method is based on
13853 * [`String#replace`](https://mdn.io/String/replace).
13859 * @param {string} [string=''] The string to modify.
13860 * @param {RegExp|string} pattern The pattern to replace.
13861 * @param {Function|string} replacement The match replacement.
13862 * @returns {string} Returns the modified string.
13865 * _.replace('Hi Fred', 'Fred', 'Barney');
13866 * // => 'Hi Barney'
13868 function replace() {
13869 var args = arguments,
13870 string = toString(args[0]);
13872 return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]);
13876 * Converts `string` to
13877 * [snake case](https://en.wikipedia.org/wiki/Snake_case).
13883 * @param {string} [string=''] The string to convert.
13884 * @returns {string} Returns the snake cased string.
13887 * _.snakeCase('Foo Bar');
13890 * _.snakeCase('fooBar');
13893 * _.snakeCase('--FOO-BAR--');
13896 var snakeCase = createCompounder(function(result, word, index) {
13897 return result + (index ? '_' : '') + word.toLowerCase();
13901 * Splits `string` by `separator`.
13903 * **Note:** This method is based on
13904 * [`String#split`](https://mdn.io/String/split).
13910 * @param {string} [string=''] The string to split.
13911 * @param {RegExp|string} separator The separator pattern to split by.
13912 * @param {number} [limit] The length to truncate results to.
13913 * @returns {Array} Returns the string segments.
13916 * _.split('a-b-c', '-', 2);
13919 function split(string, separator, limit) {
13920 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
13921 separator = limit = undefined;
13923 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
13927 string = toString(string);
13929 typeof separator == 'string' ||
13930 (separator != null && !isRegExp(separator))
13932 separator = baseToString(separator);
13933 if (separator == '' && reHasComplexSymbol.test(string)) {
13934 return castSlice(stringToArray(string), 0, limit);
13937 return nativeSplit.call(string, separator, limit);
13941 * Converts `string` to
13942 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
13948 * @param {string} [string=''] The string to convert.
13949 * @returns {string} Returns the start cased string.
13952 * _.startCase('--foo-bar--');
13955 * _.startCase('fooBar');
13958 * _.startCase('__FOO_BAR__');
13961 var startCase = createCompounder(function(result, word, index) {
13962 return result + (index ? ' ' : '') + upperFirst(word);
13966 * Checks if `string` starts with the given target string.
13972 * @param {string} [string=''] The string to search.
13973 * @param {string} [target] The string to search for.
13974 * @param {number} [position=0] The position to search from.
13975 * @returns {boolean} Returns `true` if `string` starts with `target`,
13979 * _.startsWith('abc', 'a');
13982 * _.startsWith('abc', 'b');
13985 * _.startsWith('abc', 'b', 1);
13988 function startsWith(string, target, position) {
13989 string = toString(string);
13990 position = baseClamp(toInteger(position), 0, string.length);
13991 return string.lastIndexOf(baseToString(target), position) == position;
13995 * Creates a compiled template function that can interpolate data properties
13996 * in "interpolate" delimiters, HTML-escape interpolated data properties in
13997 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
13998 * properties may be accessed as free variables in the template. If a setting
13999 * object is given, it takes precedence over `_.templateSettings` values.
14001 * **Note:** In the development build `_.template` utilizes
14002 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
14003 * for easier debugging.
14005 * For more information on precompiling templates see
14006 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
14008 * For more information on Chrome extension sandboxes see
14009 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
14015 * @param {string} [string=''] The template string.
14016 * @param {Object} [options={}] The options object.
14017 * @param {RegExp} [options.escape=_.templateSettings.escape]
14018 * The HTML "escape" delimiter.
14019 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
14020 * The "evaluate" delimiter.
14021 * @param {Object} [options.imports=_.templateSettings.imports]
14022 * An object to import into the template as free variables.
14023 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
14024 * The "interpolate" delimiter.
14025 * @param {string} [options.sourceURL='lodash.templateSources[n]']
14026 * The sourceURL of the compiled template.
14027 * @param {string} [options.variable='obj']
14028 * The data object variable name.
14029 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14030 * @returns {Function} Returns the compiled template function.
14033 * // Use the "interpolate" delimiter to create a compiled template.
14034 * var compiled = _.template('hello <%= user %>!');
14035 * compiled({ 'user': 'fred' });
14036 * // => 'hello fred!'
14038 * // Use the HTML "escape" delimiter to escape data property values.
14039 * var compiled = _.template('<b><%- value %></b>');
14040 * compiled({ 'value': '<script>' });
14041 * // => '<b><script></b>'
14043 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
14044 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
14045 * compiled({ 'users': ['fred', 'barney'] });
14046 * // => '<li>fred</li><li>barney</li>'
14048 * // Use the internal `print` function in "evaluate" delimiters.
14049 * var compiled = _.template('<% print("hello " + user); %>!');
14050 * compiled({ 'user': 'barney' });
14051 * // => 'hello barney!'
14053 * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
14054 * var compiled = _.template('hello ${ user }!');
14055 * compiled({ 'user': 'pebbles' });
14056 * // => 'hello pebbles!'
14058 * // Use backslashes to treat delimiters as plain text.
14059 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
14060 * compiled({ 'value': 'ignored' });
14061 * // => '<%- value %>'
14063 * // Use the `imports` option to import `jQuery` as `jq`.
14064 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
14065 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
14066 * compiled({ 'users': ['fred', 'barney'] });
14067 * // => '<li>fred</li><li>barney</li>'
14069 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
14070 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
14072 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
14074 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
14075 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
14077 * // => function(data) {
14078 * // var __t, __p = '';
14079 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
14083 * // Use custom template delimiters.
14084 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
14085 * var compiled = _.template('hello {{ user }}!');
14086 * compiled({ 'user': 'mustache' });
14087 * // => 'hello mustache!'
14089 * // Use the `source` property to inline compiled templates for meaningful
14090 * // line numbers in error messages and stack traces.
14091 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
14093 * "main": ' + _.template(mainText).source + '\
14097 function template(string, options, guard) {
14098 // Based on John Resig's `tmpl` implementation
14099 // (http://ejohn.org/blog/javascript-micro-templating/)
14100 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
14101 var settings = lodash.templateSettings;
14103 if (guard && isIterateeCall(string, options, guard)) {
14104 options = undefined;
14106 string = toString(string);
14107 options = assignInWith({}, options, settings, assignInDefaults);
14109 var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
14110 importsKeys = keys(imports),
14111 importsValues = baseValues(imports, importsKeys);
14116 interpolate = options.interpolate || reNoMatch,
14117 source = "__p += '";
14119 // Compile the regexp to match each delimiter.
14120 var reDelimiters = RegExp(
14121 (options.escape || reNoMatch).source + '|' +
14122 interpolate.source + '|' +
14123 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
14124 (options.evaluate || reNoMatch).source + '|$'
14127 // Use a sourceURL for easier debugging.
14128 var sourceURL = '//# sourceURL=' +
14129 ('sourceURL' in options
14130 ? options.sourceURL
14131 : ('lodash.templateSources[' + (++templateCounter) + ']')
14134 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
14135 interpolateValue || (interpolateValue = esTemplateValue);
14137 // Escape characters that can't be included in string literals.
14138 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
14140 // Replace delimiters with snippets.
14143 source += "' +\n__e(" + escapeValue + ") +\n'";
14145 if (evaluateValue) {
14146 isEvaluating = true;
14147 source += "';\n" + evaluateValue + ";\n__p += '";
14149 if (interpolateValue) {
14150 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
14152 index = offset + match.length;
14154 // The JS engine embedded in Adobe products needs `match` returned in
14155 // order to produce the correct `offset` value.
14161 // If `variable` is not specified wrap a with-statement around the generated
14162 // code to add the data object to the top of the scope chain.
14163 var variable = options.variable;
14165 source = 'with (obj) {\n' + source + '\n}\n';
14167 // Cleanup code by stripping empty strings.
14168 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
14169 .replace(reEmptyStringMiddle, '$1')
14170 .replace(reEmptyStringTrailing, '$1;');
14172 // Frame code as the function body.
14173 source = 'function(' + (variable || 'obj') + ') {\n' +
14176 : 'obj || (obj = {});\n'
14178 "var __t, __p = ''" +
14180 ? ', __e = _.escape'
14184 ? ', __j = Array.prototype.join;\n' +
14185 "function print() { __p += __j.call(arguments, '') }\n"
14191 var result = attempt(function() {
14192 return Function(importsKeys, sourceURL + 'return ' + source)
14193 .apply(undefined, importsValues);
14196 // Provide the compiled function's source by its `toString` method or
14197 // the `source` property as a convenience for inlining compiled templates.
14198 result.source = source;
14199 if (isError(result)) {
14206 * Converts `string`, as a whole, to lower case just like
14207 * [String#toLowerCase](https://mdn.io/toLowerCase).
14213 * @param {string} [string=''] The string to convert.
14214 * @returns {string} Returns the lower cased string.
14217 * _.toLower('--Foo-Bar--');
14218 * // => '--foo-bar--'
14220 * _.toLower('fooBar');
14223 * _.toLower('__FOO_BAR__');
14224 * // => '__foo_bar__'
14226 function toLower(value) {
14227 return toString(value).toLowerCase();
14231 * Converts `string`, as a whole, to upper case just like
14232 * [String#toUpperCase](https://mdn.io/toUpperCase).
14238 * @param {string} [string=''] The string to convert.
14239 * @returns {string} Returns the upper cased string.
14242 * _.toUpper('--foo-bar--');
14243 * // => '--FOO-BAR--'
14245 * _.toUpper('fooBar');
14248 * _.toUpper('__foo_bar__');
14249 * // => '__FOO_BAR__'
14251 function toUpper(value) {
14252 return toString(value).toUpperCase();
14256 * Removes leading and trailing whitespace or specified characters from `string`.
14262 * @param {string} [string=''] The string to trim.
14263 * @param {string} [chars=whitespace] The characters to trim.
14264 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14265 * @returns {string} Returns the trimmed string.
14271 * _.trim('-_-abc-_-', '_-');
14274 * _.map([' foo ', ' bar '], _.trim);
14275 * // => ['foo', 'bar']
14277 function trim(string, chars, guard) {
14278 string = toString(string);
14279 if (string && (guard || chars === undefined)) {
14280 return string.replace(reTrim, '');
14282 if (!string || !(chars = baseToString(chars))) {
14285 var strSymbols = stringToArray(string),
14286 chrSymbols = stringToArray(chars),
14287 start = charsStartIndex(strSymbols, chrSymbols),
14288 end = charsEndIndex(strSymbols, chrSymbols) + 1;
14290 return castSlice(strSymbols, start, end).join('');
14294 * Removes trailing whitespace or specified characters from `string`.
14300 * @param {string} [string=''] The string to trim.
14301 * @param {string} [chars=whitespace] The characters to trim.
14302 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14303 * @returns {string} Returns the trimmed string.
14306 * _.trimEnd(' abc ');
14309 * _.trimEnd('-_-abc-_-', '_-');
14312 function trimEnd(string, chars, guard) {
14313 string = toString(string);
14314 if (string && (guard || chars === undefined)) {
14315 return string.replace(reTrimEnd, '');
14317 if (!string || !(chars = baseToString(chars))) {
14320 var strSymbols = stringToArray(string),
14321 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
14323 return castSlice(strSymbols, 0, end).join('');
14327 * Removes leading whitespace or specified characters from `string`.
14333 * @param {string} [string=''] The string to trim.
14334 * @param {string} [chars=whitespace] The characters to trim.
14335 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14336 * @returns {string} Returns the trimmed string.
14339 * _.trimStart(' abc ');
14342 * _.trimStart('-_-abc-_-', '_-');
14345 function trimStart(string, chars, guard) {
14346 string = toString(string);
14347 if (string && (guard || chars === undefined)) {
14348 return string.replace(reTrimStart, '');
14350 if (!string || !(chars = baseToString(chars))) {
14353 var strSymbols = stringToArray(string),
14354 start = charsStartIndex(strSymbols, stringToArray(chars));
14356 return castSlice(strSymbols, start).join('');
14360 * Truncates `string` if it's longer than the given maximum string length.
14361 * The last characters of the truncated string are replaced with the omission
14362 * string which defaults to "...".
14368 * @param {string} [string=''] The string to truncate.
14369 * @param {Object} [options={}] The options object.
14370 * @param {number} [options.length=30] The maximum string length.
14371 * @param {string} [options.omission='...'] The string to indicate text is omitted.
14372 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
14373 * @returns {string} Returns the truncated string.
14376 * _.truncate('hi-diddly-ho there, neighborino');
14377 * // => 'hi-diddly-ho there, neighbo...'
14379 * _.truncate('hi-diddly-ho there, neighborino', {
14383 * // => 'hi-diddly-ho there,...'
14385 * _.truncate('hi-diddly-ho there, neighborino', {
14387 * 'separator': /,? +/
14389 * // => 'hi-diddly-ho there...'
14391 * _.truncate('hi-diddly-ho there, neighborino', {
14392 * 'omission': ' [...]'
14394 * // => 'hi-diddly-ho there, neig [...]'
14396 function truncate(string, options) {
14397 var length = DEFAULT_TRUNC_LENGTH,
14398 omission = DEFAULT_TRUNC_OMISSION;
14400 if (isObject(options)) {
14401 var separator = 'separator' in options ? options.separator : separator;
14402 length = 'length' in options ? toInteger(options.length) : length;
14403 omission = 'omission' in options ? baseToString(options.omission) : omission;
14405 string = toString(string);
14407 var strLength = string.length;
14408 if (reHasComplexSymbol.test(string)) {
14409 var strSymbols = stringToArray(string);
14410 strLength = strSymbols.length;
14412 if (length >= strLength) {
14415 var end = length - stringSize(omission);
14419 var result = strSymbols
14420 ? castSlice(strSymbols, 0, end).join('')
14421 : string.slice(0, end);
14423 if (separator === undefined) {
14424 return result + omission;
14427 end += (result.length - end);
14429 if (isRegExp(separator)) {
14430 if (string.slice(end).search(separator)) {
14432 substring = result;
14434 if (!separator.global) {
14435 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
14437 separator.lastIndex = 0;
14438 while ((match = separator.exec(substring))) {
14439 var newEnd = match.index;
14441 result = result.slice(0, newEnd === undefined ? end : newEnd);
14443 } else if (string.indexOf(baseToString(separator), end) != end) {
14444 var index = result.lastIndexOf(separator);
14446 result = result.slice(0, index);
14449 return result + omission;
14453 * The inverse of `_.escape`; this method converts the HTML entities
14454 * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to
14455 * their corresponding characters.
14457 * **Note:** No other HTML entities are unescaped. To unescape additional
14458 * HTML entities use a third-party library like [_he_](https://mths.be/he).
14464 * @param {string} [string=''] The string to unescape.
14465 * @returns {string} Returns the unescaped string.
14468 * _.unescape('fred, barney, & pebbles');
14469 * // => 'fred, barney, & pebbles'
14471 function unescape(string) {
14472 string = toString(string);
14473 return (string && reHasEscapedHtml.test(string))
14474 ? string.replace(reEscapedHtml, unescapeHtmlChar)
14479 * Converts `string`, as space separated words, to upper case.
14485 * @param {string} [string=''] The string to convert.
14486 * @returns {string} Returns the upper cased string.
14489 * _.upperCase('--foo-bar');
14492 * _.upperCase('fooBar');
14495 * _.upperCase('__foo_bar__');
14498 var upperCase = createCompounder(function(result, word, index) {
14499 return result + (index ? ' ' : '') + word.toUpperCase();
14503 * Converts the first character of `string` to upper case.
14509 * @param {string} [string=''] The string to convert.
14510 * @returns {string} Returns the converted string.
14513 * _.upperFirst('fred');
14516 * _.upperFirst('FRED');
14519 var upperFirst = createCaseFirst('toUpperCase');
14522 * Splits `string` into an array of its words.
14528 * @param {string} [string=''] The string to inspect.
14529 * @param {RegExp|string} [pattern] The pattern to match words.
14530 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14531 * @returns {Array} Returns the words of `string`.
14534 * _.words('fred, barney, & pebbles');
14535 * // => ['fred', 'barney', 'pebbles']
14537 * _.words('fred, barney, & pebbles', /[^, ]+/g);
14538 * // => ['fred', 'barney', '&', 'pebbles']
14540 function words(string, pattern, guard) {
14541 string = toString(string);
14542 pattern = guard ? undefined : pattern;
14544 if (pattern === undefined) {
14545 pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
14547 return string.match(pattern) || [];
14550 /*------------------------------------------------------------------------*/
14553 * Attempts to invoke `func`, returning either the result or the caught error
14554 * object. Any additional arguments are provided to `func` when it's invoked.
14560 * @param {Function} func The function to attempt.
14561 * @param {...*} [args] The arguments to invoke `func` with.
14562 * @returns {*} Returns the `func` result or error object.
14565 * // Avoid throwing errors for invalid selectors.
14566 * var elements = _.attempt(function(selector) {
14567 * return document.querySelectorAll(selector);
14570 * if (_.isError(elements)) {
14574 var attempt = rest(function(func, args) {
14576 return apply(func, undefined, args);
14578 return isError(e) ? e : new Error(e);
14583 * Binds methods of an object to the object itself, overwriting the existing
14586 * **Note:** This method doesn't set the "length" property of bound functions.
14592 * @param {Object} object The object to bind and assign the bound methods to.
14593 * @param {...(string|string[])} methodNames The object method names to bind.
14594 * @returns {Object} Returns `object`.
14599 * 'onClick': function() {
14600 * console.log('clicked ' + this.label);
14604 * _.bindAll(view, ['onClick']);
14605 * jQuery(element).on('click', view.onClick);
14606 * // => Logs 'clicked docs' when clicked.
14608 var bindAll = rest(function(object, methodNames) {
14609 arrayEach(baseFlatten(methodNames, 1), function(key) {
14611 object[key] = bind(object[key], object);
14617 * Creates a function that iterates over `pairs` and invokes the corresponding
14618 * function of the first predicate to return truthy. The predicate-function
14619 * pairs are invoked with the `this` binding and arguments of the created
14626 * @param {Array} pairs The predicate-function pairs.
14627 * @returns {Function} Returns the new composite function.
14630 * var func = _.cond([
14631 * [_.matches({ 'a': 1 }), _.constant('matches A')],
14632 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
14633 * [_.constant(true), _.constant('no match')]
14636 * func({ 'a': 1, 'b': 2 });
14637 * // => 'matches A'
14639 * func({ 'a': 0, 'b': 1 });
14640 * // => 'matches B'
14642 * func({ 'a': '1', 'b': '2' });
14645 function cond(pairs) {
14646 var length = pairs ? pairs.length : 0,
14647 toIteratee = getIteratee();
14649 pairs = !length ? [] : arrayMap(pairs, function(pair) {
14650 if (typeof pair[1] != 'function') {
14651 throw new TypeError(FUNC_ERROR_TEXT);
14653 return [toIteratee(pair[0]), pair[1]];
14656 return rest(function(args) {
14658 while (++index < length) {
14659 var pair = pairs[index];
14660 if (apply(pair[0], this, args)) {
14661 return apply(pair[1], this, args);
14668 * Creates a function that invokes the predicate properties of `source` with
14669 * the corresponding property values of a given object, returning `true` if
14670 * all predicates return truthy, else `false`.
14676 * @param {Object} source The object of property predicates to conform to.
14677 * @returns {Function} Returns the new spec function.
14681 * { 'user': 'barney', 'age': 36 },
14682 * { 'user': 'fred', 'age': 40 }
14685 * _.filter(users, _.conforms({ 'age': function(n) { return n > 38; } }));
14686 * // => [{ 'user': 'fred', 'age': 40 }]
14688 function conforms(source) {
14689 return baseConforms(baseClone(source, true));
14693 * Creates a function that returns `value`.
14699 * @param {*} value The value to return from the new function.
14700 * @returns {Function} Returns the new constant function.
14703 * var objects = _.times(2, _.constant({ 'a': 1 }));
14705 * console.log(objects);
14706 * // => [{ 'a': 1 }, { 'a': 1 }]
14708 * console.log(objects[0] === objects[1]);
14711 function constant(value) {
14712 return function() {
14718 * Creates a function that returns the result of invoking the given functions
14719 * with the `this` binding of the created function, where each successive
14720 * invocation is supplied the return value of the previous.
14726 * @param {...(Function|Function[])} [funcs] Functions to invoke.
14727 * @returns {Function} Returns the new composite function.
14731 * function square(n) {
14735 * var addSquare = _.flow([_.add, square]);
14739 var flow = createFlow();
14742 * This method is like `_.flow` except that it creates a function that
14743 * invokes the given functions from right to left.
14749 * @param {...(Function|Function[])} [funcs] Functions to invoke.
14750 * @returns {Function} Returns the new composite function.
14754 * function square(n) {
14758 * var addSquare = _.flowRight([square, _.add]);
14762 var flowRight = createFlow(true);
14765 * This method returns the first argument given to it.
14771 * @param {*} value Any value.
14772 * @returns {*} Returns `value`.
14775 * var object = { 'user': 'fred' };
14777 * console.log(_.identity(object) === object);
14780 function identity(value) {
14785 * Creates a function that invokes `func` with the arguments of the created
14786 * function. If `func` is a property name, the created function returns the
14787 * property value for a given element. If `func` is an array or object, the
14788 * created function returns `true` for elements that contain the equivalent
14789 * source properties, otherwise it returns `false`.
14795 * @param {*} [func=_.identity] The value to convert to a callback.
14796 * @returns {Function} Returns the callback.
14800 * { 'user': 'barney', 'age': 36, 'active': true },
14801 * { 'user': 'fred', 'age': 40, 'active': false }
14804 * // The `_.matches` iteratee shorthand.
14805 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
14806 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
14808 * // The `_.matchesProperty` iteratee shorthand.
14809 * _.filter(users, _.iteratee(['user', 'fred']));
14810 * // => [{ 'user': 'fred', 'age': 40 }]
14812 * // The `_.property` iteratee shorthand.
14813 * _.map(users, _.iteratee('user'));
14814 * // => ['barney', 'fred']
14816 * // Create custom iteratee shorthands.
14817 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
14818 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
14819 * return func.test(string);
14823 * _.filter(['abc', 'def'], /ef/);
14826 function iteratee(func) {
14827 return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
14831 * Creates a function that performs a partial deep comparison between a given
14832 * object and `source`, returning `true` if the given object has equivalent
14833 * property values, else `false`. The created function is equivalent to
14834 * `_.isMatch` with a `source` partially applied.
14836 * **Note:** This method supports comparing the same values as `_.isEqual`.
14842 * @param {Object} source The object of property values to match.
14843 * @returns {Function} Returns the new spec function.
14847 * { 'user': 'barney', 'age': 36, 'active': true },
14848 * { 'user': 'fred', 'age': 40, 'active': false }
14851 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
14852 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
14854 function matches(source) {
14855 return baseMatches(baseClone(source, true));
14859 * Creates a function that performs a partial deep comparison between the
14860 * value at `path` of a given object to `srcValue`, returning `true` if the
14861 * object value is equivalent, else `false`.
14863 * **Note:** This method supports comparing the same values as `_.isEqual`.
14869 * @param {Array|string} path The path of the property to get.
14870 * @param {*} srcValue The value to match.
14871 * @returns {Function} Returns the new spec function.
14875 * { 'user': 'barney' },
14876 * { 'user': 'fred' }
14879 * _.find(users, _.matchesProperty('user', 'fred'));
14880 * // => { 'user': 'fred' }
14882 function matchesProperty(path, srcValue) {
14883 return baseMatchesProperty(path, baseClone(srcValue, true));
14887 * Creates a function that invokes the method at `path` of a given object.
14888 * Any additional arguments are provided to the invoked method.
14894 * @param {Array|string} path The path of the method to invoke.
14895 * @param {...*} [args] The arguments to invoke the method with.
14896 * @returns {Function} Returns the new invoker function.
14900 * { 'a': { 'b': _.constant(2) } },
14901 * { 'a': { 'b': _.constant(1) } }
14904 * _.map(objects, _.method('a.b'));
14907 * _.map(objects, _.method(['a', 'b']));
14910 var method = rest(function(path, args) {
14911 return function(object) {
14912 return baseInvoke(object, path, args);
14917 * The opposite of `_.method`; this method creates a function that invokes
14918 * the method at a given path of `object`. Any additional arguments are
14919 * provided to the invoked method.
14925 * @param {Object} object The object to query.
14926 * @param {...*} [args] The arguments to invoke the method with.
14927 * @returns {Function} Returns the new invoker function.
14930 * var array = _.times(3, _.constant),
14931 * object = { 'a': array, 'b': array, 'c': array };
14933 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
14936 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
14939 var methodOf = rest(function(object, args) {
14940 return function(path) {
14941 return baseInvoke(object, path, args);
14946 * Adds all own enumerable string keyed function properties of a source
14947 * object to the destination object. If `object` is a function, then methods
14948 * are added to its prototype as well.
14950 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
14951 * avoid conflicts caused by modifying the original.
14957 * @param {Function|Object} [object=lodash] The destination object.
14958 * @param {Object} source The object of functions to add.
14959 * @param {Object} [options={}] The options object.
14960 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
14961 * @returns {Function|Object} Returns `object`.
14964 * function vowels(string) {
14965 * return _.filter(string, function(v) {
14966 * return /[aeiou]/i.test(v);
14970 * _.mixin({ 'vowels': vowels });
14971 * _.vowels('fred');
14974 * _('fred').vowels().value();
14977 * _.mixin({ 'vowels': vowels }, { 'chain': false });
14978 * _('fred').vowels();
14981 function mixin(object, source, options) {
14982 var props = keys(source),
14983 methodNames = baseFunctions(source, props);
14985 if (options == null &&
14986 !(isObject(source) && (methodNames.length || !props.length))) {
14990 methodNames = baseFunctions(source, keys(source));
14992 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
14993 isFunc = isFunction(object);
14995 arrayEach(methodNames, function(methodName) {
14996 var func = source[methodName];
14997 object[methodName] = func;
14999 object.prototype[methodName] = function() {
15000 var chainAll = this.__chain__;
15001 if (chain || chainAll) {
15002 var result = object(this.__wrapped__),
15003 actions = result.__actions__ = copyArray(this.__actions__);
15005 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
15006 result.__chain__ = chainAll;
15009 return func.apply(object, arrayPush([this.value()], arguments));
15018 * Reverts the `_` variable to its previous value and returns a reference to
15019 * the `lodash` function.
15025 * @returns {Function} Returns the `lodash` function.
15028 * var lodash = _.noConflict();
15030 function noConflict() {
15031 if (root._ === this) {
15038 * A method that returns `undefined`.
15046 * _.times(2, _.noop);
15047 * // => [undefined, undefined]
15050 // No operation performed.
15054 * Creates a function that gets the argument at index `n`. If `n` is negative,
15055 * the nth argument from the end is returned.
15061 * @param {number} [n=0] The index of the argument to return.
15062 * @returns {Function} Returns the new pass-thru function.
15065 * var func = _.nthArg(1);
15066 * func('a', 'b', 'c', 'd');
15069 * var func = _.nthArg(-2);
15070 * func('a', 'b', 'c', 'd');
15073 function nthArg(n) {
15075 return rest(function(args) {
15076 return baseNth(args, n);
15081 * Creates a function that invokes `iteratees` with the arguments it receives
15082 * and returns their results.
15088 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
15089 * [iteratees=[_.identity]] The iteratees to invoke.
15090 * @returns {Function} Returns the new function.
15093 * var func = _.over([Math.max, Math.min]);
15095 * func(1, 2, 3, 4);
15098 var over = createOver(arrayMap);
15101 * Creates a function that checks if **all** of the `predicates` return
15102 * truthy when invoked with the arguments it receives.
15108 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
15109 * [predicates=[_.identity]] The predicates to check.
15110 * @returns {Function} Returns the new function.
15113 * var func = _.overEvery([Boolean, isFinite]);
15124 var overEvery = createOver(arrayEvery);
15127 * Creates a function that checks if **any** of the `predicates` return
15128 * truthy when invoked with the arguments it receives.
15134 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
15135 * [predicates=[_.identity]] The predicates to check.
15136 * @returns {Function} Returns the new function.
15139 * var func = _.overSome([Boolean, isFinite]);
15150 var overSome = createOver(arraySome);
15153 * Creates a function that returns the value at `path` of a given object.
15159 * @param {Array|string} path The path of the property to get.
15160 * @returns {Function} Returns the new accessor function.
15164 * { 'a': { 'b': 2 } },
15165 * { 'a': { 'b': 1 } }
15168 * _.map(objects, _.property('a.b'));
15171 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
15174 function property(path) {
15175 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
15179 * The opposite of `_.property`; this method creates a function that returns
15180 * the value at a given path of `object`.
15186 * @param {Object} object The object to query.
15187 * @returns {Function} Returns the new accessor function.
15190 * var array = [0, 1, 2],
15191 * object = { 'a': array, 'b': array, 'c': array };
15193 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
15196 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
15199 function propertyOf(object) {
15200 return function(path) {
15201 return object == null ? undefined : baseGet(object, path);
15206 * Creates an array of numbers (positive and/or negative) progressing from
15207 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
15208 * `start` is specified without an `end` or `step`. If `end` is not specified,
15209 * it's set to `start` with `start` then set to `0`.
15211 * **Note:** JavaScript follows the IEEE-754 standard for resolving
15212 * floating-point values which can produce unexpected results.
15218 * @param {number} [start=0] The start of the range.
15219 * @param {number} end The end of the range.
15220 * @param {number} [step=1] The value to increment or decrement by.
15221 * @returns {Array} Returns the range of numbers.
15222 * @see _.inRange, _.rangeRight
15226 * // => [0, 1, 2, 3]
15229 * // => [0, -1, -2, -3]
15232 * // => [1, 2, 3, 4]
15234 * _.range(0, 20, 5);
15235 * // => [0, 5, 10, 15]
15237 * _.range(0, -4, -1);
15238 * // => [0, -1, -2, -3]
15240 * _.range(1, 4, 0);
15246 var range = createRange();
15249 * This method is like `_.range` except that it populates values in
15250 * descending order.
15256 * @param {number} [start=0] The start of the range.
15257 * @param {number} end The end of the range.
15258 * @param {number} [step=1] The value to increment or decrement by.
15259 * @returns {Array} Returns the range of numbers.
15260 * @see _.inRange, _.range
15264 * // => [3, 2, 1, 0]
15266 * _.rangeRight(-4);
15267 * // => [-3, -2, -1, 0]
15269 * _.rangeRight(1, 5);
15270 * // => [4, 3, 2, 1]
15272 * _.rangeRight(0, 20, 5);
15273 * // => [15, 10, 5, 0]
15275 * _.rangeRight(0, -4, -1);
15276 * // => [-3, -2, -1, 0]
15278 * _.rangeRight(1, 4, 0);
15284 var rangeRight = createRange(true);
15287 * A method that returns a new empty array.
15293 * @returns {Array} Returns the new empty array.
15296 * var arrays = _.times(2, _.stubArray);
15298 * console.log(arrays);
15301 * console.log(arrays[0] === arrays[1]);
15304 function stubArray() {
15309 * A method that returns `false`.
15315 * @returns {boolean} Returns `false`.
15318 * _.times(2, _.stubFalse);
15319 * // => [false, false]
15321 function stubFalse() {
15326 * A method that returns a new empty object.
15332 * @returns {Object} Returns the new empty object.
15335 * var objects = _.times(2, _.stubObject);
15337 * console.log(objects);
15340 * console.log(objects[0] === objects[1]);
15343 function stubObject() {
15348 * A method that returns an empty string.
15354 * @returns {string} Returns the empty string.
15357 * _.times(2, _.stubString);
15360 function stubString() {
15365 * A method that returns `true`.
15371 * @returns {boolean} Returns `true`.
15374 * _.times(2, _.stubTrue);
15375 * // => [true, true]
15377 function stubTrue() {
15382 * Invokes the iteratee `n` times, returning an array of the results of
15383 * each invocation. The iteratee is invoked with one argument; (index).
15389 * @param {number} n The number of times to invoke `iteratee`.
15390 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
15391 * @returns {Array} Returns the array of results.
15394 * _.times(3, String);
15395 * // => ['0', '1', '2']
15397 * _.times(4, _.constant(0));
15398 * // => [0, 0, 0, 0]
15400 function times(n, iteratee) {
15402 if (n < 1 || n > MAX_SAFE_INTEGER) {
15405 var index = MAX_ARRAY_LENGTH,
15406 length = nativeMin(n, MAX_ARRAY_LENGTH);
15408 iteratee = getIteratee(iteratee);
15409 n -= MAX_ARRAY_LENGTH;
15411 var result = baseTimes(length, iteratee);
15412 while (++index < n) {
15419 * Converts `value` to a property path array.
15425 * @param {*} value The value to convert.
15426 * @returns {Array} Returns the new property path array.
15429 * _.toPath('a.b.c');
15430 * // => ['a', 'b', 'c']
15432 * _.toPath('a[0].b.c');
15433 * // => ['a', '0', 'b', 'c']
15435 function toPath(value) {
15436 if (isArray(value)) {
15437 return arrayMap(value, toKey);
15439 return isSymbol(value) ? [value] : copyArray(stringToPath(value));
15443 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
15449 * @param {string} [prefix=''] The value to prefix the ID with.
15450 * @returns {string} Returns the unique ID.
15453 * _.uniqueId('contact_');
15454 * // => 'contact_104'
15459 function uniqueId(prefix) {
15460 var id = ++idCounter;
15461 return toString(prefix) + id;
15464 /*------------------------------------------------------------------------*/
15467 * Adds two numbers.
15473 * @param {number} augend The first number in an addition.
15474 * @param {number} addend The second number in an addition.
15475 * @returns {number} Returns the total.
15481 var add = createMathOperation(function(augend, addend) {
15482 return augend + addend;
15486 * Computes `number` rounded up to `precision`.
15492 * @param {number} number The number to round up.
15493 * @param {number} [precision=0] The precision to round up to.
15494 * @returns {number} Returns the rounded up number.
15500 * _.ceil(6.004, 2);
15503 * _.ceil(6040, -2);
15506 var ceil = createRound('ceil');
15509 * Divide two numbers.
15515 * @param {number} dividend The first number in a division.
15516 * @param {number} divisor The second number in a division.
15517 * @returns {number} Returns the quotient.
15523 var divide = createMathOperation(function(dividend, divisor) {
15524 return dividend / divisor;
15528 * Computes `number` rounded down to `precision`.
15534 * @param {number} number The number to round down.
15535 * @param {number} [precision=0] The precision to round down to.
15536 * @returns {number} Returns the rounded down number.
15542 * _.floor(0.046, 2);
15545 * _.floor(4060, -2);
15548 var floor = createRound('floor');
15551 * Computes the maximum value of `array`. If `array` is empty or falsey,
15552 * `undefined` is returned.
15558 * @param {Array} array The array to iterate over.
15559 * @returns {*} Returns the maximum value.
15562 * _.max([4, 2, 8, 6]);
15568 function max(array) {
15569 return (array && array.length)
15570 ? baseExtremum(array, identity, baseGt)
15575 * This method is like `_.max` except that it accepts `iteratee` which is
15576 * invoked for each element in `array` to generate the criterion by which
15577 * the value is ranked. The iteratee is invoked with one argument: (value).
15583 * @param {Array} array The array to iterate over.
15584 * @param {Array|Function|Object|string} [iteratee=_.identity]
15585 * The iteratee invoked per element.
15586 * @returns {*} Returns the maximum value.
15589 * var objects = [{ 'n': 1 }, { 'n': 2 }];
15591 * _.maxBy(objects, function(o) { return o.n; });
15594 * // The `_.property` iteratee shorthand.
15595 * _.maxBy(objects, 'n');
15598 function maxBy(array, iteratee) {
15599 return (array && array.length)
15600 ? baseExtremum(array, getIteratee(iteratee), baseGt)
15605 * Computes the mean of the values in `array`.
15611 * @param {Array} array The array to iterate over.
15612 * @returns {number} Returns the mean.
15615 * _.mean([4, 2, 8, 6]);
15618 function mean(array) {
15619 return baseMean(array, identity);
15623 * This method is like `_.mean` except that it accepts `iteratee` which is
15624 * invoked for each element in `array` to generate the value to be averaged.
15625 * The iteratee is invoked with one argument: (value).
15631 * @param {Array} array The array to iterate over.
15632 * @param {Array|Function|Object|string} [iteratee=_.identity]
15633 * The iteratee invoked per element.
15634 * @returns {number} Returns the mean.
15637 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
15639 * _.meanBy(objects, function(o) { return o.n; });
15642 * // The `_.property` iteratee shorthand.
15643 * _.meanBy(objects, 'n');
15646 function meanBy(array, iteratee) {
15647 return baseMean(array, getIteratee(iteratee));
15651 * Computes the minimum value of `array`. If `array` is empty or falsey,
15652 * `undefined` is returned.
15658 * @param {Array} array The array to iterate over.
15659 * @returns {*} Returns the minimum value.
15662 * _.min([4, 2, 8, 6]);
15668 function min(array) {
15669 return (array && array.length)
15670 ? baseExtremum(array, identity, baseLt)
15675 * This method is like `_.min` except that it accepts `iteratee` which is
15676 * invoked for each element in `array` to generate the criterion by which
15677 * the value is ranked. The iteratee is invoked with one argument: (value).
15683 * @param {Array} array The array to iterate over.
15684 * @param {Array|Function|Object|string} [iteratee=_.identity]
15685 * The iteratee invoked per element.
15686 * @returns {*} Returns the minimum value.
15689 * var objects = [{ 'n': 1 }, { 'n': 2 }];
15691 * _.minBy(objects, function(o) { return o.n; });
15694 * // The `_.property` iteratee shorthand.
15695 * _.minBy(objects, 'n');
15698 function minBy(array, iteratee) {
15699 return (array && array.length)
15700 ? baseExtremum(array, getIteratee(iteratee), baseLt)
15705 * Multiply two numbers.
15711 * @param {number} multiplier The first number in a multiplication.
15712 * @param {number} multiplicand The second number in a multiplication.
15713 * @returns {number} Returns the product.
15716 * _.multiply(6, 4);
15719 var multiply = createMathOperation(function(multiplier, multiplicand) {
15720 return multiplier * multiplicand;
15724 * Computes `number` rounded to `precision`.
15730 * @param {number} number The number to round.
15731 * @param {number} [precision=0] The precision to round to.
15732 * @returns {number} Returns the rounded number.
15738 * _.round(4.006, 2);
15741 * _.round(4060, -2);
15744 var round = createRound('round');
15747 * Subtract two numbers.
15753 * @param {number} minuend The first number in a subtraction.
15754 * @param {number} subtrahend The second number in a subtraction.
15755 * @returns {number} Returns the difference.
15758 * _.subtract(6, 4);
15761 var subtract = createMathOperation(function(minuend, subtrahend) {
15762 return minuend - subtrahend;
15766 * Computes the sum of the values in `array`.
15772 * @param {Array} array The array to iterate over.
15773 * @returns {number} Returns the sum.
15776 * _.sum([4, 2, 8, 6]);
15779 function sum(array) {
15780 return (array && array.length)
15781 ? baseSum(array, identity)
15786 * This method is like `_.sum` except that it accepts `iteratee` which is
15787 * invoked for each element in `array` to generate the value to be summed.
15788 * The iteratee is invoked with one argument: (value).
15794 * @param {Array} array The array to iterate over.
15795 * @param {Array|Function|Object|string} [iteratee=_.identity]
15796 * The iteratee invoked per element.
15797 * @returns {number} Returns the sum.
15800 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
15802 * _.sumBy(objects, function(o) { return o.n; });
15805 * // The `_.property` iteratee shorthand.
15806 * _.sumBy(objects, 'n');
15809 function sumBy(array, iteratee) {
15810 return (array && array.length)
15811 ? baseSum(array, getIteratee(iteratee))
15815 /*------------------------------------------------------------------------*/
15817 // Add methods that return wrapped values in chain sequences.
15818 lodash.after = after;
15820 lodash.assign = assign;
15821 lodash.assignIn = assignIn;
15822 lodash.assignInWith = assignInWith;
15823 lodash.assignWith = assignWith;
15825 lodash.before = before;
15826 lodash.bind = bind;
15827 lodash.bindAll = bindAll;
15828 lodash.bindKey = bindKey;
15829 lodash.castArray = castArray;
15830 lodash.chain = chain;
15831 lodash.chunk = chunk;
15832 lodash.compact = compact;
15833 lodash.concat = concat;
15834 lodash.cond = cond;
15835 lodash.conforms = conforms;
15836 lodash.constant = constant;
15837 lodash.countBy = countBy;
15838 lodash.create = create;
15839 lodash.curry = curry;
15840 lodash.curryRight = curryRight;
15841 lodash.debounce = debounce;
15842 lodash.defaults = defaults;
15843 lodash.defaultsDeep = defaultsDeep;
15844 lodash.defer = defer;
15845 lodash.delay = delay;
15846 lodash.difference = difference;
15847 lodash.differenceBy = differenceBy;
15848 lodash.differenceWith = differenceWith;
15849 lodash.drop = drop;
15850 lodash.dropRight = dropRight;
15851 lodash.dropRightWhile = dropRightWhile;
15852 lodash.dropWhile = dropWhile;
15853 lodash.fill = fill;
15854 lodash.filter = filter;
15855 lodash.flatMap = flatMap;
15856 lodash.flatMapDeep = flatMapDeep;
15857 lodash.flatMapDepth = flatMapDepth;
15858 lodash.flatten = flatten;
15859 lodash.flattenDeep = flattenDeep;
15860 lodash.flattenDepth = flattenDepth;
15861 lodash.flip = flip;
15862 lodash.flow = flow;
15863 lodash.flowRight = flowRight;
15864 lodash.fromPairs = fromPairs;
15865 lodash.functions = functions;
15866 lodash.functionsIn = functionsIn;
15867 lodash.groupBy = groupBy;
15868 lodash.initial = initial;
15869 lodash.intersection = intersection;
15870 lodash.intersectionBy = intersectionBy;
15871 lodash.intersectionWith = intersectionWith;
15872 lodash.invert = invert;
15873 lodash.invertBy = invertBy;
15874 lodash.invokeMap = invokeMap;
15875 lodash.iteratee = iteratee;
15876 lodash.keyBy = keyBy;
15877 lodash.keys = keys;
15878 lodash.keysIn = keysIn;
15880 lodash.mapKeys = mapKeys;
15881 lodash.mapValues = mapValues;
15882 lodash.matches = matches;
15883 lodash.matchesProperty = matchesProperty;
15884 lodash.memoize = memoize;
15885 lodash.merge = merge;
15886 lodash.mergeWith = mergeWith;
15887 lodash.method = method;
15888 lodash.methodOf = methodOf;
15889 lodash.mixin = mixin;
15890 lodash.negate = negate;
15891 lodash.nthArg = nthArg;
15892 lodash.omit = omit;
15893 lodash.omitBy = omitBy;
15894 lodash.once = once;
15895 lodash.orderBy = orderBy;
15896 lodash.over = over;
15897 lodash.overArgs = overArgs;
15898 lodash.overEvery = overEvery;
15899 lodash.overSome = overSome;
15900 lodash.partial = partial;
15901 lodash.partialRight = partialRight;
15902 lodash.partition = partition;
15903 lodash.pick = pick;
15904 lodash.pickBy = pickBy;
15905 lodash.property = property;
15906 lodash.propertyOf = propertyOf;
15907 lodash.pull = pull;
15908 lodash.pullAll = pullAll;
15909 lodash.pullAllBy = pullAllBy;
15910 lodash.pullAllWith = pullAllWith;
15911 lodash.pullAt = pullAt;
15912 lodash.range = range;
15913 lodash.rangeRight = rangeRight;
15914 lodash.rearg = rearg;
15915 lodash.reject = reject;
15916 lodash.remove = remove;
15917 lodash.rest = rest;
15918 lodash.reverse = reverse;
15919 lodash.sampleSize = sampleSize;
15921 lodash.setWith = setWith;
15922 lodash.shuffle = shuffle;
15923 lodash.slice = slice;
15924 lodash.sortBy = sortBy;
15925 lodash.sortedUniq = sortedUniq;
15926 lodash.sortedUniqBy = sortedUniqBy;
15927 lodash.split = split;
15928 lodash.spread = spread;
15929 lodash.tail = tail;
15930 lodash.take = take;
15931 lodash.takeRight = takeRight;
15932 lodash.takeRightWhile = takeRightWhile;
15933 lodash.takeWhile = takeWhile;
15935 lodash.throttle = throttle;
15936 lodash.thru = thru;
15937 lodash.toArray = toArray;
15938 lodash.toPairs = toPairs;
15939 lodash.toPairsIn = toPairsIn;
15940 lodash.toPath = toPath;
15941 lodash.toPlainObject = toPlainObject;
15942 lodash.transform = transform;
15943 lodash.unary = unary;
15944 lodash.union = union;
15945 lodash.unionBy = unionBy;
15946 lodash.unionWith = unionWith;
15947 lodash.uniq = uniq;
15948 lodash.uniqBy = uniqBy;
15949 lodash.uniqWith = uniqWith;
15950 lodash.unset = unset;
15951 lodash.unzip = unzip;
15952 lodash.unzipWith = unzipWith;
15953 lodash.update = update;
15954 lodash.updateWith = updateWith;
15955 lodash.values = values;
15956 lodash.valuesIn = valuesIn;
15957 lodash.without = without;
15958 lodash.words = words;
15959 lodash.wrap = wrap;
15961 lodash.xorBy = xorBy;
15962 lodash.xorWith = xorWith;
15964 lodash.zipObject = zipObject;
15965 lodash.zipObjectDeep = zipObjectDeep;
15966 lodash.zipWith = zipWith;
15969 lodash.entries = toPairs;
15970 lodash.entriesIn = toPairsIn;
15971 lodash.extend = assignIn;
15972 lodash.extendWith = assignInWith;
15974 // Add methods to `lodash.prototype`.
15975 mixin(lodash, lodash);
15977 /*------------------------------------------------------------------------*/
15979 // Add methods that return unwrapped values in chain sequences.
15981 lodash.attempt = attempt;
15982 lodash.camelCase = camelCase;
15983 lodash.capitalize = capitalize;
15984 lodash.ceil = ceil;
15985 lodash.clamp = clamp;
15986 lodash.clone = clone;
15987 lodash.cloneDeep = cloneDeep;
15988 lodash.cloneDeepWith = cloneDeepWith;
15989 lodash.cloneWith = cloneWith;
15990 lodash.deburr = deburr;
15991 lodash.divide = divide;
15992 lodash.endsWith = endsWith;
15994 lodash.escape = escape;
15995 lodash.escapeRegExp = escapeRegExp;
15996 lodash.every = every;
15997 lodash.find = find;
15998 lodash.findIndex = findIndex;
15999 lodash.findKey = findKey;
16000 lodash.findLast = findLast;
16001 lodash.findLastIndex = findLastIndex;
16002 lodash.findLastKey = findLastKey;
16003 lodash.floor = floor;
16004 lodash.forEach = forEach;
16005 lodash.forEachRight = forEachRight;
16006 lodash.forIn = forIn;
16007 lodash.forInRight = forInRight;
16008 lodash.forOwn = forOwn;
16009 lodash.forOwnRight = forOwnRight;
16014 lodash.hasIn = hasIn;
16015 lodash.head = head;
16016 lodash.identity = identity;
16017 lodash.includes = includes;
16018 lodash.indexOf = indexOf;
16019 lodash.inRange = inRange;
16020 lodash.invoke = invoke;
16021 lodash.isArguments = isArguments;
16022 lodash.isArray = isArray;
16023 lodash.isArrayBuffer = isArrayBuffer;
16024 lodash.isArrayLike = isArrayLike;
16025 lodash.isArrayLikeObject = isArrayLikeObject;
16026 lodash.isBoolean = isBoolean;
16027 lodash.isBuffer = isBuffer;
16028 lodash.isDate = isDate;
16029 lodash.isElement = isElement;
16030 lodash.isEmpty = isEmpty;
16031 lodash.isEqual = isEqual;
16032 lodash.isEqualWith = isEqualWith;
16033 lodash.isError = isError;
16034 lodash.isFinite = isFinite;
16035 lodash.isFunction = isFunction;
16036 lodash.isInteger = isInteger;
16037 lodash.isLength = isLength;
16038 lodash.isMap = isMap;
16039 lodash.isMatch = isMatch;
16040 lodash.isMatchWith = isMatchWith;
16041 lodash.isNaN = isNaN;
16042 lodash.isNative = isNative;
16043 lodash.isNil = isNil;
16044 lodash.isNull = isNull;
16045 lodash.isNumber = isNumber;
16046 lodash.isObject = isObject;
16047 lodash.isObjectLike = isObjectLike;
16048 lodash.isPlainObject = isPlainObject;
16049 lodash.isRegExp = isRegExp;
16050 lodash.isSafeInteger = isSafeInteger;
16051 lodash.isSet = isSet;
16052 lodash.isString = isString;
16053 lodash.isSymbol = isSymbol;
16054 lodash.isTypedArray = isTypedArray;
16055 lodash.isUndefined = isUndefined;
16056 lodash.isWeakMap = isWeakMap;
16057 lodash.isWeakSet = isWeakSet;
16058 lodash.join = join;
16059 lodash.kebabCase = kebabCase;
16060 lodash.last = last;
16061 lodash.lastIndexOf = lastIndexOf;
16062 lodash.lowerCase = lowerCase;
16063 lodash.lowerFirst = lowerFirst;
16067 lodash.maxBy = maxBy;
16068 lodash.mean = mean;
16069 lodash.meanBy = meanBy;
16071 lodash.minBy = minBy;
16072 lodash.stubArray = stubArray;
16073 lodash.stubFalse = stubFalse;
16074 lodash.stubObject = stubObject;
16075 lodash.stubString = stubString;
16076 lodash.stubTrue = stubTrue;
16077 lodash.multiply = multiply;
16079 lodash.noConflict = noConflict;
16080 lodash.noop = noop;
16083 lodash.padEnd = padEnd;
16084 lodash.padStart = padStart;
16085 lodash.parseInt = parseInt;
16086 lodash.random = random;
16087 lodash.reduce = reduce;
16088 lodash.reduceRight = reduceRight;
16089 lodash.repeat = repeat;
16090 lodash.replace = replace;
16091 lodash.result = result;
16092 lodash.round = round;
16093 lodash.runInContext = runInContext;
16094 lodash.sample = sample;
16095 lodash.size = size;
16096 lodash.snakeCase = snakeCase;
16097 lodash.some = some;
16098 lodash.sortedIndex = sortedIndex;
16099 lodash.sortedIndexBy = sortedIndexBy;
16100 lodash.sortedIndexOf = sortedIndexOf;
16101 lodash.sortedLastIndex = sortedLastIndex;
16102 lodash.sortedLastIndexBy = sortedLastIndexBy;
16103 lodash.sortedLastIndexOf = sortedLastIndexOf;
16104 lodash.startCase = startCase;
16105 lodash.startsWith = startsWith;
16106 lodash.subtract = subtract;
16108 lodash.sumBy = sumBy;
16109 lodash.template = template;
16110 lodash.times = times;
16111 lodash.toFinite = toFinite;
16112 lodash.toInteger = toInteger;
16113 lodash.toLength = toLength;
16114 lodash.toLower = toLower;
16115 lodash.toNumber = toNumber;
16116 lodash.toSafeInteger = toSafeInteger;
16117 lodash.toString = toString;
16118 lodash.toUpper = toUpper;
16119 lodash.trim = trim;
16120 lodash.trimEnd = trimEnd;
16121 lodash.trimStart = trimStart;
16122 lodash.truncate = truncate;
16123 lodash.unescape = unescape;
16124 lodash.uniqueId = uniqueId;
16125 lodash.upperCase = upperCase;
16126 lodash.upperFirst = upperFirst;
16129 lodash.each = forEach;
16130 lodash.eachRight = forEachRight;
16131 lodash.first = head;
16133 mixin(lodash, (function() {
16135 baseForOwn(lodash, function(func, methodName) {
16136 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
16137 source[methodName] = func;
16141 }()), { 'chain': false });
16143 /*------------------------------------------------------------------------*/
16146 * The semantic version number.
16152 lodash.VERSION = VERSION;
16154 // Assign default placeholders.
16155 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
16156 lodash[methodName].placeholder = lodash;
16159 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
16160 arrayEach(['drop', 'take'], function(methodName, index) {
16161 LazyWrapper.prototype[methodName] = function(n) {
16162 var filtered = this.__filtered__;
16163 if (filtered && !index) {
16164 return new LazyWrapper(this);
16166 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
16168 var result = this.clone();
16170 result.__takeCount__ = nativeMin(n, result.__takeCount__);
16172 result.__views__.push({
16173 'size': nativeMin(n, MAX_ARRAY_LENGTH),
16174 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
16180 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
16181 return this.reverse()[methodName](n).reverse();
16185 // Add `LazyWrapper` methods that accept an `iteratee` value.
16186 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
16187 var type = index + 1,
16188 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
16190 LazyWrapper.prototype[methodName] = function(iteratee) {
16191 var result = this.clone();
16192 result.__iteratees__.push({
16193 'iteratee': getIteratee(iteratee, 3),
16196 result.__filtered__ = result.__filtered__ || isFilter;
16201 // Add `LazyWrapper` methods for `_.head` and `_.last`.
16202 arrayEach(['head', 'last'], function(methodName, index) {
16203 var takeName = 'take' + (index ? 'Right' : '');
16205 LazyWrapper.prototype[methodName] = function() {
16206 return this[takeName](1).value()[0];
16210 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
16211 arrayEach(['initial', 'tail'], function(methodName, index) {
16212 var dropName = 'drop' + (index ? '' : 'Right');
16214 LazyWrapper.prototype[methodName] = function() {
16215 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
16219 LazyWrapper.prototype.compact = function() {
16220 return this.filter(identity);
16223 LazyWrapper.prototype.find = function(predicate) {
16224 return this.filter(predicate).head();
16227 LazyWrapper.prototype.findLast = function(predicate) {
16228 return this.reverse().find(predicate);
16231 LazyWrapper.prototype.invokeMap = rest(function(path, args) {
16232 if (typeof path == 'function') {
16233 return new LazyWrapper(this);
16235 return this.map(function(value) {
16236 return baseInvoke(value, path, args);
16240 LazyWrapper.prototype.reject = function(predicate) {
16241 predicate = getIteratee(predicate, 3);
16242 return this.filter(function(value) {
16243 return !predicate(value);
16247 LazyWrapper.prototype.slice = function(start, end) {
16248 start = toInteger(start);
16251 if (result.__filtered__ && (start > 0 || end < 0)) {
16252 return new LazyWrapper(result);
16255 result = result.takeRight(-start);
16256 } else if (start) {
16257 result = result.drop(start);
16259 if (end !== undefined) {
16260 end = toInteger(end);
16261 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
16266 LazyWrapper.prototype.takeRightWhile = function(predicate) {
16267 return this.reverse().takeWhile(predicate).reverse();
16270 LazyWrapper.prototype.toArray = function() {
16271 return this.take(MAX_ARRAY_LENGTH);
16274 // Add `LazyWrapper` methods to `lodash.prototype`.
16275 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16276 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
16277 isTaker = /^(?:head|last)$/.test(methodName),
16278 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
16279 retUnwrapped = isTaker || /^find/.test(methodName);
16284 lodash.prototype[methodName] = function() {
16285 var value = this.__wrapped__,
16286 args = isTaker ? [1] : arguments,
16287 isLazy = value instanceof LazyWrapper,
16288 iteratee = args[0],
16289 useLazy = isLazy || isArray(value);
16291 var interceptor = function(value) {
16292 var result = lodashFunc.apply(lodash, arrayPush([value], args));
16293 return (isTaker && chainAll) ? result[0] : result;
16296 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
16297 // Avoid lazy use if the iteratee has a "length" value other than `1`.
16298 isLazy = useLazy = false;
16300 var chainAll = this.__chain__,
16301 isHybrid = !!this.__actions__.length,
16302 isUnwrapped = retUnwrapped && !chainAll,
16303 onlyLazy = isLazy && !isHybrid;
16305 if (!retUnwrapped && useLazy) {
16306 value = onlyLazy ? value : new LazyWrapper(this);
16307 var result = func.apply(value, args);
16308 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
16309 return new LodashWrapper(result, chainAll);
16311 if (isUnwrapped && onlyLazy) {
16312 return func.apply(this, args);
16314 result = this.thru(interceptor);
16315 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
16319 // Add `Array` methods to `lodash.prototype`.
16320 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
16321 var func = arrayProto[methodName],
16322 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
16323 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
16325 lodash.prototype[methodName] = function() {
16326 var args = arguments;
16327 if (retUnwrapped && !this.__chain__) {
16328 var value = this.value();
16329 return func.apply(isArray(value) ? value : [], args);
16331 return this[chainName](function(value) {
16332 return func.apply(isArray(value) ? value : [], args);
16337 // Map minified method names to their real names.
16338 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16339 var lodashFunc = lodash[methodName];
16341 var key = (lodashFunc.name + ''),
16342 names = realNames[key] || (realNames[key] = []);
16344 names.push({ 'name': methodName, 'func': lodashFunc });
16348 realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{
16353 // Add methods to `LazyWrapper`.
16354 LazyWrapper.prototype.clone = lazyClone;
16355 LazyWrapper.prototype.reverse = lazyReverse;
16356 LazyWrapper.prototype.value = lazyValue;
16358 // Add chain sequence methods to the `lodash` wrapper.
16359 lodash.prototype.at = wrapperAt;
16360 lodash.prototype.chain = wrapperChain;
16361 lodash.prototype.commit = wrapperCommit;
16362 lodash.prototype.next = wrapperNext;
16363 lodash.prototype.plant = wrapperPlant;
16364 lodash.prototype.reverse = wrapperReverse;
16365 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
16367 if (iteratorSymbol) {
16368 lodash.prototype[iteratorSymbol] = wrapperToIterator;
16373 /*--------------------------------------------------------------------------*/
16376 var _ = runInContext();
16378 // Expose Lodash on the free variable `window` or `self` when available so it's
16379 // globally accessible, even when bundled with Browserify, Webpack, etc. This
16380 // also prevents errors in cases where Lodash is loaded by a script tag in the
16381 // presence of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch
16382 // for more details. Use `_.noConflict` to remove Lodash from the global object.
16383 (freeSelf || {})._ = _;
16385 // Some AMD build optimizers like r.js check for condition patterns like the following:
16386 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
16387 // Define as an anonymous module so, through path mapping, it can be
16388 // referenced as the "underscore" module.
16389 define(function() {
16393 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
16394 else if (freeModule) {
16395 // Export for Node.js.
16396 (freeModule.exports = _)._ = _;
16397 // Export for CommonJS support.
16401 // Export to the global object.