3 * Lodash <https://lodash.com/>
4 * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
5 * Released under MIT license <https://lodash.com/license>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
15 /** Used as the semantic version number. */
16 var VERSION = '4.17.20';
18 /** Used as the size to enable large array optimizations. */
19 var LARGE_ARRAY_SIZE = 200;
21 /** Error message constants. */
22 var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
23 FUNC_ERROR_TEXT = 'Expected a function';
25 /** Used to stand-in for `undefined` hash values. */
26 var HASH_UNDEFINED = '__lodash_hash_undefined__';
28 /** Used as the maximum memoize cache size. */
29 var MAX_MEMOIZE_SIZE = 500;
31 /** Used as the internal argument placeholder. */
32 var PLACEHOLDER = '__lodash_placeholder__';
34 /** Used to compose bitmasks for cloning. */
35 var CLONE_DEEP_FLAG = 1,
37 CLONE_SYMBOLS_FLAG = 4;
39 /** Used to compose bitmasks for value comparisons. */
40 var COMPARE_PARTIAL_FLAG = 1,
41 COMPARE_UNORDERED_FLAG = 2;
43 /** Used to compose bitmasks for function metadata. */
44 var WRAP_BIND_FLAG = 1,
45 WRAP_BIND_KEY_FLAG = 2,
46 WRAP_CURRY_BOUND_FLAG = 4,
48 WRAP_CURRY_RIGHT_FLAG = 16,
49 WRAP_PARTIAL_FLAG = 32,
50 WRAP_PARTIAL_RIGHT_FLAG = 64,
52 WRAP_REARG_FLAG = 256,
55 /** Used as default options for `_.truncate`. */
56 var DEFAULT_TRUNC_LENGTH = 30,
57 DEFAULT_TRUNC_OMISSION = '...';
59 /** Used to detect hot functions by number of calls within a span of milliseconds. */
63 /** Used to indicate the type of lazy iteratees. */
64 var LAZY_FILTER_FLAG = 1,
68 /** Used as references for various `Number` constants. */
70 MAX_SAFE_INTEGER = 9007199254740991,
71 MAX_INTEGER = 1.7976931348623157e+308,
74 /** Used as references for the maximum length and index of an array. */
75 var MAX_ARRAY_LENGTH = 4294967295,
76 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
77 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
79 /** Used to associate wrap methods with their bit flags. */
81 ['ary', WRAP_ARY_FLAG],
82 ['bind', WRAP_BIND_FLAG],
83 ['bindKey', WRAP_BIND_KEY_FLAG],
84 ['curry', WRAP_CURRY_FLAG],
85 ['curryRight', WRAP_CURRY_RIGHT_FLAG],
86 ['flip', WRAP_FLIP_FLAG],
87 ['partial', WRAP_PARTIAL_FLAG],
88 ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
89 ['rearg', WRAP_REARG_FLAG]
92 /** `Object#toString` result references. */
93 var argsTag = '[object Arguments]',
94 arrayTag = '[object Array]',
95 asyncTag = '[object AsyncFunction]',
96 boolTag = '[object Boolean]',
97 dateTag = '[object Date]',
98 domExcTag = '[object DOMException]',
99 errorTag = '[object Error]',
100 funcTag = '[object Function]',
101 genTag = '[object GeneratorFunction]',
102 mapTag = '[object Map]',
103 numberTag = '[object Number]',
104 nullTag = '[object Null]',
105 objectTag = '[object Object]',
106 promiseTag = '[object Promise]',
107 proxyTag = '[object Proxy]',
108 regexpTag = '[object RegExp]',
109 setTag = '[object Set]',
110 stringTag = '[object String]',
111 symbolTag = '[object Symbol]',
112 undefinedTag = '[object Undefined]',
113 weakMapTag = '[object WeakMap]',
114 weakSetTag = '[object WeakSet]';
116 var arrayBufferTag = '[object ArrayBuffer]',
117 dataViewTag = '[object DataView]',
118 float32Tag = '[object Float32Array]',
119 float64Tag = '[object Float64Array]',
120 int8Tag = '[object Int8Array]',
121 int16Tag = '[object Int16Array]',
122 int32Tag = '[object Int32Array]',
123 uint8Tag = '[object Uint8Array]',
124 uint8ClampedTag = '[object Uint8ClampedArray]',
125 uint16Tag = '[object Uint16Array]',
126 uint32Tag = '[object Uint32Array]';
128 /** Used to match empty string literals in compiled template source. */
129 var reEmptyStringLeading = /\b__p \+= '';/g,
130 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
131 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
133 /** Used to match HTML entities and HTML characters. */
134 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
135 reUnescapedHtml = /[&<>"']/g,
136 reHasEscapedHtml = RegExp(reEscapedHtml.source),
137 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
139 /** Used to match template delimiters. */
140 var reEscape = /<%-([\s\S]+?)%>/g,
141 reEvaluate = /<%([\s\S]+?)%>/g,
142 reInterpolate = /<%=([\s\S]+?)%>/g;
144 /** Used to match property names within property paths. */
145 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
146 reIsPlainProp = /^\w*$/,
147 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
150 * Used to match `RegExp`
151 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
153 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
154 reHasRegExpChar = RegExp(reRegExpChar.source);
156 /** Used to match leading and trailing whitespace. */
157 var reTrim = /^\s+|\s+$/g,
158 reTrimStart = /^\s+/,
161 /** Used to match wrap detail comments. */
162 var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
163 reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
164 reSplitDetails = /,? & /;
166 /** Used to match words composed of alphanumeric characters. */
167 var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
169 /** Used to match backslashes in property paths. */
170 var reEscapeChar = /\\(\\)?/g;
174 * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
176 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
178 /** Used to match `RegExp` flags from their coerced string values. */
179 var reFlags = /\w*$/;
181 /** Used to detect bad signed hexadecimal string values. */
182 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
184 /** Used to detect binary string values. */
185 var reIsBinary = /^0b[01]+$/i;
187 /** Used to detect host constructors (Safari). */
188 var reIsHostCtor = /^\[object .+?Constructor\]$/;
190 /** Used to detect octal string values. */
191 var reIsOctal = /^0o[0-7]+$/i;
193 /** Used to detect unsigned integer values. */
194 var reIsUint = /^(?:0|[1-9]\d*)$/;
196 /** Used to match Latin Unicode letters (excluding mathematical operators). */
197 var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
199 /** Used to ensure capturing order of template delimiters. */
200 var reNoMatch = /($^)/;
202 /** Used to match unescaped characters in compiled string literals. */
203 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
205 /** Used to compose unicode character classes. */
206 var rsAstralRange = '\\ud800-\\udfff',
207 rsComboMarksRange = '\\u0300-\\u036f',
208 reComboHalfMarksRange = '\\ufe20-\\ufe2f',
209 rsComboSymbolsRange = '\\u20d0-\\u20ff',
210 rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
211 rsDingbatRange = '\\u2700-\\u27bf',
212 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
213 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
214 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
215 rsPunctuationRange = '\\u2000-\\u206f',
216 rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
217 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
218 rsVarRange = '\\ufe0e\\ufe0f',
219 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
221 /** Used to compose unicode capture groups. */
222 var rsApos = "['\u2019]",
223 rsAstral = '[' + rsAstralRange + ']',
224 rsBreak = '[' + rsBreakRange + ']',
225 rsCombo = '[' + rsComboRange + ']',
227 rsDingbat = '[' + rsDingbatRange + ']',
228 rsLower = '[' + rsLowerRange + ']',
229 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
230 rsFitz = '\\ud83c[\\udffb-\\udfff]',
231 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
232 rsNonAstral = '[^' + rsAstralRange + ']',
233 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
234 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
235 rsUpper = '[' + rsUpperRange + ']',
238 /** Used to compose unicode regexes. */
239 var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
240 rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
241 rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
242 rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
243 reOptMod = rsModifier + '?',
244 rsOptVar = '[' + rsVarRange + ']?',
245 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
246 rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
247 rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
248 rsSeq = rsOptVar + reOptMod + rsOptJoin,
249 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
250 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
252 /** Used to match apostrophes. */
253 var reApos = RegExp(rsApos, 'g');
256 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
257 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
259 var reComboMark = RegExp(rsCombo, 'g');
261 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
262 var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
264 /** Used to match complex or compound words. */
265 var reUnicodeWord = RegExp([
266 rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
267 rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
268 rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
269 rsUpper + '+' + rsOptContrUpper,
276 /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
277 var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
279 /** Used to detect strings that need a more robust regexp to match words. */
280 var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
282 /** Used to assign default `context` object properties. */
284 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
285 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
286 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
287 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
288 '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
291 /** Used to make template sourceURLs easier to identify. */
292 var templateCounter = -1;
294 /** Used to identify `toStringTag` values of typed arrays. */
295 var typedArrayTags = {};
296 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
297 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
298 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
299 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
300 typedArrayTags[uint32Tag] = true;
301 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
302 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
303 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
304 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
305 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
306 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
307 typedArrayTags[setTag] = typedArrayTags[stringTag] =
308 typedArrayTags[weakMapTag] = false;
310 /** Used to identify `toStringTag` values supported by `_.clone`. */
311 var cloneableTags = {};
312 cloneableTags[argsTag] = cloneableTags[arrayTag] =
313 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
314 cloneableTags[boolTag] = cloneableTags[dateTag] =
315 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
316 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
317 cloneableTags[int32Tag] = cloneableTags[mapTag] =
318 cloneableTags[numberTag] = cloneableTags[objectTag] =
319 cloneableTags[regexpTag] = cloneableTags[setTag] =
320 cloneableTags[stringTag] = cloneableTags[symbolTag] =
321 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
322 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
323 cloneableTags[errorTag] = cloneableTags[funcTag] =
324 cloneableTags[weakMapTag] = false;
326 /** Used to map Latin Unicode letters to basic Latin letters. */
327 var deburredLetters = {
328 // Latin-1 Supplement block.
391 // Latin Extended-A block.
522 /** Used to map characters to HTML entities. */
531 /** Used to map HTML entities to characters. */
532 var htmlUnescapes = {
540 /** Used to escape characters for inclusion in compiled string literals. */
541 var stringEscapes = {
550 /** Built-in method references without a dependency on `root`. */
551 var freeParseFloat = parseFloat,
552 freeParseInt = parseInt;
554 /** Detect free variable `global` from Node.js. */
555 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
557 /** Detect free variable `self`. */
558 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
560 /** Used as a reference to the global object. */
561 var root = freeGlobal || freeSelf || Function('return this')();
563 /** Detect free variable `exports`. */
564 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
566 /** Detect free variable `module`. */
567 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
569 /** Detect the popular CommonJS extension `module.exports`. */
570 var moduleExports = freeModule && freeModule.exports === freeExports;
572 /** Detect free variable `process` from Node.js. */
573 var freeProcess = moduleExports && freeGlobal.process;
575 /** Used to access faster Node.js helpers. */
576 var nodeUtil = (function() {
578 // Use `util.types` for Node.js 10+.
579 var types = freeModule && freeModule.require && freeModule.require('util').types;
585 // Legacy `process.binding('util')` for Node.js < 10.
586 return freeProcess && freeProcess.binding && freeProcess.binding('util');
590 /* Node.js helper references. */
591 var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
592 nodeIsDate = nodeUtil && nodeUtil.isDate,
593 nodeIsMap = nodeUtil && nodeUtil.isMap,
594 nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
595 nodeIsSet = nodeUtil && nodeUtil.isSet,
596 nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
598 /*--------------------------------------------------------------------------*/
601 * A faster alternative to `Function#apply`, this function invokes `func`
602 * with the `this` binding of `thisArg` and the arguments of `args`.
605 * @param {Function} func The function to invoke.
606 * @param {*} thisArg The `this` binding of `func`.
607 * @param {Array} args The arguments to invoke `func` with.
608 * @returns {*} Returns the result of `func`.
610 function apply(func, thisArg, args) {
611 switch (args.length) {
613 return func.call(thisArg);
615 return func.call(thisArg, args[0]);
617 return func.call(thisArg, args[0], args[1]);
619 return func.call(thisArg, args[0], args[1], args[2]);
621 return func.apply(thisArg, args);
625 * A specialized version of `baseAggregator` for arrays.
628 * @param {Array} [array] The array to iterate over.
629 * @param {Function} setter The function to set `accumulator` values.
630 * @param {Function} iteratee The iteratee to transform keys.
631 * @param {Object} accumulator The initial aggregated object.
632 * @returns {Function} Returns `accumulator`.
634 function arrayAggregator(array, setter, iteratee, accumulator) {
636 length = array == null ? 0 : array.length;
638 while (++index < length) {
639 var value = array[index];
640 setter(accumulator, value, iteratee(value), array);
646 * A specialized version of `_.forEach` for arrays without support for
647 * iteratee shorthands.
650 * @param {Array} [array] The array to iterate over.
651 * @param {Function} iteratee The function invoked per iteration.
652 * @returns {Array} Returns `array`.
654 function arrayEach(array, iteratee) {
656 length = array == null ? 0 : array.length;
658 while (++index < length) {
659 if (iteratee(array[index], index, array) === false) {
667 * A specialized version of `_.forEachRight` for arrays without support for
668 * iteratee shorthands.
671 * @param {Array} [array] The array to iterate over.
672 * @param {Function} iteratee The function invoked per iteration.
673 * @returns {Array} Returns `array`.
675 function arrayEachRight(array, iteratee) {
676 var length = array == null ? 0 : array.length;
679 if (iteratee(array[length], length, array) === false) {
687 * A specialized version of `_.every` for arrays without support for
688 * iteratee shorthands.
691 * @param {Array} [array] The array to iterate over.
692 * @param {Function} predicate The function invoked per iteration.
693 * @returns {boolean} Returns `true` if all elements pass the predicate check,
696 function arrayEvery(array, predicate) {
698 length = array == null ? 0 : array.length;
700 while (++index < length) {
701 if (!predicate(array[index], index, array)) {
709 * A specialized version of `_.filter` for arrays without support for
710 * iteratee shorthands.
713 * @param {Array} [array] The array to iterate over.
714 * @param {Function} predicate The function invoked per iteration.
715 * @returns {Array} Returns the new filtered array.
717 function arrayFilter(array, predicate) {
719 length = array == null ? 0 : array.length,
723 while (++index < length) {
724 var value = array[index];
725 if (predicate(value, index, array)) {
726 result[resIndex++] = value;
733 * A specialized version of `_.includes` for arrays without support for
734 * specifying an index to search from.
737 * @param {Array} [array] The array to inspect.
738 * @param {*} target The value to search for.
739 * @returns {boolean} Returns `true` if `target` is found, else `false`.
741 function arrayIncludes(array, value) {
742 var length = array == null ? 0 : array.length;
743 return !!length && baseIndexOf(array, value, 0) > -1;
747 * This function is like `arrayIncludes` except that it accepts a comparator.
750 * @param {Array} [array] The array to inspect.
751 * @param {*} target The value to search for.
752 * @param {Function} comparator The comparator invoked per element.
753 * @returns {boolean} Returns `true` if `target` is found, else `false`.
755 function arrayIncludesWith(array, value, comparator) {
757 length = array == null ? 0 : array.length;
759 while (++index < length) {
760 if (comparator(value, array[index])) {
768 * A specialized version of `_.map` for arrays without support for iteratee
772 * @param {Array} [array] The array to iterate over.
773 * @param {Function} iteratee The function invoked per iteration.
774 * @returns {Array} Returns the new mapped array.
776 function arrayMap(array, iteratee) {
778 length = array == null ? 0 : array.length,
779 result = Array(length);
781 while (++index < length) {
782 result[index] = iteratee(array[index], index, array);
788 * Appends the elements of `values` to `array`.
791 * @param {Array} array The array to modify.
792 * @param {Array} values The values to append.
793 * @returns {Array} Returns `array`.
795 function arrayPush(array, values) {
797 length = values.length,
798 offset = array.length;
800 while (++index < length) {
801 array[offset + index] = values[index];
807 * A specialized version of `_.reduce` for arrays without support for
808 * iteratee shorthands.
811 * @param {Array} [array] The array to iterate over.
812 * @param {Function} iteratee The function invoked per iteration.
813 * @param {*} [accumulator] The initial value.
814 * @param {boolean} [initAccum] Specify using the first element of `array` as
816 * @returns {*} Returns the accumulated value.
818 function arrayReduce(array, iteratee, accumulator, initAccum) {
820 length = array == null ? 0 : array.length;
822 if (initAccum && length) {
823 accumulator = array[++index];
825 while (++index < length) {
826 accumulator = iteratee(accumulator, array[index], index, array);
832 * A specialized version of `_.reduceRight` for arrays without support for
833 * iteratee shorthands.
836 * @param {Array} [array] The array to iterate over.
837 * @param {Function} iteratee The function invoked per iteration.
838 * @param {*} [accumulator] The initial value.
839 * @param {boolean} [initAccum] Specify using the last element of `array` as
841 * @returns {*} Returns the accumulated value.
843 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
844 var length = array == null ? 0 : array.length;
845 if (initAccum && length) {
846 accumulator = array[--length];
849 accumulator = iteratee(accumulator, array[length], length, array);
855 * A specialized version of `_.some` for arrays without support for iteratee
859 * @param {Array} [array] The array to iterate over.
860 * @param {Function} predicate The function invoked per iteration.
861 * @returns {boolean} Returns `true` if any element passes the predicate check,
864 function arraySome(array, predicate) {
866 length = array == null ? 0 : array.length;
868 while (++index < length) {
869 if (predicate(array[index], index, array)) {
877 * Gets the size of an ASCII `string`.
880 * @param {string} string The string inspect.
881 * @returns {number} Returns the string size.
883 var asciiSize = baseProperty('length');
886 * Converts an ASCII `string` to an array.
889 * @param {string} string The string to convert.
890 * @returns {Array} Returns the converted array.
892 function asciiToArray(string) {
893 return string.split('');
897 * Splits an ASCII `string` into an array of its words.
900 * @param {string} The string to inspect.
901 * @returns {Array} Returns the words of `string`.
903 function asciiWords(string) {
904 return string.match(reAsciiWord) || [];
908 * The base implementation of methods like `_.findKey` and `_.findLastKey`,
909 * without support for iteratee shorthands, which iterates over `collection`
913 * @param {Array|Object} collection The collection to inspect.
914 * @param {Function} predicate The function invoked per iteration.
915 * @param {Function} eachFunc The function to iterate over `collection`.
916 * @returns {*} Returns the found element or its key, else `undefined`.
918 function baseFindKey(collection, predicate, eachFunc) {
920 eachFunc(collection, function(value, key, collection) {
921 if (predicate(value, key, collection)) {
930 * The base implementation of `_.findIndex` and `_.findLastIndex` without
931 * support for iteratee shorthands.
934 * @param {Array} array The array to inspect.
935 * @param {Function} predicate The function invoked per iteration.
936 * @param {number} fromIndex The index to search from.
937 * @param {boolean} [fromRight] Specify iterating from right to left.
938 * @returns {number} Returns the index of the matched value, else `-1`.
940 function baseFindIndex(array, predicate, fromIndex, fromRight) {
941 var length = array.length,
942 index = fromIndex + (fromRight ? 1 : -1);
944 while ((fromRight ? index-- : ++index < length)) {
945 if (predicate(array[index], index, array)) {
953 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
956 * @param {Array} array The array to inspect.
957 * @param {*} value The value to search for.
958 * @param {number} fromIndex The index to search from.
959 * @returns {number} Returns the index of the matched value, else `-1`.
961 function baseIndexOf(array, value, fromIndex) {
962 return value === value ?
963 strictIndexOf(array, value, fromIndex) :
964 baseFindIndex(array, baseIsNaN, fromIndex);
968 * This function is like `baseIndexOf` except that it accepts a comparator.
971 * @param {Array} array The array to inspect.
972 * @param {*} value The value to search for.
973 * @param {number} fromIndex The index to search from.
974 * @param {Function} comparator The comparator invoked per element.
975 * @returns {number} Returns the index of the matched value, else `-1`.
977 function baseIndexOfWith(array, value, fromIndex, comparator) {
978 var index = fromIndex - 1,
979 length = array.length;
981 while (++index < length) {
982 if (comparator(array[index], value)) {
990 * The base implementation of `_.isNaN` without support for number objects.
993 * @param {*} value The value to check.
994 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
996 function baseIsNaN(value) {
997 return value !== value;
1001 * The base implementation of `_.mean` and `_.meanBy` without support for
1002 * iteratee shorthands.
1005 * @param {Array} array The array to iterate over.
1006 * @param {Function} iteratee The function invoked per iteration.
1007 * @returns {number} Returns the mean.
1009 function baseMean(array, iteratee) {
1010 var length = array == null ? 0 : array.length;
1011 return length ? (baseSum(array, iteratee) / length) : NAN;
1015 * The base implementation of `_.property` without support for deep paths.
1018 * @param {string} key The key of the property to get.
1019 * @returns {Function} Returns the new accessor function.
1021 function baseProperty(key) {
1022 return function(object) {
1023 return object == null ? undefined : object[key];
1028 * The base implementation of `_.propertyOf` without support for deep paths.
1031 * @param {Object} object The object to query.
1032 * @returns {Function} Returns the new accessor function.
1034 function basePropertyOf(object) {
1035 return function(key) {
1036 return object == null ? undefined : object[key];
1041 * The base implementation of `_.reduce` and `_.reduceRight`, without support
1042 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
1045 * @param {Array|Object} collection The collection to iterate over.
1046 * @param {Function} iteratee The function invoked per iteration.
1047 * @param {*} accumulator The initial value.
1048 * @param {boolean} initAccum Specify using the first or last element of
1049 * `collection` as the initial value.
1050 * @param {Function} eachFunc The function to iterate over `collection`.
1051 * @returns {*} Returns the accumulated value.
1053 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
1054 eachFunc(collection, function(value, index, collection) {
1055 accumulator = initAccum ?
1056 (initAccum = false, value) :
1057 iteratee(accumulator, value, index, collection);
1063 * The base implementation of `_.sortBy` which uses `comparer` to define the
1064 * sort order of `array` and replaces criteria objects with their corresponding
1068 * @param {Array} array The array to sort.
1069 * @param {Function} comparer The function to define sort order.
1070 * @returns {Array} Returns `array`.
1072 function baseSortBy(array, comparer) {
1073 var length = array.length;
1075 array.sort(comparer);
1077 array[length] = array[length].value;
1083 * The base implementation of `_.sum` and `_.sumBy` without support for
1084 * iteratee shorthands.
1087 * @param {Array} array The array to iterate over.
1088 * @param {Function} iteratee The function invoked per iteration.
1089 * @returns {number} Returns the sum.
1091 function baseSum(array, iteratee) {
1094 length = array.length;
1096 while (++index < length) {
1097 var current = iteratee(array[index]);
1098 if (current !== undefined) {
1099 result = result === undefined ? current : (result + current);
1106 * The base implementation of `_.times` without support for iteratee shorthands
1107 * or max array length checks.
1110 * @param {number} n The number of times to invoke `iteratee`.
1111 * @param {Function} iteratee The function invoked per iteration.
1112 * @returns {Array} Returns the array of results.
1114 function baseTimes(n, iteratee) {
1118 while (++index < n) {
1119 result[index] = iteratee(index);
1125 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
1126 * of key-value pairs for `object` corresponding to the property names of `props`.
1129 * @param {Object} object The object to query.
1130 * @param {Array} props The property names to get values for.
1131 * @returns {Object} Returns the key-value pairs.
1133 function baseToPairs(object, props) {
1134 return arrayMap(props, function(key) {
1135 return [key, object[key]];
1140 * The base implementation of `_.unary` without support for storing metadata.
1143 * @param {Function} func The function to cap arguments for.
1144 * @returns {Function} Returns the new capped function.
1146 function baseUnary(func) {
1147 return function(value) {
1153 * The base implementation of `_.values` and `_.valuesIn` which creates an
1154 * array of `object` property values corresponding to the property names
1158 * @param {Object} object The object to query.
1159 * @param {Array} props The property names to get values for.
1160 * @returns {Object} Returns the array of property values.
1162 function baseValues(object, props) {
1163 return arrayMap(props, function(key) {
1169 * Checks if a `cache` value for `key` exists.
1172 * @param {Object} cache The cache to query.
1173 * @param {string} key The key of the entry to check.
1174 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1176 function cacheHas(cache, key) {
1177 return cache.has(key);
1181 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
1182 * that is not found in the character symbols.
1185 * @param {Array} strSymbols The string symbols to inspect.
1186 * @param {Array} chrSymbols The character symbols to find.
1187 * @returns {number} Returns the index of the first unmatched string symbol.
1189 function charsStartIndex(strSymbols, chrSymbols) {
1191 length = strSymbols.length;
1193 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1198 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
1199 * that is not found in the character symbols.
1202 * @param {Array} strSymbols The string symbols to inspect.
1203 * @param {Array} chrSymbols The character symbols to find.
1204 * @returns {number} Returns the index of the last unmatched string symbol.
1206 function charsEndIndex(strSymbols, chrSymbols) {
1207 var index = strSymbols.length;
1209 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1214 * Gets the number of `placeholder` occurrences in `array`.
1217 * @param {Array} array The array to inspect.
1218 * @param {*} placeholder The placeholder to search for.
1219 * @returns {number} Returns the placeholder count.
1221 function countHolders(array, placeholder) {
1222 var length = array.length,
1226 if (array[length] === placeholder) {
1234 * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
1235 * letters to basic Latin letters.
1238 * @param {string} letter The matched letter to deburr.
1239 * @returns {string} Returns the deburred letter.
1241 var deburrLetter = basePropertyOf(deburredLetters);
1244 * Used by `_.escape` to convert characters to HTML entities.
1247 * @param {string} chr The matched character to escape.
1248 * @returns {string} Returns the escaped character.
1250 var escapeHtmlChar = basePropertyOf(htmlEscapes);
1253 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1256 * @param {string} chr The matched character to escape.
1257 * @returns {string} Returns the escaped character.
1259 function escapeStringChar(chr) {
1260 return '\\' + stringEscapes[chr];
1264 * Gets the value at `key` of `object`.
1267 * @param {Object} [object] The object to query.
1268 * @param {string} key The key of the property to get.
1269 * @returns {*} Returns the property value.
1271 function getValue(object, key) {
1272 return object == null ? undefined : object[key];
1276 * Checks if `string` contains Unicode symbols.
1279 * @param {string} string The string to inspect.
1280 * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1282 function hasUnicode(string) {
1283 return reHasUnicode.test(string);
1287 * Checks if `string` contains a word composed of Unicode symbols.
1290 * @param {string} string The string to inspect.
1291 * @returns {boolean} Returns `true` if a word is found, else `false`.
1293 function hasUnicodeWord(string) {
1294 return reHasUnicodeWord.test(string);
1298 * Converts `iterator` to an array.
1301 * @param {Object} iterator The iterator to convert.
1302 * @returns {Array} Returns the converted array.
1304 function iteratorToArray(iterator) {
1308 while (!(data = iterator.next()).done) {
1309 result.push(data.value);
1315 * Converts `map` to its key-value pairs.
1318 * @param {Object} map The map to convert.
1319 * @returns {Array} Returns the key-value pairs.
1321 function mapToArray(map) {
1323 result = Array(map.size);
1325 map.forEach(function(value, key) {
1326 result[++index] = [key, value];
1332 * Creates a unary function that invokes `func` with its argument transformed.
1335 * @param {Function} func The function to wrap.
1336 * @param {Function} transform The argument transform.
1337 * @returns {Function} Returns the new function.
1339 function overArg(func, transform) {
1340 return function(arg) {
1341 return func(transform(arg));
1346 * Replaces all `placeholder` elements in `array` with an internal placeholder
1347 * and returns an array of their indexes.
1350 * @param {Array} array The array to modify.
1351 * @param {*} placeholder The placeholder to replace.
1352 * @returns {Array} Returns the new array of placeholder indexes.
1354 function replaceHolders(array, placeholder) {
1356 length = array.length,
1360 while (++index < length) {
1361 var value = array[index];
1362 if (value === placeholder || value === PLACEHOLDER) {
1363 array[index] = PLACEHOLDER;
1364 result[resIndex++] = index;
1371 * Converts `set` to an array of its values.
1374 * @param {Object} set The set to convert.
1375 * @returns {Array} Returns the values.
1377 function setToArray(set) {
1379 result = Array(set.size);
1381 set.forEach(function(value) {
1382 result[++index] = value;
1388 * Converts `set` to its value-value pairs.
1391 * @param {Object} set The set to convert.
1392 * @returns {Array} Returns the value-value pairs.
1394 function setToPairs(set) {
1396 result = Array(set.size);
1398 set.forEach(function(value) {
1399 result[++index] = [value, value];
1405 * A specialized version of `_.indexOf` which performs strict equality
1406 * comparisons of values, i.e. `===`.
1409 * @param {Array} array The array to inspect.
1410 * @param {*} value The value to search for.
1411 * @param {number} fromIndex The index to search from.
1412 * @returns {number} Returns the index of the matched value, else `-1`.
1414 function strictIndexOf(array, value, fromIndex) {
1415 var index = fromIndex - 1,
1416 length = array.length;
1418 while (++index < length) {
1419 if (array[index] === value) {
1427 * A specialized version of `_.lastIndexOf` which performs strict equality
1428 * comparisons of values, i.e. `===`.
1431 * @param {Array} array The array to inspect.
1432 * @param {*} value The value to search for.
1433 * @param {number} fromIndex The index to search from.
1434 * @returns {number} Returns the index of the matched value, else `-1`.
1436 function strictLastIndexOf(array, value, fromIndex) {
1437 var index = fromIndex + 1;
1439 if (array[index] === value) {
1447 * Gets the number of symbols in `string`.
1450 * @param {string} string The string to inspect.
1451 * @returns {number} Returns the string size.
1453 function stringSize(string) {
1454 return hasUnicode(string) ?
1455 unicodeSize(string) :
1460 * Converts `string` to an array.
1463 * @param {string} string The string to convert.
1464 * @returns {Array} Returns the converted array.
1466 function stringToArray(string) {
1467 return hasUnicode(string) ?
1468 unicodeToArray(string) :
1469 asciiToArray(string);
1473 * Used by `_.unescape` to convert HTML entities to characters.
1476 * @param {string} chr The matched character to unescape.
1477 * @returns {string} Returns the unescaped character.
1479 var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
1482 * Gets the size of a Unicode `string`.
1485 * @param {string} string The string inspect.
1486 * @returns {number} Returns the string size.
1488 function unicodeSize(string) {
1489 var result = reUnicode.lastIndex = 0;
1490 while (reUnicode.test(string)) {
1497 * Converts a Unicode `string` to an array.
1500 * @param {string} string The string to convert.
1501 * @returns {Array} Returns the converted array.
1503 function unicodeToArray(string) {
1504 return string.match(reUnicode) || [];
1508 * Splits a Unicode `string` into an array of its words.
1511 * @param {string} The string to inspect.
1512 * @returns {Array} Returns the words of `string`.
1514 function unicodeWords(string) {
1515 return string.match(reUnicodeWord) || [];
1518 /*--------------------------------------------------------------------------*/
1521 * Create a new pristine `lodash` function using the `context` object.
1527 * @param {Object} [context=root] The context object.
1528 * @returns {Function} Returns a new `lodash` function.
1531 * _.mixin({ 'foo': _.constant('foo') });
1533 * var lodash = _.runInContext();
1534 * lodash.mixin({ 'bar': lodash.constant('bar') });
1536 * _.isFunction(_.foo);
1538 * _.isFunction(_.bar);
1541 * lodash.isFunction(lodash.foo);
1543 * lodash.isFunction(lodash.bar);
1546 * // Create a suped-up `defer` in Node.js.
1547 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1549 var runInContext = (function runInContext(context) {
1550 context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
1552 /** Built-in constructor references. */
1553 var Array = context.Array,
1554 Date = context.Date,
1555 Error = context.Error,
1556 Function = context.Function,
1557 Math = context.Math,
1558 Object = context.Object,
1559 RegExp = context.RegExp,
1560 String = context.String,
1561 TypeError = context.TypeError;
1563 /** Used for built-in method references. */
1564 var arrayProto = Array.prototype,
1565 funcProto = Function.prototype,
1566 objectProto = Object.prototype;
1568 /** Used to detect overreaching core-js shims. */
1569 var coreJsData = context['__core-js_shared__'];
1571 /** Used to resolve the decompiled source of functions. */
1572 var funcToString = funcProto.toString;
1574 /** Used to check objects for own properties. */
1575 var hasOwnProperty = objectProto.hasOwnProperty;
1577 /** Used to generate unique IDs. */
1580 /** Used to detect methods masquerading as native. */
1581 var maskSrcKey = (function() {
1582 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
1583 return uid ? ('Symbol(src)_1.' + uid) : '';
1587 * Used to resolve the
1588 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
1591 var nativeObjectToString = objectProto.toString;
1593 /** Used to infer the `Object` constructor. */
1594 var objectCtorString = funcToString.call(Object);
1596 /** Used to restore the original `_` reference in `_.noConflict`. */
1597 var oldDash = root._;
1599 /** Used to detect if a method is native. */
1600 var reIsNative = RegExp('^' +
1601 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1602 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1605 /** Built-in value references. */
1606 var Buffer = moduleExports ? context.Buffer : undefined,
1607 Symbol = context.Symbol,
1608 Uint8Array = context.Uint8Array,
1609 allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
1610 getPrototype = overArg(Object.getPrototypeOf, Object),
1611 objectCreate = Object.create,
1612 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1613 splice = arrayProto.splice,
1614 spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
1615 symIterator = Symbol ? Symbol.iterator : undefined,
1616 symToStringTag = Symbol ? Symbol.toStringTag : undefined;
1618 var defineProperty = (function() {
1620 var func = getNative(Object, 'defineProperty');
1626 /** Mocked built-ins. */
1627 var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
1628 ctxNow = Date && Date.now !== root.Date.now && Date.now,
1629 ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1631 /* Built-in method references for those with the same name as other `lodash` methods. */
1632 var nativeCeil = Math.ceil,
1633 nativeFloor = Math.floor,
1634 nativeGetSymbols = Object.getOwnPropertySymbols,
1635 nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
1636 nativeIsFinite = context.isFinite,
1637 nativeJoin = arrayProto.join,
1638 nativeKeys = overArg(Object.keys, Object),
1639 nativeMax = Math.max,
1640 nativeMin = Math.min,
1641 nativeNow = Date.now,
1642 nativeParseInt = context.parseInt,
1643 nativeRandom = Math.random,
1644 nativeReverse = arrayProto.reverse;
1646 /* Built-in method references that are verified to be native. */
1647 var DataView = getNative(context, 'DataView'),
1648 Map = getNative(context, 'Map'),
1649 Promise = getNative(context, 'Promise'),
1650 Set = getNative(context, 'Set'),
1651 WeakMap = getNative(context, 'WeakMap'),
1652 nativeCreate = getNative(Object, 'create');
1654 /** Used to store function metadata. */
1655 var metaMap = WeakMap && new WeakMap;
1657 /** Used to lookup unminified function names. */
1660 /** Used to detect maps, sets, and weakmaps. */
1661 var dataViewCtorString = toSource(DataView),
1662 mapCtorString = toSource(Map),
1663 promiseCtorString = toSource(Promise),
1664 setCtorString = toSource(Set),
1665 weakMapCtorString = toSource(WeakMap);
1667 /** Used to convert symbols to primitives and strings. */
1668 var symbolProto = Symbol ? Symbol.prototype : undefined,
1669 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
1670 symbolToString = symbolProto ? symbolProto.toString : undefined;
1672 /*------------------------------------------------------------------------*/
1675 * Creates a `lodash` object which wraps `value` to enable implicit method
1676 * chain sequences. Methods that operate on and return arrays, collections,
1677 * and functions can be chained together. Methods that retrieve a single value
1678 * or may return a primitive value will automatically end the chain sequence
1679 * and return the unwrapped value. Otherwise, the value must be unwrapped
1682 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
1683 * enabled using `_.chain`.
1685 * The execution of chained methods is lazy, that is, it's deferred until
1686 * `_#value` is implicitly or explicitly called.
1688 * Lazy evaluation allows several methods to support shortcut fusion.
1689 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
1690 * the creation of intermediate arrays and can greatly reduce the number of
1691 * iteratee executions. Sections of a chain sequence qualify for shortcut
1692 * fusion if the section is applied to an array and iteratees accept only
1693 * one argument. The heuristic for whether a section qualifies for shortcut
1694 * fusion is subject to change.
1696 * Chaining is supported in custom builds as long as the `_#value` method is
1697 * directly or indirectly included in the build.
1699 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1701 * The wrapper `Array` methods are:
1702 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1704 * The wrapper `String` methods are:
1705 * `replace` and `split`
1707 * The wrapper methods that support shortcut fusion are:
1708 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1709 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1710 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1712 * The chainable wrapper methods are:
1713 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
1714 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
1715 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
1716 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
1717 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
1718 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
1719 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
1720 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
1721 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
1722 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
1723 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
1724 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
1725 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
1726 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
1727 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
1728 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
1729 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
1730 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
1731 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
1732 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
1733 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
1734 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
1735 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
1736 * `zipObject`, `zipObjectDeep`, and `zipWith`
1738 * The wrapper methods that are **not** chainable by default are:
1739 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1740 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
1741 * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
1742 * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
1743 * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
1744 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
1745 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
1746 * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
1747 * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
1748 * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
1749 * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
1750 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
1751 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
1752 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
1753 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
1754 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
1755 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
1756 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
1757 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
1758 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
1759 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
1760 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
1761 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
1762 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
1763 * `upperFirst`, `value`, and `words`
1768 * @param {*} value The value to wrap in a `lodash` instance.
1769 * @returns {Object} Returns the new `lodash` wrapper instance.
1772 * function square(n) {
1776 * var wrapped = _([1, 2, 3]);
1778 * // Returns an unwrapped value.
1779 * wrapped.reduce(_.add);
1782 * // Returns a wrapped value.
1783 * var squares = wrapped.map(square);
1785 * _.isArray(squares);
1788 * _.isArray(squares.value());
1791 function lodash(value) {
1792 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1793 if (value instanceof LodashWrapper) {
1796 if (hasOwnProperty.call(value, '__wrapped__')) {
1797 return wrapperClone(value);
1800 return new LodashWrapper(value);
1804 * The base implementation of `_.create` without support for assigning
1805 * properties to the created object.
1808 * @param {Object} proto The object to inherit from.
1809 * @returns {Object} Returns the new object.
1811 var baseCreate = (function() {
1812 function object() {}
1813 return function(proto) {
1814 if (!isObject(proto)) {
1818 return objectCreate(proto);
1820 object.prototype = proto;
1821 var result = new object;
1822 object.prototype = undefined;
1828 * The function whose prototype chain sequence wrappers inherit from.
1832 function baseLodash() {
1833 // No operation performed.
1837 * The base constructor for creating `lodash` wrapper objects.
1840 * @param {*} value The value to wrap.
1841 * @param {boolean} [chainAll] Enable explicit method chain sequences.
1843 function LodashWrapper(value, chainAll) {
1844 this.__wrapped__ = value;
1845 this.__actions__ = [];
1846 this.__chain__ = !!chainAll;
1848 this.__values__ = undefined;
1852 * By default, the template delimiters used by lodash are like those in
1853 * embedded Ruby (ERB) as well as ES2015 template strings. Change the
1854 * following template settings to use alternative delimiters.
1860 lodash.templateSettings = {
1863 * Used to detect `data` property values to be HTML-escaped.
1865 * @memberOf _.templateSettings
1871 * Used to detect code to be evaluated.
1873 * @memberOf _.templateSettings
1876 'evaluate': reEvaluate,
1879 * Used to detect `data` property values to inject.
1881 * @memberOf _.templateSettings
1884 'interpolate': reInterpolate,
1887 * Used to reference the data object in the template text.
1889 * @memberOf _.templateSettings
1895 * Used to import variables into the compiled template.
1897 * @memberOf _.templateSettings
1903 * A reference to the `lodash` function.
1905 * @memberOf _.templateSettings.imports
1912 // Ensure wrappers are instances of `baseLodash`.
1913 lodash.prototype = baseLodash.prototype;
1914 lodash.prototype.constructor = lodash;
1916 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
1917 LodashWrapper.prototype.constructor = LodashWrapper;
1919 /*------------------------------------------------------------------------*/
1922 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1926 * @param {*} value The value to wrap.
1928 function LazyWrapper(value) {
1929 this.__wrapped__ = value;
1930 this.__actions__ = [];
1932 this.__filtered__ = false;
1933 this.__iteratees__ = [];
1934 this.__takeCount__ = MAX_ARRAY_LENGTH;
1935 this.__views__ = [];
1939 * Creates a clone of the lazy wrapper object.
1943 * @memberOf LazyWrapper
1944 * @returns {Object} Returns the cloned `LazyWrapper` object.
1946 function lazyClone() {
1947 var result = new LazyWrapper(this.__wrapped__);
1948 result.__actions__ = copyArray(this.__actions__);
1949 result.__dir__ = this.__dir__;
1950 result.__filtered__ = this.__filtered__;
1951 result.__iteratees__ = copyArray(this.__iteratees__);
1952 result.__takeCount__ = this.__takeCount__;
1953 result.__views__ = copyArray(this.__views__);
1958 * Reverses the direction of lazy iteration.
1962 * @memberOf LazyWrapper
1963 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1965 function lazyReverse() {
1966 if (this.__filtered__) {
1967 var result = new LazyWrapper(this);
1968 result.__dir__ = -1;
1969 result.__filtered__ = true;
1971 result = this.clone();
1972 result.__dir__ *= -1;
1978 * Extracts the unwrapped value from its lazy wrapper.
1982 * @memberOf LazyWrapper
1983 * @returns {*} Returns the unwrapped value.
1985 function lazyValue() {
1986 var array = this.__wrapped__.value(),
1988 isArr = isArray(array),
1990 arrLength = isArr ? array.length : 0,
1991 view = getView(0, arrLength, this.__views__),
1994 length = end - start,
1995 index = isRight ? end : (start - 1),
1996 iteratees = this.__iteratees__,
1997 iterLength = iteratees.length,
1999 takeCount = nativeMin(length, this.__takeCount__);
2001 if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
2002 return baseWrapperValue(array, this.__actions__);
2007 while (length-- && resIndex < takeCount) {
2011 value = array[index];
2013 while (++iterIndex < iterLength) {
2014 var data = iteratees[iterIndex],
2015 iteratee = data.iteratee,
2017 computed = iteratee(value);
2019 if (type == LAZY_MAP_FLAG) {
2021 } else if (!computed) {
2022 if (type == LAZY_FILTER_FLAG) {
2029 result[resIndex++] = value;
2034 // Ensure `LazyWrapper` is an instance of `baseLodash`.
2035 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
2036 LazyWrapper.prototype.constructor = LazyWrapper;
2038 /*------------------------------------------------------------------------*/
2041 * Creates a hash object.
2045 * @param {Array} [entries] The key-value pairs to cache.
2047 function Hash(entries) {
2049 length = entries == null ? 0 : entries.length;
2052 while (++index < length) {
2053 var entry = entries[index];
2054 this.set(entry[0], entry[1]);
2059 * Removes all key-value entries from the hash.
2065 function hashClear() {
2066 this.__data__ = nativeCreate ? nativeCreate(null) : {};
2071 * Removes `key` and its value from the hash.
2076 * @param {Object} hash The hash to modify.
2077 * @param {string} key The key of the value to remove.
2078 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2080 function hashDelete(key) {
2081 var result = this.has(key) && delete this.__data__[key];
2082 this.size -= result ? 1 : 0;
2087 * Gets the hash value for `key`.
2092 * @param {string} key The key of the value to get.
2093 * @returns {*} Returns the entry value.
2095 function hashGet(key) {
2096 var data = this.__data__;
2098 var result = data[key];
2099 return result === HASH_UNDEFINED ? undefined : result;
2101 return hasOwnProperty.call(data, key) ? data[key] : undefined;
2105 * Checks if a hash value for `key` exists.
2110 * @param {string} key The key of the entry to check.
2111 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2113 function hashHas(key) {
2114 var data = this.__data__;
2115 return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
2119 * Sets the hash `key` to `value`.
2124 * @param {string} key The key of the value to set.
2125 * @param {*} value The value to set.
2126 * @returns {Object} Returns the hash instance.
2128 function hashSet(key, value) {
2129 var data = this.__data__;
2130 this.size += this.has(key) ? 0 : 1;
2131 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
2135 // Add methods to `Hash`.
2136 Hash.prototype.clear = hashClear;
2137 Hash.prototype['delete'] = hashDelete;
2138 Hash.prototype.get = hashGet;
2139 Hash.prototype.has = hashHas;
2140 Hash.prototype.set = hashSet;
2142 /*------------------------------------------------------------------------*/
2145 * Creates an list cache object.
2149 * @param {Array} [entries] The key-value pairs to cache.
2151 function ListCache(entries) {
2153 length = entries == null ? 0 : entries.length;
2156 while (++index < length) {
2157 var entry = entries[index];
2158 this.set(entry[0], entry[1]);
2163 * Removes all key-value entries from the list cache.
2167 * @memberOf ListCache
2169 function listCacheClear() {
2175 * Removes `key` and its value from the list cache.
2179 * @memberOf ListCache
2180 * @param {string} key The key of the value to remove.
2181 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2183 function listCacheDelete(key) {
2184 var data = this.__data__,
2185 index = assocIndexOf(data, key);
2190 var lastIndex = data.length - 1;
2191 if (index == lastIndex) {
2194 splice.call(data, index, 1);
2201 * Gets the list cache value for `key`.
2205 * @memberOf ListCache
2206 * @param {string} key The key of the value to get.
2207 * @returns {*} Returns the entry value.
2209 function listCacheGet(key) {
2210 var data = this.__data__,
2211 index = assocIndexOf(data, key);
2213 return index < 0 ? undefined : data[index][1];
2217 * Checks if a list cache value for `key` exists.
2221 * @memberOf ListCache
2222 * @param {string} key The key of the entry to check.
2223 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2225 function listCacheHas(key) {
2226 return assocIndexOf(this.__data__, key) > -1;
2230 * Sets the list cache `key` to `value`.
2234 * @memberOf ListCache
2235 * @param {string} key The key of the value to set.
2236 * @param {*} value The value to set.
2237 * @returns {Object} Returns the list cache instance.
2239 function listCacheSet(key, value) {
2240 var data = this.__data__,
2241 index = assocIndexOf(data, key);
2245 data.push([key, value]);
2247 data[index][1] = value;
2252 // Add methods to `ListCache`.
2253 ListCache.prototype.clear = listCacheClear;
2254 ListCache.prototype['delete'] = listCacheDelete;
2255 ListCache.prototype.get = listCacheGet;
2256 ListCache.prototype.has = listCacheHas;
2257 ListCache.prototype.set = listCacheSet;
2259 /*------------------------------------------------------------------------*/
2262 * Creates a map cache object to store key-value pairs.
2266 * @param {Array} [entries] The key-value pairs to cache.
2268 function MapCache(entries) {
2270 length = entries == null ? 0 : entries.length;
2273 while (++index < length) {
2274 var entry = entries[index];
2275 this.set(entry[0], entry[1]);
2280 * Removes all key-value entries from the map.
2284 * @memberOf MapCache
2286 function mapCacheClear() {
2290 'map': new(Map || ListCache),
2296 * Removes `key` and its value from the map.
2300 * @memberOf MapCache
2301 * @param {string} key The key of the value to remove.
2302 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2304 function mapCacheDelete(key) {
2305 var result = getMapData(this, key)['delete'](key);
2306 this.size -= result ? 1 : 0;
2311 * Gets the map value for `key`.
2315 * @memberOf MapCache
2316 * @param {string} key The key of the value to get.
2317 * @returns {*} Returns the entry value.
2319 function mapCacheGet(key) {
2320 return getMapData(this, key).get(key);
2324 * Checks if a map value for `key` exists.
2328 * @memberOf MapCache
2329 * @param {string} key The key of the entry to check.
2330 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2332 function mapCacheHas(key) {
2333 return getMapData(this, key).has(key);
2337 * Sets the map `key` to `value`.
2341 * @memberOf MapCache
2342 * @param {string} key The key of the value to set.
2343 * @param {*} value The value to set.
2344 * @returns {Object} Returns the map cache instance.
2346 function mapCacheSet(key, value) {
2347 var data = getMapData(this, key),
2350 data.set(key, value);
2351 this.size += data.size == size ? 0 : 1;
2355 // Add methods to `MapCache`.
2356 MapCache.prototype.clear = mapCacheClear;
2357 MapCache.prototype['delete'] = mapCacheDelete;
2358 MapCache.prototype.get = mapCacheGet;
2359 MapCache.prototype.has = mapCacheHas;
2360 MapCache.prototype.set = mapCacheSet;
2362 /*------------------------------------------------------------------------*/
2366 * Creates an array cache object to store unique values.
2370 * @param {Array} [values] The values to cache.
2372 function SetCache(values) {
2374 length = values == null ? 0 : values.length;
2376 this.__data__ = new MapCache;
2377 while (++index < length) {
2378 this.add(values[index]);
2383 * Adds `value` to the array cache.
2387 * @memberOf SetCache
2389 * @param {*} value The value to cache.
2390 * @returns {Object} Returns the cache instance.
2392 function setCacheAdd(value) {
2393 this.__data__.set(value, HASH_UNDEFINED);
2398 * Checks if `value` is in the array cache.
2402 * @memberOf SetCache
2403 * @param {*} value The value to search for.
2404 * @returns {number} Returns `true` if `value` is found, else `false`.
2406 function setCacheHas(value) {
2407 return this.__data__.has(value);
2410 // Add methods to `SetCache`.
2411 SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
2412 SetCache.prototype.has = setCacheHas;
2414 /*------------------------------------------------------------------------*/
2417 * Creates a stack cache object to store key-value pairs.
2421 * @param {Array} [entries] The key-value pairs to cache.
2423 function Stack(entries) {
2424 var data = this.__data__ = new ListCache(entries);
2425 this.size = data.size;
2429 * Removes all key-value entries from the stack.
2435 function stackClear() {
2436 this.__data__ = new ListCache;
2441 * Removes `key` and its value from the stack.
2446 * @param {string} key The key of the value to remove.
2447 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2449 function stackDelete(key) {
2450 var data = this.__data__,
2451 result = data['delete'](key);
2453 this.size = data.size;
2458 * Gets the stack value for `key`.
2463 * @param {string} key The key of the value to get.
2464 * @returns {*} Returns the entry value.
2466 function stackGet(key) {
2467 return this.__data__.get(key);
2471 * Checks if a stack value for `key` exists.
2476 * @param {string} key The key of the entry to check.
2477 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2479 function stackHas(key) {
2480 return this.__data__.has(key);
2484 * Sets the stack `key` to `value`.
2489 * @param {string} key The key of the value to set.
2490 * @param {*} value The value to set.
2491 * @returns {Object} Returns the stack cache instance.
2493 function stackSet(key, value) {
2494 var data = this.__data__;
2495 if (data instanceof ListCache) {
2496 var pairs = data.__data__;
2497 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
2498 pairs.push([key, value]);
2499 this.size = ++data.size;
2502 data = this.__data__ = new MapCache(pairs);
2504 data.set(key, value);
2505 this.size = data.size;
2509 // Add methods to `Stack`.
2510 Stack.prototype.clear = stackClear;
2511 Stack.prototype['delete'] = stackDelete;
2512 Stack.prototype.get = stackGet;
2513 Stack.prototype.has = stackHas;
2514 Stack.prototype.set = stackSet;
2516 /*------------------------------------------------------------------------*/
2519 * Creates an array of the enumerable property names of the array-like `value`.
2522 * @param {*} value The value to query.
2523 * @param {boolean} inherited Specify returning inherited property names.
2524 * @returns {Array} Returns the array of property names.
2526 function arrayLikeKeys(value, inherited) {
2527 var isArr = isArray(value),
2528 isArg = !isArr && isArguments(value),
2529 isBuff = !isArr && !isArg && isBuffer(value),
2530 isType = !isArr && !isArg && !isBuff && isTypedArray(value),
2531 skipIndexes = isArr || isArg || isBuff || isType,
2532 result = skipIndexes ? baseTimes(value.length, String) : [],
2533 length = result.length;
2535 for (var key in value) {
2536 if ((inherited || hasOwnProperty.call(value, key)) &&
2538 // Safari 9 has enumerable `arguments.length` in strict mode.
2540 // Node.js 0.10 has enumerable non-index properties on buffers.
2541 (isBuff && (key == 'offset' || key == 'parent')) ||
2542 // PhantomJS 2 has enumerable non-index properties on typed arrays.
2543 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
2544 // Skip index properties.
2545 isIndex(key, length)
2554 * A specialized version of `_.sample` for arrays.
2557 * @param {Array} array The array to sample.
2558 * @returns {*} Returns the random element.
2560 function arraySample(array) {
2561 var length = array.length;
2562 return length ? array[baseRandom(0, length - 1)] : undefined;
2566 * A specialized version of `_.sampleSize` for arrays.
2569 * @param {Array} array The array to sample.
2570 * @param {number} n The number of elements to sample.
2571 * @returns {Array} Returns the random elements.
2573 function arraySampleSize(array, n) {
2574 return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
2578 * A specialized version of `_.shuffle` for arrays.
2581 * @param {Array} array The array to shuffle.
2582 * @returns {Array} Returns the new shuffled array.
2584 function arrayShuffle(array) {
2585 return shuffleSelf(copyArray(array));
2589 * This function is like `assignValue` except that it doesn't assign
2590 * `undefined` values.
2593 * @param {Object} object The object to modify.
2594 * @param {string} key The key of the property to assign.
2595 * @param {*} value The value to assign.
2597 function assignMergeValue(object, key, value) {
2598 if ((value !== undefined && !eq(object[key], value)) ||
2599 (value === undefined && !(key in object))) {
2600 baseAssignValue(object, key, value);
2605 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2606 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
2607 * for equality comparisons.
2610 * @param {Object} object The object to modify.
2611 * @param {string} key The key of the property to assign.
2612 * @param {*} value The value to assign.
2614 function assignValue(object, key, value) {
2615 var objValue = object[key];
2616 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2617 (value === undefined && !(key in object))) {
2618 baseAssignValue(object, key, value);
2623 * Gets the index at which the `key` is found in `array` of key-value pairs.
2626 * @param {Array} array The array to inspect.
2627 * @param {*} key The key to search for.
2628 * @returns {number} Returns the index of the matched value, else `-1`.
2630 function assocIndexOf(array, key) {
2631 var length = array.length;
2633 if (eq(array[length][0], key)) {
2641 * Aggregates elements of `collection` on `accumulator` with keys transformed
2642 * by `iteratee` and values set by `setter`.
2645 * @param {Array|Object} collection The collection to iterate over.
2646 * @param {Function} setter The function to set `accumulator` values.
2647 * @param {Function} iteratee The iteratee to transform keys.
2648 * @param {Object} accumulator The initial aggregated object.
2649 * @returns {Function} Returns `accumulator`.
2651 function baseAggregator(collection, setter, iteratee, accumulator) {
2652 baseEach(collection, function(value, key, collection) {
2653 setter(accumulator, value, iteratee(value), collection);
2659 * The base implementation of `_.assign` without support for multiple sources
2660 * or `customizer` functions.
2663 * @param {Object} object The destination object.
2664 * @param {Object} source The source object.
2665 * @returns {Object} Returns `object`.
2667 function baseAssign(object, source) {
2668 return object && copyObject(source, keys(source), object);
2672 * The base implementation of `_.assignIn` without support for multiple sources
2673 * or `customizer` functions.
2676 * @param {Object} object The destination object.
2677 * @param {Object} source The source object.
2678 * @returns {Object} Returns `object`.
2680 function baseAssignIn(object, source) {
2681 return object && copyObject(source, keysIn(source), object);
2685 * The base implementation of `assignValue` and `assignMergeValue` without
2689 * @param {Object} object The object to modify.
2690 * @param {string} key The key of the property to assign.
2691 * @param {*} value The value to assign.
2693 function baseAssignValue(object, key, value) {
2694 if (key == '__proto__' && defineProperty) {
2695 defineProperty(object, key, {
2696 'configurable': true,
2702 object[key] = value;
2707 * The base implementation of `_.at` without support for individual paths.
2710 * @param {Object} object The object to iterate over.
2711 * @param {string[]} paths The property paths to pick.
2712 * @returns {Array} Returns the picked elements.
2714 function baseAt(object, paths) {
2716 length = paths.length,
2717 result = Array(length),
2718 skip = object == null;
2720 while (++index < length) {
2721 result[index] = skip ? undefined : get(object, paths[index]);
2727 * The base implementation of `_.clamp` which doesn't coerce arguments.
2730 * @param {number} number The number to clamp.
2731 * @param {number} [lower] The lower bound.
2732 * @param {number} upper The upper bound.
2733 * @returns {number} Returns the clamped number.
2735 function baseClamp(number, lower, upper) {
2736 if (number === number) {
2737 if (upper !== undefined) {
2738 number = number <= upper ? number : upper;
2740 if (lower !== undefined) {
2741 number = number >= lower ? number : lower;
2748 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2749 * traversed objects.
2752 * @param {*} value The value to clone.
2753 * @param {boolean} bitmask The bitmask flags.
2755 * 2 - Flatten inherited properties
2757 * @param {Function} [customizer] The function to customize cloning.
2758 * @param {string} [key] The key of `value`.
2759 * @param {Object} [object] The parent object of `value`.
2760 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2761 * @returns {*} Returns the cloned value.
2763 function baseClone(value, bitmask, customizer, key, object, stack) {
2765 isDeep = bitmask & CLONE_DEEP_FLAG,
2766 isFlat = bitmask & CLONE_FLAT_FLAG,
2767 isFull = bitmask & CLONE_SYMBOLS_FLAG;
2770 result = object ? customizer(value, key, object, stack) : customizer(value);
2772 if (result !== undefined) {
2775 if (!isObject(value)) {
2778 var isArr = isArray(value);
2780 result = initCloneArray(value);
2782 return copyArray(value, result);
2785 var tag = getTag(value),
2786 isFunc = tag == funcTag || tag == genTag;
2788 if (isBuffer(value)) {
2789 return cloneBuffer(value, isDeep);
2791 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2792 result = (isFlat || isFunc) ? {} : initCloneObject(value);
2795 copySymbolsIn(value, baseAssignIn(result, value)) :
2796 copySymbols(value, baseAssign(result, value));
2799 if (!cloneableTags[tag]) {
2800 return object ? value : {};
2802 result = initCloneByTag(value, tag, isDeep);
2805 // Check for circular references and return its corresponding clone.
2806 stack || (stack = new Stack);
2807 var stacked = stack.get(value);
2811 stack.set(value, result);
2814 value.forEach(function(subValue) {
2815 result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
2817 } else if (isMap(value)) {
2818 value.forEach(function(subValue, key) {
2819 result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
2823 var keysFunc = isFull ?
2824 (isFlat ? getAllKeysIn : getAllKeys) :
2825 (isFlat ? keysIn : keys);
2827 var props = isArr ? undefined : keysFunc(value);
2828 arrayEach(props || value, function(subValue, key) {
2831 subValue = value[key];
2833 // Recursively populate clone (susceptible to call stack limits).
2834 assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
2840 * The base implementation of `_.conforms` which doesn't clone `source`.
2843 * @param {Object} source The object of property predicates to conform to.
2844 * @returns {Function} Returns the new spec function.
2846 function baseConforms(source) {
2847 var props = keys(source);
2848 return function(object) {
2849 return baseConformsTo(object, source, props);
2854 * The base implementation of `_.conformsTo` which accepts `props` to check.
2857 * @param {Object} object The object to inspect.
2858 * @param {Object} source The object of property predicates to conform to.
2859 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
2861 function baseConformsTo(object, source, props) {
2862 var length = props.length;
2863 if (object == null) {
2866 object = Object(object);
2868 var key = props[length],
2869 predicate = source[key],
2870 value = object[key];
2872 if ((value === undefined && !(key in object)) || !predicate(value)) {
2880 * The base implementation of `_.delay` and `_.defer` which accepts `args`
2881 * to provide to `func`.
2884 * @param {Function} func The function to delay.
2885 * @param {number} wait The number of milliseconds to delay invocation.
2886 * @param {Array} args The arguments to provide to `func`.
2887 * @returns {number|Object} Returns the timer id or timeout object.
2889 function baseDelay(func, wait, args) {
2890 if (typeof func != 'function') {
2891 throw new TypeError(FUNC_ERROR_TEXT);
2893 return setTimeout(function() {
2894 func.apply(undefined, args);
2899 * The base implementation of methods like `_.difference` without support
2900 * for excluding multiple arrays or iteratee shorthands.
2903 * @param {Array} array The array to inspect.
2904 * @param {Array} values The values to exclude.
2905 * @param {Function} [iteratee] The iteratee invoked per element.
2906 * @param {Function} [comparator] The comparator invoked per element.
2907 * @returns {Array} Returns the new array of filtered values.
2909 function baseDifference(array, values, iteratee, comparator) {
2911 includes = arrayIncludes,
2913 length = array.length,
2915 valuesLength = values.length;
2921 values = arrayMap(values, baseUnary(iteratee));
2924 includes = arrayIncludesWith;
2926 } else if (values.length >= LARGE_ARRAY_SIZE) {
2927 includes = cacheHas;
2929 values = new SetCache(values);
2932 while (++index < length) {
2933 var value = array[index],
2934 computed = iteratee == null ? value : iteratee(value);
2936 value = (comparator || value !== 0) ? value : 0;
2937 if (isCommon && computed === computed) {
2938 var valuesIndex = valuesLength;
2939 while (valuesIndex--) {
2940 if (values[valuesIndex] === computed) {
2945 } else if (!includes(values, computed, comparator)) {
2953 * The base implementation of `_.forEach` without support for iteratee shorthands.
2956 * @param {Array|Object} collection The collection to iterate over.
2957 * @param {Function} iteratee The function invoked per iteration.
2958 * @returns {Array|Object} Returns `collection`.
2960 var baseEach = createBaseEach(baseForOwn);
2963 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2966 * @param {Array|Object} collection The collection to iterate over.
2967 * @param {Function} iteratee The function invoked per iteration.
2968 * @returns {Array|Object} Returns `collection`.
2970 var baseEachRight = createBaseEach(baseForOwnRight, true);
2973 * The base implementation of `_.every` without support for iteratee shorthands.
2976 * @param {Array|Object} collection The collection to iterate over.
2977 * @param {Function} predicate The function invoked per iteration.
2978 * @returns {boolean} Returns `true` if all elements pass the predicate check,
2981 function baseEvery(collection, predicate) {
2983 baseEach(collection, function(value, index, collection) {
2984 result = !!predicate(value, index, collection);
2991 * The base implementation of methods like `_.max` and `_.min` which accepts a
2992 * `comparator` to determine the extremum value.
2995 * @param {Array} array The array to iterate over.
2996 * @param {Function} iteratee The iteratee invoked per iteration.
2997 * @param {Function} comparator The comparator used to compare values.
2998 * @returns {*} Returns the extremum value.
3000 function baseExtremum(array, iteratee, comparator) {
3002 length = array.length;
3004 while (++index < length) {
3005 var value = array[index],
3006 current = iteratee(value);
3008 if (current != null && (computed === undefined ?
3009 (current === current && !isSymbol(current)) :
3010 comparator(current, computed)
3012 var computed = current,
3020 * The base implementation of `_.fill` without an iteratee call guard.
3023 * @param {Array} array The array to fill.
3024 * @param {*} value The value to fill `array` with.
3025 * @param {number} [start=0] The start position.
3026 * @param {number} [end=array.length] The end position.
3027 * @returns {Array} Returns `array`.
3029 function baseFill(array, value, start, end) {
3030 var length = array.length;
3032 start = toInteger(start);
3034 start = -start > length ? 0 : (length + start);
3036 end = (end === undefined || end > length) ? length : toInteger(end);
3040 end = start > end ? 0 : toLength(end);
3041 while (start < end) {
3042 array[start++] = value;
3048 * The base implementation of `_.filter` without support for iteratee shorthands.
3051 * @param {Array|Object} collection The collection to iterate over.
3052 * @param {Function} predicate The function invoked per iteration.
3053 * @returns {Array} Returns the new filtered array.
3055 function baseFilter(collection, predicate) {
3057 baseEach(collection, function(value, index, collection) {
3058 if (predicate(value, index, collection)) {
3066 * The base implementation of `_.flatten` with support for restricting flattening.
3069 * @param {Array} array The array to flatten.
3070 * @param {number} depth The maximum recursion depth.
3071 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
3072 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
3073 * @param {Array} [result=[]] The initial result value.
3074 * @returns {Array} Returns the new flattened array.
3076 function baseFlatten(array, depth, predicate, isStrict, result) {
3078 length = array.length;
3080 predicate || (predicate = isFlattenable);
3081 result || (result = []);
3083 while (++index < length) {
3084 var value = array[index];
3085 if (depth > 0 && predicate(value)) {
3087 // Recursively flatten arrays (susceptible to call stack limits).
3088 baseFlatten(value, depth - 1, predicate, isStrict, result);
3090 arrayPush(result, value);
3092 } else if (!isStrict) {
3093 result[result.length] = value;
3100 * The base implementation of `baseForOwn` which iterates over `object`
3101 * properties returned by `keysFunc` and invokes `iteratee` for each property.
3102 * Iteratee functions may exit iteration early by explicitly returning `false`.
3105 * @param {Object} object The object to iterate over.
3106 * @param {Function} iteratee The function invoked per iteration.
3107 * @param {Function} keysFunc The function to get the keys of `object`.
3108 * @returns {Object} Returns `object`.
3110 var baseFor = createBaseFor();
3113 * This function is like `baseFor` except that it iterates over properties
3114 * in the opposite order.
3117 * @param {Object} object The object to iterate over.
3118 * @param {Function} iteratee The function invoked per iteration.
3119 * @param {Function} keysFunc The function to get the keys of `object`.
3120 * @returns {Object} Returns `object`.
3122 var baseForRight = createBaseFor(true);
3125 * The base implementation of `_.forOwn` without support for iteratee shorthands.
3128 * @param {Object} object The object to iterate over.
3129 * @param {Function} iteratee The function invoked per iteration.
3130 * @returns {Object} Returns `object`.
3132 function baseForOwn(object, iteratee) {
3133 return object && baseFor(object, iteratee, keys);
3137 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
3140 * @param {Object} object The object to iterate over.
3141 * @param {Function} iteratee The function invoked per iteration.
3142 * @returns {Object} Returns `object`.
3144 function baseForOwnRight(object, iteratee) {
3145 return object && baseForRight(object, iteratee, keys);
3149 * The base implementation of `_.functions` which creates an array of
3150 * `object` function property names filtered from `props`.
3153 * @param {Object} object The object to inspect.
3154 * @param {Array} props The property names to filter.
3155 * @returns {Array} Returns the function names.
3157 function baseFunctions(object, props) {
3158 return arrayFilter(props, function(key) {
3159 return isFunction(object[key]);
3164 * The base implementation of `_.get` without support for default values.
3167 * @param {Object} object The object to query.
3168 * @param {Array|string} path The path of the property to get.
3169 * @returns {*} Returns the resolved value.
3171 function baseGet(object, path) {
3172 path = castPath(path, object);
3175 length = path.length;
3177 while (object != null && index < length) {
3178 object = object[toKey(path[index++])];
3180 return (index && index == length) ? object : undefined;
3184 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
3185 * `keysFunc` and `symbolsFunc` to get the enumerable property names and
3186 * symbols of `object`.
3189 * @param {Object} object The object to query.
3190 * @param {Function} keysFunc The function to get the keys of `object`.
3191 * @param {Function} symbolsFunc The function to get the symbols of `object`.
3192 * @returns {Array} Returns the array of property names and symbols.
3194 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
3195 var result = keysFunc(object);
3196 return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
3200 * The base implementation of `getTag` without fallbacks for buggy environments.
3203 * @param {*} value The value to query.
3204 * @returns {string} Returns the `toStringTag`.
3206 function baseGetTag(value) {
3207 if (value == null) {
3208 return value === undefined ? undefinedTag : nullTag;
3210 return (symToStringTag && symToStringTag in Object(value)) ?
3212 objectToString(value);
3216 * The base implementation of `_.gt` which doesn't coerce arguments.
3219 * @param {*} value The value to compare.
3220 * @param {*} other The other value to compare.
3221 * @returns {boolean} Returns `true` if `value` is greater than `other`,
3224 function baseGt(value, other) {
3225 return value > other;
3229 * The base implementation of `_.has` without support for deep paths.
3232 * @param {Object} [object] The object to query.
3233 * @param {Array|string} key The key to check.
3234 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3236 function baseHas(object, key) {
3237 return object != null && hasOwnProperty.call(object, key);
3241 * The base implementation of `_.hasIn` without support for deep paths.
3244 * @param {Object} [object] The object to query.
3245 * @param {Array|string} key The key to check.
3246 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3248 function baseHasIn(object, key) {
3249 return object != null && key in Object(object);
3253 * The base implementation of `_.inRange` which doesn't coerce arguments.
3256 * @param {number} number The number to check.
3257 * @param {number} start The start of the range.
3258 * @param {number} end The end of the range.
3259 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
3261 function baseInRange(number, start, end) {
3262 return number >= nativeMin(start, end) && number < nativeMax(start, end);
3266 * The base implementation of methods like `_.intersection`, without support
3267 * for iteratee shorthands, that accepts an array of arrays to inspect.
3270 * @param {Array} arrays The arrays to inspect.
3271 * @param {Function} [iteratee] The iteratee invoked per element.
3272 * @param {Function} [comparator] The comparator invoked per element.
3273 * @returns {Array} Returns the new array of shared values.
3275 function baseIntersection(arrays, iteratee, comparator) {
3276 var includes = comparator ? arrayIncludesWith : arrayIncludes,
3277 length = arrays[0].length,
3278 othLength = arrays.length,
3279 othIndex = othLength,
3280 caches = Array(othLength),
3281 maxLength = Infinity,
3284 while (othIndex--) {
3285 var array = arrays[othIndex];
3286 if (othIndex && iteratee) {
3287 array = arrayMap(array, baseUnary(iteratee));
3289 maxLength = nativeMin(array.length, maxLength);
3290 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) ?
3291 new SetCache(othIndex && array) :
3300 while (++index < length && result.length < maxLength) {
3301 var value = array[index],
3302 computed = iteratee ? iteratee(value) : value;
3304 value = (comparator || value !== 0) ? value : 0;
3306 cacheHas(seen, computed) :
3307 includes(result, computed, comparator)
3309 othIndex = othLength;
3310 while (--othIndex) {
3311 var cache = caches[othIndex];
3313 cacheHas(cache, computed) :
3314 includes(arrays[othIndex], computed, comparator))) {
3319 seen.push(computed);
3328 * The base implementation of `_.invert` and `_.invertBy` which inverts
3329 * `object` with values transformed by `iteratee` and set by `setter`.
3332 * @param {Object} object The object to iterate over.
3333 * @param {Function} setter The function to set `accumulator` values.
3334 * @param {Function} iteratee The iteratee to transform values.
3335 * @param {Object} accumulator The initial inverted object.
3336 * @returns {Function} Returns `accumulator`.
3338 function baseInverter(object, setter, iteratee, accumulator) {
3339 baseForOwn(object, function(value, key, object) {
3340 setter(accumulator, iteratee(value), key, object);
3346 * The base implementation of `_.invoke` without support for individual
3350 * @param {Object} object The object to query.
3351 * @param {Array|string} path The path of the method to invoke.
3352 * @param {Array} args The arguments to invoke the method with.
3353 * @returns {*} Returns the result of the invoked method.
3355 function baseInvoke(object, path, args) {
3356 path = castPath(path, object);
3357 object = parent(object, path);
3358 var func = object == null ? object : object[toKey(last(path))];
3359 return func == null ? undefined : apply(func, object, args);
3363 * The base implementation of `_.isArguments`.
3366 * @param {*} value The value to check.
3367 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
3369 function baseIsArguments(value) {
3370 return isObjectLike(value) && baseGetTag(value) == argsTag;
3374 * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
3377 * @param {*} value The value to check.
3378 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
3380 function baseIsArrayBuffer(value) {
3381 return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
3385 * The base implementation of `_.isDate` without Node.js optimizations.
3388 * @param {*} value The value to check.
3389 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
3391 function baseIsDate(value) {
3392 return isObjectLike(value) && baseGetTag(value) == dateTag;
3396 * The base implementation of `_.isEqual` which supports partial comparisons
3397 * and tracks traversed objects.
3400 * @param {*} value The value to compare.
3401 * @param {*} other The other value to compare.
3402 * @param {boolean} bitmask The bitmask flags.
3403 * 1 - Unordered comparison
3404 * 2 - Partial comparison
3405 * @param {Function} [customizer] The function to customize comparisons.
3406 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
3407 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3409 function baseIsEqual(value, other, bitmask, customizer, stack) {
3410 if (value === other) {
3413 if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
3414 return value !== value && other !== other;
3416 return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
3420 * A specialized version of `baseIsEqual` for arrays and objects which performs
3421 * deep comparisons and tracks traversed objects enabling objects with circular
3422 * references to be compared.
3425 * @param {Object} object The object to compare.
3426 * @param {Object} other The other object to compare.
3427 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
3428 * @param {Function} customizer The function to customize comparisons.
3429 * @param {Function} equalFunc The function to determine equivalents of values.
3430 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
3431 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3433 function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
3434 var objIsArr = isArray(object),
3435 othIsArr = isArray(other),
3436 objTag = objIsArr ? arrayTag : getTag(object),
3437 othTag = othIsArr ? arrayTag : getTag(other);
3439 objTag = objTag == argsTag ? objectTag : objTag;
3440 othTag = othTag == argsTag ? objectTag : othTag;
3442 var objIsObj = objTag == objectTag,
3443 othIsObj = othTag == objectTag,
3444 isSameTag = objTag == othTag;
3446 if (isSameTag && isBuffer(object)) {
3447 if (!isBuffer(other)) {
3453 if (isSameTag && !objIsObj) {
3454 stack || (stack = new Stack);
3455 return (objIsArr || isTypedArray(object)) ?
3456 equalArrays(object, other, bitmask, customizer, equalFunc, stack) :
3457 equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
3459 if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
3460 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
3461 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
3463 if (objIsWrapped || othIsWrapped) {
3464 var objUnwrapped = objIsWrapped ? object.value() : object,
3465 othUnwrapped = othIsWrapped ? other.value() : other;
3467 stack || (stack = new Stack);
3468 return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
3474 stack || (stack = new Stack);
3475 return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
3479 * The base implementation of `_.isMap` without Node.js optimizations.
3482 * @param {*} value The value to check.
3483 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
3485 function baseIsMap(value) {
3486 return isObjectLike(value) && getTag(value) == mapTag;
3490 * The base implementation of `_.isMatch` without support for iteratee shorthands.
3493 * @param {Object} object The object to inspect.
3494 * @param {Object} source The object of property values to match.
3495 * @param {Array} matchData The property names, values, and compare flags to match.
3496 * @param {Function} [customizer] The function to customize comparisons.
3497 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
3499 function baseIsMatch(object, source, matchData, customizer) {
3500 var index = matchData.length,
3502 noCustomizer = !customizer;
3504 if (object == null) {
3507 object = Object(object);
3509 var data = matchData[index];
3510 if ((noCustomizer && data[2]) ?
3511 data[1] !== object[data[0]] :
3512 !(data[0] in object)
3517 while (++index < length) {
3518 data = matchData[index];
3520 objValue = object[key],
3523 if (noCustomizer && data[2]) {
3524 if (objValue === undefined && !(key in object)) {
3528 var stack = new Stack;
3530 var result = customizer(objValue, srcValue, key, object, source, stack);
3532 if (!(result === undefined ?
3533 baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) :
3544 * The base implementation of `_.isNative` without bad shim checks.
3547 * @param {*} value The value to check.
3548 * @returns {boolean} Returns `true` if `value` is a native function,
3551 function baseIsNative(value) {
3552 if (!isObject(value) || isMasked(value)) {
3555 var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3556 return pattern.test(toSource(value));
3560 * The base implementation of `_.isRegExp` without Node.js optimizations.
3563 * @param {*} value The value to check.
3564 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
3566 function baseIsRegExp(value) {
3567 return isObjectLike(value) && baseGetTag(value) == regexpTag;
3571 * The base implementation of `_.isSet` without Node.js optimizations.
3574 * @param {*} value The value to check.
3575 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
3577 function baseIsSet(value) {
3578 return isObjectLike(value) && getTag(value) == setTag;
3582 * The base implementation of `_.isTypedArray` without Node.js optimizations.
3585 * @param {*} value The value to check.
3586 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
3588 function baseIsTypedArray(value) {
3589 return isObjectLike(value) &&
3590 isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
3594 * The base implementation of `_.iteratee`.
3597 * @param {*} [value=_.identity] The value to convert to an iteratee.
3598 * @returns {Function} Returns the iteratee.
3600 function baseIteratee(value) {
3601 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
3602 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
3603 if (typeof value == 'function') {
3606 if (value == null) {
3609 if (typeof value == 'object') {
3610 return isArray(value) ?
3611 baseMatchesProperty(value[0], value[1]) :
3614 return property(value);
3618 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
3621 * @param {Object} object The object to query.
3622 * @returns {Array} Returns the array of property names.
3624 function baseKeys(object) {
3625 if (!isPrototype(object)) {
3626 return nativeKeys(object);
3629 for (var key in Object(object)) {
3630 if (hasOwnProperty.call(object, key) && key != 'constructor') {
3638 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
3641 * @param {Object} object The object to query.
3642 * @returns {Array} Returns the array of property names.
3644 function baseKeysIn(object) {
3645 if (!isObject(object)) {
3646 return nativeKeysIn(object);
3648 var isProto = isPrototype(object),
3651 for (var key in object) {
3652 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3660 * The base implementation of `_.lt` which doesn't coerce arguments.
3663 * @param {*} value The value to compare.
3664 * @param {*} other The other value to compare.
3665 * @returns {boolean} Returns `true` if `value` is less than `other`,
3668 function baseLt(value, other) {
3669 return value < other;
3673 * The base implementation of `_.map` without support for iteratee shorthands.
3676 * @param {Array|Object} collection The collection to iterate over.
3677 * @param {Function} iteratee The function invoked per iteration.
3678 * @returns {Array} Returns the new mapped array.
3680 function baseMap(collection, iteratee) {
3682 result = isArrayLike(collection) ? Array(collection.length) : [];
3684 baseEach(collection, function(value, key, collection) {
3685 result[++index] = iteratee(value, key, collection);
3691 * The base implementation of `_.matches` which doesn't clone `source`.
3694 * @param {Object} source The object of property values to match.
3695 * @returns {Function} Returns the new spec function.
3697 function baseMatches(source) {
3698 var matchData = getMatchData(source);
3699 if (matchData.length == 1 && matchData[0][2]) {
3700 return matchesStrictComparable(matchData[0][0], matchData[0][1]);
3702 return function(object) {
3703 return object === source || baseIsMatch(object, source, matchData);
3708 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3711 * @param {string} path The path of the property to get.
3712 * @param {*} srcValue The value to match.
3713 * @returns {Function} Returns the new spec function.
3715 function baseMatchesProperty(path, srcValue) {
3716 if (isKey(path) && isStrictComparable(srcValue)) {
3717 return matchesStrictComparable(toKey(path), srcValue);
3719 return function(object) {
3720 var objValue = get(object, path);
3721 return (objValue === undefined && objValue === srcValue) ?
3722 hasIn(object, path) :
3723 baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
3728 * The base implementation of `_.merge` without support for multiple sources.
3731 * @param {Object} object The destination object.
3732 * @param {Object} source The source object.
3733 * @param {number} srcIndex The index of `source`.
3734 * @param {Function} [customizer] The function to customize merged values.
3735 * @param {Object} [stack] Tracks traversed source values and their merged
3738 function baseMerge(object, source, srcIndex, customizer, stack) {
3739 if (object === source) {
3742 baseFor(source, function(srcValue, key) {
3743 stack || (stack = new Stack);
3744 if (isObject(srcValue)) {
3745 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3747 var newValue = customizer ?
3748 customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack) :
3751 if (newValue === undefined) {
3752 newValue = srcValue;
3754 assignMergeValue(object, key, newValue);
3760 * A specialized version of `baseMerge` for arrays and objects which performs
3761 * deep merges and tracks traversed objects enabling objects with circular
3762 * references to be merged.
3765 * @param {Object} object The destination object.
3766 * @param {Object} source The source object.
3767 * @param {string} key The key of the value to merge.
3768 * @param {number} srcIndex The index of `source`.
3769 * @param {Function} mergeFunc The function to merge values.
3770 * @param {Function} [customizer] The function to customize assigned values.
3771 * @param {Object} [stack] Tracks traversed source values and their merged
3774 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3775 var objValue = safeGet(object, key),
3776 srcValue = safeGet(source, key),
3777 stacked = stack.get(srcValue);
3780 assignMergeValue(object, key, stacked);
3783 var newValue = customizer ?
3784 customizer(objValue, srcValue, (key + ''), object, source, stack) :
3787 var isCommon = newValue === undefined;
3790 var isArr = isArray(srcValue),
3791 isBuff = !isArr && isBuffer(srcValue),
3792 isTyped = !isArr && !isBuff && isTypedArray(srcValue);
3794 newValue = srcValue;
3795 if (isArr || isBuff || isTyped) {
3796 if (isArray(objValue)) {
3797 newValue = objValue;
3798 } else if (isArrayLikeObject(objValue)) {
3799 newValue = copyArray(objValue);
3800 } else if (isBuff) {
3802 newValue = cloneBuffer(srcValue, true);
3803 } else if (isTyped) {
3805 newValue = cloneTypedArray(srcValue, true);
3809 } else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3810 newValue = objValue;
3811 if (isArguments(objValue)) {
3812 newValue = toPlainObject(objValue);
3813 } else if (!isObject(objValue) || isFunction(objValue)) {
3814 newValue = initCloneObject(srcValue);
3821 // Recursively merge objects and arrays (susceptible to call stack limits).
3822 stack.set(srcValue, newValue);
3823 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3824 stack['delete'](srcValue);
3826 assignMergeValue(object, key, newValue);
3830 * The base implementation of `_.nth` which doesn't coerce arguments.
3833 * @param {Array} array The array to query.
3834 * @param {number} n The index of the element to return.
3835 * @returns {*} Returns the nth element of `array`.
3837 function baseNth(array, n) {
3838 var length = array.length;
3842 n += n < 0 ? length : 0;
3843 return isIndex(n, length) ? array[n] : undefined;
3847 * The base implementation of `_.orderBy` without param guards.
3850 * @param {Array|Object} collection The collection to iterate over.
3851 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3852 * @param {string[]} orders The sort orders of `iteratees`.
3853 * @returns {Array} Returns the new sorted array.
3855 function baseOrderBy(collection, iteratees, orders) {
3856 if (iteratees.length) {
3857 iteratees = arrayMap(iteratees, function(iteratee) {
3858 if (isArray(iteratee)) {
3859 return function(value) {
3860 return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
3866 iteratees = [identity];
3870 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
3872 var result = baseMap(collection, function(value, key, collection) {
3873 var criteria = arrayMap(iteratees, function(iteratee) {
3874 return iteratee(value);
3877 'criteria': criteria,
3883 return baseSortBy(result, function(object, other) {
3884 return compareMultiple(object, other, orders);
3889 * The base implementation of `_.pick` without support for individual
3890 * property identifiers.
3893 * @param {Object} object The source object.
3894 * @param {string[]} paths The property paths to pick.
3895 * @returns {Object} Returns the new object.
3897 function basePick(object, paths) {
3898 return basePickBy(object, paths, function(value, path) {
3899 return hasIn(object, path);
3904 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3907 * @param {Object} object The source object.
3908 * @param {string[]} paths The property paths to pick.
3909 * @param {Function} predicate The function invoked per property.
3910 * @returns {Object} Returns the new object.
3912 function basePickBy(object, paths, predicate) {
3914 length = paths.length,
3917 while (++index < length) {
3918 var path = paths[index],
3919 value = baseGet(object, path);
3921 if (predicate(value, path)) {
3922 baseSet(result, castPath(path, object), value);
3929 * A specialized version of `baseProperty` which supports deep paths.
3932 * @param {Array|string} path The path of the property to get.
3933 * @returns {Function} Returns the new accessor function.
3935 function basePropertyDeep(path) {
3936 return function(object) {
3937 return baseGet(object, path);
3942 * The base implementation of `_.pullAllBy` without support for iteratee
3946 * @param {Array} array The array to modify.
3947 * @param {Array} values The values to remove.
3948 * @param {Function} [iteratee] The iteratee invoked per element.
3949 * @param {Function} [comparator] The comparator invoked per element.
3950 * @returns {Array} Returns `array`.
3952 function basePullAll(array, values, iteratee, comparator) {
3953 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
3955 length = values.length,
3958 if (array === values) {
3959 values = copyArray(values);
3962 seen = arrayMap(array, baseUnary(iteratee));
3964 while (++index < length) {
3966 value = values[index],
3967 computed = iteratee ? iteratee(value) : value;
3969 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
3970 if (seen !== array) {
3971 splice.call(seen, fromIndex, 1);
3973 splice.call(array, fromIndex, 1);
3980 * The base implementation of `_.pullAt` without support for individual
3981 * indexes or capturing the removed elements.
3984 * @param {Array} array The array to modify.
3985 * @param {number[]} indexes The indexes of elements to remove.
3986 * @returns {Array} Returns `array`.
3988 function basePullAt(array, indexes) {
3989 var length = array ? indexes.length : 0,
3990 lastIndex = length - 1;
3993 var index = indexes[length];
3994 if (length == lastIndex || index !== previous) {
3995 var previous = index;
3996 if (isIndex(index)) {
3997 splice.call(array, index, 1);
3999 baseUnset(array, index);
4007 * The base implementation of `_.random` without support for returning
4008 * floating-point numbers.
4011 * @param {number} lower The lower bound.
4012 * @param {number} upper The upper bound.
4013 * @returns {number} Returns the random number.
4015 function baseRandom(lower, upper) {
4016 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
4020 * The base implementation of `_.range` and `_.rangeRight` which doesn't
4024 * @param {number} start The start of the range.
4025 * @param {number} end The end of the range.
4026 * @param {number} step The value to increment or decrement by.
4027 * @param {boolean} [fromRight] Specify iterating from right to left.
4028 * @returns {Array} Returns the range of numbers.
4030 function baseRange(start, end, step, fromRight) {
4032 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
4033 result = Array(length);
4036 result[fromRight ? length : ++index] = start;
4043 * The base implementation of `_.repeat` which doesn't coerce arguments.
4046 * @param {string} string The string to repeat.
4047 * @param {number} n The number of times to repeat the string.
4048 * @returns {string} Returns the repeated string.
4050 function baseRepeat(string, n) {
4052 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
4055 // Leverage the exponentiation by squaring algorithm for a faster repeat.
4056 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
4061 n = nativeFloor(n / 2);
4071 * The base implementation of `_.rest` which doesn't validate or coerce arguments.
4074 * @param {Function} func The function to apply a rest parameter to.
4075 * @param {number} [start=func.length-1] The start position of the rest parameter.
4076 * @returns {Function} Returns the new function.
4078 function baseRest(func, start) {
4079 return setToString(overRest(func, start, identity), func + '');
4083 * The base implementation of `_.sample`.
4086 * @param {Array|Object} collection The collection to sample.
4087 * @returns {*} Returns the random element.
4089 function baseSample(collection) {
4090 return arraySample(values(collection));
4094 * The base implementation of `_.sampleSize` without param guards.
4097 * @param {Array|Object} collection The collection to sample.
4098 * @param {number} n The number of elements to sample.
4099 * @returns {Array} Returns the random elements.
4101 function baseSampleSize(collection, n) {
4102 var array = values(collection);
4103 return shuffleSelf(array, baseClamp(n, 0, array.length));
4107 * The base implementation of `_.set`.
4110 * @param {Object} object The object to modify.
4111 * @param {Array|string} path The path of the property to set.
4112 * @param {*} value The value to set.
4113 * @param {Function} [customizer] The function to customize path creation.
4114 * @returns {Object} Returns `object`.
4116 function baseSet(object, path, value, customizer) {
4117 if (!isObject(object)) {
4120 path = castPath(path, object);
4123 length = path.length,
4124 lastIndex = length - 1,
4127 while (nested != null && ++index < length) {
4128 var key = toKey(path[index]),
4131 if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
4135 if (index != lastIndex) {
4136 var objValue = nested[key];
4137 newValue = customizer ? customizer(objValue, key, nested) : undefined;
4138 if (newValue === undefined) {
4139 newValue = isObject(objValue) ?
4141 (isIndex(path[index + 1]) ? [] : {});
4144 assignValue(nested, key, newValue);
4145 nested = nested[key];
4151 * The base implementation of `setData` without support for hot loop shorting.
4154 * @param {Function} func The function to associate metadata with.
4155 * @param {*} data The metadata.
4156 * @returns {Function} Returns `func`.
4158 var baseSetData = !metaMap ? identity : function(func, data) {
4159 metaMap.set(func, data);
4164 * The base implementation of `setToString` without support for hot loop shorting.
4167 * @param {Function} func The function to modify.
4168 * @param {Function} string The `toString` result.
4169 * @returns {Function} Returns `func`.
4171 var baseSetToString = !defineProperty ? identity : function(func, string) {
4172 return defineProperty(func, 'toString', {
4173 'configurable': true,
4174 'enumerable': false,
4175 'value': constant(string),
4181 * The base implementation of `_.shuffle`.
4184 * @param {Array|Object} collection The collection to shuffle.
4185 * @returns {Array} Returns the new shuffled array.
4187 function baseShuffle(collection) {
4188 return shuffleSelf(values(collection));
4192 * The base implementation of `_.slice` without an iteratee call guard.
4195 * @param {Array} array The array to slice.
4196 * @param {number} [start=0] The start position.
4197 * @param {number} [end=array.length] The end position.
4198 * @returns {Array} Returns the slice of `array`.
4200 function baseSlice(array, start, end) {
4202 length = array.length;
4205 start = -start > length ? 0 : (length + start);
4207 end = end > length ? length : end;
4211 length = start > end ? 0 : ((end - start) >>> 0);
4214 var result = Array(length);
4215 while (++index < length) {
4216 result[index] = array[index + start];
4222 * The base implementation of `_.some` without support for iteratee shorthands.
4225 * @param {Array|Object} collection The collection to iterate over.
4226 * @param {Function} predicate The function invoked per iteration.
4227 * @returns {boolean} Returns `true` if any element passes the predicate check,
4230 function baseSome(collection, predicate) {
4233 baseEach(collection, function(value, index, collection) {
4234 result = predicate(value, index, collection);
4241 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
4242 * performs a binary search of `array` to determine the index at which `value`
4243 * should be inserted into `array` in order to maintain its sort order.
4246 * @param {Array} array The sorted array to inspect.
4247 * @param {*} value The value to evaluate.
4248 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4249 * @returns {number} Returns the index at which `value` should be inserted
4252 function baseSortedIndex(array, value, retHighest) {
4254 high = array == null ? low : array.length;
4256 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
4257 while (low < high) {
4258 var mid = (low + high) >>> 1,
4259 computed = array[mid];
4261 if (computed !== null && !isSymbol(computed) &&
4262 (retHighest ? (computed <= value) : (computed < value))) {
4270 return baseSortedIndexBy(array, value, identity, retHighest);
4274 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
4275 * which invokes `iteratee` for `value` and each element of `array` to compute
4276 * their sort ranking. The iteratee is invoked with one argument; (value).
4279 * @param {Array} array The sorted array to inspect.
4280 * @param {*} value The value to evaluate.
4281 * @param {Function} iteratee The iteratee invoked per element.
4282 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4283 * @returns {number} Returns the index at which `value` should be inserted
4286 function baseSortedIndexBy(array, value, iteratee, retHighest) {
4288 high = array == null ? 0 : array.length;
4293 value = iteratee(value);
4294 var valIsNaN = value !== value,
4295 valIsNull = value === null,
4296 valIsSymbol = isSymbol(value),
4297 valIsUndefined = value === undefined;
4299 while (low < high) {
4300 var mid = nativeFloor((low + high) / 2),
4301 computed = iteratee(array[mid]),
4302 othIsDefined = computed !== undefined,
4303 othIsNull = computed === null,
4304 othIsReflexive = computed === computed,
4305 othIsSymbol = isSymbol(computed);
4308 var setLow = retHighest || othIsReflexive;
4309 } else if (valIsUndefined) {
4310 setLow = othIsReflexive && (retHighest || othIsDefined);
4311 } else if (valIsNull) {
4312 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
4313 } else if (valIsSymbol) {
4314 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
4315 } else if (othIsNull || othIsSymbol) {
4318 setLow = retHighest ? (computed <= value) : (computed < value);
4326 return nativeMin(high, MAX_ARRAY_INDEX);
4330 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
4331 * support for iteratee shorthands.
4334 * @param {Array} array The array to inspect.
4335 * @param {Function} [iteratee] The iteratee invoked per element.
4336 * @returns {Array} Returns the new duplicate free array.
4338 function baseSortedUniq(array, iteratee) {
4340 length = array.length,
4344 while (++index < length) {
4345 var value = array[index],
4346 computed = iteratee ? iteratee(value) : value;
4348 if (!index || !eq(computed, seen)) {
4349 var seen = computed;
4350 result[resIndex++] = value === 0 ? 0 : value;
4357 * The base implementation of `_.toNumber` which doesn't ensure correct
4358 * conversions of binary, hexadecimal, or octal string values.
4361 * @param {*} value The value to process.
4362 * @returns {number} Returns the number.
4364 function baseToNumber(value) {
4365 if (typeof value == 'number') {
4368 if (isSymbol(value)) {
4375 * The base implementation of `_.toString` which doesn't convert nullish
4376 * values to empty strings.
4379 * @param {*} value The value to process.
4380 * @returns {string} Returns the string.
4382 function baseToString(value) {
4383 // Exit early for strings to avoid a performance hit in some environments.
4384 if (typeof value == 'string') {
4387 if (isArray(value)) {
4388 // Recursively convert values (susceptible to call stack limits).
4389 return arrayMap(value, baseToString) + '';
4391 if (isSymbol(value)) {
4392 return symbolToString ? symbolToString.call(value) : '';
4394 var result = (value + '');
4395 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
4399 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
4402 * @param {Array} array The array to inspect.
4403 * @param {Function} [iteratee] The iteratee invoked per element.
4404 * @param {Function} [comparator] The comparator invoked per element.
4405 * @returns {Array} Returns the new duplicate free array.
4407 function baseUniq(array, iteratee, comparator) {
4409 includes = arrayIncludes,
4410 length = array.length,
4417 includes = arrayIncludesWith;
4418 } else if (length >= LARGE_ARRAY_SIZE) {
4419 var set = iteratee ? null : createSet(array);
4421 return setToArray(set);
4424 includes = cacheHas;
4425 seen = new SetCache;
4427 seen = iteratee ? [] : result;
4430 while (++index < length) {
4431 var value = array[index],
4432 computed = iteratee ? iteratee(value) : value;
4434 value = (comparator || value !== 0) ? value : 0;
4435 if (isCommon && computed === computed) {
4436 var seenIndex = seen.length;
4437 while (seenIndex--) {
4438 if (seen[seenIndex] === computed) {
4443 seen.push(computed);
4446 } else if (!includes(seen, computed, comparator)) {
4447 if (seen !== result) {
4448 seen.push(computed);
4457 * The base implementation of `_.unset`.
4460 * @param {Object} object The object to modify.
4461 * @param {Array|string} path The property path to unset.
4462 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
4464 function baseUnset(object, path) {
4465 path = castPath(path, object);
4466 object = parent(object, path);
4467 return object == null || delete object[toKey(last(path))];
4471 * The base implementation of `_.update`.
4474 * @param {Object} object The object to modify.
4475 * @param {Array|string} path The path of the property to update.
4476 * @param {Function} updater The function to produce the updated value.
4477 * @param {Function} [customizer] The function to customize path creation.
4478 * @returns {Object} Returns `object`.
4480 function baseUpdate(object, path, updater, customizer) {
4481 return baseSet(object, path, updater(baseGet(object, path)), customizer);
4485 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
4486 * without support for iteratee shorthands.
4489 * @param {Array} array The array to query.
4490 * @param {Function} predicate The function invoked per iteration.
4491 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
4492 * @param {boolean} [fromRight] Specify iterating from right to left.
4493 * @returns {Array} Returns the slice of `array`.
4495 function baseWhile(array, predicate, isDrop, fromRight) {
4496 var length = array.length,
4497 index = fromRight ? length : -1;
4499 while ((fromRight ? index-- : ++index < length) &&
4500 predicate(array[index], index, array)) {}
4503 baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) :
4504 baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
4508 * The base implementation of `wrapperValue` which returns the result of
4509 * performing a sequence of actions on the unwrapped `value`, where each
4510 * successive action is supplied the return value of the previous.
4513 * @param {*} value The unwrapped value.
4514 * @param {Array} actions Actions to perform to resolve the unwrapped value.
4515 * @returns {*} Returns the resolved value.
4517 function baseWrapperValue(value, actions) {
4519 if (result instanceof LazyWrapper) {
4520 result = result.value();
4522 return arrayReduce(actions, function(result, action) {
4523 return action.func.apply(action.thisArg, arrayPush([result], action.args));
4528 * The base implementation of methods like `_.xor`, without support for
4529 * iteratee shorthands, that accepts an array of arrays to inspect.
4532 * @param {Array} arrays The arrays to inspect.
4533 * @param {Function} [iteratee] The iteratee invoked per element.
4534 * @param {Function} [comparator] The comparator invoked per element.
4535 * @returns {Array} Returns the new array of values.
4537 function baseXor(arrays, iteratee, comparator) {
4538 var length = arrays.length;
4540 return length ? baseUniq(arrays[0]) : [];
4543 result = Array(length);
4545 while (++index < length) {
4546 var array = arrays[index],
4549 while (++othIndex < length) {
4550 if (othIndex != index) {
4551 result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
4555 return baseUniq(baseFlatten(result, 1), iteratee, comparator);
4559 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
4562 * @param {Array} props The property identifiers.
4563 * @param {Array} values The property values.
4564 * @param {Function} assignFunc The function to assign values.
4565 * @returns {Object} Returns the new object.
4567 function baseZipObject(props, values, assignFunc) {
4569 length = props.length,
4570 valsLength = values.length,
4573 while (++index < length) {
4574 var value = index < valsLength ? values[index] : undefined;
4575 assignFunc(result, props[index], value);
4581 * Casts `value` to an empty array if it's not an array like object.
4584 * @param {*} value The value to inspect.
4585 * @returns {Array|Object} Returns the cast array-like object.
4587 function castArrayLikeObject(value) {
4588 return isArrayLikeObject(value) ? value : [];
4592 * Casts `value` to `identity` if it's not a function.
4595 * @param {*} value The value to inspect.
4596 * @returns {Function} Returns cast function.
4598 function castFunction(value) {
4599 return typeof value == 'function' ? value : identity;
4603 * Casts `value` to a path array if it's not one.
4606 * @param {*} value The value to inspect.
4607 * @param {Object} [object] The object to query keys on.
4608 * @returns {Array} Returns the cast property path array.
4610 function castPath(value, object) {
4611 if (isArray(value)) {
4614 return isKey(value, object) ? [value] : stringToPath(toString(value));
4618 * A `baseRest` alias which can be replaced with `identity` by module
4619 * replacement plugins.
4623 * @param {Function} func The function to apply a rest parameter to.
4624 * @returns {Function} Returns the new function.
4626 var castRest = baseRest;
4629 * Casts `array` to a slice if it's needed.
4632 * @param {Array} array The array to inspect.
4633 * @param {number} start The start position.
4634 * @param {number} [end=array.length] The end position.
4635 * @returns {Array} Returns the cast slice.
4637 function castSlice(array, start, end) {
4638 var length = array.length;
4639 end = end === undefined ? length : end;
4640 return (!start && end >= length) ? array : baseSlice(array, start, end);
4644 * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
4647 * @param {number|Object} id The timer id or timeout object of the timer to clear.
4649 var clearTimeout = ctxClearTimeout || function(id) {
4650 return root.clearTimeout(id);
4654 * Creates a clone of `buffer`.
4657 * @param {Buffer} buffer The buffer to clone.
4658 * @param {boolean} [isDeep] Specify a deep clone.
4659 * @returns {Buffer} Returns the cloned buffer.
4661 function cloneBuffer(buffer, isDeep) {
4663 return buffer.slice();
4665 var length = buffer.length,
4666 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
4668 buffer.copy(result);
4673 * Creates a clone of `arrayBuffer`.
4676 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
4677 * @returns {ArrayBuffer} Returns the cloned array buffer.
4679 function cloneArrayBuffer(arrayBuffer) {
4680 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
4681 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
4686 * Creates a clone of `dataView`.
4689 * @param {Object} dataView The data view to clone.
4690 * @param {boolean} [isDeep] Specify a deep clone.
4691 * @returns {Object} Returns the cloned data view.
4693 function cloneDataView(dataView, isDeep) {
4694 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
4695 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
4699 * Creates a clone of `regexp`.
4702 * @param {Object} regexp The regexp to clone.
4703 * @returns {Object} Returns the cloned regexp.
4705 function cloneRegExp(regexp) {
4706 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
4707 result.lastIndex = regexp.lastIndex;
4712 * Creates a clone of the `symbol` object.
4715 * @param {Object} symbol The symbol object to clone.
4716 * @returns {Object} Returns the cloned symbol object.
4718 function cloneSymbol(symbol) {
4719 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
4723 * Creates a clone of `typedArray`.
4726 * @param {Object} typedArray The typed array to clone.
4727 * @param {boolean} [isDeep] Specify a deep clone.
4728 * @returns {Object} Returns the cloned typed array.
4730 function cloneTypedArray(typedArray, isDeep) {
4731 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
4732 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
4736 * Compares values to sort them in ascending order.
4739 * @param {*} value The value to compare.
4740 * @param {*} other The other value to compare.
4741 * @returns {number} Returns the sort order indicator for `value`.
4743 function compareAscending(value, other) {
4744 if (value !== other) {
4745 var valIsDefined = value !== undefined,
4746 valIsNull = value === null,
4747 valIsReflexive = value === value,
4748 valIsSymbol = isSymbol(value);
4750 var othIsDefined = other !== undefined,
4751 othIsNull = other === null,
4752 othIsReflexive = other === other,
4753 othIsSymbol = isSymbol(other);
4755 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
4756 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
4757 (valIsNull && othIsDefined && othIsReflexive) ||
4758 (!valIsDefined && othIsReflexive) ||
4762 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
4763 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
4764 (othIsNull && valIsDefined && valIsReflexive) ||
4765 (!othIsDefined && valIsReflexive) ||
4774 * Used by `_.orderBy` to compare multiple properties of a value to another
4775 * and stable sort them.
4777 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
4778 * specify an order of "desc" for descending or "asc" for ascending sort order
4779 * of corresponding values.
4782 * @param {Object} object The object to compare.
4783 * @param {Object} other The other object to compare.
4784 * @param {boolean[]|string[]} orders The order to sort by for each property.
4785 * @returns {number} Returns the sort order indicator for `object`.
4787 function compareMultiple(object, other, orders) {
4789 objCriteria = object.criteria,
4790 othCriteria = other.criteria,
4791 length = objCriteria.length,
4792 ordersLength = orders.length;
4794 while (++index < length) {
4795 var result = compareAscending(objCriteria[index], othCriteria[index]);
4797 if (index >= ordersLength) {
4800 var order = orders[index];
4801 return result * (order == 'desc' ? -1 : 1);
4804 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
4805 // that causes it, under certain circumstances, to provide the same value for
4806 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
4807 // for more details.
4809 // This also ensures a stable sort in V8 and other engines.
4810 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
4811 return object.index - other.index;
4815 * Creates an array that is the composition of partially applied arguments,
4816 * placeholders, and provided arguments into a single array of arguments.
4819 * @param {Array} args The provided arguments.
4820 * @param {Array} partials The arguments to prepend to those provided.
4821 * @param {Array} holders The `partials` placeholder indexes.
4822 * @params {boolean} [isCurried] Specify composing for a curried function.
4823 * @returns {Array} Returns the new array of composed arguments.
4825 function composeArgs(args, partials, holders, isCurried) {
4827 argsLength = args.length,
4828 holdersLength = holders.length,
4830 leftLength = partials.length,
4831 rangeLength = nativeMax(argsLength - holdersLength, 0),
4832 result = Array(leftLength + rangeLength),
4833 isUncurried = !isCurried;
4835 while (++leftIndex < leftLength) {
4836 result[leftIndex] = partials[leftIndex];
4838 while (++argsIndex < holdersLength) {
4839 if (isUncurried || argsIndex < argsLength) {
4840 result[holders[argsIndex]] = args[argsIndex];
4843 while (rangeLength--) {
4844 result[leftIndex++] = args[argsIndex++];
4850 * This function is like `composeArgs` except that the arguments composition
4851 * is tailored for `_.partialRight`.
4854 * @param {Array} args The provided arguments.
4855 * @param {Array} partials The arguments to append to those provided.
4856 * @param {Array} holders The `partials` placeholder indexes.
4857 * @params {boolean} [isCurried] Specify composing for a curried function.
4858 * @returns {Array} Returns the new array of composed arguments.
4860 function composeArgsRight(args, partials, holders, isCurried) {
4862 argsLength = args.length,
4864 holdersLength = holders.length,
4866 rightLength = partials.length,
4867 rangeLength = nativeMax(argsLength - holdersLength, 0),
4868 result = Array(rangeLength + rightLength),
4869 isUncurried = !isCurried;
4871 while (++argsIndex < rangeLength) {
4872 result[argsIndex] = args[argsIndex];
4874 var offset = argsIndex;
4875 while (++rightIndex < rightLength) {
4876 result[offset + rightIndex] = partials[rightIndex];
4878 while (++holdersIndex < holdersLength) {
4879 if (isUncurried || argsIndex < argsLength) {
4880 result[offset + holders[holdersIndex]] = args[argsIndex++];
4887 * Copies the values of `source` to `array`.
4890 * @param {Array} source The array to copy values from.
4891 * @param {Array} [array=[]] The array to copy values to.
4892 * @returns {Array} Returns `array`.
4894 function copyArray(source, array) {
4896 length = source.length;
4898 array || (array = Array(length));
4899 while (++index < length) {
4900 array[index] = source[index];
4906 * Copies properties of `source` to `object`.
4909 * @param {Object} source The object to copy properties from.
4910 * @param {Array} props The property identifiers to copy.
4911 * @param {Object} [object={}] The object to copy properties to.
4912 * @param {Function} [customizer] The function to customize copied values.
4913 * @returns {Object} Returns `object`.
4915 function copyObject(source, props, object, customizer) {
4916 var isNew = !object;
4917 object || (object = {});
4920 length = props.length;
4922 while (++index < length) {
4923 var key = props[index];
4925 var newValue = customizer ?
4926 customizer(object[key], source[key], key, object, source) :
4929 if (newValue === undefined) {
4930 newValue = source[key];
4933 baseAssignValue(object, key, newValue);
4935 assignValue(object, key, newValue);
4942 * Copies own symbols of `source` to `object`.
4945 * @param {Object} source The object to copy symbols from.
4946 * @param {Object} [object={}] The object to copy symbols to.
4947 * @returns {Object} Returns `object`.
4949 function copySymbols(source, object) {
4950 return copyObject(source, getSymbols(source), object);
4954 * Copies own and inherited symbols of `source` to `object`.
4957 * @param {Object} source The object to copy symbols from.
4958 * @param {Object} [object={}] The object to copy symbols to.
4959 * @returns {Object} Returns `object`.
4961 function copySymbolsIn(source, object) {
4962 return copyObject(source, getSymbolsIn(source), object);
4966 * Creates a function like `_.groupBy`.
4969 * @param {Function} setter The function to set accumulator values.
4970 * @param {Function} [initializer] The accumulator object initializer.
4971 * @returns {Function} Returns the new aggregator function.
4973 function createAggregator(setter, initializer) {
4974 return function(collection, iteratee) {
4975 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4976 accumulator = initializer ? initializer() : {};
4978 return func(collection, setter, getIteratee(iteratee, 2), accumulator);
4983 * Creates a function like `_.assign`.
4986 * @param {Function} assigner The function to assign values.
4987 * @returns {Function} Returns the new assigner function.
4989 function createAssigner(assigner) {
4990 return baseRest(function(object, sources) {
4992 length = sources.length,
4993 customizer = length > 1 ? sources[length - 1] : undefined,
4994 guard = length > 2 ? sources[2] : undefined;
4996 customizer = (assigner.length > 3 && typeof customizer == 'function') ?
4997 (length--, customizer) :
5000 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
5001 customizer = length < 3 ? undefined : customizer;
5004 object = Object(object);
5005 while (++index < length) {
5006 var source = sources[index];
5008 assigner(object, source, index, customizer);
5016 * Creates a `baseEach` or `baseEachRight` function.
5019 * @param {Function} eachFunc The function to iterate over a collection.
5020 * @param {boolean} [fromRight] Specify iterating from right to left.
5021 * @returns {Function} Returns the new base function.
5023 function createBaseEach(eachFunc, fromRight) {
5024 return function(collection, iteratee) {
5025 if (collection == null) {
5028 if (!isArrayLike(collection)) {
5029 return eachFunc(collection, iteratee);
5031 var length = collection.length,
5032 index = fromRight ? length : -1,
5033 iterable = Object(collection);
5035 while ((fromRight ? index-- : ++index < length)) {
5036 if (iteratee(iterable[index], index, iterable) === false) {
5045 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
5048 * @param {boolean} [fromRight] Specify iterating from right to left.
5049 * @returns {Function} Returns the new base function.
5051 function createBaseFor(fromRight) {
5052 return function(object, iteratee, keysFunc) {
5054 iterable = Object(object),
5055 props = keysFunc(object),
5056 length = props.length;
5059 var key = props[fromRight ? length : ++index];
5060 if (iteratee(iterable[key], key, iterable) === false) {
5069 * Creates a function that wraps `func` to invoke it with the optional `this`
5070 * binding of `thisArg`.
5073 * @param {Function} func The function to wrap.
5074 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5075 * @param {*} [thisArg] The `this` binding of `func`.
5076 * @returns {Function} Returns the new wrapped function.
5078 function createBind(func, bitmask, thisArg) {
5079 var isBind = bitmask & WRAP_BIND_FLAG,
5080 Ctor = createCtor(func);
5082 function wrapper() {
5083 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5084 return fn.apply(isBind ? thisArg : this, arguments);
5090 * Creates a function like `_.lowerFirst`.
5093 * @param {string} methodName The name of the `String` case method to use.
5094 * @returns {Function} Returns the new case function.
5096 function createCaseFirst(methodName) {
5097 return function(string) {
5098 string = toString(string);
5100 var strSymbols = hasUnicode(string) ?
5101 stringToArray(string) :
5104 var chr = strSymbols ?
5108 var trailing = strSymbols ?
5109 castSlice(strSymbols, 1).join('') :
5112 return chr[methodName]() + trailing;
5117 * Creates a function like `_.camelCase`.
5120 * @param {Function} callback The function to combine each word.
5121 * @returns {Function} Returns the new compounder function.
5123 function createCompounder(callback) {
5124 return function(string) {
5125 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
5130 * Creates a function that produces an instance of `Ctor` regardless of
5131 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
5134 * @param {Function} Ctor The constructor to wrap.
5135 * @returns {Function} Returns the new wrapped function.
5137 function createCtor(Ctor) {
5139 // Use a `switch` statement to work with class constructors. See
5140 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
5141 // for more details.
5142 var args = arguments;
5143 switch (args.length) {
5147 return new Ctor(args[0]);
5149 return new Ctor(args[0], args[1]);
5151 return new Ctor(args[0], args[1], args[2]);
5153 return new Ctor(args[0], args[1], args[2], args[3]);
5155 return new Ctor(args[0], args[1], args[2], args[3], args[4]);
5157 return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
5159 return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
5161 var thisBinding = baseCreate(Ctor.prototype),
5162 result = Ctor.apply(thisBinding, args);
5164 // Mimic the constructor's `return` behavior.
5165 // See https://es5.github.io/#x13.2.2 for more details.
5166 return isObject(result) ? result : thisBinding;
5171 * Creates a function that wraps `func` to enable currying.
5174 * @param {Function} func The function to wrap.
5175 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5176 * @param {number} arity The arity of `func`.
5177 * @returns {Function} Returns the new wrapped function.
5179 function createCurry(func, bitmask, arity) {
5180 var Ctor = createCtor(func);
5182 function wrapper() {
5183 var length = arguments.length,
5184 args = Array(length),
5186 placeholder = getHolder(wrapper);
5189 args[index] = arguments[index];
5191 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) ? [] :
5192 replaceHolders(args, placeholder);
5194 length -= holders.length;
5195 if (length < arity) {
5196 return createRecurry(
5197 func, bitmask, createHybrid, wrapper.placeholder, undefined,
5198 args, holders, undefined, undefined, arity - length);
5200 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5201 return apply(fn, this, args);
5207 * Creates a `_.find` or `_.findLast` function.
5210 * @param {Function} findIndexFunc The function to find the collection index.
5211 * @returns {Function} Returns the new find function.
5213 function createFind(findIndexFunc) {
5214 return function(collection, predicate, fromIndex) {
5215 var iterable = Object(collection);
5216 if (!isArrayLike(collection)) {
5217 var iteratee = getIteratee(predicate, 3);
5218 collection = keys(collection);
5219 predicate = function(key) {
5220 return iteratee(iterable[key], key, iterable);
5223 var index = findIndexFunc(collection, predicate, fromIndex);
5224 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
5229 * Creates a `_.flow` or `_.flowRight` function.
5232 * @param {boolean} [fromRight] Specify iterating from right to left.
5233 * @returns {Function} Returns the new flow function.
5235 function createFlow(fromRight) {
5236 return flatRest(function(funcs) {
5237 var length = funcs.length,
5239 prereq = LodashWrapper.prototype.thru;
5245 var func = funcs[index];
5246 if (typeof func != 'function') {
5247 throw new TypeError(FUNC_ERROR_TEXT);
5249 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
5250 var wrapper = new LodashWrapper([], true);
5253 index = wrapper ? index : length;
5254 while (++index < length) {
5255 func = funcs[index];
5257 var funcName = getFuncName(func),
5258 data = funcName == 'wrapper' ? getData(func) : undefined;
5260 if (data && isLaziable(data[0]) &&
5261 data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
5262 !data[4].length && data[9] == 1
5264 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
5266 wrapper = (func.length == 1 && isLaziable(func)) ?
5267 wrapper[funcName]() :
5272 var args = arguments,
5275 if (wrapper && args.length == 1 && isArray(value)) {
5276 return wrapper.plant(value).value();
5279 result = length ? funcs[index].apply(this, args) : value;
5281 while (++index < length) {
5282 result = funcs[index].call(this, result);
5290 * Creates a function that wraps `func` to invoke it with optional `this`
5291 * binding of `thisArg`, partial application, and currying.
5294 * @param {Function|string} func The function or method name to wrap.
5295 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5296 * @param {*} [thisArg] The `this` binding of `func`.
5297 * @param {Array} [partials] The arguments to prepend to those provided to
5299 * @param {Array} [holders] The `partials` placeholder indexes.
5300 * @param {Array} [partialsRight] The arguments to append to those provided
5301 * to the new function.
5302 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
5303 * @param {Array} [argPos] The argument positions of the new function.
5304 * @param {number} [ary] The arity cap of `func`.
5305 * @param {number} [arity] The arity of `func`.
5306 * @returns {Function} Returns the new wrapped function.
5308 function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
5309 var isAry = bitmask & WRAP_ARY_FLAG,
5310 isBind = bitmask & WRAP_BIND_FLAG,
5311 isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
5312 isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
5313 isFlip = bitmask & WRAP_FLIP_FLAG,
5314 Ctor = isBindKey ? undefined : createCtor(func);
5316 function wrapper() {
5317 var length = arguments.length,
5318 args = Array(length),
5322 args[index] = arguments[index];
5325 var placeholder = getHolder(wrapper),
5326 holdersCount = countHolders(args, placeholder);
5329 args = composeArgs(args, partials, holders, isCurried);
5331 if (partialsRight) {
5332 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
5334 length -= holdersCount;
5335 if (isCurried && length < arity) {
5336 var newHolders = replaceHolders(args, placeholder);
5337 return createRecurry(
5338 func, bitmask, createHybrid, wrapper.placeholder, thisArg,
5339 args, newHolders, argPos, ary, arity - length
5342 var thisBinding = isBind ? thisArg : this,
5343 fn = isBindKey ? thisBinding[func] : func;
5345 length = args.length;
5347 args = reorder(args, argPos);
5348 } else if (isFlip && length > 1) {
5351 if (isAry && ary < length) {
5354 if (this && this !== root && this instanceof wrapper) {
5355 fn = Ctor || createCtor(fn);
5357 return fn.apply(thisBinding, args);
5363 * Creates a function like `_.invertBy`.
5366 * @param {Function} setter The function to set accumulator values.
5367 * @param {Function} toIteratee The function to resolve iteratees.
5368 * @returns {Function} Returns the new inverter function.
5370 function createInverter(setter, toIteratee) {
5371 return function(object, iteratee) {
5372 return baseInverter(object, setter, toIteratee(iteratee), {});
5377 * Creates a function that performs a mathematical operation on two values.
5380 * @param {Function} operator The function to perform the operation.
5381 * @param {number} [defaultValue] The value used for `undefined` arguments.
5382 * @returns {Function} Returns the new mathematical operation function.
5384 function createMathOperation(operator, defaultValue) {
5385 return function(value, other) {
5387 if (value === undefined && other === undefined) {
5388 return defaultValue;
5390 if (value !== undefined) {
5393 if (other !== undefined) {
5394 if (result === undefined) {
5397 if (typeof value == 'string' || typeof other == 'string') {
5398 value = baseToString(value);
5399 other = baseToString(other);
5401 value = baseToNumber(value);
5402 other = baseToNumber(other);
5404 result = operator(value, other);
5411 * Creates a function like `_.over`.
5414 * @param {Function} arrayFunc The function to iterate over iteratees.
5415 * @returns {Function} Returns the new over function.
5417 function createOver(arrayFunc) {
5418 return flatRest(function(iteratees) {
5419 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
5420 return baseRest(function(args) {
5422 return arrayFunc(iteratees, function(iteratee) {
5423 return apply(iteratee, thisArg, args);
5430 * Creates the padding for `string` based on `length`. The `chars` string
5431 * is truncated if the number of characters exceeds `length`.
5434 * @param {number} length The padding length.
5435 * @param {string} [chars=' '] The string used as padding.
5436 * @returns {string} Returns the padding for `string`.
5438 function createPadding(length, chars) {
5439 chars = chars === undefined ? ' ' : baseToString(chars);
5441 var charsLength = chars.length;
5442 if (charsLength < 2) {
5443 return charsLength ? baseRepeat(chars, length) : chars;
5445 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
5446 return hasUnicode(chars) ?
5447 castSlice(stringToArray(result), 0, length).join('') :
5448 result.slice(0, length);
5452 * Creates a function that wraps `func` to invoke it with the `this` binding
5453 * of `thisArg` and `partials` prepended to the arguments it receives.
5456 * @param {Function} func The function to wrap.
5457 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5458 * @param {*} thisArg The `this` binding of `func`.
5459 * @param {Array} partials The arguments to prepend to those provided to
5461 * @returns {Function} Returns the new wrapped function.
5463 function createPartial(func, bitmask, thisArg, partials) {
5464 var isBind = bitmask & WRAP_BIND_FLAG,
5465 Ctor = createCtor(func);
5467 function wrapper() {
5469 argsLength = arguments.length,
5471 leftLength = partials.length,
5472 args = Array(leftLength + argsLength),
5473 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5475 while (++leftIndex < leftLength) {
5476 args[leftIndex] = partials[leftIndex];
5478 while (argsLength--) {
5479 args[leftIndex++] = arguments[++argsIndex];
5481 return apply(fn, isBind ? thisArg : this, args);
5487 * Creates a `_.range` or `_.rangeRight` function.
5490 * @param {boolean} [fromRight] Specify iterating from right to left.
5491 * @returns {Function} Returns the new range function.
5493 function createRange(fromRight) {
5494 return function(start, end, step) {
5495 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
5496 end = step = undefined;
5498 // Ensure the sign of `-0` is preserved.
5499 start = toFinite(start);
5500 if (end === undefined) {
5504 end = toFinite(end);
5506 step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
5507 return baseRange(start, end, step, fromRight);
5512 * Creates a function that performs a relational operation on two values.
5515 * @param {Function} operator The function to perform the operation.
5516 * @returns {Function} Returns the new relational operation function.
5518 function createRelationalOperation(operator) {
5519 return function(value, other) {
5520 if (!(typeof value == 'string' && typeof other == 'string')) {
5521 value = toNumber(value);
5522 other = toNumber(other);
5524 return operator(value, other);
5529 * Creates a function that wraps `func` to continue currying.
5532 * @param {Function} func The function to wrap.
5533 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5534 * @param {Function} wrapFunc The function to create the `func` wrapper.
5535 * @param {*} placeholder The placeholder value.
5536 * @param {*} [thisArg] The `this` binding of `func`.
5537 * @param {Array} [partials] The arguments to prepend to those provided to
5539 * @param {Array} [holders] The `partials` placeholder indexes.
5540 * @param {Array} [argPos] The argument positions of the new function.
5541 * @param {number} [ary] The arity cap of `func`.
5542 * @param {number} [arity] The arity of `func`.
5543 * @returns {Function} Returns the new wrapped function.
5545 function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
5546 var isCurry = bitmask & WRAP_CURRY_FLAG,
5547 newHolders = isCurry ? holders : undefined,
5548 newHoldersRight = isCurry ? undefined : holders,
5549 newPartials = isCurry ? partials : undefined,
5550 newPartialsRight = isCurry ? undefined : partials;
5552 bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
5553 bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
5555 if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
5556 bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
5559 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
5560 newHoldersRight, argPos, ary, arity
5563 var result = wrapFunc.apply(undefined, newData);
5564 if (isLaziable(func)) {
5565 setData(result, newData);
5567 result.placeholder = placeholder;
5568 return setWrapToString(result, func, bitmask);
5572 * Creates a function like `_.round`.
5575 * @param {string} methodName The name of the `Math` method to use when rounding.
5576 * @returns {Function} Returns the new round function.
5578 function createRound(methodName) {
5579 var func = Math[methodName];
5580 return function(number, precision) {
5581 number = toNumber(number);
5582 precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
5583 if (precision && nativeIsFinite(number)) {
5584 // Shift with exponential notation to avoid floating-point issues.
5585 // See [MDN](https://mdn.io/round#Examples) for more details.
5586 var pair = (toString(number) + 'e').split('e'),
5587 value = func(pair[0] + 'e' + (+pair[1] + precision));
5589 pair = (toString(value) + 'e').split('e');
5590 return +(pair[0] + 'e' + (+pair[1] - precision));
5592 return func(number);
5597 * Creates a set object of `values`.
5600 * @param {Array} values The values to add to the set.
5601 * @returns {Object} Returns the new set.
5603 var createSet = !(Set && (1 / setToArray(new Set([, -0]))[1]) == INFINITY) ? noop : function(values) {
5604 return new Set(values);
5608 * Creates a `_.toPairs` or `_.toPairsIn` function.
5611 * @param {Function} keysFunc The function to get the keys of a given object.
5612 * @returns {Function} Returns the new pairs function.
5614 function createToPairs(keysFunc) {
5615 return function(object) {
5616 var tag = getTag(object);
5617 if (tag == mapTag) {
5618 return mapToArray(object);
5620 if (tag == setTag) {
5621 return setToPairs(object);
5623 return baseToPairs(object, keysFunc(object));
5628 * Creates a function that either curries or invokes `func` with optional
5629 * `this` binding and partially applied arguments.
5632 * @param {Function|string} func The function or method name to wrap.
5633 * @param {number} bitmask The bitmask flags.
5636 * 4 - `_.curry` or `_.curryRight` of a bound function
5638 * 16 - `_.curryRight`
5640 * 64 - `_.partialRight`
5644 * @param {*} [thisArg] The `this` binding of `func`.
5645 * @param {Array} [partials] The arguments to be partially applied.
5646 * @param {Array} [holders] The `partials` placeholder indexes.
5647 * @param {Array} [argPos] The argument positions of the new function.
5648 * @param {number} [ary] The arity cap of `func`.
5649 * @param {number} [arity] The arity of `func`.
5650 * @returns {Function} Returns the new wrapped function.
5652 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
5653 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
5654 if (!isBindKey && typeof func != 'function') {
5655 throw new TypeError(FUNC_ERROR_TEXT);
5657 var length = partials ? partials.length : 0;
5659 bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
5660 partials = holders = undefined;
5662 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
5663 arity = arity === undefined ? arity : toInteger(arity);
5664 length -= holders ? holders.length : 0;
5666 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
5667 var partialsRight = partials,
5668 holdersRight = holders;
5670 partials = holders = undefined;
5672 var data = isBindKey ? undefined : getData(func);
5675 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
5680 mergeData(newData, data);
5683 bitmask = newData[1];
5684 thisArg = newData[2];
5685 partials = newData[3];
5686 holders = newData[4];
5687 arity = newData[9] = newData[9] === undefined ?
5688 (isBindKey ? 0 : func.length) :
5689 nativeMax(newData[9] - length, 0);
5691 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
5692 bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
5694 if (!bitmask || bitmask == WRAP_BIND_FLAG) {
5695 var result = createBind(func, bitmask, thisArg);
5696 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
5697 result = createCurry(func, bitmask, arity);
5698 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
5699 result = createPartial(func, bitmask, thisArg, partials);
5701 result = createHybrid.apply(undefined, newData);
5703 var setter = data ? baseSetData : setData;
5704 return setWrapToString(setter(result, newData), func, bitmask);
5708 * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
5709 * of source objects to the destination object for all destination properties
5710 * that resolve to `undefined`.
5713 * @param {*} objValue The destination value.
5714 * @param {*} srcValue The source value.
5715 * @param {string} key The key of the property to assign.
5716 * @param {Object} object The parent object of `objValue`.
5717 * @returns {*} Returns the value to assign.
5719 function customDefaultsAssignIn(objValue, srcValue, key, object) {
5720 if (objValue === undefined ||
5721 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
5728 * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
5729 * objects into destination objects that are passed thru.
5732 * @param {*} objValue The destination value.
5733 * @param {*} srcValue The source value.
5734 * @param {string} key The key of the property to merge.
5735 * @param {Object} object The parent object of `objValue`.
5736 * @param {Object} source The parent object of `srcValue`.
5737 * @param {Object} [stack] Tracks traversed source values and their merged
5739 * @returns {*} Returns the value to assign.
5741 function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
5742 if (isObject(objValue) && isObject(srcValue)) {
5743 // Recursively merge objects and arrays (susceptible to call stack limits).
5744 stack.set(srcValue, objValue);
5745 baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
5746 stack['delete'](srcValue);
5752 * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
5756 * @param {*} value The value to inspect.
5757 * @param {string} key The key of the property to inspect.
5758 * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
5760 function customOmitClone(value) {
5761 return isPlainObject(value) ? undefined : value;
5765 * A specialized version of `baseIsEqualDeep` for arrays with support for
5766 * partial deep comparisons.
5769 * @param {Array} array The array to compare.
5770 * @param {Array} other The other array to compare.
5771 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5772 * @param {Function} customizer The function to customize comparisons.
5773 * @param {Function} equalFunc The function to determine equivalents of values.
5774 * @param {Object} stack Tracks traversed `array` and `other` objects.
5775 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
5777 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
5778 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5779 arrLength = array.length,
5780 othLength = other.length;
5782 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
5785 // Check that cyclic values are equal.
5786 var arrStacked = stack.get(array);
5787 var othStacked = stack.get(other);
5788 if (arrStacked && othStacked) {
5789 return arrStacked == other && othStacked == array;
5793 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
5795 stack.set(array, other);
5796 stack.set(other, array);
5798 // Ignore non-index properties.
5799 while (++index < arrLength) {
5800 var arrValue = array[index],
5801 othValue = other[index];
5804 var compared = isPartial ?
5805 customizer(othValue, arrValue, index, other, array, stack) :
5806 customizer(arrValue, othValue, index, array, other, stack);
5808 if (compared !== undefined) {
5815 // Recursively compare arrays (susceptible to call stack limits).
5817 if (!arraySome(other, function(othValue, othIndex) {
5818 if (!cacheHas(seen, othIndex) &&
5819 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
5820 return seen.push(othIndex);
5827 arrValue === othValue ||
5828 equalFunc(arrValue, othValue, bitmask, customizer, stack)
5834 stack['delete'](array);
5835 stack['delete'](other);
5840 * A specialized version of `baseIsEqualDeep` for comparing objects of
5841 * the same `toStringTag`.
5843 * **Note:** This function only supports comparing values with tags of
5844 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5847 * @param {Object} object The object to compare.
5848 * @param {Object} other The other object to compare.
5849 * @param {string} tag The `toStringTag` of the objects to compare.
5850 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5851 * @param {Function} customizer The function to customize comparisons.
5852 * @param {Function} equalFunc The function to determine equivalents of values.
5853 * @param {Object} stack Tracks traversed `object` and `other` objects.
5854 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5856 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
5859 if ((object.byteLength != other.byteLength) ||
5860 (object.byteOffset != other.byteOffset)) {
5863 object = object.buffer;
5864 other = other.buffer;
5866 case arrayBufferTag:
5867 if ((object.byteLength != other.byteLength) ||
5868 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
5876 // Coerce booleans to `1` or `0` and dates to milliseconds.
5877 // Invalid dates are coerced to `NaN`.
5878 return eq(+object, +other);
5881 return object.name == other.name && object.message == other.message;
5885 // Coerce regexes to strings and treat strings, primitives and objects,
5886 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
5887 // for more details.
5888 return object == (other + '');
5891 var convert = mapToArray;
5894 var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
5895 convert || (convert = setToArray);
5897 if (object.size != other.size && !isPartial) {
5900 // Assume cyclic values are equal.
5901 var stacked = stack.get(object);
5903 return stacked == other;
5905 bitmask |= COMPARE_UNORDERED_FLAG;
5907 // Recursively compare objects (susceptible to call stack limits).
5908 stack.set(object, other);
5909 var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
5910 stack['delete'](object);
5914 if (symbolValueOf) {
5915 return symbolValueOf.call(object) == symbolValueOf.call(other);
5922 * A specialized version of `baseIsEqualDeep` for objects with support for
5923 * partial deep comparisons.
5926 * @param {Object} object The object to compare.
5927 * @param {Object} other The other object to compare.
5928 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
5929 * @param {Function} customizer The function to customize comparisons.
5930 * @param {Function} equalFunc The function to determine equivalents of values.
5931 * @param {Object} stack Tracks traversed `object` and `other` objects.
5932 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5934 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
5935 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
5936 objProps = getAllKeys(object),
5937 objLength = objProps.length,
5938 othProps = getAllKeys(other),
5939 othLength = othProps.length;
5941 if (objLength != othLength && !isPartial) {
5944 var index = objLength;
5946 var key = objProps[index];
5947 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
5951 // Check that cyclic values are equal.
5952 var objStacked = stack.get(object);
5953 var othStacked = stack.get(other);
5954 if (objStacked && othStacked) {
5955 return objStacked == other && othStacked == object;
5958 stack.set(object, other);
5959 stack.set(other, object);
5961 var skipCtor = isPartial;
5962 while (++index < objLength) {
5963 key = objProps[index];
5964 var objValue = object[key],
5965 othValue = other[key];
5968 var compared = isPartial ?
5969 customizer(othValue, objValue, key, other, object, stack) :
5970 customizer(objValue, othValue, key, object, other, stack);
5972 // Recursively compare objects (susceptible to call stack limits).
5973 if (!(compared === undefined ?
5974 (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) :
5980 skipCtor || (skipCtor = key == 'constructor');
5982 if (result && !skipCtor) {
5983 var objCtor = object.constructor,
5984 othCtor = other.constructor;
5986 // Non `Object` object instances with different constructors are not equal.
5987 if (objCtor != othCtor &&
5988 ('constructor' in object && 'constructor' in other) &&
5989 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
5990 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
5994 stack['delete'](object);
5995 stack['delete'](other);
6000 * A specialized version of `baseRest` which flattens the rest array.
6003 * @param {Function} func The function to apply a rest parameter to.
6004 * @returns {Function} Returns the new function.
6006 function flatRest(func) {
6007 return setToString(overRest(func, undefined, flatten), func + '');
6011 * Creates an array of own enumerable property names and symbols of `object`.
6014 * @param {Object} object The object to query.
6015 * @returns {Array} Returns the array of property names and symbols.
6017 function getAllKeys(object) {
6018 return baseGetAllKeys(object, keys, getSymbols);
6022 * Creates an array of own and inherited enumerable property names and
6023 * symbols of `object`.
6026 * @param {Object} object The object to query.
6027 * @returns {Array} Returns the array of property names and symbols.
6029 function getAllKeysIn(object) {
6030 return baseGetAllKeys(object, keysIn, getSymbolsIn);
6034 * Gets metadata for `func`.
6037 * @param {Function} func The function to query.
6038 * @returns {*} Returns the metadata for `func`.
6040 var getData = !metaMap ? noop : function(func) {
6041 return metaMap.get(func);
6045 * Gets the name of `func`.
6048 * @param {Function} func The function to query.
6049 * @returns {string} Returns the function name.
6051 function getFuncName(func) {
6052 var result = (func.name + ''),
6053 array = realNames[result],
6054 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
6057 var data = array[length],
6058 otherFunc = data.func;
6059 if (otherFunc == null || otherFunc == func) {
6067 * Gets the argument placeholder value for `func`.
6070 * @param {Function} func The function to inspect.
6071 * @returns {*} Returns the placeholder value.
6073 function getHolder(func) {
6074 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
6075 return object.placeholder;
6079 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
6080 * this function returns the custom method, otherwise it returns `baseIteratee`.
6081 * If arguments are provided, the chosen function is invoked with them and
6082 * its result is returned.
6085 * @param {*} [value] The value to convert to an iteratee.
6086 * @param {number} [arity] The arity of the created iteratee.
6087 * @returns {Function} Returns the chosen function or its result.
6089 function getIteratee() {
6090 var result = lodash.iteratee || iteratee;
6091 result = result === iteratee ? baseIteratee : result;
6092 return arguments.length ? result(arguments[0], arguments[1]) : result;
6096 * Gets the data for `map`.
6099 * @param {Object} map The map to query.
6100 * @param {string} key The reference key.
6101 * @returns {*} Returns the map data.
6103 function getMapData(map, key) {
6104 var data = map.__data__;
6105 return isKeyable(key) ?
6106 data[typeof key == 'string' ? 'string' : 'hash'] :
6111 * Gets the property names, values, and compare flags of `object`.
6114 * @param {Object} object The object to query.
6115 * @returns {Array} Returns the match data of `object`.
6117 function getMatchData(object) {
6118 var result = keys(object),
6119 length = result.length;
6122 var key = result[length],
6123 value = object[key];
6125 result[length] = [key, value, isStrictComparable(value)];
6131 * Gets the native function at `key` of `object`.
6134 * @param {Object} object The object to query.
6135 * @param {string} key The key of the method to get.
6136 * @returns {*} Returns the function if it's native, else `undefined`.
6138 function getNative(object, key) {
6139 var value = getValue(object, key);
6140 return baseIsNative(value) ? value : undefined;
6144 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
6147 * @param {*} value The value to query.
6148 * @returns {string} Returns the raw `toStringTag`.
6150 function getRawTag(value) {
6151 var isOwn = hasOwnProperty.call(value, symToStringTag),
6152 tag = value[symToStringTag];
6155 value[symToStringTag] = undefined;
6156 var unmasked = true;
6159 var result = nativeObjectToString.call(value);
6162 value[symToStringTag] = tag;
6164 delete value[symToStringTag];
6171 * Creates an array of the own enumerable symbols of `object`.
6174 * @param {Object} object The object to query.
6175 * @returns {Array} Returns the array of symbols.
6177 var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
6178 if (object == null) {
6181 object = Object(object);
6182 return arrayFilter(nativeGetSymbols(object), function(symbol) {
6183 return propertyIsEnumerable.call(object, symbol);
6188 * Creates an array of the own and inherited enumerable symbols of `object`.
6191 * @param {Object} object The object to query.
6192 * @returns {Array} Returns the array of symbols.
6194 var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
6197 arrayPush(result, getSymbols(object));
6198 object = getPrototype(object);
6204 * Gets the `toStringTag` of `value`.
6207 * @param {*} value The value to query.
6208 * @returns {string} Returns the `toStringTag`.
6210 var getTag = baseGetTag;
6212 // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
6213 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
6214 (Map && getTag(new Map) != mapTag) ||
6215 (Promise && getTag(Promise.resolve()) != promiseTag) ||
6216 (Set && getTag(new Set) != setTag) ||
6217 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
6218 getTag = function(value) {
6219 var result = baseGetTag(value),
6220 Ctor = result == objectTag ? value.constructor : undefined,
6221 ctorString = Ctor ? toSource(Ctor) : '';
6224 switch (ctorString) {
6225 case dataViewCtorString:
6229 case promiseCtorString:
6233 case weakMapCtorString:
6242 * Gets the view, applying any `transforms` to the `start` and `end` positions.
6245 * @param {number} start The start of the view.
6246 * @param {number} end The end of the view.
6247 * @param {Array} transforms The transformations to apply to the view.
6248 * @returns {Object} Returns an object containing the `start` and `end`
6249 * positions of the view.
6251 function getView(start, end, transforms) {
6253 length = transforms.length;
6255 while (++index < length) {
6256 var data = transforms[index],
6259 switch (data.type) {
6267 end = nativeMin(end, start + size);
6270 start = nativeMax(start, end - size);
6281 * Extracts wrapper details from the `source` body comment.
6284 * @param {string} source The source to inspect.
6285 * @returns {Array} Returns the wrapper details.
6287 function getWrapDetails(source) {
6288 var match = source.match(reWrapDetails);
6289 return match ? match[1].split(reSplitDetails) : [];
6293 * Checks if `path` exists on `object`.
6296 * @param {Object} object The object to query.
6297 * @param {Array|string} path The path to check.
6298 * @param {Function} hasFunc The function to check properties.
6299 * @returns {boolean} Returns `true` if `path` exists, else `false`.
6301 function hasPath(object, path, hasFunc) {
6302 path = castPath(path, object);
6305 length = path.length,
6308 while (++index < length) {
6309 var key = toKey(path[index]);
6310 if (!(result = object != null && hasFunc(object, key))) {
6313 object = object[key];
6315 if (result || ++index != length) {
6318 length = object == null ? 0 : object.length;
6319 return !!length && isLength(length) && isIndex(key, length) &&
6320 (isArray(object) || isArguments(object));
6324 * Initializes an array clone.
6327 * @param {Array} array The array to clone.
6328 * @returns {Array} Returns the initialized clone.
6330 function initCloneArray(array) {
6331 var length = array.length,
6332 result = new array.constructor(length);
6334 // Add properties assigned by `RegExp#exec`.
6335 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
6336 result.index = array.index;
6337 result.input = array.input;
6343 * Initializes an object clone.
6346 * @param {Object} object The object to clone.
6347 * @returns {Object} Returns the initialized clone.
6349 function initCloneObject(object) {
6350 return (typeof object.constructor == 'function' && !isPrototype(object)) ?
6351 baseCreate(getPrototype(object)) : {};
6355 * Initializes an object clone based on its `toStringTag`.
6357 * **Note:** This function only supports cloning values with tags of
6358 * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
6361 * @param {Object} object The object to clone.
6362 * @param {string} tag The `toStringTag` of the object to clone.
6363 * @param {boolean} [isDeep] Specify a deep clone.
6364 * @returns {Object} Returns the initialized clone.
6366 function initCloneByTag(object, tag, isDeep) {
6367 var Ctor = object.constructor;
6369 case arrayBufferTag:
6370 return cloneArrayBuffer(object);
6374 return new Ctor(+object);
6377 return cloneDataView(object, isDeep);
6385 case uint8ClampedTag:
6388 return cloneTypedArray(object, isDeep);
6395 return new Ctor(object);
6398 return cloneRegExp(object);
6404 return cloneSymbol(object);
6409 * Inserts wrapper `details` in a comment at the top of the `source` body.
6412 * @param {string} source The source to modify.
6413 * @returns {Array} details The details to insert.
6414 * @returns {string} Returns the modified source.
6416 function insertWrapDetails(source, details) {
6417 var length = details.length;
6421 var lastIndex = length - 1;
6422 details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
6423 details = details.join(length > 2 ? ', ' : ' ');
6424 return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
6428 * Checks if `value` is a flattenable `arguments` object or array.
6431 * @param {*} value The value to check.
6432 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
6434 function isFlattenable(value) {
6435 return isArray(value) || isArguments(value) ||
6436 !!(spreadableSymbol && value && value[spreadableSymbol]);
6440 * Checks if `value` is a valid array-like index.
6443 * @param {*} value The value to check.
6444 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
6445 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
6447 function isIndex(value, length) {
6448 var type = typeof value;
6449 length = length == null ? MAX_SAFE_INTEGER : length;
6452 (type == 'number' ||
6453 (type != 'symbol' && reIsUint.test(value))) &&
6454 (value > -1 && value % 1 == 0 && value < length);
6458 * Checks if the given arguments are from an iteratee call.
6461 * @param {*} value The potential iteratee value argument.
6462 * @param {*} index The potential iteratee index or key argument.
6463 * @param {*} object The potential iteratee object argument.
6464 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
6467 function isIterateeCall(value, index, object) {
6468 if (!isObject(object)) {
6471 var type = typeof index;
6472 if (type == 'number' ?
6473 (isArrayLike(object) && isIndex(index, object.length)) :
6474 (type == 'string' && index in object)
6476 return eq(object[index], value);
6482 * Checks if `value` is a property name and not a property path.
6485 * @param {*} value The value to check.
6486 * @param {Object} [object] The object to query keys on.
6487 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
6489 function isKey(value, object) {
6490 if (isArray(value)) {
6493 var type = typeof value;
6494 if (type == 'number' || type == 'symbol' || type == 'boolean' ||
6495 value == null || isSymbol(value)) {
6498 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
6499 (object != null && value in Object(object));
6503 * Checks if `value` is suitable for use as unique object key.
6506 * @param {*} value The value to check.
6507 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
6509 function isKeyable(value) {
6510 var type = typeof value;
6511 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') ?
6512 (value !== '__proto__') :
6517 * Checks if `func` has a lazy counterpart.
6520 * @param {Function} func The function to check.
6521 * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
6524 function isLaziable(func) {
6525 var funcName = getFuncName(func),
6526 other = lodash[funcName];
6528 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
6531 if (func === other) {
6534 var data = getData(other);
6535 return !!data && func === data[0];
6539 * Checks if `func` has its source masked.
6542 * @param {Function} func The function to check.
6543 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
6545 function isMasked(func) {
6546 return !!maskSrcKey && (maskSrcKey in func);
6550 * Checks if `func` is capable of being masked.
6553 * @param {*} value The value to check.
6554 * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
6556 var isMaskable = coreJsData ? isFunction : stubFalse;
6559 * Checks if `value` is likely a prototype object.
6562 * @param {*} value The value to check.
6563 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
6565 function isPrototype(value) {
6566 var Ctor = value && value.constructor,
6567 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
6569 return value === proto;
6573 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
6576 * @param {*} value The value to check.
6577 * @returns {boolean} Returns `true` if `value` if suitable for strict
6578 * equality comparisons, else `false`.
6580 function isStrictComparable(value) {
6581 return value === value && !isObject(value);
6585 * A specialized version of `matchesProperty` for source values suitable
6586 * for strict equality comparisons, i.e. `===`.
6589 * @param {string} key The key of the property to get.
6590 * @param {*} srcValue The value to match.
6591 * @returns {Function} Returns the new spec function.
6593 function matchesStrictComparable(key, srcValue) {
6594 return function(object) {
6595 if (object == null) {
6598 return object[key] === srcValue &&
6599 (srcValue !== undefined || (key in Object(object)));
6604 * A specialized version of `_.memoize` which clears the memoized function's
6605 * cache when it exceeds `MAX_MEMOIZE_SIZE`.
6608 * @param {Function} func The function to have its output memoized.
6609 * @returns {Function} Returns the new memoized function.
6611 function memoizeCapped(func) {
6612 var result = memoize(func, function(key) {
6613 if (cache.size === MAX_MEMOIZE_SIZE) {
6619 var cache = result.cache;
6624 * Merges the function metadata of `source` into `data`.
6626 * Merging metadata reduces the number of wrappers used to invoke a function.
6627 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
6628 * may be applied regardless of execution order. Methods like `_.ary` and
6629 * `_.rearg` modify function arguments, making the order in which they are
6630 * executed important, preventing the merging of metadata. However, we make
6631 * an exception for a safe combined case where curried functions have `_.ary`
6632 * and or `_.rearg` applied.
6635 * @param {Array} data The destination metadata.
6636 * @param {Array} source The source metadata.
6637 * @returns {Array} Returns `data`.
6639 function mergeData(data, source) {
6640 var bitmask = data[1],
6641 srcBitmask = source[1],
6642 newBitmask = bitmask | srcBitmask,
6643 isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
6646 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
6647 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
6648 ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
6650 // Exit early if metadata can't be merged.
6651 if (!(isCommon || isCombo)) {
6654 // Use source `thisArg` if available.
6655 if (srcBitmask & WRAP_BIND_FLAG) {
6656 data[2] = source[2];
6657 // Set when currying a bound function.
6658 newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
6660 // Compose partial arguments.
6661 var value = source[3];
6663 var partials = data[3];
6664 data[3] = partials ? composeArgs(partials, value, source[4]) : value;
6665 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
6667 // Compose partial right arguments.
6671 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
6672 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
6674 // Use source `argPos` if available.
6679 // Use source `ary` if it's smaller.
6680 if (srcBitmask & WRAP_ARY_FLAG) {
6681 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
6683 // Use source `arity` if one is not provided.
6684 if (data[9] == null) {
6685 data[9] = source[9];
6687 // Use source `func` and merge bitmasks.
6688 data[0] = source[0];
6689 data[1] = newBitmask;
6695 * This function is like
6696 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
6697 * except that it includes inherited enumerable properties.
6700 * @param {Object} object The object to query.
6701 * @returns {Array} Returns the array of property names.
6703 function nativeKeysIn(object) {
6705 if (object != null) {
6706 for (var key in Object(object)) {
6714 * Converts `value` to a string using `Object.prototype.toString`.
6717 * @param {*} value The value to convert.
6718 * @returns {string} Returns the converted string.
6720 function objectToString(value) {
6721 return nativeObjectToString.call(value);
6725 * A specialized version of `baseRest` which transforms the rest array.
6728 * @param {Function} func The function to apply a rest parameter to.
6729 * @param {number} [start=func.length-1] The start position of the rest parameter.
6730 * @param {Function} transform The rest array transform.
6731 * @returns {Function} Returns the new function.
6733 function overRest(func, start, transform) {
6734 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
6736 var args = arguments,
6738 length = nativeMax(args.length - start, 0),
6739 array = Array(length);
6741 while (++index < length) {
6742 array[index] = args[start + index];
6745 var otherArgs = Array(start + 1);
6746 while (++index < start) {
6747 otherArgs[index] = args[index];
6749 otherArgs[start] = transform(array);
6750 return apply(func, this, otherArgs);
6755 * Gets the parent value at `path` of `object`.
6758 * @param {Object} object The object to query.
6759 * @param {Array} path The path to get the parent value of.
6760 * @returns {*} Returns the parent value.
6762 function parent(object, path) {
6763 return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
6767 * Reorder `array` according to the specified indexes where the element at
6768 * the first index is assigned as the first element, the element at
6769 * the second index is assigned as the second element, and so on.
6772 * @param {Array} array The array to reorder.
6773 * @param {Array} indexes The arranged array indexes.
6774 * @returns {Array} Returns `array`.
6776 function reorder(array, indexes) {
6777 var arrLength = array.length,
6778 length = nativeMin(indexes.length, arrLength),
6779 oldArray = copyArray(array);
6782 var index = indexes[length];
6783 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
6789 * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
6792 * @param {Object} object The object to query.
6793 * @param {string} key The key of the property to get.
6794 * @returns {*} Returns the property value.
6796 function safeGet(object, key) {
6797 if (key === 'constructor' && typeof object[key] === 'function') {
6801 if (key == '__proto__') {
6809 * Sets metadata for `func`.
6811 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
6812 * period of time, it will trip its breaker and transition to an identity
6813 * function to avoid garbage collection pauses in V8. See
6814 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
6818 * @param {Function} func The function to associate metadata with.
6819 * @param {*} data The metadata.
6820 * @returns {Function} Returns `func`.
6822 var setData = shortOut(baseSetData);
6825 * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
6828 * @param {Function} func The function to delay.
6829 * @param {number} wait The number of milliseconds to delay invocation.
6830 * @returns {number|Object} Returns the timer id or timeout object.
6832 var setTimeout = ctxSetTimeout || function(func, wait) {
6833 return root.setTimeout(func, wait);
6837 * Sets the `toString` method of `func` to return `string`.
6840 * @param {Function} func The function to modify.
6841 * @param {Function} string The `toString` result.
6842 * @returns {Function} Returns `func`.
6844 var setToString = shortOut(baseSetToString);
6847 * Sets the `toString` method of `wrapper` to mimic the source of `reference`
6848 * with wrapper details in a comment at the top of the source body.
6851 * @param {Function} wrapper The function to modify.
6852 * @param {Function} reference The reference function.
6853 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6854 * @returns {Function} Returns `wrapper`.
6856 function setWrapToString(wrapper, reference, bitmask) {
6857 var source = (reference + '');
6858 return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
6862 * Creates a function that'll short out and invoke `identity` instead
6863 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
6867 * @param {Function} func The function to restrict.
6868 * @returns {Function} Returns the new shortable function.
6870 function shortOut(func) {
6875 var stamp = nativeNow(),
6876 remaining = HOT_SPAN - (stamp - lastCalled);
6879 if (remaining > 0) {
6880 if (++count >= HOT_COUNT) {
6881 return arguments[0];
6886 return func.apply(undefined, arguments);
6891 * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
6894 * @param {Array} array The array to shuffle.
6895 * @param {number} [size=array.length] The size of `array`.
6896 * @returns {Array} Returns `array`.
6898 function shuffleSelf(array, size) {
6900 length = array.length,
6901 lastIndex = length - 1;
6903 size = size === undefined ? length : size;
6904 while (++index < size) {
6905 var rand = baseRandom(index, lastIndex),
6906 value = array[rand];
6908 array[rand] = array[index];
6909 array[index] = value;
6911 array.length = size;
6916 * Converts `string` to a property path array.
6919 * @param {string} string The string to convert.
6920 * @returns {Array} Returns the property path array.
6922 var stringToPath = memoizeCapped(function(string) {
6924 if (string.charCodeAt(0) === 46 /* . */ ) {
6927 string.replace(rePropName, function(match, number, quote, subString) {
6928 result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
6934 * Converts `value` to a string key if it's not a string or symbol.
6937 * @param {*} value The value to inspect.
6938 * @returns {string|symbol} Returns the key.
6940 function toKey(value) {
6941 if (typeof value == 'string' || isSymbol(value)) {
6944 var result = (value + '');
6945 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
6949 * Converts `func` to its source code.
6952 * @param {Function} func The function to convert.
6953 * @returns {string} Returns the source code.
6955 function toSource(func) {
6958 return funcToString.call(func);
6968 * Updates wrapper `details` based on `bitmask` flags.
6971 * @returns {Array} details The details to modify.
6972 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6973 * @returns {Array} Returns `details`.
6975 function updateWrapDetails(details, bitmask) {
6976 arrayEach(wrapFlags, function(pair) {
6977 var value = '_.' + pair[0];
6978 if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
6979 details.push(value);
6982 return details.sort();
6986 * Creates a clone of `wrapper`.
6989 * @param {Object} wrapper The wrapper to clone.
6990 * @returns {Object} Returns the cloned wrapper.
6992 function wrapperClone(wrapper) {
6993 if (wrapper instanceof LazyWrapper) {
6994 return wrapper.clone();
6996 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
6997 result.__actions__ = copyArray(wrapper.__actions__);
6998 result.__index__ = wrapper.__index__;
6999 result.__values__ = wrapper.__values__;
7003 /*------------------------------------------------------------------------*/
7006 * Creates an array of elements split into groups the length of `size`.
7007 * If `array` can't be split evenly, the final chunk will be the remaining
7014 * @param {Array} array The array to process.
7015 * @param {number} [size=1] The length of each chunk
7016 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7017 * @returns {Array} Returns the new array of chunks.
7020 * _.chunk(['a', 'b', 'c', 'd'], 2);
7021 * // => [['a', 'b'], ['c', 'd']]
7023 * _.chunk(['a', 'b', 'c', 'd'], 3);
7024 * // => [['a', 'b', 'c'], ['d']]
7026 function chunk(array, size, guard) {
7027 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
7030 size = nativeMax(toInteger(size), 0);
7032 var length = array == null ? 0 : array.length;
7033 if (!length || size < 1) {
7038 result = Array(nativeCeil(length / size));
7040 while (index < length) {
7041 result[resIndex++] = baseSlice(array, index, (index += size));
7047 * Creates an array with all falsey values removed. The values `false`, `null`,
7048 * `0`, `""`, `undefined`, and `NaN` are falsey.
7054 * @param {Array} array The array to compact.
7055 * @returns {Array} Returns the new array of filtered values.
7058 * _.compact([0, 1, false, 2, '', 3]);
7061 function compact(array) {
7063 length = array == null ? 0 : array.length,
7067 while (++index < length) {
7068 var value = array[index];
7070 result[resIndex++] = value;
7077 * Creates a new array concatenating `array` with any additional arrays
7084 * @param {Array} array The array to concatenate.
7085 * @param {...*} [values] The values to concatenate.
7086 * @returns {Array} Returns the new concatenated array.
7090 * var other = _.concat(array, 2, [3], [[4]]);
7092 * console.log(other);
7093 * // => [1, 2, 3, [4]]
7095 * console.log(array);
7099 var length = arguments.length;
7103 var args = Array(length - 1),
7104 array = arguments[0],
7108 args[index - 1] = arguments[index];
7110 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
7114 * Creates an array of `array` values not included in the other given arrays
7115 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7116 * for equality comparisons. The order and references of result values are
7117 * determined by the first array.
7119 * **Note:** Unlike `_.pullAll`, this method returns a new array.
7125 * @param {Array} array The array to inspect.
7126 * @param {...Array} [values] The values to exclude.
7127 * @returns {Array} Returns the new array of filtered values.
7128 * @see _.without, _.xor
7131 * _.difference([2, 1], [2, 3]);
7134 var difference = baseRest(function(array, values) {
7135 return isArrayLikeObject(array) ?
7136 baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) : [];
7140 * This method is like `_.difference` except that it accepts `iteratee` which
7141 * is invoked for each element of `array` and `values` to generate the criterion
7142 * by which they're compared. The order and references of result values are
7143 * determined by the first array. The iteratee is invoked with one argument:
7146 * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
7152 * @param {Array} array The array to inspect.
7153 * @param {...Array} [values] The values to exclude.
7154 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7155 * @returns {Array} Returns the new array of filtered values.
7158 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7161 * // The `_.property` iteratee shorthand.
7162 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
7163 * // => [{ 'x': 2 }]
7165 var differenceBy = baseRest(function(array, values) {
7166 var iteratee = last(values);
7167 if (isArrayLikeObject(iteratee)) {
7168 iteratee = undefined;
7170 return isArrayLikeObject(array) ?
7171 baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)) : [];
7175 * This method is like `_.difference` except that it accepts `comparator`
7176 * which is invoked to compare elements of `array` to `values`. The order and
7177 * references of result values are determined by the first array. The comparator
7178 * is invoked with two arguments: (arrVal, othVal).
7180 * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
7186 * @param {Array} array The array to inspect.
7187 * @param {...Array} [values] The values to exclude.
7188 * @param {Function} [comparator] The comparator invoked per element.
7189 * @returns {Array} Returns the new array of filtered values.
7192 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7194 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
7195 * // => [{ 'x': 2, 'y': 1 }]
7197 var differenceWith = baseRest(function(array, values) {
7198 var comparator = last(values);
7199 if (isArrayLikeObject(comparator)) {
7200 comparator = undefined;
7202 return isArrayLikeObject(array) ?
7203 baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator) : [];
7207 * Creates a slice of `array` with `n` elements dropped from the beginning.
7213 * @param {Array} array The array to query.
7214 * @param {number} [n=1] The number of elements to drop.
7215 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7216 * @returns {Array} Returns the slice of `array`.
7219 * _.drop([1, 2, 3]);
7222 * _.drop([1, 2, 3], 2);
7225 * _.drop([1, 2, 3], 5);
7228 * _.drop([1, 2, 3], 0);
7231 function drop(array, n, guard) {
7232 var length = array == null ? 0 : array.length;
7236 n = (guard || n === undefined) ? 1 : toInteger(n);
7237 return baseSlice(array, n < 0 ? 0 : n, length);
7241 * Creates a slice of `array` with `n` elements dropped from the end.
7247 * @param {Array} array The array to query.
7248 * @param {number} [n=1] The number of elements to drop.
7249 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7250 * @returns {Array} Returns the slice of `array`.
7253 * _.dropRight([1, 2, 3]);
7256 * _.dropRight([1, 2, 3], 2);
7259 * _.dropRight([1, 2, 3], 5);
7262 * _.dropRight([1, 2, 3], 0);
7265 function dropRight(array, n, guard) {
7266 var length = array == null ? 0 : array.length;
7270 n = (guard || n === undefined) ? 1 : toInteger(n);
7272 return baseSlice(array, 0, n < 0 ? 0 : n);
7276 * Creates a slice of `array` excluding elements dropped from the end.
7277 * Elements are dropped until `predicate` returns falsey. The predicate is
7278 * invoked with three arguments: (value, index, array).
7284 * @param {Array} array The array to query.
7285 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7286 * @returns {Array} Returns the slice of `array`.
7290 * { 'user': 'barney', 'active': true },
7291 * { 'user': 'fred', 'active': false },
7292 * { 'user': 'pebbles', 'active': false }
7295 * _.dropRightWhile(users, function(o) { return !o.active; });
7296 * // => objects for ['barney']
7298 * // The `_.matches` iteratee shorthand.
7299 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
7300 * // => objects for ['barney', 'fred']
7302 * // The `_.matchesProperty` iteratee shorthand.
7303 * _.dropRightWhile(users, ['active', false]);
7304 * // => objects for ['barney']
7306 * // The `_.property` iteratee shorthand.
7307 * _.dropRightWhile(users, 'active');
7308 * // => objects for ['barney', 'fred', 'pebbles']
7310 function dropRightWhile(array, predicate) {
7311 return (array && array.length) ?
7312 baseWhile(array, getIteratee(predicate, 3), true, true) : [];
7316 * Creates a slice of `array` excluding elements dropped from the beginning.
7317 * Elements are dropped until `predicate` returns falsey. The predicate is
7318 * invoked with three arguments: (value, index, array).
7324 * @param {Array} array The array to query.
7325 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7326 * @returns {Array} Returns the slice of `array`.
7330 * { 'user': 'barney', 'active': false },
7331 * { 'user': 'fred', 'active': false },
7332 * { 'user': 'pebbles', 'active': true }
7335 * _.dropWhile(users, function(o) { return !o.active; });
7336 * // => objects for ['pebbles']
7338 * // The `_.matches` iteratee shorthand.
7339 * _.dropWhile(users, { 'user': 'barney', 'active': false });
7340 * // => objects for ['fred', 'pebbles']
7342 * // The `_.matchesProperty` iteratee shorthand.
7343 * _.dropWhile(users, ['active', false]);
7344 * // => objects for ['pebbles']
7346 * // The `_.property` iteratee shorthand.
7347 * _.dropWhile(users, 'active');
7348 * // => objects for ['barney', 'fred', 'pebbles']
7350 function dropWhile(array, predicate) {
7351 return (array && array.length) ?
7352 baseWhile(array, getIteratee(predicate, 3), true) : [];
7356 * Fills elements of `array` with `value` from `start` up to, but not
7359 * **Note:** This method mutates `array`.
7365 * @param {Array} array The array to fill.
7366 * @param {*} value The value to fill `array` with.
7367 * @param {number} [start=0] The start position.
7368 * @param {number} [end=array.length] The end position.
7369 * @returns {Array} Returns `array`.
7372 * var array = [1, 2, 3];
7374 * _.fill(array, 'a');
7375 * console.log(array);
7376 * // => ['a', 'a', 'a']
7378 * _.fill(Array(3), 2);
7381 * _.fill([4, 6, 8, 10], '*', 1, 3);
7382 * // => [4, '*', '*', 10]
7384 function fill(array, value, start, end) {
7385 var length = array == null ? 0 : array.length;
7389 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
7393 return baseFill(array, value, start, end);
7397 * This method is like `_.find` except that it returns the index of the first
7398 * element `predicate` returns truthy for instead of the element itself.
7404 * @param {Array} array The array to inspect.
7405 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7406 * @param {number} [fromIndex=0] The index to search from.
7407 * @returns {number} Returns the index of the found element, else `-1`.
7411 * { 'user': 'barney', 'active': false },
7412 * { 'user': 'fred', 'active': false },
7413 * { 'user': 'pebbles', 'active': true }
7416 * _.findIndex(users, function(o) { return o.user == 'barney'; });
7419 * // The `_.matches` iteratee shorthand.
7420 * _.findIndex(users, { 'user': 'fred', 'active': false });
7423 * // The `_.matchesProperty` iteratee shorthand.
7424 * _.findIndex(users, ['active', false]);
7427 * // The `_.property` iteratee shorthand.
7428 * _.findIndex(users, 'active');
7431 function findIndex(array, predicate, fromIndex) {
7432 var length = array == null ? 0 : array.length;
7436 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7438 index = nativeMax(length + index, 0);
7440 return baseFindIndex(array, getIteratee(predicate, 3), index);
7444 * This method is like `_.findIndex` except that it iterates over elements
7445 * of `collection` from right to left.
7451 * @param {Array} array The array to inspect.
7452 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7453 * @param {number} [fromIndex=array.length-1] The index to search from.
7454 * @returns {number} Returns the index of the found element, else `-1`.
7458 * { 'user': 'barney', 'active': true },
7459 * { 'user': 'fred', 'active': false },
7460 * { 'user': 'pebbles', 'active': false }
7463 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
7466 * // The `_.matches` iteratee shorthand.
7467 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
7470 * // The `_.matchesProperty` iteratee shorthand.
7471 * _.findLastIndex(users, ['active', false]);
7474 * // The `_.property` iteratee shorthand.
7475 * _.findLastIndex(users, 'active');
7478 function findLastIndex(array, predicate, fromIndex) {
7479 var length = array == null ? 0 : array.length;
7483 var index = length - 1;
7484 if (fromIndex !== undefined) {
7485 index = toInteger(fromIndex);
7486 index = fromIndex < 0 ?
7487 nativeMax(length + index, 0) :
7488 nativeMin(index, length - 1);
7490 return baseFindIndex(array, getIteratee(predicate, 3), index, true);
7494 * Flattens `array` a single level deep.
7500 * @param {Array} array The array to flatten.
7501 * @returns {Array} Returns the new flattened array.
7504 * _.flatten([1, [2, [3, [4]], 5]]);
7505 * // => [1, 2, [3, [4]], 5]
7507 function flatten(array) {
7508 var length = array == null ? 0 : array.length;
7509 return length ? baseFlatten(array, 1) : [];
7513 * Recursively flattens `array`.
7519 * @param {Array} array The array to flatten.
7520 * @returns {Array} Returns the new flattened array.
7523 * _.flattenDeep([1, [2, [3, [4]], 5]]);
7524 * // => [1, 2, 3, 4, 5]
7526 function flattenDeep(array) {
7527 var length = array == null ? 0 : array.length;
7528 return length ? baseFlatten(array, INFINITY) : [];
7532 * Recursively flatten `array` up to `depth` times.
7538 * @param {Array} array The array to flatten.
7539 * @param {number} [depth=1] The maximum recursion depth.
7540 * @returns {Array} Returns the new flattened array.
7543 * var array = [1, [2, [3, [4]], 5]];
7545 * _.flattenDepth(array, 1);
7546 * // => [1, 2, [3, [4]], 5]
7548 * _.flattenDepth(array, 2);
7549 * // => [1, 2, 3, [4], 5]
7551 function flattenDepth(array, depth) {
7552 var length = array == null ? 0 : array.length;
7556 depth = depth === undefined ? 1 : toInteger(depth);
7557 return baseFlatten(array, depth);
7561 * The inverse of `_.toPairs`; this method returns an object composed
7562 * from key-value `pairs`.
7568 * @param {Array} pairs The key-value pairs.
7569 * @returns {Object} Returns the new object.
7572 * _.fromPairs([['a', 1], ['b', 2]]);
7573 * // => { 'a': 1, 'b': 2 }
7575 function fromPairs(pairs) {
7577 length = pairs == null ? 0 : pairs.length,
7580 while (++index < length) {
7581 var pair = pairs[index];
7582 result[pair[0]] = pair[1];
7588 * Gets the first element of `array`.
7595 * @param {Array} array The array to query.
7596 * @returns {*} Returns the first element of `array`.
7599 * _.head([1, 2, 3]);
7605 function head(array) {
7606 return (array && array.length) ? array[0] : undefined;
7610 * Gets the index at which the first occurrence of `value` is found in `array`
7611 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7612 * for equality comparisons. If `fromIndex` is negative, it's used as the
7613 * offset from the end of `array`.
7619 * @param {Array} array The array to inspect.
7620 * @param {*} value The value to search for.
7621 * @param {number} [fromIndex=0] The index to search from.
7622 * @returns {number} Returns the index of the matched value, else `-1`.
7625 * _.indexOf([1, 2, 1, 2], 2);
7628 * // Search from the `fromIndex`.
7629 * _.indexOf([1, 2, 1, 2], 2, 2);
7632 function indexOf(array, value, fromIndex) {
7633 var length = array == null ? 0 : array.length;
7637 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7639 index = nativeMax(length + index, 0);
7641 return baseIndexOf(array, value, index);
7645 * Gets all but the last element of `array`.
7651 * @param {Array} array The array to query.
7652 * @returns {Array} Returns the slice of `array`.
7655 * _.initial([1, 2, 3]);
7658 function initial(array) {
7659 var length = array == null ? 0 : array.length;
7660 return length ? baseSlice(array, 0, -1) : [];
7664 * Creates an array of unique values that are included in all given arrays
7665 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7666 * for equality comparisons. The order and references of result values are
7667 * determined by the first array.
7673 * @param {...Array} [arrays] The arrays to inspect.
7674 * @returns {Array} Returns the new array of intersecting values.
7677 * _.intersection([2, 1], [2, 3]);
7680 var intersection = baseRest(function(arrays) {
7681 var mapped = arrayMap(arrays, castArrayLikeObject);
7682 return (mapped.length && mapped[0] === arrays[0]) ?
7683 baseIntersection(mapped) : [];
7687 * This method is like `_.intersection` except that it accepts `iteratee`
7688 * which is invoked for each element of each `arrays` to generate the criterion
7689 * by which they're compared. The order and references of result values are
7690 * determined by the first array. The iteratee is invoked with one argument:
7697 * @param {...Array} [arrays] The arrays to inspect.
7698 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7699 * @returns {Array} Returns the new array of intersecting values.
7702 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7705 * // The `_.property` iteratee shorthand.
7706 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7707 * // => [{ 'x': 1 }]
7709 var intersectionBy = baseRest(function(arrays) {
7710 var iteratee = last(arrays),
7711 mapped = arrayMap(arrays, castArrayLikeObject);
7713 if (iteratee === last(mapped)) {
7714 iteratee = undefined;
7718 return (mapped.length && mapped[0] === arrays[0]) ?
7719 baseIntersection(mapped, getIteratee(iteratee, 2)) : [];
7723 * This method is like `_.intersection` except that it accepts `comparator`
7724 * which is invoked to compare elements of `arrays`. The order and references
7725 * of result values are determined by the first array. The comparator is
7726 * invoked with two arguments: (arrVal, othVal).
7732 * @param {...Array} [arrays] The arrays to inspect.
7733 * @param {Function} [comparator] The comparator invoked per element.
7734 * @returns {Array} Returns the new array of intersecting values.
7737 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7738 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7740 * _.intersectionWith(objects, others, _.isEqual);
7741 * // => [{ 'x': 1, 'y': 2 }]
7743 var intersectionWith = baseRest(function(arrays) {
7744 var comparator = last(arrays),
7745 mapped = arrayMap(arrays, castArrayLikeObject);
7747 comparator = typeof comparator == 'function' ? comparator : undefined;
7751 return (mapped.length && mapped[0] === arrays[0]) ?
7752 baseIntersection(mapped, undefined, comparator) : [];
7756 * Converts all elements in `array` into a string separated by `separator`.
7762 * @param {Array} array The array to convert.
7763 * @param {string} [separator=','] The element separator.
7764 * @returns {string} Returns the joined string.
7767 * _.join(['a', 'b', 'c'], '~');
7770 function join(array, separator) {
7771 return array == null ? '' : nativeJoin.call(array, separator);
7775 * Gets the last element of `array`.
7781 * @param {Array} array The array to query.
7782 * @returns {*} Returns the last element of `array`.
7785 * _.last([1, 2, 3]);
7788 function last(array) {
7789 var length = array == null ? 0 : array.length;
7790 return length ? array[length - 1] : undefined;
7794 * This method is like `_.indexOf` except that it iterates over elements of
7795 * `array` from right to left.
7801 * @param {Array} array The array to inspect.
7802 * @param {*} value The value to search for.
7803 * @param {number} [fromIndex=array.length-1] The index to search from.
7804 * @returns {number} Returns the index of the matched value, else `-1`.
7807 * _.lastIndexOf([1, 2, 1, 2], 2);
7810 * // Search from the `fromIndex`.
7811 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
7814 function lastIndexOf(array, value, fromIndex) {
7815 var length = array == null ? 0 : array.length;
7820 if (fromIndex !== undefined) {
7821 index = toInteger(fromIndex);
7822 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
7824 return value === value ?
7825 strictLastIndexOf(array, value, index) :
7826 baseFindIndex(array, baseIsNaN, index, true);
7830 * Gets the element at index `n` of `array`. If `n` is negative, the nth
7831 * element from the end is returned.
7837 * @param {Array} array The array to query.
7838 * @param {number} [n=0] The index of the element to return.
7839 * @returns {*} Returns the nth element of `array`.
7842 * var array = ['a', 'b', 'c', 'd'];
7850 function nth(array, n) {
7851 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
7855 * Removes all given values from `array` using
7856 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7857 * for equality comparisons.
7859 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
7860 * to remove elements from an array by predicate.
7866 * @param {Array} array The array to modify.
7867 * @param {...*} [values] The values to remove.
7868 * @returns {Array} Returns `array`.
7871 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7873 * _.pull(array, 'a', 'c');
7874 * console.log(array);
7877 var pull = baseRest(pullAll);
7880 * This method is like `_.pull` except that it accepts an array of values to remove.
7882 * **Note:** Unlike `_.difference`, this method mutates `array`.
7888 * @param {Array} array The array to modify.
7889 * @param {Array} values The values to remove.
7890 * @returns {Array} Returns `array`.
7893 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7895 * _.pullAll(array, ['a', 'c']);
7896 * console.log(array);
7899 function pullAll(array, values) {
7900 return (array && array.length && values && values.length) ?
7901 basePullAll(array, values) :
7906 * This method is like `_.pullAll` except that it accepts `iteratee` which is
7907 * invoked for each element of `array` and `values` to generate the criterion
7908 * by which they're compared. The iteratee is invoked with one argument: (value).
7910 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
7916 * @param {Array} array The array to modify.
7917 * @param {Array} values The values to remove.
7918 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7919 * @returns {Array} Returns `array`.
7922 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
7924 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
7925 * console.log(array);
7926 * // => [{ 'x': 2 }]
7928 function pullAllBy(array, values, iteratee) {
7929 return (array && array.length && values && values.length) ?
7930 basePullAll(array, values, getIteratee(iteratee, 2)) :
7935 * This method is like `_.pullAll` except that it accepts `comparator` which
7936 * is invoked to compare elements of `array` to `values`. The comparator is
7937 * invoked with two arguments: (arrVal, othVal).
7939 * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
7945 * @param {Array} array The array to modify.
7946 * @param {Array} values The values to remove.
7947 * @param {Function} [comparator] The comparator invoked per element.
7948 * @returns {Array} Returns `array`.
7951 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
7953 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
7954 * console.log(array);
7955 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
7957 function pullAllWith(array, values, comparator) {
7958 return (array && array.length && values && values.length) ?
7959 basePullAll(array, values, undefined, comparator) :
7964 * Removes elements from `array` corresponding to `indexes` and returns an
7965 * array of removed elements.
7967 * **Note:** Unlike `_.at`, this method mutates `array`.
7973 * @param {Array} array The array to modify.
7974 * @param {...(number|number[])} [indexes] The indexes of elements to remove.
7975 * @returns {Array} Returns the new array of removed elements.
7978 * var array = ['a', 'b', 'c', 'd'];
7979 * var pulled = _.pullAt(array, [1, 3]);
7981 * console.log(array);
7984 * console.log(pulled);
7987 var pullAt = flatRest(function(array, indexes) {
7988 var length = array == null ? 0 : array.length,
7989 result = baseAt(array, indexes);
7991 basePullAt(array, arrayMap(indexes, function(index) {
7992 return isIndex(index, length) ? +index : index;
7993 }).sort(compareAscending));
7999 * Removes all elements from `array` that `predicate` returns truthy for
8000 * and returns an array of the removed elements. The predicate is invoked
8001 * with three arguments: (value, index, array).
8003 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
8004 * to pull elements from an array by value.
8010 * @param {Array} array The array to modify.
8011 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8012 * @returns {Array} Returns the new array of removed elements.
8015 * var array = [1, 2, 3, 4];
8016 * var evens = _.remove(array, function(n) {
8017 * return n % 2 == 0;
8020 * console.log(array);
8023 * console.log(evens);
8026 function remove(array, predicate) {
8028 if (!(array && array.length)) {
8033 length = array.length;
8035 predicate = getIteratee(predicate, 3);
8036 while (++index < length) {
8037 var value = array[index];
8038 if (predicate(value, index, array)) {
8040 indexes.push(index);
8043 basePullAt(array, indexes);
8048 * Reverses `array` so that the first element becomes the last, the second
8049 * element becomes the second to last, and so on.
8051 * **Note:** This method mutates `array` and is based on
8052 * [`Array#reverse`](https://mdn.io/Array/reverse).
8058 * @param {Array} array The array to modify.
8059 * @returns {Array} Returns `array`.
8062 * var array = [1, 2, 3];
8067 * console.log(array);
8070 function reverse(array) {
8071 return array == null ? array : nativeReverse.call(array);
8075 * Creates a slice of `array` from `start` up to, but not including, `end`.
8077 * **Note:** This method is used instead of
8078 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
8085 * @param {Array} array The array to slice.
8086 * @param {number} [start=0] The start position.
8087 * @param {number} [end=array.length] The end position.
8088 * @returns {Array} Returns the slice of `array`.
8090 function slice(array, start, end) {
8091 var length = array == null ? 0 : array.length;
8095 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
8099 start = start == null ? 0 : toInteger(start);
8100 end = end === undefined ? length : toInteger(end);
8102 return baseSlice(array, start, end);
8106 * Uses a binary search to determine the lowest index at which `value`
8107 * should be inserted into `array` in order to maintain its sort order.
8113 * @param {Array} array The sorted array to inspect.
8114 * @param {*} value The value to evaluate.
8115 * @returns {number} Returns the index at which `value` should be inserted
8119 * _.sortedIndex([30, 50], 40);
8122 function sortedIndex(array, value) {
8123 return baseSortedIndex(array, value);
8127 * This method is like `_.sortedIndex` except that it accepts `iteratee`
8128 * which is invoked for `value` and each element of `array` to compute their
8129 * sort ranking. The iteratee is invoked with one argument: (value).
8135 * @param {Array} array The sorted array to inspect.
8136 * @param {*} value The value to evaluate.
8137 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8138 * @returns {number} Returns the index at which `value` should be inserted
8142 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8144 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8147 * // The `_.property` iteratee shorthand.
8148 * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
8151 function sortedIndexBy(array, value, iteratee) {
8152 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
8156 * This method is like `_.indexOf` except that it performs a binary
8157 * search on a sorted `array`.
8163 * @param {Array} array The array to inspect.
8164 * @param {*} value The value to search for.
8165 * @returns {number} Returns the index of the matched value, else `-1`.
8168 * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
8171 function sortedIndexOf(array, value) {
8172 var length = array == null ? 0 : array.length;
8174 var index = baseSortedIndex(array, value);
8175 if (index < length && eq(array[index], value)) {
8183 * This method is like `_.sortedIndex` except that it returns the highest
8184 * index at which `value` should be inserted into `array` in order to
8185 * maintain its sort order.
8191 * @param {Array} array The sorted array to inspect.
8192 * @param {*} value The value to evaluate.
8193 * @returns {number} Returns the index at which `value` should be inserted
8197 * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
8200 function sortedLastIndex(array, value) {
8201 return baseSortedIndex(array, value, true);
8205 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
8206 * which is invoked for `value` and each element of `array` to compute their
8207 * sort ranking. The iteratee is invoked with one argument: (value).
8213 * @param {Array} array The sorted array to inspect.
8214 * @param {*} value The value to evaluate.
8215 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8216 * @returns {number} Returns the index at which `value` should be inserted
8220 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8222 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8225 * // The `_.property` iteratee shorthand.
8226 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
8229 function sortedLastIndexBy(array, value, iteratee) {
8230 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
8234 * This method is like `_.lastIndexOf` except that it performs a binary
8235 * search on a sorted `array`.
8241 * @param {Array} array The array to inspect.
8242 * @param {*} value The value to search for.
8243 * @returns {number} Returns the index of the matched value, else `-1`.
8246 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
8249 function sortedLastIndexOf(array, value) {
8250 var length = array == null ? 0 : array.length;
8252 var index = baseSortedIndex(array, value, true) - 1;
8253 if (eq(array[index], value)) {
8261 * This method is like `_.uniq` except that it's designed and optimized
8262 * for sorted arrays.
8268 * @param {Array} array The array to inspect.
8269 * @returns {Array} Returns the new duplicate free array.
8272 * _.sortedUniq([1, 1, 2]);
8275 function sortedUniq(array) {
8276 return (array && array.length) ?
8277 baseSortedUniq(array) : [];
8281 * This method is like `_.uniqBy` except that it's designed and optimized
8282 * for sorted arrays.
8288 * @param {Array} array The array to inspect.
8289 * @param {Function} [iteratee] The iteratee invoked per element.
8290 * @returns {Array} Returns the new duplicate free array.
8293 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
8296 function sortedUniqBy(array, iteratee) {
8297 return (array && array.length) ?
8298 baseSortedUniq(array, getIteratee(iteratee, 2)) : [];
8302 * Gets all but the first element of `array`.
8308 * @param {Array} array The array to query.
8309 * @returns {Array} Returns the slice of `array`.
8312 * _.tail([1, 2, 3]);
8315 function tail(array) {
8316 var length = array == null ? 0 : array.length;
8317 return length ? baseSlice(array, 1, length) : [];
8321 * Creates a slice of `array` with `n` elements taken from the beginning.
8327 * @param {Array} array The array to query.
8328 * @param {number} [n=1] The number of elements to take.
8329 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8330 * @returns {Array} Returns the slice of `array`.
8333 * _.take([1, 2, 3]);
8336 * _.take([1, 2, 3], 2);
8339 * _.take([1, 2, 3], 5);
8342 * _.take([1, 2, 3], 0);
8345 function take(array, n, guard) {
8346 if (!(array && array.length)) {
8349 n = (guard || n === undefined) ? 1 : toInteger(n);
8350 return baseSlice(array, 0, n < 0 ? 0 : n);
8354 * Creates a slice of `array` with `n` elements taken from the end.
8360 * @param {Array} array The array to query.
8361 * @param {number} [n=1] The number of elements to take.
8362 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8363 * @returns {Array} Returns the slice of `array`.
8366 * _.takeRight([1, 2, 3]);
8369 * _.takeRight([1, 2, 3], 2);
8372 * _.takeRight([1, 2, 3], 5);
8375 * _.takeRight([1, 2, 3], 0);
8378 function takeRight(array, n, guard) {
8379 var length = array == null ? 0 : array.length;
8383 n = (guard || n === undefined) ? 1 : toInteger(n);
8385 return baseSlice(array, n < 0 ? 0 : n, length);
8389 * Creates a slice of `array` with elements taken from the end. Elements are
8390 * taken until `predicate` returns falsey. The predicate is invoked with
8391 * three arguments: (value, index, array).
8397 * @param {Array} array The array to query.
8398 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8399 * @returns {Array} Returns the slice of `array`.
8403 * { 'user': 'barney', 'active': true },
8404 * { 'user': 'fred', 'active': false },
8405 * { 'user': 'pebbles', 'active': false }
8408 * _.takeRightWhile(users, function(o) { return !o.active; });
8409 * // => objects for ['fred', 'pebbles']
8411 * // The `_.matches` iteratee shorthand.
8412 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
8413 * // => objects for ['pebbles']
8415 * // The `_.matchesProperty` iteratee shorthand.
8416 * _.takeRightWhile(users, ['active', false]);
8417 * // => objects for ['fred', 'pebbles']
8419 * // The `_.property` iteratee shorthand.
8420 * _.takeRightWhile(users, 'active');
8423 function takeRightWhile(array, predicate) {
8424 return (array && array.length) ?
8425 baseWhile(array, getIteratee(predicate, 3), false, true) : [];
8429 * Creates a slice of `array` with elements taken from the beginning. Elements
8430 * are taken until `predicate` returns falsey. The predicate is invoked with
8431 * three arguments: (value, index, array).
8437 * @param {Array} array The array to query.
8438 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8439 * @returns {Array} Returns the slice of `array`.
8443 * { 'user': 'barney', 'active': false },
8444 * { 'user': 'fred', 'active': false },
8445 * { 'user': 'pebbles', 'active': true }
8448 * _.takeWhile(users, function(o) { return !o.active; });
8449 * // => objects for ['barney', 'fred']
8451 * // The `_.matches` iteratee shorthand.
8452 * _.takeWhile(users, { 'user': 'barney', 'active': false });
8453 * // => objects for ['barney']
8455 * // The `_.matchesProperty` iteratee shorthand.
8456 * _.takeWhile(users, ['active', false]);
8457 * // => objects for ['barney', 'fred']
8459 * // The `_.property` iteratee shorthand.
8460 * _.takeWhile(users, 'active');
8463 function takeWhile(array, predicate) {
8464 return (array && array.length) ?
8465 baseWhile(array, getIteratee(predicate, 3)) : [];
8469 * Creates an array of unique values, in order, from all given arrays using
8470 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8471 * for equality comparisons.
8477 * @param {...Array} [arrays] The arrays to inspect.
8478 * @returns {Array} Returns the new array of combined values.
8481 * _.union([2], [1, 2]);
8484 var union = baseRest(function(arrays) {
8485 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
8489 * This method is like `_.union` except that it accepts `iteratee` which is
8490 * invoked for each element of each `arrays` to generate the criterion by
8491 * which uniqueness is computed. Result values are chosen from the first
8492 * array in which the value occurs. The iteratee is invoked with one argument:
8499 * @param {...Array} [arrays] The arrays to inspect.
8500 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8501 * @returns {Array} Returns the new array of combined values.
8504 * _.unionBy([2.1], [1.2, 2.3], Math.floor);
8507 * // The `_.property` iteratee shorthand.
8508 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8509 * // => [{ 'x': 1 }, { 'x': 2 }]
8511 var unionBy = baseRest(function(arrays) {
8512 var iteratee = last(arrays);
8513 if (isArrayLikeObject(iteratee)) {
8514 iteratee = undefined;
8516 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
8520 * This method is like `_.union` except that it accepts `comparator` which
8521 * is invoked to compare elements of `arrays`. Result values are chosen from
8522 * the first array in which the value occurs. The comparator is invoked
8523 * with two arguments: (arrVal, othVal).
8529 * @param {...Array} [arrays] The arrays to inspect.
8530 * @param {Function} [comparator] The comparator invoked per element.
8531 * @returns {Array} Returns the new array of combined values.
8534 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8535 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8537 * _.unionWith(objects, others, _.isEqual);
8538 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8540 var unionWith = baseRest(function(arrays) {
8541 var comparator = last(arrays);
8542 comparator = typeof comparator == 'function' ? comparator : undefined;
8543 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
8547 * Creates a duplicate-free version of an array, using
8548 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8549 * for equality comparisons, in which only the first occurrence of each element
8550 * is kept. The order of result values is determined by the order they occur
8557 * @param {Array} array The array to inspect.
8558 * @returns {Array} Returns the new duplicate free array.
8561 * _.uniq([2, 1, 2]);
8564 function uniq(array) {
8565 return (array && array.length) ? baseUniq(array) : [];
8569 * This method is like `_.uniq` except that it accepts `iteratee` which is
8570 * invoked for each element in `array` to generate the criterion by which
8571 * uniqueness is computed. The order of result values is determined by the
8572 * order they occur in the array. The iteratee is invoked with one argument:
8579 * @param {Array} array The array to inspect.
8580 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8581 * @returns {Array} Returns the new duplicate free array.
8584 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
8587 * // The `_.property` iteratee shorthand.
8588 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
8589 * // => [{ 'x': 1 }, { 'x': 2 }]
8591 function uniqBy(array, iteratee) {
8592 return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
8596 * This method is like `_.uniq` except that it accepts `comparator` which
8597 * is invoked to compare elements of `array`. The order of result values is
8598 * determined by the order they occur in the array.The comparator is invoked
8599 * with two arguments: (arrVal, othVal).
8605 * @param {Array} array The array to inspect.
8606 * @param {Function} [comparator] The comparator invoked per element.
8607 * @returns {Array} Returns the new duplicate free array.
8610 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
8612 * _.uniqWith(objects, _.isEqual);
8613 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
8615 function uniqWith(array, comparator) {
8616 comparator = typeof comparator == 'function' ? comparator : undefined;
8617 return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
8621 * This method is like `_.zip` except that it accepts an array of grouped
8622 * elements and creates an array regrouping the elements to their pre-zip
8629 * @param {Array} array The array of grouped elements to process.
8630 * @returns {Array} Returns the new array of regrouped elements.
8633 * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
8634 * // => [['a', 1, true], ['b', 2, false]]
8637 * // => [['a', 'b'], [1, 2], [true, false]]
8639 function unzip(array) {
8640 if (!(array && array.length)) {
8644 array = arrayFilter(array, function(group) {
8645 if (isArrayLikeObject(group)) {
8646 length = nativeMax(group.length, length);
8650 return baseTimes(length, function(index) {
8651 return arrayMap(array, baseProperty(index));
8656 * This method is like `_.unzip` except that it accepts `iteratee` to specify
8657 * how regrouped values should be combined. The iteratee is invoked with the
8658 * elements of each group: (...group).
8664 * @param {Array} array The array of grouped elements to process.
8665 * @param {Function} [iteratee=_.identity] The function to combine
8667 * @returns {Array} Returns the new array of regrouped elements.
8670 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
8671 * // => [[1, 10, 100], [2, 20, 200]]
8673 * _.unzipWith(zipped, _.add);
8674 * // => [3, 30, 300]
8676 function unzipWith(array, iteratee) {
8677 if (!(array && array.length)) {
8680 var result = unzip(array);
8681 if (iteratee == null) {
8684 return arrayMap(result, function(group) {
8685 return apply(iteratee, undefined, group);
8690 * Creates an array excluding all given values using
8691 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8692 * for equality comparisons.
8694 * **Note:** Unlike `_.pull`, this method returns a new array.
8700 * @param {Array} array The array to inspect.
8701 * @param {...*} [values] The values to exclude.
8702 * @returns {Array} Returns the new array of filtered values.
8703 * @see _.difference, _.xor
8706 * _.without([2, 1, 2, 3], 1, 2);
8709 var without = baseRest(function(array, values) {
8710 return isArrayLikeObject(array) ?
8711 baseDifference(array, values) : [];
8715 * Creates an array of unique values that is the
8716 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
8717 * of the given arrays. The order of result values is determined by the order
8718 * they occur in the arrays.
8724 * @param {...Array} [arrays] The arrays to inspect.
8725 * @returns {Array} Returns the new array of filtered values.
8726 * @see _.difference, _.without
8729 * _.xor([2, 1], [2, 3]);
8732 var xor = baseRest(function(arrays) {
8733 return baseXor(arrayFilter(arrays, isArrayLikeObject));
8737 * This method is like `_.xor` except that it accepts `iteratee` which is
8738 * invoked for each element of each `arrays` to generate the criterion by
8739 * which by which they're compared. The order of result values is determined
8740 * by the order they occur in the arrays. The iteratee is invoked with one
8741 * argument: (value).
8747 * @param {...Array} [arrays] The arrays to inspect.
8748 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8749 * @returns {Array} Returns the new array of filtered values.
8752 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
8755 * // The `_.property` iteratee shorthand.
8756 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8757 * // => [{ 'x': 2 }]
8759 var xorBy = baseRest(function(arrays) {
8760 var iteratee = last(arrays);
8761 if (isArrayLikeObject(iteratee)) {
8762 iteratee = undefined;
8764 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
8768 * This method is like `_.xor` except that it accepts `comparator` which is
8769 * invoked to compare elements of `arrays`. The order of result values is
8770 * determined by the order they occur in the arrays. The comparator is invoked
8771 * with two arguments: (arrVal, othVal).
8777 * @param {...Array} [arrays] The arrays to inspect.
8778 * @param {Function} [comparator] The comparator invoked per element.
8779 * @returns {Array} Returns the new array of filtered values.
8782 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8783 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8785 * _.xorWith(objects, others, _.isEqual);
8786 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8788 var xorWith = baseRest(function(arrays) {
8789 var comparator = last(arrays);
8790 comparator = typeof comparator == 'function' ? comparator : undefined;
8791 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
8795 * Creates an array of grouped elements, the first of which contains the
8796 * first elements of the given arrays, the second of which contains the
8797 * second elements of the given arrays, and so on.
8803 * @param {...Array} [arrays] The arrays to process.
8804 * @returns {Array} Returns the new array of grouped elements.
8807 * _.zip(['a', 'b'], [1, 2], [true, false]);
8808 * // => [['a', 1, true], ['b', 2, false]]
8810 var zip = baseRest(unzip);
8813 * This method is like `_.fromPairs` except that it accepts two arrays,
8814 * one of property identifiers and one of corresponding values.
8820 * @param {Array} [props=[]] The property identifiers.
8821 * @param {Array} [values=[]] The property values.
8822 * @returns {Object} Returns the new object.
8825 * _.zipObject(['a', 'b'], [1, 2]);
8826 * // => { 'a': 1, 'b': 2 }
8828 function zipObject(props, values) {
8829 return baseZipObject(props || [], values || [], assignValue);
8833 * This method is like `_.zipObject` except that it supports property paths.
8839 * @param {Array} [props=[]] The property identifiers.
8840 * @param {Array} [values=[]] The property values.
8841 * @returns {Object} Returns the new object.
8844 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
8845 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
8847 function zipObjectDeep(props, values) {
8848 return baseZipObject(props || [], values || [], baseSet);
8852 * This method is like `_.zip` except that it accepts `iteratee` to specify
8853 * how grouped values should be combined. The iteratee is invoked with the
8854 * elements of each group: (...group).
8860 * @param {...Array} [arrays] The arrays to process.
8861 * @param {Function} [iteratee=_.identity] The function to combine
8863 * @returns {Array} Returns the new array of grouped elements.
8866 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
8871 var zipWith = baseRest(function(arrays) {
8872 var length = arrays.length,
8873 iteratee = length > 1 ? arrays[length - 1] : undefined;
8875 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
8876 return unzipWith(arrays, iteratee);
8879 /*------------------------------------------------------------------------*/
8882 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
8883 * chain sequences enabled. The result of such sequences must be unwrapped
8890 * @param {*} value The value to wrap.
8891 * @returns {Object} Returns the new `lodash` wrapper instance.
8895 * { 'user': 'barney', 'age': 36 },
8896 * { 'user': 'fred', 'age': 40 },
8897 * { 'user': 'pebbles', 'age': 1 }
8903 * .map(function(o) {
8904 * return o.user + ' is ' + o.age;
8908 * // => 'pebbles is 1'
8910 function chain(value) {
8911 var result = lodash(value);
8912 result.__chain__ = true;
8917 * This method invokes `interceptor` and returns `value`. The interceptor
8918 * is invoked with one argument; (value). The purpose of this method is to
8919 * "tap into" a method chain sequence in order to modify intermediate results.
8925 * @param {*} value The value to provide to `interceptor`.
8926 * @param {Function} interceptor The function to invoke.
8927 * @returns {*} Returns `value`.
8931 * .tap(function(array) {
8932 * // Mutate input array.
8939 function tap(value, interceptor) {
8945 * This method is like `_.tap` except that it returns the result of `interceptor`.
8946 * The purpose of this method is to "pass thru" values replacing intermediate
8947 * results in a method chain sequence.
8953 * @param {*} value The value to provide to `interceptor`.
8954 * @param {Function} interceptor The function to invoke.
8955 * @returns {*} Returns the result of `interceptor`.
8961 * .thru(function(value) {
8967 function thru(value, interceptor) {
8968 return interceptor(value);
8972 * This method is the wrapper version of `_.at`.
8978 * @param {...(string|string[])} [paths] The property paths to pick.
8979 * @returns {Object} Returns the new `lodash` wrapper instance.
8982 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
8984 * _(object).at(['a[0].b.c', 'a[1]']).value();
8987 var wrapperAt = flatRest(function(paths) {
8988 var length = paths.length,
8989 start = length ? paths[0] : 0,
8990 value = this.__wrapped__,
8991 interceptor = function(object) {
8992 return baseAt(object, paths);
8995 if (length > 1 || this.__actions__.length ||
8996 !(value instanceof LazyWrapper) || !isIndex(start)) {
8997 return this.thru(interceptor);
8999 value = value.slice(start, +start + (length ? 1 : 0));
9000 value.__actions__.push({
9002 'args': [interceptor],
9003 'thisArg': undefined
9005 return new LodashWrapper(value, this.__chain__).thru(function(array) {
9006 if (length && !array.length) {
9007 array.push(undefined);
9014 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
9020 * @returns {Object} Returns the new `lodash` wrapper instance.
9024 * { 'user': 'barney', 'age': 36 },
9025 * { 'user': 'fred', 'age': 40 }
9028 * // A sequence without explicit chaining.
9030 * // => { 'user': 'barney', 'age': 36 }
9032 * // A sequence with explicit chaining.
9038 * // => { 'user': 'barney' }
9040 function wrapperChain() {
9045 * Executes the chain sequence and returns the wrapped result.
9051 * @returns {Object} Returns the new `lodash` wrapper instance.
9054 * var array = [1, 2];
9055 * var wrapped = _(array).push(3);
9057 * console.log(array);
9060 * wrapped = wrapped.commit();
9061 * console.log(array);
9067 * console.log(array);
9070 function wrapperCommit() {
9071 return new LodashWrapper(this.value(), this.__chain__);
9075 * Gets the next value on a wrapped object following the
9076 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
9082 * @returns {Object} Returns the next iterator value.
9085 * var wrapped = _([1, 2]);
9088 * // => { 'done': false, 'value': 1 }
9091 * // => { 'done': false, 'value': 2 }
9094 * // => { 'done': true, 'value': undefined }
9096 function wrapperNext() {
9097 if (this.__values__ === undefined) {
9098 this.__values__ = toArray(this.value());
9100 var done = this.__index__ >= this.__values__.length,
9101 value = done ? undefined : this.__values__[this.__index__++];
9110 * Enables the wrapper to be iterable.
9112 * @name Symbol.iterator
9116 * @returns {Object} Returns the wrapper object.
9119 * var wrapped = _([1, 2]);
9121 * wrapped[Symbol.iterator]() === wrapped;
9124 * Array.from(wrapped);
9127 function wrapperToIterator() {
9132 * Creates a clone of the chain sequence planting `value` as the wrapped value.
9138 * @param {*} value The value to plant.
9139 * @returns {Object} Returns the new `lodash` wrapper instance.
9142 * function square(n) {
9146 * var wrapped = _([1, 2]).map(square);
9147 * var other = wrapped.plant([3, 4]);
9155 function wrapperPlant(value) {
9159 while (parent instanceof baseLodash) {
9160 var clone = wrapperClone(parent);
9161 clone.__index__ = 0;
9162 clone.__values__ = undefined;
9164 previous.__wrapped__ = clone;
9168 var previous = clone;
9169 parent = parent.__wrapped__;
9171 previous.__wrapped__ = value;
9176 * This method is the wrapper version of `_.reverse`.
9178 * **Note:** This method mutates the wrapped array.
9184 * @returns {Object} Returns the new `lodash` wrapper instance.
9187 * var array = [1, 2, 3];
9189 * _(array).reverse().value()
9192 * console.log(array);
9195 function wrapperReverse() {
9196 var value = this.__wrapped__;
9197 if (value instanceof LazyWrapper) {
9198 var wrapped = value;
9199 if (this.__actions__.length) {
9200 wrapped = new LazyWrapper(this);
9202 wrapped = wrapped.reverse();
9203 wrapped.__actions__.push({
9206 'thisArg': undefined
9208 return new LodashWrapper(wrapped, this.__chain__);
9210 return this.thru(reverse);
9214 * Executes the chain sequence to resolve the unwrapped value.
9219 * @alias toJSON, valueOf
9221 * @returns {*} Returns the resolved unwrapped value.
9224 * _([1, 2, 3]).value();
9227 function wrapperValue() {
9228 return baseWrapperValue(this.__wrapped__, this.__actions__);
9231 /*------------------------------------------------------------------------*/
9234 * Creates an object composed of keys generated from the results of running
9235 * each element of `collection` thru `iteratee`. The corresponding value of
9236 * each key is the number of times the key was returned by `iteratee`. The
9237 * iteratee is invoked with one argument: (value).
9242 * @category Collection
9243 * @param {Array|Object} collection The collection to iterate over.
9244 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9245 * @returns {Object} Returns the composed aggregate object.
9248 * _.countBy([6.1, 4.2, 6.3], Math.floor);
9249 * // => { '4': 1, '6': 2 }
9251 * // The `_.property` iteratee shorthand.
9252 * _.countBy(['one', 'two', 'three'], 'length');
9253 * // => { '3': 2, '5': 1 }
9255 var countBy = createAggregator(function(result, value, key) {
9256 if (hasOwnProperty.call(result, key)) {
9259 baseAssignValue(result, key, 1);
9264 * Checks if `predicate` returns truthy for **all** elements of `collection`.
9265 * Iteration is stopped once `predicate` returns falsey. The predicate is
9266 * invoked with three arguments: (value, index|key, collection).
9268 * **Note:** This method returns `true` for
9269 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
9270 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
9271 * elements of empty collections.
9276 * @category Collection
9277 * @param {Array|Object} collection The collection to iterate over.
9278 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9279 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9280 * @returns {boolean} Returns `true` if all elements pass the predicate check,
9284 * _.every([true, 1, null, 'yes'], Boolean);
9288 * { 'user': 'barney', 'age': 36, 'active': false },
9289 * { 'user': 'fred', 'age': 40, 'active': false }
9292 * // The `_.matches` iteratee shorthand.
9293 * _.every(users, { 'user': 'barney', 'active': false });
9296 * // The `_.matchesProperty` iteratee shorthand.
9297 * _.every(users, ['active', false]);
9300 * // The `_.property` iteratee shorthand.
9301 * _.every(users, 'active');
9304 function every(collection, predicate, guard) {
9305 var func = isArray(collection) ? arrayEvery : baseEvery;
9306 if (guard && isIterateeCall(collection, predicate, guard)) {
9307 predicate = undefined;
9309 return func(collection, getIteratee(predicate, 3));
9313 * Iterates over elements of `collection`, returning an array of all elements
9314 * `predicate` returns truthy for. The predicate is invoked with three
9315 * arguments: (value, index|key, collection).
9317 * **Note:** Unlike `_.remove`, this method returns a new array.
9322 * @category Collection
9323 * @param {Array|Object} collection The collection to iterate over.
9324 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9325 * @returns {Array} Returns the new filtered array.
9330 * { 'user': 'barney', 'age': 36, 'active': true },
9331 * { 'user': 'fred', 'age': 40, 'active': false }
9334 * _.filter(users, function(o) { return !o.active; });
9335 * // => objects for ['fred']
9337 * // The `_.matches` iteratee shorthand.
9338 * _.filter(users, { 'age': 36, 'active': true });
9339 * // => objects for ['barney']
9341 * // The `_.matchesProperty` iteratee shorthand.
9342 * _.filter(users, ['active', false]);
9343 * // => objects for ['fred']
9345 * // The `_.property` iteratee shorthand.
9346 * _.filter(users, 'active');
9347 * // => objects for ['barney']
9349 * // Combining several predicates using `_.overEvery` or `_.overSome`.
9350 * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
9351 * // => objects for ['fred', 'barney']
9353 function filter(collection, predicate) {
9354 var func = isArray(collection) ? arrayFilter : baseFilter;
9355 return func(collection, getIteratee(predicate, 3));
9359 * Iterates over elements of `collection`, returning the first element
9360 * `predicate` returns truthy for. The predicate is invoked with three
9361 * arguments: (value, index|key, collection).
9366 * @category Collection
9367 * @param {Array|Object} collection The collection to inspect.
9368 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9369 * @param {number} [fromIndex=0] The index to search from.
9370 * @returns {*} Returns the matched element, else `undefined`.
9374 * { 'user': 'barney', 'age': 36, 'active': true },
9375 * { 'user': 'fred', 'age': 40, 'active': false },
9376 * { 'user': 'pebbles', 'age': 1, 'active': true }
9379 * _.find(users, function(o) { return o.age < 40; });
9380 * // => object for 'barney'
9382 * // The `_.matches` iteratee shorthand.
9383 * _.find(users, { 'age': 1, 'active': true });
9384 * // => object for 'pebbles'
9386 * // The `_.matchesProperty` iteratee shorthand.
9387 * _.find(users, ['active', false]);
9388 * // => object for 'fred'
9390 * // The `_.property` iteratee shorthand.
9391 * _.find(users, 'active');
9392 * // => object for 'barney'
9394 var find = createFind(findIndex);
9397 * This method is like `_.find` except that it iterates over elements of
9398 * `collection` from right to left.
9403 * @category Collection
9404 * @param {Array|Object} collection The collection to inspect.
9405 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9406 * @param {number} [fromIndex=collection.length-1] The index to search from.
9407 * @returns {*} Returns the matched element, else `undefined`.
9410 * _.findLast([1, 2, 3, 4], function(n) {
9411 * return n % 2 == 1;
9415 var findLast = createFind(findLastIndex);
9418 * Creates a flattened array of values by running each element in `collection`
9419 * thru `iteratee` and flattening the mapped results. The iteratee is invoked
9420 * with three arguments: (value, index|key, collection).
9425 * @category Collection
9426 * @param {Array|Object} collection The collection to iterate over.
9427 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9428 * @returns {Array} Returns the new flattened array.
9431 * function duplicate(n) {
9435 * _.flatMap([1, 2], duplicate);
9436 * // => [1, 1, 2, 2]
9438 function flatMap(collection, iteratee) {
9439 return baseFlatten(map(collection, iteratee), 1);
9443 * This method is like `_.flatMap` except that it recursively flattens the
9449 * @category Collection
9450 * @param {Array|Object} collection The collection to iterate over.
9451 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9452 * @returns {Array} Returns the new flattened array.
9455 * function duplicate(n) {
9456 * return [[[n, n]]];
9459 * _.flatMapDeep([1, 2], duplicate);
9460 * // => [1, 1, 2, 2]
9462 function flatMapDeep(collection, iteratee) {
9463 return baseFlatten(map(collection, iteratee), INFINITY);
9467 * This method is like `_.flatMap` except that it recursively flattens the
9468 * mapped results up to `depth` times.
9473 * @category Collection
9474 * @param {Array|Object} collection The collection to iterate over.
9475 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9476 * @param {number} [depth=1] The maximum recursion depth.
9477 * @returns {Array} Returns the new flattened array.
9480 * function duplicate(n) {
9481 * return [[[n, n]]];
9484 * _.flatMapDepth([1, 2], duplicate, 2);
9485 * // => [[1, 1], [2, 2]]
9487 function flatMapDepth(collection, iteratee, depth) {
9488 depth = depth === undefined ? 1 : toInteger(depth);
9489 return baseFlatten(map(collection, iteratee), depth);
9493 * Iterates over elements of `collection` and invokes `iteratee` for each element.
9494 * The iteratee is invoked with three arguments: (value, index|key, collection).
9495 * Iteratee functions may exit iteration early by explicitly returning `false`.
9497 * **Note:** As with other "Collections" methods, objects with a "length"
9498 * property are iterated like arrays. To avoid this behavior use `_.forIn`
9499 * or `_.forOwn` for object iteration.
9505 * @category Collection
9506 * @param {Array|Object} collection The collection to iterate over.
9507 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9508 * @returns {Array|Object} Returns `collection`.
9509 * @see _.forEachRight
9512 * _.forEach([1, 2], function(value) {
9513 * console.log(value);
9515 * // => Logs `1` then `2`.
9517 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
9520 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
9522 function forEach(collection, iteratee) {
9523 var func = isArray(collection) ? arrayEach : baseEach;
9524 return func(collection, getIteratee(iteratee, 3));
9528 * This method is like `_.forEach` except that it iterates over elements of
9529 * `collection` from right to left.
9535 * @category Collection
9536 * @param {Array|Object} collection The collection to iterate over.
9537 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9538 * @returns {Array|Object} Returns `collection`.
9542 * _.forEachRight([1, 2], function(value) {
9543 * console.log(value);
9545 * // => Logs `2` then `1`.
9547 function forEachRight(collection, iteratee) {
9548 var func = isArray(collection) ? arrayEachRight : baseEachRight;
9549 return func(collection, getIteratee(iteratee, 3));
9553 * Creates an object composed of keys generated from the results of running
9554 * each element of `collection` thru `iteratee`. The order of grouped values
9555 * is determined by the order they occur in `collection`. The corresponding
9556 * value of each key is an array of elements responsible for generating the
9557 * key. The iteratee is invoked with one argument: (value).
9562 * @category Collection
9563 * @param {Array|Object} collection The collection to iterate over.
9564 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9565 * @returns {Object} Returns the composed aggregate object.
9568 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
9569 * // => { '4': [4.2], '6': [6.1, 6.3] }
9571 * // The `_.property` iteratee shorthand.
9572 * _.groupBy(['one', 'two', 'three'], 'length');
9573 * // => { '3': ['one', 'two'], '5': ['three'] }
9575 var groupBy = createAggregator(function(result, value, key) {
9576 if (hasOwnProperty.call(result, key)) {
9577 result[key].push(value);
9579 baseAssignValue(result, key, [value]);
9584 * Checks if `value` is in `collection`. If `collection` is a string, it's
9585 * checked for a substring of `value`, otherwise
9586 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
9587 * is used for equality comparisons. If `fromIndex` is negative, it's used as
9588 * the offset from the end of `collection`.
9593 * @category Collection
9594 * @param {Array|Object|string} collection The collection to inspect.
9595 * @param {*} value The value to search for.
9596 * @param {number} [fromIndex=0] The index to search from.
9597 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9598 * @returns {boolean} Returns `true` if `value` is found, else `false`.
9601 * _.includes([1, 2, 3], 1);
9604 * _.includes([1, 2, 3], 1, 2);
9607 * _.includes({ 'a': 1, 'b': 2 }, 1);
9610 * _.includes('abcd', 'bc');
9613 function includes(collection, value, fromIndex, guard) {
9614 collection = isArrayLike(collection) ? collection : values(collection);
9615 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
9617 var length = collection.length;
9618 if (fromIndex < 0) {
9619 fromIndex = nativeMax(length + fromIndex, 0);
9621 return isString(collection) ?
9622 (fromIndex <= length && collection.indexOf(value, fromIndex) > -1) :
9623 (!!length && baseIndexOf(collection, value, fromIndex) > -1);
9627 * Invokes the method at `path` of each element in `collection`, returning
9628 * an array of the results of each invoked method. Any additional arguments
9629 * are provided to each invoked method. If `path` is a function, it's invoked
9630 * for, and `this` bound to, each element in `collection`.
9635 * @category Collection
9636 * @param {Array|Object} collection The collection to iterate over.
9637 * @param {Array|Function|string} path The path of the method to invoke or
9638 * the function invoked per iteration.
9639 * @param {...*} [args] The arguments to invoke each method with.
9640 * @returns {Array} Returns the array of results.
9643 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
9644 * // => [[1, 5, 7], [1, 2, 3]]
9646 * _.invokeMap([123, 456], String.prototype.split, '');
9647 * // => [['1', '2', '3'], ['4', '5', '6']]
9649 var invokeMap = baseRest(function(collection, path, args) {
9651 isFunc = typeof path == 'function',
9652 result = isArrayLike(collection) ? Array(collection.length) : [];
9654 baseEach(collection, function(value) {
9655 result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
9661 * Creates an object composed of keys generated from the results of running
9662 * each element of `collection` thru `iteratee`. The corresponding value of
9663 * each key is the last element responsible for generating the key. The
9664 * iteratee is invoked with one argument: (value).
9669 * @category Collection
9670 * @param {Array|Object} collection The collection to iterate over.
9671 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9672 * @returns {Object} Returns the composed aggregate object.
9676 * { 'dir': 'left', 'code': 97 },
9677 * { 'dir': 'right', 'code': 100 }
9680 * _.keyBy(array, function(o) {
9681 * return String.fromCharCode(o.code);
9683 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
9685 * _.keyBy(array, 'dir');
9686 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
9688 var keyBy = createAggregator(function(result, value, key) {
9689 baseAssignValue(result, key, value);
9693 * Creates an array of values by running each element in `collection` thru
9694 * `iteratee`. The iteratee is invoked with three arguments:
9695 * (value, index|key, collection).
9697 * Many lodash methods are guarded to work as iteratees for methods like
9698 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
9700 * The guarded methods are:
9701 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
9702 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
9703 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
9704 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
9709 * @category Collection
9710 * @param {Array|Object} collection The collection to iterate over.
9711 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9712 * @returns {Array} Returns the new mapped array.
9715 * function square(n) {
9719 * _.map([4, 8], square);
9722 * _.map({ 'a': 4, 'b': 8 }, square);
9723 * // => [16, 64] (iteration order is not guaranteed)
9726 * { 'user': 'barney' },
9727 * { 'user': 'fred' }
9730 * // The `_.property` iteratee shorthand.
9731 * _.map(users, 'user');
9732 * // => ['barney', 'fred']
9734 function map(collection, iteratee) {
9735 var func = isArray(collection) ? arrayMap : baseMap;
9736 return func(collection, getIteratee(iteratee, 3));
9740 * This method is like `_.sortBy` except that it allows specifying the sort
9741 * orders of the iteratees to sort by. If `orders` is unspecified, all values
9742 * are sorted in ascending order. Otherwise, specify an order of "desc" for
9743 * descending or "asc" for ascending sort order of corresponding values.
9748 * @category Collection
9749 * @param {Array|Object} collection The collection to iterate over.
9750 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
9751 * The iteratees to sort by.
9752 * @param {string[]} [orders] The sort orders of `iteratees`.
9753 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9754 * @returns {Array} Returns the new sorted array.
9758 * { 'user': 'fred', 'age': 48 },
9759 * { 'user': 'barney', 'age': 34 },
9760 * { 'user': 'fred', 'age': 40 },
9761 * { 'user': 'barney', 'age': 36 }
9764 * // Sort by `user` in ascending order and by `age` in descending order.
9765 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
9766 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9768 function orderBy(collection, iteratees, orders, guard) {
9769 if (collection == null) {
9772 if (!isArray(iteratees)) {
9773 iteratees = iteratees == null ? [] : [iteratees];
9775 orders = guard ? undefined : orders;
9776 if (!isArray(orders)) {
9777 orders = orders == null ? [] : [orders];
9779 return baseOrderBy(collection, iteratees, orders);
9783 * Creates an array of elements split into two groups, the first of which
9784 * contains elements `predicate` returns truthy for, the second of which
9785 * contains elements `predicate` returns falsey for. The predicate is
9786 * invoked with one argument: (value).
9791 * @category Collection
9792 * @param {Array|Object} collection The collection to iterate over.
9793 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9794 * @returns {Array} Returns the array of grouped elements.
9798 * { 'user': 'barney', 'age': 36, 'active': false },
9799 * { 'user': 'fred', 'age': 40, 'active': true },
9800 * { 'user': 'pebbles', 'age': 1, 'active': false }
9803 * _.partition(users, function(o) { return o.active; });
9804 * // => objects for [['fred'], ['barney', 'pebbles']]
9806 * // The `_.matches` iteratee shorthand.
9807 * _.partition(users, { 'age': 1, 'active': false });
9808 * // => objects for [['pebbles'], ['barney', 'fred']]
9810 * // The `_.matchesProperty` iteratee shorthand.
9811 * _.partition(users, ['active', false]);
9812 * // => objects for [['barney', 'pebbles'], ['fred']]
9814 * // The `_.property` iteratee shorthand.
9815 * _.partition(users, 'active');
9816 * // => objects for [['fred'], ['barney', 'pebbles']]
9818 var partition = createAggregator(function(result, value, key) {
9819 result[key ? 0 : 1].push(value);
9828 * Reduces `collection` to a value which is the accumulated result of running
9829 * each element in `collection` thru `iteratee`, where each successive
9830 * invocation is supplied the return value of the previous. If `accumulator`
9831 * is not given, the first element of `collection` is used as the initial
9832 * value. The iteratee is invoked with four arguments:
9833 * (accumulator, value, index|key, collection).
9835 * Many lodash methods are guarded to work as iteratees for methods like
9836 * `_.reduce`, `_.reduceRight`, and `_.transform`.
9838 * The guarded methods are:
9839 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
9845 * @category Collection
9846 * @param {Array|Object} collection The collection to iterate over.
9847 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9848 * @param {*} [accumulator] The initial value.
9849 * @returns {*} Returns the accumulated value.
9850 * @see _.reduceRight
9853 * _.reduce([1, 2], function(sum, n) {
9858 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
9859 * (result[value] || (result[value] = [])).push(key);
9862 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
9864 function reduce(collection, iteratee, accumulator) {
9865 var func = isArray(collection) ? arrayReduce : baseReduce,
9866 initAccum = arguments.length < 3;
9868 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
9872 * This method is like `_.reduce` except that it iterates over elements of
9873 * `collection` from right to left.
9878 * @category Collection
9879 * @param {Array|Object} collection The collection to iterate over.
9880 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9881 * @param {*} [accumulator] The initial value.
9882 * @returns {*} Returns the accumulated value.
9886 * var array = [[0, 1], [2, 3], [4, 5]];
9888 * _.reduceRight(array, function(flattened, other) {
9889 * return flattened.concat(other);
9891 * // => [4, 5, 2, 3, 0, 1]
9893 function reduceRight(collection, iteratee, accumulator) {
9894 var func = isArray(collection) ? arrayReduceRight : baseReduce,
9895 initAccum = arguments.length < 3;
9897 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
9901 * The opposite of `_.filter`; this method returns the elements of `collection`
9902 * that `predicate` does **not** return truthy for.
9907 * @category Collection
9908 * @param {Array|Object} collection The collection to iterate over.
9909 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9910 * @returns {Array} Returns the new filtered array.
9915 * { 'user': 'barney', 'age': 36, 'active': false },
9916 * { 'user': 'fred', 'age': 40, 'active': true }
9919 * _.reject(users, function(o) { return !o.active; });
9920 * // => objects for ['fred']
9922 * // The `_.matches` iteratee shorthand.
9923 * _.reject(users, { 'age': 40, 'active': true });
9924 * // => objects for ['barney']
9926 * // The `_.matchesProperty` iteratee shorthand.
9927 * _.reject(users, ['active', false]);
9928 * // => objects for ['fred']
9930 * // The `_.property` iteratee shorthand.
9931 * _.reject(users, 'active');
9932 * // => objects for ['barney']
9934 function reject(collection, predicate) {
9935 var func = isArray(collection) ? arrayFilter : baseFilter;
9936 return func(collection, negate(getIteratee(predicate, 3)));
9940 * Gets a random element from `collection`.
9945 * @category Collection
9946 * @param {Array|Object} collection The collection to sample.
9947 * @returns {*} Returns the random element.
9950 * _.sample([1, 2, 3, 4]);
9953 function sample(collection) {
9954 var func = isArray(collection) ? arraySample : baseSample;
9955 return func(collection);
9959 * Gets `n` random elements at unique keys from `collection` up to the
9960 * size of `collection`.
9965 * @category Collection
9966 * @param {Array|Object} collection The collection to sample.
9967 * @param {number} [n=1] The number of elements to sample.
9968 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9969 * @returns {Array} Returns the random elements.
9972 * _.sampleSize([1, 2, 3], 2);
9975 * _.sampleSize([1, 2, 3], 4);
9978 function sampleSize(collection, n, guard) {
9979 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
9984 var func = isArray(collection) ? arraySampleSize : baseSampleSize;
9985 return func(collection, n);
9989 * Creates an array of shuffled values, using a version of the
9990 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
9995 * @category Collection
9996 * @param {Array|Object} collection The collection to shuffle.
9997 * @returns {Array} Returns the new shuffled array.
10000 * _.shuffle([1, 2, 3, 4]);
10001 * // => [4, 1, 3, 2]
10003 function shuffle(collection) {
10004 var func = isArray(collection) ? arrayShuffle : baseShuffle;
10005 return func(collection);
10009 * Gets the size of `collection` by returning its length for array-like
10010 * values or the number of own enumerable string keyed properties for objects.
10015 * @category Collection
10016 * @param {Array|Object|string} collection The collection to inspect.
10017 * @returns {number} Returns the collection size.
10020 * _.size([1, 2, 3]);
10023 * _.size({ 'a': 1, 'b': 2 });
10026 * _.size('pebbles');
10029 function size(collection) {
10030 if (collection == null) {
10033 if (isArrayLike(collection)) {
10034 return isString(collection) ? stringSize(collection) : collection.length;
10036 var tag = getTag(collection);
10037 if (tag == mapTag || tag == setTag) {
10038 return collection.size;
10040 return baseKeys(collection).length;
10044 * Checks if `predicate` returns truthy for **any** element of `collection`.
10045 * Iteration is stopped once `predicate` returns truthy. The predicate is
10046 * invoked with three arguments: (value, index|key, collection).
10051 * @category Collection
10052 * @param {Array|Object} collection The collection to iterate over.
10053 * @param {Function} [predicate=_.identity] The function invoked per iteration.
10054 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10055 * @returns {boolean} Returns `true` if any element passes the predicate check,
10059 * _.some([null, 0, 'yes', false], Boolean);
10063 * { 'user': 'barney', 'active': true },
10064 * { 'user': 'fred', 'active': false }
10067 * // The `_.matches` iteratee shorthand.
10068 * _.some(users, { 'user': 'barney', 'active': false });
10071 * // The `_.matchesProperty` iteratee shorthand.
10072 * _.some(users, ['active', false]);
10075 * // The `_.property` iteratee shorthand.
10076 * _.some(users, 'active');
10079 function some(collection, predicate, guard) {
10080 var func = isArray(collection) ? arraySome : baseSome;
10081 if (guard && isIterateeCall(collection, predicate, guard)) {
10082 predicate = undefined;
10084 return func(collection, getIteratee(predicate, 3));
10088 * Creates an array of elements, sorted in ascending order by the results of
10089 * running each element in a collection thru each iteratee. This method
10090 * performs a stable sort, that is, it preserves the original sort order of
10091 * equal elements. The iteratees are invoked with one argument: (value).
10096 * @category Collection
10097 * @param {Array|Object} collection The collection to iterate over.
10098 * @param {...(Function|Function[])} [iteratees=[_.identity]]
10099 * The iteratees to sort by.
10100 * @returns {Array} Returns the new sorted array.
10104 * { 'user': 'fred', 'age': 48 },
10105 * { 'user': 'barney', 'age': 36 },
10106 * { 'user': 'fred', 'age': 30 },
10107 * { 'user': 'barney', 'age': 34 }
10110 * _.sortBy(users, [function(o) { return o.user; }]);
10111 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
10113 * _.sortBy(users, ['user', 'age']);
10114 * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
10116 var sortBy = baseRest(function(collection, iteratees) {
10117 if (collection == null) {
10120 var length = iteratees.length;
10121 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
10123 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
10124 iteratees = [iteratees[0]];
10126 return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
10129 /*------------------------------------------------------------------------*/
10132 * Gets the timestamp of the number of milliseconds that have elapsed since
10133 * the Unix epoch (1 January 1970 00:00:00 UTC).
10139 * @returns {number} Returns the timestamp.
10142 * _.defer(function(stamp) {
10143 * console.log(_.now() - stamp);
10145 * // => Logs the number of milliseconds it took for the deferred invocation.
10147 var now = ctxNow || function() {
10148 return root.Date.now();
10151 /*------------------------------------------------------------------------*/
10154 * The opposite of `_.before`; this method creates a function that invokes
10155 * `func` once it's called `n` or more times.
10160 * @category Function
10161 * @param {number} n The number of calls before `func` is invoked.
10162 * @param {Function} func The function to restrict.
10163 * @returns {Function} Returns the new restricted function.
10166 * var saves = ['profile', 'settings'];
10168 * var done = _.after(saves.length, function() {
10169 * console.log('done saving!');
10172 * _.forEach(saves, function(type) {
10173 * asyncSave({ 'type': type, 'complete': done });
10175 * // => Logs 'done saving!' after the two async saves have completed.
10177 function after(n, func) {
10178 if (typeof func != 'function') {
10179 throw new TypeError(FUNC_ERROR_TEXT);
10182 return function() {
10184 return func.apply(this, arguments);
10190 * Creates a function that invokes `func`, with up to `n` arguments,
10191 * ignoring any additional arguments.
10196 * @category Function
10197 * @param {Function} func The function to cap arguments for.
10198 * @param {number} [n=func.length] The arity cap.
10199 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10200 * @returns {Function} Returns the new capped function.
10203 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
10206 function ary(func, n, guard) {
10207 n = guard ? undefined : n;
10208 n = (func && n == null) ? func.length : n;
10209 return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
10213 * Creates a function that invokes `func`, with the `this` binding and arguments
10214 * of the created function, while it's called less than `n` times. Subsequent
10215 * calls to the created function return the result of the last `func` invocation.
10220 * @category Function
10221 * @param {number} n The number of calls at which `func` is no longer invoked.
10222 * @param {Function} func The function to restrict.
10223 * @returns {Function} Returns the new restricted function.
10226 * jQuery(element).on('click', _.before(5, addContactToList));
10227 * // => Allows adding up to 4 contacts to the list.
10229 function before(n, func) {
10231 if (typeof func != 'function') {
10232 throw new TypeError(FUNC_ERROR_TEXT);
10235 return function() {
10237 result = func.apply(this, arguments);
10247 * Creates a function that invokes `func` with the `this` binding of `thisArg`
10248 * and `partials` prepended to the arguments it receives.
10250 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
10251 * may be used as a placeholder for partially applied arguments.
10253 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
10254 * property of bound functions.
10259 * @category Function
10260 * @param {Function} func The function to bind.
10261 * @param {*} thisArg The `this` binding of `func`.
10262 * @param {...*} [partials] The arguments to be partially applied.
10263 * @returns {Function} Returns the new bound function.
10266 * function greet(greeting, punctuation) {
10267 * return greeting + ' ' + this.user + punctuation;
10270 * var object = { 'user': 'fred' };
10272 * var bound = _.bind(greet, object, 'hi');
10276 * // Bound with placeholders.
10277 * var bound = _.bind(greet, object, _, '!');
10281 var bind = baseRest(function(func, thisArg, partials) {
10282 var bitmask = WRAP_BIND_FLAG;
10283 if (partials.length) {
10284 var holders = replaceHolders(partials, getHolder(bind));
10285 bitmask |= WRAP_PARTIAL_FLAG;
10287 return createWrap(func, bitmask, thisArg, partials, holders);
10291 * Creates a function that invokes the method at `object[key]` with `partials`
10292 * prepended to the arguments it receives.
10294 * This method differs from `_.bind` by allowing bound functions to reference
10295 * methods that may be redefined or don't yet exist. See
10296 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
10297 * for more details.
10299 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
10300 * builds, may be used as a placeholder for partially applied arguments.
10305 * @category Function
10306 * @param {Object} object The object to invoke the method on.
10307 * @param {string} key The key of the method.
10308 * @param {...*} [partials] The arguments to be partially applied.
10309 * @returns {Function} Returns the new bound function.
10314 * 'greet': function(greeting, punctuation) {
10315 * return greeting + ' ' + this.user + punctuation;
10319 * var bound = _.bindKey(object, 'greet', 'hi');
10323 * object.greet = function(greeting, punctuation) {
10324 * return greeting + 'ya ' + this.user + punctuation;
10328 * // => 'hiya fred!'
10330 * // Bound with placeholders.
10331 * var bound = _.bindKey(object, 'greet', _, '!');
10333 * // => 'hiya fred!'
10335 var bindKey = baseRest(function(object, key, partials) {
10336 var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
10337 if (partials.length) {
10338 var holders = replaceHolders(partials, getHolder(bindKey));
10339 bitmask |= WRAP_PARTIAL_FLAG;
10341 return createWrap(key, bitmask, object, partials, holders);
10345 * Creates a function that accepts arguments of `func` and either invokes
10346 * `func` returning its result, if at least `arity` number of arguments have
10347 * been provided, or returns a function that accepts the remaining `func`
10348 * arguments, and so on. The arity of `func` may be specified if `func.length`
10349 * is not sufficient.
10351 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
10352 * may be used as a placeholder for provided arguments.
10354 * **Note:** This method doesn't set the "length" property of curried functions.
10359 * @category Function
10360 * @param {Function} func The function to curry.
10361 * @param {number} [arity=func.length] The arity of `func`.
10362 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10363 * @returns {Function} Returns the new curried function.
10366 * var abc = function(a, b, c) {
10367 * return [a, b, c];
10370 * var curried = _.curry(abc);
10372 * curried(1)(2)(3);
10375 * curried(1, 2)(3);
10378 * curried(1, 2, 3);
10381 * // Curried with placeholders.
10382 * curried(1)(_, 3)(2);
10385 function curry(func, arity, guard) {
10386 arity = guard ? undefined : arity;
10387 var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10388 result.placeholder = curry.placeholder;
10393 * This method is like `_.curry` except that arguments are applied to `func`
10394 * in the manner of `_.partialRight` instead of `_.partial`.
10396 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
10397 * builds, may be used as a placeholder for provided arguments.
10399 * **Note:** This method doesn't set the "length" property of curried functions.
10404 * @category Function
10405 * @param {Function} func The function to curry.
10406 * @param {number} [arity=func.length] The arity of `func`.
10407 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10408 * @returns {Function} Returns the new curried function.
10411 * var abc = function(a, b, c) {
10412 * return [a, b, c];
10415 * var curried = _.curryRight(abc);
10417 * curried(3)(2)(1);
10420 * curried(2, 3)(1);
10423 * curried(1, 2, 3);
10426 * // Curried with placeholders.
10427 * curried(3)(1, _)(2);
10430 function curryRight(func, arity, guard) {
10431 arity = guard ? undefined : arity;
10432 var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10433 result.placeholder = curryRight.placeholder;
10438 * Creates a debounced function that delays invoking `func` until after `wait`
10439 * milliseconds have elapsed since the last time the debounced function was
10440 * invoked. The debounced function comes with a `cancel` method to cancel
10441 * delayed `func` invocations and a `flush` method to immediately invoke them.
10442 * Provide `options` to indicate whether `func` should be invoked on the
10443 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
10444 * with the last arguments provided to the debounced function. Subsequent
10445 * calls to the debounced function return the result of the last `func`
10448 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10449 * invoked on the trailing edge of the timeout only if the debounced function
10450 * is invoked more than once during the `wait` timeout.
10452 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10453 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10455 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10456 * for details over the differences between `_.debounce` and `_.throttle`.
10461 * @category Function
10462 * @param {Function} func The function to debounce.
10463 * @param {number} [wait=0] The number of milliseconds to delay.
10464 * @param {Object} [options={}] The options object.
10465 * @param {boolean} [options.leading=false]
10466 * Specify invoking on the leading edge of the timeout.
10467 * @param {number} [options.maxWait]
10468 * The maximum time `func` is allowed to be delayed before it's invoked.
10469 * @param {boolean} [options.trailing=true]
10470 * Specify invoking on the trailing edge of the timeout.
10471 * @returns {Function} Returns the new debounced function.
10474 * // Avoid costly calculations while the window size is in flux.
10475 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
10477 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
10478 * jQuery(element).on('click', _.debounce(sendMail, 300, {
10480 * 'trailing': false
10483 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
10484 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
10485 * var source = new EventSource('/stream');
10486 * jQuery(source).on('message', debounced);
10488 * // Cancel the trailing debounced invocation.
10489 * jQuery(window).on('popstate', debounced.cancel);
10491 function debounce(func, wait, options) {
10498 lastInvokeTime = 0,
10503 if (typeof func != 'function') {
10504 throw new TypeError(FUNC_ERROR_TEXT);
10506 wait = toNumber(wait) || 0;
10507 if (isObject(options)) {
10508 leading = !!options.leading;
10509 maxing = 'maxWait' in options;
10510 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
10511 trailing = 'trailing' in options ? !!options.trailing : trailing;
10514 function invokeFunc(time) {
10515 var args = lastArgs,
10516 thisArg = lastThis;
10518 lastArgs = lastThis = undefined;
10519 lastInvokeTime = time;
10520 result = func.apply(thisArg, args);
10524 function leadingEdge(time) {
10525 // Reset any `maxWait` timer.
10526 lastInvokeTime = time;
10527 // Start the timer for the trailing edge.
10528 timerId = setTimeout(timerExpired, wait);
10529 // Invoke the leading edge.
10530 return leading ? invokeFunc(time) : result;
10533 function remainingWait(time) {
10534 var timeSinceLastCall = time - lastCallTime,
10535 timeSinceLastInvoke = time - lastInvokeTime,
10536 timeWaiting = wait - timeSinceLastCall;
10539 nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) :
10543 function shouldInvoke(time) {
10544 var timeSinceLastCall = time - lastCallTime,
10545 timeSinceLastInvoke = time - lastInvokeTime;
10547 // Either this is the first call, activity has stopped and we're at the
10548 // trailing edge, the system time has gone backwards and we're treating
10549 // it as the trailing edge, or we've hit the `maxWait` limit.
10550 return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
10551 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
10554 function timerExpired() {
10556 if (shouldInvoke(time)) {
10557 return trailingEdge(time);
10559 // Restart the timer.
10560 timerId = setTimeout(timerExpired, remainingWait(time));
10563 function trailingEdge(time) {
10564 timerId = undefined;
10566 // Only invoke if we have `lastArgs` which means `func` has been
10567 // debounced at least once.
10568 if (trailing && lastArgs) {
10569 return invokeFunc(time);
10571 lastArgs = lastThis = undefined;
10575 function cancel() {
10576 if (timerId !== undefined) {
10577 clearTimeout(timerId);
10579 lastInvokeTime = 0;
10580 lastArgs = lastCallTime = lastThis = timerId = undefined;
10584 return timerId === undefined ? result : trailingEdge(now());
10587 function debounced() {
10589 isInvoking = shouldInvoke(time);
10591 lastArgs = arguments;
10593 lastCallTime = time;
10596 if (timerId === undefined) {
10597 return leadingEdge(lastCallTime);
10600 // Handle invocations in a tight loop.
10601 clearTimeout(timerId);
10602 timerId = setTimeout(timerExpired, wait);
10603 return invokeFunc(lastCallTime);
10606 if (timerId === undefined) {
10607 timerId = setTimeout(timerExpired, wait);
10611 debounced.cancel = cancel;
10612 debounced.flush = flush;
10617 * Defers invoking the `func` until the current call stack has cleared. Any
10618 * additional arguments are provided to `func` when it's invoked.
10623 * @category Function
10624 * @param {Function} func The function to defer.
10625 * @param {...*} [args] The arguments to invoke `func` with.
10626 * @returns {number} Returns the timer id.
10629 * _.defer(function(text) {
10630 * console.log(text);
10632 * // => Logs 'deferred' after one millisecond.
10634 var defer = baseRest(function(func, args) {
10635 return baseDelay(func, 1, args);
10639 * Invokes `func` after `wait` milliseconds. Any additional arguments are
10640 * provided to `func` when it's invoked.
10645 * @category Function
10646 * @param {Function} func The function to delay.
10647 * @param {number} wait The number of milliseconds to delay invocation.
10648 * @param {...*} [args] The arguments to invoke `func` with.
10649 * @returns {number} Returns the timer id.
10652 * _.delay(function(text) {
10653 * console.log(text);
10654 * }, 1000, 'later');
10655 * // => Logs 'later' after one second.
10657 var delay = baseRest(function(func, wait, args) {
10658 return baseDelay(func, toNumber(wait) || 0, args);
10662 * Creates a function that invokes `func` with arguments reversed.
10667 * @category Function
10668 * @param {Function} func The function to flip arguments for.
10669 * @returns {Function} Returns the new flipped function.
10672 * var flipped = _.flip(function() {
10673 * return _.toArray(arguments);
10676 * flipped('a', 'b', 'c', 'd');
10677 * // => ['d', 'c', 'b', 'a']
10679 function flip(func) {
10680 return createWrap(func, WRAP_FLIP_FLAG);
10684 * Creates a function that memoizes the result of `func`. If `resolver` is
10685 * provided, it determines the cache key for storing the result based on the
10686 * arguments provided to the memoized function. By default, the first argument
10687 * provided to the memoized function is used as the map cache key. The `func`
10688 * is invoked with the `this` binding of the memoized function.
10690 * **Note:** The cache is exposed as the `cache` property on the memoized
10691 * function. Its creation may be customized by replacing the `_.memoize.Cache`
10692 * constructor with one whose instances implement the
10693 * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
10694 * method interface of `clear`, `delete`, `get`, `has`, and `set`.
10699 * @category Function
10700 * @param {Function} func The function to have its output memoized.
10701 * @param {Function} [resolver] The function to resolve the cache key.
10702 * @returns {Function} Returns the new memoized function.
10705 * var object = { 'a': 1, 'b': 2 };
10706 * var other = { 'c': 3, 'd': 4 };
10708 * var values = _.memoize(_.values);
10719 * // Modify the result cache.
10720 * values.cache.set(object, ['a', 'b']);
10724 * // Replace `_.memoize.Cache`.
10725 * _.memoize.Cache = WeakMap;
10727 function memoize(func, resolver) {
10728 if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
10729 throw new TypeError(FUNC_ERROR_TEXT);
10731 var memoized = function() {
10732 var args = arguments,
10733 key = resolver ? resolver.apply(this, args) : args[0],
10734 cache = memoized.cache;
10736 if (cache.has(key)) {
10737 return cache.get(key);
10739 var result = func.apply(this, args);
10740 memoized.cache = cache.set(key, result) || cache;
10743 memoized.cache = new(memoize.Cache || MapCache);
10747 // Expose `MapCache`.
10748 memoize.Cache = MapCache;
10751 * Creates a function that negates the result of the predicate `func`. The
10752 * `func` predicate is invoked with the `this` binding and arguments of the
10753 * created function.
10758 * @category Function
10759 * @param {Function} predicate The predicate to negate.
10760 * @returns {Function} Returns the new negated function.
10763 * function isEven(n) {
10764 * return n % 2 == 0;
10767 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
10770 function negate(predicate) {
10771 if (typeof predicate != 'function') {
10772 throw new TypeError(FUNC_ERROR_TEXT);
10774 return function() {
10775 var args = arguments;
10776 switch (args.length) {
10778 return !predicate.call(this);
10780 return !predicate.call(this, args[0]);
10782 return !predicate.call(this, args[0], args[1]);
10784 return !predicate.call(this, args[0], args[1], args[2]);
10786 return !predicate.apply(this, args);
10791 * Creates a function that is restricted to invoking `func` once. Repeat calls
10792 * to the function return the value of the first invocation. The `func` is
10793 * invoked with the `this` binding and arguments of the created function.
10798 * @category Function
10799 * @param {Function} func The function to restrict.
10800 * @returns {Function} Returns the new restricted function.
10803 * var initialize = _.once(createApplication);
10806 * // => `createApplication` is invoked once
10808 function once(func) {
10809 return before(2, func);
10813 * Creates a function that invokes `func` with its arguments transformed.
10818 * @category Function
10819 * @param {Function} func The function to wrap.
10820 * @param {...(Function|Function[])} [transforms=[_.identity]]
10821 * The argument transforms.
10822 * @returns {Function} Returns the new function.
10825 * function doubled(n) {
10829 * function square(n) {
10833 * var func = _.overArgs(function(x, y) {
10835 * }, [square, doubled]);
10843 var overArgs = castRest(function(func, transforms) {
10844 transforms = (transforms.length == 1 && isArray(transforms[0])) ?
10845 arrayMap(transforms[0], baseUnary(getIteratee())) :
10846 arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
10848 var funcsLength = transforms.length;
10849 return baseRest(function(args) {
10851 length = nativeMin(args.length, funcsLength);
10853 while (++index < length) {
10854 args[index] = transforms[index].call(this, args[index]);
10856 return apply(func, this, args);
10861 * Creates a function that invokes `func` with `partials` prepended to the
10862 * arguments it receives. This method is like `_.bind` except it does **not**
10863 * alter the `this` binding.
10865 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
10866 * builds, may be used as a placeholder for partially applied arguments.
10868 * **Note:** This method doesn't set the "length" property of partially
10869 * applied functions.
10874 * @category Function
10875 * @param {Function} func The function to partially apply arguments to.
10876 * @param {...*} [partials] The arguments to be partially applied.
10877 * @returns {Function} Returns the new partially applied function.
10880 * function greet(greeting, name) {
10881 * return greeting + ' ' + name;
10884 * var sayHelloTo = _.partial(greet, 'hello');
10885 * sayHelloTo('fred');
10886 * // => 'hello fred'
10888 * // Partially applied with placeholders.
10889 * var greetFred = _.partial(greet, _, 'fred');
10893 var partial = baseRest(function(func, partials) {
10894 var holders = replaceHolders(partials, getHolder(partial));
10895 return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
10899 * This method is like `_.partial` except that partially applied arguments
10900 * are appended to the arguments it receives.
10902 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
10903 * builds, may be used as a placeholder for partially applied arguments.
10905 * **Note:** This method doesn't set the "length" property of partially
10906 * applied functions.
10911 * @category Function
10912 * @param {Function} func The function to partially apply arguments to.
10913 * @param {...*} [partials] The arguments to be partially applied.
10914 * @returns {Function} Returns the new partially applied function.
10917 * function greet(greeting, name) {
10918 * return greeting + ' ' + name;
10921 * var greetFred = _.partialRight(greet, 'fred');
10925 * // Partially applied with placeholders.
10926 * var sayHelloTo = _.partialRight(greet, 'hello', _);
10927 * sayHelloTo('fred');
10928 * // => 'hello fred'
10930 var partialRight = baseRest(function(func, partials) {
10931 var holders = replaceHolders(partials, getHolder(partialRight));
10932 return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
10936 * Creates a function that invokes `func` with arguments arranged according
10937 * to the specified `indexes` where the argument value at the first index is
10938 * provided as the first argument, the argument value at the second index is
10939 * provided as the second argument, and so on.
10944 * @category Function
10945 * @param {Function} func The function to rearrange arguments for.
10946 * @param {...(number|number[])} indexes The arranged argument indexes.
10947 * @returns {Function} Returns the new function.
10950 * var rearged = _.rearg(function(a, b, c) {
10951 * return [a, b, c];
10954 * rearged('b', 'c', 'a')
10955 * // => ['a', 'b', 'c']
10957 var rearg = flatRest(function(func, indexes) {
10958 return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
10962 * Creates a function that invokes `func` with the `this` binding of the
10963 * created function and arguments from `start` and beyond provided as
10966 * **Note:** This method is based on the
10967 * [rest parameter](https://mdn.io/rest_parameters).
10972 * @category Function
10973 * @param {Function} func The function to apply a rest parameter to.
10974 * @param {number} [start=func.length-1] The start position of the rest parameter.
10975 * @returns {Function} Returns the new function.
10978 * var say = _.rest(function(what, names) {
10979 * return what + ' ' + _.initial(names).join(', ') +
10980 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
10983 * say('hello', 'fred', 'barney', 'pebbles');
10984 * // => 'hello fred, barney, & pebbles'
10986 function rest(func, start) {
10987 if (typeof func != 'function') {
10988 throw new TypeError(FUNC_ERROR_TEXT);
10990 start = start === undefined ? start : toInteger(start);
10991 return baseRest(func, start);
10995 * Creates a function that invokes `func` with the `this` binding of the
10996 * create function and an array of arguments much like
10997 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
10999 * **Note:** This method is based on the
11000 * [spread operator](https://mdn.io/spread_operator).
11005 * @category Function
11006 * @param {Function} func The function to spread arguments over.
11007 * @param {number} [start=0] The start position of the spread.
11008 * @returns {Function} Returns the new function.
11011 * var say = _.spread(function(who, what) {
11012 * return who + ' says ' + what;
11015 * say(['fred', 'hello']);
11016 * // => 'fred says hello'
11018 * var numbers = Promise.all([
11019 * Promise.resolve(40),
11020 * Promise.resolve(36)
11023 * numbers.then(_.spread(function(x, y) {
11026 * // => a Promise of 76
11028 function spread(func, start) {
11029 if (typeof func != 'function') {
11030 throw new TypeError(FUNC_ERROR_TEXT);
11032 start = start == null ? 0 : nativeMax(toInteger(start), 0);
11033 return baseRest(function(args) {
11034 var array = args[start],
11035 otherArgs = castSlice(args, 0, start);
11038 arrayPush(otherArgs, array);
11040 return apply(func, this, otherArgs);
11045 * Creates a throttled function that only invokes `func` at most once per
11046 * every `wait` milliseconds. The throttled function comes with a `cancel`
11047 * method to cancel delayed `func` invocations and a `flush` method to
11048 * immediately invoke them. Provide `options` to indicate whether `func`
11049 * should be invoked on the leading and/or trailing edge of the `wait`
11050 * timeout. The `func` is invoked with the last arguments provided to the
11051 * throttled function. Subsequent calls to the throttled function return the
11052 * result of the last `func` invocation.
11054 * **Note:** If `leading` and `trailing` options are `true`, `func` is
11055 * invoked on the trailing edge of the timeout only if the throttled function
11056 * is invoked more than once during the `wait` timeout.
11058 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
11059 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
11061 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
11062 * for details over the differences between `_.throttle` and `_.debounce`.
11067 * @category Function
11068 * @param {Function} func The function to throttle.
11069 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
11070 * @param {Object} [options={}] The options object.
11071 * @param {boolean} [options.leading=true]
11072 * Specify invoking on the leading edge of the timeout.
11073 * @param {boolean} [options.trailing=true]
11074 * Specify invoking on the trailing edge of the timeout.
11075 * @returns {Function} Returns the new throttled function.
11078 * // Avoid excessively updating the position while scrolling.
11079 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
11081 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
11082 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
11083 * jQuery(element).on('click', throttled);
11085 * // Cancel the trailing throttled invocation.
11086 * jQuery(window).on('popstate', throttled.cancel);
11088 function throttle(func, wait, options) {
11089 var leading = true,
11092 if (typeof func != 'function') {
11093 throw new TypeError(FUNC_ERROR_TEXT);
11095 if (isObject(options)) {
11096 leading = 'leading' in options ? !!options.leading : leading;
11097 trailing = 'trailing' in options ? !!options.trailing : trailing;
11099 return debounce(func, wait, {
11100 'leading': leading,
11102 'trailing': trailing
11107 * Creates a function that accepts up to one argument, ignoring any
11108 * additional arguments.
11113 * @category Function
11114 * @param {Function} func The function to cap arguments for.
11115 * @returns {Function} Returns the new capped function.
11118 * _.map(['6', '8', '10'], _.unary(parseInt));
11121 function unary(func) {
11122 return ary(func, 1);
11126 * Creates a function that provides `value` to `wrapper` as its first
11127 * argument. Any additional arguments provided to the function are appended
11128 * to those provided to the `wrapper`. The wrapper is invoked with the `this`
11129 * binding of the created function.
11134 * @category Function
11135 * @param {*} value The value to wrap.
11136 * @param {Function} [wrapper=identity] The wrapper function.
11137 * @returns {Function} Returns the new function.
11140 * var p = _.wrap(_.escape, function(func, text) {
11141 * return '<p>' + func(text) + '</p>';
11144 * p('fred, barney, & pebbles');
11145 * // => '<p>fred, barney, & pebbles</p>'
11147 function wrap(value, wrapper) {
11148 return partial(castFunction(wrapper), value);
11151 /*------------------------------------------------------------------------*/
11154 * Casts `value` as an array if it's not one.
11160 * @param {*} value The value to inspect.
11161 * @returns {Array} Returns the cast array.
11167 * _.castArray({ 'a': 1 });
11168 * // => [{ 'a': 1 }]
11170 * _.castArray('abc');
11173 * _.castArray(null);
11176 * _.castArray(undefined);
11177 * // => [undefined]
11182 * var array = [1, 2, 3];
11183 * console.log(_.castArray(array) === array);
11186 function castArray() {
11187 if (!arguments.length) {
11190 var value = arguments[0];
11191 return isArray(value) ? value : [value];
11195 * Creates a shallow clone of `value`.
11197 * **Note:** This method is loosely based on the
11198 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
11199 * and supports cloning arrays, array buffers, booleans, date objects, maps,
11200 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
11201 * arrays. The own enumerable properties of `arguments` objects are cloned
11202 * as plain objects. An empty object is returned for uncloneable values such
11203 * as error objects, functions, DOM nodes, and WeakMaps.
11209 * @param {*} value The value to clone.
11210 * @returns {*} Returns the cloned value.
11214 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11216 * var shallow = _.clone(objects);
11217 * console.log(shallow[0] === objects[0]);
11220 function clone(value) {
11221 return baseClone(value, CLONE_SYMBOLS_FLAG);
11225 * This method is like `_.clone` except that it accepts `customizer` which
11226 * is invoked to produce the cloned value. If `customizer` returns `undefined`,
11227 * cloning is handled by the method instead. The `customizer` is invoked with
11228 * up to four arguments; (value [, index|key, object, stack]).
11234 * @param {*} value The value to clone.
11235 * @param {Function} [customizer] The function to customize cloning.
11236 * @returns {*} Returns the cloned value.
11237 * @see _.cloneDeepWith
11240 * function customizer(value) {
11241 * if (_.isElement(value)) {
11242 * return value.cloneNode(false);
11246 * var el = _.cloneWith(document.body, customizer);
11248 * console.log(el === document.body);
11250 * console.log(el.nodeName);
11252 * console.log(el.childNodes.length);
11255 function cloneWith(value, customizer) {
11256 customizer = typeof customizer == 'function' ? customizer : undefined;
11257 return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
11261 * This method is like `_.clone` except that it recursively clones `value`.
11267 * @param {*} value The value to recursively clone.
11268 * @returns {*} Returns the deep cloned value.
11272 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11274 * var deep = _.cloneDeep(objects);
11275 * console.log(deep[0] === objects[0]);
11278 function cloneDeep(value) {
11279 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
11283 * This method is like `_.cloneWith` except that it recursively clones `value`.
11289 * @param {*} value The value to recursively clone.
11290 * @param {Function} [customizer] The function to customize cloning.
11291 * @returns {*} Returns the deep cloned value.
11295 * function customizer(value) {
11296 * if (_.isElement(value)) {
11297 * return value.cloneNode(true);
11301 * var el = _.cloneDeepWith(document.body, customizer);
11303 * console.log(el === document.body);
11305 * console.log(el.nodeName);
11307 * console.log(el.childNodes.length);
11310 function cloneDeepWith(value, customizer) {
11311 customizer = typeof customizer == 'function' ? customizer : undefined;
11312 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
11316 * Checks if `object` conforms to `source` by invoking the predicate
11317 * properties of `source` with the corresponding property values of `object`.
11319 * **Note:** This method is equivalent to `_.conforms` when `source` is
11320 * partially applied.
11326 * @param {Object} object The object to inspect.
11327 * @param {Object} source The object of property predicates to conform to.
11328 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
11331 * var object = { 'a': 1, 'b': 2 };
11333 * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
11336 * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
11339 function conformsTo(object, source) {
11340 return source == null || baseConformsTo(object, source, keys(source));
11345 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
11346 * comparison between two values to determine if they are equivalent.
11352 * @param {*} value The value to compare.
11353 * @param {*} other The other value to compare.
11354 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11357 * var object = { 'a': 1 };
11358 * var other = { 'a': 1 };
11360 * _.eq(object, object);
11363 * _.eq(object, other);
11369 * _.eq('a', Object('a'));
11375 function eq(value, other) {
11376 return value === other || (value !== value && other !== other);
11380 * Checks if `value` is greater than `other`.
11386 * @param {*} value The value to compare.
11387 * @param {*} other The other value to compare.
11388 * @returns {boolean} Returns `true` if `value` is greater than `other`,
11402 var gt = createRelationalOperation(baseGt);
11405 * Checks if `value` is greater than or equal to `other`.
11411 * @param {*} value The value to compare.
11412 * @param {*} other The other value to compare.
11413 * @returns {boolean} Returns `true` if `value` is greater than or equal to
11414 * `other`, else `false`.
11427 var gte = createRelationalOperation(function(value, other) {
11428 return value >= other;
11432 * Checks if `value` is likely an `arguments` object.
11438 * @param {*} value The value to check.
11439 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
11443 * _.isArguments(function() { return arguments; }());
11446 * _.isArguments([1, 2, 3]);
11449 var isArguments = baseIsArguments(function() {
11451 }()) ? baseIsArguments : function(value) {
11452 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
11453 !propertyIsEnumerable.call(value, 'callee');
11457 * Checks if `value` is classified as an `Array` object.
11463 * @param {*} value The value to check.
11464 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
11467 * _.isArray([1, 2, 3]);
11470 * _.isArray(document.body.children);
11473 * _.isArray('abc');
11476 * _.isArray(_.noop);
11479 var isArray = Array.isArray;
11482 * Checks if `value` is classified as an `ArrayBuffer` object.
11488 * @param {*} value The value to check.
11489 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
11492 * _.isArrayBuffer(new ArrayBuffer(2));
11495 * _.isArrayBuffer(new Array(2));
11498 var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
11501 * Checks if `value` is array-like. A value is considered array-like if it's
11502 * not a function and has a `value.length` that's an integer greater than or
11503 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
11509 * @param {*} value The value to check.
11510 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11513 * _.isArrayLike([1, 2, 3]);
11516 * _.isArrayLike(document.body.children);
11519 * _.isArrayLike('abc');
11522 * _.isArrayLike(_.noop);
11525 function isArrayLike(value) {
11526 return value != null && isLength(value.length) && !isFunction(value);
11530 * This method is like `_.isArrayLike` except that it also checks if `value`
11537 * @param {*} value The value to check.
11538 * @returns {boolean} Returns `true` if `value` is an array-like object,
11542 * _.isArrayLikeObject([1, 2, 3]);
11545 * _.isArrayLikeObject(document.body.children);
11548 * _.isArrayLikeObject('abc');
11551 * _.isArrayLikeObject(_.noop);
11554 function isArrayLikeObject(value) {
11555 return isObjectLike(value) && isArrayLike(value);
11559 * Checks if `value` is classified as a boolean primitive or object.
11565 * @param {*} value The value to check.
11566 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
11569 * _.isBoolean(false);
11572 * _.isBoolean(null);
11575 function isBoolean(value) {
11576 return value === true || value === false ||
11577 (isObjectLike(value) && baseGetTag(value) == boolTag);
11581 * Checks if `value` is a buffer.
11587 * @param {*} value The value to check.
11588 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
11591 * _.isBuffer(new Buffer(2));
11594 * _.isBuffer(new Uint8Array(2));
11597 var isBuffer = nativeIsBuffer || stubFalse;
11600 * Checks if `value` is classified as a `Date` object.
11606 * @param {*} value The value to check.
11607 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
11610 * _.isDate(new Date);
11613 * _.isDate('Mon April 23 2012');
11616 var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
11619 * Checks if `value` is likely a DOM element.
11625 * @param {*} value The value to check.
11626 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
11629 * _.isElement(document.body);
11632 * _.isElement('<body>');
11635 function isElement(value) {
11636 return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
11640 * Checks if `value` is an empty object, collection, map, or set.
11642 * Objects are considered empty if they have no own enumerable string keyed
11645 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
11646 * jQuery-like collections are considered empty if they have a `length` of `0`.
11647 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
11653 * @param {*} value The value to check.
11654 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
11666 * _.isEmpty([1, 2, 3]);
11669 * _.isEmpty({ 'a': 1 });
11672 function isEmpty(value) {
11673 if (value == null) {
11676 if (isArrayLike(value) &&
11677 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
11678 isBuffer(value) || isTypedArray(value) || isArguments(value))) {
11679 return !value.length;
11681 var tag = getTag(value);
11682 if (tag == mapTag || tag == setTag) {
11683 return !value.size;
11685 if (isPrototype(value)) {
11686 return !baseKeys(value).length;
11688 for (var key in value) {
11689 if (hasOwnProperty.call(value, key)) {
11697 * Performs a deep comparison between two values to determine if they are
11700 * **Note:** This method supports comparing arrays, array buffers, booleans,
11701 * date objects, error objects, maps, numbers, `Object` objects, regexes,
11702 * sets, strings, symbols, and typed arrays. `Object` objects are compared
11703 * by their own, not inherited, enumerable properties. Functions and DOM
11704 * nodes are compared by strict equality, i.e. `===`.
11710 * @param {*} value The value to compare.
11711 * @param {*} other The other value to compare.
11712 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11715 * var object = { 'a': 1 };
11716 * var other = { 'a': 1 };
11718 * _.isEqual(object, other);
11721 * object === other;
11724 function isEqual(value, other) {
11725 return baseIsEqual(value, other);
11729 * This method is like `_.isEqual` except that it accepts `customizer` which
11730 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11731 * are handled by the method instead. The `customizer` is invoked with up to
11732 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
11738 * @param {*} value The value to compare.
11739 * @param {*} other The other value to compare.
11740 * @param {Function} [customizer] The function to customize comparisons.
11741 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11744 * function isGreeting(value) {
11745 * return /^h(?:i|ello)$/.test(value);
11748 * function customizer(objValue, othValue) {
11749 * if (isGreeting(objValue) && isGreeting(othValue)) {
11754 * var array = ['hello', 'goodbye'];
11755 * var other = ['hi', 'goodbye'];
11757 * _.isEqualWith(array, other, customizer);
11760 function isEqualWith(value, other, customizer) {
11761 customizer = typeof customizer == 'function' ? customizer : undefined;
11762 var result = customizer ? customizer(value, other) : undefined;
11763 return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
11767 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
11768 * `SyntaxError`, `TypeError`, or `URIError` object.
11774 * @param {*} value The value to check.
11775 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
11778 * _.isError(new Error);
11781 * _.isError(Error);
11784 function isError(value) {
11785 if (!isObjectLike(value)) {
11788 var tag = baseGetTag(value);
11789 return tag == errorTag || tag == domExcTag ||
11790 (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
11794 * Checks if `value` is a finite primitive number.
11796 * **Note:** This method is based on
11797 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
11803 * @param {*} value The value to check.
11804 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
11810 * _.isFinite(Number.MIN_VALUE);
11813 * _.isFinite(Infinity);
11819 function isFinite(value) {
11820 return typeof value == 'number' && nativeIsFinite(value);
11824 * Checks if `value` is classified as a `Function` object.
11830 * @param {*} value The value to check.
11831 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
11837 * _.isFunction(/abc/);
11840 function isFunction(value) {
11841 if (!isObject(value)) {
11844 // The use of `Object#toString` avoids issues with the `typeof` operator
11845 // in Safari 9 which returns 'object' for typed arrays and other constructors.
11846 var tag = baseGetTag(value);
11847 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
11851 * Checks if `value` is an integer.
11853 * **Note:** This method is based on
11854 * [`Number.isInteger`](https://mdn.io/Number/isInteger).
11860 * @param {*} value The value to check.
11861 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
11867 * _.isInteger(Number.MIN_VALUE);
11870 * _.isInteger(Infinity);
11873 * _.isInteger('3');
11876 function isInteger(value) {
11877 return typeof value == 'number' && value == toInteger(value);
11881 * Checks if `value` is a valid array-like length.
11883 * **Note:** This method is loosely based on
11884 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
11890 * @param {*} value The value to check.
11891 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11897 * _.isLength(Number.MIN_VALUE);
11900 * _.isLength(Infinity);
11906 function isLength(value) {
11907 return typeof value == 'number' &&
11908 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11912 * Checks if `value` is the
11913 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
11914 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11920 * @param {*} value The value to check.
11921 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11927 * _.isObject([1, 2, 3]);
11930 * _.isObject(_.noop);
11933 * _.isObject(null);
11936 function isObject(value) {
11937 var type = typeof value;
11938 return value != null && (type == 'object' || type == 'function');
11942 * Checks if `value` is object-like. A value is object-like if it's not `null`
11943 * and has a `typeof` result of "object".
11949 * @param {*} value The value to check.
11950 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11953 * _.isObjectLike({});
11956 * _.isObjectLike([1, 2, 3]);
11959 * _.isObjectLike(_.noop);
11962 * _.isObjectLike(null);
11965 function isObjectLike(value) {
11966 return value != null && typeof value == 'object';
11970 * Checks if `value` is classified as a `Map` object.
11976 * @param {*} value The value to check.
11977 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
11980 * _.isMap(new Map);
11983 * _.isMap(new WeakMap);
11986 var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
11989 * Performs a partial deep comparison between `object` and `source` to
11990 * determine if `object` contains equivalent property values.
11992 * **Note:** This method is equivalent to `_.matches` when `source` is
11993 * partially applied.
11995 * Partial comparisons will match empty array and empty object `source`
11996 * values against any array or object value, respectively. See `_.isEqual`
11997 * for a list of supported value comparisons.
12003 * @param {Object} object The object to inspect.
12004 * @param {Object} source The object of property values to match.
12005 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
12008 * var object = { 'a': 1, 'b': 2 };
12010 * _.isMatch(object, { 'b': 2 });
12013 * _.isMatch(object, { 'b': 1 });
12016 function isMatch(object, source) {
12017 return object === source || baseIsMatch(object, source, getMatchData(source));
12021 * This method is like `_.isMatch` except that it accepts `customizer` which
12022 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
12023 * are handled by the method instead. The `customizer` is invoked with five
12024 * arguments: (objValue, srcValue, index|key, object, source).
12030 * @param {Object} object The object to inspect.
12031 * @param {Object} source The object of property values to match.
12032 * @param {Function} [customizer] The function to customize comparisons.
12033 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
12036 * function isGreeting(value) {
12037 * return /^h(?:i|ello)$/.test(value);
12040 * function customizer(objValue, srcValue) {
12041 * if (isGreeting(objValue) && isGreeting(srcValue)) {
12046 * var object = { 'greeting': 'hello' };
12047 * var source = { 'greeting': 'hi' };
12049 * _.isMatchWith(object, source, customizer);
12052 function isMatchWith(object, source, customizer) {
12053 customizer = typeof customizer == 'function' ? customizer : undefined;
12054 return baseIsMatch(object, source, getMatchData(source), customizer);
12058 * Checks if `value` is `NaN`.
12060 * **Note:** This method is based on
12061 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
12062 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
12063 * `undefined` and other non-number values.
12069 * @param {*} value The value to check.
12070 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
12076 * _.isNaN(new Number(NaN));
12079 * isNaN(undefined);
12082 * _.isNaN(undefined);
12085 function isNaN(value) {
12086 // An `NaN` primitive is the only value that is not equal to itself.
12087 // Perform the `toStringTag` check first to avoid errors with some
12088 // ActiveX objects in IE.
12089 return isNumber(value) && value != +value;
12093 * Checks if `value` is a pristine native function.
12095 * **Note:** This method can't reliably detect native functions in the presence
12096 * of the core-js package because core-js circumvents this kind of detection.
12097 * Despite multiple requests, the core-js maintainer has made it clear: any
12098 * attempt to fix the detection will be obstructed. As a result, we're left
12099 * with little choice but to throw an error. Unfortunately, this also affects
12100 * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
12101 * which rely on core-js.
12107 * @param {*} value The value to check.
12108 * @returns {boolean} Returns `true` if `value` is a native function,
12112 * _.isNative(Array.prototype.push);
12118 function isNative(value) {
12119 if (isMaskable(value)) {
12120 throw new Error(CORE_ERROR_TEXT);
12122 return baseIsNative(value);
12126 * Checks if `value` is `null`.
12132 * @param {*} value The value to check.
12133 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
12139 * _.isNull(void 0);
12142 function isNull(value) {
12143 return value === null;
12147 * Checks if `value` is `null` or `undefined`.
12153 * @param {*} value The value to check.
12154 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
12166 function isNil(value) {
12167 return value == null;
12171 * Checks if `value` is classified as a `Number` primitive or object.
12173 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
12174 * classified as numbers, use the `_.isFinite` method.
12180 * @param {*} value The value to check.
12181 * @returns {boolean} Returns `true` if `value` is a number, else `false`.
12187 * _.isNumber(Number.MIN_VALUE);
12190 * _.isNumber(Infinity);
12196 function isNumber(value) {
12197 return typeof value == 'number' ||
12198 (isObjectLike(value) && baseGetTag(value) == numberTag);
12202 * Checks if `value` is a plain object, that is, an object created by the
12203 * `Object` constructor or one with a `[[Prototype]]` of `null`.
12209 * @param {*} value The value to check.
12210 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12217 * _.isPlainObject(new Foo);
12220 * _.isPlainObject([1, 2, 3]);
12223 * _.isPlainObject({ 'x': 0, 'y': 0 });
12226 * _.isPlainObject(Object.create(null));
12229 function isPlainObject(value) {
12230 if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
12233 var proto = getPrototype(value);
12234 if (proto === null) {
12237 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
12238 return typeof Ctor == 'function' && Ctor instanceof Ctor &&
12239 funcToString.call(Ctor) == objectCtorString;
12243 * Checks if `value` is classified as a `RegExp` object.
12249 * @param {*} value The value to check.
12250 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
12253 * _.isRegExp(/abc/);
12256 * _.isRegExp('/abc/');
12259 var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
12262 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
12263 * double precision number which isn't the result of a rounded unsafe integer.
12265 * **Note:** This method is based on
12266 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
12272 * @param {*} value The value to check.
12273 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
12276 * _.isSafeInteger(3);
12279 * _.isSafeInteger(Number.MIN_VALUE);
12282 * _.isSafeInteger(Infinity);
12285 * _.isSafeInteger('3');
12288 function isSafeInteger(value) {
12289 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
12293 * Checks if `value` is classified as a `Set` object.
12299 * @param {*} value The value to check.
12300 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
12303 * _.isSet(new Set);
12306 * _.isSet(new WeakSet);
12309 var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
12312 * Checks if `value` is classified as a `String` primitive or object.
12318 * @param {*} value The value to check.
12319 * @returns {boolean} Returns `true` if `value` is a string, else `false`.
12322 * _.isString('abc');
12328 function isString(value) {
12329 return typeof value == 'string' ||
12330 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
12334 * Checks if `value` is classified as a `Symbol` primitive or object.
12340 * @param {*} value The value to check.
12341 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
12344 * _.isSymbol(Symbol.iterator);
12347 * _.isSymbol('abc');
12350 function isSymbol(value) {
12351 return typeof value == 'symbol' ||
12352 (isObjectLike(value) && baseGetTag(value) == symbolTag);
12356 * Checks if `value` is classified as a typed array.
12362 * @param {*} value The value to check.
12363 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
12366 * _.isTypedArray(new Uint8Array);
12369 * _.isTypedArray([]);
12372 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
12375 * Checks if `value` is `undefined`.
12381 * @param {*} value The value to check.
12382 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
12385 * _.isUndefined(void 0);
12388 * _.isUndefined(null);
12391 function isUndefined(value) {
12392 return value === undefined;
12396 * Checks if `value` is classified as a `WeakMap` object.
12402 * @param {*} value The value to check.
12403 * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
12406 * _.isWeakMap(new WeakMap);
12409 * _.isWeakMap(new Map);
12412 function isWeakMap(value) {
12413 return isObjectLike(value) && getTag(value) == weakMapTag;
12417 * Checks if `value` is classified as a `WeakSet` object.
12423 * @param {*} value The value to check.
12424 * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
12427 * _.isWeakSet(new WeakSet);
12430 * _.isWeakSet(new Set);
12433 function isWeakSet(value) {
12434 return isObjectLike(value) && baseGetTag(value) == weakSetTag;
12438 * Checks if `value` is less than `other`.
12444 * @param {*} value The value to compare.
12445 * @param {*} other The other value to compare.
12446 * @returns {boolean} Returns `true` if `value` is less than `other`,
12460 var lt = createRelationalOperation(baseLt);
12463 * Checks if `value` is less than or equal to `other`.
12469 * @param {*} value The value to compare.
12470 * @param {*} other The other value to compare.
12471 * @returns {boolean} Returns `true` if `value` is less than or equal to
12472 * `other`, else `false`.
12485 var lte = createRelationalOperation(function(value, other) {
12486 return value <= other;
12490 * Converts `value` to an array.
12496 * @param {*} value The value to convert.
12497 * @returns {Array} Returns the converted array.
12500 * _.toArray({ 'a': 1, 'b': 2 });
12503 * _.toArray('abc');
12504 * // => ['a', 'b', 'c']
12512 function toArray(value) {
12516 if (isArrayLike(value)) {
12517 return isString(value) ? stringToArray(value) : copyArray(value);
12519 if (symIterator && value[symIterator]) {
12520 return iteratorToArray(value[symIterator]());
12522 var tag = getTag(value),
12523 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
12525 return func(value);
12529 * Converts `value` to a finite number.
12535 * @param {*} value The value to convert.
12536 * @returns {number} Returns the converted number.
12542 * _.toFinite(Number.MIN_VALUE);
12545 * _.toFinite(Infinity);
12546 * // => 1.7976931348623157e+308
12548 * _.toFinite('3.2');
12551 function toFinite(value) {
12553 return value === 0 ? value : 0;
12555 value = toNumber(value);
12556 if (value === INFINITY || value === -INFINITY) {
12557 var sign = (value < 0 ? -1 : 1);
12558 return sign * MAX_INTEGER;
12560 return value === value ? value : 0;
12564 * Converts `value` to an integer.
12566 * **Note:** This method is loosely based on
12567 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
12573 * @param {*} value The value to convert.
12574 * @returns {number} Returns the converted integer.
12577 * _.toInteger(3.2);
12580 * _.toInteger(Number.MIN_VALUE);
12583 * _.toInteger(Infinity);
12584 * // => 1.7976931348623157e+308
12586 * _.toInteger('3.2');
12589 function toInteger(value) {
12590 var result = toFinite(value),
12591 remainder = result % 1;
12593 return result === result ? (remainder ? result - remainder : result) : 0;
12597 * Converts `value` to an integer suitable for use as the length of an
12598 * array-like object.
12600 * **Note:** This method is based on
12601 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
12607 * @param {*} value The value to convert.
12608 * @returns {number} Returns the converted integer.
12614 * _.toLength(Number.MIN_VALUE);
12617 * _.toLength(Infinity);
12620 * _.toLength('3.2');
12623 function toLength(value) {
12624 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
12628 * Converts `value` to a number.
12634 * @param {*} value The value to process.
12635 * @returns {number} Returns the number.
12641 * _.toNumber(Number.MIN_VALUE);
12644 * _.toNumber(Infinity);
12647 * _.toNumber('3.2');
12650 function toNumber(value) {
12651 if (typeof value == 'number') {
12654 if (isSymbol(value)) {
12657 if (isObject(value)) {
12658 var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
12659 value = isObject(other) ? (other + '') : other;
12661 if (typeof value != 'string') {
12662 return value === 0 ? value : +value;
12664 value = value.replace(reTrim, '');
12665 var isBinary = reIsBinary.test(value);
12666 return (isBinary || reIsOctal.test(value)) ?
12667 freeParseInt(value.slice(2), isBinary ? 2 : 8) :
12668 (reIsBadHex.test(value) ? NAN : +value);
12672 * Converts `value` to a plain object flattening inherited enumerable string
12673 * keyed properties of `value` to own properties of the plain object.
12679 * @param {*} value The value to convert.
12680 * @returns {Object} Returns the converted plain object.
12687 * Foo.prototype.c = 3;
12689 * _.assign({ 'a': 1 }, new Foo);
12690 * // => { 'a': 1, 'b': 2 }
12692 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
12693 * // => { 'a': 1, 'b': 2, 'c': 3 }
12695 function toPlainObject(value) {
12696 return copyObject(value, keysIn(value));
12700 * Converts `value` to a safe integer. A safe integer can be compared and
12701 * represented correctly.
12707 * @param {*} value The value to convert.
12708 * @returns {number} Returns the converted integer.
12711 * _.toSafeInteger(3.2);
12714 * _.toSafeInteger(Number.MIN_VALUE);
12717 * _.toSafeInteger(Infinity);
12718 * // => 9007199254740991
12720 * _.toSafeInteger('3.2');
12723 function toSafeInteger(value) {
12725 baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) :
12726 (value === 0 ? value : 0);
12730 * Converts `value` to a string. An empty string is returned for `null`
12731 * and `undefined` values. The sign of `-0` is preserved.
12737 * @param {*} value The value to convert.
12738 * @returns {string} Returns the converted string.
12741 * _.toString(null);
12747 * _.toString([1, 2, 3]);
12750 function toString(value) {
12751 return value == null ? '' : baseToString(value);
12754 /*------------------------------------------------------------------------*/
12757 * Assigns own enumerable string keyed properties of source objects to the
12758 * destination object. Source objects are applied from left to right.
12759 * Subsequent sources overwrite property assignments of previous sources.
12761 * **Note:** This method mutates `object` and is loosely based on
12762 * [`Object.assign`](https://mdn.io/Object/assign).
12768 * @param {Object} object The destination object.
12769 * @param {...Object} [sources] The source objects.
12770 * @returns {Object} Returns `object`.
12782 * Foo.prototype.b = 2;
12783 * Bar.prototype.d = 4;
12785 * _.assign({ 'a': 0 }, new Foo, new Bar);
12786 * // => { 'a': 1, 'c': 3 }
12788 var assign = createAssigner(function(object, source) {
12789 if (isPrototype(source) || isArrayLike(source)) {
12790 copyObject(source, keys(source), object);
12793 for (var key in source) {
12794 if (hasOwnProperty.call(source, key)) {
12795 assignValue(object, key, source[key]);
12801 * This method is like `_.assign` except that it iterates over own and
12802 * inherited source properties.
12804 * **Note:** This method mutates `object`.
12811 * @param {Object} object The destination object.
12812 * @param {...Object} [sources] The source objects.
12813 * @returns {Object} Returns `object`.
12825 * Foo.prototype.b = 2;
12826 * Bar.prototype.d = 4;
12828 * _.assignIn({ 'a': 0 }, new Foo, new Bar);
12829 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
12831 var assignIn = createAssigner(function(object, source) {
12832 copyObject(source, keysIn(source), object);
12836 * This method is like `_.assignIn` except that it accepts `customizer`
12837 * which is invoked to produce the assigned values. If `customizer` returns
12838 * `undefined`, assignment is handled by the method instead. The `customizer`
12839 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12841 * **Note:** This method mutates `object`.
12846 * @alias extendWith
12848 * @param {Object} object The destination object.
12849 * @param {...Object} sources The source objects.
12850 * @param {Function} [customizer] The function to customize assigned values.
12851 * @returns {Object} Returns `object`.
12852 * @see _.assignWith
12855 * function customizer(objValue, srcValue) {
12856 * return _.isUndefined(objValue) ? srcValue : objValue;
12859 * var defaults = _.partialRight(_.assignInWith, customizer);
12861 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12862 * // => { 'a': 1, 'b': 2 }
12864 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
12865 copyObject(source, keysIn(source), object, customizer);
12869 * This method is like `_.assign` except that it accepts `customizer`
12870 * which is invoked to produce the assigned values. If `customizer` returns
12871 * `undefined`, assignment is handled by the method instead. The `customizer`
12872 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12874 * **Note:** This method mutates `object`.
12880 * @param {Object} object The destination object.
12881 * @param {...Object} sources The source objects.
12882 * @param {Function} [customizer] The function to customize assigned values.
12883 * @returns {Object} Returns `object`.
12884 * @see _.assignInWith
12887 * function customizer(objValue, srcValue) {
12888 * return _.isUndefined(objValue) ? srcValue : objValue;
12891 * var defaults = _.partialRight(_.assignWith, customizer);
12893 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12894 * // => { 'a': 1, 'b': 2 }
12896 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
12897 copyObject(source, keys(source), object, customizer);
12901 * Creates an array of values corresponding to `paths` of `object`.
12907 * @param {Object} object The object to iterate over.
12908 * @param {...(string|string[])} [paths] The property paths to pick.
12909 * @returns {Array} Returns the picked values.
12912 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
12914 * _.at(object, ['a[0].b.c', 'a[1]']);
12917 var at = flatRest(baseAt);
12920 * Creates an object that inherits from the `prototype` object. If a
12921 * `properties` object is given, its own enumerable string keyed properties
12922 * are assigned to the created object.
12928 * @param {Object} prototype The object to inherit from.
12929 * @param {Object} [properties] The properties to assign to the object.
12930 * @returns {Object} Returns the new object.
12933 * function Shape() {
12938 * function Circle() {
12939 * Shape.call(this);
12942 * Circle.prototype = _.create(Shape.prototype, {
12943 * 'constructor': Circle
12946 * var circle = new Circle;
12947 * circle instanceof Circle;
12950 * circle instanceof Shape;
12953 function create(prototype, properties) {
12954 var result = baseCreate(prototype);
12955 return properties == null ? result : baseAssign(result, properties);
12959 * Assigns own and inherited enumerable string keyed properties of source
12960 * objects to the destination object for all destination properties that
12961 * resolve to `undefined`. Source objects are applied from left to right.
12962 * Once a property is set, additional values of the same property are ignored.
12964 * **Note:** This method mutates `object`.
12970 * @param {Object} object The destination object.
12971 * @param {...Object} [sources] The source objects.
12972 * @returns {Object} Returns `object`.
12973 * @see _.defaultsDeep
12976 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12977 * // => { 'a': 1, 'b': 2 }
12979 var defaults = baseRest(function(object, sources) {
12980 object = Object(object);
12983 var length = sources.length;
12984 var guard = length > 2 ? sources[2] : undefined;
12986 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
12990 while (++index < length) {
12991 var source = sources[index];
12992 var props = keysIn(source);
12993 var propsIndex = -1;
12994 var propsLength = props.length;
12996 while (++propsIndex < propsLength) {
12997 var key = props[propsIndex];
12998 var value = object[key];
13000 if (value === undefined ||
13001 (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
13002 object[key] = source[key];
13011 * This method is like `_.defaults` except that it recursively assigns
13012 * default properties.
13014 * **Note:** This method mutates `object`.
13020 * @param {Object} object The destination object.
13021 * @param {...Object} [sources] The source objects.
13022 * @returns {Object} Returns `object`.
13026 * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
13027 * // => { 'a': { 'b': 2, 'c': 3 } }
13029 var defaultsDeep = baseRest(function(args) {
13030 args.push(undefined, customDefaultsMerge);
13031 return apply(mergeWith, undefined, args);
13035 * This method is like `_.find` except that it returns the key of the first
13036 * element `predicate` returns truthy for instead of the element itself.
13042 * @param {Object} object The object to inspect.
13043 * @param {Function} [predicate=_.identity] The function invoked per iteration.
13044 * @returns {string|undefined} Returns the key of the matched element,
13045 * else `undefined`.
13049 * 'barney': { 'age': 36, 'active': true },
13050 * 'fred': { 'age': 40, 'active': false },
13051 * 'pebbles': { 'age': 1, 'active': true }
13054 * _.findKey(users, function(o) { return o.age < 40; });
13055 * // => 'barney' (iteration order is not guaranteed)
13057 * // The `_.matches` iteratee shorthand.
13058 * _.findKey(users, { 'age': 1, 'active': true });
13061 * // The `_.matchesProperty` iteratee shorthand.
13062 * _.findKey(users, ['active', false]);
13065 * // The `_.property` iteratee shorthand.
13066 * _.findKey(users, 'active');
13069 function findKey(object, predicate) {
13070 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
13074 * This method is like `_.findKey` except that it iterates over elements of
13075 * a collection in the opposite order.
13081 * @param {Object} object The object to inspect.
13082 * @param {Function} [predicate=_.identity] The function invoked per iteration.
13083 * @returns {string|undefined} Returns the key of the matched element,
13084 * else `undefined`.
13088 * 'barney': { 'age': 36, 'active': true },
13089 * 'fred': { 'age': 40, 'active': false },
13090 * 'pebbles': { 'age': 1, 'active': true }
13093 * _.findLastKey(users, function(o) { return o.age < 40; });
13094 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
13096 * // The `_.matches` iteratee shorthand.
13097 * _.findLastKey(users, { 'age': 36, 'active': true });
13100 * // The `_.matchesProperty` iteratee shorthand.
13101 * _.findLastKey(users, ['active', false]);
13104 * // The `_.property` iteratee shorthand.
13105 * _.findLastKey(users, 'active');
13108 function findLastKey(object, predicate) {
13109 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
13113 * Iterates over own and inherited enumerable string keyed properties of an
13114 * object and invokes `iteratee` for each property. The iteratee is invoked
13115 * with three arguments: (value, key, object). Iteratee functions may exit
13116 * iteration early by explicitly returning `false`.
13122 * @param {Object} object The object to iterate over.
13123 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13124 * @returns {Object} Returns `object`.
13125 * @see _.forInRight
13133 * Foo.prototype.c = 3;
13135 * _.forIn(new Foo, function(value, key) {
13136 * console.log(key);
13138 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
13140 function forIn(object, iteratee) {
13141 return object == null ?
13143 baseFor(object, getIteratee(iteratee, 3), keysIn);
13147 * This method is like `_.forIn` except that it iterates over properties of
13148 * `object` in the opposite order.
13154 * @param {Object} object The object to iterate over.
13155 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13156 * @returns {Object} Returns `object`.
13165 * Foo.prototype.c = 3;
13167 * _.forInRight(new Foo, function(value, key) {
13168 * console.log(key);
13170 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
13172 function forInRight(object, iteratee) {
13173 return object == null ?
13175 baseForRight(object, getIteratee(iteratee, 3), keysIn);
13179 * Iterates over own enumerable string keyed properties of an object and
13180 * invokes `iteratee` for each property. The iteratee is invoked with three
13181 * arguments: (value, key, object). Iteratee functions may exit iteration
13182 * early by explicitly returning `false`.
13188 * @param {Object} object The object to iterate over.
13189 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13190 * @returns {Object} Returns `object`.
13191 * @see _.forOwnRight
13199 * Foo.prototype.c = 3;
13201 * _.forOwn(new Foo, function(value, key) {
13202 * console.log(key);
13204 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
13206 function forOwn(object, iteratee) {
13207 return object && baseForOwn(object, getIteratee(iteratee, 3));
13211 * This method is like `_.forOwn` except that it iterates over properties of
13212 * `object` in the opposite order.
13218 * @param {Object} object The object to iterate over.
13219 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13220 * @returns {Object} Returns `object`.
13229 * Foo.prototype.c = 3;
13231 * _.forOwnRight(new Foo, function(value, key) {
13232 * console.log(key);
13234 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
13236 function forOwnRight(object, iteratee) {
13237 return object && baseForOwnRight(object, getIteratee(iteratee, 3));
13241 * Creates an array of function property names from own enumerable properties
13248 * @param {Object} object The object to inspect.
13249 * @returns {Array} Returns the function names.
13250 * @see _.functionsIn
13254 * this.a = _.constant('a');
13255 * this.b = _.constant('b');
13258 * Foo.prototype.c = _.constant('c');
13260 * _.functions(new Foo);
13263 function functions(object) {
13264 return object == null ? [] : baseFunctions(object, keys(object));
13268 * Creates an array of function property names from own and inherited
13269 * enumerable properties of `object`.
13275 * @param {Object} object The object to inspect.
13276 * @returns {Array} Returns the function names.
13281 * this.a = _.constant('a');
13282 * this.b = _.constant('b');
13285 * Foo.prototype.c = _.constant('c');
13287 * _.functionsIn(new Foo);
13288 * // => ['a', 'b', 'c']
13290 function functionsIn(object) {
13291 return object == null ? [] : baseFunctions(object, keysIn(object));
13295 * Gets the value at `path` of `object`. If the resolved value is
13296 * `undefined`, the `defaultValue` is returned in its place.
13302 * @param {Object} object The object to query.
13303 * @param {Array|string} path The path of the property to get.
13304 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13305 * @returns {*} Returns the resolved value.
13308 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13310 * _.get(object, 'a[0].b.c');
13313 * _.get(object, ['a', '0', 'b', 'c']);
13316 * _.get(object, 'a.b.c', 'default');
13319 function get(object, path, defaultValue) {
13320 var result = object == null ? undefined : baseGet(object, path);
13321 return result === undefined ? defaultValue : result;
13325 * Checks if `path` is a direct property of `object`.
13331 * @param {Object} object The object to query.
13332 * @param {Array|string} path The path to check.
13333 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13336 * var object = { 'a': { 'b': 2 } };
13337 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
13339 * _.has(object, 'a');
13342 * _.has(object, 'a.b');
13345 * _.has(object, ['a', 'b']);
13348 * _.has(other, 'a');
13351 function has(object, path) {
13352 return object != null && hasPath(object, path, baseHas);
13356 * Checks if `path` is a direct or inherited property of `object`.
13362 * @param {Object} object The object to query.
13363 * @param {Array|string} path The path to check.
13364 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13367 * var object = _.create({ 'a': _.create({ 'b': 2 }) });
13369 * _.hasIn(object, 'a');
13372 * _.hasIn(object, 'a.b');
13375 * _.hasIn(object, ['a', 'b']);
13378 * _.hasIn(object, 'b');
13381 function hasIn(object, path) {
13382 return object != null && hasPath(object, path, baseHasIn);
13386 * Creates an object composed of the inverted keys and values of `object`.
13387 * If `object` contains duplicate values, subsequent values overwrite
13388 * property assignments of previous values.
13394 * @param {Object} object The object to invert.
13395 * @returns {Object} Returns the new inverted object.
13398 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13400 * _.invert(object);
13401 * // => { '1': 'c', '2': 'b' }
13403 var invert = createInverter(function(result, value, key) {
13404 if (value != null &&
13405 typeof value.toString != 'function') {
13406 value = nativeObjectToString.call(value);
13409 result[value] = key;
13410 }, constant(identity));
13413 * This method is like `_.invert` except that the inverted object is generated
13414 * from the results of running each element of `object` thru `iteratee`. The
13415 * corresponding inverted value of each inverted key is an array of keys
13416 * responsible for generating the inverted value. The iteratee is invoked
13417 * with one argument: (value).
13423 * @param {Object} object The object to invert.
13424 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
13425 * @returns {Object} Returns the new inverted object.
13428 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13430 * _.invertBy(object);
13431 * // => { '1': ['a', 'c'], '2': ['b'] }
13433 * _.invertBy(object, function(value) {
13434 * return 'group' + value;
13436 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
13438 var invertBy = createInverter(function(result, value, key) {
13439 if (value != null &&
13440 typeof value.toString != 'function') {
13441 value = nativeObjectToString.call(value);
13444 if (hasOwnProperty.call(result, value)) {
13445 result[value].push(key);
13447 result[value] = [key];
13452 * Invokes the method at `path` of `object`.
13458 * @param {Object} object The object to query.
13459 * @param {Array|string} path The path of the method to invoke.
13460 * @param {...*} [args] The arguments to invoke the method with.
13461 * @returns {*} Returns the result of the invoked method.
13464 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
13466 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
13469 var invoke = baseRest(baseInvoke);
13472 * Creates an array of the own enumerable property names of `object`.
13474 * **Note:** Non-object values are coerced to objects. See the
13475 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
13476 * for more details.
13482 * @param {Object} object The object to query.
13483 * @returns {Array} Returns the array of property names.
13491 * Foo.prototype.c = 3;
13494 * // => ['a', 'b'] (iteration order is not guaranteed)
13499 function keys(object) {
13500 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
13504 * Creates an array of the own and inherited enumerable property names of `object`.
13506 * **Note:** Non-object values are coerced to objects.
13512 * @param {Object} object The object to query.
13513 * @returns {Array} Returns the array of property names.
13521 * Foo.prototype.c = 3;
13523 * _.keysIn(new Foo);
13524 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
13526 function keysIn(object) {
13527 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
13531 * The opposite of `_.mapValues`; this method creates an object with the
13532 * same values as `object` and keys generated by running each own enumerable
13533 * string keyed property of `object` thru `iteratee`. The iteratee is invoked
13534 * with three arguments: (value, key, object).
13540 * @param {Object} object The object to iterate over.
13541 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13542 * @returns {Object} Returns the new mapped object.
13546 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
13547 * return key + value;
13549 * // => { 'a1': 1, 'b2': 2 }
13551 function mapKeys(object, iteratee) {
13553 iteratee = getIteratee(iteratee, 3);
13555 baseForOwn(object, function(value, key, object) {
13556 baseAssignValue(result, iteratee(value, key, object), value);
13562 * Creates an object with the same keys as `object` and values generated
13563 * by running each own enumerable string keyed property of `object` thru
13564 * `iteratee`. The iteratee is invoked with three arguments:
13565 * (value, key, object).
13571 * @param {Object} object The object to iterate over.
13572 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13573 * @returns {Object} Returns the new mapped object.
13578 * 'fred': { 'user': 'fred', 'age': 40 },
13579 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
13582 * _.mapValues(users, function(o) { return o.age; });
13583 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13585 * // The `_.property` iteratee shorthand.
13586 * _.mapValues(users, 'age');
13587 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13589 function mapValues(object, iteratee) {
13591 iteratee = getIteratee(iteratee, 3);
13593 baseForOwn(object, function(value, key, object) {
13594 baseAssignValue(result, key, iteratee(value, key, object));
13600 * This method is like `_.assign` except that it recursively merges own and
13601 * inherited enumerable string keyed properties of source objects into the
13602 * destination object. Source properties that resolve to `undefined` are
13603 * skipped if a destination value exists. Array and plain object properties
13604 * are merged recursively. Other objects and value types are overridden by
13605 * assignment. Source objects are applied from left to right. Subsequent
13606 * sources overwrite property assignments of previous sources.
13608 * **Note:** This method mutates `object`.
13614 * @param {Object} object The destination object.
13615 * @param {...Object} [sources] The source objects.
13616 * @returns {Object} Returns `object`.
13620 * 'a': [{ 'b': 2 }, { 'd': 4 }]
13624 * 'a': [{ 'c': 3 }, { 'e': 5 }]
13627 * _.merge(object, other);
13628 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
13630 var merge = createAssigner(function(object, source, srcIndex) {
13631 baseMerge(object, source, srcIndex);
13635 * This method is like `_.merge` except that it accepts `customizer` which
13636 * is invoked to produce the merged values of the destination and source
13637 * properties. If `customizer` returns `undefined`, merging is handled by the
13638 * method instead. The `customizer` is invoked with six arguments:
13639 * (objValue, srcValue, key, object, source, stack).
13641 * **Note:** This method mutates `object`.
13647 * @param {Object} object The destination object.
13648 * @param {...Object} sources The source objects.
13649 * @param {Function} customizer The function to customize assigned values.
13650 * @returns {Object} Returns `object`.
13653 * function customizer(objValue, srcValue) {
13654 * if (_.isArray(objValue)) {
13655 * return objValue.concat(srcValue);
13659 * var object = { 'a': [1], 'b': [2] };
13660 * var other = { 'a': [3], 'b': [4] };
13662 * _.mergeWith(object, other, customizer);
13663 * // => { 'a': [1, 3], 'b': [2, 4] }
13665 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
13666 baseMerge(object, source, srcIndex, customizer);
13670 * The opposite of `_.pick`; this method creates an object composed of the
13671 * own and inherited enumerable property paths of `object` that are not omitted.
13673 * **Note:** This method is considerably slower than `_.pick`.
13679 * @param {Object} object The source object.
13680 * @param {...(string|string[])} [paths] The property paths to omit.
13681 * @returns {Object} Returns the new object.
13684 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13686 * _.omit(object, ['a', 'c']);
13687 * // => { 'b': '2' }
13689 var omit = flatRest(function(object, paths) {
13691 if (object == null) {
13694 var isDeep = false;
13695 paths = arrayMap(paths, function(path) {
13696 path = castPath(path, object);
13697 isDeep || (isDeep = path.length > 1);
13700 copyObject(object, getAllKeysIn(object), result);
13702 result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
13704 var length = paths.length;
13706 baseUnset(result, paths[length]);
13712 * The opposite of `_.pickBy`; this method creates an object composed of
13713 * the own and inherited enumerable string keyed properties of `object` that
13714 * `predicate` doesn't return truthy for. The predicate is invoked with two
13715 * arguments: (value, key).
13721 * @param {Object} object The source object.
13722 * @param {Function} [predicate=_.identity] The function invoked per property.
13723 * @returns {Object} Returns the new object.
13726 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13728 * _.omitBy(object, _.isNumber);
13729 * // => { 'b': '2' }
13731 function omitBy(object, predicate) {
13732 return pickBy(object, negate(getIteratee(predicate)));
13736 * Creates an object composed of the picked `object` properties.
13742 * @param {Object} object The source object.
13743 * @param {...(string|string[])} [paths] The property paths to pick.
13744 * @returns {Object} Returns the new object.
13747 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13749 * _.pick(object, ['a', 'c']);
13750 * // => { 'a': 1, 'c': 3 }
13752 var pick = flatRest(function(object, paths) {
13753 return object == null ? {} : basePick(object, paths);
13757 * Creates an object composed of the `object` properties `predicate` returns
13758 * truthy for. The predicate is invoked with two arguments: (value, key).
13764 * @param {Object} object The source object.
13765 * @param {Function} [predicate=_.identity] The function invoked per property.
13766 * @returns {Object} Returns the new object.
13769 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13771 * _.pickBy(object, _.isNumber);
13772 * // => { 'a': 1, 'c': 3 }
13774 function pickBy(object, predicate) {
13775 if (object == null) {
13778 var props = arrayMap(getAllKeysIn(object), function(prop) {
13781 predicate = getIteratee(predicate);
13782 return basePickBy(object, props, function(value, path) {
13783 return predicate(value, path[0]);
13788 * This method is like `_.get` except that if the resolved value is a
13789 * function it's invoked with the `this` binding of its parent object and
13790 * its result is returned.
13796 * @param {Object} object The object to query.
13797 * @param {Array|string} path The path of the property to resolve.
13798 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13799 * @returns {*} Returns the resolved value.
13802 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
13804 * _.result(object, 'a[0].b.c1');
13807 * _.result(object, 'a[0].b.c2');
13810 * _.result(object, 'a[0].b.c3', 'default');
13813 * _.result(object, 'a[0].b.c3', _.constant('default'));
13816 function result(object, path, defaultValue) {
13817 path = castPath(path, object);
13820 length = path.length;
13822 // Ensure the loop is entered when path is empty.
13825 object = undefined;
13827 while (++index < length) {
13828 var value = object == null ? undefined : object[toKey(path[index])];
13829 if (value === undefined) {
13831 value = defaultValue;
13833 object = isFunction(value) ? value.call(object) : value;
13839 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
13840 * it's created. Arrays are created for missing index properties while objects
13841 * are created for all other missing properties. Use `_.setWith` to customize
13844 * **Note:** This method mutates `object`.
13850 * @param {Object} object The object to modify.
13851 * @param {Array|string} path The path of the property to set.
13852 * @param {*} value The value to set.
13853 * @returns {Object} Returns `object`.
13856 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13858 * _.set(object, 'a[0].b.c', 4);
13859 * console.log(object.a[0].b.c);
13862 * _.set(object, ['x', '0', 'y', 'z'], 5);
13863 * console.log(object.x[0].y.z);
13866 function set(object, path, value) {
13867 return object == null ? object : baseSet(object, path, value);
13871 * This method is like `_.set` except that it accepts `customizer` which is
13872 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13873 * path creation is handled by the method instead. The `customizer` is invoked
13874 * with three arguments: (nsValue, key, nsObject).
13876 * **Note:** This method mutates `object`.
13882 * @param {Object} object The object to modify.
13883 * @param {Array|string} path The path of the property to set.
13884 * @param {*} value The value to set.
13885 * @param {Function} [customizer] The function to customize assigned values.
13886 * @returns {Object} Returns `object`.
13891 * _.setWith(object, '[0][1]', 'a', Object);
13892 * // => { '0': { '1': 'a' } }
13894 function setWith(object, path, value, customizer) {
13895 customizer = typeof customizer == 'function' ? customizer : undefined;
13896 return object == null ? object : baseSet(object, path, value, customizer);
13900 * Creates an array of own enumerable string keyed-value pairs for `object`
13901 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
13902 * entries are returned.
13909 * @param {Object} object The object to query.
13910 * @returns {Array} Returns the key-value pairs.
13918 * Foo.prototype.c = 3;
13920 * _.toPairs(new Foo);
13921 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
13923 var toPairs = createToPairs(keys);
13926 * Creates an array of own and inherited enumerable string keyed-value pairs
13927 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
13928 * or set, its entries are returned.
13935 * @param {Object} object The object to query.
13936 * @returns {Array} Returns the key-value pairs.
13944 * Foo.prototype.c = 3;
13946 * _.toPairsIn(new Foo);
13947 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
13949 var toPairsIn = createToPairs(keysIn);
13952 * An alternative to `_.reduce`; this method transforms `object` to a new
13953 * `accumulator` object which is the result of running each of its own
13954 * enumerable string keyed properties thru `iteratee`, with each invocation
13955 * potentially mutating the `accumulator` object. If `accumulator` is not
13956 * provided, a new object with the same `[[Prototype]]` will be used. The
13957 * iteratee is invoked with four arguments: (accumulator, value, key, object).
13958 * Iteratee functions may exit iteration early by explicitly returning `false`.
13964 * @param {Object} object The object to iterate over.
13965 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13966 * @param {*} [accumulator] The custom accumulator value.
13967 * @returns {*} Returns the accumulated value.
13970 * _.transform([2, 3, 4], function(result, n) {
13971 * result.push(n *= n);
13972 * return n % 2 == 0;
13976 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
13977 * (result[value] || (result[value] = [])).push(key);
13979 * // => { '1': ['a', 'c'], '2': ['b'] }
13981 function transform(object, iteratee, accumulator) {
13982 var isArr = isArray(object),
13983 isArrLike = isArr || isBuffer(object) || isTypedArray(object);
13985 iteratee = getIteratee(iteratee, 4);
13986 if (accumulator == null) {
13987 var Ctor = object && object.constructor;
13989 accumulator = isArr ? new Ctor : [];
13990 } else if (isObject(object)) {
13991 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
13996 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
13997 return iteratee(accumulator, value, index, object);
13999 return accumulator;
14003 * Removes the property at `path` of `object`.
14005 * **Note:** This method mutates `object`.
14011 * @param {Object} object The object to modify.
14012 * @param {Array|string} path The path of the property to unset.
14013 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
14016 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
14017 * _.unset(object, 'a[0].b.c');
14020 * console.log(object);
14021 * // => { 'a': [{ 'b': {} }] };
14023 * _.unset(object, ['a', '0', 'b', 'c']);
14026 * console.log(object);
14027 * // => { 'a': [{ 'b': {} }] };
14029 function unset(object, path) {
14030 return object == null ? true : baseUnset(object, path);
14034 * This method is like `_.set` except that accepts `updater` to produce the
14035 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
14036 * is invoked with one argument: (value).
14038 * **Note:** This method mutates `object`.
14044 * @param {Object} object The object to modify.
14045 * @param {Array|string} path The path of the property to set.
14046 * @param {Function} updater The function to produce the updated value.
14047 * @returns {Object} Returns `object`.
14050 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
14052 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
14053 * console.log(object.a[0].b.c);
14056 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
14057 * console.log(object.x[0].y.z);
14060 function update(object, path, updater) {
14061 return object == null ? object : baseUpdate(object, path, castFunction(updater));
14065 * This method is like `_.update` except that it accepts `customizer` which is
14066 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
14067 * path creation is handled by the method instead. The `customizer` is invoked
14068 * with three arguments: (nsValue, key, nsObject).
14070 * **Note:** This method mutates `object`.
14076 * @param {Object} object The object to modify.
14077 * @param {Array|string} path The path of the property to set.
14078 * @param {Function} updater The function to produce the updated value.
14079 * @param {Function} [customizer] The function to customize assigned values.
14080 * @returns {Object} Returns `object`.
14085 * _.updateWith(object, '[0][1]', _.constant('a'), Object);
14086 * // => { '0': { '1': 'a' } }
14088 function updateWith(object, path, updater, customizer) {
14089 customizer = typeof customizer == 'function' ? customizer : undefined;
14090 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
14094 * Creates an array of the own enumerable string keyed property values of `object`.
14096 * **Note:** Non-object values are coerced to objects.
14102 * @param {Object} object The object to query.
14103 * @returns {Array} Returns the array of property values.
14111 * Foo.prototype.c = 3;
14113 * _.values(new Foo);
14114 * // => [1, 2] (iteration order is not guaranteed)
14119 function values(object) {
14120 return object == null ? [] : baseValues(object, keys(object));
14124 * Creates an array of the own and inherited enumerable string keyed property
14125 * values of `object`.
14127 * **Note:** Non-object values are coerced to objects.
14133 * @param {Object} object The object to query.
14134 * @returns {Array} Returns the array of property values.
14142 * Foo.prototype.c = 3;
14144 * _.valuesIn(new Foo);
14145 * // => [1, 2, 3] (iteration order is not guaranteed)
14147 function valuesIn(object) {
14148 return object == null ? [] : baseValues(object, keysIn(object));
14151 /*------------------------------------------------------------------------*/
14154 * Clamps `number` within the inclusive `lower` and `upper` bounds.
14160 * @param {number} number The number to clamp.
14161 * @param {number} [lower] The lower bound.
14162 * @param {number} upper The upper bound.
14163 * @returns {number} Returns the clamped number.
14166 * _.clamp(-10, -5, 5);
14169 * _.clamp(10, -5, 5);
14172 function clamp(number, lower, upper) {
14173 if (upper === undefined) {
14177 if (upper !== undefined) {
14178 upper = toNumber(upper);
14179 upper = upper === upper ? upper : 0;
14181 if (lower !== undefined) {
14182 lower = toNumber(lower);
14183 lower = lower === lower ? lower : 0;
14185 return baseClamp(toNumber(number), lower, upper);
14189 * Checks if `n` is between `start` and up to, but not including, `end`. If
14190 * `end` is not specified, it's set to `start` with `start` then set to `0`.
14191 * If `start` is greater than `end` the params are swapped to support
14198 * @param {number} number The number to check.
14199 * @param {number} [start=0] The start of the range.
14200 * @param {number} end The end of the range.
14201 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
14202 * @see _.range, _.rangeRight
14205 * _.inRange(3, 2, 4);
14217 * _.inRange(1.2, 2);
14220 * _.inRange(5.2, 4);
14223 * _.inRange(-3, -2, -6);
14226 function inRange(number, start, end) {
14227 start = toFinite(start);
14228 if (end === undefined) {
14232 end = toFinite(end);
14234 number = toNumber(number);
14235 return baseInRange(number, start, end);
14239 * Produces a random number between the inclusive `lower` and `upper` bounds.
14240 * If only one argument is provided a number between `0` and the given number
14241 * is returned. If `floating` is `true`, or either `lower` or `upper` are
14242 * floats, a floating-point number is returned instead of an integer.
14244 * **Note:** JavaScript follows the IEEE-754 standard for resolving
14245 * floating-point values which can produce unexpected results.
14251 * @param {number} [lower=0] The lower bound.
14252 * @param {number} [upper=1] The upper bound.
14253 * @param {boolean} [floating] Specify returning a floating-point number.
14254 * @returns {number} Returns the random number.
14258 * // => an integer between 0 and 5
14261 * // => also an integer between 0 and 5
14263 * _.random(5, true);
14264 * // => a floating-point number between 0 and 5
14266 * _.random(1.2, 5.2);
14267 * // => a floating-point number between 1.2 and 5.2
14269 function random(lower, upper, floating) {
14270 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
14271 upper = floating = undefined;
14273 if (floating === undefined) {
14274 if (typeof upper == 'boolean') {
14277 } else if (typeof lower == 'boolean') {
14282 if (lower === undefined && upper === undefined) {
14286 lower = toFinite(lower);
14287 if (upper === undefined) {
14291 upper = toFinite(upper);
14294 if (lower > upper) {
14299 if (floating || lower % 1 || upper % 1) {
14300 var rand = nativeRandom();
14301 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
14303 return baseRandom(lower, upper);
14306 /*------------------------------------------------------------------------*/
14309 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
14315 * @param {string} [string=''] The string to convert.
14316 * @returns {string} Returns the camel cased string.
14319 * _.camelCase('Foo Bar');
14322 * _.camelCase('--foo-bar--');
14325 * _.camelCase('__FOO_BAR__');
14328 var camelCase = createCompounder(function(result, word, index) {
14329 word = word.toLowerCase();
14330 return result + (index ? capitalize(word) : word);
14334 * Converts the first character of `string` to upper case and the remaining
14341 * @param {string} [string=''] The string to capitalize.
14342 * @returns {string} Returns the capitalized string.
14345 * _.capitalize('FRED');
14348 function capitalize(string) {
14349 return upperFirst(toString(string).toLowerCase());
14353 * Deburrs `string` by converting
14354 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
14355 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
14356 * letters to basic Latin letters and removing
14357 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
14363 * @param {string} [string=''] The string to deburr.
14364 * @returns {string} Returns the deburred string.
14367 * _.deburr('déjà vu');
14370 function deburr(string) {
14371 string = toString(string);
14372 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
14376 * Checks if `string` ends with the given target string.
14382 * @param {string} [string=''] The string to inspect.
14383 * @param {string} [target] The string to search for.
14384 * @param {number} [position=string.length] The position to search up to.
14385 * @returns {boolean} Returns `true` if `string` ends with `target`,
14389 * _.endsWith('abc', 'c');
14392 * _.endsWith('abc', 'b');
14395 * _.endsWith('abc', 'b', 2);
14398 function endsWith(string, target, position) {
14399 string = toString(string);
14400 target = baseToString(target);
14402 var length = string.length;
14403 position = position === undefined ?
14405 baseClamp(toInteger(position), 0, length);
14407 var end = position;
14408 position -= target.length;
14409 return position >= 0 && string.slice(position, end) == target;
14413 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
14414 * corresponding HTML entities.
14416 * **Note:** No other characters are escaped. To escape additional
14417 * characters use a third-party library like [_he_](https://mths.be/he).
14419 * Though the ">" character is escaped for symmetry, characters like
14420 * ">" and "/" don't need escaping in HTML and have no special meaning
14421 * unless they're part of a tag or unquoted attribute value. See
14422 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
14423 * (under "semi-related fun fact") for more details.
14425 * When working with HTML you should always
14426 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
14433 * @param {string} [string=''] The string to escape.
14434 * @returns {string} Returns the escaped string.
14437 * _.escape('fred, barney, & pebbles');
14438 * // => 'fred, barney, & pebbles'
14440 function escape(string) {
14441 string = toString(string);
14442 return (string && reHasUnescapedHtml.test(string)) ?
14443 string.replace(reUnescapedHtml, escapeHtmlChar) :
14448 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
14449 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
14455 * @param {string} [string=''] The string to escape.
14456 * @returns {string} Returns the escaped string.
14459 * _.escapeRegExp('[lodash](https://lodash.com/)');
14460 * // => '\[lodash\]\(https://lodash\.com/\)'
14462 function escapeRegExp(string) {
14463 string = toString(string);
14464 return (string && reHasRegExpChar.test(string)) ?
14465 string.replace(reRegExpChar, '\\$&') :
14470 * Converts `string` to
14471 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
14477 * @param {string} [string=''] The string to convert.
14478 * @returns {string} Returns the kebab cased string.
14481 * _.kebabCase('Foo Bar');
14484 * _.kebabCase('fooBar');
14487 * _.kebabCase('__FOO_BAR__');
14490 var kebabCase = createCompounder(function(result, word, index) {
14491 return result + (index ? '-' : '') + word.toLowerCase();
14495 * Converts `string`, as space separated words, to lower case.
14501 * @param {string} [string=''] The string to convert.
14502 * @returns {string} Returns the lower cased string.
14505 * _.lowerCase('--Foo-Bar--');
14508 * _.lowerCase('fooBar');
14511 * _.lowerCase('__FOO_BAR__');
14514 var lowerCase = createCompounder(function(result, word, index) {
14515 return result + (index ? ' ' : '') + word.toLowerCase();
14519 * Converts the first character of `string` to lower case.
14525 * @param {string} [string=''] The string to convert.
14526 * @returns {string} Returns the converted string.
14529 * _.lowerFirst('Fred');
14532 * _.lowerFirst('FRED');
14535 var lowerFirst = createCaseFirst('toLowerCase');
14538 * Pads `string` on the left and right sides if it's shorter than `length`.
14539 * Padding characters are truncated if they can't be evenly divided by `length`.
14545 * @param {string} [string=''] The string to pad.
14546 * @param {number} [length=0] The padding length.
14547 * @param {string} [chars=' '] The string used as padding.
14548 * @returns {string} Returns the padded string.
14554 * _.pad('abc', 8, '_-');
14560 function pad(string, length, chars) {
14561 string = toString(string);
14562 length = toInteger(length);
14564 var strLength = length ? stringSize(string) : 0;
14565 if (!length || strLength >= length) {
14568 var mid = (length - strLength) / 2;
14570 createPadding(nativeFloor(mid), chars) +
14572 createPadding(nativeCeil(mid), chars)
14577 * Pads `string` on the right side if it's shorter than `length`. Padding
14578 * characters are truncated if they exceed `length`.
14584 * @param {string} [string=''] The string to pad.
14585 * @param {number} [length=0] The padding length.
14586 * @param {string} [chars=' '] The string used as padding.
14587 * @returns {string} Returns the padded string.
14590 * _.padEnd('abc', 6);
14593 * _.padEnd('abc', 6, '_-');
14596 * _.padEnd('abc', 3);
14599 function padEnd(string, length, chars) {
14600 string = toString(string);
14601 length = toInteger(length);
14603 var strLength = length ? stringSize(string) : 0;
14604 return (length && strLength < length) ?
14605 (string + createPadding(length - strLength, chars)) :
14610 * Pads `string` on the left side if it's shorter than `length`. Padding
14611 * characters are truncated if they exceed `length`.
14617 * @param {string} [string=''] The string to pad.
14618 * @param {number} [length=0] The padding length.
14619 * @param {string} [chars=' '] The string used as padding.
14620 * @returns {string} Returns the padded string.
14623 * _.padStart('abc', 6);
14626 * _.padStart('abc', 6, '_-');
14629 * _.padStart('abc', 3);
14632 function padStart(string, length, chars) {
14633 string = toString(string);
14634 length = toInteger(length);
14636 var strLength = length ? stringSize(string) : 0;
14637 return (length && strLength < length) ?
14638 (createPadding(length - strLength, chars) + string) :
14643 * Converts `string` to an integer of the specified radix. If `radix` is
14644 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
14645 * hexadecimal, in which case a `radix` of `16` is used.
14647 * **Note:** This method aligns with the
14648 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
14654 * @param {string} string The string to convert.
14655 * @param {number} [radix=10] The radix to interpret `value` by.
14656 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14657 * @returns {number} Returns the converted integer.
14660 * _.parseInt('08');
14663 * _.map(['6', '08', '10'], _.parseInt);
14666 function parseInt(string, radix, guard) {
14667 if (guard || radix == null) {
14669 } else if (radix) {
14672 return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
14676 * Repeats the given string `n` times.
14682 * @param {string} [string=''] The string to repeat.
14683 * @param {number} [n=1] The number of times to repeat the string.
14684 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14685 * @returns {string} Returns the repeated string.
14688 * _.repeat('*', 3);
14691 * _.repeat('abc', 2);
14694 * _.repeat('abc', 0);
14697 function repeat(string, n, guard) {
14698 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
14703 return baseRepeat(toString(string), n);
14707 * Replaces matches for `pattern` in `string` with `replacement`.
14709 * **Note:** This method is based on
14710 * [`String#replace`](https://mdn.io/String/replace).
14716 * @param {string} [string=''] The string to modify.
14717 * @param {RegExp|string} pattern The pattern to replace.
14718 * @param {Function|string} replacement The match replacement.
14719 * @returns {string} Returns the modified string.
14722 * _.replace('Hi Fred', 'Fred', 'Barney');
14723 * // => 'Hi Barney'
14725 function replace() {
14726 var args = arguments,
14727 string = toString(args[0]);
14729 return args.length < 3 ? string : string.replace(args[1], args[2]);
14733 * Converts `string` to
14734 * [snake case](https://en.wikipedia.org/wiki/Snake_case).
14740 * @param {string} [string=''] The string to convert.
14741 * @returns {string} Returns the snake cased string.
14744 * _.snakeCase('Foo Bar');
14747 * _.snakeCase('fooBar');
14750 * _.snakeCase('--FOO-BAR--');
14753 var snakeCase = createCompounder(function(result, word, index) {
14754 return result + (index ? '_' : '') + word.toLowerCase();
14758 * Splits `string` by `separator`.
14760 * **Note:** This method is based on
14761 * [`String#split`](https://mdn.io/String/split).
14767 * @param {string} [string=''] The string to split.
14768 * @param {RegExp|string} separator The separator pattern to split by.
14769 * @param {number} [limit] The length to truncate results to.
14770 * @returns {Array} Returns the string segments.
14773 * _.split('a-b-c', '-', 2);
14776 function split(string, separator, limit) {
14777 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
14778 separator = limit = undefined;
14780 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
14784 string = toString(string);
14786 typeof separator == 'string' ||
14787 (separator != null && !isRegExp(separator))
14789 separator = baseToString(separator);
14790 if (!separator && hasUnicode(string)) {
14791 return castSlice(stringToArray(string), 0, limit);
14794 return string.split(separator, limit);
14798 * Converts `string` to
14799 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
14805 * @param {string} [string=''] The string to convert.
14806 * @returns {string} Returns the start cased string.
14809 * _.startCase('--foo-bar--');
14812 * _.startCase('fooBar');
14815 * _.startCase('__FOO_BAR__');
14818 var startCase = createCompounder(function(result, word, index) {
14819 return result + (index ? ' ' : '') + upperFirst(word);
14823 * Checks if `string` starts with the given target string.
14829 * @param {string} [string=''] The string to inspect.
14830 * @param {string} [target] The string to search for.
14831 * @param {number} [position=0] The position to search from.
14832 * @returns {boolean} Returns `true` if `string` starts with `target`,
14836 * _.startsWith('abc', 'a');
14839 * _.startsWith('abc', 'b');
14842 * _.startsWith('abc', 'b', 1);
14845 function startsWith(string, target, position) {
14846 string = toString(string);
14847 position = position == null ?
14849 baseClamp(toInteger(position), 0, string.length);
14851 target = baseToString(target);
14852 return string.slice(position, position + target.length) == target;
14856 * Creates a compiled template function that can interpolate data properties
14857 * in "interpolate" delimiters, HTML-escape interpolated data properties in
14858 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
14859 * properties may be accessed as free variables in the template. If a setting
14860 * object is given, it takes precedence over `_.templateSettings` values.
14862 * **Note:** In the development build `_.template` utilizes
14863 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
14864 * for easier debugging.
14866 * For more information on precompiling templates see
14867 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
14869 * For more information on Chrome extension sandboxes see
14870 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
14876 * @param {string} [string=''] The template string.
14877 * @param {Object} [options={}] The options object.
14878 * @param {RegExp} [options.escape=_.templateSettings.escape]
14879 * The HTML "escape" delimiter.
14880 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
14881 * The "evaluate" delimiter.
14882 * @param {Object} [options.imports=_.templateSettings.imports]
14883 * An object to import into the template as free variables.
14884 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
14885 * The "interpolate" delimiter.
14886 * @param {string} [options.sourceURL='lodash.templateSources[n]']
14887 * The sourceURL of the compiled template.
14888 * @param {string} [options.variable='obj']
14889 * The data object variable name.
14890 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14891 * @returns {Function} Returns the compiled template function.
14894 * // Use the "interpolate" delimiter to create a compiled template.
14895 * var compiled = _.template('hello <%= user %>!');
14896 * compiled({ 'user': 'fred' });
14897 * // => 'hello fred!'
14899 * // Use the HTML "escape" delimiter to escape data property values.
14900 * var compiled = _.template('<b><%- value %></b>');
14901 * compiled({ 'value': '<script>' });
14902 * // => '<b><script></b>'
14904 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
14905 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
14906 * compiled({ 'users': ['fred', 'barney'] });
14907 * // => '<li>fred</li><li>barney</li>'
14909 * // Use the internal `print` function in "evaluate" delimiters.
14910 * var compiled = _.template('<% print("hello " + user); %>!');
14911 * compiled({ 'user': 'barney' });
14912 * // => 'hello barney!'
14914 * // Use the ES template literal delimiter as an "interpolate" delimiter.
14915 * // Disable support by replacing the "interpolate" delimiter.
14916 * var compiled = _.template('hello ${ user }!');
14917 * compiled({ 'user': 'pebbles' });
14918 * // => 'hello pebbles!'
14920 * // Use backslashes to treat delimiters as plain text.
14921 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
14922 * compiled({ 'value': 'ignored' });
14923 * // => '<%- value %>'
14925 * // Use the `imports` option to import `jQuery` as `jq`.
14926 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
14927 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
14928 * compiled({ 'users': ['fred', 'barney'] });
14929 * // => '<li>fred</li><li>barney</li>'
14931 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
14932 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
14934 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
14936 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
14937 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
14939 * // => function(data) {
14940 * // var __t, __p = '';
14941 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
14945 * // Use custom template delimiters.
14946 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
14947 * var compiled = _.template('hello {{ user }}!');
14948 * compiled({ 'user': 'mustache' });
14949 * // => 'hello mustache!'
14951 * // Use the `source` property to inline compiled templates for meaningful
14952 * // line numbers in error messages and stack traces.
14953 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
14955 * "main": ' + _.template(mainText).source + '\
14959 function template(string, options, guard) {
14960 // Based on John Resig's `tmpl` implementation
14961 // (http://ejohn.org/blog/javascript-micro-templating/)
14962 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
14963 var settings = lodash.templateSettings;
14965 if (guard && isIterateeCall(string, options, guard)) {
14966 options = undefined;
14968 string = toString(string);
14969 options = assignInWith({}, options, settings, customDefaultsAssignIn);
14971 var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
14972 importsKeys = keys(imports),
14973 importsValues = baseValues(imports, importsKeys);
14978 interpolate = options.interpolate || reNoMatch,
14979 source = "__p += '";
14981 // Compile the regexp to match each delimiter.
14982 var reDelimiters = RegExp(
14983 (options.escape || reNoMatch).source + '|' +
14984 interpolate.source + '|' +
14985 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
14986 (options.evaluate || reNoMatch).source + '|$', 'g');
14988 // Use a sourceURL for easier debugging.
14989 // The sourceURL gets injected into the source that's eval-ed, so be careful
14990 // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
14991 // and escape the comment, thus injecting code that gets evaled.
14992 var sourceURL = '//# sourceURL=' +
14993 (hasOwnProperty.call(options, 'sourceURL') ?
14994 (options.sourceURL + '').replace(/\s/g, ' ') :
14995 ('lodash.templateSources[' + (++templateCounter) + ']')
14998 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
14999 interpolateValue || (interpolateValue = esTemplateValue);
15001 // Escape characters that can't be included in string literals.
15002 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
15004 // Replace delimiters with snippets.
15007 source += "' +\n__e(" + escapeValue + ") +\n'";
15009 if (evaluateValue) {
15010 isEvaluating = true;
15011 source += "';\n" + evaluateValue + ";\n__p += '";
15013 if (interpolateValue) {
15014 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
15016 index = offset + match.length;
15018 // The JS engine embedded in Adobe products needs `match` returned in
15019 // order to produce the correct `offset` value.
15025 // If `variable` is not specified wrap a with-statement around the generated
15026 // code to add the data object to the top of the scope chain.
15027 var variable = hasOwnProperty.call(options, 'variable') && options.variable;
15029 source = 'with (obj) {\n' + source + '\n}\n';
15031 // Cleanup code by stripping empty strings.
15032 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
15033 .replace(reEmptyStringMiddle, '$1')
15034 .replace(reEmptyStringTrailing, '$1;');
15036 // Frame code as the function body.
15037 source = 'function(' + (variable || 'obj') + ') {\n' +
15040 'obj || (obj = {});\n'
15042 "var __t, __p = ''" +
15044 ', __e = _.escape' :
15048 ', __j = Array.prototype.join;\n' +
15049 "function print() { __p += __j.call(arguments, '') }\n" :
15055 var result = attempt(function() {
15056 return Function(importsKeys, sourceURL + 'return ' + source)
15057 .apply(undefined, importsValues);
15060 // Provide the compiled function's source by its `toString` method or
15061 // the `source` property as a convenience for inlining compiled templates.
15062 result.source = source;
15063 if (isError(result)) {
15070 * Converts `string`, as a whole, to lower case just like
15071 * [String#toLowerCase](https://mdn.io/toLowerCase).
15077 * @param {string} [string=''] The string to convert.
15078 * @returns {string} Returns the lower cased string.
15081 * _.toLower('--Foo-Bar--');
15082 * // => '--foo-bar--'
15084 * _.toLower('fooBar');
15087 * _.toLower('__FOO_BAR__');
15088 * // => '__foo_bar__'
15090 function toLower(value) {
15091 return toString(value).toLowerCase();
15095 * Converts `string`, as a whole, to upper case just like
15096 * [String#toUpperCase](https://mdn.io/toUpperCase).
15102 * @param {string} [string=''] The string to convert.
15103 * @returns {string} Returns the upper cased string.
15106 * _.toUpper('--foo-bar--');
15107 * // => '--FOO-BAR--'
15109 * _.toUpper('fooBar');
15112 * _.toUpper('__foo_bar__');
15113 * // => '__FOO_BAR__'
15115 function toUpper(value) {
15116 return toString(value).toUpperCase();
15120 * Removes leading and trailing whitespace or specified characters from `string`.
15126 * @param {string} [string=''] The string to trim.
15127 * @param {string} [chars=whitespace] The characters to trim.
15128 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15129 * @returns {string} Returns the trimmed string.
15135 * _.trim('-_-abc-_-', '_-');
15138 * _.map([' foo ', ' bar '], _.trim);
15139 * // => ['foo', 'bar']
15141 function trim(string, chars, guard) {
15142 string = toString(string);
15143 if (string && (guard || chars === undefined)) {
15144 return string.replace(reTrim, '');
15146 if (!string || !(chars = baseToString(chars))) {
15149 var strSymbols = stringToArray(string),
15150 chrSymbols = stringToArray(chars),
15151 start = charsStartIndex(strSymbols, chrSymbols),
15152 end = charsEndIndex(strSymbols, chrSymbols) + 1;
15154 return castSlice(strSymbols, start, end).join('');
15158 * Removes trailing whitespace or specified characters from `string`.
15164 * @param {string} [string=''] The string to trim.
15165 * @param {string} [chars=whitespace] The characters to trim.
15166 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15167 * @returns {string} Returns the trimmed string.
15170 * _.trimEnd(' abc ');
15173 * _.trimEnd('-_-abc-_-', '_-');
15176 function trimEnd(string, chars, guard) {
15177 string = toString(string);
15178 if (string && (guard || chars === undefined)) {
15179 return string.replace(reTrimEnd, '');
15181 if (!string || !(chars = baseToString(chars))) {
15184 var strSymbols = stringToArray(string),
15185 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
15187 return castSlice(strSymbols, 0, end).join('');
15191 * Removes leading whitespace or specified characters from `string`.
15197 * @param {string} [string=''] The string to trim.
15198 * @param {string} [chars=whitespace] The characters to trim.
15199 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15200 * @returns {string} Returns the trimmed string.
15203 * _.trimStart(' abc ');
15206 * _.trimStart('-_-abc-_-', '_-');
15209 function trimStart(string, chars, guard) {
15210 string = toString(string);
15211 if (string && (guard || chars === undefined)) {
15212 return string.replace(reTrimStart, '');
15214 if (!string || !(chars = baseToString(chars))) {
15217 var strSymbols = stringToArray(string),
15218 start = charsStartIndex(strSymbols, stringToArray(chars));
15220 return castSlice(strSymbols, start).join('');
15224 * Truncates `string` if it's longer than the given maximum string length.
15225 * The last characters of the truncated string are replaced with the omission
15226 * string which defaults to "...".
15232 * @param {string} [string=''] The string to truncate.
15233 * @param {Object} [options={}] The options object.
15234 * @param {number} [options.length=30] The maximum string length.
15235 * @param {string} [options.omission='...'] The string to indicate text is omitted.
15236 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
15237 * @returns {string} Returns the truncated string.
15240 * _.truncate('hi-diddly-ho there, neighborino');
15241 * // => 'hi-diddly-ho there, neighbo...'
15243 * _.truncate('hi-diddly-ho there, neighborino', {
15247 * // => 'hi-diddly-ho there,...'
15249 * _.truncate('hi-diddly-ho there, neighborino', {
15251 * 'separator': /,? +/
15253 * // => 'hi-diddly-ho there...'
15255 * _.truncate('hi-diddly-ho there, neighborino', {
15256 * 'omission': ' [...]'
15258 * // => 'hi-diddly-ho there, neig [...]'
15260 function truncate(string, options) {
15261 var length = DEFAULT_TRUNC_LENGTH,
15262 omission = DEFAULT_TRUNC_OMISSION;
15264 if (isObject(options)) {
15265 var separator = 'separator' in options ? options.separator : separator;
15266 length = 'length' in options ? toInteger(options.length) : length;
15267 omission = 'omission' in options ? baseToString(options.omission) : omission;
15269 string = toString(string);
15271 var strLength = string.length;
15272 if (hasUnicode(string)) {
15273 var strSymbols = stringToArray(string);
15274 strLength = strSymbols.length;
15276 if (length >= strLength) {
15279 var end = length - stringSize(omission);
15283 var result = strSymbols ?
15284 castSlice(strSymbols, 0, end).join('') :
15285 string.slice(0, end);
15287 if (separator === undefined) {
15288 return result + omission;
15291 end += (result.length - end);
15293 if (isRegExp(separator)) {
15294 if (string.slice(end).search(separator)) {
15296 substring = result;
15298 if (!separator.global) {
15299 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
15301 separator.lastIndex = 0;
15302 while ((match = separator.exec(substring))) {
15303 var newEnd = match.index;
15305 result = result.slice(0, newEnd === undefined ? end : newEnd);
15307 } else if (string.indexOf(baseToString(separator), end) != end) {
15308 var index = result.lastIndexOf(separator);
15310 result = result.slice(0, index);
15313 return result + omission;
15317 * The inverse of `_.escape`; this method converts the HTML entities
15318 * `&`, `<`, `>`, `"`, and `'` in `string` to
15319 * their corresponding characters.
15321 * **Note:** No other HTML entities are unescaped. To unescape additional
15322 * HTML entities use a third-party library like [_he_](https://mths.be/he).
15328 * @param {string} [string=''] The string to unescape.
15329 * @returns {string} Returns the unescaped string.
15332 * _.unescape('fred, barney, & pebbles');
15333 * // => 'fred, barney, & pebbles'
15335 function unescape(string) {
15336 string = toString(string);
15337 return (string && reHasEscapedHtml.test(string)) ?
15338 string.replace(reEscapedHtml, unescapeHtmlChar) :
15343 * Converts `string`, as space separated words, to upper case.
15349 * @param {string} [string=''] The string to convert.
15350 * @returns {string} Returns the upper cased string.
15353 * _.upperCase('--foo-bar');
15356 * _.upperCase('fooBar');
15359 * _.upperCase('__foo_bar__');
15362 var upperCase = createCompounder(function(result, word, index) {
15363 return result + (index ? ' ' : '') + word.toUpperCase();
15367 * Converts the first character of `string` to upper case.
15373 * @param {string} [string=''] The string to convert.
15374 * @returns {string} Returns the converted string.
15377 * _.upperFirst('fred');
15380 * _.upperFirst('FRED');
15383 var upperFirst = createCaseFirst('toUpperCase');
15386 * Splits `string` into an array of its words.
15392 * @param {string} [string=''] The string to inspect.
15393 * @param {RegExp|string} [pattern] The pattern to match words.
15394 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15395 * @returns {Array} Returns the words of `string`.
15398 * _.words('fred, barney, & pebbles');
15399 * // => ['fred', 'barney', 'pebbles']
15401 * _.words('fred, barney, & pebbles', /[^, ]+/g);
15402 * // => ['fred', 'barney', '&', 'pebbles']
15404 function words(string, pattern, guard) {
15405 string = toString(string);
15406 pattern = guard ? undefined : pattern;
15408 if (pattern === undefined) {
15409 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
15411 return string.match(pattern) || [];
15414 /*------------------------------------------------------------------------*/
15417 * Attempts to invoke `func`, returning either the result or the caught error
15418 * object. Any additional arguments are provided to `func` when it's invoked.
15424 * @param {Function} func The function to attempt.
15425 * @param {...*} [args] The arguments to invoke `func` with.
15426 * @returns {*} Returns the `func` result or error object.
15429 * // Avoid throwing errors for invalid selectors.
15430 * var elements = _.attempt(function(selector) {
15431 * return document.querySelectorAll(selector);
15434 * if (_.isError(elements)) {
15438 var attempt = baseRest(function(func, args) {
15440 return apply(func, undefined, args);
15442 return isError(e) ? e : new Error(e);
15447 * Binds methods of an object to the object itself, overwriting the existing
15450 * **Note:** This method doesn't set the "length" property of bound functions.
15456 * @param {Object} object The object to bind and assign the bound methods to.
15457 * @param {...(string|string[])} methodNames The object method names to bind.
15458 * @returns {Object} Returns `object`.
15463 * 'click': function() {
15464 * console.log('clicked ' + this.label);
15468 * _.bindAll(view, ['click']);
15469 * jQuery(element).on('click', view.click);
15470 * // => Logs 'clicked docs' when clicked.
15472 var bindAll = flatRest(function(object, methodNames) {
15473 arrayEach(methodNames, function(key) {
15475 baseAssignValue(object, key, bind(object[key], object));
15481 * Creates a function that iterates over `pairs` and invokes the corresponding
15482 * function of the first predicate to return truthy. The predicate-function
15483 * pairs are invoked with the `this` binding and arguments of the created
15490 * @param {Array} pairs The predicate-function pairs.
15491 * @returns {Function} Returns the new composite function.
15494 * var func = _.cond([
15495 * [_.matches({ 'a': 1 }), _.constant('matches A')],
15496 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
15497 * [_.stubTrue, _.constant('no match')]
15500 * func({ 'a': 1, 'b': 2 });
15501 * // => 'matches A'
15503 * func({ 'a': 0, 'b': 1 });
15504 * // => 'matches B'
15506 * func({ 'a': '1', 'b': '2' });
15509 function cond(pairs) {
15510 var length = pairs == null ? 0 : pairs.length,
15511 toIteratee = getIteratee();
15513 pairs = !length ? [] : arrayMap(pairs, function(pair) {
15514 if (typeof pair[1] != 'function') {
15515 throw new TypeError(FUNC_ERROR_TEXT);
15517 return [toIteratee(pair[0]), pair[1]];
15520 return baseRest(function(args) {
15522 while (++index < length) {
15523 var pair = pairs[index];
15524 if (apply(pair[0], this, args)) {
15525 return apply(pair[1], this, args);
15532 * Creates a function that invokes the predicate properties of `source` with
15533 * the corresponding property values of a given object, returning `true` if
15534 * all predicates return truthy, else `false`.
15536 * **Note:** The created function is equivalent to `_.conformsTo` with
15537 * `source` partially applied.
15543 * @param {Object} source The object of property predicates to conform to.
15544 * @returns {Function} Returns the new spec function.
15548 * { 'a': 2, 'b': 1 },
15549 * { 'a': 1, 'b': 2 }
15552 * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
15553 * // => [{ 'a': 1, 'b': 2 }]
15555 function conforms(source) {
15556 return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
15560 * Creates a function that returns `value`.
15566 * @param {*} value The value to return from the new function.
15567 * @returns {Function} Returns the new constant function.
15570 * var objects = _.times(2, _.constant({ 'a': 1 }));
15572 * console.log(objects);
15573 * // => [{ 'a': 1 }, { 'a': 1 }]
15575 * console.log(objects[0] === objects[1]);
15578 function constant(value) {
15579 return function() {
15585 * Checks `value` to determine whether a default value should be returned in
15586 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
15593 * @param {*} value The value to check.
15594 * @param {*} defaultValue The default value.
15595 * @returns {*} Returns the resolved value.
15598 * _.defaultTo(1, 10);
15601 * _.defaultTo(undefined, 10);
15604 function defaultTo(value, defaultValue) {
15605 return (value == null || value !== value) ? defaultValue : value;
15609 * Creates a function that returns the result of invoking the given functions
15610 * with the `this` binding of the created function, where each successive
15611 * invocation is supplied the return value of the previous.
15617 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15618 * @returns {Function} Returns the new composite function.
15622 * function square(n) {
15626 * var addSquare = _.flow([_.add, square]);
15630 var flow = createFlow();
15633 * This method is like `_.flow` except that it creates a function that
15634 * invokes the given functions from right to left.
15640 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15641 * @returns {Function} Returns the new composite function.
15645 * function square(n) {
15649 * var addSquare = _.flowRight([square, _.add]);
15653 var flowRight = createFlow(true);
15656 * This method returns the first argument it receives.
15662 * @param {*} value Any value.
15663 * @returns {*} Returns `value`.
15666 * var object = { 'a': 1 };
15668 * console.log(_.identity(object) === object);
15671 function identity(value) {
15676 * Creates a function that invokes `func` with the arguments of the created
15677 * function. If `func` is a property name, the created function returns the
15678 * property value for a given element. If `func` is an array or object, the
15679 * created function returns `true` for elements that contain the equivalent
15680 * source properties, otherwise it returns `false`.
15686 * @param {*} [func=_.identity] The value to convert to a callback.
15687 * @returns {Function} Returns the callback.
15691 * { 'user': 'barney', 'age': 36, 'active': true },
15692 * { 'user': 'fred', 'age': 40, 'active': false }
15695 * // The `_.matches` iteratee shorthand.
15696 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
15697 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
15699 * // The `_.matchesProperty` iteratee shorthand.
15700 * _.filter(users, _.iteratee(['user', 'fred']));
15701 * // => [{ 'user': 'fred', 'age': 40 }]
15703 * // The `_.property` iteratee shorthand.
15704 * _.map(users, _.iteratee('user'));
15705 * // => ['barney', 'fred']
15707 * // Create custom iteratee shorthands.
15708 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
15709 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
15710 * return func.test(string);
15714 * _.filter(['abc', 'def'], /ef/);
15717 function iteratee(func) {
15718 return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
15722 * Creates a function that performs a partial deep comparison between a given
15723 * object and `source`, returning `true` if the given object has equivalent
15724 * property values, else `false`.
15726 * **Note:** The created function is equivalent to `_.isMatch` with `source`
15727 * partially applied.
15729 * Partial comparisons will match empty array and empty object `source`
15730 * values against any array or object value, respectively. See `_.isEqual`
15731 * for a list of supported value comparisons.
15733 * **Note:** Multiple values can be checked by combining several matchers
15734 * using `_.overSome`
15740 * @param {Object} source The object of property values to match.
15741 * @returns {Function} Returns the new spec function.
15745 * { 'a': 1, 'b': 2, 'c': 3 },
15746 * { 'a': 4, 'b': 5, 'c': 6 }
15749 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
15750 * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
15752 * // Checking for several possible values
15753 * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
15754 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
15756 function matches(source) {
15757 return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
15761 * Creates a function that performs a partial deep comparison between the
15762 * value at `path` of a given object to `srcValue`, returning `true` if the
15763 * object value is equivalent, else `false`.
15765 * **Note:** Partial comparisons will match empty array and empty object
15766 * `srcValue` values against any array or object value, respectively. See
15767 * `_.isEqual` for a list of supported value comparisons.
15769 * **Note:** Multiple values can be checked by combining several matchers
15770 * using `_.overSome`
15776 * @param {Array|string} path The path of the property to get.
15777 * @param {*} srcValue The value to match.
15778 * @returns {Function} Returns the new spec function.
15782 * { 'a': 1, 'b': 2, 'c': 3 },
15783 * { 'a': 4, 'b': 5, 'c': 6 }
15786 * _.find(objects, _.matchesProperty('a', 4));
15787 * // => { 'a': 4, 'b': 5, 'c': 6 }
15789 * // Checking for several possible values
15790 * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
15791 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
15793 function matchesProperty(path, srcValue) {
15794 return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
15798 * Creates a function that invokes the method at `path` of a given object.
15799 * Any additional arguments are provided to the invoked method.
15805 * @param {Array|string} path The path of the method to invoke.
15806 * @param {...*} [args] The arguments to invoke the method with.
15807 * @returns {Function} Returns the new invoker function.
15811 * { 'a': { 'b': _.constant(2) } },
15812 * { 'a': { 'b': _.constant(1) } }
15815 * _.map(objects, _.method('a.b'));
15818 * _.map(objects, _.method(['a', 'b']));
15821 var method = baseRest(function(path, args) {
15822 return function(object) {
15823 return baseInvoke(object, path, args);
15828 * The opposite of `_.method`; this method creates a function that invokes
15829 * the method at a given path of `object`. Any additional arguments are
15830 * provided to the invoked method.
15836 * @param {Object} object The object to query.
15837 * @param {...*} [args] The arguments to invoke the method with.
15838 * @returns {Function} Returns the new invoker function.
15841 * var array = _.times(3, _.constant),
15842 * object = { 'a': array, 'b': array, 'c': array };
15844 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
15847 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
15850 var methodOf = baseRest(function(object, args) {
15851 return function(path) {
15852 return baseInvoke(object, path, args);
15857 * Adds all own enumerable string keyed function properties of a source
15858 * object to the destination object. If `object` is a function, then methods
15859 * are added to its prototype as well.
15861 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
15862 * avoid conflicts caused by modifying the original.
15868 * @param {Function|Object} [object=lodash] The destination object.
15869 * @param {Object} source The object of functions to add.
15870 * @param {Object} [options={}] The options object.
15871 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
15872 * @returns {Function|Object} Returns `object`.
15875 * function vowels(string) {
15876 * return _.filter(string, function(v) {
15877 * return /[aeiou]/i.test(v);
15881 * _.mixin({ 'vowels': vowels });
15882 * _.vowels('fred');
15885 * _('fred').vowels().value();
15888 * _.mixin({ 'vowels': vowels }, { 'chain': false });
15889 * _('fred').vowels();
15892 function mixin(object, source, options) {
15893 var props = keys(source),
15894 methodNames = baseFunctions(source, props);
15896 if (options == null &&
15897 !(isObject(source) && (methodNames.length || !props.length))) {
15901 methodNames = baseFunctions(source, keys(source));
15903 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
15904 isFunc = isFunction(object);
15906 arrayEach(methodNames, function(methodName) {
15907 var func = source[methodName];
15908 object[methodName] = func;
15910 object.prototype[methodName] = function() {
15911 var chainAll = this.__chain__;
15912 if (chain || chainAll) {
15913 var result = object(this.__wrapped__),
15914 actions = result.__actions__ = copyArray(this.__actions__);
15921 result.__chain__ = chainAll;
15924 return func.apply(object, arrayPush([this.value()], arguments));
15933 * Reverts the `_` variable to its previous value and returns a reference to
15934 * the `lodash` function.
15940 * @returns {Function} Returns the `lodash` function.
15943 * var lodash = _.noConflict();
15945 function noConflict() {
15946 if (root._ === this) {
15953 * This method returns `undefined`.
15961 * _.times(2, _.noop);
15962 * // => [undefined, undefined]
15965 // No operation performed.
15969 * Creates a function that gets the argument at index `n`. If `n` is negative,
15970 * the nth argument from the end is returned.
15976 * @param {number} [n=0] The index of the argument to return.
15977 * @returns {Function} Returns the new pass-thru function.
15980 * var func = _.nthArg(1);
15981 * func('a', 'b', 'c', 'd');
15984 * var func = _.nthArg(-2);
15985 * func('a', 'b', 'c', 'd');
15988 function nthArg(n) {
15990 return baseRest(function(args) {
15991 return baseNth(args, n);
15996 * Creates a function that invokes `iteratees` with the arguments it receives
15997 * and returns their results.
16003 * @param {...(Function|Function[])} [iteratees=[_.identity]]
16004 * The iteratees to invoke.
16005 * @returns {Function} Returns the new function.
16008 * var func = _.over([Math.max, Math.min]);
16010 * func(1, 2, 3, 4);
16013 var over = createOver(arrayMap);
16016 * Creates a function that checks if **all** of the `predicates` return
16017 * truthy when invoked with the arguments it receives.
16019 * Following shorthands are possible for providing predicates.
16020 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
16021 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
16027 * @param {...(Function|Function[])} [predicates=[_.identity]]
16028 * The predicates to check.
16029 * @returns {Function} Returns the new function.
16032 * var func = _.overEvery([Boolean, isFinite]);
16043 var overEvery = createOver(arrayEvery);
16046 * Creates a function that checks if **any** of the `predicates` return
16047 * truthy when invoked with the arguments it receives.
16049 * Following shorthands are possible for providing predicates.
16050 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
16051 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
16057 * @param {...(Function|Function[])} [predicates=[_.identity]]
16058 * The predicates to check.
16059 * @returns {Function} Returns the new function.
16062 * var func = _.overSome([Boolean, isFinite]);
16073 * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
16074 * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
16076 var overSome = createOver(arraySome);
16079 * Creates a function that returns the value at `path` of a given object.
16085 * @param {Array|string} path The path of the property to get.
16086 * @returns {Function} Returns the new accessor function.
16090 * { 'a': { 'b': 2 } },
16091 * { 'a': { 'b': 1 } }
16094 * _.map(objects, _.property('a.b'));
16097 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
16100 function property(path) {
16101 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
16105 * The opposite of `_.property`; this method creates a function that returns
16106 * the value at a given path of `object`.
16112 * @param {Object} object The object to query.
16113 * @returns {Function} Returns the new accessor function.
16116 * var array = [0, 1, 2],
16117 * object = { 'a': array, 'b': array, 'c': array };
16119 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
16122 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
16125 function propertyOf(object) {
16126 return function(path) {
16127 return object == null ? undefined : baseGet(object, path);
16132 * Creates an array of numbers (positive and/or negative) progressing from
16133 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
16134 * `start` is specified without an `end` or `step`. If `end` is not specified,
16135 * it's set to `start` with `start` then set to `0`.
16137 * **Note:** JavaScript follows the IEEE-754 standard for resolving
16138 * floating-point values which can produce unexpected results.
16144 * @param {number} [start=0] The start of the range.
16145 * @param {number} end The end of the range.
16146 * @param {number} [step=1] The value to increment or decrement by.
16147 * @returns {Array} Returns the range of numbers.
16148 * @see _.inRange, _.rangeRight
16152 * // => [0, 1, 2, 3]
16155 * // => [0, -1, -2, -3]
16158 * // => [1, 2, 3, 4]
16160 * _.range(0, 20, 5);
16161 * // => [0, 5, 10, 15]
16163 * _.range(0, -4, -1);
16164 * // => [0, -1, -2, -3]
16166 * _.range(1, 4, 0);
16172 var range = createRange();
16175 * This method is like `_.range` except that it populates values in
16176 * descending order.
16182 * @param {number} [start=0] The start of the range.
16183 * @param {number} end The end of the range.
16184 * @param {number} [step=1] The value to increment or decrement by.
16185 * @returns {Array} Returns the range of numbers.
16186 * @see _.inRange, _.range
16190 * // => [3, 2, 1, 0]
16192 * _.rangeRight(-4);
16193 * // => [-3, -2, -1, 0]
16195 * _.rangeRight(1, 5);
16196 * // => [4, 3, 2, 1]
16198 * _.rangeRight(0, 20, 5);
16199 * // => [15, 10, 5, 0]
16201 * _.rangeRight(0, -4, -1);
16202 * // => [-3, -2, -1, 0]
16204 * _.rangeRight(1, 4, 0);
16210 var rangeRight = createRange(true);
16213 * This method returns a new empty array.
16219 * @returns {Array} Returns the new empty array.
16222 * var arrays = _.times(2, _.stubArray);
16224 * console.log(arrays);
16227 * console.log(arrays[0] === arrays[1]);
16230 function stubArray() {
16235 * This method returns `false`.
16241 * @returns {boolean} Returns `false`.
16244 * _.times(2, _.stubFalse);
16245 * // => [false, false]
16247 function stubFalse() {
16252 * This method returns a new empty object.
16258 * @returns {Object} Returns the new empty object.
16261 * var objects = _.times(2, _.stubObject);
16263 * console.log(objects);
16266 * console.log(objects[0] === objects[1]);
16269 function stubObject() {
16274 * This method returns an empty string.
16280 * @returns {string} Returns the empty string.
16283 * _.times(2, _.stubString);
16286 function stubString() {
16291 * This method returns `true`.
16297 * @returns {boolean} Returns `true`.
16300 * _.times(2, _.stubTrue);
16301 * // => [true, true]
16303 function stubTrue() {
16308 * Invokes the iteratee `n` times, returning an array of the results of
16309 * each invocation. The iteratee is invoked with one argument; (index).
16315 * @param {number} n The number of times to invoke `iteratee`.
16316 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
16317 * @returns {Array} Returns the array of results.
16320 * _.times(3, String);
16321 * // => ['0', '1', '2']
16323 * _.times(4, _.constant(0));
16324 * // => [0, 0, 0, 0]
16326 function times(n, iteratee) {
16328 if (n < 1 || n > MAX_SAFE_INTEGER) {
16331 var index = MAX_ARRAY_LENGTH,
16332 length = nativeMin(n, MAX_ARRAY_LENGTH);
16334 iteratee = getIteratee(iteratee);
16335 n -= MAX_ARRAY_LENGTH;
16337 var result = baseTimes(length, iteratee);
16338 while (++index < n) {
16345 * Converts `value` to a property path array.
16351 * @param {*} value The value to convert.
16352 * @returns {Array} Returns the new property path array.
16355 * _.toPath('a.b.c');
16356 * // => ['a', 'b', 'c']
16358 * _.toPath('a[0].b.c');
16359 * // => ['a', '0', 'b', 'c']
16361 function toPath(value) {
16362 if (isArray(value)) {
16363 return arrayMap(value, toKey);
16365 return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
16369 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
16375 * @param {string} [prefix=''] The value to prefix the ID with.
16376 * @returns {string} Returns the unique ID.
16379 * _.uniqueId('contact_');
16380 * // => 'contact_104'
16385 function uniqueId(prefix) {
16386 var id = ++idCounter;
16387 return toString(prefix) + id;
16390 /*------------------------------------------------------------------------*/
16393 * Adds two numbers.
16399 * @param {number} augend The first number in an addition.
16400 * @param {number} addend The second number in an addition.
16401 * @returns {number} Returns the total.
16407 var add = createMathOperation(function(augend, addend) {
16408 return augend + addend;
16412 * Computes `number` rounded up to `precision`.
16418 * @param {number} number The number to round up.
16419 * @param {number} [precision=0] The precision to round up to.
16420 * @returns {number} Returns the rounded up number.
16426 * _.ceil(6.004, 2);
16429 * _.ceil(6040, -2);
16432 var ceil = createRound('ceil');
16435 * Divide two numbers.
16441 * @param {number} dividend The first number in a division.
16442 * @param {number} divisor The second number in a division.
16443 * @returns {number} Returns the quotient.
16449 var divide = createMathOperation(function(dividend, divisor) {
16450 return dividend / divisor;
16454 * Computes `number` rounded down to `precision`.
16460 * @param {number} number The number to round down.
16461 * @param {number} [precision=0] The precision to round down to.
16462 * @returns {number} Returns the rounded down number.
16468 * _.floor(0.046, 2);
16471 * _.floor(4060, -2);
16474 var floor = createRound('floor');
16477 * Computes the maximum value of `array`. If `array` is empty or falsey,
16478 * `undefined` is returned.
16484 * @param {Array} array The array to iterate over.
16485 * @returns {*} Returns the maximum value.
16488 * _.max([4, 2, 8, 6]);
16494 function max(array) {
16495 return (array && array.length) ?
16496 baseExtremum(array, identity, baseGt) :
16501 * This method is like `_.max` except that it accepts `iteratee` which is
16502 * invoked for each element in `array` to generate the criterion by which
16503 * the value is ranked. The iteratee is invoked with one argument: (value).
16509 * @param {Array} array The array to iterate over.
16510 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16511 * @returns {*} Returns the maximum value.
16514 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16516 * _.maxBy(objects, function(o) { return o.n; });
16519 * // The `_.property` iteratee shorthand.
16520 * _.maxBy(objects, 'n');
16523 function maxBy(array, iteratee) {
16524 return (array && array.length) ?
16525 baseExtremum(array, getIteratee(iteratee, 2), baseGt) :
16530 * Computes the mean of the values in `array`.
16536 * @param {Array} array The array to iterate over.
16537 * @returns {number} Returns the mean.
16540 * _.mean([4, 2, 8, 6]);
16543 function mean(array) {
16544 return baseMean(array, identity);
16548 * This method is like `_.mean` except that it accepts `iteratee` which is
16549 * invoked for each element in `array` to generate the value to be averaged.
16550 * The iteratee is invoked with one argument: (value).
16556 * @param {Array} array The array to iterate over.
16557 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16558 * @returns {number} Returns the mean.
16561 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16563 * _.meanBy(objects, function(o) { return o.n; });
16566 * // The `_.property` iteratee shorthand.
16567 * _.meanBy(objects, 'n');
16570 function meanBy(array, iteratee) {
16571 return baseMean(array, getIteratee(iteratee, 2));
16575 * Computes the minimum value of `array`. If `array` is empty or falsey,
16576 * `undefined` is returned.
16582 * @param {Array} array The array to iterate over.
16583 * @returns {*} Returns the minimum value.
16586 * _.min([4, 2, 8, 6]);
16592 function min(array) {
16593 return (array && array.length) ?
16594 baseExtremum(array, identity, baseLt) :
16599 * This method is like `_.min` except that it accepts `iteratee` which is
16600 * invoked for each element in `array` to generate the criterion by which
16601 * the value is ranked. The iteratee is invoked with one argument: (value).
16607 * @param {Array} array The array to iterate over.
16608 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16609 * @returns {*} Returns the minimum value.
16612 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16614 * _.minBy(objects, function(o) { return o.n; });
16617 * // The `_.property` iteratee shorthand.
16618 * _.minBy(objects, 'n');
16621 function minBy(array, iteratee) {
16622 return (array && array.length) ?
16623 baseExtremum(array, getIteratee(iteratee, 2), baseLt) :
16628 * Multiply two numbers.
16634 * @param {number} multiplier The first number in a multiplication.
16635 * @param {number} multiplicand The second number in a multiplication.
16636 * @returns {number} Returns the product.
16639 * _.multiply(6, 4);
16642 var multiply = createMathOperation(function(multiplier, multiplicand) {
16643 return multiplier * multiplicand;
16647 * Computes `number` rounded to `precision`.
16653 * @param {number} number The number to round.
16654 * @param {number} [precision=0] The precision to round to.
16655 * @returns {number} Returns the rounded number.
16661 * _.round(4.006, 2);
16664 * _.round(4060, -2);
16667 var round = createRound('round');
16670 * Subtract two numbers.
16676 * @param {number} minuend The first number in a subtraction.
16677 * @param {number} subtrahend The second number in a subtraction.
16678 * @returns {number} Returns the difference.
16681 * _.subtract(6, 4);
16684 var subtract = createMathOperation(function(minuend, subtrahend) {
16685 return minuend - subtrahend;
16689 * Computes the sum of the values in `array`.
16695 * @param {Array} array The array to iterate over.
16696 * @returns {number} Returns the sum.
16699 * _.sum([4, 2, 8, 6]);
16702 function sum(array) {
16703 return (array && array.length) ?
16704 baseSum(array, identity) :
16709 * This method is like `_.sum` except that it accepts `iteratee` which is
16710 * invoked for each element in `array` to generate the value to be summed.
16711 * The iteratee is invoked with one argument: (value).
16717 * @param {Array} array The array to iterate over.
16718 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16719 * @returns {number} Returns the sum.
16722 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16724 * _.sumBy(objects, function(o) { return o.n; });
16727 * // The `_.property` iteratee shorthand.
16728 * _.sumBy(objects, 'n');
16731 function sumBy(array, iteratee) {
16732 return (array && array.length) ?
16733 baseSum(array, getIteratee(iteratee, 2)) :
16737 /*------------------------------------------------------------------------*/
16739 // Add methods that return wrapped values in chain sequences.
16740 lodash.after = after;
16742 lodash.assign = assign;
16743 lodash.assignIn = assignIn;
16744 lodash.assignInWith = assignInWith;
16745 lodash.assignWith = assignWith;
16747 lodash.before = before;
16748 lodash.bind = bind;
16749 lodash.bindAll = bindAll;
16750 lodash.bindKey = bindKey;
16751 lodash.castArray = castArray;
16752 lodash.chain = chain;
16753 lodash.chunk = chunk;
16754 lodash.compact = compact;
16755 lodash.concat = concat;
16756 lodash.cond = cond;
16757 lodash.conforms = conforms;
16758 lodash.constant = constant;
16759 lodash.countBy = countBy;
16760 lodash.create = create;
16761 lodash.curry = curry;
16762 lodash.curryRight = curryRight;
16763 lodash.debounce = debounce;
16764 lodash.defaults = defaults;
16765 lodash.defaultsDeep = defaultsDeep;
16766 lodash.defer = defer;
16767 lodash.delay = delay;
16768 lodash.difference = difference;
16769 lodash.differenceBy = differenceBy;
16770 lodash.differenceWith = differenceWith;
16771 lodash.drop = drop;
16772 lodash.dropRight = dropRight;
16773 lodash.dropRightWhile = dropRightWhile;
16774 lodash.dropWhile = dropWhile;
16775 lodash.fill = fill;
16776 lodash.filter = filter;
16777 lodash.flatMap = flatMap;
16778 lodash.flatMapDeep = flatMapDeep;
16779 lodash.flatMapDepth = flatMapDepth;
16780 lodash.flatten = flatten;
16781 lodash.flattenDeep = flattenDeep;
16782 lodash.flattenDepth = flattenDepth;
16783 lodash.flip = flip;
16784 lodash.flow = flow;
16785 lodash.flowRight = flowRight;
16786 lodash.fromPairs = fromPairs;
16787 lodash.functions = functions;
16788 lodash.functionsIn = functionsIn;
16789 lodash.groupBy = groupBy;
16790 lodash.initial = initial;
16791 lodash.intersection = intersection;
16792 lodash.intersectionBy = intersectionBy;
16793 lodash.intersectionWith = intersectionWith;
16794 lodash.invert = invert;
16795 lodash.invertBy = invertBy;
16796 lodash.invokeMap = invokeMap;
16797 lodash.iteratee = iteratee;
16798 lodash.keyBy = keyBy;
16799 lodash.keys = keys;
16800 lodash.keysIn = keysIn;
16802 lodash.mapKeys = mapKeys;
16803 lodash.mapValues = mapValues;
16804 lodash.matches = matches;
16805 lodash.matchesProperty = matchesProperty;
16806 lodash.memoize = memoize;
16807 lodash.merge = merge;
16808 lodash.mergeWith = mergeWith;
16809 lodash.method = method;
16810 lodash.methodOf = methodOf;
16811 lodash.mixin = mixin;
16812 lodash.negate = negate;
16813 lodash.nthArg = nthArg;
16814 lodash.omit = omit;
16815 lodash.omitBy = omitBy;
16816 lodash.once = once;
16817 lodash.orderBy = orderBy;
16818 lodash.over = over;
16819 lodash.overArgs = overArgs;
16820 lodash.overEvery = overEvery;
16821 lodash.overSome = overSome;
16822 lodash.partial = partial;
16823 lodash.partialRight = partialRight;
16824 lodash.partition = partition;
16825 lodash.pick = pick;
16826 lodash.pickBy = pickBy;
16827 lodash.property = property;
16828 lodash.propertyOf = propertyOf;
16829 lodash.pull = pull;
16830 lodash.pullAll = pullAll;
16831 lodash.pullAllBy = pullAllBy;
16832 lodash.pullAllWith = pullAllWith;
16833 lodash.pullAt = pullAt;
16834 lodash.range = range;
16835 lodash.rangeRight = rangeRight;
16836 lodash.rearg = rearg;
16837 lodash.reject = reject;
16838 lodash.remove = remove;
16839 lodash.rest = rest;
16840 lodash.reverse = reverse;
16841 lodash.sampleSize = sampleSize;
16843 lodash.setWith = setWith;
16844 lodash.shuffle = shuffle;
16845 lodash.slice = slice;
16846 lodash.sortBy = sortBy;
16847 lodash.sortedUniq = sortedUniq;
16848 lodash.sortedUniqBy = sortedUniqBy;
16849 lodash.split = split;
16850 lodash.spread = spread;
16851 lodash.tail = tail;
16852 lodash.take = take;
16853 lodash.takeRight = takeRight;
16854 lodash.takeRightWhile = takeRightWhile;
16855 lodash.takeWhile = takeWhile;
16857 lodash.throttle = throttle;
16858 lodash.thru = thru;
16859 lodash.toArray = toArray;
16860 lodash.toPairs = toPairs;
16861 lodash.toPairsIn = toPairsIn;
16862 lodash.toPath = toPath;
16863 lodash.toPlainObject = toPlainObject;
16864 lodash.transform = transform;
16865 lodash.unary = unary;
16866 lodash.union = union;
16867 lodash.unionBy = unionBy;
16868 lodash.unionWith = unionWith;
16869 lodash.uniq = uniq;
16870 lodash.uniqBy = uniqBy;
16871 lodash.uniqWith = uniqWith;
16872 lodash.unset = unset;
16873 lodash.unzip = unzip;
16874 lodash.unzipWith = unzipWith;
16875 lodash.update = update;
16876 lodash.updateWith = updateWith;
16877 lodash.values = values;
16878 lodash.valuesIn = valuesIn;
16879 lodash.without = without;
16880 lodash.words = words;
16881 lodash.wrap = wrap;
16883 lodash.xorBy = xorBy;
16884 lodash.xorWith = xorWith;
16886 lodash.zipObject = zipObject;
16887 lodash.zipObjectDeep = zipObjectDeep;
16888 lodash.zipWith = zipWith;
16891 lodash.entries = toPairs;
16892 lodash.entriesIn = toPairsIn;
16893 lodash.extend = assignIn;
16894 lodash.extendWith = assignInWith;
16896 // Add methods to `lodash.prototype`.
16897 mixin(lodash, lodash);
16899 /*------------------------------------------------------------------------*/
16901 // Add methods that return unwrapped values in chain sequences.
16903 lodash.attempt = attempt;
16904 lodash.camelCase = camelCase;
16905 lodash.capitalize = capitalize;
16906 lodash.ceil = ceil;
16907 lodash.clamp = clamp;
16908 lodash.clone = clone;
16909 lodash.cloneDeep = cloneDeep;
16910 lodash.cloneDeepWith = cloneDeepWith;
16911 lodash.cloneWith = cloneWith;
16912 lodash.conformsTo = conformsTo;
16913 lodash.deburr = deburr;
16914 lodash.defaultTo = defaultTo;
16915 lodash.divide = divide;
16916 lodash.endsWith = endsWith;
16918 lodash.escape = escape;
16919 lodash.escapeRegExp = escapeRegExp;
16920 lodash.every = every;
16921 lodash.find = find;
16922 lodash.findIndex = findIndex;
16923 lodash.findKey = findKey;
16924 lodash.findLast = findLast;
16925 lodash.findLastIndex = findLastIndex;
16926 lodash.findLastKey = findLastKey;
16927 lodash.floor = floor;
16928 lodash.forEach = forEach;
16929 lodash.forEachRight = forEachRight;
16930 lodash.forIn = forIn;
16931 lodash.forInRight = forInRight;
16932 lodash.forOwn = forOwn;
16933 lodash.forOwnRight = forOwnRight;
16938 lodash.hasIn = hasIn;
16939 lodash.head = head;
16940 lodash.identity = identity;
16941 lodash.includes = includes;
16942 lodash.indexOf = indexOf;
16943 lodash.inRange = inRange;
16944 lodash.invoke = invoke;
16945 lodash.isArguments = isArguments;
16946 lodash.isArray = isArray;
16947 lodash.isArrayBuffer = isArrayBuffer;
16948 lodash.isArrayLike = isArrayLike;
16949 lodash.isArrayLikeObject = isArrayLikeObject;
16950 lodash.isBoolean = isBoolean;
16951 lodash.isBuffer = isBuffer;
16952 lodash.isDate = isDate;
16953 lodash.isElement = isElement;
16954 lodash.isEmpty = isEmpty;
16955 lodash.isEqual = isEqual;
16956 lodash.isEqualWith = isEqualWith;
16957 lodash.isError = isError;
16958 lodash.isFinite = isFinite;
16959 lodash.isFunction = isFunction;
16960 lodash.isInteger = isInteger;
16961 lodash.isLength = isLength;
16962 lodash.isMap = isMap;
16963 lodash.isMatch = isMatch;
16964 lodash.isMatchWith = isMatchWith;
16965 lodash.isNaN = isNaN;
16966 lodash.isNative = isNative;
16967 lodash.isNil = isNil;
16968 lodash.isNull = isNull;
16969 lodash.isNumber = isNumber;
16970 lodash.isObject = isObject;
16971 lodash.isObjectLike = isObjectLike;
16972 lodash.isPlainObject = isPlainObject;
16973 lodash.isRegExp = isRegExp;
16974 lodash.isSafeInteger = isSafeInteger;
16975 lodash.isSet = isSet;
16976 lodash.isString = isString;
16977 lodash.isSymbol = isSymbol;
16978 lodash.isTypedArray = isTypedArray;
16979 lodash.isUndefined = isUndefined;
16980 lodash.isWeakMap = isWeakMap;
16981 lodash.isWeakSet = isWeakSet;
16982 lodash.join = join;
16983 lodash.kebabCase = kebabCase;
16984 lodash.last = last;
16985 lodash.lastIndexOf = lastIndexOf;
16986 lodash.lowerCase = lowerCase;
16987 lodash.lowerFirst = lowerFirst;
16991 lodash.maxBy = maxBy;
16992 lodash.mean = mean;
16993 lodash.meanBy = meanBy;
16995 lodash.minBy = minBy;
16996 lodash.stubArray = stubArray;
16997 lodash.stubFalse = stubFalse;
16998 lodash.stubObject = stubObject;
16999 lodash.stubString = stubString;
17000 lodash.stubTrue = stubTrue;
17001 lodash.multiply = multiply;
17003 lodash.noConflict = noConflict;
17004 lodash.noop = noop;
17007 lodash.padEnd = padEnd;
17008 lodash.padStart = padStart;
17009 lodash.parseInt = parseInt;
17010 lodash.random = random;
17011 lodash.reduce = reduce;
17012 lodash.reduceRight = reduceRight;
17013 lodash.repeat = repeat;
17014 lodash.replace = replace;
17015 lodash.result = result;
17016 lodash.round = round;
17017 lodash.runInContext = runInContext;
17018 lodash.sample = sample;
17019 lodash.size = size;
17020 lodash.snakeCase = snakeCase;
17021 lodash.some = some;
17022 lodash.sortedIndex = sortedIndex;
17023 lodash.sortedIndexBy = sortedIndexBy;
17024 lodash.sortedIndexOf = sortedIndexOf;
17025 lodash.sortedLastIndex = sortedLastIndex;
17026 lodash.sortedLastIndexBy = sortedLastIndexBy;
17027 lodash.sortedLastIndexOf = sortedLastIndexOf;
17028 lodash.startCase = startCase;
17029 lodash.startsWith = startsWith;
17030 lodash.subtract = subtract;
17032 lodash.sumBy = sumBy;
17033 lodash.template = template;
17034 lodash.times = times;
17035 lodash.toFinite = toFinite;
17036 lodash.toInteger = toInteger;
17037 lodash.toLength = toLength;
17038 lodash.toLower = toLower;
17039 lodash.toNumber = toNumber;
17040 lodash.toSafeInteger = toSafeInteger;
17041 lodash.toString = toString;
17042 lodash.toUpper = toUpper;
17043 lodash.trim = trim;
17044 lodash.trimEnd = trimEnd;
17045 lodash.trimStart = trimStart;
17046 lodash.truncate = truncate;
17047 lodash.unescape = unescape;
17048 lodash.uniqueId = uniqueId;
17049 lodash.upperCase = upperCase;
17050 lodash.upperFirst = upperFirst;
17053 lodash.each = forEach;
17054 lodash.eachRight = forEachRight;
17055 lodash.first = head;
17057 mixin(lodash, (function() {
17059 baseForOwn(lodash, function(func, methodName) {
17060 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
17061 source[methodName] = func;
17069 /*------------------------------------------------------------------------*/
17072 * The semantic version number.
17078 lodash.VERSION = VERSION;
17080 // Assign default placeholders.
17081 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
17082 lodash[methodName].placeholder = lodash;
17085 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
17086 arrayEach(['drop', 'take'], function(methodName, index) {
17087 LazyWrapper.prototype[methodName] = function(n) {
17088 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
17090 var result = (this.__filtered__ && !index) ?
17091 new LazyWrapper(this) :
17094 if (result.__filtered__) {
17095 result.__takeCount__ = nativeMin(n, result.__takeCount__);
17097 result.__views__.push({
17098 'size': nativeMin(n, MAX_ARRAY_LENGTH),
17099 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
17105 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
17106 return this.reverse()[methodName](n).reverse();
17110 // Add `LazyWrapper` methods that accept an `iteratee` value.
17111 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
17112 var type = index + 1,
17113 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
17115 LazyWrapper.prototype[methodName] = function(iteratee) {
17116 var result = this.clone();
17117 result.__iteratees__.push({
17118 'iteratee': getIteratee(iteratee, 3),
17121 result.__filtered__ = result.__filtered__ || isFilter;
17126 // Add `LazyWrapper` methods for `_.head` and `_.last`.
17127 arrayEach(['head', 'last'], function(methodName, index) {
17128 var takeName = 'take' + (index ? 'Right' : '');
17130 LazyWrapper.prototype[methodName] = function() {
17131 return this[takeName](1).value()[0];
17135 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
17136 arrayEach(['initial', 'tail'], function(methodName, index) {
17137 var dropName = 'drop' + (index ? '' : 'Right');
17139 LazyWrapper.prototype[methodName] = function() {
17140 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
17144 LazyWrapper.prototype.compact = function() {
17145 return this.filter(identity);
17148 LazyWrapper.prototype.find = function(predicate) {
17149 return this.filter(predicate).head();
17152 LazyWrapper.prototype.findLast = function(predicate) {
17153 return this.reverse().find(predicate);
17156 LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
17157 if (typeof path == 'function') {
17158 return new LazyWrapper(this);
17160 return this.map(function(value) {
17161 return baseInvoke(value, path, args);
17165 LazyWrapper.prototype.reject = function(predicate) {
17166 return this.filter(negate(getIteratee(predicate)));
17169 LazyWrapper.prototype.slice = function(start, end) {
17170 start = toInteger(start);
17173 if (result.__filtered__ && (start > 0 || end < 0)) {
17174 return new LazyWrapper(result);
17177 result = result.takeRight(-start);
17178 } else if (start) {
17179 result = result.drop(start);
17181 if (end !== undefined) {
17182 end = toInteger(end);
17183 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
17188 LazyWrapper.prototype.takeRightWhile = function(predicate) {
17189 return this.reverse().takeWhile(predicate).reverse();
17192 LazyWrapper.prototype.toArray = function() {
17193 return this.take(MAX_ARRAY_LENGTH);
17196 // Add `LazyWrapper` methods to `lodash.prototype`.
17197 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
17198 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
17199 isTaker = /^(?:head|last)$/.test(methodName),
17200 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
17201 retUnwrapped = isTaker || /^find/.test(methodName);
17206 lodash.prototype[methodName] = function() {
17207 var value = this.__wrapped__,
17208 args = isTaker ? [1] : arguments,
17209 isLazy = value instanceof LazyWrapper,
17210 iteratee = args[0],
17211 useLazy = isLazy || isArray(value);
17213 var interceptor = function(value) {
17214 var result = lodashFunc.apply(lodash, arrayPush([value], args));
17215 return (isTaker && chainAll) ? result[0] : result;
17218 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
17219 // Avoid lazy use if the iteratee has a "length" value other than `1`.
17220 isLazy = useLazy = false;
17222 var chainAll = this.__chain__,
17223 isHybrid = !!this.__actions__.length,
17224 isUnwrapped = retUnwrapped && !chainAll,
17225 onlyLazy = isLazy && !isHybrid;
17227 if (!retUnwrapped && useLazy) {
17228 value = onlyLazy ? value : new LazyWrapper(this);
17229 var result = func.apply(value, args);
17230 result.__actions__.push({
17232 'args': [interceptor],
17233 'thisArg': undefined
17235 return new LodashWrapper(result, chainAll);
17237 if (isUnwrapped && onlyLazy) {
17238 return func.apply(this, args);
17240 result = this.thru(interceptor);
17241 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
17245 // Add `Array` methods to `lodash.prototype`.
17246 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
17247 var func = arrayProto[methodName],
17248 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
17249 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
17251 lodash.prototype[methodName] = function() {
17252 var args = arguments;
17253 if (retUnwrapped && !this.__chain__) {
17254 var value = this.value();
17255 return func.apply(isArray(value) ? value : [], args);
17257 return this[chainName](function(value) {
17258 return func.apply(isArray(value) ? value : [], args);
17263 // Map minified method names to their real names.
17264 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
17265 var lodashFunc = lodash[methodName];
17267 var key = lodashFunc.name + '';
17268 if (!hasOwnProperty.call(realNames, key)) {
17269 realNames[key] = [];
17271 realNames[key].push({
17272 'name': methodName,
17278 realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
17283 // Add methods to `LazyWrapper`.
17284 LazyWrapper.prototype.clone = lazyClone;
17285 LazyWrapper.prototype.reverse = lazyReverse;
17286 LazyWrapper.prototype.value = lazyValue;
17288 // Add chain sequence methods to the `lodash` wrapper.
17289 lodash.prototype.at = wrapperAt;
17290 lodash.prototype.chain = wrapperChain;
17291 lodash.prototype.commit = wrapperCommit;
17292 lodash.prototype.next = wrapperNext;
17293 lodash.prototype.plant = wrapperPlant;
17294 lodash.prototype.reverse = wrapperReverse;
17295 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
17297 // Add lazy aliases.
17298 lodash.prototype.first = lodash.prototype.head;
17301 lodash.prototype[symIterator] = wrapperToIterator;
17306 /*--------------------------------------------------------------------------*/
17309 var _ = runInContext();
17311 // Some AMD build optimizers, like r.js, check for condition patterns like:
17312 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
17313 // Expose Lodash on the global object to prevent errors when Lodash is
17314 // loaded by a script tag in the presence of an AMD loader.
17315 // See http://requirejs.org/docs/errors.html#mismatch for more details.
17316 // Use `_.noConflict` to remove Lodash from the global object.
17319 // Define as an anonymous module so, through path mapping, it can be
17320 // referenced as the "underscore" module.
17321 define(function() {
17325 // Check for `exports` after `define` in case a build optimizer adds it.
17326 else if (freeModule) {
17327 // Export for Node.js.
17328 (freeModule.exports = _)._ = _;
17329 // Export for CommonJS support.
17332 // Export to the global object.