3 * lodash 4.3.0 (Custom Build) <https://lodash.com/>
4 * Build: `lodash -d -o ./foo/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.3.0';
18 /** Used to compose bitmasks for wrapper metadata. */
23 CURRY_RIGHT_FLAG = 16,
25 PARTIAL_RIGHT_FLAG = 64,
30 /** Used to compose bitmasks for comparison styles. */
31 var UNORDERED_COMPARE_FLAG = 1,
32 PARTIAL_COMPARE_FLAG = 2;
34 /** Used as default options for `_.truncate`. */
35 var DEFAULT_TRUNC_LENGTH = 30,
36 DEFAULT_TRUNC_OMISSION = '...';
38 /** Used to detect hot functions by number of calls within a span of milliseconds. */
42 /** Used as the size to enable large array optimizations. */
43 var LARGE_ARRAY_SIZE = 200;
45 /** Used to indicate the type of lazy iteratees. */
46 var LAZY_FILTER_FLAG = 1,
50 /** Used as the `TypeError` message for "Functions" methods. */
51 var FUNC_ERROR_TEXT = 'Expected a function';
53 /** Used to stand-in for `undefined` hash values. */
54 var HASH_UNDEFINED = '__lodash_hash_undefined__';
56 /** Used as references for various `Number` constants. */
58 MAX_SAFE_INTEGER = 9007199254740991,
59 MAX_INTEGER = 1.7976931348623157e+308,
62 /** Used as references for the maximum length and index of an array. */
63 var MAX_ARRAY_LENGTH = 4294967295,
64 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
65 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
67 /** Used as the internal argument placeholder. */
68 var PLACEHOLDER = '__lodash_placeholder__';
70 /** `Object#toString` result references. */
71 var argsTag = '[object Arguments]',
72 arrayTag = '[object Array]',
73 boolTag = '[object Boolean]',
74 dateTag = '[object Date]',
75 errorTag = '[object Error]',
76 funcTag = '[object Function]',
77 genTag = '[object GeneratorFunction]',
78 mapTag = '[object Map]',
79 numberTag = '[object Number]',
80 objectTag = '[object Object]',
81 regexpTag = '[object RegExp]',
82 setTag = '[object Set]',
83 stringTag = '[object String]',
84 symbolTag = '[object Symbol]',
85 weakMapTag = '[object WeakMap]',
86 weakSetTag = '[object WeakSet]';
88 var arrayBufferTag = '[object ArrayBuffer]',
89 float32Tag = '[object Float32Array]',
90 float64Tag = '[object Float64Array]',
91 int8Tag = '[object Int8Array]',
92 int16Tag = '[object Int16Array]',
93 int32Tag = '[object Int32Array]',
94 uint8Tag = '[object Uint8Array]',
95 uint8ClampedTag = '[object Uint8ClampedArray]',
96 uint16Tag = '[object Uint16Array]',
97 uint32Tag = '[object Uint32Array]';
99 /** Used to match empty string literals in compiled template source. */
100 var reEmptyStringLeading = /\b__p \+= '';/g,
101 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
102 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
104 /** Used to match HTML entities and HTML characters. */
105 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
106 reUnescapedHtml = /[&<>"'`]/g,
107 reHasEscapedHtml = RegExp(reEscapedHtml.source),
108 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
110 /** Used to match template delimiters. */
111 var reEscape = /<%-([\s\S]+?)%>/g,
112 reEvaluate = /<%([\s\S]+?)%>/g,
113 reInterpolate = /<%=([\s\S]+?)%>/g;
115 /** Used to match property names within property paths. */
116 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
117 reIsPlainProp = /^\w*$/,
118 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
120 /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */
121 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
122 reHasRegExpChar = RegExp(reRegExpChar.source);
124 /** Used to match leading and trailing whitespace. */
125 var reTrim = /^\s+|\s+$/g,
126 reTrimStart = /^\s+/,
129 /** Used to match backslashes in property paths. */
130 var reEscapeChar = /\\(\\)?/g;
132 /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
133 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
135 /** Used to match `RegExp` flags from their coerced string values. */
136 var reFlags = /\w*$/;
138 /** Used to detect hexadecimal string values. */
139 var reHasHexPrefix = /^0x/i;
141 /** Used to detect bad signed hexadecimal string values. */
142 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
144 /** Used to detect binary string values. */
145 var reIsBinary = /^0b[01]+$/i;
147 /** Used to detect host constructors (Safari > 5). */
148 var reIsHostCtor = /^\[object .+?Constructor\]$/;
150 /** Used to detect octal string values. */
151 var reIsOctal = /^0o[0-7]+$/i;
153 /** Used to detect unsigned integer values. */
154 var reIsUint = /^(?:0|[1-9]\d*)$/;
156 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
157 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
159 /** Used to ensure capturing order of template delimiters. */
160 var reNoMatch = /($^)/;
162 /** Used to match unescaped characters in compiled string literals. */
163 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
165 /** Used to compose unicode character classes. */
166 var rsAstralRange = '\\ud800-\\udfff',
167 rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
168 rsComboSymbolsRange = '\\u20d0-\\u20f0',
169 rsDingbatRange = '\\u2700-\\u27bf',
170 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
171 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
172 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
173 rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d',
174 rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
175 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
176 rsVarRange = '\\ufe0e\\ufe0f',
177 rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange;
179 /** Used to compose unicode capture groups. */
180 var rsAstral = '[' + rsAstralRange + ']',
181 rsBreak = '[' + rsBreakRange + ']',
182 rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
184 rsDingbat = '[' + rsDingbatRange + ']',
185 rsLower = '[' + rsLowerRange + ']',
186 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
187 rsFitz = '\\ud83c[\\udffb-\\udfff]',
188 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
189 rsNonAstral = '[^' + rsAstralRange + ']',
190 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
191 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
192 rsUpper = '[' + rsUpperRange + ']',
195 /** Used to compose unicode regexes. */
196 var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
197 rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
198 reOptMod = rsModifier + '?',
199 rsOptVar = '[' + rsVarRange + ']?',
200 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
201 rsSeq = rsOptVar + reOptMod + rsOptJoin,
202 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
203 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
206 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
207 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
209 var reComboMark = RegExp(rsCombo, 'g');
211 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
212 var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
214 /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
215 var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
217 /** Used to match non-compound words composed of alphanumeric characters. */
218 var reBasicWord = /[a-zA-Z0-9]+/g;
220 /** Used to match complex or compound words. */
221 var reComplexWord = RegExp([
222 rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
223 rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
224 rsUpper + '?' + rsLowerMisc + '+',
230 /** Used to detect strings that need a more robust regexp to match words. */
231 var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
233 /** Used to assign default `context` object properties. */
235 'Array', 'Buffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
236 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
237 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
238 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_',
239 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
242 /** Used to make template sourceURLs easier to identify. */
243 var templateCounter = -1;
245 /** Used to identify `toStringTag` values of typed arrays. */
246 var typedArrayTags = {};
247 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
248 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
249 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
250 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
251 typedArrayTags[uint32Tag] = true;
252 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
253 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
254 typedArrayTags[dateTag] = typedArrayTags[errorTag] =
255 typedArrayTags[funcTag] = typedArrayTags[mapTag] =
256 typedArrayTags[numberTag] = typedArrayTags[objectTag] =
257 typedArrayTags[regexpTag] = typedArrayTags[setTag] =
258 typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
260 /** Used to identify `toStringTag` values supported by `_.clone`. */
261 var cloneableTags = {};
262 cloneableTags[argsTag] = cloneableTags[arrayTag] =
263 cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
264 cloneableTags[dateTag] = cloneableTags[float32Tag] =
265 cloneableTags[float64Tag] = cloneableTags[int8Tag] =
266 cloneableTags[int16Tag] = cloneableTags[int32Tag] =
267 cloneableTags[mapTag] = cloneableTags[numberTag] =
268 cloneableTags[objectTag] = cloneableTags[regexpTag] =
269 cloneableTags[setTag] = cloneableTags[stringTag] =
270 cloneableTags[symbolTag] = cloneableTags[uint8Tag] =
271 cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] =
272 cloneableTags[uint32Tag] = true;
273 cloneableTags[errorTag] = cloneableTags[funcTag] =
274 cloneableTags[weakMapTag] = false;
276 /** Used to map latin-1 supplementary letters to basic latin letters. */
277 var deburredLetters = {
278 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
279 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
280 '\xc7': 'C', '\xe7': 'c',
281 '\xd0': 'D', '\xf0': 'd',
282 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
283 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
284 '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
285 '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
286 '\xd1': 'N', '\xf1': 'n',
287 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
288 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
289 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
290 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
291 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
292 '\xc6': 'Ae', '\xe6': 'ae',
293 '\xde': 'Th', '\xfe': 'th',
297 /** Used to map characters to HTML entities. */
307 /** Used to map HTML entities to characters. */
308 var htmlUnescapes = {
317 /** Used to determine if values are of the language type `Object`. */
323 /** Used to escape characters for inclusion in compiled string literals. */
324 var stringEscapes = {
333 /** Built-in method references without a dependency on `root`. */
334 var freeParseFloat = parseFloat,
335 freeParseInt = parseInt;
337 /** Detect free variable `exports`. */
338 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
340 /** Detect free variable `module`. */
341 var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
343 /** Detect free variable `global` from Node.js. */
344 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
346 /** Detect free variable `self`. */
347 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
349 /** Detect free variable `window`. */
350 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
352 /** Detect the popular CommonJS extension `module.exports`. */
353 var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null;
355 /** Detect `this` as the global object. */
356 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
359 * Used as a reference to the global object.
361 * The `this` value is used if it's the global object to avoid Greasemonkey's
362 * restricted `window` object, otherwise the `window` object is used.
364 var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
366 /*--------------------------------------------------------------------------*/
369 * Adds the key-value `pair` to `map`.
372 * @param {Object} map The map to modify.
373 * @param {Array} pair The key-value pair to add.
374 * @returns {Object} Returns `map`.
376 function addMapEntry(map, pair) {
377 map.set(pair[0], pair[1]);
382 * Adds `value` to `set`.
385 * @param {Object} set The set to modify.
386 * @param {*} value The value to add.
387 * @returns {Object} Returns `set`.
389 function addSetEntry(set, value) {
395 * A faster alternative to `Function#apply`, this function invokes `func`
396 * with the `this` binding of `thisArg` and the arguments of `args`.
399 * @param {Function} func The function to invoke.
400 * @param {*} thisArg The `this` binding of `func`.
401 * @param {...*} args The arguments to invoke `func` with.
402 * @returns {*} Returns the result of `func`.
404 function apply(func, thisArg, args) {
405 var length = args.length;
407 case 0: return func.call(thisArg);
408 case 1: return func.call(thisArg, args[0]);
409 case 2: return func.call(thisArg, args[0], args[1]);
410 case 3: return func.call(thisArg, args[0], args[1], args[2]);
412 return func.apply(thisArg, args);
416 * A specialized version of `baseAggregator` for arrays.
419 * @param {Array} array The array to iterate over.
420 * @param {Function} setter The function to set `accumulator` values.
421 * @param {Function} iteratee The iteratee to transform keys.
422 * @param {Object} accumulator The initial aggregated object.
423 * @returns {Function} Returns `accumulator`.
425 function arrayAggregator(array, setter, iteratee, accumulator) {
427 length = array.length;
429 while (++index < length) {
430 var value = array[index];
431 setter(accumulator, value, iteratee(value), array);
437 * Creates a new array concatenating `array` with `other`.
440 * @param {Array} array The first array to concatenate.
441 * @param {Array} other The second array to concatenate.
442 * @returns {Array} Returns the new concatenated array.
444 function arrayConcat(array, other) {
446 length = array.length,
448 othLength = other.length,
449 result = Array(length + othLength);
451 while (++index < length) {
452 result[index] = array[index];
454 while (++othIndex < othLength) {
455 result[index++] = other[othIndex];
461 * A specialized version of `_.forEach` for arrays without support for
462 * iteratee shorthands.
465 * @param {Array} array The array to iterate over.
466 * @param {Function} iteratee The function invoked per iteration.
467 * @returns {Array} Returns `array`.
469 function arrayEach(array, iteratee) {
471 length = array.length;
473 while (++index < length) {
474 if (iteratee(array[index], index, array) === false) {
482 * A specialized version of `_.forEachRight` for arrays without support for
483 * iteratee shorthands.
486 * @param {Array} array The array to iterate over.
487 * @param {Function} iteratee The function invoked per iteration.
488 * @returns {Array} Returns `array`.
490 function arrayEachRight(array, iteratee) {
491 var length = array.length;
494 if (iteratee(array[length], length, array) === false) {
502 * A specialized version of `_.every` for arrays without support for
503 * iteratee shorthands.
506 * @param {Array} array The array to iterate over.
507 * @param {Function} predicate The function invoked per iteration.
508 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
510 function arrayEvery(array, predicate) {
512 length = array.length;
514 while (++index < length) {
515 if (!predicate(array[index], index, array)) {
523 * A specialized version of `_.filter` for arrays without support for
524 * iteratee shorthands.
527 * @param {Array} array The array to iterate over.
528 * @param {Function} predicate The function invoked per iteration.
529 * @returns {Array} Returns the new filtered array.
531 function arrayFilter(array, predicate) {
533 length = array.length,
537 while (++index < length) {
538 var value = array[index];
539 if (predicate(value, index, array)) {
540 result[++resIndex] = value;
547 * A specialized version of `_.includes` for arrays without support for
548 * specifying an index to search from.
551 * @param {Array} array The array to search.
552 * @param {*} target The value to search for.
553 * @returns {boolean} Returns `true` if `target` is found, else `false`.
555 function arrayIncludes(array, value) {
556 return !!array.length && baseIndexOf(array, value, 0) > -1;
560 * A specialized version of `_.includesWith` for arrays without support for
561 * specifying an index to search from.
564 * @param {Array} array The array to search.
565 * @param {*} target The value to search for.
566 * @param {Function} comparator The comparator invoked per element.
567 * @returns {boolean} Returns `true` if `target` is found, else `false`.
569 function arrayIncludesWith(array, value, comparator) {
571 length = array.length;
573 while (++index < length) {
574 if (comparator(value, array[index])) {
582 * A specialized version of `_.map` for arrays without support for iteratee
586 * @param {Array} array The array to iterate over.
587 * @param {Function} iteratee The function invoked per iteration.
588 * @returns {Array} Returns the new mapped array.
590 function arrayMap(array, iteratee) {
592 length = array.length,
593 result = Array(length);
595 while (++index < length) {
596 result[index] = iteratee(array[index], index, array);
602 * Appends the elements of `values` to `array`.
605 * @param {Array} array The array to modify.
606 * @param {Array} values The values to append.
607 * @returns {Array} Returns `array`.
609 function arrayPush(array, values) {
611 length = values.length,
612 offset = array.length;
614 while (++index < length) {
615 array[offset + index] = values[index];
621 * A specialized version of `_.reduce` for arrays without support for
622 * iteratee shorthands.
625 * @param {Array} array The array to iterate over.
626 * @param {Function} iteratee The function invoked per iteration.
627 * @param {*} [accumulator] The initial value.
628 * @param {boolean} [initAccum] Specify using the first element of `array` as the initial value.
629 * @returns {*} Returns the accumulated value.
631 function arrayReduce(array, iteratee, accumulator, initAccum) {
633 length = array.length;
635 if (initAccum && length) {
636 accumulator = array[++index];
638 while (++index < length) {
639 accumulator = iteratee(accumulator, array[index], index, array);
645 * A specialized version of `_.reduceRight` for arrays without support for
646 * iteratee shorthands.
649 * @param {Array} array The array to iterate over.
650 * @param {Function} iteratee The function invoked per iteration.
651 * @param {*} [accumulator] The initial value.
652 * @param {boolean} [initAccum] Specify using the last element of `array` as the initial value.
653 * @returns {*} Returns the accumulated value.
655 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
656 var length = array.length;
657 if (initAccum && length) {
658 accumulator = array[--length];
661 accumulator = iteratee(accumulator, array[length], length, array);
667 * A specialized version of `_.some` for arrays without support for iteratee
671 * @param {Array} array The array to iterate over.
672 * @param {Function} predicate The function invoked per iteration.
673 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
675 function arraySome(array, predicate) {
677 length = array.length;
679 while (++index < length) {
680 if (predicate(array[index], index, array)) {
688 * The base implementation of methods like `_.max` and `_.min` which accepts a
689 * `comparator` to determine the extremum value.
692 * @param {Array} array The array to iterate over.
693 * @param {Function} iteratee The iteratee invoked per iteration.
694 * @param {Function} comparator The comparator used to compare values.
695 * @returns {*} Returns the extremum value.
697 function baseExtremum(array, iteratee, comparator) {
699 length = array.length;
701 while (++index < length) {
702 var value = array[index],
703 current = iteratee(value);
705 if (current != null && (computed === undefined
706 ? current === current
707 : comparator(current, computed)
709 var computed = current,
717 * The base implementation of methods like `_.find` and `_.findKey`, without
718 * support for iteratee shorthands, which iterates over `collection` using
722 * @param {Array|Object} collection The collection to search.
723 * @param {Function} predicate The function invoked per iteration.
724 * @param {Function} eachFunc The function to iterate over `collection`.
725 * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
726 * @returns {*} Returns the found element or its key, else `undefined`.
728 function baseFind(collection, predicate, eachFunc, retKey) {
730 eachFunc(collection, function(value, key, collection) {
731 if (predicate(value, key, collection)) {
732 result = retKey ? key : value;
740 * The base implementation of `_.findIndex` and `_.findLastIndex` without
741 * support for iteratee shorthands.
744 * @param {Array} array The array to search.
745 * @param {Function} predicate The function invoked per iteration.
746 * @param {boolean} [fromRight] Specify iterating from right to left.
747 * @returns {number} Returns the index of the matched value, else `-1`.
749 function baseFindIndex(array, predicate, fromRight) {
750 var length = array.length,
751 index = fromRight ? length : -1;
753 while ((fromRight ? index-- : ++index < length)) {
754 if (predicate(array[index], index, array)) {
762 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
765 * @param {Array} array The array to search.
766 * @param {*} value The value to search for.
767 * @param {number} fromIndex The index to search from.
768 * @returns {number} Returns the index of the matched value, else `-1`.
770 function baseIndexOf(array, value, fromIndex) {
771 if (value !== value) {
772 return indexOfNaN(array, fromIndex);
774 var index = fromIndex - 1,
775 length = array.length;
777 while (++index < length) {
778 if (array[index] === value) {
786 * The base implementation of `_.reduce` and `_.reduceRight`, without support
787 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
790 * @param {Array|Object} collection The collection to iterate over.
791 * @param {Function} iteratee The function invoked per iteration.
792 * @param {*} accumulator The initial value.
793 * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value.
794 * @param {Function} eachFunc The function to iterate over `collection`.
795 * @returns {*} Returns the accumulated value.
797 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
798 eachFunc(collection, function(value, index, collection) {
799 accumulator = initAccum
800 ? (initAccum = false, value)
801 : iteratee(accumulator, value, index, collection);
807 * The base implementation of `_.sortBy` which uses `comparer` to define
808 * the sort order of `array` and replaces criteria objects with their
809 * corresponding values.
812 * @param {Array} array The array to sort.
813 * @param {Function} comparer The function to define sort order.
814 * @returns {Array} Returns `array`.
816 function baseSortBy(array, comparer) {
817 var length = array.length;
819 array.sort(comparer);
821 array[length] = array[length].value;
827 * The base implementation of `_.sum` without support for iteratee shorthands.
830 * @param {Array} array The array to iterate over.
831 * @param {Function} iteratee The function invoked per iteration.
832 * @returns {number} Returns the sum.
834 function baseSum(array, iteratee) {
837 length = array.length;
839 while (++index < length) {
840 var current = iteratee(array[index]);
841 if (current !== undefined) {
842 result = result === undefined ? current : (result + current);
849 * The base implementation of `_.times` without support for iteratee shorthands
850 * or max array length checks.
853 * @param {number} n The number of times to invoke `iteratee`.
854 * @param {Function} iteratee The function invoked per iteration.
855 * @returns {Array} Returns the array of results.
857 function baseTimes(n, iteratee) {
861 while (++index < n) {
862 result[index] = iteratee(index);
868 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
869 * of key-value pairs for `object` corresponding to the property names of `props`.
872 * @param {Object} object The object to query.
873 * @param {Array} props The property names to get values for.
874 * @returns {Object} Returns the new array of key-value pairs.
876 function baseToPairs(object, props) {
877 return arrayMap(props, function(key) {
878 return [key, object[key]];
883 * The base implementation of `_.unary` without support for storing wrapper metadata.
886 * @param {Function} func The function to cap arguments for.
887 * @returns {Function} Returns the new function.
889 function baseUnary(func) {
890 return function(value) {
896 * The base implementation of `_.values` and `_.valuesIn` which creates an
897 * array of `object` property values corresponding to the property names
901 * @param {Object} object The object to query.
902 * @param {Array} props The property names to get values for.
903 * @returns {Object} Returns the array of property values.
905 function baseValues(object, props) {
906 return arrayMap(props, function(key) {
912 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
913 * that is not found in the character symbols.
916 * @param {Array} strSymbols The string symbols to inspect.
917 * @param {Array} chrSymbols The character symbols to find.
918 * @returns {number} Returns the index of the first unmatched string symbol.
920 function charsStartIndex(strSymbols, chrSymbols) {
922 length = strSymbols.length;
924 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
929 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
930 * that is not found in the character symbols.
933 * @param {Array} strSymbols The string symbols to inspect.
934 * @param {Array} chrSymbols The character symbols to find.
935 * @returns {number} Returns the index of the last unmatched string symbol.
937 function charsEndIndex(strSymbols, chrSymbols) {
938 var index = strSymbols.length;
940 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
945 * Checks if `value` is a global object.
948 * @param {*} value The value to check.
949 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
951 function checkGlobal(value) {
952 return (value && value.Object === Object) ? value : null;
956 * Compares values to sort them in ascending order.
959 * @param {*} value The value to compare.
960 * @param {*} other The other value to compare.
961 * @returns {number} Returns the sort order indicator for `value`.
963 function compareAscending(value, other) {
964 if (value !== other) {
965 var valIsNull = value === null,
966 valIsUndef = value === undefined,
967 valIsReflexive = value === value;
969 var othIsNull = other === null,
970 othIsUndef = other === undefined,
971 othIsReflexive = other === other;
973 if ((value > other && !othIsNull) || !valIsReflexive ||
974 (valIsNull && !othIsUndef && othIsReflexive) ||
975 (valIsUndef && othIsReflexive)) {
978 if ((value < other && !valIsNull) || !othIsReflexive ||
979 (othIsNull && !valIsUndef && valIsReflexive) ||
980 (othIsUndef && valIsReflexive)) {
988 * Used by `_.orderBy` to compare multiple properties of a value to another
989 * and stable sort them.
991 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
992 * specify an order of "desc" for descending or "asc" for ascending sort order
993 * of corresponding values.
996 * @param {Object} object The object to compare.
997 * @param {Object} other The other object to compare.
998 * @param {boolean[]|string[]} orders The order to sort by for each property.
999 * @returns {number} Returns the sort order indicator for `object`.
1001 function compareMultiple(object, other, orders) {
1003 objCriteria = object.criteria,
1004 othCriteria = other.criteria,
1005 length = objCriteria.length,
1006 ordersLength = orders.length;
1008 while (++index < length) {
1009 var result = compareAscending(objCriteria[index], othCriteria[index]);
1011 if (index >= ordersLength) {
1014 var order = orders[index];
1015 return result * (order == 'desc' ? -1 : 1);
1018 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
1019 // that causes it, under certain circumstances, to provide the same value for
1020 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
1021 // for more details.
1023 // This also ensures a stable sort in V8 and other engines.
1024 // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
1025 return object.index - other.index;
1029 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
1032 * @param {string} letter The matched letter to deburr.
1033 * @returns {string} Returns the deburred letter.
1035 function deburrLetter(letter) {
1036 return deburredLetters[letter];
1040 * Used by `_.escape` to convert characters to HTML entities.
1043 * @param {string} chr The matched character to escape.
1044 * @returns {string} Returns the escaped character.
1046 function escapeHtmlChar(chr) {
1047 return htmlEscapes[chr];
1051 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1054 * @param {string} chr The matched character to escape.
1055 * @returns {string} Returns the escaped character.
1057 function escapeStringChar(chr) {
1058 return '\\' + stringEscapes[chr];
1062 * Gets the index at which the first occurrence of `NaN` is found in `array`.
1065 * @param {Array} array The array to search.
1066 * @param {number} fromIndex The index to search from.
1067 * @param {boolean} [fromRight] Specify iterating from right to left.
1068 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
1070 function indexOfNaN(array, fromIndex, fromRight) {
1071 var length = array.length,
1072 index = fromIndex + (fromRight ? 0 : -1);
1074 while ((fromRight ? index-- : ++index < length)) {
1075 var other = array[index];
1076 if (other !== other) {
1084 * Checks if `value` is a host object in IE < 9.
1087 * @param {*} value The value to check.
1088 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
1090 function isHostObject(value) {
1091 // Many host objects are `Object` objects that can coerce to strings
1092 // despite having improperly defined `toString` methods.
1094 if (value != null && typeof value.toString != 'function') {
1096 result = !!(value + '');
1103 * Checks if `value` is a valid array-like index.
1106 * @param {*} value The value to check.
1107 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1108 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1110 function isIndex(value, length) {
1111 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
1112 length = length == null ? MAX_SAFE_INTEGER : length;
1113 return value > -1 && value % 1 == 0 && value < length;
1117 * Converts `iterator` to an array.
1120 * @param {Object} iterator The iterator to convert.
1121 * @returns {Array} Returns the converted array.
1123 function iteratorToArray(iterator) {
1127 while (!(data = iterator.next()).done) {
1128 result.push(data.value);
1134 * Converts `map` to an array.
1137 * @param {Object} map The map to convert.
1138 * @returns {Array} Returns the converted array.
1140 function mapToArray(map) {
1142 result = Array(map.size);
1144 map.forEach(function(value, key) {
1145 result[++index] = [key, value];
1151 * Replaces all `placeholder` elements in `array` with an internal placeholder
1152 * and returns an array of their indexes.
1155 * @param {Array} array The array to modify.
1156 * @param {*} placeholder The placeholder to replace.
1157 * @returns {Array} Returns the new array of placeholder indexes.
1159 function replaceHolders(array, placeholder) {
1161 length = array.length,
1165 while (++index < length) {
1166 if (array[index] === placeholder) {
1167 array[index] = PLACEHOLDER;
1168 result[++resIndex] = index;
1175 * Converts `set` to an array.
1178 * @param {Object} set The set to convert.
1179 * @returns {Array} Returns the converted array.
1181 function setToArray(set) {
1183 result = Array(set.size);
1185 set.forEach(function(value) {
1186 result[++index] = value;
1192 * Gets the number of symbols in `string`.
1195 * @param {string} string The string to inspect.
1196 * @returns {number} Returns the string size.
1198 function stringSize(string) {
1199 if (!(string && reHasComplexSymbol.test(string))) {
1200 return string.length;
1202 var result = reComplexSymbol.lastIndex = 0;
1203 while (reComplexSymbol.test(string)) {
1210 * Converts `string` to an array.
1213 * @param {string} string The string to convert.
1214 * @returns {Array} Returns the converted array.
1216 function stringToArray(string) {
1217 return string.match(reComplexSymbol);
1221 * Used by `_.unescape` to convert HTML entities to characters.
1224 * @param {string} chr The matched character to unescape.
1225 * @returns {string} Returns the unescaped character.
1227 function unescapeHtmlChar(chr) {
1228 return htmlUnescapes[chr];
1231 /*--------------------------------------------------------------------------*/
1234 * Create a new pristine `lodash` function using the `context` object.
1239 * @param {Object} [context=root] The context object.
1240 * @returns {Function} Returns a new `lodash` function.
1243 * _.mixin({ 'foo': _.constant('foo') });
1245 * var lodash = _.runInContext();
1246 * lodash.mixin({ 'bar': lodash.constant('bar') });
1248 * _.isFunction(_.foo);
1250 * _.isFunction(_.bar);
1253 * lodash.isFunction(lodash.foo);
1255 * lodash.isFunction(lodash.bar);
1258 * // Use `context` to mock `Date#getTime` use in `_.now`.
1259 * var mock = _.runInContext({
1260 * 'Date': function() {
1261 * return { 'getTime': getTimeMock };
1265 * // Create a suped-up `defer` in Node.js.
1266 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1268 function runInContext(context) {
1269 context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
1271 /** Built-in constructor references. */
1272 var Date = context.Date,
1273 Error = context.Error,
1274 Math = context.Math,
1275 RegExp = context.RegExp,
1276 TypeError = context.TypeError;
1278 /** Used for built-in method references. */
1279 var arrayProto = context.Array.prototype,
1280 objectProto = context.Object.prototype;
1282 /** Used to resolve the decompiled source of functions. */
1283 var funcToString = context.Function.prototype.toString;
1285 /** Used to check objects for own properties. */
1286 var hasOwnProperty = objectProto.hasOwnProperty;
1288 /** Used to generate unique IDs. */
1291 /** Used to infer the `Object` constructor. */
1292 var objectCtorString = funcToString.call(Object);
1295 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
1298 var objectToString = objectProto.toString;
1300 /** Used to restore the original `_` reference in `_.noConflict`. */
1301 var oldDash = root._;
1303 /** Used to detect if a method is native. */
1304 var reIsNative = RegExp('^' +
1305 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1306 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1309 /** Built-in value references. */
1310 var Buffer = moduleExports ? context.Buffer : undefined,
1311 Reflect = context.Reflect,
1312 Symbol = context.Symbol,
1313 Uint8Array = context.Uint8Array,
1314 clearTimeout = context.clearTimeout,
1315 enumerate = Reflect ? Reflect.enumerate : undefined,
1316 getPrototypeOf = Object.getPrototypeOf,
1317 getOwnPropertySymbols = Object.getOwnPropertySymbols,
1318 iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
1319 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1320 setTimeout = context.setTimeout,
1321 splice = arrayProto.splice;
1323 /* Built-in method references for those with the same name as other `lodash` methods. */
1324 var nativeCeil = Math.ceil,
1325 nativeFloor = Math.floor,
1326 nativeIsFinite = context.isFinite,
1327 nativeJoin = arrayProto.join,
1328 nativeKeys = Object.keys,
1329 nativeMax = Math.max,
1330 nativeMin = Math.min,
1331 nativeParseInt = context.parseInt,
1332 nativeRandom = Math.random,
1333 nativeReverse = arrayProto.reverse;
1335 /* Built-in method references that are verified to be native. */
1336 var Map = getNative(context, 'Map'),
1337 Set = getNative(context, 'Set'),
1338 WeakMap = getNative(context, 'WeakMap'),
1339 nativeCreate = getNative(Object, 'create');
1341 /** Used to store function metadata. */
1342 var metaMap = WeakMap && new WeakMap;
1344 /** Used to detect maps, sets, and weakmaps. */
1345 var mapCtorString = Map ? funcToString.call(Map) : '',
1346 setCtorString = Set ? funcToString.call(Set) : '',
1347 weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : '';
1349 /** Used to convert symbols to primitives and strings. */
1350 var symbolProto = Symbol ? Symbol.prototype : undefined,
1351 symbolValueOf = Symbol ? symbolProto.valueOf : undefined,
1352 symbolToString = Symbol ? symbolProto.toString : undefined;
1354 /** Used to lookup unminified function names. */
1357 /*------------------------------------------------------------------------*/
1360 * Creates a `lodash` object which wraps `value` to enable implicit method
1361 * chaining. Methods that operate on and return arrays, collections, and
1362 * functions can be chained together. Methods that retrieve a single value or
1363 * may return a primitive value will automatically end the chain sequence and
1364 * return the unwrapped value. Otherwise, the value must be unwrapped with
1367 * Explicit chaining, which must be unwrapped with `_#value` in all cases,
1368 * may be enabled using `_.chain`.
1370 * The execution of chained methods is lazy, that is, it's deferred until
1371 * `_#value` is implicitly or explicitly called.
1373 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
1374 * fusion is an optimization to merge iteratee calls; this avoids the creation
1375 * of intermediate arrays and can greatly reduce the number of iteratee executions.
1376 * Sections of a chain sequence qualify for shortcut fusion if the section is
1377 * applied to an array of at least two hundred elements and any iteratees
1378 * accept only one argument. The heuristic for whether a section qualifies
1379 * for shortcut fusion is subject to change.
1381 * Chaining is supported in custom builds as long as the `_#value` method is
1382 * directly or indirectly included in the build.
1384 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1386 * The wrapper `Array` methods are:
1387 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1389 * The wrapper `String` methods are:
1390 * `replace` and `split`
1392 * The wrapper methods that support shortcut fusion are:
1393 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1394 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1395 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1397 * The chainable wrapper methods are:
1398 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
1399 * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
1400 * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`,
1401 * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
1402 * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
1403 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
1404 * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`,
1405 * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invertBy`,
1406 * `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`,
1407 * `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`,
1408 * `method`, `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`,
1409 * `orderBy`, `over`, `overArgs`, `overEvery`, `overSome`, `partial`,
1410 * `partialRight`, `partition`, `pick`, `pickBy`, `plant`, `property`,
1411 * `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`,
1412 * `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`, `sampleSize`,
1413 * `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`,
1414 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
1415 * `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`,
1416 * `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`,
1417 * `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`,
1418 * `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`,
1419 * `zipObjectDeep`, and `zipWith`
1421 * The wrapper methods that are **not** chainable by default are:
1422 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1423 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
1424 * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
1425 * `findLast`, `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`,
1426 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
1427 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
1428 * `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
1429 * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
1430 * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`, `isMatchWith`,
1431 * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`,
1432 * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isString`, `isUndefined`,
1433 * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`,
1434 * `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`,
1435 * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`,
1436 * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
1437 * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
1438 * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
1439 * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toLower`,
1440 * `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`,
1441 * `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
1442 * `upperCase`, `upperFirst`, `value`, and `words`
1447 * @param {*} value The value to wrap in a `lodash` instance.
1448 * @returns {Object} Returns the new `lodash` wrapper instance.
1451 * function square(n) {
1455 * var wrapped = _([1, 2, 3]);
1457 * // Returns an unwrapped value.
1458 * wrapped.reduce(_.add);
1461 * // Returns a wrapped value.
1462 * var squares = wrapped.map(square);
1464 * _.isArray(squares);
1467 * _.isArray(squares.value());
1470 function lodash(value) {
1471 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1472 if (value instanceof LodashWrapper) {
1475 if (hasOwnProperty.call(value, '__wrapped__')) {
1476 return wrapperClone(value);
1479 return new LodashWrapper(value);
1483 * The function whose prototype all chaining wrappers inherit from.
1487 function baseLodash() {
1488 // No operation performed.
1492 * The base constructor for creating `lodash` wrapper objects.
1495 * @param {*} value The value to wrap.
1496 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
1498 function LodashWrapper(value, chainAll) {
1499 this.__wrapped__ = value;
1500 this.__actions__ = [];
1501 this.__chain__ = !!chainAll;
1503 this.__values__ = undefined;
1507 * By default, the template delimiters used by lodash are like those in
1508 * embedded Ruby (ERB). Change the following template settings to use
1509 * alternative delimiters.
1515 lodash.templateSettings = {
1518 * Used to detect `data` property values to be HTML-escaped.
1520 * @memberOf _.templateSettings
1526 * Used to detect code to be evaluated.
1528 * @memberOf _.templateSettings
1531 'evaluate': reEvaluate,
1534 * Used to detect `data` property values to inject.
1536 * @memberOf _.templateSettings
1539 'interpolate': reInterpolate,
1542 * Used to reference the data object in the template text.
1544 * @memberOf _.templateSettings
1550 * Used to import variables into the compiled template.
1552 * @memberOf _.templateSettings
1558 * A reference to the `lodash` function.
1560 * @memberOf _.templateSettings.imports
1567 /*------------------------------------------------------------------------*/
1570 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1573 * @param {*} value The value to wrap.
1575 function LazyWrapper(value) {
1576 this.__wrapped__ = value;
1577 this.__actions__ = [];
1579 this.__filtered__ = false;
1580 this.__iteratees__ = [];
1581 this.__takeCount__ = MAX_ARRAY_LENGTH;
1582 this.__views__ = [];
1586 * Creates a clone of the lazy wrapper object.
1590 * @memberOf LazyWrapper
1591 * @returns {Object} Returns the cloned `LazyWrapper` object.
1593 function lazyClone() {
1594 var result = new LazyWrapper(this.__wrapped__);
1595 result.__actions__ = copyArray(this.__actions__);
1596 result.__dir__ = this.__dir__;
1597 result.__filtered__ = this.__filtered__;
1598 result.__iteratees__ = copyArray(this.__iteratees__);
1599 result.__takeCount__ = this.__takeCount__;
1600 result.__views__ = copyArray(this.__views__);
1605 * Reverses the direction of lazy iteration.
1609 * @memberOf LazyWrapper
1610 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1612 function lazyReverse() {
1613 if (this.__filtered__) {
1614 var result = new LazyWrapper(this);
1615 result.__dir__ = -1;
1616 result.__filtered__ = true;
1618 result = this.clone();
1619 result.__dir__ *= -1;
1625 * Extracts the unwrapped value from its lazy wrapper.
1629 * @memberOf LazyWrapper
1630 * @returns {*} Returns the unwrapped value.
1632 function lazyValue() {
1633 var array = this.__wrapped__.value(),
1635 isArr = isArray(array),
1637 arrLength = isArr ? array.length : 0,
1638 view = getView(0, arrLength, this.__views__),
1641 length = end - start,
1642 index = isRight ? end : (start - 1),
1643 iteratees = this.__iteratees__,
1644 iterLength = iteratees.length,
1646 takeCount = nativeMin(length, this.__takeCount__);
1648 if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
1649 return baseWrapperValue(array, this.__actions__);
1654 while (length-- && resIndex < takeCount) {
1658 value = array[index];
1660 while (++iterIndex < iterLength) {
1661 var data = iteratees[iterIndex],
1662 iteratee = data.iteratee,
1664 computed = iteratee(value);
1666 if (type == LAZY_MAP_FLAG) {
1668 } else if (!computed) {
1669 if (type == LAZY_FILTER_FLAG) {
1676 result[resIndex++] = value;
1681 /*------------------------------------------------------------------------*/
1684 * Creates an hash object.
1687 * @returns {Object} Returns the new hash object.
1692 * Removes `key` and its value from the hash.
1695 * @param {Object} hash The hash to modify.
1696 * @param {string} key The key of the value to remove.
1697 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1699 function hashDelete(hash, key) {
1700 return hashHas(hash, key) && delete hash[key];
1704 * Gets the hash value for `key`.
1707 * @param {Object} hash The hash to query.
1708 * @param {string} key The key of the value to get.
1709 * @returns {*} Returns the entry value.
1711 function hashGet(hash, key) {
1713 var result = hash[key];
1714 return result === HASH_UNDEFINED ? undefined : result;
1716 return hasOwnProperty.call(hash, key) ? hash[key] : undefined;
1720 * Checks if a hash value for `key` exists.
1723 * @param {Object} hash The hash to query.
1724 * @param {string} key The key of the entry to check.
1725 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1727 function hashHas(hash, key) {
1728 return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash, key);
1732 * Sets the hash `key` to `value`.
1735 * @param {Object} hash The hash to modify.
1736 * @param {string} key The key of the value to set.
1737 * @param {*} value The value to set.
1739 function hashSet(hash, key, value) {
1740 hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
1743 /*------------------------------------------------------------------------*/
1746 * Creates a map cache object to store key-value pairs.
1749 * @param {Array} [values] The values to cache.
1751 function MapCache(values) {
1753 length = values ? values.length : 0;
1756 while (++index < length) {
1757 var entry = values[index];
1758 this.set(entry[0], entry[1]);
1763 * Removes all key-value entries from the map.
1767 * @memberOf MapCache
1769 function mapClear() {
1770 this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': new Hash };
1774 * Removes `key` and its value from the map.
1778 * @memberOf MapCache
1779 * @param {string} key The key of the value to remove.
1780 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1782 function mapDelete(key) {
1783 var data = this.__data__;
1784 if (isKeyable(key)) {
1785 return hashDelete(typeof key == 'string' ? data.string : data.hash, key);
1787 return Map ? data.map['delete'](key) : assocDelete(data.map, key);
1791 * Gets the map value for `key`.
1795 * @memberOf MapCache
1796 * @param {string} key The key of the value to get.
1797 * @returns {*} Returns the entry value.
1799 function mapGet(key) {
1800 var data = this.__data__;
1801 if (isKeyable(key)) {
1802 return hashGet(typeof key == 'string' ? data.string : data.hash, key);
1804 return Map ? data.map.get(key) : assocGet(data.map, key);
1808 * Checks if a map value for `key` exists.
1812 * @memberOf MapCache
1813 * @param {string} key The key of the entry to check.
1814 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1816 function mapHas(key) {
1817 var data = this.__data__;
1818 if (isKeyable(key)) {
1819 return hashHas(typeof key == 'string' ? data.string : data.hash, key);
1821 return Map ? data.map.has(key) : assocHas(data.map, key);
1825 * Sets the map `key` to `value`.
1829 * @memberOf MapCache
1830 * @param {string} key The key of the value to set.
1831 * @param {*} value The value to set.
1832 * @returns {Object} Returns the map cache object.
1834 function mapSet(key, value) {
1835 var data = this.__data__;
1836 if (isKeyable(key)) {
1837 hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
1839 data.map.set(key, value);
1841 assocSet(data.map, key, value);
1846 /*------------------------------------------------------------------------*/
1850 * Creates a set cache object to store unique values.
1853 * @param {Array} [values] The values to cache.
1855 function SetCache(values) {
1857 length = values ? values.length : 0;
1859 this.__data__ = new MapCache;
1860 while (++index < length) {
1861 this.push(values[index]);
1866 * Checks if `value` is in `cache`.
1869 * @param {Object} cache The set cache to search.
1870 * @param {*} value The value to search for.
1871 * @returns {number} Returns `true` if `value` is found, else `false`.
1873 function cacheHas(cache, value) {
1874 var map = cache.__data__;
1875 if (isKeyable(value)) {
1876 var data = map.__data__,
1877 hash = typeof value == 'string' ? data.string : data.hash;
1879 return hash[value] === HASH_UNDEFINED;
1881 return map.has(value);
1885 * Adds `value` to the set cache.
1889 * @memberOf SetCache
1890 * @param {*} value The value to cache.
1892 function cachePush(value) {
1893 var map = this.__data__;
1894 if (isKeyable(value)) {
1895 var data = map.__data__,
1896 hash = typeof value == 'string' ? data.string : data.hash;
1898 hash[value] = HASH_UNDEFINED;
1901 map.set(value, HASH_UNDEFINED);
1905 /*------------------------------------------------------------------------*/
1908 * Creates a stack cache object to store key-value pairs.
1911 * @param {Array} [values] The values to cache.
1913 function Stack(values) {
1915 length = values ? values.length : 0;
1918 while (++index < length) {
1919 var entry = values[index];
1920 this.set(entry[0], entry[1]);
1925 * Removes all key-value entries from the stack.
1931 function stackClear() {
1932 this.__data__ = { 'array': [], 'map': null };
1936 * Removes `key` and its value from the stack.
1941 * @param {string} key The key of the value to remove.
1942 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1944 function stackDelete(key) {
1945 var data = this.__data__,
1948 return array ? assocDelete(array, key) : data.map['delete'](key);
1952 * Gets the stack value for `key`.
1957 * @param {string} key The key of the value to get.
1958 * @returns {*} Returns the entry value.
1960 function stackGet(key) {
1961 var data = this.__data__,
1964 return array ? assocGet(array, key) : data.map.get(key);
1968 * Checks if a stack value for `key` exists.
1973 * @param {string} key The key of the entry to check.
1974 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1976 function stackHas(key) {
1977 var data = this.__data__,
1980 return array ? assocHas(array, key) : data.map.has(key);
1984 * Sets the stack `key` to `value`.
1989 * @param {string} key The key of the value to set.
1990 * @param {*} value The value to set.
1991 * @returns {Object} Returns the stack cache object.
1993 function stackSet(key, value) {
1994 var data = this.__data__,
1998 if (array.length < (LARGE_ARRAY_SIZE - 1)) {
1999 assocSet(array, key, value);
2002 data.map = new MapCache(array);
2007 map.set(key, value);
2012 /*------------------------------------------------------------------------*/
2015 * Removes `key` and its value from the associative array.
2018 * @param {Array} array The array to query.
2019 * @param {string} key The key of the value to remove.
2020 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2022 function assocDelete(array, key) {
2023 var index = assocIndexOf(array, key);
2027 var lastIndex = array.length - 1;
2028 if (index == lastIndex) {
2031 splice.call(array, index, 1);
2037 * Gets the associative array value for `key`.
2040 * @param {Array} array The array to query.
2041 * @param {string} key The key of the value to get.
2042 * @returns {*} Returns the entry value.
2044 function assocGet(array, key) {
2045 var index = assocIndexOf(array, key);
2046 return index < 0 ? undefined : array[index][1];
2050 * Checks if an associative array value for `key` exists.
2053 * @param {Array} array The array to query.
2054 * @param {string} key The key of the entry to check.
2055 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2057 function assocHas(array, key) {
2058 return assocIndexOf(array, key) > -1;
2062 * Gets the index at which the first occurrence of `key` is found in `array`
2063 * of key-value pairs.
2066 * @param {Array} array The array to search.
2067 * @param {*} key The key to search for.
2068 * @returns {number} Returns the index of the matched value, else `-1`.
2070 function assocIndexOf(array, key) {
2071 var length = array.length;
2073 if (eq(array[length][0], key)) {
2081 * Sets the associative array `key` to `value`.
2084 * @param {Array} array The array to modify.
2085 * @param {string} key The key of the value to set.
2086 * @param {*} value The value to set.
2088 function assocSet(array, key, value) {
2089 var index = assocIndexOf(array, key);
2091 array.push([key, value]);
2093 array[index][1] = value;
2097 /*------------------------------------------------------------------------*/
2100 * Used by `_.defaults` to customize its `_.assignIn` use.
2103 * @param {*} objValue The destination value.
2104 * @param {*} srcValue The source value.
2105 * @param {string} key The key of the property to assign.
2106 * @param {Object} object The parent object of `objValue`.
2107 * @returns {*} Returns the value to assign.
2109 function assignInDefaults(objValue, srcValue, key, object) {
2110 if (objValue === undefined ||
2111 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
2118 * This function is like `assignValue` except that it doesn't assign `undefined` values.
2121 * @param {Object} object The object to modify.
2122 * @param {string} key The key of the property to assign.
2123 * @param {*} value The value to assign.
2125 function assignMergeValue(object, key, value) {
2126 if ((value !== undefined && !eq(object[key], value)) ||
2127 (typeof key == 'number' && value === undefined && !(key in object))) {
2128 object[key] = value;
2133 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2134 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2135 * for equality comparisons.
2138 * @param {Object} object The object to modify.
2139 * @param {string} key The key of the property to assign.
2140 * @param {*} value The value to assign.
2142 function assignValue(object, key, value) {
2143 var objValue = object[key];
2144 if ((!eq(objValue, value) ||
2145 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
2146 (value === undefined && !(key in object))) {
2147 object[key] = value;
2152 * Aggregates elements of `collection` on `accumulator` with keys transformed
2153 * by `iteratee` and values set by `setter`.
2156 * @param {Array|Object} collection The collection to iterate over.
2157 * @param {Function} setter The function to set `accumulator` values.
2158 * @param {Function} iteratee The iteratee to transform keys.
2159 * @param {Object} accumulator The initial aggregated object.
2160 * @returns {Function} Returns `accumulator`.
2162 function baseAggregator(collection, setter, iteratee, accumulator) {
2163 baseEach(collection, function(value, key, collection) {
2164 setter(accumulator, value, iteratee(value), collection);
2170 * The base implementation of `_.assign` without support for multiple sources
2171 * or `customizer` functions.
2174 * @param {Object} object The destination object.
2175 * @param {Object} source The source object.
2176 * @returns {Object} Returns `object`.
2178 function baseAssign(object, source) {
2179 return object && copyObject(source, keys(source), object);
2183 * The base implementation of `_.at` without support for individual paths.
2186 * @param {Object} object The object to iterate over.
2187 * @param {string[]} paths The property paths of elements to pick.
2188 * @returns {Array} Returns the new array of picked elements.
2190 function baseAt(object, paths) {
2192 isNil = object == null,
2193 length = paths.length,
2194 result = Array(length);
2196 while (++index < length) {
2197 result[index] = isNil ? undefined : get(object, paths[index]);
2203 * The base implementation of `_.clamp` which doesn't coerce arguments to numbers.
2206 * @param {number} number The number to clamp.
2207 * @param {number} [lower] The lower bound.
2208 * @param {number} upper The upper bound.
2209 * @returns {number} Returns the clamped number.
2211 function baseClamp(number, lower, upper) {
2212 if (number === number) {
2213 if (upper !== undefined) {
2214 number = number <= upper ? number : upper;
2216 if (lower !== undefined) {
2217 number = number >= lower ? number : lower;
2224 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2225 * traversed objects.
2228 * @param {*} value The value to clone.
2229 * @param {boolean} [isDeep] Specify a deep clone.
2230 * @param {Function} [customizer] The function to customize cloning.
2231 * @param {string} [key] The key of `value`.
2232 * @param {Object} [object] The parent object of `value`.
2233 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2234 * @returns {*} Returns the cloned value.
2236 function baseClone(value, isDeep, customizer, key, object, stack) {
2239 result = object ? customizer(value, key, object, stack) : customizer(value);
2241 if (result !== undefined) {
2244 if (!isObject(value)) {
2247 var isArr = isArray(value);
2249 result = initCloneArray(value);
2251 return copyArray(value, result);
2254 var tag = getTag(value),
2255 isFunc = tag == funcTag || tag == genTag;
2257 if (isBuffer(value)) {
2258 return cloneBuffer(value, isDeep);
2260 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2261 if (isHostObject(value)) {
2262 return object ? value : {};
2264 result = initCloneObject(isFunc ? {} : value);
2266 return copySymbols(value, baseAssign(result, value));
2269 return cloneableTags[tag]
2270 ? initCloneByTag(value, tag, isDeep)
2271 : (object ? value : {});
2274 // Check for circular references and return its corresponding clone.
2275 stack || (stack = new Stack);
2276 var stacked = stack.get(value);
2280 stack.set(value, result);
2282 // Recursively populate clone (susceptible to call stack limits).
2283 (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
2284 assignValue(result, key, baseClone(subValue, isDeep, customizer, key, value, stack));
2286 return isArr ? result : copySymbols(value, result);
2290 * The base implementation of `_.conforms` which doesn't clone `source`.
2293 * @param {Object} source The object of property predicates to conform to.
2294 * @returns {Function} Returns the new function.
2296 function baseConforms(source) {
2297 var props = keys(source),
2298 length = props.length;
2300 return function(object) {
2301 if (object == null) {
2306 var key = props[index],
2307 predicate = source[key],
2308 value = object[key];
2310 if ((value === undefined && !(key in Object(object))) || !predicate(value)) {
2319 * The base implementation of `_.create` without support for assigning
2320 * properties to the created object.
2323 * @param {Object} prototype The object to inherit from.
2324 * @returns {Object} Returns the new object.
2326 var baseCreate = (function() {
2327 function object() {}
2328 return function(prototype) {
2329 if (isObject(prototype)) {
2330 object.prototype = prototype;
2331 var result = new object;
2332 object.prototype = undefined;
2334 return result || {};
2339 * The base implementation of `_.delay` and `_.defer` which accepts an array
2340 * of `func` arguments.
2343 * @param {Function} func The function to delay.
2344 * @param {number} wait The number of milliseconds to delay invocation.
2345 * @param {Object} args The arguments to provide to `func`.
2346 * @returns {number} Returns the timer id.
2348 function baseDelay(func, wait, args) {
2349 if (typeof func != 'function') {
2350 throw new TypeError(FUNC_ERROR_TEXT);
2352 return setTimeout(function() { func.apply(undefined, args); }, wait);
2356 * The base implementation of methods like `_.difference` without support for
2357 * excluding multiple arrays or iteratee shorthands.
2360 * @param {Array} array The array to inspect.
2361 * @param {Array} values The values to exclude.
2362 * @param {Function} [iteratee] The iteratee invoked per element.
2363 * @param {Function} [comparator] The comparator invoked per element.
2364 * @returns {Array} Returns the new array of filtered values.
2366 function baseDifference(array, values, iteratee, comparator) {
2368 includes = arrayIncludes,
2370 length = array.length,
2372 valuesLength = values.length;
2378 values = arrayMap(values, baseUnary(iteratee));
2381 includes = arrayIncludesWith;
2384 else if (values.length >= LARGE_ARRAY_SIZE) {
2385 includes = cacheHas;
2387 values = new SetCache(values);
2390 while (++index < length) {
2391 var value = array[index],
2392 computed = iteratee ? iteratee(value) : value;
2394 if (isCommon && computed === computed) {
2395 var valuesIndex = valuesLength;
2396 while (valuesIndex--) {
2397 if (values[valuesIndex] === computed) {
2403 else if (!includes(values, computed, comparator)) {
2411 * The base implementation of `_.forEach` without support for iteratee shorthands.
2414 * @param {Array|Object} collection The collection to iterate over.
2415 * @param {Function} iteratee The function invoked per iteration.
2416 * @returns {Array|Object} Returns `collection`.
2418 var baseEach = createBaseEach(baseForOwn);
2421 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2424 * @param {Array|Object} collection The collection to iterate over.
2425 * @param {Function} iteratee The function invoked per iteration.
2426 * @returns {Array|Object} Returns `collection`.
2428 var baseEachRight = createBaseEach(baseForOwnRight, true);
2431 * The base implementation of `_.every` without support for iteratee shorthands.
2434 * @param {Array|Object} collection The collection to iterate over.
2435 * @param {Function} predicate The function invoked per iteration.
2436 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
2438 function baseEvery(collection, predicate) {
2440 baseEach(collection, function(value, index, collection) {
2441 result = !!predicate(value, index, collection);
2448 * The base implementation of `_.fill` without an iteratee call guard.
2451 * @param {Array} array The array to fill.
2452 * @param {*} value The value to fill `array` with.
2453 * @param {number} [start=0] The start position.
2454 * @param {number} [end=array.length] The end position.
2455 * @returns {Array} Returns `array`.
2457 function baseFill(array, value, start, end) {
2458 var length = array.length;
2460 start = toInteger(start);
2462 start = -start > length ? 0 : (length + start);
2464 end = (end === undefined || end > length) ? length : toInteger(end);
2468 end = start > end ? 0 : toLength(end);
2469 while (start < end) {
2470 array[start++] = value;
2476 * The base implementation of `_.filter` without support for iteratee shorthands.
2479 * @param {Array|Object} collection The collection to iterate over.
2480 * @param {Function} predicate The function invoked per iteration.
2481 * @returns {Array} Returns the new filtered array.
2483 function baseFilter(collection, predicate) {
2485 baseEach(collection, function(value, index, collection) {
2486 if (predicate(value, index, collection)) {
2494 * The base implementation of `_.flatten` with support for restricting flattening.
2497 * @param {Array} array The array to flatten.
2498 * @param {boolean} [isDeep] Specify a deep flatten.
2499 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
2500 * @param {Array} [result=[]] The initial result value.
2501 * @returns {Array} Returns the new flattened array.
2503 function baseFlatten(array, isDeep, isStrict, result) {
2504 result || (result = []);
2507 length = array.length;
2509 while (++index < length) {
2510 var value = array[index];
2511 if (isArrayLikeObject(value) &&
2512 (isStrict || isArray(value) || isArguments(value))) {
2514 // Recursively flatten arrays (susceptible to call stack limits).
2515 baseFlatten(value, isDeep, isStrict, result);
2517 arrayPush(result, value);
2519 } else if (!isStrict) {
2520 result[result.length] = value;
2527 * The base implementation of `baseForIn` and `baseForOwn` which iterates
2528 * over `object` properties returned by `keysFunc` invoking `iteratee` for
2529 * each property. Iteratee functions may exit iteration early by explicitly
2530 * returning `false`.
2533 * @param {Object} object The object to iterate over.
2534 * @param {Function} iteratee The function invoked per iteration.
2535 * @param {Function} keysFunc The function to get the keys of `object`.
2536 * @returns {Object} Returns `object`.
2538 var baseFor = createBaseFor();
2541 * This function is like `baseFor` except that it iterates over properties
2542 * in the opposite order.
2545 * @param {Object} object The object to iterate over.
2546 * @param {Function} iteratee The function invoked per iteration.
2547 * @param {Function} keysFunc The function to get the keys of `object`.
2548 * @returns {Object} Returns `object`.
2550 var baseForRight = createBaseFor(true);
2553 * The base implementation of `_.forIn` without support for iteratee shorthands.
2556 * @param {Object} object The object to iterate over.
2557 * @param {Function} iteratee The function invoked per iteration.
2558 * @returns {Object} Returns `object`.
2560 function baseForIn(object, iteratee) {
2561 return object == null ? object : baseFor(object, iteratee, keysIn);
2565 * The base implementation of `_.forOwn` without support for iteratee shorthands.
2568 * @param {Object} object The object to iterate over.
2569 * @param {Function} iteratee The function invoked per iteration.
2570 * @returns {Object} Returns `object`.
2572 function baseForOwn(object, iteratee) {
2573 return object && baseFor(object, iteratee, keys);
2577 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
2580 * @param {Object} object The object to iterate over.
2581 * @param {Function} iteratee The function invoked per iteration.
2582 * @returns {Object} Returns `object`.
2584 function baseForOwnRight(object, iteratee) {
2585 return object && baseForRight(object, iteratee, keys);
2589 * The base implementation of `_.functions` which creates an array of
2590 * `object` function property names filtered from `props`.
2593 * @param {Object} object The object to inspect.
2594 * @param {Array} props The property names to filter.
2595 * @returns {Array} Returns the new array of filtered property names.
2597 function baseFunctions(object, props) {
2598 return arrayFilter(props, function(key) {
2599 return isFunction(object[key]);
2604 * The base implementation of `_.get` without support for default values.
2607 * @param {Object} object The object to query.
2608 * @param {Array|string} path The path of the property to get.
2609 * @returns {*} Returns the resolved value.
2611 function baseGet(object, path) {
2612 path = isKey(path, object) ? [path + ''] : baseToPath(path);
2615 length = path.length;
2617 while (object != null && index < length) {
2618 object = object[path[index++]];
2620 return (index && index == length) ? object : undefined;
2624 * The base implementation of `_.has` without support for deep paths.
2627 * @param {Object} object The object to query.
2628 * @param {Array|string} key The key to check.
2629 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2631 function baseHas(object, key) {
2632 // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
2633 // that are composed entirely of index properties, return `false` for
2634 // `hasOwnProperty` checks of them.
2635 return hasOwnProperty.call(object, key) ||
2636 (typeof object == 'object' && key in object && getPrototypeOf(object) === null);
2640 * The base implementation of `_.hasIn` without support for deep paths.
2643 * @param {Object} object The object to query.
2644 * @param {Array|string} key The key to check.
2645 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2647 function baseHasIn(object, key) {
2648 return key in Object(object);
2652 * The base implementation of `_.inRange` which doesn't coerce arguments to numbers.
2655 * @param {number} number The number to check.
2656 * @param {number} start The start of the range.
2657 * @param {number} end The end of the range.
2658 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
2660 function baseInRange(number, start, end) {
2661 return number >= nativeMin(start, end) && number < nativeMax(start, end);
2665 * The base implementation of methods like `_.intersection`, without support
2666 * for iteratee shorthands, that accepts an array of arrays to inspect.
2669 * @param {Array} arrays The arrays to inspect.
2670 * @param {Function} [iteratee] The iteratee invoked per element.
2671 * @param {Function} [comparator] The comparator invoked per element.
2672 * @returns {Array} Returns the new array of shared values.
2674 function baseIntersection(arrays, iteratee, comparator) {
2675 var includes = comparator ? arrayIncludesWith : arrayIncludes,
2676 othLength = arrays.length,
2677 othIndex = othLength,
2678 caches = Array(othLength),
2681 while (othIndex--) {
2682 var array = arrays[othIndex];
2683 if (othIndex && iteratee) {
2684 array = arrayMap(array, baseUnary(iteratee));
2686 caches[othIndex] = !comparator && (iteratee || array.length >= 120)
2687 ? new SetCache(othIndex && array)
2693 length = array.length,
2697 while (++index < length) {
2698 var value = array[index],
2699 computed = iteratee ? iteratee(value) : value;
2701 if (!(seen ? cacheHas(seen, computed) : includes(result, computed, comparator))) {
2702 var othIndex = othLength;
2703 while (--othIndex) {
2704 var cache = caches[othIndex];
2705 if (!(cache ? cacheHas(cache, computed) : includes(arrays[othIndex], computed, comparator))) {
2710 seen.push(computed);
2719 * The base implementation of `_.invert` and `_.invertBy` which inverts
2720 * `object` with values transformed by `iteratee` and set by `setter`.
2723 * @param {Object} object The object to iterate over.
2724 * @param {Function} setter The function to set `accumulator` values.
2725 * @param {Function} iteratee The iteratee to transform values.
2726 * @param {Object} accumulator The initial inverted object.
2727 * @returns {Function} Returns `accumulator`.
2729 function baseInverter(object, setter, iteratee, accumulator) {
2730 baseForOwn(object, function(value, key, object) {
2731 setter(accumulator, iteratee(value), key, object);
2737 * The base implementation of `_.invoke` without support for individual
2741 * @param {Object} object The object to query.
2742 * @param {Array|string} path The path of the method to invoke.
2743 * @param {Array} args The arguments to invoke the method with.
2744 * @returns {*} Returns the result of the invoked method.
2746 function baseInvoke(object, path, args) {
2747 if (!isKey(path, object)) {
2748 path = baseToPath(path);
2749 object = parent(object, path);
2752 var func = object == null ? object : object[path];
2753 return func == null ? undefined : apply(func, object, args);
2757 * The base implementation of `_.isEqual` which supports partial comparisons
2758 * and tracks traversed objects.
2761 * @param {*} value The value to compare.
2762 * @param {*} other The other value to compare.
2763 * @param {Function} [customizer] The function to customize comparisons.
2764 * @param {boolean} [bitmask] The bitmask of comparison flags.
2765 * The bitmask may be composed of the following flags:
2766 * 1 - Unordered comparison
2767 * 2 - Partial comparison
2768 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
2769 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2771 function baseIsEqual(value, other, customizer, bitmask, stack) {
2772 if (value === other) {
2775 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
2776 return value !== value && other !== other;
2778 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
2782 * A specialized version of `baseIsEqual` for arrays and objects which performs
2783 * deep comparisons and tracks traversed objects enabling objects with circular
2784 * references to be compared.
2787 * @param {Object} object The object to compare.
2788 * @param {Object} other The other object to compare.
2789 * @param {Function} equalFunc The function to determine equivalents of values.
2790 * @param {Function} [customizer] The function to customize comparisons.
2791 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
2792 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
2793 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2795 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
2796 var objIsArr = isArray(object),
2797 othIsArr = isArray(other),
2802 objTag = getTag(object);
2803 if (objTag == argsTag) {
2805 } else if (objTag != objectTag) {
2806 objIsArr = isTypedArray(object);
2810 othTag = getTag(other);
2811 if (othTag == argsTag) {
2813 } else if (othTag != objectTag) {
2814 othIsArr = isTypedArray(other);
2817 var objIsObj = objTag == objectTag && !isHostObject(object),
2818 othIsObj = othTag == objectTag && !isHostObject(other),
2819 isSameTag = objTag == othTag;
2821 if (isSameTag && !(objIsArr || objIsObj)) {
2822 return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
2824 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
2826 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2827 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2829 if (objIsWrapped || othIsWrapped) {
2830 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
2836 stack || (stack = new Stack);
2837 return (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
2841 * The base implementation of `_.isMatch` without support for iteratee shorthands.
2844 * @param {Object} object The object to inspect.
2845 * @param {Object} source The object of property values to match.
2846 * @param {Array} matchData The property names, values, and compare flags to match.
2847 * @param {Function} [customizer] The function to customize comparisons.
2848 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2850 function baseIsMatch(object, source, matchData, customizer) {
2851 var index = matchData.length,
2853 noCustomizer = !customizer;
2855 if (object == null) {
2858 object = Object(object);
2860 var data = matchData[index];
2861 if ((noCustomizer && data[2])
2862 ? data[1] !== object[data[0]]
2863 : !(data[0] in object)
2868 while (++index < length) {
2869 data = matchData[index];
2871 objValue = object[key],
2874 if (noCustomizer && data[2]) {
2875 if (objValue === undefined && !(key in object)) {
2879 var stack = new Stack,
2880 result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined;
2882 if (!(result === undefined
2883 ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
2894 * The base implementation of `_.iteratee`.
2897 * @param {*} [value=_.identity] The value to convert to an iteratee.
2898 * @returns {Function} Returns the iteratee.
2900 function baseIteratee(value) {
2901 var type = typeof value;
2902 if (type == 'function') {
2905 if (value == null) {
2908 if (type == 'object') {
2909 return isArray(value)
2910 ? baseMatchesProperty(value[0], value[1])
2911 : baseMatches(value);
2913 return property(value);
2917 * The base implementation of `_.keys` which doesn't skip the constructor
2918 * property of prototypes or treat sparse arrays as dense.
2922 * @param {Object} object The object to query.
2923 * @returns {Array} Returns the array of property names.
2925 function baseKeys(object) {
2926 return nativeKeys(Object(object));
2930 * The base implementation of `_.keysIn` which doesn't skip the constructor
2931 * property of prototypes or treat sparse arrays as dense.
2934 * @param {Object} object The object to query.
2935 * @returns {Array} Returns the array of property names.
2937 function baseKeysIn(object) {
2938 object = object == null ? object : Object(object);
2941 for (var key in object) {
2947 // Fallback for IE < 9 with es6-shim.
2948 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
2949 baseKeysIn = function(object) {
2950 return iteratorToArray(enumerate(object));
2955 * The base implementation of `_.map` without support for iteratee shorthands.
2958 * @param {Array|Object} collection The collection to iterate over.
2959 * @param {Function} iteratee The function invoked per iteration.
2960 * @returns {Array} Returns the new mapped array.
2962 function baseMap(collection, iteratee) {
2964 result = isArrayLike(collection) ? Array(collection.length) : [];
2966 baseEach(collection, function(value, key, collection) {
2967 result[++index] = iteratee(value, key, collection);
2973 * The base implementation of `_.matches` which doesn't clone `source`.
2976 * @param {Object} source The object of property values to match.
2977 * @returns {Function} Returns the new function.
2979 function baseMatches(source) {
2980 var matchData = getMatchData(source);
2981 if (matchData.length == 1 && matchData[0][2]) {
2982 var key = matchData[0][0],
2983 value = matchData[0][1];
2985 return function(object) {
2986 if (object == null) {
2989 return object[key] === value &&
2990 (value !== undefined || (key in Object(object)));
2993 return function(object) {
2994 return object === source || baseIsMatch(object, source, matchData);
2999 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3002 * @param {string} path The path of the property to get.
3003 * @param {*} srcValue The value to match.
3004 * @returns {Function} Returns the new function.
3006 function baseMatchesProperty(path, srcValue) {
3007 return function(object) {
3008 var objValue = get(object, path);
3009 return (objValue === undefined && objValue === srcValue)
3010 ? hasIn(object, path)
3011 : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
3016 * The base implementation of `_.merge` without support for multiple sources.
3019 * @param {Object} object The destination object.
3020 * @param {Object} source The source object.
3021 * @param {number} srcIndex The index of `source`.
3022 * @param {Function} [customizer] The function to customize merged values.
3023 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
3025 function baseMerge(object, source, srcIndex, customizer, stack) {
3026 if (object === source) {
3029 var props = (isArray(source) || isTypedArray(source)) ? undefined : keysIn(source);
3030 arrayEach(props || source, function(srcValue, key) {
3033 srcValue = source[key];
3035 if (isObject(srcValue)) {
3036 stack || (stack = new Stack);
3037 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3040 var newValue = customizer ? customizer(object[key], srcValue, (key + ''), object, source, stack) : undefined;
3041 if (newValue === undefined) {
3042 newValue = srcValue;
3044 assignMergeValue(object, key, newValue);
3050 * A specialized version of `baseMerge` for arrays and objects which performs
3051 * deep merges and tracks traversed objects enabling objects with circular
3052 * references to be merged.
3055 * @param {Object} object The destination object.
3056 * @param {Object} source The source object.
3057 * @param {string} key The key of the value to merge.
3058 * @param {number} srcIndex The index of `source`.
3059 * @param {Function} mergeFunc The function to merge values.
3060 * @param {Function} [customizer] The function to customize assigned values.
3061 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
3063 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3064 var objValue = object[key],
3065 srcValue = source[key],
3066 stacked = stack.get(srcValue);
3069 assignMergeValue(object, key, stacked);
3072 var newValue = customizer ? customizer(objValue, srcValue, (key + ''), object, source, stack) : undefined,
3073 isCommon = newValue === undefined;
3076 newValue = srcValue;
3077 if (isArray(srcValue) || isTypedArray(srcValue)) {
3078 if (isArray(objValue)) {
3079 newValue = srcIndex ? copyArray(objValue) : objValue;
3081 else if (isArrayLikeObject(objValue)) {
3082 newValue = copyArray(objValue);
3086 newValue = baseClone(srcValue);
3089 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3090 if (isArguments(objValue)) {
3091 newValue = toPlainObject(objValue);
3093 else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
3095 newValue = baseClone(srcValue);
3098 newValue = srcIndex ? baseClone(objValue) : objValue;
3105 stack.set(srcValue, newValue);
3108 // Recursively merge objects and arrays (susceptible to call stack limits).
3109 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3111 assignMergeValue(object, key, newValue);
3115 * The base implementation of `_.orderBy` without param guards.
3118 * @param {Array|Object} collection The collection to iterate over.
3119 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3120 * @param {string[]} orders The sort orders of `iteratees`.
3121 * @returns {Array} Returns the new sorted array.
3123 function baseOrderBy(collection, iteratees, orders) {
3125 toIteratee = getIteratee();
3127 iteratees = arrayMap(iteratees.length ? iteratees : Array(1), function(iteratee) {
3128 return toIteratee(iteratee);
3131 var result = baseMap(collection, function(value, key, collection) {
3132 var criteria = arrayMap(iteratees, function(iteratee) {
3133 return iteratee(value);
3135 return { 'criteria': criteria, 'index': ++index, 'value': value };
3138 return baseSortBy(result, function(object, other) {
3139 return compareMultiple(object, other, orders);
3144 * The base implementation of `_.pick` without support for individual
3148 * @param {Object} object The source object.
3149 * @param {string[]} props The property names to pick.
3150 * @returns {Object} Returns the new object.
3152 function basePick(object, props) {
3153 object = Object(object);
3154 return arrayReduce(props, function(result, key) {
3155 if (key in object) {
3156 result[key] = object[key];
3163 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3166 * @param {Object} object The source object.
3167 * @param {Function} predicate The function invoked per property.
3168 * @returns {Object} Returns the new object.
3170 function basePickBy(object, predicate) {
3172 baseForIn(object, function(value, key) {
3173 if (predicate(value, key)) {
3174 result[key] = value;
3181 * The base implementation of `_.property` without support for deep paths.
3184 * @param {string} key The key of the property to get.
3185 * @returns {Function} Returns the new function.
3187 function baseProperty(key) {
3188 return function(object) {
3189 return object == null ? undefined : object[key];
3194 * A specialized version of `baseProperty` which supports deep paths.
3197 * @param {Array|string} path The path of the property to get.
3198 * @returns {Function} Returns the new function.
3200 function basePropertyDeep(path) {
3201 return function(object) {
3202 return baseGet(object, path);
3207 * The base implementation of `_.pullAll`.
3210 * @param {Array} array The array to modify.
3211 * @param {Array} values The values to remove.
3212 * @returns {Array} Returns `array`.
3214 function basePullAll(array, values) {
3215 return basePullAllBy(array, values);
3219 * The base implementation of `_.pullAllBy` without support for iteratee
3223 * @param {Array} array The array to modify.
3224 * @param {Array} values The values to remove.
3225 * @param {Function} [iteratee] The iteratee invoked per element.
3226 * @returns {Array} Returns `array`.
3228 function basePullAllBy(array, values, iteratee) {
3230 length = values.length,
3234 seen = arrayMap(array, function(value) { return iteratee(value); });
3236 while (++index < length) {
3238 value = values[index],
3239 computed = iteratee ? iteratee(value) : value;
3241 while ((fromIndex = baseIndexOf(seen, computed, fromIndex)) > -1) {
3242 if (seen !== array) {
3243 splice.call(seen, fromIndex, 1);
3245 splice.call(array, fromIndex, 1);
3252 * The base implementation of `_.pullAt` without support for individual
3253 * indexes or capturing the removed elements.
3256 * @param {Array} array The array to modify.
3257 * @param {number[]} indexes The indexes of elements to remove.
3258 * @returns {Array} Returns `array`.
3260 function basePullAt(array, indexes) {
3261 var length = array ? indexes.length : 0,
3262 lastIndex = length - 1;
3265 var index = indexes[length];
3266 if (lastIndex == length || index != previous) {
3267 var previous = index;
3268 if (isIndex(index)) {
3269 splice.call(array, index, 1);
3271 else if (!isKey(index, array)) {
3272 var path = baseToPath(index),
3273 object = parent(array, path);
3275 if (object != null) {
3276 delete object[last(path)];
3280 delete array[index];
3288 * The base implementation of `_.random` without support for returning
3289 * floating-point numbers.
3292 * @param {number} lower The lower bound.
3293 * @param {number} upper The upper bound.
3294 * @returns {number} Returns the random number.
3296 function baseRandom(lower, upper) {
3297 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3301 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3302 * coerce arguments to numbers.
3305 * @param {number} start The start of the range.
3306 * @param {number} end The end of the range.
3307 * @param {number} step The value to increment or decrement by.
3308 * @param {boolean} [fromRight] Specify iterating from right to left.
3309 * @returns {Array} Returns the new array of numbers.
3311 function baseRange(start, end, step, fromRight) {
3313 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3314 result = Array(length);
3317 result[fromRight ? length : ++index] = start;
3324 * The base implementation of `_.set`.
3327 * @param {Object} object The object to query.
3328 * @param {Array|string} path The path of the property to set.
3329 * @param {*} value The value to set.
3330 * @param {Function} [customizer] The function to customize path creation.
3331 * @returns {Object} Returns `object`.
3333 function baseSet(object, path, value, customizer) {
3334 path = isKey(path, object) ? [path + ''] : baseToPath(path);
3337 length = path.length,
3338 lastIndex = length - 1,
3341 while (nested != null && ++index < length) {
3342 var key = path[index];
3343 if (isObject(nested)) {
3344 var newValue = value;
3345 if (index != lastIndex) {
3346 var objValue = nested[key];
3347 newValue = customizer ? customizer(objValue, key, nested) : undefined;
3348 if (newValue === undefined) {
3349 newValue = objValue == null ? (isIndex(path[index + 1]) ? [] : {}) : objValue;
3352 assignValue(nested, key, newValue);
3354 nested = nested[key];
3360 * The base implementation of `setData` without support for hot loop detection.
3363 * @param {Function} func The function to associate metadata with.
3364 * @param {*} data The metadata.
3365 * @returns {Function} Returns `func`.
3367 var baseSetData = !metaMap ? identity : function(func, data) {
3368 metaMap.set(func, data);
3373 * The base implementation of `_.slice` without an iteratee call guard.
3376 * @param {Array} array The array to slice.
3377 * @param {number} [start=0] The start position.
3378 * @param {number} [end=array.length] The end position.
3379 * @returns {Array} Returns the slice of `array`.
3381 function baseSlice(array, start, end) {
3383 length = array.length;
3386 start = -start > length ? 0 : (length + start);
3388 end = end > length ? length : end;
3392 length = start > end ? 0 : ((end - start) >>> 0);
3395 var result = Array(length);
3396 while (++index < length) {
3397 result[index] = array[index + start];
3403 * The base implementation of `_.some` without support for iteratee shorthands.
3406 * @param {Array|Object} collection The collection to iterate over.
3407 * @param {Function} predicate The function invoked per iteration.
3408 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
3410 function baseSome(collection, predicate) {
3413 baseEach(collection, function(value, index, collection) {
3414 result = predicate(value, index, collection);
3421 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
3422 * performs a binary search of `array` to determine the index at which `value`
3423 * should be inserted into `array` in order to maintain its sort order.
3426 * @param {Array} array The sorted array to inspect.
3427 * @param {*} value The value to evaluate.
3428 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3429 * @returns {number} Returns the index at which `value` should be inserted
3432 function baseSortedIndex(array, value, retHighest) {
3434 high = array ? array.length : low;
3436 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
3437 while (low < high) {
3438 var mid = (low + high) >>> 1,
3439 computed = array[mid];
3441 if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
3449 return baseSortedIndexBy(array, value, identity, retHighest);
3453 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
3454 * which invokes `iteratee` for `value` and each element of `array` to compute
3455 * their sort ranking. The iteratee is invoked with one argument; (value).
3458 * @param {Array} array The sorted array to inspect.
3459 * @param {*} value The value to evaluate.
3460 * @param {Function} iteratee The iteratee invoked per element.
3461 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3462 * @returns {number} Returns the index at which `value` should be inserted into `array`.
3464 function baseSortedIndexBy(array, value, iteratee, retHighest) {
3465 value = iteratee(value);
3468 high = array ? array.length : 0,
3469 valIsNaN = value !== value,
3470 valIsNull = value === null,
3471 valIsUndef = value === undefined;
3473 while (low < high) {
3474 var mid = nativeFloor((low + high) / 2),
3475 computed = iteratee(array[mid]),
3476 isDef = computed !== undefined,
3477 isReflexive = computed === computed;
3480 var setLow = isReflexive || retHighest;
3481 } else if (valIsNull) {
3482 setLow = isReflexive && isDef && (retHighest || computed != null);
3483 } else if (valIsUndef) {
3484 setLow = isReflexive && (retHighest || isDef);
3485 } else if (computed == null) {
3488 setLow = retHighest ? (computed <= value) : (computed < value);
3496 return nativeMin(high, MAX_ARRAY_INDEX);
3500 * The base implementation of `_.sortedUniq`.
3503 * @param {Array} array The array to inspect.
3504 * @returns {Array} Returns the new duplicate free array.
3506 function baseSortedUniq(array) {
3507 return baseSortedUniqBy(array);
3511 * The base implementation of `_.sortedUniqBy` without support for iteratee
3515 * @param {Array} array The array to inspect.
3516 * @param {Function} [iteratee] The iteratee invoked per element.
3517 * @returns {Array} Returns the new duplicate free array.
3519 function baseSortedUniqBy(array, iteratee) {
3521 length = array.length,
3523 computed = iteratee ? iteratee(value) : value,
3528 while (++index < length) {
3529 value = array[index],
3530 computed = iteratee ? iteratee(value) : value;
3532 if (!eq(computed, seen)) {
3534 result[++resIndex] = value;
3541 * The base implementation of `_.toPath` which only converts `value` to a
3542 * path if it's not one.
3545 * @param {*} value The value to process.
3546 * @returns {Array} Returns the property path array.
3548 function baseToPath(value) {
3549 return isArray(value) ? value : stringToPath(value);
3553 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
3556 * @param {Array} array The array to inspect.
3557 * @param {Function} [iteratee] The iteratee invoked per element.
3558 * @param {Function} [comparator] The comparator invoked per element.
3559 * @returns {Array} Returns the new duplicate free array.
3561 function baseUniq(array, iteratee, comparator) {
3563 includes = arrayIncludes,
3564 length = array.length,
3571 includes = arrayIncludesWith;
3573 else if (length >= LARGE_ARRAY_SIZE) {
3574 var set = iteratee ? null : createSet(array);
3576 return setToArray(set);
3579 includes = cacheHas;
3580 seen = new SetCache;
3583 seen = iteratee ? [] : result;
3586 while (++index < length) {
3587 var value = array[index],
3588 computed = iteratee ? iteratee(value) : value;
3590 if (isCommon && computed === computed) {
3591 var seenIndex = seen.length;
3592 while (seenIndex--) {
3593 if (seen[seenIndex] === computed) {
3598 seen.push(computed);
3602 else if (!includes(seen, computed, comparator)) {
3603 if (seen !== result) {
3604 seen.push(computed);
3613 * The base implementation of `_.unset`.
3616 * @param {Object} object The object to modify.
3617 * @param {Array|string} path The path of the property to unset.
3618 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
3620 function baseUnset(object, path) {
3621 path = isKey(path, object) ? [path + ''] : baseToPath(path);
3622 object = parent(object, path);
3623 var key = last(path);
3624 return (object != null && has(object, key)) ? delete object[key] : true;
3628 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
3629 * without support for iteratee shorthands.
3632 * @param {Array} array The array to query.
3633 * @param {Function} predicate The function invoked per iteration.
3634 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
3635 * @param {boolean} [fromRight] Specify iterating from right to left.
3636 * @returns {Array} Returns the slice of `array`.
3638 function baseWhile(array, predicate, isDrop, fromRight) {
3639 var length = array.length,
3640 index = fromRight ? length : -1;
3642 while ((fromRight ? index-- : ++index < length) &&
3643 predicate(array[index], index, array)) {}
3646 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
3647 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
3651 * The base implementation of `wrapperValue` which returns the result of
3652 * performing a sequence of actions on the unwrapped `value`, where each
3653 * successive action is supplied the return value of the previous.
3656 * @param {*} value The unwrapped value.
3657 * @param {Array} actions Actions to perform to resolve the unwrapped value.
3658 * @returns {*} Returns the resolved value.
3660 function baseWrapperValue(value, actions) {
3662 if (result instanceof LazyWrapper) {
3663 result = result.value();
3665 return arrayReduce(actions, function(result, action) {
3666 return action.func.apply(action.thisArg, arrayPush([result], action.args));
3671 * The base implementation of methods like `_.xor`, without support for
3672 * iteratee shorthands, that accepts an array of arrays to inspect.
3675 * @param {Array} arrays The arrays to inspect.
3676 * @param {Function} [iteratee] The iteratee invoked per element.
3677 * @param {Function} [comparator] The comparator invoked per element.
3678 * @returns {Array} Returns the new array of values.
3680 function baseXor(arrays, iteratee, comparator) {
3682 length = arrays.length;
3684 while (++index < length) {
3687 baseDifference(result, arrays[index], iteratee, comparator),
3688 baseDifference(arrays[index], result, iteratee, comparator)
3692 return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
3696 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
3699 * @param {Array} props The property names.
3700 * @param {Array} values The property values.
3701 * @param {Function} assignFunc The function to assign values.
3702 * @returns {Object} Returns the new object.
3704 function baseZipObject(props, values, assignFunc) {
3706 length = props.length,
3707 valsLength = values.length,
3710 while (++index < length) {
3711 assignFunc(result, props[index], index < valsLength ? values[index] : undefined);
3717 * Creates a clone of `buffer`.
3720 * @param {Buffer} buffer The buffer to clone.
3721 * @param {boolean} [isDeep] Specify a deep clone.
3722 * @returns {Buffer} Returns the cloned buffer.
3724 function cloneBuffer(buffer, isDeep) {
3726 return buffer.slice();
3728 var Ctor = buffer.constructor,
3729 result = new Ctor(buffer.length);
3731 buffer.copy(result);
3736 * Creates a clone of `arrayBuffer`.
3739 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
3740 * @returns {ArrayBuffer} Returns the cloned array buffer.
3742 function cloneArrayBuffer(arrayBuffer) {
3743 var Ctor = arrayBuffer.constructor,
3744 result = new Ctor(arrayBuffer.byteLength),
3745 view = new Uint8Array(result);
3747 view.set(new Uint8Array(arrayBuffer));
3752 * Creates a clone of `map`.
3755 * @param {Object} map The map to clone.
3756 * @returns {Object} Returns the cloned map.
3758 function cloneMap(map) {
3759 var Ctor = map.constructor;
3760 return arrayReduce(mapToArray(map), addMapEntry, new Ctor);
3764 * Creates a clone of `regexp`.
3767 * @param {Object} regexp The regexp to clone.
3768 * @returns {Object} Returns the cloned regexp.
3770 function cloneRegExp(regexp) {
3771 var Ctor = regexp.constructor,
3772 result = new Ctor(regexp.source, reFlags.exec(regexp));
3774 result.lastIndex = regexp.lastIndex;
3779 * Creates a clone of `set`.
3782 * @param {Object} set The set to clone.
3783 * @returns {Object} Returns the cloned set.
3785 function cloneSet(set) {
3786 var Ctor = set.constructor;
3787 return arrayReduce(setToArray(set), addSetEntry, new Ctor);
3791 * Creates a clone of the `symbol` object.
3794 * @param {Object} symbol The symbol object to clone.
3795 * @returns {Object} Returns the cloned symbol object.
3797 function cloneSymbol(symbol) {
3798 return Symbol ? Object(symbolValueOf.call(symbol)) : {};
3802 * Creates a clone of `typedArray`.
3805 * @param {Object} typedArray The typed array to clone.
3806 * @param {boolean} [isDeep] Specify a deep clone.
3807 * @returns {Object} Returns the cloned typed array.
3809 function cloneTypedArray(typedArray, isDeep) {
3810 var buffer = typedArray.buffer,
3811 Ctor = typedArray.constructor;
3813 return new Ctor(isDeep ? cloneArrayBuffer(buffer) : buffer, typedArray.byteOffset, typedArray.length);
3817 * Creates an array that is the composition of partially applied arguments,
3818 * placeholders, and provided arguments into a single array of arguments.
3821 * @param {Array|Object} args The provided arguments.
3822 * @param {Array} partials The arguments to prepend to those provided.
3823 * @param {Array} holders The `partials` placeholder indexes.
3824 * @returns {Array} Returns the new array of composed arguments.
3826 function composeArgs(args, partials, holders) {
3827 var holdersLength = holders.length,
3829 argsLength = nativeMax(args.length - holdersLength, 0),
3831 leftLength = partials.length,
3832 result = Array(leftLength + argsLength);
3834 while (++leftIndex < leftLength) {
3835 result[leftIndex] = partials[leftIndex];
3837 while (++argsIndex < holdersLength) {
3838 result[holders[argsIndex]] = args[argsIndex];
3840 while (argsLength--) {
3841 result[leftIndex++] = args[argsIndex++];
3847 * This function is like `composeArgs` except that the arguments composition
3848 * is tailored for `_.partialRight`.
3851 * @param {Array|Object} args The provided arguments.
3852 * @param {Array} partials The arguments to append to those provided.
3853 * @param {Array} holders The `partials` placeholder indexes.
3854 * @returns {Array} Returns the new array of composed arguments.
3856 function composeArgsRight(args, partials, holders) {
3857 var holdersIndex = -1,
3858 holdersLength = holders.length,
3860 argsLength = nativeMax(args.length - holdersLength, 0),
3862 rightLength = partials.length,
3863 result = Array(argsLength + rightLength);
3865 while (++argsIndex < argsLength) {
3866 result[argsIndex] = args[argsIndex];
3868 var offset = argsIndex;
3869 while (++rightIndex < rightLength) {
3870 result[offset + rightIndex] = partials[rightIndex];
3872 while (++holdersIndex < holdersLength) {
3873 result[offset + holders[holdersIndex]] = args[argsIndex++];
3879 * Copies the values of `source` to `array`.
3882 * @param {Array} source The array to copy values from.
3883 * @param {Array} [array=[]] The array to copy values to.
3884 * @returns {Array} Returns `array`.
3886 function copyArray(source, array) {
3888 length = source.length;
3890 array || (array = Array(length));
3891 while (++index < length) {
3892 array[index] = source[index];
3898 * Copies properties of `source` to `object`.
3901 * @param {Object} source The object to copy properties from.
3902 * @param {Array} props The property names to copy.
3903 * @param {Object} [object={}] The object to copy properties to.
3904 * @returns {Object} Returns `object`.
3906 function copyObject(source, props, object) {
3907 return copyObjectWith(source, props, object);
3911 * This function is like `copyObject` except that it accepts a function to
3912 * customize copied values.
3915 * @param {Object} source The object to copy properties from.
3916 * @param {Array} props The property names to copy.
3917 * @param {Object} [object={}] The object to copy properties to.
3918 * @param {Function} [customizer] The function to customize copied values.
3919 * @returns {Object} Returns `object`.
3921 function copyObjectWith(source, props, object, customizer) {
3922 object || (object = {});
3925 length = props.length;
3927 while (++index < length) {
3928 var key = props[index],
3929 newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
3931 assignValue(object, key, newValue);
3937 * Copies own symbol properties of `source` to `object`.
3940 * @param {Object} source The object to copy symbols from.
3941 * @param {Object} [object={}] The object to copy symbols to.
3942 * @returns {Object} Returns `object`.
3944 function copySymbols(source, object) {
3945 return copyObject(source, getSymbols(source), object);
3949 * Creates a function like `_.groupBy`.
3952 * @param {Function} setter The function to set accumulator values.
3953 * @param {Function} [initializer] The accumulator object initializer.
3954 * @returns {Function} Returns the new aggregator function.
3956 function createAggregator(setter, initializer) {
3957 return function(collection, iteratee) {
3958 var func = isArray(collection) ? arrayAggregator : baseAggregator,
3959 accumulator = initializer ? initializer() : {};
3961 return func(collection, setter, getIteratee(iteratee), accumulator);
3966 * Creates a function like `_.assign`.
3969 * @param {Function} assigner The function to assign values.
3970 * @returns {Function} Returns the new assigner function.
3972 function createAssigner(assigner) {
3973 return rest(function(object, sources) {
3975 length = sources.length,
3976 customizer = length > 1 ? sources[length - 1] : undefined,
3977 guard = length > 2 ? sources[2] : undefined;
3979 customizer = typeof customizer == 'function' ? (length--, customizer) : undefined;
3980 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
3981 customizer = length < 3 ? undefined : customizer;
3984 object = Object(object);
3985 while (++index < length) {
3986 var source = sources[index];
3988 assigner(object, source, index, customizer);
3996 * Creates a `baseEach` or `baseEachRight` function.
3999 * @param {Function} eachFunc The function to iterate over a collection.
4000 * @param {boolean} [fromRight] Specify iterating from right to left.
4001 * @returns {Function} Returns the new base function.
4003 function createBaseEach(eachFunc, fromRight) {
4004 return function(collection, iteratee) {
4005 if (collection == null) {
4008 if (!isArrayLike(collection)) {
4009 return eachFunc(collection, iteratee);
4011 var length = collection.length,
4012 index = fromRight ? length : -1,
4013 iterable = Object(collection);
4015 while ((fromRight ? index-- : ++index < length)) {
4016 if (iteratee(iterable[index], index, iterable) === false) {
4025 * Creates a base function for methods like `_.forIn`.
4028 * @param {boolean} [fromRight] Specify iterating from right to left.
4029 * @returns {Function} Returns the new base function.
4031 function createBaseFor(fromRight) {
4032 return function(object, iteratee, keysFunc) {
4034 iterable = Object(object),
4035 props = keysFunc(object),
4036 length = props.length;
4039 var key = props[fromRight ? length : ++index];
4040 if (iteratee(iterable[key], key, iterable) === false) {
4049 * Creates a function that wraps `func` to invoke it with the optional `this`
4050 * binding of `thisArg`.
4053 * @param {Function} func The function to wrap.
4054 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4055 * @param {*} [thisArg] The `this` binding of `func`.
4056 * @returns {Function} Returns the new wrapped function.
4058 function createBaseWrapper(func, bitmask, thisArg) {
4059 var isBind = bitmask & BIND_FLAG,
4060 Ctor = createCtorWrapper(func);
4062 function wrapper() {
4063 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4064 return fn.apply(isBind ? thisArg : this, arguments);
4070 * Creates a function like `_.lowerFirst`.
4073 * @param {string} methodName The name of the `String` case method to use.
4074 * @returns {Function} Returns the new function.
4076 function createCaseFirst(methodName) {
4077 return function(string) {
4078 string = toString(string);
4080 var strSymbols = reHasComplexSymbol.test(string) ? stringToArray(string) : undefined,
4081 chr = strSymbols ? strSymbols[0] : string.charAt(0),
4082 trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1);
4084 return chr[methodName]() + trailing;
4089 * Creates a function like `_.camelCase`.
4092 * @param {Function} callback The function to combine each word.
4093 * @returns {Function} Returns the new compounder function.
4095 function createCompounder(callback) {
4096 return function(string) {
4097 return arrayReduce(words(deburr(string)), callback, '');
4102 * Creates a function that produces an instance of `Ctor` regardless of
4103 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
4106 * @param {Function} Ctor The constructor to wrap.
4107 * @returns {Function} Returns the new wrapped function.
4109 function createCtorWrapper(Ctor) {
4111 // Use a `switch` statement to work with class constructors.
4112 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
4113 // for more details.
4114 var args = arguments;
4115 switch (args.length) {
4116 case 0: return new Ctor;
4117 case 1: return new Ctor(args[0]);
4118 case 2: return new Ctor(args[0], args[1]);
4119 case 3: return new Ctor(args[0], args[1], args[2]);
4120 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
4121 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
4122 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
4123 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
4125 var thisBinding = baseCreate(Ctor.prototype),
4126 result = Ctor.apply(thisBinding, args);
4128 // Mimic the constructor's `return` behavior.
4129 // See https://es5.github.io/#x13.2.2 for more details.
4130 return isObject(result) ? result : thisBinding;
4135 * Creates a function that wraps `func` to enable currying.
4138 * @param {Function} func The function to wrap.
4139 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4140 * @param {number} arity The arity of `func`.
4141 * @returns {Function} Returns the new wrapped function.
4143 function createCurryWrapper(func, bitmask, arity) {
4144 var Ctor = createCtorWrapper(func);
4146 function wrapper() {
4147 var length = arguments.length,
4149 args = Array(length),
4150 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func,
4151 placeholder = lodash.placeholder || wrapper.placeholder;
4154 args[index] = arguments[index];
4156 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
4158 : replaceHolders(args, placeholder);
4160 length -= holders.length;
4161 return length < arity
4162 ? createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, undefined, args, holders, undefined, undefined, arity - length)
4163 : apply(fn, this, args);
4169 * Creates a `_.flow` or `_.flowRight` function.
4172 * @param {boolean} [fromRight] Specify iterating from right to left.
4173 * @returns {Function} Returns the new flow function.
4175 function createFlow(fromRight) {
4176 return rest(function(funcs) {
4177 funcs = baseFlatten(funcs);
4179 var length = funcs.length,
4181 prereq = LodashWrapper.prototype.thru;
4187 var func = funcs[index];
4188 if (typeof func != 'function') {
4189 throw new TypeError(FUNC_ERROR_TEXT);
4191 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
4192 var wrapper = new LodashWrapper([], true);
4195 index = wrapper ? index : length;
4196 while (++index < length) {
4197 func = funcs[index];
4199 var funcName = getFuncName(func),
4200 data = funcName == 'wrapper' ? getData(func) : undefined;
4202 if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
4203 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
4205 wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
4209 var args = arguments,
4212 if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
4213 return wrapper.plant(value).value();
4216 result = length ? funcs[index].apply(this, args) : value;
4218 while (++index < length) {
4219 result = funcs[index].call(this, result);
4227 * Creates a function that wraps `func` to invoke it with optional `this`
4228 * binding of `thisArg`, partial application, and currying.
4231 * @param {Function|string} func The function or method name to wrap.
4232 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4233 * @param {*} [thisArg] The `this` binding of `func`.
4234 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
4235 * @param {Array} [holders] The `partials` placeholder indexes.
4236 * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
4237 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
4238 * @param {Array} [argPos] The argument positions of the new function.
4239 * @param {number} [ary] The arity cap of `func`.
4240 * @param {number} [arity] The arity of `func`.
4241 * @returns {Function} Returns the new wrapped function.
4243 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
4244 var isAry = bitmask & ARY_FLAG,
4245 isBind = bitmask & BIND_FLAG,
4246 isBindKey = bitmask & BIND_KEY_FLAG,
4247 isCurry = bitmask & CURRY_FLAG,
4248 isCurryRight = bitmask & CURRY_RIGHT_FLAG,
4249 isFlip = bitmask & FLIP_FLAG,
4250 Ctor = isBindKey ? undefined : createCtorWrapper(func);
4252 function wrapper() {
4253 var length = arguments.length,
4255 args = Array(length);
4258 args[index] = arguments[index];
4261 args = composeArgs(args, partials, holders);
4263 if (partialsRight) {
4264 args = composeArgsRight(args, partialsRight, holdersRight);
4266 if (isCurry || isCurryRight) {
4267 var placeholder = lodash.placeholder || wrapper.placeholder,
4268 argsHolders = replaceHolders(args, placeholder);
4270 length -= argsHolders.length;
4271 if (length < arity) {
4272 return createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, thisArg, args, argsHolders, argPos, ary, arity - length);
4275 var thisBinding = isBind ? thisArg : this,
4276 fn = isBindKey ? thisBinding[func] : func;
4279 args = reorder(args, argPos);
4280 } else if (isFlip && args.length > 1) {
4283 if (isAry && ary < args.length) {
4286 if (this && this !== root && this instanceof wrapper) {
4287 fn = Ctor || createCtorWrapper(fn);
4289 return fn.apply(thisBinding, args);
4295 * Creates a function like `_.invertBy`.
4298 * @param {Function} setter The function to set accumulator values.
4299 * @param {Function} toIteratee The function to resolve iteratees.
4300 * @returns {Function} Returns the new inverter function.
4302 function createInverter(setter, toIteratee) {
4303 return function(object, iteratee) {
4304 return baseInverter(object, setter, toIteratee(iteratee), {});
4309 * Creates a function like `_.over`.
4312 * @param {Function} arrayFunc The function to iterate over iteratees.
4313 * @returns {Function} Returns the new invoker function.
4315 function createOver(arrayFunc) {
4316 return rest(function(iteratees) {
4317 iteratees = arrayMap(baseFlatten(iteratees), getIteratee());
4318 return rest(function(args) {
4320 return arrayFunc(iteratees, function(iteratee) {
4321 return apply(iteratee, thisArg, args);
4328 * Creates the padding for `string` based on `length`. The `chars` string
4329 * is truncated if the number of characters exceeds `length`.
4332 * @param {string} string The string to create padding for.
4333 * @param {number} [length=0] The padding length.
4334 * @param {string} [chars=' '] The string used as padding.
4335 * @returns {string} Returns the padding for `string`.
4337 function createPadding(string, length, chars) {
4338 length = toInteger(length);
4340 var strLength = stringSize(string);
4341 if (!length || strLength >= length) {
4344 var padLength = length - strLength;
4345 chars = chars === undefined ? ' ' : (chars + '');
4347 var result = repeat(chars, nativeCeil(padLength / stringSize(chars)));
4348 return reHasComplexSymbol.test(chars)
4349 ? stringToArray(result).slice(0, padLength).join('')
4350 : result.slice(0, padLength);
4354 * Creates a function that wraps `func` to invoke it with the optional `this`
4355 * binding of `thisArg` and the `partials` prepended to those provided to
4359 * @param {Function} func The function to wrap.
4360 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4361 * @param {*} thisArg The `this` binding of `func`.
4362 * @param {Array} partials The arguments to prepend to those provided to the new function.
4363 * @returns {Function} Returns the new wrapped function.
4365 function createPartialWrapper(func, bitmask, thisArg, partials) {
4366 var isBind = bitmask & BIND_FLAG,
4367 Ctor = createCtorWrapper(func);
4369 function wrapper() {
4371 argsLength = arguments.length,
4373 leftLength = partials.length,
4374 args = Array(leftLength + argsLength),
4375 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4377 while (++leftIndex < leftLength) {
4378 args[leftIndex] = partials[leftIndex];
4380 while (argsLength--) {
4381 args[leftIndex++] = arguments[++argsIndex];
4383 return apply(fn, isBind ? thisArg : this, args);
4389 * Creates a `_.range` or `_.rangeRight` function.
4392 * @param {boolean} [fromRight] Specify iterating from right to left.
4393 * @returns {Function} Returns the new range function.
4395 function createRange(fromRight) {
4396 return function(start, end, step) {
4397 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
4398 end = step = undefined;
4400 // Ensure the sign of `-0` is preserved.
4401 start = toNumber(start);
4402 start = start === start ? start : 0;
4403 if (end === undefined) {
4407 end = toNumber(end) || 0;
4409 step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
4410 return baseRange(start, end, step, fromRight);
4415 * Creates a function that wraps `func` to continue currying.
4418 * @param {Function} func The function to wrap.
4419 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
4420 * @param {Function} wrapFunc The function to create the `func` wrapper.
4421 * @param {*} placeholder The placeholder to replace.
4422 * @param {*} [thisArg] The `this` binding of `func`.
4423 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
4424 * @param {Array} [holders] The `partials` placeholder indexes.
4425 * @param {Array} [argPos] The argument positions of the new function.
4426 * @param {number} [ary] The arity cap of `func`.
4427 * @param {number} [arity] The arity of `func`.
4428 * @returns {Function} Returns the new wrapped function.
4430 function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
4431 var isCurry = bitmask & CURRY_FLAG,
4432 newArgPos = argPos ? copyArray(argPos) : undefined,
4433 newsHolders = isCurry ? holders : undefined,
4434 newHoldersRight = isCurry ? undefined : holders,
4435 newPartials = isCurry ? partials : undefined,
4436 newPartialsRight = isCurry ? undefined : partials;
4438 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
4439 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
4441 if (!(bitmask & CURRY_BOUND_FLAG)) {
4442 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
4444 var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, arity],
4445 result = wrapFunc.apply(undefined, newData);
4447 if (isLaziable(func)) {
4448 setData(result, newData);
4450 result.placeholder = placeholder;
4455 * Creates a function like `_.round`.
4458 * @param {string} methodName The name of the `Math` method to use when rounding.
4459 * @returns {Function} Returns the new round function.
4461 function createRound(methodName) {
4462 var func = Math[methodName];
4463 return function(number, precision) {
4464 number = toNumber(number);
4465 precision = toInteger(precision);
4467 // Shift with exponential notation to avoid floating-point issues.
4468 // See [MDN](https://mdn.io/round#Examples) for more details.
4469 var pair = (toString(number) + 'e').split('e'),
4470 value = func(pair[0] + 'e' + (+pair[1] + precision));
4472 pair = (toString(value) + 'e').split('e');
4473 return +(pair[0] + 'e' + (+pair[1] - precision));
4475 return func(number);
4480 * Creates a set of `values`.
4483 * @param {Array} values The values to add to the set.
4484 * @returns {Object} Returns the new set.
4486 var createSet = !(Set && new Set([1, 2]).size === 2) ? noop : function(values) {
4487 return new Set(values);
4491 * Creates a function that either curries or invokes `func` with optional
4492 * `this` binding and partially applied arguments.
4495 * @param {Function|string} func The function or method name to wrap.
4496 * @param {number} bitmask The bitmask of wrapper flags.
4497 * The bitmask may be composed of the following flags:
4500 * 4 - `_.curry` or `_.curryRight` of a bound function
4502 * 16 - `_.curryRight`
4504 * 64 - `_.partialRight`
4507 * @param {*} [thisArg] The `this` binding of `func`.
4508 * @param {Array} [partials] The arguments to be partially applied.
4509 * @param {Array} [holders] The `partials` placeholder indexes.
4510 * @param {Array} [argPos] The argument positions of the new function.
4511 * @param {number} [ary] The arity cap of `func`.
4512 * @param {number} [arity] The arity of `func`.
4513 * @returns {Function} Returns the new wrapped function.
4515 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
4516 var isBindKey = bitmask & BIND_KEY_FLAG;
4517 if (!isBindKey && typeof func != 'function') {
4518 throw new TypeError(FUNC_ERROR_TEXT);
4520 var length = partials ? partials.length : 0;
4522 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
4523 partials = holders = undefined;
4525 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
4526 arity = arity === undefined ? arity : toInteger(arity);
4527 length -= holders ? holders.length : 0;
4529 if (bitmask & PARTIAL_RIGHT_FLAG) {
4530 var partialsRight = partials,
4531 holdersRight = holders;
4533 partials = holders = undefined;
4535 var data = isBindKey ? undefined : getData(func),
4536 newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
4539 mergeData(newData, data);
4542 bitmask = newData[1];
4543 thisArg = newData[2];
4544 partials = newData[3];
4545 holders = newData[4];
4546 arity = newData[9] = newData[9] == null
4547 ? (isBindKey ? 0 : func.length)
4548 : nativeMax(newData[9] - length, 0);
4550 if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
4551 bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
4553 if (!bitmask || bitmask == BIND_FLAG) {
4554 var result = createBaseWrapper(func, bitmask, thisArg);
4555 } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
4556 result = createCurryWrapper(func, bitmask, arity);
4557 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
4558 result = createPartialWrapper(func, bitmask, thisArg, partials);
4560 result = createHybridWrapper.apply(undefined, newData);
4562 var setter = data ? baseSetData : setData;
4563 return setter(result, newData);
4567 * A specialized version of `baseIsEqualDeep` for arrays with support for
4568 * partial deep comparisons.
4571 * @param {Array} array The array to compare.
4572 * @param {Array} other The other array to compare.
4573 * @param {Function} equalFunc The function to determine equivalents of values.
4574 * @param {Function} [customizer] The function to customize comparisons.
4575 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4576 * @param {Object} [stack] Tracks traversed `array` and `other` objects.
4577 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
4579 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
4581 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
4582 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
4583 arrLength = array.length,
4584 othLength = other.length;
4586 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
4589 // Assume cyclic values are equal.
4590 var stacked = stack.get(array);
4592 return stacked == other;
4595 stack.set(array, other);
4597 // Ignore non-index properties.
4598 while (++index < arrLength) {
4599 var arrValue = array[index],
4600 othValue = other[index];
4603 var compared = isPartial
4604 ? customizer(othValue, arrValue, index, other, array, stack)
4605 : customizer(arrValue, othValue, index, array, other, stack);
4607 if (compared !== undefined) {
4614 // Recursively compare arrays (susceptible to call stack limits).
4616 if (!arraySome(other, function(othValue) {
4617 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
4622 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
4627 stack['delete'](array);
4632 * A specialized version of `baseIsEqualDeep` for comparing objects of
4633 * the same `toStringTag`.
4635 * **Note:** This function only supports comparing values with tags of
4636 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4639 * @param {Object} object The object to compare.
4640 * @param {Object} other The other object to compare.
4641 * @param {string} tag The `toStringTag` of the objects to compare.
4642 * @param {Function} equalFunc The function to determine equivalents of values.
4643 * @param {Function} [customizer] The function to customize comparisons.
4644 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4645 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
4647 function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
4649 case arrayBufferTag:
4650 if ((object.byteLength != other.byteLength) ||
4651 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
4658 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
4659 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
4660 return +object == +other;
4663 return object.name == other.name && object.message == other.message;
4666 // Treat `NaN` vs. `NaN` as equal.
4667 return (object != +object) ? other != +other : object == +other;
4671 // Coerce regexes to strings and treat strings primitives and string
4672 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
4673 return object == (other + '');
4676 var convert = mapToArray;
4679 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
4680 convert || (convert = setToArray);
4682 // Recursively compare objects (susceptible to call stack limits).
4683 return (isPartial || object.size == other.size) &&
4684 equalFunc(convert(object), convert(other), customizer, bitmask | UNORDERED_COMPARE_FLAG);
4687 return !!Symbol && (symbolValueOf.call(object) == symbolValueOf.call(other));
4693 * A specialized version of `baseIsEqualDeep` for objects with support for
4694 * partial deep comparisons.
4697 * @param {Object} object The object to compare.
4698 * @param {Object} other The other object to compare.
4699 * @param {Function} equalFunc The function to determine equivalents of values.
4700 * @param {Function} [customizer] The function to customize comparisons.
4701 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
4702 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
4703 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
4705 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
4706 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
4707 objProps = keys(object),
4708 objLength = objProps.length,
4709 othProps = keys(other),
4710 othLength = othProps.length;
4712 if (objLength != othLength && !isPartial) {
4715 var index = objLength;
4717 var key = objProps[index];
4718 if (!(isPartial ? key in other : baseHas(other, key))) {
4722 // Assume cyclic values are equal.
4723 var stacked = stack.get(object);
4725 return stacked == other;
4728 stack.set(object, other);
4730 var skipCtor = isPartial;
4731 while (++index < objLength) {
4732 key = objProps[index];
4733 var objValue = object[key],
4734 othValue = other[key];
4737 var compared = isPartial
4738 ? customizer(othValue, objValue, key, other, object, stack)
4739 : customizer(objValue, othValue, key, object, other, stack);
4741 // Recursively compare objects (susceptible to call stack limits).
4742 if (!(compared === undefined
4743 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
4749 skipCtor || (skipCtor = key == 'constructor');
4751 if (result && !skipCtor) {
4752 var objCtor = object.constructor,
4753 othCtor = other.constructor;
4755 // Non `Object` object instances with different constructors are not equal.
4756 if (objCtor != othCtor &&
4757 ('constructor' in object && 'constructor' in other) &&
4758 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
4759 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
4763 stack['delete'](object);
4768 * Gets metadata for `func`.
4771 * @param {Function} func The function to query.
4772 * @returns {*} Returns the metadata for `func`.
4774 var getData = !metaMap ? noop : function(func) {
4775 return metaMap.get(func);
4779 * Gets the name of `func`.
4782 * @param {Function} func The function to query.
4783 * @returns {string} Returns the function name.
4785 function getFuncName(func) {
4786 var result = (func.name + ''),
4787 array = realNames[result],
4788 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
4791 var data = array[length],
4792 otherFunc = data.func;
4793 if (otherFunc == null || otherFunc == func) {
4801 * Gets the appropriate "iteratee" function. If the `_.iteratee` method is
4802 * customized this function returns the custom method, otherwise it returns
4803 * `baseIteratee`. If arguments are provided the chosen function is invoked
4804 * with them and its result is returned.
4807 * @param {*} [value] The value to convert to an iteratee.
4808 * @param {number} [arity] The arity of the created iteratee.
4809 * @returns {Function} Returns the chosen function or its result.
4811 function getIteratee() {
4812 var result = lodash.iteratee || iteratee;
4813 result = result === iteratee ? baseIteratee : result;
4814 return arguments.length ? result(arguments[0], arguments[1]) : result;
4818 * Gets the "length" property value of `object`.
4820 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
4821 * that affects Safari on at least iOS 8.1-8.3 ARM64.
4824 * @param {Object} object The object to query.
4825 * @returns {*} Returns the "length" value.
4827 var getLength = baseProperty('length');
4830 * Gets the property names, values, and compare flags of `object`.
4833 * @param {Object} object The object to query.
4834 * @returns {Array} Returns the match data of `object`.
4836 function getMatchData(object) {
4837 var result = toPairs(object),
4838 length = result.length;
4841 result[length][2] = isStrictComparable(result[length][1]);
4847 * Gets the native function at `key` of `object`.
4850 * @param {Object} object The object to query.
4851 * @param {string} key The key of the method to get.
4852 * @returns {*} Returns the function if it's native, else `undefined`.
4854 function getNative(object, key) {
4855 var value = object == null ? undefined : object[key];
4856 return isNative(value) ? value : undefined;
4860 * Creates an array of the own symbol properties of `object`.
4863 * @param {Object} object The object to query.
4864 * @returns {Array} Returns the array of symbols.
4866 var getSymbols = getOwnPropertySymbols || function() {
4871 * Gets the `toStringTag` of `value`.
4874 * @param {*} value The value to query.
4875 * @returns {string} Returns the `toStringTag`.
4877 function getTag(value) {
4878 return objectToString.call(value);
4881 // Fallback for IE 11 providing `toStringTag` values for maps, sets, and weakmaps.
4882 if ((Map && getTag(new Map) != mapTag) ||
4883 (Set && getTag(new Set) != setTag) ||
4884 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
4885 getTag = function(value) {
4886 var result = objectToString.call(value),
4887 Ctor = result == objectTag ? value.constructor : null,
4888 ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '';
4891 switch (ctorString) {
4892 case mapCtorString: return mapTag;
4893 case setCtorString: return setTag;
4894 case weakMapCtorString: return weakMapTag;
4902 * Gets the view, applying any `transforms` to the `start` and `end` positions.
4905 * @param {number} start The start of the view.
4906 * @param {number} end The end of the view.
4907 * @param {Array} transforms The transformations to apply to the view.
4908 * @returns {Object} Returns an object containing the `start` and `end`
4909 * positions of the view.
4911 function getView(start, end, transforms) {
4913 length = transforms.length;
4915 while (++index < length) {
4916 var data = transforms[index],
4919 switch (data.type) {
4920 case 'drop': start += size; break;
4921 case 'dropRight': end -= size; break;
4922 case 'take': end = nativeMin(end, start + size); break;
4923 case 'takeRight': start = nativeMax(start, end - size); break;
4926 return { 'start': start, 'end': end };
4930 * Checks if `path` exists on `object`.
4933 * @param {Object} object The object to query.
4934 * @param {Array|string} path The path to check.
4935 * @param {Function} hasFunc The function to check properties.
4936 * @returns {boolean} Returns `true` if `path` exists, else `false`.
4938 function hasPath(object, path, hasFunc) {
4939 if (object == null) {
4942 var result = hasFunc(object, path);
4943 if (!result && !isKey(path)) {
4944 path = baseToPath(path);
4945 object = parent(object, path);
4946 if (object != null) {
4948 result = hasFunc(object, path);
4951 var length = object ? object.length : undefined;
4953 !!length && isLength(length) && isIndex(path, length) &&
4954 (isArray(object) || isString(object) || isArguments(object))
4959 * Initializes an array clone.
4962 * @param {Array} array The array to clone.
4963 * @returns {Array} Returns the initialized clone.
4965 function initCloneArray(array) {
4966 var length = array.length,
4967 result = array.constructor(length);
4969 // Add properties assigned by `RegExp#exec`.
4970 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
4971 result.index = array.index;
4972 result.input = array.input;
4978 * Initializes an object clone.
4981 * @param {Object} object The object to clone.
4982 * @returns {Object} Returns the initialized clone.
4984 function initCloneObject(object) {
4985 if (isPrototype(object)) {
4988 var Ctor = object.constructor;
4989 return baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
4993 * Initializes an object clone based on its `toStringTag`.
4995 * **Note:** This function only supports cloning values with tags of
4996 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4999 * @param {Object} object The object to clone.
5000 * @param {string} tag The `toStringTag` of the object to clone.
5001 * @param {boolean} [isDeep] Specify a deep clone.
5002 * @returns {Object} Returns the initialized clone.
5004 function initCloneByTag(object, tag, isDeep) {
5005 var Ctor = object.constructor;
5007 case arrayBufferTag:
5008 return cloneArrayBuffer(object);
5012 return new Ctor(+object);
5014 case float32Tag: case float64Tag:
5015 case int8Tag: case int16Tag: case int32Tag:
5016 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
5017 return cloneTypedArray(object, isDeep);
5020 return cloneMap(object);
5024 return new Ctor(object);
5027 return cloneRegExp(object);
5030 return cloneSet(object);
5033 return cloneSymbol(object);
5038 * Creates an array of index keys for `object` values of arrays,
5039 * `arguments` objects, and strings, otherwise `null` is returned.
5042 * @param {Object} object The object to query.
5043 * @returns {Array|null} Returns index keys, else `null`.
5045 function indexKeys(object) {
5046 var length = object ? object.length : undefined;
5047 if (isLength(length) &&
5048 (isArray(object) || isString(object) || isArguments(object))) {
5049 return baseTimes(length, String);
5055 * Checks if the given arguments are from an iteratee call.
5058 * @param {*} value The potential iteratee value argument.
5059 * @param {*} index The potential iteratee index or key argument.
5060 * @param {*} object The potential iteratee object argument.
5061 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
5063 function isIterateeCall(value, index, object) {
5064 if (!isObject(object)) {
5067 var type = typeof index;
5068 if (type == 'number'
5069 ? (isArrayLike(object) && isIndex(index, object.length))
5070 : (type == 'string' && index in object)) {
5071 return eq(object[index], value);
5077 * Checks if `value` is a property name and not a property path.
5080 * @param {*} value The value to check.
5081 * @param {Object} [object] The object to query keys on.
5082 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
5084 function isKey(value, object) {
5085 if (typeof value == 'number') {
5088 return !isArray(value) &&
5089 (reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
5090 (object != null && value in Object(object)));
5094 * Checks if `value` is suitable for use as unique object key.
5097 * @param {*} value The value to check.
5098 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
5100 function isKeyable(value) {
5101 var type = typeof value;
5102 return type == 'number' || type == 'boolean' ||
5103 (type == 'string' && value !== '__proto__') || value == null;
5107 * Checks if `func` has a lazy counterpart.
5110 * @param {Function} func The function to check.
5111 * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
5113 function isLaziable(func) {
5114 var funcName = getFuncName(func),
5115 other = lodash[funcName];
5117 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
5120 if (func === other) {
5123 var data = getData(other);
5124 return !!data && func === data[0];
5128 * Checks if `value` is likely a prototype object.
5131 * @param {*} value The value to check.
5132 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
5134 function isPrototype(value) {
5135 var Ctor = value && value.constructor,
5136 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
5138 return value === proto;
5142 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
5145 * @param {*} value The value to check.
5146 * @returns {boolean} Returns `true` if `value` if suitable for strict
5147 * equality comparisons, else `false`.
5149 function isStrictComparable(value) {
5150 return value === value && !isObject(value);
5154 * Merges the function metadata of `source` into `data`.
5156 * Merging metadata reduces the number of wrappers used to invoke a function.
5157 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
5158 * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
5159 * modify function arguments, making the order in which they are executed important,
5160 * preventing the merging of metadata. However, we make an exception for a safe
5161 * combined case where curried functions have `_.ary` and or `_.rearg` applied.
5164 * @param {Array} data The destination metadata.
5165 * @param {Array} source The source metadata.
5166 * @returns {Array} Returns `data`.
5168 function mergeData(data, source) {
5169 var bitmask = data[1],
5170 srcBitmask = source[1],
5171 newBitmask = bitmask | srcBitmask,
5172 isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
5175 (srcBitmask == ARY_FLAG && (bitmask == CURRY_FLAG)) ||
5176 (srcBitmask == ARY_FLAG && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
5177 (srcBitmask == (ARY_FLAG | REARG_FLAG) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
5179 // Exit early if metadata can't be merged.
5180 if (!(isCommon || isCombo)) {
5183 // Use source `thisArg` if available.
5184 if (srcBitmask & BIND_FLAG) {
5185 data[2] = source[2];
5186 // Set when currying a bound function.
5187 newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
5189 // Compose partial arguments.
5190 var value = source[3];
5192 var partials = data[3];
5193 data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray(value);
5194 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : copyArray(source[4]);
5196 // Compose partial right arguments.
5200 data[5] = partials ? composeArgsRight(partials, value, source[6]) : copyArray(value);
5201 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : copyArray(source[6]);
5203 // Use source `argPos` if available.
5206 data[7] = copyArray(value);
5208 // Use source `ary` if it's smaller.
5209 if (srcBitmask & ARY_FLAG) {
5210 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
5212 // Use source `arity` if one is not provided.
5213 if (data[9] == null) {
5214 data[9] = source[9];
5216 // Use source `func` and merge bitmasks.
5217 data[0] = source[0];
5218 data[1] = newBitmask;
5224 * Used by `_.defaultsDeep` to customize its `_.merge` use.
5227 * @param {*} objValue The destination value.
5228 * @param {*} srcValue The source value.
5229 * @param {string} key The key of the property to merge.
5230 * @param {Object} object The parent object of `objValue`.
5231 * @param {Object} source The parent object of `srcValue`.
5232 * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
5233 * @returns {*} Returns the value to assign.
5235 function mergeDefaults(objValue, srcValue, key, object, source, stack) {
5236 if (isObject(objValue) && isObject(srcValue)) {
5237 stack.set(srcValue, objValue);
5238 baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
5244 * Gets the parent value at `path` of `object`.
5247 * @param {Object} object The object to query.
5248 * @param {Array} path The path to get the parent value of.
5249 * @returns {*} Returns the parent value.
5251 function parent(object, path) {
5252 return path.length == 1 ? object : get(object, baseSlice(path, 0, -1));
5256 * Reorder `array` according to the specified indexes where the element at
5257 * the first index is assigned as the first element, the element at
5258 * the second index is assigned as the second element, and so on.
5261 * @param {Array} array The array to reorder.
5262 * @param {Array} indexes The arranged array indexes.
5263 * @returns {Array} Returns `array`.
5265 function reorder(array, indexes) {
5266 var arrLength = array.length,
5267 length = nativeMin(indexes.length, arrLength),
5268 oldArray = copyArray(array);
5271 var index = indexes[length];
5272 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
5278 * Sets metadata for `func`.
5280 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
5281 * period of time, it will trip its breaker and transition to an identity function
5282 * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
5286 * @param {Function} func The function to associate metadata with.
5287 * @param {*} data The metadata.
5288 * @returns {Function} Returns `func`.
5290 var setData = (function() {
5294 return function(key, value) {
5296 remaining = HOT_SPAN - (stamp - lastCalled);
5299 if (remaining > 0) {
5300 if (++count >= HOT_COUNT) {
5306 return baseSetData(key, value);
5311 * Converts `string` to a property path array.
5314 * @param {string} string The string to convert.
5315 * @returns {Array} Returns the property path array.
5317 function stringToPath(string) {
5319 toString(string).replace(rePropName, function(match, number, quote, string) {
5320 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
5326 * Converts `value` to an array-like object if it's not one.
5329 * @param {*} value The value to process.
5330 * @returns {Array} Returns the array-like object.
5332 function toArrayLikeObject(value) {
5333 return isArrayLikeObject(value) ? value : [];
5337 * Converts `value` to a function if it's not one.
5340 * @param {*} value The value to process.
5341 * @returns {Function} Returns the function.
5343 function toFunction(value) {
5344 return typeof value == 'function' ? value : identity;
5348 * Creates a clone of `wrapper`.
5351 * @param {Object} wrapper The wrapper to clone.
5352 * @returns {Object} Returns the cloned wrapper.
5354 function wrapperClone(wrapper) {
5355 if (wrapper instanceof LazyWrapper) {
5356 return wrapper.clone();
5358 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
5359 result.__actions__ = copyArray(wrapper.__actions__);
5360 result.__index__ = wrapper.__index__;
5361 result.__values__ = wrapper.__values__;
5365 /*------------------------------------------------------------------------*/
5368 * Creates an array of elements split into groups the length of `size`.
5369 * If `array` can't be split evenly, the final chunk will be the remaining
5375 * @param {Array} array The array to process.
5376 * @param {number} [size=0] The length of each chunk.
5377 * @returns {Array} Returns the new array containing chunks.
5380 * _.chunk(['a', 'b', 'c', 'd'], 2);
5381 * // => [['a', 'b'], ['c', 'd']]
5383 * _.chunk(['a', 'b', 'c', 'd'], 3);
5384 * // => [['a', 'b', 'c'], ['d']]
5386 function chunk(array, size) {
5387 size = nativeMax(toInteger(size), 0);
5389 var length = array ? array.length : 0;
5390 if (!length || size < 1) {
5395 result = Array(nativeCeil(length / size));
5397 while (index < length) {
5398 result[++resIndex] = baseSlice(array, index, (index += size));
5404 * Creates an array with all falsey values removed. The values `false`, `null`,
5405 * `0`, `""`, `undefined`, and `NaN` are falsey.
5410 * @param {Array} array The array to compact.
5411 * @returns {Array} Returns the new array of filtered values.
5414 * _.compact([0, 1, false, 2, '', 3]);
5417 function compact(array) {
5419 length = array ? array.length : 0,
5423 while (++index < length) {
5424 var value = array[index];
5426 result[++resIndex] = value;
5433 * Creates a new array concatenating `array` with any additional arrays
5439 * @param {Array} array The array to concatenate.
5440 * @param {...*} [values] The values to concatenate.
5441 * @returns {Array} Returns the new concatenated array.
5445 * var other = _.concat(array, 2, [3], [[4]]);
5447 * console.log(other);
5448 * // => [1, 2, 3, [4]]
5450 * console.log(array);
5453 var concat = rest(function(array, values) {
5454 if (!isArray(array)) {
5455 array = array == null ? [] : [Object(array)];
5457 values = baseFlatten(values);
5458 return arrayConcat(array, values);
5462 * Creates an array of unique `array` values not included in the other
5463 * given arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5464 * for equality comparisons.
5469 * @param {Array} array The array to inspect.
5470 * @param {...Array} [values] The values to exclude.
5471 * @returns {Array} Returns the new array of filtered values.
5474 * _.difference([3, 2, 1], [4, 2]);
5477 var difference = rest(function(array, values) {
5478 return isArrayLikeObject(array)
5479 ? baseDifference(array, baseFlatten(values, false, true))
5484 * This method is like `_.difference` except that it accepts `iteratee` which
5485 * is invoked for each element of `array` and `values` to generate the criterion
5486 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
5491 * @param {Array} array The array to inspect.
5492 * @param {...Array} [values] The values to exclude.
5493 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
5494 * @returns {Array} Returns the new array of filtered values.
5497 * _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
5500 * // The `_.property` iteratee shorthand.
5501 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
5502 * // => [{ 'x': 2 }]
5504 var differenceBy = rest(function(array, values) {
5505 var iteratee = last(values);
5506 if (isArrayLikeObject(iteratee)) {
5507 iteratee = undefined;
5509 return isArrayLikeObject(array)
5510 ? baseDifference(array, baseFlatten(values, false, true), getIteratee(iteratee))
5515 * This method is like `_.difference` except that it accepts `comparator`
5516 * which is invoked to compare elements of `array` to `values`. The comparator
5517 * is invoked with two arguments: (arrVal, othVal).
5522 * @param {Array} array The array to inspect.
5523 * @param {...Array} [values] The values to exclude.
5524 * @param {Function} [comparator] The comparator invoked per element.
5525 * @returns {Array} Returns the new array of filtered values.
5528 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
5530 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
5531 * // => [{ 'x': 2, 'y': 1 }]
5533 var differenceWith = rest(function(array, values) {
5534 var comparator = last(values);
5535 if (isArrayLikeObject(comparator)) {
5536 comparator = undefined;
5538 return isArrayLikeObject(array)
5539 ? baseDifference(array, baseFlatten(values, false, true), undefined, comparator)
5544 * Creates a slice of `array` with `n` elements dropped from the beginning.
5549 * @param {Array} array The array to query.
5550 * @param {number} [n=1] The number of elements to drop.
5551 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
5552 * @returns {Array} Returns the slice of `array`.
5555 * _.drop([1, 2, 3]);
5558 * _.drop([1, 2, 3], 2);
5561 * _.drop([1, 2, 3], 5);
5564 * _.drop([1, 2, 3], 0);
5567 function drop(array, n, guard) {
5568 var length = array ? array.length : 0;
5572 n = (guard || n === undefined) ? 1 : toInteger(n);
5573 return baseSlice(array, n < 0 ? 0 : n, length);
5577 * Creates a slice of `array` with `n` elements dropped from the end.
5582 * @param {Array} array The array to query.
5583 * @param {number} [n=1] The number of elements to drop.
5584 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
5585 * @returns {Array} Returns the slice of `array`.
5588 * _.dropRight([1, 2, 3]);
5591 * _.dropRight([1, 2, 3], 2);
5594 * _.dropRight([1, 2, 3], 5);
5597 * _.dropRight([1, 2, 3], 0);
5600 function dropRight(array, n, guard) {
5601 var length = array ? array.length : 0;
5605 n = (guard || n === undefined) ? 1 : toInteger(n);
5607 return baseSlice(array, 0, n < 0 ? 0 : n);
5611 * Creates a slice of `array` excluding elements dropped from the end.
5612 * Elements are dropped until `predicate` returns falsey. The predicate is
5613 * invoked with three arguments: (value, index, array).
5618 * @param {Array} array The array to query.
5619 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5620 * @returns {Array} Returns the slice of `array`.
5624 * { 'user': 'barney', 'active': true },
5625 * { 'user': 'fred', 'active': false },
5626 * { 'user': 'pebbles', 'active': false }
5629 * _.dropRightWhile(users, function(o) { return !o.active; });
5630 * // => objects for ['barney']
5632 * // The `_.matches` iteratee shorthand.
5633 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
5634 * // => objects for ['barney', 'fred']
5636 * // The `_.matchesProperty` iteratee shorthand.
5637 * _.dropRightWhile(users, ['active', false]);
5638 * // => objects for ['barney']
5640 * // The `_.property` iteratee shorthand.
5641 * _.dropRightWhile(users, 'active');
5642 * // => objects for ['barney', 'fred', 'pebbles']
5644 function dropRightWhile(array, predicate) {
5645 return (array && array.length)
5646 ? baseWhile(array, getIteratee(predicate, 3), true, true)
5651 * Creates a slice of `array` excluding elements dropped from the beginning.
5652 * Elements are dropped until `predicate` returns falsey. The predicate is
5653 * invoked with three arguments: (value, index, array).
5658 * @param {Array} array The array to query.
5659 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5660 * @returns {Array} Returns the slice of `array`.
5664 * { 'user': 'barney', 'active': false },
5665 * { 'user': 'fred', 'active': false },
5666 * { 'user': 'pebbles', 'active': true }
5669 * _.dropWhile(users, function(o) { return !o.active; });
5670 * // => objects for ['pebbles']
5672 * // The `_.matches` iteratee shorthand.
5673 * _.dropWhile(users, { 'user': 'barney', 'active': false });
5674 * // => objects for ['fred', 'pebbles']
5676 * // The `_.matchesProperty` iteratee shorthand.
5677 * _.dropWhile(users, ['active', false]);
5678 * // => objects for ['pebbles']
5680 * // The `_.property` iteratee shorthand.
5681 * _.dropWhile(users, 'active');
5682 * // => objects for ['barney', 'fred', 'pebbles']
5684 function dropWhile(array, predicate) {
5685 return (array && array.length)
5686 ? baseWhile(array, getIteratee(predicate, 3), true)
5691 * Fills elements of `array` with `value` from `start` up to, but not
5694 * **Note:** This method mutates `array`.
5699 * @param {Array} array The array to fill.
5700 * @param {*} value The value to fill `array` with.
5701 * @param {number} [start=0] The start position.
5702 * @param {number} [end=array.length] The end position.
5703 * @returns {Array} Returns `array`.
5706 * var array = [1, 2, 3];
5708 * _.fill(array, 'a');
5709 * console.log(array);
5710 * // => ['a', 'a', 'a']
5712 * _.fill(Array(3), 2);
5715 * _.fill([4, 6, 8, 10], '*', 1, 3);
5716 * // => [4, '*', '*', 10]
5718 function fill(array, value, start, end) {
5719 var length = array ? array.length : 0;
5723 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
5727 return baseFill(array, value, start, end);
5731 * This method is like `_.find` except that it returns the index of the first
5732 * element `predicate` returns truthy for instead of the element itself.
5737 * @param {Array} array The array to search.
5738 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5739 * @returns {number} Returns the index of the found element, else `-1`.
5743 * { 'user': 'barney', 'active': false },
5744 * { 'user': 'fred', 'active': false },
5745 * { 'user': 'pebbles', 'active': true }
5748 * _.findIndex(users, function(o) { return o.user == 'barney'; });
5751 * // The `_.matches` iteratee shorthand.
5752 * _.findIndex(users, { 'user': 'fred', 'active': false });
5755 * // The `_.matchesProperty` iteratee shorthand.
5756 * _.findIndex(users, ['active', false]);
5759 * // The `_.property` iteratee shorthand.
5760 * _.findIndex(users, 'active');
5763 function findIndex(array, predicate) {
5764 return (array && array.length)
5765 ? baseFindIndex(array, getIteratee(predicate, 3))
5770 * This method is like `_.findIndex` except that it iterates over elements
5771 * of `collection` from right to left.
5776 * @param {Array} array The array to search.
5777 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
5778 * @returns {number} Returns the index of the found element, else `-1`.
5782 * { 'user': 'barney', 'active': true },
5783 * { 'user': 'fred', 'active': false },
5784 * { 'user': 'pebbles', 'active': false }
5787 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
5790 * // The `_.matches` iteratee shorthand.
5791 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
5794 * // The `_.matchesProperty` iteratee shorthand.
5795 * _.findLastIndex(users, ['active', false]);
5798 * // The `_.property` iteratee shorthand.
5799 * _.findLastIndex(users, 'active');
5802 function findLastIndex(array, predicate) {
5803 return (array && array.length)
5804 ? baseFindIndex(array, getIteratee(predicate, 3), true)
5809 * Flattens `array` a single level.
5814 * @param {Array} array The array to flatten.
5815 * @returns {Array} Returns the new flattened array.
5818 * _.flatten([1, [2, 3, [4]]]);
5819 * // => [1, 2, 3, [4]]
5821 function flatten(array) {
5822 var length = array ? array.length : 0;
5823 return length ? baseFlatten(array) : [];
5827 * This method is like `_.flatten` except that it recursively flattens `array`.
5832 * @param {Array} array The array to recursively flatten.
5833 * @returns {Array} Returns the new flattened array.
5836 * _.flattenDeep([1, [2, 3, [4]]]);
5837 * // => [1, 2, 3, 4]
5839 function flattenDeep(array) {
5840 var length = array ? array.length : 0;
5841 return length ? baseFlatten(array, true) : [];
5845 * The inverse of `_.toPairs`; this method returns an object composed
5846 * from key-value `pairs`.
5851 * @param {Array} pairs The key-value pairs.
5852 * @returns {Object} Returns the new object.
5855 * _.fromPairs([['fred', 30], ['barney', 40]]);
5856 * // => { 'fred': 30, 'barney': 40 }
5858 function fromPairs(pairs) {
5860 length = pairs ? pairs.length : 0,
5863 while (++index < length) {
5864 var pair = pairs[index];
5865 result[pair[0]] = pair[1];
5871 * Gets the first element of `array`.
5877 * @param {Array} array The array to query.
5878 * @returns {*} Returns the first element of `array`.
5881 * _.head([1, 2, 3]);
5887 function head(array) {
5888 return array ? array[0] : undefined;
5892 * Gets the index at which the first occurrence of `value` is found in `array`
5893 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5894 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
5895 * from the end of `array`.
5900 * @param {Array} array The array to search.
5901 * @param {*} value The value to search for.
5902 * @param {number} [fromIndex=0] The index to search from.
5903 * @returns {number} Returns the index of the matched value, else `-1`.
5906 * _.indexOf([1, 2, 1, 2], 2);
5909 * // Search from the `fromIndex`.
5910 * _.indexOf([1, 2, 1, 2], 2, 2);
5913 function indexOf(array, value, fromIndex) {
5914 var length = array ? array.length : 0;
5918 fromIndex = toInteger(fromIndex);
5919 if (fromIndex < 0) {
5920 fromIndex = nativeMax(length + fromIndex, 0);
5922 return baseIndexOf(array, value, fromIndex);
5926 * Gets all but the last element of `array`.
5931 * @param {Array} array The array to query.
5932 * @returns {Array} Returns the slice of `array`.
5935 * _.initial([1, 2, 3]);
5938 function initial(array) {
5939 return dropRight(array, 1);
5943 * Creates an array of unique values that are included in all given arrays
5944 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5945 * for equality comparisons.
5950 * @param {...Array} [arrays] The arrays to inspect.
5951 * @returns {Array} Returns the new array of shared values.
5954 * _.intersection([2, 1], [4, 2], [1, 2]);
5957 var intersection = rest(function(arrays) {
5958 var mapped = arrayMap(arrays, toArrayLikeObject);
5959 return (mapped.length && mapped[0] === arrays[0])
5960 ? baseIntersection(mapped)
5965 * This method is like `_.intersection` except that it accepts `iteratee`
5966 * which is invoked for each element of each `arrays` to generate the criterion
5967 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
5972 * @param {...Array} [arrays] The arrays to inspect.
5973 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
5974 * @returns {Array} Returns the new array of shared values.
5977 * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
5980 * // The `_.property` iteratee shorthand.
5981 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
5982 * // => [{ 'x': 1 }]
5984 var intersectionBy = rest(function(arrays) {
5985 var iteratee = last(arrays),
5986 mapped = arrayMap(arrays, toArrayLikeObject);
5988 if (iteratee === last(mapped)) {
5989 iteratee = undefined;
5993 return (mapped.length && mapped[0] === arrays[0])
5994 ? baseIntersection(mapped, getIteratee(iteratee))
5999 * This method is like `_.intersection` except that it accepts `comparator`
6000 * which is invoked to compare elements of `arrays`. The comparator is invoked
6001 * with two arguments: (arrVal, othVal).
6006 * @param {...Array} [arrays] The arrays to inspect.
6007 * @param {Function} [comparator] The comparator invoked per element.
6008 * @returns {Array} Returns the new array of shared values.
6011 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6012 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6014 * _.intersectionWith(objects, others, _.isEqual);
6015 * // => [{ 'x': 1, 'y': 2 }]
6017 var intersectionWith = rest(function(arrays) {
6018 var comparator = last(arrays),
6019 mapped = arrayMap(arrays, toArrayLikeObject);
6021 if (comparator === last(mapped)) {
6022 comparator = undefined;
6026 return (mapped.length && mapped[0] === arrays[0])
6027 ? baseIntersection(mapped, undefined, comparator)
6032 * Converts all elements in `array` into a string separated by `separator`.
6037 * @param {Array} array The array to convert.
6038 * @param {string} [separator=','] The element separator.
6039 * @returns {string} Returns the joined string.
6042 * _.join(['a', 'b', 'c'], '~');
6045 function join(array, separator) {
6046 return array ? nativeJoin.call(array, separator) : '';
6050 * Gets the last element of `array`.
6055 * @param {Array} array The array to query.
6056 * @returns {*} Returns the last element of `array`.
6059 * _.last([1, 2, 3]);
6062 function last(array) {
6063 var length = array ? array.length : 0;
6064 return length ? array[length - 1] : undefined;
6068 * This method is like `_.indexOf` except that it iterates over elements of
6069 * `array` from right to left.
6074 * @param {Array} array The array to search.
6075 * @param {*} value The value to search for.
6076 * @param {number} [fromIndex=array.length-1] The index to search from.
6077 * @returns {number} Returns the index of the matched value, else `-1`.
6080 * _.lastIndexOf([1, 2, 1, 2], 2);
6083 * // Search from the `fromIndex`.
6084 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
6087 function lastIndexOf(array, value, fromIndex) {
6088 var length = array ? array.length : 0;
6093 if (fromIndex !== undefined) {
6094 index = toInteger(fromIndex);
6095 index = (index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1)) + 1;
6097 if (value !== value) {
6098 return indexOfNaN(array, index, true);
6101 if (array[index] === value) {
6109 * Removes all given values from `array` using
6110 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6111 * for equality comparisons.
6113 * **Note:** Unlike `_.without`, this method mutates `array`.
6118 * @param {Array} array The array to modify.
6119 * @param {...*} [values] The values to remove.
6120 * @returns {Array} Returns `array`.
6123 * var array = [1, 2, 3, 1, 2, 3];
6125 * _.pull(array, 2, 3);
6126 * console.log(array);
6129 var pull = rest(pullAll);
6132 * This method is like `_.pull` except that it accepts an array of values to remove.
6134 * **Note:** Unlike `_.difference`, this method mutates `array`.
6139 * @param {Array} array The array to modify.
6140 * @param {Array} values The values to remove.
6141 * @returns {Array} Returns `array`.
6144 * var array = [1, 2, 3, 1, 2, 3];
6146 * _.pullAll(array, [2, 3]);
6147 * console.log(array);
6150 function pullAll(array, values) {
6151 return (array && array.length && values && values.length)
6152 ? basePullAll(array, values)
6157 * This method is like `_.pullAll` except that it accepts `iteratee` which is
6158 * invoked for each element of `array` and `values` to generate the criterion
6159 * by which uniqueness is computed. The iteratee is invoked with one argument: (value).
6161 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
6166 * @param {Array} array The array to modify.
6167 * @param {Array} values The values to remove.
6168 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6169 * @returns {Array} Returns `array`.
6172 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
6174 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
6175 * console.log(array);
6176 * // => [{ 'x': 2 }]
6178 function pullAllBy(array, values, iteratee) {
6179 return (array && array.length && values && values.length)
6180 ? basePullAllBy(array, values, getIteratee(iteratee))
6185 * Removes elements from `array` corresponding to `indexes` and returns an
6186 * array of removed elements.
6188 * **Note:** Unlike `_.at`, this method mutates `array`.
6193 * @param {Array} array The array to modify.
6194 * @param {...(number|number[])} [indexes] The indexes of elements to remove,
6195 * specified individually or in arrays.
6196 * @returns {Array} Returns the new array of removed elements.
6199 * var array = [5, 10, 15, 20];
6200 * var evens = _.pullAt(array, 1, 3);
6202 * console.log(array);
6205 * console.log(evens);
6208 var pullAt = rest(function(array, indexes) {
6209 indexes = arrayMap(baseFlatten(indexes), String);
6211 var result = baseAt(array, indexes);
6212 basePullAt(array, indexes.sort(compareAscending));
6217 * Removes all elements from `array` that `predicate` returns truthy for
6218 * and returns an array of the removed elements. The predicate is invoked with
6219 * three arguments: (value, index, array).
6221 * **Note:** Unlike `_.filter`, this method mutates `array`.
6226 * @param {Array} array The array to modify.
6227 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6228 * @returns {Array} Returns the new array of removed elements.
6231 * var array = [1, 2, 3, 4];
6232 * var evens = _.remove(array, function(n) {
6233 * return n % 2 == 0;
6236 * console.log(array);
6239 * console.log(evens);
6242 function remove(array, predicate) {
6244 if (!(array && array.length)) {
6249 length = array.length;
6251 predicate = getIteratee(predicate, 3);
6252 while (++index < length) {
6253 var value = array[index];
6254 if (predicate(value, index, array)) {
6256 indexes.push(index);
6259 basePullAt(array, indexes);
6264 * Reverses `array` so that the first element becomes the last, the second
6265 * element becomes the second to last, and so on.
6267 * **Note:** This method mutates `array` and is based on
6268 * [`Array#reverse`](https://mdn.io/Array/reverse).
6273 * @returns {Array} Returns `array`.
6276 * var array = [1, 2, 3];
6281 * console.log(array);
6284 function reverse(array) {
6285 return array ? nativeReverse.call(array) : array;
6289 * Creates a slice of `array` from `start` up to, but not including, `end`.
6291 * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
6292 * to ensure dense arrays are returned.
6297 * @param {Array} array The array to slice.
6298 * @param {number} [start=0] The start position.
6299 * @param {number} [end=array.length] The end position.
6300 * @returns {Array} Returns the slice of `array`.
6302 function slice(array, start, end) {
6303 var length = array ? array.length : 0;
6307 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
6312 start = start == null ? 0 : toInteger(start);
6313 end = end === undefined ? length : toInteger(end);
6315 return baseSlice(array, start, end);
6319 * Uses a binary search to determine the lowest index at which `value` should
6320 * be inserted into `array` in order to maintain its sort order.
6325 * @param {Array} array The sorted array to inspect.
6326 * @param {*} value The value to evaluate.
6327 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6330 * _.sortedIndex([30, 50], 40);
6333 * _.sortedIndex([4, 5], 4);
6336 function sortedIndex(array, value) {
6337 return baseSortedIndex(array, value);
6341 * This method is like `_.sortedIndex` except that it accepts `iteratee`
6342 * which is invoked for `value` and each element of `array` to compute their
6343 * sort ranking. The iteratee is invoked with one argument: (value).
6348 * @param {Array} array The sorted array to inspect.
6349 * @param {*} value The value to evaluate.
6350 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6351 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6354 * var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 };
6356 * _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict));
6359 * // The `_.property` iteratee shorthand.
6360 * _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
6363 function sortedIndexBy(array, value, iteratee) {
6364 return baseSortedIndexBy(array, value, getIteratee(iteratee));
6368 * This method is like `_.indexOf` except that it performs a binary
6369 * search on a sorted `array`.
6374 * @param {Array} array The array to search.
6375 * @param {*} value The value to search for.
6376 * @returns {number} Returns the index of the matched value, else `-1`.
6379 * _.sortedIndexOf([1, 1, 2, 2], 2);
6382 function sortedIndexOf(array, value) {
6383 var length = array ? array.length : 0;
6385 var index = baseSortedIndex(array, value);
6386 if (index < length && eq(array[index], value)) {
6394 * This method is like `_.sortedIndex` except that it returns the highest
6395 * index at which `value` should be inserted into `array` in order to
6396 * maintain its sort order.
6401 * @param {Array} array The sorted array to inspect.
6402 * @param {*} value The value to evaluate.
6403 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6406 * _.sortedLastIndex([4, 5], 4);
6409 function sortedLastIndex(array, value) {
6410 return baseSortedIndex(array, value, true);
6414 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
6415 * which is invoked for `value` and each element of `array` to compute their
6416 * sort ranking. The iteratee is invoked with one argument: (value).
6421 * @param {Array} array The sorted array to inspect.
6422 * @param {*} value The value to evaluate.
6423 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6424 * @returns {number} Returns the index at which `value` should be inserted into `array`.
6427 * // The `_.property` iteratee shorthand.
6428 * _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
6431 function sortedLastIndexBy(array, value, iteratee) {
6432 return baseSortedIndexBy(array, value, getIteratee(iteratee), true);
6436 * This method is like `_.lastIndexOf` except that it performs a binary
6437 * search on a sorted `array`.
6442 * @param {Array} array The array to search.
6443 * @param {*} value The value to search for.
6444 * @returns {number} Returns the index of the matched value, else `-1`.
6447 * _.sortedLastIndexOf([1, 1, 2, 2], 2);
6450 function sortedLastIndexOf(array, value) {
6451 var length = array ? array.length : 0;
6453 var index = baseSortedIndex(array, value, true) - 1;
6454 if (eq(array[index], value)) {
6462 * This method is like `_.uniq` except that it's designed and optimized
6463 * for sorted arrays.
6468 * @param {Array} array The array to inspect.
6469 * @returns {Array} Returns the new duplicate free array.
6472 * _.sortedUniq([1, 1, 2]);
6475 function sortedUniq(array) {
6476 return (array && array.length)
6477 ? baseSortedUniq(array)
6482 * This method is like `_.uniqBy` except that it's designed and optimized
6483 * for sorted arrays.
6488 * @param {Array} array The array to inspect.
6489 * @param {Function} [iteratee] The iteratee invoked per element.
6490 * @returns {Array} Returns the new duplicate free array.
6493 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
6496 function sortedUniqBy(array, iteratee) {
6497 return (array && array.length)
6498 ? baseSortedUniqBy(array, getIteratee(iteratee))
6503 * Gets all but the first element of `array`.
6508 * @param {Array} array The array to query.
6509 * @returns {Array} Returns the slice of `array`.
6512 * _.tail([1, 2, 3]);
6515 function tail(array) {
6516 return drop(array, 1);
6520 * Creates a slice of `array` with `n` elements taken from the beginning.
6525 * @param {Array} array The array to query.
6526 * @param {number} [n=1] The number of elements to take.
6527 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
6528 * @returns {Array} Returns the slice of `array`.
6531 * _.take([1, 2, 3]);
6534 * _.take([1, 2, 3], 2);
6537 * _.take([1, 2, 3], 5);
6540 * _.take([1, 2, 3], 0);
6543 function take(array, n, guard) {
6544 if (!(array && array.length)) {
6547 n = (guard || n === undefined) ? 1 : toInteger(n);
6548 return baseSlice(array, 0, n < 0 ? 0 : n);
6552 * Creates a slice of `array` with `n` elements taken from the end.
6557 * @param {Array} array The array to query.
6558 * @param {number} [n=1] The number of elements to take.
6559 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
6560 * @returns {Array} Returns the slice of `array`.
6563 * _.takeRight([1, 2, 3]);
6566 * _.takeRight([1, 2, 3], 2);
6569 * _.takeRight([1, 2, 3], 5);
6572 * _.takeRight([1, 2, 3], 0);
6575 function takeRight(array, n, guard) {
6576 var length = array ? array.length : 0;
6580 n = (guard || n === undefined) ? 1 : toInteger(n);
6582 return baseSlice(array, n < 0 ? 0 : n, length);
6586 * Creates a slice of `array` with elements taken from the end. Elements are
6587 * taken until `predicate` returns falsey. The predicate is invoked with three
6588 * arguments: (value, index, array).
6593 * @param {Array} array The array to query.
6594 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6595 * @returns {Array} Returns the slice of `array`.
6599 * { 'user': 'barney', 'active': true },
6600 * { 'user': 'fred', 'active': false },
6601 * { 'user': 'pebbles', 'active': false }
6604 * _.takeRightWhile(users, function(o) { return !o.active; });
6605 * // => objects for ['fred', 'pebbles']
6607 * // The `_.matches` iteratee shorthand.
6608 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
6609 * // => objects for ['pebbles']
6611 * // The `_.matchesProperty` iteratee shorthand.
6612 * _.takeRightWhile(users, ['active', false]);
6613 * // => objects for ['fred', 'pebbles']
6615 * // The `_.property` iteratee shorthand.
6616 * _.takeRightWhile(users, 'active');
6619 function takeRightWhile(array, predicate) {
6620 return (array && array.length)
6621 ? baseWhile(array, getIteratee(predicate, 3), false, true)
6626 * Creates a slice of `array` with elements taken from the beginning. Elements
6627 * are taken until `predicate` returns falsey. The predicate is invoked with
6628 * three arguments: (value, index, array).
6633 * @param {Array} array The array to query.
6634 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
6635 * @returns {Array} Returns the slice of `array`.
6639 * { 'user': 'barney', 'active': false },
6640 * { 'user': 'fred', 'active': false},
6641 * { 'user': 'pebbles', 'active': true }
6644 * _.takeWhile(users, function(o) { return !o.active; });
6645 * // => objects for ['barney', 'fred']
6647 * // The `_.matches` iteratee shorthand.
6648 * _.takeWhile(users, { 'user': 'barney', 'active': false });
6649 * // => objects for ['barney']
6651 * // The `_.matchesProperty` iteratee shorthand.
6652 * _.takeWhile(users, ['active', false]);
6653 * // => objects for ['barney', 'fred']
6655 * // The `_.property` iteratee shorthand.
6656 * _.takeWhile(users, 'active');
6659 function takeWhile(array, predicate) {
6660 return (array && array.length)
6661 ? baseWhile(array, getIteratee(predicate, 3))
6666 * Creates an array of unique values, in order, from all given arrays using
6667 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6668 * for equality comparisons.
6673 * @param {...Array} [arrays] The arrays to inspect.
6674 * @returns {Array} Returns the new array of combined values.
6677 * _.union([2, 1], [4, 2], [1, 2]);
6680 var union = rest(function(arrays) {
6681 return baseUniq(baseFlatten(arrays, false, true));
6685 * This method is like `_.union` except that it accepts `iteratee` which is
6686 * invoked for each element of each `arrays` to generate the criterion by which
6687 * uniqueness is computed. The iteratee is invoked with one argument: (value).
6692 * @param {...Array} [arrays] The arrays to inspect.
6693 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6694 * @returns {Array} Returns the new array of combined values.
6697 * _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
6698 * // => [2.1, 1.2, 4.3]
6700 * // The `_.property` iteratee shorthand.
6701 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
6702 * // => [{ 'x': 1 }, { 'x': 2 }]
6704 var unionBy = rest(function(arrays) {
6705 var iteratee = last(arrays);
6706 if (isArrayLikeObject(iteratee)) {
6707 iteratee = undefined;
6709 return baseUniq(baseFlatten(arrays, false, true), getIteratee(iteratee));
6713 * This method is like `_.union` except that it accepts `comparator` which
6714 * is invoked to compare elements of `arrays`. The comparator is invoked
6715 * with two arguments: (arrVal, othVal).
6720 * @param {...Array} [arrays] The arrays to inspect.
6721 * @param {Function} [comparator] The comparator invoked per element.
6722 * @returns {Array} Returns the new array of combined values.
6725 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6726 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6728 * _.unionWith(objects, others, _.isEqual);
6729 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
6731 var unionWith = rest(function(arrays) {
6732 var comparator = last(arrays);
6733 if (isArrayLikeObject(comparator)) {
6734 comparator = undefined;
6736 return baseUniq(baseFlatten(arrays, false, true), undefined, comparator);
6740 * Creates a duplicate-free version of an array, using
6741 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6742 * for equality comparisons, in which only the first occurrence of each element
6748 * @param {Array} array The array to inspect.
6749 * @returns {Array} Returns the new duplicate free array.
6752 * _.uniq([2, 1, 2]);
6755 function uniq(array) {
6756 return (array && array.length)
6762 * This method is like `_.uniq` except that it accepts `iteratee` which is
6763 * invoked for each element in `array` to generate the criterion by which
6764 * uniqueness is computed. The iteratee is invoked with one argument: (value).
6769 * @param {Array} array The array to inspect.
6770 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6771 * @returns {Array} Returns the new duplicate free array.
6774 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
6777 * // The `_.property` iteratee shorthand.
6778 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
6779 * // => [{ 'x': 1 }, { 'x': 2 }]
6781 function uniqBy(array, iteratee) {
6782 return (array && array.length)
6783 ? baseUniq(array, getIteratee(iteratee))
6788 * This method is like `_.uniq` except that it accepts `comparator` which
6789 * is invoked to compare elements of `array`. The comparator is invoked with
6790 * two arguments: (arrVal, othVal).
6795 * @param {Array} array The array to inspect.
6796 * @param {Function} [comparator] The comparator invoked per element.
6797 * @returns {Array} Returns the new duplicate free array.
6800 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
6802 * _.uniqWith(objects, _.isEqual);
6803 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
6805 function uniqWith(array, comparator) {
6806 return (array && array.length)
6807 ? baseUniq(array, undefined, comparator)
6812 * This method is like `_.zip` except that it accepts an array of grouped
6813 * elements and creates an array regrouping the elements to their pre-zip
6819 * @param {Array} array The array of grouped elements to process.
6820 * @returns {Array} Returns the new array of regrouped elements.
6823 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
6824 * // => [['fred', 30, true], ['barney', 40, false]]
6827 * // => [['fred', 'barney'], [30, 40], [true, false]]
6829 function unzip(array) {
6830 if (!(array && array.length)) {
6834 array = arrayFilter(array, function(group) {
6835 if (isArrayLikeObject(group)) {
6836 length = nativeMax(group.length, length);
6840 return baseTimes(length, function(index) {
6841 return arrayMap(array, baseProperty(index));
6846 * This method is like `_.unzip` except that it accepts `iteratee` to specify
6847 * how regrouped values should be combined. The iteratee is invoked with the
6848 * elements of each group: (...group).
6853 * @param {Array} array The array of grouped elements to process.
6854 * @param {Function} [iteratee=_.identity] The function to combine regrouped values.
6855 * @returns {Array} Returns the new array of regrouped elements.
6858 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
6859 * // => [[1, 10, 100], [2, 20, 200]]
6861 * _.unzipWith(zipped, _.add);
6862 * // => [3, 30, 300]
6864 function unzipWith(array, iteratee) {
6865 if (!(array && array.length)) {
6868 var result = unzip(array);
6869 if (iteratee == null) {
6872 return arrayMap(result, function(group) {
6873 return apply(iteratee, undefined, group);
6878 * Creates an array excluding all given values using
6879 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6880 * for equality comparisons.
6885 * @param {Array} array The array to filter.
6886 * @param {...*} [values] The values to exclude.
6887 * @returns {Array} Returns the new array of filtered values.
6890 * _.without([1, 2, 1, 3], 1, 2);
6893 var without = rest(function(array, values) {
6894 return isArrayLikeObject(array)
6895 ? baseDifference(array, values)
6900 * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
6901 * of the given arrays.
6906 * @param {...Array} [arrays] The arrays to inspect.
6907 * @returns {Array} Returns the new array of values.
6910 * _.xor([2, 1], [4, 2]);
6913 var xor = rest(function(arrays) {
6914 return baseXor(arrayFilter(arrays, isArrayLikeObject));
6918 * This method is like `_.xor` except that it accepts `iteratee` which is
6919 * invoked for each element of each `arrays` to generate the criterion by which
6920 * uniqueness is computed. The iteratee is invoked with one argument: (value).
6925 * @param {...Array} [arrays] The arrays to inspect.
6926 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
6927 * @returns {Array} Returns the new array of values.
6930 * _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
6933 * // The `_.property` iteratee shorthand.
6934 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
6935 * // => [{ 'x': 2 }]
6937 var xorBy = rest(function(arrays) {
6938 var iteratee = last(arrays);
6939 if (isArrayLikeObject(iteratee)) {
6940 iteratee = undefined;
6942 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee));
6946 * This method is like `_.xor` except that it accepts `comparator` which is
6947 * invoked to compare elements of `arrays`. The comparator is invoked with
6948 * two arguments: (arrVal, othVal).
6953 * @param {...Array} [arrays] The arrays to inspect.
6954 * @param {Function} [comparator] The comparator invoked per element.
6955 * @returns {Array} Returns the new array of values.
6958 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6959 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6961 * _.xorWith(objects, others, _.isEqual);
6962 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
6964 var xorWith = rest(function(arrays) {
6965 var comparator = last(arrays);
6966 if (isArrayLikeObject(comparator)) {
6967 comparator = undefined;
6969 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
6973 * Creates an array of grouped elements, the first of which contains the first
6974 * elements of the given arrays, the second of which contains the second elements
6975 * of the given arrays, and so on.
6980 * @param {...Array} [arrays] The arrays to process.
6981 * @returns {Array} Returns the new array of grouped elements.
6984 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
6985 * // => [['fred', 30, true], ['barney', 40, false]]
6987 var zip = rest(unzip);
6990 * This method is like `_.fromPairs` except that it accepts two arrays,
6991 * one of property names and one of corresponding values.
6996 * @param {Array} [props=[]] The property names.
6997 * @param {Array} [values=[]] The property values.
6998 * @returns {Object} Returns the new object.
7001 * _.zipObject(['a', 'b'], [1, 2]);
7002 * // => { 'a': 1, 'b': 2 }
7004 function zipObject(props, values) {
7005 return baseZipObject(props || [], values || [], assignValue);
7009 * This method is like `_.zipObject` except that it supports property paths.
7014 * @param {Array} [props=[]] The property names.
7015 * @param {Array} [values=[]] The property values.
7016 * @returns {Object} Returns the new object.
7019 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
7020 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
7022 function zipObjectDeep(props, values) {
7023 return baseZipObject(props || [], values || [], baseSet);
7027 * This method is like `_.zip` except that it accepts `iteratee` to specify
7028 * how grouped values should be combined. The iteratee is invoked with the
7029 * elements of each group: (...group).
7034 * @param {...Array} [arrays] The arrays to process.
7035 * @param {Function} [iteratee=_.identity] The function to combine grouped values.
7036 * @returns {Array} Returns the new array of grouped elements.
7039 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
7044 var zipWith = rest(function(arrays) {
7045 var length = arrays.length,
7046 iteratee = length > 1 ? arrays[length - 1] : undefined;
7048 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
7049 return unzipWith(arrays, iteratee);
7052 /*------------------------------------------------------------------------*/
7055 * Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
7056 * The result of such method chaining must be unwrapped with `_#value`.
7061 * @param {*} value The value to wrap.
7062 * @returns {Object} Returns the new `lodash` wrapper instance.
7066 * { 'user': 'barney', 'age': 36 },
7067 * { 'user': 'fred', 'age': 40 },
7068 * { 'user': 'pebbles', 'age': 1 }
7074 * .map(function(o) {
7075 * return o.user + ' is ' + o.age;
7079 * // => 'pebbles is 1'
7081 function chain(value) {
7082 var result = lodash(value);
7083 result.__chain__ = true;
7088 * This method invokes `interceptor` and returns `value`. The interceptor
7089 * is invoked with one argument; (value). The purpose of this method is to
7090 * "tap into" a method chain in order to modify intermediate results.
7095 * @param {*} value The value to provide to `interceptor`.
7096 * @param {Function} interceptor The function to invoke.
7097 * @returns {*} Returns `value`.
7101 * .tap(function(array) {
7102 * // Mutate input array.
7109 function tap(value, interceptor) {
7115 * This method is like `_.tap` except that it returns the result of `interceptor`.
7116 * The purpose of this method is to "pass thru" values replacing intermediate
7117 * results in a method chain.
7122 * @param {*} value The value to provide to `interceptor`.
7123 * @param {Function} interceptor The function to invoke.
7124 * @returns {*} Returns the result of `interceptor`.
7130 * .thru(function(value) {
7136 function thru(value, interceptor) {
7137 return interceptor(value);
7141 * This method is the wrapper version of `_.at`.
7146 * @param {...(string|string[])} [paths] The property paths of elements to pick,
7147 * specified individually or in arrays.
7148 * @returns {Object} Returns the new `lodash` wrapper instance.
7151 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
7153 * _(object).at(['a[0].b.c', 'a[1]']).value();
7156 * _(['a', 'b', 'c']).at(0, 2).value();
7159 var wrapperAt = rest(function(paths) {
7160 paths = baseFlatten(paths);
7161 var length = paths.length,
7162 start = length ? paths[0] : 0,
7163 value = this.__wrapped__,
7164 interceptor = function(object) { return baseAt(object, paths); };
7166 if (length > 1 || this.__actions__.length || !(value instanceof LazyWrapper) || !isIndex(start)) {
7167 return this.thru(interceptor);
7169 value = value.slice(start, +start + (length ? 1 : 0));
7170 value.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
7171 return new LodashWrapper(value, this.__chain__).thru(function(array) {
7172 if (length && !array.length) {
7173 array.push(undefined);
7180 * Enables explicit method chaining on the wrapper object.
7185 * @returns {Object} Returns the new `lodash` wrapper instance.
7189 * { 'user': 'barney', 'age': 36 },
7190 * { 'user': 'fred', 'age': 40 }
7193 * // A sequence without explicit chaining.
7195 * // => { 'user': 'barney', 'age': 36 }
7197 * // A sequence with explicit chaining.
7203 * // => { 'user': 'barney' }
7205 function wrapperChain() {
7210 * Executes the chained sequence and returns the wrapped result.
7215 * @returns {Object} Returns the new `lodash` wrapper instance.
7218 * var array = [1, 2];
7219 * var wrapped = _(array).push(3);
7221 * console.log(array);
7224 * wrapped = wrapped.commit();
7225 * console.log(array);
7231 * console.log(array);
7234 function wrapperCommit() {
7235 return new LodashWrapper(this.value(), this.__chain__);
7239 * This method is the wrapper version of `_.flatMap`.
7244 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
7245 * @returns {Object} Returns the new `lodash` wrapper instance.
7248 * function duplicate(n) {
7252 * _([1, 2]).flatMap(duplicate).value();
7253 * // => [1, 1, 2, 2]
7255 function wrapperFlatMap(iteratee) {
7256 return this.map(iteratee).flatten();
7260 * Gets the next value on a wrapped object following the
7261 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
7266 * @returns {Object} Returns the next iterator value.
7269 * var wrapped = _([1, 2]);
7272 * // => { 'done': false, 'value': 1 }
7275 * // => { 'done': false, 'value': 2 }
7278 * // => { 'done': true, 'value': undefined }
7280 function wrapperNext() {
7281 if (this.__values__ === undefined) {
7282 this.__values__ = toArray(this.value());
7284 var done = this.__index__ >= this.__values__.length,
7285 value = done ? undefined : this.__values__[this.__index__++];
7287 return { 'done': done, 'value': value };
7291 * Enables the wrapper to be iterable.
7293 * @name Symbol.iterator
7296 * @returns {Object} Returns the wrapper object.
7299 * var wrapped = _([1, 2]);
7301 * wrapped[Symbol.iterator]() === wrapped;
7304 * Array.from(wrapped);
7307 function wrapperToIterator() {
7312 * Creates a clone of the chained sequence planting `value` as the wrapped value.
7317 * @param {*} value The value to plant.
7318 * @returns {Object} Returns the new `lodash` wrapper instance.
7321 * function square(n) {
7325 * var wrapped = _([1, 2]).map(square);
7326 * var other = wrapped.plant([3, 4]);
7334 function wrapperPlant(value) {
7338 while (parent instanceof baseLodash) {
7339 var clone = wrapperClone(parent);
7340 clone.__index__ = 0;
7341 clone.__values__ = undefined;
7343 previous.__wrapped__ = clone;
7347 var previous = clone;
7348 parent = parent.__wrapped__;
7350 previous.__wrapped__ = value;
7355 * This method is the wrapper version of `_.reverse`.
7357 * **Note:** This method mutates the wrapped array.
7362 * @returns {Object} Returns the new `lodash` wrapper instance.
7365 * var array = [1, 2, 3];
7367 * _(array).reverse().value()
7370 * console.log(array);
7373 function wrapperReverse() {
7374 var value = this.__wrapped__;
7375 if (value instanceof LazyWrapper) {
7376 var wrapped = value;
7377 if (this.__actions__.length) {
7378 wrapped = new LazyWrapper(this);
7380 wrapped = wrapped.reverse();
7381 wrapped.__actions__.push({ 'func': thru, 'args': [reverse], 'thisArg': undefined });
7382 return new LodashWrapper(wrapped, this.__chain__);
7384 return this.thru(reverse);
7388 * Executes the chained sequence to extract the unwrapped value.
7392 * @alias toJSON, valueOf
7394 * @returns {*} Returns the resolved unwrapped value.
7397 * _([1, 2, 3]).value();
7400 function wrapperValue() {
7401 return baseWrapperValue(this.__wrapped__, this.__actions__);
7404 /*------------------------------------------------------------------------*/
7407 * Creates an object composed of keys generated from the results of running
7408 * each element of `collection` through `iteratee`. The corresponding value
7409 * of each key is the number of times the key was returned by `iteratee`.
7410 * The iteratee is invoked with one argument: (value).
7414 * @category Collection
7415 * @param {Array|Object} collection The collection to iterate over.
7416 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7417 * @returns {Object} Returns the composed aggregate object.
7420 * _.countBy([6.1, 4.2, 6.3], Math.floor);
7421 * // => { '4': 1, '6': 2 }
7423 * _.countBy(['one', 'two', 'three'], 'length');
7424 * // => { '3': 2, '5': 1 }
7426 var countBy = createAggregator(function(result, value, key) {
7427 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
7431 * Checks if `predicate` returns truthy for **all** elements of `collection`.
7432 * Iteration is stopped once `predicate` returns falsey. The predicate is
7433 * invoked with three arguments: (value, index|key, collection).
7437 * @category Collection
7438 * @param {Array|Object} collection The collection to iterate over.
7439 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7440 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
7441 * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
7444 * _.every([true, 1, null, 'yes'], Boolean);
7448 * { 'user': 'barney', 'active': false },
7449 * { 'user': 'fred', 'active': false }
7452 * // The `_.matches` iteratee shorthand.
7453 * _.every(users, { 'user': 'barney', 'active': false });
7456 * // The `_.matchesProperty` iteratee shorthand.
7457 * _.every(users, ['active', false]);
7460 * // The `_.property` iteratee shorthand.
7461 * _.every(users, 'active');
7464 function every(collection, predicate, guard) {
7465 var func = isArray(collection) ? arrayEvery : baseEvery;
7466 if (guard && isIterateeCall(collection, predicate, guard)) {
7467 predicate = undefined;
7469 return func(collection, getIteratee(predicate, 3));
7473 * Iterates over elements of `collection`, returning an array of all elements
7474 * `predicate` returns truthy for. The predicate is invoked with three arguments:
7475 * (value, index|key, collection).
7479 * @category Collection
7480 * @param {Array|Object} collection The collection to iterate over.
7481 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7482 * @returns {Array} Returns the new filtered array.
7486 * { 'user': 'barney', 'age': 36, 'active': true },
7487 * { 'user': 'fred', 'age': 40, 'active': false }
7490 * _.filter(users, function(o) { return !o.active; });
7491 * // => objects for ['fred']
7493 * // The `_.matches` iteratee shorthand.
7494 * _.filter(users, { 'age': 36, 'active': true });
7495 * // => objects for ['barney']
7497 * // The `_.matchesProperty` iteratee shorthand.
7498 * _.filter(users, ['active', false]);
7499 * // => objects for ['fred']
7501 * // The `_.property` iteratee shorthand.
7502 * _.filter(users, 'active');
7503 * // => objects for ['barney']
7505 function filter(collection, predicate) {
7506 var func = isArray(collection) ? arrayFilter : baseFilter;
7507 return func(collection, getIteratee(predicate, 3));
7511 * Iterates over elements of `collection`, returning the first element
7512 * `predicate` returns truthy for. The predicate is invoked with three arguments:
7513 * (value, index|key, collection).
7517 * @category Collection
7518 * @param {Array|Object} collection The collection to search.
7519 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7520 * @returns {*} Returns the matched element, else `undefined`.
7524 * { 'user': 'barney', 'age': 36, 'active': true },
7525 * { 'user': 'fred', 'age': 40, 'active': false },
7526 * { 'user': 'pebbles', 'age': 1, 'active': true }
7529 * _.find(users, function(o) { return o.age < 40; });
7530 * // => object for 'barney'
7532 * // The `_.matches` iteratee shorthand.
7533 * _.find(users, { 'age': 1, 'active': true });
7534 * // => object for 'pebbles'
7536 * // The `_.matchesProperty` iteratee shorthand.
7537 * _.find(users, ['active', false]);
7538 * // => object for 'fred'
7540 * // The `_.property` iteratee shorthand.
7541 * _.find(users, 'active');
7542 * // => object for 'barney'
7544 function find(collection, predicate) {
7545 predicate = getIteratee(predicate, 3);
7546 if (isArray(collection)) {
7547 var index = baseFindIndex(collection, predicate);
7548 return index > -1 ? collection[index] : undefined;
7550 return baseFind(collection, predicate, baseEach);
7554 * This method is like `_.find` except that it iterates over elements of
7555 * `collection` from right to left.
7559 * @category Collection
7560 * @param {Array|Object} collection The collection to search.
7561 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7562 * @returns {*} Returns the matched element, else `undefined`.
7565 * _.findLast([1, 2, 3, 4], function(n) {
7566 * return n % 2 == 1;
7570 function findLast(collection, predicate) {
7571 predicate = getIteratee(predicate, 3);
7572 if (isArray(collection)) {
7573 var index = baseFindIndex(collection, predicate, true);
7574 return index > -1 ? collection[index] : undefined;
7576 return baseFind(collection, predicate, baseEachRight);
7580 * Creates an array of flattened values by running each element in `collection`
7581 * through `iteratee` and concating its result to the other mapped values.
7582 * The iteratee is invoked with three arguments: (value, index|key, collection).
7586 * @category Collection
7587 * @param {Array|Object} collection The collection to iterate over.
7588 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
7589 * @returns {Array} Returns the new flattened array.
7592 * function duplicate(n) {
7596 * _.flatMap([1, 2], duplicate);
7597 * // => [1, 1, 2, 2]
7599 function flatMap(collection, iteratee) {
7600 return baseFlatten(map(collection, iteratee));
7604 * Iterates over elements of `collection` invoking `iteratee` for each element.
7605 * The iteratee is invoked with three arguments: (value, index|key, collection).
7606 * Iteratee functions may exit iteration early by explicitly returning `false`.
7608 * **Note:** As with other "Collections" methods, objects with a "length" property
7609 * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
7610 * for object iteration.
7615 * @category Collection
7616 * @param {Array|Object} collection The collection to iterate over.
7617 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7618 * @returns {Array|Object} Returns `collection`.
7621 * _([1, 2]).forEach(function(value) {
7622 * console.log(value);
7624 * // => logs `1` then `2`
7626 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
7629 * // => logs 'a' then 'b' (iteration order is not guaranteed)
7631 function forEach(collection, iteratee) {
7632 return (typeof iteratee == 'function' && isArray(collection))
7633 ? arrayEach(collection, iteratee)
7634 : baseEach(collection, toFunction(iteratee));
7638 * This method is like `_.forEach` except that it iterates over elements of
7639 * `collection` from right to left.
7644 * @category Collection
7645 * @param {Array|Object} collection The collection to iterate over.
7646 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7647 * @returns {Array|Object} Returns `collection`.
7650 * _.forEachRight([1, 2], function(value) {
7651 * console.log(value);
7653 * // => logs `2` then `1`
7655 function forEachRight(collection, iteratee) {
7656 return (typeof iteratee == 'function' && isArray(collection))
7657 ? arrayEachRight(collection, iteratee)
7658 : baseEachRight(collection, toFunction(iteratee));
7662 * Creates an object composed of keys generated from the results of running
7663 * each element of `collection` through `iteratee`. The corresponding value
7664 * of each key is an array of elements responsible for generating the key.
7665 * The iteratee is invoked with one argument: (value).
7669 * @category Collection
7670 * @param {Array|Object} collection The collection to iterate over.
7671 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7672 * @returns {Object} Returns the composed aggregate object.
7675 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
7676 * // => { '4': [4.2], '6': [6.1, 6.3] }
7678 * // The `_.property` iteratee shorthand.
7679 * _.groupBy(['one', 'two', 'three'], 'length');
7680 * // => { '3': ['one', 'two'], '5': ['three'] }
7682 var groupBy = createAggregator(function(result, value, key) {
7683 if (hasOwnProperty.call(result, key)) {
7684 result[key].push(value);
7686 result[key] = [value];
7691 * Checks if `value` is in `collection`. If `collection` is a string it's checked
7692 * for a substring of `value`, otherwise [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7693 * is used for equality comparisons. If `fromIndex` is negative, it's used as
7694 * the offset from the end of `collection`.
7698 * @category Collection
7699 * @param {Array|Object|string} collection The collection to search.
7700 * @param {*} value The value to search for.
7701 * @param {number} [fromIndex=0] The index to search from.
7702 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`.
7703 * @returns {boolean} Returns `true` if `value` is found, else `false`.
7706 * _.includes([1, 2, 3], 1);
7709 * _.includes([1, 2, 3], 1, 2);
7712 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
7715 * _.includes('pebbles', 'eb');
7718 function includes(collection, value, fromIndex, guard) {
7719 collection = isArrayLike(collection) ? collection : values(collection);
7720 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
7722 var length = collection.length;
7723 if (fromIndex < 0) {
7724 fromIndex = nativeMax(length + fromIndex, 0);
7726 return isString(collection)
7727 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
7728 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
7732 * Invokes the method at `path` of each element in `collection`, returning
7733 * an array of the results of each invoked method. Any additional arguments
7734 * are provided to each invoked method. If `methodName` is a function it's
7735 * invoked for, and `this` bound to, each element in `collection`.
7739 * @category Collection
7740 * @param {Array|Object} collection The collection to iterate over.
7741 * @param {Array|Function|string} path The path of the method to invoke or
7742 * the function invoked per iteration.
7743 * @param {...*} [args] The arguments to invoke each method with.
7744 * @returns {Array} Returns the array of results.
7747 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
7748 * // => [[1, 5, 7], [1, 2, 3]]
7750 * _.invokeMap([123, 456], String.prototype.split, '');
7751 * // => [['1', '2', '3'], ['4', '5', '6']]
7753 var invokeMap = rest(function(collection, path, args) {
7755 isFunc = typeof path == 'function',
7756 isProp = isKey(path),
7757 result = isArrayLike(collection) ? Array(collection.length) : [];
7759 baseEach(collection, function(value) {
7760 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
7761 result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
7767 * Creates an object composed of keys generated from the results of running
7768 * each element of `collection` through `iteratee`. The corresponding value
7769 * of each key is the last element responsible for generating the key. The
7770 * iteratee is invoked with one argument: (value).
7774 * @category Collection
7775 * @param {Array|Object} collection The collection to iterate over.
7776 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
7777 * @returns {Object} Returns the composed aggregate object.
7781 * { 'dir': 'left', 'code': 97 },
7782 * { 'dir': 'right', 'code': 100 }
7785 * _.keyBy(array, function(o) {
7786 * return String.fromCharCode(o.code);
7788 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
7790 * _.keyBy(array, 'dir');
7791 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
7793 var keyBy = createAggregator(function(result, value, key) {
7794 result[key] = value;
7798 * Creates an array of values by running each element in `collection` through
7799 * `iteratee`. The iteratee is invoked with three arguments:
7800 * (value, index|key, collection).
7802 * Many lodash methods are guarded to work as iteratees for methods like
7803 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
7805 * The guarded methods are:
7806 * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
7807 * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
7808 * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
7813 * @category Collection
7814 * @param {Array|Object} collection The collection to iterate over.
7815 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
7816 * @returns {Array} Returns the new mapped array.
7819 * function square(n) {
7823 * _.map([4, 8], square);
7826 * _.map({ 'a': 4, 'b': 8 }, square);
7827 * // => [16, 64] (iteration order is not guaranteed)
7830 * { 'user': 'barney' },
7831 * { 'user': 'fred' }
7834 * // The `_.property` iteratee shorthand.
7835 * _.map(users, 'user');
7836 * // => ['barney', 'fred']
7838 function map(collection, iteratee) {
7839 var func = isArray(collection) ? arrayMap : baseMap;
7840 return func(collection, getIteratee(iteratee, 3));
7844 * This method is like `_.sortBy` except that it allows specifying the sort
7845 * orders of the iteratees to sort by. If `orders` is unspecified, all values
7846 * are sorted in ascending order. Otherwise, specify an order of "desc" for
7847 * descending or "asc" for ascending sort order of corresponding values.
7851 * @category Collection
7852 * @param {Array|Object} collection The collection to iterate over.
7853 * @param {Function[]|Object[]|string[]} [iteratees=[_.identity]] The iteratees to sort by.
7854 * @param {string[]} [orders] The sort orders of `iteratees`.
7855 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.reduce`.
7856 * @returns {Array} Returns the new sorted array.
7860 * { 'user': 'fred', 'age': 48 },
7861 * { 'user': 'barney', 'age': 34 },
7862 * { 'user': 'fred', 'age': 42 },
7863 * { 'user': 'barney', 'age': 36 }
7866 * // Sort by `user` in ascending order and by `age` in descending order.
7867 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
7868 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
7870 function orderBy(collection, iteratees, orders, guard) {
7871 if (collection == null) {
7874 if (!isArray(iteratees)) {
7875 iteratees = iteratees == null ? [] : [iteratees];
7877 orders = guard ? undefined : orders;
7878 if (!isArray(orders)) {
7879 orders = orders == null ? [] : [orders];
7881 return baseOrderBy(collection, iteratees, orders);
7885 * Creates an array of elements split into two groups, the first of which
7886 * contains elements `predicate` returns truthy for, the second of which
7887 * contains elements `predicate` returns falsey for. The predicate is
7888 * invoked with one argument: (value).
7892 * @category Collection
7893 * @param {Array|Object} collection The collection to iterate over.
7894 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
7895 * @returns {Array} Returns the array of grouped elements.
7899 * { 'user': 'barney', 'age': 36, 'active': false },
7900 * { 'user': 'fred', 'age': 40, 'active': true },
7901 * { 'user': 'pebbles', 'age': 1, 'active': false }
7904 * _.partition(users, function(o) { return o.active; });
7905 * // => objects for [['fred'], ['barney', 'pebbles']]
7907 * // The `_.matches` iteratee shorthand.
7908 * _.partition(users, { 'age': 1, 'active': false });
7909 * // => objects for [['pebbles'], ['barney', 'fred']]
7911 * // The `_.matchesProperty` iteratee shorthand.
7912 * _.partition(users, ['active', false]);
7913 * // => objects for [['barney', 'pebbles'], ['fred']]
7915 * // The `_.property` iteratee shorthand.
7916 * _.partition(users, 'active');
7917 * // => objects for [['fred'], ['barney', 'pebbles']]
7919 var partition = createAggregator(function(result, value, key) {
7920 result[key ? 0 : 1].push(value);
7921 }, function() { return [[], []]; });
7924 * Reduces `collection` to a value which is the accumulated result of running
7925 * each element in `collection` through `iteratee`, where each successive
7926 * invocation is supplied the return value of the previous. If `accumulator`
7927 * is not given the first element of `collection` is used as the initial
7928 * value. The iteratee is invoked with four arguments:
7929 * (accumulator, value, index|key, collection).
7931 * Many lodash methods are guarded to work as iteratees for methods like
7932 * `_.reduce`, `_.reduceRight`, and `_.transform`.
7934 * The guarded methods are:
7935 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
7940 * @category Collection
7941 * @param {Array|Object} collection The collection to iterate over.
7942 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7943 * @param {*} [accumulator] The initial value.
7944 * @returns {*} Returns the accumulated value.
7947 * _.reduce([1, 2], function(sum, n) {
7952 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
7953 * (result[value] || (result[value] = [])).push(key);
7956 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
7958 function reduce(collection, iteratee, accumulator) {
7959 var func = isArray(collection) ? arrayReduce : baseReduce,
7960 initAccum = arguments.length < 3;
7962 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
7966 * This method is like `_.reduce` except that it iterates over elements of
7967 * `collection` from right to left.
7971 * @category Collection
7972 * @param {Array|Object} collection The collection to iterate over.
7973 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7974 * @param {*} [accumulator] The initial value.
7975 * @returns {*} Returns the accumulated value.
7978 * var array = [[0, 1], [2, 3], [4, 5]];
7980 * _.reduceRight(array, function(flattened, other) {
7981 * return flattened.concat(other);
7983 * // => [4, 5, 2, 3, 0, 1]
7985 function reduceRight(collection, iteratee, accumulator) {
7986 var func = isArray(collection) ? arrayReduceRight : baseReduce,
7987 initAccum = arguments.length < 3;
7989 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
7993 * The opposite of `_.filter`; this method returns the elements of `collection`
7994 * that `predicate` does **not** return truthy for.
7998 * @category Collection
7999 * @param {Array|Object} collection The collection to iterate over.
8000 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
8001 * @returns {Array} Returns the new filtered array.
8005 * { 'user': 'barney', 'age': 36, 'active': false },
8006 * { 'user': 'fred', 'age': 40, 'active': true }
8009 * _.reject(users, function(o) { return !o.active; });
8010 * // => objects for ['fred']
8012 * // The `_.matches` iteratee shorthand.
8013 * _.reject(users, { 'age': 40, 'active': true });
8014 * // => objects for ['barney']
8016 * // The `_.matchesProperty` iteratee shorthand.
8017 * _.reject(users, ['active', false]);
8018 * // => objects for ['fred']
8020 * // The `_.property` iteratee shorthand.
8021 * _.reject(users, 'active');
8022 * // => objects for ['barney']
8024 function reject(collection, predicate) {
8025 var func = isArray(collection) ? arrayFilter : baseFilter;
8026 predicate = getIteratee(predicate, 3);
8027 return func(collection, function(value, index, collection) {
8028 return !predicate(value, index, collection);
8033 * Gets a random element from `collection`.
8037 * @category Collection
8038 * @param {Array|Object} collection The collection to sample.
8039 * @returns {*} Returns the random element.
8042 * _.sample([1, 2, 3, 4]);
8045 function sample(collection) {
8046 var array = isArrayLike(collection) ? collection : values(collection),
8047 length = array.length;
8049 return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
8053 * Gets `n` random elements at unique keys from `collection` up to the
8054 * size of `collection`.
8058 * @category Collection
8059 * @param {Array|Object} collection The collection to sample.
8060 * @param {number} [n=0] The number of elements to sample.
8061 * @returns {Array} Returns the random elements.
8064 * _.sampleSize([1, 2, 3], 2);
8067 * _.sampleSize([1, 2, 3], 4);
8070 function sampleSize(collection, n) {
8072 result = toArray(collection),
8073 length = result.length,
8074 lastIndex = length - 1;
8076 n = baseClamp(toInteger(n), 0, length);
8077 while (++index < n) {
8078 var rand = baseRandom(index, lastIndex),
8079 value = result[rand];
8081 result[rand] = result[index];
8082 result[index] = value;
8089 * Creates an array of shuffled values, using a version of the
8090 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
8094 * @category Collection
8095 * @param {Array|Object} collection The collection to shuffle.
8096 * @returns {Array} Returns the new shuffled array.
8099 * _.shuffle([1, 2, 3, 4]);
8100 * // => [4, 1, 3, 2]
8102 function shuffle(collection) {
8103 return sampleSize(collection, MAX_ARRAY_LENGTH);
8107 * Gets the size of `collection` by returning its length for array-like
8108 * values or the number of own enumerable properties for objects.
8112 * @category Collection
8113 * @param {Array|Object} collection The collection to inspect.
8114 * @returns {number} Returns the collection size.
8117 * _.size([1, 2, 3]);
8120 * _.size({ 'a': 1, 'b': 2 });
8123 * _.size('pebbles');
8126 function size(collection) {
8127 if (collection == null) {
8130 if (isArrayLike(collection)) {
8131 var result = collection.length;
8132 return (result && isString(collection)) ? stringSize(collection) : result;
8134 return keys(collection).length;
8138 * Checks if `predicate` returns truthy for **any** element of `collection`.
8139 * Iteration is stopped once `predicate` returns truthy. The predicate is
8140 * invoked with three arguments: (value, index|key, collection).
8144 * @category Collection
8145 * @param {Array|Object} collection The collection to iterate over.
8146 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
8147 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8148 * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
8151 * _.some([null, 0, 'yes', false], Boolean);
8155 * { 'user': 'barney', 'active': true },
8156 * { 'user': 'fred', 'active': false }
8159 * // The `_.matches` iteratee shorthand.
8160 * _.some(users, { 'user': 'barney', 'active': false });
8163 * // The `_.matchesProperty` iteratee shorthand.
8164 * _.some(users, ['active', false]);
8167 * // The `_.property` iteratee shorthand.
8168 * _.some(users, 'active');
8171 function some(collection, predicate, guard) {
8172 var func = isArray(collection) ? arraySome : baseSome;
8173 if (guard && isIterateeCall(collection, predicate, guard)) {
8174 predicate = undefined;
8176 return func(collection, getIteratee(predicate, 3));
8180 * Creates an array of elements, sorted in ascending order by the results of
8181 * running each element in a collection through each iteratee. This method
8182 * performs a stable sort, that is, it preserves the original sort order of
8183 * equal elements. The iteratees are invoked with one argument: (value).
8187 * @category Collection
8188 * @param {Array|Object} collection The collection to iterate over.
8189 * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
8190 * The iteratees to sort by, specified individually or in arrays.
8191 * @returns {Array} Returns the new sorted array.
8195 * { 'user': 'fred', 'age': 48 },
8196 * { 'user': 'barney', 'age': 36 },
8197 * { 'user': 'fred', 'age': 42 },
8198 * { 'user': 'barney', 'age': 34 }
8201 * _.sortBy(users, function(o) { return o.user; });
8202 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
8204 * _.sortBy(users, ['user', 'age']);
8205 * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
8207 * _.sortBy(users, 'user', function(o) {
8208 * return Math.floor(o.age / 10);
8210 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
8212 var sortBy = rest(function(collection, iteratees) {
8213 if (collection == null) {
8216 var length = iteratees.length;
8217 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
8219 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
8220 iteratees.length = 1;
8222 return baseOrderBy(collection, baseFlatten(iteratees), []);
8225 /*------------------------------------------------------------------------*/
8228 * Gets the timestamp of the number of milliseconds that have elapsed since
8229 * the Unix epoch (1 January 1970 00:00:00 UTC).
8235 * @returns {number} Returns the timestamp.
8238 * _.defer(function(stamp) {
8239 * console.log(_.now() - stamp);
8241 * // => logs the number of milliseconds it took for the deferred function to be invoked
8245 /*------------------------------------------------------------------------*/
8248 * The opposite of `_.before`; this method creates a function that invokes
8249 * `func` once it's called `n` or more times.
8253 * @category Function
8254 * @param {number} n The number of calls before `func` is invoked.
8255 * @param {Function} func The function to restrict.
8256 * @returns {Function} Returns the new restricted function.
8259 * var saves = ['profile', 'settings'];
8261 * var done = _.after(saves.length, function() {
8262 * console.log('done saving!');
8265 * _.forEach(saves, function(type) {
8266 * asyncSave({ 'type': type, 'complete': done });
8268 * // => logs 'done saving!' after the two async saves have completed
8270 function after(n, func) {
8271 if (typeof func != 'function') {
8272 throw new TypeError(FUNC_ERROR_TEXT);
8277 return func.apply(this, arguments);
8283 * Creates a function that accepts up to `n` arguments, ignoring any
8284 * additional arguments.
8288 * @category Function
8289 * @param {Function} func The function to cap arguments for.
8290 * @param {number} [n=func.length] The arity cap.
8291 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8292 * @returns {Function} Returns the new function.
8295 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
8298 function ary(func, n, guard) {
8299 n = guard ? undefined : n;
8300 n = (func && n == null) ? func.length : n;
8301 return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
8305 * Creates a function that invokes `func`, with the `this` binding and arguments
8306 * of the created function, while it's called less than `n` times. Subsequent
8307 * calls to the created function return the result of the last `func` invocation.
8311 * @category Function
8312 * @param {number} n The number of calls at which `func` is no longer invoked.
8313 * @param {Function} func The function to restrict.
8314 * @returns {Function} Returns the new restricted function.
8317 * jQuery(element).on('click', _.before(5, addContactToList));
8318 * // => allows adding up to 4 contacts to the list
8320 function before(n, func) {
8322 if (typeof func != 'function') {
8323 throw new TypeError(FUNC_ERROR_TEXT);
8328 result = func.apply(this, arguments);
8338 * Creates a function that invokes `func` with the `this` binding of `thisArg`
8339 * and prepends any additional `_.bind` arguments to those provided to the
8342 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
8343 * may be used as a placeholder for partially applied arguments.
8345 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
8346 * property of bound functions.
8350 * @category Function
8351 * @param {Function} func The function to bind.
8352 * @param {*} thisArg The `this` binding of `func`.
8353 * @param {...*} [partials] The arguments to be partially applied.
8354 * @returns {Function} Returns the new bound function.
8357 * var greet = function(greeting, punctuation) {
8358 * return greeting + ' ' + this.user + punctuation;
8361 * var object = { 'user': 'fred' };
8363 * var bound = _.bind(greet, object, 'hi');
8367 * // Bound with placeholders.
8368 * var bound = _.bind(greet, object, _, '!');
8372 var bind = rest(function(func, thisArg, partials) {
8373 var bitmask = BIND_FLAG;
8374 if (partials.length) {
8375 var placeholder = lodash.placeholder || bind.placeholder,
8376 holders = replaceHolders(partials, placeholder);
8378 bitmask |= PARTIAL_FLAG;
8380 return createWrapper(func, bitmask, thisArg, partials, holders);
8384 * Creates a function that invokes the method at `object[key]` and prepends
8385 * any additional `_.bindKey` arguments to those provided to the bound function.
8387 * This method differs from `_.bind` by allowing bound functions to reference
8388 * methods that may be redefined or don't yet exist.
8389 * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
8392 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
8393 * builds, may be used as a placeholder for partially applied arguments.
8397 * @category Function
8398 * @param {Object} object The object to invoke the method on.
8399 * @param {string} key The key of the method.
8400 * @param {...*} [partials] The arguments to be partially applied.
8401 * @returns {Function} Returns the new bound function.
8406 * 'greet': function(greeting, punctuation) {
8407 * return greeting + ' ' + this.user + punctuation;
8411 * var bound = _.bindKey(object, 'greet', 'hi');
8415 * object.greet = function(greeting, punctuation) {
8416 * return greeting + 'ya ' + this.user + punctuation;
8420 * // => 'hiya fred!'
8422 * // Bound with placeholders.
8423 * var bound = _.bindKey(object, 'greet', _, '!');
8425 * // => 'hiya fred!'
8427 var bindKey = rest(function(object, key, partials) {
8428 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
8429 if (partials.length) {
8430 var placeholder = lodash.placeholder || bindKey.placeholder,
8431 holders = replaceHolders(partials, placeholder);
8433 bitmask |= PARTIAL_FLAG;
8435 return createWrapper(key, bitmask, object, partials, holders);
8439 * Creates a function that accepts arguments of `func` and either invokes
8440 * `func` returning its result, if at least `arity` number of arguments have
8441 * been provided, or returns a function that accepts the remaining `func`
8442 * arguments, and so on. The arity of `func` may be specified if `func.length`
8443 * is not sufficient.
8445 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
8446 * may be used as a placeholder for provided arguments.
8448 * **Note:** This method doesn't set the "length" property of curried functions.
8452 * @category Function
8453 * @param {Function} func The function to curry.
8454 * @param {number} [arity=func.length] The arity of `func`.
8455 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8456 * @returns {Function} Returns the new curried function.
8459 * var abc = function(a, b, c) {
8463 * var curried = _.curry(abc);
8474 * // Curried with placeholders.
8475 * curried(1)(_, 3)(2);
8478 function curry(func, arity, guard) {
8479 arity = guard ? undefined : arity;
8480 var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
8481 result.placeholder = lodash.placeholder || curry.placeholder;
8486 * This method is like `_.curry` except that arguments are applied to `func`
8487 * in the manner of `_.partialRight` instead of `_.partial`.
8489 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
8490 * builds, may be used as a placeholder for provided arguments.
8492 * **Note:** This method doesn't set the "length" property of curried functions.
8496 * @category Function
8497 * @param {Function} func The function to curry.
8498 * @param {number} [arity=func.length] The arity of `func`.
8499 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
8500 * @returns {Function} Returns the new curried function.
8503 * var abc = function(a, b, c) {
8507 * var curried = _.curryRight(abc);
8518 * // Curried with placeholders.
8519 * curried(3)(1, _)(2);
8522 function curryRight(func, arity, guard) {
8523 arity = guard ? undefined : arity;
8524 var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
8525 result.placeholder = lodash.placeholder || curryRight.placeholder;
8530 * Creates a debounced function that delays invoking `func` until after `wait`
8531 * milliseconds have elapsed since the last time the debounced function was
8532 * invoked. The debounced function comes with a `cancel` method to cancel
8533 * delayed `func` invocations and a `flush` method to immediately invoke them.
8534 * Provide an options object to indicate whether `func` should be invoked on
8535 * the leading and/or trailing edge of the `wait` timeout. The `func` is invoked
8536 * with the last arguments provided to the debounced function. Subsequent calls
8537 * to the debounced function return the result of the last `func` invocation.
8539 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
8540 * on the trailing edge of the timeout only if the debounced function is
8541 * invoked more than once during the `wait` timeout.
8543 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
8544 * for details over the differences between `_.debounce` and `_.throttle`.
8548 * @category Function
8549 * @param {Function} func The function to debounce.
8550 * @param {number} [wait=0] The number of milliseconds to delay.
8551 * @param {Object} [options] The options object.
8552 * @param {boolean} [options.leading=false] Specify invoking on the leading
8553 * edge of the timeout.
8554 * @param {number} [options.maxWait] The maximum time `func` is allowed to be
8555 * delayed before it's invoked.
8556 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
8557 * edge of the timeout.
8558 * @returns {Function} Returns the new debounced function.
8561 * // Avoid costly calculations while the window size is in flux.
8562 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
8564 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
8565 * jQuery(element).on('click', _.debounce(sendMail, 300, {
8570 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
8571 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
8572 * var source = new EventSource('/stream');
8573 * jQuery(source).on('message', debounced);
8575 * // Cancel the trailing debounced invocation.
8576 * jQuery(window).on('popstate', debounced.cancel);
8578 function debounce(func, wait, options) {
8591 if (typeof func != 'function') {
8592 throw new TypeError(FUNC_ERROR_TEXT);
8594 wait = toNumber(wait) || 0;
8595 if (isObject(options)) {
8596 leading = !!options.leading;
8597 maxWait = 'maxWait' in options && nativeMax(toNumber(options.maxWait) || 0, wait);
8598 trailing = 'trailing' in options ? !!options.trailing : trailing;
8603 clearTimeout(timeoutId);
8606 clearTimeout(maxTimeoutId);
8609 args = maxTimeoutId = thisArg = timeoutId = trailingCall = undefined;
8612 function complete(isCalled, id) {
8616 maxTimeoutId = timeoutId = trailingCall = undefined;
8619 result = func.apply(thisArg, args);
8620 if (!timeoutId && !maxTimeoutId) {
8621 args = thisArg = undefined;
8626 function delayed() {
8627 var remaining = wait - (now() - stamp);
8628 if (remaining <= 0 || remaining > wait) {
8629 complete(trailingCall, maxTimeoutId);
8631 timeoutId = setTimeout(delayed, remaining);
8636 if ((timeoutId && trailingCall) || (maxTimeoutId && trailing)) {
8637 result = func.apply(thisArg, args);
8643 function maxDelayed() {
8644 complete(trailing, timeoutId);
8647 function debounced() {
8651 trailingCall = trailing && (timeoutId || !leading);
8653 if (maxWait === false) {
8654 var leadingCall = leading && !timeoutId;
8656 if (!lastCalled && !maxTimeoutId && !leading) {
8659 var remaining = maxWait - (stamp - lastCalled),
8660 isCalled = remaining <= 0 || remaining > maxWait;
8664 maxTimeoutId = clearTimeout(maxTimeoutId);
8667 result = func.apply(thisArg, args);
8669 else if (!maxTimeoutId) {
8670 maxTimeoutId = setTimeout(maxDelayed, remaining);
8673 if (isCalled && timeoutId) {
8674 timeoutId = clearTimeout(timeoutId);
8676 else if (!timeoutId && wait !== maxWait) {
8677 timeoutId = setTimeout(delayed, wait);
8681 result = func.apply(thisArg, args);
8683 if (isCalled && !timeoutId && !maxTimeoutId) {
8684 args = thisArg = undefined;
8688 debounced.cancel = cancel;
8689 debounced.flush = flush;
8694 * Defers invoking the `func` until the current call stack has cleared. Any
8695 * additional arguments are provided to `func` when it's invoked.
8699 * @category Function
8700 * @param {Function} func The function to defer.
8701 * @param {...*} [args] The arguments to invoke `func` with.
8702 * @returns {number} Returns the timer id.
8705 * _.defer(function(text) {
8706 * console.log(text);
8708 * // => logs 'deferred' after one or more milliseconds
8710 var defer = rest(function(func, args) {
8711 return baseDelay(func, 1, args);
8715 * Invokes `func` after `wait` milliseconds. Any additional arguments are
8716 * provided to `func` when it's invoked.
8720 * @category Function
8721 * @param {Function} func The function to delay.
8722 * @param {number} wait The number of milliseconds to delay invocation.
8723 * @param {...*} [args] The arguments to invoke `func` with.
8724 * @returns {number} Returns the timer id.
8727 * _.delay(function(text) {
8728 * console.log(text);
8729 * }, 1000, 'later');
8730 * // => logs 'later' after one second
8732 var delay = rest(function(func, wait, args) {
8733 return baseDelay(func, toNumber(wait) || 0, args);
8737 * Creates a function that invokes `func` with arguments reversed.
8741 * @category Function
8742 * @param {Function} func The function to flip arguments for.
8743 * @returns {Function} Returns the new function.
8746 * var flipped = _.flip(function() {
8747 * return _.toArray(arguments);
8750 * flipped('a', 'b', 'c', 'd');
8751 * // => ['d', 'c', 'b', 'a']
8753 function flip(func) {
8754 return createWrapper(func, FLIP_FLAG);
8758 * Creates a function that memoizes the result of `func`. If `resolver` is
8759 * provided it determines the cache key for storing the result based on the
8760 * arguments provided to the memoized function. By default, the first argument
8761 * provided to the memoized function is used as the map cache key. The `func`
8762 * is invoked with the `this` binding of the memoized function.
8764 * **Note:** The cache is exposed as the `cache` property on the memoized
8765 * function. Its creation may be customized by replacing the `_.memoize.Cache`
8766 * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
8767 * method interface of `delete`, `get`, `has`, and `set`.
8771 * @category Function
8772 * @param {Function} func The function to have its output memoized.
8773 * @param {Function} [resolver] The function to resolve the cache key.
8774 * @returns {Function} Returns the new memoizing function.
8777 * var object = { 'a': 1, 'b': 2 };
8778 * var other = { 'c': 3, 'd': 4 };
8780 * var values = _.memoize(_.values);
8791 * // Modify the result cache.
8792 * values.cache.set(object, ['a', 'b']);
8796 * // Replace `_.memoize.Cache`.
8797 * _.memoize.Cache = WeakMap;
8799 function memoize(func, resolver) {
8800 if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
8801 throw new TypeError(FUNC_ERROR_TEXT);
8803 var memoized = function() {
8804 var args = arguments,
8805 key = resolver ? resolver.apply(this, args) : args[0],
8806 cache = memoized.cache;
8808 if (cache.has(key)) {
8809 return cache.get(key);
8811 var result = func.apply(this, args);
8812 memoized.cache = cache.set(key, result);
8815 memoized.cache = new memoize.Cache;
8820 * Creates a function that negates the result of the predicate `func`. The
8821 * `func` predicate is invoked with the `this` binding and arguments of the
8826 * @category Function
8827 * @param {Function} predicate The predicate to negate.
8828 * @returns {Function} Returns the new function.
8831 * function isEven(n) {
8832 * return n % 2 == 0;
8835 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
8838 function negate(predicate) {
8839 if (typeof predicate != 'function') {
8840 throw new TypeError(FUNC_ERROR_TEXT);
8843 return !predicate.apply(this, arguments);
8848 * Creates a function that is restricted to invoking `func` once. Repeat calls
8849 * to the function return the value of the first invocation. The `func` is
8850 * invoked with the `this` binding and arguments of the created function.
8854 * @category Function
8855 * @param {Function} func The function to restrict.
8856 * @returns {Function} Returns the new restricted function.
8859 * var initialize = _.once(createApplication);
8862 * // `initialize` invokes `createApplication` once
8864 function once(func) {
8865 return before(2, func);
8869 * Creates a function that invokes `func` with arguments transformed by
8870 * corresponding `transforms`.
8874 * @category Function
8875 * @param {Function} func The function to wrap.
8876 * @param {...(Function|Function[])} [transforms] The functions to transform
8877 * arguments, specified individually or in arrays.
8878 * @returns {Function} Returns the new function.
8881 * function doubled(n) {
8885 * function square(n) {
8889 * var func = _.overArgs(function(x, y) {
8891 * }, square, doubled);
8899 var overArgs = rest(function(func, transforms) {
8900 transforms = arrayMap(baseFlatten(transforms), getIteratee());
8902 var funcsLength = transforms.length;
8903 return rest(function(args) {
8905 length = nativeMin(args.length, funcsLength);
8907 while (++index < length) {
8908 args[index] = transforms[index].call(this, args[index]);
8910 return apply(func, this, args);
8915 * Creates a function that invokes `func` with `partial` arguments prepended
8916 * to those provided to the new function. This method is like `_.bind` except
8917 * it does **not** alter the `this` binding.
8919 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
8920 * builds, may be used as a placeholder for partially applied arguments.
8922 * **Note:** This method doesn't set the "length" property of partially
8923 * applied functions.
8927 * @category Function
8928 * @param {Function} func The function to partially apply arguments to.
8929 * @param {...*} [partials] The arguments to be partially applied.
8930 * @returns {Function} Returns the new partially applied function.
8933 * var greet = function(greeting, name) {
8934 * return greeting + ' ' + name;
8937 * var sayHelloTo = _.partial(greet, 'hello');
8938 * sayHelloTo('fred');
8939 * // => 'hello fred'
8941 * // Partially applied with placeholders.
8942 * var greetFred = _.partial(greet, _, 'fred');
8946 var partial = rest(function(func, partials) {
8947 var placeholder = lodash.placeholder || partial.placeholder,
8948 holders = replaceHolders(partials, placeholder);
8950 return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
8954 * This method is like `_.partial` except that partially applied arguments
8955 * are appended to those provided to the new function.
8957 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
8958 * builds, may be used as a placeholder for partially applied arguments.
8960 * **Note:** This method doesn't set the "length" property of partially
8961 * applied functions.
8965 * @category Function
8966 * @param {Function} func The function to partially apply arguments to.
8967 * @param {...*} [partials] The arguments to be partially applied.
8968 * @returns {Function} Returns the new partially applied function.
8971 * var greet = function(greeting, name) {
8972 * return greeting + ' ' + name;
8975 * var greetFred = _.partialRight(greet, 'fred');
8979 * // Partially applied with placeholders.
8980 * var sayHelloTo = _.partialRight(greet, 'hello', _);
8981 * sayHelloTo('fred');
8982 * // => 'hello fred'
8984 var partialRight = rest(function(func, partials) {
8985 var placeholder = lodash.placeholder || partialRight.placeholder,
8986 holders = replaceHolders(partials, placeholder);
8988 return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
8992 * Creates a function that invokes `func` with arguments arranged according
8993 * to the specified indexes where the argument value at the first index is
8994 * provided as the first argument, the argument value at the second index is
8995 * provided as the second argument, and so on.
8999 * @category Function
9000 * @param {Function} func The function to rearrange arguments for.
9001 * @param {...(number|number[])} indexes The arranged argument indexes,
9002 * specified individually or in arrays.
9003 * @returns {Function} Returns the new function.
9006 * var rearged = _.rearg(function(a, b, c) {
9010 * rearged('b', 'c', 'a')
9011 * // => ['a', 'b', 'c']
9013 var rearg = rest(function(func, indexes) {
9014 return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
9018 * Creates a function that invokes `func` with the `this` binding of the
9019 * created function and arguments from `start` and beyond provided as an array.
9021 * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
9025 * @category Function
9026 * @param {Function} func The function to apply a rest parameter to.
9027 * @param {number} [start=func.length-1] The start position of the rest parameter.
9028 * @returns {Function} Returns the new function.
9031 * var say = _.rest(function(what, names) {
9032 * return what + ' ' + _.initial(names).join(', ') +
9033 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
9036 * say('hello', 'fred', 'barney', 'pebbles');
9037 * // => 'hello fred, barney, & pebbles'
9039 function rest(func, start) {
9040 if (typeof func != 'function') {
9041 throw new TypeError(FUNC_ERROR_TEXT);
9043 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
9045 var args = arguments,
9047 length = nativeMax(args.length - start, 0),
9048 array = Array(length);
9050 while (++index < length) {
9051 array[index] = args[start + index];
9054 case 0: return func.call(this, array);
9055 case 1: return func.call(this, args[0], array);
9056 case 2: return func.call(this, args[0], args[1], array);
9058 var otherArgs = Array(start + 1);
9060 while (++index < start) {
9061 otherArgs[index] = args[index];
9063 otherArgs[start] = array;
9064 return apply(func, this, otherArgs);
9069 * Creates a function that invokes `func` with the `this` binding of the created
9070 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
9072 * **Note:** This method is based on the [spread operator](https://mdn.io/spread_operator).
9076 * @category Function
9077 * @param {Function} func The function to spread arguments over.
9078 * @param {number} [start=0] The start position of the spread.
9079 * @returns {Function} Returns the new function.
9082 * var say = _.spread(function(who, what) {
9083 * return who + ' says ' + what;
9086 * say(['fred', 'hello']);
9087 * // => 'fred says hello'
9089 * var numbers = Promise.all([
9090 * Promise.resolve(40),
9091 * Promise.resolve(36)
9094 * numbers.then(_.spread(function(x, y) {
9097 * // => a Promise of 76
9099 function spread(func, start) {
9100 if (typeof func != 'function') {
9101 throw new TypeError(FUNC_ERROR_TEXT);
9103 start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
9104 return rest(function(args) {
9105 var array = args[start],
9106 otherArgs = args.slice(0, start);
9109 arrayPush(otherArgs, array);
9111 return apply(func, this, otherArgs);
9116 * Creates a throttled function that only invokes `func` at most once per
9117 * every `wait` milliseconds. The throttled function comes with a `cancel`
9118 * method to cancel delayed `func` invocations and a `flush` method to
9119 * immediately invoke them. Provide an options object to indicate whether
9120 * `func` should be invoked on the leading and/or trailing edge of the `wait`
9121 * timeout. The `func` is invoked with the last arguments provided to the
9122 * throttled function. Subsequent calls to the throttled function return the
9123 * result of the last `func` invocation.
9125 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
9126 * on the trailing edge of the timeout only if the throttled function is
9127 * invoked more than once during the `wait` timeout.
9129 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
9130 * for details over the differences between `_.throttle` and `_.debounce`.
9134 * @category Function
9135 * @param {Function} func The function to throttle.
9136 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
9137 * @param {Object} [options] The options object.
9138 * @param {boolean} [options.leading=true] Specify invoking on the leading
9139 * edge of the timeout.
9140 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
9141 * edge of the timeout.
9142 * @returns {Function} Returns the new throttled function.
9145 * // Avoid excessively updating the position while scrolling.
9146 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
9148 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
9149 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
9150 * jQuery(element).on('click', throttled);
9152 * // Cancel the trailing throttled invocation.
9153 * jQuery(window).on('popstate', throttled.cancel);
9155 function throttle(func, wait, options) {
9159 if (typeof func != 'function') {
9160 throw new TypeError(FUNC_ERROR_TEXT);
9162 if (isObject(options)) {
9163 leading = 'leading' in options ? !!options.leading : leading;
9164 trailing = 'trailing' in options ? !!options.trailing : trailing;
9166 return debounce(func, wait, { 'leading': leading, 'maxWait': wait, 'trailing': trailing });
9170 * Creates a function that accepts up to one argument, ignoring any
9171 * additional arguments.
9175 * @category Function
9176 * @param {Function} func The function to cap arguments for.
9177 * @returns {Function} Returns the new function.
9180 * _.map(['6', '8', '10'], _.unary(parseInt));
9183 function unary(func) {
9184 return ary(func, 1);
9188 * Creates a function that provides `value` to the wrapper function as its
9189 * first argument. Any additional arguments provided to the function are
9190 * appended to those provided to the wrapper function. The wrapper is invoked
9191 * with the `this` binding of the created function.
9195 * @category Function
9196 * @param {*} value The value to wrap.
9197 * @param {Function} wrapper The wrapper function.
9198 * @returns {Function} Returns the new function.
9201 * var p = _.wrap(_.escape, function(func, text) {
9202 * return '<p>' + func(text) + '</p>';
9205 * p('fred, barney, & pebbles');
9206 * // => '<p>fred, barney, & pebbles</p>'
9208 function wrap(value, wrapper) {
9209 wrapper = wrapper == null ? identity : wrapper;
9210 return partial(wrapper, value);
9213 /*------------------------------------------------------------------------*/
9216 * Creates a shallow clone of `value`.
9218 * **Note:** This method is loosely based on the
9219 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
9220 * and supports cloning arrays, array buffers, booleans, date objects, maps,
9221 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
9222 * arrays. The own enumerable properties of `arguments` objects are cloned
9223 * as plain objects. An empty object is returned for uncloneable values such
9224 * as error objects, functions, DOM nodes, and WeakMaps.
9229 * @param {*} value The value to clone.
9230 * @returns {*} Returns the cloned value.
9233 * var objects = [{ 'a': 1 }, { 'b': 2 }];
9235 * var shallow = _.clone(objects);
9236 * console.log(shallow[0] === objects[0]);
9239 function clone(value) {
9240 return baseClone(value);
9244 * This method is like `_.clone` except that it accepts `customizer` which
9245 * is invoked to produce the cloned value. If `customizer` returns `undefined`
9246 * cloning is handled by the method instead. The `customizer` is invoked with
9247 * up to four arguments; (value [, index|key, object, stack]).
9252 * @param {*} value The value to clone.
9253 * @param {Function} [customizer] The function to customize cloning.
9254 * @returns {*} Returns the cloned value.
9257 * function customizer(value) {
9258 * if (_.isElement(value)) {
9259 * return value.cloneNode(false);
9263 * var el = _.cloneWith(document.body, customizer);
9265 * console.log(el === document.body);
9267 * console.log(el.nodeName);
9269 * console.log(el.childNodes.length);
9272 function cloneWith(value, customizer) {
9273 return baseClone(value, false, customizer);
9277 * This method is like `_.clone` except that it recursively clones `value`.
9282 * @param {*} value The value to recursively clone.
9283 * @returns {*} Returns the deep cloned value.
9286 * var objects = [{ 'a': 1 }, { 'b': 2 }];
9288 * var deep = _.cloneDeep(objects);
9289 * console.log(deep[0] === objects[0]);
9292 function cloneDeep(value) {
9293 return baseClone(value, true);
9297 * This method is like `_.cloneWith` except that it recursively clones `value`.
9302 * @param {*} value The value to recursively clone.
9303 * @param {Function} [customizer] The function to customize cloning.
9304 * @returns {*} Returns the deep cloned value.
9307 * function customizer(value) {
9308 * if (_.isElement(value)) {
9309 * return value.cloneNode(true);
9313 * var el = _.cloneDeepWith(document.body, customizer);
9315 * console.log(el === document.body);
9317 * console.log(el.nodeName);
9319 * console.log(el.childNodes.length);
9322 function cloneDeepWith(value, customizer) {
9323 return baseClone(value, true, customizer);
9327 * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
9328 * comparison between two values to determine if they are equivalent.
9333 * @param {*} value The value to compare.
9334 * @param {*} other The other value to compare.
9335 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9338 * var object = { 'user': 'fred' };
9339 * var other = { 'user': 'fred' };
9341 * _.eq(object, object);
9344 * _.eq(object, other);
9350 * _.eq('a', Object('a'));
9356 function eq(value, other) {
9357 return value === other || (value !== value && other !== other);
9361 * Checks if `value` is greater than `other`.
9366 * @param {*} value The value to compare.
9367 * @param {*} other The other value to compare.
9368 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
9380 function gt(value, other) {
9381 return value > other;
9385 * Checks if `value` is greater than or equal to `other`.
9390 * @param {*} value The value to compare.
9391 * @param {*} other The other value to compare.
9392 * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
9404 function gte(value, other) {
9405 return value >= other;
9409 * Checks if `value` is likely an `arguments` object.
9414 * @param {*} value The value to check.
9415 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9418 * _.isArguments(function() { return arguments; }());
9421 * _.isArguments([1, 2, 3]);
9424 function isArguments(value) {
9425 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
9426 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
9427 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
9431 * Checks if `value` is classified as an `Array` object.
9437 * @param {*} value The value to check.
9438 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9441 * _.isArray([1, 2, 3]);
9444 * _.isArray(document.body.children);
9450 * _.isArray(_.noop);
9453 var isArray = Array.isArray;
9456 * Checks if `value` is classified as an `ArrayBuffer` object.
9462 * @param {*} value The value to check.
9463 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9466 * _.isArrayBuffer(new ArrayBuffer(2));
9469 * _.isArrayBuffer(new Array(2));
9472 function isArrayBuffer(value) {
9473 return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
9477 * Checks if `value` is array-like. A value is considered array-like if it's
9478 * not a function and has a `value.length` that's an integer greater than or
9479 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
9485 * @param {*} value The value to check.
9486 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
9489 * _.isArrayLike([1, 2, 3]);
9492 * _.isArrayLike(document.body.children);
9495 * _.isArrayLike('abc');
9498 * _.isArrayLike(_.noop);
9501 function isArrayLike(value) {
9502 return value != null &&
9503 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
9507 * This method is like `_.isArrayLike` except that it also checks if `value`
9514 * @param {*} value The value to check.
9515 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
9518 * _.isArrayLikeObject([1, 2, 3]);
9521 * _.isArrayLikeObject(document.body.children);
9524 * _.isArrayLikeObject('abc');
9527 * _.isArrayLikeObject(_.noop);
9530 function isArrayLikeObject(value) {
9531 return isObjectLike(value) && isArrayLike(value);
9535 * Checks if `value` is classified as a boolean primitive or object.
9540 * @param {*} value The value to check.
9541 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9544 * _.isBoolean(false);
9547 * _.isBoolean(null);
9550 function isBoolean(value) {
9551 return value === true || value === false ||
9552 (isObjectLike(value) && objectToString.call(value) == boolTag);
9556 * Checks if `value` is a buffer.
9561 * @param {*} value The value to check.
9562 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
9565 * _.isBuffer(new Buffer(2));
9568 * _.isBuffer(new Uint8Array(2));
9571 var isBuffer = !Buffer ? constant(false) : function(value) {
9572 return value instanceof Buffer;
9576 * Checks if `value` is classified as a `Date` object.
9581 * @param {*} value The value to check.
9582 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9585 * _.isDate(new Date);
9588 * _.isDate('Mon April 23 2012');
9591 function isDate(value) {
9592 return isObjectLike(value) && objectToString.call(value) == dateTag;
9596 * Checks if `value` is likely a DOM element.
9601 * @param {*} value The value to check.
9602 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
9605 * _.isElement(document.body);
9608 * _.isElement('<body>');
9611 function isElement(value) {
9612 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
9616 * Checks if `value` is empty. A value is considered empty unless it's an
9617 * `arguments` object, array, string, or jQuery-like collection with a length
9618 * greater than `0` or an object with own enumerable properties.
9623 * @param {Array|Object|string} value The value to inspect.
9624 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
9636 * _.isEmpty([1, 2, 3]);
9639 * _.isEmpty({ 'a': 1 });
9642 function isEmpty(value) {
9643 if (isArrayLike(value) &&
9644 (isArray(value) || isString(value) || isFunction(value.splice) || isArguments(value))) {
9645 return !value.length;
9647 for (var key in value) {
9648 if (hasOwnProperty.call(value, key)) {
9656 * Performs a deep comparison between two values to determine if they are
9659 * **Note:** This method supports comparing arrays, array buffers, booleans,
9660 * date objects, error objects, maps, numbers, `Object` objects, regexes,
9661 * sets, strings, symbols, and typed arrays. `Object` objects are compared
9662 * by their own, not inherited, enumerable properties. Functions and DOM
9663 * nodes are **not** supported.
9668 * @param {*} value The value to compare.
9669 * @param {*} other The other value to compare.
9670 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9673 * var object = { 'user': 'fred' };
9674 * var other = { 'user': 'fred' };
9676 * _.isEqual(object, other);
9682 function isEqual(value, other) {
9683 return baseIsEqual(value, other);
9687 * This method is like `_.isEqual` except that it accepts `customizer` which is
9688 * invoked to compare values. If `customizer` returns `undefined` comparisons are
9689 * handled by the method instead. The `customizer` is invoked with up to six arguments:
9690 * (objValue, othValue [, index|key, object, other, stack]).
9695 * @param {*} value The value to compare.
9696 * @param {*} other The other value to compare.
9697 * @param {Function} [customizer] The function to customize comparisons.
9698 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
9701 * function isGreeting(value) {
9702 * return /^h(?:i|ello)$/.test(value);
9705 * function customizer(objValue, othValue) {
9706 * if (isGreeting(objValue) && isGreeting(othValue)) {
9711 * var array = ['hello', 'goodbye'];
9712 * var other = ['hi', 'goodbye'];
9714 * _.isEqualWith(array, other, customizer);
9717 function isEqualWith(value, other, customizer) {
9718 customizer = typeof customizer == 'function' ? customizer : undefined;
9719 var result = customizer ? customizer(value, other) : undefined;
9720 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
9724 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
9725 * `SyntaxError`, `TypeError`, or `URIError` object.
9730 * @param {*} value The value to check.
9731 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
9734 * _.isError(new Error);
9740 function isError(value) {
9741 return isObjectLike(value) &&
9742 typeof value.message == 'string' && objectToString.call(value) == errorTag;
9746 * Checks if `value` is a finite primitive number.
9748 * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
9753 * @param {*} value The value to check.
9754 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
9760 * _.isFinite(Number.MAX_VALUE);
9766 * _.isFinite(Infinity);
9769 function isFinite(value) {
9770 return typeof value == 'number' && nativeIsFinite(value);
9774 * Checks if `value` is classified as a `Function` object.
9779 * @param {*} value The value to check.
9780 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9786 * _.isFunction(/abc/);
9789 function isFunction(value) {
9790 // The use of `Object#toString` avoids issues with the `typeof` operator
9791 // in Safari 8 which returns 'object' for typed array constructors, and
9792 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
9793 var tag = isObject(value) ? objectToString.call(value) : '';
9794 return tag == funcTag || tag == genTag;
9798 * Checks if `value` is an integer.
9800 * **Note:** This method is based on [`Number.isInteger`](https://mdn.io/Number/isInteger).
9805 * @param {*} value The value to check.
9806 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
9812 * _.isInteger(Number.MIN_VALUE);
9815 * _.isInteger(Infinity);
9821 function isInteger(value) {
9822 return typeof value == 'number' && value == toInteger(value);
9826 * Checks if `value` is a valid array-like length.
9828 * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
9833 * @param {*} value The value to check.
9834 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
9840 * _.isLength(Number.MIN_VALUE);
9843 * _.isLength(Infinity);
9849 function isLength(value) {
9850 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
9854 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
9855 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
9860 * @param {*} value The value to check.
9861 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
9867 * _.isObject([1, 2, 3]);
9870 * _.isObject(_.noop);
9876 function isObject(value) {
9877 var type = typeof value;
9878 return !!value && (type == 'object' || type == 'function');
9882 * Checks if `value` is object-like. A value is object-like if it's not `null`
9883 * and has a `typeof` result of "object".
9888 * @param {*} value The value to check.
9889 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
9892 * _.isObjectLike({});
9895 * _.isObjectLike([1, 2, 3]);
9898 * _.isObjectLike(_.noop);
9901 * _.isObjectLike(null);
9904 function isObjectLike(value) {
9905 return !!value && typeof value == 'object';
9909 * Checks if `value` is classified as a `Map` object.
9914 * @param {*} value The value to check.
9915 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9921 * _.isMap(new WeakMap);
9924 function isMap(value) {
9925 return isObjectLike(value) && getTag(value) == mapTag;
9929 * Performs a deep comparison between `object` and `source` to determine if
9930 * `object` contains equivalent property values.
9932 * **Note:** This method supports comparing the same values as `_.isEqual`.
9937 * @param {Object} object The object to inspect.
9938 * @param {Object} source The object of property values to match.
9939 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
9942 * var object = { 'user': 'fred', 'age': 40 };
9944 * _.isMatch(object, { 'age': 40 });
9947 * _.isMatch(object, { 'age': 36 });
9950 function isMatch(object, source) {
9951 return object === source || baseIsMatch(object, source, getMatchData(source));
9955 * This method is like `_.isMatch` except that it accepts `customizer` which
9956 * is invoked to compare values. If `customizer` returns `undefined` comparisons
9957 * are handled by the method instead. The `customizer` is invoked with five
9958 * arguments: (objValue, srcValue, index|key, object, source).
9963 * @param {Object} object The object to inspect.
9964 * @param {Object} source The object of property values to match.
9965 * @param {Function} [customizer] The function to customize comparisons.
9966 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
9969 * function isGreeting(value) {
9970 * return /^h(?:i|ello)$/.test(value);
9973 * function customizer(objValue, srcValue) {
9974 * if (isGreeting(objValue) && isGreeting(srcValue)) {
9979 * var object = { 'greeting': 'hello' };
9980 * var source = { 'greeting': 'hi' };
9982 * _.isMatchWith(object, source, customizer);
9985 function isMatchWith(object, source, customizer) {
9986 customizer = typeof customizer == 'function' ? customizer : undefined;
9987 return baseIsMatch(object, source, getMatchData(source), customizer);
9991 * Checks if `value` is `NaN`.
9993 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
9994 * which returns `true` for `undefined` and other non-numeric values.
9999 * @param {*} value The value to check.
10000 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
10006 * _.isNaN(new Number(NaN));
10009 * isNaN(undefined);
10012 * _.isNaN(undefined);
10015 function isNaN(value) {
10016 // An `NaN` primitive is the only value that is not equal to itself.
10017 // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
10018 return isNumber(value) && value != +value;
10022 * Checks if `value` is a native function.
10027 * @param {*} value The value to check.
10028 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
10031 * _.isNative(Array.prototype.push);
10037 function isNative(value) {
10038 if (value == null) {
10041 if (isFunction(value)) {
10042 return reIsNative.test(funcToString.call(value));
10044 return isObjectLike(value) &&
10045 (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
10049 * Checks if `value` is `null`.
10054 * @param {*} value The value to check.
10055 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
10061 * _.isNull(void 0);
10064 function isNull(value) {
10065 return value === null;
10069 * Checks if `value` is `null` or `undefined`.
10074 * @param {*} value The value to check.
10075 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
10087 function isNil(value) {
10088 return value == null;
10092 * Checks if `value` is classified as a `Number` primitive or object.
10094 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
10095 * as numbers, use the `_.isFinite` method.
10100 * @param {*} value The value to check.
10101 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10107 * _.isNumber(Number.MIN_VALUE);
10110 * _.isNumber(Infinity);
10116 function isNumber(value) {
10117 return typeof value == 'number' ||
10118 (isObjectLike(value) && objectToString.call(value) == numberTag);
10122 * Checks if `value` is a plain object, that is, an object created by the
10123 * `Object` constructor or one with a `[[Prototype]]` of `null`.
10128 * @param {*} value The value to check.
10129 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
10136 * _.isPlainObject(new Foo);
10139 * _.isPlainObject([1, 2, 3]);
10142 * _.isPlainObject({ 'x': 0, 'y': 0 });
10145 * _.isPlainObject(Object.create(null));
10148 function isPlainObject(value) {
10149 if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) {
10152 var proto = objectProto;
10153 if (typeof value.constructor == 'function') {
10154 proto = getPrototypeOf(value);
10156 if (proto === null) {
10159 var Ctor = proto.constructor;
10160 return (typeof Ctor == 'function' &&
10161 Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
10165 * Checks if `value` is classified as a `RegExp` object.
10170 * @param {*} value The value to check.
10171 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10174 * _.isRegExp(/abc/);
10177 * _.isRegExp('/abc/');
10180 function isRegExp(value) {
10181 return isObject(value) && objectToString.call(value) == regexpTag;
10185 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
10186 * double precision number which isn't the result of a rounded unsafe integer.
10188 * **Note:** This method is based on [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
10193 * @param {*} value The value to check.
10194 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
10197 * _.isSafeInteger(3);
10200 * _.isSafeInteger(Number.MIN_VALUE);
10203 * _.isSafeInteger(Infinity);
10206 * _.isSafeInteger('3');
10209 function isSafeInteger(value) {
10210 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
10214 * Checks if `value` is classified as a `Set` object.
10219 * @param {*} value The value to check.
10220 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10223 * _.isSet(new Set);
10226 * _.isSet(new WeakSet);
10229 function isSet(value) {
10230 return isObjectLike(value) && getTag(value) == setTag;
10234 * Checks if `value` is classified as a `String` primitive or object.
10239 * @param {*} value The value to check.
10240 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10243 * _.isString('abc');
10249 function isString(value) {
10250 return typeof value == 'string' ||
10251 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
10255 * Checks if `value` is classified as a `Symbol` primitive or object.
10260 * @param {*} value The value to check.
10261 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10264 * _.isSymbol(Symbol.iterator);
10267 * _.isSymbol('abc');
10270 function isSymbol(value) {
10271 return typeof value == 'symbol' ||
10272 (isObjectLike(value) && objectToString.call(value) == symbolTag);
10276 * Checks if `value` is classified as a typed array.
10281 * @param {*} value The value to check.
10282 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10285 * _.isTypedArray(new Uint8Array);
10288 * _.isTypedArray([]);
10291 function isTypedArray(value) {
10292 return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
10296 * Checks if `value` is `undefined`.
10301 * @param {*} value The value to check.
10302 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
10305 * _.isUndefined(void 0);
10308 * _.isUndefined(null);
10311 function isUndefined(value) {
10312 return value === undefined;
10316 * Checks if `value` is classified as a `WeakMap` object.
10321 * @param {*} value The value to check.
10322 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10325 * _.isWeakMap(new WeakMap);
10328 * _.isWeakMap(new Map);
10331 function isWeakMap(value) {
10332 return isObjectLike(value) && getTag(value) == weakMapTag;
10336 * Checks if `value` is classified as a `WeakSet` object.
10341 * @param {*} value The value to check.
10342 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10345 * _.isWeakSet(new WeakSet);
10348 * _.isWeakSet(new Set);
10351 function isWeakSet(value) {
10352 return isObjectLike(value) && objectToString.call(value) == weakSetTag;
10356 * Checks if `value` is less than `other`.
10361 * @param {*} value The value to compare.
10362 * @param {*} other The other value to compare.
10363 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
10375 function lt(value, other) {
10376 return value < other;
10380 * Checks if `value` is less than or equal to `other`.
10385 * @param {*} value The value to compare.
10386 * @param {*} other The other value to compare.
10387 * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
10399 function lte(value, other) {
10400 return value <= other;
10404 * Converts `value` to an array.
10409 * @param {*} value The value to convert.
10410 * @returns {Array} Returns the converted array.
10413 * _.toArray({ 'a': 1, 'b': 2 });
10416 * _.toArray('abc');
10417 * // => ['a', 'b', 'c']
10425 function toArray(value) {
10429 if (isArrayLike(value)) {
10430 return isString(value) ? stringToArray(value) : copyArray(value);
10432 if (iteratorSymbol && value[iteratorSymbol]) {
10433 return iteratorToArray(value[iteratorSymbol]());
10435 var tag = getTag(value),
10436 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
10438 return func(value);
10442 * Converts `value` to an integer.
10444 * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
10449 * @param {*} value The value to convert.
10450 * @returns {number} Returns the converted integer.
10456 * _.toInteger(Number.MIN_VALUE);
10459 * _.toInteger(Infinity);
10460 * // => 1.7976931348623157e+308
10462 * _.toInteger('3');
10465 function toInteger(value) {
10467 return value === 0 ? value : 0;
10469 value = toNumber(value);
10470 if (value === INFINITY || value === -INFINITY) {
10471 var sign = (value < 0 ? -1 : 1);
10472 return sign * MAX_INTEGER;
10474 var remainder = value % 1;
10475 return value === value ? (remainder ? value - remainder : value) : 0;
10479 * Converts `value` to an integer suitable for use as the length of an
10480 * array-like object.
10482 * **Note:** This method is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
10487 * @param {*} value The value to convert.
10488 * @returns {number} Returns the converted integer.
10494 * _.toLength(Number.MIN_VALUE);
10497 * _.toLength(Infinity);
10503 function toLength(value) {
10504 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
10508 * Converts `value` to a number.
10513 * @param {*} value The value to process.
10514 * @returns {number} Returns the number.
10520 * _.toNumber(Number.MIN_VALUE);
10523 * _.toNumber(Infinity);
10529 function toNumber(value) {
10530 if (isObject(value)) {
10531 var other = isFunction(value.valueOf) ? value.valueOf() : value;
10532 value = isObject(other) ? (other + '') : other;
10534 if (typeof value != 'string') {
10535 return value === 0 ? value : +value;
10537 value = value.replace(reTrim, '');
10538 var isBinary = reIsBinary.test(value);
10539 return (isBinary || reIsOctal.test(value))
10540 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
10541 : (reIsBadHex.test(value) ? NAN : +value);
10545 * Converts `value` to a plain object flattening inherited enumerable
10546 * properties of `value` to own properties of the plain object.
10551 * @param {*} value The value to convert.
10552 * @returns {Object} Returns the converted plain object.
10559 * Foo.prototype.c = 3;
10561 * _.assign({ 'a': 1 }, new Foo);
10562 * // => { 'a': 1, 'b': 2 }
10564 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
10565 * // => { 'a': 1, 'b': 2, 'c': 3 }
10567 function toPlainObject(value) {
10568 return copyObject(value, keysIn(value));
10572 * Converts `value` to a safe integer. A safe integer can be compared and
10573 * represented correctly.
10578 * @param {*} value The value to convert.
10579 * @returns {number} Returns the converted integer.
10582 * _.toSafeInteger(3);
10585 * _.toSafeInteger(Number.MIN_VALUE);
10588 * _.toSafeInteger(Infinity);
10589 * // => 9007199254740991
10591 * _.toSafeInteger('3');
10594 function toSafeInteger(value) {
10595 return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
10599 * Converts `value` to a string if it's not one. An empty string is returned
10600 * for `null` and `undefined` values. The sign of `-0` is preserved.
10605 * @param {*} value The value to process.
10606 * @returns {string} Returns the string.
10609 * _.toString(null);
10615 * _.toString([1, 2, 3]);
10618 function toString(value) {
10619 // Exit early for strings to avoid a performance hit in some environments.
10620 if (typeof value == 'string') {
10623 if (value == null) {
10626 if (isSymbol(value)) {
10627 return Symbol ? symbolToString.call(value) : '';
10629 var result = (value + '');
10630 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
10633 /*------------------------------------------------------------------------*/
10636 * Assigns own enumerable properties of source objects to the destination
10637 * object. Source objects are applied from left to right. Subsequent sources
10638 * overwrite property assignments of previous sources.
10640 * **Note:** This method mutates `object` and is loosely based on
10641 * [`Object.assign`](https://mdn.io/Object/assign).
10646 * @param {Object} object The destination object.
10647 * @param {...Object} [sources] The source objects.
10648 * @returns {Object} Returns `object`.
10659 * Foo.prototype.d = 4;
10660 * Bar.prototype.f = 6;
10662 * _.assign({ 'a': 1 }, new Foo, new Bar);
10663 * // => { 'a': 1, 'c': 3, 'e': 5 }
10665 var assign = createAssigner(function(object, source) {
10666 copyObject(source, keys(source), object);
10670 * This method is like `_.assign` except that it iterates over own and
10671 * inherited source properties.
10673 * **Note:** This method mutates `object`.
10679 * @param {Object} object The destination object.
10680 * @param {...Object} [sources] The source objects.
10681 * @returns {Object} Returns `object`.
10692 * Foo.prototype.c = 3;
10693 * Bar.prototype.e = 5;
10695 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
10696 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
10698 var assignIn = createAssigner(function(object, source) {
10699 copyObject(source, keysIn(source), object);
10703 * This method is like `_.assignIn` except that it accepts `customizer` which
10704 * is invoked to produce the assigned values. If `customizer` returns `undefined`
10705 * assignment is handled by the method instead. The `customizer` is invoked
10706 * with five arguments: (objValue, srcValue, key, object, source).
10708 * **Note:** This method mutates `object`.
10712 * @alias extendWith
10714 * @param {Object} object The destination object.
10715 * @param {...Object} sources The source objects.
10716 * @param {Function} [customizer] The function to customize assigned values.
10717 * @returns {Object} Returns `object`.
10720 * function customizer(objValue, srcValue) {
10721 * return _.isUndefined(objValue) ? srcValue : objValue;
10724 * var defaults = _.partialRight(_.assignInWith, customizer);
10726 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
10727 * // => { 'a': 1, 'b': 2 }
10729 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
10730 copyObjectWith(source, keysIn(source), object, customizer);
10734 * This method is like `_.assign` except that it accepts `customizer` which
10735 * is invoked to produce the assigned values. If `customizer` returns `undefined`
10736 * assignment is handled by the method instead. The `customizer` is invoked
10737 * with five arguments: (objValue, srcValue, key, object, source).
10739 * **Note:** This method mutates `object`.
10744 * @param {Object} object The destination object.
10745 * @param {...Object} sources The source objects.
10746 * @param {Function} [customizer] The function to customize assigned values.
10747 * @returns {Object} Returns `object`.
10750 * function customizer(objValue, srcValue) {
10751 * return _.isUndefined(objValue) ? srcValue : objValue;
10754 * var defaults = _.partialRight(_.assignWith, customizer);
10756 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
10757 * // => { 'a': 1, 'b': 2 }
10759 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
10760 copyObjectWith(source, keys(source), object, customizer);
10764 * Creates an array of values corresponding to `paths` of `object`.
10769 * @param {Object} object The object to iterate over.
10770 * @param {...(string|string[])} [paths] The property paths of elements to pick,
10771 * specified individually or in arrays.
10772 * @returns {Array} Returns the new array of picked elements.
10775 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
10777 * _.at(object, ['a[0].b.c', 'a[1]']);
10780 * _.at(['a', 'b', 'c'], 0, 2);
10783 var at = rest(function(object, paths) {
10784 return baseAt(object, baseFlatten(paths));
10788 * Creates an object that inherits from the `prototype` object. If a `properties`
10789 * object is given its own enumerable properties are assigned to the created object.
10794 * @param {Object} prototype The object to inherit from.
10795 * @param {Object} [properties] The properties to assign to the object.
10796 * @returns {Object} Returns the new object.
10799 * function Shape() {
10804 * function Circle() {
10805 * Shape.call(this);
10808 * Circle.prototype = _.create(Shape.prototype, {
10809 * 'constructor': Circle
10812 * var circle = new Circle;
10813 * circle instanceof Circle;
10816 * circle instanceof Shape;
10819 function create(prototype, properties) {
10820 var result = baseCreate(prototype);
10821 return properties ? baseAssign(result, properties) : result;
10825 * Assigns own and inherited enumerable properties of source objects to the
10826 * destination object for all destination properties that resolve to `undefined`.
10827 * Source objects are applied from left to right. Once a property is set,
10828 * additional values of the same property are ignored.
10830 * **Note:** This method mutates `object`.
10835 * @param {Object} object The destination object.
10836 * @param {...Object} [sources] The source objects.
10837 * @returns {Object} Returns `object`.
10840 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
10841 * // => { 'user': 'barney', 'age': 36 }
10843 var defaults = rest(function(args) {
10844 args.push(undefined, assignInDefaults);
10845 return apply(assignInWith, undefined, args);
10849 * This method is like `_.defaults` except that it recursively assigns
10850 * default properties.
10852 * **Note:** This method mutates `object`.
10857 * @param {Object} object The destination object.
10858 * @param {...Object} [sources] The source objects.
10859 * @returns {Object} Returns `object`.
10862 * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
10863 * // => { 'user': { 'name': 'barney', 'age': 36 } }
10866 var defaultsDeep = rest(function(args) {
10867 args.push(undefined, mergeDefaults);
10868 return apply(mergeWith, undefined, args);
10872 * This method is like `_.find` except that it returns the key of the first
10873 * element `predicate` returns truthy for instead of the element itself.
10878 * @param {Object} object The object to search.
10879 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
10880 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
10884 * 'barney': { 'age': 36, 'active': true },
10885 * 'fred': { 'age': 40, 'active': false },
10886 * 'pebbles': { 'age': 1, 'active': true }
10889 * _.findKey(users, function(o) { return o.age < 40; });
10890 * // => 'barney' (iteration order is not guaranteed)
10892 * // The `_.matches` iteratee shorthand.
10893 * _.findKey(users, { 'age': 1, 'active': true });
10896 * // The `_.matchesProperty` iteratee shorthand.
10897 * _.findKey(users, ['active', false]);
10900 * // The `_.property` iteratee shorthand.
10901 * _.findKey(users, 'active');
10904 function findKey(object, predicate) {
10905 return baseFind(object, getIteratee(predicate, 3), baseForOwn, true);
10909 * This method is like `_.findKey` except that it iterates over elements of
10910 * a collection in the opposite order.
10915 * @param {Object} object The object to search.
10916 * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
10917 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
10921 * 'barney': { 'age': 36, 'active': true },
10922 * 'fred': { 'age': 40, 'active': false },
10923 * 'pebbles': { 'age': 1, 'active': true }
10926 * _.findLastKey(users, function(o) { return o.age < 40; });
10927 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
10929 * // The `_.matches` iteratee shorthand.
10930 * _.findLastKey(users, { 'age': 36, 'active': true });
10933 * // The `_.matchesProperty` iteratee shorthand.
10934 * _.findLastKey(users, ['active', false]);
10937 * // The `_.property` iteratee shorthand.
10938 * _.findLastKey(users, 'active');
10941 function findLastKey(object, predicate) {
10942 return baseFind(object, getIteratee(predicate, 3), baseForOwnRight, true);
10946 * Iterates over own and inherited enumerable properties of an object invoking
10947 * `iteratee` for each property. The iteratee is invoked with three arguments:
10948 * (value, key, object). Iteratee functions may exit iteration early by explicitly
10949 * returning `false`.
10954 * @param {Object} object The object to iterate over.
10955 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10956 * @returns {Object} Returns `object`.
10964 * Foo.prototype.c = 3;
10966 * _.forIn(new Foo, function(value, key) {
10967 * console.log(key);
10969 * // => logs 'a', 'b', then 'c' (iteration order is not guaranteed)
10971 function forIn(object, iteratee) {
10972 return object == null ? object : baseFor(object, toFunction(iteratee), keysIn);
10976 * This method is like `_.forIn` except that it iterates over properties of
10977 * `object` in the opposite order.
10982 * @param {Object} object The object to iterate over.
10983 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10984 * @returns {Object} Returns `object`.
10992 * Foo.prototype.c = 3;
10994 * _.forInRight(new Foo, function(value, key) {
10995 * console.log(key);
10997 * // => logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'
10999 function forInRight(object, iteratee) {
11000 return object == null ? object : baseForRight(object, toFunction(iteratee), keysIn);
11004 * Iterates over own enumerable properties of an object invoking `iteratee`
11005 * for each property. The iteratee is invoked with three arguments:
11006 * (value, key, object). Iteratee functions may exit iteration early by
11007 * explicitly returning `false`.
11012 * @param {Object} object The object to iterate over.
11013 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11014 * @returns {Object} Returns `object`.
11022 * Foo.prototype.c = 3;
11024 * _.forOwn(new Foo, function(value, key) {
11025 * console.log(key);
11027 * // => logs 'a' then 'b' (iteration order is not guaranteed)
11029 function forOwn(object, iteratee) {
11030 return object && baseForOwn(object, toFunction(iteratee));
11034 * This method is like `_.forOwn` except that it iterates over properties of
11035 * `object` in the opposite order.
11040 * @param {Object} object The object to iterate over.
11041 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11042 * @returns {Object} Returns `object`.
11050 * Foo.prototype.c = 3;
11052 * _.forOwnRight(new Foo, function(value, key) {
11053 * console.log(key);
11055 * // => logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'
11057 function forOwnRight(object, iteratee) {
11058 return object && baseForOwnRight(object, toFunction(iteratee));
11062 * Creates an array of function property names from own enumerable properties
11068 * @param {Object} object The object to inspect.
11069 * @returns {Array} Returns the new array of property names.
11073 * this.a = _.constant('a');
11074 * this.b = _.constant('b');
11077 * Foo.prototype.c = _.constant('c');
11079 * _.functions(new Foo);
11082 function functions(object) {
11083 return object == null ? [] : baseFunctions(object, keys(object));
11087 * Creates an array of function property names from own and inherited
11088 * enumerable properties of `object`.
11093 * @param {Object} object The object to inspect.
11094 * @returns {Array} Returns the new array of property names.
11098 * this.a = _.constant('a');
11099 * this.b = _.constant('b');
11102 * Foo.prototype.c = _.constant('c');
11104 * _.functionsIn(new Foo);
11105 * // => ['a', 'b', 'c']
11107 function functionsIn(object) {
11108 return object == null ? [] : baseFunctions(object, keysIn(object));
11112 * Gets the value at `path` of `object`. If the resolved value is
11113 * `undefined` the `defaultValue` is used in its place.
11118 * @param {Object} object The object to query.
11119 * @param {Array|string} path The path of the property to get.
11120 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
11121 * @returns {*} Returns the resolved value.
11124 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
11126 * _.get(object, 'a[0].b.c');
11129 * _.get(object, ['a', '0', 'b', 'c']);
11132 * _.get(object, 'a.b.c', 'default');
11135 function get(object, path, defaultValue) {
11136 var result = object == null ? undefined : baseGet(object, path);
11137 return result === undefined ? defaultValue : result;
11141 * Checks if `path` is a direct property of `object`.
11146 * @param {Object} object The object to query.
11147 * @param {Array|string} path The path to check.
11148 * @returns {boolean} Returns `true` if `path` exists, else `false`.
11151 * var object = { 'a': { 'b': { 'c': 3 } } };
11152 * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
11154 * _.has(object, 'a');
11157 * _.has(object, 'a.b.c');
11160 * _.has(object, ['a', 'b', 'c']);
11163 * _.has(other, 'a');
11166 function has(object, path) {
11167 return hasPath(object, path, baseHas);
11171 * Checks if `path` is a direct or inherited property of `object`.
11176 * @param {Object} object The object to query.
11177 * @param {Array|string} path The path to check.
11178 * @returns {boolean} Returns `true` if `path` exists, else `false`.
11181 * var object = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
11183 * _.hasIn(object, 'a');
11186 * _.hasIn(object, 'a.b.c');
11189 * _.hasIn(object, ['a', 'b', 'c']);
11192 * _.hasIn(object, 'b');
11195 function hasIn(object, path) {
11196 return hasPath(object, path, baseHasIn);
11200 * Creates an object composed of the inverted keys and values of `object`.
11201 * If `object` contains duplicate values, subsequent values overwrite property
11202 * assignments of previous values.
11207 * @param {Object} object The object to invert.
11208 * @returns {Object} Returns the new inverted object.
11211 * var object = { 'a': 1, 'b': 2, 'c': 1 };
11213 * _.invert(object);
11214 * // => { '1': 'c', '2': 'b' }
11216 var invert = createInverter(function(result, value, key) {
11217 result[value] = key;
11218 }, constant(identity));
11221 * This method is like `_.invert` except that the inverted object is generated
11222 * from the results of running each element of `object` through `iteratee`.
11223 * The corresponding inverted value of each inverted key is an array of keys
11224 * responsible for generating the inverted value. The iteratee is invoked
11225 * with one argument: (value).
11230 * @param {Object} object The object to invert.
11231 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
11232 * @returns {Object} Returns the new inverted object.
11235 * var object = { 'a': 1, 'b': 2, 'c': 1 };
11237 * _.invertBy(object);
11238 * // => { '1': ['a', 'c'], '2': ['b'] }
11240 * _.invertBy(object, function(value) {
11241 * return 'group' + value;
11243 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
11245 var invertBy = createInverter(function(result, value, key) {
11246 if (hasOwnProperty.call(result, value)) {
11247 result[value].push(key);
11249 result[value] = [key];
11254 * Invokes the method at `path` of `object`.
11259 * @param {Object} object The object to query.
11260 * @param {Array|string} path The path of the method to invoke.
11261 * @param {...*} [args] The arguments to invoke the method with.
11262 * @returns {*} Returns the result of the invoked method.
11265 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
11267 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
11270 var invoke = rest(baseInvoke);
11273 * Creates an array of the own enumerable property names of `object`.
11275 * **Note:** Non-object values are coerced to objects. See the
11276 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
11277 * for more details.
11282 * @param {Object} object The object to query.
11283 * @returns {Array} Returns the array of property names.
11291 * Foo.prototype.c = 3;
11294 * // => ['a', 'b'] (iteration order is not guaranteed)
11299 function keys(object) {
11300 var isProto = isPrototype(object);
11301 if (!(isProto || isArrayLike(object))) {
11302 return baseKeys(object);
11304 var indexes = indexKeys(object),
11305 skipIndexes = !!indexes,
11306 result = indexes || [],
11307 length = result.length;
11309 for (var key in object) {
11310 if (baseHas(object, key) &&
11311 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
11312 !(isProto && key == 'constructor')) {
11320 * Creates an array of the own and inherited enumerable property names of `object`.
11322 * **Note:** Non-object values are coerced to objects.
11327 * @param {Object} object The object to query.
11328 * @returns {Array} Returns the array of property names.
11336 * Foo.prototype.c = 3;
11338 * _.keysIn(new Foo);
11339 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
11341 function keysIn(object) {
11343 isProto = isPrototype(object),
11344 props = baseKeysIn(object),
11345 propsLength = props.length,
11346 indexes = indexKeys(object),
11347 skipIndexes = !!indexes,
11348 result = indexes || [],
11349 length = result.length;
11351 while (++index < propsLength) {
11352 var key = props[index];
11353 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
11354 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
11362 * The opposite of `_.mapValues`; this method creates an object with the
11363 * same values as `object` and keys generated by running each own enumerable
11364 * property of `object` through `iteratee`.
11369 * @param {Object} object The object to iterate over.
11370 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
11371 * @returns {Object} Returns the new mapped object.
11374 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
11375 * return key + value;
11377 * // => { 'a1': 1, 'b2': 2 }
11379 function mapKeys(object, iteratee) {
11381 iteratee = getIteratee(iteratee, 3);
11383 baseForOwn(object, function(value, key, object) {
11384 result[iteratee(value, key, object)] = value;
11390 * Creates an object with the same keys as `object` and values generated by
11391 * running each own enumerable property of `object` through `iteratee`. The
11392 * iteratee function is invoked with three arguments: (value, key, object).
11397 * @param {Object} object The object to iterate over.
11398 * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
11399 * @returns {Object} Returns the new mapped object.
11403 * 'fred': { 'user': 'fred', 'age': 40 },
11404 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
11407 * _.mapValues(users, function(o) { return o.age; });
11408 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
11410 * // The `_.property` iteratee shorthand.
11411 * _.mapValues(users, 'age');
11412 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
11414 function mapValues(object, iteratee) {
11416 iteratee = getIteratee(iteratee, 3);
11418 baseForOwn(object, function(value, key, object) {
11419 result[key] = iteratee(value, key, object);
11425 * Recursively merges own and inherited enumerable properties of source
11426 * objects into the destination object, skipping source properties that resolve
11427 * to `undefined`. Array and plain object properties are merged recursively.
11428 * Other objects and value types are overridden by assignment. Source objects
11429 * are applied from left to right. Subsequent sources overwrite property
11430 * assignments of previous sources.
11432 * **Note:** This method mutates `object`.
11437 * @param {Object} object The destination object.
11438 * @param {...Object} [sources] The source objects.
11439 * @returns {Object} Returns `object`.
11443 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
11447 * 'data': [{ 'age': 36 }, { 'age': 40 }]
11450 * _.merge(users, ages);
11451 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
11453 var merge = createAssigner(function(object, source, srcIndex) {
11454 baseMerge(object, source, srcIndex);
11458 * This method is like `_.merge` except that it accepts `customizer` which
11459 * is invoked to produce the merged values of the destination and source
11460 * properties. If `customizer` returns `undefined` merging is handled by the
11461 * method instead. The `customizer` is invoked with seven arguments:
11462 * (objValue, srcValue, key, object, source, stack).
11464 * **Note:** This method mutates `object`.
11469 * @param {Object} object The destination object.
11470 * @param {...Object} sources The source objects.
11471 * @param {Function} customizer The function to customize assigned values.
11472 * @returns {Object} Returns `object`.
11475 * function customizer(objValue, srcValue) {
11476 * if (_.isArray(objValue)) {
11477 * return objValue.concat(srcValue);
11482 * 'fruits': ['apple'],
11483 * 'vegetables': ['beet']
11487 * 'fruits': ['banana'],
11488 * 'vegetables': ['carrot']
11491 * _.mergeWith(object, other, customizer);
11492 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
11494 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
11495 baseMerge(object, source, srcIndex, customizer);
11499 * The opposite of `_.pick`; this method creates an object composed of the
11500 * own and inherited enumerable properties of `object` that are not omitted.
11505 * @param {Object} object The source object.
11506 * @param {...(string|string[])} [props] The property names to omit, specified
11507 * individually or in arrays..
11508 * @returns {Object} Returns the new object.
11511 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11513 * _.omit(object, ['a', 'c']);
11514 * // => { 'b': '2' }
11516 var omit = rest(function(object, props) {
11517 if (object == null) {
11520 props = arrayMap(baseFlatten(props), String);
11521 return basePick(object, baseDifference(keysIn(object), props));
11525 * The opposite of `_.pickBy`; this method creates an object composed of the
11526 * own and inherited enumerable properties of `object` that `predicate`
11527 * doesn't return truthy for.
11532 * @param {Object} object The source object.
11533 * @param {Function|Object|string} [predicate=_.identity] The function invoked per property.
11534 * @returns {Object} Returns the new object.
11537 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11539 * _.omitBy(object, _.isNumber);
11540 * // => { 'b': '2' }
11542 function omitBy(object, predicate) {
11543 predicate = getIteratee(predicate, 2);
11544 return basePickBy(object, function(value, key) {
11545 return !predicate(value, key);
11550 * Creates an object composed of the picked `object` properties.
11555 * @param {Object} object The source object.
11556 * @param {...(string|string[])} [props] The property names to pick, specified
11557 * individually or in arrays.
11558 * @returns {Object} Returns the new object.
11561 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11563 * _.pick(object, ['a', 'c']);
11564 * // => { 'a': 1, 'c': 3 }
11566 var pick = rest(function(object, props) {
11567 return object == null ? {} : basePick(object, baseFlatten(props));
11571 * Creates an object composed of the `object` properties `predicate` returns
11572 * truthy for. The predicate is invoked with two arguments: (value, key).
11577 * @param {Object} object The source object.
11578 * @param {Function|Object|string} [predicate=_.identity] The function invoked per property.
11579 * @returns {Object} Returns the new object.
11582 * var object = { 'a': 1, 'b': '2', 'c': 3 };
11584 * _.pickBy(object, _.isNumber);
11585 * // => { 'a': 1, 'c': 3 }
11587 function pickBy(object, predicate) {
11588 return object == null ? {} : basePickBy(object, getIteratee(predicate, 2));
11592 * This method is like `_.get` except that if the resolved value is a function
11593 * it's invoked with the `this` binding of its parent object and its result
11599 * @param {Object} object The object to query.
11600 * @param {Array|string} path The path of the property to resolve.
11601 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
11602 * @returns {*} Returns the resolved value.
11605 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
11607 * _.result(object, 'a[0].b.c1');
11610 * _.result(object, 'a[0].b.c2');
11613 * _.result(object, 'a[0].b.c3', 'default');
11616 * _.result(object, 'a[0].b.c3', _.constant('default'));
11619 function result(object, path, defaultValue) {
11620 if (!isKey(path, object)) {
11621 path = baseToPath(path);
11622 var result = get(object, path);
11623 object = parent(object, path);
11625 result = object == null ? undefined : object[path];
11627 if (result === undefined) {
11628 result = defaultValue;
11630 return isFunction(result) ? result.call(object) : result;
11634 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist
11635 * it's created. Arrays are created for missing index properties while objects
11636 * are created for all other missing properties. Use `_.setWith` to customize
11639 * **Note:** This method mutates `object`.
11644 * @param {Object} object The object to modify.
11645 * @param {Array|string} path The path of the property to set.
11646 * @param {*} value The value to set.
11647 * @returns {Object} Returns `object`.
11650 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
11652 * _.set(object, 'a[0].b.c', 4);
11653 * console.log(object.a[0].b.c);
11656 * _.set(object, 'x[0].y.z', 5);
11657 * console.log(object.x[0].y.z);
11660 function set(object, path, value) {
11661 return object == null ? object : baseSet(object, path, value);
11665 * This method is like `_.set` except that it accepts `customizer` which is
11666 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
11667 * path creation is handled by the method instead. The `customizer` is invoked
11668 * with three arguments: (nsValue, key, nsObject).
11670 * **Note:** This method mutates `object`.
11675 * @param {Object} object The object to modify.
11676 * @param {Array|string} path The path of the property to set.
11677 * @param {*} value The value to set.
11678 * @param {Function} [customizer] The function to customize assigned values.
11679 * @returns {Object} Returns `object`.
11682 * _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, Object);
11683 * // => { '0': { '1': { '2': 3 }, 'length': 2 } }
11685 function setWith(object, path, value, customizer) {
11686 customizer = typeof customizer == 'function' ? customizer : undefined;
11687 return object == null ? object : baseSet(object, path, value, customizer);
11691 * Creates an array of own enumerable key-value pairs for `object`.
11696 * @param {Object} object The object to query.
11697 * @returns {Array} Returns the new array of key-value pairs.
11705 * Foo.prototype.c = 3;
11707 * _.toPairs(new Foo);
11708 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
11710 function toPairs(object) {
11711 return baseToPairs(object, keys(object));
11715 * Creates an array of own and inherited enumerable key-value pairs for `object`.
11720 * @param {Object} object The object to query.
11721 * @returns {Array} Returns the new array of key-value pairs.
11729 * Foo.prototype.c = 3;
11731 * _.toPairsIn(new Foo);
11732 * // => [['a', 1], ['b', 2], ['c', 1]] (iteration order is not guaranteed)
11734 function toPairsIn(object) {
11735 return baseToPairs(object, keysIn(object));
11739 * An alternative to `_.reduce`; this method transforms `object` to a new
11740 * `accumulator` object which is the result of running each of its own enumerable
11741 * properties through `iteratee`, with each invocation potentially mutating
11742 * the `accumulator` object. The iteratee is invoked with four arguments:
11743 * (accumulator, value, key, object). Iteratee functions may exit iteration
11744 * early by explicitly returning `false`.
11749 * @param {Array|Object} object The object to iterate over.
11750 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11751 * @param {*} [accumulator] The custom accumulator value.
11752 * @returns {*} Returns the accumulated value.
11755 * _.transform([2, 3, 4], function(result, n) {
11756 * result.push(n *= n);
11757 * return n % 2 == 0;
11761 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
11762 * (result[value] || (result[value] = [])).push(key);
11764 * // => { '1': ['a', 'c'], '2': ['b'] }
11766 function transform(object, iteratee, accumulator) {
11767 var isArr = isArray(object) || isTypedArray(object);
11768 iteratee = getIteratee(iteratee, 4);
11770 if (accumulator == null) {
11771 if (isArr || isObject(object)) {
11772 var Ctor = object.constructor;
11774 accumulator = isArray(object) ? new Ctor : [];
11776 accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
11782 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
11783 return iteratee(accumulator, value, index, object);
11785 return accumulator;
11789 * Removes the property at `path` of `object`.
11791 * **Note:** This method mutates `object`.
11796 * @param {Object} object The object to modify.
11797 * @param {Array|string} path The path of the property to unset.
11798 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
11801 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
11802 * _.unset(object, 'a[0].b.c');
11805 * console.log(object);
11806 * // => { 'a': [{ 'b': {} }] };
11808 * _.unset(object, 'a[0].b.c');
11811 * console.log(object);
11812 * // => { 'a': [{ 'b': {} }] };
11814 function unset(object, path) {
11815 return object == null ? true : baseUnset(object, path);
11819 * Creates an array of the own enumerable property values of `object`.
11821 * **Note:** Non-object values are coerced to objects.
11826 * @param {Object} object The object to query.
11827 * @returns {Array} Returns the array of property values.
11835 * Foo.prototype.c = 3;
11837 * _.values(new Foo);
11838 * // => [1, 2] (iteration order is not guaranteed)
11843 function values(object) {
11844 return object ? baseValues(object, keys(object)) : [];
11848 * Creates an array of the own and inherited enumerable property values of `object`.
11850 * **Note:** Non-object values are coerced to objects.
11855 * @param {Object} object The object to query.
11856 * @returns {Array} Returns the array of property values.
11864 * Foo.prototype.c = 3;
11866 * _.valuesIn(new Foo);
11867 * // => [1, 2, 3] (iteration order is not guaranteed)
11869 function valuesIn(object) {
11870 return object == null ? baseValues(object, keysIn(object)) : [];
11873 /*------------------------------------------------------------------------*/
11876 * Clamps `number` within the inclusive `lower` and `upper` bounds.
11881 * @param {number} number The number to clamp.
11882 * @param {number} [lower] The lower bound.
11883 * @param {number} upper The upper bound.
11884 * @returns {number} Returns the clamped number.
11887 * _.clamp(-10, -5, 5);
11890 * _.clamp(10, -5, 5);
11893 function clamp(number, lower, upper) {
11894 if (upper === undefined) {
11898 if (upper !== undefined) {
11899 upper = toNumber(upper);
11900 upper = upper === upper ? upper : 0;
11902 if (lower !== undefined) {
11903 lower = toNumber(lower);
11904 lower = lower === lower ? lower : 0;
11906 return baseClamp(toNumber(number), lower, upper);
11910 * Checks if `n` is between `start` and up to but not including, `end`. If
11911 * `end` is not specified it's set to `start` with `start` then set to `0`.
11912 * If `start` is greater than `end` the params are swapped to support
11918 * @param {number} number The number to check.
11919 * @param {number} [start=0] The start of the range.
11920 * @param {number} end The end of the range.
11921 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
11924 * _.inRange(3, 2, 4);
11936 * _.inRange(1.2, 2);
11939 * _.inRange(5.2, 4);
11942 * _.inRange(-3, -2, -6);
11945 function inRange(number, start, end) {
11946 start = toNumber(start) || 0;
11947 if (end === undefined) {
11951 end = toNumber(end) || 0;
11953 number = toNumber(number);
11954 return baseInRange(number, start, end);
11958 * Produces a random number between the inclusive `lower` and `upper` bounds.
11959 * If only one argument is provided a number between `0` and the given number
11960 * is returned. If `floating` is `true`, or either `lower` or `upper` are floats,
11961 * a floating-point number is returned instead of an integer.
11963 * **Note:** JavaScript follows the IEEE-754 standard for resolving
11964 * floating-point values which can produce unexpected results.
11969 * @param {number} [lower=0] The lower bound.
11970 * @param {number} [upper=1] The upper bound.
11971 * @param {boolean} [floating] Specify returning a floating-point number.
11972 * @returns {number} Returns the random number.
11976 * // => an integer between 0 and 5
11979 * // => also an integer between 0 and 5
11981 * _.random(5, true);
11982 * // => a floating-point number between 0 and 5
11984 * _.random(1.2, 5.2);
11985 * // => a floating-point number between 1.2 and 5.2
11987 function random(lower, upper, floating) {
11988 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
11989 upper = floating = undefined;
11991 if (floating === undefined) {
11992 if (typeof upper == 'boolean') {
11996 else if (typeof lower == 'boolean') {
12001 if (lower === undefined && upper === undefined) {
12006 lower = toNumber(lower) || 0;
12007 if (upper === undefined) {
12011 upper = toNumber(upper) || 0;
12014 if (lower > upper) {
12019 if (floating || lower % 1 || upper % 1) {
12020 var rand = nativeRandom();
12021 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
12023 return baseRandom(lower, upper);
12026 /*------------------------------------------------------------------------*/
12029 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
12034 * @param {string} [string=''] The string to convert.
12035 * @returns {string} Returns the camel cased string.
12038 * _.camelCase('Foo Bar');
12041 * _.camelCase('--foo-bar');
12044 * _.camelCase('__foo_bar__');
12047 var camelCase = createCompounder(function(result, word, index) {
12048 word = word.toLowerCase();
12049 return result + (index ? capitalize(word) : word);
12053 * Converts the first character of `string` to upper case and the remaining
12059 * @param {string} [string=''] The string to capitalize.
12060 * @returns {string} Returns the capitalized string.
12063 * _.capitalize('FRED');
12066 function capitalize(string) {
12067 return upperFirst(toString(string).toLowerCase());
12071 * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
12072 * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
12077 * @param {string} [string=''] The string to deburr.
12078 * @returns {string} Returns the deburred string.
12081 * _.deburr('déjà vu');
12084 function deburr(string) {
12085 string = toString(string);
12086 return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
12090 * Checks if `string` ends with the given target string.
12095 * @param {string} [string=''] The string to search.
12096 * @param {string} [target] The string to search for.
12097 * @param {number} [position=string.length] The position to search from.
12098 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
12101 * _.endsWith('abc', 'c');
12104 * _.endsWith('abc', 'b');
12107 * _.endsWith('abc', 'b', 2);
12110 function endsWith(string, target, position) {
12111 string = toString(string);
12112 target = typeof target == 'string' ? target : (target + '');
12114 var length = string.length;
12115 position = position === undefined
12117 : baseClamp(toInteger(position), 0, length);
12119 position -= target.length;
12120 return position >= 0 && string.indexOf(target, position) == position;
12124 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
12125 * their corresponding HTML entities.
12127 * **Note:** No other characters are escaped. To escape additional
12128 * characters use a third-party library like [_he_](https://mths.be/he).
12130 * Though the ">" character is escaped for symmetry, characters like
12131 * ">" and "/" don't need escaping in HTML and have no special meaning
12132 * unless they're part of a tag or unquoted attribute value.
12133 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
12134 * (under "semi-related fun fact") for more details.
12136 * Backticks are escaped because in IE < 9, they can break out of
12137 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
12138 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
12139 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
12140 * for more details.
12142 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
12143 * to reduce XSS vectors.
12148 * @param {string} [string=''] The string to escape.
12149 * @returns {string} Returns the escaped string.
12152 * _.escape('fred, barney, & pebbles');
12153 * // => 'fred, barney, & pebbles'
12155 function escape(string) {
12156 string = toString(string);
12157 return (string && reHasUnescapedHtml.test(string))
12158 ? string.replace(reUnescapedHtml, escapeHtmlChar)
12163 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
12164 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
12169 * @param {string} [string=''] The string to escape.
12170 * @returns {string} Returns the escaped string.
12173 * _.escapeRegExp('[lodash](https://lodash.com/)');
12174 * // => '\[lodash\]\(https://lodash\.com/\)'
12176 function escapeRegExp(string) {
12177 string = toString(string);
12178 return (string && reHasRegExpChar.test(string))
12179 ? string.replace(reRegExpChar, '\\$&')
12184 * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
12189 * @param {string} [string=''] The string to convert.
12190 * @returns {string} Returns the kebab cased string.
12193 * _.kebabCase('Foo Bar');
12196 * _.kebabCase('fooBar');
12199 * _.kebabCase('__foo_bar__');
12202 var kebabCase = createCompounder(function(result, word, index) {
12203 return result + (index ? '-' : '') + word.toLowerCase();
12207 * Converts `string`, as space separated words, to lower case.
12212 * @param {string} [string=''] The string to convert.
12213 * @returns {string} Returns the lower cased string.
12216 * _.lowerCase('--Foo-Bar');
12219 * _.lowerCase('fooBar');
12222 * _.lowerCase('__FOO_BAR__');
12225 var lowerCase = createCompounder(function(result, word, index) {
12226 return result + (index ? ' ' : '') + word.toLowerCase();
12230 * Converts the first character of `string` to lower case.
12235 * @param {string} [string=''] The string to convert.
12236 * @returns {string} Returns the converted string.
12239 * _.lowerFirst('Fred');
12242 * _.lowerFirst('FRED');
12245 var lowerFirst = createCaseFirst('toLowerCase');
12248 * Converts the first character of `string` to upper case.
12253 * @param {string} [string=''] The string to convert.
12254 * @returns {string} Returns the converted string.
12257 * _.upperFirst('fred');
12260 * _.upperFirst('FRED');
12263 var upperFirst = createCaseFirst('toUpperCase');
12266 * Pads `string` on the left and right sides if it's shorter than `length`.
12267 * Padding characters are truncated if they can't be evenly divided by `length`.
12272 * @param {string} [string=''] The string to pad.
12273 * @param {number} [length=0] The padding length.
12274 * @param {string} [chars=' '] The string used as padding.
12275 * @returns {string} Returns the padded string.
12281 * _.pad('abc', 8, '_-');
12287 function pad(string, length, chars) {
12288 string = toString(string);
12289 length = toInteger(length);
12291 var strLength = stringSize(string);
12292 if (!length || strLength >= length) {
12295 var mid = (length - strLength) / 2,
12296 leftLength = nativeFloor(mid),
12297 rightLength = nativeCeil(mid);
12299 return createPadding('', leftLength, chars) + string + createPadding('', rightLength, chars);
12303 * Pads `string` on the right side if it's shorter than `length`. Padding
12304 * characters are truncated if they exceed `length`.
12309 * @param {string} [string=''] The string to pad.
12310 * @param {number} [length=0] The padding length.
12311 * @param {string} [chars=' '] The string used as padding.
12312 * @returns {string} Returns the padded string.
12315 * _.padEnd('abc', 6);
12318 * _.padEnd('abc', 6, '_-');
12321 * _.padEnd('abc', 3);
12324 function padEnd(string, length, chars) {
12325 string = toString(string);
12326 return string + createPadding(string, length, chars);
12330 * Pads `string` on the left side if it's shorter than `length`. Padding
12331 * characters are truncated if they exceed `length`.
12336 * @param {string} [string=''] The string to pad.
12337 * @param {number} [length=0] The padding length.
12338 * @param {string} [chars=' '] The string used as padding.
12339 * @returns {string} Returns the padded string.
12342 * _.padStart('abc', 6);
12345 * _.padStart('abc', 6, '_-');
12348 * _.padStart('abc', 3);
12351 function padStart(string, length, chars) {
12352 string = toString(string);
12353 return createPadding(string, length, chars) + string;
12357 * Converts `string` to an integer of the specified radix. If `radix` is
12358 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
12359 * in which case a `radix` of `16` is used.
12361 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#x15.1.2.2)
12367 * @param {string} string The string to convert.
12368 * @param {number} [radix] The radix to interpret `value` by.
12369 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12370 * @returns {number} Returns the converted integer.
12373 * _.parseInt('08');
12376 * _.map(['6', '08', '10'], _.parseInt);
12379 function parseInt(string, radix, guard) {
12380 // Chrome fails to trim leading <BOM> whitespace characters.
12381 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
12382 if (guard || radix == null) {
12384 } else if (radix) {
12387 string = toString(string).replace(reTrim, '');
12388 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
12392 * Repeats the given string `n` times.
12397 * @param {string} [string=''] The string to repeat.
12398 * @param {number} [n=0] The number of times to repeat the string.
12399 * @returns {string} Returns the repeated string.
12402 * _.repeat('*', 3);
12405 * _.repeat('abc', 2);
12408 * _.repeat('abc', 0);
12411 function repeat(string, n) {
12412 string = toString(string);
12416 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
12419 // Leverage the exponentiation by squaring algorithm for a faster repeat.
12420 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
12425 n = nativeFloor(n / 2);
12433 * Replaces matches for `pattern` in `string` with `replacement`.
12435 * **Note:** This method is based on [`String#replace`](https://mdn.io/String/replace).
12440 * @param {string} [string=''] The string to modify.
12441 * @param {RegExp|string} pattern The pattern to replace.
12442 * @param {Function|string} replacement The match replacement.
12443 * @returns {string} Returns the modified string.
12446 * _.replace('Hi Fred', 'Fred', 'Barney');
12447 * // => 'Hi Barney'
12449 function replace() {
12450 var args = arguments,
12451 string = toString(args[0]);
12453 return args.length < 3 ? string : string.replace(args[1], args[2]);
12457 * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
12462 * @param {string} [string=''] The string to convert.
12463 * @returns {string} Returns the snake cased string.
12466 * _.snakeCase('Foo Bar');
12469 * _.snakeCase('fooBar');
12472 * _.snakeCase('--foo-bar');
12475 var snakeCase = createCompounder(function(result, word, index) {
12476 return result + (index ? '_' : '') + word.toLowerCase();
12480 * Splits `string` by `separator`.
12482 * **Note:** This method is based on [`String#split`](https://mdn.io/String/split).
12487 * @param {string} [string=''] The string to split.
12488 * @param {RegExp|string} separator The separator pattern to split by.
12489 * @param {number} [limit] The length to truncate results to.
12490 * @returns {Array} Returns the new array of string segments.
12493 * _.split('a-b-c', '-', 2);
12496 function split(string, separator, limit) {
12497 return toString(string).split(separator, limit);
12501 * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
12506 * @param {string} [string=''] The string to convert.
12507 * @returns {string} Returns the start cased string.
12510 * _.startCase('--foo-bar');
12513 * _.startCase('fooBar');
12516 * _.startCase('__foo_bar__');
12519 var startCase = createCompounder(function(result, word, index) {
12520 return result + (index ? ' ' : '') + capitalize(word);
12524 * Checks if `string` starts with the given target string.
12529 * @param {string} [string=''] The string to search.
12530 * @param {string} [target] The string to search for.
12531 * @param {number} [position=0] The position to search from.
12532 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
12535 * _.startsWith('abc', 'a');
12538 * _.startsWith('abc', 'b');
12541 * _.startsWith('abc', 'b', 1);
12544 function startsWith(string, target, position) {
12545 string = toString(string);
12546 position = baseClamp(toInteger(position), 0, string.length);
12547 return string.lastIndexOf(target, position) == position;
12551 * Creates a compiled template function that can interpolate data properties
12552 * in "interpolate" delimiters, HTML-escape interpolated data properties in
12553 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
12554 * properties may be accessed as free variables in the template. If a setting
12555 * object is given it takes precedence over `_.templateSettings` values.
12557 * **Note:** In the development build `_.template` utilizes
12558 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
12559 * for easier debugging.
12561 * For more information on precompiling templates see
12562 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
12564 * For more information on Chrome extension sandboxes see
12565 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
12570 * @param {string} [string=''] The template string.
12571 * @param {Object} [options] The options object.
12572 * @param {RegExp} [options.escape] The HTML "escape" delimiter.
12573 * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
12574 * @param {Object} [options.imports] An object to import into the template as free variables.
12575 * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
12576 * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
12577 * @param {string} [options.variable] The data object variable name.
12578 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12579 * @returns {Function} Returns the compiled template function.
12582 * // Use the "interpolate" delimiter to create a compiled template.
12583 * var compiled = _.template('hello <%= user %>!');
12584 * compiled({ 'user': 'fred' });
12585 * // => 'hello fred!'
12587 * // Use the HTML "escape" delimiter to escape data property values.
12588 * var compiled = _.template('<b><%- value %></b>');
12589 * compiled({ 'value': '<script>' });
12590 * // => '<b><script></b>'
12592 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
12593 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
12594 * compiled({ 'users': ['fred', 'barney'] });
12595 * // => '<li>fred</li><li>barney</li>'
12597 * // Use the internal `print` function in "evaluate" delimiters.
12598 * var compiled = _.template('<% print("hello " + user); %>!');
12599 * compiled({ 'user': 'barney' });
12600 * // => 'hello barney!'
12602 * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
12603 * var compiled = _.template('hello ${ user }!');
12604 * compiled({ 'user': 'pebbles' });
12605 * // => 'hello pebbles!'
12607 * // Use custom template delimiters.
12608 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
12609 * var compiled = _.template('hello {{ user }}!');
12610 * compiled({ 'user': 'mustache' });
12611 * // => 'hello mustache!'
12613 * // Use backslashes to treat delimiters as plain text.
12614 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
12615 * compiled({ 'value': 'ignored' });
12616 * // => '<%- value %>'
12618 * // Use the `imports` option to import `jQuery` as `jq`.
12619 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
12620 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
12621 * compiled({ 'users': ['fred', 'barney'] });
12622 * // => '<li>fred</li><li>barney</li>'
12624 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
12625 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
12627 * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
12629 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
12630 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
12632 * // => function(data) {
12633 * // var __t, __p = '';
12634 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
12638 * // Use the `source` property to inline compiled templates for meaningful
12639 * // line numbers in error messages and stack traces.
12640 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
12642 * "main": ' + _.template(mainText).source + '\
12646 function template(string, options, guard) {
12647 // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
12648 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
12649 var settings = lodash.templateSettings;
12651 if (guard && isIterateeCall(string, options, guard)) {
12652 options = undefined;
12654 string = toString(string);
12655 options = assignInWith({}, options, settings, assignInDefaults);
12657 var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
12658 importsKeys = keys(imports),
12659 importsValues = baseValues(imports, importsKeys);
12664 interpolate = options.interpolate || reNoMatch,
12665 source = "__p += '";
12667 // Compile the regexp to match each delimiter.
12668 var reDelimiters = RegExp(
12669 (options.escape || reNoMatch).source + '|' +
12670 interpolate.source + '|' +
12671 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
12672 (options.evaluate || reNoMatch).source + '|$'
12675 // Use a sourceURL for easier debugging.
12676 var sourceURL = '//# sourceURL=' +
12677 ('sourceURL' in options
12678 ? options.sourceURL
12679 : ('lodash.templateSources[' + (++templateCounter) + ']')
12682 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
12683 interpolateValue || (interpolateValue = esTemplateValue);
12685 // Escape characters that can't be included in string literals.
12686 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
12688 // Replace delimiters with snippets.
12691 source += "' +\n__e(" + escapeValue + ") +\n'";
12693 if (evaluateValue) {
12694 isEvaluating = true;
12695 source += "';\n" + evaluateValue + ";\n__p += '";
12697 if (interpolateValue) {
12698 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
12700 index = offset + match.length;
12702 // The JS engine embedded in Adobe products needs `match` returned in
12703 // order to produce the correct `offset` value.
12709 // If `variable` is not specified wrap a with-statement around the generated
12710 // code to add the data object to the top of the scope chain.
12711 var variable = options.variable;
12713 source = 'with (obj) {\n' + source + '\n}\n';
12715 // Cleanup code by stripping empty strings.
12716 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
12717 .replace(reEmptyStringMiddle, '$1')
12718 .replace(reEmptyStringTrailing, '$1;');
12720 // Frame code as the function body.
12721 source = 'function(' + (variable || 'obj') + ') {\n' +
12724 : 'obj || (obj = {});\n'
12726 "var __t, __p = ''" +
12728 ? ', __e = _.escape'
12732 ? ', __j = Array.prototype.join;\n' +
12733 "function print() { __p += __j.call(arguments, '') }\n"
12739 var result = attempt(function() {
12740 return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
12743 // Provide the compiled function's source by its `toString` method or
12744 // the `source` property as a convenience for inlining compiled templates.
12745 result.source = source;
12746 if (isError(result)) {
12753 * Converts `string`, as a whole, to lower case.
12758 * @param {string} [string=''] The string to convert.
12759 * @returns {string} Returns the lower cased string.
12762 * _.toLower('--Foo-Bar');
12763 * // => '--foo-bar'
12765 * _.toLower('fooBar');
12768 * _.toLower('__FOO_BAR__');
12769 * // => '__foo_bar__'
12771 function toLower(value) {
12772 return toString(value).toLowerCase();
12776 * Converts `string`, as a whole, to upper case.
12781 * @param {string} [string=''] The string to convert.
12782 * @returns {string} Returns the upper cased string.
12785 * _.toUpper('--foo-bar');
12786 * // => '--FOO-BAR'
12788 * _.toUpper('fooBar');
12791 * _.toUpper('__foo_bar__');
12792 * // => '__FOO_BAR__'
12794 function toUpper(value) {
12795 return toString(value).toUpperCase();
12799 * Removes leading and trailing whitespace or specified characters from `string`.
12804 * @param {string} [string=''] The string to trim.
12805 * @param {string} [chars=whitespace] The characters to trim.
12806 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12807 * @returns {string} Returns the trimmed string.
12813 * _.trim('-_-abc-_-', '_-');
12816 * _.map([' foo ', ' bar '], _.trim);
12817 * // => ['foo', 'bar']
12819 function trim(string, chars, guard) {
12820 string = toString(string);
12824 if (guard || chars === undefined) {
12825 return string.replace(reTrim, '');
12827 chars = (chars + '');
12831 var strSymbols = stringToArray(string),
12832 chrSymbols = stringToArray(chars);
12834 return strSymbols.slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1).join('');
12838 * Removes trailing whitespace or specified characters from `string`.
12843 * @param {string} [string=''] The string to trim.
12844 * @param {string} [chars=whitespace] The characters to trim.
12845 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12846 * @returns {string} Returns the trimmed string.
12849 * _.trimEnd(' abc ');
12852 * _.trimEnd('-_-abc-_-', '_-');
12855 function trimEnd(string, chars, guard) {
12856 string = toString(string);
12860 if (guard || chars === undefined) {
12861 return string.replace(reTrimEnd, '');
12863 chars = (chars + '');
12867 var strSymbols = stringToArray(string);
12868 return strSymbols.slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1).join('');
12872 * Removes leading whitespace or specified characters from `string`.
12877 * @param {string} [string=''] The string to trim.
12878 * @param {string} [chars=whitespace] The characters to trim.
12879 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
12880 * @returns {string} Returns the trimmed string.
12883 * _.trimStart(' abc ');
12886 * _.trimStart('-_-abc-_-', '_-');
12889 function trimStart(string, chars, guard) {
12890 string = toString(string);
12894 if (guard || chars === undefined) {
12895 return string.replace(reTrimStart, '');
12897 chars = (chars + '');
12901 var strSymbols = stringToArray(string);
12902 return strSymbols.slice(charsStartIndex(strSymbols, stringToArray(chars))).join('');
12906 * Truncates `string` if it's longer than the given maximum string length.
12907 * The last characters of the truncated string are replaced with the omission
12908 * string which defaults to "...".
12913 * @param {string} [string=''] The string to truncate.
12914 * @param {Object} [options] The options object.
12915 * @param {number} [options.length=30] The maximum string length.
12916 * @param {string} [options.omission='...'] The string to indicate text is omitted.
12917 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
12918 * @returns {string} Returns the truncated string.
12921 * _.truncate('hi-diddly-ho there, neighborino');
12922 * // => 'hi-diddly-ho there, neighbo...'
12924 * _.truncate('hi-diddly-ho there, neighborino', {
12928 * // => 'hi-diddly-ho there,...'
12930 * _.truncate('hi-diddly-ho there, neighborino', {
12932 * 'separator': /,? +/
12934 * // => 'hi-diddly-ho there...'
12936 * _.truncate('hi-diddly-ho there, neighborino', {
12937 * 'omission': ' [...]'
12939 * // => 'hi-diddly-ho there, neig [...]'
12941 function truncate(string, options) {
12942 var length = DEFAULT_TRUNC_LENGTH,
12943 omission = DEFAULT_TRUNC_OMISSION;
12945 if (isObject(options)) {
12946 var separator = 'separator' in options ? options.separator : separator;
12947 length = 'length' in options ? toInteger(options.length) : length;
12948 omission = 'omission' in options ? toString(options.omission) : omission;
12950 string = toString(string);
12952 var strLength = string.length;
12953 if (reHasComplexSymbol.test(string)) {
12954 var strSymbols = stringToArray(string);
12955 strLength = strSymbols.length;
12957 if (length >= strLength) {
12960 var end = length - stringSize(omission);
12964 var result = strSymbols
12965 ? strSymbols.slice(0, end).join('')
12966 : string.slice(0, end);
12968 if (separator === undefined) {
12969 return result + omission;
12972 end += (result.length - end);
12974 if (isRegExp(separator)) {
12975 if (string.slice(end).search(separator)) {
12977 substring = result;
12979 if (!separator.global) {
12980 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
12982 separator.lastIndex = 0;
12983 while ((match = separator.exec(substring))) {
12984 var newEnd = match.index;
12986 result = result.slice(0, newEnd === undefined ? end : newEnd);
12988 } else if (string.indexOf(separator, end) != end) {
12989 var index = result.lastIndexOf(separator);
12991 result = result.slice(0, index);
12994 return result + omission;
12998 * The inverse of `_.escape`; this method converts the HTML entities
12999 * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
13000 * corresponding characters.
13002 * **Note:** No other HTML entities are unescaped. To unescape additional HTML
13003 * entities use a third-party library like [_he_](https://mths.be/he).
13008 * @param {string} [string=''] The string to unescape.
13009 * @returns {string} Returns the unescaped string.
13012 * _.unescape('fred, barney, & pebbles');
13013 * // => 'fred, barney, & pebbles'
13015 function unescape(string) {
13016 string = toString(string);
13017 return (string && reHasEscapedHtml.test(string))
13018 ? string.replace(reEscapedHtml, unescapeHtmlChar)
13023 * Converts `string`, as space separated words, to upper case.
13028 * @param {string} [string=''] The string to convert.
13029 * @returns {string} Returns the upper cased string.
13032 * _.upperCase('--foo-bar');
13035 * _.upperCase('fooBar');
13038 * _.upperCase('__foo_bar__');
13041 var upperCase = createCompounder(function(result, word, index) {
13042 return result + (index ? ' ' : '') + word.toUpperCase();
13046 * Splits `string` into an array of its words.
13051 * @param {string} [string=''] The string to inspect.
13052 * @param {RegExp|string} [pattern] The pattern to match words.
13053 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
13054 * @returns {Array} Returns the words of `string`.
13057 * _.words('fred, barney, & pebbles');
13058 * // => ['fred', 'barney', 'pebbles']
13060 * _.words('fred, barney, & pebbles', /[^, ]+/g);
13061 * // => ['fred', 'barney', '&', 'pebbles']
13063 function words(string, pattern, guard) {
13064 string = toString(string);
13065 pattern = guard ? undefined : pattern;
13067 if (pattern === undefined) {
13068 pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
13070 return string.match(pattern) || [];
13073 /*------------------------------------------------------------------------*/
13076 * Attempts to invoke `func`, returning either the result or the caught error
13077 * object. Any additional arguments are provided to `func` when it's invoked.
13082 * @param {Function} func The function to attempt.
13083 * @returns {*} Returns the `func` result or error object.
13086 * // Avoid throwing errors for invalid selectors.
13087 * var elements = _.attempt(function(selector) {
13088 * return document.querySelectorAll(selector);
13091 * if (_.isError(elements)) {
13095 var attempt = rest(function(func, args) {
13097 return apply(func, undefined, args);
13099 return isObject(e) ? e : new Error(e);
13104 * Binds methods of an object to the object itself, overwriting the existing
13107 * **Note:** This method doesn't set the "length" property of bound functions.
13112 * @param {Object} object The object to bind and assign the bound methods to.
13113 * @param {...(string|string[])} methodNames The object method names to bind,
13114 * specified individually or in arrays.
13115 * @returns {Object} Returns `object`.
13120 * 'onClick': function() {
13121 * console.log('clicked ' + this.label);
13125 * _.bindAll(view, 'onClick');
13126 * jQuery(element).on('click', view.onClick);
13127 * // => logs 'clicked docs' when clicked
13129 var bindAll = rest(function(object, methodNames) {
13130 arrayEach(baseFlatten(methodNames), function(key) {
13131 object[key] = bind(object[key], object);
13137 * Creates a function that iterates over `pairs` invoking the corresponding
13138 * function of the first predicate to return truthy. The predicate-function
13139 * pairs are invoked with the `this` binding and arguments of the created
13145 * @param {Array} pairs The predicate-function pairs.
13146 * @returns {Function} Returns the new function.
13149 * var func = _.cond([
13150 * [_.matches({ 'a': 1 }), _.constant('matches A')],
13151 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
13152 * [_.constant(true), _.constant('no match')]
13155 * func({ 'a': 1, 'b': 2 });
13156 * // => 'matches A'
13158 * func({ 'a': 0, 'b': 1 });
13159 * // => 'matches B'
13161 * func({ 'a': '1', 'b': '2' });
13164 function cond(pairs) {
13165 var length = pairs ? pairs.length : 0,
13166 toIteratee = getIteratee();
13168 pairs = !length ? [] : arrayMap(pairs, function(pair) {
13169 if (typeof pair[1] != 'function') {
13170 throw new TypeError(FUNC_ERROR_TEXT);
13172 return [toIteratee(pair[0]), pair[1]];
13175 return rest(function(args) {
13177 while (++index < length) {
13178 var pair = pairs[index];
13179 if (apply(pair[0], this, args)) {
13180 return apply(pair[1], this, args);
13187 * Creates a function that invokes the predicate properties of `source` with
13188 * the corresponding property values of a given object, returning `true` if
13189 * all predicates return truthy, else `false`.
13194 * @param {Object} source The object of property predicates to conform to.
13195 * @returns {Function} Returns the new function.
13199 * { 'user': 'barney', 'age': 36 },
13200 * { 'user': 'fred', 'age': 40 }
13203 * _.filter(users, _.conforms({ 'age': _.partial(_.gt, _, 38) }));
13204 * // => [{ 'user': 'fred', 'age': 40 }]
13206 function conforms(source) {
13207 return baseConforms(baseClone(source, true));
13211 * Creates a function that returns `value`.
13216 * @param {*} value The value to return from the new function.
13217 * @returns {Function} Returns the new function.
13220 * var object = { 'user': 'fred' };
13221 * var getter = _.constant(object);
13223 * getter() === object;
13226 function constant(value) {
13227 return function() {
13233 * Creates a function that returns the result of invoking the given functions
13234 * with the `this` binding of the created function, where each successive
13235 * invocation is supplied the return value of the previous.
13240 * @param {...(Function|Function[])} [funcs] Functions to invoke.
13241 * @returns {Function} Returns the new function.
13244 * function square(n) {
13248 * var addSquare = _.flow(_.add, square);
13252 var flow = createFlow();
13255 * This method is like `_.flow` except that it creates a function that
13256 * invokes the given functions from right to left.
13261 * @param {...(Function|Function[])} [funcs] Functions to invoke.
13262 * @returns {Function} Returns the new function.
13265 * function square(n) {
13269 * var addSquare = _.flowRight(square, _.add);
13273 var flowRight = createFlow(true);
13276 * This method returns the first argument given to it.
13281 * @param {*} value Any value.
13282 * @returns {*} Returns `value`.
13285 * var object = { 'user': 'fred' };
13287 * _.identity(object) === object;
13290 function identity(value) {
13295 * Creates a function that invokes `func` with the arguments of the created
13296 * function. If `func` is a property name the created callback returns the
13297 * property value for a given element. If `func` is an object the created
13298 * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`.
13303 * @param {*} [func=_.identity] The value to convert to a callback.
13304 * @returns {Function} Returns the callback.
13308 * { 'user': 'barney', 'age': 36 },
13309 * { 'user': 'fred', 'age': 40 }
13312 * // Create custom iteratee shorthands.
13313 * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
13314 * var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
13315 * return !p ? callback(func) : function(object) {
13316 * return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
13320 * _.filter(users, 'age > 36');
13321 * // => [{ 'user': 'fred', 'age': 40 }]
13323 function iteratee(func) {
13324 return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
13328 * Creates a function that performs a deep partial comparison between a given
13329 * object and `source`, returning `true` if the given object has equivalent
13330 * property values, else `false`.
13332 * **Note:** This method supports comparing the same values as `_.isEqual`.
13337 * @param {Object} source The object of property values to match.
13338 * @returns {Function} Returns the new function.
13342 * { 'user': 'barney', 'age': 36, 'active': true },
13343 * { 'user': 'fred', 'age': 40, 'active': false }
13346 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
13347 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
13349 function matches(source) {
13350 return baseMatches(baseClone(source, true));
13354 * Creates a function that performs a deep partial comparison between the
13355 * value at `path` of a given object to `srcValue`, returning `true` if the
13356 * object value is equivalent, else `false`.
13358 * **Note:** This method supports comparing the same values as `_.isEqual`.
13363 * @param {Array|string} path The path of the property to get.
13364 * @param {*} srcValue The value to match.
13365 * @returns {Function} Returns the new function.
13369 * { 'user': 'barney' },
13370 * { 'user': 'fred' }
13373 * _.find(users, _.matchesProperty('user', 'fred'));
13374 * // => { 'user': 'fred' }
13376 function matchesProperty(path, srcValue) {
13377 return baseMatchesProperty(path, baseClone(srcValue, true));
13381 * Creates a function that invokes the method at `path` of a given object.
13382 * Any additional arguments are provided to the invoked method.
13387 * @param {Array|string} path The path of the method to invoke.
13388 * @param {...*} [args] The arguments to invoke the method with.
13389 * @returns {Function} Returns the new function.
13393 * { 'a': { 'b': { 'c': _.constant(2) } } },
13394 * { 'a': { 'b': { 'c': _.constant(1) } } }
13397 * _.map(objects, _.method('a.b.c'));
13400 * _.invokeMap(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
13403 var method = rest(function(path, args) {
13404 return function(object) {
13405 return baseInvoke(object, path, args);
13410 * The opposite of `_.method`; this method creates a function that invokes
13411 * the method at a given path of `object`. Any additional arguments are
13412 * provided to the invoked method.
13417 * @param {Object} object The object to query.
13418 * @param {...*} [args] The arguments to invoke the method with.
13419 * @returns {Function} Returns the new function.
13422 * var array = _.times(3, _.constant),
13423 * object = { 'a': array, 'b': array, 'c': array };
13425 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
13428 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
13431 var methodOf = rest(function(object, args) {
13432 return function(path) {
13433 return baseInvoke(object, path, args);
13438 * Adds all own enumerable function properties of a source object to the
13439 * destination object. If `object` is a function then methods are added to
13440 * its prototype as well.
13442 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
13443 * avoid conflicts caused by modifying the original.
13448 * @param {Function|Object} [object=lodash] The destination object.
13449 * @param {Object} source The object of functions to add.
13450 * @param {Object} [options] The options object.
13451 * @param {boolean} [options.chain=true] Specify whether the functions added
13453 * @returns {Function|Object} Returns `object`.
13456 * function vowels(string) {
13457 * return _.filter(string, function(v) {
13458 * return /[aeiou]/i.test(v);
13462 * _.mixin({ 'vowels': vowels });
13463 * _.vowels('fred');
13466 * _('fred').vowels().value();
13469 * _.mixin({ 'vowels': vowels }, { 'chain': false });
13470 * _('fred').vowels();
13473 function mixin(object, source, options) {
13474 var props = keys(source),
13475 methodNames = baseFunctions(source, props);
13477 if (options == null &&
13478 !(isObject(source) && (methodNames.length || !props.length))) {
13482 methodNames = baseFunctions(source, keys(source));
13484 var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
13485 isFunc = isFunction(object);
13487 arrayEach(methodNames, function(methodName) {
13488 var func = source[methodName];
13489 object[methodName] = func;
13491 object.prototype[methodName] = function() {
13492 var chainAll = this.__chain__;
13493 if (chain || chainAll) {
13494 var result = object(this.__wrapped__),
13495 actions = result.__actions__ = copyArray(this.__actions__);
13497 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
13498 result.__chain__ = chainAll;
13501 return func.apply(object, arrayPush([this.value()], arguments));
13510 * Reverts the `_` variable to its previous value and returns a reference to
13511 * the `lodash` function.
13516 * @returns {Function} Returns the `lodash` function.
13519 * var lodash = _.noConflict();
13521 function noConflict() {
13522 if (root._ === this) {
13529 * A no-operation function that returns `undefined` regardless of the
13530 * arguments it receives.
13537 * var object = { 'user': 'fred' };
13539 * _.noop(object) === undefined;
13543 // No operation performed.
13547 * Creates a function that returns its nth argument.
13552 * @param {number} [n=0] The index of the argument to return.
13553 * @returns {Function} Returns the new function.
13556 * var func = _.nthArg(1);
13558 * func('a', 'b', 'c');
13561 function nthArg(n) {
13563 return function() {
13564 return arguments[n];
13569 * Creates a function that invokes `iteratees` with the arguments provided
13570 * to the created function and returns their results.
13575 * @param {...(Function|Function[])} iteratees The iteratees to invoke.
13576 * @returns {Function} Returns the new function.
13579 * var func = _.over(Math.max, Math.min);
13581 * func(1, 2, 3, 4);
13584 var over = createOver(arrayMap);
13587 * Creates a function that checks if **all** of the `predicates` return
13588 * truthy when invoked with the arguments provided to the created function.
13593 * @param {...(Function|Function[])} predicates The predicates to check.
13594 * @returns {Function} Returns the new function.
13597 * var func = _.overEvery(Boolean, isFinite);
13608 var overEvery = createOver(arrayEvery);
13611 * Creates a function that checks if **any** of the `predicates` return
13612 * truthy when invoked with the arguments provided to the created function.
13617 * @param {...(Function|Function[])} predicates The predicates to check.
13618 * @returns {Function} Returns the new function.
13621 * var func = _.overSome(Boolean, isFinite);
13632 var overSome = createOver(arraySome);
13635 * Creates a function that returns the value at `path` of a given object.
13640 * @param {Array|string} path The path of the property to get.
13641 * @returns {Function} Returns the new function.
13645 * { 'a': { 'b': { 'c': 2 } } },
13646 * { 'a': { 'b': { 'c': 1 } } }
13649 * _.map(objects, _.property('a.b.c'));
13652 * _.map(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
13655 function property(path) {
13656 return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
13660 * The opposite of `_.property`; this method creates a function that returns
13661 * the value at a given path of `object`.
13666 * @param {Object} object The object to query.
13667 * @returns {Function} Returns the new function.
13670 * var array = [0, 1, 2],
13671 * object = { 'a': array, 'b': array, 'c': array };
13673 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
13676 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
13679 function propertyOf(object) {
13680 return function(path) {
13681 return object == null ? undefined : baseGet(object, path);
13686 * Creates an array of numbers (positive and/or negative) progressing from
13687 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
13688 * `start` is specified without an `end` or `step`. If `end` is not specified
13689 * it's set to `start` with `start` then set to `0`.
13691 * **Note:** JavaScript follows the IEEE-754 standard for resolving
13692 * floating-point values which can produce unexpected results.
13697 * @param {number} [start=0] The start of the range.
13698 * @param {number} end The end of the range.
13699 * @param {number} [step=1] The value to increment or decrement by.
13700 * @returns {Array} Returns the new array of numbers.
13704 * // => [0, 1, 2, 3]
13707 * // => [0, -1, -2, -3]
13710 * // => [1, 2, 3, 4]
13712 * _.range(0, 20, 5);
13713 * // => [0, 5, 10, 15]
13715 * _.range(0, -4, -1);
13716 * // => [0, -1, -2, -3]
13718 * _.range(1, 4, 0);
13724 var range = createRange();
13727 * This method is like `_.range` except that it populates values in
13728 * descending order.
13733 * @param {number} [start=0] The start of the range.
13734 * @param {number} end The end of the range.
13735 * @param {number} [step=1] The value to increment or decrement by.
13736 * @returns {Array} Returns the new array of numbers.
13740 * // => [3, 2, 1, 0]
13742 * _.rangeRight(-4);
13743 * // => [-3, -2, -1, 0]
13745 * _.rangeRight(1, 5);
13746 * // => [4, 3, 2, 1]
13748 * _.rangeRight(0, 20, 5);
13749 * // => [15, 10, 5, 0]
13751 * _.rangeRight(0, -4, -1);
13752 * // => [-3, -2, -1, 0]
13754 * _.rangeRight(1, 4, 0);
13760 var rangeRight = createRange(true);
13763 * Invokes the iteratee function `n` times, returning an array of the results
13764 * of each invocation. The iteratee is invoked with one argument; (index).
13769 * @param {number} n The number of times to invoke `iteratee`.
13770 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13771 * @returns {Array} Returns the array of results.
13774 * _.times(3, String);
13775 * // => ['0', '1', '2']
13777 * _.times(4, _.constant(true));
13778 * // => [true, true, true, true]
13780 function times(n, iteratee) {
13782 if (n < 1 || n > MAX_SAFE_INTEGER) {
13785 var index = MAX_ARRAY_LENGTH,
13786 length = nativeMin(n, MAX_ARRAY_LENGTH);
13788 iteratee = toFunction(iteratee);
13789 n -= MAX_ARRAY_LENGTH;
13791 var result = baseTimes(length, iteratee);
13792 while (++index < n) {
13799 * Converts `value` to a property path array.
13804 * @param {*} value The value to convert.
13805 * @returns {Array} Returns the new property path array.
13808 * _.toPath('a.b.c');
13809 * // => ['a', 'b', 'c']
13811 * _.toPath('a[0].b.c');
13812 * // => ['a', '0', 'b', 'c']
13814 * var path = ['a', 'b', 'c'],
13815 * newPath = _.toPath(path);
13817 * console.log(newPath);
13818 * // => ['a', 'b', 'c']
13820 * console.log(path === newPath);
13823 function toPath(value) {
13824 return isArray(value) ? arrayMap(value, String) : stringToPath(value);
13828 * Generates a unique ID. If `prefix` is given the ID is appended to it.
13833 * @param {string} [prefix] The value to prefix the ID with.
13834 * @returns {string} Returns the unique ID.
13837 * _.uniqueId('contact_');
13838 * // => 'contact_104'
13843 function uniqueId(prefix) {
13844 var id = ++idCounter;
13845 return toString(prefix) + id;
13848 /*------------------------------------------------------------------------*/
13851 * Adds two numbers.
13856 * @param {number} augend The first number in an addition.
13857 * @param {number} addend The second number in an addition.
13858 * @returns {number} Returns the total.
13864 function add(augend, addend) {
13866 if (augend === undefined && addend === undefined) {
13869 if (augend !== undefined) {
13872 if (addend !== undefined) {
13873 result = result === undefined ? addend : (result + addend);
13879 * Computes `number` rounded up to `precision`.
13884 * @param {number} number The number to round up.
13885 * @param {number} [precision=0] The precision to round up to.
13886 * @returns {number} Returns the rounded up number.
13892 * _.ceil(6.004, 2);
13895 * _.ceil(6040, -2);
13898 var ceil = createRound('ceil');
13901 * Computes `number` rounded down to `precision`.
13906 * @param {number} number The number to round down.
13907 * @param {number} [precision=0] The precision to round down to.
13908 * @returns {number} Returns the rounded down number.
13914 * _.floor(0.046, 2);
13917 * _.floor(4060, -2);
13920 var floor = createRound('floor');
13923 * Computes the maximum value of `array`. If `array` is empty or falsey
13924 * `undefined` is returned.
13929 * @param {Array} array The array to iterate over.
13930 * @returns {*} Returns the maximum value.
13933 * _.max([4, 2, 8, 6]);
13939 function max(array) {
13940 return (array && array.length)
13941 ? baseExtremum(array, identity, gt)
13946 * This method is like `_.max` except that it accepts `iteratee` which is
13947 * invoked for each element in `array` to generate the criterion by which
13948 * the value is ranked. The iteratee is invoked with one argument: (value).
13953 * @param {Array} array The array to iterate over.
13954 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
13955 * @returns {*} Returns the maximum value.
13958 * var objects = [{ 'n': 1 }, { 'n': 2 }];
13960 * _.maxBy(objects, function(o) { return o.n; });
13963 * // The `_.property` iteratee shorthand.
13964 * _.maxBy(objects, 'n');
13967 function maxBy(array, iteratee) {
13968 return (array && array.length)
13969 ? baseExtremum(array, getIteratee(iteratee), gt)
13974 * Computes the mean of the values in `array`.
13979 * @param {Array} array The array to iterate over.
13980 * @returns {number} Returns the mean.
13983 * _.mean([4, 2, 8, 6]);
13986 function mean(array) {
13987 return sum(array) / (array ? array.length : 0);
13991 * Computes the minimum value of `array`. If `array` is empty or falsey
13992 * `undefined` is returned.
13997 * @param {Array} array The array to iterate over.
13998 * @returns {*} Returns the minimum value.
14001 * _.min([4, 2, 8, 6]);
14007 function min(array) {
14008 return (array && array.length)
14009 ? baseExtremum(array, identity, lt)
14014 * This method is like `_.min` except that it accepts `iteratee` which is
14015 * invoked for each element in `array` to generate the criterion by which
14016 * the value is ranked. The iteratee is invoked with one argument: (value).
14021 * @param {Array} array The array to iterate over.
14022 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
14023 * @returns {*} Returns the minimum value.
14026 * var objects = [{ 'n': 1 }, { 'n': 2 }];
14028 * _.minBy(objects, function(o) { return o.n; });
14031 * // The `_.property` iteratee shorthand.
14032 * _.minBy(objects, 'n');
14035 function minBy(array, iteratee) {
14036 return (array && array.length)
14037 ? baseExtremum(array, getIteratee(iteratee), lt)
14042 * Computes `number` rounded to `precision`.
14047 * @param {number} number The number to round.
14048 * @param {number} [precision=0] The precision to round to.
14049 * @returns {number} Returns the rounded number.
14055 * _.round(4.006, 2);
14058 * _.round(4060, -2);
14061 var round = createRound('round');
14064 * Subtract two numbers.
14069 * @param {number} minuend The first number in a subtraction.
14070 * @param {number} subtrahend The second number in a subtraction.
14071 * @returns {number} Returns the difference.
14074 * _.subtract(6, 4);
14077 function subtract(minuend, subtrahend) {
14079 if (minuend === undefined && subtrahend === undefined) {
14082 if (minuend !== undefined) {
14085 if (subtrahend !== undefined) {
14086 result = result === undefined ? subtrahend : (result - subtrahend);
14092 * Computes the sum of the values in `array`.
14097 * @param {Array} array The array to iterate over.
14098 * @returns {number} Returns the sum.
14101 * _.sum([4, 2, 8, 6]);
14104 function sum(array) {
14105 return (array && array.length)
14106 ? baseSum(array, identity)
14111 * This method is like `_.sum` except that it accepts `iteratee` which is
14112 * invoked for each element in `array` to generate the value to be summed.
14113 * The iteratee is invoked with one argument: (value).
14118 * @param {Array} array The array to iterate over.
14119 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
14120 * @returns {number} Returns the sum.
14123 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
14125 * _.sumBy(objects, function(o) { return o.n; });
14128 * // The `_.property` iteratee shorthand.
14129 * _.sumBy(objects, 'n');
14132 function sumBy(array, iteratee) {
14133 return (array && array.length)
14134 ? baseSum(array, getIteratee(iteratee))
14138 /*------------------------------------------------------------------------*/
14140 // Ensure wrappers are instances of `baseLodash`.
14141 lodash.prototype = baseLodash.prototype;
14143 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
14144 LodashWrapper.prototype.constructor = LodashWrapper;
14146 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
14147 LazyWrapper.prototype.constructor = LazyWrapper;
14149 // Avoid inheriting from `Object.prototype` when possible.
14150 Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
14152 // Add functions to the `MapCache`.
14153 MapCache.prototype.clear = mapClear;
14154 MapCache.prototype['delete'] = mapDelete;
14155 MapCache.prototype.get = mapGet;
14156 MapCache.prototype.has = mapHas;
14157 MapCache.prototype.set = mapSet;
14159 // Add functions to the `SetCache`.
14160 SetCache.prototype.push = cachePush;
14162 // Add functions to the `Stack` cache.
14163 Stack.prototype.clear = stackClear;
14164 Stack.prototype['delete'] = stackDelete;
14165 Stack.prototype.get = stackGet;
14166 Stack.prototype.has = stackHas;
14167 Stack.prototype.set = stackSet;
14169 // Assign cache to `_.memoize`.
14170 memoize.Cache = MapCache;
14172 // Add functions that return wrapped values when chaining.
14173 lodash.after = after;
14175 lodash.assign = assign;
14176 lodash.assignIn = assignIn;
14177 lodash.assignInWith = assignInWith;
14178 lodash.assignWith = assignWith;
14180 lodash.before = before;
14181 lodash.bind = bind;
14182 lodash.bindAll = bindAll;
14183 lodash.bindKey = bindKey;
14184 lodash.chain = chain;
14185 lodash.chunk = chunk;
14186 lodash.compact = compact;
14187 lodash.concat = concat;
14188 lodash.cond = cond;
14189 lodash.conforms = conforms;
14190 lodash.constant = constant;
14191 lodash.countBy = countBy;
14192 lodash.create = create;
14193 lodash.curry = curry;
14194 lodash.curryRight = curryRight;
14195 lodash.debounce = debounce;
14196 lodash.defaults = defaults;
14197 lodash.defaultsDeep = defaultsDeep;
14198 lodash.defer = defer;
14199 lodash.delay = delay;
14200 lodash.difference = difference;
14201 lodash.differenceBy = differenceBy;
14202 lodash.differenceWith = differenceWith;
14203 lodash.drop = drop;
14204 lodash.dropRight = dropRight;
14205 lodash.dropRightWhile = dropRightWhile;
14206 lodash.dropWhile = dropWhile;
14207 lodash.fill = fill;
14208 lodash.filter = filter;
14209 lodash.flatMap = flatMap;
14210 lodash.flatten = flatten;
14211 lodash.flattenDeep = flattenDeep;
14212 lodash.flip = flip;
14213 lodash.flow = flow;
14214 lodash.flowRight = flowRight;
14215 lodash.fromPairs = fromPairs;
14216 lodash.functions = functions;
14217 lodash.functionsIn = functionsIn;
14218 lodash.groupBy = groupBy;
14219 lodash.initial = initial;
14220 lodash.intersection = intersection;
14221 lodash.intersectionBy = intersectionBy;
14222 lodash.intersectionWith = intersectionWith;
14223 lodash.invert = invert;
14224 lodash.invertBy = invertBy;
14225 lodash.invokeMap = invokeMap;
14226 lodash.iteratee = iteratee;
14227 lodash.keyBy = keyBy;
14228 lodash.keys = keys;
14229 lodash.keysIn = keysIn;
14231 lodash.mapKeys = mapKeys;
14232 lodash.mapValues = mapValues;
14233 lodash.matches = matches;
14234 lodash.matchesProperty = matchesProperty;
14235 lodash.memoize = memoize;
14236 lodash.merge = merge;
14237 lodash.mergeWith = mergeWith;
14238 lodash.method = method;
14239 lodash.methodOf = methodOf;
14240 lodash.mixin = mixin;
14241 lodash.negate = negate;
14242 lodash.nthArg = nthArg;
14243 lodash.omit = omit;
14244 lodash.omitBy = omitBy;
14245 lodash.once = once;
14246 lodash.orderBy = orderBy;
14247 lodash.over = over;
14248 lodash.overArgs = overArgs;
14249 lodash.overEvery = overEvery;
14250 lodash.overSome = overSome;
14251 lodash.partial = partial;
14252 lodash.partialRight = partialRight;
14253 lodash.partition = partition;
14254 lodash.pick = pick;
14255 lodash.pickBy = pickBy;
14256 lodash.property = property;
14257 lodash.propertyOf = propertyOf;
14258 lodash.pull = pull;
14259 lodash.pullAll = pullAll;
14260 lodash.pullAllBy = pullAllBy;
14261 lodash.pullAt = pullAt;
14262 lodash.range = range;
14263 lodash.rangeRight = rangeRight;
14264 lodash.rearg = rearg;
14265 lodash.reject = reject;
14266 lodash.remove = remove;
14267 lodash.rest = rest;
14268 lodash.reverse = reverse;
14269 lodash.sampleSize = sampleSize;
14271 lodash.setWith = setWith;
14272 lodash.shuffle = shuffle;
14273 lodash.slice = slice;
14274 lodash.sortBy = sortBy;
14275 lodash.sortedUniq = sortedUniq;
14276 lodash.sortedUniqBy = sortedUniqBy;
14277 lodash.split = split;
14278 lodash.spread = spread;
14279 lodash.tail = tail;
14280 lodash.take = take;
14281 lodash.takeRight = takeRight;
14282 lodash.takeRightWhile = takeRightWhile;
14283 lodash.takeWhile = takeWhile;
14285 lodash.throttle = throttle;
14286 lodash.thru = thru;
14287 lodash.toArray = toArray;
14288 lodash.toPairs = toPairs;
14289 lodash.toPairsIn = toPairsIn;
14290 lodash.toPath = toPath;
14291 lodash.toPlainObject = toPlainObject;
14292 lodash.transform = transform;
14293 lodash.unary = unary;
14294 lodash.union = union;
14295 lodash.unionBy = unionBy;
14296 lodash.unionWith = unionWith;
14297 lodash.uniq = uniq;
14298 lodash.uniqBy = uniqBy;
14299 lodash.uniqWith = uniqWith;
14300 lodash.unset = unset;
14301 lodash.unzip = unzip;
14302 lodash.unzipWith = unzipWith;
14303 lodash.values = values;
14304 lodash.valuesIn = valuesIn;
14305 lodash.without = without;
14306 lodash.words = words;
14307 lodash.wrap = wrap;
14309 lodash.xorBy = xorBy;
14310 lodash.xorWith = xorWith;
14312 lodash.zipObject = zipObject;
14313 lodash.zipObjectDeep = zipObjectDeep;
14314 lodash.zipWith = zipWith;
14317 lodash.extend = assignIn;
14318 lodash.extendWith = assignInWith;
14320 // Add functions to `lodash.prototype`.
14321 mixin(lodash, lodash);
14323 /*------------------------------------------------------------------------*/
14325 // Add functions that return unwrapped values when chaining.
14327 lodash.attempt = attempt;
14328 lodash.camelCase = camelCase;
14329 lodash.capitalize = capitalize;
14330 lodash.ceil = ceil;
14331 lodash.clamp = clamp;
14332 lodash.clone = clone;
14333 lodash.cloneDeep = cloneDeep;
14334 lodash.cloneDeepWith = cloneDeepWith;
14335 lodash.cloneWith = cloneWith;
14336 lodash.deburr = deburr;
14337 lodash.endsWith = endsWith;
14339 lodash.escape = escape;
14340 lodash.escapeRegExp = escapeRegExp;
14341 lodash.every = every;
14342 lodash.find = find;
14343 lodash.findIndex = findIndex;
14344 lodash.findKey = findKey;
14345 lodash.findLast = findLast;
14346 lodash.findLastIndex = findLastIndex;
14347 lodash.findLastKey = findLastKey;
14348 lodash.floor = floor;
14349 lodash.forEach = forEach;
14350 lodash.forEachRight = forEachRight;
14351 lodash.forIn = forIn;
14352 lodash.forInRight = forInRight;
14353 lodash.forOwn = forOwn;
14354 lodash.forOwnRight = forOwnRight;
14359 lodash.hasIn = hasIn;
14360 lodash.head = head;
14361 lodash.identity = identity;
14362 lodash.includes = includes;
14363 lodash.indexOf = indexOf;
14364 lodash.inRange = inRange;
14365 lodash.invoke = invoke;
14366 lodash.isArguments = isArguments;
14367 lodash.isArray = isArray;
14368 lodash.isArrayBuffer = isArrayBuffer;
14369 lodash.isArrayLike = isArrayLike;
14370 lodash.isArrayLikeObject = isArrayLikeObject;
14371 lodash.isBoolean = isBoolean;
14372 lodash.isBuffer = isBuffer;
14373 lodash.isDate = isDate;
14374 lodash.isElement = isElement;
14375 lodash.isEmpty = isEmpty;
14376 lodash.isEqual = isEqual;
14377 lodash.isEqualWith = isEqualWith;
14378 lodash.isError = isError;
14379 lodash.isFinite = isFinite;
14380 lodash.isFunction = isFunction;
14381 lodash.isInteger = isInteger;
14382 lodash.isLength = isLength;
14383 lodash.isMap = isMap;
14384 lodash.isMatch = isMatch;
14385 lodash.isMatchWith = isMatchWith;
14386 lodash.isNaN = isNaN;
14387 lodash.isNative = isNative;
14388 lodash.isNil = isNil;
14389 lodash.isNull = isNull;
14390 lodash.isNumber = isNumber;
14391 lodash.isObject = isObject;
14392 lodash.isObjectLike = isObjectLike;
14393 lodash.isPlainObject = isPlainObject;
14394 lodash.isRegExp = isRegExp;
14395 lodash.isSafeInteger = isSafeInteger;
14396 lodash.isSet = isSet;
14397 lodash.isString = isString;
14398 lodash.isSymbol = isSymbol;
14399 lodash.isTypedArray = isTypedArray;
14400 lodash.isUndefined = isUndefined;
14401 lodash.isWeakMap = isWeakMap;
14402 lodash.isWeakSet = isWeakSet;
14403 lodash.join = join;
14404 lodash.kebabCase = kebabCase;
14405 lodash.last = last;
14406 lodash.lastIndexOf = lastIndexOf;
14407 lodash.lowerCase = lowerCase;
14408 lodash.lowerFirst = lowerFirst;
14412 lodash.maxBy = maxBy;
14413 lodash.mean = mean;
14415 lodash.minBy = minBy;
14416 lodash.noConflict = noConflict;
14417 lodash.noop = noop;
14420 lodash.padEnd = padEnd;
14421 lodash.padStart = padStart;
14422 lodash.parseInt = parseInt;
14423 lodash.random = random;
14424 lodash.reduce = reduce;
14425 lodash.reduceRight = reduceRight;
14426 lodash.repeat = repeat;
14427 lodash.replace = replace;
14428 lodash.result = result;
14429 lodash.round = round;
14430 lodash.runInContext = runInContext;
14431 lodash.sample = sample;
14432 lodash.size = size;
14433 lodash.snakeCase = snakeCase;
14434 lodash.some = some;
14435 lodash.sortedIndex = sortedIndex;
14436 lodash.sortedIndexBy = sortedIndexBy;
14437 lodash.sortedIndexOf = sortedIndexOf;
14438 lodash.sortedLastIndex = sortedLastIndex;
14439 lodash.sortedLastIndexBy = sortedLastIndexBy;
14440 lodash.sortedLastIndexOf = sortedLastIndexOf;
14441 lodash.startCase = startCase;
14442 lodash.startsWith = startsWith;
14443 lodash.subtract = subtract;
14445 lodash.sumBy = sumBy;
14446 lodash.template = template;
14447 lodash.times = times;
14448 lodash.toInteger = toInteger;
14449 lodash.toLength = toLength;
14450 lodash.toLower = toLower;
14451 lodash.toNumber = toNumber;
14452 lodash.toSafeInteger = toSafeInteger;
14453 lodash.toString = toString;
14454 lodash.toUpper = toUpper;
14455 lodash.trim = trim;
14456 lodash.trimEnd = trimEnd;
14457 lodash.trimStart = trimStart;
14458 lodash.truncate = truncate;
14459 lodash.unescape = unescape;
14460 lodash.uniqueId = uniqueId;
14461 lodash.upperCase = upperCase;
14462 lodash.upperFirst = upperFirst;
14465 lodash.each = forEach;
14466 lodash.eachRight = forEachRight;
14467 lodash.first = head;
14469 mixin(lodash, (function() {
14471 baseForOwn(lodash, function(func, methodName) {
14472 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
14473 source[methodName] = func;
14477 }()), { 'chain': false });
14479 /*------------------------------------------------------------------------*/
14482 * The semantic version number.
14488 lodash.VERSION = VERSION;
14490 // Assign default placeholders.
14491 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
14492 lodash[methodName].placeholder = lodash;
14495 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
14496 arrayEach(['drop', 'take'], function(methodName, index) {
14497 LazyWrapper.prototype[methodName] = function(n) {
14498 var filtered = this.__filtered__;
14499 if (filtered && !index) {
14500 return new LazyWrapper(this);
14502 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
14504 var result = this.clone();
14506 result.__takeCount__ = nativeMin(n, result.__takeCount__);
14508 result.__views__.push({ 'size': nativeMin(n, MAX_ARRAY_LENGTH), 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
14513 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
14514 return this.reverse()[methodName](n).reverse();
14518 // Add `LazyWrapper` methods that accept an `iteratee` value.
14519 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
14520 var type = index + 1,
14521 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
14523 LazyWrapper.prototype[methodName] = function(iteratee) {
14524 var result = this.clone();
14525 result.__iteratees__.push({ 'iteratee': getIteratee(iteratee, 3), 'type': type });
14526 result.__filtered__ = result.__filtered__ || isFilter;
14531 // Add `LazyWrapper` methods for `_.head` and `_.last`.
14532 arrayEach(['head', 'last'], function(methodName, index) {
14533 var takeName = 'take' + (index ? 'Right' : '');
14535 LazyWrapper.prototype[methodName] = function() {
14536 return this[takeName](1).value()[0];
14540 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
14541 arrayEach(['initial', 'tail'], function(methodName, index) {
14542 var dropName = 'drop' + (index ? '' : 'Right');
14544 LazyWrapper.prototype[methodName] = function() {
14545 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
14549 LazyWrapper.prototype.compact = function() {
14550 return this.filter(identity);
14553 LazyWrapper.prototype.find = function(predicate) {
14554 return this.filter(predicate).head();
14557 LazyWrapper.prototype.findLast = function(predicate) {
14558 return this.reverse().find(predicate);
14561 LazyWrapper.prototype.invokeMap = rest(function(path, args) {
14562 if (typeof path == 'function') {
14563 return new LazyWrapper(this);
14565 return this.map(function(value) {
14566 return baseInvoke(value, path, args);
14570 LazyWrapper.prototype.reject = function(predicate) {
14571 predicate = getIteratee(predicate, 3);
14572 return this.filter(function(value) {
14573 return !predicate(value);
14577 LazyWrapper.prototype.slice = function(start, end) {
14578 start = toInteger(start);
14581 if (result.__filtered__ && (start > 0 || end < 0)) {
14582 return new LazyWrapper(result);
14585 result = result.takeRight(-start);
14586 } else if (start) {
14587 result = result.drop(start);
14589 if (end !== undefined) {
14590 end = toInteger(end);
14591 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
14596 LazyWrapper.prototype.takeRightWhile = function(predicate) {
14597 return this.reverse().takeWhile(predicate).reverse();
14600 LazyWrapper.prototype.toArray = function() {
14601 return this.take(MAX_ARRAY_LENGTH);
14604 // Add `LazyWrapper` methods to `lodash.prototype`.
14605 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
14606 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
14607 isTaker = /^(?:head|last)$/.test(methodName),
14608 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
14609 retUnwrapped = isTaker || /^find/.test(methodName);
14614 lodash.prototype[methodName] = function() {
14615 var value = this.__wrapped__,
14616 args = isTaker ? [1] : arguments,
14617 isLazy = value instanceof LazyWrapper,
14618 iteratee = args[0],
14619 useLazy = isLazy || isArray(value);
14621 var interceptor = function(value) {
14622 var result = lodashFunc.apply(lodash, arrayPush([value], args));
14623 return (isTaker && chainAll) ? result[0] : result;
14626 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
14627 // Avoid lazy use if the iteratee has a "length" value other than `1`.
14628 isLazy = useLazy = false;
14630 var chainAll = this.__chain__,
14631 isHybrid = !!this.__actions__.length,
14632 isUnwrapped = retUnwrapped && !chainAll,
14633 onlyLazy = isLazy && !isHybrid;
14635 if (!retUnwrapped && useLazy) {
14636 value = onlyLazy ? value : new LazyWrapper(this);
14637 var result = func.apply(value, args);
14638 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
14639 return new LodashWrapper(result, chainAll);
14641 if (isUnwrapped && onlyLazy) {
14642 return func.apply(this, args);
14644 result = this.thru(interceptor);
14645 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
14649 // Add `Array` and `String` methods to `lodash.prototype`.
14650 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
14651 var func = arrayProto[methodName],
14652 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
14653 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
14655 lodash.prototype[methodName] = function() {
14656 var args = arguments;
14657 if (retUnwrapped && !this.__chain__) {
14658 return func.apply(this.value(), args);
14660 return this[chainName](function(value) {
14661 return func.apply(value, args);
14666 // Map minified function names to their real names.
14667 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
14668 var lodashFunc = lodash[methodName];
14670 var key = (lodashFunc.name + ''),
14671 names = realNames[key] || (realNames[key] = []);
14673 names.push({ 'name': methodName, 'func': lodashFunc });
14677 realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
14679 // Add functions to the lazy wrapper.
14680 LazyWrapper.prototype.clone = lazyClone;
14681 LazyWrapper.prototype.reverse = lazyReverse;
14682 LazyWrapper.prototype.value = lazyValue;
14684 // Add chaining functions to the `lodash` wrapper.
14685 lodash.prototype.at = wrapperAt;
14686 lodash.prototype.chain = wrapperChain;
14687 lodash.prototype.commit = wrapperCommit;
14688 lodash.prototype.flatMap = wrapperFlatMap;
14689 lodash.prototype.next = wrapperNext;
14690 lodash.prototype.plant = wrapperPlant;
14691 lodash.prototype.reverse = wrapperReverse;
14692 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
14694 if (iteratorSymbol) {
14695 lodash.prototype[iteratorSymbol] = wrapperToIterator;
14700 /*--------------------------------------------------------------------------*/
14703 var _ = runInContext();
14705 // Expose lodash on the free variable `window` or `self` when available. This
14706 // prevents errors in cases where lodash is loaded by a script tag in the presence
14707 // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
14708 (freeWindow || freeSelf || {})._ = _;
14710 // Some AMD build optimizers like r.js check for condition patterns like the following:
14711 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
14712 // Define as an anonymous module so, through path mapping, it can be
14713 // referenced as the "underscore" module.
14714 define(function() {
14718 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
14719 else if (freeExports && freeModule) {
14720 // Export for Node.js.
14721 if (moduleExports) {
14722 (freeModule.exports = _)._ = _;
14724 // Export for CommonJS support.
14728 // Export to the global object.