3 * lodash 4.5.1 (Custom Build) <https://lodash.com/>
4 * Build: `lodash -o ./dist/lodash.js`
5 * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
15 /** Used as the semantic version number. */
16 var VERSION = '4.5.1';
18 /** Used to compose bitmasks for wrapper metadata. */
23 CURRY_RIGHT_FLAG = 16,
25 PARTIAL_RIGHT_FLAG = 64,
30 /** Used to compose bitmasks for comparison styles. */
31 var UNORDERED_COMPARE_FLAG = 1,
32 PARTIAL_COMPARE_FLAG = 2;
34 /** Used as default options for `_.truncate`. */
35 var DEFAULT_TRUNC_LENGTH = 30,
36 DEFAULT_TRUNC_OMISSION = '...';
38 /** Used to detect hot functions by number of calls within a span of milliseconds. */
42 /** Used as the size to enable large array optimizations. */
43 var LARGE_ARRAY_SIZE = 200;
45 /** Used to indicate the type of lazy iteratees. */
46 var LAZY_FILTER_FLAG = 1,
50 /** Used as the `TypeError` message for "Functions" methods. */
51 var FUNC_ERROR_TEXT = 'Expected a function';
53 /** Used to stand-in for `undefined` hash values. */
54 var HASH_UNDEFINED = '__lodash_hash_undefined__';
56 /** Used as references for various `Number` constants. */
58 MAX_SAFE_INTEGER = 9007199254740991,
59 MAX_INTEGER = 1.7976931348623157e+308,
62 /** Used as references for the maximum length and index of an array. */
63 var MAX_ARRAY_LENGTH = 4294967295,
64 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
65 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
67 /** Used as the internal argument placeholder. */
68 var PLACEHOLDER = '__lodash_placeholder__';
70 /** `Object#toString` result references. */
71 var argsTag = '[object Arguments]',
72 arrayTag = '[object Array]',
73 boolTag = '[object Boolean]',
74 dateTag = '[object Date]',
75 errorTag = '[object Error]',
76 funcTag = '[object Function]',
77 genTag = '[object GeneratorFunction]',
78 mapTag = '[object Map]',
79 numberTag = '[object Number]',
80 objectTag = '[object Object]',
81 regexpTag = '[object RegExp]',
82 setTag = '[object Set]',
83 stringTag = '[object String]',
84 symbolTag = '[object Symbol]',
85 weakMapTag = '[object WeakMap]',
86 weakSetTag = '[object WeakSet]';
88 var arrayBufferTag = '[object ArrayBuffer]',
89 float32Tag = '[object Float32Array]',
90 float64Tag = '[object Float64Array]',
91 int8Tag = '[object Int8Array]',
92 int16Tag = '[object Int16Array]',
93 int32Tag = '[object Int32Array]',
94 uint8Tag = '[object Uint8Array]',
95 uint8ClampedTag = '[object Uint8ClampedArray]',
96 uint16Tag = '[object Uint16Array]',
97 uint32Tag = '[object Uint32Array]';
99 /** Used to match empty string literals in compiled template source. */
100 var reEmptyStringLeading = /\b__p \+= '';/g,
101 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
102 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
104 /** Used to match HTML entities and HTML characters. */
105 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
106 reUnescapedHtml = /[&<>"'`]/g,
107 reHasEscapedHtml = RegExp(reEscapedHtml.source),
108 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
110 /** Used to match template delimiters. */
111 var reEscape = /<%-([\s\S]+?)%>/g,
112 reEvaluate = /<%([\s\S]+?)%>/g,
113 reInterpolate = /<%=([\s\S]+?)%>/g;
115 /** Used to match property names within property paths. */
116 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
117 reIsPlainProp = /^\w*$/,
118 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
120 /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */
121 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
122 reHasRegExpChar = RegExp(reRegExpChar.source);
124 /** Used to match leading and trailing whitespace. */
125 var reTrim = /^\s+|\s+$/g,
126 reTrimStart = /^\s+/,
129 /** Used to match backslashes in property paths. */
130 var reEscapeChar = /\\(\\)?/g;
132 /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
133 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
135 /** Used to match `RegExp` flags from their coerced string values. */
136 var reFlags = /\w*$/;
138 /** Used to detect hexadecimal string values. */
139 var reHasHexPrefix = /^0x/i;
141 /** Used to detect bad signed hexadecimal string values. */
142 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
144 /** Used to detect binary string values. */
145 var reIsBinary = /^0b[01]+$/i;
147 /** Used to detect host constructors (Safari > 5). */
148 var reIsHostCtor = /^\[object .+?Constructor\]$/;
150 /** Used to detect octal string values. */
151 var reIsOctal = /^0o[0-7]+$/i;
153 /** Used to detect unsigned integer values. */
154 var reIsUint = /^(?:0|[1-9]\d*)$/;
156 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
157 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
159 /** Used to ensure capturing order of template delimiters. */
160 var reNoMatch = /($^)/;
162 /** Used to match unescaped characters in compiled string literals. */
163 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
165 /** Used to compose unicode character classes. */
166 var rsAstralRange = '\\ud800-\\udfff',
167 rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
168 rsComboSymbolsRange = '\\u20d0-\\u20f0',
169 rsDingbatRange = '\\u2700-\\u27bf',
170 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
171 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
172 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
173 rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d',
174 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',
175 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
176 rsVarRange = '\\ufe0e\\ufe0f',
177 rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange;
179 /** Used to compose unicode capture groups. */
180 var rsAstral = '[' + rsAstralRange + ']',
181 rsBreak = '[' + rsBreakRange + ']',
182 rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
184 rsDingbat = '[' + rsDingbatRange + ']',
185 rsLower = '[' + rsLowerRange + ']',
186 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
187 rsFitz = '\\ud83c[\\udffb-\\udfff]',
188 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
189 rsNonAstral = '[^' + rsAstralRange + ']',
190 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
191 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
192 rsUpper = '[' + rsUpperRange + ']',
195 /** Used to compose unicode regexes. */
196 var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
197 rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
198 reOptMod = rsModifier + '?',
199 rsOptVar = '[' + rsVarRange + ']?',
200 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
201 rsSeq = rsOptVar + reOptMod + rsOptJoin,
202 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
203 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
206 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
207 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
209 var reComboMark = RegExp(rsCombo, 'g');
211 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
212 var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
214 /** 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/). */
215 var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
217 /** Used to match non-compound words composed of alphanumeric characters. */
218 var reBasicWord = /[a-zA-Z0-9]+/g;
220 /** Used to match complex or compound words. */
221 var reComplexWord = RegExp([
222 rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
223 rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
224 rsUpper + '?' + rsLowerMisc + '+',
230 /** Used to detect strings that need a more robust regexp to match words. */
231 var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
233 /** Used to assign default `context` object properties. */
235 'Array', 'Buffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
236 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
237 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
238 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_',
239 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
242 /** Used to make template sourceURLs easier to identify. */
243 var templateCounter = -1;
245 /** Used to identify `toStringTag` values of typed arrays. */
246 var typedArrayTags = {};
247 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
248 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
249 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
250 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
251 typedArrayTags[uint32Tag] = true;
252 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
253 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
254 typedArrayTags[dateTag] = typedArrayTags[errorTag] =
255 typedArrayTags[funcTag] = typedArrayTags[mapTag] =
256 typedArrayTags[numberTag] = typedArrayTags[objectTag] =
257 typedArrayTags[regexpTag] = typedArrayTags[setTag] =
258 typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
260 /** Used to identify `toStringTag` values supported by `_.clone`. */
261 var cloneableTags = {};
262 cloneableTags[argsTag] = cloneableTags[arrayTag] =
263 cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
264 cloneableTags[dateTag] = cloneableTags[float32Tag] =
265 cloneableTags[float64Tag] = cloneableTags[int8Tag] =
266 cloneableTags[int16Tag] = cloneableTags[int32Tag] =
267 cloneableTags[mapTag] = cloneableTags[numberTag] =
268 cloneableTags[objectTag] = cloneableTags[regexpTag] =
269 cloneableTags[setTag] = cloneableTags[stringTag] =
270 cloneableTags[symbolTag] = cloneableTags[uint8Tag] =
271 cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] =
272 cloneableTags[uint32Tag] = true;
273 cloneableTags[errorTag] = cloneableTags[funcTag] =
274 cloneableTags[weakMapTag] = false;
276 /** Used to map latin-1 supplementary letters to basic latin letters. */
277 var deburredLetters = {
278 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
279 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
280 '\xc7': 'C', '\xe7': 'c',
281 '\xd0': 'D', '\xf0': 'd',
282 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
283 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
284 '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
285 '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
286 '\xd1': 'N', '\xf1': 'n',
287 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
288 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
289 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
290 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
291 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
292 '\xc6': 'Ae', '\xe6': 'ae',
293 '\xde': 'Th', '\xfe': 'th',
297 /** Used to map characters to HTML entities. */
307 /** Used to map HTML entities to characters. */
308 var htmlUnescapes = {
317 /** Used to determine if values are of the language type `Object`. */
323 /** Used to escape characters for inclusion in compiled string literals. */
324 var stringEscapes = {
333 /** Built-in method references without a dependency on `root`. */
334 var freeParseFloat = parseFloat,
335 freeParseInt = parseInt;
337 /** Detect free variable `exports`. */
338 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
342 /** Detect free variable `module`. */
343 var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
347 /** Detect the popular CommonJS extension `module.exports`. */
348 var moduleExports = (freeModule && freeModule.exports === freeExports)
352 /** Detect free variable `global` from Node.js. */
353 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
355 /** Detect free variable `self`. */
356 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
358 /** Detect free variable `window`. */
359 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
361 /** Detect `this` as the global object. */
362 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
365 * Used as a reference to the global object.
367 * The `this` value is used if it's the global object to avoid Greasemonkey's
368 * restricted `window` object, otherwise the `window` object is used.
370 var root = freeGlobal ||
371 ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
372 freeSelf || thisGlobal || Function('return this')();
374 /*--------------------------------------------------------------------------*/
377 * Adds the key-value `pair` to `map`.
380 * @param {Object} map The map to modify.
381 * @param {Array} pair The key-value pair to add.
382 * @returns {Object} Returns `map`.
384 function addMapEntry(map, pair) {
385 map.set(pair[0], pair[1]);
390 * Adds `value` to `set`.
393 * @param {Object} set The set to modify.
394 * @param {*} value The value to add.
395 * @returns {Object} Returns `set`.
397 function addSetEntry(set, value) {
403 * A faster alternative to `Function#apply`, this function invokes `func`
404 * with the `this` binding of `thisArg` and the arguments of `args`.
407 * @param {Function} func The function to invoke.
408 * @param {*} thisArg The `this` binding of `func`.
409 * @param {...*} args The arguments to invoke `func` with.
410 * @returns {*} Returns the result of `func`.
412 function apply(func, thisArg, args) {
413 var length = args.length;
415 case 0: return func.call(thisArg);
416 case 1: return func.call(thisArg, args[0]);
417 case 2: return func.call(thisArg, args[0], args[1]);
418 case 3: return func.call(thisArg, args[0], args[1], args[2]);
420 return func.apply(thisArg, args);
424 * A specialized version of `baseAggregator` for arrays.
427 * @param {Array} array The array to iterate over.
428 * @param {Function} setter The function to set `accumulator` values.
429 * @param {Function} iteratee The iteratee to transform keys.
430 * @param {Object} accumulator The initial aggregated object.
431 * @returns {Function} Returns `accumulator`.
433 function arrayAggregator(array, setter, iteratee, accumulator) {
435 length = array.length;
437 while (++index < length) {
438 var value = array[index];
439 setter(accumulator, value, iteratee(value), array);
445 * Creates a new array concatenating `array` with `other`.
448 * @param {Array} array The first array to concatenate.
449 * @param {Array} other The second array to concatenate.
450 * @returns {Array} Returns the new concatenated array.
452 function arrayConcat(array, other) {
454 length = array.length,
456 othLength = other.length,
457 result = Array(length + othLength);
459 while (++index < length) {
460 result[index] = array[index];
462 while (++othIndex < othLength) {
463 result[index++] = other[othIndex];
469 * A specialized version of `_.forEach` for arrays without support for
470 * iteratee shorthands.
473 * @param {Array} array The array to iterate over.
474 * @param {Function} iteratee The function invoked per iteration.
475 * @returns {Array} Returns `array`.
477 function arrayEach(array, iteratee) {
479 length = array.length;
481 while (++index < length) {
482 if (iteratee(array[index], index, array) === false) {
490 * A specialized version of `_.forEachRight` for arrays without support for
491 * iteratee shorthands.
494 * @param {Array} array The array to iterate over.
495 * @param {Function} iteratee The function invoked per iteration.
496 * @returns {Array} Returns `array`.
498 function arrayEachRight(array, iteratee) {
499 var length = array.length;
502 if (iteratee(array[length], length, array) === false) {
510 * A specialized version of `_.every` for arrays without support for
511 * iteratee shorthands.
514 * @param {Array} array The array to iterate over.
515 * @param {Function} predicate The function invoked per iteration.
516 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
518 function arrayEvery(array, predicate) {
520 length = array.length;
522 while (++index < length) {
523 if (!predicate(array[index], index, array)) {
531 * A specialized version of `_.filter` for arrays without support for
532 * iteratee shorthands.
535 * @param {Array} array The array to iterate over.
536 * @param {Function} predicate The function invoked per iteration.
537 * @returns {Array} Returns the new filtered array.
539 function arrayFilter(array, predicate) {
541 length = array.length,
545 while (++index < length) {
546 var value = array[index];
547 if (predicate(value, index, array)) {
548 result[++resIndex] = value;
555 * A specialized version of `_.includes` for arrays without support for
556 * specifying an index to search from.
559 * @param {Array} array The array to search.
560 * @param {*} target The value to search for.
561 * @returns {boolean} Returns `true` if `target` is found, else `false`.
563 function arrayIncludes(array, value) {
564 return !!array.length && baseIndexOf(array, value, 0) > -1;
568 * A specialized version of `_.includesWith` for arrays without support for
569 * specifying an index to search from.
572 * @param {Array} array The array to search.
573 * @param {*} target The value to search for.
574 * @param {Function} comparator The comparator invoked per element.
575 * @returns {boolean} Returns `true` if `target` is found, else `false`.
577 function arrayIncludesWith(array, value, comparator) {
579 length = array.length;
581 while (++index < length) {
582 if (comparator(value, array[index])) {
590 * A specialized version of `_.map` for arrays without support for iteratee
594 * @param {Array} array The array to iterate over.
595 * @param {Function} iteratee The function invoked per iteration.
596 * @returns {Array} Returns the new mapped array.
598 function arrayMap(array, iteratee) {
600 length = array.length,
601 result = Array(length);
603 while (++index < length) {
604 result[index] = iteratee(array[index], index, array);
610 * Appends the elements of `values` to `array`.
613 * @param {Array} array The array to modify.
614 * @param {Array} values The values to append.
615 * @returns {Array} Returns `array`.
617 function arrayPush(array, values) {
619 length = values.length,
620 offset = array.length;
622 while (++index < length) {
623 array[offset + index] = values[index];
629 * A specialized version of `_.reduce` for arrays without support for
630 * iteratee shorthands.
633 * @param {Array} array The array to iterate over.
634 * @param {Function} iteratee The function invoked per iteration.
635 * @param {*} [accumulator] The initial value.
636 * @param {boolean} [initAccum] Specify using the first element of `array` as the initial value.
637 * @returns {*} Returns the accumulated value.
639 function arrayReduce(array, iteratee, accumulator, initAccum) {
641 length = array.length;
643 if (initAccum && length) {
644 accumulator = array[++index];
646 while (++index < length) {
647 accumulator = iteratee(accumulator, array[index], index, array);
653 * A specialized version of `_.reduceRight` for arrays without support for
654 * iteratee shorthands.
657 * @param {Array} array The array to iterate over.
658 * @param {Function} iteratee The function invoked per iteration.
659 * @param {*} [accumulator] The initial value.
660 * @param {boolean} [initAccum] Specify using the last element of `array` as the initial value.
661 * @returns {*} Returns the accumulated value.
663 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
664 var length = array.length;
665 if (initAccum && length) {
666 accumulator = array[--length];
669 accumulator = iteratee(accumulator, array[length], length, array);
675 * A specialized version of `_.some` for arrays without support for iteratee
679 * @param {Array} array The array to iterate over.
680 * @param {Function} predicate The function invoked per iteration.
681 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
683 function arraySome(array, predicate) {
685 length = array.length;
687 while (++index < length) {
688 if (predicate(array[index], index, array)) {
696 * The base implementation of methods like `_.max` and `_.min` which accepts a
697 * `comparator` to determine the extremum value.
700 * @param {Array} array The array to iterate over.
701 * @param {Function} iteratee The iteratee invoked per iteration.
702 * @param {Function} comparator The comparator used to compare values.
703 * @returns {*} Returns the extremum value.
705 function baseExtremum(array, iteratee, comparator) {
707 length = array.length;
709 while (++index < length) {
710 var value = array[index],
711 current = iteratee(value);
713 if (current != null && (computed === undefined
714 ? current === current
715 : comparator(current, computed)
717 var computed = current,
725 * The base implementation of methods like `_.find` and `_.findKey`, without
726 * support for iteratee shorthands, which iterates over `collection` using
730 * @param {Array|Object} collection The collection to search.
731 * @param {Function} predicate The function invoked per iteration.
732 * @param {Function} eachFunc The function to iterate over `collection`.
733 * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
734 * @returns {*} Returns the found element or its key, else `undefined`.
736 function baseFind(collection, predicate, eachFunc, retKey) {
738 eachFunc(collection, function(value, key, collection) {
739 if (predicate(value, key, collection)) {
740 result = retKey ? key : value;
748 * The base implementation of `_.findIndex` and `_.findLastIndex` without
749 * support for iteratee shorthands.
752 * @param {Array} array The array to search.
753 * @param {Function} predicate The function invoked per iteration.
754 * @param {boolean} [fromRight] Specify iterating from right to left.
755 * @returns {number} Returns the index of the matched value, else `-1`.
757 function baseFindIndex(array, predicate, fromRight) {
758 var length = array.length,
759 index = fromRight ? length : -1;
761 while ((fromRight ? index-- : ++index < length)) {
762 if (predicate(array[index], index, array)) {
770 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
773 * @param {Array} array The array to search.
774 * @param {*} value The value to search for.
775 * @param {number} fromIndex The index to search from.
776 * @returns {number} Returns the index of the matched value, else `-1`.
778 function baseIndexOf(array, value, fromIndex) {
779 if (value !== value) {
780 return indexOfNaN(array, fromIndex);
782 var index = fromIndex - 1,
783 length = array.length;
785 while (++index < length) {
786 if (array[index] === value) {
794 * The base implementation of `_.reduce` and `_.reduceRight`, without support
795 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
798 * @param {Array|Object} collection The collection to iterate over.
799 * @param {Function} iteratee The function invoked per iteration.
800 * @param {*} accumulator The initial value.
801 * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value.
802 * @param {Function} eachFunc The function to iterate over `collection`.
803 * @returns {*} Returns the accumulated value.
805 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
806 eachFunc(collection, function(value, index, collection) {
807 accumulator = initAccum
808 ? (initAccum = false, value)
809 : iteratee(accumulator, value, index, collection);
815 * The base implementation of `_.sortBy` which uses `comparer` to define
816 * the sort order of `array` and replaces criteria objects with their
817 * corresponding values.
820 * @param {Array} array The array to sort.
821 * @param {Function} comparer The function to define sort order.
822 * @returns {Array} Returns `array`.
824 function baseSortBy(array, comparer) {
825 var length = array.length;
827 array.sort(comparer);
829 array[length] = array[length].value;
835 * The base implementation of `_.sum` without support for iteratee shorthands.
838 * @param {Array} array The array to iterate over.
839 * @param {Function} iteratee The function invoked per iteration.
840 * @returns {number} Returns the sum.
842 function baseSum(array, iteratee) {
845 length = array.length;
847 while (++index < length) {
848 var current = iteratee(array[index]);
849 if (current !== undefined) {
850 result = result === undefined ? current : (result + current);
857 * The base implementation of `_.times` without support for iteratee shorthands
858 * or max array length checks.
861 * @param {number} n The number of times to invoke `iteratee`.
862 * @param {Function} iteratee The function invoked per iteration.
863 * @returns {Array} Returns the array of results.
865 function baseTimes(n, iteratee) {
869 while (++index < n) {
870 result[index] = iteratee(index);
876 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
877 * of key-value pairs for `object` corresponding to the property names of `props`.
880 * @param {Object} object The object to query.
881 * @param {Array} props The property names to get values for.
882 * @returns {Object} Returns the new array of key-value pairs.
884 function baseToPairs(object, props) {
885 return arrayMap(props, function(key) {
886 return [key, object[key]];
891 * The base implementation of `_.unary` without support for storing wrapper metadata.
894 * @param {Function} func The function to cap arguments for.
895 * @returns {Function} Returns the new function.
897 function baseUnary(func) {
898 return function(value) {
904 * The base implementation of `_.values` and `_.valuesIn` which creates an
905 * array of `object` property values corresponding to the property names
909 * @param {Object} object The object to query.
910 * @param {Array} props The property names to get values for.
911 * @returns {Object} Returns the array of property values.
913 function baseValues(object, props) {
914 return arrayMap(props, function(key) {
920 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
921 * that is not found in the character symbols.
924 * @param {Array} strSymbols The string symbols to inspect.
925 * @param {Array} chrSymbols The character symbols to find.
926 * @returns {number} Returns the index of the first unmatched string symbol.
928 function charsStartIndex(strSymbols, chrSymbols) {
930 length = strSymbols.length;
932 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
937 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
938 * that is not found in the character symbols.
941 * @param {Array} strSymbols The string symbols to inspect.
942 * @param {Array} chrSymbols The character symbols to find.
943 * @returns {number} Returns the index of the last unmatched string symbol.
945 function charsEndIndex(strSymbols, chrSymbols) {
946 var index = strSymbols.length;
948 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
953 * Checks if `value` is a global object.
956 * @param {*} value The value to check.
957 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
959 function checkGlobal(value) {
960 return (value && value.Object === Object) ? value : null;
964 * Compares values to sort them in ascending order.
967 * @param {*} value The value to compare.
968 * @param {*} other The other value to compare.
969 * @returns {number} Returns the sort order indicator for `value`.
971 function compareAscending(value, other) {
972 if (value !== other) {
973 var valIsNull = value === null,
974 valIsUndef = value === undefined,
975 valIsReflexive = value === value;
977 var othIsNull = other === null,
978 othIsUndef = other === undefined,
979 othIsReflexive = other === other;
981 if ((value > other && !othIsNull) || !valIsReflexive ||
982 (valIsNull && !othIsUndef && othIsReflexive) ||
983 (valIsUndef && othIsReflexive)) {
986 if ((value < other && !valIsNull) || !othIsReflexive ||
987 (othIsNull && !valIsUndef && valIsReflexive) ||
988 (othIsUndef && valIsReflexive)) {
996 * Used by `_.orderBy` to compare multiple properties of a value to another
997 * and stable sort them.
999 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
1000 * specify an order of "desc" for descending or "asc" for ascending sort order
1001 * of corresponding values.
1004 * @param {Object} object The object to compare.
1005 * @param {Object} other The other object to compare.
1006 * @param {boolean[]|string[]} orders The order to sort by for each property.
1007 * @returns {number} Returns the sort order indicator for `object`.
1009 function compareMultiple(object, other, orders) {
1011 objCriteria = object.criteria,
1012 othCriteria = other.criteria,
1013 length = objCriteria.length,
1014 ordersLength = orders.length;
1016 while (++index < length) {
1017 var result = compareAscending(objCriteria[index], othCriteria[index]);
1019 if (index >= ordersLength) {
1022 var order = orders[index];
1023 return result * (order == 'desc' ? -1 : 1);
1026 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
1027 // that causes it, under certain circumstances, to provide the same value for
1028 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
1029 // for more details.
1031 // This also ensures a stable sort in V8 and other engines.
1032 // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
1033 return object.index - other.index;
1037 * Gets the number of `placeholder` occurrences in `array`.
1040 * @param {Array} array The array to inspect.
1041 * @param {*} placeholder The placeholder to search for.
1042 * @returns {number} Returns the placeholder count.
1044 function countHolders(array, placeholder) {
1045 var length = array.length,
1049 if (array[length] === placeholder) {
1057 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
1060 * @param {string} letter The matched letter to deburr.
1061 * @returns {string} Returns the deburred letter.
1063 function deburrLetter(letter) {
1064 return deburredLetters[letter];
1068 * Used by `_.escape` to convert characters to HTML entities.
1071 * @param {string} chr The matched character to escape.
1072 * @returns {string} Returns the escaped character.
1074 function escapeHtmlChar(chr) {
1075 return htmlEscapes[chr];
1079 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1082 * @param {string} chr The matched character to escape.
1083 * @returns {string} Returns the escaped character.
1085 function escapeStringChar(chr) {
1086 return '\\' + stringEscapes[chr];
1090 * Gets the index at which the first occurrence of `NaN` is found in `array`.
1093 * @param {Array} array The array to search.
1094 * @param {number} fromIndex The index to search from.
1095 * @param {boolean} [fromRight] Specify iterating from right to left.
1096 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
1098 function indexOfNaN(array, fromIndex, fromRight) {
1099 var length = array.length,
1100 index = fromIndex + (fromRight ? 0 : -1);
1102 while ((fromRight ? index-- : ++index < length)) {
1103 var other = array[index];
1104 if (other !== other) {
1112 * Checks if `value` is a host object in IE < 9.
1115 * @param {*} value The value to check.
1116 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
1118 function isHostObject(value) {
1119 // Many host objects are `Object` objects that can coerce to strings
1120 // despite having improperly defined `toString` methods.
1122 if (value != null && typeof value.toString != 'function') {
1124 result = !!(value + '');
1131 * Checks if `value` is a valid array-like index.
1134 * @param {*} value The value to check.
1135 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1136 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1138 function isIndex(value, length) {
1139 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
1140 length = length == null ? MAX_SAFE_INTEGER : length;
1141 return value > -1 && value % 1 == 0 && value < length;
1145 * Converts `iterator` to an array.
1148 * @param {Object} iterator The iterator to convert.
1149 * @returns {Array} Returns the converted array.
1151 function iteratorToArray(iterator) {
1155 while (!(data = iterator.next()).done) {
1156 result.push(data.value);
1162 * Converts `map` to an array.
1165 * @param {Object} map The map to convert.
1166 * @returns {Array} Returns the converted array.
1168 function mapToArray(map) {
1170 result = Array(map.size);
1172 map.forEach(function(value, key) {
1173 result[++index] = [key, value];
1179 * Replaces all `placeholder` elements in `array` with an internal placeholder
1180 * and returns an array of their indexes.
1183 * @param {Array} array The array to modify.
1184 * @param {*} placeholder The placeholder to replace.
1185 * @returns {Array} Returns the new array of placeholder indexes.
1187 function replaceHolders(array, placeholder) {
1189 length = array.length,
1193 while (++index < length) {
1194 var value = array[index];
1195 if (value === placeholder || value === PLACEHOLDER) {
1196 array[index] = PLACEHOLDER;
1197 result[++resIndex] = index;
1204 * Converts `set` to an array.
1207 * @param {Object} set The set to convert.
1208 * @returns {Array} Returns the converted array.
1210 function setToArray(set) {
1212 result = Array(set.size);
1214 set.forEach(function(value) {
1215 result[++index] = value;
1221 * Gets the number of symbols in `string`.
1224 * @param {string} string The string to inspect.
1225 * @returns {number} Returns the string size.
1227 function stringSize(string) {
1228 if (!(string && reHasComplexSymbol.test(string))) {
1229 return string.length;
1231 var result = reComplexSymbol.lastIndex = 0;
1232 while (reComplexSymbol.test(string)) {
1239 * Converts `string` to an array.
1242 * @param {string} string The string to convert.
1243 * @returns {Array} Returns the converted array.
1245 function stringToArray(string) {
1246 return string.match(reComplexSymbol);
1250 * Used by `_.unescape` to convert HTML entities to characters.
1253 * @param {string} chr The matched character to unescape.
1254 * @returns {string} Returns the unescaped character.
1256 function unescapeHtmlChar(chr) {
1257 return htmlUnescapes[chr];
1260 /*--------------------------------------------------------------------------*/
1263 * Create a new pristine `lodash` function using the `context` object.
1268 * @param {Object} [context=root] The context object.
1269 * @returns {Function} Returns a new `lodash` function.
1272 * _.mixin({ 'foo': _.constant('foo') });
1274 * var lodash = _.runInContext();
1275 * lodash.mixin({ 'bar': lodash.constant('bar') });
1277 * _.isFunction(_.foo);
1279 * _.isFunction(_.bar);
1282 * lodash.isFunction(lodash.foo);
1284 * lodash.isFunction(lodash.bar);
1287 * // Use `context` to mock `Date#getTime` use in `_.now`.
1288 * var mock = _.runInContext({
1289 * 'Date': function() {
1290 * return { 'getTime': getTimeMock };
1294 * // Create a suped-up `defer` in Node.js.
1295 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1297 function runInContext(context) {
1298 context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
1300 /** Built-in constructor references. */
1301 var Date = context.Date,
1302 Error = context.Error,
1303 Math = context.Math,
1304 RegExp = context.RegExp,
1305 TypeError = context.TypeError;
1307 /** Used for built-in method references. */
1308 var arrayProto = context.Array.prototype,
1309 objectProto = context.Object.prototype;
1311 /** Used to resolve the decompiled source of functions. */
1312 var funcToString = context.Function.prototype.toString;
1314 /** Used to check objects for own properties. */
1315 var hasOwnProperty = objectProto.hasOwnProperty;
1317 /** Used to generate unique IDs. */
1320 /** Used to infer the `Object` constructor. */
1321 var objectCtorString = funcToString.call(Object);
1324 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
1327 var objectToString = objectProto.toString;
1329 /** Used to restore the original `_` reference in `_.noConflict`. */
1330 var oldDash = root._;
1332 /** Used to detect if a method is native. */
1333 var reIsNative = RegExp('^' +
1334 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1335 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1338 /** Built-in value references. */
1339 var Buffer = moduleExports ? context.Buffer : undefined,
1340 Reflect = context.Reflect,
1341 Symbol = context.Symbol,
1342 Uint8Array = context.Uint8Array,
1343 clearTimeout = context.clearTimeout,
1344 enumerate = Reflect ? Reflect.enumerate : undefined,
1345 getPrototypeOf = Object.getPrototypeOf,
1346 getOwnPropertySymbols = Object.getOwnPropertySymbols,
1347 iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
1348 objectCreate = Object.create,
1349 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1350 setTimeout = context.setTimeout,
1351 splice = arrayProto.splice;
1353 /* Built-in method references for those with the same name as other `lodash` methods. */
1354 var nativeCeil = Math.ceil,
1355 nativeFloor = Math.floor,
1356 nativeIsFinite = context.isFinite,
1357 nativeJoin = arrayProto.join,
1358 nativeKeys = Object.keys,
1359 nativeMax = Math.max,
1360 nativeMin = Math.min,
1361 nativeParseInt = context.parseInt,
1362 nativeRandom = Math.random,
1363 nativeReverse = arrayProto.reverse;
1365 /* Built-in method references that are verified to be native. */
1366 var Map = getNative(context, 'Map'),
1367 Set = getNative(context, 'Set'),
1368 WeakMap = getNative(context, 'WeakMap'),
1369 nativeCreate = getNative(Object, 'create');
1371 /** Used to store function metadata. */
1372 var metaMap = WeakMap && new WeakMap;
1374 /** Used to detect maps, sets, and weakmaps. */
1375 var mapCtorString = Map ? funcToString.call(Map) : '',
1376 setCtorString = Set ? funcToString.call(Set) : '',
1377 weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : '';
1379 /** Used to convert symbols to primitives and strings. */
1380 var symbolProto = Symbol ? Symbol.prototype : undefined,
1381 symbolValueOf = Symbol ? symbolProto.valueOf : undefined,
1382 symbolToString = Symbol ? symbolProto.toString : undefined;
1384 /** Used to lookup unminified function names. */
1387 /*------------------------------------------------------------------------*/
1390 * Creates a `lodash` object which wraps `value` to enable implicit method
1391 * chaining. Methods that operate on and return arrays, collections, and
1392 * functions can be chained together. Methods that retrieve a single value or
1393 * may return a primitive value will automatically end the chain sequence and
1394 * return the unwrapped value. Otherwise, the value must be unwrapped with
1397 * Explicit chaining, which must be unwrapped with `_#value` in all cases,
1398 * may be enabled using `_.chain`.
1400 * The execution of chained methods is lazy, that is, it's deferred until
1401 * `_#value` is implicitly or explicitly called.
1403 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
1404 * fusion is an optimization to merge iteratee calls; this avoids the creation
1405 * of intermediate arrays and can greatly reduce the number of iteratee executions.
1406 * Sections of a chain sequence qualify for shortcut fusion if the section is
1407 * applied to an array of at least two hundred elements and any iteratees
1408 * accept only one argument. The heuristic for whether a section qualifies
1409 * for shortcut fusion is subject to change.
1411 * Chaining is supported in custom builds as long as the `_#value` method is
1412 * directly or indirectly included in the build.
1414 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1416 * The wrapper `Array` methods are:
1417 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1419 * The wrapper `String` methods are:
1420 * `replace` and `split`
1422 * The wrapper methods that support shortcut fusion are:
1423 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1424 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1425 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1427 * The chainable wrapper methods are:
1428 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
1429 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
1430 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
1431 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
1432 * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
1433 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flattenDepth`,
1434 * `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, `functionsIn`,
1435 * `groupBy`, `initial`, `intersection`, `intersectionBy`, `intersectionWith`,
1436 * `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`,
1437 * `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, `memoize`,
1438 * `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, `nthArg`,
1439 * `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, `overEvery`,
1440 * `overSome`, `partial`, `partialRight`, `partition`, `pick`, `pickBy`, `plant`,
1441 * `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`,
1442 * `range`, `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
1443 * `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`,
1444 * `splice`, `spread`, `tail`, `take`, `takeRight`, `takeRightWhile`,
1445 * `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, `toPairs`, `toPairsIn`,
1446 * `toPath`, `toPlainObject`, `transform`, `unary`, `union`, `unionBy`,
1447 * `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, `unshift`, `unzip`,
1448 * `unzipWith`, `values`, `valuesIn`, `without`, `wrap`, `xor`, `xorBy`,
1449 * `xorWith`, `zip`, `zipObject`, `zipObjectDeep`, and `zipWith`
1451 * The wrapper methods that are **not** chainable by default are:
1452 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1453 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
1454 * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
1455 * `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`, `forIn`,
1456 * `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`,
1457 * `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`,
1458 * `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
1459 * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
1460 * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`,
1461 * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
1462 * `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
1463 * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`,
1464 * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`,
1465 * `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`, `noConflict`, `noop`,
1466 * `now`, `pad`, `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`,
1467 * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `sample`,
1468 * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`,
1469 * `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, `startsWith`, `subtract`,
1470 * `sum`, `sumBy`, `template`, `times`, `toLower`, `toInteger`, `toLength`,
1471 * `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, `trimEnd`,
1472 * `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, `upperFirst`,
1473 * `value`, and `words`
1478 * @param {*} value The value to wrap in a `lodash` instance.
1479 * @returns {Object} Returns the new `lodash` wrapper instance.
1482 * function square(n) {
1486 * var wrapped = _([1, 2, 3]);
1488 * // Returns an unwrapped value.
1489 * wrapped.reduce(_.add);
1492 * // Returns a wrapped value.
1493 * var squares = wrapped.map(square);
1495 * _.isArray(squares);
1498 * _.isArray(squares.value());
1501 function lodash(value) {
1502 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1503 if (value instanceof LodashWrapper) {
1506 if (hasOwnProperty.call(value, '__wrapped__')) {
1507 return wrapperClone(value);
1510 return new LodashWrapper(value);
1514 * The function whose prototype all chaining wrappers inherit from.
1518 function baseLodash() {
1519 // No operation performed.
1523 * The base constructor for creating `lodash` wrapper objects.
1526 * @param {*} value The value to wrap.
1527 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
1529 function LodashWrapper(value, chainAll) {
1530 this.__wrapped__ = value;
1531 this.__actions__ = [];
1532 this.__chain__ = !!chainAll;
1534 this.__values__ = undefined;
1538 * By default, the template delimiters used by lodash are like those in
1539 * embedded Ruby (ERB). Change the following template settings to use
1540 * alternative delimiters.
1546 lodash.templateSettings = {
1549 * Used to detect `data` property values to be HTML-escaped.
1551 * @memberOf _.templateSettings
1557 * Used to detect code to be evaluated.
1559 * @memberOf _.templateSettings
1562 'evaluate': reEvaluate,
1565 * Used to detect `data` property values to inject.
1567 * @memberOf _.templateSettings
1570 'interpolate': reInterpolate,
1573 * Used to reference the data object in the template text.
1575 * @memberOf _.templateSettings
1581 * Used to import variables into the compiled template.
1583 * @memberOf _.templateSettings
1589 * A reference to the `lodash` function.
1591 * @memberOf _.templateSettings.imports
1598 /*------------------------------------------------------------------------*/
1601 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1605 * @param {*} value The value to wrap.
1607 function LazyWrapper(value) {
1608 this.__wrapped__ = value;
1609 this.__actions__ = [];
1611 this.__filtered__ = false;
1612 this.__iteratees__ = [];
1613 this.__takeCount__ = MAX_ARRAY_LENGTH;
1614 this.__views__ = [];
1618 * Creates a clone of the lazy wrapper object.
1622 * @memberOf LazyWrapper
1623 * @returns {Object} Returns the cloned `LazyWrapper` object.
1625 function lazyClone() {
1626 var result = new LazyWrapper(this.__wrapped__);
1627 result.__actions__ = copyArray(this.__actions__);
1628 result.__dir__ = this.__dir__;
1629 result.__filtered__ = this.__filtered__;
1630 result.__iteratees__ = copyArray(this.__iteratees__);
1631 result.__takeCount__ = this.__takeCount__;
1632 result.__views__ = copyArray(this.__views__);
1637 * Reverses the direction of lazy iteration.
1641 * @memberOf LazyWrapper
1642 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1644 function lazyReverse() {
1645 if (this.__filtered__) {
1646 var result = new LazyWrapper(this);
1647 result.__dir__ = -1;
1648 result.__filtered__ = true;
1650 result = this.clone();
1651 result.__dir__ *= -1;
1657 * Extracts the unwrapped value from its lazy wrapper.
1661 * @memberOf LazyWrapper
1662 * @returns {*} Returns the unwrapped value.
1664 function lazyValue() {
1665 var array = this.__wrapped__.value(),
1667 isArr = isArray(array),
1669 arrLength = isArr ? array.length : 0,
1670 view = getView(0, arrLength, this.__views__),
1673 length = end - start,
1674 index = isRight ? end : (start - 1),
1675 iteratees = this.__iteratees__,
1676 iterLength = iteratees.length,
1678 takeCount = nativeMin(length, this.__takeCount__);
1680 if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
1681 (arrLength == length && takeCount == length)) {
1682 return baseWrapperValue(array, this.__actions__);
1687 while (length-- && resIndex < takeCount) {
1691 value = array[index];
1693 while (++iterIndex < iterLength) {
1694 var data = iteratees[iterIndex],
1695 iteratee = data.iteratee,
1697 computed = iteratee(value);
1699 if (type == LAZY_MAP_FLAG) {
1701 } else if (!computed) {
1702 if (type == LAZY_FILTER_FLAG) {
1709 result[resIndex++] = value;
1714 /*------------------------------------------------------------------------*/
1717 * Creates an hash object.
1721 * @returns {Object} Returns the new hash object.
1726 * Removes `key` and its value from the hash.
1729 * @param {Object} hash The hash to modify.
1730 * @param {string} key The key of the value to remove.
1731 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1733 function hashDelete(hash, key) {
1734 return hashHas(hash, key) && delete hash[key];
1738 * Gets the hash value for `key`.
1741 * @param {Object} hash The hash to query.
1742 * @param {string} key The key of the value to get.
1743 * @returns {*} Returns the entry value.
1745 function hashGet(hash, key) {
1747 var result = hash[key];
1748 return result === HASH_UNDEFINED ? undefined : result;
1750 return hasOwnProperty.call(hash, key) ? hash[key] : undefined;
1754 * Checks if a hash value for `key` exists.
1757 * @param {Object} hash The hash to query.
1758 * @param {string} key The key of the entry to check.
1759 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1761 function hashHas(hash, key) {
1762 return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash, key);
1766 * Sets the hash `key` to `value`.
1769 * @param {Object} hash The hash to modify.
1770 * @param {string} key The key of the value to set.
1771 * @param {*} value The value to set.
1773 function hashSet(hash, key, value) {
1774 hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
1777 /*------------------------------------------------------------------------*/
1780 * Creates a map cache object to store key-value pairs.
1784 * @param {Array} [values] The values to cache.
1786 function MapCache(values) {
1788 length = values ? values.length : 0;
1791 while (++index < length) {
1792 var entry = values[index];
1793 this.set(entry[0], entry[1]);
1798 * Removes all key-value entries from the map.
1802 * @memberOf MapCache
1804 function mapClear() {
1807 'map': Map ? new Map : [],
1813 * Removes `key` and its value from the map.
1817 * @memberOf MapCache
1818 * @param {string} key The key of the value to remove.
1819 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1821 function mapDelete(key) {
1822 var data = this.__data__;
1823 if (isKeyable(key)) {
1824 return hashDelete(typeof key == 'string' ? data.string : data.hash, key);
1826 return Map ? data.map['delete'](key) : assocDelete(data.map, key);
1830 * Gets the map value for `key`.
1834 * @memberOf MapCache
1835 * @param {string} key The key of the value to get.
1836 * @returns {*} Returns the entry value.
1838 function mapGet(key) {
1839 var data = this.__data__;
1840 if (isKeyable(key)) {
1841 return hashGet(typeof key == 'string' ? data.string : data.hash, key);
1843 return Map ? data.map.get(key) : assocGet(data.map, key);
1847 * Checks if a map value for `key` exists.
1851 * @memberOf MapCache
1852 * @param {string} key The key of the entry to check.
1853 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1855 function mapHas(key) {
1856 var data = this.__data__;
1857 if (isKeyable(key)) {
1858 return hashHas(typeof key == 'string' ? data.string : data.hash, key);
1860 return Map ? data.map.has(key) : assocHas(data.map, key);
1864 * Sets the map `key` to `value`.
1868 * @memberOf MapCache
1869 * @param {string} key The key of the value to set.
1870 * @param {*} value The value to set.
1871 * @returns {Object} Returns the map cache object.
1873 function mapSet(key, value) {
1874 var data = this.__data__;
1875 if (isKeyable(key)) {
1876 hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
1878 data.map.set(key, value);
1880 assocSet(data.map, key, value);
1885 /*------------------------------------------------------------------------*/
1889 * Creates a set cache object to store unique values.
1893 * @param {Array} [values] The values to cache.
1895 function SetCache(values) {
1897 length = values ? values.length : 0;
1899 this.__data__ = new MapCache;
1900 while (++index < length) {
1901 this.push(values[index]);
1906 * Checks if `value` is in `cache`.
1909 * @param {Object} cache The set cache to search.
1910 * @param {*} value The value to search for.
1911 * @returns {number} Returns `true` if `value` is found, else `false`.
1913 function cacheHas(cache, value) {
1914 var map = cache.__data__;
1915 if (isKeyable(value)) {
1916 var data = map.__data__,
1917 hash = typeof value == 'string' ? data.string : data.hash;
1919 return hash[value] === HASH_UNDEFINED;
1921 return map.has(value);
1925 * Adds `value` to the set cache.
1929 * @memberOf SetCache
1930 * @param {*} value The value to cache.
1932 function cachePush(value) {
1933 var map = this.__data__;
1934 if (isKeyable(value)) {
1935 var data = map.__data__,
1936 hash = typeof value == 'string' ? data.string : data.hash;
1938 hash[value] = HASH_UNDEFINED;
1941 map.set(value, HASH_UNDEFINED);
1945 /*------------------------------------------------------------------------*/
1948 * Creates a stack cache object to store key-value pairs.
1952 * @param {Array} [values] The values to cache.
1954 function Stack(values) {
1956 length = values ? values.length : 0;
1959 while (++index < length) {
1960 var entry = values[index];
1961 this.set(entry[0], entry[1]);
1966 * Removes all key-value entries from the stack.
1972 function stackClear() {
1973 this.__data__ = { 'array': [], 'map': null };
1977 * Removes `key` and its value from the stack.
1982 * @param {string} key The key of the value to remove.
1983 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1985 function stackDelete(key) {
1986 var data = this.__data__,
1989 return array ? assocDelete(array, key) : data.map['delete'](key);
1993 * Gets the stack value for `key`.
1998 * @param {string} key The key of the value to get.
1999 * @returns {*} Returns the entry value.
2001 function stackGet(key) {
2002 var data = this.__data__,
2005 return array ? assocGet(array, key) : data.map.get(key);
2009 * Checks if a stack value for `key` exists.
2014 * @param {string} key The key of the entry to check.
2015 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2017 function stackHas(key) {
2018 var data = this.__data__,
2021 return array ? assocHas(array, key) : data.map.has(key);
2025 * Sets the stack `key` to `value`.
2030 * @param {string} key The key of the value to set.
2031 * @param {*} value The value to set.
2032 * @returns {Object} Returns the stack cache object.
2034 function stackSet(key, value) {
2035 var data = this.__data__,
2039 if (array.length < (LARGE_ARRAY_SIZE - 1)) {
2040 assocSet(array, key, value);
2043 data.map = new MapCache(array);
2048 map.set(key, value);
2053 /*------------------------------------------------------------------------*/
2056 * Removes `key` and its value from the associative array.
2059 * @param {Array} array The array to query.
2060 * @param {string} key The key of the value to remove.
2061 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2063 function assocDelete(array, key) {
2064 var index = assocIndexOf(array, key);
2068 var lastIndex = array.length - 1;
2069 if (index == lastIndex) {
2072 splice.call(array, index, 1);
2078 * Gets the associative array value for `key`.
2081 * @param {Array} array The array to query.
2082 * @param {string} key The key of the value to get.
2083 * @returns {*} Returns the entry value.
2085 function assocGet(array, key) {
2086 var index = assocIndexOf(array, key);
2087 return index < 0 ? undefined : array[index][1];
2091 * Checks if an associative array value for `key` exists.
2094 * @param {Array} array The array to query.
2095 * @param {string} key The key of the entry to check.
2096 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2098 function assocHas(array, key) {
2099 return assocIndexOf(array, key) > -1;
2103 * Gets the index at which the first occurrence of `key` is found in `array`
2104 * of key-value pairs.
2107 * @param {Array} array The array to search.
2108 * @param {*} key The key to search for.
2109 * @returns {number} Returns the index of the matched value, else `-1`.
2111 function assocIndexOf(array, key) {
2112 var length = array.length;
2114 if (eq(array[length][0], key)) {
2122 * Sets the associative array `key` to `value`.
2125 * @param {Array} array The array to modify.
2126 * @param {string} key The key of the value to set.
2127 * @param {*} value The value to set.
2129 function assocSet(array, key, value) {
2130 var index = assocIndexOf(array, key);
2132 array.push([key, value]);
2134 array[index][1] = value;
2138 /*------------------------------------------------------------------------*/
2141 * Used by `_.defaults` to customize its `_.assignIn` use.
2144 * @param {*} objValue The destination value.
2145 * @param {*} srcValue The source value.
2146 * @param {string} key The key of the property to assign.
2147 * @param {Object} object The parent object of `objValue`.
2148 * @returns {*} Returns the value to assign.
2150 function assignInDefaults(objValue, srcValue, key, object) {
2151 if (objValue === undefined ||
2152 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
2159 * This function is like `assignValue` except that it doesn't assign `undefined` values.
2162 * @param {Object} object The object to modify.
2163 * @param {string} key The key of the property to assign.
2164 * @param {*} value The value to assign.
2166 function assignMergeValue(object, key, value) {
2167 if ((value !== undefined && !eq(object[key], value)) ||
2168 (typeof key == 'number' && value === undefined && !(key in object))) {
2169 object[key] = value;
2174 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2175 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2176 * for equality comparisons.
2179 * @param {Object} object The object to modify.
2180 * @param {string} key The key of the property to assign.
2181 * @param {*} value The value to assign.
2183 function assignValue(object, key, value) {
2184 var objValue = object[key];
2185 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2186 (value === undefined && !(key in object))) {
2187 object[key] = value;
2192 * Aggregates elements of `collection` on `accumulator` with keys transformed
2193 * by `iteratee` and values set by `setter`.
2196 * @param {Array|Object} collection The collection to iterate over.
2197 * @param {Function} setter The function to set `accumulator` values.
2198 * @param {Function} iteratee The iteratee to transform keys.
2199 * @param {Object} accumulator The initial aggregated object.
2200 * @returns {Function} Returns `accumulator`.
2202 function baseAggregator(collection, setter, iteratee, accumulator) {
2203 baseEach(collection, function(value, key, collection) {
2204 setter(accumulator, value, iteratee(value), collection);
2210 * The base implementation of `_.assign` without support for multiple sources
2211 * or `customizer` functions.
2214 * @param {Object} object The destination object.
2215 * @param {Object} source The source object.
2216 * @returns {Object} Returns `object`.
2218 function baseAssign(object, source) {
2219 return object && copyObject(source, keys(source), object);
2223 * The base implementation of `_.at` without support for individual paths.
2226 * @param {Object} object The object to iterate over.
2227 * @param {string[]} paths The property paths of elements to pick.
2228 * @returns {Array} Returns the new array of picked elements.
2230 function baseAt(object, paths) {
2232 isNil = object == null,
2233 length = paths.length,
2234 result = Array(length);
2236 while (++index < length) {
2237 result[index] = isNil ? undefined : get(object, paths[index]);
2243 * Casts `value` to an empty array if it's not an array like object.
2246 * @param {*} value The value to inspect.
2247 * @returns {Array} Returns the array-like object.
2249 function baseCastArrayLikeObject(value) {
2250 return isArrayLikeObject(value) ? value : [];
2254 * Casts `value` to `identity` if it's not a function.
2257 * @param {*} value The value to inspect.
2258 * @returns {Array} Returns the array-like object.
2260 function baseCastFunction(value) {
2261 return typeof value == 'function' ? value : identity;
2265 * Casts `value` to a path array if it's not one.
2268 * @param {*} value The value to inspect.
2269 * @returns {Array} Returns the cast property path array.
2271 function baseCastPath(value) {
2272 return isArray(value) ? value : stringToPath(value);
2276 * The base implementation of `_.clamp` which doesn't coerce arguments to numbers.
2279 * @param {number} number The number to clamp.
2280 * @param {number} [lower] The lower bound.
2281 * @param {number} upper The upper bound.
2282 * @returns {number} Returns the clamped number.
2284 function baseClamp(number, lower, upper) {
2285 if (number === number) {
2286 if (upper !== undefined) {
2287 number = number <= upper ? number : upper;
2289 if (lower !== undefined) {
2290 number = number >= lower ? number : lower;
2297 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2298 * traversed objects.
2301 * @param {*} value The value to clone.
2302 * @param {boolean} [isDeep] Specify a deep clone.
2303 * @param {Function} [customizer] The function to customize cloning.
2304 * @param {string} [key] The key of `value`.
2305 * @param {Object} [object] The parent object of `value`.
2306 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2307 * @returns {*} Returns the cloned value.
2309 function baseClone(value, isDeep, customizer, key, object, stack) {
2312 result = object ? customizer(value, key, object, stack) : customizer(value);
2314 if (result !== undefined) {
2317 if (!isObject(value)) {
2320 var isArr = isArray(value);
2322 result = initCloneArray(value);
2324 return copyArray(value, result);
2327 var tag = getTag(value),
2328 isFunc = tag == funcTag || tag == genTag;
2330 if (isBuffer(value)) {
2331 return cloneBuffer(value, isDeep);
2333 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2334 if (isHostObject(value)) {
2335 return object ? value : {};
2337 result = initCloneObject(isFunc ? {} : value);
2339 return copySymbols(value, baseAssign(result, value));
2342 if (!cloneableTags[tag]) {
2343 return object ? value : {};
2345 result = initCloneByTag(value, tag, isDeep);
2348 // Check for circular references and return its corresponding clone.
2349 stack || (stack = new Stack);
2350 var stacked = stack.get(value);
2354 stack.set(value, result);
2356 // Recursively populate clone (susceptible to call stack limits).
2357 (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
2358 assignValue(result, key, baseClone(subValue, isDeep, customizer, key, value, stack));
2360 return isArr ? result : copySymbols(value, result);
2364 * The base implementation of `_.conforms` which doesn't clone `source`.
2367 * @param {Object} source The object of property predicates to conform to.
2368 * @returns {Function} Returns the new function.
2370 function baseConforms(source) {
2371 var props = keys(source),
2372 length = props.length;
2374 return function(object) {
2375 if (object == null) {
2380 var key = props[index],
2381 predicate = source[key],
2382 value = object[key];
2384 if ((value === undefined && !(key in Object(object))) || !predicate(value)) {
2393 * The base implementation of `_.create` without support for assigning
2394 * properties to the created object.
2397 * @param {Object} prototype The object to inherit from.
2398 * @returns {Object} Returns the new object.
2400 function baseCreate(proto) {
2401 return isObject(proto) ? objectCreate(proto) : {};
2405 * The base implementation of `_.delay` and `_.defer` which accepts an array
2406 * of `func` arguments.
2409 * @param {Function} func The function to delay.
2410 * @param {number} wait The number of milliseconds to delay invocation.
2411 * @param {Object} args The arguments to provide to `func`.
2412 * @returns {number} Returns the timer id.
2414 function baseDelay(func, wait, args) {
2415 if (typeof func != 'function') {
2416 throw new TypeError(FUNC_ERROR_TEXT);
2418 return setTimeout(function() { func.apply(undefined, args); }, wait);
2422 * The base implementation of methods like `_.difference` without support for
2423 * excluding multiple arrays or iteratee shorthands.
2426 * @param {Array} array The array to inspect.
2427 * @param {Array} values The values to exclude.
2428 * @param {Function} [iteratee] The iteratee invoked per element.
2429 * @param {Function} [comparator] The comparator invoked per element.
2430 * @returns {Array} Returns the new array of filtered values.
2432 function baseDifference(array, values, iteratee, comparator) {
2434 includes = arrayIncludes,
2436 length = array.length,
2438 valuesLength = values.length;
2444 values = arrayMap(values, baseUnary(iteratee));
2447 includes = arrayIncludesWith;
2450 else if (values.length >= LARGE_ARRAY_SIZE) {
2451 includes = cacheHas;
2453 values = new SetCache(values);
2456 while (++index < length) {
2457 var value = array[index],
2458 computed = iteratee ? iteratee(value) : value;
2460 if (isCommon && computed === computed) {
2461 var valuesIndex = valuesLength;
2462 while (valuesIndex--) {
2463 if (values[valuesIndex] === computed) {
2469 else if (!includes(values, computed, comparator)) {
2477 * The base implementation of `_.forEach` without support for iteratee shorthands.
2480 * @param {Array|Object} collection The collection to iterate over.
2481 * @param {Function} iteratee The function invoked per iteration.
2482 * @returns {Array|Object} Returns `collection`.
2484 var baseEach = createBaseEach(baseForOwn);
2487 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2490 * @param {Array|Object} collection The collection to iterate over.
2491 * @param {Function} iteratee The function invoked per iteration.
2492 * @returns {Array|Object} Returns `collection`.
2494 var baseEachRight = createBaseEach(baseForOwnRight, true);
2497 * The base implementation of `_.every` without support for iteratee shorthands.
2500 * @param {Array|Object} collection The collection to iterate over.
2501 * @param {Function} predicate The function invoked per iteration.
2502 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
2504 function baseEvery(collection, predicate) {
2506 baseEach(collection, function(value, index, collection) {
2507 result = !!predicate(value, index, collection);
2514 * The base implementation of `_.fill` without an iteratee call guard.
2517 * @param {Array} array The array to fill.
2518 * @param {*} value The value to fill `array` with.
2519 * @param {number} [start=0] The start position.
2520 * @param {number} [end=array.length] The end position.
2521 * @returns {Array} Returns `array`.
2523 function baseFill(array, value, start, end) {
2524 var length = array.length;
2526 start = toInteger(start);
2528 start = -start > length ? 0 : (length + start);
2530 end = (end === undefined || end > length) ? length : toInteger(end);
2534 end = start > end ? 0 : toLength(end);
2535 while (start < end) {
2536 array[start++] = value;
2542 * The base implementation of `_.filter` without support for iteratee shorthands.
2545 * @param {Array|Object} collection The collection to iterate over.
2546 * @param {Function} predicate The function invoked per iteration.
2547 * @returns {Array} Returns the new filtered array.
2549 function baseFilter(collection, predicate) {
2551 baseEach(collection, function(value, index, collection) {
2552 if (predicate(value, index, collection)) {
2560 * The base implementation of `_.flatten` with support for restricting flattening.
2563 * @param {Array} array The array to flatten.
2564 * @param {number} depth The maximum recursion depth.
2565 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
2566 * @param {Array} [result=[]] The initial result value.
2567 * @returns {Array} Returns the new flattened array.
2569 function baseFlatten(array, depth, isStrict, result) {
2570 result || (result = []);
2573 length = array.length;
2575 while (++index < length) {
2576 var value = array[index];
2577 if (depth > 0 && isArrayLikeObject(value) &&
2578 (isStrict || isArray(value) || isArguments(value))) {
2580 // Recursively flatten arrays (susceptible to call stack limits).
2581 baseFlatten(value, depth - 1, isStrict, result);
2583 arrayPush(result, value);
2585 } else if (!isStrict) {
2586 result[result.length] = value;
2593 * The base implementation of `baseForIn` and `baseForOwn` which iterates
2594 * over `object` properties returned by `keysFunc` invoking `iteratee` for
2595 * each property. Iteratee functions may exit iteration early by explicitly
2596 * returning `false`.
2599 * @param {Object} object The object to iterate over.
2600 * @param {Function} iteratee The function invoked per iteration.
2601 * @param {Function} keysFunc The function to get the keys of `object`.
2602 * @returns {Object} Returns `object`.
2604 var baseFor = createBaseFor();
2607 * This function is like `baseFor` except that it iterates over properties
2608 * in the opposite order.
2611 * @param {Object} object The object to iterate over.
2612 * @param {Function} iteratee The function invoked per iteration.
2613 * @param {Function} keysFunc The function to get the keys of `object`.
2614 * @returns {Object} Returns `object`.
2616 var baseForRight = createBaseFor(true);
2619 * The base implementation of `_.forIn` without support for iteratee shorthands.
2622 * @param {Object} object The object to iterate over.
2623 * @param {Function} iteratee The function invoked per iteration.
2624 * @returns {Object} Returns `object`.
2626 function baseForIn(object, iteratee) {
2627 return object == null ? object : baseFor(object, iteratee, keysIn);
2631 * The base implementation of `_.forOwn` without support for iteratee shorthands.
2634 * @param {Object} object The object to iterate over.
2635 * @param {Function} iteratee The function invoked per iteration.
2636 * @returns {Object} Returns `object`.
2638 function baseForOwn(object, iteratee) {
2639 return object && baseFor(object, iteratee, keys);
2643 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
2646 * @param {Object} object The object to iterate over.
2647 * @param {Function} iteratee The function invoked per iteration.
2648 * @returns {Object} Returns `object`.
2650 function baseForOwnRight(object, iteratee) {
2651 return object && baseForRight(object, iteratee, keys);
2655 * The base implementation of `_.functions` which creates an array of
2656 * `object` function property names filtered from `props`.
2659 * @param {Object} object The object to inspect.
2660 * @param {Array} props The property names to filter.
2661 * @returns {Array} Returns the new array of filtered property names.
2663 function baseFunctions(object, props) {
2664 return arrayFilter(props, function(key) {
2665 return isFunction(object[key]);
2670 * The base implementation of `_.get` without support for default values.
2673 * @param {Object} object The object to query.
2674 * @param {Array|string} path The path of the property to get.
2675 * @returns {*} Returns the resolved value.
2677 function baseGet(object, path) {
2678 path = isKey(path, object) ? [path + ''] : baseCastPath(path);
2681 length = path.length;
2683 while (object != null && index < length) {
2684 object = object[path[index++]];
2686 return (index && index == length) ? object : undefined;
2690 * The base implementation of `_.has` without support for deep paths.
2693 * @param {Object} object The object to query.
2694 * @param {Array|string} key The key to check.
2695 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2697 function baseHas(object, key) {
2698 // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
2699 // that are composed entirely of index properties, return `false` for
2700 // `hasOwnProperty` checks of them.
2701 return hasOwnProperty.call(object, key) ||
2702 (typeof object == 'object' && key in object && getPrototypeOf(object) === null);
2706 * The base implementation of `_.hasIn` without support for deep paths.
2709 * @param {Object} object The object to query.
2710 * @param {Array|string} key The key to check.
2711 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2713 function baseHasIn(object, key) {
2714 return key in Object(object);
2718 * The base implementation of `_.inRange` which doesn't coerce arguments to numbers.
2721 * @param {number} number The number to check.
2722 * @param {number} start The start of the range.
2723 * @param {number} end The end of the range.
2724 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
2726 function baseInRange(number, start, end) {
2727 return number >= nativeMin(start, end) && number < nativeMax(start, end);
2731 * The base implementation of methods like `_.intersection`, without support
2732 * for iteratee shorthands, that accepts an array of arrays to inspect.
2735 * @param {Array} arrays The arrays to inspect.
2736 * @param {Function} [iteratee] The iteratee invoked per element.
2737 * @param {Function} [comparator] The comparator invoked per element.
2738 * @returns {Array} Returns the new array of shared values.
2740 function baseIntersection(arrays, iteratee, comparator) {
2741 var includes = comparator ? arrayIncludesWith : arrayIncludes,
2742 othLength = arrays.length,
2743 othIndex = othLength,
2744 caches = Array(othLength),
2747 while (othIndex--) {
2748 var array = arrays[othIndex];
2749 if (othIndex && iteratee) {
2750 array = arrayMap(array, baseUnary(iteratee));
2752 caches[othIndex] = !comparator && (iteratee || array.length >= 120)
2753 ? new SetCache(othIndex && array)
2759 length = array.length,
2763 while (++index < length) {
2764 var value = array[index],
2765 computed = iteratee ? iteratee(value) : value;
2768 ? cacheHas(seen, computed)
2769 : includes(result, computed, comparator)
2771 var othIndex = othLength;
2772 while (--othIndex) {
2773 var cache = caches[othIndex];
2775 ? cacheHas(cache, computed)
2776 : includes(arrays[othIndex], computed, comparator))
2782 seen.push(computed);
2791 * The base implementation of `_.invert` and `_.invertBy` which inverts
2792 * `object` with values transformed by `iteratee` and set by `setter`.
2795 * @param {Object} object The object to iterate over.
2796 * @param {Function} setter The function to set `accumulator` values.
2797 * @param {Function} iteratee The iteratee to transform values.
2798 * @param {Object} accumulator The initial inverted object.
2799 * @returns {Function} Returns `accumulator`.
2801 function baseInverter(object, setter, iteratee, accumulator) {
2802 baseForOwn(object, function(value, key, object) {
2803 setter(accumulator, iteratee(value), key, object);
2809 * The base implementation of `_.invoke` without support for individual
2813 * @param {Object} object The object to query.
2814 * @param {Array|string} path The path of the method to invoke.
2815 * @param {Array} args The arguments to invoke the method with.
2816 * @returns {*} Returns the result of the invoked method.
2818 function baseInvoke(object, path, args) {
2819 if (!isKey(path, object)) {
2820 path = baseCastPath(path);
2821 object = parent(object, path);
2824 var func = object == null ? object : object[path];
2825 return func == null ? undefined : apply(func, object, args);
2829 * The base implementation of `_.isEqual` which supports partial comparisons
2830 * and tracks traversed objects.
2833 * @param {*} value The value to compare.
2834 * @param {*} other The other value to compare.
2835 * @param {Function} [customizer] The function to customize comparisons.
2836 * @param {boolean} [bitmask] The bitmask of comparison flags.
2837 * The bitmask may be composed of the following flags:
2838 * 1 - Unordered comparison
2839 * 2 - Partial comparison
2840 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
2841 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2843 function baseIsEqual(value, other, customizer, bitmask, stack) {
2844 if (value === other) {
2847 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
2848 return value !== value && other !== other;
2850 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
2854 * A specialized version of `baseIsEqual` for arrays and objects which performs
2855 * deep comparisons and tracks traversed objects enabling objects with circular
2856 * references to be compared.
2859 * @param {Object} object The object to compare.
2860 * @param {Object} other The other object to compare.
2861 * @param {Function} equalFunc The function to determine equivalents of values.
2862 * @param {Function} [customizer] The function to customize comparisons.
2863 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
2864 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
2865 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2867 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
2868 var objIsArr = isArray(object),
2869 othIsArr = isArray(other),
2874 objTag = getTag(object);
2875 if (objTag == argsTag) {
2877 } else if (objTag != objectTag) {
2878 objIsArr = isTypedArray(object);
2882 othTag = getTag(other);
2883 if (othTag == argsTag) {
2885 } else if (othTag != objectTag) {
2886 othIsArr = isTypedArray(other);
2889 var objIsObj = objTag == objectTag && !isHostObject(object),
2890 othIsObj = othTag == objectTag && !isHostObject(other),
2891 isSameTag = objTag == othTag;
2893 if (isSameTag && !(objIsArr || objIsObj)) {
2894 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
2896 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
2898 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2899 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2901 if (objIsWrapped || othIsWrapped) {
2902 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
2908 stack || (stack = new Stack);
2909 return (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
2913 * The base implementation of `_.isMatch` without support for iteratee shorthands.
2916 * @param {Object} object The object to inspect.
2917 * @param {Object} source The object of property values to match.
2918 * @param {Array} matchData The property names, values, and compare flags to match.
2919 * @param {Function} [customizer] The function to customize comparisons.
2920 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2922 function baseIsMatch(object, source, matchData, customizer) {
2923 var index = matchData.length,
2925 noCustomizer = !customizer;
2927 if (object == null) {
2930 object = Object(object);
2932 var data = matchData[index];
2933 if ((noCustomizer && data[2])
2934 ? data[1] !== object[data[0]]
2935 : !(data[0] in object)
2940 while (++index < length) {
2941 data = matchData[index];
2943 objValue = object[key],
2946 if (noCustomizer && data[2]) {
2947 if (objValue === undefined && !(key in object)) {
2951 var stack = new Stack,
2952 result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined;
2954 if (!(result === undefined
2955 ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
2966 * The base implementation of `_.iteratee`.
2969 * @param {*} [value=_.identity] The value to convert to an iteratee.
2970 * @returns {Function} Returns the iteratee.
2972 function baseIteratee(value) {
2973 var type = typeof value;
2974 if (type == 'function') {
2977 if (value == null) {
2980 if (type == 'object') {
2981 return isArray(value)
2982 ? baseMatchesProperty(value[0], value[1])
2983 : baseMatches(value);
2985 return property(value);
2989 * The base implementation of `_.keys` which doesn't skip the constructor
2990 * property of prototypes or treat sparse arrays as dense.
2993 * @param {Object} object The object to query.
2994 * @returns {Array} Returns the array of property names.
2996 function baseKeys(object) {
2997 return nativeKeys(Object(object));
3001 * The base implementation of `_.keysIn` which doesn't skip the constructor
3002 * property of prototypes or treat sparse arrays as dense.
3005 * @param {Object} object The object to query.
3006 * @returns {Array} Returns the array of property names.
3008 function baseKeysIn(object) {
3009 object = object == null ? object : Object(object);
3012 for (var key in object) {
3018 // Fallback for IE < 9 with es6-shim.
3019 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
3020 baseKeysIn = function(object) {
3021 return iteratorToArray(enumerate(object));
3026 * The base implementation of `_.map` without support for iteratee shorthands.
3029 * @param {Array|Object} collection The collection to iterate over.
3030 * @param {Function} iteratee The function invoked per iteration.
3031 * @returns {Array} Returns the new mapped array.
3033 function baseMap(collection, iteratee) {
3035 result = isArrayLike(collection) ? Array(collection.length) : [];
3037 baseEach(collection, function(value, key, collection) {
3038 result[++index] = iteratee(value, key, collection);
3044 * The base implementation of `_.matches` which doesn't clone `source`.
3047 * @param {Object} source The object of property values to match.
3048 * @returns {Function} Returns the new function.
3050 function baseMatches(source) {
3051 var matchData = getMatchData(source);
3052 if (matchData.length == 1 && matchData[0][2]) {
3053 var key = matchData[0][0],
3054 value = matchData[0][1];
3056 return function(object) {
3057 if (object == null) {
3060 return object[key] === value &&
3061 (value !== undefined || (key in Object(object)));
3064 return function(object) {
3065 return object === source || baseIsMatch(object, source, matchData);
3070 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3073 * @param {string} path The path of the property to get.
3074 * @param {*} srcValue The value to match.
3075 * @returns {Function} Returns the new function.
3077 function baseMatchesProperty(path, srcValue) {
3078 return function(object) {
3079 var objValue = get(object, path);
3080 return (objValue === undefined && objValue === srcValue)
3081 ? hasIn(object, path)
3082 : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
3087 * The base implementation of `_.merge` without support for multiple sources.
3090 * @param {Object} object The destination object.
3091 * @param {Object} source The source object.
3092 * @param {number} srcIndex The index of `source`.
3093 * @param {Function} [customizer] The function to customize merged values.
3094 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
3096 function baseMerge(object, source, srcIndex, customizer, stack) {
3097 if (object === source) {
3100 var props = (isArray(source) || isTypedArray(source))
3104 arrayEach(props || source, function(srcValue, key) {
3107 srcValue = source[key];
3109 if (isObject(srcValue)) {
3110 stack || (stack = new Stack);
3111 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3114 var newValue = customizer
3115 ? customizer(object[key], srcValue, (key + ''), object, source, stack)
3118 if (newValue === undefined) {
3119 newValue = srcValue;
3121 assignMergeValue(object, key, newValue);
3127 * A specialized version of `baseMerge` for arrays and objects which performs
3128 * deep merges and tracks traversed objects enabling objects with circular
3129 * references to be merged.
3132 * @param {Object} object The destination object.
3133 * @param {Object} source The source object.
3134 * @param {string} key The key of the value to merge.
3135 * @param {number} srcIndex The index of `source`.
3136 * @param {Function} mergeFunc The function to merge values.
3137 * @param {Function} [customizer] The function to customize assigned values.
3138 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
3140 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3141 var objValue = object[key],
3142 srcValue = source[key],
3143 stacked = stack.get(srcValue);
3146 assignMergeValue(object, key, stacked);
3149 var newValue = customizer
3150 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3153 var isCommon = newValue === undefined;
3156 newValue = srcValue;
3157 if (isArray(srcValue) || isTypedArray(srcValue)) {
3158 if (isArray(objValue)) {
3159 newValue = objValue;
3161 else if (isArrayLikeObject(objValue)) {
3162 newValue = copyArray(objValue);
3166 newValue = baseClone(srcValue, true);
3169 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3170 if (isArguments(objValue)) {
3171 newValue = toPlainObject(objValue);
3173 else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
3175 newValue = baseClone(srcValue, true);
3178 newValue = objValue;
3185 stack.set(srcValue, newValue);
3188 // Recursively merge objects and arrays (susceptible to call stack limits).
3189 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3191 assignMergeValue(object, key, newValue);
3195 * The base implementation of `_.orderBy` without param guards.
3198 * @param {Array|Object} collection The collection to iterate over.
3199 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3200 * @param {string[]} orders The sort orders of `iteratees`.
3201 * @returns {Array} Returns the new sorted array.
3203 function baseOrderBy(collection, iteratees, orders) {
3205 toIteratee = getIteratee();
3207 iteratees = arrayMap(iteratees.length ? iteratees : Array(1), function(iteratee) {
3208 return toIteratee(iteratee);
3211 var result = baseMap(collection, function(value, key, collection) {
3212 var criteria = arrayMap(iteratees, function(iteratee) {
3213 return iteratee(value);
3215 return { 'criteria': criteria, 'index': ++index, 'value': value };
3218 return baseSortBy(result, function(object, other) {
3219 return compareMultiple(object, other, orders);
3224 * The base implementation of `_.pick` without support for individual
3228 * @param {Object} object The source object.
3229 * @param {string[]} props The property names to pick.
3230 * @returns {Object} Returns the new object.
3232 function basePick(object, props) {
3233 object = Object(object);
3234 return arrayReduce(props, function(result, key) {
3235 if (key in object) {
3236 result[key] = object[key];
3243 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3246 * @param {Object} object The source object.
3247 * @param {Function} predicate The function invoked per property.
3248 * @returns {Object} Returns the new object.
3250 function basePickBy(object, predicate) {
3252 baseForIn(object, function(value, key) {
3253 if (predicate(value, key)) {
3254 result[key] = value;
3261 * The base implementation of `_.property` without support for deep paths.
3264 * @param {string} key The key of the property to get.
3265 * @returns {Function} Returns the new function.
3267 function baseProperty(key) {
3268 return function(object) {
3269 return object == null ? undefined : object[key];
3274 * A specialized version of `baseProperty` which supports deep paths.
3277 * @param {Array|string} path The path of the property to get.
3278 * @returns {Function} Returns the new function.
3280 function basePropertyDeep(path) {
3281 return function(object) {
3282 return baseGet(object, path);
3287 * The base implementation of `_.pullAll`.
3290 * @param {Array} array The array to modify.
3291 * @param {Array} values The values to remove.
3292 * @returns {Array} Returns `array`.
3294 function basePullAll(array, values) {
3295 return basePullAllBy(array, values);
3299 * The base implementation of `_.pullAllBy` without support for iteratee
3303 * @param {Array} array The array to modify.
3304 * @param {Array} values The values to remove.
3305 * @param {Function} [iteratee] The iteratee invoked per element.
3306 * @returns {Array} Returns `array`.
3308 function basePullAllBy(array, values, iteratee) {
3310 length = values.length,
3314 seen = arrayMap(array, function(value) { return iteratee(value); });
3316 while (++index < length) {
3318 value = values[index],
3319 computed = iteratee ? iteratee(value) : value;
3321 while ((fromIndex = baseIndexOf(seen, computed, fromIndex)) > -1) {
3322 if (seen !== array) {
3323 splice.call(seen, fromIndex, 1);
3325 splice.call(array, fromIndex, 1);
3332 * The base implementation of `_.pullAt` without support for individual
3333 * indexes or capturing the removed elements.
3336 * @param {Array} array The array to modify.
3337 * @param {number[]} indexes The indexes of elements to remove.
3338 * @returns {Array} Returns `array`.
3340 function basePullAt(array, indexes) {
3341 var length = array ? indexes.length : 0,
3342 lastIndex = length - 1;
3345 var index = indexes[length];
3346 if (lastIndex == length || index != previous) {
3347 var previous = index;
3348 if (isIndex(index)) {
3349 splice.call(array, index, 1);
3351 else if (!isKey(index, array)) {
3352 var path = baseCastPath(index),
3353 object = parent(array, path);
3355 if (object != null) {
3356 delete object[last(path)];
3360 delete array[index];
3368 * The base implementation of `_.random` without support for returning
3369 * floating-point numbers.
3372 * @param {number} lower The lower bound.
3373 * @param {number} upper The upper bound.
3374 * @returns {number} Returns the random number.
3376 function baseRandom(lower, upper) {
3377 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3381 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3382 * coerce arguments to numbers.
3385 * @param {number} start The start of the range.
3386 * @param {number} end The end of the range.
3387 * @param {number} step The value to increment or decrement by.
3388 * @param {boolean} [fromRight] Specify iterating from right to left.
3389 * @returns {Array} Returns the new array of numbers.
3391 function baseRange(start, end, step, fromRight) {
3393 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3394 result = Array(length);
3397 result[fromRight ? length : ++index] = start;
3404 * The base implementation of `_.set`.
3407 * @param {Object} object The object to query.
3408 * @param {Array|string} path The path of the property to set.
3409 * @param {*} value The value to set.
3410 * @param {Function} [customizer] The function to customize path creation.
3411 * @returns {Object} Returns `object`.
3413 function baseSet(object, path, value, customizer) {
3414 path = isKey(path, object) ? [path + ''] : baseCastPath(path);
3417 length = path.length,
3418 lastIndex = length - 1,
3421 while (nested != null && ++index < length) {
3422 var key = path[index];
3423 if (isObject(nested)) {
3424 var newValue = value;
3425 if (index != lastIndex) {
3426 var objValue = nested[key];
3427 newValue = customizer ? customizer(objValue, key, nested) : undefined;
3428 if (newValue === undefined) {
3429 newValue = objValue == null
3430 ? (isIndex(path[index + 1]) ? [] : {})
3434 assignValue(nested, key, newValue);
3436 nested = nested[key];
3442 * The base implementation of `setData` without support for hot loop detection.
3445 * @param {Function} func The function to associate metadata with.
3446 * @param {*} data The metadata.
3447 * @returns {Function} Returns `func`.
3449 var baseSetData = !metaMap ? identity : function(func, data) {
3450 metaMap.set(func, data);
3455 * The base implementation of `_.slice` without an iteratee call guard.
3458 * @param {Array} array The array to slice.
3459 * @param {number} [start=0] The start position.
3460 * @param {number} [end=array.length] The end position.
3461 * @returns {Array} Returns the slice of `array`.
3463 function baseSlice(array, start, end) {
3465 length = array.length;
3468 start = -start > length ? 0 : (length + start);
3470 end = end > length ? length : end;
3474 length = start > end ? 0 : ((end - start) >>> 0);
3477 var result = Array(length);
3478 while (++index < length) {
3479 result[index] = array[index + start];
3485 * The base implementation of `_.some` without support for iteratee shorthands.
3488 * @param {Array|Object} collection The collection to iterate over.
3489 * @param {Function} predicate The function invoked per iteration.
3490 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
3492 function baseSome(collection, predicate) {
3495 baseEach(collection, function(value, index, collection) {
3496 result = predicate(value, index, collection);
3503 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
3504 * performs a binary search of `array` to determine the index at which `value`
3505 * should be inserted into `array` in order to maintain its sort order.
3508 * @param {Array} array The sorted array to inspect.
3509 * @param {*} value The value to evaluate.
3510 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3511 * @returns {number} Returns the index at which `value` should be inserted
3514 function baseSortedIndex(array, value, retHighest) {
3516 high = array ? array.length : low;
3518 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
3519 while (low < high) {
3520 var mid = (low + high) >>> 1,
3521 computed = array[mid];
3523 if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
3531 return baseSortedIndexBy(array, value, identity, retHighest);
3535 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
3536 * which invokes `iteratee` for `value` and each element of `array` to compute
3537 * their sort ranking. The iteratee is invoked with one argument; (value).
3540 * @param {Array} array The sorted array to inspect.
3541 * @param {*} value The value to evaluate.
3542 * @param {Function} iteratee The iteratee invoked per element.
3543 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3544 * @returns {number} Returns the index at which `value` should be inserted into `array`.
3546 function baseSortedIndexBy(array, value, iteratee, retHighest) {
3547 value = iteratee(value);
3550 high = array ? array.length : 0,
3551 valIsNaN = value !== value,
3552 valIsNull = value === null,
3553 valIsUndef = value === undefined;
3555 while (low < high) {
3556 var mid = nativeFloor((low + high) / 2),
3557 computed = iteratee(array[mid]),
3558 isDef = computed !== undefined,
3559 isReflexive = computed === computed;
3562 var setLow = isReflexive || retHighest;
3563 } else if (valIsNull) {
3564 setLow = isReflexive && isDef && (retHighest || computed != null);
3565 } else if (valIsUndef) {
3566 setLow = isReflexive && (retHighest || isDef);
3567 } else if (computed == null) {
3570 setLow = retHighest ? (computed <= value) : (computed < value);
3578 return nativeMin(high, MAX_ARRAY_INDEX);
3582 * The base implementation of `_.sortedUniq`.
3585 * @param {Array} array The array to inspect.
3586 * @returns {Array} Returns the new duplicate free array.
3588 function baseSortedUniq(array) {
3589 return baseSortedUniqBy(array);
3593 * The base implementation of `_.sortedUniqBy` without support for iteratee
3597 * @param {Array} array The array to inspect.
3598 * @param {Function} [iteratee] The iteratee invoked per element.
3599 * @returns {Array} Returns the new duplicate free array.
3601 function baseSortedUniqBy(array, iteratee) {
3603 length = array.length,
3605 computed = iteratee ? iteratee(value) : value,
3610 while (++index < length) {
3611 value = array[index],
3612 computed = iteratee ? iteratee(value) : value;
3614 if (!eq(computed, seen)) {
3616 result[++resIndex] = value;
3623 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
3626 * @param {Array} array The array to inspect.
3627 * @param {Function} [iteratee] The iteratee invoked per element.
3628 * @param {Function} [comparator] The comparator invoked per element.
3629 * @returns {Array} Returns the new duplicate free array.
3631 function baseUniq(array, iteratee, comparator) {
3633 includes = arrayIncludes,
3634 length = array.length,
3641 includes = arrayIncludesWith;
3643 else if (length >= LARGE_ARRAY_SIZE) {
3644 var set = iteratee ? null : createSet(array);
3646 return setToArray(set);
3649 includes = cacheHas;
3650 seen = new SetCache;
3653 seen = iteratee ? [] : result;
3656 while (++index < length) {
3657 var value = array[index],
3658 computed = iteratee ? iteratee(value) : value;
3660 if (isCommon && computed === computed) {
3661 var seenIndex = seen.length;
3662 while (seenIndex--) {
3663 if (seen[seenIndex] === computed) {
3668 seen.push(computed);
3672 else if (!includes(seen, computed, comparator)) {
3673 if (seen !== result) {
3674 seen.push(computed);
3683 * The base implementation of `_.unset`.
3686 * @param {Object} object The object to modify.
3687 * @param {Array|string} path The path of the property to unset.
3688 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
3690 function baseUnset(object, path) {
3691 path = isKey(path, object) ? [path + ''] : baseCastPath(path);
3692 object = parent(object, path);
3693 var key = last(path);
3694 return (object != null && has(object, key)) ? delete object[key] : true;
3698 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
3699 * without support for iteratee shorthands.
3702 * @param {Array} array The array to query.
3703 * @param {Function} predicate The function invoked per iteration.
3704 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
3705 * @param {boolean} [fromRight] Specify iterating from right to left.
3706 * @returns {Array} Returns the slice of `array`.
3708 function baseWhile(array, predicate, isDrop, fromRight) {
3709 var length = array.length,
3710 index = fromRight ? length : -1;
3712 while ((fromRight ? index-- : ++index < length) &&
3713 predicate(array[index], index, array)) {}
3716 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
3717 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
3721 * The base implementation of `wrapperValue` which returns the result of
3722 * performing a sequence of actions on the unwrapped `value`, where each
3723 * successive action is supplied the return value of the previous.
3726 * @param {*} value The unwrapped value.
3727 * @param {Array} actions Actions to perform to resolve the unwrapped value.
3728 * @returns {*} Returns the resolved value.
3730 function baseWrapperValue(value, actions) {
3732 if (result instanceof LazyWrapper) {
3733 result = result.value();
3735 return arrayReduce(actions, function(result, action) {
3736 return action.func.apply(action.thisArg, arrayPush([result], action.args));
3741 * The base implementation of methods like `_.xor`, without support for
3742 * iteratee shorthands, that accepts an array of arrays to inspect.
3745 * @param {Array} arrays The arrays to inspect.
3746 * @param {Function} [iteratee] The iteratee invoked per element.
3747 * @param {Function} [comparator] The comparator invoked per element.
3748 * @returns {Array} Returns the new array of values.
3750 function baseXor(arrays, iteratee, comparator) {
3752 length = arrays.length;
3754 while (++index < length) {
3757 baseDifference(result, arrays[index], iteratee, comparator),
3758 baseDifference(arrays[index], result, iteratee, comparator)
3762 return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
3766 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
3769 * @param {Array} props The property names.
3770 * @param {Array} values The property values.
3771 * @param {Function} assignFunc The function to assign values.
3772 * @returns {Object} Returns the new object.
3774 function baseZipObject(props, values, assignFunc) {
3776 length = props.length,
3777 valsLength = values.length,
3780 while (++index < length) {
3781 assignFunc(result, props[index], index < valsLength ? values[index] : undefined);
3787 * Creates a clone of `buffer`.
3790 * @param {Buffer} buffer The buffer to clone.
3791 * @param {boolean} [isDeep] Specify a deep clone.
3792 * @returns {Buffer} Returns the cloned buffer.
3794 function cloneBuffer(buffer, isDeep) {
3796 return buffer.slice();
3798 var Ctor = buffer.constructor,
3799 result = new Ctor(buffer.length);
3801 buffer.copy(result);
3806 * Creates a clone of `arrayBuffer`.
3809 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
3810 * @returns {ArrayBuffer} Returns the cloned array buffer.
3812 function cloneArrayBuffer(arrayBuffer) {
3813 var Ctor = arrayBuffer.constructor,
3814 result = new Ctor(arrayBuffer.byteLength),
3815 view = new Uint8Array(result);
3817 view.set(new Uint8Array(arrayBuffer));
3822 * Creates a clone of `map`.
3825 * @param {Object} map The map to clone.
3826 * @returns {Object} Returns the cloned map.
3828 function cloneMap(map) {
3829 var Ctor = map.constructor;
3830 return arrayReduce(mapToArray(map), addMapEntry, new Ctor);
3834 * Creates a clone of `regexp`.
3837 * @param {Object} regexp The regexp to clone.
3838 * @returns {Object} Returns the cloned regexp.
3840 function cloneRegExp(regexp) {
3841 var Ctor = regexp.constructor,
3842 result = new Ctor(regexp.source, reFlags.exec(regexp));
3844 result.lastIndex = regexp.lastIndex;
3849 * Creates a clone of `set`.
3852 * @param {Object} set The set to clone.
3853 * @returns {Object} Returns the cloned set.
3855 function cloneSet(set) {
3856 var Ctor = set.constructor;
3857 return arrayReduce(setToArray(set), addSetEntry, new Ctor);
3861 * Creates a clone of the `symbol` object.
3864 * @param {Object} symbol The symbol object to clone.
3865 * @returns {Object} Returns the cloned symbol object.
3867 function cloneSymbol(symbol) {
3868 return Symbol ? Object(symbolValueOf.call(symbol)) : {};
3872 * Creates a clone of `typedArray`.
3875 * @param {Object} typedArray The typed array to clone.
3876 * @param {boolean} [isDeep] Specify a deep clone.
3877 * @returns {Object} Returns the cloned typed array.
3879 function cloneTypedArray(typedArray, isDeep) {
3880 var arrayBuffer = typedArray.buffer,
3881 buffer = isDeep ? cloneArrayBuffer(arrayBuffer) : arrayBuffer,
3882 Ctor = typedArray.constructor;
3884 return new Ctor(buffer, typedArray.byteOffset, typedArray.length);
3888 * Creates an array that is the composition of partially applied arguments,
3889 * placeholders, and provided arguments into a single array of arguments.
3892 * @param {Array|Object} args The provided arguments.
3893 * @param {Array} partials The arguments to prepend to those provided.
3894 * @param {Array} holders The `partials` placeholder indexes.
3895 * @params {boolean} [isCurried] Specify composing for a curried function.
3896 * @returns {Array} Returns the new array of composed arguments.
3898 function composeArgs(args, partials, holders, isCurried) {
3900 argsLength = args.length,
3901 holdersLength = holders.length,
3903 leftLength = partials.length,
3904 rangeLength = nativeMax(argsLength - holdersLength, 0),
3905 result = Array(leftLength + rangeLength),
3906 isUncurried = !isCurried;
3908 while (++leftIndex < leftLength) {
3909 result[leftIndex] = partials[leftIndex];
3911 while (++argsIndex < holdersLength) {
3912 if (isUncurried || argsIndex < argsLength) {
3913 result[holders[argsIndex]] = args[argsIndex];
3916 while (rangeLength--) {
3917 result[leftIndex++] = args[argsIndex++];
3923 * This function is like `composeArgs` except that the arguments composition
3924 * is tailored for `_.partialRight`.
3927 * @param {Array|Object} args The provided arguments.
3928 * @param {Array} partials The arguments to append to those provided.
3929 * @param {Array} holders The `partials` placeholder indexes.
3930 * @params {boolean} [isCurried] Specify composing for a curried function.
3931 * @returns {Array} Returns the new array of composed arguments.
3933 function composeArgsRight(args, partials, holders, isCurried) {
3935 argsLength = args.length,
3937 holdersLength = holders.length,
3939 rightLength = partials.length,
3940 rangeLength = nativeMax(argsLength - holdersLength, 0),
3941 result = Array(rangeLength + rightLength),
3942 isUncurried = !isCurried;
3944 while (++argsIndex < rangeLength) {
3945 result[argsIndex] = args[argsIndex];
3947 var offset = argsIndex;
3948 while (++rightIndex < rightLength) {
3949 result[offset + rightIndex] = partials[rightIndex];
3951 while (++holdersIndex < holdersLength) {
3952 if (isUncurried || argsIndex < argsLength) {
3953 result[offset + holders[holdersIndex]] = args[argsIndex++];
3960 * Copies the values of `source` to `array`.
3963 * @param {Array} source The array to copy values from.
3964 * @param {Array} [array=[]] The array to copy values to.
3965 * @returns {Array} Returns `array`.
3967 function copyArray(source, array) {
3969 length = source.length;
3971 array || (array = Array(length));
3972 while (++index < length) {
3973 array[index] = source[index];
3979 * Copies properties of `source` to `object`.
3982 * @param {Object} source The object to copy properties from.
3983 * @param {Array} props The property names to copy.
3984 * @param {Object} [object={}] The object to copy properties to.
3985 * @returns {Object} Returns `object`.
3987 function copyObject(source, props, object) {
3988 return copyObjectWith(source, props, object);
3992 * This function is like `copyObject` except that it accepts a function to
3993 * customize copied values.
3996 * @param {Object} source The object to copy properties from.
3997 * @param {Array} props The property names to copy.
3998 * @param {Object} [object={}] The object to copy properties to.
3999 * @param {Function} [customizer] The function to customize copied values.
4000 * @returns {Object} Returns `object`.
4002 function copyObjectWith(source, props, object, customizer) {
4003 object || (object = {});
4006 length = props.length;
4008 while (++index < length) {
4009 var key = props[index];
4011 var newValue = customizer
4012 ? customizer(object[key], source[key], key, object, source)
4015 assignValue(object, key, newValue);
4021 * Copies own symbol properties of `source` to `object`.
4024 * @param {Object} source The object to copy symbols from.
4025 * @param {Object} [object={}] The object to copy symbols to.
4026 * @returns {Object} Returns `object`.
4028 function copySymbols(source, object) {
4029 return copyObject(source, getSymbols(source), object);
4033 * Creates a function like `_.groupBy`.
4036 * @param {Function} setter The function to set accumulator values.
4037 * @param {Function} [initializer] The accumulator object initializer.
4038 * @returns {Function} Returns the new aggregator function.
4040 function createAggregator(setter, initializer) {
4041 return function(collection, iteratee) {
4042 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4043 accumulator = initializer ? initializer() : {};
4045 return func(collection, setter, getIteratee(iteratee), accumulator);
4050 * Creates a function like `_.assign`.
4053 * @param {Function} assigner The function to assign values.
4054 * @returns {Function} Returns the new assigner function.
4056 function createAssigner(assigner) {
4057 return rest(function(object, sources) {
4059 length = sources.length,
4060 customizer = length > 1 ? sources[length - 1] : undefined,
4061 guard = length > 2 ? sources[2] : undefined;
4063 customizer = typeof customizer == 'function'
4064 ? (length--, customizer)
4067 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
4068 customizer = length < 3 ? undefined : customizer;
4071 object = Object(object);
4072 while (++index < length) {
4073 var source = sources[index];
4075 assigner(object, source, index, customizer);
4083 * Creates a `baseEach` or `baseEachRight` function.
4086 * @param {Function} eachFunc The function to iterate over a collection.
4087 * @param {boolean} [fromRight] Specify iterating from right to left.
4088 * @returns {Function} Returns the new base function.
4090 function createBaseEach(eachFunc, fromRight) {
4091 return function(collection, iteratee) {
4092 if (collection == null) {
4095 if (!isArrayLike(collection)) {
4096 return eachFunc(collection, iteratee);
4098 var length = collection.length,
4099 index = fromRight ? length : -1,
4100 iterable = Object(collection);
4102 while ((fromRight ? index-- : ++index < length)) {
4103 if (iteratee(iterable[index], index, iterable) === false) {
4112 * Creates a base function for methods like `_.forIn`.
4115 * @param {boolean} [fromRight] Specify iterating from right to left.
4116 * @returns {Function} Returns the new base function.
4118 function createBaseFor(fromRight) {
4119 return function(object, iteratee, keysFunc) {
4121 iterable = Object(object),
4122 props = keysFunc(object),
4123 length = props.length;
4126 var key = props[fromRight ? length : ++index];
4127 if (iteratee(iterable[key], key, iterable) === false) {
4136 * Creates a function that wraps `func` to invoke it with the optional `this`
4137 * binding of `thisArg`.
4140 * @param {Function} func The function to wrap.
4141 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4142 * @param {*} [thisArg] The `this` binding of `func`.
4143 * @returns {Function} Returns the new wrapped function.
4145 function createBaseWrapper(func, bitmask, thisArg) {
4146 var isBind = bitmask & BIND_FLAG,
4147 Ctor = createCtorWrapper(func);
4149 function wrapper() {
4150 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4151 return fn.apply(isBind ? thisArg : this, arguments);
4157 * Creates a function like `_.lowerFirst`.
4160 * @param {string} methodName The name of the `String` case method to use.
4161 * @returns {Function} Returns the new function.
4163 function createCaseFirst(methodName) {
4164 return function(string) {
4165 string = toString(string);
4167 var strSymbols = reHasComplexSymbol.test(string)
4168 ? stringToArray(string)
4171 var chr = strSymbols ? strSymbols[0] : string.charAt(0),
4172 trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1);
4174 return chr[methodName]() + trailing;
4179 * Creates a function like `_.camelCase`.
4182 * @param {Function} callback The function to combine each word.
4183 * @returns {Function} Returns the new compounder function.
4185 function createCompounder(callback) {
4186 return function(string) {
4187 return arrayReduce(words(deburr(string)), callback, '');
4192 * Creates a function that produces an instance of `Ctor` regardless of
4193 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
4196 * @param {Function} Ctor The constructor to wrap.
4197 * @returns {Function} Returns the new wrapped function.
4199 function createCtorWrapper(Ctor) {
4201 // Use a `switch` statement to work with class constructors.
4202 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
4203 // for more details.
4204 var args = arguments;
4205 switch (args.length) {
4206 case 0: return new Ctor;
4207 case 1: return new Ctor(args[0]);
4208 case 2: return new Ctor(args[0], args[1]);
4209 case 3: return new Ctor(args[0], args[1], args[2]);
4210 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
4211 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
4212 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
4213 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
4215 var thisBinding = baseCreate(Ctor.prototype),
4216 result = Ctor.apply(thisBinding, args);
4218 // Mimic the constructor's `return` behavior.
4219 // See https://es5.github.io/#x13.2.2 for more details.
4220 return isObject(result) ? result : thisBinding;
4225 * Creates a function that wraps `func` to enable currying.
4228 * @param {Function} func The function to wrap.
4229 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4230 * @param {number} arity The arity of `func`.
4231 * @returns {Function} Returns the new wrapped function.
4233 function createCurryWrapper(func, bitmask, arity) {
4234 var Ctor = createCtorWrapper(func);
4236 function wrapper() {
4237 var length = arguments.length,
4238 args = Array(length),
4240 placeholder = getPlaceholder(wrapper);
4243 args[index] = arguments[index];
4245 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
4247 : replaceHolders(args, placeholder);
4249 length -= holders.length;
4250 if (length < arity) {
4251 return createRecurryWrapper(
4252 func, bitmask, createHybridWrapper, wrapper.placeholder, undefined,
4253 args, holders, undefined, undefined, arity - length);
4255 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4256 return apply(fn, this, args);
4262 * Creates a `_.flow` or `_.flowRight` function.
4265 * @param {boolean} [fromRight] Specify iterating from right to left.
4266 * @returns {Function} Returns the new flow function.
4268 function createFlow(fromRight) {
4269 return rest(function(funcs) {
4270 funcs = baseFlatten(funcs, 1);
4272 var length = funcs.length,
4274 prereq = LodashWrapper.prototype.thru;
4280 var func = funcs[index];
4281 if (typeof func != 'function') {
4282 throw new TypeError(FUNC_ERROR_TEXT);
4284 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
4285 var wrapper = new LodashWrapper([], true);
4288 index = wrapper ? index : length;
4289 while (++index < length) {
4290 func = funcs[index];
4292 var funcName = getFuncName(func),
4293 data = funcName == 'wrapper' ? getData(func) : undefined;
4295 if (data && isLaziable(data[0]) &&
4296 data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
4297 !data[4].length && data[9] == 1
4299 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
4301 wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
4305 var args = arguments,
4308 if (wrapper && args.length == 1 &&
4309 isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
4310 return wrapper.plant(value).value();
4313 result = length ? funcs[index].apply(this, args) : value;
4315 while (++index < length) {
4316 result = funcs[index].call(this, result);
4324 * Creates a function that wraps `func` to invoke it with optional `this`
4325 * binding of `thisArg`, partial application, and currying.
4328 * @param {Function|string} func The function or method name to wrap.
4329 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4330 * @param {*} [thisArg] The `this` binding of `func`.
4331 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
4332 * @param {Array} [holders] The `partials` placeholder indexes.
4333 * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
4334 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
4335 * @param {Array} [argPos] The argument positions of the new function.
4336 * @param {number} [ary] The arity cap of `func`.
4337 * @param {number} [arity] The arity of `func`.
4338 * @returns {Function} Returns the new wrapped function.
4340 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
4341 var isAry = bitmask & ARY_FLAG,
4342 isBind = bitmask & BIND_FLAG,
4343 isBindKey = bitmask & BIND_KEY_FLAG,
4344 isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
4345 isFlip = bitmask & FLIP_FLAG,
4346 Ctor = isBindKey ? undefined : createCtorWrapper(func);
4348 function wrapper() {
4349 var length = arguments.length,
4351 args = Array(length);
4354 args[index] = arguments[index];
4357 var placeholder = getPlaceholder(wrapper),
4358 holdersCount = countHolders(args, placeholder);
4361 args = composeArgs(args, partials, holders, isCurried);
4363 if (partialsRight) {
4364 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
4366 length -= holdersCount;
4367 if (isCurried && length < arity) {
4368 var newHolders = replaceHolders(args, placeholder);
4369 return createRecurryWrapper(
4370 func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg,
4371 args, newHolders, argPos, ary, arity - length
4374 var thisBinding = isBind ? thisArg : this,
4375 fn = isBindKey ? thisBinding[func] : func;
4377 length = args.length;
4379 args = reorder(args, argPos);
4380 } else if (isFlip && length > 1) {
4383 if (isAry && ary < length) {
4386 if (this && this !== root && this instanceof wrapper) {
4387 fn = Ctor || createCtorWrapper(fn);
4389 return fn.apply(thisBinding, args);
4395 * Creates a function like `_.invertBy`.
4398 * @param {Function} setter The function to set accumulator values.
4399 * @param {Function} toIteratee The function to resolve iteratees.
4400 * @returns {Function} Returns the new inverter function.
4402 function createInverter(setter, toIteratee) {
4403 return function(object, iteratee) {
4404 return baseInverter(object, setter, toIteratee(iteratee), {});
4409 * Creates a function like `_.over`.
4412 * @param {Function} arrayFunc The function to iterate over iteratees.
4413 * @returns {Function} Returns the new invoker function.
4415 function createOver(arrayFunc) {
4416 return rest(function(iteratees) {
4417 iteratees = arrayMap(baseFlatten(iteratees, 1), getIteratee());
4418 return rest(function(args) {
4420 return arrayFunc(iteratees, function(iteratee) {
4421 return apply(iteratee, thisArg, args);
4428 * Creates the padding for `string` based on `length`. The `chars` string
4429 * is truncated if the number of characters exceeds `length`.
4432 * @param {string} string The string to create padding for.
4433 * @param {number} [length=0] The padding length.
4434 * @param {string} [chars=' '] The string used as padding.
4435 * @returns {string} Returns the padding for `string`.
4437 function createPadding(string, length, chars) {
4438 length = toInteger(length);
4440 var strLength = stringSize(string);
4441 if (!length || strLength >= length) {
4444 var padLength = length - strLength;
4445 chars = chars === undefined ? ' ' : (chars + '');
4447 var result = repeat(chars, nativeCeil(padLength / stringSize(chars)));
4448 return reHasComplexSymbol.test(chars)
4449 ? stringToArray(result).slice(0, padLength).join('')
4450 : result.slice(0, padLength);
4454 * Creates a function that wraps `func` to invoke it with the optional `this`
4455 * binding of `thisArg` and the `partials` prepended to those provided to
4459 * @param {Function} func The function to wrap.
4460 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4461 * @param {*} thisArg The `this` binding of `func`.
4462 * @param {Array} partials The arguments to prepend to those provided to the new function.
4463 * @returns {Function} Returns the new wrapped function.
4465 function createPartialWrapper(func, bitmask, thisArg, partials) {
4466 var isBind = bitmask & BIND_FLAG,
4467 Ctor = createCtorWrapper(func);
4469 function wrapper() {
4471 argsLength = arguments.length,
4473 leftLength = partials.length,
4474 args = Array(leftLength + argsLength),
4475 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4477 while (++leftIndex < leftLength) {
4478 args[leftIndex] = partials[leftIndex];
4480 while (argsLength--) {
4481 args[leftIndex++] = arguments[++argsIndex];
4483 return apply(fn, isBind ? thisArg : this, args);
4489 * Creates a `_.range` or `_.rangeRight` function.
4492 * @param {boolean} [fromRight] Specify iterating from right to left.
4493 * @returns {Function} Returns the new range function.
4495 function createRange(fromRight) {
4496 return function(start, end, step) {
4497 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
4498 end = step = undefined;
4500 // Ensure the sign of `-0` is preserved.
4501 start = toNumber(start);
4502 start = start === start ? start : 0;
4503 if (end === undefined) {
4507 end = toNumber(end) || 0;
4509 step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
4510 return baseRange(start, end, step, fromRight);
4515 * Creates a function that wraps `func` to continue currying.
4518 * @param {Function} func The function to wrap.
4519 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4520 * @param {Function} wrapFunc The function to create the `func` wrapper.
4521 * @param {*} placeholder The placeholder value.
4522 * @param {*} [thisArg] The `this` binding of `func`.
4523 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
4524 * @param {Array} [holders] The `partials` placeholder indexes.
4525 * @param {Array} [argPos] The argument positions of the new function.
4526 * @param {number} [ary] The arity cap of `func`.
4527 * @param {number} [arity] The arity of `func`.
4528 * @returns {Function} Returns the new wrapped function.
4530 function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
4531 var isCurry = bitmask & CURRY_FLAG,
4532 newArgPos = argPos ? copyArray(argPos) : undefined,
4533 newHolders = isCurry ? holders : undefined,
4534 newHoldersRight = isCurry ? undefined : holders,
4535 newPartials = isCurry ? partials : undefined,
4536 newPartialsRight = isCurry ? undefined : partials;
4538 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
4539 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
4541 if (!(bitmask & CURRY_BOUND_FLAG)) {
4542 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
4545 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
4546 newHoldersRight, newArgPos, ary, arity
4549 var result = wrapFunc.apply(undefined, newData);
4550 if (isLaziable(func)) {
4551 setData(result, newData);
4553 result.placeholder = placeholder;
4558 * Creates a function like `_.round`.
4561 * @param {string} methodName The name of the `Math` method to use when rounding.
4562 * @returns {Function} Returns the new round function.
4564 function createRound(methodName) {
4565 var func = Math[methodName];
4566 return function(number, precision) {
4567 number = toNumber(number);
4568 precision = toInteger(precision);
4570 // Shift with exponential notation to avoid floating-point issues.
4571 // See [MDN](https://mdn.io/round#Examples) for more details.
4572 var pair = (toString(number) + 'e').split('e'),
4573 value = func(pair[0] + 'e' + (+pair[1] + precision));
4575 pair = (toString(value) + 'e').split('e');
4576 return +(pair[0] + 'e' + (+pair[1] - precision));
4578 return func(number);
4583 * Creates a set of `values`.
4586 * @param {Array} values The values to add to the set.
4587 * @returns {Object} Returns the new set.
4589 var createSet = !(Set && new Set([1, 2]).size === 2) ? noop : function(values) {
4590 return new Set(values);
4594 * Creates a function that either curries or invokes `func` with optional
4595 * `this` binding and partially applied arguments.
4598 * @param {Function|string} func The function or method name to wrap.
4599 * @param {number} bitmask The bitmask of wrapper flags.
4600 * The bitmask may be composed of the following flags:
4603 * 4 - `_.curry` or `_.curryRight` of a bound function
4605 * 16 - `_.curryRight`
4607 * 64 - `_.partialRight`
4610 * @param {*} [thisArg] The `this` binding of `func`.
4611 * @param {Array} [partials] The arguments to be partially applied.
4612 * @param {Array} [holders] The `partials` placeholder indexes.
4613 * @param {Array} [argPos] The argument positions of the new function.
4614 * @param {number} [ary] The arity cap of `func`.
4615 * @param {number} [arity] The arity of `func`.
4616 * @returns {Function} Returns the new wrapped function.
4618 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
4619 var isBindKey = bitmask & BIND_KEY_FLAG;
4620 if (!isBindKey && typeof func != 'function') {
4621 throw new TypeError(FUNC_ERROR_TEXT);
4623 var length = partials ? partials.length : 0;
4625 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
4626 partials = holders = undefined;
4628 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
4629 arity = arity === undefined ? arity : toInteger(arity);
4630 length -= holders ? holders.length : 0;
4632 if (bitmask & PARTIAL_RIGHT_FLAG) {
4633 var partialsRight = partials,
4634 holdersRight = holders;
4636 partials = holders = undefined;
4638 var data = isBindKey ? undefined : getData(func);
4641 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
4646 mergeData(newData, data);
4649 bitmask = newData[1];
4650 thisArg = newData[2];
4651 partials = newData[3];
4652 holders = newData[4];
4653 arity = newData[9] = newData[9] == null
4654 ? (isBindKey ? 0 : func.length)
4655 : nativeMax(newData[9] - length, 0);
4657 if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
4658 bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
4660 if (!bitmask || bitmask == BIND_FLAG) {
4661 var result = createBaseWrapper(func, bitmask, thisArg);
4662 } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
4663 result = createCurryWrapper(func, bitmask, arity);
4664 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
4665 result = createPartialWrapper(func, bitmask, thisArg, partials);
4667 result = createHybridWrapper.apply(undefined, newData);
4669 var setter = data ? baseSetData : setData;
4670 return setter(result, newData);
4674 * A specialized version of `baseIsEqualDeep` for arrays with support for
4675 * partial deep comparisons.
4678 * @param {Array} array The array to compare.
4679 * @param {Array} other The other array to compare.
4680 * @param {Function} equalFunc The function to determine equivalents of values.
4681 * @param {Function} [customizer] The function to customize comparisons.
4682 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4683 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
4684 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
4686 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
4688 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
4689 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
4690 arrLength = array.length,
4691 othLength = other.length;
4693 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
4696 // Assume cyclic values are equal.
4697 var stacked = stack.get(array);
4699 return stacked == other;
4702 stack.set(array, other);
4704 // Ignore non-index properties.
4705 while (++index < arrLength) {
4706 var arrValue = array[index],
4707 othValue = other[index];
4710 var compared = isPartial
4711 ? customizer(othValue, arrValue, index, other, array, stack)
4712 : customizer(arrValue, othValue, index, array, other, stack);
4714 if (compared !== undefined) {
4721 // Recursively compare arrays (susceptible to call stack limits).
4723 if (!arraySome(other, function(othValue) {
4724 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
4729 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
4734 stack['delete'](array);
4739 * A specialized version of `baseIsEqualDeep` for comparing objects of
4740 * the same `toStringTag`.
4742 * **Note:** This function only supports comparing values with tags of
4743 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4746 * @param {Object} object The object to compare.
4747 * @param {Object} other The other object to compare.
4748 * @param {string} tag The `toStringTag` of the objects to compare.
4749 * @param {Function} equalFunc The function to determine equivalents of values.
4750 * @param {Function} [customizer] The function to customize comparisons.
4751 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4752 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
4754 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
4756 case arrayBufferTag:
4757 if ((object.byteLength != other.byteLength) ||
4758 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
4765 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
4766 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
4767 return +object == +other;
4770 return object.name == other.name && object.message == other.message;
4773 // Treat `NaN` vs. `NaN` as equal.
4774 return (object != +object) ? other != +other : object == +other;
4778 // Coerce regexes to strings and treat strings primitives and string
4779 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
4780 return object == (other + '');
4783 var convert = mapToArray;
4786 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
4787 convert || (convert = setToArray);
4789 // Recursively compare objects (susceptible to call stack limits).
4790 return (isPartial || object.size == other.size) &&
4791 equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG);
4794 return !!Symbol && (symbolValueOf.call(object) == symbolValueOf.call(other));
4800 * A specialized version of `baseIsEqualDeep` for objects with support for
4801 * partial deep comparisons.
4804 * @param {Object} object The object to compare.
4805 * @param {Object} other The other object to compare.
4806 * @param {Function} equalFunc The function to determine equivalents of values.
4807 * @param {Function} [customizer] The function to customize comparisons.
4808 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4809 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
4810 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
4812 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
4813 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
4814 objProps = keys(object),
4815 objLength = objProps.length,
4816 othProps = keys(other),
4817 othLength = othProps.length;
4819 if (objLength != othLength && !isPartial) {
4822 var index = objLength;
4824 var key = objProps[index];
4825 if (!(isPartial ? key in other : baseHas(other, key))) {
4829 // Assume cyclic values are equal.
4830 var stacked = stack.get(object);
4832 return stacked == other;
4835 stack.set(object, other);
4837 var skipCtor = isPartial;
4838 while (++index < objLength) {
4839 key = objProps[index];
4840 var objValue = object[key],
4841 othValue = other[key];
4844 var compared = isPartial
4845 ? customizer(othValue, objValue, key, other, object, stack)
4846 : customizer(objValue, othValue, key, object, other, stack);
4848 // Recursively compare objects (susceptible to call stack limits).
4849 if (!(compared === undefined
4850 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
4856 skipCtor || (skipCtor = key == 'constructor');
4858 if (result && !skipCtor) {
4859 var objCtor = object.constructor,
4860 othCtor = other.constructor;
4862 // Non `Object` object instances with different constructors are not equal.
4863 if (objCtor != othCtor &&
4864 ('constructor' in object && 'constructor' in other) &&
4865 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
4866 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
4870 stack['delete'](object);
4875 * Gets metadata for `func`.
4878 * @param {Function} func The function to query.
4879 * @returns {*} Returns the metadata for `func`.
4881 var getData = !metaMap ? noop : function(func) {
4882 return metaMap.get(func);
4886 * Gets the name of `func`.
4889 * @param {Function} func The function to query.
4890 * @returns {string} Returns the function name.
4892 function getFuncName(func) {
4893 var result = (func.name + ''),
4894 array = realNames[result],
4895 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
4898 var data = array[length],
4899 otherFunc = data.func;
4900 if (otherFunc == null || otherFunc == func) {
4908 * Gets the appropriate "iteratee" function. If the `_.iteratee` method is
4909 * customized this function returns the custom method, otherwise it returns
4910 * `baseIteratee`. If arguments are provided the chosen function is invoked
4911 * with them and its result is returned.
4914 * @param {*} [value] The value to convert to an iteratee.
4915 * @param {number} [arity] The arity of the created iteratee.
4916 * @returns {Function} Returns the chosen function or its result.
4918 function getIteratee() {
4919 var result = lodash.iteratee || iteratee;
4920 result = result === iteratee ? baseIteratee : result;
4921 return arguments.length ? result(arguments[0], arguments[1]) : result;
4925 * Gets the "length" property value of `object`.
4927 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
4928 * that affects Safari on at least iOS 8.1-8.3 ARM64.
4931 * @param {Object} object The object to query.
4932 * @returns {*} Returns the "length" value.
4934 var getLength = baseProperty('length');
4937 * Gets the property names, values, and compare flags of `object`.
4940 * @param {Object} object The object to query.
4941 * @returns {Array} Returns the match data of `object`.
4943 function getMatchData(object) {
4944 var result = toPairs(object),
4945 length = result.length;
4948 result[length][2] = isStrictComparable(result[length][1]);
4954 * Gets the native function at `key` of `object`.
4957 * @param {Object} object The object to query.
4958 * @param {string} key The key of the method to get.
4959 * @returns {*} Returns the function if it's native, else `undefined`.
4961 function getNative(object, key) {
4962 var value = object == null ? undefined : object[key];
4963 return isNative(value) ? value : undefined;
4967 * Gets the argument placeholder value for `func`.
4970 * @param {Function} func The function to inspect.
4971 * @returns {*} Returns the placeholder value.
4973 function getPlaceholder(func) {
4974 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
4975 return object.placeholder;
4979 * Creates an array of the own symbol properties of `object`.
4982 * @param {Object} object The object to query.
4983 * @returns {Array} Returns the array of symbols.
4985 var getSymbols = getOwnPropertySymbols || function() {
4990 * Gets the `toStringTag` of `value`.
4993 * @param {*} value The value to query.
4994 * @returns {string} Returns the `toStringTag`.
4996 function getTag(value) {
4997 return objectToString.call(value);
5000 // Fallback for IE 11 providing `toStringTag` values for maps, sets, and weakmaps.
5001 if ((Map && getTag(new Map) != mapTag) ||
5002 (Set && getTag(new Set) != setTag) ||
5003 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
5004 getTag = function(value) {
5005 var result = objectToString.call(value),
5006 Ctor = result == objectTag ? value.constructor : null,
5007 ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '';
5010 switch (ctorString) {
5011 case mapCtorString: return mapTag;
5012 case setCtorString: return setTag;
5013 case weakMapCtorString: return weakMapTag;
5021 * Gets the view, applying any `transforms` to the `start` and `end` positions.
5024 * @param {number} start The start of the view.
5025 * @param {number} end The end of the view.
5026 * @param {Array} transforms The transformations to apply to the view.
5027 * @returns {Object} Returns an object containing the `start` and `end`
5028 * positions of the view.
5030 function getView(start, end, transforms) {
5032 length = transforms.length;
5034 while (++index < length) {
5035 var data = transforms[index],
5038 switch (data.type) {
5039 case 'drop': start += size; break;
5040 case 'dropRight': end -= size; break;
5041 case 'take': end = nativeMin(end, start + size); break;
5042 case 'takeRight': start = nativeMax(start, end - size); break;
5045 return { 'start': start, 'end': end };
5049 * Checks if `path` exists on `object`.
5052 * @param {Object} object The object to query.
5053 * @param {Array|string} path The path to check.
5054 * @param {Function} hasFunc The function to check properties.
5055 * @returns {boolean} Returns `true` if `path` exists, else `false`.
5057 function hasPath(object, path, hasFunc) {
5058 if (object == null) {
5061 var result = hasFunc(object, path);
5062 if (!result && !isKey(path)) {
5063 path = baseCastPath(path);
5064 object = parent(object, path);
5065 if (object != null) {
5067 result = hasFunc(object, path);
5070 var length = object ? object.length : undefined;
5072 !!length && isLength(length) && isIndex(path, length) &&
5073 (isArray(object) || isString(object) || isArguments(object))
5078 * Initializes an array clone.
5081 * @param {Array} array The array to clone.
5082 * @returns {Array} Returns the initialized clone.
5084 function initCloneArray(array) {
5085 var length = array.length,
5086 result = array.constructor(length);
5088 // Add properties assigned by `RegExp#exec`.
5089 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
5090 result.index = array.index;
5091 result.input = array.input;
5097 * Initializes an object clone.
5100 * @param {Object} object The object to clone.
5101 * @returns {Object} Returns the initialized clone.
5103 function initCloneObject(object) {
5104 return (isFunction(object.constructor) && !isPrototype(object))
5105 ? baseCreate(getPrototypeOf(object))
5110 * Initializes an object clone based on its `toStringTag`.
5112 * **Note:** This function only supports cloning values with tags of
5113 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5116 * @param {Object} object The object to clone.
5117 * @param {string} tag The `toStringTag` of the object to clone.
5118 * @param {boolean} [isDeep] Specify a deep clone.
5119 * @returns {Object} Returns the initialized clone.
5121 function initCloneByTag(object, tag, isDeep) {
5122 var Ctor = object.constructor;
5124 case arrayBufferTag:
5125 return cloneArrayBuffer(object);
5129 return new Ctor(+object);
5131 case float32Tag: case float64Tag:
5132 case int8Tag: case int16Tag: case int32Tag:
5133 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
5134 return cloneTypedArray(object, isDeep);
5137 return cloneMap(object);
5141 return new Ctor(object);
5144 return cloneRegExp(object);
5147 return cloneSet(object);
5150 return cloneSymbol(object);
5155 * Creates an array of index keys for `object` values of arrays,
5156 * `arguments` objects, and strings, otherwise `null` is returned.
5159 * @param {Object} object The object to query.
5160 * @returns {Array|null} Returns index keys, else `null`.
5162 function indexKeys(object) {
5163 var length = object ? object.length : undefined;
5164 if (isLength(length) &&
5165 (isArray(object) || isString(object) || isArguments(object))) {
5166 return baseTimes(length, String);
5172 * Checks if the given arguments are from an iteratee call.
5175 * @param {*} value The potential iteratee value argument.
5176 * @param {*} index The potential iteratee index or key argument.
5177 * @param {*} object The potential iteratee object argument.
5178 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
5180 function isIterateeCall(value, index, object) {
5181 if (!isObject(object)) {
5184 var type = typeof index;
5185 if (type == 'number'
5186 ? (isArrayLike(object) && isIndex(index, object.length))
5187 : (type == 'string' && index in object)) {
5188 return eq(object[index], value);
5194 * Checks if `value` is a property name and not a property path.
5197 * @param {*} value The value to check.
5198 * @param {Object} [object] The object to query keys on.
5199 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
5201 function isKey(value, object) {
5202 if (typeof value == 'number') {
5205 return !isArray(value) &&
5206 (reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
5207 (object != null && value in Object(object)));
5211 * Checks if `value` is suitable for use as unique object key.
5214 * @param {*} value The value to check.
5215 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
5217 function isKeyable(value) {
5218 var type = typeof value;
5219 return type == 'number' || type == 'boolean' ||
5220 (type == 'string' && value != '__proto__') || value == null;
5224 * Checks if `func` has a lazy counterpart.
5227 * @param {Function} func The function to check.
5228 * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
5230 function isLaziable(func) {
5231 var funcName = getFuncName(func),
5232 other = lodash[funcName];
5234 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
5237 if (func === other) {
5240 var data = getData(other);
5241 return !!data && func === data[0];
5245 * Checks if `value` is likely a prototype object.
5248 * @param {*} value The value to check.
5249 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
5251 function isPrototype(value) {
5252 var Ctor = value && value.constructor,
5253 proto = (isFunction(Ctor) && Ctor.prototype) || objectProto;
5255 return value === proto;
5259 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
5262 * @param {*} value The value to check.
5263 * @returns {boolean} Returns `true` if `value` if suitable for strict
5264 * equality comparisons, else `false`.
5266 function isStrictComparable(value) {
5267 return value === value && !isObject(value);
5271 * Merges the function metadata of `source` into `data`.
5273 * Merging metadata reduces the number of wrappers used to invoke a function.
5274 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
5275 * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
5276 * modify function arguments, making the order in which they are executed important,
5277 * preventing the merging of metadata. However, we make an exception for a safe
5278 * combined case where curried functions have `_.ary` and or `_.rearg` applied.
5281 * @param {Array} data The destination metadata.
5282 * @param {Array} source The source metadata.
5283 * @returns {Array} Returns `data`.
5285 function mergeData(data, source) {
5286 var bitmask = data[1],
5287 srcBitmask = source[1],
5288 newBitmask = bitmask | srcBitmask,
5289 isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
5292 ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
5293 ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
5294 ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
5296 // Exit early if metadata can't be merged.
5297 if (!(isCommon || isCombo)) {
5300 // Use source `thisArg` if available.
5301 if (srcBitmask & BIND_FLAG) {
5302 data[2] = source[2];
5303 // Set when currying a bound function.
5304 newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
5306 // Compose partial arguments.
5307 var value = source[3];
5309 var partials = data[3];
5310 data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray(value);
5311 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : copyArray(source[4]);
5313 // Compose partial right arguments.
5317 data[5] = partials ? composeArgsRight(partials, value, source[6]) : copyArray(value);
5318 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : copyArray(source[6]);
5320 // Use source `argPos` if available.
5323 data[7] = copyArray(value);
5325 // Use source `ary` if it's smaller.
5326 if (srcBitmask & ARY_FLAG) {
5327 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
5329 // Use source `arity` if one is not provided.
5330 if (data[9] == null) {
5331 data[9] = source[9];
5333 // Use source `func` and merge bitmasks.
5334 data[0] = source[0];
5335 data[1] = newBitmask;
5341 * Used by `_.defaultsDeep` to customize its `_.merge` use.
5344 * @param {*} objValue The destination value.
5345 * @param {*} srcValue The source value.
5346 * @param {string} key The key of the property to merge.
5347 * @param {Object} object The parent object of `objValue`.
5348 * @param {Object} source The parent object of `srcValue`.
5349 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
5350 * @returns {*} Returns the value to assign.
5352 function mergeDefaults(objValue, srcValue, key, object, source, stack) {
5353 if (isObject(objValue) && isObject(srcValue)) {
5354 stack.set(srcValue, objValue);
5355 baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
5361 * Gets the parent value at `path` of `object`.
5364 * @param {Object} object The object to query.
5365 * @param {Array} path The path to get the parent value of.
5366 * @returns {*} Returns the parent value.
5368 function parent(object, path) {
5369 return path.length == 1 ? object : get(object, baseSlice(path, 0, -1));
5373 * Reorder `array` according to the specified indexes where the element at
5374 * the first index is assigned as the first element, the element at
5375 * the second index is assigned as the second element, and so on.
5378 * @param {Array} array The array to reorder.
5379 * @param {Array} indexes The arranged array indexes.
5380 * @returns {Array} Returns `array`.
5382 function reorder(array, indexes) {
5383 var arrLength = array.length,
5384 length = nativeMin(indexes.length, arrLength),
5385 oldArray = copyArray(array);
5388 var index = indexes[length];
5389 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
5395 * Sets metadata for `func`.
5397 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
5398 * period of time, it will trip its breaker and transition to an identity function
5399 * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
5403 * @param {Function} func The function to associate metadata with.
5404 * @param {*} data The metadata.
5405 * @returns {Function} Returns `func`.
5407 var setData = (function() {
5411 return function(key, value) {
5413 remaining = HOT_SPAN - (stamp - lastCalled);
5416 if (remaining > 0) {
5417 if (++count >= HOT_COUNT) {
5423 return baseSetData(key, value);
5428 * Converts `string` to a property path array.
5431 * @param {string} string The string to convert.
5432 * @returns {Array} Returns the property path array.
5434 function stringToPath(string) {
5436 toString(string).replace(rePropName, function(match, number, quote, string) {
5437 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
5443 * Creates a clone of `wrapper`.
5446 * @param {Object} wrapper The wrapper to clone.
5447 * @returns {Object} Returns the cloned wrapper.
5449 function wrapperClone(wrapper) {
5450 if (wrapper instanceof LazyWrapper) {
5451 return wrapper.clone();
5453 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
5454 result.__actions__ = copyArray(wrapper.__actions__);
5455 result.__index__ = wrapper.__index__;
5456 result.__values__ = wrapper.__values__;
5460 /*------------------------------------------------------------------------*/
5463 * Creates an array of elements split into groups the length of `size`.
5464 * If `array` can't be split evenly, the final chunk will be the remaining
5470 * @param {Array} array The array to process.
5471 * @param {number} [size=0] The length of each chunk.
5472 * @returns {Array} Returns the new array containing chunks.
5475 * _.chunk(['a', 'b', 'c', 'd'], 2);
5476 * // => [['a', 'b'], ['c', 'd']]
5478 * _.chunk(['a', 'b', 'c', 'd'], 3);
5479 * // => [['a', 'b', 'c'], ['d']]
5481 function chunk(array, size) {
5482 size = nativeMax(toInteger(size), 0);
5484 var length = array ? array.length : 0;
5485 if (!length || size < 1) {
5490 result = Array(nativeCeil(length / size));
5492 while (index < length) {
5493 result[++resIndex] = baseSlice(array, index, (index += size));
5499 * Creates an array with all falsey values removed. The values `false`, `null`,
5500 * `0`, `""`, `undefined`, and `NaN` are falsey.
5505 * @param {Array} array The array to compact.
5506 * @returns {Array} Returns the new array of filtered values.
5509 * _.compact([0, 1, false, 2, '', 3]);
5512 function compact(array) {
5514 length = array ? array.length : 0,
5518 while (++index < length) {
5519 var value = array[index];
5521 result[++resIndex] = value;
5528 * Creates a new array concatenating `array` with any additional arrays
5534 * @param {Array} array The array to concatenate.
5535 * @param {...*} [values] The values to concatenate.
5536 * @returns {Array} Returns the new concatenated array.
5540 * var other = _.concat(array, 2, [3], [[4]]);
5542 * console.log(other);
5543 * // => [1, 2, 3, [4]]
5545 * console.log(array);
5548 var concat = rest(function(array, values) {
5549 if (!isArray(array)) {
5550 array = array == null ? [] : [Object(array)];
5552 values = baseFlatten(values, 1);
5553 return arrayConcat(array, values);
5557 * Creates an array of unique `array` values not included in the other
5558 * given arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5559 * for equality comparisons.
5564 * @param {Array} array The array to inspect.
5565 * @param {...Array} [values] The values to exclude.
5566 * @returns {Array} Returns the new array of filtered values.
5569 * _.difference([3, 2, 1], [4, 2]);
5572 var difference = rest(function(array, values) {
5573 return isArrayLikeObject(array)
5574 ? baseDifference(array, baseFlatten(values, 1, true))
5579 * This method is like `_.difference` except that it accepts `iteratee` which
5580 * is invoked for each element of `array` and `values` to generate the criterion
5581 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
5586 * @param {Array} array The array to inspect.
5587 * @param {...Array} [values] The values to exclude.
5588 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
5589 * @returns {Array} Returns the new array of filtered values.
5592 * _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
5595 * // The `_.property` iteratee shorthand.
5596 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
5597 * // => [{ 'x': 2 }]
5599 var differenceBy = rest(function(array, values) {
5600 var iteratee = last(values);
5601 if (isArrayLikeObject(iteratee)) {
5602 iteratee = undefined;
5604 return isArrayLikeObject(array)
5605 ? baseDifference(array, baseFlatten(values, 1, true), getIteratee(iteratee))
5610 * This method is like `_.difference` except that it accepts `comparator`
5611 * which is invoked to compare elements of `array` to `values`. The comparator
5612 * is invoked with two arguments: (arrVal, othVal).
5617 * @param {Array} array The array to inspect.
5618 * @param {...Array} [values] The values to exclude.
5619 * @param {Function} [comparator] The comparator invoked per element.
5620 * @returns {Array} Returns the new array of filtered values.
5623 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
5625 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
5626 * // => [{ 'x': 2, 'y': 1 }]
5628 var differenceWith = rest(function(array, values) {
5629 var comparator = last(values);
5630 if (isArrayLikeObject(comparator)) {
5631 comparator = undefined;
5633 return isArrayLikeObject(array)
5634 ? baseDifference(array, baseFlatten(values, 1, true), undefined, comparator)
5639 * Creates a slice of `array` with `n` elements dropped from the beginning.
5644 * @param {Array} array The array to query.
5645 * @param {number} [n=1] The number of elements to drop.
5646 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
5647 * @returns {Array} Returns the slice of `array`.
5650 * _.drop([1, 2, 3]);
5653 * _.drop([1, 2, 3], 2);
5656 * _.drop([1, 2, 3], 5);
5659 * _.drop([1, 2, 3], 0);
5662 function drop(array, n, guard) {
5663 var length = array ? array.length : 0;
5667 n = (guard || n === undefined) ? 1 : toInteger(n);
5668 return baseSlice(array, n < 0 ? 0 : n, length);
5672 * Creates a slice of `array` with `n` elements dropped from the end.
5677 * @param {Array} array The array to query.
5678 * @param {number} [n=1] The number of elements to drop.
5679 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
5680 * @returns {Array} Returns the slice of `array`.
5683 * _.dropRight([1, 2, 3]);
5686 * _.dropRight([1, 2, 3], 2);
5689 * _.dropRight([1, 2, 3], 5);
5692 * _.dropRight([1, 2, 3], 0);
5695 function dropRight(array, n, guard) {
5696 var length = array ? array.length : 0;
5700 n = (guard || n === undefined) ? 1 : toInteger(n);
5702 return baseSlice(array, 0, n < 0 ? 0 : n);
5706 * Creates a slice of `array` excluding elements dropped from the end.
5707 * Elements are dropped until `predicate` returns falsey. The predicate is
5708 * invoked with three arguments: (value, index, array).
5713 * @param {Array} array The array to query.
5714 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5715 * @returns {Array} Returns the slice of `array`.
5719 * { 'user': 'barney', 'active': true },
5720 * { 'user': 'fred', 'active': false },
5721 * { 'user': 'pebbles', 'active': false }
5724 * _.dropRightWhile(users, function(o) { return !o.active; });
5725 * // => objects for ['barney']
5727 * // The `_.matches` iteratee shorthand.
5728 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
5729 * // => objects for ['barney', 'fred']
5731 * // The `_.matchesProperty` iteratee shorthand.
5732 * _.dropRightWhile(users, ['active', false]);
5733 * // => objects for ['barney']
5735 * // The `_.property` iteratee shorthand.
5736 * _.dropRightWhile(users, 'active');
5737 * // => objects for ['barney', 'fred', 'pebbles']
5739 function dropRightWhile(array, predicate) {
5740 return (array && array.length)
5741 ? baseWhile(array, getIteratee(predicate, 3), true, true)
5746 * Creates a slice of `array` excluding elements dropped from the beginning.
5747 * Elements are dropped until `predicate` returns falsey. The predicate is
5748 * invoked with three arguments: (value, index, array).
5753 * @param {Array} array The array to query.
5754 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5755 * @returns {Array} Returns the slice of `array`.
5759 * { 'user': 'barney', 'active': false },
5760 * { 'user': 'fred', 'active': false },
5761 * { 'user': 'pebbles', 'active': true }
5764 * _.dropWhile(users, function(o) { return !o.active; });
5765 * // => objects for ['pebbles']
5767 * // The `_.matches` iteratee shorthand.
5768 * _.dropWhile(users, { 'user': 'barney', 'active': false });
5769 * // => objects for ['fred', 'pebbles']
5771 * // The `_.matchesProperty` iteratee shorthand.
5772 * _.dropWhile(users, ['active', false]);
5773 * // => objects for ['pebbles']
5775 * // The `_.property` iteratee shorthand.
5776 * _.dropWhile(users, 'active');
5777 * // => objects for ['barney', 'fred', 'pebbles']
5779 function dropWhile(array, predicate) {
5780 return (array && array.length)
5781 ? baseWhile(array, getIteratee(predicate, 3), true)
5786 * Fills elements of `array` with `value` from `start` up to, but not
5789 * **Note:** This method mutates `array`.
5794 * @param {Array} array The array to fill.
5795 * @param {*} value The value to fill `array` with.
5796 * @param {number} [start=0] The start position.
5797 * @param {number} [end=array.length] The end position.
5798 * @returns {Array} Returns `array`.
5801 * var array = [1, 2, 3];
5803 * _.fill(array, 'a');
5804 * console.log(array);
5805 * // => ['a', 'a', 'a']
5807 * _.fill(Array(3), 2);
5810 * _.fill([4, 6, 8, 10], '*', 1, 3);
5811 * // => [4, '*', '*', 10]
5813 function fill(array, value, start, end) {
5814 var length = array ? array.length : 0;
5818 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
5822 return baseFill(array, value, start, end);
5826 * This method is like `_.find` except that it returns the index of the first
5827 * element `predicate` returns truthy for instead of the element itself.
5832 * @param {Array} array The array to search.
5833 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5834 * @returns {number} Returns the index of the found element, else `-1`.
5838 * { 'user': 'barney', 'active': false },
5839 * { 'user': 'fred', 'active': false },
5840 * { 'user': 'pebbles', 'active': true }
5843 * _.findIndex(users, function(o) { return o.user == 'barney'; });
5846 * // The `_.matches` iteratee shorthand.
5847 * _.findIndex(users, { 'user': 'fred', 'active': false });
5850 * // The `_.matchesProperty` iteratee shorthand.
5851 * _.findIndex(users, ['active', false]);
5854 * // The `_.property` iteratee shorthand.
5855 * _.findIndex(users, 'active');
5858 function findIndex(array, predicate) {
5859 return (array && array.length)
5860 ? baseFindIndex(array, getIteratee(predicate, 3))
5865 * This method is like `_.findIndex` except that it iterates over elements
5866 * of `collection` from right to left.
5871 * @param {Array} array The array to search.
5872 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5873 * @returns {number} Returns the index of the found element, else `-1`.
5877 * { 'user': 'barney', 'active': true },
5878 * { 'user': 'fred', 'active': false },
5879 * { 'user': 'pebbles', 'active': false }
5882 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
5885 * // The `_.matches` iteratee shorthand.
5886 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
5889 * // The `_.matchesProperty` iteratee shorthand.
5890 * _.findLastIndex(users, ['active', false]);
5893 * // The `_.property` iteratee shorthand.
5894 * _.findLastIndex(users, 'active');
5897 function findLastIndex(array, predicate) {
5898 return (array && array.length)
5899 ? baseFindIndex(array, getIteratee(predicate, 3), true)
5904 * Flattens `array` a single level deep.
5909 * @param {Array} array The array to flatten.
5910 * @returns {Array} Returns the new flattened array.
5913 * _.flatten([1, [2, [3, [4]], 5]]);
5914 * // => [1, 2, [3, [4]], 5]
5916 function flatten(array) {
5917 var length = array ? array.length : 0;
5918 return length ? baseFlatten(array, 1) : [];
5922 * Recursively flattens `array`.
5927 * @param {Array} array The array to flatten.
5928 * @returns {Array} Returns the new flattened array.
5931 * _.flattenDeep([1, [2, [3, [4]], 5]]);
5932 * // => [1, 2, 3, 4, 5]
5934 function flattenDeep(array) {
5935 var length = array ? array.length : 0;
5936 return length ? baseFlatten(array, INFINITY) : [];
5940 * Recursively flatten `array` up to `depth` times.
5945 * @param {Array} array The array to flatten.
5946 * @param {number} [depth=1] The maximum recursion depth.
5947 * @returns {Array} Returns the new flattened array.
5950 * var array = [1, [2, [3, [4]], 5]];
5952 * _.flattenDepth(array, 1);
5953 * // => [1, 2, [3, [4]], 5]
5955 * _.flattenDepth(array, 2);
5956 * // => [1, 2, 3, [4], 5]
5958 function flattenDepth(array, depth) {
5959 var length = array ? array.length : 0;
5963 depth = depth === undefined ? 1 : toInteger(depth);
5964 return baseFlatten(array, depth);
5968 * The inverse of `_.toPairs`; this method returns an object composed
5969 * from key-value `pairs`.
5974 * @param {Array} pairs The key-value pairs.
5975 * @returns {Object} Returns the new object.
5978 * _.fromPairs([['fred', 30], ['barney', 40]]);
5979 * // => { 'fred': 30, 'barney': 40 }
5981 function fromPairs(pairs) {
5983 length = pairs ? pairs.length : 0,
5986 while (++index < length) {
5987 var pair = pairs[index];
5988 result[pair[0]] = pair[1];
5994 * Gets the first element of `array`.
6000 * @param {Array} array The array to query.
6001 * @returns {*} Returns the first element of `array`.
6004 * _.head([1, 2, 3]);
6010 function head(array) {
6011 return array ? array[0] : undefined;
6015 * Gets the index at which the first occurrence of `value` is found in `array`
6016 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6017 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
6018 * from the end of `array`.
6023 * @param {Array} array The array to search.
6024 * @param {*} value The value to search for.
6025 * @param {number} [fromIndex=0] The index to search from.
6026 * @returns {number} Returns the index of the matched value, else `-1`.
6029 * _.indexOf([1, 2, 1, 2], 2);
6032 * // Search from the `fromIndex`.
6033 * _.indexOf([1, 2, 1, 2], 2, 2);
6036 function indexOf(array, value, fromIndex) {
6037 var length = array ? array.length : 0;
6041 fromIndex = toInteger(fromIndex);
6042 if (fromIndex < 0) {
6043 fromIndex = nativeMax(length + fromIndex, 0);
6045 return baseIndexOf(array, value, fromIndex);
6049 * Gets all but the last element of `array`.
6054 * @param {Array} array The array to query.
6055 * @returns {Array} Returns the slice of `array`.
6058 * _.initial([1, 2, 3]);
6061 function initial(array) {
6062 return dropRight(array, 1);
6066 * Creates an array of unique values that are included in all given arrays
6067 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6068 * for equality comparisons.
6073 * @param {...Array} [arrays] The arrays to inspect.
6074 * @returns {Array} Returns the new array of shared values.
6077 * _.intersection([2, 1], [4, 2], [1, 2]);
6080 var intersection = rest(function(arrays) {
6081 var mapped = arrayMap(arrays, baseCastArrayLikeObject);
6082 return (mapped.length && mapped[0] === arrays[0])
6083 ? baseIntersection(mapped)
6088 * This method is like `_.intersection` except that it accepts `iteratee`
6089 * which is invoked for each element of each `arrays` to generate the criterion
6090 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
6095 * @param {...Array} [arrays] The arrays to inspect.
6096 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6097 * @returns {Array} Returns the new array of shared values.
6100 * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
6103 * // The `_.property` iteratee shorthand.
6104 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
6105 * // => [{ 'x': 1 }]
6107 var intersectionBy = rest(function(arrays) {
6108 var iteratee = last(arrays),
6109 mapped = arrayMap(arrays, baseCastArrayLikeObject);
6111 if (iteratee === last(mapped)) {
6112 iteratee = undefined;
6116 return (mapped.length && mapped[0] === arrays[0])
6117 ? baseIntersection(mapped, getIteratee(iteratee))
6122 * This method is like `_.intersection` except that it accepts `comparator`
6123 * which is invoked to compare elements of `arrays`. The comparator is invoked
6124 * with two arguments: (arrVal, othVal).
6129 * @param {...Array} [arrays] The arrays to inspect.
6130 * @param {Function} [comparator] The comparator invoked per element.
6131 * @returns {Array} Returns the new array of shared values.
6134 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6135 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6137 * _.intersectionWith(objects, others, _.isEqual);
6138 * // => [{ 'x': 1, 'y': 2 }]
6140 var intersectionWith = rest(function(arrays) {
6141 var comparator = last(arrays),
6142 mapped = arrayMap(arrays, baseCastArrayLikeObject);
6144 if (comparator === last(mapped)) {
6145 comparator = undefined;
6149 return (mapped.length && mapped[0] === arrays[0])
6150 ? baseIntersection(mapped, undefined, comparator)
6155 * Converts all elements in `array` into a string separated by `separator`.
6160 * @param {Array} array The array to convert.
6161 * @param {string} [separator=','] The element separator.
6162 * @returns {string} Returns the joined string.
6165 * _.join(['a', 'b', 'c'], '~');
6168 function join(array, separator) {
6169 return array ? nativeJoin.call(array, separator) : '';
6173 * Gets the last element of `array`.
6178 * @param {Array} array The array to query.
6179 * @returns {*} Returns the last element of `array`.
6182 * _.last([1, 2, 3]);
6185 function last(array) {
6186 var length = array ? array.length : 0;
6187 return length ? array[length - 1] : undefined;
6191 * This method is like `_.indexOf` except that it iterates over elements of
6192 * `array` from right to left.
6197 * @param {Array} array The array to search.
6198 * @param {*} value The value to search for.
6199 * @param {number} [fromIndex=array.length-1] The index to search from.
6200 * @returns {number} Returns the index of the matched value, else `-1`.
6203 * _.lastIndexOf([1, 2, 1, 2], 2);
6206 * // Search from the `fromIndex`.
6207 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
6210 function lastIndexOf(array, value, fromIndex) {
6211 var length = array ? array.length : 0;
6216 if (fromIndex !== undefined) {
6217 index = toInteger(fromIndex);
6218 index = (index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1)) + 1;
6220 if (value !== value) {
6221 return indexOfNaN(array, index, true);
6224 if (array[index] === value) {
6232 * Removes all given values from `array` using
6233 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6234 * for equality comparisons.
6236 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
6237 * to remove elements from an array by predicate.
6242 * @param {Array} array The array to modify.
6243 * @param {...*} [values] The values to remove.
6244 * @returns {Array} Returns `array`.
6247 * var array = [1, 2, 3, 1, 2, 3];
6249 * _.pull(array, 2, 3);
6250 * console.log(array);
6253 var pull = rest(pullAll);
6256 * This method is like `_.pull` except that it accepts an array of values to remove.
6258 * **Note:** Unlike `_.difference`, this method mutates `array`.
6263 * @param {Array} array The array to modify.
6264 * @param {Array} values The values to remove.
6265 * @returns {Array} Returns `array`.
6268 * var array = [1, 2, 3, 1, 2, 3];
6270 * _.pullAll(array, [2, 3]);
6271 * console.log(array);
6274 function pullAll(array, values) {
6275 return (array && array.length && values && values.length)
6276 ? basePullAll(array, values)
6281 * This method is like `_.pullAll` except that it accepts `iteratee` which is
6282 * invoked for each element of `array` and `values` to generate the criterion
6283 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
6285 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
6290 * @param {Array} array The array to modify.
6291 * @param {Array} values The values to remove.
6292 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6293 * @returns {Array} Returns `array`.
6296 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
6298 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
6299 * console.log(array);
6300 * // => [{ 'x': 2 }]
6302 function pullAllBy(array, values, iteratee) {
6303 return (array && array.length && values && values.length)
6304 ? basePullAllBy(array, values, getIteratee(iteratee))
6309 * Removes elements from `array` corresponding to `indexes` and returns an
6310 * array of removed elements.
6312 * **Note:** Unlike `_.at`, this method mutates `array`.
6317 * @param {Array} array The array to modify.
6318 * @param {...(number|number[])} [indexes] The indexes of elements to remove,
6319 * specified individually or in arrays.
6320 * @returns {Array} Returns the new array of removed elements.
6323 * var array = [5, 10, 15, 20];
6324 * var evens = _.pullAt(array, 1, 3);
6326 * console.log(array);
6329 * console.log(evens);
6332 var pullAt = rest(function(array, indexes) {
6333 indexes = arrayMap(baseFlatten(indexes, 1), String);
6335 var result = baseAt(array, indexes);
6336 basePullAt(array, indexes.sort(compareAscending));
6341 * Removes all elements from `array` that `predicate` returns truthy for
6342 * and returns an array of the removed elements. The predicate is invoked
6343 * with three arguments: (value, index, array).
6345 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
6346 * to pull elements from an array by value.
6351 * @param {Array} array The array to modify.
6352 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6353 * @returns {Array} Returns the new array of removed elements.
6356 * var array = [1, 2, 3, 4];
6357 * var evens = _.remove(array, function(n) {
6358 * return n % 2 == 0;
6361 * console.log(array);
6364 * console.log(evens);
6367 function remove(array, predicate) {
6369 if (!(array && array.length)) {
6374 length = array.length;
6376 predicate = getIteratee(predicate, 3);
6377 while (++index < length) {
6378 var value = array[index];
6379 if (predicate(value, index, array)) {
6381 indexes.push(index);
6384 basePullAt(array, indexes);
6389 * Reverses `array` so that the first element becomes the last, the second
6390 * element becomes the second to last, and so on.
6392 * **Note:** This method mutates `array` and is based on
6393 * [`Array#reverse`](https://mdn.io/Array/reverse).
6398 * @returns {Array} Returns `array`.
6401 * var array = [1, 2, 3];
6406 * console.log(array);
6409 function reverse(array) {
6410 return array ? nativeReverse.call(array) : array;
6414 * Creates a slice of `array` from `start` up to, but not including, `end`.
6416 * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
6417 * to ensure dense arrays are returned.
6422 * @param {Array} array The array to slice.
6423 * @param {number} [start=0] The start position.
6424 * @param {number} [end=array.length] The end position.
6425 * @returns {Array} Returns the slice of `array`.
6427 function slice(array, start, end) {
6428 var length = array ? array.length : 0;
6432 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
6437 start = start == null ? 0 : toInteger(start);
6438 end = end === undefined ? length : toInteger(end);
6440 return baseSlice(array, start, end);
6444 * Uses a binary search to determine the lowest index at which `value` should
6445 * be inserted into `array` in order to maintain its sort order.
6450 * @param {Array} array The sorted array to inspect.
6451 * @param {*} value The value to evaluate.
6452 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6455 * _.sortedIndex([30, 50], 40);
6458 * _.sortedIndex([4, 5], 4);
6461 function sortedIndex(array, value) {
6462 return baseSortedIndex(array, value);
6466 * This method is like `_.sortedIndex` except that it accepts `iteratee`
6467 * which is invoked for `value` and each element of `array` to compute their
6468 * sort ranking. The iteratee is invoked with one argument: (value).
6473 * @param {Array} array The sorted array to inspect.
6474 * @param {*} value The value to evaluate.
6475 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6476 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6479 * var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 };
6481 * _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict));
6484 * // The `_.property` iteratee shorthand.
6485 * _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
6488 function sortedIndexBy(array, value, iteratee) {
6489 return baseSortedIndexBy(array, value, getIteratee(iteratee));
6493 * This method is like `_.indexOf` except that it performs a binary
6494 * search on a sorted `array`.
6499 * @param {Array} array The array to search.
6500 * @param {*} value The value to search for.
6501 * @returns {number} Returns the index of the matched value, else `-1`.
6504 * _.sortedIndexOf([1, 1, 2, 2], 2);
6507 function sortedIndexOf(array, value) {
6508 var length = array ? array.length : 0;
6510 var index = baseSortedIndex(array, value);
6511 if (index < length && eq(array[index], value)) {
6519 * This method is like `_.sortedIndex` except that it returns the highest
6520 * index at which `value` should be inserted into `array` in order to
6521 * maintain its sort order.
6526 * @param {Array} array The sorted array to inspect.
6527 * @param {*} value The value to evaluate.
6528 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6531 * _.sortedLastIndex([4, 5], 4);
6534 function sortedLastIndex(array, value) {
6535 return baseSortedIndex(array, value, true);
6539 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
6540 * which is invoked for `value` and each element of `array` to compute their
6541 * sort ranking. The iteratee is invoked with one argument: (value).
6546 * @param {Array} array The sorted array to inspect.
6547 * @param {*} value The value to evaluate.
6548 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6549 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6552 * // The `_.property` iteratee shorthand.
6553 * _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
6556 function sortedLastIndexBy(array, value, iteratee) {
6557 return baseSortedIndexBy(array, value, getIteratee(iteratee), true);
6561 * This method is like `_.lastIndexOf` except that it performs a binary
6562 * search on a sorted `array`.
6567 * @param {Array} array The array to search.
6568 * @param {*} value The value to search for.
6569 * @returns {number} Returns the index of the matched value, else `-1`.
6572 * _.sortedLastIndexOf([1, 1, 2, 2], 2);
6575 function sortedLastIndexOf(array, value) {
6576 var length = array ? array.length : 0;
6578 var index = baseSortedIndex(array, value, true) - 1;
6579 if (eq(array[index], value)) {
6587 * This method is like `_.uniq` except that it's designed and optimized
6588 * for sorted arrays.
6593 * @param {Array} array The array to inspect.
6594 * @returns {Array} Returns the new duplicate free array.
6597 * _.sortedUniq([1, 1, 2]);
6600 function sortedUniq(array) {
6601 return (array && array.length)
6602 ? baseSortedUniq(array)
6607 * This method is like `_.uniqBy` except that it's designed and optimized
6608 * for sorted arrays.
6613 * @param {Array} array The array to inspect.
6614 * @param {Function} [iteratee] The iteratee invoked per element.
6615 * @returns {Array} Returns the new duplicate free array.
6618 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
6621 function sortedUniqBy(array, iteratee) {
6622 return (array && array.length)
6623 ? baseSortedUniqBy(array, getIteratee(iteratee))
6628 * Gets all but the first element of `array`.
6633 * @param {Array} array The array to query.
6634 * @returns {Array} Returns the slice of `array`.
6637 * _.tail([1, 2, 3]);
6640 function tail(array) {
6641 return drop(array, 1);
6645 * Creates a slice of `array` with `n` elements taken from the beginning.
6650 * @param {Array} array The array to query.
6651 * @param {number} [n=1] The number of elements to take.
6652 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
6653 * @returns {Array} Returns the slice of `array`.
6656 * _.take([1, 2, 3]);
6659 * _.take([1, 2, 3], 2);
6662 * _.take([1, 2, 3], 5);
6665 * _.take([1, 2, 3], 0);
6668 function take(array, n, guard) {
6669 if (!(array && array.length)) {
6672 n = (guard || n === undefined) ? 1 : toInteger(n);
6673 return baseSlice(array, 0, n < 0 ? 0 : n);
6677 * Creates a slice of `array` with `n` elements taken from the end.
6682 * @param {Array} array The array to query.
6683 * @param {number} [n=1] The number of elements to take.
6684 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
6685 * @returns {Array} Returns the slice of `array`.
6688 * _.takeRight([1, 2, 3]);
6691 * _.takeRight([1, 2, 3], 2);
6694 * _.takeRight([1, 2, 3], 5);
6697 * _.takeRight([1, 2, 3], 0);
6700 function takeRight(array, n, guard) {
6701 var length = array ? array.length : 0;
6705 n = (guard || n === undefined) ? 1 : toInteger(n);
6707 return baseSlice(array, n < 0 ? 0 : n, length);
6711 * Creates a slice of `array` with elements taken from the end. Elements are
6712 * taken until `predicate` returns falsey. The predicate is invoked with three
6713 * arguments: (value, index, array).
6718 * @param {Array} array The array to query.
6719 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6720 * @returns {Array} Returns the slice of `array`.
6724 * { 'user': 'barney', 'active': true },
6725 * { 'user': 'fred', 'active': false },
6726 * { 'user': 'pebbles', 'active': false }
6729 * _.takeRightWhile(users, function(o) { return !o.active; });
6730 * // => objects for ['fred', 'pebbles']
6732 * // The `_.matches` iteratee shorthand.
6733 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
6734 * // => objects for ['pebbles']
6736 * // The `_.matchesProperty` iteratee shorthand.
6737 * _.takeRightWhile(users, ['active', false]);
6738 * // => objects for ['fred', 'pebbles']
6740 * // The `_.property` iteratee shorthand.
6741 * _.takeRightWhile(users, 'active');
6744 function takeRightWhile(array, predicate) {
6745 return (array && array.length)
6746 ? baseWhile(array, getIteratee(predicate, 3), false, true)
6751 * Creates a slice of `array` with elements taken from the beginning. Elements
6752 * are taken until `predicate` returns falsey. The predicate is invoked with
6753 * three arguments: (value, index, array).
6758 * @param {Array} array The array to query.
6759 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6760 * @returns {Array} Returns the slice of `array`.
6764 * { 'user': 'barney', 'active': false },
6765 * { 'user': 'fred', 'active': false},
6766 * { 'user': 'pebbles', 'active': true }
6769 * _.takeWhile(users, function(o) { return !o.active; });
6770 * // => objects for ['barney', 'fred']
6772 * // The `_.matches` iteratee shorthand.
6773 * _.takeWhile(users, { 'user': 'barney', 'active': false });
6774 * // => objects for ['barney']
6776 * // The `_.matchesProperty` iteratee shorthand.
6777 * _.takeWhile(users, ['active', false]);
6778 * // => objects for ['barney', 'fred']
6780 * // The `_.property` iteratee shorthand.
6781 * _.takeWhile(users, 'active');
6784 function takeWhile(array, predicate) {
6785 return (array && array.length)
6786 ? baseWhile(array, getIteratee(predicate, 3))
6791 * Creates an array of unique values, in order, from all given arrays using
6792 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6793 * for equality comparisons.
6798 * @param {...Array} [arrays] The arrays to inspect.
6799 * @returns {Array} Returns the new array of combined values.
6802 * _.union([2, 1], [4, 2], [1, 2]);
6805 var union = rest(function(arrays) {
6806 return baseUniq(baseFlatten(arrays, 1, true));
6810 * This method is like `_.union` except that it accepts `iteratee` which is
6811 * invoked for each element of each `arrays` to generate the criterion by which
6812 * uniqueness is computed. The iteratee is invoked with one argument: (value).
6817 * @param {...Array} [arrays] The arrays to inspect.
6818 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6819 * @returns {Array} Returns the new array of combined values.
6822 * _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
6823 * // => [2.1, 1.2, 4.3]
6825 * // The `_.property` iteratee shorthand.
6826 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
6827 * // => [{ 'x': 1 }, { 'x': 2 }]
6829 var unionBy = rest(function(arrays) {
6830 var iteratee = last(arrays);
6831 if (isArrayLikeObject(iteratee)) {
6832 iteratee = undefined;
6834 return baseUniq(baseFlatten(arrays, 1, true), getIteratee(iteratee));
6838 * This method is like `_.union` except that it accepts `comparator` which
6839 * is invoked to compare elements of `arrays`. The comparator is invoked
6840 * with two arguments: (arrVal, othVal).
6845 * @param {...Array} [arrays] The arrays to inspect.
6846 * @param {Function} [comparator] The comparator invoked per element.
6847 * @returns {Array} Returns the new array of combined values.
6850 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6851 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6853 * _.unionWith(objects, others, _.isEqual);
6854 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
6856 var unionWith = rest(function(arrays) {
6857 var comparator = last(arrays);
6858 if (isArrayLikeObject(comparator)) {
6859 comparator = undefined;
6861 return baseUniq(baseFlatten(arrays, 1, true), undefined, comparator);
6865 * Creates a duplicate-free version of an array, using
6866 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6867 * for equality comparisons, in which only the first occurrence of each element
6873 * @param {Array} array The array to inspect.
6874 * @returns {Array} Returns the new duplicate free array.
6877 * _.uniq([2, 1, 2]);
6880 function uniq(array) {
6881 return (array && array.length)
6887 * This method is like `_.uniq` except that it accepts `iteratee` which is
6888 * invoked for each element in `array` to generate the criterion by which
6889 * uniqueness is computed. The iteratee is invoked with one argument: (value).
6894 * @param {Array} array The array to inspect.
6895 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6896 * @returns {Array} Returns the new duplicate free array.
6899 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
6902 * // The `_.property` iteratee shorthand.
6903 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
6904 * // => [{ 'x': 1 }, { 'x': 2 }]
6906 function uniqBy(array, iteratee) {
6907 return (array && array.length)
6908 ? baseUniq(array, getIteratee(iteratee))
6913 * This method is like `_.uniq` except that it accepts `comparator` which
6914 * is invoked to compare elements of `array`. The comparator is invoked with
6915 * two arguments: (arrVal, othVal).
6920 * @param {Array} array The array to inspect.
6921 * @param {Function} [comparator] The comparator invoked per element.
6922 * @returns {Array} Returns the new duplicate free array.
6925 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
6927 * _.uniqWith(objects, _.isEqual);
6928 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
6930 function uniqWith(array, comparator) {
6931 return (array && array.length)
6932 ? baseUniq(array, undefined, comparator)
6937 * This method is like `_.zip` except that it accepts an array of grouped
6938 * elements and creates an array regrouping the elements to their pre-zip
6944 * @param {Array} array The array of grouped elements to process.
6945 * @returns {Array} Returns the new array of regrouped elements.
6948 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
6949 * // => [['fred', 30, true], ['barney', 40, false]]
6952 * // => [['fred', 'barney'], [30, 40], [true, false]]
6954 function unzip(array) {
6955 if (!(array && array.length)) {
6959 array = arrayFilter(array, function(group) {
6960 if (isArrayLikeObject(group)) {
6961 length = nativeMax(group.length, length);
6965 return baseTimes(length, function(index) {
6966 return arrayMap(array, baseProperty(index));
6971 * This method is like `_.unzip` except that it accepts `iteratee` to specify
6972 * how regrouped values should be combined. The iteratee is invoked with the
6973 * elements of each group: (...group).
6978 * @param {Array} array The array of grouped elements to process.
6979 * @param {Function} [iteratee=_.identity] The function to combine regrouped values.
6980 * @returns {Array} Returns the new array of regrouped elements.
6983 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
6984 * // => [[1, 10, 100], [2, 20, 200]]
6986 * _.unzipWith(zipped, _.add);
6987 * // => [3, 30, 300]
6989 function unzipWith(array, iteratee) {
6990 if (!(array && array.length)) {
6993 var result = unzip(array);
6994 if (iteratee == null) {
6997 return arrayMap(result, function(group) {
6998 return apply(iteratee, undefined, group);
7003 * Creates an array excluding all given values using
7004 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7005 * for equality comparisons.
7010 * @param {Array} array The array to filter.
7011 * @param {...*} [values] The values to exclude.
7012 * @returns {Array} Returns the new array of filtered values.
7015 * _.without([1, 2, 1, 3], 1, 2);
7018 var without = rest(function(array, values) {
7019 return isArrayLikeObject(array)
7020 ? baseDifference(array, values)
7025 * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
7026 * of the given arrays.
7031 * @param {...Array} [arrays] The arrays to inspect.
7032 * @returns {Array} Returns the new array of values.
7035 * _.xor([2, 1], [4, 2]);
7038 var xor = rest(function(arrays) {
7039 return baseXor(arrayFilter(arrays, isArrayLikeObject));
7043 * This method is like `_.xor` except that it accepts `iteratee` which is
7044 * invoked for each element of each `arrays` to generate the criterion by which
7045 * uniqueness is computed. The iteratee is invoked with one argument: (value).
7050 * @param {...Array} [arrays] The arrays to inspect.
7051 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
7052 * @returns {Array} Returns the new array of values.
7055 * _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
7058 * // The `_.property` iteratee shorthand.
7059 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7060 * // => [{ 'x': 2 }]
7062 var xorBy = rest(function(arrays) {
7063 var iteratee = last(arrays);
7064 if (isArrayLikeObject(iteratee)) {
7065 iteratee = undefined;
7067 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee));
7071 * This method is like `_.xor` except that it accepts `comparator` which is
7072 * invoked to compare elements of `arrays`. The comparator is invoked with
7073 * two arguments: (arrVal, othVal).
7078 * @param {...Array} [arrays] The arrays to inspect.
7079 * @param {Function} [comparator] The comparator invoked per element.
7080 * @returns {Array} Returns the new array of values.
7083 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7084 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7086 * _.xorWith(objects, others, _.isEqual);
7087 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
7089 var xorWith = rest(function(arrays) {
7090 var comparator = last(arrays);
7091 if (isArrayLikeObject(comparator)) {
7092 comparator = undefined;
7094 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
7098 * Creates an array of grouped elements, the first of which contains the first
7099 * elements of the given arrays, the second of which contains the second elements
7100 * of the given arrays, and so on.
7105 * @param {...Array} [arrays] The arrays to process.
7106 * @returns {Array} Returns the new array of grouped elements.
7109 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
7110 * // => [['fred', 30, true], ['barney', 40, false]]
7112 var zip = rest(unzip);
7115 * This method is like `_.fromPairs` except that it accepts two arrays,
7116 * one of property names and one of corresponding values.
7121 * @param {Array} [props=[]] The property names.
7122 * @param {Array} [values=[]] The property values.
7123 * @returns {Object} Returns the new object.
7126 * _.zipObject(['a', 'b'], [1, 2]);
7127 * // => { 'a': 1, 'b': 2 }
7129 function zipObject(props, values) {
7130 return baseZipObject(props || [], values || [], assignValue);
7134 * This method is like `_.zipObject` except that it supports property paths.
7139 * @param {Array} [props=[]] The property names.
7140 * @param {Array} [values=[]] The property values.
7141 * @returns {Object} Returns the new object.
7144 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
7145 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
7147 function zipObjectDeep(props, values) {
7148 return baseZipObject(props || [], values || [], baseSet);
7152 * This method is like `_.zip` except that it accepts `iteratee` to specify
7153 * how grouped values should be combined. The iteratee is invoked with the
7154 * elements of each group: (...group).
7159 * @param {...Array} [arrays] The arrays to process.
7160 * @param {Function} [iteratee=_.identity] The function to combine grouped values.
7161 * @returns {Array} Returns the new array of grouped elements.
7164 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
7169 var zipWith = rest(function(arrays) {
7170 var length = arrays.length,
7171 iteratee = length > 1 ? arrays[length - 1] : undefined;
7173 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
7174 return unzipWith(arrays, iteratee);
7177 /*------------------------------------------------------------------------*/
7180 * Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
7181 * The result of such method chaining must be unwrapped with `_#value`.
7186 * @param {*} value The value to wrap.
7187 * @returns {Object} Returns the new `lodash` wrapper instance.
7191 * { 'user': 'barney', 'age': 36 },
7192 * { 'user': 'fred', 'age': 40 },
7193 * { 'user': 'pebbles', 'age': 1 }
7199 * .map(function(o) {
7200 * return o.user + ' is ' + o.age;
7204 * // => 'pebbles is 1'
7206 function chain(value) {
7207 var result = lodash(value);
7208 result.__chain__ = true;
7213 * This method invokes `interceptor` and returns `value`. The interceptor
7214 * is invoked with one argument; (value). The purpose of this method is to
7215 * "tap into" a method chain in order to modify intermediate results.
7220 * @param {*} value The value to provide to `interceptor`.
7221 * @param {Function} interceptor The function to invoke.
7222 * @returns {*} Returns `value`.
7226 * .tap(function(array) {
7227 * // Mutate input array.
7234 function tap(value, interceptor) {
7240 * This method is like `_.tap` except that it returns the result of `interceptor`.
7241 * The purpose of this method is to "pass thru" values replacing intermediate
7242 * results in a method chain.
7247 * @param {*} value The value to provide to `interceptor`.
7248 * @param {Function} interceptor The function to invoke.
7249 * @returns {*} Returns the result of `interceptor`.
7255 * .thru(function(value) {
7261 function thru(value, interceptor) {
7262 return interceptor(value);
7266 * This method is the wrapper version of `_.at`.
7271 * @param {...(string|string[])} [paths] The property paths of elements to pick,
7272 * specified individually or in arrays.
7273 * @returns {Object} Returns the new `lodash` wrapper instance.
7276 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
7278 * _(object).at(['a[0].b.c', 'a[1]']).value();
7281 * _(['a', 'b', 'c']).at(0, 2).value();
7284 var wrapperAt = rest(function(paths) {
7285 paths = baseFlatten(paths, 1);
7286 var length = paths.length,
7287 start = length ? paths[0] : 0,
7288 value = this.__wrapped__,
7289 interceptor = function(object) { return baseAt(object, paths); };
7291 if (length > 1 || this.__actions__.length ||
7292 !(value instanceof LazyWrapper) || !isIndex(start)) {
7293 return this.thru(interceptor);
7295 value = value.slice(start, +start + (length ? 1 : 0));
7296 value.__actions__.push({
7298 'args': [interceptor],
7299 'thisArg': undefined
7301 return new LodashWrapper(value, this.__chain__).thru(function(array) {
7302 if (length && !array.length) {
7303 array.push(undefined);
7310 * Enables explicit method chaining on the wrapper object.
7315 * @returns {Object} Returns the new `lodash` wrapper instance.
7319 * { 'user': 'barney', 'age': 36 },
7320 * { 'user': 'fred', 'age': 40 }
7323 * // A sequence without explicit chaining.
7325 * // => { 'user': 'barney', 'age': 36 }
7327 * // A sequence with explicit chaining.
7333 * // => { 'user': 'barney' }
7335 function wrapperChain() {
7340 * Executes the chained sequence and returns the wrapped result.
7345 * @returns {Object} Returns the new `lodash` wrapper instance.
7348 * var array = [1, 2];
7349 * var wrapped = _(array).push(3);
7351 * console.log(array);
7354 * wrapped = wrapped.commit();
7355 * console.log(array);
7361 * console.log(array);
7364 function wrapperCommit() {
7365 return new LodashWrapper(this.value(), this.__chain__);
7369 * This method is the wrapper version of `_.flatMap`.
7374 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
7375 * @returns {Object} Returns the new `lodash` wrapper instance.
7378 * function duplicate(n) {
7382 * _([1, 2]).flatMap(duplicate).value();
7383 * // => [1, 1, 2, 2]
7385 function wrapperFlatMap(iteratee) {
7386 return this.map(iteratee).flatten();
7390 * Gets the next value on a wrapped object following the
7391 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
7396 * @returns {Object} Returns the next iterator value.
7399 * var wrapped = _([1, 2]);
7402 * // => { 'done': false, 'value': 1 }
7405 * // => { 'done': false, 'value': 2 }
7408 * // => { 'done': true, 'value': undefined }
7410 function wrapperNext() {
7411 if (this.__values__ === undefined) {
7412 this.__values__ = toArray(this.value());
7414 var done = this.__index__ >= this.__values__.length,
7415 value = done ? undefined : this.__values__[this.__index__++];
7417 return { 'done': done, 'value': value };
7421 * Enables the wrapper to be iterable.
7423 * @name Symbol.iterator
7426 * @returns {Object} Returns the wrapper object.
7429 * var wrapped = _([1, 2]);
7431 * wrapped[Symbol.iterator]() === wrapped;
7434 * Array.from(wrapped);
7437 function wrapperToIterator() {
7442 * Creates a clone of the chained sequence planting `value` as the wrapped value.
7447 * @param {*} value The value to plant.
7448 * @returns {Object} Returns the new `lodash` wrapper instance.
7451 * function square(n) {
7455 * var wrapped = _([1, 2]).map(square);
7456 * var other = wrapped.plant([3, 4]);
7464 function wrapperPlant(value) {
7468 while (parent instanceof baseLodash) {
7469 var clone = wrapperClone(parent);
7470 clone.__index__ = 0;
7471 clone.__values__ = undefined;
7473 previous.__wrapped__ = clone;
7477 var previous = clone;
7478 parent = parent.__wrapped__;
7480 previous.__wrapped__ = value;
7485 * This method is the wrapper version of `_.reverse`.
7487 * **Note:** This method mutates the wrapped array.
7492 * @returns {Object} Returns the new `lodash` wrapper instance.
7495 * var array = [1, 2, 3];
7497 * _(array).reverse().value()
7500 * console.log(array);
7503 function wrapperReverse() {
7504 var value = this.__wrapped__;
7505 if (value instanceof LazyWrapper) {
7506 var wrapped = value;
7507 if (this.__actions__.length) {
7508 wrapped = new LazyWrapper(this);
7510 wrapped = wrapped.reverse();
7511 wrapped.__actions__.push({
7514 'thisArg': undefined
7516 return new LodashWrapper(wrapped, this.__chain__);
7518 return this.thru(reverse);
7522 * Executes the chained sequence to extract the unwrapped value.
7526 * @alias toJSON, valueOf
7528 * @returns {*} Returns the resolved unwrapped value.
7531 * _([1, 2, 3]).value();
7534 function wrapperValue() {
7535 return baseWrapperValue(this.__wrapped__, this.__actions__);
7538 /*------------------------------------------------------------------------*/
7541 * Creates an object composed of keys generated from the results of running
7542 * each element of `collection` through `iteratee`. The corresponding value
7543 * of each key is the number of times the key was returned by `iteratee`.
7544 * The iteratee is invoked with one argument: (value).
7548 * @category Collection
7549 * @param {Array|Object} collection The collection to iterate over.
7550 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7551 * @returns {Object} Returns the composed aggregate object.
7554 * _.countBy([6.1, 4.2, 6.3], Math.floor);
7555 * // => { '4': 1, '6': 2 }
7557 * _.countBy(['one', 'two', 'three'], 'length');
7558 * // => { '3': 2, '5': 1 }
7560 var countBy = createAggregator(function(result, value, key) {
7561 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
7565 * Checks if `predicate` returns truthy for **all** elements of `collection`.
7566 * Iteration is stopped once `predicate` returns falsey. The predicate is
7567 * invoked with three arguments: (value, index|key, collection).
7571 * @category Collection
7572 * @param {Array|Object} collection The collection to iterate over.
7573 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7574 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
7575 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
7578 * _.every([true, 1, null, 'yes'], Boolean);
7582 * { 'user': 'barney', 'active': false },
7583 * { 'user': 'fred', 'active': false }
7586 * // The `_.matches` iteratee shorthand.
7587 * _.every(users, { 'user': 'barney', 'active': false });
7590 * // The `_.matchesProperty` iteratee shorthand.
7591 * _.every(users, ['active', false]);
7594 * // The `_.property` iteratee shorthand.
7595 * _.every(users, 'active');
7598 function every(collection, predicate, guard) {
7599 var func = isArray(collection) ? arrayEvery : baseEvery;
7600 if (guard && isIterateeCall(collection, predicate, guard)) {
7601 predicate = undefined;
7603 return func(collection, getIteratee(predicate, 3));
7607 * Iterates over elements of `collection`, returning an array of all elements
7608 * `predicate` returns truthy for. The predicate is invoked with three arguments:
7609 * (value, index|key, collection).
7613 * @category Collection
7614 * @param {Array|Object} collection The collection to iterate over.
7615 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7616 * @returns {Array} Returns the new filtered array.
7620 * { 'user': 'barney', 'age': 36, 'active': true },
7621 * { 'user': 'fred', 'age': 40, 'active': false }
7624 * _.filter(users, function(o) { return !o.active; });
7625 * // => objects for ['fred']
7627 * // The `_.matches` iteratee shorthand.
7628 * _.filter(users, { 'age': 36, 'active': true });
7629 * // => objects for ['barney']
7631 * // The `_.matchesProperty` iteratee shorthand.
7632 * _.filter(users, ['active', false]);
7633 * // => objects for ['fred']
7635 * // The `_.property` iteratee shorthand.
7636 * _.filter(users, 'active');
7637 * // => objects for ['barney']
7639 function filter(collection, predicate) {
7640 var func = isArray(collection) ? arrayFilter : baseFilter;
7641 return func(collection, getIteratee(predicate, 3));
7645 * Iterates over elements of `collection`, returning the first element
7646 * `predicate` returns truthy for. The predicate is invoked with three arguments:
7647 * (value, index|key, collection).
7651 * @category Collection
7652 * @param {Array|Object} collection The collection to search.
7653 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7654 * @returns {*} Returns the matched element, else `undefined`.
7658 * { 'user': 'barney', 'age': 36, 'active': true },
7659 * { 'user': 'fred', 'age': 40, 'active': false },
7660 * { 'user': 'pebbles', 'age': 1, 'active': true }
7663 * _.find(users, function(o) { return o.age < 40; });
7664 * // => object for 'barney'
7666 * // The `_.matches` iteratee shorthand.
7667 * _.find(users, { 'age': 1, 'active': true });
7668 * // => object for 'pebbles'
7670 * // The `_.matchesProperty` iteratee shorthand.
7671 * _.find(users, ['active', false]);
7672 * // => object for 'fred'
7674 * // The `_.property` iteratee shorthand.
7675 * _.find(users, 'active');
7676 * // => object for 'barney'
7678 function find(collection, predicate) {
7679 predicate = getIteratee(predicate, 3);
7680 if (isArray(collection)) {
7681 var index = baseFindIndex(collection, predicate);
7682 return index > -1 ? collection[index] : undefined;
7684 return baseFind(collection, predicate, baseEach);
7688 * This method is like `_.find` except that it iterates over elements of
7689 * `collection` from right to left.
7693 * @category Collection
7694 * @param {Array|Object} collection The collection to search.
7695 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7696 * @returns {*} Returns the matched element, else `undefined`.
7699 * _.findLast([1, 2, 3, 4], function(n) {
7700 * return n % 2 == 1;
7704 function findLast(collection, predicate) {
7705 predicate = getIteratee(predicate, 3);
7706 if (isArray(collection)) {
7707 var index = baseFindIndex(collection, predicate, true);
7708 return index > -1 ? collection[index] : undefined;
7710 return baseFind(collection, predicate, baseEachRight);
7714 * Creates an array of flattened values by running each element in `collection`
7715 * through `iteratee` and concating its result to the other mapped values.
7716 * The iteratee is invoked with three arguments: (value, index|key, collection).
7720 * @category Collection
7721 * @param {Array|Object} collection The collection to iterate over.
7722 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
7723 * @returns {Array} Returns the new flattened array.
7726 * function duplicate(n) {
7730 * _.flatMap([1, 2], duplicate);
7731 * // => [1, 1, 2, 2]
7733 function flatMap(collection, iteratee) {
7734 return baseFlatten(map(collection, iteratee), 1);
7738 * Iterates over elements of `collection` invoking `iteratee` for each element.
7739 * The iteratee is invoked with three arguments: (value, index|key, collection).
7740 * Iteratee functions may exit iteration early by explicitly returning `false`.
7742 * **Note:** As with other "Collections" methods, objects with a "length" property
7743 * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
7744 * for object iteration.
7749 * @category Collection
7750 * @param {Array|Object} collection The collection to iterate over.
7751 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7752 * @returns {Array|Object} Returns `collection`.
7755 * _([1, 2]).forEach(function(value) {
7756 * console.log(value);
7758 * // => logs `1` then `2`
7760 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
7763 * // => logs 'a' then 'b' (iteration order is not guaranteed)
7765 function forEach(collection, iteratee) {
7766 return (typeof iteratee == 'function' && isArray(collection))
7767 ? arrayEach(collection, iteratee)
7768 : baseEach(collection, baseCastFunction(iteratee));
7772 * This method is like `_.forEach` except that it iterates over elements of
7773 * `collection` from right to left.
7778 * @category Collection
7779 * @param {Array|Object} collection The collection to iterate over.
7780 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7781 * @returns {Array|Object} Returns `collection`.
7784 * _.forEachRight([1, 2], function(value) {
7785 * console.log(value);
7787 * // => logs `2` then `1`
7789 function forEachRight(collection, iteratee) {
7790 return (typeof iteratee == 'function' && isArray(collection))
7791 ? arrayEachRight(collection, iteratee)
7792 : baseEachRight(collection, baseCastFunction(iteratee));
7796 * Creates an object composed of keys generated from the results of running
7797 * each element of `collection` through `iteratee`. The corresponding value
7798 * of each key is an array of elements responsible for generating the key.
7799 * The iteratee is invoked with one argument: (value).
7803 * @category Collection
7804 * @param {Array|Object} collection The collection to iterate over.
7805 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7806 * @returns {Object} Returns the composed aggregate object.
7809 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
7810 * // => { '4': [4.2], '6': [6.1, 6.3] }
7812 * // The `_.property` iteratee shorthand.
7813 * _.groupBy(['one', 'two', 'three'], 'length');
7814 * // => { '3': ['one', 'two'], '5': ['three'] }
7816 var groupBy = createAggregator(function(result, value, key) {
7817 if (hasOwnProperty.call(result, key)) {
7818 result[key].push(value);
7820 result[key] = [value];
7825 * Checks if `value` is in `collection`. If `collection` is a string it's checked
7826 * for a substring of `value`, otherwise [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7827 * is used for equality comparisons. If `fromIndex` is negative, it's used as
7828 * the offset from the end of `collection`.
7832 * @category Collection
7833 * @param {Array|Object|string} collection The collection to search.
7834 * @param {*} value The value to search for.
7835 * @param {number} [fromIndex=0] The index to search from.
7836 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`.
7837 * @returns {boolean} Returns `true` if `value` is found, else `false`.
7840 * _.includes([1, 2, 3], 1);
7843 * _.includes([1, 2, 3], 1, 2);
7846 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
7849 * _.includes('pebbles', 'eb');
7852 function includes(collection, value, fromIndex, guard) {
7853 collection = isArrayLike(collection) ? collection : values(collection);
7854 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
7856 var length = collection.length;
7857 if (fromIndex < 0) {
7858 fromIndex = nativeMax(length + fromIndex, 0);
7860 return isString(collection)
7861 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
7862 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
7866 * Invokes the method at `path` of each element in `collection`, returning
7867 * an array of the results of each invoked method. Any additional arguments
7868 * are provided to each invoked method. If `methodName` is a function it's
7869 * invoked for, and `this` bound to, each element in `collection`.
7873 * @category Collection
7874 * @param {Array|Object} collection The collection to iterate over.
7875 * @param {Array|Function|string} path The path of the method to invoke or
7876 * the function invoked per iteration.
7877 * @param {...*} [args] The arguments to invoke each method with.
7878 * @returns {Array} Returns the array of results.
7881 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
7882 * // => [[1, 5, 7], [1, 2, 3]]
7884 * _.invokeMap([123, 456], String.prototype.split, '');
7885 * // => [['1', '2', '3'], ['4', '5', '6']]
7887 var invokeMap = rest(function(collection, path, args) {
7889 isFunc = typeof path == 'function',
7890 isProp = isKey(path),
7891 result = isArrayLike(collection) ? Array(collection.length) : [];
7893 baseEach(collection, function(value) {
7894 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
7895 result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
7901 * Creates an object composed of keys generated from the results of running
7902 * each element of `collection` through `iteratee`. The corresponding value
7903 * of each key is the last element responsible for generating the key. The
7904 * iteratee is invoked with one argument: (value).
7908 * @category Collection
7909 * @param {Array|Object} collection The collection to iterate over.
7910 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7911 * @returns {Object} Returns the composed aggregate object.
7915 * { 'dir': 'left', 'code': 97 },
7916 * { 'dir': 'right', 'code': 100 }
7919 * _.keyBy(array, function(o) {
7920 * return String.fromCharCode(o.code);
7922 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
7924 * _.keyBy(array, 'dir');
7925 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
7927 var keyBy = createAggregator(function(result, value, key) {
7928 result[key] = value;
7932 * Creates an array of values by running each element in `collection` through
7933 * `iteratee`. The iteratee is invoked with three arguments:
7934 * (value, index|key, collection).
7936 * Many lodash methods are guarded to work as iteratees for methods like
7937 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
7939 * The guarded methods are:
7940 * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
7941 * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
7942 * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
7947 * @category Collection
7948 * @param {Array|Object} collection The collection to iterate over.
7949 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
7950 * @returns {Array} Returns the new mapped array.
7953 * function square(n) {
7957 * _.map([4, 8], square);
7960 * _.map({ 'a': 4, 'b': 8 }, square);
7961 * // => [16, 64] (iteration order is not guaranteed)
7964 * { 'user': 'barney' },
7965 * { 'user': 'fred' }
7968 * // The `_.property` iteratee shorthand.
7969 * _.map(users, 'user');
7970 * // => ['barney', 'fred']
7972 function map(collection, iteratee) {
7973 var func = isArray(collection) ? arrayMap : baseMap;
7974 return func(collection, getIteratee(iteratee, 3));
7978 * This method is like `_.sortBy` except that it allows specifying the sort
7979 * orders of the iteratees to sort by. If `orders` is unspecified, all values
7980 * are sorted in ascending order. Otherwise, specify an order of "desc" for
7981 * descending or "asc" for ascending sort order of corresponding values.
7985 * @category Collection
7986 * @param {Array|Object} collection The collection to iterate over.
7987 * @param {Function[]|Object[]|string[]} [iteratees=[_.identity]] The iteratees to sort by.
7988 * @param {string[]} [orders] The sort orders of `iteratees`.
7989 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`.
7990 * @returns {Array} Returns the new sorted array.
7994 * { 'user': 'fred', 'age': 48 },
7995 * { 'user': 'barney', 'age': 34 },
7996 * { 'user': 'fred', 'age': 42 },
7997 * { 'user': 'barney', 'age': 36 }
8000 * // Sort by `user` in ascending order and by `age` in descending order.
8001 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
8002 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
8004 function orderBy(collection, iteratees, orders, guard) {
8005 if (collection == null) {
8008 if (!isArray(iteratees)) {
8009 iteratees = iteratees == null ? [] : [iteratees];
8011 orders = guard ? undefined : orders;
8012 if (!isArray(orders)) {
8013 orders = orders == null ? [] : [orders];
8015 return baseOrderBy(collection, iteratees, orders);
8019 * Creates an array of elements split into two groups, the first of which
8020 * contains elements `predicate` returns truthy for, the second of which
8021 * contains elements `predicate` returns falsey for. The predicate is
8022 * invoked with one argument: (value).
8026 * @category Collection
8027 * @param {Array|Object} collection The collection to iterate over.
8028 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
8029 * @returns {Array} Returns the array of grouped elements.
8033 * { 'user': 'barney', 'age': 36, 'active': false },
8034 * { 'user': 'fred', 'age': 40, 'active': true },
8035 * { 'user': 'pebbles', 'age': 1, 'active': false }
8038 * _.partition(users, function(o) { return o.active; });
8039 * // => objects for [['fred'], ['barney', 'pebbles']]
8041 * // The `_.matches` iteratee shorthand.
8042 * _.partition(users, { 'age': 1, 'active': false });
8043 * // => objects for [['pebbles'], ['barney', 'fred']]
8045 * // The `_.matchesProperty` iteratee shorthand.
8046 * _.partition(users, ['active', false]);
8047 * // => objects for [['barney', 'pebbles'], ['fred']]
8049 * // The `_.property` iteratee shorthand.
8050 * _.partition(users, 'active');
8051 * // => objects for [['fred'], ['barney', 'pebbles']]
8053 var partition = createAggregator(function(result, value, key) {
8054 result[key ? 0 : 1].push(value);
8055 }, function() { return [[], []]; });
8058 * Reduces `collection` to a value which is the accumulated result of running
8059 * each element in `collection` through `iteratee`, where each successive
8060 * invocation is supplied the return value of the previous. If `accumulator`
8061 * is not given the first element of `collection` is used as the initial
8062 * value. The iteratee is invoked with four arguments:
8063 * (accumulator, value, index|key, collection).
8065 * Many lodash methods are guarded to work as iteratees for methods like
8066 * `_.reduce`, `_.reduceRight`, and `_.transform`.
8068 * The guarded methods are:
8069 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
8074 * @category Collection
8075 * @param {Array|Object} collection The collection to iterate over.
8076 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8077 * @param {*} [accumulator] The initial value.
8078 * @returns {*} Returns the accumulated value.
8081 * _.reduce([1, 2], function(sum, n) {
8086 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
8087 * (result[value] || (result[value] = [])).push(key);
8090 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
8092 function reduce(collection, iteratee, accumulator) {
8093 var func = isArray(collection) ? arrayReduce : baseReduce,
8094 initAccum = arguments.length < 3;
8096 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
8100 * This method is like `_.reduce` except that it iterates over elements of
8101 * `collection` from right to left.
8105 * @category Collection
8106 * @param {Array|Object} collection The collection to iterate over.
8107 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8108 * @param {*} [accumulator] The initial value.
8109 * @returns {*} Returns the accumulated value.
8112 * var array = [[0, 1], [2, 3], [4, 5]];
8114 * _.reduceRight(array, function(flattened, other) {
8115 * return flattened.concat(other);
8117 * // => [4, 5, 2, 3, 0, 1]
8119 function reduceRight(collection, iteratee, accumulator) {
8120 var func = isArray(collection) ? arrayReduceRight : baseReduce,
8121 initAccum = arguments.length < 3;
8123 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
8127 * The opposite of `_.filter`; this method returns the elements of `collection`
8128 * that `predicate` does **not** return truthy for.
8132 * @category Collection
8133 * @param {Array|Object} collection The collection to iterate over.
8134 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
8135 * @returns {Array} Returns the new filtered array.
8139 * { 'user': 'barney', 'age': 36, 'active': false },
8140 * { 'user': 'fred', 'age': 40, 'active': true }
8143 * _.reject(users, function(o) { return !o.active; });
8144 * // => objects for ['fred']
8146 * // The `_.matches` iteratee shorthand.
8147 * _.reject(users, { 'age': 40, 'active': true });
8148 * // => objects for ['barney']
8150 * // The `_.matchesProperty` iteratee shorthand.
8151 * _.reject(users, ['active', false]);
8152 * // => objects for ['fred']
8154 * // The `_.property` iteratee shorthand.
8155 * _.reject(users, 'active');
8156 * // => objects for ['barney']
8158 function reject(collection, predicate) {
8159 var func = isArray(collection) ? arrayFilter : baseFilter;
8160 predicate = getIteratee(predicate, 3);
8161 return func(collection, function(value, index, collection) {
8162 return !predicate(value, index, collection);
8167 * Gets a random element from `collection`.
8171 * @category Collection
8172 * @param {Array|Object} collection The collection to sample.
8173 * @returns {*} Returns the random element.
8176 * _.sample([1, 2, 3, 4]);
8179 function sample(collection) {
8180 var array = isArrayLike(collection) ? collection : values(collection),
8181 length = array.length;
8183 return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
8187 * Gets `n` random elements at unique keys from `collection` up to the
8188 * size of `collection`.
8192 * @category Collection
8193 * @param {Array|Object} collection The collection to sample.
8194 * @param {number} [n=0] The number of elements to sample.
8195 * @returns {Array} Returns the random elements.
8198 * _.sampleSize([1, 2, 3], 2);
8201 * _.sampleSize([1, 2, 3], 4);
8204 function sampleSize(collection, n) {
8206 result = toArray(collection),
8207 length = result.length,
8208 lastIndex = length - 1;
8210 n = baseClamp(toInteger(n), 0, length);
8211 while (++index < n) {
8212 var rand = baseRandom(index, lastIndex),
8213 value = result[rand];
8215 result[rand] = result[index];
8216 result[index] = value;
8223 * Creates an array of shuffled values, using a version of the
8224 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
8228 * @category Collection
8229 * @param {Array|Object} collection The collection to shuffle.
8230 * @returns {Array} Returns the new shuffled array.
8233 * _.shuffle([1, 2, 3, 4]);
8234 * // => [4, 1, 3, 2]
8236 function shuffle(collection) {
8237 return sampleSize(collection, MAX_ARRAY_LENGTH);
8241 * Gets the size of `collection` by returning its length for array-like
8242 * values or the number of own enumerable properties for objects.
8246 * @category Collection
8247 * @param {Array|Object} collection The collection to inspect.
8248 * @returns {number} Returns the collection size.
8251 * _.size([1, 2, 3]);
8254 * _.size({ 'a': 1, 'b': 2 });
8257 * _.size('pebbles');
8260 function size(collection) {
8261 if (collection == null) {
8264 if (isArrayLike(collection)) {
8265 var result = collection.length;
8266 return (result && isString(collection)) ? stringSize(collection) : result;
8268 return keys(collection).length;
8272 * Checks if `predicate` returns truthy for **any** element of `collection`.
8273 * Iteration is stopped once `predicate` returns truthy. The predicate is
8274 * invoked with three arguments: (value, index|key, collection).
8278 * @category Collection
8279 * @param {Array|Object} collection The collection to iterate over.
8280 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
8281 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8282 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
8285 * _.some([null, 0, 'yes', false], Boolean);
8289 * { 'user': 'barney', 'active': true },
8290 * { 'user': 'fred', 'active': false }
8293 * // The `_.matches` iteratee shorthand.
8294 * _.some(users, { 'user': 'barney', 'active': false });
8297 * // The `_.matchesProperty` iteratee shorthand.
8298 * _.some(users, ['active', false]);
8301 * // The `_.property` iteratee shorthand.
8302 * _.some(users, 'active');
8305 function some(collection, predicate, guard) {
8306 var func = isArray(collection) ? arraySome : baseSome;
8307 if (guard && isIterateeCall(collection, predicate, guard)) {
8308 predicate = undefined;
8310 return func(collection, getIteratee(predicate, 3));
8314 * Creates an array of elements, sorted in ascending order by the results of
8315 * running each element in a collection through each iteratee. This method
8316 * performs a stable sort, that is, it preserves the original sort order of
8317 * equal elements. The iteratees are invoked with one argument: (value).
8321 * @category Collection
8322 * @param {Array|Object} collection The collection to iterate over.
8323 * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
8324 * The iteratees to sort by, specified individually or in arrays.
8325 * @returns {Array} Returns the new sorted array.
8329 * { 'user': 'fred', 'age': 48 },
8330 * { 'user': 'barney', 'age': 36 },
8331 * { 'user': 'fred', 'age': 42 },
8332 * { 'user': 'barney', 'age': 34 }
8335 * _.sortBy(users, function(o) { return o.user; });
8336 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
8338 * _.sortBy(users, ['user', 'age']);
8339 * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
8341 * _.sortBy(users, 'user', function(o) {
8342 * return Math.floor(o.age / 10);
8344 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
8346 var sortBy = rest(function(collection, iteratees) {
8347 if (collection == null) {
8350 var length = iteratees.length;
8351 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
8353 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
8354 iteratees.length = 1;
8356 return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
8359 /*------------------------------------------------------------------------*/
8362 * Gets the timestamp of the number of milliseconds that have elapsed since
8363 * the Unix epoch (1 January 1970 00:00:00 UTC).
8369 * @returns {number} Returns the timestamp.
8372 * _.defer(function(stamp) {
8373 * console.log(_.now() - stamp);
8375 * // => logs the number of milliseconds it took for the deferred function to be invoked
8379 /*------------------------------------------------------------------------*/
8382 * The opposite of `_.before`; this method creates a function that invokes
8383 * `func` once it's called `n` or more times.
8387 * @category Function
8388 * @param {number} n The number of calls before `func` is invoked.
8389 * @param {Function} func The function to restrict.
8390 * @returns {Function} Returns the new restricted function.
8393 * var saves = ['profile', 'settings'];
8395 * var done = _.after(saves.length, function() {
8396 * console.log('done saving!');
8399 * _.forEach(saves, function(type) {
8400 * asyncSave({ 'type': type, 'complete': done });
8402 * // => logs 'done saving!' after the two async saves have completed
8404 function after(n, func) {
8405 if (typeof func != 'function') {
8406 throw new TypeError(FUNC_ERROR_TEXT);
8411 return func.apply(this, arguments);
8417 * Creates a function that accepts up to `n` arguments, ignoring any
8418 * additional arguments.
8422 * @category Function
8423 * @param {Function} func The function to cap arguments for.
8424 * @param {number} [n=func.length] The arity cap.
8425 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8426 * @returns {Function} Returns the new function.
8429 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
8432 function ary(func, n, guard) {
8433 n = guard ? undefined : n;
8434 n = (func && n == null) ? func.length : n;
8435 return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
8439 * Creates a function that invokes `func`, with the `this` binding and arguments
8440 * of the created function, while it's called less than `n` times. Subsequent
8441 * calls to the created function return the result of the last `func` invocation.
8445 * @category Function
8446 * @param {number} n The number of calls at which `func` is no longer invoked.
8447 * @param {Function} func The function to restrict.
8448 * @returns {Function} Returns the new restricted function.
8451 * jQuery(element).on('click', _.before(5, addContactToList));
8452 * // => allows adding up to 4 contacts to the list
8454 function before(n, func) {
8456 if (typeof func != 'function') {
8457 throw new TypeError(FUNC_ERROR_TEXT);
8462 result = func.apply(this, arguments);
8472 * Creates a function that invokes `func` with the `this` binding of `thisArg`
8473 * and prepends any additional `_.bind` arguments to those provided to the
8476 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
8477 * may be used as a placeholder for partially applied arguments.
8479 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
8480 * property of bound functions.
8484 * @category Function
8485 * @param {Function} func The function to bind.
8486 * @param {*} thisArg The `this` binding of `func`.
8487 * @param {...*} [partials] The arguments to be partially applied.
8488 * @returns {Function} Returns the new bound function.
8491 * var greet = function(greeting, punctuation) {
8492 * return greeting + ' ' + this.user + punctuation;
8495 * var object = { 'user': 'fred' };
8497 * var bound = _.bind(greet, object, 'hi');
8501 * // Bound with placeholders.
8502 * var bound = _.bind(greet, object, _, '!');
8506 var bind = rest(function(func, thisArg, partials) {
8507 var bitmask = BIND_FLAG;
8508 if (partials.length) {
8509 var holders = replaceHolders(partials, getPlaceholder(bind));
8510 bitmask |= PARTIAL_FLAG;
8512 return createWrapper(func, bitmask, thisArg, partials, holders);
8516 * Creates a function that invokes the method at `object[key]` and prepends
8517 * any additional `_.bindKey` arguments to those provided to the bound function.
8519 * This method differs from `_.bind` by allowing bound functions to reference
8520 * methods that may be redefined or don't yet exist.
8521 * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
8524 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
8525 * builds, may be used as a placeholder for partially applied arguments.
8529 * @category Function
8530 * @param {Object} object The object to invoke the method on.
8531 * @param {string} key The key of the method.
8532 * @param {...*} [partials] The arguments to be partially applied.
8533 * @returns {Function} Returns the new bound function.
8538 * 'greet': function(greeting, punctuation) {
8539 * return greeting + ' ' + this.user + punctuation;
8543 * var bound = _.bindKey(object, 'greet', 'hi');
8547 * object.greet = function(greeting, punctuation) {
8548 * return greeting + 'ya ' + this.user + punctuation;
8552 * // => 'hiya fred!'
8554 * // Bound with placeholders.
8555 * var bound = _.bindKey(object, 'greet', _, '!');
8557 * // => 'hiya fred!'
8559 var bindKey = rest(function(object, key, partials) {
8560 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
8561 if (partials.length) {
8562 var holders = replaceHolders(partials, getPlaceholder(bindKey));
8563 bitmask |= PARTIAL_FLAG;
8565 return createWrapper(key, bitmask, object, partials, holders);
8569 * Creates a function that accepts arguments of `func` and either invokes
8570 * `func` returning its result, if at least `arity` number of arguments have
8571 * been provided, or returns a function that accepts the remaining `func`
8572 * arguments, and so on. The arity of `func` may be specified if `func.length`
8573 * is not sufficient.
8575 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
8576 * may be used as a placeholder for provided arguments.
8578 * **Note:** This method doesn't set the "length" property of curried functions.
8582 * @category Function
8583 * @param {Function} func The function to curry.
8584 * @param {number} [arity=func.length] The arity of `func`.
8585 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8586 * @returns {Function} Returns the new curried function.
8589 * var abc = function(a, b, c) {
8593 * var curried = _.curry(abc);
8604 * // Curried with placeholders.
8605 * curried(1)(_, 3)(2);
8608 function curry(func, arity, guard) {
8609 arity = guard ? undefined : arity;
8610 var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
8611 result.placeholder = curry.placeholder;
8616 * This method is like `_.curry` except that arguments are applied to `func`
8617 * in the manner of `_.partialRight` instead of `_.partial`.
8619 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
8620 * builds, may be used as a placeholder for provided arguments.
8622 * **Note:** This method doesn't set the "length" property of curried functions.
8626 * @category Function
8627 * @param {Function} func The function to curry.
8628 * @param {number} [arity=func.length] The arity of `func`.
8629 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8630 * @returns {Function} Returns the new curried function.
8633 * var abc = function(a, b, c) {
8637 * var curried = _.curryRight(abc);
8648 * // Curried with placeholders.
8649 * curried(3)(1, _)(2);
8652 function curryRight(func, arity, guard) {
8653 arity = guard ? undefined : arity;
8654 var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
8655 result.placeholder = curryRight.placeholder;
8660 * Creates a debounced function that delays invoking `func` until after `wait`
8661 * milliseconds have elapsed since the last time the debounced function was
8662 * invoked. The debounced function comes with a `cancel` method to cancel
8663 * delayed `func` invocations and a `flush` method to immediately invoke them.
8664 * Provide an options object to indicate whether `func` should be invoked on
8665 * the leading and/or trailing edge of the `wait` timeout. The `func` is invoked
8666 * with the last arguments provided to the debounced function. Subsequent calls
8667 * to the debounced function return the result of the last `func` invocation.
8669 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
8670 * on the trailing edge of the timeout only if the debounced function is
8671 * invoked more than once during the `wait` timeout.
8673 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
8674 * for details over the differences between `_.debounce` and `_.throttle`.
8678 * @category Function
8679 * @param {Function} func The function to debounce.
8680 * @param {number} [wait=0] The number of milliseconds to delay.
8681 * @param {Object} [options] The options object.
8682 * @param {boolean} [options.leading=false] Specify invoking on the leading
8683 * edge of the timeout.
8684 * @param {number} [options.maxWait] The maximum time `func` is allowed to be
8685 * delayed before it's invoked.
8686 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
8687 * edge of the timeout.
8688 * @returns {Function} Returns the new debounced function.
8691 * // Avoid costly calculations while the window size is in flux.
8692 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
8694 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
8695 * jQuery(element).on('click', _.debounce(sendMail, 300, {
8700 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
8701 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
8702 * var source = new EventSource('/stream');
8703 * jQuery(source).on('message', debounced);
8705 * // Cancel the trailing debounced invocation.
8706 * jQuery(window).on('popstate', debounced.cancel);
8708 function debounce(func, wait, options) {
8721 if (typeof func != 'function') {
8722 throw new TypeError(FUNC_ERROR_TEXT);
8724 wait = toNumber(wait) || 0;
8725 if (isObject(options)) {
8726 leading = !!options.leading;
8727 maxWait = 'maxWait' in options && nativeMax(toNumber(options.maxWait) || 0, wait);
8728 trailing = 'trailing' in options ? !!options.trailing : trailing;
8733 clearTimeout(timeoutId);
8736 clearTimeout(maxTimeoutId);
8739 args = maxTimeoutId = thisArg = timeoutId = trailingCall = undefined;
8742 function complete(isCalled, id) {
8746 maxTimeoutId = timeoutId = trailingCall = undefined;
8749 result = func.apply(thisArg, args);
8750 if (!timeoutId && !maxTimeoutId) {
8751 args = thisArg = undefined;
8756 function delayed() {
8757 var remaining = wait - (now() - stamp);
8758 if (remaining <= 0 || remaining > wait) {
8759 complete(trailingCall, maxTimeoutId);
8761 timeoutId = setTimeout(delayed, remaining);
8766 if ((timeoutId && trailingCall) || (maxTimeoutId && trailing)) {
8767 result = func.apply(thisArg, args);
8773 function maxDelayed() {
8774 complete(trailing, timeoutId);
8777 function debounced() {
8781 trailingCall = trailing && (timeoutId || !leading);
8783 if (maxWait === false) {
8784 var leadingCall = leading && !timeoutId;
8786 if (!lastCalled && !maxTimeoutId && !leading) {
8789 var remaining = maxWait - (stamp - lastCalled);
8791 var isCalled = (remaining <= 0 || remaining > maxWait) &&
8792 (leading || maxTimeoutId);
8796 maxTimeoutId = clearTimeout(maxTimeoutId);
8799 result = func.apply(thisArg, args);
8801 else if (!maxTimeoutId) {
8802 maxTimeoutId = setTimeout(maxDelayed, remaining);
8805 if (isCalled && timeoutId) {
8806 timeoutId = clearTimeout(timeoutId);
8808 else if (!timeoutId && wait !== maxWait) {
8809 timeoutId = setTimeout(delayed, wait);
8813 result = func.apply(thisArg, args);
8815 if (isCalled && !timeoutId && !maxTimeoutId) {
8816 args = thisArg = undefined;
8820 debounced.cancel = cancel;
8821 debounced.flush = flush;
8826 * Defers invoking the `func` until the current call stack has cleared. Any
8827 * additional arguments are provided to `func` when it's invoked.
8831 * @category Function
8832 * @param {Function} func The function to defer.
8833 * @param {...*} [args] The arguments to invoke `func` with.
8834 * @returns {number} Returns the timer id.
8837 * _.defer(function(text) {
8838 * console.log(text);
8840 * // => logs 'deferred' after one or more milliseconds
8842 var defer = rest(function(func, args) {
8843 return baseDelay(func, 1, args);
8847 * Invokes `func` after `wait` milliseconds. Any additional arguments are
8848 * provided to `func` when it's invoked.
8852 * @category Function
8853 * @param {Function} func The function to delay.
8854 * @param {number} wait The number of milliseconds to delay invocation.
8855 * @param {...*} [args] The arguments to invoke `func` with.
8856 * @returns {number} Returns the timer id.
8859 * _.delay(function(text) {
8860 * console.log(text);
8861 * }, 1000, 'later');
8862 * // => logs 'later' after one second
8864 var delay = rest(function(func, wait, args) {
8865 return baseDelay(func, toNumber(wait) || 0, args);
8869 * Creates a function that invokes `func` with arguments reversed.
8873 * @category Function
8874 * @param {Function} func The function to flip arguments for.
8875 * @returns {Function} Returns the new function.
8878 * var flipped = _.flip(function() {
8879 * return _.toArray(arguments);
8882 * flipped('a', 'b', 'c', 'd');
8883 * // => ['d', 'c', 'b', 'a']
8885 function flip(func) {
8886 return createWrapper(func, FLIP_FLAG);
8890 * Creates a function that memoizes the result of `func`. If `resolver` is
8891 * provided it determines the cache key for storing the result based on the
8892 * arguments provided to the memoized function. By default, the first argument
8893 * provided to the memoized function is used as the map cache key. The `func`
8894 * is invoked with the `this` binding of the memoized function.
8896 * **Note:** The cache is exposed as the `cache` property on the memoized
8897 * function. Its creation may be customized by replacing the `_.memoize.Cache`
8898 * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
8899 * method interface of `delete`, `get`, `has`, and `set`.
8903 * @category Function
8904 * @param {Function} func The function to have its output memoized.
8905 * @param {Function} [resolver] The function to resolve the cache key.
8906 * @returns {Function} Returns the new memoizing function.
8909 * var object = { 'a': 1, 'b': 2 };
8910 * var other = { 'c': 3, 'd': 4 };
8912 * var values = _.memoize(_.values);
8923 * // Modify the result cache.
8924 * values.cache.set(object, ['a', 'b']);
8928 * // Replace `_.memoize.Cache`.
8929 * _.memoize.Cache = WeakMap;
8931 function memoize(func, resolver) {
8932 if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
8933 throw new TypeError(FUNC_ERROR_TEXT);
8935 var memoized = function() {
8936 var args = arguments,
8937 key = resolver ? resolver.apply(this, args) : args[0],
8938 cache = memoized.cache;
8940 if (cache.has(key)) {
8941 return cache.get(key);
8943 var result = func.apply(this, args);
8944 memoized.cache = cache.set(key, result);
8947 memoized.cache = new memoize.Cache;
8952 * Creates a function that negates the result of the predicate `func`. The
8953 * `func` predicate is invoked with the `this` binding and arguments of the
8958 * @category Function
8959 * @param {Function} predicate The predicate to negate.
8960 * @returns {Function} Returns the new function.
8963 * function isEven(n) {
8964 * return n % 2 == 0;
8967 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
8970 function negate(predicate) {
8971 if (typeof predicate != 'function') {
8972 throw new TypeError(FUNC_ERROR_TEXT);
8975 return !predicate.apply(this, arguments);
8980 * Creates a function that is restricted to invoking `func` once. Repeat calls
8981 * to the function return the value of the first invocation. The `func` is
8982 * invoked with the `this` binding and arguments of the created function.
8986 * @category Function
8987 * @param {Function} func The function to restrict.
8988 * @returns {Function} Returns the new restricted function.
8991 * var initialize = _.once(createApplication);
8994 * // `initialize` invokes `createApplication` once
8996 function once(func) {
8997 return before(2, func);
9001 * Creates a function that invokes `func` with arguments transformed by
9002 * corresponding `transforms`.
9006 * @category Function
9007 * @param {Function} func The function to wrap.
9008 * @param {...(Function|Function[])} [transforms] The functions to transform
9009 * arguments, specified individually or in arrays.
9010 * @returns {Function} Returns the new function.
9013 * function doubled(n) {
9017 * function square(n) {
9021 * var func = _.overArgs(function(x, y) {
9023 * }, square, doubled);
9031 var overArgs = rest(function(func, transforms) {
9032 transforms = arrayMap(baseFlatten(transforms, 1), getIteratee());
9034 var funcsLength = transforms.length;
9035 return rest(function(args) {
9037 length = nativeMin(args.length, funcsLength);
9039 while (++index < length) {
9040 args[index] = transforms[index].call(this, args[index]);
9042 return apply(func, this, args);
9047 * Creates a function that invokes `func` with `partial` arguments prepended
9048 * to those provided to the new function. This method is like `_.bind` except
9049 * it does **not** alter the `this` binding.
9051 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
9052 * builds, may be used as a placeholder for partially applied arguments.
9054 * **Note:** This method doesn't set the "length" property of partially
9055 * applied functions.
9059 * @category Function
9060 * @param {Function} func The function to partially apply arguments to.
9061 * @param {...*} [partials] The arguments to be partially applied.
9062 * @returns {Function} Returns the new partially applied function.
9065 * var greet = function(greeting, name) {
9066 * return greeting + ' ' + name;
9069 * var sayHelloTo = _.partial(greet, 'hello');
9070 * sayHelloTo('fred');
9071 * // => 'hello fred'
9073 * // Partially applied with placeholders.
9074 * var greetFred = _.partial(greet, _, 'fred');
9078 var partial = rest(function(func, partials) {
9079 var holders = replaceHolders(partials, getPlaceholder(partial));
9080 return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
9084 * This method is like `_.partial` except that partially applied arguments
9085 * are appended to those provided to the new function.
9087 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
9088 * builds, may be used as a placeholder for partially applied arguments.
9090 * **Note:** This method doesn't set the "length" property of partially
9091 * applied functions.
9095 * @category Function
9096 * @param {Function} func The function to partially apply arguments to.
9097 * @param {...*} [partials] The arguments to be partially applied.
9098 * @returns {Function} Returns the new partially applied function.
9101 * var greet = function(greeting, name) {
9102 * return greeting + ' ' + name;
9105 * var greetFred = _.partialRight(greet, 'fred');
9109 * // Partially applied with placeholders.
9110 * var sayHelloTo = _.partialRight(greet, 'hello', _);
9111 * sayHelloTo('fred');
9112 * // => 'hello fred'
9114 var partialRight = rest(function(func, partials) {
9115 var holders = replaceHolders(partials, getPlaceholder(partialRight));
9116 return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
9120 * Creates a function that invokes `func` with arguments arranged according
9121 * to the specified indexes where the argument value at the first index is
9122 * provided as the first argument, the argument value at the second index is
9123 * provided as the second argument, and so on.
9127 * @category Function
9128 * @param {Function} func The function to rearrange arguments for.
9129 * @param {...(number|number[])} indexes The arranged argument indexes,
9130 * specified individually or in arrays.
9131 * @returns {Function} Returns the new function.
9134 * var rearged = _.rearg(function(a, b, c) {
9138 * rearged('b', 'c', 'a')
9139 * // => ['a', 'b', 'c']
9141 var rearg = rest(function(func, indexes) {
9142 return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
9146 * Creates a function that invokes `func` with the `this` binding of the
9147 * created function and arguments from `start` and beyond provided as an array.
9149 * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
9153 * @category Function
9154 * @param {Function} func The function to apply a rest parameter to.
9155 * @param {number} [start=func.length-1] The start position of the rest parameter.
9156 * @returns {Function} Returns the new function.
9159 * var say = _.rest(function(what, names) {
9160 * return what + ' ' + _.initial(names).join(', ') +
9161 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
9164 * say('hello', 'fred', 'barney', 'pebbles');
9165 * // => 'hello fred, barney, & pebbles'
9167 function rest(func, start) {
9168 if (typeof func != 'function') {
9169 throw new TypeError(FUNC_ERROR_TEXT);
9171 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
9173 var args = arguments,
9175 length = nativeMax(args.length - start, 0),
9176 array = Array(length);
9178 while (++index < length) {
9179 array[index] = args[start + index];
9182 case 0: return func.call(this, array);
9183 case 1: return func.call(this, args[0], array);
9184 case 2: return func.call(this, args[0], args[1], array);
9186 var otherArgs = Array(start + 1);
9188 while (++index < start) {
9189 otherArgs[index] = args[index];
9191 otherArgs[start] = array;
9192 return apply(func, this, otherArgs);
9197 * Creates a function that invokes `func` with the `this` binding of the created
9198 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
9200 * **Note:** This method is based on the [spread operator](https://mdn.io/spread_operator).
9204 * @category Function
9205 * @param {Function} func The function to spread arguments over.
9206 * @param {number} [start=0] The start position of the spread.
9207 * @returns {Function} Returns the new function.
9210 * var say = _.spread(function(who, what) {
9211 * return who + ' says ' + what;
9214 * say(['fred', 'hello']);
9215 * // => 'fred says hello'
9217 * var numbers = Promise.all([
9218 * Promise.resolve(40),
9219 * Promise.resolve(36)
9222 * numbers.then(_.spread(function(x, y) {
9225 * // => a Promise of 76
9227 function spread(func, start) {
9228 if (typeof func != 'function') {
9229 throw new TypeError(FUNC_ERROR_TEXT);
9231 start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
9232 return rest(function(args) {
9233 var array = args[start],
9234 otherArgs = args.slice(0, start);
9237 arrayPush(otherArgs, array);
9239 return apply(func, this, otherArgs);
9244 * Creates a throttled function that only invokes `func` at most once per
9245 * every `wait` milliseconds. The throttled function comes with a `cancel`
9246 * method to cancel delayed `func` invocations and a `flush` method to
9247 * immediately invoke them. Provide an options object to indicate whether
9248 * `func` should be invoked on the leading and/or trailing edge of the `wait`
9249 * timeout. The `func` is invoked with the last arguments provided to the
9250 * throttled function. Subsequent calls to the throttled function return the
9251 * result of the last `func` invocation.
9253 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
9254 * on the trailing edge of the timeout only if the throttled function is
9255 * invoked more than once during the `wait` timeout.
9257 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
9258 * for details over the differences between `_.throttle` and `_.debounce`.
9262 * @category Function
9263 * @param {Function} func The function to throttle.
9264 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
9265 * @param {Object} [options] The options object.
9266 * @param {boolean} [options.leading=true] Specify invoking on the leading
9267 * edge of the timeout.
9268 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
9269 * edge of the timeout.
9270 * @returns {Function} Returns the new throttled function.
9273 * // Avoid excessively updating the position while scrolling.
9274 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
9276 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
9277 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
9278 * jQuery(element).on('click', throttled);
9280 * // Cancel the trailing throttled invocation.
9281 * jQuery(window).on('popstate', throttled.cancel);
9283 function throttle(func, wait, options) {
9287 if (typeof func != 'function') {
9288 throw new TypeError(FUNC_ERROR_TEXT);
9290 if (isObject(options)) {
9291 leading = 'leading' in options ? !!options.leading : leading;
9292 trailing = 'trailing' in options ? !!options.trailing : trailing;
9294 return debounce(func, wait, {
9297 'trailing': trailing
9302 * Creates a function that accepts up to one argument, ignoring any
9303 * additional arguments.
9307 * @category Function
9308 * @param {Function} func The function to cap arguments for.
9309 * @returns {Function} Returns the new function.
9312 * _.map(['6', '8', '10'], _.unary(parseInt));
9315 function unary(func) {
9316 return ary(func, 1);
9320 * Creates a function that provides `value` to the wrapper function as its
9321 * first argument. Any additional arguments provided to the function are
9322 * appended to those provided to the wrapper function. The wrapper is invoked
9323 * with the `this` binding of the created function.
9327 * @category Function
9328 * @param {*} value The value to wrap.
9329 * @param {Function} [wrapper=identity] The wrapper function.
9330 * @returns {Function} Returns the new function.
9333 * var p = _.wrap(_.escape, function(func, text) {
9334 * return '<p>' + func(text) + '</p>';
9337 * p('fred, barney, & pebbles');
9338 * // => '<p>fred, barney, & pebbles</p>'
9340 function wrap(value, wrapper) {
9341 wrapper = wrapper == null ? identity : wrapper;
9342 return partial(wrapper, value);
9345 /*------------------------------------------------------------------------*/
9348 * Casts `value` as an array if it's not one.
9353 * @param {*} value The value to inspect.
9354 * @returns {Array} Returns the cast array.
9360 * _.castArray({ 'a': 1 });
9361 * // => [{ 'a': 1 }]
9363 * _.castArray('abc');
9366 * _.castArray(null);
9369 * _.castArray(undefined);
9375 * var array = [1, 2, 3];
9376 * console.log(_.castArray(array) === array);
9379 function castArray() {
9380 if (!arguments.length) {
9383 var value = arguments[0];
9384 return isArray(value) ? value : [value];
9388 * Creates a shallow clone of `value`.
9390 * **Note:** This method is loosely based on the
9391 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
9392 * and supports cloning arrays, array buffers, booleans, date objects, maps,
9393 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
9394 * arrays. The own enumerable properties of `arguments` objects are cloned
9395 * as plain objects. An empty object is returned for uncloneable values such
9396 * as error objects, functions, DOM nodes, and WeakMaps.
9401 * @param {*} value The value to clone.
9402 * @returns {*} Returns the cloned value.
9405 * var objects = [{ 'a': 1 }, { 'b': 2 }];
9407 * var shallow = _.clone(objects);
9408 * console.log(shallow[0] === objects[0]);
9411 function clone(value) {
9412 return baseClone(value);
9416 * This method is like `_.clone` except that it accepts `customizer` which
9417 * is invoked to produce the cloned value. If `customizer` returns `undefined`
9418 * cloning is handled by the method instead. The `customizer` is invoked with
9419 * up to four arguments; (value [, index|key, object, stack]).
9424 * @param {*} value The value to clone.
9425 * @param {Function} [customizer] The function to customize cloning.
9426 * @returns {*} Returns the cloned value.
9429 * function customizer(value) {
9430 * if (_.isElement(value)) {
9431 * return value.cloneNode(false);
9435 * var el = _.cloneWith(document.body, customizer);
9437 * console.log(el === document.body);
9439 * console.log(el.nodeName);
9441 * console.log(el.childNodes.length);
9444 function cloneWith(value, customizer) {
9445 return baseClone(value, false, customizer);
9449 * This method is like `_.clone` except that it recursively clones `value`.
9454 * @param {*} value The value to recursively clone.
9455 * @returns {*} Returns the deep cloned value.
9458 * var objects = [{ 'a': 1 }, { 'b': 2 }];
9460 * var deep = _.cloneDeep(objects);
9461 * console.log(deep[0] === objects[0]);
9464 function cloneDeep(value) {
9465 return baseClone(value, true);
9469 * This method is like `_.cloneWith` except that it recursively clones `value`.
9474 * @param {*} value The value to recursively clone.
9475 * @param {Function} [customizer] The function to customize cloning.
9476 * @returns {*} Returns the deep cloned value.
9479 * function customizer(value) {
9480 * if (_.isElement(value)) {
9481 * return value.cloneNode(true);
9485 * var el = _.cloneDeepWith(document.body, customizer);
9487 * console.log(el === document.body);
9489 * console.log(el.nodeName);
9491 * console.log(el.childNodes.length);
9494 function cloneDeepWith(value, customizer) {
9495 return baseClone(value, true, customizer);
9499 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
9500 * comparison between two values to determine if they are equivalent.
9505 * @param {*} value The value to compare.
9506 * @param {*} other The other value to compare.
9507 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9510 * var object = { 'user': 'fred' };
9511 * var other = { 'user': 'fred' };
9513 * _.eq(object, object);
9516 * _.eq(object, other);
9522 * _.eq('a', Object('a'));
9528 function eq(value, other) {
9529 return value === other || (value !== value && other !== other);
9533 * Checks if `value` is greater than `other`.
9538 * @param {*} value The value to compare.
9539 * @param {*} other The other value to compare.
9540 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
9552 function gt(value, other) {
9553 return value > other;
9557 * Checks if `value` is greater than or equal to `other`.
9562 * @param {*} value The value to compare.
9563 * @param {*} other The other value to compare.
9564 * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
9576 function gte(value, other) {
9577 return value >= other;
9581 * Checks if `value` is likely an `arguments` object.
9586 * @param {*} value The value to check.
9587 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9590 * _.isArguments(function() { return arguments; }());
9593 * _.isArguments([1, 2, 3]);
9596 function isArguments(value) {
9597 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
9598 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
9599 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
9603 * Checks if `value` is classified as an `Array` object.
9609 * @param {*} value The value to check.
9610 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9613 * _.isArray([1, 2, 3]);
9616 * _.isArray(document.body.children);
9622 * _.isArray(_.noop);
9625 var isArray = Array.isArray;
9628 * Checks if `value` is classified as an `ArrayBuffer` object.
9633 * @param {*} value The value to check.
9634 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9637 * _.isArrayBuffer(new ArrayBuffer(2));
9640 * _.isArrayBuffer(new Array(2));
9643 function isArrayBuffer(value) {
9644 return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
9648 * Checks if `value` is array-like. A value is considered array-like if it's
9649 * not a function and has a `value.length` that's an integer greater than or
9650 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
9655 * @param {*} value The value to check.
9656 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
9659 * _.isArrayLike([1, 2, 3]);
9662 * _.isArrayLike(document.body.children);
9665 * _.isArrayLike('abc');
9668 * _.isArrayLike(_.noop);
9671 function isArrayLike(value) {
9672 return value != null &&
9673 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
9677 * This method is like `_.isArrayLike` except that it also checks if `value`
9683 * @param {*} value The value to check.
9684 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
9687 * _.isArrayLikeObject([1, 2, 3]);
9690 * _.isArrayLikeObject(document.body.children);
9693 * _.isArrayLikeObject('abc');
9696 * _.isArrayLikeObject(_.noop);
9699 function isArrayLikeObject(value) {
9700 return isObjectLike(value) && isArrayLike(value);
9704 * Checks if `value` is classified as a boolean primitive or object.
9709 * @param {*} value The value to check.
9710 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9713 * _.isBoolean(false);
9716 * _.isBoolean(null);
9719 function isBoolean(value) {
9720 return value === true || value === false ||
9721 (isObjectLike(value) && objectToString.call(value) == boolTag);
9725 * Checks if `value` is a buffer.
9730 * @param {*} value The value to check.
9731 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
9734 * _.isBuffer(new Buffer(2));
9737 * _.isBuffer(new Uint8Array(2));
9740 var isBuffer = !Buffer ? constant(false) : function(value) {
9741 return value instanceof Buffer;
9745 * Checks if `value` is classified as a `Date` object.
9750 * @param {*} value The value to check.
9751 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9754 * _.isDate(new Date);
9757 * _.isDate('Mon April 23 2012');
9760 function isDate(value) {
9761 return isObjectLike(value) && objectToString.call(value) == dateTag;
9765 * Checks if `value` is likely a DOM element.
9770 * @param {*} value The value to check.
9771 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
9774 * _.isElement(document.body);
9777 * _.isElement('<body>');
9780 function isElement(value) {
9781 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
9785 * Checks if `value` is empty. A value is considered empty unless it's an
9786 * `arguments` object, array, string, or jQuery-like collection with a length
9787 * greater than `0` or an object with own enumerable properties.
9792 * @param {Array|Object|string} value The value to inspect.
9793 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
9805 * _.isEmpty([1, 2, 3]);
9808 * _.isEmpty({ 'a': 1 });
9811 function isEmpty(value) {
9812 if (isArrayLike(value) &&
9813 (isArray(value) || isString(value) ||
9814 isFunction(value.splice) || isArguments(value))) {
9815 return !value.length;
9817 for (var key in value) {
9818 if (hasOwnProperty.call(value, key)) {
9826 * Performs a deep comparison between two values to determine if they are
9829 * **Note:** This method supports comparing arrays, array buffers, booleans,
9830 * date objects, error objects, maps, numbers, `Object` objects, regexes,
9831 * sets, strings, symbols, and typed arrays. `Object` objects are compared
9832 * by their own, not inherited, enumerable properties. Functions and DOM
9833 * nodes are **not** supported.
9838 * @param {*} value The value to compare.
9839 * @param {*} other The other value to compare.
9840 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9843 * var object = { 'user': 'fred' };
9844 * var other = { 'user': 'fred' };
9846 * _.isEqual(object, other);
9852 function isEqual(value, other) {
9853 return baseIsEqual(value, other);
9857 * This method is like `_.isEqual` except that it accepts `customizer` which
9858 * is invoked to compare values. If `customizer` returns `undefined` comparisons
9859 * are handled by the method instead. The `customizer` is invoked with up to
9860 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
9865 * @param {*} value The value to compare.
9866 * @param {*} other The other value to compare.
9867 * @param {Function} [customizer] The function to customize comparisons.
9868 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9871 * function isGreeting(value) {
9872 * return /^h(?:i|ello)$/.test(value);
9875 * function customizer(objValue, othValue) {
9876 * if (isGreeting(objValue) && isGreeting(othValue)) {
9881 * var array = ['hello', 'goodbye'];
9882 * var other = ['hi', 'goodbye'];
9884 * _.isEqualWith(array, other, customizer);
9887 function isEqualWith(value, other, customizer) {
9888 customizer = typeof customizer == 'function' ? customizer : undefined;
9889 var result = customizer ? customizer(value, other) : undefined;
9890 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
9894 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
9895 * `SyntaxError`, `TypeError`, or `URIError` object.
9900 * @param {*} value The value to check.
9901 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
9904 * _.isError(new Error);
9910 function isError(value) {
9911 if (!isObjectLike(value)) {
9914 return (objectToString.call(value) == errorTag) ||
9915 (typeof value.message == 'string' && typeof value.name == 'string');
9919 * Checks if `value` is a finite primitive number.
9921 * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
9926 * @param {*} value The value to check.
9927 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
9933 * _.isFinite(Number.MAX_VALUE);
9939 * _.isFinite(Infinity);
9942 function isFinite(value) {
9943 return typeof value == 'number' && nativeIsFinite(value);
9947 * Checks if `value` is classified as a `Function` object.
9952 * @param {*} value The value to check.
9953 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9959 * _.isFunction(/abc/);
9962 function isFunction(value) {
9963 // The use of `Object#toString` avoids issues with the `typeof` operator
9964 // in Safari 8 which returns 'object' for typed array constructors, and
9965 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
9966 var tag = isObject(value) ? objectToString.call(value) : '';
9967 return tag == funcTag || tag == genTag;
9971 * Checks if `value` is an integer.
9973 * **Note:** This method is based on [`Number.isInteger`](https://mdn.io/Number/isInteger).
9978 * @param {*} value The value to check.
9979 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
9985 * _.isInteger(Number.MIN_VALUE);
9988 * _.isInteger(Infinity);
9994 function isInteger(value) {
9995 return typeof value == 'number' && value == toInteger(value);
9999 * Checks if `value` is a valid array-like length.
10001 * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
10006 * @param {*} value The value to check.
10007 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
10013 * _.isLength(Number.MIN_VALUE);
10016 * _.isLength(Infinity);
10022 function isLength(value) {
10023 return typeof value == 'number' &&
10024 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
10028 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
10029 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
10034 * @param {*} value The value to check.
10035 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
10041 * _.isObject([1, 2, 3]);
10044 * _.isObject(_.noop);
10047 * _.isObject(null);
10050 function isObject(value) {
10051 var type = typeof value;
10052 return !!value && (type == 'object' || type == 'function');
10056 * Checks if `value` is object-like. A value is object-like if it's not `null`
10057 * and has a `typeof` result of "object".
10062 * @param {*} value The value to check.
10063 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
10066 * _.isObjectLike({});
10069 * _.isObjectLike([1, 2, 3]);
10072 * _.isObjectLike(_.noop);
10075 * _.isObjectLike(null);
10078 function isObjectLike(value) {
10079 return !!value && typeof value == 'object';
10083 * Checks if `value` is classified as a `Map` object.
10088 * @param {*} value The value to check.
10089 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10092 * _.isMap(new Map);
10095 * _.isMap(new WeakMap);
10098 function isMap(value) {
10099 return isObjectLike(value) && getTag(value) == mapTag;
10103 * Performs a partial deep comparison between `object` and `source` to
10104 * determine if `object` contains equivalent property values. This method is
10105 * equivalent to a `_.matches` function when `source` is partially applied.
10107 * **Note:** This method supports comparing the same values as `_.isEqual`.
10112 * @param {Object} object The object to inspect.
10113 * @param {Object} source The object of property values to match.
10114 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
10117 * var object = { 'user': 'fred', 'age': 40 };
10119 * _.isMatch(object, { 'age': 40 });
10122 * _.isMatch(object, { 'age': 36 });
10125 function isMatch(object, source) {
10126 return object === source || baseIsMatch(object, source, getMatchData(source));
10130 * This method is like `_.isMatch` except that it accepts `customizer` which
10131 * is invoked to compare values. If `customizer` returns `undefined` comparisons
10132 * are handled by the method instead. The `customizer` is invoked with five
10133 * arguments: (objValue, srcValue, index|key, object, source).
10138 * @param {Object} object The object to inspect.
10139 * @param {Object} source The object of property values to match.
10140 * @param {Function} [customizer] The function to customize comparisons.
10141 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
10144 * function isGreeting(value) {
10145 * return /^h(?:i|ello)$/.test(value);
10148 * function customizer(objValue, srcValue) {
10149 * if (isGreeting(objValue) && isGreeting(srcValue)) {
10154 * var object = { 'greeting': 'hello' };
10155 * var source = { 'greeting': 'hi' };
10157 * _.isMatchWith(object, source, customizer);
10160 function isMatchWith(object, source, customizer) {
10161 customizer = typeof customizer == 'function' ? customizer : undefined;
10162 return baseIsMatch(object, source, getMatchData(source), customizer);
10166 * Checks if `value` is `NaN`.
10168 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
10169 * which returns `true` for `undefined` and other non-numeric values.
10174 * @param {*} value The value to check.
10175 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
10181 * _.isNaN(new Number(NaN));
10184 * isNaN(undefined);
10187 * _.isNaN(undefined);
10190 function isNaN(value) {
10191 // An `NaN` primitive is the only value that is not equal to itself.
10192 // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
10193 return isNumber(value) && value != +value;
10197 * Checks if `value` is a native function.
10202 * @param {*} value The value to check.
10203 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
10206 * _.isNative(Array.prototype.push);
10212 function isNative(value) {
10213 if (value == null) {
10216 if (isFunction(value)) {
10217 return reIsNative.test(funcToString.call(value));
10219 return isObjectLike(value) &&
10220 (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
10224 * Checks if `value` is `null`.
10229 * @param {*} value The value to check.
10230 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
10236 * _.isNull(void 0);
10239 function isNull(value) {
10240 return value === null;
10244 * Checks if `value` is `null` or `undefined`.
10249 * @param {*} value The value to check.
10250 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
10262 function isNil(value) {
10263 return value == null;
10267 * Checks if `value` is classified as a `Number` primitive or object.
10269 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
10270 * as numbers, use the `_.isFinite` method.
10275 * @param {*} value The value to check.
10276 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10282 * _.isNumber(Number.MIN_VALUE);
10285 * _.isNumber(Infinity);
10291 function isNumber(value) {
10292 return typeof value == 'number' ||
10293 (isObjectLike(value) && objectToString.call(value) == numberTag);
10297 * Checks if `value` is a plain object, that is, an object created by the
10298 * `Object` constructor or one with a `[[Prototype]]` of `null`.
10303 * @param {*} value The value to check.
10304 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
10311 * _.isPlainObject(new Foo);
10314 * _.isPlainObject([1, 2, 3]);
10317 * _.isPlainObject({ 'x': 0, 'y': 0 });
10320 * _.isPlainObject(Object.create(null));
10323 function isPlainObject(value) {
10324 if (!isObjectLike(value) ||
10325 objectToString.call(value) != objectTag || isHostObject(value)) {
10328 var proto = getPrototypeOf(value);
10329 if (proto === null) {
10332 var Ctor = proto.constructor;
10333 return (typeof Ctor == 'function' &&
10334 Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
10338 * Checks if `value` is classified as a `RegExp` object.
10343 * @param {*} value The value to check.
10344 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10347 * _.isRegExp(/abc/);
10350 * _.isRegExp('/abc/');
10353 function isRegExp(value) {
10354 return isObject(value) && objectToString.call(value) == regexpTag;
10358 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
10359 * double precision number which isn't the result of a rounded unsafe integer.
10361 * **Note:** This method is based on [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
10366 * @param {*} value The value to check.
10367 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
10370 * _.isSafeInteger(3);
10373 * _.isSafeInteger(Number.MIN_VALUE);
10376 * _.isSafeInteger(Infinity);
10379 * _.isSafeInteger('3');
10382 function isSafeInteger(value) {
10383 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
10387 * Checks if `value` is classified as a `Set` object.
10392 * @param {*} value The value to check.
10393 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10396 * _.isSet(new Set);
10399 * _.isSet(new WeakSet);
10402 function isSet(value) {
10403 return isObjectLike(value) && getTag(value) == setTag;
10407 * Checks if `value` is classified as a `String` primitive or object.
10412 * @param {*} value The value to check.
10413 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10416 * _.isString('abc');
10422 function isString(value) {
10423 return typeof value == 'string' ||
10424 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
10428 * Checks if `value` is classified as a `Symbol` primitive or object.
10433 * @param {*} value The value to check.
10434 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10437 * _.isSymbol(Symbol.iterator);
10440 * _.isSymbol('abc');
10443 function isSymbol(value) {
10444 return typeof value == 'symbol' ||
10445 (isObjectLike(value) && objectToString.call(value) == symbolTag);
10449 * Checks if `value` is classified as a typed array.
10454 * @param {*} value The value to check.
10455 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10458 * _.isTypedArray(new Uint8Array);
10461 * _.isTypedArray([]);
10464 function isTypedArray(value) {
10465 return isObjectLike(value) &&
10466 isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
10470 * Checks if `value` is `undefined`.
10475 * @param {*} value The value to check.
10476 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
10479 * _.isUndefined(void 0);
10482 * _.isUndefined(null);
10485 function isUndefined(value) {
10486 return value === undefined;
10490 * Checks if `value` is classified as a `WeakMap` object.
10495 * @param {*} value The value to check.
10496 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10499 * _.isWeakMap(new WeakMap);
10502 * _.isWeakMap(new Map);
10505 function isWeakMap(value) {
10506 return isObjectLike(value) && getTag(value) == weakMapTag;
10510 * Checks if `value` is classified as a `WeakSet` object.
10515 * @param {*} value The value to check.
10516 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10519 * _.isWeakSet(new WeakSet);
10522 * _.isWeakSet(new Set);
10525 function isWeakSet(value) {
10526 return isObjectLike(value) && objectToString.call(value) == weakSetTag;
10530 * Checks if `value` is less than `other`.
10535 * @param {*} value The value to compare.
10536 * @param {*} other The other value to compare.
10537 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
10549 function lt(value, other) {
10550 return value < other;
10554 * Checks if `value` is less than or equal to `other`.
10559 * @param {*} value The value to compare.
10560 * @param {*} other The other value to compare.
10561 * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
10573 function lte(value, other) {
10574 return value <= other;
10578 * Converts `value` to an array.
10583 * @param {*} value The value to convert.
10584 * @returns {Array} Returns the converted array.
10587 * _.toArray({ 'a': 1, 'b': 2 });
10590 * _.toArray('abc');
10591 * // => ['a', 'b', 'c']
10599 function toArray(value) {
10603 if (isArrayLike(value)) {
10604 return isString(value) ? stringToArray(value) : copyArray(value);
10606 if (iteratorSymbol && value[iteratorSymbol]) {
10607 return iteratorToArray(value[iteratorSymbol]());
10609 var tag = getTag(value),
10610 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
10612 return func(value);
10616 * Converts `value` to an integer.
10618 * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
10623 * @param {*} value The value to convert.
10624 * @returns {number} Returns the converted integer.
10630 * _.toInteger(Number.MIN_VALUE);
10633 * _.toInteger(Infinity);
10634 * // => 1.7976931348623157e+308
10636 * _.toInteger('3');
10639 function toInteger(value) {
10641 return value === 0 ? value : 0;
10643 value = toNumber(value);
10644 if (value === INFINITY || value === -INFINITY) {
10645 var sign = (value < 0 ? -1 : 1);
10646 return sign * MAX_INTEGER;
10648 var remainder = value % 1;
10649 return value === value ? (remainder ? value - remainder : value) : 0;
10653 * Converts `value` to an integer suitable for use as the length of an
10654 * array-like object.
10656 * **Note:** This method is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
10661 * @param {*} value The value to convert.
10662 * @returns {number} Returns the converted integer.
10668 * _.toLength(Number.MIN_VALUE);
10671 * _.toLength(Infinity);
10677 function toLength(value) {
10678 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
10682 * Converts `value` to a number.
10687 * @param {*} value The value to process.
10688 * @returns {number} Returns the number.
10694 * _.toNumber(Number.MIN_VALUE);
10697 * _.toNumber(Infinity);
10703 function toNumber(value) {
10704 if (isObject(value)) {
10705 var other = isFunction(value.valueOf) ? value.valueOf() : value;
10706 value = isObject(other) ? (other + '') : other;
10708 if (typeof value != 'string') {
10709 return value === 0 ? value : +value;
10711 value = value.replace(reTrim, '');
10712 var isBinary = reIsBinary.test(value);
10713 return (isBinary || reIsOctal.test(value))
10714 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
10715 : (reIsBadHex.test(value) ? NAN : +value);
10719 * Converts `value` to a plain object flattening inherited enumerable
10720 * properties of `value` to own properties of the plain object.
10725 * @param {*} value The value to convert.
10726 * @returns {Object} Returns the converted plain object.
10733 * Foo.prototype.c = 3;
10735 * _.assign({ 'a': 1 }, new Foo);
10736 * // => { 'a': 1, 'b': 2 }
10738 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
10739 * // => { 'a': 1, 'b': 2, 'c': 3 }
10741 function toPlainObject(value) {
10742 return copyObject(value, keysIn(value));
10746 * Converts `value` to a safe integer. A safe integer can be compared and
10747 * represented correctly.
10752 * @param {*} value The value to convert.
10753 * @returns {number} Returns the converted integer.
10756 * _.toSafeInteger(3);
10759 * _.toSafeInteger(Number.MIN_VALUE);
10762 * _.toSafeInteger(Infinity);
10763 * // => 9007199254740991
10765 * _.toSafeInteger('3');
10768 function toSafeInteger(value) {
10769 return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
10773 * Converts `value` to a string if it's not one. An empty string is returned
10774 * for `null` and `undefined` values. The sign of `-0` is preserved.
10779 * @param {*} value The value to process.
10780 * @returns {string} Returns the string.
10783 * _.toString(null);
10789 * _.toString([1, 2, 3]);
10792 function toString(value) {
10793 // Exit early for strings to avoid a performance hit in some environments.
10794 if (typeof value == 'string') {
10797 if (value == null) {
10800 if (isSymbol(value)) {
10801 return Symbol ? symbolToString.call(value) : '';
10803 var result = (value + '');
10804 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
10807 /*------------------------------------------------------------------------*/
10810 * Assigns own enumerable properties of source objects to the destination
10811 * object. Source objects are applied from left to right. Subsequent sources
10812 * overwrite property assignments of previous sources.
10814 * **Note:** This method mutates `object` and is loosely based on
10815 * [`Object.assign`](https://mdn.io/Object/assign).
10820 * @param {Object} object The destination object.
10821 * @param {...Object} [sources] The source objects.
10822 * @returns {Object} Returns `object`.
10833 * Foo.prototype.d = 4;
10834 * Bar.prototype.f = 6;
10836 * _.assign({ 'a': 1 }, new Foo, new Bar);
10837 * // => { 'a': 1, 'c': 3, 'e': 5 }
10839 var assign = createAssigner(function(object, source) {
10840 copyObject(source, keys(source), object);
10844 * This method is like `_.assign` except that it iterates over own and
10845 * inherited source properties.
10847 * **Note:** This method mutates `object`.
10853 * @param {Object} object The destination object.
10854 * @param {...Object} [sources] The source objects.
10855 * @returns {Object} Returns `object`.
10866 * Foo.prototype.c = 3;
10867 * Bar.prototype.e = 5;
10869 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
10870 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
10872 var assignIn = createAssigner(function(object, source) {
10873 copyObject(source, keysIn(source), object);
10877 * This method is like `_.assignIn` except that it accepts `customizer` which
10878 * is invoked to produce the assigned values. If `customizer` returns `undefined`
10879 * assignment is handled by the method instead. The `customizer` is invoked
10880 * with five arguments: (objValue, srcValue, key, object, source).
10882 * **Note:** This method mutates `object`.
10886 * @alias extendWith
10888 * @param {Object} object The destination object.
10889 * @param {...Object} sources The source objects.
10890 * @param {Function} [customizer] The function to customize assigned values.
10891 * @returns {Object} Returns `object`.
10894 * function customizer(objValue, srcValue) {
10895 * return _.isUndefined(objValue) ? srcValue : objValue;
10898 * var defaults = _.partialRight(_.assignInWith, customizer);
10900 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
10901 * // => { 'a': 1, 'b': 2 }
10903 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
10904 copyObjectWith(source, keysIn(source), object, customizer);
10908 * This method is like `_.assign` except that it accepts `customizer` which
10909 * is invoked to produce the assigned values. If `customizer` returns `undefined`
10910 * assignment is handled by the method instead. The `customizer` is invoked
10911 * with five arguments: (objValue, srcValue, key, object, source).
10913 * **Note:** This method mutates `object`.
10918 * @param {Object} object The destination object.
10919 * @param {...Object} sources The source objects.
10920 * @param {Function} [customizer] The function to customize assigned values.
10921 * @returns {Object} Returns `object`.
10924 * function customizer(objValue, srcValue) {
10925 * return _.isUndefined(objValue) ? srcValue : objValue;
10928 * var defaults = _.partialRight(_.assignWith, customizer);
10930 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
10931 * // => { 'a': 1, 'b': 2 }
10933 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
10934 copyObjectWith(source, keys(source), object, customizer);
10938 * Creates an array of values corresponding to `paths` of `object`.
10943 * @param {Object} object The object to iterate over.
10944 * @param {...(string|string[])} [paths] The property paths of elements to pick,
10945 * specified individually or in arrays.
10946 * @returns {Array} Returns the new array of picked elements.
10949 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
10951 * _.at(object, ['a[0].b.c', 'a[1]']);
10954 * _.at(['a', 'b', 'c'], 0, 2);
10957 var at = rest(function(object, paths) {
10958 return baseAt(object, baseFlatten(paths, 1));
10962 * Creates an object that inherits from the `prototype` object. If a `properties`
10963 * object is given its own enumerable properties are assigned to the created object.
10968 * @param {Object} prototype The object to inherit from.
10969 * @param {Object} [properties] The properties to assign to the object.
10970 * @returns {Object} Returns the new object.
10973 * function Shape() {
10978 * function Circle() {
10979 * Shape.call(this);
10982 * Circle.prototype = _.create(Shape.prototype, {
10983 * 'constructor': Circle
10986 * var circle = new Circle;
10987 * circle instanceof Circle;
10990 * circle instanceof Shape;
10993 function create(prototype, properties) {
10994 var result = baseCreate(prototype);
10995 return properties ? baseAssign(result, properties) : result;
10999 * Assigns own and inherited enumerable properties of source objects to the
11000 * destination object for all destination properties that resolve to `undefined`.
11001 * Source objects are applied from left to right. Once a property is set,
11002 * additional values of the same property are ignored.
11004 * **Note:** This method mutates `object`.
11009 * @param {Object} object The destination object.
11010 * @param {...Object} [sources] The source objects.
11011 * @returns {Object} Returns `object`.
11014 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
11015 * // => { 'user': 'barney', 'age': 36 }
11017 var defaults = rest(function(args) {
11018 args.push(undefined, assignInDefaults);
11019 return apply(assignInWith, undefined, args);
11023 * This method is like `_.defaults` except that it recursively assigns
11024 * default properties.
11026 * **Note:** This method mutates `object`.
11031 * @param {Object} object The destination object.
11032 * @param {...Object} [sources] The source objects.
11033 * @returns {Object} Returns `object`.
11036 * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
11037 * // => { 'user': { 'name': 'barney', 'age': 36 } }
11040 var defaultsDeep = rest(function(args) {
11041 args.push(undefined, mergeDefaults);
11042 return apply(mergeWith, undefined, args);
11046 * This method is like `_.find` except that it returns the key of the first
11047 * element `predicate` returns truthy for instead of the element itself.
11052 * @param {Object} object The object to search.
11053 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
11054 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
11058 * 'barney': { 'age': 36, 'active': true },
11059 * 'fred': { 'age': 40, 'active': false },
11060 * 'pebbles': { 'age': 1, 'active': true }
11063 * _.findKey(users, function(o) { return o.age < 40; });
11064 * // => 'barney' (iteration order is not guaranteed)
11066 * // The `_.matches` iteratee shorthand.
11067 * _.findKey(users, { 'age': 1, 'active': true });
11070 * // The `_.matchesProperty` iteratee shorthand.
11071 * _.findKey(users, ['active', false]);
11074 * // The `_.property` iteratee shorthand.
11075 * _.findKey(users, 'active');
11078 function findKey(object, predicate) {
11079 return baseFind(object, getIteratee(predicate, 3), baseForOwn, true);
11083 * This method is like `_.findKey` except that it iterates over elements of
11084 * a collection in the opposite order.
11089 * @param {Object} object The object to search.
11090 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
11091 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
11095 * 'barney': { 'age': 36, 'active': true },
11096 * 'fred': { 'age': 40, 'active': false },
11097 * 'pebbles': { 'age': 1, 'active': true }
11100 * _.findLastKey(users, function(o) { return o.age < 40; });
11101 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
11103 * // The `_.matches` iteratee shorthand.
11104 * _.findLastKey(users, { 'age': 36, 'active': true });
11107 * // The `_.matchesProperty` iteratee shorthand.
11108 * _.findLastKey(users, ['active', false]);
11111 * // The `_.property` iteratee shorthand.
11112 * _.findLastKey(users, 'active');
11115 function findLastKey(object, predicate) {
11116 return baseFind(object, getIteratee(predicate, 3), baseForOwnRight, true);
11120 * Iterates over own and inherited enumerable properties of an object invoking
11121 * `iteratee` for each property. The iteratee is invoked with three arguments:
11122 * (value, key, object). Iteratee functions may exit iteration early by explicitly
11123 * returning `false`.
11128 * @param {Object} object The object to iterate over.
11129 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11130 * @returns {Object} Returns `object`.
11138 * Foo.prototype.c = 3;
11140 * _.forIn(new Foo, function(value, key) {
11141 * console.log(key);
11143 * // => logs 'a', 'b', then 'c' (iteration order is not guaranteed)
11145 function forIn(object, iteratee) {
11146 return object == null
11148 : baseFor(object, baseCastFunction(iteratee), keysIn);
11152 * This method is like `_.forIn` except that it iterates over properties of
11153 * `object` in the opposite order.
11158 * @param {Object} object The object to iterate over.
11159 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11160 * @returns {Object} Returns `object`.
11168 * Foo.prototype.c = 3;
11170 * _.forInRight(new Foo, function(value, key) {
11171 * console.log(key);
11173 * // => logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'
11175 function forInRight(object, iteratee) {
11176 return object == null
11178 : baseForRight(object, baseCastFunction(iteratee), keysIn);
11182 * Iterates over own enumerable properties of an object invoking `iteratee`
11183 * for each property. The iteratee is invoked with three arguments:
11184 * (value, key, object). Iteratee functions may exit iteration early by
11185 * explicitly returning `false`.
11190 * @param {Object} object The object to iterate over.
11191 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11192 * @returns {Object} Returns `object`.
11200 * Foo.prototype.c = 3;
11202 * _.forOwn(new Foo, function(value, key) {
11203 * console.log(key);
11205 * // => logs 'a' then 'b' (iteration order is not guaranteed)
11207 function forOwn(object, iteratee) {
11208 return object && baseForOwn(object, baseCastFunction(iteratee));
11212 * This method is like `_.forOwn` except that it iterates over properties of
11213 * `object` in the opposite order.
11218 * @param {Object} object The object to iterate over.
11219 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11220 * @returns {Object} Returns `object`.
11228 * Foo.prototype.c = 3;
11230 * _.forOwnRight(new Foo, function(value, key) {
11231 * console.log(key);
11233 * // => logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'
11235 function forOwnRight(object, iteratee) {
11236 return object && baseForOwnRight(object, baseCastFunction(iteratee));
11240 * Creates an array of function property names from own enumerable properties
11246 * @param {Object} object The object to inspect.
11247 * @returns {Array} Returns the new array of property names.
11251 * this.a = _.constant('a');
11252 * this.b = _.constant('b');
11255 * Foo.prototype.c = _.constant('c');
11257 * _.functions(new Foo);
11260 function functions(object) {
11261 return object == null ? [] : baseFunctions(object, keys(object));
11265 * Creates an array of function property names from own and inherited
11266 * enumerable properties of `object`.
11271 * @param {Object} object The object to inspect.
11272 * @returns {Array} Returns the new array of property names.
11276 * this.a = _.constant('a');
11277 * this.b = _.constant('b');
11280 * Foo.prototype.c = _.constant('c');
11282 * _.functionsIn(new Foo);
11283 * // => ['a', 'b', 'c']
11285 function functionsIn(object) {
11286 return object == null ? [] : baseFunctions(object, keysIn(object));
11290 * Gets the value at `path` of `object`. If the resolved value is
11291 * `undefined` the `defaultValue` is used in its place.
11296 * @param {Object} object The object to query.
11297 * @param {Array|string} path The path of the property to get.
11298 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
11299 * @returns {*} Returns the resolved value.
11302 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
11304 * _.get(object, 'a[0].b.c');
11307 * _.get(object, ['a', '0', 'b', 'c']);
11310 * _.get(object, 'a.b.c', 'default');
11313 function get(object, path, defaultValue) {
11314 var result = object == null ? undefined : baseGet(object, path);
11315 return result === undefined ? defaultValue : result;
11319 * Checks if `path` is a direct property of `object`.
11324 * @param {Object} object The object to query.
11325 * @param {Array|string} path The path to check.
11326 * @returns {boolean} Returns `true` if `path` exists, else `false`.
11329 * var object = { 'a': { 'b': { 'c': 3 } } };
11330 * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
11332 * _.has(object, 'a');
11335 * _.has(object, 'a.b.c');
11338 * _.has(object, ['a', 'b', 'c']);
11341 * _.has(other, 'a');
11344 function has(object, path) {
11345 return hasPath(object, path, baseHas);
11349 * Checks if `path` is a direct or inherited property of `object`.
11354 * @param {Object} object The object to query.
11355 * @param {Array|string} path The path to check.
11356 * @returns {boolean} Returns `true` if `path` exists, else `false`.
11359 * var object = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
11361 * _.hasIn(object, 'a');
11364 * _.hasIn(object, 'a.b.c');
11367 * _.hasIn(object, ['a', 'b', 'c']);
11370 * _.hasIn(object, 'b');
11373 function hasIn(object, path) {
11374 return hasPath(object, path, baseHasIn);
11378 * Creates an object composed of the inverted keys and values of `object`.
11379 * If `object` contains duplicate values, subsequent values overwrite property
11380 * assignments of previous values.
11385 * @param {Object} object The object to invert.
11386 * @returns {Object} Returns the new inverted object.
11389 * var object = { 'a': 1, 'b': 2, 'c': 1 };
11391 * _.invert(object);
11392 * // => { '1': 'c', '2': 'b' }
11394 var invert = createInverter(function(result, value, key) {
11395 result[value] = key;
11396 }, constant(identity));
11399 * This method is like `_.invert` except that the inverted object is generated
11400 * from the results of running each element of `object` through `iteratee`.
11401 * The corresponding inverted value of each inverted key is an array of keys
11402 * responsible for generating the inverted value. The iteratee is invoked
11403 * with one argument: (value).
11408 * @param {Object} object The object to invert.
11409 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
11410 * @returns {Object} Returns the new inverted object.
11413 * var object = { 'a': 1, 'b': 2, 'c': 1 };
11415 * _.invertBy(object);
11416 * // => { '1': ['a', 'c'], '2': ['b'] }
11418 * _.invertBy(object, function(value) {
11419 * return 'group' + value;
11421 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
11423 var invertBy = createInverter(function(result, value, key) {
11424 if (hasOwnProperty.call(result, value)) {
11425 result[value].push(key);
11427 result[value] = [key];
11432 * Invokes the method at `path` of `object`.
11437 * @param {Object} object The object to query.
11438 * @param {Array|string} path The path of the method to invoke.
11439 * @param {...*} [args] The arguments to invoke the method with.
11440 * @returns {*} Returns the result of the invoked method.
11443 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
11445 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
11448 var invoke = rest(baseInvoke);
11451 * Creates an array of the own enumerable property names of `object`.
11453 * **Note:** Non-object values are coerced to objects. See the
11454 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
11455 * for more details.
11460 * @param {Object} object The object to query.
11461 * @returns {Array} Returns the array of property names.
11469 * Foo.prototype.c = 3;
11472 * // => ['a', 'b'] (iteration order is not guaranteed)
11477 function keys(object) {
11478 var isProto = isPrototype(object);
11479 if (!(isProto || isArrayLike(object))) {
11480 return baseKeys(object);
11482 var indexes = indexKeys(object),
11483 skipIndexes = !!indexes,
11484 result = indexes || [],
11485 length = result.length;
11487 for (var key in object) {
11488 if (baseHas(object, key) &&
11489 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
11490 !(isProto && key == 'constructor')) {
11498 * Creates an array of the own and inherited enumerable property names of `object`.
11500 * **Note:** Non-object values are coerced to objects.
11505 * @param {Object} object The object to query.
11506 * @returns {Array} Returns the array of property names.
11514 * Foo.prototype.c = 3;
11516 * _.keysIn(new Foo);
11517 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
11519 function keysIn(object) {
11521 isProto = isPrototype(object),
11522 props = baseKeysIn(object),
11523 propsLength = props.length,
11524 indexes = indexKeys(object),
11525 skipIndexes = !!indexes,
11526 result = indexes || [],
11527 length = result.length;
11529 while (++index < propsLength) {
11530 var key = props[index];
11531 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
11532 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
11540 * The opposite of `_.mapValues`; this method creates an object with the
11541 * same values as `object` and keys generated by running each own enumerable
11542 * property of `object` through `iteratee`. The iteratee is invoked with
11543 * three arguments: (value, key, object).
11548 * @param {Object} object The object to iterate over.
11549 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
11550 * @returns {Object} Returns the new mapped object.
11553 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
11554 * return key + value;
11556 * // => { 'a1': 1, 'b2': 2 }
11558 function mapKeys(object, iteratee) {
11560 iteratee = getIteratee(iteratee, 3);
11562 baseForOwn(object, function(value, key, object) {
11563 result[iteratee(value, key, object)] = value;
11569 * Creates an object with the same keys as `object` and values generated by
11570 * running each own enumerable property of `object` through `iteratee`. The
11571 * iteratee is invoked with three arguments: (value, key, object).
11576 * @param {Object} object The object to iterate over.
11577 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
11578 * @returns {Object} Returns the new mapped object.
11582 * 'fred': { 'user': 'fred', 'age': 40 },
11583 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
11586 * _.mapValues(users, function(o) { return o.age; });
11587 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
11589 * // The `_.property` iteratee shorthand.
11590 * _.mapValues(users, 'age');
11591 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
11593 function mapValues(object, iteratee) {
11595 iteratee = getIteratee(iteratee, 3);
11597 baseForOwn(object, function(value, key, object) {
11598 result[key] = iteratee(value, key, object);
11604 * Recursively merges own and inherited enumerable properties of source objects
11605 * into the destination object. Source properties that resolve to `undefined`
11606 * are skipped if a destination value exists. Array and plain object properties
11607 * are merged recursively. Other objects and value types are overridden by
11608 * assignment. Source objects are applied from left to right. Subsequent
11609 * sources overwrite property assignments of previous sources.
11611 * **Note:** This method mutates `object`.
11616 * @param {Object} object The destination object.
11617 * @param {...Object} [sources] The source objects.
11618 * @returns {Object} Returns `object`.
11622 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
11626 * 'data': [{ 'age': 36 }, { 'age': 40 }]
11629 * _.merge(users, ages);
11630 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
11632 var merge = createAssigner(function(object, source, srcIndex) {
11633 baseMerge(object, source, srcIndex);
11637 * This method is like `_.merge` except that it accepts `customizer` which
11638 * is invoked to produce the merged values of the destination and source
11639 * properties. If `customizer` returns `undefined` merging is handled by the
11640 * method instead. The `customizer` is invoked with seven arguments:
11641 * (objValue, srcValue, key, object, source, stack).
11643 * **Note:** This method mutates `object`.
11648 * @param {Object} object The destination object.
11649 * @param {...Object} sources The source objects.
11650 * @param {Function} customizer The function to customize assigned values.
11651 * @returns {Object} Returns `object`.
11654 * function customizer(objValue, srcValue) {
11655 * if (_.isArray(objValue)) {
11656 * return objValue.concat(srcValue);
11661 * 'fruits': ['apple'],
11662 * 'vegetables': ['beet']
11666 * 'fruits': ['banana'],
11667 * 'vegetables': ['carrot']
11670 * _.mergeWith(object, other, customizer);
11671 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
11673 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
11674 baseMerge(object, source, srcIndex, customizer);
11678 * The opposite of `_.pick`; this method creates an object composed of the
11679 * own and inherited enumerable properties of `object` that are not omitted.
11684 * @param {Object} object The source object.
11685 * @param {...(string|string[])} [props] The property names to omit, specified
11686 * individually or in arrays.
11687 * @returns {Object} Returns the new object.
11690 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11692 * _.omit(object, ['a', 'c']);
11693 * // => { 'b': '2' }
11695 var omit = rest(function(object, props) {
11696 if (object == null) {
11699 props = arrayMap(baseFlatten(props, 1), String);
11700 return basePick(object, baseDifference(keysIn(object), props));
11704 * The opposite of `_.pickBy`; this method creates an object composed of
11705 * the own and inherited enumerable properties of `object` that `predicate`
11706 * doesn't return truthy for. The predicate is invoked with two arguments:
11712 * @param {Object} object The source object.
11713 * @param {Function|Object|string} [predicate=_.identity] The function invoked per property.
11714 * @returns {Object} Returns the new object.
11717 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11719 * _.omitBy(object, _.isNumber);
11720 * // => { 'b': '2' }
11722 function omitBy(object, predicate) {
11723 predicate = getIteratee(predicate);
11724 return basePickBy(object, function(value, key) {
11725 return !predicate(value, key);
11730 * Creates an object composed of the picked `object` properties.
11735 * @param {Object} object The source object.
11736 * @param {...(string|string[])} [props] The property names to pick, specified
11737 * individually or in arrays.
11738 * @returns {Object} Returns the new object.
11741 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11743 * _.pick(object, ['a', 'c']);
11744 * // => { 'a': 1, 'c': 3 }
11746 var pick = rest(function(object, props) {
11747 return object == null ? {} : basePick(object, baseFlatten(props, 1));
11751 * Creates an object composed of the `object` properties `predicate` returns
11752 * truthy for. The predicate is invoked with two arguments: (value, key).
11757 * @param {Object} object The source object.
11758 * @param {Function|Object|string} [predicate=_.identity] The function invoked per property.
11759 * @returns {Object} Returns the new object.
11762 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11764 * _.pickBy(object, _.isNumber);
11765 * // => { 'a': 1, 'c': 3 }
11767 function pickBy(object, predicate) {
11768 return object == null ? {} : basePickBy(object, getIteratee(predicate));
11772 * This method is like `_.get` except that if the resolved value is a function
11773 * it's invoked with the `this` binding of its parent object and its result
11779 * @param {Object} object The object to query.
11780 * @param {Array|string} path The path of the property to resolve.
11781 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
11782 * @returns {*} Returns the resolved value.
11785 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
11787 * _.result(object, 'a[0].b.c1');
11790 * _.result(object, 'a[0].b.c2');
11793 * _.result(object, 'a[0].b.c3', 'default');
11796 * _.result(object, 'a[0].b.c3', _.constant('default'));
11799 function result(object, path, defaultValue) {
11800 if (!isKey(path, object)) {
11801 path = baseCastPath(path);
11802 var result = get(object, path);
11803 object = parent(object, path);
11805 result = object == null ? undefined : object[path];
11807 if (result === undefined) {
11808 result = defaultValue;
11810 return isFunction(result) ? result.call(object) : result;
11814 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist
11815 * it's created. Arrays are created for missing index properties while objects
11816 * are created for all other missing properties. Use `_.setWith` to customize
11819 * **Note:** This method mutates `object`.
11824 * @param {Object} object The object to modify.
11825 * @param {Array|string} path The path of the property to set.
11826 * @param {*} value The value to set.
11827 * @returns {Object} Returns `object`.
11830 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
11832 * _.set(object, 'a[0].b.c', 4);
11833 * console.log(object.a[0].b.c);
11836 * _.set(object, 'x[0].y.z', 5);
11837 * console.log(object.x[0].y.z);
11840 function set(object, path, value) {
11841 return object == null ? object : baseSet(object, path, value);
11845 * This method is like `_.set` except that it accepts `customizer` which is
11846 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
11847 * path creation is handled by the method instead. The `customizer` is invoked
11848 * with three arguments: (nsValue, key, nsObject).
11850 * **Note:** This method mutates `object`.
11855 * @param {Object} object The object to modify.
11856 * @param {Array|string} path The path of the property to set.
11857 * @param {*} value The value to set.
11858 * @param {Function} [customizer] The function to customize assigned values.
11859 * @returns {Object} Returns `object`.
11862 * _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, Object);
11863 * // => { '0': { '1': { '2': 3 }, 'length': 2 } }
11865 function setWith(object, path, value, customizer) {
11866 customizer = typeof customizer == 'function' ? customizer : undefined;
11867 return object == null ? object : baseSet(object, path, value, customizer);
11871 * Creates an array of own enumerable key-value pairs for `object` which
11872 * can be consumed by `_.fromPairs`.
11877 * @param {Object} object The object to query.
11878 * @returns {Array} Returns the new array of key-value pairs.
11886 * Foo.prototype.c = 3;
11888 * _.toPairs(new Foo);
11889 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
11891 function toPairs(object) {
11892 return baseToPairs(object, keys(object));
11896 * Creates an array of own and inherited enumerable key-value pairs for
11897 * `object` which can be consumed by `_.fromPairs`.
11902 * @param {Object} object The object to query.
11903 * @returns {Array} Returns the new array of key-value pairs.
11911 * Foo.prototype.c = 3;
11913 * _.toPairsIn(new Foo);
11914 * // => [['a', 1], ['b', 2], ['c', 1]] (iteration order is not guaranteed)
11916 function toPairsIn(object) {
11917 return baseToPairs(object, keysIn(object));
11921 * An alternative to `_.reduce`; this method transforms `object` to a new
11922 * `accumulator` object which is the result of running each of its own enumerable
11923 * properties through `iteratee`, with each invocation potentially mutating
11924 * the `accumulator` object. The iteratee is invoked with four arguments:
11925 * (accumulator, value, key, object). Iteratee functions may exit iteration
11926 * early by explicitly returning `false`.
11931 * @param {Array|Object} object The object to iterate over.
11932 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11933 * @param {*} [accumulator] The custom accumulator value.
11934 * @returns {*} Returns the accumulated value.
11937 * _.transform([2, 3, 4], function(result, n) {
11938 * result.push(n *= n);
11939 * return n % 2 == 0;
11943 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
11944 * (result[value] || (result[value] = [])).push(key);
11946 * // => { '1': ['a', 'c'], '2': ['b'] }
11948 function transform(object, iteratee, accumulator) {
11949 var isArr = isArray(object) || isTypedArray(object);
11950 iteratee = getIteratee(iteratee, 4);
11952 if (accumulator == null) {
11953 if (isArr || isObject(object)) {
11954 var Ctor = object.constructor;
11956 accumulator = isArray(object) ? new Ctor : [];
11958 accumulator = isFunction(Ctor) ? baseCreate(getPrototypeOf(object)) : {};
11964 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
11965 return iteratee(accumulator, value, index, object);
11967 return accumulator;
11971 * Removes the property at `path` of `object`.
11973 * **Note:** This method mutates `object`.
11978 * @param {Object} object The object to modify.
11979 * @param {Array|string} path The path of the property to unset.
11980 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
11983 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
11984 * _.unset(object, 'a[0].b.c');
11987 * console.log(object);
11988 * // => { 'a': [{ 'b': {} }] };
11990 * _.unset(object, 'a[0].b.c');
11993 * console.log(object);
11994 * // => { 'a': [{ 'b': {} }] };
11996 function unset(object, path) {
11997 return object == null ? true : baseUnset(object, path);
12001 * Creates an array of the own enumerable property values of `object`.
12003 * **Note:** Non-object values are coerced to objects.
12008 * @param {Object} object The object to query.
12009 * @returns {Array} Returns the array of property values.
12017 * Foo.prototype.c = 3;
12019 * _.values(new Foo);
12020 * // => [1, 2] (iteration order is not guaranteed)
12025 function values(object) {
12026 return object ? baseValues(object, keys(object)) : [];
12030 * Creates an array of the own and inherited enumerable property values of `object`.
12032 * **Note:** Non-object values are coerced to objects.
12037 * @param {Object} object The object to query.
12038 * @returns {Array} Returns the array of property values.
12046 * Foo.prototype.c = 3;
12048 * _.valuesIn(new Foo);
12049 * // => [1, 2, 3] (iteration order is not guaranteed)
12051 function valuesIn(object) {
12052 return object == null ? [] : baseValues(object, keysIn(object));
12055 /*------------------------------------------------------------------------*/
12058 * Clamps `number` within the inclusive `lower` and `upper` bounds.
12063 * @param {number} number The number to clamp.
12064 * @param {number} [lower] The lower bound.
12065 * @param {number} upper The upper bound.
12066 * @returns {number} Returns the clamped number.
12069 * _.clamp(-10, -5, 5);
12072 * _.clamp(10, -5, 5);
12075 function clamp(number, lower, upper) {
12076 if (upper === undefined) {
12080 if (upper !== undefined) {
12081 upper = toNumber(upper);
12082 upper = upper === upper ? upper : 0;
12084 if (lower !== undefined) {
12085 lower = toNumber(lower);
12086 lower = lower === lower ? lower : 0;
12088 return baseClamp(toNumber(number), lower, upper);
12092 * Checks if `n` is between `start` and up to but not including, `end`. If
12093 * `end` is not specified it's set to `start` with `start` then set to `0`.
12094 * If `start` is greater than `end` the params are swapped to support
12100 * @param {number} number The number to check.
12101 * @param {number} [start=0] The start of the range.
12102 * @param {number} end The end of the range.
12103 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
12106 * _.inRange(3, 2, 4);
12118 * _.inRange(1.2, 2);
12121 * _.inRange(5.2, 4);
12124 * _.inRange(-3, -2, -6);
12127 function inRange(number, start, end) {
12128 start = toNumber(start) || 0;
12129 if (end === undefined) {
12133 end = toNumber(end) || 0;
12135 number = toNumber(number);
12136 return baseInRange(number, start, end);
12140 * Produces a random number between the inclusive `lower` and `upper` bounds.
12141 * If only one argument is provided a number between `0` and the given number
12142 * is returned. If `floating` is `true`, or either `lower` or `upper` are floats,
12143 * a floating-point number is returned instead of an integer.
12145 * **Note:** JavaScript follows the IEEE-754 standard for resolving
12146 * floating-point values which can produce unexpected results.
12151 * @param {number} [lower=0] The lower bound.
12152 * @param {number} [upper=1] The upper bound.
12153 * @param {boolean} [floating] Specify returning a floating-point number.
12154 * @returns {number} Returns the random number.
12158 * // => an integer between 0 and 5
12161 * // => also an integer between 0 and 5
12163 * _.random(5, true);
12164 * // => a floating-point number between 0 and 5
12166 * _.random(1.2, 5.2);
12167 * // => a floating-point number between 1.2 and 5.2
12169 function random(lower, upper, floating) {
12170 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
12171 upper = floating = undefined;
12173 if (floating === undefined) {
12174 if (typeof upper == 'boolean') {
12178 else if (typeof lower == 'boolean') {
12183 if (lower === undefined && upper === undefined) {
12188 lower = toNumber(lower) || 0;
12189 if (upper === undefined) {
12193 upper = toNumber(upper) || 0;
12196 if (lower > upper) {
12201 if (floating || lower % 1 || upper % 1) {
12202 var rand = nativeRandom();
12203 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
12205 return baseRandom(lower, upper);
12208 /*------------------------------------------------------------------------*/
12211 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
12216 * @param {string} [string=''] The string to convert.
12217 * @returns {string} Returns the camel cased string.
12220 * _.camelCase('Foo Bar');
12223 * _.camelCase('--foo-bar');
12226 * _.camelCase('__foo_bar__');
12229 var camelCase = createCompounder(function(result, word, index) {
12230 word = word.toLowerCase();
12231 return result + (index ? capitalize(word) : word);
12235 * Converts the first character of `string` to upper case and the remaining
12241 * @param {string} [string=''] The string to capitalize.
12242 * @returns {string} Returns the capitalized string.
12245 * _.capitalize('FRED');
12248 function capitalize(string) {
12249 return upperFirst(toString(string).toLowerCase());
12253 * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
12254 * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
12259 * @param {string} [string=''] The string to deburr.
12260 * @returns {string} Returns the deburred string.
12263 * _.deburr('déjà vu');
12266 function deburr(string) {
12267 string = toString(string);
12268 return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
12272 * Checks if `string` ends with the given target string.
12277 * @param {string} [string=''] The string to search.
12278 * @param {string} [target] The string to search for.
12279 * @param {number} [position=string.length] The position to search from.
12280 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
12283 * _.endsWith('abc', 'c');
12286 * _.endsWith('abc', 'b');
12289 * _.endsWith('abc', 'b', 2);
12292 function endsWith(string, target, position) {
12293 string = toString(string);
12294 target = typeof target == 'string' ? target : (target + '');
12296 var length = string.length;
12297 position = position === undefined
12299 : baseClamp(toInteger(position), 0, length);
12301 position -= target.length;
12302 return position >= 0 && string.indexOf(target, position) == position;
12306 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
12307 * their corresponding HTML entities.
12309 * **Note:** No other characters are escaped. To escape additional
12310 * characters use a third-party library like [_he_](https://mths.be/he).
12312 * Though the ">" character is escaped for symmetry, characters like
12313 * ">" and "/" don't need escaping in HTML and have no special meaning
12314 * unless they're part of a tag or unquoted attribute value.
12315 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
12316 * (under "semi-related fun fact") for more details.
12318 * Backticks are escaped because in IE < 9, they can break out of
12319 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
12320 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
12321 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
12322 * for more details.
12324 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
12325 * to reduce XSS vectors.
12330 * @param {string} [string=''] The string to escape.
12331 * @returns {string} Returns the escaped string.
12334 * _.escape('fred, barney, & pebbles');
12335 * // => 'fred, barney, & pebbles'
12337 function escape(string) {
12338 string = toString(string);
12339 return (string && reHasUnescapedHtml.test(string))
12340 ? string.replace(reUnescapedHtml, escapeHtmlChar)
12345 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
12346 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
12351 * @param {string} [string=''] The string to escape.
12352 * @returns {string} Returns the escaped string.
12355 * _.escapeRegExp('[lodash](https://lodash.com/)');
12356 * // => '\[lodash\]\(https://lodash\.com/\)'
12358 function escapeRegExp(string) {
12359 string = toString(string);
12360 return (string && reHasRegExpChar.test(string))
12361 ? string.replace(reRegExpChar, '\\$&')
12366 * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
12371 * @param {string} [string=''] The string to convert.
12372 * @returns {string} Returns the kebab cased string.
12375 * _.kebabCase('Foo Bar');
12378 * _.kebabCase('fooBar');
12381 * _.kebabCase('__foo_bar__');
12384 var kebabCase = createCompounder(function(result, word, index) {
12385 return result + (index ? '-' : '') + word.toLowerCase();
12389 * Converts `string`, as space separated words, to lower case.
12394 * @param {string} [string=''] The string to convert.
12395 * @returns {string} Returns the lower cased string.
12398 * _.lowerCase('--Foo-Bar');
12401 * _.lowerCase('fooBar');
12404 * _.lowerCase('__FOO_BAR__');
12407 var lowerCase = createCompounder(function(result, word, index) {
12408 return result + (index ? ' ' : '') + word.toLowerCase();
12412 * Converts the first character of `string` to lower case.
12417 * @param {string} [string=''] The string to convert.
12418 * @returns {string} Returns the converted string.
12421 * _.lowerFirst('Fred');
12424 * _.lowerFirst('FRED');
12427 var lowerFirst = createCaseFirst('toLowerCase');
12430 * Converts the first character of `string` to upper case.
12435 * @param {string} [string=''] The string to convert.
12436 * @returns {string} Returns the converted string.
12439 * _.upperFirst('fred');
12442 * _.upperFirst('FRED');
12445 var upperFirst = createCaseFirst('toUpperCase');
12448 * Pads `string` on the left and right sides if it's shorter than `length`.
12449 * Padding characters are truncated if they can't be evenly divided by `length`.
12454 * @param {string} [string=''] The string to pad.
12455 * @param {number} [length=0] The padding length.
12456 * @param {string} [chars=' '] The string used as padding.
12457 * @returns {string} Returns the padded string.
12463 * _.pad('abc', 8, '_-');
12469 function pad(string, length, chars) {
12470 string = toString(string);
12471 length = toInteger(length);
12473 var strLength = stringSize(string);
12474 if (!length || strLength >= length) {
12477 var mid = (length - strLength) / 2,
12478 leftLength = nativeFloor(mid),
12479 rightLength = nativeCeil(mid);
12481 return createPadding('', leftLength, chars) + string + createPadding('', rightLength, chars);
12485 * Pads `string` on the right side if it's shorter than `length`. Padding
12486 * characters are truncated if they exceed `length`.
12491 * @param {string} [string=''] The string to pad.
12492 * @param {number} [length=0] The padding length.
12493 * @param {string} [chars=' '] The string used as padding.
12494 * @returns {string} Returns the padded string.
12497 * _.padEnd('abc', 6);
12500 * _.padEnd('abc', 6, '_-');
12503 * _.padEnd('abc', 3);
12506 function padEnd(string, length, chars) {
12507 string = toString(string);
12508 return string + createPadding(string, length, chars);
12512 * Pads `string` on the left side if it's shorter than `length`. Padding
12513 * characters are truncated if they exceed `length`.
12518 * @param {string} [string=''] The string to pad.
12519 * @param {number} [length=0] The padding length.
12520 * @param {string} [chars=' '] The string used as padding.
12521 * @returns {string} Returns the padded string.
12524 * _.padStart('abc', 6);
12527 * _.padStart('abc', 6, '_-');
12530 * _.padStart('abc', 3);
12533 function padStart(string, length, chars) {
12534 string = toString(string);
12535 return createPadding(string, length, chars) + string;
12539 * Converts `string` to an integer of the specified radix. If `radix` is
12540 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
12541 * in which case a `radix` of `16` is used.
12543 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#x15.1.2.2)
12549 * @param {string} string The string to convert.
12550 * @param {number} [radix=10] The radix to interpret `value` by.
12551 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12552 * @returns {number} Returns the converted integer.
12555 * _.parseInt('08');
12558 * _.map(['6', '08', '10'], _.parseInt);
12561 function parseInt(string, radix, guard) {
12562 // Chrome fails to trim leading <BOM> whitespace characters.
12563 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
12564 if (guard || radix == null) {
12566 } else if (radix) {
12569 string = toString(string).replace(reTrim, '');
12570 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
12574 * Repeats the given string `n` times.
12579 * @param {string} [string=''] The string to repeat.
12580 * @param {number} [n=0] The number of times to repeat the string.
12581 * @returns {string} Returns the repeated string.
12584 * _.repeat('*', 3);
12587 * _.repeat('abc', 2);
12590 * _.repeat('abc', 0);
12593 function repeat(string, n) {
12594 string = toString(string);
12598 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
12601 // Leverage the exponentiation by squaring algorithm for a faster repeat.
12602 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
12607 n = nativeFloor(n / 2);
12615 * Replaces matches for `pattern` in `string` with `replacement`.
12617 * **Note:** This method is based on [`String#replace`](https://mdn.io/String/replace).
12622 * @param {string} [string=''] The string to modify.
12623 * @param {RegExp|string} pattern The pattern to replace.
12624 * @param {Function|string} replacement The match replacement.
12625 * @returns {string} Returns the modified string.
12628 * _.replace('Hi Fred', 'Fred', 'Barney');
12629 * // => 'Hi Barney'
12631 function replace() {
12632 var args = arguments,
12633 string = toString(args[0]);
12635 return args.length < 3 ? string : string.replace(args[1], args[2]);
12639 * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
12644 * @param {string} [string=''] The string to convert.
12645 * @returns {string} Returns the snake cased string.
12648 * _.snakeCase('Foo Bar');
12651 * _.snakeCase('fooBar');
12654 * _.snakeCase('--foo-bar');
12657 var snakeCase = createCompounder(function(result, word, index) {
12658 return result + (index ? '_' : '') + word.toLowerCase();
12662 * Splits `string` by `separator`.
12664 * **Note:** This method is based on [`String#split`](https://mdn.io/String/split).
12669 * @param {string} [string=''] The string to split.
12670 * @param {RegExp|string} separator The separator pattern to split by.
12671 * @param {number} [limit] The length to truncate results to.
12672 * @returns {Array} Returns the new array of string segments.
12675 * _.split('a-b-c', '-', 2);
12678 function split(string, separator, limit) {
12679 return toString(string).split(separator, limit);
12683 * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
12688 * @param {string} [string=''] The string to convert.
12689 * @returns {string} Returns the start cased string.
12692 * _.startCase('--foo-bar');
12695 * _.startCase('fooBar');
12698 * _.startCase('__foo_bar__');
12701 var startCase = createCompounder(function(result, word, index) {
12702 return result + (index ? ' ' : '') + capitalize(word);
12706 * Checks if `string` starts with the given target string.
12711 * @param {string} [string=''] The string to search.
12712 * @param {string} [target] The string to search for.
12713 * @param {number} [position=0] The position to search from.
12714 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
12717 * _.startsWith('abc', 'a');
12720 * _.startsWith('abc', 'b');
12723 * _.startsWith('abc', 'b', 1);
12726 function startsWith(string, target, position) {
12727 string = toString(string);
12728 position = baseClamp(toInteger(position), 0, string.length);
12729 return string.lastIndexOf(target, position) == position;
12733 * Creates a compiled template function that can interpolate data properties
12734 * in "interpolate" delimiters, HTML-escape interpolated data properties in
12735 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
12736 * properties may be accessed as free variables in the template. If a setting
12737 * object is given it takes precedence over `_.templateSettings` values.
12739 * **Note:** In the development build `_.template` utilizes
12740 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
12741 * for easier debugging.
12743 * For more information on precompiling templates see
12744 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
12746 * For more information on Chrome extension sandboxes see
12747 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
12752 * @param {string} [string=''] The template string.
12753 * @param {Object} [options] The options object.
12754 * @param {RegExp} [options.escape] The HTML "escape" delimiter.
12755 * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
12756 * @param {Object} [options.imports] An object to import into the template as free variables.
12757 * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
12758 * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
12759 * @param {string} [options.variable] The data object variable name.
12760 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12761 * @returns {Function} Returns the compiled template function.
12764 * // Use the "interpolate" delimiter to create a compiled template.
12765 * var compiled = _.template('hello <%= user %>!');
12766 * compiled({ 'user': 'fred' });
12767 * // => 'hello fred!'
12769 * // Use the HTML "escape" delimiter to escape data property values.
12770 * var compiled = _.template('<b><%- value %></b>');
12771 * compiled({ 'value': '<script>' });
12772 * // => '<b><script></b>'
12774 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
12775 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
12776 * compiled({ 'users': ['fred', 'barney'] });
12777 * // => '<li>fred</li><li>barney</li>'
12779 * // Use the internal `print` function in "evaluate" delimiters.
12780 * var compiled = _.template('<% print("hello " + user); %>!');
12781 * compiled({ 'user': 'barney' });
12782 * // => 'hello barney!'
12784 * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
12785 * var compiled = _.template('hello ${ user }!');
12786 * compiled({ 'user': 'pebbles' });
12787 * // => 'hello pebbles!'
12789 * // Use custom template delimiters.
12790 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
12791 * var compiled = _.template('hello {{ user }}!');
12792 * compiled({ 'user': 'mustache' });
12793 * // => 'hello mustache!'
12795 * // Use backslashes to treat delimiters as plain text.
12796 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
12797 * compiled({ 'value': 'ignored' });
12798 * // => '<%- value %>'
12800 * // Use the `imports` option to import `jQuery` as `jq`.
12801 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
12802 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
12803 * compiled({ 'users': ['fred', 'barney'] });
12804 * // => '<li>fred</li><li>barney</li>'
12806 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
12807 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
12809 * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
12811 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
12812 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
12814 * // => function(data) {
12815 * // var __t, __p = '';
12816 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
12820 * // Use the `source` property to inline compiled templates for meaningful
12821 * // line numbers in error messages and stack traces.
12822 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
12824 * "main": ' + _.template(mainText).source + '\
12828 function template(string, options, guard) {
12829 // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
12830 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
12831 var settings = lodash.templateSettings;
12833 if (guard && isIterateeCall(string, options, guard)) {
12834 options = undefined;
12836 string = toString(string);
12837 options = assignInWith({}, options, settings, assignInDefaults);
12839 var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
12840 importsKeys = keys(imports),
12841 importsValues = baseValues(imports, importsKeys);
12846 interpolate = options.interpolate || reNoMatch,
12847 source = "__p += '";
12849 // Compile the regexp to match each delimiter.
12850 var reDelimiters = RegExp(
12851 (options.escape || reNoMatch).source + '|' +
12852 interpolate.source + '|' +
12853 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
12854 (options.evaluate || reNoMatch).source + '|$'
12857 // Use a sourceURL for easier debugging.
12858 var sourceURL = '//# sourceURL=' +
12859 ('sourceURL' in options
12860 ? options.sourceURL
12861 : ('lodash.templateSources[' + (++templateCounter) + ']')
12864 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
12865 interpolateValue || (interpolateValue = esTemplateValue);
12867 // Escape characters that can't be included in string literals.
12868 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
12870 // Replace delimiters with snippets.
12873 source += "' +\n__e(" + escapeValue + ") +\n'";
12875 if (evaluateValue) {
12876 isEvaluating = true;
12877 source += "';\n" + evaluateValue + ";\n__p += '";
12879 if (interpolateValue) {
12880 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
12882 index = offset + match.length;
12884 // The JS engine embedded in Adobe products needs `match` returned in
12885 // order to produce the correct `offset` value.
12891 // If `variable` is not specified wrap a with-statement around the generated
12892 // code to add the data object to the top of the scope chain.
12893 var variable = options.variable;
12895 source = 'with (obj) {\n' + source + '\n}\n';
12897 // Cleanup code by stripping empty strings.
12898 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
12899 .replace(reEmptyStringMiddle, '$1')
12900 .replace(reEmptyStringTrailing, '$1;');
12902 // Frame code as the function body.
12903 source = 'function(' + (variable || 'obj') + ') {\n' +
12906 : 'obj || (obj = {});\n'
12908 "var __t, __p = ''" +
12910 ? ', __e = _.escape'
12914 ? ', __j = Array.prototype.join;\n' +
12915 "function print() { __p += __j.call(arguments, '') }\n"
12921 var result = attempt(function() {
12922 return Function(importsKeys, sourceURL + 'return ' + source)
12923 .apply(undefined, importsValues);
12926 // Provide the compiled function's source by its `toString` method or
12927 // the `source` property as a convenience for inlining compiled templates.
12928 result.source = source;
12929 if (isError(result)) {
12936 * Converts `string`, as a whole, to lower case.
12941 * @param {string} [string=''] The string to convert.
12942 * @returns {string} Returns the lower cased string.
12945 * _.toLower('--Foo-Bar');
12946 * // => '--foo-bar'
12948 * _.toLower('fooBar');
12951 * _.toLower('__FOO_BAR__');
12952 * // => '__foo_bar__'
12954 function toLower(value) {
12955 return toString(value).toLowerCase();
12959 * Converts `string`, as a whole, to upper case.
12964 * @param {string} [string=''] The string to convert.
12965 * @returns {string} Returns the upper cased string.
12968 * _.toUpper('--foo-bar');
12969 * // => '--FOO-BAR'
12971 * _.toUpper('fooBar');
12974 * _.toUpper('__foo_bar__');
12975 * // => '__FOO_BAR__'
12977 function toUpper(value) {
12978 return toString(value).toUpperCase();
12982 * Removes leading and trailing whitespace or specified characters from `string`.
12987 * @param {string} [string=''] The string to trim.
12988 * @param {string} [chars=whitespace] The characters to trim.
12989 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12990 * @returns {string} Returns the trimmed string.
12996 * _.trim('-_-abc-_-', '_-');
12999 * _.map([' foo ', ' bar '], _.trim);
13000 * // => ['foo', 'bar']
13002 function trim(string, chars, guard) {
13003 string = toString(string);
13007 if (guard || chars === undefined) {
13008 return string.replace(reTrim, '');
13010 chars = (chars + '');
13014 var strSymbols = stringToArray(string),
13015 chrSymbols = stringToArray(chars);
13018 .slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1)
13023 * Removes trailing whitespace or specified characters from `string`.
13028 * @param {string} [string=''] The string to trim.
13029 * @param {string} [chars=whitespace] The characters to trim.
13030 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
13031 * @returns {string} Returns the trimmed string.
13034 * _.trimEnd(' abc ');
13037 * _.trimEnd('-_-abc-_-', '_-');
13040 function trimEnd(string, chars, guard) {
13041 string = toString(string);
13045 if (guard || chars === undefined) {
13046 return string.replace(reTrimEnd, '');
13048 chars = (chars + '');
13052 var strSymbols = stringToArray(string);
13054 .slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1)
13059 * Removes leading whitespace or specified characters from `string`.
13064 * @param {string} [string=''] The string to trim.
13065 * @param {string} [chars=whitespace] The characters to trim.
13066 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
13067 * @returns {string} Returns the trimmed string.
13070 * _.trimStart(' abc ');
13073 * _.trimStart('-_-abc-_-', '_-');
13076 function trimStart(string, chars, guard) {
13077 string = toString(string);
13081 if (guard || chars === undefined) {
13082 return string.replace(reTrimStart, '');
13084 chars = (chars + '');
13088 var strSymbols = stringToArray(string);
13090 .slice(charsStartIndex(strSymbols, stringToArray(chars)))
13095 * Truncates `string` if it's longer than the given maximum string length.
13096 * The last characters of the truncated string are replaced with the omission
13097 * string which defaults to "...".
13102 * @param {string} [string=''] The string to truncate.
13103 * @param {Object} [options=({})] The options object.
13104 * @param {number} [options.length=30] The maximum string length.
13105 * @param {string} [options.omission='...'] The string to indicate text is omitted.
13106 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
13107 * @returns {string} Returns the truncated string.
13110 * _.truncate('hi-diddly-ho there, neighborino');
13111 * // => 'hi-diddly-ho there, neighbo...'
13113 * _.truncate('hi-diddly-ho there, neighborino', {
13117 * // => 'hi-diddly-ho there,...'
13119 * _.truncate('hi-diddly-ho there, neighborino', {
13121 * 'separator': /,? +/
13123 * // => 'hi-diddly-ho there...'
13125 * _.truncate('hi-diddly-ho there, neighborino', {
13126 * 'omission': ' [...]'
13128 * // => 'hi-diddly-ho there, neig [...]'
13130 function truncate(string, options) {
13131 var length = DEFAULT_TRUNC_LENGTH,
13132 omission = DEFAULT_TRUNC_OMISSION;
13134 if (isObject(options)) {
13135 var separator = 'separator' in options ? options.separator : separator;
13136 length = 'length' in options ? toInteger(options.length) : length;
13137 omission = 'omission' in options ? toString(options.omission) : omission;
13139 string = toString(string);
13141 var strLength = string.length;
13142 if (reHasComplexSymbol.test(string)) {
13143 var strSymbols = stringToArray(string);
13144 strLength = strSymbols.length;
13146 if (length >= strLength) {
13149 var end = length - stringSize(omission);
13153 var result = strSymbols
13154 ? strSymbols.slice(0, end).join('')
13155 : string.slice(0, end);
13157 if (separator === undefined) {
13158 return result + omission;
13161 end += (result.length - end);
13163 if (isRegExp(separator)) {
13164 if (string.slice(end).search(separator)) {
13166 substring = result;
13168 if (!separator.global) {
13169 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
13171 separator.lastIndex = 0;
13172 while ((match = separator.exec(substring))) {
13173 var newEnd = match.index;
13175 result = result.slice(0, newEnd === undefined ? end : newEnd);
13177 } else if (string.indexOf(separator, end) != end) {
13178 var index = result.lastIndexOf(separator);
13180 result = result.slice(0, index);
13183 return result + omission;
13187 * The inverse of `_.escape`; this method converts the HTML entities
13188 * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
13189 * corresponding characters.
13191 * **Note:** No other HTML entities are unescaped. To unescape additional HTML
13192 * entities use a third-party library like [_he_](https://mths.be/he).
13197 * @param {string} [string=''] The string to unescape.
13198 * @returns {string} Returns the unescaped string.
13201 * _.unescape('fred, barney, & pebbles');
13202 * // => 'fred, barney, & pebbles'
13204 function unescape(string) {
13205 string = toString(string);
13206 return (string && reHasEscapedHtml.test(string))
13207 ? string.replace(reEscapedHtml, unescapeHtmlChar)
13212 * Converts `string`, as space separated words, to upper case.
13217 * @param {string} [string=''] The string to convert.
13218 * @returns {string} Returns the upper cased string.
13221 * _.upperCase('--foo-bar');
13224 * _.upperCase('fooBar');
13227 * _.upperCase('__foo_bar__');
13230 var upperCase = createCompounder(function(result, word, index) {
13231 return result + (index ? ' ' : '') + word.toUpperCase();
13235 * Splits `string` into an array of its words.
13240 * @param {string} [string=''] The string to inspect.
13241 * @param {RegExp|string} [pattern] The pattern to match words.
13242 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
13243 * @returns {Array} Returns the words of `string`.
13246 * _.words('fred, barney, & pebbles');
13247 * // => ['fred', 'barney', 'pebbles']
13249 * _.words('fred, barney, & pebbles', /[^, ]+/g);
13250 * // => ['fred', 'barney', '&', 'pebbles']
13252 function words(string, pattern, guard) {
13253 string = toString(string);
13254 pattern = guard ? undefined : pattern;
13256 if (pattern === undefined) {
13257 pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
13259 return string.match(pattern) || [];
13262 /*------------------------------------------------------------------------*/
13265 * Attempts to invoke `func`, returning either the result or the caught error
13266 * object. Any additional arguments are provided to `func` when it's invoked.
13271 * @param {Function} func The function to attempt.
13272 * @returns {*} Returns the `func` result or error object.
13275 * // Avoid throwing errors for invalid selectors.
13276 * var elements = _.attempt(function(selector) {
13277 * return document.querySelectorAll(selector);
13280 * if (_.isError(elements)) {
13284 var attempt = rest(function(func, args) {
13286 return apply(func, undefined, args);
13288 return isError(e) ? e : new Error(e);
13293 * Binds methods of an object to the object itself, overwriting the existing
13296 * **Note:** This method doesn't set the "length" property of bound functions.
13301 * @param {Object} object The object to bind and assign the bound methods to.
13302 * @param {...(string|string[])} methodNames The object method names to bind,
13303 * specified individually or in arrays.
13304 * @returns {Object} Returns `object`.
13309 * 'onClick': function() {
13310 * console.log('clicked ' + this.label);
13314 * _.bindAll(view, 'onClick');
13315 * jQuery(element).on('click', view.onClick);
13316 * // => logs 'clicked docs' when clicked
13318 var bindAll = rest(function(object, methodNames) {
13319 arrayEach(baseFlatten(methodNames, 1), function(key) {
13320 object[key] = bind(object[key], object);
13326 * Creates a function that iterates over `pairs` invoking the corresponding
13327 * function of the first predicate to return truthy. The predicate-function
13328 * pairs are invoked with the `this` binding and arguments of the created
13334 * @param {Array} pairs The predicate-function pairs.
13335 * @returns {Function} Returns the new function.
13338 * var func = _.cond([
13339 * [_.matches({ 'a': 1 }), _.constant('matches A')],
13340 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
13341 * [_.constant(true), _.constant('no match')]
13344 * func({ 'a': 1, 'b': 2 });
13345 * // => 'matches A'
13347 * func({ 'a': 0, 'b': 1 });
13348 * // => 'matches B'
13350 * func({ 'a': '1', 'b': '2' });
13353 function cond(pairs) {
13354 var length = pairs ? pairs.length : 0,
13355 toIteratee = getIteratee();
13357 pairs = !length ? [] : arrayMap(pairs, function(pair) {
13358 if (typeof pair[1] != 'function') {
13359 throw new TypeError(FUNC_ERROR_TEXT);
13361 return [toIteratee(pair[0]), pair[1]];
13364 return rest(function(args) {
13366 while (++index < length) {
13367 var pair = pairs[index];
13368 if (apply(pair[0], this, args)) {
13369 return apply(pair[1], this, args);
13376 * Creates a function that invokes the predicate properties of `source` with
13377 * the corresponding property values of a given object, returning `true` if
13378 * all predicates return truthy, else `false`.
13383 * @param {Object} source The object of property predicates to conform to.
13384 * @returns {Function} Returns the new function.
13388 * { 'user': 'barney', 'age': 36 },
13389 * { 'user': 'fred', 'age': 40 }
13392 * _.filter(users, _.conforms({ 'age': _.partial(_.gt, _, 38) }));
13393 * // => [{ 'user': 'fred', 'age': 40 }]
13395 function conforms(source) {
13396 return baseConforms(baseClone(source, true));
13400 * Creates a function that returns `value`.
13405 * @param {*} value The value to return from the new function.
13406 * @returns {Function} Returns the new function.
13409 * var object = { 'user': 'fred' };
13410 * var getter = _.constant(object);
13412 * getter() === object;
13415 function constant(value) {
13416 return function() {
13422 * Creates a function that returns the result of invoking the given functions
13423 * with the `this` binding of the created function, where each successive
13424 * invocation is supplied the return value of the previous.
13429 * @param {...(Function|Function[])} [funcs] Functions to invoke.
13430 * @returns {Function} Returns the new function.
13433 * function square(n) {
13437 * var addSquare = _.flow(_.add, square);
13441 var flow = createFlow();
13444 * This method is like `_.flow` except that it creates a function that
13445 * invokes the given functions from right to left.
13450 * @param {...(Function|Function[])} [funcs] Functions to invoke.
13451 * @returns {Function} Returns the new function.
13454 * function square(n) {
13458 * var addSquare = _.flowRight(square, _.add);
13462 var flowRight = createFlow(true);
13465 * This method returns the first argument given to it.
13470 * @param {*} value Any value.
13471 * @returns {*} Returns `value`.
13474 * var object = { 'user': 'fred' };
13476 * _.identity(object) === object;
13479 function identity(value) {
13484 * Creates a function that invokes `func` with the arguments of the created
13485 * function. If `func` is a property name the created callback returns the
13486 * property value for a given element. If `func` is an object the created
13487 * callback returns `true` for elements that contain the equivalent object
13488 * properties, otherwise it returns `false`.
13493 * @param {*} [func=_.identity] The value to convert to a callback.
13494 * @returns {Function} Returns the callback.
13498 * { 'user': 'barney', 'age': 36 },
13499 * { 'user': 'fred', 'age': 40 }
13502 * // Create custom iteratee shorthands.
13503 * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
13504 * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
13505 * return !p ? callback(func) : function(object) {
13506 * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
13510 * _.filter(users, 'age > 36');
13511 * // => [{ 'user': 'fred', 'age': 40 }]
13513 function iteratee(func) {
13514 return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
13518 * Creates a function that performs a partial deep comparison between a given
13519 * object and `source`, returning `true` if the given object has equivalent
13520 * property values, else `false`. The created function is equivalent to
13521 * `_.isMatch` with a `source` partially applied.
13523 * **Note:** This method supports comparing the same values as `_.isEqual`.
13528 * @param {Object} source The object of property values to match.
13529 * @returns {Function} Returns the new function.
13533 * { 'user': 'barney', 'age': 36, 'active': true },
13534 * { 'user': 'fred', 'age': 40, 'active': false }
13537 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
13538 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
13540 function matches(source) {
13541 return baseMatches(baseClone(source, true));
13545 * Creates a function that performs a partial deep comparison between the
13546 * value at `path` of a given object to `srcValue`, returning `true` if the
13547 * object value is equivalent, else `false`.
13549 * **Note:** This method supports comparing the same values as `_.isEqual`.
13554 * @param {Array|string} path The path of the property to get.
13555 * @param {*} srcValue The value to match.
13556 * @returns {Function} Returns the new function.
13560 * { 'user': 'barney' },
13561 * { 'user': 'fred' }
13564 * _.find(users, _.matchesProperty('user', 'fred'));
13565 * // => { 'user': 'fred' }
13567 function matchesProperty(path, srcValue) {
13568 return baseMatchesProperty(path, baseClone(srcValue, true));
13572 * Creates a function that invokes the method at `path` of a given object.
13573 * Any additional arguments are provided to the invoked method.
13578 * @param {Array|string} path The path of the method to invoke.
13579 * @param {...*} [args] The arguments to invoke the method with.
13580 * @returns {Function} Returns the new function.
13584 * { 'a': { 'b': { 'c': _.constant(2) } } },
13585 * { 'a': { 'b': { 'c': _.constant(1) } } }
13588 * _.map(objects, _.method('a.b.c'));
13591 * _.invokeMap(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
13594 var method = rest(function(path, args) {
13595 return function(object) {
13596 return baseInvoke(object, path, args);
13601 * The opposite of `_.method`; this method creates a function that invokes
13602 * the method at a given path of `object`. Any additional arguments are
13603 * provided to the invoked method.
13608 * @param {Object} object The object to query.
13609 * @param {...*} [args] The arguments to invoke the method with.
13610 * @returns {Function} Returns the new function.
13613 * var array = _.times(3, _.constant),
13614 * object = { 'a': array, 'b': array, 'c': array };
13616 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
13619 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
13622 var methodOf = rest(function(object, args) {
13623 return function(path) {
13624 return baseInvoke(object, path, args);
13629 * Adds all own enumerable function properties of a source object to the
13630 * destination object. If `object` is a function then methods are added to
13631 * its prototype as well.
13633 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
13634 * avoid conflicts caused by modifying the original.
13639 * @param {Function|Object} [object=lodash] The destination object.
13640 * @param {Object} source The object of functions to add.
13641 * @param {Object} [options] The options object.
13642 * @param {boolean} [options.chain=true] Specify whether the functions added
13644 * @returns {Function|Object} Returns `object`.
13647 * function vowels(string) {
13648 * return _.filter(string, function(v) {
13649 * return /[aeiou]/i.test(v);
13653 * _.mixin({ 'vowels': vowels });
13654 * _.vowels('fred');
13657 * _('fred').vowels().value();
13660 * _.mixin({ 'vowels': vowels }, { 'chain': false });
13661 * _('fred').vowels();
13664 function mixin(object, source, options) {
13665 var props = keys(source),
13666 methodNames = baseFunctions(source, props);
13668 if (options == null &&
13669 !(isObject(source) && (methodNames.length || !props.length))) {
13673 methodNames = baseFunctions(source, keys(source));
13675 var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
13676 isFunc = isFunction(object);
13678 arrayEach(methodNames, function(methodName) {
13679 var func = source[methodName];
13680 object[methodName] = func;
13682 object.prototype[methodName] = function() {
13683 var chainAll = this.__chain__;
13684 if (chain || chainAll) {
13685 var result = object(this.__wrapped__),
13686 actions = result.__actions__ = copyArray(this.__actions__);
13688 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
13689 result.__chain__ = chainAll;
13692 return func.apply(object, arrayPush([this.value()], arguments));
13701 * Reverts the `_` variable to its previous value and returns a reference to
13702 * the `lodash` function.
13707 * @returns {Function} Returns the `lodash` function.
13710 * var lodash = _.noConflict();
13712 function noConflict() {
13713 if (root._ === this) {
13720 * A no-operation function that returns `undefined` regardless of the
13721 * arguments it receives.
13728 * var object = { 'user': 'fred' };
13730 * _.noop(object) === undefined;
13734 // No operation performed.
13738 * Creates a function that returns its nth argument.
13743 * @param {number} [n=0] The index of the argument to return.
13744 * @returns {Function} Returns the new function.
13747 * var func = _.nthArg(1);
13749 * func('a', 'b', 'c');
13752 function nthArg(n) {
13754 return function() {
13755 return arguments[n];
13760 * Creates a function that invokes `iteratees` with the arguments provided
13761 * to the created function and returns their results.
13766 * @param {...(Function|Function[])} iteratees The iteratees to invoke.
13767 * @returns {Function} Returns the new function.
13770 * var func = _.over(Math.max, Math.min);
13772 * func(1, 2, 3, 4);
13775 var over = createOver(arrayMap);
13778 * Creates a function that checks if **all** of the `predicates` return
13779 * truthy when invoked with the arguments provided to the created function.
13784 * @param {...(Function|Function[])} predicates The predicates to check.
13785 * @returns {Function} Returns the new function.
13788 * var func = _.overEvery(Boolean, isFinite);
13799 var overEvery = createOver(arrayEvery);
13802 * Creates a function that checks if **any** of the `predicates` return
13803 * truthy when invoked with the arguments provided to the created function.
13808 * @param {...(Function|Function[])} predicates The predicates to check.
13809 * @returns {Function} Returns the new function.
13812 * var func = _.overSome(Boolean, isFinite);
13823 var overSome = createOver(arraySome);
13826 * Creates a function that returns the value at `path` of a given object.
13831 * @param {Array|string} path The path of the property to get.
13832 * @returns {Function} Returns the new function.
13836 * { 'a': { 'b': { 'c': 2 } } },
13837 * { 'a': { 'b': { 'c': 1 } } }
13840 * _.map(objects, _.property('a.b.c'));
13843 * _.map(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
13846 function property(path) {
13847 return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
13851 * The opposite of `_.property`; this method creates a function that returns
13852 * the value at a given path of `object`.
13857 * @param {Object} object The object to query.
13858 * @returns {Function} Returns the new function.
13861 * var array = [0, 1, 2],
13862 * object = { 'a': array, 'b': array, 'c': array };
13864 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
13867 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
13870 function propertyOf(object) {
13871 return function(path) {
13872 return object == null ? undefined : baseGet(object, path);
13877 * Creates an array of numbers (positive and/or negative) progressing from
13878 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
13879 * `start` is specified without an `end` or `step`. If `end` is not specified
13880 * it's set to `start` with `start` then set to `0`.
13882 * **Note:** JavaScript follows the IEEE-754 standard for resolving
13883 * floating-point values which can produce unexpected results.
13888 * @param {number} [start=0] The start of the range.
13889 * @param {number} end The end of the range.
13890 * @param {number} [step=1] The value to increment or decrement by.
13891 * @returns {Array} Returns the new array of numbers.
13895 * // => [0, 1, 2, 3]
13898 * // => [0, -1, -2, -3]
13901 * // => [1, 2, 3, 4]
13903 * _.range(0, 20, 5);
13904 * // => [0, 5, 10, 15]
13906 * _.range(0, -4, -1);
13907 * // => [0, -1, -2, -3]
13909 * _.range(1, 4, 0);
13915 var range = createRange();
13918 * This method is like `_.range` except that it populates values in
13919 * descending order.
13924 * @param {number} [start=0] The start of the range.
13925 * @param {number} end The end of the range.
13926 * @param {number} [step=1] The value to increment or decrement by.
13927 * @returns {Array} Returns the new array of numbers.
13931 * // => [3, 2, 1, 0]
13933 * _.rangeRight(-4);
13934 * // => [-3, -2, -1, 0]
13936 * _.rangeRight(1, 5);
13937 * // => [4, 3, 2, 1]
13939 * _.rangeRight(0, 20, 5);
13940 * // => [15, 10, 5, 0]
13942 * _.rangeRight(0, -4, -1);
13943 * // => [-3, -2, -1, 0]
13945 * _.rangeRight(1, 4, 0);
13951 var rangeRight = createRange(true);
13954 * Invokes the iteratee `n` times, returning an array of the results of
13955 * each invocation. The iteratee is invoked with one argument; (index).
13960 * @param {number} n The number of times to invoke `iteratee`.
13961 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13962 * @returns {Array} Returns the array of results.
13965 * _.times(3, String);
13966 * // => ['0', '1', '2']
13968 * _.times(4, _.constant(true));
13969 * // => [true, true, true, true]
13971 function times(n, iteratee) {
13973 if (n < 1 || n > MAX_SAFE_INTEGER) {
13976 var index = MAX_ARRAY_LENGTH,
13977 length = nativeMin(n, MAX_ARRAY_LENGTH);
13979 iteratee = baseCastFunction(iteratee);
13980 n -= MAX_ARRAY_LENGTH;
13982 var result = baseTimes(length, iteratee);
13983 while (++index < n) {
13990 * Converts `value` to a property path array.
13995 * @param {*} value The value to convert.
13996 * @returns {Array} Returns the new property path array.
13999 * _.toPath('a.b.c');
14000 * // => ['a', 'b', 'c']
14002 * _.toPath('a[0].b.c');
14003 * // => ['a', '0', 'b', 'c']
14005 * var path = ['a', 'b', 'c'],
14006 * newPath = _.toPath(path);
14008 * console.log(newPath);
14009 * // => ['a', 'b', 'c']
14011 * console.log(path === newPath);
14014 function toPath(value) {
14015 return isArray(value) ? arrayMap(value, String) : stringToPath(value);
14019 * Generates a unique ID. If `prefix` is given the ID is appended to it.
14024 * @param {string} [prefix=''] The value to prefix the ID with.
14025 * @returns {string} Returns the unique ID.
14028 * _.uniqueId('contact_');
14029 * // => 'contact_104'
14034 function uniqueId(prefix) {
14035 var id = ++idCounter;
14036 return toString(prefix) + id;
14039 /*------------------------------------------------------------------------*/
14042 * Adds two numbers.
14047 * @param {number} augend The first number in an addition.
14048 * @param {number} addend The second number in an addition.
14049 * @returns {number} Returns the total.
14055 function add(augend, addend) {
14057 if (augend === undefined && addend === undefined) {
14060 if (augend !== undefined) {
14063 if (addend !== undefined) {
14064 result = result === undefined ? addend : (result + addend);
14070 * Computes `number` rounded up to `precision`.
14075 * @param {number} number The number to round up.
14076 * @param {number} [precision=0] The precision to round up to.
14077 * @returns {number} Returns the rounded up number.
14083 * _.ceil(6.004, 2);
14086 * _.ceil(6040, -2);
14089 var ceil = createRound('ceil');
14092 * Computes `number` rounded down to `precision`.
14097 * @param {number} number The number to round down.
14098 * @param {number} [precision=0] The precision to round down to.
14099 * @returns {number} Returns the rounded down number.
14105 * _.floor(0.046, 2);
14108 * _.floor(4060, -2);
14111 var floor = createRound('floor');
14114 * Computes the maximum value of `array`. If `array` is empty or falsey
14115 * `undefined` is returned.
14120 * @param {Array} array The array to iterate over.
14121 * @returns {*} Returns the maximum value.
14124 * _.max([4, 2, 8, 6]);
14130 function max(array) {
14131 return (array && array.length)
14132 ? baseExtremum(array, identity, gt)
14137 * This method is like `_.max` except that it accepts `iteratee` which is
14138 * invoked for each element in `array` to generate the criterion by which
14139 * the value is ranked. The iteratee is invoked with one argument: (value).
14144 * @param {Array} array The array to iterate over.
14145 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
14146 * @returns {*} Returns the maximum value.
14149 * var objects = [{ 'n': 1 }, { 'n': 2 }];
14151 * _.maxBy(objects, function(o) { return o.n; });
14154 * // The `_.property` iteratee shorthand.
14155 * _.maxBy(objects, 'n');
14158 function maxBy(array, iteratee) {
14159 return (array && array.length)
14160 ? baseExtremum(array, getIteratee(iteratee), gt)
14165 * Computes the mean of the values in `array`.
14170 * @param {Array} array The array to iterate over.
14171 * @returns {number} Returns the mean.
14174 * _.mean([4, 2, 8, 6]);
14177 function mean(array) {
14178 return sum(array) / (array ? array.length : 0);
14182 * Computes the minimum value of `array`. If `array` is empty or falsey
14183 * `undefined` is returned.
14188 * @param {Array} array The array to iterate over.
14189 * @returns {*} Returns the minimum value.
14192 * _.min([4, 2, 8, 6]);
14198 function min(array) {
14199 return (array && array.length)
14200 ? baseExtremum(array, identity, lt)
14205 * This method is like `_.min` except that it accepts `iteratee` which is
14206 * invoked for each element in `array` to generate the criterion by which
14207 * the value is ranked. The iteratee is invoked with one argument: (value).
14212 * @param {Array} array The array to iterate over.
14213 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
14214 * @returns {*} Returns the minimum value.
14217 * var objects = [{ 'n': 1 }, { 'n': 2 }];
14219 * _.minBy(objects, function(o) { return o.n; });
14222 * // The `_.property` iteratee shorthand.
14223 * _.minBy(objects, 'n');
14226 function minBy(array, iteratee) {
14227 return (array && array.length)
14228 ? baseExtremum(array, getIteratee(iteratee), lt)
14233 * Computes `number` rounded to `precision`.
14238 * @param {number} number The number to round.
14239 * @param {number} [precision=0] The precision to round to.
14240 * @returns {number} Returns the rounded number.
14246 * _.round(4.006, 2);
14249 * _.round(4060, -2);
14252 var round = createRound('round');
14255 * Subtract two numbers.
14260 * @param {number} minuend The first number in a subtraction.
14261 * @param {number} subtrahend The second number in a subtraction.
14262 * @returns {number} Returns the difference.
14265 * _.subtract(6, 4);
14268 function subtract(minuend, subtrahend) {
14270 if (minuend === undefined && subtrahend === undefined) {
14273 if (minuend !== undefined) {
14276 if (subtrahend !== undefined) {
14277 result = result === undefined ? subtrahend : (result - subtrahend);
14283 * Computes the sum of the values in `array`.
14288 * @param {Array} array The array to iterate over.
14289 * @returns {number} Returns the sum.
14292 * _.sum([4, 2, 8, 6]);
14295 function sum(array) {
14296 return (array && array.length)
14297 ? baseSum(array, identity)
14302 * This method is like `_.sum` except that it accepts `iteratee` which is
14303 * invoked for each element in `array` to generate the value to be summed.
14304 * The iteratee is invoked with one argument: (value).
14309 * @param {Array} array The array to iterate over.
14310 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
14311 * @returns {number} Returns the sum.
14314 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
14316 * _.sumBy(objects, function(o) { return o.n; });
14319 * // The `_.property` iteratee shorthand.
14320 * _.sumBy(objects, 'n');
14323 function sumBy(array, iteratee) {
14324 return (array && array.length)
14325 ? baseSum(array, getIteratee(iteratee))
14329 /*------------------------------------------------------------------------*/
14331 // Ensure wrappers are instances of `baseLodash`.
14332 lodash.prototype = baseLodash.prototype;
14334 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
14335 LodashWrapper.prototype.constructor = LodashWrapper;
14337 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
14338 LazyWrapper.prototype.constructor = LazyWrapper;
14340 // Avoid inheriting from `Object.prototype` when possible.
14341 Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
14343 // Add functions to the `MapCache`.
14344 MapCache.prototype.clear = mapClear;
14345 MapCache.prototype['delete'] = mapDelete;
14346 MapCache.prototype.get = mapGet;
14347 MapCache.prototype.has = mapHas;
14348 MapCache.prototype.set = mapSet;
14350 // Add functions to the `SetCache`.
14351 SetCache.prototype.push = cachePush;
14353 // Add functions to the `Stack` cache.
14354 Stack.prototype.clear = stackClear;
14355 Stack.prototype['delete'] = stackDelete;
14356 Stack.prototype.get = stackGet;
14357 Stack.prototype.has = stackHas;
14358 Stack.prototype.set = stackSet;
14360 // Assign cache to `_.memoize`.
14361 memoize.Cache = MapCache;
14363 // Add functions that return wrapped values when chaining.
14364 lodash.after = after;
14366 lodash.assign = assign;
14367 lodash.assignIn = assignIn;
14368 lodash.assignInWith = assignInWith;
14369 lodash.assignWith = assignWith;
14371 lodash.before = before;
14372 lodash.bind = bind;
14373 lodash.bindAll = bindAll;
14374 lodash.bindKey = bindKey;
14375 lodash.castArray = castArray;
14376 lodash.chain = chain;
14377 lodash.chunk = chunk;
14378 lodash.compact = compact;
14379 lodash.concat = concat;
14380 lodash.cond = cond;
14381 lodash.conforms = conforms;
14382 lodash.constant = constant;
14383 lodash.countBy = countBy;
14384 lodash.create = create;
14385 lodash.curry = curry;
14386 lodash.curryRight = curryRight;
14387 lodash.debounce = debounce;
14388 lodash.defaults = defaults;
14389 lodash.defaultsDeep = defaultsDeep;
14390 lodash.defer = defer;
14391 lodash.delay = delay;
14392 lodash.difference = difference;
14393 lodash.differenceBy = differenceBy;
14394 lodash.differenceWith = differenceWith;
14395 lodash.drop = drop;
14396 lodash.dropRight = dropRight;
14397 lodash.dropRightWhile = dropRightWhile;
14398 lodash.dropWhile = dropWhile;
14399 lodash.fill = fill;
14400 lodash.filter = filter;
14401 lodash.flatMap = flatMap;
14402 lodash.flatten = flatten;
14403 lodash.flattenDeep = flattenDeep;
14404 lodash.flattenDepth = flattenDepth;
14405 lodash.flip = flip;
14406 lodash.flow = flow;
14407 lodash.flowRight = flowRight;
14408 lodash.fromPairs = fromPairs;
14409 lodash.functions = functions;
14410 lodash.functionsIn = functionsIn;
14411 lodash.groupBy = groupBy;
14412 lodash.initial = initial;
14413 lodash.intersection = intersection;
14414 lodash.intersectionBy = intersectionBy;
14415 lodash.intersectionWith = intersectionWith;
14416 lodash.invert = invert;
14417 lodash.invertBy = invertBy;
14418 lodash.invokeMap = invokeMap;
14419 lodash.iteratee = iteratee;
14420 lodash.keyBy = keyBy;
14421 lodash.keys = keys;
14422 lodash.keysIn = keysIn;
14424 lodash.mapKeys = mapKeys;
14425 lodash.mapValues = mapValues;
14426 lodash.matches = matches;
14427 lodash.matchesProperty = matchesProperty;
14428 lodash.memoize = memoize;
14429 lodash.merge = merge;
14430 lodash.mergeWith = mergeWith;
14431 lodash.method = method;
14432 lodash.methodOf = methodOf;
14433 lodash.mixin = mixin;
14434 lodash.negate = negate;
14435 lodash.nthArg = nthArg;
14436 lodash.omit = omit;
14437 lodash.omitBy = omitBy;
14438 lodash.once = once;
14439 lodash.orderBy = orderBy;
14440 lodash.over = over;
14441 lodash.overArgs = overArgs;
14442 lodash.overEvery = overEvery;
14443 lodash.overSome = overSome;
14444 lodash.partial = partial;
14445 lodash.partialRight = partialRight;
14446 lodash.partition = partition;
14447 lodash.pick = pick;
14448 lodash.pickBy = pickBy;
14449 lodash.property = property;
14450 lodash.propertyOf = propertyOf;
14451 lodash.pull = pull;
14452 lodash.pullAll = pullAll;
14453 lodash.pullAllBy = pullAllBy;
14454 lodash.pullAt = pullAt;
14455 lodash.range = range;
14456 lodash.rangeRight = rangeRight;
14457 lodash.rearg = rearg;
14458 lodash.reject = reject;
14459 lodash.remove = remove;
14460 lodash.rest = rest;
14461 lodash.reverse = reverse;
14462 lodash.sampleSize = sampleSize;
14464 lodash.setWith = setWith;
14465 lodash.shuffle = shuffle;
14466 lodash.slice = slice;
14467 lodash.sortBy = sortBy;
14468 lodash.sortedUniq = sortedUniq;
14469 lodash.sortedUniqBy = sortedUniqBy;
14470 lodash.split = split;
14471 lodash.spread = spread;
14472 lodash.tail = tail;
14473 lodash.take = take;
14474 lodash.takeRight = takeRight;
14475 lodash.takeRightWhile = takeRightWhile;
14476 lodash.takeWhile = takeWhile;
14478 lodash.throttle = throttle;
14479 lodash.thru = thru;
14480 lodash.toArray = toArray;
14481 lodash.toPairs = toPairs;
14482 lodash.toPairsIn = toPairsIn;
14483 lodash.toPath = toPath;
14484 lodash.toPlainObject = toPlainObject;
14485 lodash.transform = transform;
14486 lodash.unary = unary;
14487 lodash.union = union;
14488 lodash.unionBy = unionBy;
14489 lodash.unionWith = unionWith;
14490 lodash.uniq = uniq;
14491 lodash.uniqBy = uniqBy;
14492 lodash.uniqWith = uniqWith;
14493 lodash.unset = unset;
14494 lodash.unzip = unzip;
14495 lodash.unzipWith = unzipWith;
14496 lodash.values = values;
14497 lodash.valuesIn = valuesIn;
14498 lodash.without = without;
14499 lodash.words = words;
14500 lodash.wrap = wrap;
14502 lodash.xorBy = xorBy;
14503 lodash.xorWith = xorWith;
14505 lodash.zipObject = zipObject;
14506 lodash.zipObjectDeep = zipObjectDeep;
14507 lodash.zipWith = zipWith;
14510 lodash.extend = assignIn;
14511 lodash.extendWith = assignInWith;
14513 // Add functions to `lodash.prototype`.
14514 mixin(lodash, lodash);
14516 /*------------------------------------------------------------------------*/
14518 // Add functions that return unwrapped values when chaining.
14520 lodash.attempt = attempt;
14521 lodash.camelCase = camelCase;
14522 lodash.capitalize = capitalize;
14523 lodash.ceil = ceil;
14524 lodash.clamp = clamp;
14525 lodash.clone = clone;
14526 lodash.cloneDeep = cloneDeep;
14527 lodash.cloneDeepWith = cloneDeepWith;
14528 lodash.cloneWith = cloneWith;
14529 lodash.deburr = deburr;
14530 lodash.endsWith = endsWith;
14532 lodash.escape = escape;
14533 lodash.escapeRegExp = escapeRegExp;
14534 lodash.every = every;
14535 lodash.find = find;
14536 lodash.findIndex = findIndex;
14537 lodash.findKey = findKey;
14538 lodash.findLast = findLast;
14539 lodash.findLastIndex = findLastIndex;
14540 lodash.findLastKey = findLastKey;
14541 lodash.floor = floor;
14542 lodash.forEach = forEach;
14543 lodash.forEachRight = forEachRight;
14544 lodash.forIn = forIn;
14545 lodash.forInRight = forInRight;
14546 lodash.forOwn = forOwn;
14547 lodash.forOwnRight = forOwnRight;
14552 lodash.hasIn = hasIn;
14553 lodash.head = head;
14554 lodash.identity = identity;
14555 lodash.includes = includes;
14556 lodash.indexOf = indexOf;
14557 lodash.inRange = inRange;
14558 lodash.invoke = invoke;
14559 lodash.isArguments = isArguments;
14560 lodash.isArray = isArray;
14561 lodash.isArrayBuffer = isArrayBuffer;
14562 lodash.isArrayLike = isArrayLike;
14563 lodash.isArrayLikeObject = isArrayLikeObject;
14564 lodash.isBoolean = isBoolean;
14565 lodash.isBuffer = isBuffer;
14566 lodash.isDate = isDate;
14567 lodash.isElement = isElement;
14568 lodash.isEmpty = isEmpty;
14569 lodash.isEqual = isEqual;
14570 lodash.isEqualWith = isEqualWith;
14571 lodash.isError = isError;
14572 lodash.isFinite = isFinite;
14573 lodash.isFunction = isFunction;
14574 lodash.isInteger = isInteger;
14575 lodash.isLength = isLength;
14576 lodash.isMap = isMap;
14577 lodash.isMatch = isMatch;
14578 lodash.isMatchWith = isMatchWith;
14579 lodash.isNaN = isNaN;
14580 lodash.isNative = isNative;
14581 lodash.isNil = isNil;
14582 lodash.isNull = isNull;
14583 lodash.isNumber = isNumber;
14584 lodash.isObject = isObject;
14585 lodash.isObjectLike = isObjectLike;
14586 lodash.isPlainObject = isPlainObject;
14587 lodash.isRegExp = isRegExp;
14588 lodash.isSafeInteger = isSafeInteger;
14589 lodash.isSet = isSet;
14590 lodash.isString = isString;
14591 lodash.isSymbol = isSymbol;
14592 lodash.isTypedArray = isTypedArray;
14593 lodash.isUndefined = isUndefined;
14594 lodash.isWeakMap = isWeakMap;
14595 lodash.isWeakSet = isWeakSet;
14596 lodash.join = join;
14597 lodash.kebabCase = kebabCase;
14598 lodash.last = last;
14599 lodash.lastIndexOf = lastIndexOf;
14600 lodash.lowerCase = lowerCase;
14601 lodash.lowerFirst = lowerFirst;
14605 lodash.maxBy = maxBy;
14606 lodash.mean = mean;
14608 lodash.minBy = minBy;
14609 lodash.noConflict = noConflict;
14610 lodash.noop = noop;
14613 lodash.padEnd = padEnd;
14614 lodash.padStart = padStart;
14615 lodash.parseInt = parseInt;
14616 lodash.random = random;
14617 lodash.reduce = reduce;
14618 lodash.reduceRight = reduceRight;
14619 lodash.repeat = repeat;
14620 lodash.replace = replace;
14621 lodash.result = result;
14622 lodash.round = round;
14623 lodash.runInContext = runInContext;
14624 lodash.sample = sample;
14625 lodash.size = size;
14626 lodash.snakeCase = snakeCase;
14627 lodash.some = some;
14628 lodash.sortedIndex = sortedIndex;
14629 lodash.sortedIndexBy = sortedIndexBy;
14630 lodash.sortedIndexOf = sortedIndexOf;
14631 lodash.sortedLastIndex = sortedLastIndex;
14632 lodash.sortedLastIndexBy = sortedLastIndexBy;
14633 lodash.sortedLastIndexOf = sortedLastIndexOf;
14634 lodash.startCase = startCase;
14635 lodash.startsWith = startsWith;
14636 lodash.subtract = subtract;
14638 lodash.sumBy = sumBy;
14639 lodash.template = template;
14640 lodash.times = times;
14641 lodash.toInteger = toInteger;
14642 lodash.toLength = toLength;
14643 lodash.toLower = toLower;
14644 lodash.toNumber = toNumber;
14645 lodash.toSafeInteger = toSafeInteger;
14646 lodash.toString = toString;
14647 lodash.toUpper = toUpper;
14648 lodash.trim = trim;
14649 lodash.trimEnd = trimEnd;
14650 lodash.trimStart = trimStart;
14651 lodash.truncate = truncate;
14652 lodash.unescape = unescape;
14653 lodash.uniqueId = uniqueId;
14654 lodash.upperCase = upperCase;
14655 lodash.upperFirst = upperFirst;
14658 lodash.each = forEach;
14659 lodash.eachRight = forEachRight;
14660 lodash.first = head;
14662 mixin(lodash, (function() {
14664 baseForOwn(lodash, function(func, methodName) {
14665 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
14666 source[methodName] = func;
14670 }()), { 'chain': false });
14672 /*------------------------------------------------------------------------*/
14675 * The semantic version number.
14681 lodash.VERSION = VERSION;
14683 // Assign default placeholders.
14684 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
14685 lodash[methodName].placeholder = lodash;
14688 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
14689 arrayEach(['drop', 'take'], function(methodName, index) {
14690 LazyWrapper.prototype[methodName] = function(n) {
14691 var filtered = this.__filtered__;
14692 if (filtered && !index) {
14693 return new LazyWrapper(this);
14695 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
14697 var result = this.clone();
14699 result.__takeCount__ = nativeMin(n, result.__takeCount__);
14701 result.__views__.push({
14702 'size': nativeMin(n, MAX_ARRAY_LENGTH),
14703 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
14709 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
14710 return this.reverse()[methodName](n).reverse();
14714 // Add `LazyWrapper` methods that accept an `iteratee` value.
14715 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
14716 var type = index + 1,
14717 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
14719 LazyWrapper.prototype[methodName] = function(iteratee) {
14720 var result = this.clone();
14721 result.__iteratees__.push({
14722 'iteratee': getIteratee(iteratee, 3),
14725 result.__filtered__ = result.__filtered__ || isFilter;
14730 // Add `LazyWrapper` methods for `_.head` and `_.last`.
14731 arrayEach(['head', 'last'], function(methodName, index) {
14732 var takeName = 'take' + (index ? 'Right' : '');
14734 LazyWrapper.prototype[methodName] = function() {
14735 return this[takeName](1).value()[0];
14739 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
14740 arrayEach(['initial', 'tail'], function(methodName, index) {
14741 var dropName = 'drop' + (index ? '' : 'Right');
14743 LazyWrapper.prototype[methodName] = function() {
14744 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
14748 LazyWrapper.prototype.compact = function() {
14749 return this.filter(identity);
14752 LazyWrapper.prototype.find = function(predicate) {
14753 return this.filter(predicate).head();
14756 LazyWrapper.prototype.findLast = function(predicate) {
14757 return this.reverse().find(predicate);
14760 LazyWrapper.prototype.invokeMap = rest(function(path, args) {
14761 if (typeof path == 'function') {
14762 return new LazyWrapper(this);
14764 return this.map(function(value) {
14765 return baseInvoke(value, path, args);
14769 LazyWrapper.prototype.reject = function(predicate) {
14770 predicate = getIteratee(predicate, 3);
14771 return this.filter(function(value) {
14772 return !predicate(value);
14776 LazyWrapper.prototype.slice = function(start, end) {
14777 start = toInteger(start);
14780 if (result.__filtered__ && (start > 0 || end < 0)) {
14781 return new LazyWrapper(result);
14784 result = result.takeRight(-start);
14785 } else if (start) {
14786 result = result.drop(start);
14788 if (end !== undefined) {
14789 end = toInteger(end);
14790 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
14795 LazyWrapper.prototype.takeRightWhile = function(predicate) {
14796 return this.reverse().takeWhile(predicate).reverse();
14799 LazyWrapper.prototype.toArray = function() {
14800 return this.take(MAX_ARRAY_LENGTH);
14803 // Add `LazyWrapper` methods to `lodash.prototype`.
14804 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
14805 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
14806 isTaker = /^(?:head|last)$/.test(methodName),
14807 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
14808 retUnwrapped = isTaker || /^find/.test(methodName);
14813 lodash.prototype[methodName] = function() {
14814 var value = this.__wrapped__,
14815 args = isTaker ? [1] : arguments,
14816 isLazy = value instanceof LazyWrapper,
14817 iteratee = args[0],
14818 useLazy = isLazy || isArray(value);
14820 var interceptor = function(value) {
14821 var result = lodashFunc.apply(lodash, arrayPush([value], args));
14822 return (isTaker && chainAll) ? result[0] : result;
14825 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
14826 // Avoid lazy use if the iteratee has a "length" value other than `1`.
14827 isLazy = useLazy = false;
14829 var chainAll = this.__chain__,
14830 isHybrid = !!this.__actions__.length,
14831 isUnwrapped = retUnwrapped && !chainAll,
14832 onlyLazy = isLazy && !isHybrid;
14834 if (!retUnwrapped && useLazy) {
14835 value = onlyLazy ? value : new LazyWrapper(this);
14836 var result = func.apply(value, args);
14837 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
14838 return new LodashWrapper(result, chainAll);
14840 if (isUnwrapped && onlyLazy) {
14841 return func.apply(this, args);
14843 result = this.thru(interceptor);
14844 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
14848 // Add `Array` and `String` methods to `lodash.prototype`.
14849 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
14850 var func = arrayProto[methodName],
14851 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
14852 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
14854 lodash.prototype[methodName] = function() {
14855 var args = arguments;
14856 if (retUnwrapped && !this.__chain__) {
14857 return func.apply(this.value(), args);
14859 return this[chainName](function(value) {
14860 return func.apply(value, args);
14865 // Map minified function names to their real names.
14866 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
14867 var lodashFunc = lodash[methodName];
14869 var key = (lodashFunc.name + ''),
14870 names = realNames[key] || (realNames[key] = []);
14872 names.push({ 'name': methodName, 'func': lodashFunc });
14876 realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{
14881 // Add functions to the lazy wrapper.
14882 LazyWrapper.prototype.clone = lazyClone;
14883 LazyWrapper.prototype.reverse = lazyReverse;
14884 LazyWrapper.prototype.value = lazyValue;
14886 // Add chaining functions to the `lodash` wrapper.
14887 lodash.prototype.at = wrapperAt;
14888 lodash.prototype.chain = wrapperChain;
14889 lodash.prototype.commit = wrapperCommit;
14890 lodash.prototype.flatMap = wrapperFlatMap;
14891 lodash.prototype.next = wrapperNext;
14892 lodash.prototype.plant = wrapperPlant;
14893 lodash.prototype.reverse = wrapperReverse;
14894 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
14896 if (iteratorSymbol) {
14897 lodash.prototype[iteratorSymbol] = wrapperToIterator;
14902 /*--------------------------------------------------------------------------*/
14905 var _ = runInContext();
14907 // Expose lodash on the free variable `window` or `self` when available. This
14908 // prevents errors in cases where lodash is loaded by a script tag in the presence
14909 // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
14910 (freeWindow || freeSelf || {})._ = _;
14912 // Some AMD build optimizers like r.js check for condition patterns like the following:
14913 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
14914 // Define as an anonymous module so, through path mapping, it can be
14915 // referenced as the "underscore" module.
14916 define(function() {
14920 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
14921 else if (freeExports && freeModule) {
14922 // Export for Node.js.
14923 if (moduleExports) {
14924 (freeModule.exports = _)._ = _;
14926 // Export for CommonJS support.
14930 // Export to the global object.