3 * lodash 4.0.1 (Custom Build) <https://lodash.com/>
4 * Build: `lodash -d -o ./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.0.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]';
87 var arrayBufferTag = '[object ArrayBuffer]',
88 float32Tag = '[object Float32Array]',
89 float64Tag = '[object Float64Array]',
90 int8Tag = '[object Int8Array]',
91 int16Tag = '[object Int16Array]',
92 int32Tag = '[object Int32Array]',
93 uint8Tag = '[object Uint8Array]',
94 uint8ClampedTag = '[object Uint8ClampedArray]',
95 uint16Tag = '[object Uint16Array]',
96 uint32Tag = '[object Uint32Array]';
98 /** Used to match empty string literals in compiled template source. */
99 var reEmptyStringLeading = /\b__p \+= '';/g,
100 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
101 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
103 /** Used to match HTML entities and HTML characters. */
104 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
105 reUnescapedHtml = /[&<>"'`]/g,
106 reHasEscapedHtml = RegExp(reEscapedHtml.source),
107 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
109 /** Used to match template delimiters. */
110 var reEscape = /<%-([\s\S]+?)%>/g,
111 reEvaluate = /<%([\s\S]+?)%>/g,
112 reInterpolate = /<%=([\s\S]+?)%>/g;
114 /** Used to match property names within property paths. */
115 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
116 reIsPlainProp = /^\w*$/,
117 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
119 /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */
120 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
121 reHasRegExpChar = RegExp(reRegExpChar.source);
123 /** Used to match leading and trailing whitespace. */
124 var reTrim = /^\s+|\s+$/g,
125 reTrimStart = /^\s+/,
128 /** Used to match backslashes in property paths. */
129 var reEscapeChar = /\\(\\)?/g;
131 /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
132 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
134 /** Used to match `RegExp` flags from their coerced string values. */
135 var reFlags = /\w*$/;
137 /** Used to detect hexadecimal string values. */
138 var reHasHexPrefix = /^0x/i;
140 /** Used to detect bad signed hexadecimal string values. */
141 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
143 /** Used to detect binary string values. */
144 var reIsBinary = /^0b[01]+$/i;
146 /** Used to detect host constructors (Safari > 5). */
147 var reIsHostCtor = /^\[object .+?Constructor\]$/;
149 /** Used to detect octal string values. */
150 var reIsOctal = /^0o[0-7]+$/i;
152 /** Used to detect unsigned integer values. */
153 var reIsUint = /^(?:0|[1-9]\d*)$/;
155 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
156 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
158 /** Used to ensure capturing order of template delimiters. */
159 var reNoMatch = /($^)/;
161 /** Used to match unescaped characters in compiled string literals. */
162 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
164 /** Used to compose unicode character classes. */
165 var rsAstralRange = '\\ud800-\\udfff',
166 rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
167 rsComboSymbolsRange = '\\u20d0-\\u20f0',
168 rsDingbatRange = '\\u2700-\\u27bf',
169 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
170 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
171 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
172 rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d',
173 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',
174 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
175 rsVarRange = '\\ufe0e\\ufe0f',
176 rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange;
178 /** Used to compose unicode capture groups. */
179 var rsAstral = '[' + rsAstralRange + ']',
180 rsBreak = '[' + rsBreakRange + ']',
181 rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
183 rsDingbat = '[' + rsDingbatRange + ']',
184 rsLower = '[' + rsLowerRange + ']',
185 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
186 rsFitz = '\\ud83c[\\udffb-\\udfff]',
187 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
188 rsNonAstral = '[^' + rsAstralRange + ']',
189 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
190 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
191 rsUpper = '[' + rsUpperRange + ']',
194 /** Used to compose unicode regexes. */
195 var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
196 rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
197 reOptMod = rsModifier + '?',
198 rsOptVar = '[' + rsVarRange + ']?',
199 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
200 rsSeq = rsOptVar + reOptMod + rsOptJoin,
201 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
202 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
205 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
206 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
208 var reComboMark = RegExp(rsCombo, 'g');
210 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
211 var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
213 /** 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/). */
214 var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
216 /** Used to match non-compound words composed of alphanumeric characters. */
217 var reBasicWord = /[a-zA-Z0-9]+/g;
219 /** Used to match complex or compound words. */
220 var reComplexWord = RegExp([
221 rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
222 rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
223 rsUpper + '?' + rsLowerMisc + '+',
229 /** Used to detect strings that need a more robust regexp to match words. */
230 var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
232 /** Used to assign default `context` object properties. */
234 'Array', 'Date', 'Error', 'Float32Array', 'Float64Array', 'Function',
235 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
236 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
237 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_',
238 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
241 /** Used to make template sourceURLs easier to identify. */
242 var templateCounter = -1;
244 /** Used to identify `toStringTag` values of typed arrays. */
245 var typedArrayTags = {};
246 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
247 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
248 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
249 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
250 typedArrayTags[uint32Tag] = true;
251 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
252 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
253 typedArrayTags[dateTag] = typedArrayTags[errorTag] =
254 typedArrayTags[funcTag] = typedArrayTags[mapTag] =
255 typedArrayTags[numberTag] = typedArrayTags[objectTag] =
256 typedArrayTags[regexpTag] = typedArrayTags[setTag] =
257 typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
259 /** Used to identify `toStringTag` values supported by `_.clone`. */
260 var cloneableTags = {};
261 cloneableTags[argsTag] = cloneableTags[arrayTag] =
262 cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
263 cloneableTags[dateTag] = cloneableTags[float32Tag] =
264 cloneableTags[float64Tag] = cloneableTags[int8Tag] =
265 cloneableTags[int16Tag] = cloneableTags[int32Tag] =
266 cloneableTags[mapTag] = cloneableTags[numberTag] =
267 cloneableTags[objectTag] = cloneableTags[regexpTag] =
268 cloneableTags[setTag] = cloneableTags[stringTag] =
269 cloneableTags[symbolTag] = cloneableTags[uint8Tag] =
270 cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] =
271 cloneableTags[uint32Tag] = true;
272 cloneableTags[errorTag] = cloneableTags[funcTag] =
273 cloneableTags[weakMapTag] = false;
275 /** Used to map latin-1 supplementary letters to basic latin letters. */
276 var deburredLetters = {
277 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
278 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
279 '\xc7': 'C', '\xe7': 'c',
280 '\xd0': 'D', '\xf0': 'd',
281 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
282 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
283 '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
284 '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
285 '\xd1': 'N', '\xf1': 'n',
286 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
287 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
288 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
289 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
290 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
291 '\xc6': 'Ae', '\xe6': 'ae',
292 '\xde': 'Th', '\xfe': 'th',
296 /** Used to map characters to HTML entities. */
306 /** Used to map HTML entities to characters. */
307 var htmlUnescapes = {
316 /** Used to determine if values are of the language type `Object`. */
322 /** Used to escape characters for inclusion in compiled string literals. */
323 var stringEscapes = {
332 /** Built-in method references without a dependency on `root`. */
333 var freeParseFloat = parseFloat,
334 freeParseInt = parseInt;
336 /** Detect free variable `exports`. */
337 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
339 /** Detect free variable `module`. */
340 var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
342 /** Detect free variable `global` from Node.js. */
343 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
345 /** Detect free variable `self`. */
346 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
348 /** Detect free variable `window`. */
349 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
351 /** Detect the popular CommonJS extension `module.exports`. */
352 var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null;
354 /** Detect `this` as the global object. */
355 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
358 * Used as a reference to the global object.
360 * The `this` value is used if it's the global object to avoid Greasemonkey's
361 * restricted `window` object, otherwise the `window` object is used.
363 var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
365 /*--------------------------------------------------------------------------*/
368 * Adds the key-value `pair` to `map`.
371 * @param {Object} map The map to modify.
372 * @param {Array} pair The key-value pair to add.
373 * @returns {Object} Returns `map`.
375 function addMapEntry(map, pair) {
376 map.set(pair[0], pair[1]);
381 * Adds `value` to `set`.
384 * @param {Object} set The set to modify.
385 * @param {*} value The value to add.
386 * @returns {Object} Returns `set`.
388 function addSetEntry(set, value) {
394 * A faster alternative to `Function#apply`, this function invokes `func`
395 * with the `this` binding of `thisArg` and the arguments of `args`.
398 * @param {Function} func The function to invoke.
399 * @param {*} thisArg The `this` binding of `func`.
400 * @param {...*} [args] The arguments to invoke `func` with.
401 * @returns {*} Returns the result of `func`.
403 function apply(func, thisArg, args) {
404 var length = args ? args.length : 0;
406 case 0: return func.call(thisArg);
407 case 1: return func.call(thisArg, args[0]);
408 case 2: return func.call(thisArg, args[0], args[1]);
409 case 3: return func.call(thisArg, args[0], args[1], args[2]);
411 return func.apply(thisArg, args);
415 * Creates a new array concatenating `array` with `other`.
418 * @param {Array} array The first array to concatenate.
419 * @param {Array} other The second array to concatenate.
420 * @returns {Array} Returns the new concatenated array.
422 function arrayConcat(array, other) {
424 length = array.length,
426 othLength = other.length,
427 result = Array(length + othLength);
429 while (++index < length) {
430 result[index] = array[index];
432 while (++othIndex < othLength) {
433 result[index++] = other[othIndex];
439 * A specialized version of `_.forEach` for arrays without support for
440 * iteratee shorthands.
443 * @param {Array} array The array to iterate over.
444 * @param {Function} iteratee The function invoked per iteration.
445 * @returns {Array} Returns `array`.
447 function arrayEach(array, iteratee) {
449 length = array.length;
451 while (++index < length) {
452 if (iteratee(array[index], index, array) === false) {
460 * A specialized version of `_.forEachRight` for arrays without support for
461 * iteratee shorthands.
464 * @param {Array} array The array to iterate over.
465 * @param {Function} iteratee The function invoked per iteration.
466 * @returns {Array} Returns `array`.
468 function arrayEachRight(array, iteratee) {
469 var length = array.length;
472 if (iteratee(array[length], length, array) === false) {
480 * A specialized version of `_.every` for arrays without support for
481 * iteratee shorthands.
484 * @param {Array} array The array to iterate over.
485 * @param {Function} predicate The function invoked per iteration.
486 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
488 function arrayEvery(array, predicate) {
490 length = array.length;
492 while (++index < length) {
493 if (!predicate(array[index], index, array)) {
501 * A specialized version of `_.filter` for arrays without support for
502 * iteratee shorthands.
505 * @param {Array} array The array to iterate over.
506 * @param {Function} predicate The function invoked per iteration.
507 * @returns {Array} Returns the new filtered array.
509 function arrayFilter(array, predicate) {
511 length = array.length,
515 while (++index < length) {
516 var value = array[index];
517 if (predicate(value, index, array)) {
518 result[++resIndex] = value;
525 * A specialized version of `_.includes` for arrays without support for
526 * specifying an index to search from.
529 * @param {Array} array The array to search.
530 * @param {*} target The value to search for.
531 * @returns {boolean} Returns `true` if `target` is found, else `false`.
533 function arrayIncludes(array, value) {
534 return !!array.length && baseIndexOf(array, value, 0) > -1;
538 * A specialized version of `_.includesWith` for arrays without support for
539 * specifying an index to search from.
542 * @param {Array} array The array to search.
543 * @param {*} target The value to search for.
544 * @param {Function} comparator The comparator invoked per element.
545 * @returns {boolean} Returns `true` if `target` is found, else `false`.
547 function arrayIncludesWith(array, value, comparator) {
549 length = array.length;
551 while (++index < length) {
552 if (comparator(value, array[index])) {
560 * A specialized version of `_.map` for arrays without support for iteratee
564 * @param {Array} array The array to iterate over.
565 * @param {Function} iteratee The function invoked per iteration.
566 * @returns {Array} Returns the new mapped array.
568 function arrayMap(array, iteratee) {
570 length = array.length,
571 result = Array(length);
573 while (++index < length) {
574 result[index] = iteratee(array[index], index, array);
580 * Appends the elements of `values` to `array`.
583 * @param {Array} array The array to modify.
584 * @param {Array} values The values to append.
585 * @returns {Array} Returns `array`.
587 function arrayPush(array, values) {
589 length = values.length,
590 offset = array.length;
592 while (++index < length) {
593 array[offset + index] = values[index];
599 * A specialized version of `_.reduce` for arrays without support for
600 * iteratee shorthands.
603 * @param {Array} array The array to iterate over.
604 * @param {Function} iteratee The function invoked per iteration.
605 * @param {*} [accumulator] The initial value.
606 * @param {boolean} [initAccum] Specify using the first element of `array` as the initial value.
607 * @returns {*} Returns the accumulated value.
609 function arrayReduce(array, iteratee, accumulator, initAccum) {
611 length = array.length;
613 if (initAccum && length) {
614 accumulator = array[++index];
616 while (++index < length) {
617 accumulator = iteratee(accumulator, array[index], index, array);
623 * A specialized version of `_.reduceRight` for arrays without support for
624 * iteratee shorthands.
627 * @param {Array} array The array to iterate over.
628 * @param {Function} iteratee The function invoked per iteration.
629 * @param {*} [accumulator] The initial value.
630 * @param {boolean} [initAccum] Specify using the last element of `array` as the initial value.
631 * @returns {*} Returns the accumulated value.
633 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
634 var length = array.length;
635 if (initAccum && length) {
636 accumulator = array[--length];
639 accumulator = iteratee(accumulator, array[length], length, array);
645 * A specialized version of `_.some` for arrays without support for iteratee
649 * @param {Array} array The array to iterate over.
650 * @param {Function} predicate The function invoked per iteration.
651 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
653 function arraySome(array, predicate) {
655 length = array.length;
657 while (++index < length) {
658 if (predicate(array[index], index, array)) {
666 * The base implementation of methods like `_.max` and `_.min` which accepts a
667 * `comparator` to determine the extremum value.
670 * @param {Array} array The array to iterate over.
671 * @param {Function} iteratee The iteratee invoked per iteration.
672 * @param {Function} comparator The comparator used to compare values.
673 * @returns {*} Returns the extremum value.
675 function baseExtremum(array, iteratee, comparator) {
677 length = array.length;
679 while (++index < length) {
680 var value = array[index],
681 current = iteratee(value);
683 if (current != null && (computed === undefined
684 ? current === current
685 : comparator(current, computed)
687 var computed = current,
695 * The base implementation of methods like `_.find` and `_.findKey`, without
696 * support for iteratee shorthands, which iterates over `collection` using
700 * @param {Array|Object} collection The collection to search.
701 * @param {Function} predicate The function invoked per iteration.
702 * @param {Function} eachFunc The function to iterate over `collection`.
703 * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
704 * @returns {*} Returns the found element or its key, else `undefined`.
706 function baseFind(collection, predicate, eachFunc, retKey) {
708 eachFunc(collection, function(value, key, collection) {
709 if (predicate(value, key, collection)) {
710 result = retKey ? key : value;
718 * The base implementation of `_.findIndex` and `_.findLastIndex` without
719 * support for iteratee shorthands.
722 * @param {Array} array The array to search.
723 * @param {Function} predicate The function invoked per iteration.
724 * @param {boolean} [fromRight] Specify iterating from right to left.
725 * @returns {number} Returns the index of the matched value, else `-1`.
727 function baseFindIndex(array, predicate, fromRight) {
728 var length = array.length,
729 index = fromRight ? length : -1;
731 while ((fromRight ? index-- : ++index < length)) {
732 if (predicate(array[index], index, array)) {
740 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
743 * @param {Array} array The array to search.
744 * @param {*} value The value to search for.
745 * @param {number} fromIndex The index to search from.
746 * @returns {number} Returns the index of the matched value, else `-1`.
748 function baseIndexOf(array, value, fromIndex) {
749 if (value !== value) {
750 return indexOfNaN(array, fromIndex);
752 var index = fromIndex - 1,
753 length = array.length;
755 while (++index < length) {
756 if (array[index] === value) {
764 * The base implementation of `_.reduce` and `_.reduceRight`, without support
765 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
768 * @param {Array|Object} collection The collection to iterate over.
769 * @param {Function} iteratee The function invoked per iteration.
770 * @param {*} accumulator The initial value.
771 * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value.
772 * @param {Function} eachFunc The function to iterate over `collection`.
773 * @returns {*} Returns the accumulated value.
775 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
776 eachFunc(collection, function(value, index, collection) {
777 accumulator = initAccum
778 ? (initAccum = false, value)
779 : iteratee(accumulator, value, index, collection);
785 * The base implementation of `_.sortBy` which uses `comparer` to define
786 * the sort order of `array` and replaces criteria objects with their
787 * corresponding values.
790 * @param {Array} array The array to sort.
791 * @param {Function} comparer The function to define sort order.
792 * @returns {Array} Returns `array`.
794 function baseSortBy(array, comparer) {
795 var length = array.length;
797 array.sort(comparer);
799 array[length] = array[length].value;
805 * The base implementation of `_.sum` without support for iteratee shorthands.
808 * @param {Array} array The array to iterate over.
809 * @param {Function} iteratee The function invoked per iteration.
810 * @returns {number} Returns the sum.
812 function baseSum(array, iteratee) {
815 length = array.length;
817 while (++index < length) {
818 var current = iteratee(array[index]);
819 if (current !== undefined) {
820 result = result === undefined ? current : (result + current);
827 * The base implementation of `_.times` without support for iteratee shorthands
828 * or max array length checks.
831 * @param {number} n The number of times to invoke `iteratee`.
832 * @param {Function} iteratee The function invoked per iteration.
833 * @returns {Array} Returns the array of results.
835 function baseTimes(n, iteratee) {
839 while (++index < n) {
840 result[index] = iteratee(index);
846 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
847 * of key-value pairs for `object` corresponding to the property names of `props`.
850 * @param {Object} object The object to query.
851 * @param {Array} props The property names to get values for.
852 * @returns {Object} Returns the new array of key-value pairs.
854 function baseToPairs(object, props) {
855 return arrayMap(props, function(key) {
856 return [key, object[key]];
861 * The base implementation of `_.unary` without support for storing wrapper metadata.
864 * @param {Function} func The function to cap arguments for.
865 * @returns {Function} Returns the new function.
867 function baseUnary(func) {
868 return function(value) {
874 * The base implementation of `_.values` and `_.valuesIn` which creates an
875 * array of `object` property values corresponding to the property names
879 * @param {Object} object The object to query.
880 * @param {Array} props The property names to get values for.
881 * @returns {Object} Returns the array of property values.
883 function baseValues(object, props) {
884 return arrayMap(props, function(key) {
890 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
891 * that is not found in the character symbols.
894 * @param {Array} strSymbols The string symbols to inspect.
895 * @param {Array} chrSymbols The character symbols to find.
896 * @returns {number} Returns the index of the first unmatched string symbol.
898 function charsStartIndex(strSymbols, chrSymbols) {
900 length = strSymbols.length;
902 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
907 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
908 * that is not found in the character symbols.
911 * @param {Array} strSymbols The string symbols to inspect.
912 * @param {Array} chrSymbols The character symbols to find.
913 * @returns {number} Returns the index of the last unmatched string symbol.
915 function charsEndIndex(strSymbols, chrSymbols) {
916 var index = strSymbols.length;
918 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
923 * Checks if `value` is a global object.
926 * @param {*} value The value to check.
927 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
929 function checkGlobal(value) {
930 return (value && value.Object === Object) ? value : null;
934 * Compares values to sort them in ascending order.
937 * @param {*} value The value to compare.
938 * @param {*} other The other value to compare.
939 * @returns {number} Returns the sort order indicator for `value`.
941 function compareAscending(value, other) {
942 if (value !== other) {
943 var valIsNull = value === null,
944 valIsUndef = value === undefined,
945 valIsReflexive = value === value;
947 var othIsNull = other === null,
948 othIsUndef = other === undefined,
949 othIsReflexive = other === other;
951 if ((value > other && !othIsNull) || !valIsReflexive ||
952 (valIsNull && !othIsUndef && othIsReflexive) ||
953 (valIsUndef && othIsReflexive)) {
956 if ((value < other && !valIsNull) || !othIsReflexive ||
957 (othIsNull && !valIsUndef && valIsReflexive) ||
958 (othIsUndef && valIsReflexive)) {
966 * Used by `_.orderBy` to compare multiple properties of a value to another
967 * and stable sort them.
969 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
970 * specify an order of "desc" for descending or "asc" for ascending sort order
971 * of corresponding values.
974 * @param {Object} object The object to compare.
975 * @param {Object} other The other object to compare.
976 * @param {boolean[]|string[]} orders The order to sort by for each property.
977 * @returns {number} Returns the sort order indicator for `object`.
979 function compareMultiple(object, other, orders) {
981 objCriteria = object.criteria,
982 othCriteria = other.criteria,
983 length = objCriteria.length,
984 ordersLength = orders.length;
986 while (++index < length) {
987 var result = compareAscending(objCriteria[index], othCriteria[index]);
989 if (index >= ordersLength) {
992 var order = orders[index];
993 return result * (order == 'desc' ? -1 : 1);
996 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
997 // that causes it, under certain circumstances, to provide the same value for
998 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
1001 // This also ensures a stable sort in V8 and other engines.
1002 // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
1003 return object.index - other.index;
1007 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
1010 * @param {string} letter The matched letter to deburr.
1011 * @returns {string} Returns the deburred letter.
1013 function deburrLetter(letter) {
1014 return deburredLetters[letter];
1018 * Used by `_.escape` to convert characters to HTML entities.
1021 * @param {string} chr The matched character to escape.
1022 * @returns {string} Returns the escaped character.
1024 function escapeHtmlChar(chr) {
1025 return htmlEscapes[chr];
1029 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1032 * @param {string} chr The matched character to escape.
1033 * @returns {string} Returns the escaped character.
1035 function escapeStringChar(chr) {
1036 return '\\' + stringEscapes[chr];
1040 * Gets the index at which the first occurrence of `NaN` is found in `array`.
1043 * @param {Array} array The array to search.
1044 * @param {number} fromIndex The index to search from.
1045 * @param {boolean} [fromRight] Specify iterating from right to left.
1046 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
1048 function indexOfNaN(array, fromIndex, fromRight) {
1049 var length = array.length,
1050 index = fromIndex + (fromRight ? 0 : -1);
1052 while ((fromRight ? index-- : ++index < length)) {
1053 var other = array[index];
1054 if (other !== other) {
1062 * Checks if `value` is a host object in IE < 9.
1065 * @param {*} value The value to check.
1066 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
1068 function isHostObject(value) {
1069 // Many host objects are `Object` objects that can coerce to strings
1070 // despite having improperly defined `toString` methods.
1072 if (value != null && typeof value.toString != 'function') {
1074 result = !!(value + '');
1081 * Checks if `value` is a valid array-like index.
1084 * @param {*} value The value to check.
1085 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1086 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1088 function isIndex(value, length) {
1089 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
1090 length = length == null ? MAX_SAFE_INTEGER : length;
1091 return value > -1 && value % 1 == 0 && value < length;
1095 * Converts `iterator` to an array.
1098 * @param {Object} iterator The iterator to convert.
1099 * @returns {Array} Returns the converted array.
1101 function iteratorToArray(iterator) {
1105 while (!(data = iterator.next()).done) {
1106 result.push(data.value);
1112 * Converts `map` to an array.
1115 * @param {Object} map The map to convert.
1116 * @returns {Array} Returns the converted array.
1118 function mapToArray(map) {
1120 result = Array(map.size);
1122 map.forEach(function(value, key) {
1123 result[++index] = [key, value];
1129 * Replaces all `placeholder` elements in `array` with an internal placeholder
1130 * and returns an array of their indexes.
1133 * @param {Array} array The array to modify.
1134 * @param {*} placeholder The placeholder to replace.
1135 * @returns {Array} Returns the new array of placeholder indexes.
1137 function replaceHolders(array, placeholder) {
1139 length = array.length,
1143 while (++index < length) {
1144 if (array[index] === placeholder) {
1145 array[index] = PLACEHOLDER;
1146 result[++resIndex] = index;
1153 * Converts `set` to an array.
1156 * @param {Object} set The set to convert.
1157 * @returns {Array} Returns the converted array.
1159 function setToArray(set) {
1161 result = Array(set.size);
1163 set.forEach(function(value) {
1164 result[++index] = value;
1170 * Gets the number of symbols in `string`.
1173 * @param {string} string The string to inspect.
1174 * @returns {number} Returns the string size.
1176 function stringSize(string) {
1177 if (!(string && reHasComplexSymbol.test(string))) {
1178 return string.length;
1180 var result = reComplexSymbol.lastIndex = 0;
1181 while (reComplexSymbol.test(string)) {
1188 * Converts `string` to an array.
1191 * @param {string} string The string to convert.
1192 * @returns {Array} Returns the converted array.
1194 function stringToArray(string) {
1195 return string.match(reComplexSymbol);
1199 * Used by `_.unescape` to convert HTML entities to characters.
1202 * @param {string} chr The matched character to unescape.
1203 * @returns {string} Returns the unescaped character.
1205 function unescapeHtmlChar(chr) {
1206 return htmlUnescapes[chr];
1209 /*--------------------------------------------------------------------------*/
1212 * Create a new pristine `lodash` function using the `context` object.
1217 * @param {Object} [context=root] The context object.
1218 * @returns {Function} Returns a new `lodash` function.
1221 * _.mixin({ 'foo': _.constant('foo') });
1223 * var lodash = _.runInContext();
1224 * lodash.mixin({ 'bar': lodash.constant('bar') });
1226 * _.isFunction(_.foo);
1228 * _.isFunction(_.bar);
1231 * lodash.isFunction(lodash.foo);
1233 * lodash.isFunction(lodash.bar);
1236 * // using `context` to mock `Date#getTime` use in `_.now`
1237 * var mock = _.runInContext({
1238 * 'Date': function() {
1239 * return { 'getTime': getTimeMock };
1243 * // or creating a suped-up `defer` in Node.js
1244 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1246 function runInContext(context) {
1247 context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
1249 /** Built-in constructor references. */
1250 var Date = context.Date,
1251 Error = context.Error,
1252 Math = context.Math,
1253 RegExp = context.RegExp,
1254 TypeError = context.TypeError;
1256 /** Used for built-in method references. */
1257 var arrayProto = context.Array.prototype,
1258 objectProto = context.Object.prototype;
1260 /** Used to resolve the decompiled source of functions. */
1261 var funcToString = context.Function.prototype.toString;
1263 /** Used to check objects for own properties. */
1264 var hasOwnProperty = objectProto.hasOwnProperty;
1266 /** Used to generate unique IDs. */
1269 /** Used to infer the `Object` constructor. */
1270 var objectCtorString = funcToString.call(Object);
1273 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
1276 var objectToString = objectProto.toString;
1278 /** Used to restore the original `_` reference in `_.noConflict`. */
1279 var oldDash = root._;
1281 /** Used to detect if a method is native. */
1282 var reIsNative = RegExp('^' +
1283 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1284 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1287 /** Built-in value references. */
1288 var Reflect = context.Reflect,
1289 Symbol = context.Symbol,
1290 Uint8Array = context.Uint8Array,
1291 clearTimeout = context.clearTimeout,
1292 enumerate = Reflect ? Reflect.enumerate : undefined,
1293 getPrototypeOf = Object.getPrototypeOf,
1294 getOwnPropertySymbols = Object.getOwnPropertySymbols,
1295 iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
1296 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1297 setTimeout = context.setTimeout,
1298 splice = arrayProto.splice;
1300 /* Built-in method references for those with the same name as other `lodash` methods. */
1301 var nativeCeil = Math.ceil,
1302 nativeFloor = Math.floor,
1303 nativeIsFinite = context.isFinite,
1304 nativeJoin = arrayProto.join,
1305 nativeKeys = Object.keys,
1306 nativeMax = Math.max,
1307 nativeMin = Math.min,
1308 nativeParseInt = context.parseInt,
1309 nativeRandom = Math.random,
1310 nativeReverse = arrayProto.reverse;
1312 /* Built-in method references that are verified to be native. */
1313 var Map = getNative(context, 'Map'),
1314 Set = getNative(context, 'Set'),
1315 WeakMap = getNative(context, 'WeakMap'),
1316 nativeCreate = getNative(Object, 'create');
1318 /** Used to store function metadata. */
1319 var metaMap = WeakMap && new WeakMap;
1321 /** Used to detect maps and sets. */
1322 var mapCtorString = Map ? funcToString.call(Map) : '',
1323 setCtorString = Set ? funcToString.call(Set) : '';
1325 /** Used to convert symbols to primitives and strings. */
1326 var symbolProto = Symbol ? Symbol.prototype : undefined,
1327 symbolValueOf = Symbol ? symbolProto.valueOf : undefined,
1328 symbolToString = Symbol ? symbolProto.toString : undefined;
1330 /** Used to lookup unminified function names. */
1333 /*------------------------------------------------------------------------*/
1336 * Creates a `lodash` object which wraps `value` to enable implicit method
1337 * chaining. Methods that operate on and return arrays, collections, and
1338 * functions can be chained together. Methods that retrieve a single value or
1339 * may return a primitive value will automatically end the chain sequence and
1340 * return the unwrapped value. Otherwise, the value must be unwrapped with
1343 * Explicit chaining, which must be unwrapped with `_#value` in all cases,
1344 * may be enabled using `_.chain`.
1346 * The execution of chained methods is lazy, that is, it's deferred until
1347 * `_#value` is implicitly or explicitly called.
1349 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
1350 * fusion is an optimization to merge iteratee calls; this avoids the creation
1351 * of intermediate arrays and can greatly reduce the number of iteratee executions.
1352 * Sections of a chain sequence qualify for shortcut fusion if the section is
1353 * applied to an array of at least two hundred elements and any iteratees
1354 * accept only one argument. The heuristic for whether a section qualifies
1355 * for shortcut fusion is subject to change.
1357 * Chaining is supported in custom builds as long as the `_#value` method is
1358 * directly or indirectly included in the build.
1360 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1362 * The wrapper `Array` methods are:
1363 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1365 * The wrapper `String` methods are:
1366 * `replace` and `split`
1368 * The wrapper methods that support shortcut fusion are:
1369 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1370 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1371 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1373 * The chainable wrapper methods are:
1374 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
1375 * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
1376 * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`,
1377 * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
1378 * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
1379 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
1380 * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`,
1381 * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invokeMap`,
1382 * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
1383 * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
1384 * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`,
1385 * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
1386 * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
1387 * `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
1388 * `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
1389 * `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`,
1390 * `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`,
1391 * `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`,
1392 * `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`,
1393 * `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`,
1394 * `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith`
1396 * The wrapper methods that are **not** chainable by default are:
1397 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1398 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
1399 * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
1400 * `findLast`, `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`,
1401 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
1402 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
1403 * `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
1404 * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
1405 * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`, `isMatchWith`,
1406 * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`,
1407 * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isString`, `isUndefined`,
1408 * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`,
1409 * `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`,
1410 * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`,
1411 * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
1412 * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
1413 * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
1414 * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toLower`,
1415 * `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`,
1416 * `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
1417 * `upperCase`, `upperFirst`, `value`, and `words`
1422 * @param {*} value The value to wrap in a `lodash` instance.
1423 * @returns {Object} Returns the new `lodash` wrapper instance.
1426 * function square(n) {
1430 * var wrapped = _([1, 2, 3]);
1432 * // returns an unwrapped value
1433 * wrapped.reduce(_.add);
1436 * // returns a wrapped value
1437 * var squares = wrapped.map(square);
1439 * _.isArray(squares);
1442 * _.isArray(squares.value());
1445 function lodash(value) {
1446 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1447 if (value instanceof LodashWrapper) {
1450 if (hasOwnProperty.call(value, '__wrapped__')) {
1451 return wrapperClone(value);
1454 return new LodashWrapper(value);
1458 * The function whose prototype all chaining wrappers inherit from.
1462 function baseLodash() {
1463 // No operation performed.
1467 * The base constructor for creating `lodash` wrapper objects.
1470 * @param {*} value The value to wrap.
1471 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
1473 function LodashWrapper(value, chainAll) {
1474 this.__wrapped__ = value;
1475 this.__actions__ = [];
1476 this.__chain__ = !!chainAll;
1478 this.__values__ = undefined;
1482 * By default, the template delimiters used by lodash are like those in
1483 * embedded Ruby (ERB). Change the following template settings to use
1484 * alternative delimiters.
1490 lodash.templateSettings = {
1493 * Used to detect `data` property values to be HTML-escaped.
1495 * @memberOf _.templateSettings
1501 * Used to detect code to be evaluated.
1503 * @memberOf _.templateSettings
1506 'evaluate': reEvaluate,
1509 * Used to detect `data` property values to inject.
1511 * @memberOf _.templateSettings
1514 'interpolate': reInterpolate,
1517 * Used to reference the data object in the template text.
1519 * @memberOf _.templateSettings
1525 * Used to import variables into the compiled template.
1527 * @memberOf _.templateSettings
1533 * A reference to the `lodash` function.
1535 * @memberOf _.templateSettings.imports
1542 /*------------------------------------------------------------------------*/
1545 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1548 * @param {*} value The value to wrap.
1550 function LazyWrapper(value) {
1551 this.__wrapped__ = value;
1552 this.__actions__ = [];
1554 this.__filtered__ = false;
1555 this.__iteratees__ = [];
1556 this.__takeCount__ = MAX_ARRAY_LENGTH;
1557 this.__views__ = [];
1561 * Creates a clone of the lazy wrapper object.
1565 * @memberOf LazyWrapper
1566 * @returns {Object} Returns the cloned `LazyWrapper` object.
1568 function lazyClone() {
1569 var result = new LazyWrapper(this.__wrapped__);
1570 result.__actions__ = copyArray(this.__actions__);
1571 result.__dir__ = this.__dir__;
1572 result.__filtered__ = this.__filtered__;
1573 result.__iteratees__ = copyArray(this.__iteratees__);
1574 result.__takeCount__ = this.__takeCount__;
1575 result.__views__ = copyArray(this.__views__);
1580 * Reverses the direction of lazy iteration.
1584 * @memberOf LazyWrapper
1585 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1587 function lazyReverse() {
1588 if (this.__filtered__) {
1589 var result = new LazyWrapper(this);
1590 result.__dir__ = -1;
1591 result.__filtered__ = true;
1593 result = this.clone();
1594 result.__dir__ *= -1;
1600 * Extracts the unwrapped value from its lazy wrapper.
1604 * @memberOf LazyWrapper
1605 * @returns {*} Returns the unwrapped value.
1607 function lazyValue() {
1608 var array = this.__wrapped__.value(),
1610 isArr = isArray(array),
1612 arrLength = isArr ? array.length : 0,
1613 view = getView(0, arrLength, this.__views__),
1616 length = end - start,
1617 index = isRight ? end : (start - 1),
1618 iteratees = this.__iteratees__,
1619 iterLength = iteratees.length,
1621 takeCount = nativeMin(length, this.__takeCount__);
1623 if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
1624 return baseWrapperValue(array, this.__actions__);
1629 while (length-- && resIndex < takeCount) {
1633 value = array[index];
1635 while (++iterIndex < iterLength) {
1636 var data = iteratees[iterIndex],
1637 iteratee = data.iteratee,
1639 computed = iteratee(value);
1641 if (type == LAZY_MAP_FLAG) {
1643 } else if (!computed) {
1644 if (type == LAZY_FILTER_FLAG) {
1651 result[resIndex++] = value;
1656 /*------------------------------------------------------------------------*/
1659 * Creates an hash object.
1662 * @returns {Object} Returns the new hash object.
1667 * Removes `key` and its value from the hash.
1670 * @param {Object} hash The hash to modify.
1671 * @param {string} key The key of the value to remove.
1672 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1674 function hashDelete(hash, key) {
1675 return hashHas(hash, key) && delete hash[key];
1679 * Gets the hash value for `key`.
1682 * @param {Object} hash The hash to query.
1683 * @param {string} key The key of the value to get.
1684 * @returns {*} Returns the entry value.
1686 function hashGet(hash, key) {
1688 var result = hash[key];
1689 return result === HASH_UNDEFINED ? undefined : result;
1691 return hasOwnProperty.call(hash, key) ? hash[key] : undefined;
1695 * Checks if a hash value for `key` exists.
1698 * @param {Object} hash The hash to query.
1699 * @param {string} key The key of the entry to check.
1700 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1702 function hashHas(hash, key) {
1703 return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash, key);
1707 * Sets the hash `key` to `value`.
1710 * @param {Object} hash The hash to modify.
1711 * @param {string} key The key of the value to set.
1712 * @param {*} value The value to set.
1714 function hashSet(hash, key, value) {
1715 hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
1718 /*------------------------------------------------------------------------*/
1721 * Creates a map cache object to store key-value pairs.
1724 * @param {Array} [values] The values to cache.
1726 function MapCache(values) {
1728 length = values ? values.length : 0;
1731 while (++index < length) {
1732 var entry = values[index];
1733 this.set(entry[0], entry[1]);
1738 * Removes all key-value entries from the map.
1742 * @memberOf MapCache
1744 function mapClear() {
1745 this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash };
1749 * Removes `key` and its value from the map.
1753 * @memberOf MapCache
1754 * @param {string} key The key of the value to remove.
1755 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1757 function mapDelete(key) {
1758 var data = this.__data__;
1759 if (isKeyable(key)) {
1760 return hashDelete(typeof key == 'string' ? data.string : data.hash, key);
1762 return Map ? data.map['delete'](key) : assocDelete(data.map, key);
1766 * Gets the map value for `key`.
1770 * @memberOf MapCache
1771 * @param {string} key The key of the value to get.
1772 * @returns {*} Returns the entry value.
1774 function mapGet(key) {
1775 var data = this.__data__;
1776 if (isKeyable(key)) {
1777 return hashGet(typeof key == 'string' ? data.string : data.hash, key);
1779 return Map ? data.map.get(key) : assocGet(data.map, key);
1783 * Checks if a map value for `key` exists.
1787 * @memberOf MapCache
1788 * @param {string} key The key of the entry to check.
1789 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1791 function mapHas(key) {
1792 var data = this.__data__;
1793 if (isKeyable(key)) {
1794 return hashHas(typeof key == 'string' ? data.string : data.hash, key);
1796 return Map ? data.map.has(key) : assocHas(data.map, key);
1800 * Sets the map `key` to `value`.
1804 * @memberOf MapCache
1805 * @param {string} key The key of the value to set.
1806 * @param {*} value The value to set.
1807 * @returns {Object} Returns the map cache object.
1809 function mapSet(key, value) {
1810 var data = this.__data__;
1811 if (isKeyable(key)) {
1812 hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
1814 data.map.set(key, value);
1816 assocSet(data.map, key, value);
1821 /*------------------------------------------------------------------------*/
1825 * Creates a set cache object to store unique values.
1828 * @param {Array} [values] The values to cache.
1830 function SetCache(values) {
1832 length = values ? values.length : 0;
1834 this.__data__ = new MapCache;
1835 while (++index < length) {
1836 this.push(values[index]);
1841 * Checks if `value` is in `cache`.
1844 * @param {Object} cache The set cache to search.
1845 * @param {*} value The value to search for.
1846 * @returns {number} Returns `true` if `value` is found, else `false`.
1848 function cacheHas(cache, value) {
1849 var map = cache.__data__;
1850 if (isKeyable(value)) {
1851 var data = map.__data__,
1852 hash = typeof value == 'string' ? data.string : data.hash;
1854 return hash[value] === HASH_UNDEFINED;
1856 return map.has(value);
1860 * Adds `value` to the set cache.
1864 * @memberOf SetCache
1865 * @param {*} value The value to cache.
1867 function cachePush(value) {
1868 var map = this.__data__;
1869 if (isKeyable(value)) {
1870 var data = map.__data__,
1871 hash = typeof value == 'string' ? data.string : data.hash;
1873 hash[value] = HASH_UNDEFINED;
1876 map.set(value, HASH_UNDEFINED);
1880 /*------------------------------------------------------------------------*/
1883 * Creates a stack cache object to store key-value pairs.
1886 * @param {Array} [values] The values to cache.
1888 function Stack(values) {
1890 length = values ? values.length : 0;
1893 while (++index < length) {
1894 var entry = values[index];
1895 this.set(entry[0], entry[1]);
1900 * Removes all key-value entries from the stack.
1906 function stackClear() {
1907 this.__data__ = { 'array': [], 'map': null };
1911 * Removes `key` and its value from the stack.
1916 * @param {string} key The key of the value to remove.
1917 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1919 function stackDelete(key) {
1920 var data = this.__data__,
1923 return array ? assocDelete(array, key) : data.map['delete'](key);
1927 * Gets the stack value for `key`.
1932 * @param {string} key The key of the value to get.
1933 * @returns {*} Returns the entry value.
1935 function stackGet(key) {
1936 var data = this.__data__,
1939 return array ? assocGet(array, key) : data.map.get(key);
1943 * Checks if a stack value for `key` exists.
1948 * @param {string} key The key of the entry to check.
1949 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1951 function stackHas(key) {
1952 var data = this.__data__,
1955 return array ? assocHas(array, key) : data.map.has(key);
1959 * Sets the stack `key` to `value`.
1964 * @param {string} key The key of the value to set.
1965 * @param {*} value The value to set.
1966 * @returns {Object} Returns the stack cache object.
1968 function stackSet(key, value) {
1969 var data = this.__data__,
1973 if (array.length < (LARGE_ARRAY_SIZE - 1)) {
1974 assocSet(array, key, value);
1977 data.map = new MapCache(array);
1982 map.set(key, value);
1987 /*------------------------------------------------------------------------*/
1990 * Removes `key` and its value from the associative array.
1993 * @param {Array} array The array to query.
1994 * @param {string} key The key of the value to remove.
1995 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1997 function assocDelete(array, key) {
1998 var index = assocIndexOf(array, key);
2002 var lastIndex = array.length - 1;
2003 if (index == lastIndex) {
2006 splice.call(array, index, 1);
2012 * Gets the associative array value for `key`.
2015 * @param {Array} array The array to query.
2016 * @param {string} key The key of the value to get.
2017 * @returns {*} Returns the entry value.
2019 function assocGet(array, key) {
2020 var index = assocIndexOf(array, key);
2021 return index < 0 ? undefined : array[index][1];
2025 * Checks if an associative array value for `key` exists.
2028 * @param {Array} array The array to query.
2029 * @param {string} key The key of the entry to check.
2030 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2032 function assocHas(array, key) {
2033 return assocIndexOf(array, key) > -1;
2037 * Gets the index at which the first occurrence of `key` is found in `array`
2038 * of key-value pairs.
2041 * @param {Array} array The array to search.
2042 * @param {*} key The key to search for.
2043 * @returns {number} Returns the index of the matched value, else `-1`.
2045 function assocIndexOf(array, key) {
2046 var length = array.length;
2048 if (eq(array[length][0], key)) {
2056 * Sets the associative array `key` to `value`.
2059 * @param {Array} array The array to modify.
2060 * @param {string} key The key of the value to set.
2061 * @param {*} value The value to set.
2063 function assocSet(array, key, value) {
2064 var index = assocIndexOf(array, key);
2066 array.push([key, value]);
2068 array[index][1] = value;
2072 /*------------------------------------------------------------------------*/
2075 * Used by `_.defaults` to customize its `_.assignIn` use.
2078 * @param {*} objValue The destination value.
2079 * @param {*} srcValue The source value.
2080 * @param {string} key The key of the property to assign.
2081 * @param {Object} object The parent object of `objValue`.
2082 * @returns {*} Returns the value to assign.
2084 function assignInDefaults(objValue, srcValue, key, object) {
2085 if (objValue === undefined ||
2086 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
2093 * This function is like `assignValue` except that it doesn't assign `undefined` values.
2096 * @param {Object} object The object to modify.
2097 * @param {string} key The key of the property to assign.
2098 * @param {*} value The value to assign.
2100 function assignMergeValue(object, key, value) {
2101 if ((value !== undefined && !eq(object[key], value)) ||
2102 (typeof key == 'number' && value === undefined && !(key in object))) {
2103 object[key] = value;
2108 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2109 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2110 * for equality comparisons.
2113 * @param {Object} object The object to modify.
2114 * @param {string} key The key of the property to assign.
2115 * @param {*} value The value to assign.
2117 function assignValue(object, key, value) {
2118 var objValue = object[key];
2119 if ((!eq(objValue, value) ||
2120 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
2121 (value === undefined && !(key in object))) {
2122 object[key] = value;
2127 * The base implementation of `_.assign` without support for multiple sources
2128 * or `customizer` functions.
2131 * @param {Object} object The destination object.
2132 * @param {Object} source The source object.
2133 * @returns {Object} Returns `object`.
2135 function baseAssign(object, source) {
2136 return object && copyObject(source, keys(source), object);
2140 * The base implementation of `_.at` without support for individual paths.
2143 * @param {Object} object The object to iterate over.
2144 * @param {string[]} paths The property paths of elements to pick.
2145 * @returns {Array} Returns the new array of picked elements.
2147 function baseAt(object, paths) {
2149 isNil = object == null,
2150 length = paths.length,
2151 result = Array(length);
2153 while (++index < length) {
2154 result[index] = isNil ? undefined : get(object, paths[index]);
2160 * The base implementation of `_.clamp` which doesn't coerce arguments to numbers.
2163 * @param {number} number The number to clamp.
2164 * @param {number} [lower] The lower bound.
2165 * @param {number} upper The upper bound.
2166 * @returns {number} Returns the clamped number.
2168 function baseClamp(number, lower, upper) {
2169 if (number === number) {
2170 if (upper !== undefined) {
2171 number = number <= upper ? number : upper;
2173 if (lower !== undefined) {
2174 number = number >= lower ? number : lower;
2181 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2182 * traversed objects.
2185 * @param {*} value The value to clone.
2186 * @param {boolean} [isDeep] Specify a deep clone.
2187 * @param {Function} [customizer] The function to customize cloning.
2188 * @param {string} [key] The key of `value`.
2189 * @param {Object} [object] The parent object of `value`.
2190 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2191 * @returns {*} Returns the cloned value.
2193 function baseClone(value, isDeep, customizer, key, object, stack) {
2196 result = object ? customizer(value, key, object, stack) : customizer(value);
2198 if (result !== undefined) {
2201 if (!isObject(value)) {
2204 var isArr = isArray(value);
2206 result = initCloneArray(value);
2208 return copyArray(value, result);
2211 var tag = getTag(value),
2212 isFunc = tag == funcTag || tag == genTag;
2214 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2215 if (isHostObject(value)) {
2216 return object ? value : {};
2218 result = initCloneObject(isFunc ? {} : value);
2220 return copySymbols(value, baseAssign(result, value));
2223 return cloneableTags[tag]
2224 ? initCloneByTag(value, tag, isDeep)
2225 : (object ? value : {});
2228 // Check for circular references and return its corresponding clone.
2229 stack || (stack = new Stack);
2230 var stacked = stack.get(value);
2234 stack.set(value, result);
2236 // Recursively populate clone (susceptible to call stack limits).
2237 (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
2238 assignValue(result, key, baseClone(subValue, isDeep, customizer, key, value, stack));
2240 return isArr ? result : copySymbols(value, result);
2244 * The base implementation of `_.conforms` which doesn't clone `source`.
2247 * @param {Object} source The object of property predicates to conform to.
2248 * @returns {Function} Returns the new function.
2250 function baseConforms(source) {
2251 var props = keys(source),
2252 length = props.length;
2254 return function(object) {
2255 if (object == null) {
2260 var key = props[index],
2261 predicate = source[key],
2262 value = object[key];
2264 if ((value === undefined && !(key in Object(object))) || !predicate(value)) {
2273 * The base implementation of `_.create` without support for assigning
2274 * properties to the created object.
2277 * @param {Object} prototype The object to inherit from.
2278 * @returns {Object} Returns the new object.
2280 var baseCreate = (function() {
2281 function object() {}
2282 return function(prototype) {
2283 if (isObject(prototype)) {
2284 object.prototype = prototype;
2285 var result = new object;
2286 object.prototype = undefined;
2288 return result || {};
2293 * The base implementation of `_.delay` and `_.defer` which accepts an array
2294 * of `func` arguments.
2297 * @param {Function} func The function to delay.
2298 * @param {number} wait The number of milliseconds to delay invocation.
2299 * @param {Object} args The arguments provide to `func`.
2300 * @returns {number} Returns the timer id.
2302 function baseDelay(func, wait, args) {
2303 if (typeof func != 'function') {
2304 throw new TypeError(FUNC_ERROR_TEXT);
2306 return setTimeout(function() { func.apply(undefined, args); }, wait);
2310 * The base implementation of methods like `_.difference` without support for
2311 * excluding multiple arrays or iteratee shorthands.
2314 * @param {Array} array The array to inspect.
2315 * @param {Array} values The values to exclude.
2316 * @param {Function} [iteratee] The iteratee invoked per element.
2317 * @param {Function} [comparator] The comparator invoked per element.
2318 * @returns {Array} Returns the new array of filtered values.
2320 function baseDifference(array, values, iteratee, comparator) {
2322 includes = arrayIncludes,
2324 length = array.length,
2326 valuesLength = values.length;
2332 values = arrayMap(values, baseUnary(iteratee));
2335 includes = arrayIncludesWith;
2338 else if (values.length >= LARGE_ARRAY_SIZE) {
2339 includes = cacheHas;
2341 values = new SetCache(values);
2344 while (++index < length) {
2345 var value = array[index],
2346 computed = iteratee ? iteratee(value) : value;
2348 if (isCommon && computed === computed) {
2349 var valuesIndex = valuesLength;
2350 while (valuesIndex--) {
2351 if (values[valuesIndex] === computed) {
2357 else if (!includes(values, computed, comparator)) {
2365 * The base implementation of `_.forEach` without support for iteratee shorthands.
2368 * @param {Array|Object} collection The collection to iterate over.
2369 * @param {Function} iteratee The function invoked per iteration.
2370 * @returns {Array|Object} Returns `collection`.
2372 var baseEach = createBaseEach(baseForOwn);
2375 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2378 * @param {Array|Object} collection The collection to iterate over.
2379 * @param {Function} iteratee The function invoked per iteration.
2380 * @returns {Array|Object} Returns `collection`.
2382 var baseEachRight = createBaseEach(baseForOwnRight, true);
2385 * The base implementation of `_.every` without support for iteratee shorthands.
2388 * @param {Array|Object} collection The collection to iterate over.
2389 * @param {Function} predicate The function invoked per iteration.
2390 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
2392 function baseEvery(collection, predicate) {
2394 baseEach(collection, function(value, index, collection) {
2395 result = !!predicate(value, index, collection);
2402 * The base implementation of `_.fill` without an iteratee call guard.
2405 * @param {Array} array The array to fill.
2406 * @param {*} value The value to fill `array` with.
2407 * @param {number} [start=0] The start position.
2408 * @param {number} [end=array.length] The end position.
2409 * @returns {Array} Returns `array`.
2411 function baseFill(array, value, start, end) {
2412 var length = array.length;
2414 start = toInteger(start);
2416 start = -start > length ? 0 : (length + start);
2418 end = (end === undefined || end > length) ? length : toInteger(end);
2422 end = start > end ? 0 : toLength(end);
2423 while (start < end) {
2424 array[start++] = value;
2430 * The base implementation of `_.filter` without support for iteratee shorthands.
2433 * @param {Array|Object} collection The collection to iterate over.
2434 * @param {Function} predicate The function invoked per iteration.
2435 * @returns {Array} Returns the new filtered array.
2437 function baseFilter(collection, predicate) {
2439 baseEach(collection, function(value, index, collection) {
2440 if (predicate(value, index, collection)) {
2448 * The base implementation of `_.flatten` with support for restricting flattening.
2451 * @param {Array} array The array to flatten.
2452 * @param {boolean} [isDeep] Specify a deep flatten.
2453 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
2454 * @param {Array} [result=[]] The initial result value.
2455 * @returns {Array} Returns the new flattened array.
2457 function baseFlatten(array, isDeep, isStrict, result) {
2458 result || (result = []);
2461 length = array.length;
2463 while (++index < length) {
2464 var value = array[index];
2465 if (isArrayLikeObject(value) &&
2466 (isStrict || isArray(value) || isArguments(value))) {
2468 // Recursively flatten arrays (susceptible to call stack limits).
2469 baseFlatten(value, isDeep, isStrict, result);
2471 arrayPush(result, value);
2473 } else if (!isStrict) {
2474 result[result.length] = value;
2481 * The base implementation of `baseForIn` and `baseForOwn` which iterates
2482 * over `object` properties returned by `keysFunc` invoking `iteratee` for
2483 * each property. Iteratee functions may exit iteration early by explicitly
2484 * returning `false`.
2487 * @param {Object} object The object to iterate over.
2488 * @param {Function} iteratee The function invoked per iteration.
2489 * @param {Function} keysFunc The function to get the keys of `object`.
2490 * @returns {Object} Returns `object`.
2492 var baseFor = createBaseFor();
2495 * This function is like `baseFor` except that it iterates over properties
2496 * in the opposite order.
2499 * @param {Object} object The object to iterate over.
2500 * @param {Function} iteratee The function invoked per iteration.
2501 * @param {Function} keysFunc The function to get the keys of `object`.
2502 * @returns {Object} Returns `object`.
2504 var baseForRight = createBaseFor(true);
2507 * The base implementation of `_.forIn` without support for iteratee shorthands.
2510 * @param {Object} object The object to iterate over.
2511 * @param {Function} iteratee The function invoked per iteration.
2512 * @returns {Object} Returns `object`.
2514 function baseForIn(object, iteratee) {
2515 return object == null ? object : baseFor(object, iteratee, keysIn);
2519 * The base implementation of `_.forOwn` without support for iteratee shorthands.
2522 * @param {Object} object The object to iterate over.
2523 * @param {Function} iteratee The function invoked per iteration.
2524 * @returns {Object} Returns `object`.
2526 function baseForOwn(object, iteratee) {
2527 return object && baseFor(object, iteratee, keys);
2531 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
2534 * @param {Object} object The object to iterate over.
2535 * @param {Function} iteratee The function invoked per iteration.
2536 * @returns {Object} Returns `object`.
2538 function baseForOwnRight(object, iteratee) {
2539 return object && baseForRight(object, iteratee, keys);
2543 * The base implementation of `_.functions` which creates an array of
2544 * `object` function property names filtered from those provided.
2547 * @param {Object} object The object to inspect.
2548 * @param {Array} props The property names to filter.
2549 * @returns {Array} Returns the new array of filtered property names.
2551 function baseFunctions(object, props) {
2552 return arrayFilter(props, function(key) {
2553 return isFunction(object[key]);
2558 * The base implementation of `_.get` without support for default values.
2561 * @param {Object} object The object to query.
2562 * @param {Array|string} path The path of the property to get.
2563 * @returns {*} Returns the resolved value.
2565 function baseGet(object, path) {
2566 path = isKey(path, object) ? [path + ''] : baseToPath(path);
2569 length = path.length;
2571 while (object != null && index < length) {
2572 object = object[path[index++]];
2574 return (index && index == length) ? object : undefined;
2578 * The base implementation of `_.has` without support for deep paths.
2581 * @param {Object} object The object to query.
2582 * @param {Array|string} key The key to check.
2583 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2585 function baseHas(object, key) {
2586 // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
2587 // that are composed entirely of index properties, return `false` for
2588 // `hasOwnProperty` checks of them.
2589 return hasOwnProperty.call(object, key) ||
2590 (typeof object == 'object' && key in object && getPrototypeOf(object) === null);
2594 * The base implementation of `_.hasIn` without support for deep paths.
2597 * @param {Object} object The object to query.
2598 * @param {Array|string} key The key to check.
2599 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2601 function baseHasIn(object, key) {
2602 return key in Object(object);
2606 * The base implementation of `_.inRange` which doesn't coerce arguments to numbers.
2609 * @param {number} number The number to check.
2610 * @param {number} start The start of the range.
2611 * @param {number} end The end of the range.
2612 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
2614 function baseInRange(number, start, end) {
2615 return number >= nativeMin(start, end) && number < nativeMax(start, end);
2619 * The base implementation of methods like `_.intersection`, without support
2620 * for iteratee shorthands, that accepts an array of arrays to inspect.
2623 * @param {Array} arrays The arrays to inspect.
2624 * @param {Function} [iteratee] The iteratee invoked per element.
2625 * @param {Function} [comparator] The comparator invoked per element.
2626 * @returns {Array} Returns the new array of shared values.
2628 function baseIntersection(arrays, iteratee, comparator) {
2629 var includes = comparator ? arrayIncludesWith : arrayIncludes,
2630 othLength = arrays.length,
2631 othIndex = othLength,
2632 caches = Array(othLength),
2635 while (othIndex--) {
2636 var array = arrays[othIndex];
2637 if (othIndex && iteratee) {
2638 array = arrayMap(array, baseUnary(iteratee));
2640 caches[othIndex] = !comparator && (iteratee || array.length >= 120)
2641 ? new SetCache(othIndex && array)
2647 length = array.length,
2651 while (++index < length) {
2652 var value = array[index],
2653 computed = iteratee ? iteratee(value) : value;
2655 if (!(seen ? cacheHas(seen, computed) : includes(result, computed, comparator))) {
2656 var othIndex = othLength;
2657 while (--othIndex) {
2658 var cache = caches[othIndex];
2659 if (!(cache ? cacheHas(cache, computed) : includes(arrays[othIndex], computed, comparator))) {
2664 seen.push(computed);
2673 * The base implementation of `_.invoke` without support for individual
2677 * @param {Object} object The object to query.
2678 * @param {Array|string} path The path of the method to invoke.
2679 * @param {Array} args The arguments to invoke the method with.
2680 * @returns {*} Returns the result of the invoked method.
2682 function baseInvoke(object, path, args) {
2683 if (!isKey(path, object)) {
2684 path = baseToPath(path);
2685 object = parent(object, path);
2688 var func = object == null ? object : object[path];
2689 return func == null ? undefined : apply(func, object, args);
2693 * The base implementation of `_.isEqual` which supports partial comparisons
2694 * and tracks traversed objects.
2697 * @param {*} value The value to compare.
2698 * @param {*} other The other value to compare.
2699 * @param {Function} [customizer] The function to customize comparisons.
2700 * @param {boolean} [bitmask] The bitmask of comparison flags.
2701 * The bitmask may be composed of the following flags:
2702 * 1 - Unordered comparison
2703 * 2 - Partial comparison
2704 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
2705 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2707 function baseIsEqual(value, other, customizer, bitmask, stack) {
2708 if (value === other) {
2711 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
2712 return value !== value && other !== other;
2714 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
2718 * A specialized version of `baseIsEqual` for arrays and objects which performs
2719 * deep comparisons and tracks traversed objects enabling objects with circular
2720 * references to be compared.
2723 * @param {Object} object The object to compare.
2724 * @param {Object} other The other object to compare.
2725 * @param {Function} equalFunc The function to determine equivalents of values.
2726 * @param {Function} [customizer] The function to customize comparisons.
2727 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
2728 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
2729 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2731 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
2732 var objIsArr = isArray(object),
2733 othIsArr = isArray(other),
2738 objTag = getTag(object);
2739 if (objTag == argsTag) {
2741 } else if (objTag != objectTag) {
2742 objIsArr = isTypedArray(object);
2746 othTag = getTag(other);
2747 if (othTag == argsTag) {
2749 } else if (othTag != objectTag) {
2750 othIsArr = isTypedArray(other);
2753 var objIsObj = objTag == objectTag && !isHostObject(object),
2754 othIsObj = othTag == objectTag && !isHostObject(other),
2755 isSameTag = objTag == othTag;
2757 if (isSameTag && !(objIsArr || objIsObj)) {
2758 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
2760 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
2762 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2763 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2765 if (objIsWrapped || othIsWrapped) {
2766 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
2772 stack || (stack = new Stack);
2773 return (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
2777 * The base implementation of `_.isMatch` without support for iteratee shorthands.
2780 * @param {Object} object The object to inspect.
2781 * @param {Object} source The object of property values to match.
2782 * @param {Array} matchData The property names, values, and compare flags to match.
2783 * @param {Function} [customizer] The function to customize comparisons.
2784 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2786 function baseIsMatch(object, source, matchData, customizer) {
2787 var index = matchData.length,
2789 noCustomizer = !customizer;
2791 if (object == null) {
2794 object = Object(object);
2796 var data = matchData[index];
2797 if ((noCustomizer && data[2])
2798 ? data[1] !== object[data[0]]
2799 : !(data[0] in object)
2804 while (++index < length) {
2805 data = matchData[index];
2807 objValue = object[key],
2810 if (noCustomizer && data[2]) {
2811 if (objValue === undefined && !(key in object)) {
2815 var stack = new Stack,
2816 result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined;
2818 if (!(result === undefined
2819 ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
2830 * The base implementation of `_.iteratee`.
2833 * @param {*} [value=_.identity] The value to convert to an iteratee.
2834 * @returns {Function} Returns the iteratee.
2836 function baseIteratee(value) {
2837 var type = typeof value;
2838 if (type == 'function') {
2841 if (value == null) {
2844 if (type == 'object') {
2845 return isArray(value)
2846 ? baseMatchesProperty(value[0], value[1])
2847 : baseMatches(value);
2849 return property(value);
2853 * The base implementation of `_.keys` which doesn't skip the constructor
2854 * property of prototypes or treat sparse arrays as dense.
2858 * @param {Object} object The object to query.
2859 * @returns {Array} Returns the array of property names.
2861 function baseKeys(object) {
2862 return nativeKeys(Object(object));
2866 * The base implementation of `_.keysIn` which doesn't skip the constructor
2867 * property of prototypes or treat sparse arrays as dense.
2870 * @param {Object} object The object to query.
2871 * @returns {Array} Returns the array of property names.
2873 function baseKeysIn(object) {
2874 object = object == null ? object : Object(object);
2877 for (var key in object) {
2883 // Fallback for IE < 9 with es6-shim.
2884 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
2885 baseKeysIn = function(object) {
2886 return iteratorToArray(enumerate(object));
2891 * The base implementation of `_.map` without support for iteratee shorthands.
2894 * @param {Array|Object} collection The collection to iterate over.
2895 * @param {Function} iteratee The function invoked per iteration.
2896 * @returns {Array} Returns the new mapped array.
2898 function baseMap(collection, iteratee) {
2900 result = isArrayLike(collection) ? Array(collection.length) : [];
2902 baseEach(collection, function(value, key, collection) {
2903 result[++index] = iteratee(value, key, collection);
2909 * The base implementation of `_.matches` which doesn't clone `source`.
2912 * @param {Object} source The object of property values to match.
2913 * @returns {Function} Returns the new function.
2915 function baseMatches(source) {
2916 var matchData = getMatchData(source);
2917 if (matchData.length == 1 && matchData[0][2]) {
2918 var key = matchData[0][0],
2919 value = matchData[0][1];
2921 return function(object) {
2922 if (object == null) {
2925 return object[key] === value &&
2926 (value !== undefined || (key in Object(object)));
2929 return function(object) {
2930 return object === source || baseIsMatch(object, source, matchData);
2935 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
2938 * @param {string} path The path of the property to get.
2939 * @param {*} srcValue The value to match.
2940 * @returns {Function} Returns the new function.
2942 function baseMatchesProperty(path, srcValue) {
2943 return function(object) {
2944 var objValue = get(object, path);
2945 return (objValue === undefined && objValue === srcValue)
2946 ? hasIn(object, path)
2947 : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
2952 * The base implementation of `_.merge` without support for multiple sources.
2955 * @param {Object} object The destination object.
2956 * @param {Object} source The source object.
2957 * @param {number} srcIndex The index of `source`.
2958 * @param {Function} [customizer] The function to customize merged values.
2959 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
2961 function baseMerge(object, source, srcIndex, customizer, stack) {
2962 if (object === source) {
2965 var props = (isArray(source) || isTypedArray(source)) ? undefined : keysIn(source);
2966 arrayEach(props || source, function(srcValue, key) {
2969 srcValue = source[key];
2971 if (isObject(srcValue)) {
2972 stack || (stack = new Stack);
2973 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
2976 var newValue = customizer ? customizer(object[key], srcValue, (key + ''), object, source, stack) : undefined;
2977 if (newValue === undefined) {
2978 newValue = srcValue;
2980 assignMergeValue(object, key, newValue);
2986 * A specialized version of `baseMerge` for arrays and objects which performs
2987 * deep merges and tracks traversed objects enabling objects with circular
2988 * references to be merged.
2991 * @param {Object} object The destination object.
2992 * @param {Object} source The source object.
2993 * @param {string} key The key of the value to merge.
2994 * @param {number} srcIndex The index of `source`.
2995 * @param {Function} mergeFunc The function to merge values.
2996 * @param {Function} [customizer] The function to customize assigned values.
2997 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
2999 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3000 var objValue = object[key],
3001 srcValue = source[key],
3002 stacked = stack.get(srcValue) || stack.get(objValue);
3005 assignMergeValue(object, key, stacked);
3008 var newValue = customizer ? customizer(objValue, srcValue, (key + ''), object, source, stack) : undefined,
3009 isCommon = newValue === undefined;
3012 newValue = srcValue;
3013 if (isArray(srcValue) || isTypedArray(srcValue)) {
3014 if (isArray(objValue)) {
3015 newValue = srcIndex ? copyArray(objValue) : objValue;
3017 else if (isArrayLikeObject(objValue)) {
3018 newValue = copyArray(objValue);
3021 newValue = baseClone(srcValue);
3024 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3025 if (isArguments(objValue)) {
3026 newValue = toPlainObject(objValue);
3028 else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
3029 newValue = baseClone(srcValue);
3032 newValue = srcIndex ? baseClone(objValue) : objValue;
3039 stack.set(srcValue, newValue);
3042 // Recursively merge objects and arrays (susceptible to call stack limits).
3043 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3045 assignMergeValue(object, key, newValue);
3049 * The base implementation of `_.orderBy` without param guards.
3052 * @param {Array|Object} collection The collection to iterate over.
3053 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3054 * @param {string[]} orders The sort orders of `iteratees`.
3055 * @returns {Array} Returns the new sorted array.
3057 function baseOrderBy(collection, iteratees, orders) {
3059 toIteratee = getIteratee();
3061 iteratees = arrayMap(iteratees.length ? iteratees : Array(1), function(iteratee) {
3062 return toIteratee(iteratee);
3065 var result = baseMap(collection, function(value, key, collection) {
3066 var criteria = arrayMap(iteratees, function(iteratee) {
3067 return iteratee(value);
3069 return { 'criteria': criteria, 'index': ++index, 'value': value };
3072 return baseSortBy(result, function(object, other) {
3073 return compareMultiple(object, other, orders);
3078 * The base implementation of `_.pick` without support for individual
3082 * @param {Object} object The source object.
3083 * @param {string[]} props The property names to pick.
3084 * @returns {Object} Returns the new object.
3086 function basePick(object, props) {
3087 object = Object(object);
3088 return arrayReduce(props, function(result, key) {
3089 if (key in object) {
3090 result[key] = object[key];
3097 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3100 * @param {Object} object The source object.
3101 * @param {Function} predicate The function invoked per property.
3102 * @returns {Object} Returns the new object.
3104 function basePickBy(object, predicate) {
3106 baseForIn(object, function(value, key) {
3107 if (predicate(value, key)) {
3108 result[key] = value;
3115 * The base implementation of `_.property` without support for deep paths.
3118 * @param {string} key The key of the property to get.
3119 * @returns {Function} Returns the new function.
3121 function baseProperty(key) {
3122 return function(object) {
3123 return object == null ? undefined : object[key];
3128 * A specialized version of `baseProperty` which supports deep paths.
3131 * @param {Array|string} path The path of the property to get.
3132 * @returns {Function} Returns the new function.
3134 function basePropertyDeep(path) {
3135 return function(object) {
3136 return baseGet(object, path);
3141 * The base implementation of `_.pullAll`.
3144 * @param {Array} array The array to modify.
3145 * @param {Array} values The values to remove.
3146 * @returns {Array} Returns `array`.
3148 function basePullAll(array, values) {
3149 return basePullAllBy(array, values);
3153 * The base implementation of `_.pullAllBy` without support for iteratee
3157 * @param {Array} array The array to modify.
3158 * @param {Array} values The values to remove.
3159 * @param {Function} [iteratee] The iteratee invoked per element.
3160 * @returns {Array} Returns `array`.
3162 function basePullAllBy(array, values, iteratee) {
3164 length = values.length,
3168 seen = arrayMap(array, function(value) { return iteratee(value); });
3170 while (++index < length) {
3172 value = values[index],
3173 computed = iteratee ? iteratee(value) : value;
3175 while ((fromIndex = baseIndexOf(seen, computed, fromIndex)) > -1) {
3176 if (seen !== array) {
3177 splice.call(seen, fromIndex, 1);
3179 splice.call(array, fromIndex, 1);
3186 * The base implementation of `_.pullAt` without support for individual
3187 * indexes or capturing the removed elements.
3190 * @param {Array} array The array to modify.
3191 * @param {number[]} indexes The indexes of elements to remove.
3192 * @returns {Array} Returns `array`.
3194 function basePullAt(array, indexes) {
3195 var length = array ? indexes.length : 0,
3196 lastIndex = length - 1;
3199 var index = indexes[length];
3200 if (lastIndex == length || index != previous) {
3201 var previous = index;
3202 if (isIndex(index)) {
3203 splice.call(array, index, 1);
3205 else if (!isKey(index, array)) {
3206 var path = baseToPath(index),
3207 object = parent(array, path);
3209 if (object != null) {
3210 delete object[last(path)];
3214 delete array[index];
3222 * The base implementation of `_.random` without support for returning
3223 * floating-point numbers.
3226 * @param {number} lower The lower bound.
3227 * @param {number} upper The upper bound.
3228 * @returns {number} Returns the random number.
3230 function baseRandom(lower, upper) {
3231 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3235 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3236 * coerce arguments to numbers.
3239 * @param {number} start The start of the range.
3240 * @param {number} end The end of the range.
3241 * @param {number} step The value to increment or decrement by.
3242 * @param {boolean} [fromRight] Specify iterating from right to left.
3243 * @returns {Array} Returns the new array of numbers.
3245 function baseRange(start, end, step, fromRight) {
3247 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3248 result = Array(length);
3251 result[fromRight ? length : ++index] = start;
3258 * The base implementation of `_.set`.
3261 * @param {Object} object The object to query.
3262 * @param {Array|string} path The path of the property to set.
3263 * @param {*} value The value to set.
3264 * @param {Function} [customizer] The function to customize path creation.
3265 * @returns {Object} Returns `object`.
3267 function baseSet(object, path, value, customizer) {
3268 path = isKey(path, object) ? [path + ''] : baseToPath(path);
3271 length = path.length,
3272 lastIndex = length - 1,
3275 while (nested != null && ++index < length) {
3276 var key = path[index];
3277 if (isObject(nested)) {
3278 var newValue = value;
3279 if (index != lastIndex) {
3280 var objValue = nested[key];
3281 newValue = customizer ? customizer(objValue, key, nested) : undefined;
3282 if (newValue === undefined) {
3283 newValue = objValue == null ? (isIndex(path[index + 1]) ? [] : {}) : objValue;
3286 assignValue(nested, key, newValue);
3288 nested = nested[key];
3294 * The base implementation of `setData` without support for hot loop detection.
3297 * @param {Function} func The function to associate metadata with.
3298 * @param {*} data The metadata.
3299 * @returns {Function} Returns `func`.
3301 var baseSetData = !metaMap ? identity : function(func, data) {
3302 metaMap.set(func, data);
3307 * The base implementation of `_.slice` without an iteratee call guard.
3310 * @param {Array} array The array to slice.
3311 * @param {number} [start=0] The start position.
3312 * @param {number} [end=array.length] The end position.
3313 * @returns {Array} Returns the slice of `array`.
3315 function baseSlice(array, start, end) {
3317 length = array.length;
3320 start = -start > length ? 0 : (length + start);
3322 end = end > length ? length : end;
3326 length = start > end ? 0 : ((end - start) >>> 0);
3329 var result = Array(length);
3330 while (++index < length) {
3331 result[index] = array[index + start];
3337 * The base implementation of `_.some` without support for iteratee shorthands.
3340 * @param {Array|Object} collection The collection to iterate over.
3341 * @param {Function} predicate The function invoked per iteration.
3342 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
3344 function baseSome(collection, predicate) {
3347 baseEach(collection, function(value, index, collection) {
3348 result = predicate(value, index, collection);
3355 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
3356 * performs a binary search of `array` to determine the index at which `value`
3357 * should be inserted into `array` in order to maintain its sort order.
3360 * @param {Array} array The sorted array to inspect.
3361 * @param {*} value The value to evaluate.
3362 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3363 * @returns {number} Returns the index at which `value` should be inserted
3366 function baseSortedIndex(array, value, retHighest) {
3368 high = array ? array.length : low;
3370 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
3371 while (low < high) {
3372 var mid = (low + high) >>> 1,
3373 computed = array[mid];
3375 if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
3383 return baseSortedIndexBy(array, value, identity, retHighest);
3387 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
3388 * which invokes `iteratee` for `value` and each element of `array` to compute
3389 * their sort ranking. The iteratee is invoked with one argument; (value).
3392 * @param {Array} array The sorted array to inspect.
3393 * @param {*} value The value to evaluate.
3394 * @param {Function} iteratee The iteratee invoked per element.
3395 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3396 * @returns {number} Returns the index at which `value` should be inserted into `array`.
3398 function baseSortedIndexBy(array, value, iteratee, retHighest) {
3399 value = iteratee(value);
3402 high = array ? array.length : 0,
3403 valIsNaN = value !== value,
3404 valIsNull = value === null,
3405 valIsUndef = value === undefined;
3407 while (low < high) {
3408 var mid = nativeFloor((low + high) / 2),
3409 computed = iteratee(array[mid]),
3410 isDef = computed !== undefined,
3411 isReflexive = computed === computed;
3414 var setLow = isReflexive || retHighest;
3415 } else if (valIsNull) {
3416 setLow = isReflexive && isDef && (retHighest || computed != null);
3417 } else if (valIsUndef) {
3418 setLow = isReflexive && (retHighest || isDef);
3419 } else if (computed == null) {
3422 setLow = retHighest ? (computed <= value) : (computed < value);
3430 return nativeMin(high, MAX_ARRAY_INDEX);
3434 * The base implementation of `_.sortedUniq`.
3437 * @param {Array} array The array to inspect.
3438 * @returns {Array} Returns the new duplicate free array.
3440 function baseSortedUniq(array) {
3441 return baseSortedUniqBy(array);
3445 * The base implementation of `_.sortedUniqBy` without support for iteratee
3449 * @param {Array} array The array to inspect.
3450 * @param {Function} [iteratee] The iteratee invoked per element.
3451 * @returns {Array} Returns the new duplicate free array.
3453 function baseSortedUniqBy(array, iteratee) {
3455 length = array.length,
3457 computed = iteratee ? iteratee(value) : value,
3462 while (++index < length) {
3463 value = array[index],
3464 computed = iteratee ? iteratee(value) : value;
3466 if (!eq(computed, seen)) {
3468 result[++resIndex] = value;
3475 * The base implementation of `_.toPath` which only converts `value` to a
3476 * path if it's not one.
3479 * @param {*} value The value to process.
3480 * @returns {Array} Returns the property path array.
3482 function baseToPath(value) {
3483 return isArray(value) ? value : stringToPath(value);
3487 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
3490 * @param {Array} array The array to inspect.
3491 * @param {Function} [iteratee] The iteratee invoked per element.
3492 * @param {Function} [comparator] The comparator invoked per element.
3493 * @returns {Array} Returns the new duplicate free array.
3495 function baseUniq(array, iteratee, comparator) {
3497 includes = arrayIncludes,
3498 length = array.length,
3505 includes = arrayIncludesWith;
3507 else if (length >= LARGE_ARRAY_SIZE) {
3508 var set = iteratee ? null : createSet(array);
3510 return setToArray(set);
3513 includes = cacheHas;
3514 seen = new SetCache;
3517 seen = iteratee ? [] : result;
3520 while (++index < length) {
3521 var value = array[index],
3522 computed = iteratee ? iteratee(value) : value;
3524 if (isCommon && computed === computed) {
3525 var seenIndex = seen.length;
3526 while (seenIndex--) {
3527 if (seen[seenIndex] === computed) {
3532 seen.push(computed);
3536 else if (!includes(seen, computed, comparator)) {
3537 if (seen !== result) {
3538 seen.push(computed);
3547 * The base implementation of `_.unset`.
3550 * @param {Object} object The object to modify.
3551 * @param {Array|string} path The path of the property to unset.
3552 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
3554 function baseUnset(object, path) {
3555 path = isKey(path, object) ? [path + ''] : baseToPath(path);
3556 object = parent(object, path);
3557 var key = last(path);
3558 return (object != null && has(object, key)) ? delete object[key] : true;
3562 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
3563 * without support for iteratee shorthands.
3566 * @param {Array} array The array to query.
3567 * @param {Function} predicate The function invoked per iteration.
3568 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
3569 * @param {boolean} [fromRight] Specify iterating from right to left.
3570 * @returns {Array} Returns the slice of `array`.
3572 function baseWhile(array, predicate, isDrop, fromRight) {
3573 var length = array.length,
3574 index = fromRight ? length : -1;
3576 while ((fromRight ? index-- : ++index < length) &&
3577 predicate(array[index], index, array)) {}
3580 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
3581 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
3585 * The base implementation of `wrapperValue` which returns the result of
3586 * performing a sequence of actions on the unwrapped `value`, where each
3587 * successive action is supplied the return value of the previous.
3590 * @param {*} value The unwrapped value.
3591 * @param {Array} actions Actions to perform to resolve the unwrapped value.
3592 * @returns {*} Returns the resolved value.
3594 function baseWrapperValue(value, actions) {
3596 if (result instanceof LazyWrapper) {
3597 result = result.value();
3599 return arrayReduce(actions, function(result, action) {
3600 return action.func.apply(action.thisArg, arrayPush([result], action.args));
3605 * The base implementation of methods like `_.xor`, without support for
3606 * iteratee shorthands, that accepts an array of arrays to inspect.
3609 * @param {Array} arrays The arrays to inspect.
3610 * @param {Function} [iteratee] The iteratee invoked per element.
3611 * @param {Function} [comparator] The comparator invoked per element.
3612 * @returns {Array} Returns the new array of values.
3614 function baseXor(arrays, iteratee, comparator) {
3616 length = arrays.length;
3618 while (++index < length) {
3621 baseDifference(result, arrays[index], iteratee, comparator),
3622 baseDifference(arrays[index], result, iteratee, comparator)
3626 return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
3630 * Creates a clone of `buffer`.
3633 * @param {ArrayBuffer} buffer The array buffer to clone.
3634 * @returns {ArrayBuffer} Returns the cloned array buffer.
3636 function cloneBuffer(buffer) {
3637 var Ctor = buffer.constructor,
3638 result = new Ctor(buffer.byteLength),
3639 view = new Uint8Array(result);
3641 view.set(new Uint8Array(buffer));
3646 * Creates a clone of `map`.
3649 * @param {Object} map The map to clone.
3650 * @returns {Object} Returns the cloned map.
3652 function cloneMap(map) {
3653 var Ctor = map.constructor;
3654 return arrayReduce(mapToArray(map), addMapEntry, new Ctor);
3658 * Creates a clone of `regexp`.
3661 * @param {Object} regexp The regexp to clone.
3662 * @returns {Object} Returns the cloned regexp.
3664 function cloneRegExp(regexp) {
3665 var Ctor = regexp.constructor,
3666 result = new Ctor(regexp.source, reFlags.exec(regexp));
3668 result.lastIndex = regexp.lastIndex;
3673 * Creates a clone of `set`.
3676 * @param {Object} set The set to clone.
3677 * @returns {Object} Returns the cloned set.
3679 function cloneSet(set) {
3680 var Ctor = set.constructor;
3681 return arrayReduce(setToArray(set), addSetEntry, new Ctor);
3685 * Creates a clone of the `symbol` object.
3688 * @param {Object} symbol The symbol object to clone.
3689 * @returns {Object} Returns the cloned symbol object.
3691 function cloneSymbol(symbol) {
3692 return Symbol ? Object(symbolValueOf.call(symbol)) : {};
3696 * Creates a clone of `typedArray`.
3699 * @param {Object} typedArray The typed array to clone.
3700 * @param {boolean} [isDeep] Specify a deep clone.
3701 * @returns {Object} Returns the cloned typed array.
3703 function cloneTypedArray(typedArray, isDeep) {
3704 var buffer = typedArray.buffer,
3705 Ctor = typedArray.constructor;
3707 return new Ctor(isDeep ? cloneBuffer(buffer) : buffer, typedArray.byteOffset, typedArray.length);
3711 * Creates an array that is the composition of partially applied arguments,
3712 * placeholders, and provided arguments into a single array of arguments.
3715 * @param {Array|Object} args The provided arguments.
3716 * @param {Array} partials The arguments to prepend to those provided.
3717 * @param {Array} holders The `partials` placeholder indexes.
3718 * @returns {Array} Returns the new array of composed arguments.
3720 function composeArgs(args, partials, holders) {
3721 var holdersLength = holders.length,
3723 argsLength = nativeMax(args.length - holdersLength, 0),
3725 leftLength = partials.length,
3726 result = Array(leftLength + argsLength);
3728 while (++leftIndex < leftLength) {
3729 result[leftIndex] = partials[leftIndex];
3731 while (++argsIndex < holdersLength) {
3732 result[holders[argsIndex]] = args[argsIndex];
3734 while (argsLength--) {
3735 result[leftIndex++] = args[argsIndex++];
3741 * This function is like `composeArgs` except that the arguments composition
3742 * is tailored for `_.partialRight`.
3745 * @param {Array|Object} args The provided arguments.
3746 * @param {Array} partials The arguments to append to those provided.
3747 * @param {Array} holders The `partials` placeholder indexes.
3748 * @returns {Array} Returns the new array of composed arguments.
3750 function composeArgsRight(args, partials, holders) {
3751 var holdersIndex = -1,
3752 holdersLength = holders.length,
3754 argsLength = nativeMax(args.length - holdersLength, 0),
3756 rightLength = partials.length,
3757 result = Array(argsLength + rightLength);
3759 while (++argsIndex < argsLength) {
3760 result[argsIndex] = args[argsIndex];
3762 var offset = argsIndex;
3763 while (++rightIndex < rightLength) {
3764 result[offset + rightIndex] = partials[rightIndex];
3766 while (++holdersIndex < holdersLength) {
3767 result[offset + holders[holdersIndex]] = args[argsIndex++];
3773 * Copies the values of `source` to `array`.
3776 * @param {Array} source The array to copy values from.
3777 * @param {Array} [array=[]] The array to copy values to.
3778 * @returns {Array} Returns `array`.
3780 function copyArray(source, array) {
3782 length = source.length;
3784 array || (array = Array(length));
3785 while (++index < length) {
3786 array[index] = source[index];
3792 * Copies properties of `source` to `object`.
3795 * @param {Object} source The object to copy properties from.
3796 * @param {Array} props The property names to copy.
3797 * @param {Object} [object={}] The object to copy properties to.
3798 * @returns {Object} Returns `object`.
3800 function copyObject(source, props, object) {
3801 return copyObjectWith(source, props, object);
3805 * This function is like `copyObject` except that it accepts a function to
3806 * customize copied values.
3809 * @param {Object} source The object to copy properties from.
3810 * @param {Array} props The property names to copy.
3811 * @param {Object} [object={}] The object to copy properties to.
3812 * @param {Function} [customizer] The function to customize copied values.
3813 * @returns {Object} Returns `object`.
3815 function copyObjectWith(source, props, object, customizer) {
3816 object || (object = {});
3819 length = props.length;
3821 while (++index < length) {
3822 var key = props[index],
3823 newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
3825 assignValue(object, key, newValue);
3831 * Copies own symbol properties of `source` to `object`.
3834 * @param {Object} source The object to copy symbols from.
3835 * @param {Object} [object={}] The object to copy symbols to.
3836 * @returns {Object} Returns `object`.
3838 function copySymbols(source, object) {
3839 return copyObject(source, getSymbols(source), object);
3843 * Creates a function like `_.groupBy`.
3846 * @param {Function} setter The function to set keys and values of the accumulator object.
3847 * @param {Function} [initializer] The function to initialize the accumulator object.
3848 * @returns {Function} Returns the new aggregator function.
3850 function createAggregator(setter, initializer) {
3851 return function(collection, iteratee) {
3852 var result = initializer ? initializer() : {};
3853 iteratee = getIteratee(iteratee);
3855 if (isArray(collection)) {
3857 length = collection.length;
3859 while (++index < length) {
3860 var value = collection[index];
3861 setter(result, value, iteratee(value), collection);
3864 baseEach(collection, function(value, key, collection) {
3865 setter(result, value, iteratee(value), collection);
3873 * Creates a function like `_.assign`.
3876 * @param {Function} assigner The function to assign values.
3877 * @returns {Function} Returns the new assigner function.
3879 function createAssigner(assigner) {
3880 return rest(function(object, sources) {
3882 length = sources.length,
3883 customizer = length > 1 ? sources[length - 1] : undefined,
3884 guard = length > 2 ? sources[2] : undefined;
3886 customizer = typeof customizer == 'function' ? (length--, customizer) : undefined;
3887 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
3888 customizer = length < 3 ? undefined : customizer;
3891 object = Object(object);
3892 while (++index < length) {
3893 var source = sources[index];
3895 assigner(object, source, index, customizer);
3903 * Creates a `baseEach` or `baseEachRight` function.
3906 * @param {Function} eachFunc The function to iterate over a collection.
3907 * @param {boolean} [fromRight] Specify iterating from right to left.
3908 * @returns {Function} Returns the new base function.
3910 function createBaseEach(eachFunc, fromRight) {
3911 return function(collection, iteratee) {
3912 if (collection == null) {
3915 if (!isArrayLike(collection)) {
3916 return eachFunc(collection, iteratee);
3918 var length = collection.length,
3919 index = fromRight ? length : -1,
3920 iterable = Object(collection);
3922 while ((fromRight ? index-- : ++index < length)) {
3923 if (iteratee(iterable[index], index, iterable) === false) {
3932 * Creates a base function for methods like `_.forIn`.
3935 * @param {boolean} [fromRight] Specify iterating from right to left.
3936 * @returns {Function} Returns the new base function.
3938 function createBaseFor(fromRight) {
3939 return function(object, iteratee, keysFunc) {
3941 iterable = Object(object),
3942 props = keysFunc(object),
3943 length = props.length;
3946 var key = props[fromRight ? length : ++index];
3947 if (iteratee(iterable[key], key, iterable) === false) {
3956 * Creates a function that wraps `func` to invoke it with the optional `this`
3957 * binding of `thisArg`.
3960 * @param {Function} func The function to wrap.
3961 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
3962 * @param {*} [thisArg] The `this` binding of `func`.
3963 * @returns {Function} Returns the new wrapped function.
3965 function createBaseWrapper(func, bitmask, thisArg) {
3966 var isBind = bitmask & BIND_FLAG,
3967 Ctor = createCtorWrapper(func);
3969 function wrapper() {
3970 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
3971 return fn.apply(isBind ? thisArg : this, arguments);
3977 * Creates a function like `_.lowerFirst`.
3980 * @param {string} methodName The name of the `String` case method to use.
3981 * @returns {Function} Returns the new function.
3983 function createCaseFirst(methodName) {
3984 return function(string) {
3985 string = toString(string);
3987 var strSymbols = reHasComplexSymbol.test(string) ? stringToArray(string) : undefined,
3988 chr = strSymbols ? strSymbols[0] : string.charAt(0),
3989 trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1);
3991 return chr[methodName]() + trailing;
3996 * Creates a function like `_.camelCase`.
3999 * @param {Function} callback The function to combine each word.
4000 * @returns {Function} Returns the new compounder function.
4002 function createCompounder(callback) {
4003 return function(string) {
4004 return arrayReduce(words(deburr(string)), callback, '');
4009 * Creates a function that produces an instance of `Ctor` regardless of
4010 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
4013 * @param {Function} Ctor The constructor to wrap.
4014 * @returns {Function} Returns the new wrapped function.
4016 function createCtorWrapper(Ctor) {
4018 // Use a `switch` statement to work with class constructors.
4019 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
4020 // for more details.
4021 var args = arguments;
4022 switch (args.length) {
4023 case 0: return new Ctor;
4024 case 1: return new Ctor(args[0]);
4025 case 2: return new Ctor(args[0], args[1]);
4026 case 3: return new Ctor(args[0], args[1], args[2]);
4027 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
4028 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
4029 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
4030 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
4032 var thisBinding = baseCreate(Ctor.prototype),
4033 result = Ctor.apply(thisBinding, args);
4035 // Mimic the constructor's `return` behavior.
4036 // See https://es5.github.io/#x13.2.2 for more details.
4037 return isObject(result) ? result : thisBinding;
4042 * Creates a function that wraps `func` to enable currying.
4045 * @param {Function} func The function to wrap.
4046 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4047 * @param {number} arity The arity of `func`.
4048 * @returns {Function} Returns the new wrapped function.
4050 function createCurryWrapper(func, bitmask, arity) {
4051 var Ctor = createCtorWrapper(func);
4053 function wrapper() {
4054 var length = arguments.length,
4056 args = Array(length),
4057 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func,
4058 placeholder = wrapper.placeholder;
4061 args[index] = arguments[index];
4063 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
4065 : replaceHolders(args, placeholder);
4067 length -= holders.length;
4068 return length < arity
4069 ? createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, undefined, args, holders, undefined, undefined, arity - length)
4070 : apply(fn, this, args);
4076 * Creates a `_.flow` or `_.flowRight` function.
4079 * @param {boolean} [fromRight] Specify iterating from right to left.
4080 * @returns {Function} Returns the new flow function.
4082 function createFlow(fromRight) {
4083 return rest(function(funcs) {
4084 funcs = baseFlatten(funcs);
4086 var length = funcs.length,
4088 prereq = LodashWrapper.prototype.thru;
4094 var func = funcs[index];
4095 if (typeof func != 'function') {
4096 throw new TypeError(FUNC_ERROR_TEXT);
4098 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
4099 var wrapper = new LodashWrapper([], true);
4102 index = wrapper ? index : length;
4103 while (++index < length) {
4104 func = funcs[index];
4106 var funcName = getFuncName(func),
4107 data = funcName == 'wrapper' ? getData(func) : undefined;
4109 if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
4110 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
4112 wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
4116 var args = arguments,
4119 if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
4120 return wrapper.plant(value).value();
4123 result = length ? funcs[index].apply(this, args) : value;
4125 while (++index < length) {
4126 result = funcs[index].call(this, result);
4134 * Creates a function that wraps `func` to invoke it with optional `this`
4135 * binding of `thisArg`, partial application, and currying.
4138 * @param {Function|string} func The function or method name to wrap.
4139 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4140 * @param {*} [thisArg] The `this` binding of `func`.
4141 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
4142 * @param {Array} [holders] The `partials` placeholder indexes.
4143 * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
4144 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
4145 * @param {Array} [argPos] The argument positions of the new function.
4146 * @param {number} [ary] The arity cap of `func`.
4147 * @param {number} [arity] The arity of `func`.
4148 * @returns {Function} Returns the new wrapped function.
4150 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
4151 var isAry = bitmask & ARY_FLAG,
4152 isBind = bitmask & BIND_FLAG,
4153 isBindKey = bitmask & BIND_KEY_FLAG,
4154 isCurry = bitmask & CURRY_FLAG,
4155 isCurryRight = bitmask & CURRY_RIGHT_FLAG,
4156 isFlip = bitmask & FLIP_FLAG,
4157 Ctor = isBindKey ? undefined : createCtorWrapper(func);
4159 function wrapper() {
4160 var length = arguments.length,
4162 args = Array(length);
4165 args[index] = arguments[index];
4168 args = composeArgs(args, partials, holders);
4170 if (partialsRight) {
4171 args = composeArgsRight(args, partialsRight, holdersRight);
4173 if (isCurry || isCurryRight) {
4174 var placeholder = wrapper.placeholder,
4175 argsHolders = replaceHolders(args, placeholder);
4177 length -= argsHolders.length;
4178 if (length < arity) {
4179 return createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, thisArg, args, argsHolders, argPos, ary, arity - length);
4182 var thisBinding = isBind ? thisArg : this,
4183 fn = isBindKey ? thisBinding[func] : func;
4186 args = reorder(args, argPos);
4187 } else if (isFlip && args.length > 1) {
4190 if (isAry && ary < args.length) {
4193 if (this && this !== root && this instanceof wrapper) {
4194 fn = Ctor || createCtorWrapper(fn);
4196 return fn.apply(thisBinding, args);
4202 * Creates a function like `_.over`.
4205 * @param {Function} arrayFunc The function to iterate over iteratees.
4206 * @returns {Function} Returns the new invoker function.
4208 function createOver(arrayFunc) {
4209 return rest(function(iteratees) {
4210 iteratees = arrayMap(baseFlatten(iteratees), getIteratee());
4211 return rest(function(args) {
4213 return arrayFunc(iteratees, function(iteratee) {
4214 return apply(iteratee, thisArg, args);
4221 * Creates the padding for `string` based on `length`. The `chars` string
4222 * is truncated if the number of characters exceeds `length`.
4225 * @param {string} string The string to create padding for.
4226 * @param {number} [length=0] The padding length.
4227 * @param {string} [chars=' '] The string used as padding.
4228 * @returns {string} Returns the padding for `string`.
4230 function createPadding(string, length, chars) {
4231 length = toInteger(length);
4233 var strLength = stringSize(string);
4234 if (!length || strLength >= length) {
4237 var padLength = length - strLength;
4238 chars = chars === undefined ? ' ' : (chars + '');
4240 var result = repeat(chars, nativeCeil(padLength / stringSize(chars)));
4241 return reHasComplexSymbol.test(chars)
4242 ? stringToArray(result).slice(0, padLength).join('')
4243 : result.slice(0, padLength);
4247 * Creates a function that wraps `func` to invoke it with the optional `this`
4248 * binding of `thisArg` and the `partials` prepended to those provided to
4252 * @param {Function} func The function to wrap.
4253 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4254 * @param {*} thisArg The `this` binding of `func`.
4255 * @param {Array} partials The arguments to prepend to those provided to the new function.
4256 * @returns {Function} Returns the new wrapped function.
4258 function createPartialWrapper(func, bitmask, thisArg, partials) {
4259 var isBind = bitmask & BIND_FLAG,
4260 Ctor = createCtorWrapper(func);
4262 function wrapper() {
4264 argsLength = arguments.length,
4266 leftLength = partials.length,
4267 args = Array(leftLength + argsLength),
4268 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4270 while (++leftIndex < leftLength) {
4271 args[leftIndex] = partials[leftIndex];
4273 while (argsLength--) {
4274 args[leftIndex++] = arguments[++argsIndex];
4276 return apply(fn, isBind ? thisArg : this, args);
4282 * Creates a `_.range` or `_.rangeRight` function.
4285 * @param {boolean} [fromRight] Specify iterating from right to left.
4286 * @returns {Function} Returns the new range function.
4288 function createRange(fromRight) {
4289 return function(start, end, step) {
4290 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
4291 end = step = undefined;
4293 // Ensure the sign of `-0` is preserved.
4294 start = toNumber(start);
4295 start = start === start ? start : 0;
4296 if (end === undefined) {
4300 end = toNumber(end) || 0;
4302 step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
4303 return baseRange(start, end, step, fromRight);
4308 * Creates a function that wraps `func` to continue currying.
4311 * @param {Function} func The function to wrap.
4312 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4313 * @param {Function} wrapFunc The function to create the `func` wrapper.
4314 * @param {*} placeholder The placeholder to replace.
4315 * @param {*} [thisArg] The `this` binding of `func`.
4316 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
4317 * @param {Array} [holders] The `partials` placeholder indexes.
4318 * @param {Array} [argPos] The argument positions of the new function.
4319 * @param {number} [ary] The arity cap of `func`.
4320 * @param {number} [arity] The arity of `func`.
4321 * @returns {Function} Returns the new wrapped function.
4323 function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
4324 var isCurry = bitmask & CURRY_FLAG,
4325 newArgPos = argPos ? copyArray(argPos) : undefined,
4326 newsHolders = isCurry ? holders : undefined,
4327 newHoldersRight = isCurry ? undefined : holders,
4328 newPartials = isCurry ? partials : undefined,
4329 newPartialsRight = isCurry ? undefined : partials;
4331 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
4332 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
4334 if (!(bitmask & CURRY_BOUND_FLAG)) {
4335 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
4337 var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, arity],
4338 result = wrapFunc.apply(undefined, newData);
4340 if (isLaziable(func)) {
4341 setData(result, newData);
4343 result.placeholder = placeholder;
4348 * Creates a function like `_.round`.
4351 * @param {string} methodName The name of the `Math` method to use when rounding.
4352 * @returns {Function} Returns the new round function.
4354 function createRound(methodName) {
4355 var func = Math[methodName];
4356 return function(number, precision) {
4357 number = toNumber(number);
4358 precision = toInteger(precision);
4360 // Shift with exponential notation to avoid floating-point issues.
4361 // See [MDN](https://mdn.io/round#Examples) for more details.
4362 var pair = (toString(number) + 'e').split('e'),
4363 value = func(pair[0] + 'e' + (+pair[1] + precision));
4365 pair = (toString(value) + 'e').split('e');
4366 return +(pair[0] + 'e' + (+pair[1] - precision));
4368 return func(number);
4373 * Creates a set of `values`.
4376 * @param {Array} values The values to add to the set.
4377 * @returns {Object} Returns the new set.
4379 var createSet = !(Set && new Set([1, 2]).size === 2) ? noop : function(values) {
4380 return new Set(values);
4384 * Creates a function that either curries or invokes `func` with optional
4385 * `this` binding and partially applied arguments.
4388 * @param {Function|string} func The function or method name to wrap.
4389 * @param {number} bitmask The bitmask of wrapper flags.
4390 * The bitmask may be composed of the following flags:
4393 * 4 - `_.curry` or `_.curryRight` of a bound function
4395 * 16 - `_.curryRight`
4397 * 64 - `_.partialRight`
4400 * @param {*} [thisArg] The `this` binding of `func`.
4401 * @param {Array} [partials] The arguments to be partially applied.
4402 * @param {Array} [holders] The `partials` placeholder indexes.
4403 * @param {Array} [argPos] The argument positions of the new function.
4404 * @param {number} [ary] The arity cap of `func`.
4405 * @param {number} [arity] The arity of `func`.
4406 * @returns {Function} Returns the new wrapped function.
4408 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
4409 var isBindKey = bitmask & BIND_KEY_FLAG;
4410 if (!isBindKey && typeof func != 'function') {
4411 throw new TypeError(FUNC_ERROR_TEXT);
4413 var length = partials ? partials.length : 0;
4415 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
4416 partials = holders = undefined;
4418 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
4419 arity = arity === undefined ? arity : toInteger(arity);
4420 length -= holders ? holders.length : 0;
4422 if (bitmask & PARTIAL_RIGHT_FLAG) {
4423 var partialsRight = partials,
4424 holdersRight = holders;
4426 partials = holders = undefined;
4428 var data = isBindKey ? undefined : getData(func),
4429 newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
4432 mergeData(newData, data);
4435 bitmask = newData[1];
4436 thisArg = newData[2];
4437 partials = newData[3];
4438 holders = newData[4];
4439 arity = newData[9] = newData[9] == null
4440 ? (isBindKey ? 0 : func.length)
4441 : nativeMax(newData[9] - length, 0);
4443 if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
4444 bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
4446 if (!bitmask || bitmask == BIND_FLAG) {
4447 var result = createBaseWrapper(func, bitmask, thisArg);
4448 } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
4449 result = createCurryWrapper(func, bitmask, arity);
4450 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
4451 result = createPartialWrapper(func, bitmask, thisArg, partials);
4453 result = createHybridWrapper.apply(undefined, newData);
4455 var setter = data ? baseSetData : setData;
4456 return setter(result, newData);
4460 * A specialized version of `baseIsEqualDeep` for arrays with support for
4461 * partial deep comparisons.
4464 * @param {Array} array The array to compare.
4465 * @param {Array} other The other array to compare.
4466 * @param {Function} equalFunc The function to determine equivalents of values.
4467 * @param {Function} [customizer] The function to customize comparisons.
4468 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4469 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
4470 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
4472 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
4474 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
4475 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
4476 arrLength = array.length,
4477 othLength = other.length;
4479 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
4482 // Assume cyclic values are equal.
4483 var stacked = stack.get(array);
4485 return stacked == other;
4488 stack.set(array, other);
4490 // Ignore non-index properties.
4491 while (++index < arrLength) {
4492 var arrValue = array[index],
4493 othValue = other[index];
4496 var compared = isPartial
4497 ? customizer(othValue, arrValue, index, other, array, stack)
4498 : customizer(arrValue, othValue, index, array, other, stack);
4500 if (compared !== undefined) {
4507 // Recursively compare arrays (susceptible to call stack limits).
4509 if (!arraySome(other, function(othValue) {
4510 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
4515 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
4520 stack['delete'](array);
4525 * A specialized version of `baseIsEqualDeep` for comparing objects of
4526 * the same `toStringTag`.
4528 * **Note:** This function only supports comparing values with tags of
4529 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4532 * @param {Object} object The object to compare.
4533 * @param {Object} other The other object to compare.
4534 * @param {string} tag The `toStringTag` of the objects to compare.
4535 * @param {Function} equalFunc The function to determine equivalents of values.
4536 * @param {Function} [customizer] The function to customize comparisons.
4537 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4538 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
4540 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
4542 case arrayBufferTag:
4543 if ((object.byteLength != other.byteLength) ||
4544 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
4551 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
4552 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
4553 return +object == +other;
4556 return object.name == other.name && object.message == other.message;
4559 // Treat `NaN` vs. `NaN` as equal.
4560 return (object != +object) ? other != +other : object == +other;
4564 // Coerce regexes to strings and treat strings primitives and string
4565 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
4566 return object == (other + '');
4569 var convert = mapToArray;
4572 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
4573 convert || (convert = setToArray);
4575 // Recursively compare objects (susceptible to call stack limits).
4576 return (isPartial || object.size == other.size) &&
4577 equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG);
4580 return !!Symbol && (symbolValueOf.call(object) == symbolValueOf.call(other));
4586 * A specialized version of `baseIsEqualDeep` for objects with support for
4587 * partial deep comparisons.
4590 * @param {Object} object The object to compare.
4591 * @param {Object} other The other object to compare.
4592 * @param {Function} equalFunc The function to determine equivalents of values.
4593 * @param {Function} [customizer] The function to customize comparisons.
4594 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4595 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
4596 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
4598 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
4599 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
4600 objProps = keys(object),
4601 objLength = objProps.length,
4602 othProps = keys(other),
4603 othLength = othProps.length;
4605 if (objLength != othLength && !isPartial) {
4608 var index = objLength;
4610 var key = objProps[index];
4611 if (!(isPartial ? key in other : baseHas(other, key))) {
4615 // Assume cyclic values are equal.
4616 var stacked = stack.get(object);
4618 return stacked == other;
4621 stack.set(object, other);
4623 var skipCtor = isPartial;
4624 while (++index < objLength) {
4625 key = objProps[index];
4626 var objValue = object[key],
4627 othValue = other[key];
4630 var compared = isPartial
4631 ? customizer(othValue, objValue, key, other, object, stack)
4632 : customizer(objValue, othValue, key, object, other, stack);
4634 // Recursively compare objects (susceptible to call stack limits).
4635 if (!(compared === undefined
4636 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
4642 skipCtor || (skipCtor = key == 'constructor');
4644 if (result && !skipCtor) {
4645 var objCtor = object.constructor,
4646 othCtor = other.constructor;
4648 // Non `Object` object instances with different constructors are not equal.
4649 if (objCtor != othCtor &&
4650 ('constructor' in object && 'constructor' in other) &&
4651 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
4652 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
4656 stack['delete'](object);
4661 * Gets metadata for `func`.
4664 * @param {Function} func The function to query.
4665 * @returns {*} Returns the metadata for `func`.
4667 var getData = !metaMap ? noop : function(func) {
4668 return metaMap.get(func);
4672 * Gets the name of `func`.
4675 * @param {Function} func The function to query.
4676 * @returns {string} Returns the function name.
4678 function getFuncName(func) {
4679 var result = (func.name + ''),
4680 array = realNames[result],
4681 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
4684 var data = array[length],
4685 otherFunc = data.func;
4686 if (otherFunc == null || otherFunc == func) {
4694 * Gets the appropriate "iteratee" function. If the `_.iteratee` method is
4695 * customized this function returns the custom method, otherwise it returns
4696 * `baseIteratee`. If arguments are provided the chosen function is invoked
4697 * with them and its result is returned.
4700 * @param {*} [value] The value to convert to an iteratee.
4701 * @param {number} [arity] The arity of the created iteratee.
4702 * @returns {Function} Returns the chosen function or its result.
4704 function getIteratee() {
4705 var result = lodash.iteratee || iteratee;
4706 result = result === iteratee ? baseIteratee : result;
4707 return arguments.length ? result(arguments[0], arguments[1]) : result;
4711 * Gets the "length" property value of `object`.
4713 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
4714 * that affects Safari on at least iOS 8.1-8.3 ARM64.
4717 * @param {Object} object The object to query.
4718 * @returns {*} Returns the "length" value.
4720 var getLength = baseProperty('length');
4723 * Gets the property names, values, and compare flags of `object`.
4726 * @param {Object} object The object to query.
4727 * @returns {Array} Returns the match data of `object`.
4729 function getMatchData(object) {
4730 var result = toPairs(object),
4731 length = result.length;
4734 result[length][2] = isStrictComparable(result[length][1]);
4740 * Gets the native function at `key` of `object`.
4743 * @param {Object} object The object to query.
4744 * @param {string} key The key of the method to get.
4745 * @returns {*} Returns the function if it's native, else `undefined`.
4747 function getNative(object, key) {
4748 var value = object == null ? undefined : object[key];
4749 return isNative(value) ? value : undefined;
4753 * Creates an array of the own symbol properties of `object`.
4756 * @param {Object} object The object to query.
4757 * @returns {Array} Returns the array of symbols.
4759 var getSymbols = getOwnPropertySymbols || function() {
4764 * Gets the `toStringTag` of `value`.
4767 * @param {*} value The value to query.
4768 * @returns {string} Returns the `toStringTag`.
4770 function getTag(value) {
4771 return objectToString.call(value);
4774 // Fallback for IE 11 providing `toStringTag` values for maps and sets.
4775 if ((Map && getTag(new Map) != mapTag) || (Set && getTag(new Set) != setTag)) {
4776 getTag = function(value) {
4777 var result = objectToString.call(value),
4778 Ctor = result == objectTag ? value.constructor : null,
4779 ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '';
4782 if (ctorString == mapCtorString) {
4785 if (ctorString == setCtorString) {
4794 * Gets the view, applying any `transforms` to the `start` and `end` positions.
4797 * @param {number} start The start of the view.
4798 * @param {number} end The end of the view.
4799 * @param {Array} transforms The transformations to apply to the view.
4800 * @returns {Object} Returns an object containing the `start` and `end`
4801 * positions of the view.
4803 function getView(start, end, transforms) {
4805 length = transforms.length;
4807 while (++index < length) {
4808 var data = transforms[index],
4811 switch (data.type) {
4812 case 'drop': start += size; break;
4813 case 'dropRight': end -= size; break;
4814 case 'take': end = nativeMin(end, start + size); break;
4815 case 'takeRight': start = nativeMax(start, end - size); break;
4818 return { 'start': start, 'end': end };
4822 * Checks if `path` exists on `object`.
4825 * @param {Object} object The object to query.
4826 * @param {Array|string} path The path to check.
4827 * @param {Function} hasFunc The function to check properties.
4828 * @returns {boolean} Returns `true` if `path` exists, else `false`.
4830 function hasPath(object, path, hasFunc) {
4831 if (object == null) {
4834 var result = hasFunc(object, path);
4835 if (!result && !isKey(path)) {
4836 path = baseToPath(path);
4837 object = parent(object, path);
4838 if (object != null) {
4840 result = hasFunc(object, path);
4843 return result || (isLength(object && object.length) && isIndex(path, object.length) &&
4844 (isArray(object) || isString(object) || isArguments(object)));
4848 * Initializes an array clone.
4851 * @param {Array} array The array to clone.
4852 * @returns {Array} Returns the initialized clone.
4854 function initCloneArray(array) {
4855 var length = array.length,
4856 result = array.constructor(length);
4858 // Add properties assigned by `RegExp#exec`.
4859 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
4860 result.index = array.index;
4861 result.input = array.input;
4867 * Initializes an object clone.
4870 * @param {Object} object The object to clone.
4871 * @returns {Object} Returns the initialized clone.
4873 function initCloneObject(object) {
4874 var Ctor = object.constructor;
4875 return baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
4879 * Initializes an object clone based on its `toStringTag`.
4881 * **Note:** This function only supports cloning values with tags of
4882 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4885 * @param {Object} object The object to clone.
4886 * @param {string} tag The `toStringTag` of the object to clone.
4887 * @param {boolean} [isDeep] Specify a deep clone.
4888 * @returns {Object} Returns the initialized clone.
4890 function initCloneByTag(object, tag, isDeep) {
4891 var Ctor = object.constructor;
4893 case arrayBufferTag:
4894 return cloneBuffer(object);
4898 return new Ctor(+object);
4900 case float32Tag: case float64Tag:
4901 case int8Tag: case int16Tag: case int32Tag:
4902 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
4903 return cloneTypedArray(object, isDeep);
4906 return cloneMap(object);
4910 return new Ctor(object);
4913 return cloneRegExp(object);
4916 return cloneSet(object);
4919 return cloneSymbol(object);
4924 * Creates an array of index keys for `object` values of arrays,
4925 * `arguments` objects, and strings, otherwise `null` is returned.
4928 * @param {Object} object The object to query.
4929 * @returns {Array|null} Returns index keys, else `null`.
4931 function indexKeys(object) {
4932 var length = object ? object.length : undefined;
4933 return (isLength(length) && (isArray(object) || isString(object) || isArguments(object)))
4934 ? baseTimes(length, String)
4939 * Checks if the provided arguments are from an iteratee call.
4942 * @param {*} value The potential iteratee value argument.
4943 * @param {*} index The potential iteratee index or key argument.
4944 * @param {*} object The potential iteratee object argument.
4945 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
4947 function isIterateeCall(value, index, object) {
4948 if (!isObject(object)) {
4951 var type = typeof index;
4952 if (type == 'number'
4953 ? (isArrayLike(object) && isIndex(index, object.length))
4954 : (type == 'string' && index in object)) {
4955 return eq(object[index], value);
4961 * Checks if `value` is a property name and not a property path.
4964 * @param {*} value The value to check.
4965 * @param {Object} [object] The object to query keys on.
4966 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
4968 function isKey(value, object) {
4969 if (typeof value == 'number') {
4972 return !isArray(value) &&
4973 (reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
4974 (object != null && value in Object(object)));
4978 * Checks if `value` is suitable for use as unique object key.
4981 * @param {*} value The value to check.
4982 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
4984 function isKeyable(value) {
4985 var type = typeof value;
4986 return type == 'number' || type == 'boolean' ||
4987 (type == 'string' && value !== '__proto__') || value == null;
4991 * Checks if `func` has a lazy counterpart.
4994 * @param {Function} func The function to check.
4995 * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
4997 function isLaziable(func) {
4998 var funcName = getFuncName(func),
4999 other = lodash[funcName];
5001 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
5004 if (func === other) {
5007 var data = getData(other);
5008 return !!data && func === data[0];
5012 * Checks if `value` is likely a prototype object.
5015 * @param {*} value The value to check.
5016 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
5018 function isPrototype(value) {
5019 var Ctor = value && value.constructor,
5020 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
5022 return value === proto;
5026 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
5029 * @param {*} value The value to check.
5030 * @returns {boolean} Returns `true` if `value` if suitable for strict
5031 * equality comparisons, else `false`.
5033 function isStrictComparable(value) {
5034 return value === value && !isObject(value);
5038 * Merges the function metadata of `source` into `data`.
5040 * Merging metadata reduces the number of wrappers used to invoke a function.
5041 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
5042 * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
5043 * modify function arguments, making the order in which they are executed important,
5044 * preventing the merging of metadata. However, we make an exception for a safe
5045 * combined case where curried functions have `_.ary` and or `_.rearg` applied.
5048 * @param {Array} data The destination metadata.
5049 * @param {Array} source The source metadata.
5050 * @returns {Array} Returns `data`.
5052 function mergeData(data, source) {
5053 var bitmask = data[1],
5054 srcBitmask = source[1],
5055 newBitmask = bitmask | srcBitmask,
5056 isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
5059 (srcBitmask == ARY_FLAG && (bitmask == CURRY_FLAG)) ||
5060 (srcBitmask == ARY_FLAG && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
5061 (srcBitmask == (ARY_FLAG | REARG_FLAG) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
5063 // Exit early if metadata can't be merged.
5064 if (!(isCommon || isCombo)) {
5067 // Use source `thisArg` if available.
5068 if (srcBitmask & BIND_FLAG) {
5069 data[2] = source[2];
5070 // Set when currying a bound function.
5071 newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
5073 // Compose partial arguments.
5074 var value = source[3];
5076 var partials = data[3];
5077 data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray(value);
5078 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : copyArray(source[4]);
5080 // Compose partial right arguments.
5084 data[5] = partials ? composeArgsRight(partials, value, source[6]) : copyArray(value);
5085 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : copyArray(source[6]);
5087 // Use source `argPos` if available.
5090 data[7] = copyArray(value);
5092 // Use source `ary` if it's smaller.
5093 if (srcBitmask & ARY_FLAG) {
5094 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
5096 // Use source `arity` if one is not provided.
5097 if (data[9] == null) {
5098 data[9] = source[9];
5100 // Use source `func` and merge bitmasks.
5101 data[0] = source[0];
5102 data[1] = newBitmask;
5108 * Used by `_.defaultsDeep` to customize its `_.merge` use.
5111 * @param {*} objValue The destination value.
5112 * @param {*} srcValue The source value.
5113 * @param {string} key The key of the property to merge.
5114 * @param {Object} object The parent object of `objValue`.
5115 * @param {Object} source The parent object of `srcValue`.
5116 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
5117 * @returns {*} Returns the value to assign.
5119 function mergeDefaults(objValue, srcValue, key, object, source, stack) {
5120 if (isObject(objValue) && isObject(srcValue)) {
5121 stack.set(srcValue, objValue);
5122 baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
5128 * Gets the parent value at `path` of `object`.
5131 * @param {Object} object The object to query.
5132 * @param {Array} path The path to get the parent value of.
5133 * @returns {*} Returns the parent value.
5135 function parent(object, path) {
5136 return path.length == 1 ? object : get(object, baseSlice(path, 0, -1));
5140 * Reorder `array` according to the specified indexes where the element at
5141 * the first index is assigned as the first element, the element at
5142 * the second index is assigned as the second element, and so on.
5145 * @param {Array} array The array to reorder.
5146 * @param {Array} indexes The arranged array indexes.
5147 * @returns {Array} Returns `array`.
5149 function reorder(array, indexes) {
5150 var arrLength = array.length,
5151 length = nativeMin(indexes.length, arrLength),
5152 oldArray = copyArray(array);
5155 var index = indexes[length];
5156 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
5162 * Sets metadata for `func`.
5164 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
5165 * period of time, it will trip its breaker and transition to an identity function
5166 * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
5170 * @param {Function} func The function to associate metadata with.
5171 * @param {*} data The metadata.
5172 * @returns {Function} Returns `func`.
5174 var setData = (function() {
5178 return function(key, value) {
5180 remaining = HOT_SPAN - (stamp - lastCalled);
5183 if (remaining > 0) {
5184 if (++count >= HOT_COUNT) {
5190 return baseSetData(key, value);
5195 * Converts `string` to a property path array.
5198 * @param {string} string The string to convert.
5199 * @returns {Array} Returns the property path array.
5201 function stringToPath(string) {
5203 toString(string).replace(rePropName, function(match, number, quote, string) {
5204 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
5210 * Converts `value` to an array-like object if it's not one.
5213 * @param {*} value The value to process.
5214 * @returns {Array} Returns the array-like object.
5216 function toArrayLikeObject(value) {
5217 return isArrayLikeObject(value) ? value : [];
5221 * Converts `value` to a function if it's not one.
5224 * @param {*} value The value to process.
5225 * @returns {Function} Returns the function.
5227 function toFunction(value) {
5228 return typeof value == 'function' ? value : identity;
5232 * Creates a clone of `wrapper`.
5235 * @param {Object} wrapper The wrapper to clone.
5236 * @returns {Object} Returns the cloned wrapper.
5238 function wrapperClone(wrapper) {
5239 if (wrapper instanceof LazyWrapper) {
5240 return wrapper.clone();
5242 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
5243 result.__actions__ = copyArray(wrapper.__actions__);
5244 result.__index__ = wrapper.__index__;
5245 result.__values__ = wrapper.__values__;
5249 /*------------------------------------------------------------------------*/
5252 * Creates an array of elements split into groups the length of `size`.
5253 * If `array` can't be split evenly, the final chunk will be the remaining
5259 * @param {Array} array The array to process.
5260 * @param {number} [size=0] The length of each chunk.
5261 * @returns {Array} Returns the new array containing chunks.
5264 * _.chunk(['a', 'b', 'c', 'd'], 2);
5265 * // => [['a', 'b'], ['c', 'd']]
5267 * _.chunk(['a', 'b', 'c', 'd'], 3);
5268 * // => [['a', 'b', 'c'], ['d']]
5270 function chunk(array, size) {
5271 size = nativeMax(toInteger(size), 0);
5273 var length = array ? array.length : 0;
5274 if (!length || size < 1) {
5279 result = Array(nativeCeil(length / size));
5281 while (index < length) {
5282 result[++resIndex] = baseSlice(array, index, (index += size));
5288 * Creates an array with all falsey values removed. The values `false`, `null`,
5289 * `0`, `""`, `undefined`, and `NaN` are falsey.
5294 * @param {Array} array The array to compact.
5295 * @returns {Array} Returns the new array of filtered values.
5298 * _.compact([0, 1, false, 2, '', 3]);
5301 function compact(array) {
5303 length = array ? array.length : 0,
5307 while (++index < length) {
5308 var value = array[index];
5310 result[++resIndex] = value;
5317 * Creates a new array concatenating `array` with any additional arrays
5323 * @param {Array} array The array to concatenate.
5324 * @param {...*} [values] The values to concatenate.
5325 * @returns {Array} Returns the new concatenated array.
5329 * var other = _.concat(array, 2, [3], [[4]]);
5331 * console.log(other);
5332 * // => [1, 2, 3, [4]]
5334 * console.log(array);
5337 var concat = rest(function(array, values) {
5338 if (!isArray(array)) {
5339 array = array == null ? [] : [Object(array)];
5341 values = baseFlatten(values);
5342 return arrayConcat(array, values);
5346 * Creates an array of unique `array` values not included in the other
5347 * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5348 * for equality comparisons.
5353 * @param {Array} array The array to inspect.
5354 * @param {...Array} [values] The values to exclude.
5355 * @returns {Array} Returns the new array of filtered values.
5358 * _.difference([3, 2, 1], [4, 2]);
5361 var difference = rest(function(array, values) {
5362 return isArrayLikeObject(array)
5363 ? baseDifference(array, baseFlatten(values, false, true))
5368 * This method is like `_.difference` except that it accepts `iteratee` which
5369 * is invoked for each element of `array` and `values` to generate the criterion
5370 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
5375 * @param {Array} array The array to inspect.
5376 * @param {...Array} [values] The values to exclude.
5377 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
5378 * @returns {Array} Returns the new array of filtered values.
5381 * _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
5384 * // using the `_.property` iteratee shorthand
5385 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
5386 * // => [{ 'x': 2 }]
5388 var differenceBy = rest(function(array, values) {
5389 var iteratee = last(values);
5390 if (isArrayLikeObject(iteratee)) {
5391 iteratee = undefined;
5393 return isArrayLikeObject(array)
5394 ? baseDifference(array, baseFlatten(values, false, true), getIteratee(iteratee))
5399 * This method is like `_.difference` except that it accepts `comparator`
5400 * which is invoked to compare elements of `array` to `values`. The comparator
5401 * is invoked with two arguments: (arrVal, othVal).
5406 * @param {Array} array The array to inspect.
5407 * @param {...Array} [values] The values to exclude.
5408 * @param {Function} [comparator] The comparator invoked per element.
5409 * @returns {Array} Returns the new array of filtered values.
5412 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
5414 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
5415 * // => [{ 'x': 2, 'y': 1 }]
5417 var differenceWith = rest(function(array, values) {
5418 var comparator = last(values);
5419 if (isArrayLikeObject(comparator)) {
5420 comparator = undefined;
5422 return isArrayLikeObject(array)
5423 ? baseDifference(array, baseFlatten(values, false, true), undefined, comparator)
5428 * Creates a slice of `array` with `n` elements dropped from the beginning.
5433 * @param {Array} array The array to query.
5434 * @param {number} [n=1] The number of elements to drop.
5435 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
5436 * @returns {Array} Returns the slice of `array`.
5439 * _.drop([1, 2, 3]);
5442 * _.drop([1, 2, 3], 2);
5445 * _.drop([1, 2, 3], 5);
5448 * _.drop([1, 2, 3], 0);
5451 function drop(array, n, guard) {
5452 var length = array ? array.length : 0;
5456 n = (guard || n === undefined) ? 1 : toInteger(n);
5457 return baseSlice(array, n < 0 ? 0 : n, length);
5461 * Creates a slice of `array` with `n` elements dropped from the end.
5466 * @param {Array} array The array to query.
5467 * @param {number} [n=1] The number of elements to drop.
5468 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
5469 * @returns {Array} Returns the slice of `array`.
5472 * _.dropRight([1, 2, 3]);
5475 * _.dropRight([1, 2, 3], 2);
5478 * _.dropRight([1, 2, 3], 5);
5481 * _.dropRight([1, 2, 3], 0);
5484 function dropRight(array, n, guard) {
5485 var length = array ? array.length : 0;
5489 n = (guard || n === undefined) ? 1 : toInteger(n);
5491 return baseSlice(array, 0, n < 0 ? 0 : n);
5495 * Creates a slice of `array` excluding elements dropped from the end.
5496 * Elements are dropped until `predicate` returns falsey. The predicate is
5497 * invoked with three arguments: (value, index, array).
5502 * @param {Array} array The array to query.
5503 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5504 * @returns {Array} Returns the slice of `array`.
5508 * { 'user': 'barney', 'active': true },
5509 * { 'user': 'fred', 'active': false },
5510 * { 'user': 'pebbles', 'active': false }
5513 * _.dropRightWhile(users, function(o) { return !o.active; });
5514 * // => objects for ['barney']
5516 * // using the `_.matches` iteratee shorthand
5517 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
5518 * // => objects for ['barney', 'fred']
5520 * // using the `_.matchesProperty` iteratee shorthand
5521 * _.dropRightWhile(users, ['active', false]);
5522 * // => objects for ['barney']
5524 * // using the `_.property` iteratee shorthand
5525 * _.dropRightWhile(users, 'active');
5526 * // => objects for ['barney', 'fred', 'pebbles']
5528 function dropRightWhile(array, predicate) {
5529 return (array && array.length)
5530 ? baseWhile(array, getIteratee(predicate, 3), true, true)
5535 * Creates a slice of `array` excluding elements dropped from the beginning.
5536 * Elements are dropped until `predicate` returns falsey. The predicate is
5537 * invoked with three arguments: (value, index, array).
5542 * @param {Array} array The array to query.
5543 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5544 * @returns {Array} Returns the slice of `array`.
5548 * { 'user': 'barney', 'active': false },
5549 * { 'user': 'fred', 'active': false },
5550 * { 'user': 'pebbles', 'active': true }
5553 * _.dropWhile(users, function(o) { return !o.active; });
5554 * // => objects for ['pebbles']
5556 * // using the `_.matches` iteratee shorthand
5557 * _.dropWhile(users, { 'user': 'barney', 'active': false });
5558 * // => objects for ['fred', 'pebbles']
5560 * // using the `_.matchesProperty` iteratee shorthand
5561 * _.dropWhile(users, ['active', false]);
5562 * // => objects for ['pebbles']
5564 * // using the `_.property` iteratee shorthand
5565 * _.dropWhile(users, 'active');
5566 * // => objects for ['barney', 'fred', 'pebbles']
5568 function dropWhile(array, predicate) {
5569 return (array && array.length)
5570 ? baseWhile(array, getIteratee(predicate, 3), true)
5575 * Fills elements of `array` with `value` from `start` up to, but not
5578 * **Note:** This method mutates `array`.
5583 * @param {Array} array The array to fill.
5584 * @param {*} value The value to fill `array` with.
5585 * @param {number} [start=0] The start position.
5586 * @param {number} [end=array.length] The end position.
5587 * @returns {Array} Returns `array`.
5590 * var array = [1, 2, 3];
5592 * _.fill(array, 'a');
5593 * console.log(array);
5594 * // => ['a', 'a', 'a']
5596 * _.fill(Array(3), 2);
5599 * _.fill([4, 6, 8, 10], '*', 1, 3);
5600 * // => [4, '*', '*', 10]
5602 function fill(array, value, start, end) {
5603 var length = array ? array.length : 0;
5607 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
5611 return baseFill(array, value, start, end);
5615 * This method is like `_.find` except that it returns the index of the first
5616 * element `predicate` returns truthy for instead of the element itself.
5621 * @param {Array} array The array to search.
5622 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5623 * @returns {number} Returns the index of the found element, else `-1`.
5627 * { 'user': 'barney', 'active': false },
5628 * { 'user': 'fred', 'active': false },
5629 * { 'user': 'pebbles', 'active': true }
5632 * _.findIndex(users, function(o) { return o.user == 'barney'; });
5635 * // using the `_.matches` iteratee shorthand
5636 * _.findIndex(users, { 'user': 'fred', 'active': false });
5639 * // using the `_.matchesProperty` iteratee shorthand
5640 * _.findIndex(users, ['active', false]);
5643 * // using the `_.property` iteratee shorthand
5644 * _.findIndex(users, 'active');
5647 function findIndex(array, predicate) {
5648 return (array && array.length)
5649 ? baseFindIndex(array, getIteratee(predicate, 3))
5654 * This method is like `_.findIndex` except that it iterates over elements
5655 * of `collection` from right to left.
5660 * @param {Array} array The array to search.
5661 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5662 * @returns {number} Returns the index of the found element, else `-1`.
5666 * { 'user': 'barney', 'active': true },
5667 * { 'user': 'fred', 'active': false },
5668 * { 'user': 'pebbles', 'active': false }
5671 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
5674 * // using the `_.matches` iteratee shorthand
5675 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
5678 * // using the `_.matchesProperty` iteratee shorthand
5679 * _.findLastIndex(users, ['active', false]);
5682 * // using the `_.property` iteratee shorthand
5683 * _.findLastIndex(users, 'active');
5686 function findLastIndex(array, predicate) {
5687 return (array && array.length)
5688 ? baseFindIndex(array, getIteratee(predicate, 3), true)
5693 * Creates an array of flattened values by running each element in `array`
5694 * through `iteratee` and concating its result to the other mapped values.
5695 * The iteratee is invoked with three arguments: (value, index|key, array).
5700 * @param {Array} array The array to iterate over.
5701 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
5702 * @returns {Array} Returns the new array.
5705 * function duplicate(n) {
5709 * _.flatMap([1, 2], duplicate);
5710 * // => [1, 1, 2, 2]
5712 function flatMap(array, iteratee) {
5713 var length = array ? array.length : 0;
5714 return length ? baseFlatten(arrayMap(array, getIteratee(iteratee, 3))) : [];
5718 * Flattens `array` a single level.
5723 * @param {Array} array The array to flatten.
5724 * @returns {Array} Returns the new flattened array.
5727 * _.flatten([1, [2, 3, [4]]]);
5728 * // => [1, 2, 3, [4]]
5730 function flatten(array) {
5731 var length = array ? array.length : 0;
5732 return length ? baseFlatten(array) : [];
5736 * This method is like `_.flatten` except that it recursively flattens `array`.
5741 * @param {Array} array The array to recursively flatten.
5742 * @returns {Array} Returns the new flattened array.
5745 * _.flattenDeep([1, [2, 3, [4]]]);
5746 * // => [1, 2, 3, 4]
5748 function flattenDeep(array) {
5749 var length = array ? array.length : 0;
5750 return length ? baseFlatten(array, true) : [];
5754 * The inverse of `_.toPairs`; this method returns an object composed
5755 * from key-value `pairs`.
5760 * @param {Array} pairs The key-value pairs.
5761 * @returns {Object} Returns the new object.
5764 * _.fromPairs([['fred', 30], ['barney', 40]]);
5765 * // => { 'fred': 30, 'barney': 40 }
5767 function fromPairs(pairs) {
5769 length = pairs ? pairs.length : 0,
5772 while (++index < length) {
5773 var pair = pairs[index];
5774 result[pair[0]] = pair[1];
5780 * Gets the first element of `array`.
5786 * @param {Array} array The array to query.
5787 * @returns {*} Returns the first element of `array`.
5790 * _.head([1, 2, 3]);
5796 function head(array) {
5797 return array ? array[0] : undefined;
5801 * Gets the index at which the first occurrence of `value` is found in `array`
5802 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5803 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
5804 * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
5805 * performs a faster binary search.
5810 * @param {Array} array The array to search.
5811 * @param {*} value The value to search for.
5812 * @param {number} [fromIndex=0] The index to search from.
5813 * @returns {number} Returns the index of the matched value, else `-1`.
5816 * _.indexOf([1, 2, 1, 2], 2);
5819 * // using `fromIndex`
5820 * _.indexOf([1, 2, 1, 2], 2, 2);
5823 function indexOf(array, value, fromIndex) {
5824 var length = array ? array.length : 0;
5828 fromIndex = toInteger(fromIndex);
5829 if (fromIndex < 0) {
5830 fromIndex = nativeMax(length + fromIndex, 0);
5832 return baseIndexOf(array, value, fromIndex);
5836 * Gets all but the last element of `array`.
5841 * @param {Array} array The array to query.
5842 * @returns {Array} Returns the slice of `array`.
5845 * _.initial([1, 2, 3]);
5848 function initial(array) {
5849 return dropRight(array, 1);
5853 * Creates an array of unique values that are included in all of the provided
5854 * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5855 * for equality comparisons.
5860 * @param {...Array} [arrays] The arrays to inspect.
5861 * @returns {Array} Returns the new array of shared values.
5864 * _.intersection([2, 1], [4, 2], [1, 2]);
5867 var intersection = rest(function(arrays) {
5868 var mapped = arrayMap(arrays, toArrayLikeObject);
5869 return (mapped.length && mapped[0] === arrays[0])
5870 ? baseIntersection(mapped)
5875 * This method is like `_.intersection` except that it accepts `iteratee`
5876 * which is invoked for each element of each `arrays` to generate the criterion
5877 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
5882 * @param {...Array} [arrays] The arrays to inspect.
5883 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
5884 * @returns {Array} Returns the new array of shared values.
5887 * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
5890 * // using the `_.property` iteratee shorthand
5891 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
5892 * // => [{ 'x': 1 }]
5894 var intersectionBy = rest(function(arrays) {
5895 var iteratee = last(arrays),
5896 mapped = arrayMap(arrays, toArrayLikeObject);
5898 if (iteratee === last(mapped)) {
5899 iteratee = undefined;
5903 return (mapped.length && mapped[0] === arrays[0])
5904 ? baseIntersection(mapped, getIteratee(iteratee))
5909 * This method is like `_.intersection` except that it accepts `comparator`
5910 * which is invoked to compare elements of `arrays`. The comparator is invoked
5911 * with two arguments: (arrVal, othVal).
5916 * @param {...Array} [arrays] The arrays to inspect.
5917 * @param {Function} [comparator] The comparator invoked per element.
5918 * @returns {Array} Returns the new array of shared values.
5921 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
5922 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
5924 * _.intersectionWith(objects, others, _.isEqual);
5925 * // => [{ 'x': 1, 'y': 2 }]
5927 var intersectionWith = rest(function(arrays) {
5928 var comparator = last(arrays),
5929 mapped = arrayMap(arrays, toArrayLikeObject);
5931 if (comparator === last(mapped)) {
5932 comparator = undefined;
5936 return (mapped.length && mapped[0] === arrays[0])
5937 ? baseIntersection(mapped, undefined, comparator)
5942 * Converts all elements in `array` into a string separated by `separator`.
5947 * @param {Array} array The array to convert.
5948 * @param {string} [separator=','] The element separator.
5949 * @returns {string} Returns the joined string.
5952 * _.join(['a', 'b', 'c'], '~');
5955 function join(array, separator) {
5956 return array ? nativeJoin.call(array, separator) : '';
5960 * Gets the last element of `array`.
5965 * @param {Array} array The array to query.
5966 * @returns {*} Returns the last element of `array`.
5969 * _.last([1, 2, 3]);
5972 function last(array) {
5973 var length = array ? array.length : 0;
5974 return length ? array[length - 1] : undefined;
5978 * This method is like `_.indexOf` except that it iterates over elements of
5979 * `array` from right to left.
5984 * @param {Array} array The array to search.
5985 * @param {*} value The value to search for.
5986 * @param {number} [fromIndex=array.length-1] The index to search from.
5987 * @returns {number} Returns the index of the matched value, else `-1`.
5990 * _.lastIndexOf([1, 2, 1, 2], 2);
5993 * // using `fromIndex`
5994 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
5997 function lastIndexOf(array, value, fromIndex) {
5998 var length = array ? array.length : 0;
6003 if (fromIndex !== undefined) {
6004 index = toInteger(fromIndex);
6005 index = (index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1)) + 1;
6007 if (value !== value) {
6008 return indexOfNaN(array, index, true);
6011 if (array[index] === value) {
6019 * Removes all provided values from `array` using
6020 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6021 * for equality comparisons.
6023 * **Note:** Unlike `_.without`, this method mutates `array`.
6028 * @param {Array} array The array to modify.
6029 * @param {...*} [values] The values to remove.
6030 * @returns {Array} Returns `array`.
6033 * var array = [1, 2, 3, 1, 2, 3];
6035 * _.pull(array, 2, 3);
6036 * console.log(array);
6039 var pull = rest(pullAll);
6042 * This method is like `_.pull` except that it accepts an array of values to remove.
6044 * **Note:** Unlike `_.difference`, this method mutates `array`.
6049 * @param {Array} array The array to modify.
6050 * @param {Array} values The values to remove.
6051 * @returns {Array} Returns `array`.
6054 * var array = [1, 2, 3, 1, 2, 3];
6056 * _.pullAll(array, [2, 3]);
6057 * console.log(array);
6060 function pullAll(array, values) {
6061 return (array && array.length && values && values.length)
6062 ? basePullAll(array, values)
6067 * This method is like `_.pullAll` except that it accepts `iteratee` which is
6068 * invoked for each element of `array` and `values` to to generate the criterion
6069 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
6071 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
6076 * @param {Array} array The array to modify.
6077 * @param {Array} values The values to remove.
6078 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6079 * @returns {Array} Returns `array`.
6082 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
6084 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
6085 * console.log(array);
6086 * // => [{ 'x': 2 }]
6088 function pullAllBy(array, values, iteratee) {
6089 return (array && array.length && values && values.length)
6090 ? basePullAllBy(array, values, getIteratee(iteratee))
6095 * Removes elements from `array` corresponding to `indexes` and returns an
6096 * array of removed elements.
6098 * **Note:** Unlike `_.at`, this method mutates `array`.
6103 * @param {Array} array The array to modify.
6104 * @param {...(number|number[])} [indexes] The indexes of elements to remove,
6105 * specified individually or in arrays.
6106 * @returns {Array} Returns the new array of removed elements.
6109 * var array = [5, 10, 15, 20];
6110 * var evens = _.pullAt(array, 1, 3);
6112 * console.log(array);
6115 * console.log(evens);
6118 var pullAt = rest(function(array, indexes) {
6119 indexes = arrayMap(baseFlatten(indexes), String);
6121 var result = baseAt(array, indexes);
6122 basePullAt(array, indexes.sort(compareAscending));
6127 * Removes all elements from `array` that `predicate` returns truthy for
6128 * and returns an array of the removed elements. The predicate is invoked with
6129 * three arguments: (value, index, array).
6131 * **Note:** Unlike `_.filter`, this method mutates `array`.
6136 * @param {Array} array The array to modify.
6137 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6138 * @returns {Array} Returns the new array of removed elements.
6141 * var array = [1, 2, 3, 4];
6142 * var evens = _.remove(array, function(n) {
6143 * return n % 2 == 0;
6146 * console.log(array);
6149 * console.log(evens);
6152 function remove(array, predicate) {
6154 if (!(array && array.length)) {
6159 length = array.length;
6161 predicate = getIteratee(predicate, 3);
6162 while (++index < length) {
6163 var value = array[index];
6164 if (predicate(value, index, array)) {
6166 indexes.push(index);
6169 basePullAt(array, indexes);
6174 * Reverses `array` so that the first element becomes the last, the second
6175 * element becomes the second to last, and so on.
6177 * **Note:** This method mutates `array` and is based on
6178 * [`Array#reverse`](https://mdn.io/Array/reverse).
6183 * @returns {Array} Returns `array`.
6186 * var array = [1, 2, 3];
6191 * console.log(array);
6194 function reverse(array) {
6195 return array ? nativeReverse.call(array) : array;
6199 * Creates a slice of `array` from `start` up to, but not including, `end`.
6201 * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
6202 * to ensure dense arrays are returned.
6207 * @param {Array} array The array to slice.
6208 * @param {number} [start=0] The start position.
6209 * @param {number} [end=array.length] The end position.
6210 * @returns {Array} Returns the slice of `array`.
6212 function slice(array, start, end) {
6213 var length = array ? array.length : 0;
6217 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
6222 start = start == null ? 0 : toInteger(start);
6223 end = end === undefined ? length : toInteger(end);
6225 return baseSlice(array, start, end);
6229 * Uses a binary search to determine the lowest index at which `value` should
6230 * be inserted into `array` in order to maintain its sort order.
6235 * @param {Array} array The sorted array to inspect.
6236 * @param {*} value The value to evaluate.
6237 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6240 * _.sortedIndex([30, 50], 40);
6243 * _.sortedIndex([4, 5], 4);
6246 function sortedIndex(array, value) {
6247 return baseSortedIndex(array, value);
6251 * This method is like `_.sortedIndex` except that it accepts `iteratee`
6252 * which is invoked for `value` and each element of `array` to compute their
6253 * sort ranking. The iteratee is invoked with one argument: (value).
6258 * @param {Array} array The sorted array to inspect.
6259 * @param {*} value The value to evaluate.
6260 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6261 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6264 * var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 };
6266 * _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict));
6269 * // using the `_.property` iteratee shorthand
6270 * _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
6273 function sortedIndexBy(array, value, iteratee) {
6274 return baseSortedIndexBy(array, value, getIteratee(iteratee));
6278 * This method is like `_.indexOf` except that it performs a binary
6279 * search on a sorted `array`.
6284 * @param {Array} array The array to search.
6285 * @param {*} value The value to search for.
6286 * @returns {number} Returns the index of the matched value, else `-1`.
6289 * _.sortedIndexOf([1, 1, 2, 2], 2);
6292 function sortedIndexOf(array, value) {
6293 var length = array ? array.length : 0;
6295 var index = baseSortedIndex(array, value);
6296 if (index < length && eq(array[index], value)) {
6304 * This method is like `_.sortedIndex` except that it returns the highest
6305 * index at which `value` should be inserted into `array` in order to
6306 * maintain its sort order.
6311 * @param {Array} array The sorted array to inspect.
6312 * @param {*} value The value to evaluate.
6313 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6316 * _.sortedLastIndex([4, 5], 4);
6319 function sortedLastIndex(array, value) {
6320 return baseSortedIndex(array, value, true);
6324 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
6325 * which is invoked for `value` and each element of `array` to compute their
6326 * sort ranking. The iteratee is invoked with one argument: (value).
6331 * @param {Array} array The sorted array to inspect.
6332 * @param {*} value The value to evaluate.
6333 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6334 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6337 * // using the `_.property` iteratee shorthand
6338 * _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
6341 function sortedLastIndexBy(array, value, iteratee) {
6342 return baseSortedIndexBy(array, value, getIteratee(iteratee), true);
6346 * This method is like `_.lastIndexOf` except that it performs a binary
6347 * search on a sorted `array`.
6352 * @param {Array} array The array to search.
6353 * @param {*} value The value to search for.
6354 * @returns {number} Returns the index of the matched value, else `-1`.
6357 * _.sortedLastIndexOf([1, 1, 2, 2], 2);
6360 function sortedLastIndexOf(array, value) {
6361 var length = array ? array.length : 0;
6363 var index = baseSortedIndex(array, value, true) - 1;
6364 if (eq(array[index], value)) {
6372 * This method is like `_.uniq` except that it's designed and optimized
6373 * for sorted arrays.
6378 * @param {Array} array The array to inspect.
6379 * @returns {Array} Returns the new duplicate free array.
6382 * _.sortedUniq([1, 1, 2]);
6385 function sortedUniq(array) {
6386 return (array && array.length)
6387 ? baseSortedUniq(array)
6392 * This method is like `_.uniqBy` except that it's designed and optimized
6393 * for sorted arrays.
6398 * @param {Array} array The array to inspect.
6399 * @param {Function} [iteratee] The iteratee invoked per element.
6400 * @returns {Array} Returns the new duplicate free array.
6403 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
6406 function sortedUniqBy(array, iteratee) {
6407 return (array && array.length)
6408 ? baseSortedUniqBy(array, getIteratee(iteratee))
6413 * Gets all but the first element of `array`.
6418 * @param {Array} array The array to query.
6419 * @returns {Array} Returns the slice of `array`.
6422 * _.tail([1, 2, 3]);
6425 function tail(array) {
6426 return drop(array, 1);
6430 * Creates a slice of `array` with `n` elements taken from the beginning.
6435 * @param {Array} array The array to query.
6436 * @param {number} [n=1] The number of elements to take.
6437 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
6438 * @returns {Array} Returns the slice of `array`.
6441 * _.take([1, 2, 3]);
6444 * _.take([1, 2, 3], 2);
6447 * _.take([1, 2, 3], 5);
6450 * _.take([1, 2, 3], 0);
6453 function take(array, n, guard) {
6454 if (!(array && array.length)) {
6457 n = (guard || n === undefined) ? 1 : toInteger(n);
6458 return baseSlice(array, 0, n < 0 ? 0 : n);
6462 * Creates a slice of `array` with `n` elements taken from the end.
6467 * @param {Array} array The array to query.
6468 * @param {number} [n=1] The number of elements to take.
6469 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
6470 * @returns {Array} Returns the slice of `array`.
6473 * _.takeRight([1, 2, 3]);
6476 * _.takeRight([1, 2, 3], 2);
6479 * _.takeRight([1, 2, 3], 5);
6482 * _.takeRight([1, 2, 3], 0);
6485 function takeRight(array, n, guard) {
6486 var length = array ? array.length : 0;
6490 n = (guard || n === undefined) ? 1 : toInteger(n);
6492 return baseSlice(array, n < 0 ? 0 : n, length);
6496 * Creates a slice of `array` with elements taken from the end. Elements are
6497 * taken until `predicate` returns falsey. The predicate is invoked with three
6498 * arguments: (value, index, array).
6503 * @param {Array} array The array to query.
6504 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6505 * @returns {Array} Returns the slice of `array`.
6509 * { 'user': 'barney', 'active': true },
6510 * { 'user': 'fred', 'active': false },
6511 * { 'user': 'pebbles', 'active': false }
6514 * _.takeRightWhile(users, function(o) { return !o.active; });
6515 * // => objects for ['fred', 'pebbles']
6517 * // using the `_.matches` iteratee shorthand
6518 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
6519 * // => objects for ['pebbles']
6521 * // using the `_.matchesProperty` iteratee shorthand
6522 * _.takeRightWhile(users, ['active', false]);
6523 * // => objects for ['fred', 'pebbles']
6525 * // using the `_.property` iteratee shorthand
6526 * _.takeRightWhile(users, 'active');
6529 function takeRightWhile(array, predicate) {
6530 return (array && array.length)
6531 ? baseWhile(array, getIteratee(predicate, 3), false, true)
6536 * Creates a slice of `array` with elements taken from the beginning. Elements
6537 * are taken until `predicate` returns falsey. The predicate is invoked with
6538 * three arguments: (value, index, array).
6543 * @param {Array} array The array to query.
6544 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6545 * @returns {Array} Returns the slice of `array`.
6549 * { 'user': 'barney', 'active': false },
6550 * { 'user': 'fred', 'active': false},
6551 * { 'user': 'pebbles', 'active': true }
6554 * _.takeWhile(users, function(o) { return !o.active; });
6555 * // => objects for ['barney', 'fred']
6557 * // using the `_.matches` iteratee shorthand
6558 * _.takeWhile(users, { 'user': 'barney', 'active': false });
6559 * // => objects for ['barney']
6561 * // using the `_.matchesProperty` iteratee shorthand
6562 * _.takeWhile(users, ['active', false]);
6563 * // => objects for ['barney', 'fred']
6565 * // using the `_.property` iteratee shorthand
6566 * _.takeWhile(users, 'active');
6569 function takeWhile(array, predicate) {
6570 return (array && array.length)
6571 ? baseWhile(array, getIteratee(predicate, 3))
6576 * Creates an array of unique values, in order, from all of the provided arrays
6577 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6578 * for equality comparisons.
6583 * @param {...Array} [arrays] The arrays to inspect.
6584 * @returns {Array} Returns the new array of combined values.
6587 * _.union([2, 1], [4, 2], [1, 2]);
6590 var union = rest(function(arrays) {
6591 return baseUniq(baseFlatten(arrays, false, true));
6595 * This method is like `_.union` except that it accepts `iteratee` which is
6596 * invoked for each element of each `arrays` to generate the criterion by which
6597 * uniqueness is computed. The iteratee is invoked with one argument: (value).
6602 * @param {...Array} [arrays] The arrays to inspect.
6603 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6604 * @returns {Array} Returns the new array of combined values.
6607 * _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
6608 * // => [2.1, 1.2, 4.3]
6610 * // using the `_.property` iteratee shorthand
6611 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
6612 * // => [{ 'x': 1 }, { 'x': 2 }]
6614 var unionBy = rest(function(arrays) {
6615 var iteratee = last(arrays);
6616 if (isArrayLikeObject(iteratee)) {
6617 iteratee = undefined;
6619 return baseUniq(baseFlatten(arrays, false, true), getIteratee(iteratee));
6623 * This method is like `_.union` except that it accepts `comparator` which
6624 * is invoked to compare elements of `arrays`. The comparator is invoked
6625 * with two arguments: (arrVal, othVal).
6630 * @param {...Array} [arrays] The arrays to inspect.
6631 * @param {Function} [comparator] The comparator invoked per element.
6632 * @returns {Array} Returns the new array of combined values.
6635 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6636 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6638 * _.unionWith(objects, others, _.isEqual);
6639 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
6641 var unionWith = rest(function(arrays) {
6642 var comparator = last(arrays);
6643 if (isArrayLikeObject(comparator)) {
6644 comparator = undefined;
6646 return baseUniq(baseFlatten(arrays, false, true), undefined, comparator);
6650 * Creates a duplicate-free version of an array, using
6651 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6652 * for equality comparisons, in which only the first occurrence of each element
6658 * @param {Array} array The array to inspect.
6659 * @returns {Array} Returns the new duplicate free array.
6662 * _.uniq([2, 1, 2]);
6665 function uniq(array) {
6666 return (array && array.length)
6672 * This method is like `_.uniq` except that it accepts `iteratee` which is
6673 * invoked for each element in `array` to generate the criterion by which
6674 * uniqueness is computed. The iteratee is invoked with one argument: (value).
6679 * @param {Array} array The array to inspect.
6680 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6681 * @returns {Array} Returns the new duplicate free array.
6684 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
6687 * // using the `_.property` iteratee shorthand
6688 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
6689 * // => [{ 'x': 1 }, { 'x': 2 }]
6691 function uniqBy(array, iteratee) {
6692 return (array && array.length)
6693 ? baseUniq(array, getIteratee(iteratee))
6698 * This method is like `_.uniq` except that it accepts `comparator` which
6699 * is invoked to compare elements of `array`. The comparator is invoked with
6700 * two arguments: (arrVal, othVal).
6705 * @param {Array} array The array to inspect.
6706 * @param {Function} [comparator] The comparator invoked per element.
6707 * @returns {Array} Returns the new duplicate free array.
6710 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
6712 * _.uniqWith(objects, _.isEqual);
6713 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
6715 function uniqWith(array, comparator) {
6716 return (array && array.length)
6717 ? baseUniq(array, undefined, comparator)
6722 * This method is like `_.zip` except that it accepts an array of grouped
6723 * elements and creates an array regrouping the elements to their pre-zip
6729 * @param {Array} array The array of grouped elements to process.
6730 * @returns {Array} Returns the new array of regrouped elements.
6733 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
6734 * // => [['fred', 30, true], ['barney', 40, false]]
6737 * // => [['fred', 'barney'], [30, 40], [true, false]]
6739 function unzip(array) {
6740 if (!(array && array.length)) {
6744 array = arrayFilter(array, function(group) {
6745 if (isArrayLikeObject(group)) {
6746 length = nativeMax(group.length, length);
6750 return baseTimes(length, function(index) {
6751 return arrayMap(array, baseProperty(index));
6756 * This method is like `_.unzip` except that it accepts `iteratee` to specify
6757 * how regrouped values should be combined. The iteratee is invoked with the
6758 * elements of each group: (...group).
6763 * @param {Array} array The array of grouped elements to process.
6764 * @param {Function} [iteratee=_.identity] The function to combine regrouped values.
6765 * @returns {Array} Returns the new array of regrouped elements.
6768 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
6769 * // => [[1, 10, 100], [2, 20, 200]]
6771 * _.unzipWith(zipped, _.add);
6772 * // => [3, 30, 300]
6774 function unzipWith(array, iteratee) {
6775 if (!(array && array.length)) {
6778 var result = unzip(array);
6779 if (iteratee == null) {
6782 return arrayMap(result, function(group) {
6783 return apply(iteratee, undefined, group);
6788 * Creates an array excluding all provided values using
6789 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6790 * for equality comparisons.
6795 * @param {Array} array The array to filter.
6796 * @param {...*} [values] The values to exclude.
6797 * @returns {Array} Returns the new array of filtered values.
6800 * _.without([1, 2, 1, 3], 1, 2);
6803 var without = rest(function(array, values) {
6804 return isArrayLikeObject(array)
6805 ? baseDifference(array, values)
6810 * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
6811 * of the provided arrays.
6816 * @param {...Array} [arrays] The arrays to inspect.
6817 * @returns {Array} Returns the new array of values.
6820 * _.xor([2, 1], [4, 2]);
6823 var xor = rest(function(arrays) {
6824 return baseXor(arrayFilter(arrays, isArrayLikeObject));
6828 * This method is like `_.xor` except that it accepts `iteratee` which is
6829 * invoked for each element of each `arrays` to generate the criterion by which
6830 * uniqueness is computed. The iteratee is invoked with one argument: (value).
6835 * @param {...Array} [arrays] The arrays to inspect.
6836 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6837 * @returns {Array} Returns the new array of values.
6840 * _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
6843 * // using the `_.property` iteratee shorthand
6844 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
6845 * // => [{ 'x': 2 }]
6847 var xorBy = rest(function(arrays) {
6848 var iteratee = last(arrays);
6849 if (isArrayLikeObject(iteratee)) {
6850 iteratee = undefined;
6852 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee));
6856 * This method is like `_.xor` except that it accepts `comparator` which is
6857 * invoked to compare elements of `arrays`. The comparator is invoked with
6858 * two arguments: (arrVal, othVal).
6863 * @param {...Array} [arrays] The arrays to inspect.
6864 * @param {Function} [comparator] The comparator invoked per element.
6865 * @returns {Array} Returns the new array of values.
6868 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6869 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6871 * _.xorWith(objects, others, _.isEqual);
6872 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
6874 var xorWith = rest(function(arrays) {
6875 var comparator = last(arrays);
6876 if (isArrayLikeObject(comparator)) {
6877 comparator = undefined;
6879 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
6883 * Creates an array of grouped elements, the first of which contains the first
6884 * elements of the given arrays, the second of which contains the second elements
6885 * of the given arrays, and so on.
6890 * @param {...Array} [arrays] The arrays to process.
6891 * @returns {Array} Returns the new array of grouped elements.
6894 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
6895 * // => [['fred', 30, true], ['barney', 40, false]]
6897 var zip = rest(unzip);
6900 * This method is like `_.fromPairs` except that it accepts two arrays,
6901 * one of property names and one of corresponding values.
6906 * @param {Array} [props=[]] The property names.
6907 * @param {Array} [values=[]] The property values.
6908 * @returns {Object} Returns the new object.
6911 * _.zipObject(['fred', 'barney'], [30, 40]);
6912 * // => { 'fred': 30, 'barney': 40 }
6914 function zipObject(props, values) {
6916 length = props ? props.length : 0,
6917 valsLength = values ? values.length : 0,
6920 while (++index < length) {
6921 baseSet(result, props[index], index < valsLength ? values[index] : undefined);
6927 * This method is like `_.zip` except that it accepts `iteratee` to specify
6928 * how grouped values should be combined. The iteratee is invoked with the
6929 * elements of each group: (...group).
6934 * @param {...Array} [arrays] The arrays to process.
6935 * @param {Function} [iteratee=_.identity] The function to combine grouped values.
6936 * @returns {Array} Returns the new array of grouped elements.
6939 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
6944 var zipWith = rest(function(arrays) {
6945 var length = arrays.length,
6946 iteratee = length > 1 ? arrays[length - 1] : undefined;
6948 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
6949 return unzipWith(arrays, iteratee);
6952 /*------------------------------------------------------------------------*/
6955 * Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
6956 * The result of such method chaining must be unwrapped with `_#value`.
6961 * @param {*} value The value to wrap.
6962 * @returns {Object} Returns the new `lodash` wrapper instance.
6966 * { 'user': 'barney', 'age': 36 },
6967 * { 'user': 'fred', 'age': 40 },
6968 * { 'user': 'pebbles', 'age': 1 }
6974 * .map(function(o) {
6975 * return o.user + ' is ' + o.age;
6979 * // => 'pebbles is 1'
6981 function chain(value) {
6982 var result = lodash(value);
6983 result.__chain__ = true;
6988 * This method invokes `interceptor` and returns `value`. The interceptor is
6989 * invoked with one argument; (value). The purpose of this method is to "tap into"
6990 * a method chain in order to perform operations on intermediate results within
6996 * @param {*} value The value to provide to `interceptor`.
6997 * @param {Function} interceptor The function to invoke.
6998 * @returns {*} Returns `value`.
7002 * .tap(function(array) {
7009 function tap(value, interceptor) {
7015 * This method is like `_.tap` except that it returns the result of `interceptor`.
7020 * @param {*} value The value to provide to `interceptor`.
7021 * @param {Function} interceptor The function to invoke.
7022 * @returns {*} Returns the result of `interceptor`.
7028 * .thru(function(value) {
7034 function thru(value, interceptor) {
7035 return interceptor(value);
7039 * This method is the wrapper version of `_.at`.
7044 * @param {...(string|string[])} [paths] The property paths of elements to pick,
7045 * specified individually or in arrays.
7046 * @returns {Object} Returns the new `lodash` wrapper instance.
7049 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
7051 * _(object).at(['a[0].b.c', 'a[1]']).value();
7054 * _(['a', 'b', 'c']).at(0, 2).value();
7057 var wrapperAt = rest(function(paths) {
7058 paths = baseFlatten(paths);
7059 var length = paths.length,
7060 start = length ? paths[0] : 0,
7061 value = this.__wrapped__,
7062 interceptor = function(object) { return baseAt(object, paths); };
7064 if (length > 1 || this.__actions__.length || !(value instanceof LazyWrapper) || !isIndex(start)) {
7065 return this.thru(interceptor);
7067 value = value.slice(start, +start + (length ? 1 : 0));
7068 value.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
7069 return new LodashWrapper(value, this.__chain__).thru(function(array) {
7070 if (length && !array.length) {
7071 array.push(undefined);
7078 * Enables explicit method chaining on the wrapper object.
7083 * @returns {Object} Returns the new `lodash` wrapper instance.
7087 * { 'user': 'barney', 'age': 36 },
7088 * { 'user': 'fred', 'age': 40 }
7091 * // without explicit chaining
7093 * // => { 'user': 'barney', 'age': 36 }
7095 * // with explicit chaining
7101 * // => { 'user': 'barney' }
7103 function wrapperChain() {
7108 * Executes the chained sequence and returns the wrapped result.
7113 * @returns {Object} Returns the new `lodash` wrapper instance.
7116 * var array = [1, 2];
7117 * var wrapped = _(array).push(3);
7119 * console.log(array);
7122 * wrapped = wrapped.commit();
7123 * console.log(array);
7129 * console.log(array);
7132 function wrapperCommit() {
7133 return new LodashWrapper(this.value(), this.__chain__);
7137 * This method is the wrapper version of `_.flatMap`.
7142 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
7143 * @returns {Object} Returns the new `lodash` wrapper instance.
7146 * function duplicate(n) {
7150 * _([1, 2]).flatMap(duplicate).value();
7151 * // => [1, 1, 2, 2]
7153 function wrapperFlatMap(iteratee) {
7154 return this.map(iteratee).flatten();
7158 * Gets the next value on a wrapped object following the
7159 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
7164 * @returns {Object} Returns the next iterator value.
7167 * var wrapped = _([1, 2]);
7170 * // => { 'done': false, 'value': 1 }
7173 * // => { 'done': false, 'value': 2 }
7176 * // => { 'done': true, 'value': undefined }
7178 function wrapperNext() {
7179 if (this.__values__ === undefined) {
7180 this.__values__ = toArray(this.value());
7182 var done = this.__index__ >= this.__values__.length,
7183 value = done ? undefined : this.__values__[this.__index__++];
7185 return { 'done': done, 'value': value };
7189 * Enables the wrapper to be iterable.
7191 * @name Symbol.iterator
7194 * @returns {Object} Returns the wrapper object.
7197 * var wrapped = _([1, 2]);
7199 * wrapped[Symbol.iterator]() === wrapped;
7202 * Array.from(wrapped);
7205 function wrapperToIterator() {
7210 * Creates a clone of the chained sequence planting `value` as the wrapped value.
7215 * @param {*} value The value to plant.
7216 * @returns {Object} Returns the new `lodash` wrapper instance.
7219 * function square(n) {
7223 * var wrapped = _([1, 2]).map(square);
7224 * var other = wrapped.plant([3, 4]);
7232 function wrapperPlant(value) {
7236 while (parent instanceof baseLodash) {
7237 var clone = wrapperClone(parent);
7238 clone.__index__ = 0;
7239 clone.__values__ = undefined;
7241 previous.__wrapped__ = clone;
7245 var previous = clone;
7246 parent = parent.__wrapped__;
7248 previous.__wrapped__ = value;
7253 * This method is the wrapper version of `_.reverse`.
7255 * **Note:** This method mutates the wrapped array.
7260 * @returns {Object} Returns the new `lodash` wrapper instance.
7263 * var array = [1, 2, 3];
7265 * _(array).reverse().value()
7268 * console.log(array);
7271 function wrapperReverse() {
7272 var value = this.__wrapped__;
7273 if (value instanceof LazyWrapper) {
7274 var wrapped = value;
7275 if (this.__actions__.length) {
7276 wrapped = new LazyWrapper(this);
7278 wrapped = wrapped.reverse();
7279 wrapped.__actions__.push({ 'func': thru, 'args': [reverse], 'thisArg': undefined });
7280 return new LodashWrapper(wrapped, this.__chain__);
7282 return this.thru(reverse);
7286 * Executes the chained sequence to extract the unwrapped value.
7290 * @alias toJSON, valueOf
7292 * @returns {*} Returns the resolved unwrapped value.
7295 * _([1, 2, 3]).value();
7298 function wrapperValue() {
7299 return baseWrapperValue(this.__wrapped__, this.__actions__);
7302 /*------------------------------------------------------------------------*/
7305 * Creates an object composed of keys generated from the results of running
7306 * each element of `collection` through `iteratee`. The corresponding value
7307 * of each key is the number of times the key was returned by `iteratee`.
7308 * The iteratee is invoked with one argument: (value).
7312 * @category Collection
7313 * @param {Array|Object} collection The collection to iterate over.
7314 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7315 * @returns {Object} Returns the composed aggregate object.
7318 * _.countBy([6.1, 4.2, 6.3], Math.floor);
7319 * // => { '4': 1, '6': 2 }
7321 * _.countBy(['one', 'two', 'three'], 'length');
7322 * // => { '3': 2, '5': 1 }
7324 var countBy = createAggregator(function(result, value, key) {
7325 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
7329 * Checks if `predicate` returns truthy for **all** elements of `collection`.
7330 * Iteration is stopped once `predicate` returns falsey. The predicate is
7331 * invoked with three arguments: (value, index|key, collection).
7335 * @category Collection
7336 * @param {Array|Object} collection The collection to iterate over.
7337 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7338 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
7339 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
7342 * _.every([true, 1, null, 'yes'], Boolean);
7346 * { 'user': 'barney', 'active': false },
7347 * { 'user': 'fred', 'active': false }
7350 * // using the `_.matches` iteratee shorthand
7351 * _.every(users, { 'user': 'barney', 'active': false });
7354 * // using the `_.matchesProperty` iteratee shorthand
7355 * _.every(users, ['active', false]);
7358 * // using the `_.property` iteratee shorthand
7359 * _.every(users, 'active');
7362 function every(collection, predicate, guard) {
7363 var func = isArray(collection) ? arrayEvery : baseEvery;
7364 if (guard && isIterateeCall(collection, predicate, guard)) {
7365 predicate = undefined;
7367 return func(collection, getIteratee(predicate, 3));
7371 * Iterates over elements of `collection`, returning an array of all elements
7372 * `predicate` returns truthy for. The predicate is invoked with three arguments:
7373 * (value, index|key, collection).
7377 * @category Collection
7378 * @param {Array|Object} collection The collection to iterate over.
7379 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7380 * @returns {Array} Returns the new filtered array.
7384 * { 'user': 'barney', 'age': 36, 'active': true },
7385 * { 'user': 'fred', 'age': 40, 'active': false }
7388 * _.filter(users, function(o) { return !o.active; });
7389 * // => objects for ['fred']
7391 * // using the `_.matches` iteratee shorthand
7392 * _.filter(users, { 'age': 36, 'active': true });
7393 * // => objects for ['barney']
7395 * // using the `_.matchesProperty` iteratee shorthand
7396 * _.filter(users, ['active', false]);
7397 * // => objects for ['fred']
7399 * // using the `_.property` iteratee shorthand
7400 * _.filter(users, 'active');
7401 * // => objects for ['barney']
7403 function filter(collection, predicate) {
7404 var func = isArray(collection) ? arrayFilter : baseFilter;
7405 return func(collection, getIteratee(predicate, 3));
7409 * Iterates over elements of `collection`, returning the first element
7410 * `predicate` returns truthy for. The predicate is invoked with three arguments:
7411 * (value, index|key, collection).
7415 * @category Collection
7416 * @param {Array|Object} collection The collection to search.
7417 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7418 * @returns {*} Returns the matched element, else `undefined`.
7422 * { 'user': 'barney', 'age': 36, 'active': true },
7423 * { 'user': 'fred', 'age': 40, 'active': false },
7424 * { 'user': 'pebbles', 'age': 1, 'active': true }
7427 * _.find(users, function(o) { return o.age < 40; });
7428 * // => object for 'barney'
7430 * // using the `_.matches` iteratee shorthand
7431 * _.find(users, { 'age': 1, 'active': true });
7432 * // => object for 'pebbles'
7434 * // using the `_.matchesProperty` iteratee shorthand
7435 * _.find(users, ['active', false]);
7436 * // => object for 'fred'
7438 * // using the `_.property` iteratee shorthand
7439 * _.find(users, 'active');
7440 * // => object for 'barney'
7442 function find(collection, predicate) {
7443 predicate = getIteratee(predicate, 3);
7444 if (isArray(collection)) {
7445 var index = baseFindIndex(collection, predicate);
7446 return index > -1 ? collection[index] : undefined;
7448 return baseFind(collection, predicate, baseEach);
7452 * This method is like `_.find` except that it iterates over elements of
7453 * `collection` from right to left.
7457 * @category Collection
7458 * @param {Array|Object} collection The collection to search.
7459 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7460 * @returns {*} Returns the matched element, else `undefined`.
7463 * _.findLast([1, 2, 3, 4], function(n) {
7464 * return n % 2 == 1;
7468 function findLast(collection, predicate) {
7469 predicate = getIteratee(predicate, 3);
7470 if (isArray(collection)) {
7471 var index = baseFindIndex(collection, predicate, true);
7472 return index > -1 ? collection[index] : undefined;
7474 return baseFind(collection, predicate, baseEachRight);
7478 * Iterates over elements of `collection` invoking `iteratee` for each element.
7479 * The iteratee is invoked with three arguments: (value, index|key, collection).
7480 * Iteratee functions may exit iteration early by explicitly returning `false`.
7482 * **Note:** As with other "Collections" methods, objects with a "length" property
7483 * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
7484 * for object iteration.
7489 * @category Collection
7490 * @param {Array|Object} collection The collection to iterate over.
7491 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7492 * @returns {Array|Object} Returns `collection`.
7495 * _([1, 2]).forEach(function(value) {
7496 * console.log(value);
7498 * // => logs `1` then `2`
7500 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
7503 * // => logs 'a' then 'b' (iteration order is not guaranteed)
7505 function forEach(collection, iteratee) {
7506 return (typeof iteratee == 'function' && isArray(collection))
7507 ? arrayEach(collection, iteratee)
7508 : baseEach(collection, toFunction(iteratee));
7512 * This method is like `_.forEach` except that it iterates over elements of
7513 * `collection` from right to left.
7518 * @category Collection
7519 * @param {Array|Object} collection The collection to iterate over.
7520 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7521 * @returns {Array|Object} Returns `collection`.
7524 * _.forEachRight([1, 2], function(value) {
7525 * console.log(value);
7527 * // => logs `2` then `1`
7529 function forEachRight(collection, iteratee) {
7530 return (typeof iteratee == 'function' && isArray(collection))
7531 ? arrayEachRight(collection, iteratee)
7532 : baseEachRight(collection, toFunction(iteratee));
7536 * Creates an object composed of keys generated from the results of running
7537 * each element of `collection` through `iteratee`. The corresponding value
7538 * of each key is an array of elements responsible for generating the key.
7539 * The iteratee is invoked with one argument: (value).
7543 * @category Collection
7544 * @param {Array|Object} collection The collection to iterate over.
7545 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7546 * @returns {Object} Returns the composed aggregate object.
7549 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
7550 * // => { '4': [4.2], '6': [6.1, 6.3] }
7552 * // using the `_.property` iteratee shorthand
7553 * _.groupBy(['one', 'two', 'three'], 'length');
7554 * // => { '3': ['one', 'two'], '5': ['three'] }
7556 var groupBy = createAggregator(function(result, value, key) {
7557 if (hasOwnProperty.call(result, key)) {
7558 result[key].push(value);
7560 result[key] = [value];
7565 * Checks if `value` is in `collection`. If `collection` is a string it's checked
7566 * for a substring of `value`, otherwise [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7567 * is used for equality comparisons. If `fromIndex` is negative, it's used as
7568 * the offset from the end of `collection`.
7572 * @category Collection
7573 * @param {Array|Object|string} collection The collection to search.
7574 * @param {*} value The value to search for.
7575 * @param {number} [fromIndex=0] The index to search from.
7576 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`.
7577 * @returns {boolean} Returns `true` if `value` is found, else `false`.
7580 * _.includes([1, 2, 3], 1);
7583 * _.includes([1, 2, 3], 1, 2);
7586 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
7589 * _.includes('pebbles', 'eb');
7592 function includes(collection, value, fromIndex, guard) {
7593 collection = isArrayLike(collection) ? collection : values(collection);
7594 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
7596 var length = collection.length;
7597 if (fromIndex < 0) {
7598 fromIndex = nativeMax(length + fromIndex, 0);
7600 return isString(collection)
7601 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
7602 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
7606 * Invokes the method at `path` of each element in `collection`, returning
7607 * an array of the results of each invoked method. Any additional arguments
7608 * are provided to each invoked method. If `methodName` is a function it's
7609 * invoked for, and `this` bound to, each element in `collection`.
7613 * @category Collection
7614 * @param {Array|Object} collection The collection to iterate over.
7615 * @param {Array|Function|string} path The path of the method to invoke or
7616 * the function invoked per iteration.
7617 * @param {...*} [args] The arguments to invoke each method with.
7618 * @returns {Array} Returns the array of results.
7621 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
7622 * // => [[1, 5, 7], [1, 2, 3]]
7624 * _.invokeMap([123, 456], String.prototype.split, '');
7625 * // => [['1', '2', '3'], ['4', '5', '6']]
7627 var invokeMap = rest(function(collection, path, args) {
7629 isFunc = typeof path == 'function',
7630 isProp = isKey(path),
7631 result = isArrayLike(collection) ? Array(collection.length) : [];
7633 baseEach(collection, function(value) {
7634 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
7635 result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
7641 * Creates an object composed of keys generated from the results of running
7642 * each element of `collection` through `iteratee`. The corresponding value
7643 * of each key is the last element responsible for generating the key. The
7644 * iteratee is invoked with one argument: (value).
7648 * @category Collection
7649 * @param {Array|Object} collection The collection to iterate over.
7650 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7651 * @returns {Object} Returns the composed aggregate object.
7655 * { 'dir': 'left', 'code': 97 },
7656 * { 'dir': 'right', 'code': 100 }
7659 * _.keyBy(keyData, function(o) {
7660 * return String.fromCharCode(o.code);
7662 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
7664 * _.keyBy(keyData, 'dir');
7665 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
7667 var keyBy = createAggregator(function(result, value, key) {
7668 result[key] = value;
7672 * Creates an array of values by running each element in `collection` through
7673 * `iteratee`. The iteratee is invoked with three arguments:
7674 * (value, index|key, collection).
7676 * Many lodash methods are guarded to work as iteratees for methods like
7677 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
7679 * The guarded methods are:
7680 * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
7681 * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
7682 * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
7687 * @category Collection
7688 * @param {Array|Object} collection The collection to iterate over.
7689 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
7690 * @returns {Array} Returns the new mapped array.
7693 * function square(n) {
7697 * _.map([4, 8], square);
7700 * _.map({ 'a': 4, 'b': 8 }, square);
7701 * // => [16, 64] (iteration order is not guaranteed)
7704 * { 'user': 'barney' },
7705 * { 'user': 'fred' }
7708 * // using the `_.property` iteratee shorthand
7709 * _.map(users, 'user');
7710 * // => ['barney', 'fred']
7712 function map(collection, iteratee) {
7713 var func = isArray(collection) ? arrayMap : baseMap;
7714 return func(collection, getIteratee(iteratee, 3));
7718 * This method is like `_.sortBy` except that it allows specifying the sort
7719 * orders of the iteratees to sort by. If `orders` is unspecified, all values
7720 * are sorted in ascending order. Otherwise, specify an order of "desc" for
7721 * descending or "asc" for ascending sort order of corresponding values.
7725 * @category Collection
7726 * @param {Array|Object} collection The collection to iterate over.
7727 * @param {Function[]|Object[]|string[]} [iteratees=[_.identity]] The iteratees to sort by.
7728 * @param {string[]} [orders] The sort orders of `iteratees`.
7729 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`.
7730 * @returns {Array} Returns the new sorted array.
7734 * { 'user': 'fred', 'age': 48 },
7735 * { 'user': 'barney', 'age': 34 },
7736 * { 'user': 'fred', 'age': 42 },
7737 * { 'user': 'barney', 'age': 36 }
7740 * // sort by `user` in ascending order and by `age` in descending order
7741 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
7742 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
7744 function orderBy(collection, iteratees, orders, guard) {
7745 if (collection == null) {
7748 if (!isArray(iteratees)) {
7749 iteratees = iteratees == null ? [] : [iteratees];
7751 orders = guard ? undefined : orders;
7752 if (!isArray(orders)) {
7753 orders = orders == null ? [] : [orders];
7755 return baseOrderBy(collection, iteratees, orders);
7759 * Creates an array of elements split into two groups, the first of which
7760 * contains elements `predicate` returns truthy for, the second of which
7761 * contains elements `predicate` returns falsey for. The predicate is
7762 * invoked with one argument: (value).
7766 * @category Collection
7767 * @param {Array|Object} collection The collection to iterate over.
7768 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7769 * @returns {Array} Returns the array of grouped elements.
7773 * { 'user': 'barney', 'age': 36, 'active': false },
7774 * { 'user': 'fred', 'age': 40, 'active': true },
7775 * { 'user': 'pebbles', 'age': 1, 'active': false }
7778 * _.partition(users, function(o) { return o.active; });
7779 * // => objects for [['fred'], ['barney', 'pebbles']]
7781 * // using the `_.matches` iteratee shorthand
7782 * _.partition(users, { 'age': 1, 'active': false });
7783 * // => objects for [['pebbles'], ['barney', 'fred']]
7785 * // using the `_.matchesProperty` iteratee shorthand
7786 * _.partition(users, ['active', false]);
7787 * // => objects for [['barney', 'pebbles'], ['fred']]
7789 * // using the `_.property` iteratee shorthand
7790 * _.partition(users, 'active');
7791 * // => objects for [['fred'], ['barney', 'pebbles']]
7793 var partition = createAggregator(function(result, value, key) {
7794 result[key ? 0 : 1].push(value);
7795 }, function() { return [[], []]; });
7798 * Reduces `collection` to a value which is the accumulated result of running
7799 * each element in `collection` through `iteratee`, where each successive
7800 * invocation is supplied the return value of the previous. If `accumulator`
7801 * is not provided the first element of `collection` is used as the initial
7802 * value. The iteratee is invoked with four arguments:
7803 * (accumulator, value, index|key, collection).
7805 * Many lodash methods are guarded to work as iteratees for methods like
7806 * `_.reduce`, `_.reduceRight`, and `_.transform`.
7808 * The guarded methods are:
7809 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
7814 * @category Collection
7815 * @param {Array|Object} collection The collection to iterate over.
7816 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7817 * @param {*} [accumulator] The initial value.
7818 * @returns {*} Returns the accumulated value.
7821 * _.reduce([1, 2], function(sum, n) {
7826 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
7827 * (result[value] || (result[value] = [])).push(key);
7830 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
7832 function reduce(collection, iteratee, accumulator) {
7833 var func = isArray(collection) ? arrayReduce : baseReduce,
7834 initAccum = arguments.length < 3;
7836 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
7840 * This method is like `_.reduce` except that it iterates over elements of
7841 * `collection` from right to left.
7845 * @category Collection
7846 * @param {Array|Object} collection The collection to iterate over.
7847 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7848 * @param {*} [accumulator] The initial value.
7849 * @returns {*} Returns the accumulated value.
7852 * var array = [[0, 1], [2, 3], [4, 5]];
7854 * _.reduceRight(array, function(flattened, other) {
7855 * return flattened.concat(other);
7857 * // => [4, 5, 2, 3, 0, 1]
7859 function reduceRight(collection, iteratee, accumulator) {
7860 var func = isArray(collection) ? arrayReduceRight : baseReduce,
7861 initAccum = arguments.length < 3;
7863 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
7867 * The opposite of `_.filter`; this method returns the elements of `collection`
7868 * that `predicate` does **not** return truthy for.
7872 * @category Collection
7873 * @param {Array|Object} collection The collection to iterate over.
7874 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7875 * @returns {Array} Returns the new filtered array.
7879 * { 'user': 'barney', 'age': 36, 'active': false },
7880 * { 'user': 'fred', 'age': 40, 'active': true }
7883 * _.reject(users, function(o) { return !o.active; });
7884 * // => objects for ['fred']
7886 * // using the `_.matches` iteratee shorthand
7887 * _.reject(users, { 'age': 40, 'active': true });
7888 * // => objects for ['barney']
7890 * // using the `_.matchesProperty` iteratee shorthand
7891 * _.reject(users, ['active', false]);
7892 * // => objects for ['fred']
7894 * // using the `_.property` iteratee shorthand
7895 * _.reject(users, 'active');
7896 * // => objects for ['barney']
7898 function reject(collection, predicate) {
7899 var func = isArray(collection) ? arrayFilter : baseFilter;
7900 predicate = getIteratee(predicate, 3);
7901 return func(collection, function(value, index, collection) {
7902 return !predicate(value, index, collection);
7907 * Gets a random element from `collection`.
7911 * @category Collection
7912 * @param {Array|Object} collection The collection to sample.
7913 * @returns {*} Returns the random element.
7916 * _.sample([1, 2, 3, 4]);
7919 function sample(collection) {
7920 var array = isArrayLike(collection) ? collection : values(collection),
7921 length = array.length;
7923 return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
7927 * Gets `n` random elements at unique keys from `collection` up to the
7928 * size of `collection`.
7932 * @category Collection
7933 * @param {Array|Object} collection The collection to sample.
7934 * @param {number} [n=0] The number of elements to sample.
7935 * @returns {Array} Returns the random elements.
7938 * _.sampleSize([1, 2, 3], 2);
7941 * _.sampleSize([1, 2, 3], 4);
7944 function sampleSize(collection, n) {
7946 result = toArray(collection),
7947 length = result.length,
7948 lastIndex = length - 1;
7950 n = baseClamp(toInteger(n), 0, length);
7951 while (++index < n) {
7952 var rand = baseRandom(index, lastIndex),
7953 value = result[rand];
7955 result[rand] = result[index];
7956 result[index] = value;
7963 * Creates an array of shuffled values, using a version of the
7964 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
7968 * @category Collection
7969 * @param {Array|Object} collection The collection to shuffle.
7970 * @returns {Array} Returns the new shuffled array.
7973 * _.shuffle([1, 2, 3, 4]);
7974 * // => [4, 1, 3, 2]
7976 function shuffle(collection) {
7977 return sampleSize(collection, MAX_ARRAY_LENGTH);
7981 * Gets the size of `collection` by returning its length for array-like
7982 * values or the number of own enumerable properties for objects.
7986 * @category Collection
7987 * @param {Array|Object} collection The collection to inspect.
7988 * @returns {number} Returns the collection size.
7991 * _.size([1, 2, 3]);
7994 * _.size({ 'a': 1, 'b': 2 });
7997 * _.size('pebbles');
8000 function size(collection) {
8001 if (collection == null) {
8004 if (isArrayLike(collection)) {
8005 var result = collection.length;
8006 return (result && isString(collection)) ? stringSize(collection) : result;
8008 return keys(collection).length;
8012 * Checks if `predicate` returns truthy for **any** element of `collection`.
8013 * Iteration is stopped once `predicate` returns truthy. The predicate is
8014 * invoked with three arguments: (value, index|key, collection).
8018 * @category Collection
8019 * @param {Array|Object} collection The collection to iterate over.
8020 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
8021 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8022 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
8025 * _.some([null, 0, 'yes', false], Boolean);
8029 * { 'user': 'barney', 'active': true },
8030 * { 'user': 'fred', 'active': false }
8033 * // using the `_.matches` iteratee shorthand
8034 * _.some(users, { 'user': 'barney', 'active': false });
8037 * // using the `_.matchesProperty` iteratee shorthand
8038 * _.some(users, ['active', false]);
8041 * // using the `_.property` iteratee shorthand
8042 * _.some(users, 'active');
8045 function some(collection, predicate, guard) {
8046 var func = isArray(collection) ? arraySome : baseSome;
8047 if (guard && isIterateeCall(collection, predicate, guard)) {
8048 predicate = undefined;
8050 return func(collection, getIteratee(predicate, 3));
8054 * Creates an array of elements, sorted in ascending order by the results of
8055 * running each element in a collection through each iteratee. This method
8056 * performs a stable sort, that is, it preserves the original sort order of
8057 * equal elements. The iteratees are invoked with one argument: (value).
8061 * @category Collection
8062 * @param {Array|Object} collection The collection to iterate over.
8063 * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
8064 * The iteratees to sort by, specified individually or in arrays.
8065 * @returns {Array} Returns the new sorted array.
8069 * { 'user': 'fred', 'age': 48 },
8070 * { 'user': 'barney', 'age': 36 },
8071 * { 'user': 'fred', 'age': 42 },
8072 * { 'user': 'barney', 'age': 34 }
8075 * _.sortBy(users, function(o) { return o.user; });
8076 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
8078 * _.sortBy(users, ['user', 'age']);
8079 * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
8081 * _.sortBy(users, 'user', function(o) {
8082 * return Math.floor(o.age / 10);
8084 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
8086 var sortBy = rest(function(collection, iteratees) {
8087 if (collection == null) {
8090 var length = iteratees.length;
8091 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
8093 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
8094 iteratees.length = 1;
8096 return baseOrderBy(collection, baseFlatten(iteratees), []);
8099 /*------------------------------------------------------------------------*/
8102 * Gets the timestamp of the number of milliseconds that have elapsed since
8103 * the Unix epoch (1 January 1970 00:00:00 UTC).
8109 * @returns {number} Returns the timestamp.
8112 * _.defer(function(stamp) {
8113 * console.log(_.now() - stamp);
8115 * // => logs the number of milliseconds it took for the deferred function to be invoked
8119 /*------------------------------------------------------------------------*/
8122 * The opposite of `_.before`; this method creates a function that invokes
8123 * `func` once it's called `n` or more times.
8127 * @category Function
8128 * @param {number} n The number of calls before `func` is invoked.
8129 * @param {Function} func The function to restrict.
8130 * @returns {Function} Returns the new restricted function.
8133 * var saves = ['profile', 'settings'];
8135 * var done = _.after(saves.length, function() {
8136 * console.log('done saving!');
8139 * _.forEach(saves, function(type) {
8140 * asyncSave({ 'type': type, 'complete': done });
8142 * // => logs 'done saving!' after the two async saves have completed
8144 function after(n, func) {
8145 if (typeof func != 'function') {
8146 throw new TypeError(FUNC_ERROR_TEXT);
8151 return func.apply(this, arguments);
8157 * Creates a function that accepts up to `n` arguments, ignoring any
8158 * additional arguments.
8162 * @category Function
8163 * @param {Function} func The function to cap arguments for.
8164 * @param {number} [n=func.length] The arity cap.
8165 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8166 * @returns {Function} Returns the new function.
8169 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
8172 function ary(func, n, guard) {
8173 n = guard ? undefined : n;
8174 n = (func && n == null) ? func.length : n;
8175 return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
8179 * Creates a function that invokes `func`, with the `this` binding and arguments
8180 * of the created function, while it's called less than `n` times. Subsequent
8181 * calls to the created function return the result of the last `func` invocation.
8185 * @category Function
8186 * @param {number} n The number of calls at which `func` is no longer invoked.
8187 * @param {Function} func The function to restrict.
8188 * @returns {Function} Returns the new restricted function.
8191 * jQuery(element).on('click', _.before(5, addContactToList));
8192 * // => allows adding up to 4 contacts to the list
8194 function before(n, func) {
8196 if (typeof func != 'function') {
8197 throw new TypeError(FUNC_ERROR_TEXT);
8202 result = func.apply(this, arguments);
8212 * Creates a function that invokes `func` with the `this` binding of `thisArg`
8213 * and prepends any additional `_.bind` arguments to those provided to the
8216 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
8217 * may be used as a placeholder for partially applied arguments.
8219 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
8220 * property of bound functions.
8224 * @category Function
8225 * @param {Function} func The function to bind.
8226 * @param {*} thisArg The `this` binding of `func`.
8227 * @param {...*} [partials] The arguments to be partially applied.
8228 * @returns {Function} Returns the new bound function.
8231 * var greet = function(greeting, punctuation) {
8232 * return greeting + ' ' + this.user + punctuation;
8235 * var object = { 'user': 'fred' };
8237 * var bound = _.bind(greet, object, 'hi');
8241 * // using placeholders
8242 * var bound = _.bind(greet, object, _, '!');
8246 var bind = rest(function(func, thisArg, partials) {
8247 var bitmask = BIND_FLAG;
8248 if (partials.length) {
8249 var holders = replaceHolders(partials, bind.placeholder);
8250 bitmask |= PARTIAL_FLAG;
8252 return createWrapper(func, bitmask, thisArg, partials, holders);
8256 * Creates a function that invokes the method at `object[key]` and prepends
8257 * any additional `_.bindKey` arguments to those provided to the bound function.
8259 * This method differs from `_.bind` by allowing bound functions to reference
8260 * methods that may be redefined or don't yet exist.
8261 * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
8264 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
8265 * builds, may be used as a placeholder for partially applied arguments.
8269 * @category Function
8270 * @param {Object} object The object to invoke the method on.
8271 * @param {string} key The key of the method.
8272 * @param {...*} [partials] The arguments to be partially applied.
8273 * @returns {Function} Returns the new bound function.
8278 * 'greet': function(greeting, punctuation) {
8279 * return greeting + ' ' + this.user + punctuation;
8283 * var bound = _.bindKey(object, 'greet', 'hi');
8287 * object.greet = function(greeting, punctuation) {
8288 * return greeting + 'ya ' + this.user + punctuation;
8292 * // => 'hiya fred!'
8294 * // using placeholders
8295 * var bound = _.bindKey(object, 'greet', _, '!');
8297 * // => 'hiya fred!'
8299 var bindKey = rest(function(object, key, partials) {
8300 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
8301 if (partials.length) {
8302 var holders = replaceHolders(partials, bindKey.placeholder);
8303 bitmask |= PARTIAL_FLAG;
8305 return createWrapper(key, bitmask, object, partials, holders);
8309 * Creates a function that accepts arguments of `func` and either invokes
8310 * `func` returning its result, if at least `arity` number of arguments have
8311 * been provided, or returns a function that accepts the remaining `func`
8312 * arguments, and so on. The arity of `func` may be specified if `func.length`
8313 * is not sufficient.
8315 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
8316 * may be used as a placeholder for provided arguments.
8318 * **Note:** This method doesn't set the "length" property of curried functions.
8322 * @category Function
8323 * @param {Function} func The function to curry.
8324 * @param {number} [arity=func.length] The arity of `func`.
8325 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8326 * @returns {Function} Returns the new curried function.
8329 * var abc = function(a, b, c) {
8333 * var curried = _.curry(abc);
8344 * // using placeholders
8345 * curried(1)(_, 3)(2);
8348 function curry(func, arity, guard) {
8349 arity = guard ? undefined : arity;
8350 var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
8351 result.placeholder = curry.placeholder;
8356 * This method is like `_.curry` except that arguments are applied to `func`
8357 * in the manner of `_.partialRight` instead of `_.partial`.
8359 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
8360 * builds, may be used as a placeholder for provided arguments.
8362 * **Note:** This method doesn't set the "length" property of curried functions.
8366 * @category Function
8367 * @param {Function} func The function to curry.
8368 * @param {number} [arity=func.length] The arity of `func`.
8369 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8370 * @returns {Function} Returns the new curried function.
8373 * var abc = function(a, b, c) {
8377 * var curried = _.curryRight(abc);
8388 * // using placeholders
8389 * curried(3)(1, _)(2);
8392 function curryRight(func, arity, guard) {
8393 arity = guard ? undefined : arity;
8394 var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
8395 result.placeholder = curryRight.placeholder;
8400 * Creates a debounced function that delays invoking `func` until after `wait`
8401 * milliseconds have elapsed since the last time the debounced function was
8402 * invoked. The debounced function comes with a `cancel` method to cancel
8403 * delayed `func` invocations and a `flush` method to immediately invoke them.
8404 * Provide an options object to indicate whether `func` should be invoked on
8405 * the leading and/or trailing edge of the `wait` timeout. The `func` is invoked
8406 * with the last arguments provided to the debounced function. Subsequent calls
8407 * to the debounced function return the result of the last `func` invocation.
8409 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
8410 * on the trailing edge of the timeout only if the the debounced function is
8411 * invoked more than once during the `wait` timeout.
8413 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
8414 * for details over the differences between `_.debounce` and `_.throttle`.
8418 * @category Function
8419 * @param {Function} func The function to debounce.
8420 * @param {number} [wait=0] The number of milliseconds to delay.
8421 * @param {Object} [options] The options object.
8422 * @param {boolean} [options.leading=false] Specify invoking on the leading
8423 * edge of the timeout.
8424 * @param {number} [options.maxWait] The maximum time `func` is allowed to be
8425 * delayed before it's invoked.
8426 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
8427 * edge of the timeout.
8428 * @returns {Function} Returns the new debounced function.
8431 * // avoid costly calculations while the window size is in flux
8432 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
8434 * // invoke `sendMail` when clicked, debouncing subsequent calls
8435 * jQuery(element).on('click', _.debounce(sendMail, 300, {
8440 * // ensure `batchLog` is invoked once after 1 second of debounced calls
8441 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
8442 * var source = new EventSource('/stream');
8443 * jQuery(source).on('message', debounced);
8445 * // cancel a trailing debounced invocation
8446 * jQuery(window).on('popstate', debounced.cancel);
8448 function debounce(func, wait, options) {
8461 if (typeof func != 'function') {
8462 throw new TypeError(FUNC_ERROR_TEXT);
8464 wait = toNumber(wait) || 0;
8465 if (isObject(options)) {
8466 leading = !!options.leading;
8467 maxWait = 'maxWait' in options && nativeMax(toNumber(options.maxWait) || 0, wait);
8468 trailing = 'trailing' in options ? !!options.trailing : trailing;
8473 clearTimeout(timeoutId);
8476 clearTimeout(maxTimeoutId);
8479 args = maxTimeoutId = thisArg = timeoutId = trailingCall = undefined;
8482 function complete(isCalled, id) {
8486 maxTimeoutId = timeoutId = trailingCall = undefined;
8489 result = func.apply(thisArg, args);
8490 if (!timeoutId && !maxTimeoutId) {
8491 args = thisArg = undefined;
8496 function delayed() {
8497 var remaining = wait - (now() - stamp);
8498 if (remaining <= 0 || remaining > wait) {
8499 complete(trailingCall, maxTimeoutId);
8501 timeoutId = setTimeout(delayed, remaining);
8506 if ((timeoutId && trailingCall) || (maxTimeoutId && trailing)) {
8507 result = func.apply(thisArg, args);
8513 function maxDelayed() {
8514 complete(trailing, timeoutId);
8517 function debounced() {
8521 trailingCall = trailing && (timeoutId || !leading);
8523 if (maxWait === false) {
8524 var leadingCall = leading && !timeoutId;
8526 if (!maxTimeoutId && !leading) {
8529 var remaining = maxWait - (stamp - lastCalled),
8530 isCalled = remaining <= 0 || remaining > maxWait;
8534 maxTimeoutId = clearTimeout(maxTimeoutId);
8537 result = func.apply(thisArg, args);
8539 else if (!maxTimeoutId) {
8540 maxTimeoutId = setTimeout(maxDelayed, remaining);
8543 if (isCalled && timeoutId) {
8544 timeoutId = clearTimeout(timeoutId);
8546 else if (!timeoutId && wait !== maxWait) {
8547 timeoutId = setTimeout(delayed, wait);
8551 result = func.apply(thisArg, args);
8553 if (isCalled && !timeoutId && !maxTimeoutId) {
8554 args = thisArg = undefined;
8558 debounced.cancel = cancel;
8559 debounced.flush = flush;
8564 * Defers invoking the `func` until the current call stack has cleared. Any
8565 * additional arguments are provided to `func` when it's invoked.
8569 * @category Function
8570 * @param {Function} func The function to defer.
8571 * @param {...*} [args] The arguments to invoke `func` with.
8572 * @returns {number} Returns the timer id.
8575 * _.defer(function(text) {
8576 * console.log(text);
8578 * // logs 'deferred' after one or more milliseconds
8580 var defer = rest(function(func, args) {
8581 return baseDelay(func, 1, args);
8585 * Invokes `func` after `wait` milliseconds. Any additional arguments are
8586 * provided to `func` when it's invoked.
8590 * @category Function
8591 * @param {Function} func The function to delay.
8592 * @param {number} wait The number of milliseconds to delay invocation.
8593 * @param {...*} [args] The arguments to invoke `func` with.
8594 * @returns {number} Returns the timer id.
8597 * _.delay(function(text) {
8598 * console.log(text);
8599 * }, 1000, 'later');
8600 * // => logs 'later' after one second
8602 var delay = rest(function(func, wait, args) {
8603 return baseDelay(func, toNumber(wait) || 0, args);
8607 * Creates a function that invokes `func` with arguments reversed.
8611 * @category Function
8612 * @param {Function} func The function to flip arguments for.
8613 * @returns {Function} Returns the new function.
8616 * var flipped = _.flip(function() {
8617 * return _.toArray(arguments);
8620 * flipped('a', 'b', 'c', 'd');
8621 * // => ['d', 'c', 'b', 'a']
8623 function flip(func) {
8624 return createWrapper(func, FLIP_FLAG);
8628 * Creates a function that memoizes the result of `func`. If `resolver` is
8629 * provided it determines the cache key for storing the result based on the
8630 * arguments provided to the memoized function. By default, the first argument
8631 * provided to the memoized function is used as the map cache key. The `func`
8632 * is invoked with the `this` binding of the memoized function.
8634 * **Note:** The cache is exposed as the `cache` property on the memoized
8635 * function. Its creation may be customized by replacing the `_.memoize.Cache`
8636 * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
8637 * method interface of `delete`, `get`, `has`, and `set`.
8641 * @category Function
8642 * @param {Function} func The function to have its output memoized.
8643 * @param {Function} [resolver] The function to resolve the cache key.
8644 * @returns {Function} Returns the new memoizing function.
8647 * var object = { 'a': 1, 'b': 2 };
8648 * var other = { 'c': 3, 'd': 4 };
8650 * var values = _.memoize(_.values);
8661 * // modifying the result cache
8662 * values.cache.set(object, ['a', 'b']);
8666 * // replacing `_.memoize.Cache`
8667 * _.memoize.Cache = WeakMap;
8669 function memoize(func, resolver) {
8670 if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
8671 throw new TypeError(FUNC_ERROR_TEXT);
8673 var memoized = function() {
8674 var args = arguments,
8675 key = resolver ? resolver.apply(this, args) : args[0],
8676 cache = memoized.cache;
8678 if (cache.has(key)) {
8679 return cache.get(key);
8681 var result = func.apply(this, args);
8682 memoized.cache = cache.set(key, result);
8685 memoized.cache = new memoize.Cache;
8690 * Creates a function that negates the result of the predicate `func`. The
8691 * `func` predicate is invoked with the `this` binding and arguments of the
8696 * @category Function
8697 * @param {Function} predicate The predicate to negate.
8698 * @returns {Function} Returns the new function.
8701 * function isEven(n) {
8702 * return n % 2 == 0;
8705 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
8708 function negate(predicate) {
8709 if (typeof predicate != 'function') {
8710 throw new TypeError(FUNC_ERROR_TEXT);
8713 return !predicate.apply(this, arguments);
8718 * Creates a function that is restricted to invoking `func` once. Repeat calls
8719 * to the function return the value of the first invocation. The `func` is
8720 * invoked with the `this` binding and arguments of the created function.
8724 * @category Function
8725 * @param {Function} func The function to restrict.
8726 * @returns {Function} Returns the new restricted function.
8729 * var initialize = _.once(createApplication);
8732 * // `initialize` invokes `createApplication` once
8734 function once(func) {
8735 return before(2, func);
8739 * Creates a function that invokes `func` with arguments transformed by
8740 * corresponding `transforms`.
8744 * @category Function
8745 * @param {Function} func The function to wrap.
8746 * @param {...(Function|Function[])} [transforms] The functions to transform
8747 * arguments, specified individually or in arrays.
8748 * @returns {Function} Returns the new function.
8751 * function doubled(n) {
8755 * function square(n) {
8759 * var func = _.overArgs(function(x, y) {
8761 * }, square, doubled);
8769 var overArgs = rest(function(func, transforms) {
8770 transforms = arrayMap(baseFlatten(transforms), getIteratee());
8772 var funcsLength = transforms.length;
8773 return rest(function(args) {
8775 length = nativeMin(args.length, funcsLength);
8777 while (++index < length) {
8778 args[index] = transforms[index].call(this, args[index]);
8780 return apply(func, this, args);
8785 * Creates a function that invokes `func` with `partial` arguments prepended
8786 * to those provided to the new function. This method is like `_.bind` except
8787 * it does **not** alter the `this` binding.
8789 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
8790 * builds, may be used as a placeholder for partially applied arguments.
8792 * **Note:** This method doesn't set the "length" property of partially
8793 * applied functions.
8797 * @category Function
8798 * @param {Function} func The function to partially apply arguments to.
8799 * @param {...*} [partials] The arguments to be partially applied.
8800 * @returns {Function} Returns the new partially applied function.
8803 * var greet = function(greeting, name) {
8804 * return greeting + ' ' + name;
8807 * var sayHelloTo = _.partial(greet, 'hello');
8808 * sayHelloTo('fred');
8809 * // => 'hello fred'
8811 * // using placeholders
8812 * var greetFred = _.partial(greet, _, 'fred');
8816 var partial = rest(function(func, partials) {
8817 var holders = replaceHolders(partials, partial.placeholder);
8818 return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
8822 * This method is like `_.partial` except that partially applied arguments
8823 * are appended to those provided to the new function.
8825 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
8826 * builds, may be used as a placeholder for partially applied arguments.
8828 * **Note:** This method doesn't set the "length" property of partially
8829 * applied functions.
8833 * @category Function
8834 * @param {Function} func The function to partially apply arguments to.
8835 * @param {...*} [partials] The arguments to be partially applied.
8836 * @returns {Function} Returns the new partially applied function.
8839 * var greet = function(greeting, name) {
8840 * return greeting + ' ' + name;
8843 * var greetFred = _.partialRight(greet, 'fred');
8847 * // using placeholders
8848 * var sayHelloTo = _.partialRight(greet, 'hello', _);
8849 * sayHelloTo('fred');
8850 * // => 'hello fred'
8852 var partialRight = rest(function(func, partials) {
8853 var holders = replaceHolders(partials, partialRight.placeholder);
8854 return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
8858 * Creates a function that invokes `func` with arguments arranged according
8859 * to the specified indexes where the argument value at the first index is
8860 * provided as the first argument, the argument value at the second index is
8861 * provided as the second argument, and so on.
8865 * @category Function
8866 * @param {Function} func The function to rearrange arguments for.
8867 * @param {...(number|number[])} indexes The arranged argument indexes,
8868 * specified individually or in arrays.
8869 * @returns {Function} Returns the new function.
8872 * var rearged = _.rearg(function(a, b, c) {
8876 * rearged('b', 'c', 'a')
8877 * // => ['a', 'b', 'c']
8879 var rearg = rest(function(func, indexes) {
8880 return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
8884 * Creates a function that invokes `func` with the `this` binding of the
8885 * created function and arguments from `start` and beyond provided as an array.
8887 * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
8891 * @category Function
8892 * @param {Function} func The function to apply a rest parameter to.
8893 * @param {number} [start=func.length-1] The start position of the rest parameter.
8894 * @returns {Function} Returns the new function.
8897 * var say = _.rest(function(what, names) {
8898 * return what + ' ' + _.initial(names).join(', ') +
8899 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
8902 * say('hello', 'fred', 'barney', 'pebbles');
8903 * // => 'hello fred, barney, & pebbles'
8905 function rest(func, start) {
8906 if (typeof func != 'function') {
8907 throw new TypeError(FUNC_ERROR_TEXT);
8909 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
8911 var args = arguments,
8913 length = nativeMax(args.length - start, 0),
8914 array = Array(length);
8916 while (++index < length) {
8917 array[index] = args[start + index];
8920 case 0: return func.call(this, array);
8921 case 1: return func.call(this, args[0], array);
8922 case 2: return func.call(this, args[0], args[1], array);
8924 var otherArgs = Array(start + 1);
8926 while (++index < start) {
8927 otherArgs[index] = args[index];
8929 otherArgs[start] = array;
8930 return apply(func, this, otherArgs);
8935 * Creates a function that invokes `func` with the `this` binding of the created
8936 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
8938 * **Note:** This method is based on the [spread operator](https://mdn.io/spread_operator).
8942 * @category Function
8943 * @param {Function} func The function to spread arguments over.
8944 * @returns {Function} Returns the new function.
8947 * var say = _.spread(function(who, what) {
8948 * return who + ' says ' + what;
8951 * say(['fred', 'hello']);
8952 * // => 'fred says hello'
8955 * var numbers = Promise.all([
8956 * Promise.resolve(40),
8957 * Promise.resolve(36)
8960 * numbers.then(_.spread(function(x, y) {
8963 * // => a Promise of 76
8965 function spread(func) {
8966 if (typeof func != 'function') {
8967 throw new TypeError(FUNC_ERROR_TEXT);
8969 return function(array) {
8970 return apply(func, this, array);
8975 * Creates a throttled function that only invokes `func` at most once per
8976 * every `wait` milliseconds. The throttled function comes with a `cancel`
8977 * method to cancel delayed `func` invocations and a `flush` method to
8978 * immediately invoke them. Provide an options object to indicate whether
8979 * `func` should be invoked on the leading and/or trailing edge of the `wait`
8980 * timeout. The `func` is invoked with the last arguments provided to the
8981 * throttled function. Subsequent calls to the throttled function return the
8982 * result of the last `func` invocation.
8984 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
8985 * on the trailing edge of the timeout only if the the throttled function is
8986 * invoked more than once during the `wait` timeout.
8988 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
8989 * for details over the differences between `_.throttle` and `_.debounce`.
8993 * @category Function
8994 * @param {Function} func The function to throttle.
8995 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
8996 * @param {Object} [options] The options object.
8997 * @param {boolean} [options.leading=true] Specify invoking on the leading
8998 * edge of the timeout.
8999 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
9000 * edge of the timeout.
9001 * @returns {Function} Returns the new throttled function.
9004 * // avoid excessively updating the position while scrolling
9005 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
9007 * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
9008 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
9009 * jQuery(element).on('click', throttled);
9011 * // cancel a trailing throttled invocation
9012 * jQuery(window).on('popstate', throttled.cancel);
9014 function throttle(func, wait, options) {
9018 if (typeof func != 'function') {
9019 throw new TypeError(FUNC_ERROR_TEXT);
9021 if (isObject(options)) {
9022 leading = 'leading' in options ? !!options.leading : leading;
9023 trailing = 'trailing' in options ? !!options.trailing : trailing;
9025 return debounce(func, wait, { 'leading': leading, 'maxWait': wait, 'trailing': trailing });
9029 * Creates a function that accepts up to one argument, ignoring any
9030 * additional arguments.
9034 * @category Function
9035 * @param {Function} func The function to cap arguments for.
9036 * @returns {Function} Returns the new function.
9039 * _.map(['6', '8', '10'], _.unary(parseInt));
9042 function unary(func) {
9043 return ary(func, 1);
9047 * Creates a function that provides `value` to the wrapper function as its
9048 * first argument. Any additional arguments provided to the function are
9049 * appended to those provided to the wrapper function. The wrapper is invoked
9050 * with the `this` binding of the created function.
9054 * @category Function
9055 * @param {*} value The value to wrap.
9056 * @param {Function} wrapper The wrapper function.
9057 * @returns {Function} Returns the new function.
9060 * var p = _.wrap(_.escape, function(func, text) {
9061 * return '<p>' + func(text) + '</p>';
9064 * p('fred, barney, & pebbles');
9065 * // => '<p>fred, barney, & pebbles</p>'
9067 function wrap(value, wrapper) {
9068 wrapper = wrapper == null ? identity : wrapper;
9069 return partial(wrapper, value);
9072 /*------------------------------------------------------------------------*/
9075 * Creates a shallow clone of `value`.
9077 * **Note:** This method is loosely based on the
9078 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
9079 * and supports cloning arrays, array buffers, booleans, date objects, maps,
9080 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
9081 * arrays. The own enumerable properties of `arguments` objects are cloned
9082 * as plain objects. An empty object is returned for uncloneable values such
9083 * as error objects, functions, DOM nodes, and WeakMaps.
9088 * @param {*} value The value to clone.
9089 * @returns {*} Returns the cloned value.
9092 * var objects = [{ 'a': 1 }, { 'b': 2 }];
9094 * var shallow = _.clone(objects);
9095 * console.log(shallow[0] === objects[0]);
9098 function clone(value) {
9099 return baseClone(value);
9103 * This method is like `_.clone` except that it accepts `customizer` which
9104 * is invoked to produce the cloned value. If `customizer` returns `undefined`
9105 * cloning is handled by the method instead. The `customizer` is invoked with
9106 * up to four arguments; (value [, index|key, object, stack]).
9111 * @param {*} value The value to clone.
9112 * @param {Function} [customizer] The function to customize cloning.
9113 * @returns {*} Returns the cloned value.
9116 * function customizer(value) {
9117 * if (_.isElement(value)) {
9118 * return value.cloneNode(false);
9122 * var el = _.cloneWith(document.body, customizer);
9124 * console.log(el === document.body);
9126 * console.log(el.nodeName);
9128 * console.log(el.childNodes.length);
9131 function cloneWith(value, customizer) {
9132 return baseClone(value, false, customizer);
9136 * This method is like `_.clone` except that it recursively clones `value`.
9141 * @param {*} value The value to recursively clone.
9142 * @returns {*} Returns the deep cloned value.
9145 * var objects = [{ 'a': 1 }, { 'b': 2 }];
9147 * var deep = _.cloneDeep(objects);
9148 * console.log(deep[0] === objects[0]);
9151 function cloneDeep(value) {
9152 return baseClone(value, true);
9156 * This method is like `_.cloneWith` except that it recursively clones `value`.
9161 * @param {*} value The value to recursively clone.
9162 * @param {Function} [customizer] The function to customize cloning.
9163 * @returns {*} Returns the deep cloned value.
9166 * function customizer(value) {
9167 * if (_.isElement(value)) {
9168 * return value.cloneNode(true);
9172 * var el = _.cloneDeepWith(document.body, customizer);
9174 * console.log(el === document.body);
9176 * console.log(el.nodeName);
9178 * console.log(el.childNodes.length);
9181 function cloneDeepWith(value, customizer) {
9182 return baseClone(value, true, customizer);
9186 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
9187 * comparison between two values to determine if they are equivalent.
9192 * @param {*} value The value to compare.
9193 * @param {*} other The other value to compare.
9194 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9197 * var object = { 'user': 'fred' };
9198 * var other = { 'user': 'fred' };
9200 * _.eq(object, object);
9203 * _.eq(object, other);
9209 * _.eq('a', Object('a'));
9215 function eq(value, other) {
9216 return value === other || (value !== value && other !== other);
9220 * Checks if `value` is greater than `other`.
9225 * @param {*} value The value to compare.
9226 * @param {*} other The other value to compare.
9227 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
9239 function gt(value, other) {
9240 return value > other;
9244 * Checks if `value` is greater than or equal to `other`.
9249 * @param {*} value The value to compare.
9250 * @param {*} other The other value to compare.
9251 * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
9263 function gte(value, other) {
9264 return value >= other;
9268 * Checks if `value` is likely an `arguments` object.
9273 * @param {*} value The value to check.
9274 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9277 * _.isArguments(function() { return arguments; }());
9280 * _.isArguments([1, 2, 3]);
9283 function isArguments(value) {
9284 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
9285 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
9286 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
9290 * Checks if `value` is classified as an `Array` object.
9296 * @param {*} value The value to check.
9297 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9300 * _.isArray([1, 2, 3]);
9303 * _.isArray(document.body.children);
9309 * _.isArray(_.noop);
9312 var isArray = Array.isArray;
9315 * Checks if `value` is array-like. A value is considered array-like if it's
9316 * not a function and has a `value.length` that's an integer greater than or
9317 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
9323 * @param {*} value The value to check.
9324 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
9327 * _.isArrayLike([1, 2, 3]);
9330 * _.isArrayLike(document.body.children);
9333 * _.isArrayLike('abc');
9336 * _.isArrayLike(_.noop);
9339 function isArrayLike(value) {
9340 return value != null &&
9341 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
9345 * This method is like `_.isArrayLike` except that it also checks if `value`
9352 * @param {*} value The value to check.
9353 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
9356 * _.isArrayLikeObject([1, 2, 3]);
9359 * _.isArrayLikeObject(document.body.children);
9362 * _.isArrayLikeObject('abc');
9365 * _.isArrayLikeObject(_.noop);
9368 function isArrayLikeObject(value) {
9369 return isObjectLike(value) && isArrayLike(value);
9373 * Checks if `value` is classified as a boolean primitive or object.
9378 * @param {*} value The value to check.
9379 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9382 * _.isBoolean(false);
9385 * _.isBoolean(null);
9388 function isBoolean(value) {
9389 return value === true || value === false ||
9390 (isObjectLike(value) && objectToString.call(value) == boolTag);
9394 * Checks if `value` is classified as a `Date` object.
9399 * @param {*} value The value to check.
9400 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9403 * _.isDate(new Date);
9406 * _.isDate('Mon April 23 2012');
9409 function isDate(value) {
9410 return isObjectLike(value) && objectToString.call(value) == dateTag;
9414 * Checks if `value` is likely a DOM element.
9419 * @param {*} value The value to check.
9420 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
9423 * _.isElement(document.body);
9426 * _.isElement('<body>');
9429 function isElement(value) {
9430 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
9434 * Checks if `value` is empty. A value is considered empty unless it's an
9435 * `arguments` object, array, string, or jQuery-like collection with a length
9436 * greater than `0` or an object with own enumerable properties.
9441 * @param {Array|Object|string} value The value to inspect.
9442 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
9454 * _.isEmpty([1, 2, 3]);
9457 * _.isEmpty({ 'a': 1 });
9460 function isEmpty(value) {
9461 return (!isObjectLike(value) || isFunction(value.splice))
9463 : !keys(value).length;
9467 * Performs a deep comparison between two values to determine if they are
9470 * **Note:** This method supports comparing arrays, array buffers, booleans,
9471 * date objects, error objects, maps, numbers, `Object` objects, regexes,
9472 * sets, strings, symbols, and typed arrays. `Object` objects are compared
9473 * by their own, not inherited, enumerable properties. Functions and DOM
9474 * nodes are **not** supported.
9479 * @param {*} value The value to compare.
9480 * @param {*} other The other value to compare.
9481 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9484 * var object = { 'user': 'fred' };
9485 * var other = { 'user': 'fred' };
9487 * _.isEqual(object, other);
9493 function isEqual(value, other) {
9494 return baseIsEqual(value, other);
9498 * This method is like `_.isEqual` except that it accepts `customizer` which is
9499 * invoked to compare values. If `customizer` returns `undefined` comparisons are
9500 * handled by the method instead. The `customizer` is invoked with up to six arguments:
9501 * (objValue, othValue [, index|key, object, other, stack]).
9506 * @param {*} value The value to compare.
9507 * @param {*} other The other value to compare.
9508 * @param {Function} [customizer] The function to customize comparisons.
9509 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9512 * function isGreeting(value) {
9513 * return /^h(?:i|ello)$/.test(value);
9516 * function customizer(objValue, othValue) {
9517 * if (isGreeting(objValue) && isGreeting(othValue)) {
9522 * var array = ['hello', 'goodbye'];
9523 * var other = ['hi', 'goodbye'];
9525 * _.isEqualWith(array, other, customizer);
9528 function isEqualWith(value, other, customizer) {
9529 customizer = typeof customizer == 'function' ? customizer : undefined;
9530 var result = customizer ? customizer(value, other) : undefined;
9531 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
9535 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
9536 * `SyntaxError`, `TypeError`, or `URIError` object.
9541 * @param {*} value The value to check.
9542 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
9545 * _.isError(new Error);
9551 function isError(value) {
9552 return isObjectLike(value) &&
9553 typeof value.message == 'string' && objectToString.call(value) == errorTag;
9557 * Checks if `value` is a finite primitive number.
9559 * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
9564 * @param {*} value The value to check.
9565 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
9571 * _.isFinite(Number.MAX_VALUE);
9577 * _.isFinite(Infinity);
9580 function isFinite(value) {
9581 return typeof value == 'number' && nativeIsFinite(value);
9585 * Checks if `value` is classified as a `Function` object.
9590 * @param {*} value The value to check.
9591 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9597 * _.isFunction(/abc/);
9600 function isFunction(value) {
9601 // The use of `Object#toString` avoids issues with the `typeof` operator
9602 // in Safari 8 which returns 'object' for typed array constructors, and
9603 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
9604 var tag = isObject(value) ? objectToString.call(value) : '';
9605 return tag == funcTag || tag == genTag;
9609 * Checks if `value` is an integer.
9611 * **Note:** This method is based on [`Number.isInteger`](https://mdn.io/Number/isInteger).
9616 * @param {*} value The value to check.
9617 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
9623 * _.isInteger(Number.MIN_VALUE);
9626 * _.isInteger(Infinity);
9632 function isInteger(value) {
9633 return typeof value == 'number' && value == toInteger(value);
9637 * Checks if `value` is a valid array-like length.
9639 * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
9644 * @param {*} value The value to check.
9645 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
9651 * _.isLength(Number.MIN_VALUE);
9654 * _.isLength(Infinity);
9660 function isLength(value) {
9661 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
9665 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
9666 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
9671 * @param {*} value The value to check.
9672 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
9678 * _.isObject([1, 2, 3]);
9681 * _.isObject(_.noop);
9687 function isObject(value) {
9688 // Avoid a V8 JIT bug in Chrome 19-20.
9689 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
9690 var type = typeof value;
9691 return !!value && (type == 'object' || type == 'function');
9695 * Checks if `value` is object-like. A value is object-like if it's not `null`
9696 * and has a `typeof` result of "object".
9701 * @param {*} value The value to check.
9702 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
9705 * _.isObjectLike({});
9708 * _.isObjectLike([1, 2, 3]);
9711 * _.isObjectLike(_.noop);
9714 * _.isObjectLike(null);
9717 function isObjectLike(value) {
9718 return !!value && typeof value == 'object';
9722 * Performs a deep comparison between `object` and `source` to determine if
9723 * `object` contains equivalent property values.
9725 * **Note:** This method supports comparing the same values as `_.isEqual`.
9730 * @param {Object} object The object to inspect.
9731 * @param {Object} source The object of property values to match.
9732 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
9735 * var object = { 'user': 'fred', 'age': 40 };
9737 * _.isMatch(object, { 'age': 40 });
9740 * _.isMatch(object, { 'age': 36 });
9743 function isMatch(object, source) {
9744 return object === source || baseIsMatch(object, source, getMatchData(source));
9748 * This method is like `_.isMatch` except that it accepts `customizer` which
9749 * is invoked to compare values. If `customizer` returns `undefined` comparisons
9750 * are handled by the method instead. The `customizer` is invoked with five
9751 * arguments: (objValue, srcValue, index|key, object, source).
9756 * @param {Object} object The object to inspect.
9757 * @param {Object} source The object of property values to match.
9758 * @param {Function} [customizer] The function to customize comparisons.
9759 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
9762 * function isGreeting(value) {
9763 * return /^h(?:i|ello)$/.test(value);
9766 * function customizer(objValue, srcValue) {
9767 * if (isGreeting(objValue) && isGreeting(srcValue)) {
9772 * var object = { 'greeting': 'hello' };
9773 * var source = { 'greeting': 'hi' };
9775 * _.isMatchWith(object, source, customizer);
9778 function isMatchWith(object, source, customizer) {
9779 customizer = typeof customizer == 'function' ? customizer : undefined;
9780 return baseIsMatch(object, source, getMatchData(source), customizer);
9784 * Checks if `value` is `NaN`.
9786 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
9787 * which returns `true` for `undefined` and other non-numeric values.
9792 * @param {*} value The value to check.
9793 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
9799 * _.isNaN(new Number(NaN));
9805 * _.isNaN(undefined);
9808 function isNaN(value) {
9809 // An `NaN` primitive is the only value that is not equal to itself.
9810 // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
9811 return isNumber(value) && value != +value;
9815 * Checks if `value` is a native function.
9820 * @param {*} value The value to check.
9821 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
9824 * _.isNative(Array.prototype.push);
9830 function isNative(value) {
9831 if (value == null) {
9834 if (isFunction(value)) {
9835 return reIsNative.test(funcToString.call(value));
9837 return isObjectLike(value) &&
9838 (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
9842 * Checks if `value` is `null`.
9847 * @param {*} value The value to check.
9848 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
9857 function isNull(value) {
9858 return value === null;
9862 * Checks if `value` is `null` or `undefined`.
9867 * @param {*} value The value to check.
9868 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
9880 function isNil(value) {
9881 return value == null;
9885 * Checks if `value` is classified as a `Number` primitive or object.
9887 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
9888 * as numbers, use the `_.isFinite` method.
9893 * @param {*} value The value to check.
9894 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9900 * _.isNumber(Number.MIN_VALUE);
9903 * _.isNumber(Infinity);
9909 function isNumber(value) {
9910 return typeof value == 'number' ||
9911 (isObjectLike(value) && objectToString.call(value) == numberTag);
9915 * Checks if `value` is a plain object, that is, an object created by the
9916 * `Object` constructor or one with a `[[Prototype]]` of `null`.
9921 * @param {*} value The value to check.
9922 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
9929 * _.isPlainObject(new Foo);
9932 * _.isPlainObject([1, 2, 3]);
9935 * _.isPlainObject({ 'x': 0, 'y': 0 });
9938 * _.isPlainObject(Object.create(null));
9941 function isPlainObject(value) {
9942 if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) {
9945 var proto = objectProto;
9946 if (typeof value.constructor == 'function') {
9947 proto = getPrototypeOf(value);
9949 if (proto === null) {
9952 var Ctor = proto.constructor;
9953 return (typeof Ctor == 'function' &&
9954 Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
9958 * Checks if `value` is classified as a `RegExp` object.
9963 * @param {*} value The value to check.
9964 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9967 * _.isRegExp(/abc/);
9970 * _.isRegExp('/abc/');
9973 function isRegExp(value) {
9974 return isObject(value) && objectToString.call(value) == regexpTag;
9978 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
9979 * double precision number which isn't the result of a rounded unsafe integer.
9981 * **Note:** This method is based on [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
9986 * @param {*} value The value to check.
9987 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
9990 * _.isSafeInteger(3);
9993 * _.isSafeInteger(Number.MIN_VALUE);
9996 * _.isSafeInteger(Infinity);
9999 * _.isSafeInteger('3');
10002 function isSafeInteger(value) {
10003 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
10007 * Checks if `value` is classified as a `String` primitive or object.
10012 * @param {*} value The value to check.
10013 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10016 * _.isString('abc');
10022 function isString(value) {
10023 return typeof value == 'string' ||
10024 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
10028 * Checks if `value` is classified as a `Symbol` primitive or object.
10033 * @param {*} value The value to check.
10034 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10037 * _.isSymbol(Symbol.iterator);
10040 * _.isSymbol('abc');
10043 function isSymbol(value) {
10044 return typeof value == 'symbol' ||
10045 (isObjectLike(value) && objectToString.call(value) == symbolTag);
10049 * Checks if `value` is classified as a typed array.
10054 * @param {*} value The value to check.
10055 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10058 * _.isTypedArray(new Uint8Array);
10061 * _.isTypedArray([]);
10064 function isTypedArray(value) {
10065 return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
10069 * Checks if `value` is `undefined`.
10074 * @param {*} value The value to check.
10075 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
10078 * _.isUndefined(void 0);
10081 * _.isUndefined(null);
10084 function isUndefined(value) {
10085 return value === undefined;
10089 * Checks if `value` is less than `other`.
10094 * @param {*} value The value to compare.
10095 * @param {*} other The other value to compare.
10096 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
10108 function lt(value, other) {
10109 return value < other;
10113 * Checks if `value` is less than or equal to `other`.
10118 * @param {*} value The value to compare.
10119 * @param {*} other The other value to compare.
10120 * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
10132 function lte(value, other) {
10133 return value <= other;
10137 * Converts `value` to an array.
10142 * @param {*} value The value to convert.
10143 * @returns {Array} Returns the converted array.
10146 * _.toArray({ 'a': 1, 'b': 2 });
10149 * _.toArray('abc');
10150 * // => ['a', 'b', 'c']
10158 function toArray(value) {
10162 if (isArrayLike(value)) {
10163 return isString(value) ? stringToArray(value) : copyArray(value);
10165 if (iteratorSymbol && value[iteratorSymbol]) {
10166 return iteratorToArray(value[iteratorSymbol]());
10168 var tag = getTag(value),
10169 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
10171 return func(value);
10175 * Converts `value` to an integer.
10177 * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
10182 * @param {*} value The value to convert.
10183 * @returns {number} Returns the converted integer.
10189 * _.toInteger(Number.MIN_VALUE);
10192 * _.toInteger(Infinity);
10193 * // => 1.7976931348623157e+308
10195 * _.toInteger('3');
10198 function toInteger(value) {
10200 return value === 0 ? value : 0;
10202 value = toNumber(value);
10203 if (value === INFINITY || value === -INFINITY) {
10204 var sign = (value < 0 ? -1 : 1);
10205 return sign * MAX_INTEGER;
10207 var remainder = value % 1;
10208 return value === value ? (remainder ? value - remainder : value) : 0;
10212 * Converts `value` to an integer suitable for use as the length of an
10213 * array-like object.
10215 * **Note:** This method is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
10220 * @param {*} value The value to convert.
10221 * @returns {number} Returns the converted integer.
10227 * _.toLength(Number.MIN_VALUE);
10230 * _.toLength(Infinity);
10236 function toLength(value) {
10237 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
10241 * Converts `value` to a number.
10246 * @param {*} value The value to process.
10247 * @returns {number} Returns the number.
10253 * _.toNumber(Number.MIN_VALUE);
10256 * _.toNumber(Infinity);
10262 function toNumber(value) {
10263 if (isObject(value)) {
10264 var other = isFunction(value.valueOf) ? value.valueOf() : value;
10265 value = isObject(other) ? (other + '') : other;
10267 if (typeof value != 'string') {
10268 return value === 0 ? value : +value;
10270 value = value.replace(reTrim, '');
10271 var isBinary = reIsBinary.test(value);
10272 return (isBinary || reIsOctal.test(value))
10273 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
10274 : (reIsBadHex.test(value) ? NAN : +value);
10278 * Converts `value` to a plain object flattening inherited enumerable
10279 * properties of `value` to own properties of the plain object.
10284 * @param {*} value The value to convert.
10285 * @returns {Object} Returns the converted plain object.
10292 * Foo.prototype.c = 3;
10294 * _.assign({ 'a': 1 }, new Foo);
10295 * // => { 'a': 1, 'b': 2 }
10297 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
10298 * // => { 'a': 1, 'b': 2, 'c': 3 }
10300 function toPlainObject(value) {
10301 return copyObject(value, keysIn(value));
10305 * Converts `value` to a safe integer. A safe integer can be compared and
10306 * represented correctly.
10311 * @param {*} value The value to convert.
10312 * @returns {number} Returns the converted integer.
10315 * _.toSafeInteger(3);
10318 * _.toSafeInteger(Number.MIN_VALUE);
10321 * _.toSafeInteger(Infinity);
10322 * // => 9007199254740991
10324 * _.toSafeInteger('3');
10327 function toSafeInteger(value) {
10328 return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
10332 * Converts `value` to a string if it's not one. An empty string is returned
10333 * for `null` and `undefined` values. The sign of `-0` is preserved.
10338 * @param {*} value The value to process.
10339 * @returns {string} Returns the string.
10342 * _.toString(null);
10348 * _.toString([1, 2, 3]);
10351 function toString(value) {
10352 // Exit early for strings to avoid a performance hit in some environments.
10353 if (typeof value == 'string') {
10356 if (value == null) {
10359 if (isSymbol(value)) {
10360 return Symbol ? symbolToString.call(value) : '';
10362 var result = (value + '');
10363 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
10366 /*------------------------------------------------------------------------*/
10369 * Assigns own enumerable properties of source objects to the destination
10370 * object. Source objects are applied from left to right. Subsequent sources
10371 * overwrite property assignments of previous sources.
10373 * **Note:** This method mutates `object` and is loosely based on
10374 * [`Object.assign`](https://mdn.io/Object/assign).
10379 * @param {Object} object The destination object.
10380 * @param {...Object} [sources] The source objects.
10381 * @returns {Object} Returns `object`.
10392 * Foo.prototype.d = 4;
10393 * Bar.prototype.f = 6;
10395 * _.assign({ 'a': 1 }, new Foo, new Bar);
10396 * // => { 'a': 1, 'c': 3, 'e': 5 }
10398 var assign = createAssigner(function(object, source) {
10399 copyObject(source, keys(source), object);
10403 * This method is like `_.assign` except that it iterates over own and
10404 * inherited source properties.
10406 * **Note:** This method mutates `object`.
10412 * @param {Object} object The destination object.
10413 * @param {...Object} [sources] The source objects.
10414 * @returns {Object} Returns `object`.
10425 * Foo.prototype.c = 3;
10426 * Bar.prototype.e = 5;
10428 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
10429 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
10431 var assignIn = createAssigner(function(object, source) {
10432 copyObject(source, keysIn(source), object);
10436 * This method is like `_.assignIn` except that it accepts `customizer` which
10437 * is invoked to produce the assigned values. If `customizer` returns `undefined`
10438 * assignment is handled by the method instead. The `customizer` is invoked
10439 * with five arguments: (objValue, srcValue, key, object, source).
10441 * **Note:** This method mutates `object`.
10445 * @alias extendWith
10447 * @param {Object} object The destination object.
10448 * @param {...Object} sources The source objects.
10449 * @param {Function} [customizer] The function to customize assigned values.
10450 * @returns {Object} Returns `object`.
10453 * function customizer(objValue, srcValue) {
10454 * return _.isUndefined(objValue) ? srcValue : objValue;
10457 * var defaults = _.partialRight(_.assignInWith, customizer);
10459 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
10460 * // => { 'a': 1, 'b': 2 }
10462 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
10463 copyObjectWith(source, keysIn(source), object, customizer);
10467 * This method is like `_.assign` except that it accepts `customizer` which
10468 * is invoked to produce the assigned values. If `customizer` returns `undefined`
10469 * assignment is handled by the method instead. The `customizer` is invoked
10470 * with five arguments: (objValue, srcValue, key, object, source).
10472 * **Note:** This method mutates `object`.
10477 * @param {Object} object The destination object.
10478 * @param {...Object} sources The source objects.
10479 * @param {Function} [customizer] The function to customize assigned values.
10480 * @returns {Object} Returns `object`.
10483 * function customizer(objValue, srcValue) {
10484 * return _.isUndefined(objValue) ? srcValue : objValue;
10487 * var defaults = _.partialRight(_.assignWith, customizer);
10489 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
10490 * // => { 'a': 1, 'b': 2 }
10492 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
10493 copyObjectWith(source, keys(source), object, customizer);
10497 * Creates an array of values corresponding to `paths` of `object`.
10502 * @param {Object} object The object to iterate over.
10503 * @param {...(string|string[])} [paths] The property paths of elements to pick,
10504 * specified individually or in arrays.
10505 * @returns {Array} Returns the new array of picked elements.
10508 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
10510 * _.at(object, ['a[0].b.c', 'a[1]']);
10513 * _.at(['a', 'b', 'c'], 0, 2);
10516 var at = rest(function(object, paths) {
10517 return baseAt(object, baseFlatten(paths));
10521 * Creates an object that inherits from the `prototype` object. If a `properties`
10522 * object is provided its own enumerable properties are assigned to the created object.
10527 * @param {Object} prototype The object to inherit from.
10528 * @param {Object} [properties] The properties to assign to the object.
10529 * @returns {Object} Returns the new object.
10532 * function Shape() {
10537 * function Circle() {
10538 * Shape.call(this);
10541 * Circle.prototype = _.create(Shape.prototype, {
10542 * 'constructor': Circle
10545 * var circle = new Circle;
10546 * circle instanceof Circle;
10549 * circle instanceof Shape;
10552 function create(prototype, properties) {
10553 var result = baseCreate(prototype);
10554 return properties ? baseAssign(result, properties) : result;
10558 * Assigns own and inherited enumerable properties of source objects to the
10559 * destination object for all destination properties that resolve to `undefined`.
10560 * Source objects are applied from left to right. Once a property is set,
10561 * additional values of the same property are ignored.
10563 * **Note:** This method mutates `object`.
10568 * @param {Object} object The destination object.
10569 * @param {...Object} [sources] The source objects.
10570 * @returns {Object} Returns `object`.
10573 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
10574 * // => { 'user': 'barney', 'age': 36 }
10576 var defaults = rest(function(args) {
10577 args.push(undefined, assignInDefaults);
10578 return apply(assignInWith, undefined, args);
10582 * This method is like `_.defaults` except that it recursively assigns
10583 * default properties.
10585 * **Note:** This method mutates `object`.
10590 * @param {Object} object The destination object.
10591 * @param {...Object} [sources] The source objects.
10592 * @returns {Object} Returns `object`.
10595 * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
10596 * // => { 'user': { 'name': 'barney', 'age': 36 } }
10599 var defaultsDeep = rest(function(args) {
10600 args.push(undefined, mergeDefaults);
10601 return apply(mergeWith, undefined, args);
10605 * This method is like `_.find` except that it returns the key of the first
10606 * element `predicate` returns truthy for instead of the element itself.
10611 * @param {Object} object The object to search.
10612 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
10613 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
10617 * 'barney': { 'age': 36, 'active': true },
10618 * 'fred': { 'age': 40, 'active': false },
10619 * 'pebbles': { 'age': 1, 'active': true }
10622 * _.findKey(users, function(o) { return o.age < 40; });
10623 * // => 'barney' (iteration order is not guaranteed)
10625 * // using the `_.matches` iteratee shorthand
10626 * _.findKey(users, { 'age': 1, 'active': true });
10629 * // using the `_.matchesProperty` iteratee shorthand
10630 * _.findKey(users, ['active', false]);
10633 * // using the `_.property` iteratee shorthand
10634 * _.findKey(users, 'active');
10637 function findKey(object, predicate) {
10638 return baseFind(object, getIteratee(predicate, 3), baseForOwn, true);
10642 * This method is like `_.findKey` except that it iterates over elements of
10643 * a collection in the opposite order.
10648 * @param {Object} object The object to search.
10649 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
10650 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
10654 * 'barney': { 'age': 36, 'active': true },
10655 * 'fred': { 'age': 40, 'active': false },
10656 * 'pebbles': { 'age': 1, 'active': true }
10659 * _.findLastKey(users, function(o) { return o.age < 40; });
10660 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
10662 * // using the `_.matches` iteratee shorthand
10663 * _.findLastKey(users, { 'age': 36, 'active': true });
10666 * // using the `_.matchesProperty` iteratee shorthand
10667 * _.findLastKey(users, ['active', false]);
10670 * // using the `_.property` iteratee shorthand
10671 * _.findLastKey(users, 'active');
10674 function findLastKey(object, predicate) {
10675 return baseFind(object, getIteratee(predicate, 3), baseForOwnRight, true);
10679 * Iterates over own and inherited enumerable properties of an object invoking
10680 * `iteratee` for each property. The iteratee is invoked with three arguments:
10681 * (value, key, object). Iteratee functions may exit iteration early by explicitly
10682 * returning `false`.
10687 * @param {Object} object The object to iterate over.
10688 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10689 * @returns {Object} Returns `object`.
10697 * Foo.prototype.c = 3;
10699 * _.forIn(new Foo, function(value, key) {
10700 * console.log(key);
10702 * // => logs 'a', 'b', then 'c' (iteration order is not guaranteed)
10704 function forIn(object, iteratee) {
10705 return object == null ? object : baseFor(object, toFunction(iteratee), keysIn);
10709 * This method is like `_.forIn` except that it iterates over properties of
10710 * `object` in the opposite order.
10715 * @param {Object} object The object to iterate over.
10716 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10717 * @returns {Object} Returns `object`.
10725 * Foo.prototype.c = 3;
10727 * _.forInRight(new Foo, function(value, key) {
10728 * console.log(key);
10730 * // => logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'
10732 function forInRight(object, iteratee) {
10733 return object == null ? object : baseForRight(object, toFunction(iteratee), keysIn);
10737 * Iterates over own enumerable properties of an object invoking `iteratee`
10738 * for each property. The iteratee is invoked with three arguments:
10739 * (value, key, object). Iteratee functions may exit iteration early by
10740 * explicitly returning `false`.
10745 * @param {Object} object The object to iterate over.
10746 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10747 * @returns {Object} Returns `object`.
10755 * Foo.prototype.c = 3;
10757 * _.forOwn(new Foo, function(value, key) {
10758 * console.log(key);
10760 * // => logs 'a' then 'b' (iteration order is not guaranteed)
10762 function forOwn(object, iteratee) {
10763 return object && baseForOwn(object, toFunction(iteratee));
10767 * This method is like `_.forOwn` except that it iterates over properties of
10768 * `object` in the opposite order.
10773 * @param {Object} object The object to iterate over.
10774 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10775 * @returns {Object} Returns `object`.
10783 * Foo.prototype.c = 3;
10785 * _.forOwnRight(new Foo, function(value, key) {
10786 * console.log(key);
10788 * // => logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'
10790 function forOwnRight(object, iteratee) {
10791 return object && baseForOwnRight(object, toFunction(iteratee));
10795 * Creates an array of function property names from own enumerable properties
10801 * @param {Object} object The object to inspect.
10802 * @returns {Array} Returns the new array of property names.
10806 * this.a = _.constant('a');
10807 * this.b = _.constant('b');
10810 * Foo.prototype.c = _.constant('c');
10812 * _.functions(new Foo);
10815 function functions(object) {
10816 return object == null ? [] : baseFunctions(object, keys(object));
10820 * Creates an array of function property names from own and inherited
10821 * enumerable properties of `object`.
10826 * @param {Object} object The object to inspect.
10827 * @returns {Array} Returns the new array of property names.
10831 * this.a = _.constant('a');
10832 * this.b = _.constant('b');
10835 * Foo.prototype.c = _.constant('c');
10837 * _.functionsIn(new Foo);
10838 * // => ['a', 'b', 'c']
10840 function functionsIn(object) {
10841 return object == null ? [] : baseFunctions(object, keysIn(object));
10845 * Gets the value at `path` of `object`. If the resolved value is
10846 * `undefined` the `defaultValue` is used in its place.
10851 * @param {Object} object The object to query.
10852 * @param {Array|string} path The path of the property to get.
10853 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
10854 * @returns {*} Returns the resolved value.
10857 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
10859 * _.get(object, 'a[0].b.c');
10862 * _.get(object, ['a', '0', 'b', 'c']);
10865 * _.get(object, 'a.b.c', 'default');
10868 function get(object, path, defaultValue) {
10869 var result = object == null ? undefined : baseGet(object, path);
10870 return result === undefined ? defaultValue : result;
10874 * Checks if `path` is a direct property of `object`.
10879 * @param {Object} object The object to query.
10880 * @param {Array|string} path The path to check.
10881 * @returns {boolean} Returns `true` if `path` exists, else `false`.
10884 * var object = { 'a': { 'b': { 'c': 3 } } };
10885 * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
10887 * _.has(object, 'a');
10890 * _.has(object, 'a.b.c');
10893 * _.has(object, ['a', 'b', 'c']);
10896 * _.has(other, 'a');
10899 function has(object, path) {
10900 return hasPath(object, path, baseHas);
10904 * Checks if `path` is a direct or inherited property of `object`.
10909 * @param {Object} object The object to query.
10910 * @param {Array|string} path The path to check.
10911 * @returns {boolean} Returns `true` if `path` exists, else `false`.
10914 * var object = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
10916 * _.hasIn(object, 'a');
10919 * _.hasIn(object, 'a.b.c');
10922 * _.hasIn(object, ['a', 'b', 'c']);
10925 * _.hasIn(object, 'b');
10928 function hasIn(object, path) {
10929 return hasPath(object, path, baseHasIn);
10933 * Creates an object composed of the inverted keys and values of `object`.
10934 * If `object` contains duplicate values, subsequent values overwrite property
10935 * assignments of previous values unless `multiVal` is `true`.
10940 * @param {Object} object The object to invert.
10941 * @param {boolean} [multiVal] Allow multiple values per key.
10942 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
10943 * @returns {Object} Returns the new inverted object.
10946 * var object = { 'a': 1, 'b': 2, 'c': 1 };
10948 * _.invert(object);
10949 * // => { '1': 'c', '2': 'b' }
10951 * // with `multiVal`
10952 * _.invert(object, true);
10953 * // => { '1': ['a', 'c'], '2': ['b'] }
10955 function invert(object, multiVal, guard) {
10956 return arrayReduce(keys(object), function(result, key) {
10957 var value = object[key];
10958 if (multiVal && !guard) {
10959 if (hasOwnProperty.call(result, value)) {
10960 result[value].push(key);
10962 result[value] = [key];
10966 result[value] = key;
10973 * Invokes the method at `path` of `object`.
10978 * @param {Object} object The object to query.
10979 * @param {Array|string} path The path of the method to invoke.
10980 * @param {...*} [args] The arguments to invoke the method with.
10981 * @returns {*} Returns the result of the invoked method.
10984 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
10986 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
10989 var invoke = rest(baseInvoke);
10992 * Creates an array of the own enumerable property names of `object`.
10994 * **Note:** Non-object values are coerced to objects. See the
10995 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
10996 * for more details.
11001 * @param {Object} object The object to query.
11002 * @returns {Array} Returns the array of property names.
11010 * Foo.prototype.c = 3;
11013 * // => ['a', 'b'] (iteration order is not guaranteed)
11018 function keys(object) {
11019 var isProto = isPrototype(object);
11020 if (!(isProto || isArrayLike(object))) {
11021 return baseKeys(object);
11023 var indexes = indexKeys(object),
11024 skipIndexes = !!indexes,
11025 result = indexes || [],
11026 length = result.length;
11028 for (var key in object) {
11029 if (baseHas(object, key) &&
11030 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
11031 !(isProto && key == 'constructor')) {
11039 * Creates an array of the own and inherited enumerable property names of `object`.
11041 * **Note:** Non-object values are coerced to objects.
11046 * @param {Object} object The object to query.
11047 * @returns {Array} Returns the array of property names.
11055 * Foo.prototype.c = 3;
11057 * _.keysIn(new Foo);
11058 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
11060 function keysIn(object) {
11062 isProto = isPrototype(object),
11063 props = baseKeysIn(object),
11064 propsLength = props.length,
11065 indexes = indexKeys(object),
11066 skipIndexes = !!indexes,
11067 result = indexes || [],
11068 length = result.length;
11070 while (++index < propsLength) {
11071 var key = props[index];
11072 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
11073 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
11081 * The opposite of `_.mapValues`; this method creates an object with the
11082 * same values as `object` and keys generated by running each own enumerable
11083 * property of `object` through `iteratee`.
11088 * @param {Object} object The object to iterate over.
11089 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
11090 * @returns {Object} Returns the new mapped object.
11093 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
11094 * return key + value;
11096 * // => { 'a1': 1, 'b2': 2 }
11098 function mapKeys(object, iteratee) {
11100 iteratee = getIteratee(iteratee, 3);
11102 baseForOwn(object, function(value, key, object) {
11103 result[iteratee(value, key, object)] = value;
11109 * Creates an object with the same keys as `object` and values generated by
11110 * running each own enumerable property of `object` through `iteratee`. The
11111 * iteratee function is invoked with three arguments: (value, key, object).
11116 * @param {Object} object The object to iterate over.
11117 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
11118 * @returns {Object} Returns the new mapped object.
11122 * 'fred': { 'user': 'fred', 'age': 40 },
11123 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
11126 * _.mapValues(users, function(o) { return o.age; });
11127 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
11129 * // using the `_.property` iteratee shorthand
11130 * _.mapValues(users, 'age');
11131 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
11133 function mapValues(object, iteratee) {
11135 iteratee = getIteratee(iteratee, 3);
11137 baseForOwn(object, function(value, key, object) {
11138 result[key] = iteratee(value, key, object);
11144 * Recursively merges own and inherited enumerable properties of source
11145 * objects into the destination object, skipping source properties that resolve
11146 * to `undefined`. Array and plain object properties are merged recursively.
11147 * Other objects and value types are overridden by assignment. Source objects
11148 * are applied from left to right. Subsequent sources overwrite property
11149 * assignments of previous sources.
11151 * **Note:** This method mutates `object`.
11156 * @param {Object} object The destination object.
11157 * @param {...Object} [sources] The source objects.
11158 * @returns {Object} Returns `object`.
11162 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
11166 * 'data': [{ 'age': 36 }, { 'age': 40 }]
11169 * _.merge(users, ages);
11170 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
11172 var merge = createAssigner(function(object, source, srcIndex) {
11173 baseMerge(object, source, srcIndex);
11177 * This method is like `_.merge` except that it accepts `customizer` which
11178 * is invoked to produce the merged values of the destination and source
11179 * properties. If `customizer` returns `undefined` merging is handled by the
11180 * method instead. The `customizer` is invoked with seven arguments:
11181 * (objValue, srcValue, key, object, source, stack).
11186 * @param {Object} object The destination object.
11187 * @param {...Object} sources The source objects.
11188 * @param {Function} customizer The function to customize assigned values.
11189 * @returns {Object} Returns `object`.
11192 * function customizer(objValue, srcValue) {
11193 * if (_.isArray(objValue)) {
11194 * return objValue.concat(srcValue);
11199 * 'fruits': ['apple'],
11200 * 'vegetables': ['beet']
11204 * 'fruits': ['banana'],
11205 * 'vegetables': ['carrot']
11208 * _.mergeWith(object, other, customizer);
11209 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
11211 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
11212 baseMerge(object, source, srcIndex, customizer);
11216 * The opposite of `_.pick`; this method creates an object composed of the
11217 * own and inherited enumerable properties of `object` that are not omitted.
11222 * @param {Object} object The source object.
11223 * @param {...(string|string[])} [props] The property names to omit, specified
11224 * individually or in arrays..
11225 * @returns {Object} Returns the new object.
11228 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11230 * _.omit(object, ['a', 'c']);
11231 * // => { 'b': '2' }
11233 var omit = rest(function(object, props) {
11234 if (object == null) {
11237 props = arrayMap(baseFlatten(props), String);
11238 return basePick(object, baseDifference(keysIn(object), props));
11242 * The opposite of `_.pickBy`; this method creates an object composed of the
11243 * own and inherited enumerable properties of `object` that `predicate`
11244 * doesn't return truthy for.
11249 * @param {Object} object The source object.
11250 * @param {Function|Object|string} [predicate=_.identity] The function invoked per property.
11251 * @returns {Object} Returns the new object.
11254 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11256 * _.omitBy(object, _.isNumber);
11257 * // => { 'b': '2' }
11259 function omitBy(object, predicate) {
11260 predicate = getIteratee(predicate, 2);
11261 return basePickBy(object, function(value, key) {
11262 return !predicate(value, key);
11267 * Creates an object composed of the picked `object` properties.
11272 * @param {Object} object The source object.
11273 * @param {...(string|string[])} [props] The property names to pick, specified
11274 * individually or in arrays.
11275 * @returns {Object} Returns the new object.
11278 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11280 * _.pick(object, ['a', 'c']);
11281 * // => { 'a': 1, 'c': 3 }
11283 var pick = rest(function(object, props) {
11284 return object == null ? {} : basePick(object, baseFlatten(props));
11288 * Creates an object composed of the `object` properties `predicate` returns
11289 * truthy for. The predicate is invoked with one argument: (value).
11294 * @param {Object} object The source object.
11295 * @param {Function|Object|string} [predicate=_.identity] The function invoked per property.
11296 * @returns {Object} Returns the new object.
11299 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11301 * _.pickBy(object, _.isNumber);
11302 * // => { 'a': 1, 'c': 3 }
11304 function pickBy(object, predicate) {
11305 return object == null ? {} : basePickBy(object, getIteratee(predicate, 2));
11309 * This method is like `_.get` except that if the resolved value is a function
11310 * it's invoked with the `this` binding of its parent object and its result
11316 * @param {Object} object The object to query.
11317 * @param {Array|string} path The path of the property to resolve.
11318 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
11319 * @returns {*} Returns the resolved value.
11322 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
11324 * _.result(object, 'a[0].b.c1');
11327 * _.result(object, 'a[0].b.c2');
11330 * _.result(object, 'a[0].b.c3', 'default');
11333 * _.result(object, 'a[0].b.c3', _.constant('default'));
11336 function result(object, path, defaultValue) {
11337 if (!isKey(path, object)) {
11338 path = baseToPath(path);
11339 var result = get(object, path);
11340 object = parent(object, path);
11342 result = object == null ? undefined : object[path];
11344 if (result === undefined) {
11345 result = defaultValue;
11347 return isFunction(result) ? result.call(object) : result;
11351 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist
11352 * it's created. Arrays are created for missing index properties while objects
11353 * are created for all other missing properties. Use `_.setWith` to customize
11359 * @param {Object} object The object to modify.
11360 * @param {Array|string} path The path of the property to set.
11361 * @param {*} value The value to set.
11362 * @returns {Object} Returns `object`.
11365 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
11367 * _.set(object, 'a[0].b.c', 4);
11368 * console.log(object.a[0].b.c);
11371 * _.set(object, 'x[0].y.z', 5);
11372 * console.log(object.x[0].y.z);
11375 function set(object, path, value) {
11376 return object == null ? object : baseSet(object, path, value);
11380 * This method is like `_.set` except that it accepts `customizer` which is
11381 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
11382 * path creation is handled by the method instead. The `customizer` is invoked
11383 * with three arguments: (nsValue, key, nsObject).
11388 * @param {Object} object The object to modify.
11389 * @param {Array|string} path The path of the property to set.
11390 * @param {*} value The value to set.
11391 * @param {Function} [customizer] The function to customize assigned values.
11392 * @returns {Object} Returns `object`.
11395 * _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, Object);
11396 * // => { '0': { '1': { '2': 3 }, 'length': 2 } }
11398 function setWith(object, path, value, customizer) {
11399 customizer = typeof customizer == 'function' ? customizer : undefined;
11400 return object == null ? object : baseSet(object, path, value, customizer);
11404 * Creates an array of own enumerable key-value pairs for `object`.
11409 * @param {Object} object The object to query.
11410 * @returns {Array} Returns the new array of key-value pairs.
11418 * Foo.prototype.c = 3;
11420 * _.toPairs(new Foo);
11421 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
11423 function toPairs(object) {
11424 return baseToPairs(object, keys(object));
11428 * Creates an array of own and inherited enumerable key-value pairs for `object`.
11433 * @param {Object} object The object to query.
11434 * @returns {Array} Returns the new array of key-value pairs.
11442 * Foo.prototype.c = 3;
11444 * _.toPairsIn(new Foo);
11445 * // => [['a', 1], ['b', 2], ['c', 1]] (iteration order is not guaranteed)
11447 function toPairsIn(object) {
11448 return baseToPairs(object, keysIn(object));
11452 * An alternative to `_.reduce`; this method transforms `object` to a new
11453 * `accumulator` object which is the result of running each of its own enumerable
11454 * properties through `iteratee`, with each invocation potentially mutating
11455 * the `accumulator` object. The iteratee is invoked with four arguments:
11456 * (accumulator, value, key, object). Iteratee functions may exit iteration
11457 * early by explicitly returning `false`.
11462 * @param {Array|Object} object The object to iterate over.
11463 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11464 * @param {*} [accumulator] The custom accumulator value.
11465 * @returns {*} Returns the accumulated value.
11468 * _.transform([2, 3, 4], function(result, n) {
11469 * result.push(n *= n);
11470 * return n % 2 == 0;
11474 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
11475 * (result[value] || (result[value] = [])).push(key);
11477 * // => { '1': ['a', 'c'], '2': ['b'] }
11479 function transform(object, iteratee, accumulator) {
11480 var isArr = isArray(object) || isTypedArray(object);
11481 iteratee = getIteratee(iteratee, 4);
11483 if (accumulator == null) {
11484 if (isArr || isObject(object)) {
11485 var Ctor = object.constructor;
11487 accumulator = isArray(object) ? new Ctor : [];
11489 accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
11495 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
11496 return iteratee(accumulator, value, index, object);
11498 return accumulator;
11502 * Removes the property at `path` of `object`.
11507 * @param {Object} object The object to modify.
11508 * @param {Array|string} path The path of the property to unset.
11509 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
11512 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
11513 * _.unset(object, 'a[0].b.c');
11516 * console.log(object);
11517 * // => { 'a': [{ 'b': {} }] };
11519 * _.unset(object, 'a[0].b.c');
11522 * console.log(object);
11523 * // => { 'a': [{ 'b': {} }] };
11525 function unset(object, path) {
11526 return object == null ? true : baseUnset(object, path);
11530 * Creates an array of the own enumerable property values of `object`.
11532 * **Note:** Non-object values are coerced to objects.
11537 * @param {Object} object The object to query.
11538 * @returns {Array} Returns the array of property values.
11546 * Foo.prototype.c = 3;
11548 * _.values(new Foo);
11549 * // => [1, 2] (iteration order is not guaranteed)
11554 function values(object) {
11555 return object ? baseValues(object, keys(object)) : [];
11559 * Creates an array of the own and inherited enumerable property values of `object`.
11561 * **Note:** Non-object values are coerced to objects.
11566 * @param {Object} object The object to query.
11567 * @returns {Array} Returns the array of property values.
11575 * Foo.prototype.c = 3;
11577 * _.valuesIn(new Foo);
11578 * // => [1, 2, 3] (iteration order is not guaranteed)
11580 function valuesIn(object) {
11581 return object == null ? baseValues(object, keysIn(object)) : [];
11584 /*------------------------------------------------------------------------*/
11587 * Clamps `number` within the inclusive `lower` and `upper` bounds.
11592 * @param {number} number The number to clamp.
11593 * @param {number} [lower] The lower bound.
11594 * @param {number} upper The upper bound.
11595 * @returns {number} Returns the clamped number.
11598 * _.clamp(-10, -5, 5);
11601 * _.clamp(10, -5, 5);
11604 function clamp(number, lower, upper) {
11605 if (upper === undefined) {
11609 if (upper !== undefined) {
11610 upper = toNumber(upper);
11611 upper = upper === upper ? upper : 0;
11613 if (lower !== undefined) {
11614 lower = toNumber(lower);
11615 lower = lower === lower ? lower : 0;
11617 return baseClamp(toNumber(number), lower, upper);
11621 * Checks if `n` is between `start` and up to but not including, `end`. If
11622 * `end` is not specified it's set to `start` with `start` then set to `0`.
11623 * If `start` is greater than `end` the params are swapped to support
11629 * @param {number} number The number to check.
11630 * @param {number} [start=0] The start of the range.
11631 * @param {number} end The end of the range.
11632 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
11635 * _.inRange(3, 2, 4);
11647 * _.inRange(1.2, 2);
11650 * _.inRange(5.2, 4);
11653 * _.inRange(-3, -2, -6);
11656 function inRange(number, start, end) {
11657 start = toNumber(start) || 0;
11658 if (end === undefined) {
11662 end = toNumber(end) || 0;
11664 number = toNumber(number);
11665 return baseInRange(number, start, end);
11669 * Produces a random number between the inclusive `lower` and `upper` bounds.
11670 * If only one argument is provided a number between `0` and the given number
11671 * is returned. If `floating` is `true`, or either `lower` or `upper` are floats,
11672 * a floating-point number is returned instead of an integer.
11674 * **Note:** JavaScript follows the IEEE-754 standard for resolving
11675 * floating-point values which can produce unexpected results.
11680 * @param {number} [lower=0] The lower bound.
11681 * @param {number} [upper=1] The upper bound.
11682 * @param {boolean} [floating] Specify returning a floating-point number.
11683 * @returns {number} Returns the random number.
11687 * // => an integer between 0 and 5
11690 * // => also an integer between 0 and 5
11692 * _.random(5, true);
11693 * // => a floating-point number between 0 and 5
11695 * _.random(1.2, 5.2);
11696 * // => a floating-point number between 1.2 and 5.2
11698 function random(lower, upper, floating) {
11699 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
11700 upper = floating = undefined;
11702 if (floating === undefined) {
11703 if (typeof upper == 'boolean') {
11707 else if (typeof lower == 'boolean') {
11712 if (lower === undefined && upper === undefined) {
11717 lower = toNumber(lower) || 0;
11718 if (upper === undefined) {
11722 upper = toNumber(upper) || 0;
11725 if (lower > upper) {
11730 if (floating || lower % 1 || upper % 1) {
11731 var rand = nativeRandom();
11732 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
11734 return baseRandom(lower, upper);
11737 /*------------------------------------------------------------------------*/
11740 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
11745 * @param {string} [string=''] The string to convert.
11746 * @returns {string} Returns the camel cased string.
11749 * _.camelCase('Foo Bar');
11752 * _.camelCase('--foo-bar');
11755 * _.camelCase('__foo_bar__');
11758 var camelCase = createCompounder(function(result, word, index) {
11759 word = word.toLowerCase();
11760 return result + (index ? capitalize(word) : word);
11764 * Converts the first character of `string` to upper case and the remaining
11770 * @param {string} [string=''] The string to capitalize.
11771 * @returns {string} Returns the capitalized string.
11774 * _.capitalize('FRED');
11777 function capitalize(string) {
11778 return upperFirst(toString(string).toLowerCase());
11782 * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
11783 * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
11788 * @param {string} [string=''] The string to deburr.
11789 * @returns {string} Returns the deburred string.
11792 * _.deburr('déjà vu');
11795 function deburr(string) {
11796 string = toString(string);
11797 return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
11801 * Checks if `string` ends with the given target string.
11806 * @param {string} [string=''] The string to search.
11807 * @param {string} [target] The string to search for.
11808 * @param {number} [position=string.length] The position to search from.
11809 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
11812 * _.endsWith('abc', 'c');
11815 * _.endsWith('abc', 'b');
11818 * _.endsWith('abc', 'b', 2);
11821 function endsWith(string, target, position) {
11822 string = toString(string);
11823 target = typeof target == 'string' ? target : (target + '');
11825 var length = string.length;
11826 position = position === undefined
11828 : baseClamp(toInteger(position), 0, length);
11830 position -= target.length;
11831 return position >= 0 && string.indexOf(target, position) == position;
11835 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
11836 * their corresponding HTML entities.
11838 * **Note:** No other characters are escaped. To escape additional
11839 * characters use a third-party library like [_he_](https://mths.be/he).
11841 * Though the ">" character is escaped for symmetry, characters like
11842 * ">" and "/" don't need escaping in HTML and have no special meaning
11843 * unless they're part of a tag or unquoted attribute value.
11844 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
11845 * (under "semi-related fun fact") for more details.
11847 * Backticks are escaped because in IE < 9, they can break out of
11848 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
11849 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
11850 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
11851 * for more details.
11853 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
11854 * to reduce XSS vectors.
11859 * @param {string} [string=''] The string to escape.
11860 * @returns {string} Returns the escaped string.
11863 * _.escape('fred, barney, & pebbles');
11864 * // => 'fred, barney, & pebbles'
11866 function escape(string) {
11867 string = toString(string);
11868 return (string && reHasUnescapedHtml.test(string))
11869 ? string.replace(reUnescapedHtml, escapeHtmlChar)
11874 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
11875 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
11880 * @param {string} [string=''] The string to escape.
11881 * @returns {string} Returns the escaped string.
11884 * _.escapeRegExp('[lodash](https://lodash.com/)');
11885 * // => '\[lodash\]\(https://lodash\.com/\)'
11887 function escapeRegExp(string) {
11888 string = toString(string);
11889 return (string && reHasRegExpChar.test(string))
11890 ? string.replace(reRegExpChar, '\\$&')
11895 * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
11900 * @param {string} [string=''] The string to convert.
11901 * @returns {string} Returns the kebab cased string.
11904 * _.kebabCase('Foo Bar');
11907 * _.kebabCase('fooBar');
11910 * _.kebabCase('__foo_bar__');
11913 var kebabCase = createCompounder(function(result, word, index) {
11914 return result + (index ? '-' : '') + word.toLowerCase();
11918 * Converts `string`, as space separated words, to lower case.
11923 * @param {string} [string=''] The string to convert.
11924 * @returns {string} Returns the lower cased string.
11927 * _.lowerCase('--Foo-Bar');
11930 * _.lowerCase('fooBar');
11933 * _.lowerCase('__FOO_BAR__');
11936 var lowerCase = createCompounder(function(result, word, index) {
11937 return result + (index ? ' ' : '') + word.toLowerCase();
11941 * Converts the first character of `string` to lower case.
11946 * @param {string} [string=''] The string to convert.
11947 * @returns {string} Returns the converted string.
11950 * _.lowerFirst('Fred');
11953 * _.lowerFirst('FRED');
11956 var lowerFirst = createCaseFirst('toLowerCase');
11959 * Converts the first character of `string` to upper case.
11964 * @param {string} [string=''] The string to convert.
11965 * @returns {string} Returns the converted string.
11968 * _.upperFirst('fred');
11971 * _.upperFirst('FRED');
11974 var upperFirst = createCaseFirst('toUpperCase');
11977 * Pads `string` on the left and right sides if it's shorter than `length`.
11978 * Padding characters are truncated if they can't be evenly divided by `length`.
11983 * @param {string} [string=''] The string to pad.
11984 * @param {number} [length=0] The padding length.
11985 * @param {string} [chars=' '] The string used as padding.
11986 * @returns {string} Returns the padded string.
11992 * _.pad('abc', 8, '_-');
11998 function pad(string, length, chars) {
11999 string = toString(string);
12000 length = toInteger(length);
12002 var strLength = stringSize(string);
12003 if (!length || strLength >= length) {
12006 var mid = (length - strLength) / 2,
12007 leftLength = nativeFloor(mid),
12008 rightLength = nativeCeil(mid);
12010 return createPadding('', leftLength, chars) + string + createPadding('', rightLength, chars);
12014 * Pads `string` on the right side if it's shorter than `length`. Padding
12015 * characters are truncated if they exceed `length`.
12020 * @param {string} [string=''] The string to pad.
12021 * @param {number} [length=0] The padding length.
12022 * @param {string} [chars=' '] The string used as padding.
12023 * @returns {string} Returns the padded string.
12026 * _.padEnd('abc', 6);
12029 * _.padEnd('abc', 6, '_-');
12032 * _.padEnd('abc', 3);
12035 function padEnd(string, length, chars) {
12036 string = toString(string);
12037 return string + createPadding(string, length, chars);
12041 * Pads `string` on the left side if it's shorter than `length`. Padding
12042 * characters are truncated if they exceed `length`.
12047 * @param {string} [string=''] The string to pad.
12048 * @param {number} [length=0] The padding length.
12049 * @param {string} [chars=' '] The string used as padding.
12050 * @returns {string} Returns the padded string.
12053 * _.padStart('abc', 6);
12056 * _.padStart('abc', 6, '_-');
12059 * _.padStart('abc', 3);
12062 function padStart(string, length, chars) {
12063 string = toString(string);
12064 return createPadding(string, length, chars) + string;
12068 * Converts `string` to an integer of the specified radix. If `radix` is
12069 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
12070 * in which case a `radix` of `16` is used.
12072 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#x15.1.2.2)
12078 * @param {string} string The string to convert.
12079 * @param {number} [radix] The radix to interpret `value` by.
12080 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12081 * @returns {number} Returns the converted integer.
12084 * _.parseInt('08');
12087 * _.map(['6', '08', '10'], _.parseInt);
12090 function parseInt(string, radix, guard) {
12091 // Chrome fails to trim leading <BOM> whitespace characters.
12092 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
12093 if (guard || radix == null) {
12095 } else if (radix) {
12098 string = toString(string).replace(reTrim, '');
12099 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
12103 * Repeats the given string `n` times.
12108 * @param {string} [string=''] The string to repeat.
12109 * @param {number} [n=0] The number of times to repeat the string.
12110 * @returns {string} Returns the repeated string.
12113 * _.repeat('*', 3);
12116 * _.repeat('abc', 2);
12119 * _.repeat('abc', 0);
12122 function repeat(string, n) {
12123 string = toString(string);
12127 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
12130 // Leverage the exponentiation by squaring algorithm for a faster repeat.
12131 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
12136 n = nativeFloor(n / 2);
12144 * Replaces matches for `pattern` in `string` with `replacement`.
12146 * **Note:** This method is based on [`String#replace`](https://mdn.io/String/replace).
12151 * @param {string} [string=''] The string to modify.
12152 * @param {RegExp|string} pattern The pattern to replace.
12153 * @param {Function|string} replacement The match replacement.
12154 * @returns {string} Returns the modified string.
12157 * _.replace('Hi Fred', 'Fred', 'Barney');
12158 * // => 'Hi Barney'
12160 function replace() {
12161 var args = arguments,
12162 string = toString(args[0]);
12164 return args.length < 3 ? string : string.replace(args[1], args[2]);
12168 * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
12173 * @param {string} [string=''] The string to convert.
12174 * @returns {string} Returns the snake cased string.
12177 * _.snakeCase('Foo Bar');
12180 * _.snakeCase('fooBar');
12183 * _.snakeCase('--foo-bar');
12186 var snakeCase = createCompounder(function(result, word, index) {
12187 return result + (index ? '_' : '') + word.toLowerCase();
12191 * Splits `string` by `separator`.
12193 * **Note:** This method is based on [`String#split`](https://mdn.io/String/split).
12198 * @param {string} [string=''] The string to split.
12199 * @param {RegExp|string} separator The separator pattern to split by.
12200 * @param {number} [limit] The length to truncate results to.
12201 * @returns {Array} Returns the new array of string segments.
12204 * _.split('a-b-c', '-', 2);
12207 function split(string, separator, limit) {
12208 return toString(string).split(separator, limit);
12212 * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
12217 * @param {string} [string=''] The string to convert.
12218 * @returns {string} Returns the start cased string.
12221 * _.startCase('--foo-bar');
12224 * _.startCase('fooBar');
12227 * _.startCase('__foo_bar__');
12230 var startCase = createCompounder(function(result, word, index) {
12231 return result + (index ? ' ' : '') + capitalize(word);
12235 * Checks if `string` starts with the given target string.
12240 * @param {string} [string=''] The string to search.
12241 * @param {string} [target] The string to search for.
12242 * @param {number} [position=0] The position to search from.
12243 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
12246 * _.startsWith('abc', 'a');
12249 * _.startsWith('abc', 'b');
12252 * _.startsWith('abc', 'b', 1);
12255 function startsWith(string, target, position) {
12256 string = toString(string);
12257 position = baseClamp(toInteger(position), 0, string.length);
12258 return string.lastIndexOf(target, position) == position;
12262 * Creates a compiled template function that can interpolate data properties
12263 * in "interpolate" delimiters, HTML-escape interpolated data properties in
12264 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
12265 * properties may be accessed as free variables in the template. If a setting
12266 * object is provided it takes precedence over `_.templateSettings` values.
12268 * **Note:** In the development build `_.template` utilizes
12269 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
12270 * for easier debugging.
12272 * For more information on precompiling templates see
12273 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
12275 * For more information on Chrome extension sandboxes see
12276 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
12281 * @param {string} [string=''] The template string.
12282 * @param {Object} [options] The options object.
12283 * @param {RegExp} [options.escape] The HTML "escape" delimiter.
12284 * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
12285 * @param {Object} [options.imports] An object to import into the template as free variables.
12286 * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
12287 * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
12288 * @param {string} [options.variable] The data object variable name.
12289 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12290 * @returns {Function} Returns the compiled template function.
12293 * // using the "interpolate" delimiter to create a compiled template
12294 * var compiled = _.template('hello <%= user %>!');
12295 * compiled({ 'user': 'fred' });
12296 * // => 'hello fred!'
12298 * // using the HTML "escape" delimiter to escape data property values
12299 * var compiled = _.template('<b><%- value %></b>');
12300 * compiled({ 'value': '<script>' });
12301 * // => '<b><script></b>'
12303 * // using the "evaluate" delimiter to execute JavaScript and generate HTML
12304 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
12305 * compiled({ 'users': ['fred', 'barney'] });
12306 * // => '<li>fred</li><li>barney</li>'
12308 * // using the internal `print` function in "evaluate" delimiters
12309 * var compiled = _.template('<% print("hello " + user); %>!');
12310 * compiled({ 'user': 'barney' });
12311 * // => 'hello barney!'
12313 * // using the ES delimiter as an alternative to the default "interpolate" delimiter
12314 * var compiled = _.template('hello ${ user }!');
12315 * compiled({ 'user': 'pebbles' });
12316 * // => 'hello pebbles!'
12318 * // using custom template delimiters
12319 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
12320 * var compiled = _.template('hello {{ user }}!');
12321 * compiled({ 'user': 'mustache' });
12322 * // => 'hello mustache!'
12324 * // using backslashes to treat delimiters as plain text
12325 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
12326 * compiled({ 'value': 'ignored' });
12327 * // => '<%- value %>'
12329 * // using the `imports` option to import `jQuery` as `jq`
12330 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
12331 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
12332 * compiled({ 'users': ['fred', 'barney'] });
12333 * // => '<li>fred</li><li>barney</li>'
12335 * // using the `sourceURL` option to specify a custom sourceURL for the template
12336 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
12338 * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
12340 * // using the `variable` option to ensure a with-statement isn't used in the compiled template
12341 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
12343 * // => function(data) {
12344 * // var __t, __p = '';
12345 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
12349 * // using the `source` property to inline compiled templates for meaningful
12350 * // line numbers in error messages and a stack trace
12351 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
12353 * "main": ' + _.template(mainText).source + '\
12357 function template(string, options, guard) {
12358 // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
12359 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
12360 var settings = lodash.templateSettings;
12362 if (guard && isIterateeCall(string, options, guard)) {
12363 options = undefined;
12365 string = toString(string);
12366 options = assignInWith({}, options, settings, assignInDefaults);
12368 var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
12369 importsKeys = keys(imports),
12370 importsValues = baseValues(imports, importsKeys);
12375 interpolate = options.interpolate || reNoMatch,
12376 source = "__p += '";
12378 // Compile the regexp to match each delimiter.
12379 var reDelimiters = RegExp(
12380 (options.escape || reNoMatch).source + '|' +
12381 interpolate.source + '|' +
12382 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
12383 (options.evaluate || reNoMatch).source + '|$'
12386 // Use a sourceURL for easier debugging.
12387 var sourceURL = '//# sourceURL=' +
12388 ('sourceURL' in options
12389 ? options.sourceURL
12390 : ('lodash.templateSources[' + (++templateCounter) + ']')
12393 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
12394 interpolateValue || (interpolateValue = esTemplateValue);
12396 // Escape characters that can't be included in string literals.
12397 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
12399 // Replace delimiters with snippets.
12402 source += "' +\n__e(" + escapeValue + ") +\n'";
12404 if (evaluateValue) {
12405 isEvaluating = true;
12406 source += "';\n" + evaluateValue + ";\n__p += '";
12408 if (interpolateValue) {
12409 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
12411 index = offset + match.length;
12413 // The JS engine embedded in Adobe products needs `match` returned in
12414 // order to produce the correct `offset` value.
12420 // If `variable` is not specified wrap a with-statement around the generated
12421 // code to add the data object to the top of the scope chain.
12422 var variable = options.variable;
12424 source = 'with (obj) {\n' + source + '\n}\n';
12426 // Cleanup code by stripping empty strings.
12427 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
12428 .replace(reEmptyStringMiddle, '$1')
12429 .replace(reEmptyStringTrailing, '$1;');
12431 // Frame code as the function body.
12432 source = 'function(' + (variable || 'obj') + ') {\n' +
12435 : 'obj || (obj = {});\n'
12437 "var __t, __p = ''" +
12439 ? ', __e = _.escape'
12443 ? ', __j = Array.prototype.join;\n' +
12444 "function print() { __p += __j.call(arguments, '') }\n"
12450 var result = attempt(function() {
12451 return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
12454 // Provide the compiled function's source by its `toString` method or
12455 // the `source` property as a convenience for inlining compiled templates.
12456 result.source = source;
12457 if (isError(result)) {
12464 * Converts `string`, as a whole, to lower case.
12469 * @param {string} [string=''] The string to convert.
12470 * @returns {string} Returns the lower cased string.
12473 * _.toLower('--Foo-Bar');
12474 * // => '--foo-bar'
12476 * _.toLower('fooBar');
12479 * _.toLower('__FOO_BAR__');
12480 * // => '__foo_bar__'
12482 function toLower(value) {
12483 return toString(value).toLowerCase();
12487 * Converts `string`, as a whole, to upper case.
12492 * @param {string} [string=''] The string to convert.
12493 * @returns {string} Returns the upper cased string.
12496 * _.toUpper('--foo-bar');
12497 * // => '--FOO-BAR'
12499 * _.toUpper('fooBar');
12502 * _.toUpper('__foo_bar__');
12503 * // => '__FOO_BAR__'
12505 function toUpper(value) {
12506 return toString(value).toUpperCase();
12510 * Removes leading and trailing whitespace or specified characters from `string`.
12515 * @param {string} [string=''] The string to trim.
12516 * @param {string} [chars=whitespace] The characters to trim.
12517 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12518 * @returns {string} Returns the trimmed string.
12524 * _.trim('-_-abc-_-', '_-');
12527 * _.map([' foo ', ' bar '], _.trim);
12528 * // => ['foo', 'bar']
12530 function trim(string, chars, guard) {
12531 string = toString(string);
12535 if (guard || chars === undefined) {
12536 return string.replace(reTrim, '');
12538 chars = (chars + '');
12542 var strSymbols = stringToArray(string),
12543 chrSymbols = stringToArray(chars);
12545 return strSymbols.slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1).join('');
12549 * Removes trailing whitespace or specified characters from `string`.
12554 * @param {string} [string=''] The string to trim.
12555 * @param {string} [chars=whitespace] The characters to trim.
12556 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12557 * @returns {string} Returns the trimmed string.
12560 * _.trimEnd(' abc ');
12563 * _.trimEnd('-_-abc-_-', '_-');
12566 function trimEnd(string, chars, guard) {
12567 string = toString(string);
12571 if (guard || chars === undefined) {
12572 return string.replace(reTrimEnd, '');
12574 chars = (chars + '');
12578 var strSymbols = stringToArray(string);
12579 return strSymbols.slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1).join('');
12583 * Removes leading whitespace or specified characters from `string`.
12588 * @param {string} [string=''] The string to trim.
12589 * @param {string} [chars=whitespace] The characters to trim.
12590 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12591 * @returns {string} Returns the trimmed string.
12594 * _.trimStart(' abc ');
12597 * _.trimStart('-_-abc-_-', '_-');
12600 function trimStart(string, chars, guard) {
12601 string = toString(string);
12605 if (guard || chars === undefined) {
12606 return string.replace(reTrimStart, '');
12608 chars = (chars + '');
12612 var strSymbols = stringToArray(string);
12613 return strSymbols.slice(charsStartIndex(strSymbols, stringToArray(chars))).join('');
12617 * Truncates `string` if it's longer than the given maximum string length.
12618 * The last characters of the truncated string are replaced with the omission
12619 * string which defaults to "...".
12624 * @param {string} [string=''] The string to truncate.
12625 * @param {Object} [options] The options object.
12626 * @param {number} [options.length=30] The maximum string length.
12627 * @param {string} [options.omission='...'] The string to indicate text is omitted.
12628 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
12629 * @returns {string} Returns the truncated string.
12632 * _.truncate('hi-diddly-ho there, neighborino');
12633 * // => 'hi-diddly-ho there, neighbo...'
12635 * _.truncate('hi-diddly-ho there, neighborino', {
12639 * // => 'hi-diddly-ho there,...'
12641 * _.truncate('hi-diddly-ho there, neighborino', {
12643 * 'separator': /,? +/
12645 * // => 'hi-diddly-ho there...'
12647 * _.truncate('hi-diddly-ho there, neighborino', {
12648 * 'omission': ' [...]'
12650 * // => 'hi-diddly-ho there, neig [...]'
12652 function truncate(string, options) {
12653 var length = DEFAULT_TRUNC_LENGTH,
12654 omission = DEFAULT_TRUNC_OMISSION;
12656 if (isObject(options)) {
12657 var separator = 'separator' in options ? options.separator : separator;
12658 length = 'length' in options ? toInteger(options.length) : length;
12659 omission = 'omission' in options ? toString(options.omission) : omission;
12661 string = toString(string);
12663 var strLength = string.length;
12664 if (reHasComplexSymbol.test(string)) {
12665 var strSymbols = stringToArray(string);
12666 strLength = strSymbols.length;
12668 if (length >= strLength) {
12671 var end = length - stringSize(omission);
12675 var result = strSymbols
12676 ? strSymbols.slice(0, end).join('')
12677 : string.slice(0, end);
12679 if (separator === undefined) {
12680 return result + omission;
12683 end += (result.length - end);
12685 if (isRegExp(separator)) {
12686 if (string.slice(end).search(separator)) {
12688 substring = result;
12690 if (!separator.global) {
12691 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
12693 separator.lastIndex = 0;
12694 while ((match = separator.exec(substring))) {
12695 var newEnd = match.index;
12697 result = result.slice(0, newEnd === undefined ? end : newEnd);
12699 } else if (string.indexOf(separator, end) != end) {
12700 var index = result.lastIndexOf(separator);
12702 result = result.slice(0, index);
12705 return result + omission;
12709 * The inverse of `_.escape`; this method converts the HTML entities
12710 * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
12711 * corresponding characters.
12713 * **Note:** No other HTML entities are unescaped. To unescape additional HTML
12714 * entities use a third-party library like [_he_](https://mths.be/he).
12719 * @param {string} [string=''] The string to unescape.
12720 * @returns {string} Returns the unescaped string.
12723 * _.unescape('fred, barney, & pebbles');
12724 * // => 'fred, barney, & pebbles'
12726 function unescape(string) {
12727 string = toString(string);
12728 return (string && reHasEscapedHtml.test(string))
12729 ? string.replace(reEscapedHtml, unescapeHtmlChar)
12734 * Converts `string`, as space separated words, to upper case.
12739 * @param {string} [string=''] The string to convert.
12740 * @returns {string} Returns the upper cased string.
12743 * _.upperCase('--foo-bar');
12746 * _.upperCase('fooBar');
12749 * _.upperCase('__foo_bar__');
12752 var upperCase = createCompounder(function(result, word, index) {
12753 return result + (index ? ' ' : '') + word.toUpperCase();
12757 * Splits `string` into an array of its words.
12762 * @param {string} [string=''] The string to inspect.
12763 * @param {RegExp|string} [pattern] The pattern to match words.
12764 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12765 * @returns {Array} Returns the words of `string`.
12768 * _.words('fred, barney, & pebbles');
12769 * // => ['fred', 'barney', 'pebbles']
12771 * _.words('fred, barney, & pebbles', /[^, ]+/g);
12772 * // => ['fred', 'barney', '&', 'pebbles']
12774 function words(string, pattern, guard) {
12775 string = toString(string);
12776 pattern = guard ? undefined : pattern;
12778 if (pattern === undefined) {
12779 pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
12781 return string.match(pattern) || [];
12784 /*------------------------------------------------------------------------*/
12787 * Attempts to invoke `func`, returning either the result or the caught error
12788 * object. Any additional arguments are provided to `func` when it's invoked.
12793 * @param {Function} func The function to attempt.
12794 * @returns {*} Returns the `func` result or error object.
12797 * // avoid throwing errors for invalid selectors
12798 * var elements = _.attempt(function(selector) {
12799 * return document.querySelectorAll(selector);
12802 * if (_.isError(elements)) {
12806 var attempt = rest(function(func, args) {
12808 return apply(func, undefined, args);
12810 return isError(e) ? e : new Error(e);
12815 * Binds methods of an object to the object itself, overwriting the existing
12818 * **Note:** This method doesn't set the "length" property of bound functions.
12823 * @param {Object} object The object to bind and assign the bound methods to.
12824 * @param {...(string|string[])} methodNames The object method names to bind,
12825 * specified individually or in arrays.
12826 * @returns {Object} Returns `object`.
12831 * 'onClick': function() {
12832 * console.log('clicked ' + this.label);
12836 * _.bindAll(view, 'onClick');
12837 * jQuery(element).on('click', view.onClick);
12838 * // => logs 'clicked docs' when clicked
12840 var bindAll = rest(function(object, methodNames) {
12841 arrayEach(baseFlatten(methodNames), function(key) {
12842 object[key] = bind(object[key], object);
12848 * Creates a function that iterates over `pairs` invoking the corresponding
12849 * function of the first predicate to return truthy. The predicate-function
12850 * pairs are invoked with the `this` binding and arguments of the created
12856 * @param {Array} pairs The predicate-function pairs.
12857 * @returns {Function} Returns the new function.
12860 * var func = _.cond([
12861 * [_.matches({ 'a': 1 }), _.constant('matches A')],
12862 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
12863 * [_.constant(true), _.constant('no match')]
12866 * func({ 'a': 1, 'b': 2 });
12867 * // => 'matches A'
12869 * func({ 'a': 0, 'b': 1 });
12870 * // => 'matches B'
12872 * func({ 'a': '1', 'b': '2' });
12875 function cond(pairs) {
12876 var length = pairs ? pairs.length : 0,
12877 toIteratee = getIteratee();
12879 pairs = !length ? [] : arrayMap(pairs, function(pair) {
12880 if (typeof pair[1] != 'function') {
12881 throw new TypeError(FUNC_ERROR_TEXT);
12883 return [toIteratee(pair[0]), pair[1]];
12886 return rest(function(args) {
12888 while (++index < length) {
12889 var pair = pairs[index];
12890 if (apply(pair[0], this, args)) {
12891 return apply(pair[1], this, args);
12898 * Creates a function that invokes the predicate properties of `source` with
12899 * the corresponding property values of a given object, returning `true` if
12900 * all predicates return truthy, else `false`.
12905 * @param {Object} source The object of property predicates to conform to.
12906 * @returns {Function} Returns the new function.
12910 * { 'user': 'barney', 'age': 36 },
12911 * { 'user': 'fred', 'age': 40 }
12914 * _.filter(users, _.conforms({ 'age': _.partial(_.gt, _, 38) }));
12915 * // => [{ 'user': 'fred', 'age': 40 }]
12917 function conforms(source) {
12918 return baseConforms(baseClone(source, true));
12922 * Creates a function that returns `value`.
12927 * @param {*} value The value to return from the new function.
12928 * @returns {Function} Returns the new function.
12931 * var object = { 'user': 'fred' };
12932 * var getter = _.constant(object);
12934 * getter() === object;
12937 function constant(value) {
12938 return function() {
12944 * Creates a function that returns the result of invoking the provided
12945 * functions with the `this` binding of the created function, where each
12946 * successive invocation is supplied the return value of the previous.
12951 * @param {...(Function|Function[])} [funcs] Functions to invoke.
12952 * @returns {Function} Returns the new function.
12955 * function square(n) {
12959 * var addSquare = _.flow(_.add, square);
12963 var flow = createFlow();
12966 * This method is like `_.flow` except that it creates a function that
12967 * invokes the provided functions from right to left.
12972 * @param {...(Function|Function[])} [funcs] Functions to invoke.
12973 * @returns {Function} Returns the new function.
12976 * function square(n) {
12980 * var addSquare = _.flowRight(square, _.add);
12984 var flowRight = createFlow(true);
12987 * This method returns the first argument provided to it.
12992 * @param {*} value Any value.
12993 * @returns {*} Returns `value`.
12996 * var object = { 'user': 'fred' };
12998 * _.identity(object) === object;
13001 function identity(value) {
13006 * Creates a function that invokes `func` with the arguments of the created
13007 * function. If `func` is a property name the created callback returns the
13008 * property value for a given element. If `func` is an object the created
13009 * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`.
13014 * @param {*} [func=_.identity] The value to convert to a callback.
13015 * @returns {Function} Returns the callback.
13019 * { 'user': 'barney', 'age': 36 },
13020 * { 'user': 'fred', 'age': 40 }
13023 * // create custom iteratee shorthands
13024 * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
13025 * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
13026 * return !p ? callback(func) : function(object) {
13027 * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
13031 * _.filter(users, 'age > 36');
13032 * // => [{ 'user': 'fred', 'age': 40 }]
13034 function iteratee(func) {
13035 return (isObjectLike(func) && !isArray(func))
13037 : baseIteratee(func);
13041 * Creates a function that performs a deep partial comparison between a given
13042 * object and `source`, returning `true` if the given object has equivalent
13043 * property values, else `false`.
13045 * **Note:** This method supports comparing the same values as `_.isEqual`.
13050 * @param {Object} source The object of property values to match.
13051 * @returns {Function} Returns the new function.
13055 * { 'user': 'barney', 'age': 36, 'active': true },
13056 * { 'user': 'fred', 'age': 40, 'active': false }
13059 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
13060 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
13062 function matches(source) {
13063 return baseMatches(baseClone(source, true));
13067 * Creates a function that performs a deep partial comparison between the
13068 * value at `path` of a given object to `srcValue`, returning `true` if the
13069 * object value is equivalent, else `false`.
13071 * **Note:** This method supports comparing the same values as `_.isEqual`.
13076 * @param {Array|string} path The path of the property to get.
13077 * @param {*} srcValue The value to match.
13078 * @returns {Function} Returns the new function.
13082 * { 'user': 'barney' },
13083 * { 'user': 'fred' }
13086 * _.find(users, _.matchesProperty('user', 'fred'));
13087 * // => { 'user': 'fred' }
13089 function matchesProperty(path, srcValue) {
13090 return baseMatchesProperty(path, baseClone(srcValue, true));
13094 * Creates a function that invokes the method at `path` of a given object.
13095 * Any additional arguments are provided to the invoked method.
13100 * @param {Array|string} path The path of the method to invoke.
13101 * @param {...*} [args] The arguments to invoke the method with.
13102 * @returns {Function} Returns the new function.
13106 * { 'a': { 'b': { 'c': _.constant(2) } } },
13107 * { 'a': { 'b': { 'c': _.constant(1) } } }
13110 * _.map(objects, _.method('a.b.c'));
13113 * _.invokeMap(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
13116 var method = rest(function(path, args) {
13117 return function(object) {
13118 return baseInvoke(object, path, args);
13123 * The opposite of `_.method`; this method creates a function that invokes
13124 * the method at a given path of `object`. Any additional arguments are
13125 * provided to the invoked method.
13130 * @param {Object} object The object to query.
13131 * @param {...*} [args] The arguments to invoke the method with.
13132 * @returns {Function} Returns the new function.
13135 * var array = _.times(3, _.constant),
13136 * object = { 'a': array, 'b': array, 'c': array };
13138 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
13141 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
13144 var methodOf = rest(function(object, args) {
13145 return function(path) {
13146 return baseInvoke(object, path, args);
13151 * Adds all own enumerable function properties of a source object to the
13152 * destination object. If `object` is a function then methods are added to
13153 * its prototype as well.
13155 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
13156 * avoid conflicts caused by modifying the original.
13161 * @param {Function|Object} [object=lodash] The destination object.
13162 * @param {Object} source The object of functions to add.
13163 * @param {Object} [options] The options object.
13164 * @param {boolean} [options.chain=true] Specify whether the functions added
13166 * @returns {Function|Object} Returns `object`.
13169 * function vowels(string) {
13170 * return _.filter(string, function(v) {
13171 * return /[aeiou]/i.test(v);
13175 * _.mixin({ 'vowels': vowels });
13176 * _.vowels('fred');
13179 * _('fred').vowels().value();
13182 * _.mixin({ 'vowels': vowels }, { 'chain': false });
13183 * _('fred').vowels();
13186 function mixin(object, source, options) {
13187 var props = keys(source),
13188 methodNames = baseFunctions(source, props);
13190 if (options == null &&
13191 !(isObject(source) && (methodNames.length || !props.length))) {
13195 methodNames = baseFunctions(source, keys(source));
13197 var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
13198 isFunc = isFunction(object);
13200 arrayEach(methodNames, function(methodName) {
13201 var func = source[methodName];
13202 object[methodName] = func;
13204 object.prototype[methodName] = function() {
13205 var chainAll = this.__chain__;
13206 if (chain || chainAll) {
13207 var result = object(this.__wrapped__),
13208 actions = result.__actions__ = copyArray(this.__actions__);
13210 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
13211 result.__chain__ = chainAll;
13214 return func.apply(object, arrayPush([this.value()], arguments));
13223 * Reverts the `_` variable to its previous value and returns a reference to
13224 * the `lodash` function.
13229 * @returns {Function} Returns the `lodash` function.
13232 * var lodash = _.noConflict();
13234 function noConflict() {
13235 if (root._ === this) {
13242 * A no-operation function that returns `undefined` regardless of the
13243 * arguments it receives.
13250 * var object = { 'user': 'fred' };
13252 * _.noop(object) === undefined;
13256 // No operation performed.
13260 * Creates a function that returns its nth argument.
13265 * @param {number} [n=0] The index of the argument to return.
13266 * @returns {Function} Returns the new function.
13269 * var func = _.nthArg(1);
13271 * func('a', 'b', 'c');
13274 function nthArg(n) {
13276 return function() {
13277 return arguments[n];
13282 * Creates a function that invokes `iteratees` with the arguments provided
13283 * to the created function and returns their results.
13288 * @param {...(Function|Function[])} iteratees The iteratees to invoke.
13289 * @returns {Function} Returns the new function.
13292 * var func = _.over(Math.max, Math.min);
13294 * func(1, 2, 3, 4);
13297 var over = createOver(arrayMap);
13300 * Creates a function that checks if **all** of the `predicates` return
13301 * truthy when invoked with the arguments provided to the created function.
13306 * @param {...(Function|Function[])} predicates The predicates to check.
13307 * @returns {Function} Returns the new function.
13310 * var func = _.overEvery(Boolean, isFinite);
13321 var overEvery = createOver(arrayEvery);
13324 * Creates a function that checks if **any** of the `predicates` return
13325 * truthy when invoked with the arguments provided to the created function.
13330 * @param {...(Function|Function[])} predicates The predicates to check.
13331 * @returns {Function} Returns the new function.
13334 * var func = _.overSome(Boolean, isFinite);
13345 var overSome = createOver(arraySome);
13348 * Creates a function that returns the value at `path` of a given object.
13353 * @param {Array|string} path The path of the property to get.
13354 * @returns {Function} Returns the new function.
13358 * { 'a': { 'b': { 'c': 2 } } },
13359 * { 'a': { 'b': { 'c': 1 } } }
13362 * _.map(objects, _.property('a.b.c'));
13365 * _.map(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
13368 function property(path) {
13369 return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
13373 * The opposite of `_.property`; this method creates a function that returns
13374 * the value at a given path of `object`.
13379 * @param {Object} object The object to query.
13380 * @returns {Function} Returns the new function.
13383 * var array = [0, 1, 2],
13384 * object = { 'a': array, 'b': array, 'c': array };
13386 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
13389 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
13392 function propertyOf(object) {
13393 return function(path) {
13394 return object == null ? undefined : baseGet(object, path);
13399 * Creates an array of numbers (positive and/or negative) progressing from
13400 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
13401 * `start` is specified without an `end` or `step`. If `end` is not specified
13402 * it's set to `start` with `start` then set to `0`.
13404 * **Note:** JavaScript follows the IEEE-754 standard for resolving
13405 * floating-point values which can produce unexpected results.
13410 * @param {number} [start=0] The start of the range.
13411 * @param {number} end The end of the range.
13412 * @param {number} [step=1] The value to increment or decrement by.
13413 * @returns {Array} Returns the new array of numbers.
13417 * // => [0, 1, 2, 3]
13420 * // => [0, -1, -2, -3]
13423 * // => [1, 2, 3, 4]
13425 * _.range(0, 20, 5);
13426 * // => [0, 5, 10, 15]
13428 * _.range(0, -4, -1);
13429 * // => [0, -1, -2, -3]
13431 * _.range(1, 4, 0);
13437 var range = createRange();
13440 * This method is like `_.range` except that it populates values in
13441 * descending order.
13446 * @param {number} [start=0] The start of the range.
13447 * @param {number} end The end of the range.
13448 * @param {number} [step=1] The value to increment or decrement by.
13449 * @returns {Array} Returns the new array of numbers.
13453 * // => [3, 2, 1, 0]
13455 * _.rangeRight(-4);
13456 * // => [-3, -2, -1, 0]
13458 * _.rangeRight(1, 5);
13459 * // => [4, 3, 2, 1]
13461 * _.rangeRight(0, 20, 5);
13462 * // => [15, 10, 5, 0]
13464 * _.rangeRight(0, -4, -1);
13465 * // => [-3, -2, -1, 0]
13467 * _.rangeRight(1, 4, 0);
13473 var rangeRight = createRange(true);
13476 * Invokes the iteratee function `n` times, returning an array of the results
13477 * of each invocation. The iteratee is invoked with one argument; (index).
13482 * @param {number} n The number of times to invoke `iteratee`.
13483 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13484 * @returns {Array} Returns the array of results.
13487 * _.times(3, String);
13488 * // => ['0', '1', '2']
13490 * _.times(4, _.constant(true));
13491 * // => [true, true, true, true]
13493 function times(n, iteratee) {
13495 if (n < 1 || n > MAX_SAFE_INTEGER) {
13498 var index = MAX_ARRAY_LENGTH,
13499 length = nativeMin(n, MAX_ARRAY_LENGTH);
13501 iteratee = toFunction(iteratee);
13502 n -= MAX_ARRAY_LENGTH;
13504 var result = baseTimes(length, iteratee);
13505 while (++index < n) {
13512 * Converts `value` to a property path array.
13517 * @param {*} value The value to convert.
13518 * @returns {Array} Returns the new property path array.
13521 * _.toPath('a.b.c');
13522 * // => ['a', 'b', 'c']
13524 * _.toPath('a[0].b.c');
13525 * // => ['a', '0', 'b', 'c']
13527 * var path = ['a', 'b', 'c'],
13528 * newPath = _.toPath(path);
13530 * console.log(newPath);
13531 * // => ['a', 'b', 'c']
13533 * console.log(path === newPath);
13536 function toPath(value) {
13537 return isArray(value) ? arrayMap(value, String) : stringToPath(value);
13541 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
13546 * @param {string} [prefix] The value to prefix the ID with.
13547 * @returns {string} Returns the unique ID.
13550 * _.uniqueId('contact_');
13551 * // => 'contact_104'
13556 function uniqueId(prefix) {
13557 var id = ++idCounter;
13558 return toString(prefix) + id;
13561 /*------------------------------------------------------------------------*/
13564 * Adds two numbers.
13569 * @param {number} augend The first number in an addition.
13570 * @param {number} addend The second number in an addition.
13571 * @returns {number} Returns the total.
13577 function add(augend, addend) {
13579 if (augend !== undefined) {
13582 if (addend !== undefined) {
13583 result = result === undefined ? addend : (result + addend);
13589 * Computes `number` rounded up to `precision`.
13594 * @param {number} number The number to round up.
13595 * @param {number} [precision=0] The precision to round up to.
13596 * @returns {number} Returns the rounded up number.
13602 * _.ceil(6.004, 2);
13605 * _.ceil(6040, -2);
13608 var ceil = createRound('ceil');
13611 * Computes `number` rounded down to `precision`.
13616 * @param {number} number The number to round down.
13617 * @param {number} [precision=0] The precision to round down to.
13618 * @returns {number} Returns the rounded down number.
13624 * _.floor(0.046, 2);
13627 * _.floor(4060, -2);
13630 var floor = createRound('floor');
13633 * Computes the maximum value of `array`. If `array` is empty or falsey
13634 * `undefined` is returned.
13639 * @param {Array} array The array to iterate over.
13640 * @returns {*} Returns the maximum value.
13643 * _.max([4, 2, 8, 6]);
13649 function max(array) {
13650 return (array && array.length)
13651 ? baseExtremum(array, identity, gt)
13656 * This method is like `_.max` except that it accepts `iteratee` which is
13657 * invoked for each element in `array` to generate the criterion by which
13658 * the value is ranked. The iteratee is invoked with one argument: (value).
13663 * @param {Array} array The array to iterate over.
13664 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
13665 * @returns {*} Returns the maximum value.
13668 * var objects = [{ 'n': 1 }, { 'n': 2 }];
13670 * _.maxBy(objects, function(o) { return o.n; });
13673 * // using the `_.property` iteratee shorthand
13674 * _.maxBy(objects, 'n');
13677 function maxBy(array, iteratee) {
13678 return (array && array.length)
13679 ? baseExtremum(array, getIteratee(iteratee), gt)
13684 * Computes the mean of the values in `array`.
13689 * @param {Array} array The array to iterate over.
13690 * @returns {number} Returns the mean.
13693 * _.mean([4, 2, 8, 6]);
13696 function mean(array) {
13697 return sum(array) / (array ? array.length : 0);
13701 * Computes the minimum value of `array`. If `array` is empty or falsey
13702 * `undefined` is returned.
13707 * @param {Array} array The array to iterate over.
13708 * @returns {*} Returns the minimum value.
13711 * _.min([4, 2, 8, 6]);
13717 function min(array) {
13718 return (array && array.length)
13719 ? baseExtremum(array, identity, lt)
13724 * This method is like `_.min` except that it accepts `iteratee` which is
13725 * invoked for each element in `array` to generate the criterion by which
13726 * the value is ranked. The iteratee is invoked with one argument: (value).
13731 * @param {Array} array The array to iterate over.
13732 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
13733 * @returns {*} Returns the minimum value.
13736 * var objects = [{ 'n': 1 }, { 'n': 2 }];
13738 * _.minBy(objects, function(o) { return o.n; });
13741 * // using the `_.property` iteratee shorthand
13742 * _.minBy(objects, 'n');
13745 function minBy(array, iteratee) {
13746 return (array && array.length)
13747 ? baseExtremum(array, getIteratee(iteratee), lt)
13752 * Computes `number` rounded to `precision`.
13757 * @param {number} number The number to round.
13758 * @param {number} [precision=0] The precision to round to.
13759 * @returns {number} Returns the rounded number.
13765 * _.round(4.006, 2);
13768 * _.round(4060, -2);
13771 var round = createRound('round');
13774 * Subtract two numbers.
13779 * @param {number} minuend The first number in a subtraction.
13780 * @param {number} subtrahend The second number in a subtraction.
13781 * @returns {number} Returns the difference.
13784 * _.subtract(6, 4);
13787 function subtract(minuend, subtrahend) {
13789 if (minuend !== undefined) {
13792 if (subtrahend !== undefined) {
13793 result = result === undefined ? subtrahend : (result - subtrahend);
13799 * Computes the sum of the values in `array`.
13804 * @param {Array} array The array to iterate over.
13805 * @returns {number} Returns the sum.
13808 * _.sum([4, 2, 8, 6]);
13811 function sum(array) {
13812 return (array && array.length)
13813 ? baseSum(array, identity)
13818 * This method is like `_.sum` except that it accepts `iteratee` which is
13819 * invoked for each element in `array` to generate the value to be summed.
13820 * The iteratee is invoked with one argument: (value).
13825 * @param {Array} array The array to iterate over.
13826 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
13827 * @returns {number} Returns the sum.
13830 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
13832 * _.sumBy(objects, function(o) { return o.n; });
13835 * // using the `_.property` iteratee shorthand
13836 * _.sumBy(objects, 'n');
13839 function sumBy(array, iteratee) {
13840 return (array && array.length)
13841 ? baseSum(array, getIteratee(iteratee))
13845 /*------------------------------------------------------------------------*/
13847 // Ensure wrappers are instances of `baseLodash`.
13848 lodash.prototype = baseLodash.prototype;
13850 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
13851 LodashWrapper.prototype.constructor = LodashWrapper;
13853 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
13854 LazyWrapper.prototype.constructor = LazyWrapper;
13856 // Avoid inheriting from `Object.prototype` when possible.
13857 Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
13859 // Add functions to the `MapCache`.
13860 MapCache.prototype.clear = mapClear;
13861 MapCache.prototype['delete'] = mapDelete;
13862 MapCache.prototype.get = mapGet;
13863 MapCache.prototype.has = mapHas;
13864 MapCache.prototype.set = mapSet;
13866 // Add functions to the `SetCache`.
13867 SetCache.prototype.push = cachePush;
13869 // Add functions to the `Stack` cache.
13870 Stack.prototype.clear = stackClear;
13871 Stack.prototype['delete'] = stackDelete;
13872 Stack.prototype.get = stackGet;
13873 Stack.prototype.has = stackHas;
13874 Stack.prototype.set = stackSet;
13876 // Assign cache to `_.memoize`.
13877 memoize.Cache = MapCache;
13879 // Add functions that return wrapped values when chaining.
13880 lodash.after = after;
13882 lodash.assign = assign;
13883 lodash.assignIn = assignIn;
13884 lodash.assignInWith = assignInWith;
13885 lodash.assignWith = assignWith;
13887 lodash.before = before;
13888 lodash.bind = bind;
13889 lodash.bindAll = bindAll;
13890 lodash.bindKey = bindKey;
13891 lodash.chain = chain;
13892 lodash.chunk = chunk;
13893 lodash.compact = compact;
13894 lodash.concat = concat;
13895 lodash.cond = cond;
13896 lodash.conforms = conforms;
13897 lodash.constant = constant;
13898 lodash.countBy = countBy;
13899 lodash.create = create;
13900 lodash.curry = curry;
13901 lodash.curryRight = curryRight;
13902 lodash.debounce = debounce;
13903 lodash.defaults = defaults;
13904 lodash.defaultsDeep = defaultsDeep;
13905 lodash.defer = defer;
13906 lodash.delay = delay;
13907 lodash.difference = difference;
13908 lodash.differenceBy = differenceBy;
13909 lodash.differenceWith = differenceWith;
13910 lodash.drop = drop;
13911 lodash.dropRight = dropRight;
13912 lodash.dropRightWhile = dropRightWhile;
13913 lodash.dropWhile = dropWhile;
13914 lodash.fill = fill;
13915 lodash.filter = filter;
13916 lodash.flatMap = flatMap;
13917 lodash.flatten = flatten;
13918 lodash.flattenDeep = flattenDeep;
13919 lodash.flip = flip;
13920 lodash.flow = flow;
13921 lodash.flowRight = flowRight;
13922 lodash.fromPairs = fromPairs;
13923 lodash.functions = functions;
13924 lodash.functionsIn = functionsIn;
13925 lodash.groupBy = groupBy;
13926 lodash.initial = initial;
13927 lodash.intersection = intersection;
13928 lodash.intersectionBy = intersectionBy;
13929 lodash.intersectionWith = intersectionWith;
13930 lodash.invert = invert;
13931 lodash.invokeMap = invokeMap;
13932 lodash.iteratee = iteratee;
13933 lodash.keyBy = keyBy;
13934 lodash.keys = keys;
13935 lodash.keysIn = keysIn;
13937 lodash.mapKeys = mapKeys;
13938 lodash.mapValues = mapValues;
13939 lodash.matches = matches;
13940 lodash.matchesProperty = matchesProperty;
13941 lodash.memoize = memoize;
13942 lodash.merge = merge;
13943 lodash.mergeWith = mergeWith;
13944 lodash.method = method;
13945 lodash.methodOf = methodOf;
13946 lodash.mixin = mixin;
13947 lodash.negate = negate;
13948 lodash.nthArg = nthArg;
13949 lodash.omit = omit;
13950 lodash.omitBy = omitBy;
13951 lodash.once = once;
13952 lodash.orderBy = orderBy;
13953 lodash.over = over;
13954 lodash.overArgs = overArgs;
13955 lodash.overEvery = overEvery;
13956 lodash.overSome = overSome;
13957 lodash.partial = partial;
13958 lodash.partialRight = partialRight;
13959 lodash.partition = partition;
13960 lodash.pick = pick;
13961 lodash.pickBy = pickBy;
13962 lodash.property = property;
13963 lodash.propertyOf = propertyOf;
13964 lodash.pull = pull;
13965 lodash.pullAll = pullAll;
13966 lodash.pullAllBy = pullAllBy;
13967 lodash.pullAt = pullAt;
13968 lodash.range = range;
13969 lodash.rangeRight = rangeRight;
13970 lodash.rearg = rearg;
13971 lodash.reject = reject;
13972 lodash.remove = remove;
13973 lodash.rest = rest;
13974 lodash.reverse = reverse;
13975 lodash.sampleSize = sampleSize;
13977 lodash.setWith = setWith;
13978 lodash.shuffle = shuffle;
13979 lodash.slice = slice;
13980 lodash.sortBy = sortBy;
13981 lodash.sortedUniq = sortedUniq;
13982 lodash.sortedUniqBy = sortedUniqBy;
13983 lodash.split = split;
13984 lodash.spread = spread;
13985 lodash.tail = tail;
13986 lodash.take = take;
13987 lodash.takeRight = takeRight;
13988 lodash.takeRightWhile = takeRightWhile;
13989 lodash.takeWhile = takeWhile;
13991 lodash.throttle = throttle;
13992 lodash.thru = thru;
13993 lodash.toArray = toArray;
13994 lodash.toPairs = toPairs;
13995 lodash.toPairsIn = toPairsIn;
13996 lodash.toPath = toPath;
13997 lodash.toPlainObject = toPlainObject;
13998 lodash.transform = transform;
13999 lodash.unary = unary;
14000 lodash.union = union;
14001 lodash.unionBy = unionBy;
14002 lodash.unionWith = unionWith;
14003 lodash.uniq = uniq;
14004 lodash.uniqBy = uniqBy;
14005 lodash.uniqWith = uniqWith;
14006 lodash.unset = unset;
14007 lodash.unzip = unzip;
14008 lodash.unzipWith = unzipWith;
14009 lodash.values = values;
14010 lodash.valuesIn = valuesIn;
14011 lodash.without = without;
14012 lodash.words = words;
14013 lodash.wrap = wrap;
14015 lodash.xorBy = xorBy;
14016 lodash.xorWith = xorWith;
14018 lodash.zipObject = zipObject;
14019 lodash.zipWith = zipWith;
14022 lodash.extend = assignIn;
14023 lodash.extendWith = assignInWith;
14025 // Add functions to `lodash.prototype`.
14026 mixin(lodash, lodash);
14028 /*------------------------------------------------------------------------*/
14030 // Add functions that return unwrapped values when chaining.
14032 lodash.attempt = attempt;
14033 lodash.camelCase = camelCase;
14034 lodash.capitalize = capitalize;
14035 lodash.ceil = ceil;
14036 lodash.clamp = clamp;
14037 lodash.clone = clone;
14038 lodash.cloneDeep = cloneDeep;
14039 lodash.cloneDeepWith = cloneDeepWith;
14040 lodash.cloneWith = cloneWith;
14041 lodash.deburr = deburr;
14042 lodash.endsWith = endsWith;
14044 lodash.escape = escape;
14045 lodash.escapeRegExp = escapeRegExp;
14046 lodash.every = every;
14047 lodash.find = find;
14048 lodash.findIndex = findIndex;
14049 lodash.findKey = findKey;
14050 lodash.findLast = findLast;
14051 lodash.findLastIndex = findLastIndex;
14052 lodash.findLastKey = findLastKey;
14053 lodash.floor = floor;
14054 lodash.forEach = forEach;
14055 lodash.forEachRight = forEachRight;
14056 lodash.forIn = forIn;
14057 lodash.forInRight = forInRight;
14058 lodash.forOwn = forOwn;
14059 lodash.forOwnRight = forOwnRight;
14064 lodash.hasIn = hasIn;
14065 lodash.head = head;
14066 lodash.identity = identity;
14067 lodash.includes = includes;
14068 lodash.indexOf = indexOf;
14069 lodash.inRange = inRange;
14070 lodash.invoke = invoke;
14071 lodash.isArguments = isArguments;
14072 lodash.isArray = isArray;
14073 lodash.isArrayLike = isArrayLike;
14074 lodash.isArrayLikeObject = isArrayLikeObject;
14075 lodash.isBoolean = isBoolean;
14076 lodash.isDate = isDate;
14077 lodash.isElement = isElement;
14078 lodash.isEmpty = isEmpty;
14079 lodash.isEqual = isEqual;
14080 lodash.isEqualWith = isEqualWith;
14081 lodash.isError = isError;
14082 lodash.isFinite = isFinite;
14083 lodash.isFunction = isFunction;
14084 lodash.isInteger = isInteger;
14085 lodash.isLength = isLength;
14086 lodash.isMatch = isMatch;
14087 lodash.isMatchWith = isMatchWith;
14088 lodash.isNaN = isNaN;
14089 lodash.isNative = isNative;
14090 lodash.isNil = isNil;
14091 lodash.isNull = isNull;
14092 lodash.isNumber = isNumber;
14093 lodash.isObject = isObject;
14094 lodash.isObjectLike = isObjectLike;
14095 lodash.isPlainObject = isPlainObject;
14096 lodash.isRegExp = isRegExp;
14097 lodash.isSafeInteger = isSafeInteger;
14098 lodash.isString = isString;
14099 lodash.isSymbol = isSymbol;
14100 lodash.isTypedArray = isTypedArray;
14101 lodash.isUndefined = isUndefined;
14102 lodash.join = join;
14103 lodash.kebabCase = kebabCase;
14104 lodash.last = last;
14105 lodash.lastIndexOf = lastIndexOf;
14106 lodash.lowerCase = lowerCase;
14107 lodash.lowerFirst = lowerFirst;
14111 lodash.maxBy = maxBy;
14112 lodash.mean = mean;
14114 lodash.minBy = minBy;
14115 lodash.noConflict = noConflict;
14116 lodash.noop = noop;
14119 lodash.padEnd = padEnd;
14120 lodash.padStart = padStart;
14121 lodash.parseInt = parseInt;
14122 lodash.random = random;
14123 lodash.reduce = reduce;
14124 lodash.reduceRight = reduceRight;
14125 lodash.repeat = repeat;
14126 lodash.replace = replace;
14127 lodash.result = result;
14128 lodash.round = round;
14129 lodash.runInContext = runInContext;
14130 lodash.sample = sample;
14131 lodash.size = size;
14132 lodash.snakeCase = snakeCase;
14133 lodash.some = some;
14134 lodash.sortedIndex = sortedIndex;
14135 lodash.sortedIndexBy = sortedIndexBy;
14136 lodash.sortedIndexOf = sortedIndexOf;
14137 lodash.sortedLastIndex = sortedLastIndex;
14138 lodash.sortedLastIndexBy = sortedLastIndexBy;
14139 lodash.sortedLastIndexOf = sortedLastIndexOf;
14140 lodash.startCase = startCase;
14141 lodash.startsWith = startsWith;
14142 lodash.subtract = subtract;
14144 lodash.sumBy = sumBy;
14145 lodash.template = template;
14146 lodash.times = times;
14147 lodash.toInteger = toInteger;
14148 lodash.toLength = toLength;
14149 lodash.toLower = toLower;
14150 lodash.toNumber = toNumber;
14151 lodash.toSafeInteger = toSafeInteger;
14152 lodash.toString = toString;
14153 lodash.toUpper = toUpper;
14154 lodash.trim = trim;
14155 lodash.trimEnd = trimEnd;
14156 lodash.trimStart = trimStart;
14157 lodash.truncate = truncate;
14158 lodash.unescape = unescape;
14159 lodash.uniqueId = uniqueId;
14160 lodash.upperCase = upperCase;
14161 lodash.upperFirst = upperFirst;
14164 lodash.each = forEach;
14165 lodash.eachRight = forEachRight;
14166 lodash.first = head;
14168 mixin(lodash, (function() {
14170 baseForOwn(lodash, function(func, methodName) {
14171 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
14172 source[methodName] = func;
14176 }()), { 'chain': false });
14178 /*------------------------------------------------------------------------*/
14181 * The semantic version number.
14187 lodash.VERSION = VERSION;
14189 // Assign default placeholders.
14190 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
14191 lodash[methodName].placeholder = lodash;
14194 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
14195 arrayEach(['drop', 'take'], function(methodName, index) {
14196 LazyWrapper.prototype[methodName] = function(n) {
14197 var filtered = this.__filtered__;
14198 if (filtered && !index) {
14199 return new LazyWrapper(this);
14201 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
14203 var result = this.clone();
14205 result.__takeCount__ = nativeMin(n, result.__takeCount__);
14207 result.__views__.push({ 'size': nativeMin(n, MAX_ARRAY_LENGTH), 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
14212 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
14213 return this.reverse()[methodName](n).reverse();
14217 // Add `LazyWrapper` methods that accept an `iteratee` value.
14218 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
14219 var type = index + 1,
14220 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
14222 LazyWrapper.prototype[methodName] = function(iteratee) {
14223 var result = this.clone();
14224 result.__iteratees__.push({ 'iteratee': getIteratee(iteratee, 3), 'type': type });
14225 result.__filtered__ = result.__filtered__ || isFilter;
14230 // Add `LazyWrapper` methods for `_.head` and `_.last`.
14231 arrayEach(['head', 'last'], function(methodName, index) {
14232 var takeName = 'take' + (index ? 'Right' : '');
14234 LazyWrapper.prototype[methodName] = function() {
14235 return this[takeName](1).value()[0];
14239 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
14240 arrayEach(['initial', 'tail'], function(methodName, index) {
14241 var dropName = 'drop' + (index ? '' : 'Right');
14243 LazyWrapper.prototype[methodName] = function() {
14244 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
14248 LazyWrapper.prototype.compact = function() {
14249 return this.filter(identity);
14252 LazyWrapper.prototype.find = function(predicate) {
14253 return this.filter(predicate).head();
14256 LazyWrapper.prototype.findLast = function(predicate) {
14257 return this.reverse().find(predicate);
14260 LazyWrapper.prototype.invokeMap = rest(function(path, args) {
14261 if (typeof path == 'function') {
14262 return new LazyWrapper(this);
14264 return this.map(function(value) {
14265 return baseInvoke(value, path, args);
14269 LazyWrapper.prototype.reject = function(predicate) {
14270 predicate = getIteratee(predicate, 3);
14271 return this.filter(function(value) {
14272 return !predicate(value);
14276 LazyWrapper.prototype.slice = function(start, end) {
14277 start = toInteger(start);
14280 if (result.__filtered__ && (start > 0 || end < 0)) {
14281 return new LazyWrapper(result);
14284 result = result.takeRight(-start);
14285 } else if (start) {
14286 result = result.drop(start);
14288 if (end !== undefined) {
14289 end = toInteger(end);
14290 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
14295 LazyWrapper.prototype.takeRightWhile = function(predicate) {
14296 return this.reverse().takeWhile(predicate).reverse();
14299 LazyWrapper.prototype.toArray = function() {
14300 return this.take(MAX_ARRAY_LENGTH);
14303 // Add `LazyWrapper` methods to `lodash.prototype`.
14304 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
14305 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
14306 isTaker = /^(?:head|last)$/.test(methodName),
14307 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
14308 retUnwrapped = isTaker || /^find/.test(methodName);
14313 lodash.prototype[methodName] = function() {
14314 var value = this.__wrapped__,
14315 args = isTaker ? [1] : arguments,
14316 isLazy = value instanceof LazyWrapper,
14317 iteratee = args[0],
14318 useLazy = isLazy || isArray(value);
14320 var interceptor = function(value) {
14321 var result = lodashFunc.apply(lodash, arrayPush([value], args));
14322 return (isTaker && chainAll) ? result[0] : result;
14325 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
14326 // Avoid lazy use if the iteratee has a "length" value other than `1`.
14327 isLazy = useLazy = false;
14329 var chainAll = this.__chain__,
14330 isHybrid = !!this.__actions__.length,
14331 isUnwrapped = retUnwrapped && !chainAll,
14332 onlyLazy = isLazy && !isHybrid;
14334 if (!retUnwrapped && useLazy) {
14335 value = onlyLazy ? value : new LazyWrapper(this);
14336 var result = func.apply(value, args);
14337 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
14338 return new LodashWrapper(result, chainAll);
14340 if (isUnwrapped && onlyLazy) {
14341 return func.apply(this, args);
14343 result = this.thru(interceptor);
14344 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
14348 // Add `Array` and `String` methods to `lodash.prototype`.
14349 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
14350 var func = arrayProto[methodName],
14351 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
14352 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
14354 lodash.prototype[methodName] = function() {
14355 var args = arguments;
14356 if (retUnwrapped && !this.__chain__) {
14357 return func.apply(this.value(), args);
14359 return this[chainName](function(value) {
14360 return func.apply(value, args);
14365 // Map minified function names to their real names.
14366 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
14367 var lodashFunc = lodash[methodName];
14369 var key = (lodashFunc.name + ''),
14370 names = realNames[key] || (realNames[key] = []);
14372 names.push({ 'name': methodName, 'func': lodashFunc });
14376 realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
14378 // Add functions to the lazy wrapper.
14379 LazyWrapper.prototype.clone = lazyClone;
14380 LazyWrapper.prototype.reverse = lazyReverse;
14381 LazyWrapper.prototype.value = lazyValue;
14383 // Add chaining functions to the `lodash` wrapper.
14384 lodash.prototype.at = wrapperAt;
14385 lodash.prototype.chain = wrapperChain;
14386 lodash.prototype.commit = wrapperCommit;
14387 lodash.prototype.flatMap = wrapperFlatMap;
14388 lodash.prototype.next = wrapperNext;
14389 lodash.prototype.plant = wrapperPlant;
14390 lodash.prototype.reverse = wrapperReverse;
14391 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
14393 if (iteratorSymbol) {
14394 lodash.prototype[iteratorSymbol] = wrapperToIterator;
14399 /*--------------------------------------------------------------------------*/
14402 var _ = runInContext();
14404 // Expose lodash on the free variable `window` or `self` when available. This
14405 // prevents errors in cases where lodash is loaded by a script tag in the presence
14406 // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
14407 (freeWindow || freeSelf || {})._ = _;
14409 // Some AMD build optimizers like r.js check for condition patterns like the following:
14410 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
14411 // Define as an anonymous module so, through path mapping, it can be
14412 // referenced as the "underscore" module.
14413 define(function() {
14417 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
14418 else if (freeExports && freeModule) {
14419 // Export for Node.js.
14420 if (moduleExports) {
14421 (freeModule.exports = _)._ = _;
14423 // Export for CommonJS support.
14427 // Export to the global object.