Debian Codegraph @

externals/lodash.js

raw symbols SCIP
1 /**
2 * @license
3 * lodash 3.0.0 (Custom Build) <https://lodash.com/>
4 * Build: `lodash modern -o ./lodash.js`
5 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
9 */
10 ;(function() {
11
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
13 var undefined;
14
15 /** Used as the semantic version number. */
16 var VERSION = '3.0.0';
17
18 /** Used to compose bitmasks for wrapper metadata. */
19 var BIND_FLAG = 1,
20 BIND_KEY_FLAG = 2,
21 CURRY_BOUND_FLAG = 4,
22 CURRY_FLAG = 8,
23 CURRY_RIGHT_FLAG = 16,
24 PARTIAL_FLAG = 32,
25 PARTIAL_RIGHT_FLAG = 64,
26 REARG_FLAG = 128,
27 ARY_FLAG = 256;
28
29 /** Used as default options for `_.trunc`. */
30 var DEFAULT_TRUNC_LENGTH = 30,
31 DEFAULT_TRUNC_OMISSION = '...';
32
33 /** Used to detect when a function becomes hot. */
34 var HOT_COUNT = 150,
35 HOT_SPAN = 16;
36
37 /** Used to indicate the type of lazy iteratees. */
38 var LAZY_FILTER_FLAG = 0,
39 LAZY_MAP_FLAG = 1,
40 LAZY_WHILE_FLAG = 2;
41
42 /** Used as the `TypeError` message for "Functions" methods. */
43 var FUNC_ERROR_TEXT = 'Expected a function';
44
45 /** Used as the internal argument placeholder. */
46 var PLACEHOLDER = '__lodash_placeholder__';
47
48 /** `Object#toString` result references. */
49 var argsTag = '[object Arguments]',
50 arrayTag = '[object Array]',
51 boolTag = '[object Boolean]',
52 dateTag = '[object Date]',
53 errorTag = '[object Error]',
54 funcTag = '[object Function]',
55 mapTag = '[object Map]',
56 numberTag = '[object Number]',
57 objectTag = '[object Object]',
58 regexpTag = '[object RegExp]',
59 setTag = '[object Set]',
60 stringTag = '[object String]',
61 weakMapTag = '[object WeakMap]';
62
63 var arrayBufferTag = '[object ArrayBuffer]',
64 float32Tag = '[object Float32Array]',
65 float64Tag = '[object Float64Array]',
66 int8Tag = '[object Int8Array]',
67 int16Tag = '[object Int16Array]',
68 int32Tag = '[object Int32Array]',
69 uint8Tag = '[object Uint8Array]',
70 uint8ClampedTag = '[object Uint8ClampedArray]',
71 uint16Tag = '[object Uint16Array]',
72 uint32Tag = '[object Uint32Array]';
73
74 /** Used to match empty string literals in compiled template source. */
75 var reEmptyStringLeading = /\b__p \+= '';/g,
76 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
77 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
78
79 /** Used to match HTML entities and HTML characters. */
80 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
81 reUnescapedHtml = /[&<>"'`]/g,
82 reHasEscapedHtml = RegExp(reEscapedHtml.source),
83 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
84
85 /** Used to match template delimiters. */
86 var reEscape = /<%-([\s\S]+?)%>/g,
87 reEvaluate = /<%([\s\S]+?)%>/g,
88 reInterpolate = /<%=([\s\S]+?)%>/g;
89
90 /**
91 * Used to match ES template delimiters.
92 * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
93 * for more details.
94 */
95 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
96
97 /** Used to match `RegExp` flags from their coerced string values. */
98 var reFlags = /\w*$/;
99
100 /** Used to detect named functions. */
101 var reFuncName = /^\s*function[ \n\r\t]+\w/;
102
103 /** Used to detect hexadecimal string values. */
104 var reHexPrefix = /^0[xX]/;
105
106 /** Used to detect host constructors (Safari > 5). */
107 var reHostCtor = /^\[object .+?Constructor\]$/;
108
109 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
110 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
111
112 /** Used to ensure capturing order of template delimiters. */
113 var reNoMatch = /($^)/;
114
115 /**
116 * Used to match `RegExp` special characters.
117 * See this [article on `RegExp` characters](http://www.regular-expressions.info/characters.html#special)
118 * for more details.
119 */
120 var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
121 reHasRegExpChars = RegExp(reRegExpChars.source);
122
123 /** Used to detect functions containing a `this` reference. */
124 var reThis = /\bthis\b/;
125
126 /** Used to match unescaped characters in compiled string literals. */
127 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
128
129 /** Used to match words to create compound words. */
130 var reWords = (function() {
131 var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
132 lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
133
134 return RegExp(upper + '{2,}(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
135 }());
136
137 /** Used to detect and test for whitespace. */
138 var whitespace = (
139 // Basic whitespace characters.
140 ' \t\x0b\f\xa0\ufeff' +
141
142 // Line terminators.
143 '\n\r\u2028\u2029' +
144
145 // Unicode category "Zs" space separators.
146 '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
147 );
148
149 /** Used to assign default `context` object properties. */
150 var contextProps = [
151 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
152 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
153 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'document',
154 'isFinite', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
155 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
156 'window', 'WinRTError'
157 ];
158
159 /** Used to make template sourceURLs easier to identify. */
160 var templateCounter = -1;
161
162 /** Used to identify `toStringTag` values of typed arrays. */
163 var typedArrayTags = {};
164 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
165 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
166 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
167 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
168 typedArrayTags[uint32Tag] = true;
169 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
170 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
171 typedArrayTags[dateTag] = typedArrayTags[errorTag] =
172 typedArrayTags[funcTag] = typedArrayTags[mapTag] =
173 typedArrayTags[numberTag] = typedArrayTags[objectTag] =
174 typedArrayTags[regexpTag] = typedArrayTags[setTag] =
175 typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
176
177 /** Used to identify `toStringTag` values supported by `_.clone`. */
178 var cloneableTags = {};
179 cloneableTags[argsTag] = cloneableTags[arrayTag] =
180 cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
181 cloneableTags[dateTag] = cloneableTags[float32Tag] =
182 cloneableTags[float64Tag] = cloneableTags[int8Tag] =
183 cloneableTags[int16Tag] = cloneableTags[int32Tag] =
184 cloneableTags[numberTag] = cloneableTags[objectTag] =
185 cloneableTags[regexpTag] = cloneableTags[stringTag] =
186 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
187 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
188 cloneableTags[errorTag] = cloneableTags[funcTag] =
189 cloneableTags[mapTag] = cloneableTags[setTag] =
190 cloneableTags[weakMapTag] = false;
191
192 /** Used as an internal `_.debounce` options object by `_.throttle`. */
193 var debounceOptions = {
194 'leading': false,
195 'maxWait': 0,
196 'trailing': false
197 };
198
199 /** Used to map latin-1 supplementary letters to basic latin letters. */
200 var deburredLetters = {
201 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
202 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
203 '\xc7': 'C', '\xe7': 'c',
204 '\xd0': 'D', '\xf0': 'd',
205 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
206 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
207 '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
208 '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
209 '\xd1': 'N', '\xf1': 'n',
210 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
211 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
212 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
213 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
214 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
215 '\xc6': 'Ae', '\xe6': 'ae',
216 '\xde': 'Th', '\xfe': 'th',
217 '\xdf': 'ss'
218 };
219
220 /** Used to map characters to HTML entities. */
221 var htmlEscapes = {
222 '&': '&amp;',
223 '<': '&lt;',
224 '>': '&gt;',
225 '"': '&quot;',
226 "'": '&#39;',
227 '`': '&#96;'
228 };
229
230 /** Used to map HTML entities to characters. */
231 var htmlUnescapes = {
232 '&amp;': '&',
233 '&lt;': '<',
234 '&gt;': '>',
235 '&quot;': '"',
236 '&#39;': "'",
237 '&#96;': '`'
238 };
239
240 /** Used to determine if values are of the language type `Object`. */
241 var objectTypes = {
242 'function': true,
243 'object': true
244 };
245
246 /** Used to escape characters for inclusion in compiled string literals. */
247 var stringEscapes = {
248 '\\': '\\',
249 "'": "'",
250 '\n': 'n',
251 '\r': 'r',
252 '\u2028': 'u2028',
253 '\u2029': 'u2029'
254 };
255
256 /**
257 * Used as a reference to the global object.
258 *
259 * The `this` value is used if it is the global object to avoid Greasemonkey's
260 * restricted `window` object, otherwise the `window` object is used.
261 */
262 var root = (objectTypes[typeof window] && window !== (this && this.window)) ? window : this;
263
264 /** Detect free variable `exports`. */
265 var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
266
267 /** Detect free variable `module`. */
268 var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
269
270 /** Detect free variable `global` from Node.js or Browserified code and use it as `root`. */
271 var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
272 if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
273 root = freeGlobal;
274 }
275
276 /** Detect the popular CommonJS extension `module.exports`. */
277 var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
278
279 /*--------------------------------------------------------------------------*/
280
281 /**
282 * The base implementation of `compareAscending` which compares values and
283 * sorts them in ascending order without guaranteeing a stable sort.
284 *
285 * @private
286 * @param {*} value The value to compare to `other`.
287 * @param {*} other The value to compare to `value`.
288 * @returns {number} Returns the sort order indicator for `value`.
289 */
290 function baseCompareAscending(value, other) {
291 if (value !== other) {
292 var valIsReflexive = value === value,
293 othIsReflexive = other === other;
294
295 if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
296 return 1;
297 }
298 if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
299 return -1;
300 }
301 }
302 return 0;
303 }
304
305 /**
306 * The base implementation of `_.indexOf` without support for binary searches.
307 *
308 * @private
309 * @param {Array} array The array to search.
310 * @param {*} value The value to search for.
311 * @param {number} [fromIndex=0] The index to search from.
312 * @returns {number} Returns the index of the matched value, else `-1`.
313 */
314 function baseIndexOf(array, value, fromIndex) {
315 if (value !== value) {
316 return indexOfNaN(array, fromIndex);
317 }
318 var index = (fromIndex || 0) - 1,
319 length = array.length;
320
321 while (++index < length) {
322 if (array[index] === value) {
323 return index;
324 }
325 }
326 return -1;
327 }
328
329 /**
330 * The base implementation of `_.sortBy` and `_.sortByAll` which uses `comparer`
331 * to define the sort order of `array` and replaces criteria objects with their
332 * corresponding values.
333 *
334 * @private
335 * @param {Array} array The array to sort.
336 * @param {Function} comparer The function to define sort order.
337 * @returns {Array} Returns `array`.
338 */
339 function baseSortBy(array, comparer) {
340 var length = array.length;
341
342 array.sort(comparer);
343 while (length--) {
344 array[length] = array[length].value;
345 }
346 return array;
347 }
348
349 /**
350 * Converts `value` to a string if it is not one. An empty string is returned
351 * for `null` or `undefined` values.
352 *
353 * @private
354 * @param {*} value The value to process.
355 * @returns {string} Returns the string.
356 */
357 function baseToString(value) {
358 if (typeof value == 'string') {
359 return value;
360 }
361 return value == null ? '' : (value + '');
362 }
363
364 /**
365 * Used by `_.max` and `_.min` as the default callback for string values.
366 *
367 * @private
368 * @param {string} string The string to inspect.
369 * @returns {number} Returns the code unit of the first character of the string.
370 */
371 function charAtCallback(string) {
372 return string.charCodeAt(0);
373 }
374
375 /**
376 * Used by `_.trim` and `_.trimLeft` to get the index of the first character
377 * of `string` that is not found in `chars`.
378 *
379 * @private
380 * @param {string} string The string to inspect.
381 * @param {string} chars The characters to find.
382 * @returns {number} Returns the index of the first character not found in `chars`.
383 */
384 function charsLeftIndex(string, chars) {
385 var index = -1,
386 length = string.length;
387
388 while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
389 return index;
390 }
391
392 /**
393 * Used by `_.trim` and `_.trimRight` to get the index of the last character
394 * of `string` that is not found in `chars`.
395 *
396 * @private
397 * @param {string} string The string to inspect.
398 * @param {string} chars The characters to find.
399 * @returns {number} Returns the index of the last character not found in `chars`.
400 */
401 function charsRightIndex(string, chars) {
402 var index = string.length;
403
404 while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
405 return index;
406 }
407
408 /**
409 * Used by `_.sortBy` to compare transformed elements of a collection and stable
410 * sort them in ascending order.
411 *
412 * @private
413 * @param {Object} object The object to compare to `other`.
414 * @param {Object} other The object to compare to `object`.
415 * @returns {number} Returns the sort order indicator for `object`.
416 */
417 function compareAscending(object, other) {
418 return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
419 }
420
421 /**
422 * Used by `_.sortByAll` to compare multiple properties of each element
423 * in a collection and stable sort them in ascending order.
424 *
425 * @private
426 * @param {Object} object The object to compare to `other`.
427 * @param {Object} other The object to compare to `object`.
428 * @returns {number} Returns the sort order indicator for `object`.
429 */
430 function compareMultipleAscending(object, other) {
431 var index = -1,
432 objCriteria = object.criteria,
433 othCriteria = other.criteria,
434 length = objCriteria.length;
435
436 while (++index < length) {
437 var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
438 if (result) {
439 return result;
440 }
441 }
442 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
443 // that causes it, under certain circumstances, to provide the same value for
444 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
445 // for more details.
446 //
447 // This also ensures a stable sort in V8 and other engines.
448 // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
449 return object.index - other.index;
450 }
451
452 /**
453 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
454 *
455 * @private
456 * @param {string} letter The matched letter to deburr.
457 * @returns {string} Returns the deburred letter.
458 */
459 function deburrLetter(letter) {
460 return deburredLetters[letter];
461 }
462
463 /**
464 * Used by `_.escape` to convert characters to HTML entities.
465 *
466 * @private
467 * @param {string} chr The matched character to escape.
468 * @returns {string} Returns the escaped character.
469 */
470 function escapeHtmlChar(chr) {
471 return htmlEscapes[chr];
472 }
473
474 /**
475 * Used by `_.template` to escape characters for inclusion in compiled
476 * string literals.
477 *
478 * @private
479 * @param {string} chr The matched character to escape.
480 * @returns {string} Returns the escaped character.
481 */
482 function escapeStringChar(chr) {
483 return '\\' + stringEscapes[chr];
484 }
485
486 /**
487 * Gets the index at which the first occurrence of `NaN` is found in `array`.
488 * If `fromRight` is provided elements of `array` are iterated from right to left.
489 *
490 * @private
491 * @param {Array} array The array to search.
492 * @param {number} [fromIndex] The index to search from.
493 * @param {boolean} [fromRight] Specify iterating from right to left.
494 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
495 */
496 function indexOfNaN(array, fromIndex, fromRight) {
497 var length = array.length,
498 index = fromRight ? (fromIndex || length) : ((fromIndex || 0) - 1);
499
500 while ((fromRight ? index-- : ++index < length)) {
501 var other = array[index];
502 if (other !== other) {
503 return index;
504 }
505 }
506 return -1;
507 }
508
509 /**
510 * Checks if `value` is object-like.
511 *
512 * @private
513 * @param {*} value The value to check.
514 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
515 */
516 function isObjectLike(value) {
517 return (value && typeof value == 'object') || false;
518 }
519
520 /**
521 * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
522 * character code is whitespace.
523 *
524 * @private
525 * @param {number} charCode The character code to inspect.
526 * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
527 */
528 function isSpace(charCode) {
529 return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
530 (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
531 }
532
533 /**
534 * Replaces all `placeholder` elements in `array` with an internal placeholder
535 * and returns an array of their indexes.
536 *
537 * @private
538 * @param {Array} array The array to modify.
539 * @param {*} placeholder The placeholder to replace.
540 * @returns {Array} Returns the new array of placeholder indexes.
541 */
542 function replaceHolders(array, placeholder) {
543 var index = -1,
544 length = array.length,
545 resIndex = -1,
546 result = [];
547
548 while (++index < length) {
549 if (array[index] === placeholder) {
550 array[index] = PLACEHOLDER;
551 result[++resIndex] = index;
552 }
553 }
554 return result;
555 }
556
557 /**
558 * An implementation of `_.uniq` optimized for sorted arrays without support
559 * for callback shorthands and `this` binding.
560 *
561 * @private
562 * @param {Array} array The array to inspect.
563 * @param {Function} [iteratee] The function invoked per iteration.
564 * @returns {Array} Returns the new duplicate-value-free array.
565 */
566 function sortedUniq(array, iteratee) {
567 var seen,
568 index = -1,
569 length = array.length,
570 resIndex = -1,
571 result = [];
572
573 while (++index < length) {
574 var value = array[index],
575 computed = iteratee ? iteratee(value, index, array) : value;
576
577 if (!index || seen !== computed) {
578 seen = computed;
579 result[++resIndex] = value;
580 }
581 }
582 return result;
583 }
584
585 /**
586 * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
587 * character of `string`.
588 *
589 * @private
590 * @param {string} string The string to inspect.
591 * @returns {number} Returns the index of the first non-whitespace character.
592 */
593 function trimmedLeftIndex(string) {
594 var index = -1,
595 length = string.length;
596
597 while (++index < length && isSpace(string.charCodeAt(index))) {}
598 return index;
599 }
600
601 /**
602 * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
603 * character of `string`.
604 *
605 * @private
606 * @param {string} string The string to inspect.
607 * @returns {number} Returns the index of the last non-whitespace character.
608 */
609 function trimmedRightIndex(string) {
610 var index = string.length;
611
612 while (index-- && isSpace(string.charCodeAt(index))) {}
613 return index;
614 }
615
616 /**
617 * Used by `_.unescape` to convert HTML entities to characters.
618 *
619 * @private
620 * @param {string} chr The matched character to unescape.
621 * @returns {string} Returns the unescaped character.
622 */
623 function unescapeHtmlChar(chr) {
624 return htmlUnescapes[chr];
625 }
626
627 /*--------------------------------------------------------------------------*/
628
629 /**
630 * Create a new pristine `lodash` function using the given `context` object.
631 *
632 * @static
633 * @memberOf _
634 * @category Utility
635 * @param {Object} [context=root] The context object.
636 * @returns {Function} Returns a new `lodash` function.
637 * @example
638 *
639 * _.mixin({ 'add': function(a, b) { return a + b; } });
640 *
641 * var lodash = _.runInContext();
642 * lodash.mixin({ 'sub': function(a, b) { return a - b; } });
643 *
644 * _.isFunction(_.add);
645 * // => true
646 * _.isFunction(_.sub);
647 * // => false
648 *
649 * lodash.isFunction(lodash.add);
650 * // => false
651 * lodash.isFunction(lodash.sub);
652 * // => true
653 *
654 * // using `context` to mock `Date#getTime` use in `_.now`
655 * var mock = _.runInContext({
656 * 'Date': function() {
657 * return { 'getTime': getTimeMock };
658 * }
659 * });
660 *
661 * // or creating a suped-up `defer` in Node.js
662 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
663 */
664 function runInContext(context) {
665 // Avoid issues with some ES3 environments that attempt to use values, named
666 // after built-in constructors like `Object`, for the creation of literals.
667 // ES5 clears this up by stating that literals must use built-in constructors.
668 // See https://es5.github.io/#x11.1.5 for more details.
669 context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
670
671 /** Native constructor references. */
672 var Array = context.Array,
673 Date = context.Date,
674 Error = context.Error,
675 Function = context.Function,
676 Math = context.Math,
677 Number = context.Number,
678 Object = context.Object,
679 RegExp = context.RegExp,
680 String = context.String,
681 TypeError = context.TypeError;
682
683 /** Used for native method references. */
684 var arrayProto = Array.prototype,
685 objectProto = Object.prototype;
686
687 /** Used to detect DOM support. */
688 var document = (document = context.window) && document.document;
689
690 /** Used to resolve the decompiled source of functions. */
691 var fnToString = Function.prototype.toString;
692
693 /** Used to the length of n-tuples for `_.unzip`. */
694 var getLength = baseProperty('length');
695
696 /** Used to check objects for own properties. */
697 var hasOwnProperty = objectProto.hasOwnProperty;
698
699 /** Used to generate unique IDs. */
700 var idCounter = 0;
701
702 /**
703 * Used to resolve the `toStringTag` of values.
704 * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
705 * for more details.
706 */
707 var objToString = objectProto.toString;
708
709 /** Used to restore the original `_` reference in `_.noConflict`. */
710 var oldDash = context._;
711
712 /** Used to detect if a method is native. */
713 var reNative = RegExp('^' +
714 escapeRegExp(objToString)
715 .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
716 );
717
718 /** Native method references. */
719 var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer,
720 bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
721 ceil = Math.ceil,
722 clearTimeout = context.clearTimeout,
723 floor = Math.floor,
724 getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
725 push = arrayProto.push,
726 propertyIsEnumerable = objectProto.propertyIsEnumerable,
727 Set = isNative(Set = context.Set) && Set,
728 setTimeout = context.setTimeout,
729 splice = arrayProto.splice,
730 Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
731 unshift = arrayProto.unshift,
732 WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap;
733
734 /** Used to clone array buffers. */
735 var Float64Array = (function() {
736 // Safari 5 errors when using an array buffer to initialize a typed array
737 // where the array buffer's `byteLength` is not a multiple of the typed
738 // array's `BYTES_PER_ELEMENT`.
739 try {
740 var func = isNative(func = context.Float64Array) && func,
741 result = new func(new ArrayBuffer(10), 0, 1) && func;
742 } catch(e) {}
743 return result;
744 }());
745
746 /* Native method references for those with the same name as other `lodash` methods. */
747 var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
748 nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
749 nativeIsFinite = context.isFinite,
750 nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
751 nativeMax = Math.max,
752 nativeMin = Math.min,
753 nativeNow = isNative(nativeNow = Date.now) && nativeNow,
754 nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite,
755 nativeParseInt = context.parseInt,
756 nativeRandom = Math.random;
757
758 /** Used as references for `-Infinity` and `Infinity`. */
759 var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
760 POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
761
762 /** Used as references for the maximum length and index of an array. */
763 var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
764 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
765 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
766
767 /** Used as the size, in bytes, of each `Float64Array` element. */
768 var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
769
770 /**
771 * Used as the maximum length of an array-like value.
772 * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
773 * for more details.
774 */
775 var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
776
777 /** Used to store function metadata. */
778 var metaMap = WeakMap && new WeakMap;
779
780 /*------------------------------------------------------------------------*/
781
782 /**
783 * Creates a `lodash` object which wraps `value` to enable intuitive chaining.
784 * Methods that operate on and return arrays, collections, and functions can
785 * be chained together. Methods that return a boolean or single value will
786 * automatically end the chain returning the unwrapped value. Explicit chaining
787 * may be enabled using `_.chain`. The execution of chained methods is lazy,
788 * that is, execution is deferred until `_#value` is implicitly or explicitly
789 * called.
790 *
791 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
792 * fusion is an optimization that merges iteratees to avoid creating intermediate
793 * arrays and reduce the number of iteratee executions.
794 *
795 * Chaining is supported in custom builds as long as the `_#value` method is
796 * directly or indirectly included in the build.
797 *
798 * In addition to lodash methods, wrappers also have the following `Array` methods:
799 * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
800 * and `unshift`
801 *
802 * The wrapper functions that support shortcut fusion are:
803 * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`,
804 * `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`,
805 * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where`
806 *
807 * The chainable wrapper functions are:
808 * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
809 * `callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`,
810 * `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`,
811 * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`,
812 * `flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`,
813 * `forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`,
814 * `initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`,
815 * `mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`,
816 * `omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`,
817 * `pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`,
818 * `rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
819 * `sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`,
820 * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
821 * `transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`,
822 * `where`, `without`, `wrap`, `xor`, `zip`, and `zipObject`
823 *
824 * The wrapper functions that are **not** chainable by default are:
825 * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
826 * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
827 * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
828 * `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
829 * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
830 * `isFunction`, `isMatch` , `isNative`, `isNaN`, `isNull`, `isNumber`,
831 * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
832 * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
833 * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
834 * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
835 * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
836 * `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
837 * `unescape`, `uniqueId`, `value`, and `words`
838 *
839 * The wrapper function `sample` will return a wrapped value when `n` is provided,
840 * otherwise an unwrapped value is returned.
841 *
842 * @name _
843 * @constructor
844 * @category Chain
845 * @param {*} value The value to wrap in a `lodash` instance.
846 * @returns {Object} Returns a `lodash` instance.
847 * @example
848 *
849 * var wrapped = _([1, 2, 3]);
850 *
851 * // returns an unwrapped value
852 * wrapped.reduce(function(sum, n) { return sum + n; });
853 * // => 6
854 *
855 * // returns a wrapped value
856 * var squares = wrapped.map(function(n) { return n * n; });
857 *
858 * _.isArray(squares);
859 * // => false
860 *
861 * _.isArray(squares.value());
862 * // => true
863 */
864 function lodash(value) {
865 if (isObjectLike(value) && !isArray(value)) {
866 if (value instanceof LodashWrapper) {
867 return value;
868 }
869 if (hasOwnProperty.call(value, '__wrapped__')) {
870 return new LodashWrapper(value.__wrapped__, value.__chain__, arrayCopy(value.__actions__));
871 }
872 }
873 return new LodashWrapper(value);
874 }
875
876 /**
877 * The base constructor for creating `lodash` wrapper objects.
878 *
879 * @private
880 * @param {*} value The value to wrap.
881 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
882 * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
883 */
884 function LodashWrapper(value, chainAll, actions) {
885 this.__actions__ = actions || [];
886 this.__chain__ = !!chainAll;
887 this.__wrapped__ = value;
888 }
889
890 /**
891 * An object environment feature flags.
892 *
893 * @static
894 * @memberOf _
895 * @type Object
896 */
897 var support = lodash.support = {};
898
899 (function(x) {
900
901 /**
902 * Detect if functions can be decompiled by `Function#toString`
903 * (all but Firefox OS certified apps, older Opera mobile browsers, and
904 * the PlayStation 3; forced `false` for Windows 8 apps).
905 *
906 * @memberOf _.support
907 * @type boolean
908 */
909 support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
910
911 /**
912 * Detect if `Function#name` is supported (all but IE).
913 *
914 * @memberOf _.support
915 * @type boolean
916 */
917 support.funcNames = typeof Function.name == 'string';
918
919 /**
920 * Detect if the DOM is supported.
921 *
922 * @memberOf _.support
923 * @type boolean
924 */
925 try {
926 support.dom = document.createDocumentFragment().nodeType === 11;
927 } catch(e) {
928 support.dom = false;
929 }
930
931 /**
932 * Detect if `arguments` object indexes are non-enumerable.
933 *
934 * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
935 * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
936 * `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
937 * checks for indexes that exceed their function's formal parameters with
938 * associated values of `0`.
939 *
940 * @memberOf _.support
941 * @type boolean
942 */
943 try {
944 support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
945 } catch(e) {
946 support.nonEnumArgs = true;
947 }
948 }(0, 0));
949
950 /**
951 * By default, the template delimiters used by lodash are like those in
952 * embedded Ruby (ERB). Change the following template settings to use
953 * alternative delimiters.
954 *
955 * @static
956 * @memberOf _
957 * @type Object
958 */
959 lodash.templateSettings = {
960
961 /**
962 * Used to detect `data` property values to be HTML-escaped.
963 *
964 * @memberOf _.templateSettings
965 * @type RegExp
966 */
967 'escape': reEscape,
968
969 /**
970 * Used to detect code to be evaluated.
971 *
972 * @memberOf _.templateSettings
973 * @type RegExp
974 */
975 'evaluate': reEvaluate,
976
977 /**
978 * Used to detect `data` property values to inject.
979 *
980 * @memberOf _.templateSettings
981 * @type RegExp
982 */
983 'interpolate': reInterpolate,
984
985 /**
986 * Used to reference the data object in the template text.
987 *
988 * @memberOf _.templateSettings
989 * @type string
990 */
991 'variable': '',
992
993 /**
994 * Used to import variables into the compiled template.
995 *
996 * @memberOf _.templateSettings
997 * @type Object
998 */
999 'imports': {
1000
1001 /**
1002 * A reference to the `lodash` function.
1003 *
1004 * @memberOf _.templateSettings.imports
1005 * @type Function
1006 */
1007 '_': lodash
1008 }
1009 };
1010
1011 /*------------------------------------------------------------------------*/
1012
1013 /**
1014 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1015 *
1016 * @private
1017 * @param {*} value The value to wrap.
1018 */
1019 function LazyWrapper(value) {
1020 this.actions = null;
1021 this.dir = 1;
1022 this.dropCount = 0;
1023 this.filtered = false;
1024 this.iteratees = null;
1025 this.takeCount = POSITIVE_INFINITY;
1026 this.views = null;
1027 this.wrapped = value;
1028 }
1029
1030 /**
1031 * Creates a clone of the lazy wrapper object.
1032 *
1033 * @private
1034 * @name clone
1035 * @memberOf LazyWrapper
1036 * @returns {Object} Returns the cloned `LazyWrapper` object.
1037 */
1038 function lazyClone() {
1039 var actions = this.actions,
1040 iteratees = this.iteratees,
1041 views = this.views,
1042 result = new LazyWrapper(this.wrapped);
1043
1044 result.actions = actions ? arrayCopy(actions) : null;
1045 result.dir = this.dir;
1046 result.dropCount = this.dropCount;
1047 result.filtered = this.filtered;
1048 result.iteratees = iteratees ? arrayCopy(iteratees) : null;
1049 result.takeCount = this.takeCount;
1050 result.views = views ? arrayCopy(views) : null;
1051 return result;
1052 }
1053
1054 /**
1055 * Reverses the direction of lazy iteration.
1056 *
1057 * @private
1058 * @name reverse
1059 * @memberOf LazyWrapper
1060 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1061 */
1062 function lazyReverse() {
1063 var filtered = this.filtered,
1064 result = filtered ? new LazyWrapper(this) : this.clone();
1065
1066 result.dir = this.dir * -1;
1067 result.filtered = filtered;
1068 return result;
1069 }
1070
1071 /**
1072 * Extracts the unwrapped value from its lazy wrapper.
1073 *
1074 * @private
1075 * @name value
1076 * @memberOf LazyWrapper
1077 * @returns {*} Returns the unwrapped value.
1078 */
1079 function lazyValue() {
1080 var array = this.wrapped.value();
1081 if (!isArray(array)) {
1082 return baseWrapperValue(array, this.actions);
1083 }
1084 var dir = this.dir,
1085 isRight = dir < 0,
1086 length = array.length,
1087 view = getView(0, length, this.views),
1088 start = view.start,
1089 end = view.end,
1090 dropCount = this.dropCount,
1091 takeCount = nativeMin(end - start, this.takeCount - dropCount),
1092 index = isRight ? end : start - 1,
1093 iteratees = this.iteratees,
1094 iterLength = iteratees ? iteratees.length : 0,
1095 resIndex = 0,
1096 result = [];
1097
1098 outer:
1099 while (length-- && resIndex < takeCount) {
1100 index += dir;
1101
1102 var iterIndex = -1,
1103 value = array[index];
1104
1105 while (++iterIndex < iterLength) {
1106 var data = iteratees[iterIndex],
1107 iteratee = data.iteratee,
1108 computed = iteratee(value, index, array),
1109 type = data.type;
1110
1111 if (type == LAZY_MAP_FLAG) {
1112 value = computed;
1113 } else if (!computed) {
1114 if (type == LAZY_FILTER_FLAG) {
1115 continue outer;
1116 } else {
1117 break outer;
1118 }
1119 }
1120 }
1121 if (dropCount) {
1122 dropCount--;
1123 } else {
1124 result[resIndex++] = value;
1125 }
1126 }
1127 return isRight ? result.reverse() : result;
1128 }
1129
1130 /*------------------------------------------------------------------------*/
1131
1132 /**
1133 * Creates a cache object to store key/value pairs.
1134 *
1135 * @private
1136 * @static
1137 * @name Cache
1138 * @memberOf _.memoize
1139 */
1140 function MapCache() {
1141 this.__data__ = {};
1142 }
1143
1144 /**
1145 * Removes `key` and its value from the cache.
1146 *
1147 * @private
1148 * @name delete
1149 * @memberOf _.memoize.Cache
1150 * @param {string} key The key of the value to remove.
1151 * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
1152 */
1153 function mapDelete(key) {
1154 return this.has(key) && delete this.__data__[key];
1155 }
1156
1157 /**
1158 * Gets the cached value for `key`.
1159 *
1160 * @private
1161 * @name get
1162 * @memberOf _.memoize.Cache
1163 * @param {string} key The key of the value to get.
1164 * @returns {*} Returns the cached value.
1165 */
1166 function mapGet(key) {
1167 return key == '__proto__' ? undefined : this.__data__[key];
1168 }
1169
1170 /**
1171 * Checks if a cached value for `key` exists.
1172 *
1173 * @private
1174 * @name has
1175 * @memberOf _.memoize.Cache
1176 * @param {string} key The key of the entry to check.
1177 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1178 */
1179 function mapHas(key) {
1180 return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
1181 }
1182
1183 /**
1184 * Adds `value` to `key` of the cache.
1185 *
1186 * @private
1187 * @name set
1188 * @memberOf _.memoize.Cache
1189 * @param {string} key The key of the value to cache.
1190 * @param {*} value The value to cache.
1191 * @returns {Object} Returns the cache object.
1192 */
1193 function mapSet(key, value) {
1194 if (key != '__proto__') {
1195 this.__data__[key] = value;
1196 }
1197 return this;
1198 }
1199
1200 /*------------------------------------------------------------------------*/
1201
1202 /**
1203 *
1204 * Creates a cache object to store unique values.
1205 *
1206 * @private
1207 * @param {Array} [values] The values to cache.
1208 */
1209 function SetCache(values) {
1210 var length = values ? values.length : 0;
1211
1212 this.data = { 'hash': nativeCreate(null), 'set': new Set };
1213 while (length--) {
1214 this.push(values[length]);
1215 }
1216 }
1217
1218 /**
1219 * Checks if `value` is in `cache` mimicking the return signature of
1220 * `_.indexOf` by returning `0` if the value is found, else `-1`.
1221 *
1222 * @private
1223 * @param {Object} cache The cache to search.
1224 * @param {*} value The value to search for.
1225 * @returns {number} Returns `0` if `value` is found, else `-1`.
1226 */
1227 function cacheIndexOf(cache, value) {
1228 var data = cache.data,
1229 result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
1230
1231 return result ? 0 : -1;
1232 }
1233
1234 /**
1235 * Adds `value` to the cache.
1236 *
1237 * @private
1238 * @name push
1239 * @memberOf SetCache
1240 * @param {*} value The value to cache.
1241 */
1242 function cachePush(value) {
1243 var data = this.data;
1244 if (typeof value == 'string' || isObject(value)) {
1245 data.set.add(value);
1246 } else {
1247 data.hash[value] = true;
1248 }
1249 }
1250
1251 /*------------------------------------------------------------------------*/
1252
1253 /**
1254 * Copies the values of `source` to `array`.
1255 *
1256 * @private
1257 * @param {Array} source The array to copy values from.
1258 * @param {Array} [array=[]] The array to copy values to.
1259 * @returns {Array} Returns `array`.
1260 */
1261 function arrayCopy(source, array) {
1262 var index = -1,
1263 length = source.length;
1264
1265 array || (array = Array(length));
1266 while (++index < length) {
1267 array[index] = source[index];
1268 }
1269 return array;
1270 }
1271
1272 /**
1273 * A specialized version of `_.forEach` for arrays without support for callback
1274 * shorthands or `this` binding.
1275 *
1276 * @private
1277 * @param {Array} array The array to iterate over.
1278 * @param {Function} iteratee The function invoked per iteration.
1279 * @returns {Array} Returns `array`.
1280 */
1281 function arrayEach(array, iteratee) {
1282 var index = -1,
1283 length = array.length;
1284
1285 while (++index < length) {
1286 if (iteratee(array[index], index, array) === false) {
1287 break;
1288 }
1289 }
1290 return array;
1291 }
1292
1293 /**
1294 * A specialized version of `_.forEachRight` for arrays without support for
1295 * callback shorthands or `this` binding.
1296 *
1297 * @private
1298 * @param {Array} array The array to iterate over.
1299 * @param {Function} iteratee The function invoked per iteration.
1300 * @returns {Array} Returns `array`.
1301 */
1302 function arrayEachRight(array, iteratee) {
1303 var length = array.length;
1304
1305 while (length--) {
1306 if (iteratee(array[length], length, array) === false) {
1307 break;
1308 }
1309 }
1310 return array;
1311 }
1312
1313 /**
1314 * A specialized version of `_.every` for arrays without support for callback
1315 * shorthands or `this` binding.
1316 *
1317 * @private
1318 * @param {Array} array The array to iterate over.
1319 * @param {Function} predicate The function invoked per iteration.
1320 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1321 * else `false`.
1322 */
1323 function arrayEvery(array, predicate) {
1324 var index = -1,
1325 length = array.length;
1326
1327 while (++index < length) {
1328 if (!predicate(array[index], index, array)) {
1329 return false;
1330 }
1331 }
1332 return true;
1333 }
1334
1335 /**
1336 * A specialized version of `_.filter` for arrays without support for callback
1337 * shorthands or `this` binding.
1338 *
1339 * @private
1340 * @param {Array} array The array to iterate over.
1341 * @param {Function} predicate The function invoked per iteration.
1342 * @returns {Array} Returns the new filtered array.
1343 */
1344 function arrayFilter(array, predicate) {
1345 var index = -1,
1346 length = array.length,
1347 resIndex = -1,
1348 result = [];
1349
1350 while (++index < length) {
1351 var value = array[index];
1352 if (predicate(value, index, array)) {
1353 result[++resIndex] = value;
1354 }
1355 }
1356 return result;
1357 }
1358
1359 /**
1360 * A specialized version of `_.map` for arrays without support for callback
1361 * shorthands or `this` binding.
1362 *
1363 * @private
1364 * @param {Array} array The array to iterate over.
1365 * @param {Function} iteratee The function invoked per iteration.
1366 * @returns {Array} Returns the new mapped array.
1367 */
1368 function arrayMap(array, iteratee) {
1369 var index = -1,
1370 length = array.length,
1371 result = Array(length);
1372
1373 while (++index < length) {
1374 result[index] = iteratee(array[index], index, array);
1375 }
1376 return result;
1377 }
1378
1379 /**
1380 * A specialized version of `_.max` for arrays without support for iteratees.
1381 *
1382 * @private
1383 * @param {Array} array The array to iterate over.
1384 * @returns {*} Returns the maximum value.
1385 */
1386 function arrayMax(array) {
1387 var index = -1,
1388 length = array.length,
1389 result = NEGATIVE_INFINITY;
1390
1391 while (++index < length) {
1392 var value = array[index];
1393 if (value > result) {
1394 result = value;
1395 }
1396 }
1397 return result;
1398 }
1399
1400 /**
1401 * A specialized version of `_.min` for arrays without support for iteratees.
1402 *
1403 * @private
1404 * @param {Array} array The array to iterate over.
1405 * @returns {*} Returns the minimum value.
1406 */
1407 function arrayMin(array) {
1408 var index = -1,
1409 length = array.length,
1410 result = POSITIVE_INFINITY;
1411
1412 while (++index < length) {
1413 var value = array[index];
1414 if (value < result) {
1415 result = value;
1416 }
1417 }
1418 return result;
1419 }
1420
1421 /**
1422 * A specialized version of `_.reduce` for arrays without support for callback
1423 * shorthands or `this` binding.
1424 *
1425 * @private
1426 * @param {Array} array The array to iterate over.
1427 * @param {Function} iteratee The function invoked per iteration.
1428 * @param {*} [accumulator] The initial value.
1429 * @param {boolean} [initFromArray] Specify using the first element of `array`
1430 * as the initial value.
1431 * @returns {*} Returns the accumulated value.
1432 */
1433 function arrayReduce(array, iteratee, accumulator, initFromArray) {
1434 var index = -1,
1435 length = array.length;
1436
1437 if (initFromArray && length) {
1438 accumulator = array[++index];
1439 }
1440 while (++index < length) {
1441 accumulator = iteratee(accumulator, array[index], index, array);
1442 }
1443 return accumulator;
1444 }
1445
1446 /**
1447 * A specialized version of `_.reduceRight` for arrays without support for
1448 * callback shorthands or `this` binding.
1449 *
1450 * @private
1451 * @param {Array} array The array to iterate over.
1452 * @param {Function} iteratee The function invoked per iteration.
1453 * @param {*} [accumulator] The initial value.
1454 * @param {boolean} [initFromArray] Specify using the last element of `array`
1455 * as the initial value.
1456 * @returns {*} Returns the accumulated value.
1457 */
1458 function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
1459 var length = array.length;
1460 if (initFromArray && length) {
1461 accumulator = array[--length];
1462 }
1463 while (length--) {
1464 accumulator = iteratee(accumulator, array[length], length, array);
1465 }
1466 return accumulator;
1467 }
1468
1469 /**
1470 * A specialized version of `_.some` for arrays without support for callback
1471 * shorthands or `this` binding.
1472 *
1473 * @private
1474 * @param {Array} array The array to iterate over.
1475 * @param {Function} predicate The function invoked per iteration.
1476 * @returns {boolean} Returns `true` if any element passes the predicate check,
1477 * else `false`.
1478 */
1479 function arraySome(array, predicate) {
1480 var index = -1,
1481 length = array.length;
1482
1483 while (++index < length) {
1484 if (predicate(array[index], index, array)) {
1485 return true;
1486 }
1487 }
1488 return false;
1489 }
1490
1491 /**
1492 * Used by `_.defaults` to customize its `_.assign` use.
1493 *
1494 * @private
1495 * @param {*} objectValue The destination object property value.
1496 * @param {*} sourceValue The source object property value.
1497 * @returns {*} Returns the value to assign to the destination object.
1498 */
1499 function assignDefaults(objectValue, sourceValue) {
1500 return typeof objectValue == 'undefined' ? sourceValue : objectValue;
1501 }
1502
1503 /**
1504 * Used by `_.template` to customize its `_.assign` use.
1505 *
1506 * **Note:** This method is like `assignDefaults` except that it ignores
1507 * inherited property values when checking if a property is `undefined`.
1508 *
1509 * @private
1510 * @param {*} objectValue The destination object property value.
1511 * @param {*} sourceValue The source object property value.
1512 * @param {string} key The key associated with the object and source values.
1513 * @param {Object} object The destination object.
1514 * @returns {*} Returns the value to assign to the destination object.
1515 */
1516 function assignOwnDefaults(objectValue, sourceValue, key, object) {
1517 return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
1518 ? sourceValue
1519 : objectValue;
1520 }
1521
1522 /**
1523 * The base implementation of `_.assign` without support for argument juggling,
1524 * multiple sources, and `this` binding `customizer` functions.
1525 *
1526 * @private
1527 * @param {Object} object The destination object.
1528 * @param {Object} source The source object.
1529 * @param {Function} [customizer] The function to customize assigning values.
1530 * @returns {Object} Returns the destination object.
1531 */
1532 function baseAssign(object, source, customizer) {
1533 var props = keys(source);
1534 if (!customizer) {
1535 return baseCopy(source, object, props);
1536 }
1537 var index = -1,
1538 length = props.length
1539
1540 while (++index < length) {
1541 var key = props[index],
1542 value = object[key],
1543 result = customizer(value, source[key], key, object, source);
1544
1545 if ((result === result ? result !== value : value === value) ||
1546 (typeof value == 'undefined' && !(key in object))) {
1547 object[key] = result;
1548 }
1549 }
1550 return object;
1551 }
1552
1553 /**
1554 * The base implementation of `_.at` without support for strings and individual
1555 * key arguments.
1556 *
1557 * @private
1558 * @param {Array|Object} collection The collection to iterate over.
1559 * @param {number[]|string[]} [props] The property names or indexes of elements to pick.
1560 * @returns {Array} Returns the new array of picked elements.
1561 */
1562 function baseAt(collection, props) {
1563 var index = -1,
1564 length = collection.length,
1565 isArr = isLength(length),
1566 propsLength = props.length,
1567 result = Array(propsLength);
1568
1569 while(++index < propsLength) {
1570 var key = props[index];
1571 if (isArr) {
1572 key = parseFloat(key);
1573 result[index] = isIndex(key, length) ? collection[key] : undefined;
1574 } else {
1575 result[index] = collection[key];
1576 }
1577 }
1578 return result;
1579 }
1580
1581 /**
1582 * Copies the properties of `source` to `object`.
1583 *
1584 * @private
1585 * @param {Object} source The object to copy properties from.
1586 * @param {Object} [object={}] The object to copy properties to.
1587 * @param {Array} props The property names to copy.
1588 * @returns {Object} Returns `object`.
1589 */
1590 function baseCopy(source, object, props) {
1591 if (!props) {
1592 props = object;
1593 object = {};
1594 }
1595 var index = -1,
1596 length = props.length;
1597
1598 while (++index < length) {
1599 var key = props[index];
1600 object[key] = source[key];
1601 }
1602 return object;
1603 }
1604
1605 /**
1606 * The base implementation of `_.bindAll` without support for individual
1607 * method name arguments.
1608 *
1609 * @private
1610 * @param {Object} object The object to bind and assign the bound methods to.
1611 * @param {string[]} methodNames The object method names to bind.
1612 * @returns {Object} Returns `object`.
1613 */
1614 function baseBindAll(object, methodNames) {
1615 var index = -1,
1616 length = methodNames.length;
1617
1618 while (++index < length) {
1619 var key = methodNames[index];
1620 object[key] = createWrapper(object[key], BIND_FLAG, object);
1621 }
1622 return object;
1623 }
1624
1625 /**
1626 * The base implementation of `_.callback` which supports specifying the
1627 * number of arguments to provide to `func`.
1628 *
1629 * @private
1630 * @param {*} [func=_.identity] The value to convert to a callback.
1631 * @param {*} [thisArg] The `this` binding of `func`.
1632 * @param {number} [argCount] The number of arguments to provide to `func`.
1633 * @returns {Function} Returns the callback.
1634 */
1635 function baseCallback(func, thisArg, argCount) {
1636 var type = typeof func;
1637 if (type == 'function') {
1638 return (typeof thisArg != 'undefined' && isBindable(func))
1639 ? bindCallback(func, thisArg, argCount)
1640 : func;
1641 }
1642 if (func == null) {
1643 return identity;
1644 }
1645 // Handle "_.property" and "_.matches" style callback shorthands.
1646 return type == 'object'
1647 ? baseMatches(func, !argCount)
1648 : baseProperty(argCount ? baseToString(func) : func);
1649 }
1650
1651 /**
1652 * The base implementation of `_.clone` without support for argument juggling
1653 * and `this` binding `customizer` functions.
1654 *
1655 * @private
1656 * @param {*} value The value to clone.
1657 * @param {boolean} [isDeep] Specify a deep clone.
1658 * @param {Function} [customizer] The function to customize cloning values.
1659 * @param {string} [key] The key of `value`.
1660 * @param {Object} [object] The object `value` belongs to.
1661 * @param {Array} [stackA=[]] Tracks traversed source objects.
1662 * @param {Array} [stackB=[]] Associates clones with source counterparts.
1663 * @returns {*} Returns the cloned value.
1664 */
1665 function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
1666 var result;
1667 if (customizer) {
1668 result = object ? customizer(value, key, object) : customizer(value);
1669 }
1670 if (typeof result != 'undefined') {
1671 return result;
1672 }
1673 if (!isObject(value)) {
1674 return value;
1675 }
1676 var isArr = isArray(value);
1677 if (isArr) {
1678 result = initCloneArray(value);
1679 if (!isDeep) {
1680 return arrayCopy(value, result);
1681 }
1682 } else {
1683 var tag = objToString.call(value),
1684 isFunc = tag == funcTag;
1685
1686 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
1687 result = initCloneObject(isFunc ? {} : value);
1688 if (!isDeep) {
1689 return baseCopy(value, result, keys(value));
1690 }
1691 } else {
1692 return cloneableTags[tag]
1693 ? initCloneByTag(value, tag, isDeep)
1694 : (object ? value : {});
1695 }
1696 }
1697 // Check for circular references and return corresponding clone.
1698 stackA || (stackA = []);
1699 stackB || (stackB = []);
1700
1701 var length = stackA.length;
1702 while (length--) {
1703 if (stackA[length] == value) {
1704 return stackB[length];
1705 }
1706 }
1707 // Add the source value to the stack of traversed objects and associate it with its clone.
1708 stackA.push(value);
1709 stackB.push(result);
1710
1711 // Recursively populate clone (susceptible to call stack limits).
1712 (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
1713 result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
1714 });
1715 return result;
1716 }
1717
1718 /**
1719 * The base implementation of `_.create` without support for assigning
1720 * properties to the created object.
1721 *
1722 * @private
1723 * @param {Object} prototype The object to inherit from.
1724 * @returns {Object} Returns the new object.
1725 */
1726 var baseCreate = (function() {
1727 function Object() {}
1728 return function(prototype) {
1729 if (isObject(prototype)) {
1730 Object.prototype = prototype;
1731 var result = new Object;
1732 Object.prototype = null;
1733 }
1734 return result || context.Object();
1735 };
1736 }());
1737
1738 /**
1739 * The base implementation of `_.delay` and `_.defer` which accepts an index
1740 * of where to slice the arguments to provide to `func`.
1741 *
1742 * @private
1743 * @param {Function} func The function to delay.
1744 * @param {number} wait The number of milliseconds to delay invocation.
1745 * @param {Object} args The `arguments` object to slice and provide to `func`.
1746 * @returns {number} Returns the timer id.
1747 */
1748 function baseDelay(func, wait, args, fromIndex) {
1749 if (!isFunction(func)) {
1750 throw new TypeError(FUNC_ERROR_TEXT);
1751 }
1752 return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
1753 }
1754
1755 /**
1756 * The base implementation of `_.difference` which accepts a single array
1757 * of values to exclude.
1758 *
1759 * @private
1760 * @param {Array} array The array to inspect.
1761 * @param {Array} values The values to exclude.
1762 * @returns {Array} Returns the new array of filtered values.
1763 */
1764 function baseDifference(array, values) {
1765 var length = array ? array.length : 0,
1766 result = [];
1767
1768 if (!length) {
1769 return result;
1770 }
1771 var index = -1,
1772 indexOf = getIndexOf(),
1773 isCommon = indexOf == baseIndexOf,
1774 cache = isCommon && values.length >= 200 && createCache(values),
1775 valuesLength = values.length;
1776
1777 if (cache) {
1778 indexOf = cacheIndexOf;
1779 isCommon = false;
1780 values = cache;
1781 }
1782 outer:
1783 while (++index < length) {
1784 var value = array[index];
1785
1786 if (isCommon && value === value) {
1787 var valuesIndex = valuesLength;
1788 while (valuesIndex--) {
1789 if (values[valuesIndex] === value) {
1790 continue outer;
1791 }
1792 }
1793 result.push(value);
1794 }
1795 else if (indexOf(values, value) < 0) {
1796 result.push(value);
1797 }
1798 }
1799 return result;
1800 }
1801
1802 /**
1803 * The base implementation of `_.forEach` without support for callback
1804 * shorthands and `this` binding.
1805 *
1806 * @private
1807 * @param {Array|Object|string} collection The collection to iterate over.
1808 * @param {Function} iteratee The function invoked per iteration.
1809 * @returns {Array|Object|string} Returns `collection`.
1810 */
1811 function baseEach(collection, iteratee) {
1812 var length = collection ? collection.length : 0;
1813 if (!isLength(length)) {
1814 return baseForOwn(collection, iteratee);
1815 }
1816 var index = -1,
1817 iterable = toObject(collection);
1818
1819 while (++index < length) {
1820 if (iteratee(iterable[index], index, iterable) === false) {
1821 break;
1822 }
1823 }
1824 return collection;
1825 }
1826
1827 /**
1828 * The base implementation of `_.forEachRight` without support for callback
1829 * shorthands and `this` binding.
1830 *
1831 * @private
1832 * @param {Array|Object|string} collection The collection to iterate over.
1833 * @param {Function} iteratee The function invoked per iteration.
1834 * @returns {Array|Object|string} Returns `collection`.
1835 */
1836 function baseEachRight(collection, iteratee) {
1837 var length = collection ? collection.length : 0;
1838 if (!isLength(length)) {
1839 return baseForOwnRight(collection, iteratee);
1840 }
1841 var iterable = toObject(collection);
1842 while (length--) {
1843 if (iteratee(iterable[length], length, iterable) === false) {
1844 break;
1845 }
1846 }
1847 return collection;
1848 }
1849
1850 /**
1851 * The base implementation of `_.every` without support for callback
1852 * shorthands or `this` binding.
1853 *
1854 * @private
1855 * @param {Array|Object|string} collection The collection to iterate over.
1856 * @param {Function} predicate The function invoked per iteration.
1857 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1858 * else `false`
1859 */
1860 function baseEvery(collection, predicate) {
1861 var result = true;
1862 baseEach(collection, function(value, index, collection) {
1863 result = !!predicate(value, index, collection);
1864 return result;
1865 });
1866 return result;
1867 }
1868
1869 /**
1870 * The base implementation of `_.filter` without support for callback
1871 * shorthands or `this` binding.
1872 *
1873 * @private
1874 * @param {Array|Object|string} collection The collection to iterate over.
1875 * @param {Function} predicate The function invoked per iteration.
1876 * @returns {Array} Returns the new filtered array.
1877 */
1878 function baseFilter(collection, predicate) {
1879 var result = [];
1880 baseEach(collection, function(value, index, collection) {
1881 if (predicate(value, index, collection)) {
1882 result.push(value);
1883 }
1884 });
1885 return result;
1886 }
1887
1888 /**
1889 * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
1890 * without support for callback shorthands and `this` binding, which iterates
1891 * over `collection` using the provided `eachFunc`.
1892 *
1893 * @private
1894 * @param {Array|Object|string} collection The collection to search.
1895 * @param {Function} predicate The function invoked per iteration.
1896 * @param {Function} eachFunc The function to iterate over `collection`.
1897 * @param {boolean} [retKey] Specify returning the key of the found element
1898 * instead of the element itself.
1899 * @returns {*} Returns the found element or its key, else `undefined`.
1900 */
1901 function baseFind(collection, predicate, eachFunc, retKey) {
1902 var result;
1903 eachFunc(collection, function(value, key, collection) {
1904 if (predicate(value, key, collection)) {
1905 result = retKey ? key : value;
1906 return false;
1907 }
1908 });
1909 return result;
1910 }
1911
1912 /**
1913 * The base implementation of `_.flatten` with added support for restricting
1914 * flattening and specifying the start index.
1915 *
1916 * @private
1917 * @param {Array} array The array to flatten.
1918 * @param {boolean} [isDeep] Specify a deep flatten.
1919 * @param {boolean} [isStrict] Restrict flattening to arrays and `arguments` objects.
1920 * @param {number} [fromIndex=0] The index to start from.
1921 * @returns {Array} Returns the new flattened array.
1922 */
1923 function baseFlatten(array, isDeep, isStrict, fromIndex) {
1924 var index = (fromIndex || 0) - 1,
1925 length = array.length,
1926 resIndex = -1,
1927 result = [];
1928
1929 while (++index < length) {
1930 var value = array[index];
1931
1932 if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
1933 if (isDeep) {
1934 // Recursively flatten arrays (susceptible to call stack limits).
1935 value = baseFlatten(value, isDeep, isStrict);
1936 }
1937 var valIndex = -1,
1938 valLength = value.length;
1939
1940 result.length += valLength;
1941 while (++valIndex < valLength) {
1942 result[++resIndex] = value[valIndex];
1943 }
1944 } else if (!isStrict) {
1945 result[++resIndex] = value;
1946 }
1947 }
1948 return result;
1949 }
1950
1951 /**
1952 * The base implementation of `baseForIn` and `baseForOwn` which iterates
1953 * over `object` properties returned by `keysFunc` invoking `iteratee` for
1954 * each property. Iterator functions may exit iteration early by explicitly
1955 * returning `false`.
1956 *
1957 * @private
1958 * @param {Object} object The object to iterate over.
1959 * @param {Function} iteratee The function invoked per iteration.
1960 * @param {Function} keysFunc The function to get the keys of `object`.
1961 * @returns {Object} Returns `object`.
1962 */
1963 function baseFor(object, iteratee, keysFunc) {
1964 var index = -1,
1965 iterable = toObject(object),
1966 props = keysFunc(object),
1967 length = props.length;
1968
1969 while (++index < length) {
1970 var key = props[index];
1971 if (iteratee(iterable[key], key, iterable) === false) {
1972 break;
1973 }
1974 }
1975 return object;
1976 }
1977
1978 /**
1979 * This function is like `baseFor` except that it iterates over properties
1980 * in the opposite order.
1981 *
1982 * @private
1983 * @param {Object} object The object to iterate over.
1984 * @param {Function} iteratee The function invoked per iteration.
1985 * @param {Function} keysFunc The function to get the keys of `object`.
1986 * @returns {Object} Returns `object`.
1987 */
1988 function baseForRight(object, iteratee, keysFunc) {
1989 var iterable = toObject(object),
1990 props = keysFunc(object),
1991 length = props.length;
1992
1993 while (length--) {
1994 var key = props[length];
1995 if (iteratee(iterable[key], key, iterable) === false) {
1996 break;
1997 }
1998 }
1999 return object;
2000 }
2001
2002 /**
2003 * The base implementation of `_.forIn` without support for callback
2004 * shorthands and `this` binding.
2005 *
2006 * @private
2007 * @param {Object} object The object to iterate over.
2008 * @param {Function} iteratee The function invoked per iteration.
2009 * @returns {Object} Returns `object`.
2010 */
2011 function baseForIn(object, iteratee) {
2012 return baseFor(object, iteratee, keysIn);
2013 }
2014
2015 /**
2016 * The base implementation of `_.forOwn` without support for callback
2017 * shorthands and `this` binding.
2018 *
2019 * @private
2020 * @param {Object} object The object to iterate over.
2021 * @param {Function} iteratee The function invoked per iteration.
2022 * @returns {Object} Returns `object`.
2023 */
2024 function baseForOwn(object, iteratee) {
2025 return baseFor(object, iteratee, keys);
2026 }
2027
2028 /**
2029 * The base implementation of `_.forOwnRight` without support for callback
2030 * shorthands and `this` binding.
2031 *
2032 * @private
2033 * @param {Object} object The object to iterate over.
2034 * @param {Function} iteratee The function invoked per iteration.
2035 * @returns {Object} Returns `object`.
2036 */
2037 function baseForOwnRight(object, iteratee) {
2038 return baseForRight(object, iteratee, keys);
2039 }
2040
2041 /**
2042 * The base implementation of `_.functions` which creates an array of
2043 * `object` function property names filtered from those provided.
2044 *
2045 * @private
2046 * @param {Object} object The object to inspect.
2047 * @param {Array} props The property names to filter.
2048 * @returns {Array} Returns the new array of filtered property names.
2049 */
2050 function baseFunctions(object, props) {
2051 var index = -1,
2052 length = props.length,
2053 resIndex = -1,
2054 result = [];
2055
2056 while (++index < length) {
2057 var key = props[index];
2058 if (isFunction(object[key])) {
2059 result[++resIndex] = key;
2060 }
2061 }
2062 return result;
2063 }
2064
2065 /**
2066 * The base implementation of `_.invoke` which requires additional arguments
2067 * to be provided as an array of arguments rather than individually.
2068 *
2069 * @private
2070 * @param {Array|Object|string} collection The collection to iterate over.
2071 * @param {Function|string} methodName The name of the method to invoke or
2072 * the function invoked per iteration.
2073 * @param {Array} [args] The arguments to invoke the method with.
2074 * @returns {Array} Returns the array of results.
2075 */
2076 function baseInvoke(collection, methodName, args) {
2077 var index = -1,
2078 isFunc = typeof methodName == 'function',
2079 length = collection ? collection.length : 0,
2080 result = isLength(length) ? Array(length) : [];
2081
2082 baseEach(collection, function(value) {
2083 var func = isFunc ? methodName : (value != null && value[methodName]);
2084 result[++index] = func ? func.apply(value, args) : undefined;
2085 });
2086 return result;
2087 }
2088
2089 /**
2090 * The base implementation of `_.isEqual` without support for `this` binding
2091 * `customizer` functions.
2092 *
2093 * @private
2094 * @param {*} value The value to compare.
2095 * @param {*} other The other value to compare.
2096 * @param {Function} [customizer] The function to customize comparing values.
2097 * @param {boolean} [isWhere] Specify performing partial comparisons.
2098 * @param {Array} [stackA] Tracks traversed `value` objects.
2099 * @param {Array} [stackB] Tracks traversed `other` objects.
2100 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2101 */
2102 function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) {
2103 // Exit early for identical values.
2104 if (value === other) {
2105 // Treat `+0` vs. `-0` as not equal.
2106 return value !== 0 || (1 / value == 1 / other);
2107 }
2108 var valType = typeof value,
2109 othType = typeof other;
2110
2111 // Exit early for unlike primitive values.
2112 if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') ||
2113 value == null || other == null) {
2114 // Return `false` unless both values are `NaN`.
2115 return value !== value && other !== other;
2116 }
2117 return baseIsEqualDeep(value, other, baseIsEqual, customizer, isWhere, stackA, stackB);
2118 }
2119
2120 /**
2121 * A specialized version of `baseIsEqual` for arrays and objects which performs
2122 * deep comparisons and tracks traversed objects enabling objects with circular
2123 * references to be compared.
2124 *
2125 * @private
2126 * @param {Object} object The object to compare.
2127 * @param {Object} other The other object to compare.
2128 * @param {Function} equalFunc The function to determine equivalents of values.
2129 * @param {Function} [customizer] The function to customize comparing objects.
2130 * @param {boolean} [isWhere] Specify performing partial comparisons.
2131 * @param {Array} [stackA=[]] Tracks traversed `value` objects.
2132 * @param {Array} [stackB=[]] Tracks traversed `other` objects.
2133 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2134 */
2135 function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stackA, stackB) {
2136 var objIsArr = isArray(object),
2137 othIsArr = isArray(other),
2138 objTag = arrayTag,
2139 othTag = arrayTag;
2140
2141 if (!objIsArr) {
2142 objTag = objToString.call(object);
2143 if (objTag == argsTag) {
2144 objTag = objectTag;
2145 } else if (objTag != objectTag) {
2146 objIsArr = isTypedArray(object);
2147 }
2148 }
2149 if (!othIsArr) {
2150 othTag = objToString.call(other);
2151 if (othTag == argsTag) {
2152 othTag = objectTag;
2153 } else if (othTag != objectTag) {
2154 othIsArr = isTypedArray(other);
2155 }
2156 }
2157 var objIsObj = objTag == objectTag,
2158 othIsObj = othTag == objectTag,
2159 isSameTag = objTag == othTag;
2160
2161 if (isSameTag && !(objIsArr || objIsObj)) {
2162 return equalByTag(object, other, objTag);
2163 }
2164 var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2165 othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2166
2167 if (valWrapped || othWrapped) {
2168 return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isWhere, stackA, stackB);
2169 }
2170 if (!isSameTag) {
2171 return false;
2172 }
2173 // Assume cyclic values are equal.
2174 // For more information on detecting circular references see https://es5.github.io/#JO.
2175 stackA || (stackA = []);
2176 stackB || (stackB = []);
2177
2178 var length = stackA.length;
2179 while (length--) {
2180 if (stackA[length] == object) {
2181 return stackB[length] == other;
2182 }
2183 }
2184 // Add `object` and `other` to the stack of traversed objects.
2185 stackA.push(object);
2186 stackB.push(other);
2187
2188 var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isWhere, stackA, stackB);
2189
2190 stackA.pop();
2191 stackB.pop();
2192
2193 return result;
2194 }
2195
2196 /**
2197 * The base implementation of `_.isMatch` without support for callback
2198 * shorthands or `this` binding.
2199 *
2200 * @private
2201 * @param {Object} source The object to inspect.
2202 * @param {Array} props The source property names to match.
2203 * @param {Array} values The source values to match.
2204 * @param {Array} strictCompareFlags Strict comparison flags for source values.
2205 * @param {Function} [customizer] The function to customize comparing objects.
2206 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2207 */
2208 function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
2209 var length = props.length;
2210 if (object == null) {
2211 return !length;
2212 }
2213 var index = -1,
2214 noCustomizer = !customizer;
2215
2216 while (++index < length) {
2217 if ((noCustomizer && strictCompareFlags[index])
2218 ? values[index] !== object[props[index]]
2219 : !hasOwnProperty.call(object, props[index])
2220 ) {
2221 return false;
2222 }
2223 }
2224 index = -1;
2225 while (++index < length) {
2226 var key = props[index];
2227 if (noCustomizer && strictCompareFlags[index]) {
2228 var result = hasOwnProperty.call(object, key);
2229 } else {
2230 var objValue = object[key],
2231 srcValue = values[index];
2232
2233 result = customizer ? customizer(objValue, srcValue, key) : undefined;
2234 if (typeof result == 'undefined') {
2235 result = baseIsEqual(srcValue, objValue, customizer, true);
2236 }
2237 }
2238 if (!result) {
2239 return false;
2240 }
2241 }
2242 return true;
2243 }
2244
2245 /**
2246 * The base implementation of `_.map` without support for callback shorthands
2247 * or `this` binding.
2248 *
2249 * @private
2250 * @param {Array|Object|string} collection The collection to iterate over.
2251 * @param {Function} iteratee The function invoked per iteration.
2252 * @returns {Array} Returns the new mapped array.
2253 */
2254 function baseMap(collection, iteratee) {
2255 var result = [];
2256 baseEach(collection, function(value, key, collection) {
2257 result.push(iteratee(value, key, collection));
2258 });
2259 return result;
2260 }
2261
2262 /**
2263 * The base implementation of `_.matches` which supports specifying whether
2264 * `source` should be cloned.
2265 *
2266 * @private
2267 * @param {Object} source The object of property values to match.
2268 * @param {boolean} [isCloned] Specify cloning the source object.
2269 * @returns {Function} Returns the new function.
2270 */
2271 function baseMatches(source, isCloned) {
2272 var props = keys(source),
2273 length = props.length;
2274
2275 if (length == 1) {
2276 var key = props[0],
2277 value = source[key];
2278
2279 if (isStrictComparable(value)) {
2280 return function(object) {
2281 return object != null && value === object[key] && hasOwnProperty.call(object, key);
2282 };
2283 }
2284 }
2285 if (isCloned) {
2286 source = baseClone(source, true);
2287 }
2288 var values = Array(length),
2289 strictCompareFlags = Array(length);
2290
2291 while (length--) {
2292 value = source[props[length]];
2293 values[length] = value;
2294 strictCompareFlags[length] = isStrictComparable(value);
2295 }
2296 return function(object) {
2297 return baseIsMatch(object, props, values, strictCompareFlags);
2298 };
2299 }
2300
2301 /**
2302 * The base implementation of `_.merge` without support for argument juggling,
2303 * multiple sources, and `this` binding `customizer` functions.
2304 *
2305 * @private
2306 * @param {Object} object The destination object.
2307 * @param {Object} source The source object.
2308 * @param {Function} [customizer] The function to customize merging properties.
2309 * @param {Array} [stackA=[]] Tracks traversed source objects.
2310 * @param {Array} [stackB=[]] Associates values with source counterparts.
2311 * @returns {Object} Returns the destination object.
2312 */
2313 function baseMerge(object, source, customizer, stackA, stackB) {
2314 var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
2315
2316 (isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
2317 if (isObjectLike(srcValue)) {
2318 stackA || (stackA = []);
2319 stackB || (stackB = []);
2320 return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
2321 }
2322 var value = object[key],
2323 result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
2324 isCommon = typeof result == 'undefined';
2325
2326 if (isCommon) {
2327 result = srcValue;
2328 }
2329 if ((isSrcArr || typeof result != 'undefined') &&
2330 (isCommon || (result === result ? result !== value : value === value))) {
2331 object[key] = result;
2332 }
2333 });
2334 return object;
2335 }
2336
2337 /**
2338 * A specialized version of `baseMerge` for arrays and objects which performs
2339 * deep merges and tracks traversed objects enabling objects with circular
2340 * references to be merged.
2341 *
2342 * @private
2343 * @param {Object} object The destination object.
2344 * @param {Object} source The source object.
2345 * @param {string} key The key of the value to merge.
2346 * @param {Function} mergeFunc The function to merge values.
2347 * @param {Function} [customizer] The function to customize merging properties.
2348 * @param {Array} [stackA=[]] Tracks traversed source objects.
2349 * @param {Array} [stackB=[]] Associates values with source counterparts.
2350 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2351 */
2352 function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
2353 var length = stackA.length,
2354 srcValue = source[key];
2355
2356 while (length--) {
2357 if (stackA[length] == srcValue) {
2358 object[key] = stackB[length];
2359 return;
2360 }
2361 }
2362 var value = object[key],
2363 result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
2364 isCommon = typeof result == 'undefined';
2365
2366 if (isCommon) {
2367 result = srcValue;
2368 if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
2369 result = isArray(value)
2370 ? value
2371 : (value ? arrayCopy(value) : []);
2372 }
2373 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
2374 result = isArguments(value)
2375 ? toPlainObject(value)
2376 : (isPlainObject(value) ? value : {});
2377 }
2378 }
2379 // Add the source value to the stack of traversed objects and associate
2380 // it with its merged value.
2381 stackA.push(srcValue);
2382 stackB.push(result);
2383
2384 if (isCommon) {
2385 // Recursively merge objects and arrays (susceptible to call stack limits).
2386 object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
2387 } else if (result === result ? result !== value : value === value) {
2388 object[key] = result;
2389 }
2390 }
2391
2392 /**
2393 * The base implementation of `_.property` which does not coerce `key` to a string.
2394 *
2395 * @private
2396 * @param {string} key The key of the property to get.
2397 * @returns {Function} Returns the new function.
2398 */
2399 function baseProperty(key) {
2400 return function(object) {
2401 return object == null ? undefined : object[key];
2402 };
2403 }
2404
2405 /**
2406 * The base implementation of `_.pullAt` without support for individual
2407 * index arguments.
2408 *
2409 * @private
2410 * @param {Array} array The array to modify.
2411 * @param {number[]} indexes The indexes of elements to remove.
2412 * @returns {Array} Returns the new array of removed elements.
2413 */
2414 function basePullAt(array, indexes) {
2415 var length = indexes.length,
2416 result = baseAt(array, indexes);
2417
2418 indexes.sort(baseCompareAscending);
2419 while (length--) {
2420 var index = parseFloat(indexes[length]);
2421 if (index != previous && isIndex(index)) {
2422 var previous = index;
2423 splice.call(array, index, 1);
2424 }
2425 }
2426 return result;
2427 }
2428
2429 /**
2430 * The base implementation of `_.random` without support for argument juggling
2431 * and returning floating-point numbers.
2432 *
2433 * @private
2434 * @param {number} min The minimum possible value.
2435 * @param {number} max The maximum possible value.
2436 * @returns {number} Returns the random number.
2437 */
2438 function baseRandom(min, max) {
2439 return min + floor(nativeRandom() * (max - min + 1));
2440 }
2441
2442 /**
2443 * The base implementation of `_.reduce` and `_.reduceRight` without support
2444 * for callback shorthands or `this` binding, which iterates over `collection`
2445 * using the provided `eachFunc`.
2446 *
2447 * @private
2448 * @param {Array|Object|string} collection The collection to iterate over.
2449 * @param {Function} iteratee The function invoked per iteration.
2450 * @param {*} accumulator The initial value.
2451 * @param {boolean} initFromCollection Specify using the first or last element
2452 * of `collection` as the initial value.
2453 * @param {Function} eachFunc The function to iterate over `collection`.
2454 * @returns {*} Returns the accumulated value.
2455 */
2456 function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
2457 eachFunc(collection, function(value, index, collection) {
2458 accumulator = initFromCollection
2459 ? (initFromCollection = false, value)
2460 : iteratee(accumulator, value, index, collection)
2461 });
2462 return accumulator;
2463 }
2464
2465 /**
2466 * The base implementation of `setData` without support for hot loop detection.
2467 *
2468 * @private
2469 * @param {Function} func The function to associate metadata with.
2470 * @param {*} data The metadata.
2471 * @returns {Function} Returns `func`.
2472 */
2473 var baseSetData = !metaMap ? identity : function(func, data) {
2474 metaMap.set(func, data);
2475 return func;
2476 };
2477
2478 /**
2479 * The base implementation of `_.slice` without an iteratee call guard.
2480 *
2481 * @private
2482 * @param {Array} array The array to slice.
2483 * @param {number} [start=0] The start position.
2484 * @param {number} [end=array.length] The end position.
2485 * @returns {Array} Returns the slice of `array`.
2486 */
2487 function baseSlice(array, start, end) {
2488 var index = -1,
2489 length = array.length;
2490
2491 start = start == null ? 0 : (+start || 0);
2492 if (start < 0) {
2493 start = -start > length ? 0 : (length + start);
2494 }
2495 end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
2496 if (end < 0) {
2497 end += length;
2498 }
2499 length = start > end ? 0 : (end - start);
2500
2501 var result = Array(length);
2502 while (++index < length) {
2503 result[index] = array[index + start];
2504 }
2505 return result;
2506 }
2507
2508 /**
2509 * The base implementation of `_.some` without support for callback shorthands
2510 * or `this` binding.
2511 *
2512 * @private
2513 * @param {Array|Object|string} collection The collection to iterate over.
2514 * @param {Function} predicate The function invoked per iteration.
2515 * @returns {boolean} Returns `true` if any element passes the predicate check,
2516 * else `false`.
2517 */
2518 function baseSome(collection, predicate) {
2519 var result;
2520
2521 baseEach(collection, function(value, index, collection) {
2522 result = predicate(value, index, collection);
2523 return !result;
2524 });
2525 return !!result;
2526 }
2527
2528 /**
2529 * The base implementation of `_.uniq` without support for callback shorthands
2530 * and `this` binding.
2531 *
2532 * @private
2533 * @param {Array} array The array to inspect.
2534 * @param {Function} [iteratee] The function invoked per iteration.
2535 * @returns {Array} Returns the new duplicate-value-free array.
2536 */
2537 function baseUniq(array, iteratee) {
2538 var index = -1,
2539 indexOf = getIndexOf(),
2540 length = array.length,
2541 isCommon = indexOf == baseIndexOf,
2542 isLarge = isCommon && length >= 200,
2543 seen = isLarge && createCache(),
2544 result = [];
2545
2546 if (seen) {
2547 indexOf = cacheIndexOf;
2548 isCommon = false;
2549 } else {
2550 isLarge = false;
2551 seen = iteratee ? [] : result;
2552 }
2553 outer:
2554 while (++index < length) {
2555 var value = array[index],
2556 computed = iteratee ? iteratee(value, index, array) : value;
2557
2558 if (isCommon && value === value) {
2559 var seenIndex = seen.length;
2560 while (seenIndex--) {
2561 if (seen[seenIndex] === computed) {
2562 continue outer;
2563 }
2564 }
2565 if (iteratee) {
2566 seen.push(computed);
2567 }
2568 result.push(value);
2569 }
2570 else if (indexOf(seen, computed) < 0) {
2571 if (iteratee || isLarge) {
2572 seen.push(computed);
2573 }
2574 result.push(value);
2575 }
2576 }
2577 return result;
2578 }
2579
2580 /**
2581 * The base implementation of `_.values` and `_.valuesIn` which creates an
2582 * array of `object` property values corresponding to the property names
2583 * returned by `keysFunc`.
2584 *
2585 * @private
2586 * @param {Object} object The object to query.
2587 * @param {Array} props The property names to get values for.
2588 * @returns {Object} Returns the array of property values.
2589 */
2590 function baseValues(object, props) {
2591 var index = -1,
2592 length = props.length,
2593 result = Array(length);
2594
2595 while (++index < length) {
2596 result[index] = object[props[index]];
2597 }
2598 return result;
2599 }
2600
2601 /**
2602 * The base implementation of `wrapperValue` which returns the result of
2603 * performing a sequence of actions on the unwrapped `value`, where each
2604 * successive action is supplied the return value of the previous.
2605 *
2606 * @private
2607 * @param {*} value The unwrapped value.
2608 * @param {Array} actions Actions to peform to resolve the unwrapped value.
2609 * @returns {*} Returns the resolved unwrapped value.
2610 */
2611 function baseWrapperValue(value, actions) {
2612 var result = value;
2613 if (result instanceof LazyWrapper) {
2614 result = result.value();
2615 }
2616 var index = -1,
2617 length = actions.length;
2618
2619 while (++index < length) {
2620 var args = [result],
2621 action = actions[index];
2622
2623 push.apply(args, action.args);
2624 result = action.func.apply(action.thisArg, args);
2625 }
2626 return result;
2627 }
2628
2629 /**
2630 * Performs a binary search of `array` to determine the index at which `value`
2631 * should be inserted into `array` in order to maintain its sort order.
2632 *
2633 * @private
2634 * @param {Array} array The sorted array to inspect.
2635 * @param {*} value The value to evaluate.
2636 * @param {boolean} [retHighest] Specify returning the highest, instead
2637 * of the lowest, index at which a value should be inserted into `array`.
2638 * @returns {number} Returns the index at which `value` should be inserted
2639 * into `array`.
2640 */
2641 function binaryIndex(array, value, retHighest) {
2642 var low = 0,
2643 high = array ? array.length : low;
2644
2645 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
2646 while (low < high) {
2647 var mid = (low + high) >>> 1,
2648 computed = array[mid];
2649
2650 if (retHighest ? (computed <= value) : (computed < value)) {
2651 low = mid + 1;
2652 } else {
2653 high = mid;
2654 }
2655 }
2656 return high;
2657 }
2658 return binaryIndexBy(array, value, identity, retHighest);
2659 }
2660
2661 /**
2662 * This function is like `binaryIndex` except that it invokes `iteratee` for
2663 * `value` and each element of `array` to compute their sort ranking. The
2664 * iteratee is invoked with one argument; (value).
2665 *
2666 * @private
2667 * @param {Array} array The sorted array to inspect.
2668 * @param {*} value The value to evaluate.
2669 * @param {Function} iteratee The function invoked per iteration.
2670 * @param {boolean} [retHighest] Specify returning the highest, instead
2671 * of the lowest, index at which a value should be inserted into `array`.
2672 * @returns {number} Returns the index at which `value` should be inserted
2673 * into `array`.
2674 */
2675 function binaryIndexBy(array, value, iteratee, retHighest) {
2676 value = iteratee(value);
2677
2678 var low = 0,
2679 high = array ? array.length : 0,
2680 valIsNaN = value !== value,
2681 valIsUndef = typeof value == 'undefined';
2682
2683 while (low < high) {
2684 var mid = floor((low + high) / 2),
2685 computed = iteratee(array[mid]),
2686 isReflexive = computed === computed;
2687
2688 if (valIsNaN) {
2689 var setLow = isReflexive || retHighest;
2690 } else if (valIsUndef) {
2691 setLow = isReflexive && (retHighest || typeof computed != 'undefined');
2692 } else {
2693 setLow = retHighest ? (computed <= value) : (computed < value);
2694 }
2695 if (setLow) {
2696 low = mid + 1;
2697 } else {
2698 high = mid;
2699 }
2700 }
2701 return nativeMin(high, MAX_ARRAY_INDEX);
2702 }
2703
2704 /**
2705 * A specialized version of `baseCallback` which only supports `this` binding
2706 * and specifying the number of arguments to provide to `func`.
2707 *
2708 * @private
2709 * @param {Function} func The function to bind.
2710 * @param {*} thisArg The `this` binding of `func`.
2711 * @param {number} [argCount] The number of arguments to provide to `func`.
2712 * @returns {Function} Returns the callback.
2713 */
2714 function bindCallback(func, thisArg, argCount) {
2715 if (typeof func != 'function') {
2716 return identity;
2717 }
2718 if (typeof thisArg == 'undefined') {
2719 return func;
2720 }
2721 switch (argCount) {
2722 case 1: return function(value) {
2723 return func.call(thisArg, value);
2724 };
2725 case 3: return function(value, index, collection) {
2726 return func.call(thisArg, value, index, collection);
2727 };
2728 case 4: return function(accumulator, value, index, collection) {
2729 return func.call(thisArg, accumulator, value, index, collection);
2730 };
2731 case 5: return function(value, other, key, object, source) {
2732 return func.call(thisArg, value, other, key, object, source);
2733 };
2734 }
2735 return function() {
2736 return func.apply(thisArg, arguments);
2737 };
2738 }
2739
2740 /**
2741 * Creates a clone of the given array buffer.
2742 *
2743 * @private
2744 * @param {ArrayBuffer} buffer The array buffer to clone.
2745 * @returns {ArrayBuffer} Returns the cloned array buffer.
2746 */
2747 function bufferClone(buffer) {
2748 return bufferSlice.call(buffer, 0);
2749 }
2750 if (!bufferSlice) {
2751 // PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array`.
2752 bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buffer) {
2753 var byteLength = buffer.byteLength,
2754 floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0,
2755 offset = floatLength * FLOAT64_BYTES_PER_ELEMENT,
2756 result = new ArrayBuffer(byteLength);
2757
2758 if (floatLength) {
2759 var view = new Float64Array(result, 0, floatLength);
2760 view.set(new Float64Array(buffer, 0, floatLength));
2761 }
2762 if (byteLength != offset) {
2763 view = new Uint8Array(result, offset);
2764 view.set(new Uint8Array(buffer, offset));
2765 }
2766 return result;
2767 };
2768 }
2769
2770 /**
2771 * Creates an array that is the composition of partially applied arguments,
2772 * placeholders, and provided arguments into a single array of arguments.
2773 *
2774 * @private
2775 * @param {Array|Object} args The provided arguments.
2776 * @param {Array} partials The arguments to prepend to those provided.
2777 * @param {Array} holders The `partials` placeholder indexes.
2778 * @returns {Array} Returns the new array of composed arguments.
2779 */
2780 function composeArgs(args, partials, holders) {
2781 var holdersLength = holders.length,
2782 argsIndex = -1,
2783 argsLength = nativeMax(args.length - holdersLength, 0),
2784 leftIndex = -1,
2785 leftLength = partials.length,
2786 result = Array(argsLength + leftLength);
2787
2788 while (++leftIndex < leftLength) {
2789 result[leftIndex] = partials[leftIndex];
2790 }
2791 while (++argsIndex < holdersLength) {
2792 result[holders[argsIndex]] = args[argsIndex];
2793 }
2794 while (argsLength--) {
2795 result[leftIndex++] = args[argsIndex++];
2796 }
2797 return result;
2798 }
2799
2800 /**
2801 * This function is like `composeArgs` except that the arguments composition
2802 * is tailored for `_.partialRight`.
2803 *
2804 * @private
2805 * @param {Array|Object} args The provided arguments.
2806 * @param {Array} partials The arguments to append to those provided.
2807 * @param {Array} holders The `partials` placeholder indexes.
2808 * @returns {Array} Returns the new array of composed arguments.
2809 */
2810 function composeArgsRight(args, partials, holders) {
2811 var holdersIndex = -1,
2812 holdersLength = holders.length,
2813 argsIndex = -1,
2814 argsLength = nativeMax(args.length - holdersLength, 0),
2815 rightIndex = -1,
2816 rightLength = partials.length,
2817 result = Array(argsLength + rightLength);
2818
2819 while (++argsIndex < argsLength) {
2820 result[argsIndex] = args[argsIndex];
2821 }
2822 var pad = argsIndex;
2823 while (++rightIndex < rightLength) {
2824 result[pad + rightIndex] = partials[rightIndex];
2825 }
2826 while (++holdersIndex < holdersLength) {
2827 result[pad + holders[holdersIndex]] = args[argsIndex++];
2828 }
2829 return result;
2830 }
2831
2832 /**
2833 * Creates a function that aggregates a collection, creating an accumulator
2834 * object composed from the results of running each element in the collection
2835 * through an iteratee. The `setter` sets the keys and values of the accumulator
2836 * object. If `initializer` is provided initializes the accumulator object.
2837 *
2838 * @private
2839 * @param {Function} setter The function to set keys and values of the accumulator object.
2840 * @param {Function} [initializer] The function to initialize the accumulator object.
2841 * @returns {Function} Returns the new aggregator function.
2842 */
2843 function createAggregator(setter, initializer) {
2844 return function(collection, iteratee, thisArg) {
2845 var result = initializer ? initializer() : {};
2846 iteratee = getCallback(iteratee, thisArg, 3);
2847
2848 if (isArray(collection)) {
2849 var index = -1,
2850 length = collection.length;
2851
2852 while (++index < length) {
2853 var value = collection[index];
2854 setter(result, value, iteratee(value, index, collection), collection);
2855 }
2856 } else {
2857 baseEach(collection, function(value, key, collection) {
2858 setter(result, value, iteratee(value, key, collection), collection);
2859 });
2860 }
2861 return result;
2862 };
2863 }
2864
2865 /**
2866 * Creates a function that assigns properties of source object(s) to a given
2867 * destination object.
2868 *
2869 * @private
2870 * @param {Function} assigner The function to assign values.
2871 * @returns {Function} Returns the new assigner function.
2872 */
2873 function createAssigner(assigner) {
2874 return function() {
2875 var length = arguments.length,
2876 object = arguments[0];
2877
2878 if (length < 2 || object == null) {
2879 return object;
2880 }
2881 if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3])) {
2882 length = 2;
2883 }
2884 // Juggle arguments.
2885 if (length > 3 && typeof arguments[length - 2] == 'function') {
2886 var customizer = bindCallback(arguments[--length - 1], arguments[length--], 5);
2887 } else if (length > 2 && typeof arguments[length - 1] == 'function') {
2888 customizer = arguments[--length];
2889 }
2890 var index = 0;
2891 while (++index < length) {
2892 var source = arguments[index];
2893 if (source) {
2894 assigner(object, source, customizer);
2895 }
2896 }
2897 return object;
2898 };
2899 }
2900
2901 /**
2902 * Creates a function that wraps `func` and invokes it with the `this`
2903 * binding of `thisArg`.
2904 *
2905 * @private
2906 * @param {Function} func The function to bind.
2907 * @param {*} [thisArg] The `this` binding of `func`.
2908 * @returns {Function} Returns the new bound function.
2909 */
2910 function createBindWrapper(func, thisArg) {
2911 var Ctor = createCtorWrapper(func);
2912
2913 function wrapper() {
2914 return (this instanceof wrapper ? Ctor : func).apply(thisArg, arguments);
2915 }
2916 return wrapper;
2917 }
2918
2919 /**
2920 * Creates a `Set` cache object to optimize linear searches of large arrays.
2921 *
2922 * @private
2923 * @param {Array} [values] The values to cache.
2924 * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
2925 */
2926 var createCache = !(nativeCreate && Set) ? constant(null) : function(values) {
2927 return new SetCache(values);
2928 };
2929
2930 /**
2931 * Creates a function that produces compound words out of the words in a
2932 * given string.
2933 *
2934 * @private
2935 * @param {Function} callback The function to combine each word.
2936 * @returns {Function} Returns the new compounder function.
2937 */
2938 function createCompounder(callback) {
2939 return function(string) {
2940 var index = -1,
2941 array = words(deburr(string)),
2942 length = array.length,
2943 result = '';
2944
2945 while (++index < length) {
2946 result = callback(result, array[index], index);
2947 }
2948 return result;
2949 };
2950 }
2951
2952 /**
2953 * Creates a function that produces an instance of `Ctor` regardless of
2954 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
2955 *
2956 * @private
2957 * @param {Function} Ctor The constructor to wrap.
2958 * @returns {Function} Returns the new wrapped function.
2959 */
2960 function createCtorWrapper(Ctor) {
2961 return function() {
2962 var thisBinding = baseCreate(Ctor.prototype),
2963 result = Ctor.apply(thisBinding, arguments);
2964
2965 // Mimic the constructor's `return` behavior.
2966 // See https://es5.github.io/#x13.2.2 for more details.
2967 return isObject(result) ? result : thisBinding;
2968 };
2969 }
2970
2971 /**
2972 * Creates a function that gets the extremum value of a collection.
2973 *
2974 * @private
2975 * @param {Function} arrayFunc The function to get the extremum value from an array.
2976 * @param {boolean} [isMin] Specify returning the minimum, instead of the maximum,
2977 * extremum value.
2978 * @returns {Function} Returns the new extremum function.
2979 */
2980 function createExtremum(arrayFunc, isMin) {
2981 return function(collection, iteratee, thisArg) {
2982 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
2983 iteratee = null;
2984 }
2985 var func = getCallback(),
2986 noIteratee = iteratee == null;
2987
2988 if (!(func === baseCallback && noIteratee)) {
2989 noIteratee = false;
2990 iteratee = func(iteratee, thisArg, 3);
2991 }
2992 if (noIteratee) {
2993 var isArr = isArray(collection);
2994 if (!isArr && isString(collection)) {
2995 iteratee = charAtCallback;
2996 } else {
2997 return arrayFunc(isArr ? collection : toIterable(collection));
2998 }
2999 }
3000 return extremumBy(collection, iteratee, isMin);
3001 };
3002 }
3003
3004 /**
3005 * Creates a function that wraps `func` and invokes it with optional `this`
3006 * binding of, partial application, and currying.
3007 *
3008 * @private
3009 * @param {Function|string} func The function or method name to reference.
3010 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
3011 * @param {*} [thisArg] The `this` binding of `func`.
3012 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
3013 * @param {Array} [holders] The `partials` placeholder indexes.
3014 * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
3015 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
3016 * @param {Array} [argPos] The argument positions of the new function.
3017 * @param {number} [ary] The arity cap of `func`.
3018 * @param {number} [arity] The arity of `func`.
3019 * @returns {Function} Returns the new wrapped function.
3020 */
3021 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
3022 var isAry = bitmask & ARY_FLAG,
3023 isBind = bitmask & BIND_FLAG,
3024 isBindKey = bitmask & BIND_KEY_FLAG,
3025 isCurry = bitmask & CURRY_FLAG,
3026 isCurryBound = bitmask & CURRY_BOUND_FLAG,
3027 isCurryRight = bitmask & CURRY_RIGHT_FLAG;
3028
3029 var Ctor = !isBindKey && createCtorWrapper(func),
3030 key = func;
3031
3032 function wrapper() {
3033 // Avoid `arguments` object use disqualifying optimizations by
3034 // converting it to an array before providing it to other functions.
3035 var length = arguments.length,
3036 index = length,
3037 args = Array(length);
3038
3039 while (index--) {
3040 args[index] = arguments[index];
3041 }
3042 if (partials) {
3043 args = composeArgs(args, partials, holders);
3044 }
3045 if (partialsRight) {
3046 args = composeArgsRight(args, partialsRight, holdersRight);
3047 }
3048 if (isCurry || isCurryRight) {
3049 var placeholder = wrapper.placeholder,
3050 argsHolders = replaceHolders(args, placeholder);
3051
3052 length -= argsHolders.length;
3053 if (length < arity) {
3054 var newArgPos = argPos ? arrayCopy(argPos) : null,
3055 newArity = nativeMax(arity - length, 0),
3056 newsHolders = isCurry ? argsHolders : null,
3057 newHoldersRight = isCurry ? null : argsHolders,
3058 newPartials = isCurry ? args : null,
3059 newPartialsRight = isCurry ? null : args;
3060
3061 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
3062 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
3063
3064 if (!isCurryBound) {
3065 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
3066 }
3067 var result = createHybridWrapper(func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity);
3068 result.placeholder = placeholder;
3069 return result;
3070 }
3071 }
3072 var thisBinding = isBind ? thisArg : this;
3073 if (isBindKey) {
3074 func = thisBinding[key];
3075 }
3076 if (argPos) {
3077 args = reorder(args, argPos);
3078 }
3079 if (isAry && ary < args.length) {
3080 args.length = ary;
3081 }
3082 return (this instanceof wrapper ? (Ctor || createCtorWrapper(func)) : func).apply(thisBinding, args);
3083 }
3084 return wrapper;
3085 }
3086
3087 /**
3088 * Creates the pad required for `string` based on the given padding length.
3089 * The `chars` string may be truncated if the number of padding characters
3090 * exceeds the padding length.
3091 *
3092 * @private
3093 * @param {string} string The string to create padding for.
3094 * @param {number} [length=0] The padding length.
3095 * @param {string} [chars=' '] The string used as padding.
3096 * @returns {string} Returns the pad for `string`.
3097 */
3098 function createPad(string, length, chars) {
3099 var strLength = string.length;
3100 length = +length;
3101
3102 if (strLength >= length || !nativeIsFinite(length)) {
3103 return '';
3104 }
3105 var padLength = length - strLength;
3106 chars = chars == null ? ' ' : baseToString(chars);
3107 return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
3108 }
3109
3110 /**
3111 * Creates a function that wraps `func` and invokes it with the optional `this`
3112 * binding of `thisArg` and the `partials` prepended to those provided to
3113 * the wrapper.
3114 *
3115 * @private
3116 * @param {Function} func The function to partially apply arguments to.
3117 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
3118 * @param {*} thisArg The `this` binding of `func`.
3119 * @param {Array} partials The arguments to prepend to those provided to the new function.
3120 * @returns {Function} Returns the new bound function.
3121 */
3122 function createPartialWrapper(func, bitmask, thisArg, partials) {
3123 var isBind = bitmask & BIND_FLAG,
3124 Ctor = createCtorWrapper(func);
3125
3126 function wrapper() {
3127 // Avoid `arguments` object use disqualifying optimizations by
3128 // converting it to an array before providing it `func`.
3129 var argsIndex = -1,
3130 argsLength = arguments.length,
3131 leftIndex = -1,
3132 leftLength = partials.length,
3133 args = Array(argsLength + leftLength);
3134
3135 while (++leftIndex < leftLength) {
3136 args[leftIndex] = partials[leftIndex];
3137 }
3138 while (argsLength--) {
3139 args[leftIndex++] = arguments[++argsIndex];
3140 }
3141 return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args);
3142 }
3143 return wrapper;
3144 }
3145
3146 /**
3147 * Creates a function that either curries or invokes `func` with optional
3148 * `this` binding and partially applied arguments.
3149 *
3150 * @private
3151 * @param {Function|string} func The function or method name to reference.
3152 * @param {number} bitmask The bitmask of flags.
3153 * The bitmask may be composed of the following flags:
3154 * 1 - `_.bind`
3155 * 2 - `_.bindKey`
3156 * 4 - `_.curry` or `_.curryRight` of a bound function
3157 * 8 - `_.curry`
3158 * 16 - `_.curryRight`
3159 * 32 - `_.partial`
3160 * 64 - `_.partialRight`
3161 * 128 - `_.rearg`
3162 * 256 - `_.ary`
3163 * @param {*} [thisArg] The `this` binding of `func`.
3164 * @param {Array} [partials] The arguments to be partially applied.
3165 * @param {Array} [holders] The `partials` placeholder indexes.
3166 * @param {Array} [argPos] The argument positions of the new function.
3167 * @param {number} [ary] The arity cap of `func`.
3168 * @param {number} [arity] The arity of `func`.
3169 * @returns {Function} Returns the new wrapped function.
3170 */
3171 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
3172 var isBindKey = bitmask & BIND_KEY_FLAG;
3173 if (!isBindKey && !isFunction(func)) {
3174 throw new TypeError(FUNC_ERROR_TEXT);
3175 }
3176 var length = partials ? partials.length : 0;
3177 if (!length) {
3178 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
3179 partials = holders = null;
3180 }
3181 length -= (holders ? holders.length : 0);
3182 if (bitmask & PARTIAL_RIGHT_FLAG) {
3183 var partialsRight = partials,
3184 holdersRight = holders;
3185
3186 partials = holders = null;
3187 }
3188 var data = !isBindKey && getData(func),
3189 newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
3190
3191 if (data && data !== true) {
3192 mergeData(newData, data);
3193 bitmask = newData[1];
3194 arity = newData[9];
3195 }
3196 newData[9] = arity == null
3197 ? (isBindKey ? 0 : func.length)
3198 : (nativeMax(arity - length, 0) || 0);
3199
3200 if (bitmask == BIND_FLAG) {
3201 var result = createBindWrapper(newData[0], newData[2]);
3202 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
3203 result = createPartialWrapper.apply(null, newData);
3204 } else {
3205 result = createHybridWrapper.apply(null, newData);
3206 }
3207 var setter = data ? baseSetData : setData;
3208 return setter(result, newData);
3209 }
3210
3211 /**
3212 * A specialized version of `baseIsEqualDeep` for arrays with support for
3213 * partial deep comparisons.
3214 *
3215 * @private
3216 * @param {Array} array The array to compare.
3217 * @param {Array} other The other array to compare.
3218 * @param {Function} equalFunc The function to determine equivalents of values.
3219 * @param {Function} [customizer] The function to customize comparing arrays.
3220 * @param {boolean} [isWhere] Specify performing partial comparisons.
3221 * @param {Array} [stackA] Tracks traversed `value` objects.
3222 * @param {Array} [stackB] Tracks traversed `other` objects.
3223 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
3224 */
3225 function equalArrays(array, other, equalFunc, customizer, isWhere, stackA, stackB) {
3226 var index = -1,
3227 arrLength = array.length,
3228 othLength = other.length,
3229 result = true;
3230
3231 if (arrLength != othLength && !(isWhere && othLength > arrLength)) {
3232 return false;
3233 }
3234 // Deep compare the contents, ignoring non-numeric properties.
3235 while (result && ++index < arrLength) {
3236 var arrValue = array[index],
3237 othValue = other[index];
3238
3239 result = undefined;
3240 if (customizer) {
3241 result = isWhere
3242 ? customizer(othValue, arrValue, index)
3243 : customizer(arrValue, othValue, index);
3244 }
3245 if (typeof result == 'undefined') {
3246 // Recursively compare arrays (susceptible to call stack limits).
3247 if (isWhere) {
3248 var othIndex = othLength;
3249 while (othIndex--) {
3250 othValue = other[othIndex];
3251 result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isWhere, stackA, stackB);
3252 if (result) {
3253 break;
3254 }
3255 }
3256 } else {
3257 result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isWhere, stackA, stackB);
3258 }
3259 }
3260 }
3261 return !!result;
3262 }
3263
3264 /**
3265 * A specialized version of `baseIsEqualDeep` for comparing objects of
3266 * the same `toStringTag`.
3267 *
3268 * **Note:** This function only supports comparing values with tags of
3269 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
3270 *
3271 * @private
3272 * @param {Object} value The object to compare.
3273 * @param {Object} other The other object to compare.
3274 * @param {string} tag The `toStringTag` of the objects to compare.
3275 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3276 */
3277 function equalByTag(object, other, tag) {
3278 switch (tag) {
3279 case boolTag:
3280 case dateTag:
3281 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
3282 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
3283 return +object == +other;
3284
3285 case errorTag:
3286 return object.name == other.name && object.message == other.message;
3287
3288 case numberTag:
3289 // Treat `NaN` vs. `NaN` as equal.
3290 return (object != +object)
3291 ? other != +other
3292 // But, treat `-0` vs. `+0` as not equal.
3293 : (object == 0 ? ((1 / object) == (1 / other)) : object == +other);
3294
3295 case regexpTag:
3296 case stringTag:
3297 // Coerce regexes to strings and treat strings primitives and string
3298 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
3299 return object == baseToString(other);
3300 }
3301 return false;
3302 }
3303
3304 /**
3305 * A specialized version of `baseIsEqualDeep` for objects with support for
3306 * partial deep comparisons.
3307 *
3308 * @private
3309 * @param {Object} object The object to compare.
3310 * @param {Object} other The other object to compare.
3311 * @param {Function} equalFunc The function to determine equivalents of values.
3312 * @param {Function} [customizer] The function to customize comparing values.
3313 * @param {boolean} [isWhere] Specify performing partial comparisons.
3314 * @param {Array} [stackA] Tracks traversed `value` objects.
3315 * @param {Array} [stackB] Tracks traversed `other` objects.
3316 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3317 */
3318 function equalObjects(object, other, equalFunc, customizer, isWhere, stackA, stackB) {
3319 var objProps = keys(object),
3320 objLength = objProps.length,
3321 othProps = keys(other),
3322 othLength = othProps.length;
3323
3324 if (objLength != othLength && !isWhere) {
3325 return false;
3326 }
3327 var hasCtor,
3328 index = -1;
3329
3330 while (++index < objLength) {
3331 var key = objProps[index],
3332 result = hasOwnProperty.call(other, key);
3333
3334 if (result) {
3335 var objValue = object[key],
3336 othValue = other[key];
3337
3338 result = undefined;
3339 if (customizer) {
3340 result = isWhere
3341 ? customizer(othValue, objValue, key)
3342 : customizer(objValue, othValue, key);
3343 }
3344 if (typeof result == 'undefined') {
3345 // Recursively compare objects (susceptible to call stack limits).
3346 result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isWhere, stackA, stackB);
3347 }
3348 }
3349 if (!result) {
3350 return false;
3351 }
3352 hasCtor || (hasCtor = key == 'constructor');
3353 }
3354 if (!hasCtor) {
3355 var objCtor = object.constructor,
3356 othCtor = other.constructor;
3357
3358 // Non `Object` object instances with different constructors are not equal.
3359 if (objCtor != othCtor && ('constructor' in object && 'constructor' in other) &&
3360 !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
3361 return false;
3362 }
3363 }
3364 return true;
3365 }
3366
3367 /**
3368 * Gets the extremum value of `collection` invoking `iteratee` for each value
3369 * in `collection` to generate the criterion by which the value is ranked.
3370 * The `iteratee` is invoked with three arguments; (value, index, collection).
3371 *
3372 * @private
3373 * @param {Array|Object|string} collection The collection to iterate over.
3374 * @param {Function} iteratee The function invoked per iteration.
3375 * @param {boolean} [isMin] Specify returning the minimum, instead of the
3376 * maximum, extremum value.
3377 * @returns {*} Returns the extremum value.
3378 */
3379 function extremumBy(collection, iteratee, isMin) {
3380 var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY,
3381 computed = exValue,
3382 result = computed;
3383
3384 baseEach(collection, function(value, index, collection) {
3385 var current = iteratee(value, index, collection);
3386 if ((isMin ? current < computed : current > computed) || (current === exValue && current === result)) {
3387 computed = current;
3388 result = value;
3389 }
3390 });
3391 return result;
3392 }
3393
3394 /**
3395 * Gets the appropriate "callback" function. If the `_.callback` method is
3396 * customized this function returns the custom method, otherwise it returns
3397 * the `baseCallback` function. If arguments are provided the chosen function
3398 * is invoked with them and its result is returned.
3399 *
3400 * @private
3401 * @returns {Function} Returns the chosen function or its result.
3402 */
3403 function getCallback(func, thisArg, argCount) {
3404 var result = lodash.callback || callback;
3405 result = result === callback ? baseCallback : result;
3406 return argCount ? result(func, thisArg, argCount) : result;
3407 }
3408
3409 /**
3410 * Gets metadata for `func`.
3411 *
3412 * @private
3413 * @param {Function} func The function to query.
3414 * @returns {*} Returns the metadata for `func`.
3415 */
3416 var getData = !metaMap ? noop : function(func) {
3417 return metaMap.get(func);
3418 };
3419
3420 /**
3421 * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
3422 * customized this function returns the custom method, otherwise it returns
3423 * the `baseIndexOf` function. If arguments are provided the chosen function
3424 * is invoked with them and its result is returned.
3425 *
3426 * @private
3427 * @returns {Function|number} Returns the chosen function or its result.
3428 */
3429 function getIndexOf(collection, target, fromIndex) {
3430 var result = lodash.indexOf || indexOf;
3431 result = result === indexOf ? baseIndexOf : result;
3432 return collection ? result(collection, target, fromIndex) : result;
3433 }
3434
3435 /**
3436 * Gets the view, applying any `transforms` to the `start` and `end` positions.
3437 *
3438 * @private
3439 * @param {number} start The start of the view.
3440 * @param {number} end The end of the view.
3441 * @param {Array} [transforms] The transformations to apply to the view.
3442 * @returns {Object} Returns an object containing the `start` and `end`
3443 * positions of the view.
3444 */
3445 function getView(start, end, transforms) {
3446 var index = -1,
3447 length = transforms ? transforms.length : 0;
3448
3449 while (++index < length) {
3450 var data = transforms[index],
3451 size = data.size;
3452
3453 switch (data.type) {
3454 case 'drop': start += size; break;
3455 case 'dropRight': end -= size; break;
3456 case 'take': end = nativeMin(end, start + size); break;
3457 case 'takeRight': start = nativeMax(start, end - size); break;
3458 }
3459 }
3460 return { 'start': start, 'end': end };
3461 }
3462
3463 /**
3464 * Initializes an array clone.
3465 *
3466 * @private
3467 * @param {Array} array The array to clone.
3468 * @returns {Array} Returns the initialized clone.
3469 */
3470 function initCloneArray(array) {
3471 var length = array.length,
3472 result = new array.constructor(length);
3473
3474 // Add array properties assigned by `RegExp#exec`.
3475 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
3476 result.index = array.index;
3477 result.input = array.input;
3478 }
3479 return result;
3480 }
3481
3482 /**
3483 * Initializes an object clone.
3484 *
3485 * @private
3486 * @param {Object} object The object to clone.
3487 * @returns {Object} Returns the initialized clone.
3488 */
3489 function initCloneObject(object) {
3490 var Ctor = object.constructor;
3491 if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
3492 Ctor = Object;
3493 }
3494 return new Ctor;
3495 }
3496
3497 /**
3498 * Initializes an object clone based on its `toStringTag`.
3499 *
3500 * **Note:** This function only supports cloning values with tags of
3501 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
3502 *
3503 *
3504 * @private
3505 * @param {Object} object The object to clone.
3506 * @param {string} tag The `toStringTag` of the object to clone.
3507 * @param {boolean} [isDeep] Specify a deep clone.
3508 * @returns {Object} Returns the initialized clone.
3509 */
3510 function initCloneByTag(object, tag, isDeep) {
3511 var Ctor = object.constructor;
3512 switch (tag) {
3513 case arrayBufferTag:
3514 return bufferClone(object);
3515
3516 case boolTag:
3517 case dateTag:
3518 return new Ctor(+object);
3519
3520 case float32Tag: case float64Tag:
3521 case int8Tag: case int16Tag: case int32Tag:
3522 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
3523 var buffer = object.buffer;
3524 return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
3525
3526 case numberTag:
3527 case stringTag:
3528 return new Ctor(object);
3529
3530 case regexpTag:
3531 var result = new Ctor(object.source, reFlags.exec(object));
3532 result.lastIndex = object.lastIndex;
3533 }
3534 return result;
3535 }
3536
3537 /**
3538 * Checks if `func` is eligible for `this` binding.
3539 *
3540 * @private
3541 * @param {Function} func The function to check.
3542 * @returns {boolean} Returns `true` if `func` is eligible, else `false`.
3543 */
3544 function isBindable(func) {
3545 var support = lodash.support,
3546 result = !(support.funcNames ? func.name : support.funcDecomp);
3547
3548 if (!result) {
3549 var source = fnToString.call(func);
3550 if (!support.funcNames) {
3551 result = !reFuncName.test(source);
3552 }
3553 if (!result) {
3554 // Check if `func` references the `this` keyword and store the result.
3555 result = reThis.test(source) || isNative(func);
3556 baseSetData(func, result);
3557 }
3558 }
3559 return result;
3560 }
3561
3562 /**
3563 * Checks if `value` is a valid array-like index.
3564 *
3565 * @private
3566 * @param {*} value The value to check.
3567 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
3568 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
3569 */
3570 function isIndex(value, length) {
3571 value = +value;
3572 length = length == null ? MAX_SAFE_INTEGER : length;
3573 return value > -1 && value % 1 == 0 && value < length;
3574 }
3575
3576 /**
3577 * Checks if the provided arguments are from an iteratee call.
3578 *
3579 * @private
3580 * @param {*} value The potential iteratee value argument.
3581 * @param {*} index The potential iteratee index or key argument.
3582 * @param {*} object The potential iteratee object argument.
3583 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
3584 */
3585 function isIterateeCall(value, index, object) {
3586 if (!isObject(object)) {
3587 return false;
3588 }
3589 var type = typeof index;
3590 if (type == 'number') {
3591 var length = object.length,
3592 prereq = isLength(length) && isIndex(index, length);
3593 } else {
3594 prereq = type == 'string' && index in value;
3595 }
3596 return prereq && object[index] === value;
3597 }
3598
3599 /**
3600 * Checks if `value` is a valid array-like length.
3601 *
3602 * @private
3603 * @param {*} value The value to check.
3604 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
3605 */
3606 function isLength(value) {
3607 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
3608 }
3609
3610 /**
3611 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
3612 *
3613 * @private
3614 * @param {*} value The value to check.
3615 * @returns {boolean} Returns `true` if `value` if suitable for strict
3616 * equality comparisons, else `false`.
3617 */
3618 function isStrictComparable(value) {
3619 return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value));
3620 }
3621
3622 /**
3623 * Merges the function metadata of `source` into `data`.
3624 *
3625 * Merging metadata reduces the number of wrappers required to invoke a function.
3626 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
3627 * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
3628 * augment function arguments, making the order in which they are executed important,
3629 * preventing the merging of metadata. However, we make an exception for a safe
3630 * common case where curried functions have `_.ary` and or `_.rearg` applied.
3631 *
3632 * @private
3633 * @param {Array} data The destination metadata.
3634 * @param {Array} source The source metadata.
3635 * @returns {Array} Returns `data`.
3636 */
3637 function mergeData(data, source) {
3638 var bitmask = data[1],
3639 srcBitmask = source[1],
3640 newBitmask = bitmask | srcBitmask;
3641
3642 var arityFlags = ARY_FLAG | REARG_FLAG,
3643 bindFlags = BIND_FLAG | BIND_KEY_FLAG,
3644 comboFlags = arityFlags | bindFlags | CURRY_BOUND_FLAG | CURRY_RIGHT_FLAG;
3645
3646 var isAry = bitmask & ARY_FLAG && !(srcBitmask & ARY_FLAG),
3647 isRearg = bitmask & REARG_FLAG && !(srcBitmask & REARG_FLAG),
3648 argPos = (isRearg ? data : source)[7],
3649 ary = (isAry ? data : source)[8];
3650
3651 var isCommon = !(bitmask >= REARG_FLAG && srcBitmask > bindFlags) &&
3652 !(bitmask > bindFlags && srcBitmask >= REARG_FLAG);
3653
3654 var isCombo = (newBitmask >= arityFlags && newBitmask <= comboFlags) &&
3655 (bitmask < REARG_FLAG || ((isRearg || isAry) && argPos.length <= ary));
3656
3657 // Exit early if metadata can't be merged.
3658 if (!(isCommon || isCombo)) {
3659 return data;
3660 }
3661 // Use source `thisArg` if available.
3662 if (srcBitmask & BIND_FLAG) {
3663 data[2] = source[2];
3664 // Set when currying a bound function.
3665 newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
3666 }
3667 // Compose partial arguments.
3668 var value = source[3];
3669 if (value) {
3670 var partials = data[3];
3671 data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
3672 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
3673 }
3674 // Compose partial right arguments.
3675 value = source[5];
3676 if (value) {
3677 partials = data[5];
3678 data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
3679 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
3680 }
3681 // Use source `argPos` if available.
3682 value = source[7];
3683 if (value) {
3684 data[7] = arrayCopy(value);
3685 }
3686 // Use source `ary` if it's smaller.
3687 if (srcBitmask & ARY_FLAG) {
3688 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
3689 }
3690 // Use source `arity` if one is not provided.
3691 if (data[9] == null) {
3692 data[9] = source[9];
3693 }
3694 // Use source `func` and merge bitmasks.
3695 data[0] = source[0];
3696 data[1] = newBitmask;
3697
3698 return data;
3699 }
3700
3701 /**
3702 * A specialized version of `_.pick` that picks `object` properties specified
3703 * by the `props` array.
3704 *
3705 * @private
3706 * @param {Object} object The source object.
3707 * @param {string[]} props The property names to pick.
3708 * @returns {Object} Returns the new object.
3709 */
3710 function pickByArray(object, props) {
3711 object = toObject(object);
3712
3713 var index = -1,
3714 length = props.length,
3715 result = {};
3716
3717 while (++index < length) {
3718 var key = props[index];
3719 if (key in object) {
3720 result[key] = object[key];
3721 }
3722 }
3723 return result;
3724 }
3725
3726 /**
3727 * A specialized version of `_.pick` that picks `object` properties `predicate`
3728 * returns truthy for.
3729 *
3730 * @private
3731 * @param {Object} object The source object.
3732 * @param {Function} predicate The function invoked per iteration.
3733 * @returns {Object} Returns the new object.
3734 */
3735 function pickByCallback(object, predicate) {
3736 var result = {};
3737 baseForIn(object, function(value, key, object) {
3738 if (predicate(value, key, object)) {
3739 result[key] = value;
3740 }
3741 });
3742 return result;
3743 }
3744
3745 /**
3746 * Reorder `array` according to the specified indexes where the element at
3747 * the first index is assigned as the first element, the element at
3748 * the second index is assigned as the second element, and so on.
3749 *
3750 * @private
3751 * @param {Array} array The array to reorder.
3752 * @param {Array} indexes The arranged array indexes.
3753 * @returns {Array} Returns `array`.
3754 */
3755 function reorder(array, indexes) {
3756 var arrLength = array.length,
3757 length = nativeMin(indexes.length, arrLength),
3758 oldArray = arrayCopy(array);
3759
3760 while (length--) {
3761 var index = indexes[length];
3762 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
3763 }
3764 return array;
3765 }
3766
3767 /**
3768 * Sets metadata for `func`.
3769 *
3770 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
3771 * period of time, it will trip its breaker and transition to an identity function
3772 * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
3773 * for more details.
3774 *
3775 * @private
3776 * @param {Function} func The function to associate metadata with.
3777 * @param {*} data The metadata.
3778 * @returns {Function} Returns `func`.
3779 */
3780 var setData = (function() {
3781 var count = 0,
3782 lastCalled = 0;
3783
3784 return function(key, value) {
3785 var stamp = now(),
3786 remaining = HOT_SPAN - (stamp - lastCalled);
3787
3788 lastCalled = stamp;
3789 if (remaining > 0) {
3790 if (++count >= HOT_COUNT) {
3791 return key;
3792 }
3793 } else {
3794 count = 0;
3795 }
3796 return baseSetData(key, value);
3797 };
3798 }());
3799
3800 /**
3801 * A fallback implementation of `_.isPlainObject` which checks if `value`
3802 * is an object created by the `Object` constructor or has a `[[Prototype]]`
3803 * of `null`.
3804 *
3805 * @private
3806 * @param {*} value The value to check.
3807 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
3808 */
3809 function shimIsPlainObject(value) {
3810 var Ctor,
3811 support = lodash.support;
3812
3813 // Exit early for non `Object` objects.
3814 if (!(isObjectLike(value) && objToString.call(value) == objectTag) ||
3815 (!hasOwnProperty.call(value, 'constructor') &&
3816 (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
3817 return false;
3818 }
3819 // IE < 9 iterates inherited properties before own properties. If the first
3820 // iterated property is an object's own property then there are no inherited
3821 // enumerable properties.
3822 var result;
3823 // In most environments an object's own properties are iterated before
3824 // its inherited properties. If the last iterated property is an object's
3825 // own property then there are no inherited enumerable properties.
3826 baseForIn(value, function(subValue, key) {
3827 result = key;
3828 });
3829 return typeof result == 'undefined' || hasOwnProperty.call(value, result);
3830 }
3831
3832 /**
3833 * A fallback implementation of `Object.keys` which creates an array of the
3834 * own enumerable property names of `object`.
3835 *
3836 * @private
3837 * @param {Object} object The object to inspect.
3838 * @returns {Array} Returns the array of property names.
3839 */
3840 function shimKeys(object) {
3841 var props = keysIn(object),
3842 propsLength = props.length,
3843 length = propsLength && object.length,
3844 support = lodash.support;
3845
3846 var allowIndexes = length && isLength(length) &&
3847 (isArray(object) || (support.nonEnumArgs && isArguments(object)));
3848
3849 var index = -1,
3850 result = [];
3851
3852 while (++index < propsLength) {
3853 var key = props[index];
3854 if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
3855 result.push(key);
3856 }
3857 }
3858 return result;
3859 }
3860
3861 /**
3862 * Converts `value` to an array-like object if it is not one.
3863 *
3864 * @private
3865 * @param {*} value The value to process.
3866 * @returns {Array|Object} Returns the array-like object.
3867 */
3868 function toIterable(value) {
3869 if (value == null) {
3870 return [];
3871 }
3872 if (!isLength(value.length)) {
3873 return values(value);
3874 }
3875 return isObject(value) ? value : Object(value);
3876 }
3877
3878 /**
3879 * Converts `value` to an object if it is not one.
3880 *
3881 * @private
3882 * @param {*} value The value to process.
3883 * @returns {Object} Returns the object.
3884 */
3885 function toObject(value) {
3886 return isObject(value) ? value : Object(value);
3887 }
3888
3889 /*------------------------------------------------------------------------*/
3890
3891 /**
3892 * Creates an array of elements split into groups the length of `size`.
3893 * If `collection` can't be split evenly, the final chunk will be the remaining
3894 * elements.
3895 *
3896 * @static
3897 * @memberOf _
3898 * @category Array
3899 * @param {Array} array The array to process.
3900 * @param {numer} [size=1] The length of each chunk.
3901 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
3902 * @returns {Array} Returns the new array containing chunks.
3903 * @example
3904 *
3905 * _.chunk(['a', 'b', 'c', 'd'], 2);
3906 * // => [['a', 'b'], ['c', 'd']]
3907 *
3908 * _.chunk(['a', 'b', 'c', 'd'], 3);
3909 * // => [['a', 'b', 'c'], ['d']]
3910 */
3911 function chunk(array, size, guard) {
3912 if (guard ? isIterateeCall(array, size, guard) : size == null) {
3913 size = 1;
3914 } else {
3915 size = nativeMax(+size || 1, 1);
3916 }
3917 var index = 0,
3918 length = array ? array.length : 0,
3919 resIndex = -1,
3920 result = Array(ceil(length / size));
3921
3922 while (index < length) {
3923 result[++resIndex] = baseSlice(array, index, (index += size));
3924 }
3925 return result;
3926 }
3927
3928 /**
3929 * Creates an array with all falsey values removed. The values `false`, `null`,
3930 * `0`, `""`, `undefined`, and `NaN` are falsey.
3931 *
3932 * @static
3933 * @memberOf _
3934 * @category Array
3935 * @param {Array} array The array to compact.
3936 * @returns {Array} Returns the new array of filtered values.
3937 * @example
3938 *
3939 * _.compact([0, 1, false, 2, '', 3]);
3940 * // => [1, 2, 3]
3941 */
3942 function compact(array) {
3943 var index = -1,
3944 length = array ? array.length : 0,
3945 resIndex = -1,
3946 result = [];
3947
3948 while (++index < length) {
3949 var value = array[index];
3950 if (value) {
3951 result[++resIndex] = value;
3952 }
3953 }
3954 return result;
3955 }
3956
3957 /**
3958 * Creates an array excluding all values of the provided arrays using
3959 * `SameValueZero` for equality comparisons.
3960 *
3961 * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
3962 * e.g. `===`, except that `NaN` matches `NaN`. See the
3963 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
3964 * for more details.
3965 *
3966 * @static
3967 * @memberOf _
3968 * @category Array
3969 * @param {Array} array The array to inspect.
3970 * @param {...Array} [values] The arrays of values to exclude.
3971 * @returns {Array} Returns the new array of filtered values.
3972 * @example
3973 *
3974 * _.difference([1, 2, 3], [5, 2, 10]);
3975 * // => [1, 3]
3976 */
3977 function difference() {
3978 var index = -1,
3979 length = arguments.length;
3980
3981 while (++index < length) {
3982 var value = arguments[index];
3983 if (isArray(value) || isArguments(value)) {
3984 break;
3985 }
3986 }
3987 return baseDifference(value, baseFlatten(arguments, false, true, ++index));
3988 }
3989
3990 /**
3991 * Creates a slice of `array` with `n` elements dropped from the beginning.
3992 *
3993 * @static
3994 * @memberOf _
3995 * @type Function
3996 * @category Array
3997 * @param {Array} array The array to query.
3998 * @param {number} [n=1] The number of elements to drop.
3999 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4000 * @returns {Array} Returns the slice of `array`.
4001 * @example
4002 *
4003 * _.drop([1, 2, 3]);
4004 * // => [2, 3]
4005 *
4006 * _.drop([1, 2, 3], 2);
4007 * // => [3]
4008 *
4009 * _.drop([1, 2, 3], 5);
4010 * // => []
4011 *
4012 * _.drop([1, 2, 3], 0);
4013 * // => [1, 2, 3]
4014 */
4015 function drop(array, n, guard) {
4016 var length = array ? array.length : 0;
4017 if (!length) {
4018 return [];
4019 }
4020 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4021 n = 1;
4022 }
4023 return baseSlice(array, n < 0 ? 0 : n);
4024 }
4025
4026 /**
4027 * Creates a slice of `array` with `n` elements dropped from the end.
4028 *
4029 * @static
4030 * @memberOf _
4031 * @type Function
4032 * @category Array
4033 * @param {Array} array The array to query.
4034 * @param {number} [n=1] The number of elements to drop.
4035 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4036 * @returns {Array} Returns the slice of `array`.
4037 * @example
4038 *
4039 * _.dropRight([1, 2, 3]);
4040 * // => [1, 2]
4041 *
4042 * _.dropRight([1, 2, 3], 2);
4043 * // => [1]
4044 *
4045 * _.dropRight([1, 2, 3], 5);
4046 * // => []
4047 *
4048 * _.dropRight([1, 2, 3], 0);
4049 * // => [1, 2, 3]
4050 */
4051 function dropRight(array, n, guard) {
4052 var length = array ? array.length : 0;
4053 if (!length) {
4054 return [];
4055 }
4056 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4057 n = 1;
4058 }
4059 n = length - (+n || 0);
4060 return baseSlice(array, 0, n < 0 ? 0 : n);
4061 }
4062
4063 /**
4064 * Creates a slice of `array` excluding elements dropped from the end.
4065 * Elements are dropped until `predicate` returns falsey. The predicate is
4066 * bound to `thisArg` and invoked with three arguments; (value, index, array).
4067 *
4068 * If a property name is provided for `predicate` the created "_.property"
4069 * style callback returns the property value of the given element.
4070 *
4071 * If an object is provided for `predicate` the created "_.matches" style
4072 * callback returns `true` for elements that have the properties of the given
4073 * object, else `false`.
4074 *
4075 * @static
4076 * @memberOf _
4077 * @type Function
4078 * @category Array
4079 * @param {Array} array The array to query.
4080 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4081 * per element.
4082 * @param {*} [thisArg] The `this` binding of `predicate`.
4083 * @returns {Array} Returns the slice of `array`.
4084 * @example
4085 *
4086 * _.dropRightWhile([1, 2, 3], function(n) { return n > 1; });
4087 * // => [1]
4088 *
4089 * var users = [
4090 * { 'user': 'barney', 'status': 'busy', 'active': false },
4091 * { 'user': 'fred', 'status': 'busy', 'active': true },
4092 * { 'user': 'pebbles', 'status': 'away', 'active': true }
4093 * ];
4094 *
4095 * // using the "_.property" callback shorthand
4096 * _.pluck(_.dropRightWhile(users, 'active'), 'user');
4097 * // => ['barney']
4098 *
4099 * // using the "_.matches" callback shorthand
4100 * _.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user');
4101 * // => ['barney', 'fred']
4102 */
4103 function dropRightWhile(array, predicate, thisArg) {
4104 var length = array ? array.length : 0;
4105 if (!length) {
4106 return [];
4107 }
4108 predicate = getCallback(predicate, thisArg, 3);
4109 while (length-- && predicate(array[length], length, array)) {}
4110 return baseSlice(array, 0, length + 1);
4111 }
4112
4113 /**
4114 * Creates a slice of `array` excluding elements dropped from the beginning.
4115 * Elements are dropped until `predicate` returns falsey. The predicate is
4116 * bound to `thisArg` and invoked with three arguments; (value, index, array).
4117 *
4118 * If a property name is provided for `predicate` the created "_.property"
4119 * style callback returns the property value of the given element.
4120 *
4121 * If an object is provided for `predicate` the created "_.matches" style
4122 * callback returns `true` for elements that have the properties of the given
4123 * object, else `false`.
4124 *
4125 * @static
4126 * @memberOf _
4127 * @type Function
4128 * @category Array
4129 * @param {Array} array The array to query.
4130 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4131 * per element.
4132 * @param {*} [thisArg] The `this` binding of `predicate`.
4133 * @returns {Array} Returns the slice of `array`.
4134 * @example
4135 *
4136 * _.dropWhile([1, 2, 3], function(n) { return n < 3; });
4137 * // => [3]
4138 *
4139 * var users = [
4140 * { 'user': 'barney', 'status': 'busy', 'active': true },
4141 * { 'user': 'fred', 'status': 'busy', 'active': false },
4142 * { 'user': 'pebbles', 'status': 'away', 'active': true }
4143 * ];
4144 *
4145 * // using the "_.property" callback shorthand
4146 * _.pluck(_.dropWhile(users, 'active'), 'user');
4147 * // => ['fred', 'pebbles']
4148 *
4149 * // using the "_.matches" callback shorthand
4150 * _.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user');
4151 * // => ['pebbles']
4152 */
4153 function dropWhile(array, predicate, thisArg) {
4154 var length = array ? array.length : 0;
4155 if (!length) {
4156 return [];
4157 }
4158 var index = -1;
4159 predicate = getCallback(predicate, thisArg, 3);
4160 while (++index < length && predicate(array[index], index, array)) {}
4161 return baseSlice(array, index);
4162 }
4163
4164 /**
4165 * This method is like `_.find` except that it returns the index of the first
4166 * element `predicate` returns truthy for, instead of the element itself.
4167 *
4168 * If a property name is provided for `predicate` the created "_.property"
4169 * style callback returns the property value of the given element.
4170 *
4171 * If an object is provided for `predicate` the created "_.matches" style
4172 * callback returns `true` for elements that have the properties of the given
4173 * object, else `false`.
4174 *
4175 * @static
4176 * @memberOf _
4177 * @category Array
4178 * @param {Array} array The array to search.
4179 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4180 * per iteration. If a property name or object is provided it is used to
4181 * create a "_.property" or "_.matches" style callback respectively.
4182 * @param {*} [thisArg] The `this` binding of `predicate`.
4183 * @returns {number} Returns the index of the found element, else `-1`.
4184 * @example
4185 *
4186 * var users = [
4187 * { 'user': 'barney', 'age': 36, 'active': false },
4188 * { 'user': 'fred', 'age': 40, 'active': true },
4189 * { 'user': 'pebbles', 'age': 1, 'active': false }
4190 * ];
4191 *
4192 * _.findIndex(users, function(chr) { return chr.age < 40; });
4193 * // => 0
4194 *
4195 * // using the "_.matches" callback shorthand
4196 * _.findIndex(users, { 'age': 1 });
4197 * // => 2
4198 *
4199 * // using the "_.property" callback shorthand
4200 * _.findIndex(users, 'active');
4201 * // => 1
4202 */
4203 function findIndex(array, predicate, thisArg) {
4204 var index = -1,
4205 length = array ? array.length : 0;
4206
4207 predicate = getCallback(predicate, thisArg, 3);
4208 while (++index < length) {
4209 if (predicate(array[index], index, array)) {
4210 return index;
4211 }
4212 }
4213 return -1;
4214 }
4215
4216 /**
4217 * This method is like `_.findIndex` except that it iterates over elements
4218 * of `collection` from right to left.
4219 *
4220 * If a property name is provided for `predicate` the created "_.property"
4221 * style callback returns the property value of the given element.
4222 *
4223 * If an object is provided for `predicate` the created "_.matches" style
4224 * callback returns `true` for elements that have the properties of the given
4225 * object, else `false`.
4226 *
4227 * @static
4228 * @memberOf _
4229 * @category Array
4230 * @param {Array} array The array to search.
4231 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4232 * per iteration. If a property name or object is provided it is used to
4233 * create a "_.property" or "_.matches" style callback respectively.
4234 * @param {*} [thisArg] The `this` binding of `predicate`.
4235 * @returns {number} Returns the index of the found element, else `-1`.
4236 * @example
4237 *
4238 * var users = [
4239 * { 'user': 'barney', 'age': 36, 'active': true },
4240 * { 'user': 'fred', 'age': 40, 'active': false },
4241 * { 'user': 'pebbles', 'age': 1, 'active': false }
4242 * ];
4243 *
4244 * _.findLastIndex(users, function(chr) { return chr.age < 40; });
4245 * // => 2
4246 *
4247 * // using the "_.matches" callback shorthand
4248 * _.findLastIndex(users, { 'age': 40 });
4249 * // => 1
4250 *
4251 * // using the "_.property" callback shorthand
4252 * _.findLastIndex(users, 'active');
4253 * // => 0
4254 */
4255 function findLastIndex(array, predicate, thisArg) {
4256 var length = array ? array.length : 0;
4257 predicate = getCallback(predicate, thisArg, 3);
4258 while (length--) {
4259 if (predicate(array[length], length, array)) {
4260 return length;
4261 }
4262 }
4263 return -1;
4264 }
4265
4266 /**
4267 * Gets the first element of `array`.
4268 *
4269 * @static
4270 * @memberOf _
4271 * @alias head
4272 * @category Array
4273 * @param {Array} array The array to query.
4274 * @returns {*} Returns the first element of `array`.
4275 * @example
4276 *
4277 * _.first([1, 2, 3]);
4278 * // => 1
4279 *
4280 * _.first([]);
4281 * // => undefined
4282 */
4283 function first(array) {
4284 return array ? array[0] : undefined;
4285 }
4286
4287 /**
4288 * Flattens a nested array. If `isDeep` is `true` the array is recursively
4289 * flattened, otherwise it is only flattened a single level.
4290 *
4291 * @static
4292 * @memberOf _
4293 * @category Array
4294 * @param {Array} array The array to flatten.
4295 * @param {boolean} [isDeep] Specify a deep flatten.
4296 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4297 * @returns {Array} Returns the new flattened array.
4298 * @example
4299 *
4300 * _.flatten([1, [2], [3, [[4]]]]);
4301 * // => [1, 2, 3, [[4]]];
4302 *
4303 * // using `isDeep`
4304 * _.flatten([1, [2], [3, [[4]]]], true);
4305 * // => [1, 2, 3, 4];
4306 */
4307 function flatten(array, isDeep, guard) {
4308 var length = array ? array.length : 0;
4309 if (guard && isIterateeCall(array, isDeep, guard)) {
4310 isDeep = false;
4311 }
4312 return length ? baseFlatten(array, isDeep) : [];
4313 }
4314
4315 /**
4316 * Recursively flattens a nested array.
4317 *
4318 * @static
4319 * @memberOf _
4320 * @category Array
4321 * @param {Array} array The array to recursively flatten.
4322 * @returns {Array} Returns the new flattened array.
4323 * @example
4324 *
4325 * _.flattenDeep([1, [2], [3, [[4]]]]);
4326 * // => [1, 2, 3, 4];
4327 */
4328 function flattenDeep(array) {
4329 var length = array ? array.length : 0;
4330 return length ? baseFlatten(array, true) : [];
4331 }
4332
4333 /**
4334 * Gets the index at which the first occurrence of `value` is found in `array`
4335 * using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
4336 * it is used as the offset from the end of `array`. If `array` is sorted
4337 * providing `true` for `fromIndex` performs a faster binary search.
4338 *
4339 * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
4340 * e.g. `===`, except that `NaN` matches `NaN`. See the
4341 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
4342 * for more details.
4343 *
4344 * @static
4345 * @memberOf _
4346 * @category Array
4347 * @param {Array} array The array to search.
4348 * @param {*} value The value to search for.
4349 * @param {boolean|number} [fromIndex=0] The index to search from or `true`
4350 * to perform a binary search on a sorted array.
4351 * @returns {number} Returns the index of the matched value, else `-1`.
4352 * @example
4353 *
4354 * _.indexOf([1, 2, 3, 1, 2, 3], 2);
4355 * // => 1
4356 *
4357 * // using `fromIndex`
4358 * _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
4359 * // => 4
4360 *
4361 * // performing a binary search
4362 * _.indexOf([4, 4, 5, 5, 6, 6], 5, true);
4363 * // => 2
4364 */
4365 function indexOf(array, value, fromIndex) {
4366 var length = array ? array.length : 0;
4367 if (!length) {
4368 return -1;
4369 }
4370 if (typeof fromIndex == 'number') {
4371 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
4372 } else if (fromIndex) {
4373 var index = binaryIndex(array, value),
4374 other = array[index];
4375
4376 return (value === value ? value === other : other !== other) ? index : -1;
4377 }
4378 return baseIndexOf(array, value, fromIndex);
4379 }
4380
4381 /**
4382 * Gets all but the last element of `array`.
4383 *
4384 * @static
4385 * @memberOf _
4386 * @category Array
4387 * @param {Array} array The array to query.
4388 * @returns {Array} Returns the slice of `array`.
4389 * @example
4390 *
4391 * _.initial([1, 2, 3]);
4392 * // => [1, 2]
4393 */
4394 function initial(array) {
4395 return dropRight(array, 1);
4396 }
4397
4398 /**
4399 * Creates an array of unique values in all provided arrays using `SameValueZero`
4400 * for equality comparisons.
4401 *
4402 * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
4403 * e.g. `===`, except that `NaN` matches `NaN`. See the
4404 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
4405 * for more details.
4406 *
4407 * @static
4408 * @memberOf _
4409 * @category Array
4410 * @param {...Array} [arrays] The arrays to inspect.
4411 * @returns {Array} Returns the new array of shared values.
4412 * @example
4413 *
4414 * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]);
4415 * // => [1, 2]
4416 */
4417 function intersection() {
4418 var args = [],
4419 argsIndex = -1,
4420 argsLength = arguments.length,
4421 caches = [],
4422 indexOf = getIndexOf(),
4423 isCommon = indexOf == baseIndexOf;
4424
4425 while (++argsIndex < argsLength) {
4426 var value = arguments[argsIndex];
4427 if (isArray(value) || isArguments(value)) {
4428 args.push(value);
4429 caches.push(isCommon && value.length >= 120 && createCache(argsIndex && value));
4430 }
4431 }
4432 argsLength = args.length;
4433 var array = args[0],
4434 index = -1,
4435 length = array ? array.length : 0,
4436 result = [],
4437 seen = caches[0];
4438
4439 outer:
4440 while (++index < length) {
4441 value = array[index];
4442 if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value)) < 0) {
4443 argsIndex = argsLength;
4444 while (--argsIndex) {
4445 var cache = caches[argsIndex];
4446 if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value)) < 0) {
4447 continue outer;
4448 }
4449 }
4450 if (seen) {
4451 seen.push(value);
4452 }
4453 result.push(value);
4454 }
4455 }
4456 return result;
4457 }
4458
4459 /**
4460 * Gets the last element of `array`.
4461 *
4462 * @static
4463 * @memberOf _
4464 * @category Array
4465 * @param {Array} array The array to query.
4466 * @returns {*} Returns the last element of `array`.
4467 * @example
4468 *
4469 * _.last([1, 2, 3]);
4470 * // => 3
4471 */
4472 function last(array) {
4473 var length = array ? array.length : 0;
4474 return length ? array[length - 1] : undefined;
4475 }
4476
4477 /**
4478 * This method is like `_.indexOf` except that it iterates over elements of
4479 * `array` from right to left.
4480 *
4481 * @static
4482 * @memberOf _
4483 * @category Array
4484 * @param {Array} array The array to search.
4485 * @param {*} value The value to search for.
4486 * @param {boolean|number} [fromIndex=array.length-1] The index to search from
4487 * or `true` to perform a binary search on a sorted array.
4488 * @returns {number} Returns the index of the matched value, else `-1`.
4489 * @example
4490 *
4491 * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
4492 * // => 4
4493 *
4494 * // using `fromIndex`
4495 * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
4496 * // => 1
4497 *
4498 * // performing a binary search
4499 * _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true);
4500 * // => 3
4501 */
4502 function lastIndexOf(array, value, fromIndex) {
4503 var length = array ? array.length : 0;
4504 if (!length) {
4505 return -1;
4506 }
4507 var index = length;
4508 if (typeof fromIndex == 'number') {
4509 index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
4510 } else if (fromIndex) {
4511 index = binaryIndex(array, value, true) - 1;
4512 var other = array[index];
4513 return (value === value ? value === other : other !== other) ? index : -1;
4514 }
4515 if (value !== value) {
4516 return indexOfNaN(array, index, true);
4517 }
4518 while (index--) {
4519 if (array[index] === value) {
4520 return index;
4521 }
4522 }
4523 return -1;
4524 }
4525
4526 /**
4527 * Removes all provided values from `array` using `SameValueZero` for equality
4528 * comparisons.
4529 *
4530 * **Notes:**
4531 * - Unlike `_.without`, this method mutates `array`.
4532 * - `SameValueZero` comparisons are like strict equality comparisons, e.g. `===`,
4533 * except that `NaN` matches `NaN`. See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
4534 * for more details.
4535 *
4536 * @static
4537 * @memberOf _
4538 * @category Array
4539 * @param {Array} array The array to modify.
4540 * @param {...*} [values] The values to remove.
4541 * @returns {Array} Returns `array`.
4542 * @example
4543 *
4544 * var array = [1, 2, 3, 1, 2, 3];
4545 * _.pull(array, 2, 3);
4546 * console.log(array);
4547 * // => [1, 1]
4548 */
4549 function pull() {
4550 var array = arguments[0];
4551 if (!(array && array.length)) {
4552 return array;
4553 }
4554 var index = 0,
4555 indexOf = getIndexOf(),
4556 length = arguments.length;
4557
4558 while (++index < length) {
4559 var fromIndex = 0,
4560 value = arguments[index];
4561
4562 while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
4563 splice.call(array, fromIndex, 1);
4564 }
4565 }
4566 return array;
4567 }
4568
4569 /**
4570 * Removes elements from `array` corresponding to the given indexes and returns
4571 * an array of the removed elements. Indexes may be specified as an array of
4572 * indexes or as individual arguments.
4573 *
4574 * **Note:** Unlike `_.at`, this method mutates `array`.
4575 *
4576 * @static
4577 * @memberOf _
4578 * @category Array
4579 * @param {Array} array The array to modify.
4580 * @param {...(number|number[])} [indexes] The indexes of elements to remove,
4581 * specified as individual indexes or arrays of indexes.
4582 * @returns {Array} Returns the new array of removed elements.
4583 * @example
4584 *
4585 * var array = [5, 10, 15, 20];
4586 * var evens = _.pullAt(array, [1, 3]);
4587 *
4588 * console.log(array);
4589 * // => [5, 15]
4590 *
4591 * console.log(evens);
4592 * // => [10, 20]
4593 */
4594 function pullAt(array) {
4595 return basePullAt(array || [], baseFlatten(arguments, false, false, 1));
4596 }
4597
4598 /**
4599 * Removes all elements from `array` that `predicate` returns truthy for
4600 * and returns an array of the removed elements. The predicate is bound to
4601 * `thisArg` and invoked with three arguments; (value, index, array).
4602 *
4603 * If a property name is provided for `predicate` the created "_.property"
4604 * style callback returns the property value of the given element.
4605 *
4606 * If an object is provided for `predicate` the created "_.matches" style
4607 * callback returns `true` for elements that have the properties of the given
4608 * object, else `false`.
4609 *
4610 * **Note:** Unlike `_.filter`, this method mutates `array`.
4611 *
4612 * @static
4613 * @memberOf _
4614 * @category Array
4615 * @param {Array} array The array to modify.
4616 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4617 * per iteration. If a property name or object is provided it is used to
4618 * create a "_.property" or "_.matches" style callback respectively.
4619 * @param {*} [thisArg] The `this` binding of `predicate`.
4620 * @returns {Array} Returns the new array of removed elements.
4621 * @example
4622 *
4623 * var array = [1, 2, 3, 4];
4624 * var evens = _.remove(array, function(n) { return n % 2 == 0; });
4625 *
4626 * console.log(array);
4627 * // => [1, 3]
4628 *
4629 * console.log(evens);
4630 * // => [2, 4]
4631 */
4632 function remove(array, predicate, thisArg) {
4633 var index = -1,
4634 length = array ? array.length : 0,
4635 result = [];
4636
4637 predicate = getCallback(predicate, thisArg, 3);
4638 while (++index < length) {
4639 var value = array[index];
4640 if (predicate(value, index, array)) {
4641 result.push(value);
4642 splice.call(array, index--, 1);
4643 length--;
4644 }
4645 }
4646 return result;
4647 }
4648
4649 /**
4650 * Gets all but the first element of `array`.
4651 *
4652 * @static
4653 * @memberOf _
4654 * @alias tail
4655 * @category Array
4656 * @param {Array} array The array to query.
4657 * @returns {Array} Returns the slice of `array`.
4658 * @example
4659 *
4660 * _.rest([1, 2, 3]);
4661 * // => [2, 3]
4662 */
4663 function rest(array) {
4664 return drop(array, 1);
4665 }
4666
4667 /**
4668 * Creates a slice of `array` from `start` up to, but not including, `end`.
4669 *
4670 * **Note:** This function is used instead of `Array#slice` to support node
4671 * lists in IE < 9 and to ensure dense arrays are returned.
4672 *
4673 * @static
4674 * @memberOf _
4675 * @category Array
4676 * @param {Array} array The array to slice.
4677 * @param {number} [start=0] The start position.
4678 * @param {number} [end=array.length] The end position.
4679 * @returns {Array} Returns the slice of `array`.
4680 */
4681 function slice(array, start, end) {
4682 var length = array ? array.length : 0;
4683 if (!length) {
4684 return [];
4685 }
4686 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
4687 start = 0;
4688 end = length;
4689 }
4690 return baseSlice(array, start, end);
4691 }
4692
4693 /**
4694 * Uses a binary search to determine the lowest index at which `value` should
4695 * be inserted into `array` in order to maintain its sort order. If an iteratee
4696 * function is provided it is invoked for `value` and each element of `array`
4697 * to compute their sort ranking. The iteratee is bound to `thisArg` and
4698 * invoked with one argument; (value).
4699 *
4700 * If a property name is provided for `predicate` the created "_.property"
4701 * style callback returns the property value of the given element.
4702 *
4703 * If an object is provided for `predicate` the created "_.matches" style
4704 * callback returns `true` for elements that have the properties of the given
4705 * object, else `false`.
4706 *
4707 * @static
4708 * @memberOf _
4709 * @category Array
4710 * @param {Array} array The sorted array to inspect.
4711 * @param {*} value The value to evaluate.
4712 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
4713 * per iteration. If a property name or object is provided it is used to
4714 * create a "_.property" or "_.matches" style callback respectively.
4715 * @param {*} [thisArg] The `this` binding of `iteratee`.
4716 * @returns {number} Returns the index at which `value` should be inserted
4717 * into `array`.
4718 * @example
4719 *
4720 * _.sortedIndex([30, 50], 40);
4721 * // => 1
4722 *
4723 * _.sortedIndex([4, 4, 5, 5, 6, 6], 5);
4724 * // => 2
4725 *
4726 * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
4727 *
4728 * // using an iteratee function
4729 * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
4730 * return this.data[word];
4731 * }, dict);
4732 * // => 1
4733 *
4734 * // using the "_.property" callback shorthand
4735 * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
4736 * // => 1
4737 */
4738 function sortedIndex(array, value, iteratee, thisArg) {
4739 var func = getCallback(iteratee);
4740 return (func === baseCallback && iteratee == null)
4741 ? binaryIndex(array, value)
4742 : binaryIndexBy(array, value, func(iteratee, thisArg, 1));
4743 }
4744
4745 /**
4746 * This method is like `_.sortedIndex` except that it returns the highest
4747 * index at which `value` should be inserted into `array` in order to
4748 * maintain its sort order.
4749 *
4750 * @static
4751 * @memberOf _
4752 * @category Array
4753 * @param {Array} array The sorted array to inspect.
4754 * @param {*} value The value to evaluate.
4755 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
4756 * per iteration. If a property name or object is provided it is used to
4757 * create a "_.property" or "_.matches" style callback respectively.
4758 * @param {*} [thisArg] The `this` binding of `iteratee`.
4759 * @returns {number} Returns the index at which `value` should be inserted
4760 * into `array`.
4761 * @example
4762 *
4763 * _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5);
4764 * // => 4
4765 */
4766 function sortedLastIndex(array, value, iteratee, thisArg) {
4767 var func = getCallback(iteratee);
4768 return (func === baseCallback && iteratee == null)
4769 ? binaryIndex(array, value, true)
4770 : binaryIndexBy(array, value, func(iteratee, thisArg, 1), true);
4771 }
4772
4773 /**
4774 * Creates a slice of `array` with `n` elements taken from the beginning.
4775 *
4776 * @static
4777 * @memberOf _
4778 * @type Function
4779 * @category Array
4780 * @param {Array} array The array to query.
4781 * @param {number} [n=1] The number of elements to take.
4782 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4783 * @returns {Array} Returns the slice of `array`.
4784 * @example
4785 *
4786 * _.take([1, 2, 3]);
4787 * // => [1]
4788 *
4789 * _.take([1, 2, 3], 2);
4790 * // => [1, 2]
4791 *
4792 * _.take([1, 2, 3], 5);
4793 * // => [1, 2, 3]
4794 *
4795 * _.take([1, 2, 3], 0);
4796 * // => []
4797 */
4798 function take(array, n, guard) {
4799 var length = array ? array.length : 0;
4800 if (!length) {
4801 return [];
4802 }
4803 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4804 n = 1;
4805 }
4806 return baseSlice(array, 0, n < 0 ? 0 : n);
4807 }
4808
4809 /**
4810 * Creates a slice of `array` with `n` elements taken from the end.
4811 *
4812 * @static
4813 * @memberOf _
4814 * @type Function
4815 * @category Array
4816 * @param {Array} array The array to query.
4817 * @param {number} [n=1] The number of elements to take.
4818 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4819 * @returns {Array} Returns the slice of `array`.
4820 * @example
4821 *
4822 * _.takeRight([1, 2, 3]);
4823 * // => [3]
4824 *
4825 * _.takeRight([1, 2, 3], 2);
4826 * // => [2, 3]
4827 *
4828 * _.takeRight([1, 2, 3], 5);
4829 * // => [1, 2, 3]
4830 *
4831 * _.takeRight([1, 2, 3], 0);
4832 * // => []
4833 */
4834 function takeRight(array, n, guard) {
4835 var length = array ? array.length : 0;
4836 if (!length) {
4837 return [];
4838 }
4839 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4840 n = 1;
4841 }
4842 n = length - (+n || 0);
4843 return baseSlice(array, n < 0 ? 0 : n);
4844 }
4845
4846 /**
4847 * Creates a slice of `array` with elements taken from the end. Elements are
4848 * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
4849 * and invoked with three arguments; (value, index, array).
4850 *
4851 * If a property name is provided for `predicate` the created "_.property"
4852 * style callback returns the property value of the given element.
4853 *
4854 * If an object is provided for `predicate` the created "_.matches" style
4855 * callback returns `true` for elements that have the properties of the given
4856 * object, else `false`.
4857 *
4858 * @static
4859 * @memberOf _
4860 * @type Function
4861 * @category Array
4862 * @param {Array} array The array to query.
4863 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4864 * per element.
4865 * @param {*} [thisArg] The `this` binding of `predicate`.
4866 * @returns {Array} Returns the slice of `array`.
4867 * @example
4868 *
4869 * _.takeRightWhile([1, 2, 3], function(n) { return n > 1; });
4870 * // => [2, 3]
4871 *
4872 * var users = [
4873 * { 'user': 'barney', 'status': 'busy', 'active': false },
4874 * { 'user': 'fred', 'status': 'busy', 'active': true },
4875 * { 'user': 'pebbles', 'status': 'away', 'active': true }
4876 * ];
4877 *
4878 * // using the "_.property" callback shorthand
4879 * _.pluck(_.takeRightWhile(users, 'active'), 'user');
4880 * // => ['fred', 'pebbles']
4881 *
4882 * // using the "_.matches" callback shorthand
4883 * _.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user');
4884 * // => ['pebbles']
4885 */
4886 function takeRightWhile(array, predicate, thisArg) {
4887 var length = array ? array.length : 0;
4888 if (!length) {
4889 return [];
4890 }
4891 predicate = getCallback(predicate, thisArg, 3);
4892 while (length-- && predicate(array[length], length, array)) {}
4893 return baseSlice(array, length + 1);
4894 }
4895
4896 /**
4897 * Creates a slice of `array` with elements taken from the beginning. Elements
4898 * are taken until `predicate` returns falsey. The predicate is bound to
4899 * `thisArg` and invoked with three arguments; (value, index, array).
4900 *
4901 * If a property name is provided for `predicate` the created "_.property"
4902 * style callback returns the property value of the given element.
4903 *
4904 * If an object is provided for `predicate` the created "_.matches" style
4905 * callback returns `true` for elements that have the properties of the given
4906 * object, else `false`.
4907 *
4908 * @static
4909 * @memberOf _
4910 * @type Function
4911 * @category Array
4912 * @param {Array} array The array to query.
4913 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4914 * per element.
4915 * @param {*} [thisArg] The `this` binding of `predicate`.
4916 * @returns {Array} Returns the slice of `array`.
4917 * @example
4918 *
4919 * _.takeWhile([1, 2, 3], function(n) { return n < 3; });
4920 * // => [1, 2]
4921 *
4922 * var users = [
4923 * { 'user': 'barney', 'status': 'busy', 'active': true },
4924 * { 'user': 'fred', 'status': 'busy', 'active': false },
4925 * { 'user': 'pebbles', 'status': 'away', 'active': true }
4926 * ];
4927 *
4928 * // using the "_.property" callback shorthand
4929 * _.pluck(_.takeWhile(users, 'active'), 'user');
4930 * // => ['barney']
4931 *
4932 * // using the "_.matches" callback shorthand
4933 * _.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user');
4934 * // => ['barney', 'fred']
4935 */
4936 function takeWhile(array, predicate, thisArg) {
4937 var length = array ? array.length : 0;
4938 if (!length) {
4939 return [];
4940 }
4941 var index = -1;
4942 predicate = getCallback(predicate, thisArg, 3);
4943 while (++index < length && predicate(array[index], index, array)) {}
4944 return baseSlice(array, 0, index);
4945 }
4946
4947 /**
4948 * Creates an array of unique values, in order, of the provided arrays using
4949 * `SameValueZero` for equality comparisons.
4950 *
4951 * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
4952 * e.g. `===`, except that `NaN` matches `NaN`. See the
4953 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
4954 * for more details.
4955 *
4956 * @static
4957 * @memberOf _
4958 * @category Array
4959 * @param {...Array} [arrays] The arrays to inspect.
4960 * @returns {Array} Returns the new array of combined values.
4961 * @example
4962 *
4963 * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]);
4964 * // => [1, 2, 3, 5, 4]
4965 */
4966 function union() {
4967 return baseUniq(baseFlatten(arguments, false, true));
4968 }
4969
4970 /**
4971 * Creates a duplicate-value-free version of an array using `SameValueZero`
4972 * for equality comparisons. Providing `true` for `isSorted` performs a faster
4973 * search algorithm for sorted arrays. If an iteratee function is provided it
4974 * is invoked for each value in the array to generate the criterion by which
4975 * uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
4976 * with three arguments; (value, index, array).
4977 *
4978 * If a property name is provided for `predicate` the created "_.property"
4979 * style callback returns the property value of the given element.
4980 *
4981 * If an object is provided for `predicate` the created "_.matches" style
4982 * callback returns `true` for elements that have the properties of the given
4983 * object, else `false`.
4984 *
4985 * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
4986 * e.g. `===`, except that `NaN` matches `NaN`. See the
4987 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
4988 * for more details.
4989 *
4990 * @static
4991 * @memberOf _
4992 * @alias unique
4993 * @category Array
4994 * @param {Array} array The array to inspect.
4995 * @param {boolean} [isSorted] Specify the array is sorted.
4996 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
4997 * If a property name or object is provided it is used to create a "_.property"
4998 * or "_.matches" style callback respectively.
4999 * @param {*} [thisArg] The `this` binding of `iteratee`.
5000 * @returns {Array} Returns the new duplicate-value-free array.
5001 * @example
5002 *
5003 * _.uniq([1, 2, 1]);
5004 * // => [1, 2]
5005 *
5006 * // using `isSorted`
5007 * _.uniq([1, 1, 2], true);
5008 * // => [1, 2]
5009 *
5010 * // using an iteratee function
5011 * _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math);
5012 * // => [1, 2.5]
5013 *
5014 * // using the "_.property" callback shorthand
5015 * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
5016 * // => [{ 'x': 1 }, { 'x': 2 }]
5017 */
5018 function uniq(array, isSorted, iteratee, thisArg) {
5019 var length = array ? array.length : 0;
5020 if (!length) {
5021 return [];
5022 }
5023 // Juggle arguments.
5024 if (typeof isSorted != 'boolean' && isSorted != null) {
5025 thisArg = iteratee;
5026 iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
5027 isSorted = false;
5028 }
5029 var func = getCallback();
5030 if (!(func === baseCallback && iteratee == null)) {
5031 iteratee = func(iteratee, thisArg, 3);
5032 }
5033 return (isSorted && getIndexOf() == baseIndexOf)
5034 ? sortedUniq(array, iteratee)
5035 : baseUniq(array, iteratee);
5036 }
5037
5038 /**
5039 * This method is like `_.zip` except that it accepts an array of grouped
5040 * elements and creates an array regrouping the elements to their pre-`_.zip`
5041 * configuration.
5042 *
5043 * @static
5044 * @memberOf _
5045 * @category Array
5046 * @param {Array} array The array of grouped elements to process.
5047 * @returns {Array} Returns the new array of regrouped elements.
5048 * @example
5049 *
5050 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
5051 * // => [['fred', 30, true], ['barney', 40, false]]
5052 *
5053 * _.unzip(zipped);
5054 * // => [['fred', 'barney'], [30, 40], [true, false]]
5055 */
5056 function unzip(array) {
5057 var index = -1,
5058 length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0,
5059 result = Array(length);
5060
5061 while (++index < length) {
5062 result[index] = arrayMap(array, baseProperty(index));
5063 }
5064 return result;
5065 }
5066
5067 /**
5068 * Creates an array excluding all provided values using `SameValueZero` for
5069 * equality comparisons.
5070 *
5071 * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
5072 * e.g. `===`, except that `NaN` matches `NaN`. See the
5073 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
5074 * for more details.
5075 *
5076 * @static
5077 * @memberOf _
5078 * @category Array
5079 * @param {Array} array The array to filter.
5080 * @param {...*} [values] The values to exclude.
5081 * @returns {Array} Returns the new array of filtered values.
5082 * @example
5083 *
5084 * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
5085 * // => [2, 3, 4]
5086 */
5087 function without(array) {
5088 return baseDifference(array, baseSlice(arguments, 1));
5089 }
5090
5091 /**
5092 * Creates an array that is the symmetric difference of the provided arrays.
5093 * See [Wikipedia](https://en.wikipedia.org/wiki/Symmetric_difference) for
5094 * more details.
5095 *
5096 * @static
5097 * @memberOf _
5098 * @category Array
5099 * @param {...Array} [arrays] The arrays to inspect.
5100 * @returns {Array} Returns the new array of values.
5101 * @example
5102 *
5103 * _.xor([1, 2, 3], [5, 2, 1, 4]);
5104 * // => [3, 5, 4]
5105 *
5106 * _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
5107 * // => [1, 4, 5]
5108 */
5109 function xor() {
5110 var index = -1,
5111 length = arguments.length;
5112
5113 while (++index < length) {
5114 var array = arguments[index];
5115 if (isArray(array) || isArguments(array)) {
5116 var result = result
5117 ? baseDifference(result, array).concat(baseDifference(array, result))
5118 : array;
5119 }
5120 }
5121 return result ? baseUniq(result) : [];
5122 }
5123
5124 /**
5125 * Creates an array of grouped elements, the first of which contains the first
5126 * elements of the given arrays, the second of which contains the second elements
5127 * of the given arrays, and so on.
5128 *
5129 * @static
5130 * @memberOf _
5131 * @category Array
5132 * @param {...Array} [arrays] The arrays to process.
5133 * @returns {Array} Returns the new array of grouped elements.
5134 * @example
5135 *
5136 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
5137 * // => [['fred', 30, true], ['barney', 40, false]]
5138 */
5139 function zip() {
5140 var length = arguments.length,
5141 array = Array(length);
5142
5143 while (length--) {
5144 array[length] = arguments[length];
5145 }
5146 return unzip(array);
5147 }
5148
5149 /**
5150 * Creates an object composed from arrays of property names and values. Provide
5151 * either a single two dimensional array, e.g. `[[key1, value1], [key2, value2]]`
5152 * or two arrays, one of property names and one of corresponding values.
5153 *
5154 * @static
5155 * @memberOf _
5156 * @alias object
5157 * @category Array
5158 * @param {Array} props The property names.
5159 * @param {Array} [values=[]] The property values.
5160 * @returns {Object} Returns the new object.
5161 * @example
5162 *
5163 * _.zipObject(['fred', 'barney'], [30, 40]);
5164 * // => { 'fred': 30, 'barney': 40 }
5165 */
5166 function zipObject(props, values) {
5167 var index = -1,
5168 length = props ? props.length : 0,
5169 result = {};
5170
5171 if (length && !values && !isArray(props[0])) {
5172 values = [];
5173 }
5174 while (++index < length) {
5175 var key = props[index];
5176 if (values) {
5177 result[key] = values[index];
5178 } else if (key) {
5179 result[key[0]] = key[1];
5180 }
5181 }
5182 return result;
5183 }
5184
5185 /*------------------------------------------------------------------------*/
5186
5187 /**
5188 * Creates a `lodash` object that wraps `value` with explicit method
5189 * chaining enabled.
5190 *
5191 * @static
5192 * @memberOf _
5193 * @category Chain
5194 * @param {*} value The value to wrap.
5195 * @returns {Object} Returns the new `lodash` object.
5196 * @example
5197 *
5198 * var users = [
5199 * { 'user': 'barney', 'age': 36 },
5200 * { 'user': 'fred', 'age': 40 },
5201 * { 'user': 'pebbles', 'age': 1 }
5202 * ];
5203 *
5204 * var youngest = _.chain(users)
5205 * .sortBy('age')
5206 * .map(function(chr) { return chr.user + ' is ' + chr.age; })
5207 * .first()
5208 * .value();
5209 * // => 'pebbles is 1'
5210 */
5211 function chain(value) {
5212 var result = lodash(value);
5213 result.__chain__ = true;
5214 return result;
5215 }
5216
5217 /**
5218 * This method invokes `interceptor` and returns `value`. The interceptor is
5219 * bound to `thisArg` and invoked with one argument; (value). The purpose of
5220 * this method is to "tap into" a method chain in order to perform operations
5221 * on intermediate results within the chain.
5222 *
5223 * @static
5224 * @memberOf _
5225 * @category Chain
5226 * @param {*} value The value to provide to `interceptor`.
5227 * @param {Function} interceptor The function to invoke.
5228 * @param {*} [thisArg] The `this` binding of `interceptor`.
5229 * @returns {*} Returns `value`.
5230 * @example
5231 *
5232 * _([1, 2, 3])
5233 * .tap(function(array) { array.pop(); })
5234 * .reverse()
5235 * .value();
5236 * // => [2, 1]
5237 */
5238 function tap(value, interceptor, thisArg) {
5239 interceptor.call(thisArg, value);
5240 return value;
5241 }
5242
5243 /**
5244 * This method is like `_.tap` except that it returns the result of `interceptor`.
5245 *
5246 * @static
5247 * @memberOf _
5248 * @category Chain
5249 * @param {*} value The value to provide to `interceptor`.
5250 * @param {Function} interceptor The function to invoke.
5251 * @param {*} [thisArg] The `this` binding of `interceptor`.
5252 * @returns {*} Returns the result of `interceptor`.
5253 * @example
5254 *
5255 * _([1, 2, 3])
5256 * .last()
5257 * .thru(function(value) { return [value]; })
5258 * .value();
5259 * // => [3]
5260 */
5261 function thru(value, interceptor, thisArg) {
5262 return interceptor.call(thisArg, value);
5263 }
5264
5265 /**
5266 * Enables explicit method chaining on the wrapper object.
5267 *
5268 * @name chain
5269 * @memberOf _
5270 * @category Chain
5271 * @returns {*} Returns the `lodash` object.
5272 * @example
5273 *
5274 * var users = [
5275 * { 'user': 'barney', 'age': 36 },
5276 * { 'user': 'fred', 'age': 40 }
5277 * ];
5278 *
5279 * // without explicit chaining
5280 * _(users).first();
5281 * // => { 'user': 'barney', 'age': 36 }
5282 *
5283 * // with explicit chaining
5284 * _(users).chain()
5285 * .first()
5286 * .pick('user')
5287 * .value();
5288 * // => { 'user': 'barney' }
5289 */
5290 function wrapperChain() {
5291 return chain(this);
5292 }
5293
5294 /**
5295 * Reverses the wrapped array so the first element becomes the last, the
5296 * second element becomes the second to last, and so on.
5297 *
5298 * **Note:** This method mutates the wrapped array.
5299 *
5300 * @name reverse
5301 * @memberOf _
5302 * @category Chain
5303 * @returns {Object} Returns the new reversed `lodash` object.
5304 * @example
5305 *
5306 * var array = [1, 2, 3];
5307 *
5308 * _(array).reverse().value()
5309 * // => [3, 2, 1]
5310 *
5311 * console.log(array);
5312 * // => [3, 2, 1]
5313 */
5314 function wrapperReverse() {
5315 var value = this.__wrapped__;
5316 if (value instanceof LazyWrapper) {
5317 return new LodashWrapper(value.reverse());
5318 }
5319 return this.thru(function(value) {
5320 return value.reverse();
5321 });
5322 }
5323
5324 /**
5325 * Produces the result of coercing the unwrapped value to a string.
5326 *
5327 * @name toString
5328 * @memberOf _
5329 * @category Chain
5330 * @returns {string} Returns the coerced string value.
5331 * @example
5332 *
5333 * _([1, 2, 3]).toString();
5334 * // => '1,2,3'
5335 */
5336 function wrapperToString() {
5337 return (this.value() + '');
5338 }
5339
5340 /**
5341 * Executes the chained sequence to extract the unwrapped value.
5342 *
5343 * @name value
5344 * @memberOf _
5345 * @alias toJSON, valueOf
5346 * @category Chain
5347 * @returns {*} Returns the resolved unwrapped value.
5348 * @example
5349 *
5350 * _([1, 2, 3]).value();
5351 * // => [1, 2, 3]
5352 */
5353 function wrapperValue() {
5354 return baseWrapperValue(this.__wrapped__, this.__actions__);
5355 }
5356
5357 /*------------------------------------------------------------------------*/
5358
5359 /**
5360 * Creates an array of elements corresponding to the given keys, or indexes,
5361 * of `collection`. Keys may be specified as individual arguments or as arrays
5362 * of keys.
5363 *
5364 * @static
5365 * @memberOf _
5366 * @category Collection
5367 * @param {Array|Object|string} collection The collection to iterate over.
5368 * @param {...(number|number[]|string|string[])} [props] The property names
5369 * or indexes of elements to pick, specified individually or in arrays.
5370 * @returns {Array} Returns the new array of picked elements.
5371 * @example
5372 *
5373 * _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
5374 * // => ['a', 'c', 'e']
5375 *
5376 * _.at(['fred', 'barney', 'pebbles'], 0, 2);
5377 * // => ['fred', 'pebbles']
5378 */
5379 function at(collection) {
5380 var length = collection ? collection.length : 0;
5381 if (isLength(length)) {
5382 collection = toIterable(collection);
5383 }
5384 return baseAt(collection, baseFlatten(arguments, false, false, 1));
5385 }
5386
5387 /**
5388 * Checks if `value` is in `collection` using `SameValueZero` for equality
5389 * comparisons. If `fromIndex` is negative, it is used as the offset from
5390 * the end of `collection`.
5391 *
5392 * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
5393 * e.g. `===`, except that `NaN` matches `NaN`. See the
5394 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
5395 * for more details.
5396 *
5397 * @static
5398 * @memberOf _
5399 * @alias contains, include
5400 * @category Collection
5401 * @param {Array|Object|string} collection The collection to search.
5402 * @param {*} target The value to search for.
5403 * @param {number} [fromIndex=0] The index to search from.
5404 * @returns {boolean} Returns `true` if a matching element is found, else `false`.
5405 * @example
5406 *
5407 * _.includes([1, 2, 3], 1);
5408 * // => true
5409 *
5410 * _.includes([1, 2, 3], 1, 2);
5411 * // => false
5412 *
5413 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
5414 * // => true
5415 *
5416 * _.includes('pebbles', 'eb');
5417 * // => true
5418 */
5419 function includes(collection, target, fromIndex) {
5420 var length = collection ? collection.length : 0;
5421 if (!isLength(length)) {
5422 collection = values(collection);
5423 length = collection.length;
5424 }
5425 if (!length) {
5426 return false;
5427 }
5428 if (typeof fromIndex == 'number') {
5429 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
5430 } else {
5431 fromIndex = 0;
5432 }
5433 return (typeof collection == 'string' || !isArray(collection) && isString(collection))
5434 ? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
5435 : (getIndexOf(collection, target, fromIndex) > -1);
5436 }
5437
5438 /**
5439 * Creates an object composed of keys generated from the results of running
5440 * each element of `collection` through `iteratee`. The corresponding value
5441 * of each key is the number of times the key was returned by `iteratee`.
5442 * The `iteratee` is bound to `thisArg` and invoked with three arguments;
5443 * (value, index|key, collection).
5444 *
5445 * If a property name is provided for `predicate` the created "_.property"
5446 * style callback returns the property value of the given element.
5447 *
5448 * If an object is provided for `predicate` the created "_.matches" style
5449 * callback returns `true` for elements that have the properties of the given
5450 * object, else `false`.
5451 *
5452 * @static
5453 * @memberOf _
5454 * @category Collection
5455 * @param {Array|Object|string} collection The collection to iterate over.
5456 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5457 * per iteration. If a property name or object is provided it is used to
5458 * create a "_.property" or "_.matches" style callback respectively.
5459 * @param {*} [thisArg] The `this` binding of `iteratee`.
5460 * @returns {Object} Returns the composed aggregate object.
5461 * @example
5462 *
5463 * _.countBy([4.3, 6.1, 6.4], function(n) { return Math.floor(n); });
5464 * // => { '4': 1, '6': 2 }
5465 *
5466 * _.countBy([4.3, 6.1, 6.4], function(n) { return this.floor(n); }, Math);
5467 * // => { '4': 1, '6': 2 }
5468 *
5469 * _.countBy(['one', 'two', 'three'], 'length');
5470 * // => { '3': 2, '5': 1 }
5471 */
5472 var countBy = createAggregator(function(result, value, key) {
5473 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
5474 });
5475
5476 /**
5477 * Checks if `predicate` returns truthy for **all** elements of `collection`.
5478 * The predicate is bound to `thisArg` and invoked with three arguments;
5479 * (value, index|key, collection).
5480 *
5481 * If a property name is provided for `predicate` the created "_.property"
5482 * style callback returns the property value of the given element.
5483 *
5484 * If an object is provided for `predicate` the created "_.matches" style
5485 * callback returns `true` for elements that have the properties of the given
5486 * object, else `false`.
5487 *
5488 * @static
5489 * @memberOf _
5490 * @alias all
5491 * @category Collection
5492 * @param {Array|Object|string} collection The collection to iterate over.
5493 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5494 * per iteration. If a property name or object is provided it is used to
5495 * create a "_.property" or "_.matches" style callback respectively.
5496 * @param {*} [thisArg] The `this` binding of `predicate`.
5497 * @returns {boolean} Returns `true` if all elements pass the predicate check,
5498 * else `false`.
5499 * @example
5500 *
5501 * _.every([true, 1, null, 'yes']);
5502 * // => false
5503 *
5504 * var users = [
5505 * { 'user': 'barney', 'age': 36 },
5506 * { 'user': 'fred', 'age': 40 }
5507 * ];
5508 *
5509 * // using the "_.property" callback shorthand
5510 * _.every(users, 'age');
5511 * // => true
5512 *
5513 * // using the "_.matches" callback shorthand
5514 * _.every(users, { 'age': 36 });
5515 * // => false
5516 */
5517 function every(collection, predicate, thisArg) {
5518 var func = isArray(collection) ? arrayEvery : baseEvery;
5519 if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
5520 predicate = getCallback(predicate, thisArg, 3);
5521 }
5522 return func(collection, predicate);
5523 }
5524
5525 /**
5526 * Iterates over elements of `collection`, returning an array of all elements
5527 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
5528 * invoked with three arguments; (value, index|key, collection).
5529 *
5530 * If a property name is provided for `predicate` the created "_.property"
5531 * style callback returns the property value of the given element.
5532 *
5533 * If an object is provided for `predicate` the created "_.matches" style
5534 * callback returns `true` for elements that have the properties of the given
5535 * object, else `false`.
5536 *
5537 * @static
5538 * @memberOf _
5539 * @alias select
5540 * @category Collection
5541 * @param {Array|Object|string} collection The collection to iterate over.
5542 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5543 * per iteration. If a property name or object is provided it is used to
5544 * create a "_.property" or "_.matches" style callback respectively.
5545 * @param {*} [thisArg] The `this` binding of `predicate`.
5546 * @returns {Array} Returns the new filtered array.
5547 * @example
5548 *
5549 * var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; });
5550 * // => [2, 4]
5551 *
5552 * var users = [
5553 * { 'user': 'barney', 'age': 36, 'active': false },
5554 * { 'user': 'fred', 'age': 40, 'active': true }
5555 * ];
5556 *
5557 * // using the "_.property" callback shorthand
5558 * _.pluck(_.filter(users, 'active'), 'user');
5559 * // => ['fred']
5560 *
5561 * // using the "_.matches" callback shorthand
5562 * _.pluck(_.filter(users, { 'age': 36 }), 'user');
5563 * // => ['barney']
5564 */
5565 function filter(collection, predicate, thisArg) {
5566 var func = isArray(collection) ? arrayFilter : baseFilter;
5567 predicate = getCallback(predicate, thisArg, 3);
5568 return func(collection, predicate);
5569 }
5570
5571 /**
5572 * Iterates over elements of `collection`, returning the first element
5573 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
5574 * invoked with three arguments; (value, index|key, collection).
5575 *
5576 * If a property name is provided for `predicate` the created "_.property"
5577 * style callback returns the property value of the given element.
5578 *
5579 * If an object is provided for `predicate` the created "_.matches" style
5580 * callback returns `true` for elements that have the properties of the given
5581 * object, else `false`.
5582 *
5583 * @static
5584 * @memberOf _
5585 * @alias detect
5586 * @category Collection
5587 * @param {Array|Object|string} collection The collection to search.
5588 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5589 * per iteration. If a property name or object is provided it is used to
5590 * create a "_.property" or "_.matches" style callback respectively.
5591 * @param {*} [thisArg] The `this` binding of `predicate`.
5592 * @returns {*} Returns the matched element, else `undefined`.
5593 * @example
5594 *
5595 * var users = [
5596 * { 'user': 'barney', 'age': 36, 'active': false },
5597 * { 'user': 'fred', 'age': 40, 'active': true },
5598 * { 'user': 'pebbles', 'age': 1, 'active': false }
5599 * ];
5600 *
5601 * _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user');
5602 * // => 'barney'
5603 *
5604 * // using the "_.matches" callback shorthand
5605 * _.result(_.find(users, { 'age': 1 }), 'user');
5606 * // => 'pebbles'
5607 *
5608 * // using the "_.property" callback shorthand
5609 * _.result(_.find(users, 'active'), 'user');
5610 * // => 'fred'
5611 */
5612 function find(collection, predicate, thisArg) {
5613 if (isArray(collection)) {
5614 var index = findIndex(collection, predicate, thisArg);
5615 return index > -1 ? collection[index] : undefined;
5616 }
5617 predicate = getCallback(predicate, thisArg, 3);
5618 return baseFind(collection, predicate, baseEach);
5619 }
5620
5621 /**
5622 * This method is like `_.find` except that it iterates over elements of
5623 * `collection` from right to left.
5624 *
5625 * @static
5626 * @memberOf _
5627 * @category Collection
5628 * @param {Array|Object|string} collection The collection to search.
5629 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5630 * per iteration. If a property name or object is provided it is used to
5631 * create a "_.property" or "_.matches" style callback respectively.
5632 * @param {*} [thisArg] The `this` binding of `predicate`.
5633 * @returns {*} Returns the matched element, else `undefined`.
5634 * @example
5635 *
5636 * _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; });
5637 * // => 3
5638 */
5639 function findLast(collection, predicate, thisArg) {
5640 predicate = getCallback(predicate, thisArg, 3);
5641 return baseFind(collection, predicate, baseEachRight);
5642 }
5643
5644 /**
5645 * Performs a deep comparison between each element in `collection` and the
5646 * source object, returning the first element that has equivalent property
5647 * values.
5648 *
5649 * @static
5650 * @memberOf _
5651 * @category Collection
5652 * @param {Array|Object|string} collection The collection to search.
5653 * @param {Object} source The object of property values to match.
5654 * @returns {*} Returns the matched element, else `undefined`.
5655 * @example
5656 *
5657 * var users = [
5658 * { 'user': 'barney', 'age': 36, 'status': 'busy' },
5659 * { 'user': 'fred', 'age': 40, 'status': 'busy' }
5660 * ];
5661 *
5662 * _.result(_.findWhere(users, { 'status': 'busy' }), 'user');
5663 * // => 'barney'
5664 *
5665 * _.result(_.findWhere(users, { 'age': 40 }), 'user');
5666 * // => 'fred'
5667 */
5668 function findWhere(collection, source) {
5669 return find(collection, matches(source));
5670 }
5671
5672 /**
5673 * Iterates over elements of `collection` invoking `iteratee` for each element.
5674 * The `iteratee` is bound to `thisArg` and invoked with three arguments;
5675 * (value, index|key, collection). Iterator functions may exit iteration early
5676 * by explicitly returning `false`.
5677 *
5678 * **Note:** As with other "Collections" methods, objects with a `length` property
5679 * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
5680 * may be used for object iteration.
5681 *
5682 * @static
5683 * @memberOf _
5684 * @alias each
5685 * @category Collection
5686 * @param {Array|Object|string} collection The collection to iterate over.
5687 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
5688 * @param {*} [thisArg] The `this` binding of `iteratee`.
5689 * @returns {Array|Object|string} Returns `collection`.
5690 * @example
5691 *
5692 * _([1, 2, 3]).forEach(function(n) { console.log(n); });
5693 * // => logs each value from left to right and returns the array
5694 *
5695 * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });
5696 * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
5697 */
5698 function forEach(collection, iteratee, thisArg) {
5699 return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
5700 ? arrayEach(collection, iteratee)
5701 : baseEach(collection, bindCallback(iteratee, thisArg, 3));
5702 }
5703
5704 /**
5705 * This method is like `_.forEach` except that it iterates over elements of
5706 * `collection` from right to left.
5707 *
5708 * @static
5709 * @memberOf _
5710 * @alias eachRight
5711 * @category Collection
5712 * @param {Array|Object|string} collection The collection to iterate over.
5713 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
5714 * @param {*} [thisArg] The `this` binding of `iteratee`.
5715 * @returns {Array|Object|string} Returns `collection`.
5716 * @example
5717 *
5718 * _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(',');
5719 * // => logs each value from right to left and returns the array
5720 */
5721 function forEachRight(collection, iteratee, thisArg) {
5722 return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
5723 ? arrayEachRight(collection, iteratee)
5724 : baseEachRight(collection, bindCallback(iteratee, thisArg, 3));
5725 }
5726
5727 /**
5728 * Creates an object composed of keys generated from the results of running
5729 * each element of `collection` through `iteratee`. The corresponding value
5730 * of each key is an array of the elements responsible for generating the key.
5731 * The `iteratee` is bound to `thisArg` and invoked with three arguments;
5732 * (value, index|key, collection).
5733 *
5734 * If a property name is provided for `predicate` the created "_.property"
5735 * style callback returns the property value of the given element.
5736 *
5737 * If an object is provided for `predicate` the created "_.matches" style
5738 * callback returns `true` for elements that have the properties of the given
5739 * object, else `false`.
5740 *
5741 * @static
5742 * @memberOf _
5743 * @category Collection
5744 * @param {Array|Object|string} collection The collection to iterate over.
5745 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5746 * per iteration. If a property name or object is provided it is used to
5747 * create a "_.property" or "_.matches" style callback respectively.
5748 * @param {*} [thisArg] The `this` binding of `iteratee`.
5749 * @returns {Object} Returns the composed aggregate object.
5750 * @example
5751 *
5752 * _.groupBy([4.2, 6.1, 6.4], function(n) { return Math.floor(n); });
5753 * // => { '4': [4.2], '6': [6.1, 6.4] }
5754 *
5755 * _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math);
5756 * // => { '4': [4.2], '6': [6.1, 6.4] }
5757 *
5758 * // using the "_.property" callback shorthand
5759 * _.groupBy(['one', 'two', 'three'], 'length');
5760 * // => { '3': ['one', 'two'], '5': ['three'] }
5761 */
5762 var groupBy = createAggregator(function(result, value, key) {
5763 if (hasOwnProperty.call(result, key)) {
5764 result[key].push(value);
5765 } else {
5766 result[key] = [value];
5767 }
5768 });
5769
5770 /**
5771 * Creates an object composed of keys generated from the results of running
5772 * each element of `collection` through `iteratee`. The corresponding value
5773 * of each key is the last element responsible for generating the key. The
5774 * iteratee function is bound to `thisArg` and invoked with three arguments;
5775 * (value, index|key, collection).
5776 *
5777 * If a property name is provided for `predicate` the created "_.property"
5778 * style callback returns the property value of the given element.
5779 *
5780 * If an object is provided for `predicate` the created "_.matches" style
5781 * callback returns `true` for elements that have the properties of the given
5782 * object, else `false`.
5783 *
5784 * @static
5785 * @memberOf _
5786 * @category Collection
5787 * @param {Array|Object|string} collection The collection to iterate over.
5788 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5789 * per iteration. If a property name or object is provided it is used to
5790 * create a "_.property" or "_.matches" style callback respectively.
5791 * @param {*} [thisArg] The `this` binding of `iteratee`.
5792 * @returns {Object} Returns the composed aggregate object.
5793 * @example
5794 *
5795 * var keyData = [
5796 * { 'dir': 'left', 'code': 97 },
5797 * { 'dir': 'right', 'code': 100 }
5798 * ];
5799 *
5800 * _.indexBy(keyData, 'dir');
5801 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
5802 *
5803 * _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); });
5804 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
5805 *
5806 * _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String);
5807 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
5808 */
5809 var indexBy = createAggregator(function(result, value, key) {
5810 result[key] = value;
5811 });
5812
5813 /**
5814 * Invokes the method named by `methodName` on each element in `collection`,
5815 * returning an array of the results of each invoked method. Any additional
5816 * arguments are provided to each invoked method. If `methodName` is a function
5817 * it is invoked for, and `this` bound to, each element in `collection`.
5818 *
5819 * @static
5820 * @memberOf _
5821 * @category Collection
5822 * @param {Array|Object|string} collection The collection to iterate over.
5823 * @param {Function|string} methodName The name of the method to invoke or
5824 * the function invoked per iteration.
5825 * @param {...*} [args] The arguments to invoke the method with.
5826 * @returns {Array} Returns the array of results.
5827 * @example
5828 *
5829 * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
5830 * // => [[1, 5, 7], [1, 2, 3]]
5831 *
5832 * _.invoke([123, 456], String.prototype.split, '');
5833 * // => [['1', '2', '3'], ['4', '5', '6']]
5834 */
5835 function invoke(collection, methodName) {
5836 return baseInvoke(collection, methodName, baseSlice(arguments, 2));
5837 }
5838
5839 /**
5840 * Creates an array of values by running each element in `collection` through
5841 * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
5842 * arguments; (value, index|key, collection).
5843 *
5844 * If a property name is provided for `predicate` the created "_.property"
5845 * style callback returns the property value of the given element.
5846 *
5847 * If an object is provided for `predicate` the created "_.matches" style
5848 * callback returns `true` for elements that have the properties of the given
5849 * object, else `false`.
5850 *
5851 * @static
5852 * @memberOf _
5853 * @alias collect
5854 * @category Collection
5855 * @param {Array|Object|string} collection The collection to iterate over.
5856 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5857 * per iteration. If a property name or object is provided it is used to
5858 * create a "_.property" or "_.matches" style callback respectively.
5859 * @param {*} [thisArg] The `this` binding of `iteratee`.
5860 * @returns {Array} Returns the new mapped array.
5861 * @example
5862 *
5863 * _.map([1, 2, 3], function(n) { return n * 3; });
5864 * // => [3, 6, 9]
5865 *
5866 * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; });
5867 * // => [3, 6, 9] (iteration order is not guaranteed)
5868 *
5869 * var users = [
5870 * { 'user': 'barney' },
5871 * { 'user': 'fred' }
5872 * ];
5873 *
5874 * // using the "_.property" callback shorthand
5875 * _.map(users, 'user');
5876 * // => ['barney', 'fred']
5877 */
5878 function map(collection, iteratee, thisArg) {
5879 var func = isArray(collection) ? arrayMap : baseMap;
5880 iteratee = getCallback(iteratee, thisArg, 3);
5881 return func(collection, iteratee);
5882 }
5883
5884 /**
5885 * Gets the maximum value of `collection`. If `collection` is empty or falsey
5886 * `-Infinity` is returned. If an iteratee function is provided it is invoked
5887 * for each value in `collection` to generate the criterion by which the value
5888 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
5889 * arguments; (value, index, collection).
5890 *
5891 * If a property name is provided for `predicate` the created "_.property"
5892 * style callback returns the property value of the given element.
5893 *
5894 * If an object is provided for `predicate` the created "_.matches" style
5895 * callback returns `true` for elements that have the properties of the given
5896 * object, else `false`.
5897 *
5898 * @static
5899 * @memberOf _
5900 * @category Collection
5901 * @param {Array|Object|string} collection The collection to iterate over.
5902 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
5903 * If a property name or object is provided it is used to create a "_.property"
5904 * or "_.matches" style callback respectively.
5905 * @param {*} [thisArg] The `this` binding of `iteratee`.
5906 * @returns {*} Returns the maximum value.
5907 * @example
5908 *
5909 * _.max([4, 2, 8, 6]);
5910 * // => 8
5911 *
5912 * _.max([]);
5913 * // => -Infinity
5914 *
5915 * var users = [
5916 * { 'user': 'barney', 'age': 36 },
5917 * { 'user': 'fred', 'age': 40 }
5918 * ];
5919 *
5920 * _.max(users, function(chr) { return chr.age; });
5921 * // => { 'user': 'fred', 'age': 40 };
5922 *
5923 * // using the "_.property" callback shorthand
5924 * _.max(users, 'age');
5925 * // => { 'user': 'fred', 'age': 40 };
5926 */
5927 var max = createExtremum(arrayMax);
5928
5929 /**
5930 * Gets the minimum value of `collection`. If `collection` is empty or falsey
5931 * `Infinity` is returned. If an iteratee function is provided it is invoked
5932 * for each value in `collection` to generate the criterion by which the value
5933 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
5934 * arguments; (value, index, collection).
5935 *
5936 * If a property name is provided for `predicate` the created "_.property"
5937 * style callback returns the property value of the given element.
5938 *
5939 * If an object is provided for `predicate` the created "_.matches" style
5940 * callback returns `true` for elements that have the properties of the given
5941 * object, else `false`.
5942 *
5943 * @static
5944 * @memberOf _
5945 * @category Collection
5946 * @param {Array|Object|string} collection The collection to iterate over.
5947 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
5948 * If a property name or object is provided it is used to create a "_.property"
5949 * or "_.matches" style callback respectively.
5950 * @param {*} [thisArg] The `this` binding of `iteratee`.
5951 * @returns {*} Returns the minimum value.
5952 * @example
5953 *
5954 * _.min([4, 2, 8, 6]);
5955 * // => 2
5956 *
5957 * _.min([]);
5958 * // => Infinity
5959 *
5960 * var users = [
5961 * { 'user': 'barney', 'age': 36 },
5962 * { 'user': 'fred', 'age': 40 }
5963 * ];
5964 *
5965 * _.min(users, function(chr) { return chr.age; });
5966 * // => { 'user': 'barney', 'age': 36 };
5967 *
5968 * // using the "_.property" callback shorthand
5969 * _.min(users, 'age');
5970 * // => { 'user': 'barney', 'age': 36 };
5971 */
5972 var min = createExtremum(arrayMin, true);
5973
5974 /**
5975 * Creates an array of elements split into two groups, the first of which
5976 * contains elements `predicate` returns truthy for, while the second of which
5977 * contains elements `predicate` returns falsey for. The predicate is bound
5978 * to `thisArg` and invoked with three arguments; (value, index|key, collection).
5979 *
5980 * If a property name is provided for `predicate` the created "_.property"
5981 * style callback returns the property value of the given element.
5982 *
5983 * If an object is provided for `predicate` the created "_.matches" style
5984 * callback returns `true` for elements that have the properties of the given
5985 * object, else `false`.
5986 *
5987 * @static
5988 * @memberOf _
5989 * @category Collection
5990 * @param {Array|Object|string} collection The collection to iterate over.
5991 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5992 * per iteration. If a property name or object is provided it is used to
5993 * create a "_.property" or "_.matches" style callback respectively.
5994 * @param {*} [thisArg] The `this` binding of `predicate`.
5995 * @returns {Array} Returns the array of grouped elements.
5996 * @example
5997 *
5998 * _.partition([1, 2, 3], function(n) { return n % 2; });
5999 * // => [[1, 3], [2]]
6000 *
6001 * _.partition([1.2, 2.3, 3.4], function(n) { return this.floor(n) % 2; }, Math);
6002 * // => [[1, 3], [2]]
6003 *
6004 * var users = [
6005 * { 'user': 'barney', 'age': 36, 'active': false },
6006 * { 'user': 'fred', 'age': 40, 'active': true },
6007 * { 'user': 'pebbles', 'age': 1, 'active': false }
6008 * ];
6009 *
6010 * // using the "_.matches" callback shorthand
6011 * _.map(_.partition(users, { 'age': 1 }), function(array) { return _.pluck(array, 'user'); });
6012 * // => [['pebbles'], ['barney', 'fred']]
6013 *
6014 * // using the "_.property" callback shorthand
6015 * _.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'user'); });
6016 * // => [['fred'], ['barney', 'pebbles']]
6017 */
6018 var partition = createAggregator(function(result, value, key) {
6019 result[key ? 0 : 1].push(value);
6020 }, function() { return [[], []]; });
6021
6022 /**
6023 * Gets the value of `key` from all elements in `collection`.
6024 *
6025 * @static
6026 * @memberOf _
6027 * @category Collection
6028 * @param {Array|Object|string} collection The collection to iterate over.
6029 * @param {string} key The key of the property to pluck.
6030 * @returns {Array} Returns the property values.
6031 * @example
6032 *
6033 * var users = [
6034 * { 'user': 'barney', 'age': 36 },
6035 * { 'user': 'fred', 'age': 40 }
6036 * ];
6037 *
6038 * _.pluck(users, 'user');
6039 * // => ['barney', 'fred']
6040 *
6041 * var userIndex = _.indexBy(users, 'user');
6042 * _.pluck(userIndex, 'age');
6043 * // => [36, 40] (iteration order is not guaranteed)
6044 */
6045 function pluck(collection, key) {
6046 return map(collection, property(key));
6047 }
6048
6049 /**
6050 * Reduces `collection` to a value which is the accumulated result of running
6051 * each element in `collection` through `iteratee`, where each successive
6052 * invocation is supplied the return value of the previous. If `accumulator`
6053 * is not provided the first element of `collection` is used as the initial
6054 * value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
6055 * (accumulator, value, index|key, collection).
6056 *
6057 * @static
6058 * @memberOf _
6059 * @alias foldl, inject
6060 * @category Collection
6061 * @param {Array|Object|string} collection The collection to iterate over.
6062 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6063 * @param {*} [accumulator] The initial value.
6064 * @param {*} [thisArg] The `this` binding of `iteratee`.
6065 * @returns {*} Returns the accumulated value.
6066 * @example
6067 *
6068 * var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; });
6069 * // => 6
6070 *
6071 * var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) {
6072 * result[key] = n * 3;
6073 * return result;
6074 * }, {});
6075 * // => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed)
6076 */
6077 function reduce(collection, iteratee, accumulator, thisArg) {
6078 var func = isArray(collection) ? arrayReduce : baseReduce;
6079 return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEach);
6080 }
6081
6082 /**
6083 * This method is like `_.reduce` except that it iterates over elements of
6084 * `collection` from right to left.
6085 *
6086 * @static
6087 * @memberOf _
6088 * @alias foldr
6089 * @category Collection
6090 * @param {Array|Object|string} collection The collection to iterate over.
6091 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6092 * @param {*} [accumulator] The initial value.
6093 * @param {*} [thisArg] The `this` binding of `iteratee`.
6094 * @returns {*} Returns the accumulated value.
6095 * @example
6096 *
6097 * var array = [[0, 1], [2, 3], [4, 5]];
6098 * _.reduceRight(array, function(flattened, other) { return flattened.concat(other); }, []);
6099 * // => [4, 5, 2, 3, 0, 1]
6100 */
6101 function reduceRight(collection, iteratee, accumulator, thisArg) {
6102 var func = isArray(collection) ? arrayReduceRight : baseReduce;
6103 return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEachRight);
6104 }
6105
6106 /**
6107 * The opposite of `_.filter`; this method returns the elements of `collection`
6108 * that `predicate` does **not** return truthy for.
6109 *
6110 * If a property name is provided for `predicate` the created "_.property"
6111 * style callback returns the property value of the given element.
6112 *
6113 * If an object is provided for `predicate` the created "_.matches" style
6114 * callback returns `true` for elements that have the properties of the given
6115 * object, else `false`.
6116 *
6117 * @static
6118 * @memberOf _
6119 * @category Collection
6120 * @param {Array|Object|string} collection The collection to iterate over.
6121 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6122 * per iteration. If a property name or object is provided it is used to
6123 * create a "_.property" or "_.matches" style callback respectively.
6124 * @param {*} [thisArg] The `this` binding of `predicate`.
6125 * @returns {Array} Returns the new filtered array.
6126 * @example
6127 *
6128 * var odds = _.reject([1, 2, 3, 4], function(n) { return n % 2 == 0; });
6129 * // => [1, 3]
6130 *
6131 * var users = [
6132 * { 'user': 'barney', 'age': 36, 'active': false },
6133 * { 'user': 'fred', 'age': 40, 'active': true }
6134 * ];
6135 *
6136 * // using the "_.property" callback shorthand
6137 * _.pluck(_.reject(users, 'active'), 'user');
6138 * // => ['barney']
6139 *
6140 * // using the "_.matches" callback shorthand
6141 * _.pluck(_.reject(users, { 'age': 36 }), 'user');
6142 * // => ['fred']
6143 */
6144 function reject(collection, predicate, thisArg) {
6145 var func = isArray(collection) ? arrayFilter : baseFilter;
6146 predicate = getCallback(predicate, thisArg, 3);
6147 return func(collection, function(value, index, collection) {
6148 return !predicate(value, index, collection);
6149 });
6150 }
6151
6152 /**
6153 * Gets a random element or `n` random elements from a collection.
6154 *
6155 * @static
6156 * @memberOf _
6157 * @category Collection
6158 * @param {Array|Object|string} collection The collection to sample.
6159 * @param {number} [n] The number of elements to sample.
6160 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6161 * @returns {*} Returns the random sample(s).
6162 * @example
6163 *
6164 * _.sample([1, 2, 3, 4]);
6165 * // => 2
6166 *
6167 * _.sample([1, 2, 3, 4], 2);
6168 * // => [3, 1]
6169 */
6170 function sample(collection, n, guard) {
6171 if (guard ? isIterateeCall(collection, n, guard) : n == null) {
6172 collection = toIterable(collection);
6173 var length = collection.length;
6174 return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
6175 }
6176 var result = shuffle(collection);
6177 result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
6178 return result;
6179 }
6180
6181 /**
6182 * Creates an array of shuffled values, using a version of the Fisher-Yates
6183 * shuffle. See [Wikipedia](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle)
6184 * for more details.
6185 *
6186 * @static
6187 * @memberOf _
6188 * @category Collection
6189 * @param {Array|Object|string} collection The collection to shuffle.
6190 * @returns {Array} Returns the new shuffled array.
6191 * @example
6192 *
6193 * _.shuffle([1, 2, 3, 4]);
6194 * // => [4, 1, 3, 2]
6195 */
6196 function shuffle(collection) {
6197 collection = toIterable(collection);
6198
6199 var index = -1,
6200 length = collection.length,
6201 result = Array(length);
6202
6203 while (++index < length) {
6204 var rand = baseRandom(0, index);
6205 if (index != rand) {
6206 result[index] = result[rand];
6207 }
6208 result[rand] = collection[index];
6209 }
6210 return result;
6211 }
6212
6213 /**
6214 * Gets the size of `collection` by returning `collection.length` for
6215 * array-like values or the number of own enumerable properties for objects.
6216 *
6217 * @static
6218 * @memberOf _
6219 * @category Collection
6220 * @param {Array|Object|string} collection The collection to inspect.
6221 * @returns {number} Returns the size of `collection`.
6222 * @example
6223 *
6224 * _.size([1, 2]);
6225 * // => 2
6226 *
6227 * _.size({ 'one': 1, 'two': 2, 'three': 3 });
6228 * // => 3
6229 *
6230 * _.size('pebbles');
6231 * // => 7
6232 */
6233 function size(collection) {
6234 var length = collection ? collection.length : 0;
6235 return isLength(length) ? length : keys(collection).length;
6236 }
6237
6238 /**
6239 * Checks if `predicate` returns truthy for **any** element of `collection`.
6240 * The function returns as soon as it finds a passing value and does not iterate
6241 * over the entire collection. The predicate is bound to `thisArg` and invoked
6242 * with three arguments; (value, index|key, collection).
6243 *
6244 * If a property name is provided for `predicate` the created "_.property"
6245 * style callback returns the property value of the given element.
6246 *
6247 * If an object is provided for `predicate` the created "_.matches" style
6248 * callback returns `true` for elements that have the properties of the given
6249 * object, else `false`.
6250 *
6251 * @static
6252 * @memberOf _
6253 * @alias any
6254 * @category Collection
6255 * @param {Array|Object|string} collection The collection to iterate over.
6256 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6257 * per iteration. If a property name or object is provided it is used to
6258 * create a "_.property" or "_.matches" style callback respectively.
6259 * @param {*} [thisArg] The `this` binding of `predicate`.
6260 * @returns {boolean} Returns `true` if any element passes the predicate check,
6261 * else `false`.
6262 * @example
6263 *
6264 * _.some([null, 0, 'yes', false], Boolean);
6265 * // => true
6266 *
6267 * var users = [
6268 * { 'user': 'barney', 'age': 36, 'active': false },
6269 * { 'user': 'fred', 'age': 40, 'active': true }
6270 * ];
6271 *
6272 * // using the "_.property" callback shorthand
6273 * _.some(users, 'active');
6274 * // => true
6275 *
6276 * // using the "_.matches" callback shorthand
6277 * _.some(users, { 'age': 1 });
6278 * // => false
6279 */
6280 function some(collection, predicate, thisArg) {
6281 var func = isArray(collection) ? arraySome : baseSome;
6282 if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
6283 predicate = getCallback(predicate, thisArg, 3);
6284 }
6285 return func(collection, predicate);
6286 }
6287
6288 /**
6289 * Creates an array of elements, sorted in ascending order by the results of
6290 * running each element in a collection through `iteratee`. This method performs
6291 * a stable sort, that is, it preserves the original sort order of equal elements.
6292 * The `iteratee` is bound to `thisArg` and invoked with three arguments;
6293 * (value, index|key, collection).
6294 *
6295 * If a property name is provided for `predicate` the created "_.property"
6296 * style callback returns the property value of the given element.
6297 *
6298 * If an object is provided for `predicate` the created "_.matches" style
6299 * callback returns `true` for elements that have the properties of the given
6300 * object, else `false`.
6301 *
6302 * @static
6303 * @memberOf _
6304 * @category Collection
6305 * @param {Array|Object|string} collection The collection to iterate over.
6306 * @param {Array|Function|Object|string} [iteratee=_.identity] The function
6307 * invoked per iteration. If a property name or an object is provided it is
6308 * used to create a "_.property" or "_.matches" style callback respectively.
6309 * @param {*} [thisArg] The `this` binding of `iteratee`.
6310 * @returns {Array} Returns the new sorted array.
6311 * @example
6312 *
6313 * _.sortBy([1, 2, 3], function(n) { return Math.sin(n); });
6314 * // => [3, 1, 2]
6315 *
6316 * _.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math);
6317 * // => [3, 1, 2]
6318 *
6319 * var users = [
6320 * { 'user': 'fred' },
6321 * { 'user': 'pebbles' },
6322 * { 'user': 'barney' }
6323 * ];
6324 *
6325 * // using the "_.property" callback shorthand
6326 * _.pluck(_.sortBy(users, 'user'), 'user');
6327 * // => ['barney', 'fred', 'pebbles']
6328 */
6329 function sortBy(collection, iteratee, thisArg) {
6330 var index = -1,
6331 length = collection ? collection.length : 0,
6332 result = isLength(length) ? Array(length) : [];
6333
6334 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
6335 iteratee = null;
6336 }
6337 iteratee = getCallback(iteratee, thisArg, 3);
6338 baseEach(collection, function(value, key, collection) {
6339 result[++index] = { 'criteria': iteratee(value, key, collection), 'index': index, 'value': value };
6340 });
6341 return baseSortBy(result, compareAscending);
6342 }
6343
6344 /**
6345 * This method is like `_.sortBy` except that it sorts by property names
6346 * instead of an iteratee function.
6347 *
6348 * @static
6349 * @memberOf _
6350 * @category Collection
6351 * @param {Array|Object|string} collection The collection to iterate over.
6352 * @param {...(string|string[])} props The property names to sort by,
6353 * specified as individual property names or arrays of property names.
6354 * @returns {Array} Returns the new sorted array.
6355 * @example
6356 *
6357 * var users = [
6358 * { 'user': 'barney', 'age': 36 },
6359 * { 'user': 'fred', 'age': 40 },
6360 * { 'user': 'barney', 'age': 26 },
6361 * { 'user': 'fred', 'age': 30 }
6362 * ];
6363 *
6364 * _.map(_.sortByAll(users, ['user', 'age']), _.values);
6365 * // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
6366 */
6367 function sortByAll(collection) {
6368 var args = arguments;
6369 if (args.length > 3 && isIterateeCall(args[1], args[2], args[3])) {
6370 args = [collection, args[1]];
6371 }
6372 var index = -1,
6373 length = collection ? collection.length : 0,
6374 props = baseFlatten(args, false, false, 1),
6375 result = isLength(length) ? Array(length) : [];
6376
6377 baseEach(collection, function(value, key, collection) {
6378 var length = props.length,
6379 criteria = Array(length);
6380
6381 while (length--) {
6382 criteria[length] = value == null ? undefined : value[props[length]];
6383 }
6384 result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
6385 });
6386 return baseSortBy(result, compareMultipleAscending);
6387 }
6388
6389 /**
6390 * Performs a deep comparison between each element in `collection` and the
6391 * source object, returning an array of all elements that have equivalent
6392 * property values.
6393 *
6394 * @static
6395 * @memberOf _
6396 * @category Collection
6397 * @param {Array|Object|string} collection The collection to search.
6398 * @param {Object} source The object of property values to match.
6399 * @returns {Array} Returns the new filtered array.
6400 * @example
6401 *
6402 * var users = [
6403 * { 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] },
6404 * { 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] }
6405 * ];
6406 *
6407 * _.pluck(_.where(users, { 'age': 36 }), 'user');
6408 * // => ['barney']
6409 *
6410 * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
6411 * // => ['fred']
6412 *
6413 * _.pluck(_.where(users, { 'status': 'busy' }), 'user');
6414 * // => ['barney', 'fred']
6415 */
6416 function where(collection, source) {
6417 return filter(collection, matches(source));
6418 }
6419
6420 /*------------------------------------------------------------------------*/
6421
6422 /**
6423 * Gets the number of milliseconds that have elapsed since the Unix epoch
6424 * (1 January 1970 00:00:00 UTC).
6425 *
6426 * @static
6427 * @memberOf _
6428 * @category Date
6429 * @example
6430 *
6431 * _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now());
6432 * // => logs the number of milliseconds it took for the deferred function to be invoked
6433 */
6434 var now = nativeNow || function() {
6435 return new Date().getTime();
6436 };
6437
6438 /*------------------------------------------------------------------------*/
6439
6440 /**
6441 * The opposite of `_.before`; this method creates a function that invokes
6442 * `func` once it is called `n` or more times.
6443 *
6444 * @static
6445 * @memberOf _
6446 * @category Function
6447 * @param {number} n The number of calls before `func` is invoked.
6448 * @param {Function} func The function to restrict.
6449 * @returns {Function} Returns the new restricted function.
6450 * @example
6451 *
6452 * var saves = ['profile', 'settings'];
6453 *
6454 * var done = _.after(saves.length, function() {
6455 * console.log('done saving!');
6456 * });
6457 *
6458 * _.forEach(saves, function(type) {
6459 * asyncSave({ 'type': type, 'complete': done });
6460 * });
6461 * // => logs 'done saving!' after the two async saves have completed
6462 */
6463 function after(n, func) {
6464 if (!isFunction(func)) {
6465 if (isFunction(n)) {
6466 var temp = n;
6467 n = func;
6468 func = temp;
6469 } else {
6470 throw new TypeError(FUNC_ERROR_TEXT);
6471 }
6472 }
6473 n = nativeIsFinite(n = +n) ? n : 0;
6474 return function() {
6475 if (--n < 1) {
6476 return func.apply(this, arguments);
6477 }
6478 };
6479 }
6480
6481 /**
6482 * Creates a function that accepts up to `n` arguments ignoring any
6483 * additional arguments.
6484 *
6485 * @static
6486 * @memberOf _
6487 * @category Function
6488 * @param {Function} func The function to cap arguments for.
6489 * @param {number} [n=func.length] The arity cap.
6490 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6491 * @returns {Function} Returns the new function.
6492 * @example
6493 *
6494 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
6495 * // => [6, 8, 10]
6496 */
6497 function ary(func, n, guard) {
6498 if (guard && isIterateeCall(func, n, guard)) {
6499 n = null;
6500 }
6501 n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
6502 return createWrapper(func, ARY_FLAG, null, null, null, null, n);
6503 }
6504
6505 /**
6506 * Creates a function that invokes `func`, with the `this` binding and arguments
6507 * of the created function, while it is called less than `n` times. Subsequent
6508 * calls to the created function return the result of the last `func` invocation.
6509 *
6510 * @static
6511 * @memberOf _
6512 * @category Function
6513 * @param {number} n The number of calls at which `func` is no longer invoked.
6514 * @param {Function} func The function to restrict.
6515 * @returns {Function} Returns the new restricted function.
6516 * @example
6517 *
6518 * jQuery('#add').on('click', _.before(5, addContactToList));
6519 * // => allows adding up to 4 contacts to the list
6520 */
6521 function before(n, func) {
6522 var result;
6523 if (!isFunction(func)) {
6524 if (isFunction(n)) {
6525 var temp = n;
6526 n = func;
6527 func = temp;
6528 } else {
6529 throw new TypeError(FUNC_ERROR_TEXT);
6530 }
6531 }
6532 return function() {
6533 if (--n > 0) {
6534 result = func.apply(this, arguments);
6535 } else {
6536 func = null;
6537 }
6538 return result;
6539 };
6540 }
6541
6542 /**
6543 * Creates a function that invokes `func` with the `this` binding of `thisArg`
6544 * and prepends any additional `_.bind` arguments to those provided to the
6545 * bound function.
6546 *
6547 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
6548 * may be used as a placeholder for partially applied arguments.
6549 *
6550 * **Note:** Unlike native `Function#bind` this method does not set the `length`
6551 * property of bound functions.
6552 *
6553 * @static
6554 * @memberOf _
6555 * @category Function
6556 * @param {Function} func The function to bind.
6557 * @param {*} thisArg The `this` binding of `func`.
6558 * @param {...*} [args] The arguments to be partially applied.
6559 * @returns {Function} Returns the new bound function.
6560 * @example
6561 *
6562 * var greet = function(greeting, punctuation) {
6563 * return greeting + ' ' + this.user + punctuation;
6564 * };
6565 *
6566 * var object = { 'user': 'fred' };
6567 *
6568 * var bound = _.bind(greet, object, 'hi');
6569 * bound('!');
6570 * // => 'hi fred!'
6571 *
6572 * // using placeholders
6573 * var bound = _.bind(greet, object, _, '!');
6574 * bound('hi');
6575 * // => 'hi fred!'
6576 */
6577 function bind(func, thisArg) {
6578 var bitmask = BIND_FLAG;
6579 if (arguments.length > 2) {
6580 var partials = baseSlice(arguments, 2),
6581 holders = replaceHolders(partials, bind.placeholder);
6582
6583 bitmask |= PARTIAL_FLAG;
6584 }
6585 return createWrapper(func, bitmask, thisArg, partials, holders);
6586 }
6587
6588 /**
6589 * Binds methods of an object to the object itself, overwriting the existing
6590 * method. Method names may be specified as individual arguments or as arrays
6591 * of method names. If no method names are provided all enumerable function
6592 * properties, own and inherited, of `object` are bound.
6593 *
6594 * **Note:** This method does not set the `length` property of bound functions.
6595 *
6596 * @static
6597 * @memberOf _
6598 * @category Function
6599 * @param {Object} object The object to bind and assign the bound methods to.
6600 * @param {...(string|string[])} [methodNames] The object method names to bind,
6601 * specified as individual method names or arrays of method names.
6602 * @returns {Object} Returns `object`.
6603 * @example
6604 *
6605 * var view = {
6606 * 'label': 'docs',
6607 * 'onClick': function() { console.log('clicked ' + this.label); }
6608 * };
6609 *
6610 * _.bindAll(view);
6611 * jQuery('#docs').on('click', view.onClick);
6612 * // => logs 'clicked docs' when the element is clicked
6613 */
6614 function bindAll(object) {
6615 return baseBindAll(object,
6616 arguments.length > 1
6617 ? baseFlatten(arguments, false, false, 1)
6618 : functions(object)
6619 );
6620 }
6621
6622 /**
6623 * Creates a function that invokes the method at `object[key]` and prepends
6624 * any additional `_.bindKey` arguments to those provided to the bound function.
6625 *
6626 * This method differs from `_.bind` by allowing bound functions to reference
6627 * methods that may be redefined or don't yet exist.
6628 * See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern)
6629 * for more details.
6630 *
6631 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
6632 * builds, may be used as a placeholder for partially applied arguments.
6633 *
6634 * @static
6635 * @memberOf _
6636 * @category Function
6637 * @param {Object} object The object the method belongs to.
6638 * @param {string} key The key of the method.
6639 * @param {...*} [args] The arguments to be partially applied.
6640 * @returns {Function} Returns the new bound function.
6641 * @example
6642 *
6643 * var object = {
6644 * 'user': 'fred',
6645 * 'greet': function(greeting, punctuation) {
6646 * return greeting + ' ' + this.user + punctuation;
6647 * }
6648 * };
6649 *
6650 * var bound = _.bindKey(object, 'greet', 'hi');
6651 * bound('!');
6652 * // => 'hi fred!'
6653 *
6654 * object.greet = function(greeting, punctuation) {
6655 * return greeting + 'ya ' + this.user + punctuation;
6656 * };
6657 *
6658 * bound('!');
6659 * // => 'hiya fred!'
6660 *
6661 * // using placeholders
6662 * var bound = _.bindKey(object, 'greet', _, '!');
6663 * bound('hi');
6664 * // => 'hiya fred!'
6665 */
6666 function bindKey(object, key) {
6667 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
6668 if (arguments.length > 2) {
6669 var partials = baseSlice(arguments, 2),
6670 holders = replaceHolders(partials, bindKey.placeholder);
6671
6672 bitmask |= PARTIAL_FLAG;
6673 }
6674 return createWrapper(key, bitmask, object, partials, holders);
6675 }
6676
6677 /**
6678 * Creates a function that accepts one or more arguments of `func` that when
6679 * called either invokes `func` returning its result, if all `func` arguments
6680 * have been provided, or returns a function that accepts one or more of the
6681 * remaining `func` arguments, and so on. The arity of `func` may be specified
6682 * if `func.length` is not sufficient.
6683 *
6684 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
6685 * may be used as a placeholder for provided arguments.
6686 *
6687 * **Note:** This method does not set the `length` property of curried functions.
6688 *
6689 * @static
6690 * @memberOf _
6691 * @category Function
6692 * @param {Function} func The function to curry.
6693 * @param {number} [arity=func.length] The arity of `func`.
6694 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6695 * @returns {Function} Returns the new curried function.
6696 * @example
6697 *
6698 * var abc = function(a, b, c) {
6699 * return [a, b, c];
6700 * };
6701 *
6702 * var curried = _.curry(abc);
6703 *
6704 * curried(1)(2)(3);
6705 * // => [1, 2, 3]
6706 *
6707 * curried(1, 2)(3);
6708 * // => [1, 2, 3]
6709 *
6710 * curried(1, 2, 3);
6711 * // => [1, 2, 3]
6712 *
6713 * // using placeholders
6714 * curried(1)(_, 3)(2);
6715 * // => [1, 2, 3]
6716 */
6717 function curry(func, arity, guard) {
6718 if (guard && isIterateeCall(func, arity, guard)) {
6719 arity = null;
6720 }
6721 var result = createWrapper(func, CURRY_FLAG, null, null, null, null, null, arity);
6722 result.placeholder = curry.placeholder;
6723 return result;
6724 }
6725
6726 /**
6727 * This method is like `_.curry` except that arguments are applied to `func`
6728 * in the manner of `_.partialRight` instead of `_.partial`.
6729 *
6730 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
6731 * builds, may be used as a placeholder for provided arguments.
6732 *
6733 * **Note:** This method does not set the `length` property of curried functions.
6734 *
6735 * @static
6736 * @memberOf _
6737 * @category Function
6738 * @param {Function} func The function to curry.
6739 * @param {number} [arity=func.length] The arity of `func`.
6740 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6741 * @returns {Function} Returns the new curried function.
6742 * @example
6743 *
6744 * var abc = function(a, b, c) {
6745 * return [a, b, c];
6746 * };
6747 *
6748 * var curried = _.curryRight(abc);
6749 *
6750 * curried(3)(2)(1);
6751 * // => [1, 2, 3]
6752 *
6753 * curried(2, 3)(1);
6754 * // => [1, 2, 3]
6755 *
6756 * curried(1, 2, 3);
6757 * // => [1, 2, 3]
6758 *
6759 * // using placeholders
6760 * curried(3)(1, _)(2);
6761 * // => [1, 2, 3]
6762 */
6763 function curryRight(func, arity, guard) {
6764 if (guard && isIterateeCall(func, arity, guard)) {
6765 arity = null;
6766 }
6767 var result = createWrapper(func, CURRY_RIGHT_FLAG, null, null, null, null, null, arity);
6768 result.placeholder = curryRight.placeholder;
6769 return result;
6770 }
6771
6772 /**
6773 * Creates a function that delays invoking `func` until after `wait` milliseconds
6774 * have elapsed since the last time it was invoked. The created function comes
6775 * with a `cancel` method to cancel delayed invocations. Provide an options
6776 * object to indicate that `func` should be invoked on the leading and/or
6777 * trailing edge of the `wait` timeout. Subsequent calls to the debounced
6778 * function return the result of the last `func` invocation.
6779 *
6780 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
6781 * on the trailing edge of the timeout only if the the debounced function is
6782 * invoked more than once during the `wait` timeout.
6783 *
6784 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
6785 * for details over the differences between `_.debounce` and `_.throttle`.
6786 *
6787 * @static
6788 * @memberOf _
6789 * @category Function
6790 * @param {Function} func The function to debounce.
6791 * @param {number} wait The number of milliseconds to delay.
6792 * @param {Object} [options] The options object.
6793 * @param {boolean} [options.leading=false] Specify invoking on the leading
6794 * edge of the timeout.
6795 * @param {number} [options.maxWait] The maximum time `func` is allowed to be
6796 * delayed before it is invoked.
6797 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
6798 * edge of the timeout.
6799 * @returns {Function} Returns the new debounced function.
6800 * @example
6801 *
6802 * // avoid costly calculations while the window size is in flux
6803 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
6804 *
6805 * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
6806 * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
6807 * 'leading': true,
6808 * 'trailing': false
6809 * }));
6810 *
6811 * // ensure `batchLog` is invoked once after 1 second of debounced calls
6812 * var source = new EventSource('/stream');
6813 * jQuery(source).on('message', _.debounce(batchLog, 250, {
6814 * 'maxWait': 1000
6815 * }));
6816 *
6817 * // cancel a debounced call
6818 * var todoChanges = _.debounce(batchLog, 1000);
6819 * Object.observe(models.todo, todoChanges);
6820 *
6821 * Object.observe(models, function(changes) {
6822 * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
6823 * todoChanges.cancel();
6824 * }
6825 * }, ['delete']);
6826 *
6827 * // ...at some point `models.todo` is changed
6828 * models.todo.completed = true;
6829 *
6830 * // ...before 1 second has passed `models.todo` is deleted
6831 * // which cancels the debounced `todoChanges` call
6832 * delete models.todo;
6833 */
6834 function debounce(func, wait, options) {
6835 var args,
6836 maxTimeoutId,
6837 result,
6838 stamp,
6839 thisArg,
6840 timeoutId,
6841 trailingCall,
6842 lastCalled = 0,
6843 maxWait = false,
6844 trailing = true;
6845
6846 if (!isFunction(func)) {
6847 throw new TypeError(FUNC_ERROR_TEXT);
6848 }
6849 wait = wait < 0 ? 0 : wait;
6850 if (options === true) {
6851 var leading = true;
6852 trailing = false;
6853 } else if (isObject(options)) {
6854 leading = options.leading;
6855 maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
6856 trailing = 'trailing' in options ? options.trailing : trailing;
6857 }
6858
6859 function cancel() {
6860 if (timeoutId) {
6861 clearTimeout(timeoutId);
6862 }
6863 if (maxTimeoutId) {
6864 clearTimeout(maxTimeoutId);
6865 }
6866 maxTimeoutId = timeoutId = trailingCall = undefined;
6867 }
6868
6869 function delayed() {
6870 var remaining = wait - (now() - stamp);
6871 if (remaining <= 0 || remaining > wait) {
6872 if (maxTimeoutId) {
6873 clearTimeout(maxTimeoutId);
6874 }
6875 var isCalled = trailingCall;
6876 maxTimeoutId = timeoutId = trailingCall = undefined;
6877 if (isCalled) {
6878 lastCalled = now();
6879 result = func.apply(thisArg, args);
6880 if (!timeoutId && !maxTimeoutId) {
6881 args = thisArg = null;
6882 }
6883 }
6884 } else {
6885 timeoutId = setTimeout(delayed, remaining);
6886 }
6887 }
6888
6889 function maxDelayed() {
6890 if (timeoutId) {
6891 clearTimeout(timeoutId);
6892 }
6893 maxTimeoutId = timeoutId = trailingCall = undefined;
6894 if (trailing || (maxWait !== wait)) {
6895 lastCalled = now();
6896 result = func.apply(thisArg, args);
6897 if (!timeoutId && !maxTimeoutId) {
6898 args = thisArg = null;
6899 }
6900 }
6901 }
6902
6903 function debounced() {
6904 args = arguments;
6905 stamp = now();
6906 thisArg = this;
6907 trailingCall = trailing && (timeoutId || !leading);
6908
6909 if (maxWait === false) {
6910 var leadingCall = leading && !timeoutId;
6911 } else {
6912 if (!maxTimeoutId && !leading) {
6913 lastCalled = stamp;
6914 }
6915 var remaining = maxWait - (stamp - lastCalled),
6916 isCalled = remaining <= 0 || remaining > maxWait;
6917
6918 if (isCalled) {
6919 if (maxTimeoutId) {
6920 maxTimeoutId = clearTimeout(maxTimeoutId);
6921 }
6922 lastCalled = stamp;
6923 result = func.apply(thisArg, args);
6924 }
6925 else if (!maxTimeoutId) {
6926 maxTimeoutId = setTimeout(maxDelayed, remaining);
6927 }
6928 }
6929 if (isCalled && timeoutId) {
6930 timeoutId = clearTimeout(timeoutId);
6931 }
6932 else if (!timeoutId && wait !== maxWait) {
6933 timeoutId = setTimeout(delayed, wait);
6934 }
6935 if (leadingCall) {
6936 isCalled = true;
6937 result = func.apply(thisArg, args);
6938 }
6939 if (isCalled && !timeoutId && !maxTimeoutId) {
6940 args = thisArg = null;
6941 }
6942 return result;
6943 }
6944 debounced.cancel = cancel;
6945 return debounced;
6946 }
6947
6948 /**
6949 * Defers invoking the `func` until the current call stack has cleared. Any
6950 * additional arguments are provided to `func` when it is invoked.
6951 *
6952 * @static
6953 * @memberOf _
6954 * @category Function
6955 * @param {Function} func The function to defer.
6956 * @param {...*} [args] The arguments to invoke the function with.
6957 * @returns {number} Returns the timer id.
6958 * @example
6959 *
6960 * _.defer(function(text) { console.log(text); }, 'deferred');
6961 * // logs 'deferred' after one or more milliseconds
6962 */
6963 function defer(func) {
6964 return baseDelay(func, 1, arguments, 1);
6965 }
6966
6967 /**
6968 * Invokes `func` after `wait` milliseconds. Any additional arguments are
6969 * provided to `func` when it is invoked.
6970 *
6971 * @static
6972 * @memberOf _
6973 * @category Function
6974 * @param {Function} func The function to delay.
6975 * @param {number} wait The number of milliseconds to delay invocation.
6976 * @param {...*} [args] The arguments to invoke the function with.
6977 * @returns {number} Returns the timer id.
6978 * @example
6979 *
6980 * _.delay(function(text) { console.log(text); }, 1000, 'later');
6981 * // => logs 'later' after one second
6982 */
6983 function delay(func, wait) {
6984 return baseDelay(func, wait, arguments, 2);
6985 }
6986
6987 /**
6988 * Creates a function that returns the result of invoking the provided
6989 * functions with the `this` binding of the created function, where each
6990 * successive invocation is supplied the return value of the previous.
6991 *
6992 * @static
6993 * @memberOf _
6994 * @category Function
6995 * @param {...Function} [funcs] Functions to invoke.
6996 * @returns {Function} Returns the new function.
6997 * @example
6998 *
6999 * function add(x, y) {
7000 * return x + y;
7001 * }
7002 *
7003 * function square(n) {
7004 * return n * n;
7005 * }
7006 *
7007 * var addSquare = _.flow(add, square);
7008 * addSquare(1, 2);
7009 * // => 9
7010 */
7011 function flow() {
7012 var funcs = arguments,
7013 length = funcs.length;
7014
7015 if (!length) {
7016 return function() {};
7017 }
7018 if (!arrayEvery(funcs, isFunction)) {
7019 throw new TypeError(FUNC_ERROR_TEXT);
7020 }
7021 return function() {
7022 var index = 0,
7023 result = funcs[index].apply(this, arguments);
7024
7025 while (++index < length) {
7026 result = funcs[index].call(this, result);
7027 }
7028 return result;
7029 };
7030 }
7031
7032 /**
7033 * This method is like `_.flow` except that it creates a function that
7034 * invokes the provided functions from right to left.
7035 *
7036 * @static
7037 * @memberOf _
7038 * @alias backflow, compose
7039 * @category Function
7040 * @param {...Function} [funcs] Functions to invoke.
7041 * @returns {Function} Returns the new function.
7042 * @example
7043 *
7044 * function add(x, y) {
7045 * return x + y;
7046 * }
7047 *
7048 * function square(n) {
7049 * return n * n;
7050 * }
7051 *
7052 * var addSquare = _.flowRight(square, add);
7053 * addSquare(1, 2);
7054 * // => 9
7055 */
7056 function flowRight() {
7057 var funcs = arguments,
7058 fromIndex = funcs.length - 1;
7059
7060 if (fromIndex < 0) {
7061 return function() {};
7062 }
7063 if (!arrayEvery(funcs, isFunction)) {
7064 throw new TypeError(FUNC_ERROR_TEXT);
7065 }
7066 return function() {
7067 var index = fromIndex,
7068 result = funcs[index].apply(this, arguments);
7069
7070 while (index--) {
7071 result = funcs[index].call(this, result);
7072 }
7073 return result;
7074 };
7075 }
7076
7077 /**
7078 * Creates a function that memoizes the result of `func`. If `resolver` is
7079 * provided it determines the cache key for storing the result based on the
7080 * arguments provided to the memoized function. By default, the first argument
7081 * provided to the memoized function is coerced to a string and used as the
7082 * cache key. The `func` is invoked with the `this` binding of the memoized
7083 * function.
7084 *
7085 * **Note:** The cache is exposed as the `cache` property on the memoized
7086 * function. Its creation may be customized by replacing the `_.memoize.Cache`
7087 * constructor with one whose instances implement the ES `Map` method interface
7088 * of `get`, `has`, and `set`. See the
7089 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
7090 * for more details.
7091 *
7092 * @static
7093 * @memberOf _
7094 * @category Function
7095 * @param {Function} func The function to have its output memoized.
7096 * @param {Function} [resolver] The function to resolve the cache key.
7097 * @returns {Function} Returns the new memoizing function.
7098 * @example
7099 *
7100 * var upperCase = _.memoize(function(string) {
7101 * return string.toUpperCase();
7102 * });
7103 *
7104 * upperCase('fred');
7105 * // => 'FRED'
7106 *
7107 * // modifying the result cache
7108 * upperCase.cache.set('fred, 'BARNEY');
7109 * upperCase('fred');
7110 * // => 'BARNEY'
7111 *
7112 * // replacing `_.memoize.Cache`
7113 * var object = { 'user': 'fred' };
7114 * var other = { 'user': 'barney' };
7115 * var identity = _.memoize(_.identity);
7116 *
7117 * identity(object);
7118 * // => { 'user': 'fred' }
7119 * identity(other);
7120 * // => { 'user': 'fred' }
7121 *
7122 * _.memoize.Cache = WeakMap;
7123 * var identity = _.memoize(_.identity);
7124 *
7125 * identity(object);
7126 * // => { 'user': 'fred' }
7127 * identity(other);
7128 * // => { 'user': 'barney' }
7129 */
7130 function memoize(func, resolver) {
7131 if (!isFunction(func) || (resolver && !isFunction(resolver))) {
7132 throw new TypeError(FUNC_ERROR_TEXT);
7133 }
7134 var memoized = function() {
7135 var cache = memoized.cache,
7136 key = resolver ? resolver.apply(this, arguments) : arguments[0];
7137
7138 if (cache.has(key)) {
7139 return cache.get(key);
7140 }
7141 var result = func.apply(this, arguments);
7142 cache.set(key, result);
7143 return result;
7144 };
7145 memoized.cache = new memoize.Cache;
7146 return memoized;
7147 }
7148
7149 /**
7150 * Creates a function that negates the result of the predicate `func`. The
7151 * `func` predicate is invoked with the `this` binding and arguments of the
7152 * created function.
7153 *
7154 * @static
7155 * @memberOf _
7156 * @category Function
7157 * @param {Function} predicate The predicate to negate.
7158 * @returns {Function} Returns the new function.
7159 * @example
7160 *
7161 * function isEven(n) {
7162 * return n % 2 == 0;
7163 * }
7164 *
7165 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
7166 * // => [1, 3, 5]
7167 */
7168 function negate(predicate) {
7169 if (!isFunction(predicate)) {
7170 throw new TypeError(FUNC_ERROR_TEXT);
7171 }
7172 return function() {
7173 return !predicate.apply(this, arguments);
7174 };
7175 }
7176
7177 /**
7178 * Creates a function that is restricted to invoking `func` once. Repeat calls
7179 * to the function return the value of the first call. The `func` is invoked
7180 * with the `this` binding of the created function.
7181 *
7182 * @static
7183 * @memberOf _
7184 * @type Function
7185 * @category Function
7186 * @param {Function} func The function to restrict.
7187 * @returns {Function} Returns the new restricted function.
7188 * @example
7189 *
7190 * var initialize = _.once(createApplication);
7191 * initialize();
7192 * initialize();
7193 * // `initialize` invokes `createApplication` once
7194 */
7195 function once(func) {
7196 return before(func, 2);
7197 }
7198
7199 /**
7200 * Creates a function that invokes `func` with `partial` arguments prepended
7201 * to those provided to the new function. This method is like `_.bind` except
7202 * it does **not** alter the `this` binding.
7203 *
7204 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
7205 * builds, may be used as a placeholder for partially applied arguments.
7206 *
7207 * **Note:** This method does not set the `length` property of partially
7208 * applied functions.
7209 *
7210 * @static
7211 * @memberOf _
7212 * @category Function
7213 * @param {Function} func The function to partially apply arguments to.
7214 * @param {...*} [args] The arguments to be partially applied.
7215 * @returns {Function} Returns the new partially applied function.
7216 * @example
7217 *
7218 * var greet = function(greeting, name) {
7219 * return greeting + ' ' + name;
7220 * };
7221 *
7222 * var sayHelloTo = _.partial(greet, 'hello');
7223 * sayHelloTo('fred');
7224 * // => 'hello fred'
7225 *
7226 * // using placeholders
7227 * var greetFred = _.partial(greet, _, 'fred');
7228 * greetFred('hi');
7229 * // => 'hi fred'
7230 */
7231 function partial(func) {
7232 var partials = baseSlice(arguments, 1),
7233 holders = replaceHolders(partials, partial.placeholder);
7234
7235 return createWrapper(func, PARTIAL_FLAG, null, partials, holders);
7236 }
7237
7238 /**
7239 * This method is like `_.partial` except that partially applied arguments
7240 * are appended to those provided to the new function.
7241 *
7242 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
7243 * builds, may be used as a placeholder for partially applied arguments.
7244 *
7245 * **Note:** This method does not set the `length` property of partially
7246 * applied functions.
7247 *
7248 * @static
7249 * @memberOf _
7250 * @category Function
7251 * @param {Function} func The function to partially apply arguments to.
7252 * @param {...*} [args] The arguments to be partially applied.
7253 * @returns {Function} Returns the new partially applied function.
7254 * @example
7255 *
7256 * var greet = function(greeting, name) {
7257 * return greeting + ' ' + name;
7258 * };
7259 *
7260 * var greetFred = _.partialRight(greet, 'fred');
7261 * greetFred('hi');
7262 * // => 'hi fred'
7263 *
7264 * // using placeholders
7265 * var sayHelloTo = _.partialRight(greet, 'hello', _);
7266 * sayHelloTo('fred');
7267 * // => 'hello fred'
7268 */
7269 function partialRight(func) {
7270 var partials = baseSlice(arguments, 1),
7271 holders = replaceHolders(partials, partialRight.placeholder);
7272
7273 return createWrapper(func, PARTIAL_RIGHT_FLAG, null, partials, holders);
7274 }
7275
7276 /**
7277 * Creates a function that invokes `func` with arguments arranged according
7278 * to the specified indexes where the argument value at the first index is
7279 * provided as the first argument, the argument value at the second index is
7280 * provided as the second argument, and so on.
7281 *
7282 * @static
7283 * @memberOf _
7284 * @category Function
7285 * @param {Function} func The function to rearrange arguments for.
7286 * @param {...(number|number[])} indexes The arranged argument indexes,
7287 * specified as individual indexes or arrays of indexes.
7288 * @returns {Function} Returns the new function.
7289 * @example
7290 *
7291 * var rearged = _.rearg(function(a, b, c) {
7292 * return [a, b, c];
7293 * }, 2, 0, 1);
7294 *
7295 * rearged('b', 'c', 'a')
7296 * // => ['a', 'b', 'c']
7297 *
7298 * var map = _.rearg(_.map, [1, 0]);
7299 * map(function(n) { return n * 3; }, [1, 2, 3]);
7300 * // => [3, 6, 9]
7301 */
7302 function rearg(func) {
7303 var indexes = baseFlatten(arguments, false, false, 1);
7304 return createWrapper(func, REARG_FLAG, null, null, null, indexes);
7305 }
7306
7307 /**
7308 * Creates a function that only invokes `func` at most once per every `wait`
7309 * milliseconds. The created function comes with a `cancel` method to cancel
7310 * delayed invocations. Provide an options object to indicate that `func`
7311 * should be invoked on the leading and/or trailing edge of the `wait` timeout.
7312 * Subsequent calls to the throttled function return the result of the last
7313 * `func` call.
7314 *
7315 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
7316 * on the trailing edge of the timeout only if the the throttled function is
7317 * invoked more than once during the `wait` timeout.
7318 *
7319 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
7320 * for details over the differences between `_.throttle` and `_.debounce`.
7321 *
7322 * @static
7323 * @memberOf _
7324 * @category Function
7325 * @param {Function} func The function to throttle.
7326 * @param {number} wait The number of milliseconds to throttle invocations to.
7327 * @param {Object} [options] The options object.
7328 * @param {boolean} [options.leading=true] Specify invoking on the leading
7329 * edge of the timeout.
7330 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
7331 * edge of the timeout.
7332 * @returns {Function} Returns the new throttled function.
7333 * @example
7334 *
7335 * // avoid excessively updating the position while scrolling
7336 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
7337 *
7338 * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
7339 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false })
7340 * jQuery('.interactive').on('click', throttled);
7341 *
7342 * // cancel a trailing throttled call
7343 * jQuery(window).on('popstate', throttled.cancel);
7344 */
7345 function throttle(func, wait, options) {
7346 var leading = true,
7347 trailing = true;
7348
7349 if (!isFunction(func)) {
7350 throw new TypeError(FUNC_ERROR_TEXT);
7351 }
7352 if (options === false) {
7353 leading = false;
7354 } else if (isObject(options)) {
7355 leading = 'leading' in options ? !!options.leading : leading;
7356 trailing = 'trailing' in options ? !!options.trailing : trailing;
7357 }
7358 debounceOptions.leading = leading;
7359 debounceOptions.maxWait = +wait;
7360 debounceOptions.trailing = trailing;
7361 return debounce(func, wait, debounceOptions);
7362 }
7363
7364 /**
7365 * Creates a function that provides `value` to the wrapper function as its
7366 * first argument. Any additional arguments provided to the function are
7367 * appended to those provided to the wrapper function. The wrapper is invoked
7368 * with the `this` binding of the created function.
7369 *
7370 * @static
7371 * @memberOf _
7372 * @category Function
7373 * @param {*} value The value to wrap.
7374 * @param {Function} wrapper The wrapper function.
7375 * @returns {Function} Returns the new function.
7376 * @example
7377 *
7378 * var p = _.wrap(_.escape, function(func, text) {
7379 * return '<p>' + func(text) + '</p>';
7380 * });
7381 *
7382 * p('fred, barney, & pebbles');
7383 * // => '<p>fred, barney, &amp; pebbles</p>'
7384 */
7385 function wrap(value, wrapper) {
7386 wrapper = wrapper == null ? identity : wrapper;
7387 return createWrapper(wrapper, PARTIAL_FLAG, null, [value], []);
7388 }
7389
7390 /*------------------------------------------------------------------------*/
7391
7392 /**
7393 * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
7394 * otherwise they are assigned by reference. If `customizer` is provided it is
7395 * invoked to produce the cloned values. If `customizer` returns `undefined`
7396 * cloning is handled by the method instead. The `customizer` is bound to
7397 * `thisArg` and invoked with two argument; (value [, index|key, object]).
7398 *
7399 * **Note:** This method is loosely based on the structured clone algorithm.
7400 * The enumerable properties of `arguments` objects and objects created by
7401 * constructors other than `Object` are cloned to plain `Object` objects. An
7402 * empty object is returned for uncloneable values such as functions, DOM nodes,
7403 * Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
7404 * for more details.
7405 *
7406 * @static
7407 * @memberOf _
7408 * @category Lang
7409 * @param {*} value The value to clone.
7410 * @param {boolean} [isDeep] Specify a deep clone.
7411 * @param {Function} [customizer] The function to customize cloning values.
7412 * @param {*} [thisArg] The `this` binding of `customizer`.
7413 * @returns {*} Returns the cloned value.
7414 * @example
7415 *
7416 * var users = [
7417 * { 'user': 'barney' },
7418 * { 'user': 'fred' }
7419 * ];
7420 *
7421 * var shallow = _.clone(users);
7422 * shallow[0] === users[0];
7423 * // => true
7424 *
7425 * var deep = _.clone(users, true);
7426 * deep[0] === users[0];
7427 * // => false
7428 *
7429 * // using a customizer callback
7430 * var body = _.clone(document.body, function(value) {
7431 * return _.isElement(value) ? value.cloneNode(false) : undefined;
7432 * });
7433 *
7434 * body === document.body
7435 * // => false
7436 * body.nodeName
7437 * // => BODY
7438 * body.childNodes.length;
7439 * // => 0
7440 */
7441 function clone(value, isDeep, customizer, thisArg) {
7442 // Juggle arguments.
7443 if (typeof isDeep != 'boolean' && isDeep != null) {
7444 thisArg = customizer;
7445 customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep;
7446 isDeep = false;
7447 }
7448 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
7449 return baseClone(value, isDeep, customizer);
7450 }
7451
7452 /**
7453 * Creates a deep clone of `value`. If `customizer` is provided it is invoked
7454 * to produce the cloned values. If `customizer` returns `undefined` cloning
7455 * is handled by the method instead. The `customizer` is bound to `thisArg`
7456 * and invoked with two argument; (value [, index|key, object]).
7457 *
7458 * **Note:** This method is loosely based on the structured clone algorithm.
7459 * The enumerable properties of `arguments` objects and objects created by
7460 * constructors other than `Object` are cloned to plain `Object` objects. An
7461 * empty object is returned for uncloneable values such as functions, DOM nodes,
7462 * Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
7463 * for more details.
7464 *
7465 * @static
7466 * @memberOf _
7467 * @category Lang
7468 * @param {*} value The value to deep clone.
7469 * @param {Function} [customizer] The function to customize cloning values.
7470 * @param {*} [thisArg] The `this` binding of `customizer`.
7471 * @returns {*} Returns the deep cloned value.
7472 * @example
7473 *
7474 * var users = [
7475 * { 'user': 'barney' },
7476 * { 'user': 'fred' }
7477 * ];
7478 *
7479 * var deep = _.cloneDeep(users);
7480 * deep[0] === users[0];
7481 * // => false
7482 *
7483 * // using a customizer callback
7484 * var el = _.cloneDeep(document.body, function(value) {
7485 * return _.isElement(value) ? value.cloneNode(true) : undefined;
7486 * });
7487 *
7488 * body === document.body
7489 * // => false
7490 * body.nodeName
7491 * // => BODY
7492 * body.childNodes.length;
7493 * // => 20
7494 */
7495 function cloneDeep(value, customizer, thisArg) {
7496 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
7497 return baseClone(value, true, customizer);
7498 }
7499
7500 /**
7501 * Checks if `value` is classified as an `arguments` object.
7502 *
7503 * @static
7504 * @memberOf _
7505 * @category Lang
7506 * @param {*} value The value to check.
7507 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7508 * @example
7509 *
7510 * (function() { return _.isArguments(arguments); })();
7511 * // => true
7512 *
7513 * _.isArguments([1, 2, 3]);
7514 * // => false
7515 */
7516 function isArguments(value) {
7517 var length = isObjectLike(value) ? value.length : undefined;
7518 return (isLength(length) && objToString.call(value) == argsTag) || false;
7519 }
7520
7521 /**
7522 * Checks if `value` is classified as an `Array` object.
7523 *
7524 * @static
7525 * @memberOf _
7526 * @category Lang
7527 * @param {*} value The value to check.
7528 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7529 * @example
7530 *
7531 * _.isArray([1, 2, 3]);
7532 * // => true
7533 *
7534 * (function() { return _.isArray(arguments); })();
7535 * // => false
7536 */
7537 var isArray = nativeIsArray || function(value) {
7538 return (isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag) || false;
7539 };
7540
7541 /**
7542 * Checks if `value` is classified as a boolean primitive or object.
7543 *
7544 * @static
7545 * @memberOf _
7546 * @category Lang
7547 * @param {*} value The value to check.
7548 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7549 * @example
7550 *
7551 * _.isBoolean(false);
7552 * // => true
7553 *
7554 * _.isBoolean(null);
7555 * // => false
7556 */
7557 function isBoolean(value) {
7558 return (value === true || value === false || isObjectLike(value) && objToString.call(value) == boolTag) || false;
7559 }
7560
7561 /**
7562 * Checks if `value` is classified as a `Date` object.
7563 *
7564 * @static
7565 * @memberOf _
7566 * @category Lang
7567 * @param {*} value The value to check.
7568 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7569 * @example
7570 *
7571 * _.isDate(new Date);
7572 * // => true
7573 *
7574 * _.isDate('Mon April 23 2012');
7575 * // => false
7576 */
7577 function isDate(value) {
7578 return (isObjectLike(value) && objToString.call(value) == dateTag) || false;
7579 }
7580
7581 /**
7582 * Checks if `value` is a DOM element.
7583 *
7584 * @static
7585 * @memberOf _
7586 * @category Lang
7587 * @param {*} value The value to check.
7588 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
7589 * @example
7590 *
7591 * _.isElement(document.body);
7592 * // => true
7593 *
7594 * _.isElement('<body>');
7595 * // => false
7596 */
7597 function isElement(value) {
7598 return (value && value.nodeType === 1 && isObjectLike(value) &&
7599 objToString.call(value).indexOf('Element') > -1) || false;
7600 }
7601 // Fallback for environments without DOM support.
7602 if (!support.dom) {
7603 isElement = function(value) {
7604 return (value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value)) || false;
7605 };
7606 }
7607
7608 /**
7609 * Checks if a value is empty. A value is considered empty unless it is an
7610 * `arguments` object, array, string, or jQuery-like collection with a length
7611 * greater than `0` or an object with own enumerable properties.
7612 *
7613 * @static
7614 * @memberOf _
7615 * @category Lang
7616 * @param {Array|Object|string} value The value to inspect.
7617 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
7618 * @example
7619 *
7620 * _.isEmpty(null);
7621 * // => true
7622 *
7623 * _.isEmpty(true);
7624 * // => true
7625 *
7626 * _.isEmpty(1);
7627 * // => true
7628 *
7629 * _.isEmpty([1, 2, 3]);
7630 * // => false
7631 *
7632 * _.isEmpty({ 'a': 1 });
7633 * // => false
7634 */
7635 function isEmpty(value) {
7636 if (value == null) {
7637 return true;
7638 }
7639 var length = value.length;
7640 if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) ||
7641 (isObjectLike(value) && isFunction(value.splice)))) {
7642 return !length;
7643 }
7644 return !keys(value).length;
7645 }
7646
7647 /**
7648 * Performs a deep comparison between two values to determine if they are
7649 * equivalent. If `customizer` is provided it is invoked to compare values.
7650 * If `customizer` returns `undefined` comparisons are handled by the method
7651 * instead. The `customizer` is bound to `thisArg` and invoked with three
7652 * arguments; (value, other [, index|key]).
7653 *
7654 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
7655 * numbers, `Object` objects, regexes, and strings. Functions and DOM nodes
7656 * are **not** supported. Provide a customizer function to extend support
7657 * for comparing other values.
7658 *
7659 * @static
7660 * @memberOf _
7661 * @category Lang
7662 * @param {*} value The value to compare.
7663 * @param {*} other The other value to compare.
7664 * @param {Function} [customizer] The function to customize comparing values.
7665 * @param {*} [thisArg] The `this` binding of `customizer`.
7666 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
7667 * @example
7668 *
7669 * var object = { 'user': 'fred' };
7670 * var other = { 'user': 'fred' };
7671 *
7672 * object == other;
7673 * // => false
7674 *
7675 * _.isEqual(object, other);
7676 * // => true
7677 *
7678 * // using a customizer callback
7679 * var array = ['hello', 'goodbye'];
7680 * var other = ['hi', 'goodbye'];
7681 *
7682 * _.isEqual(array, other, function(value, other) {
7683 * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
7684 * });
7685 * // => true
7686 */
7687 function isEqual(value, other, customizer, thisArg) {
7688 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
7689 if (!customizer && isStrictComparable(value) && isStrictComparable(other)) {
7690 return value === other;
7691 }
7692 var result = customizer ? customizer(value, other) : undefined;
7693 return typeof result == 'undefined' ? baseIsEqual(value, other, customizer) : !!result;
7694 }
7695
7696 /**
7697 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
7698 * `SyntaxError`, `TypeError`, or `URIError` object.
7699 *
7700 * @static
7701 * @memberOf _
7702 * @category Lang
7703 * @param {*} value The value to check.
7704 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
7705 * @example
7706 *
7707 * _.isError(new Error);
7708 * // => true
7709 *
7710 * _.isError(Error);
7711 * // => false
7712 */
7713 function isError(value) {
7714 return (isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag) || false;
7715 }
7716
7717 /**
7718 * Checks if `value` is a finite primitive number.
7719 *
7720 * **Note:** This method is based on ES `Number.isFinite`. See the
7721 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite)
7722 * for more details.
7723 *
7724 * @static
7725 * @memberOf _
7726 * @category Lang
7727 * @param {*} value The value to check.
7728 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
7729 * @example
7730 *
7731 * _.isFinite(10);
7732 * // => true
7733 *
7734 * _.isFinite('10');
7735 * // => false
7736 *
7737 * _.isFinite(true);
7738 * // => false
7739 *
7740 * _.isFinite(Object(10));
7741 * // => false
7742 *
7743 * _.isFinite(Infinity);
7744 * // => false
7745 */
7746 var isFinite = nativeNumIsFinite || function(value) {
7747 return typeof value == 'number' && nativeIsFinite(value);
7748 };
7749
7750 /**
7751 * Checks if `value` is classified as a `Function` object.
7752 *
7753 * @static
7754 * @memberOf _
7755 * @category Lang
7756 * @param {*} value The value to check.
7757 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7758 * @example
7759 *
7760 * _.isFunction(_);
7761 * // => true
7762 *
7763 * _.isFunction(/abc/);
7764 * // => false
7765 */
7766 function isFunction(value) {
7767 // Avoid a Chakra JIT bug in compatibility modes of IE 11.
7768 // See https://github.com/jashkenas/underscore/issues/1621 for more details.
7769 return typeof value == 'function' || false;
7770 }
7771 // Fallback for environments that return incorrect `typeof` operator results.
7772 if (isFunction(/x/) || (Uint8Array && !isFunction(Uint8Array))) {
7773 isFunction = function(value) {
7774 // The use of `Object#toString` avoids issues with the `typeof` operator
7775 // in older versions of Chrome and Safari which return 'function' for regexes
7776 // and Safari 8 equivalents which return 'object' for typed array constructors.
7777 return objToString.call(value) == funcTag;
7778 };
7779 }
7780
7781 /**
7782 * Checks if `value` is the language type of `Object`.
7783 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
7784 *
7785 * **Note:** See the [ES5 spec](https://es5.github.io/#x8) for more details.
7786 *
7787 * @static
7788 * @memberOf _
7789 * @category Lang
7790 * @param {*} value The value to check.
7791 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
7792 * @example
7793 *
7794 * _.isObject({});
7795 * // => true
7796 *
7797 * _.isObject([1, 2, 3]);
7798 * // => true
7799 *
7800 * _.isObject(1);
7801 * // => false
7802 */
7803 function isObject(value) {
7804 // Avoid a V8 JIT bug in Chrome 19-20.
7805 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
7806 var type = typeof value;
7807 return type == 'function' || (value && type == 'object') || false;
7808 }
7809
7810 /**
7811 * Performs a deep comparison between `object` and `source` to determine if
7812 * `object` contains equivalent property values. If `customizer` is provided
7813 * it is invoked to compare values. If `customizer` returns `undefined`
7814 * comparisons are handled by the method instead. The `customizer` is bound
7815 * to `thisArg` and invoked with three arguments; (value, other, index|key).
7816 *
7817 * **Note:** This method supports comparing properties of arrays, booleans,
7818 * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
7819 * and DOM nodes are **not** supported. Provide a customizer function to extend
7820 * support for comparing other values.
7821 *
7822 * @static
7823 * @memberOf _
7824 * @category Lang
7825 * @param {Object} source The object to inspect.
7826 * @param {Object} source The object of property values to match.
7827 * @param {Function} [customizer] The function to customize comparing values.
7828 * @param {*} [thisArg] The `this` binding of `customizer`.
7829 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
7830 * @example
7831 *
7832 * var object = { 'user': 'fred', 'age': 40 };
7833 *
7834 * _.isMatch(object, { 'age': 40 });
7835 * // => true
7836 *
7837 * _.isMatch(object, { 'age': 36 });
7838 * // => false
7839 *
7840 * // using a customizer callback
7841 * var object = { 'greeting': 'hello' };
7842 * var source = { 'greeting': 'hi' };
7843 *
7844 * _.isMatch(object, source, function(value, other) {
7845 * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
7846 * });
7847 * // => true
7848 */
7849 function isMatch(object, source, customizer, thisArg) {
7850 var props = keys(source),
7851 length = props.length;
7852
7853 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
7854 if (!customizer && length == 1) {
7855 var key = props[0],
7856 value = source[key];
7857
7858 if (isStrictComparable(value)) {
7859 return object != null && value === object[key] && hasOwnProperty.call(object, key);
7860 }
7861 }
7862 var values = Array(length),
7863 strictCompareFlags = Array(length);
7864
7865 while (length--) {
7866 value = values[length] = source[props[length]];
7867 strictCompareFlags[length] = isStrictComparable(value);
7868 }
7869 return baseIsMatch(object, props, values, strictCompareFlags, customizer);
7870 }
7871
7872 /**
7873 * Checks if `value` is `NaN`.
7874 *
7875 * **Note:** This method is not the same as native `isNaN` which returns `true`
7876 * for `undefined` and other non-numeric values. See the [ES5 spec](https://es5.github.io/#x15.1.2.4)
7877 * for more details.
7878 *
7879 * @static
7880 * @memberOf _
7881 * @category Lang
7882 * @param {*} value The value to check.
7883 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
7884 * @example
7885 *
7886 * _.isNaN(NaN);
7887 * // => true
7888 *
7889 * _.isNaN(new Number(NaN));
7890 * // => true
7891 *
7892 * isNaN(undefined);
7893 * // => true
7894 *
7895 * _.isNaN(undefined);
7896 * // => false
7897 */
7898 function isNaN(value) {
7899 // An `NaN` primitive is the only value that is not equal to itself.
7900 // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
7901 return isNumber(value) && value != +value;
7902 }
7903
7904 /**
7905 * Checks if `value` is a native function.
7906 *
7907 * @static
7908 * @memberOf _
7909 * @category Lang
7910 * @param {*} value The value to check.
7911 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
7912 * @example
7913 *
7914 * _.isNative(Array.prototype.push);
7915 * // => true
7916 *
7917 * _.isNative(_);
7918 * // => false
7919 */
7920 function isNative(value) {
7921 if (value == null) {
7922 return false;
7923 }
7924 if (objToString.call(value) == funcTag) {
7925 return reNative.test(fnToString.call(value));
7926 }
7927 return (isObjectLike(value) && reHostCtor.test(value)) || false;
7928 }
7929
7930 /**
7931 * Checks if `value` is `null`.
7932 *
7933 * @static
7934 * @memberOf _
7935 * @category Lang
7936 * @param {*} value The value to check.
7937 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
7938 * @example
7939 *
7940 * _.isNull(null);
7941 * // => true
7942 *
7943 * _.isNull(void 0);
7944 * // => false
7945 */
7946 function isNull(value) {
7947 return value === null;
7948 }
7949
7950 /**
7951 * Checks if `value` is classified as a `Number` primitive or object.
7952 *
7953 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
7954 * as numbers, use the `_.isFinite` method.
7955 *
7956 * @static
7957 * @memberOf _
7958 * @category Lang
7959 * @param {*} value The value to check.
7960 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7961 * @example
7962 *
7963 * _.isNumber(8.4);
7964 * // => true
7965 *
7966 * _.isNumber(NaN);
7967 * // => true
7968 *
7969 * _.isNumber('8.4');
7970 * // => false
7971 */
7972 function isNumber(value) {
7973 return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag) || false;
7974 }
7975
7976 /**
7977 * Checks if `value` is a plain object, that is, an object created by the
7978 * `Object` constructor or one with a `[[Prototype]]` of `null`.
7979 *
7980 * **Note:** This method assumes objects created by the `Object` constructor
7981 * have no inherited enumerable properties.
7982 *
7983 * @static
7984 * @memberOf _
7985 * @category Lang
7986 * @param {*} value The value to check.
7987 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
7988 * @example
7989 *
7990 * function Foo() {
7991 * this.a = 1;
7992 * }
7993 *
7994 * _.isPlainObject(new Foo);
7995 * // => false
7996 *
7997 * _.isPlainObject([1, 2, 3]);
7998 * // => false
7999 *
8000 * _.isPlainObject({ 'x': 0, 'y': 0 });
8001 * // => true
8002 *
8003 * _.isPlainObject(Object.create(null));
8004 * // => true
8005 */
8006 var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
8007 if (!(value && objToString.call(value) == objectTag)) {
8008 return false;
8009 }
8010 var valueOf = value.valueOf,
8011 objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
8012
8013 return objProto
8014 ? (value == objProto || getPrototypeOf(value) == objProto)
8015 : shimIsPlainObject(value);
8016 };
8017
8018 /**
8019 * Checks if `value` is classified as a `RegExp` object.
8020 *
8021 * @static
8022 * @memberOf _
8023 * @category Lang
8024 * @param {*} value The value to check.
8025 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8026 * @example
8027 *
8028 * _.isRegExp(/abc/);
8029 * // => true
8030 *
8031 * _.isRegExp('/abc/');
8032 * // => false
8033 */
8034 function isRegExp(value) {
8035 return (isObjectLike(value) && objToString.call(value) == regexpTag) || false;
8036 }
8037
8038 /**
8039 * Checks if `value` is classified as a `String` primitive or object.
8040 *
8041 * @static
8042 * @memberOf _
8043 * @category Lang
8044 * @param {*} value The value to check.
8045 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8046 * @example
8047 *
8048 * _.isString('abc');
8049 * // => true
8050 *
8051 * _.isString(1);
8052 * // => false
8053 */
8054 function isString(value) {
8055 return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag) || false;
8056 }
8057
8058 /**
8059 * Checks if `value` is classified as a typed array.
8060 *
8061 * @static
8062 * @memberOf _
8063 * @category Lang
8064 * @param {*} value The value to check.
8065 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8066 * @example
8067 *
8068 * _.isTypedArray(new Uint8Array);
8069 * // => true
8070 *
8071 * _.isTypedArray([]);
8072 * // => false
8073 */
8074 function isTypedArray(value) {
8075 return (isObjectLike(value) && isLength(value.length) && typedArrayTags[objToString.call(value)]) || false;
8076 }
8077
8078 /**
8079 * Checks if `value` is `undefined`.
8080 *
8081 * @static
8082 * @memberOf _
8083 * @category Lang
8084 * @param {*} value The value to check.
8085 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
8086 * @example
8087 *
8088 * _.isUndefined(void 0);
8089 * // => true
8090 *
8091 * _.isUndefined(null);
8092 * // => false
8093 */
8094 function isUndefined(value) {
8095 return typeof value == 'undefined';
8096 }
8097
8098 /**
8099 * Converts `value` to an array.
8100 *
8101 * @static
8102 * @memberOf _
8103 * @category Lang
8104 * @param {*} value The value to convert.
8105 * @returns {Array} Returns the converted array.
8106 * @example
8107 *
8108 * (function() { return _.toArray(arguments).slice(1); })(1, 2, 3);
8109 * // => [2, 3]
8110 */
8111 function toArray(value) {
8112 var length = value ? value.length : 0;
8113 if (!isLength(length)) {
8114 return values(value);
8115 }
8116 if (!length) {
8117 return [];
8118 }
8119 return arrayCopy(value);
8120 }
8121
8122 /**
8123 * Converts `value` to a plain object flattening inherited enumerable
8124 * properties of `value` to own properties of the plain object.
8125 *
8126 * @static
8127 * @memberOf _
8128 * @category Lang
8129 * @param {*} value The value to convert.
8130 * @returns {Object} Returns the converted plain object.
8131 * @example
8132 *
8133 * function Foo() {
8134 * this.b = 2;
8135 * }
8136 *
8137 * Foo.prototype.c = 3;
8138 *
8139 * _.assign({ 'a': 1 }, new Foo);
8140 * // => { 'a': 1, 'b': 2 }
8141 *
8142 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
8143 * // => { 'a': 1, 'b': 2, 'c': 3 }
8144 */
8145 function toPlainObject(value) {
8146 return baseCopy(value, keysIn(value));
8147 }
8148
8149 /*------------------------------------------------------------------------*/
8150
8151 /**
8152 * Assigns own enumerable properties of source object(s) to the destination
8153 * object. Subsequent sources overwrite property assignments of previous sources.
8154 * If `customizer` is provided it is invoked to produce the assigned values.
8155 * The `customizer` is bound to `thisArg` and invoked with five arguments;
8156 * (objectValue, sourceValue, key, object, source).
8157 *
8158 * @static
8159 * @memberOf _
8160 * @alias extend
8161 * @category Object
8162 * @param {Object} object The destination object.
8163 * @param {...Object} [sources] The source objects.
8164 * @param {Function} [customizer] The function to customize assigning values.
8165 * @param {*} [thisArg] The `this` binding of `customizer`.
8166 * @returns {Object} Returns `object`.
8167 * @example
8168 *
8169 * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
8170 * // => { 'user': 'fred', 'age': 40 }
8171 *
8172 * // using a customizer callback
8173 * var defaults = _.partialRight(_.assign, function(value, other) {
8174 * return typeof value == 'undefined' ? other : value;
8175 * });
8176 *
8177 * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
8178 * // => { 'user': 'barney', 'age': 36 }
8179 */
8180 var assign = createAssigner(baseAssign);
8181
8182 /**
8183 * Creates an object that inherits from the given `prototype` object. If a
8184 * `properties` object is provided its own enumerable properties are assigned
8185 * to the created object.
8186 *
8187 * @static
8188 * @memberOf _
8189 * @category Object
8190 * @param {Object} prototype The object to inherit from.
8191 * @param {Object} [properties] The properties to assign to the object.
8192 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
8193 * @returns {Object} Returns the new object.
8194 * @example
8195 *
8196 * function Shape() {
8197 * this.x = 0;
8198 * this.y = 0;
8199 * }
8200 *
8201 * function Circle() {
8202 * Shape.call(this);
8203 * }
8204 *
8205 * Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle });
8206 *
8207 * var circle = new Circle;
8208 * circle instanceof Circle;
8209 * // => true
8210 *
8211 * circle instanceof Shape;
8212 * // => true
8213 */
8214 function create(prototype, properties, guard) {
8215 var result = baseCreate(prototype);
8216 if (guard && isIterateeCall(prototype, properties, guard)) {
8217 properties = null;
8218 }
8219 return properties ? baseCopy(properties, result, keys(properties)) : result;
8220 }
8221
8222 /**
8223 * Assigns own enumerable properties of source object(s) to the destination
8224 * object for all destination properties that resolve to `undefined`. Once a
8225 * property is set, additional defaults of the same property are ignored.
8226 *
8227 * @static
8228 * @memberOf _
8229 * @category Object
8230 * @param {Object} object The destination object.
8231 * @param {...Object} [sources] The source objects.
8232 * @returns {Object} Returns `object`.
8233 * @example
8234 *
8235 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
8236 * // => { 'user': 'barney', 'age': 36 }
8237 */
8238 function defaults(object) {
8239 if (object == null) {
8240 return object;
8241 }
8242 var args = arrayCopy(arguments);
8243 args.push(assignDefaults);
8244 return assign.apply(undefined, args);
8245 }
8246
8247 /**
8248 * This method is like `_.findIndex` except that it returns the key of the
8249 * first element `predicate` returns truthy for, instead of the element itself.
8250 *
8251 * If a property name is provided for `predicate` the created "_.property"
8252 * style callback returns the property value of the given element.
8253 *
8254 * If an object is provided for `predicate` the created "_.matches" style
8255 * callback returns `true` for elements that have the properties of the given
8256 * object, else `false`.
8257 *
8258 * @static
8259 * @memberOf _
8260 * @category Object
8261 * @param {Object} object The object to search.
8262 * @param {Function|Object|string} [predicate=_.identity] The function invoked
8263 * per iteration. If a property name or object is provided it is used to
8264 * create a "_.property" or "_.matches" style callback respectively.
8265 * @param {*} [thisArg] The `this` binding of `predicate`.
8266 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
8267 * @example
8268 *
8269 * var users = {
8270 * 'barney': { 'age': 36, 'active': true },
8271 * 'fred': { 'age': 40, 'active': false },
8272 * 'pebbles': { 'age': 1, 'active': true }
8273 * };
8274 *
8275 * _.findKey(users, function(chr) { return chr.age < 40; });
8276 * // => 'barney' (iteration order is not guaranteed)
8277 *
8278 * // using the "_.matches" callback shorthand
8279 * _.findKey(users, { 'age': 1 });
8280 * // => 'pebbles'
8281 *
8282 * // using the "_.property" callback shorthand
8283 * _.findKey(users, 'active');
8284 * // => 'barney'
8285 */
8286 function findKey(object, predicate, thisArg) {
8287 predicate = getCallback(predicate, thisArg, 3);
8288 return baseFind(object, predicate, baseForOwn, true);
8289 }
8290
8291 /**
8292 * This method is like `_.findKey` except that it iterates over elements of
8293 * a collection in the opposite order.
8294 *
8295 * If a property name is provided for `predicate` the created "_.property"
8296 * style callback returns the property value of the given element.
8297 *
8298 * If an object is provided for `predicate` the created "_.matches" style
8299 * callback returns `true` for elements that have the properties of the given
8300 * object, else `false`.
8301 *
8302 * @static
8303 * @memberOf _
8304 * @category Object
8305 * @param {Object} object The object to search.
8306 * @param {Function|Object|string} [predicate=_.identity] The function invoked
8307 * per iteration. If a property name or object is provided it is used to
8308 * create a "_.property" or "_.matches" style callback respectively.
8309 * @param {*} [thisArg] The `this` binding of `predicate`.
8310 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
8311 * @example
8312 *
8313 * var users = {
8314 * 'barney': { 'age': 36, 'active': true },
8315 * 'fred': { 'age': 40, 'active': false },
8316 * 'pebbles': { 'age': 1, 'active': true }
8317 * };
8318 *
8319 * _.findLastKey(users, function(chr) { return chr.age < 40; });
8320 * // => returns `pebbles` assuming `_.findKey` returns `barney`
8321 *
8322 * // using the "_.matches" callback shorthand
8323 * _.findLastKey(users, { 'age': 36 });
8324 * // => 'barney'
8325 *
8326 * // using the "_.property" callback shorthand
8327 * _.findLastKey(users, 'active');
8328 * // => 'pebbles'
8329 */
8330 function findLastKey(object, predicate, thisArg) {
8331 predicate = getCallback(predicate, thisArg, 3);
8332 return baseFind(object, predicate, baseForOwnRight, true);
8333 }
8334
8335 /**
8336 * Iterates over own and inherited enumerable properties of an object invoking
8337 * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
8338 * with three arguments; (value, key, object). Iterator functions may exit
8339 * iteration early by explicitly returning `false`.
8340 *
8341 * @static
8342 * @memberOf _
8343 * @category Object
8344 * @param {Object} object The object to iterate over.
8345 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8346 * @param {*} [thisArg] The `this` binding of `iteratee`.
8347 * @returns {Object} Returns `object`.
8348 * @example
8349 *
8350 * function Foo() {
8351 * this.a = 1;
8352 * this.b = 2;
8353 * }
8354 *
8355 * Foo.prototype.c = 3;
8356 *
8357 * _.forIn(new Foo, function(value, key) {
8358 * console.log(key);
8359 * });
8360 * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
8361 */
8362 function forIn(object, iteratee, thisArg) {
8363 if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
8364 iteratee = bindCallback(iteratee, thisArg, 3);
8365 }
8366 return baseFor(object, iteratee, keysIn);
8367 }
8368
8369 /**
8370 * This method is like `_.forIn` except that it iterates over properties of
8371 * `object` in the opposite order.
8372 *
8373 * @static
8374 * @memberOf _
8375 * @category Object
8376 * @param {Object} object The object to iterate over.
8377 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8378 * @param {*} [thisArg] The `this` binding of `iteratee`.
8379 * @returns {Object} Returns `object`.
8380 * @example
8381 *
8382 * function Foo() {
8383 * this.a = 1;
8384 * this.b = 2;
8385 * }
8386 *
8387 * Foo.prototype.c = 3;
8388 *
8389 * _.forInRight(new Foo, function(value, key) {
8390 * console.log(key);
8391 * });
8392 * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
8393 */
8394 function forInRight(object, iteratee, thisArg) {
8395 iteratee = bindCallback(iteratee, thisArg, 3);
8396 return baseForRight(object, iteratee, keysIn);
8397 }
8398
8399 /**
8400 * Iterates over own enumerable properties of an object invoking `iteratee`
8401 * for each property. The `iteratee` is bound to `thisArg` and invoked with
8402 * three arguments; (value, key, object). Iterator functions may exit iteration
8403 * early by explicitly returning `false`.
8404 *
8405 * @static
8406 * @memberOf _
8407 * @category Object
8408 * @param {Object} object The object to iterate over.
8409 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8410 * @param {*} [thisArg] The `this` binding of `iteratee`.
8411 * @returns {Object} Returns `object`.
8412 * @example
8413 *
8414 * _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
8415 * console.log(key);
8416 * });
8417 * // => logs '0', '1', and 'length' (iteration order is not guaranteed)
8418 */
8419 function forOwn(object, iteratee, thisArg) {
8420 if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
8421 iteratee = bindCallback(iteratee, thisArg, 3);
8422 }
8423 return baseForOwn(object, iteratee);
8424 }
8425
8426 /**
8427 * This method is like `_.forOwn` except that it iterates over properties of
8428 * `object` in the opposite order.
8429 *
8430 * @static
8431 * @memberOf _
8432 * @category Object
8433 * @param {Object} object The object to iterate over.
8434 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8435 * @param {*} [thisArg] The `this` binding of `iteratee`.
8436 * @returns {Object} Returns `object`.
8437 * @example
8438 *
8439 * _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
8440 * console.log(key);
8441 * });
8442 * // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length'
8443 */
8444 function forOwnRight(object, iteratee, thisArg) {
8445 iteratee = bindCallback(iteratee, thisArg, 3);
8446 return baseForRight(object, iteratee, keys);
8447 }
8448
8449 /**
8450 * Creates an array of function property names from all enumerable properties,
8451 * own and inherited, of `object`.
8452 *
8453 * @static
8454 * @memberOf _
8455 * @alias methods
8456 * @category Object
8457 * @param {Object} object The object to inspect.
8458 * @returns {Array} Returns the new array of property names.
8459 * @example
8460 *
8461 * _.functions(_);
8462 * // => ['all', 'any', 'bind', ...]
8463 */
8464 function functions(object) {
8465 return baseFunctions(object, keysIn(object));
8466 }
8467
8468 /**
8469 * Checks if `key` exists as a direct property of `object` instead of an
8470 * inherited property.
8471 *
8472 * @static
8473 * @memberOf _
8474 * @category Object
8475 * @param {Object} object The object to inspect.
8476 * @param {string} key The key to check.
8477 * @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
8478 * @example
8479 *
8480 * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
8481 * // => true
8482 */
8483 function has(object, key) {
8484 return object ? hasOwnProperty.call(object, key) : false;
8485 }
8486
8487 /**
8488 * Creates an object composed of the inverted keys and values of `object`.
8489 * If `object` contains duplicate values, subsequent values overwrite property
8490 * assignments of previous values unless `multiValue` is `true`.
8491 *
8492 * @static
8493 * @memberOf _
8494 * @category Object
8495 * @param {Object} object The object to invert.
8496 * @param {boolean} [multiValue] Allow multiple values per key.
8497 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
8498 * @returns {Object} Returns the new inverted object.
8499 * @example
8500 *
8501 * _.invert({ 'first': 'fred', 'second': 'barney' });
8502 * // => { 'fred': 'first', 'barney': 'second' }
8503 *
8504 * // without `multiValue`
8505 * _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' });
8506 * // => { 'fred': 'third', 'barney': 'second' }
8507 *
8508 * // with `multiValue`
8509 * _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }, true);
8510 * // => { 'fred': ['first', 'third'], 'barney': ['second'] }
8511 */
8512 function invert(object, multiValue, guard) {
8513 if (guard && isIterateeCall(object, multiValue, guard)) {
8514 multiValue = null;
8515 }
8516 var index = -1,
8517 props = keys(object),
8518 length = props.length,
8519 result = {};
8520
8521 while (++index < length) {
8522 var key = props[index],
8523 value = object[key];
8524
8525 if (multiValue) {
8526 if (hasOwnProperty.call(result, value)) {
8527 result[value].push(key);
8528 } else {
8529 result[value] = [key];
8530 }
8531 }
8532 else {
8533 result[value] = key;
8534 }
8535 }
8536 return result;
8537 }
8538
8539 /**
8540 * Creates an array of the own enumerable property names of `object`.
8541 *
8542 * **Note:** Non-object values are coerced to objects. See the
8543 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.keys)
8544 * for more details.
8545 *
8546 * @static
8547 * @memberOf _
8548 * @category Object
8549 * @param {Object} object The object to inspect.
8550 * @returns {Array} Returns the array of property names.
8551 * @example
8552 *
8553 * function Foo() {
8554 * this.a = 1;
8555 * this.b = 2;
8556 * }
8557 *
8558 * Foo.prototype.c = 3;
8559 *
8560 * _.keys(new Foo);
8561 * // => ['a', 'b'] (iteration order is not guaranteed)
8562 *
8563 * _.keys('hi');
8564 * // => ['0', '1']
8565 */
8566 var keys = !nativeKeys ? shimKeys : function(object) {
8567 if (object) {
8568 var Ctor = object.constructor,
8569 length = object.length;
8570 }
8571 if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
8572 (typeof object != 'function' && (length && isLength(length)))) {
8573 return shimKeys(object);
8574 }
8575 return isObject(object) ? nativeKeys(object) : [];
8576 };
8577
8578 /**
8579 * Creates an array of the own and inherited enumerable property names of `object`.
8580 *
8581 * **Note:** Non-object values are coerced to objects.
8582 *
8583 * @static
8584 * @memberOf _
8585 * @category Object
8586 * @param {Object} object The object to inspect.
8587 * @returns {Array} Returns the array of property names.
8588 * @example
8589 *
8590 * function Foo() {
8591 * this.a = 1;
8592 * this.b = 2;
8593 * }
8594 *
8595 * Foo.prototype.c = 3;
8596 *
8597 * _.keysIn(new Foo);
8598 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
8599 */
8600 function keysIn(object) {
8601 if (object == null) {
8602 return [];
8603 }
8604 if (!isObject(object)) {
8605 object = Object(object);
8606 }
8607 var length = object.length;
8608 length = (length && isLength(length) &&
8609 (isArray(object) || (support.nonEnumArgs && isArguments(object))) && length) || 0;
8610
8611 var Ctor = object.constructor,
8612 index = -1,
8613 isProto = typeof Ctor == 'function' && Ctor.prototype == object,
8614 result = Array(length),
8615 skipIndexes = length > 0;
8616
8617 while (++index < length) {
8618 result[index] = (index + '');
8619 }
8620 for (var key in object) {
8621 if (!(skipIndexes && isIndex(key, length)) &&
8622 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
8623 result.push(key);
8624 }
8625 }
8626 return result;
8627 }
8628
8629 /**
8630 * Creates an object with the same keys as `object` and values generated by
8631 * running each own enumerable property of `object` through `iteratee`. The
8632 * iteratee function is bound to `thisArg` and invoked with three arguments;
8633 * (value, key, object).
8634 *
8635 * If a property name is provided for `iteratee` the created "_.property"
8636 * style callback returns the property value of the given element.
8637 *
8638 * If an object is provided for `iteratee` the created "_.matches" style
8639 * callback returns `true` for elements that have the properties of the given
8640 * object, else `false`.
8641 *
8642 * @static
8643 * @memberOf _
8644 * @category Object
8645 * @param {Object} object The object to iterate over.
8646 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
8647 * per iteration. If a property name or object is provided it is used to
8648 * create a "_.property" or "_.matches" style callback respectively.
8649 * @param {*} [thisArg] The `this` binding of `iteratee`.
8650 * @returns {Object} Returns the new mapped object.
8651 * @example
8652 *
8653 * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(n) { return n * 3; });
8654 * // => { 'a': 3, 'b': 6, 'c': 9 }
8655 *
8656 * var users = {
8657 * 'fred': { 'user': 'fred', 'age': 40 },
8658 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
8659 * };
8660 *
8661 * // using the "_.property" callback shorthand
8662 * _.mapValues(users, 'age');
8663 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
8664 */
8665 function mapValues(object, iteratee, thisArg) {
8666 var result = {};
8667 iteratee = getCallback(iteratee, thisArg, 3);
8668
8669 baseForOwn(object, function(value, key, object) {
8670 result[key] = iteratee(value, key, object);
8671 });
8672 return result;
8673 }
8674
8675 /**
8676 * Recursively merges own enumerable properties of the source object(s), that
8677 * don't resolve to `undefined` into the destination object. Subsequent sources
8678 * overwrite property assignments of previous sources. If `customizer` is
8679 * provided it is invoked to produce the merged values of the destination and
8680 * source properties. If `customizer` returns `undefined` merging is handled
8681 * by the method instead. The `customizer` is bound to `thisArg` and invoked
8682 * with five arguments; (objectValue, sourceValue, key, object, source).
8683 *
8684 * @static
8685 * @memberOf _
8686 * @category Object
8687 * @param {Object} object The destination object.
8688 * @param {...Object} [sources] The source objects.
8689 * @param {Function} [customizer] The function to customize merging properties.
8690 * @param {*} [thisArg] The `this` binding of `customizer`.
8691 * @returns {Object} Returns `object`.
8692 * @example
8693 *
8694 * var users = {
8695 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
8696 * };
8697 *
8698 * var ages = {
8699 * 'data': [{ 'age': 36 }, { 'age': 40 }]
8700 * };
8701 *
8702 * _.merge(users, ages);
8703 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
8704 *
8705 * // using a customizer callback
8706 * var object = {
8707 * 'fruits': ['apple'],
8708 * 'vegetables': ['beet']
8709 * };
8710 *
8711 * var other = {
8712 * 'fruits': ['banana'],
8713 * 'vegetables': ['carrot']
8714 * };
8715 *
8716 * _.merge(object, other, function(a, b) {
8717 * return _.isArray(a) ? a.concat(b) : undefined;
8718 * });
8719 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
8720 */
8721 var merge = createAssigner(baseMerge);
8722
8723 /**
8724 * The opposite of `_.pick`; this method creates an object composed of the
8725 * own and inherited enumerable properties of `object` that are not omitted.
8726 * Property names may be specified as individual arguments or as arrays of
8727 * property names. If `predicate` is provided it is invoked for each property
8728 * of `object` omitting the properties `predicate` returns truthy for. The
8729 * predicate is bound to `thisArg` and invoked with three arguments;
8730 * (value, key, object).
8731 *
8732 * @static
8733 * @memberOf _
8734 * @category Object
8735 * @param {Object} object The source object.
8736 * @param {Function|...(string|string[])} [predicate] The function invoked per
8737 * iteration or property names to omit, specified as individual property
8738 * names or arrays of property names.
8739 * @param {*} [thisArg] The `this` binding of `predicate`.
8740 * @returns {Object} Returns the new object.
8741 * @example
8742 *
8743 * var object = { 'user': 'fred', 'age': 40 };
8744 *
8745 * _.omit(object, 'age');
8746 * // => { 'user': 'fred' }
8747 *
8748 * _.omit(object, _.isNumber);
8749 * // => { 'user': 'fred' }
8750 */
8751 function omit(object, predicate, thisArg) {
8752 if (object == null) {
8753 return {};
8754 }
8755 if (typeof predicate != 'function') {
8756 var props = arrayMap(baseFlatten(arguments, false, false, 1), String);
8757 return pickByArray(object, baseDifference(keysIn(object), props));
8758 }
8759 predicate = bindCallback(predicate, thisArg, 3);
8760 return pickByCallback(object, function(value, key, object) {
8761 return !predicate(value, key, object);
8762 });
8763 }
8764
8765 /**
8766 * Creates a two dimensional array of the key-value pairs for `object`,
8767 * e.g. `[[key1, value1], [key2, value2]]`.
8768 *
8769 * @static
8770 * @memberOf _
8771 * @category Object
8772 * @param {Object} object The object to inspect.
8773 * @returns {Array} Returns the new array of key-value pairs.
8774 * @example
8775 *
8776 * _.pairs({ 'barney': 36, 'fred': 40 });
8777 * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
8778 */
8779 function pairs(object) {
8780 var index = -1,
8781 props = keys(object),
8782 length = props.length,
8783 result = Array(length);
8784
8785 while (++index < length) {
8786 var key = props[index];
8787 result[index] = [key, object[key]];
8788 }
8789 return result;
8790 }
8791
8792 /**
8793 * Creates an object composed of the picked `object` properties. Property
8794 * names may be specified as individual arguments or as arrays of property
8795 * names. If `predicate` is provided it is invoked for each property of `object`
8796 * picking the properties `predicate` returns truthy for. The predicate is
8797 * bound to `thisArg` and invoked with three arguments; (value, key, object).
8798 *
8799 * @static
8800 * @memberOf _
8801 * @category Object
8802 * @param {Object} object The source object.
8803 * @param {Function|...(string|string[])} [predicate] The function invoked per
8804 * iteration or property names to pick, specified as individual property
8805 * names or arrays of property names.
8806 * @param {*} [thisArg] The `this` binding of `predicate`.
8807 * @returns {Object} Returns the new object.
8808 * @example
8809 *
8810 * var object = { 'user': 'fred', 'age': 40 };
8811 *
8812 * _.pick(object, 'user');
8813 * // => { 'user': 'fred' }
8814 *
8815 * _.pick(object, _.isString);
8816 * // => { 'user': 'fred' }
8817 */
8818 function pick(object, predicate, thisArg) {
8819 if (object == null) {
8820 return {};
8821 }
8822 return typeof predicate == 'function'
8823 ? pickByCallback(object, bindCallback(predicate, thisArg, 3))
8824 : pickByArray(object, baseFlatten(arguments, false, false, 1));
8825 }
8826
8827 /**
8828 * Resolves the value of property `key` on `object`. If the value of `key` is
8829 * a function it is invoked with the `this` binding of `object` and its result
8830 * is returned, else the property value is returned. If the property value is
8831 * `undefined` the `defaultValue` is used in its place.
8832 *
8833 * @static
8834 * @memberOf _
8835 * @category Object
8836 * @param {Object} object The object to query.
8837 * @param {string} key The key of the property to resolve.
8838 * @param {*} [defaultValue] The value returned if the property value
8839 * resolves to `undefined`.
8840 * @returns {*} Returns the resolved value.
8841 * @example
8842 *
8843 * var object = { 'user': 'fred', 'age': _.constant(40) };
8844 *
8845 * _.result(object, 'user');
8846 * // => 'fred'
8847 *
8848 * _.result(object, 'age');
8849 * // => 40
8850 *
8851 * _.result(object, 'status', 'busy');
8852 * // => 'busy'
8853 *
8854 * _.result(object, 'status', _.constant('busy'));
8855 * // => 'busy'
8856 */
8857 function result(object, key, defaultValue) {
8858 var value = object == null ? undefined : object[key];
8859 if (typeof value == 'undefined') {
8860 value = defaultValue;
8861 }
8862 return isFunction(value) ? value.call(object) : value;
8863 }
8864
8865 /**
8866 * An alternative to `_.reduce`; this method transforms `object` to a new
8867 * `accumulator` object which is the result of running each of its own enumerable
8868 * properties through `iteratee`, with each invocation potentially mutating
8869 * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
8870 * with four arguments; (accumulator, value, key, object). Iterator functions
8871 * may exit iteration early by explicitly returning `false`.
8872 *
8873 * @static
8874 * @memberOf _
8875 * @category Object
8876 * @param {Array|Object} object The object to iterate over.
8877 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8878 * @param {*} [accumulator] The custom accumulator value.
8879 * @param {*} [thisArg] The `this` binding of `iteratee`.
8880 * @returns {*} Returns the accumulated value.
8881 * @example
8882 *
8883 * var squares = _.transform([1, 2, 3, 4, 5, 6], function(result, n) {
8884 * n *= n;
8885 * if (n % 2) {
8886 * return result.push(n) < 3;
8887 * }
8888 * });
8889 * // => [1, 9, 25]
8890 *
8891 * var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) {
8892 * result[key] = n * 3;
8893 * });
8894 * // => { 'a': 3, 'b': 6, 'c': 9 }
8895 */
8896 function transform(object, iteratee, accumulator, thisArg) {
8897 var isArr = isArray(object) || isTypedArray(object);
8898 iteratee = getCallback(iteratee, thisArg, 4);
8899
8900 if (accumulator == null) {
8901 if (isArr || isObject(object)) {
8902 var Ctor = object.constructor;
8903 if (isArr) {
8904 accumulator = isArray(object) ? new Ctor : [];
8905 } else {
8906 accumulator = baseCreate(typeof Ctor == 'function' && Ctor.prototype);
8907 }
8908 } else {
8909 accumulator = {};
8910 }
8911 }
8912 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
8913 return iteratee(accumulator, value, index, object);
8914 });
8915 return accumulator;
8916 }
8917
8918 /**
8919 * Creates an array of the own enumerable property values of `object`.
8920 *
8921 * **Note:** Non-object values are coerced to objects.
8922 *
8923 * @static
8924 * @memberOf _
8925 * @category Object
8926 * @param {Object} object The object to query.
8927 * @returns {Array} Returns the array of property values.
8928 * @example
8929 *
8930 * function Foo() {
8931 * this.a = 1;
8932 * this.b = 2;
8933 * }
8934 *
8935 * Foo.prototype.c = 3;
8936 *
8937 * _.values(new Foo);
8938 * // => [1, 2] (iteration order is not guaranteed)
8939 *
8940 * _.values('hi');
8941 * // => ['h', 'i']
8942 */
8943 function values(object) {
8944 return baseValues(object, keys(object));
8945 }
8946
8947 /**
8948 * Creates an array of the own and inherited enumerable property values
8949 * of `object`.
8950 *
8951 * **Note:** Non-object values are coerced to objects.
8952 *
8953 * @static
8954 * @memberOf _
8955 * @category Object
8956 * @param {Object} object The object to query.
8957 * @returns {Array} Returns the array of property values.
8958 * @example
8959 *
8960 * function Foo() {
8961 * this.a = 1;
8962 * this.b = 2;
8963 * }
8964 *
8965 * Foo.prototype.c = 3;
8966 *
8967 * _.valuesIn(new Foo);
8968 * // => [1, 2, 3] (iteration order is not guaranteed)
8969 */
8970 function valuesIn(object) {
8971 return baseValues(object, keysIn(object));
8972 }
8973
8974 /*------------------------------------------------------------------------*/
8975
8976 /**
8977 * Produces a random number between `min` and `max` (inclusive). If only one
8978 * argument is provided a number between `0` and the given number is returned.
8979 * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
8980 * number is returned instead of an integer.
8981 *
8982 * @static
8983 * @memberOf _
8984 * @category Number
8985 * @param {number} [min=0] The minimum possible value.
8986 * @param {number} [max=1] The maximum possible value.
8987 * @param {boolean} [floating] Specify returning a floating-point number.
8988 * @returns {number} Returns the random number.
8989 * @example
8990 *
8991 * _.random(0, 5);
8992 * // => an integer between 0 and 5
8993 *
8994 * _.random(5);
8995 * // => also an integer between 0 and 5
8996 *
8997 * _.random(5, true);
8998 * // => a floating-point number between 0 and 5
8999 *
9000 * _.random(1.2, 5.2);
9001 * // => a floating-point number between 1.2 and 5.2
9002 */
9003 function random(min, max, floating) {
9004 if (floating && isIterateeCall(min, max, floating)) {
9005 max = floating = null;
9006 }
9007 var noMin = min == null,
9008 noMax = max == null;
9009
9010 if (floating == null) {
9011 if (noMax && typeof min == 'boolean') {
9012 floating = min;
9013 min = 1;
9014 }
9015 else if (typeof max == 'boolean') {
9016 floating = max;
9017 noMax = true;
9018 }
9019 }
9020 if (noMin && noMax) {
9021 max = 1;
9022 noMax = false;
9023 }
9024 min = +min || 0;
9025 if (noMax) {
9026 max = min;
9027 min = 0;
9028 } else {
9029 max = +max || 0;
9030 }
9031 if (floating || min % 1 || max % 1) {
9032 var rand = nativeRandom();
9033 return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
9034 }
9035 return baseRandom(min, max);
9036 }
9037
9038 /*------------------------------------------------------------------------*/
9039
9040 /**
9041 * Converts `string` to camel case.
9042 * See [Wikipedia](https://en.wikipedia.org/wiki/CamelCase) for more details.
9043 *
9044 * @static
9045 * @memberOf _
9046 * @category String
9047 * @param {string} [string=''] The string to convert.
9048 * @returns {string} Returns the camel cased string.
9049 * @example
9050 *
9051 * _.camelCase('Foo Bar');
9052 * // => 'fooBar'
9053 *
9054 * _.camelCase('--foo-bar');
9055 * // => 'fooBar'
9056 *
9057 * _.camelCase('__foo_bar__');
9058 * // => 'fooBar'
9059 */
9060 var camelCase = createCompounder(function(result, word, index) {
9061 word = word.toLowerCase();
9062 return index ? (result + word.charAt(0).toUpperCase() + word.slice(1)) : word;
9063 });
9064
9065 /**
9066 * Capitalizes the first character of `string`.
9067 *
9068 * @static
9069 * @memberOf _
9070 * @category String
9071 * @param {string} [string=''] The string to capitalize.
9072 * @returns {string} Returns the capitalized string.
9073 * @example
9074 *
9075 * _.capitalize('fred');
9076 * // => 'Fred'
9077 */
9078 function capitalize(string) {
9079 string = baseToString(string);
9080 return string && (string.charAt(0).toUpperCase() + string.slice(1));
9081 }
9082
9083 /**
9084 * Deburrs `string` by converting latin-1 supplementary letters to basic latin letters.
9085 * See [Wikipedia](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
9086 * for more details.
9087 *
9088 * @static
9089 * @memberOf _
9090 * @category String
9091 * @param {string} [string=''] The string to deburr.
9092 * @returns {string} Returns the deburred string.
9093 * @example
9094 *
9095 * _.deburr('déjà vu');
9096 * // => 'deja vu'
9097 */
9098 function deburr(string) {
9099 string = baseToString(string);
9100 return string && string.replace(reLatin1, deburrLetter);
9101 }
9102
9103 /**
9104 * Checks if `string` ends with the given target string.
9105 *
9106 * @static
9107 * @memberOf _
9108 * @category String
9109 * @param {string} [string=''] The string to search.
9110 * @param {string} [target] The string to search for.
9111 * @param {number} [position=string.length] The position to search from.
9112 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
9113 * @example
9114 *
9115 * _.endsWith('abc', 'c');
9116 * // => true
9117 *
9118 * _.endsWith('abc', 'b');
9119 * // => false
9120 *
9121 * _.endsWith('abc', 'b', 2);
9122 * // => true
9123 */
9124 function endsWith(string, target, position) {
9125 string = baseToString(string);
9126 target = (target + '');
9127
9128 var length = string.length;
9129 position = (typeof position == 'undefined' ? length : nativeMin(position < 0 ? 0 : (+position || 0), length)) - target.length;
9130 return position >= 0 && string.indexOf(target, position) == position;
9131 }
9132
9133 /**
9134 * Converts the characters "&", "<", ">", '"', "'", and '`', in `string` to
9135 * their corresponding HTML entities.
9136 *
9137 * **Note:** No other characters are escaped. To escape additional characters
9138 * use a third-party library like [_he_](https://mths.be/he).
9139 *
9140 * Though the ">" character is escaped for symmetry, characters like
9141 * ">" and "/" don't require escaping in HTML and have no special meaning
9142 * unless they're part of a tag or unquoted attribute value.
9143 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
9144 * (under "semi-related fun fact") for more details.
9145 *
9146 * Backticks are escaped because in Internet Explorer < 9, they can break out
9147 * of attribute values or HTML comments. See [#102](https://html5sec.org/#102),
9148 * [#108](https://html5sec.org/#108), and [#133](https://html5sec.org/#133) of
9149 * the [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
9150 *
9151 * When working with HTML you should always quote attribute values to reduce
9152 * XSS vectors. See [Ryan Grove's article](http://wonko.com/post/html-escaping)
9153 * for more details.
9154 *
9155 * @static
9156 * @memberOf _
9157 * @category String
9158 * @param {string} [string=''] The string to escape.
9159 * @returns {string} Returns the escaped string.
9160 * @example
9161 *
9162 * _.escape('fred, barney, & pebbles');
9163 * // => 'fred, barney, &amp; pebbles'
9164 */
9165 function escape(string) {
9166 // Reset `lastIndex` because in IE < 9 `String#replace` does not.
9167 string = baseToString(string);
9168 return (string && reHasUnescapedHtml.test(string))
9169 ? string.replace(reUnescapedHtml, escapeHtmlChar)
9170 : string;
9171 }
9172
9173 /**
9174 * Escapes the `RegExp` special characters "\", "^", "$", ".", "|", "?", "*",
9175 * "+", "(", ")", "[", "]", "{" and "}" in `string`.
9176 *
9177 * @static
9178 * @memberOf _
9179 * @category String
9180 * @param {string} [string=''] The string to escape.
9181 * @returns {string} Returns the escaped string.
9182 * @example
9183 *
9184 * _.escapeRegExp('[lodash](https://lodash.com/)');
9185 * // => '\[lodash\]\(https://lodash\.com/\)'
9186 */
9187 function escapeRegExp(string) {
9188 string = baseToString(string);
9189 return (string && reHasRegExpChars.test(string))
9190 ? string.replace(reRegExpChars, '\\$&')
9191 : string;
9192 }
9193
9194 /**
9195 * Converts `string` to kebab case (a.k.a. spinal case).
9196 * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Computers) for
9197 * more details.
9198 *
9199 * @static
9200 * @memberOf _
9201 * @category String
9202 * @param {string} [string=''] The string to convert.
9203 * @returns {string} Returns the kebab cased string.
9204 * @example
9205 *
9206 * _.kebabCase('Foo Bar');
9207 * // => 'foo-bar'
9208 *
9209 * _.kebabCase('fooBar');
9210 * // => 'foo-bar'
9211 *
9212 * _.kebabCase('__foo_bar__');
9213 * // => 'foo-bar'
9214 */
9215 var kebabCase = createCompounder(function(result, word, index) {
9216 return result + (index ? '-' : '') + word.toLowerCase();
9217 });
9218
9219 /**
9220 * Pads `string` on the left and right sides if it is shorter then the given
9221 * padding length. The `chars` string may be truncated if the number of padding
9222 * characters can't be evenly divided by the padding length.
9223 *
9224 * @static
9225 * @memberOf _
9226 * @category String
9227 * @param {string} [string=''] The string to pad.
9228 * @param {number} [length=0] The padding length.
9229 * @param {string} [chars=' '] The string used as padding.
9230 * @returns {string} Returns the padded string.
9231 * @example
9232 *
9233 * _.pad('abc', 8);
9234 * // => ' abc '
9235 *
9236 * _.pad('abc', 8, '_-');
9237 * // => '_-abc_-_'
9238 *
9239 * _.pad('abc', 3);
9240 * // => 'abc'
9241 */
9242 function pad(string, length, chars) {
9243 string = baseToString(string);
9244 length = +length;
9245
9246 var strLength = string.length;
9247 if (strLength >= length || !nativeIsFinite(length)) {
9248 return string;
9249 }
9250 var mid = (length - strLength) / 2,
9251 leftLength = floor(mid),
9252 rightLength = ceil(mid);
9253
9254 chars = createPad('', rightLength, chars);
9255 return chars.slice(0, leftLength) + string + chars;
9256 }
9257
9258 /**
9259 * Pads `string` on the left side if it is shorter then the given padding
9260 * length. The `chars` string may be truncated if the number of padding
9261 * characters exceeds the padding length.
9262 *
9263 * @static
9264 * @memberOf _
9265 * @category String
9266 * @param {string} [string=''] The string to pad.
9267 * @param {number} [length=0] The padding length.
9268 * @param {string} [chars=' '] The string used as padding.
9269 * @returns {string} Returns the padded string.
9270 * @example
9271 *
9272 * _.padLeft('abc', 6);
9273 * // => ' abc'
9274 *
9275 * _.padLeft('abc', 6, '_-');
9276 * // => '_-_abc'
9277 *
9278 * _.padLeft('abc', 3);
9279 * // => 'abc'
9280 */
9281 function padLeft(string, length, chars) {
9282 string = baseToString(string);
9283 return string && (createPad(string, length, chars) + string);
9284 }
9285
9286 /**
9287 * Pads `string` on the right side if it is shorter then the given padding
9288 * length. The `chars` string may be truncated if the number of padding
9289 * characters exceeds the padding length.
9290 *
9291 * @static
9292 * @memberOf _
9293 * @category String
9294 * @param {string} [string=''] The string to pad.
9295 * @param {number} [length=0] The padding length.
9296 * @param {string} [chars=' '] The string used as padding.
9297 * @returns {string} Returns the padded string.
9298 * @example
9299 *
9300 * _.padRight('abc', 6);
9301 * // => 'abc '
9302 *
9303 * _.padRight('abc', 6, '_-');
9304 * // => 'abc_-_'
9305 *
9306 * _.padRight('abc', 3);
9307 * // => 'abc'
9308 */
9309 function padRight(string, length, chars) {
9310 string = baseToString(string);
9311 return string && (string + createPad(string, length, chars));
9312 }
9313
9314 /**
9315 * Converts `string` to an integer of the specified radix. If `radix` is
9316 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
9317 * in which case a `radix` of `16` is used.
9318 *
9319 * **Note:** This method aligns with the ES5 implementation of `parseInt`.
9320 * See the [ES5 spec](https://es5.github.io/#E) for more details.
9321 *
9322 * @static
9323 * @memberOf _
9324 * @category String
9325 * @param {string} string The string to convert.
9326 * @param {number} [radix] The radix to interpret `value` by.
9327 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9328 * @returns {number} Returns the converted integer.
9329 * @example
9330 *
9331 * _.parseInt('08');
9332 * // => 8
9333 *
9334 * _.map(['6', '08', '10'], _.parseInt);
9335 * // => [6, 8, 10]
9336 */
9337 function parseInt(string, radix, guard) {
9338 if (guard && isIterateeCall(string, radix, guard)) {
9339 radix = 0;
9340 }
9341 return nativeParseInt(string, radix);
9342 }
9343 // Fallback for environments with pre-ES5 implementations.
9344 if (nativeParseInt(whitespace + '08') != 8) {
9345 parseInt = function(string, radix, guard) {
9346 // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
9347 // Chrome fails to trim leading <BOM> whitespace characters.
9348 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
9349 if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
9350 radix = 0;
9351 } else if (radix) {
9352 radix = +radix;
9353 }
9354 string = trim(string);
9355 return nativeParseInt(string, radix || (reHexPrefix.test(string) ? 16 : 10));
9356 };
9357 }
9358
9359 /**
9360 * Repeats the given string `n` times.
9361 *
9362 * @static
9363 * @memberOf _
9364 * @category String
9365 * @param {string} [string=''] The string to repeat.
9366 * @param {number} [n=0] The number of times to repeat the string.
9367 * @returns {string} Returns the repeated string.
9368 * @example
9369 *
9370 * _.repeat('*', 3);
9371 * // => '***'
9372 *
9373 * _.repeat('abc', 2);
9374 * // => 'abcabc'
9375 *
9376 * _.repeat('abc', 0);
9377 * // => ''
9378 */
9379 function repeat(string, n) {
9380 var result = '';
9381 string = baseToString(string);
9382 n = +n;
9383 if (n < 1 || !string || !nativeIsFinite(n)) {
9384 return result;
9385 }
9386 // Leverage the exponentiation by squaring algorithm for a faster repeat.
9387 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
9388 do {
9389 if (n % 2) {
9390 result += string;
9391 }
9392 n = floor(n / 2);
9393 string += string;
9394 } while (n);
9395
9396 return result;
9397 }
9398
9399 /**
9400 * Converts `string` to snake case.
9401 * See [Wikipedia](https://en.wikipedia.org/wiki/Snake_case) for more details.
9402 *
9403 * @static
9404 * @memberOf _
9405 * @category String
9406 * @param {string} [string=''] The string to convert.
9407 * @returns {string} Returns the snake cased string.
9408 * @example
9409 *
9410 * _.snakeCase('Foo Bar');
9411 * // => 'foo_bar'
9412 *
9413 * _.snakeCase('--foo-bar');
9414 * // => 'foo_bar'
9415 *
9416 * _.snakeCase('fooBar');
9417 * // => 'foo_bar'
9418 */
9419 var snakeCase = createCompounder(function(result, word, index) {
9420 return result + (index ? '_' : '') + word.toLowerCase();
9421 });
9422
9423 /**
9424 * Checks if `string` starts with the given target string.
9425 *
9426 * @static
9427 * @memberOf _
9428 * @category String
9429 * @param {string} [string=''] The string to search.
9430 * @param {string} [target] The string to search for.
9431 * @param {number} [position=0] The position to search from.
9432 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
9433 * @example
9434 *
9435 * _.startsWith('abc', 'a');
9436 * // => true
9437 *
9438 * _.startsWith('abc', 'b');
9439 * // => false
9440 *
9441 * _.startsWith('abc', 'b', 1);
9442 * // => true
9443 */
9444 function startsWith(string, target, position) {
9445 string = baseToString(string);
9446 position = position == null ? 0 : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
9447 return string.lastIndexOf(target, position) == position;
9448 }
9449
9450 /**
9451 * Creates a compiled template function that can interpolate data properties
9452 * in "interpolate" delimiters, HTML-escape interpolated data properties in
9453 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
9454 * properties may be accessed as free variables in the template. If a setting
9455 * object is provided it takes precedence over `_.templateSettings` values.
9456 *
9457 * **Note:** In the development build `_.template` utilizes sourceURLs for easier debugging.
9458 * See the [HTML5 Rocks article on sourcemaps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
9459 * for more details.
9460 *
9461 * For more information on precompiling templates see
9462 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
9463 *
9464 * For more information on Chrome extension sandboxes see
9465 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
9466 *
9467 * @static
9468 * @memberOf _
9469 * @category String
9470 * @param {string} [string=''] The template string.
9471 * @param {Object} [options] The options object.
9472 * @param {RegExp} [options.escape] The HTML "escape" delimiter.
9473 * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
9474 * @param {Object} [options.imports] An object to import into the template as free variables.
9475 * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
9476 * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
9477 * @param {string} [options.variable] The data object variable name.
9478 * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
9479 * @returns {Function} Returns the compiled template function.
9480 * @example
9481 *
9482 * // using the "interpolate" delimiter to create a compiled template
9483 * var compiled = _.template('hello <%= user %>!');
9484 * compiled({ 'user': 'fred' });
9485 * // => 'hello fred!'
9486 *
9487 * // using the HTML "escape" delimiter to escape data property values
9488 * var compiled = _.template('<b><%- value %></b>');
9489 * compiled({ 'value': '<script>' });
9490 * // => '<b>&lt;script&gt;</b>'
9491 *
9492 * // using the "evaluate" delimiter to execute JavaScript and generate HTML
9493 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
9494 * compiled({ 'users': ['fred', 'barney'] });
9495 * // => '<li>fred</li><li>barney</li>'
9496 *
9497 * // using the internal `print` function in "evaluate" delimiters
9498 * var compiled = _.template('<% print("hello " + user); %>!');
9499 * compiled({ 'user': 'barney' });
9500 * // => 'hello barney!'
9501 *
9502 * // using the ES delimiter as an alternative to the default "interpolate" delimiter
9503 * var compiled = _.template('hello ${ user }!');
9504 * compiled({ 'user': 'pebbles' });
9505 * // => 'hello pebbles!'
9506 *
9507 * // using custom template delimiters
9508 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
9509 * var compiled = _.template('hello {{ user }}!');
9510 * compiled({ 'user': 'mustache' });
9511 * // => 'hello mustache!'
9512 *
9513 * // using backslashes to treat delimiters as plain text
9514 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
9515 * compiled({ 'value': 'ignored' });
9516 * // => '<%- value %>'
9517 *
9518 * // using the `imports` option to import `jQuery` as `jq`
9519 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
9520 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
9521 * compiled({ 'users': ['fred', 'barney'] });
9522 * // => '<li>fred</li><li>barney</li>'
9523 *
9524 * // using the `sourceURL` option to specify a custom sourceURL for the template
9525 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
9526 * compiled(data);
9527 * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
9528 *
9529 * // using the `variable` option to ensure a with-statement isn't used in the compiled template
9530 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
9531 * compiled.source;
9532 * // => function(data) {
9533 * var __t, __p = '';
9534 * __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
9535 * return __p;
9536 * }
9537 *
9538 * // using the `source` property to inline compiled templates for meaningful
9539 * // line numbers in error messages and a stack trace
9540 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
9541 * var JST = {\
9542 * "main": ' + _.template(mainText).source + '\
9543 * };\
9544 * ');
9545 */
9546 function template(string, options, otherOptions) {
9547 // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
9548 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
9549 var settings = lodash.templateSettings;
9550
9551 if (otherOptions && isIterateeCall(string, options, otherOptions)) {
9552 options = otherOptions = null;
9553 }
9554 string = baseToString(string);
9555 options = baseAssign(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
9556
9557 var imports = baseAssign(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
9558 importsKeys = keys(imports),
9559 importsValues = baseValues(imports, importsKeys);
9560
9561 var isEscaping,
9562 isEvaluating,
9563 index = 0,
9564 interpolate = options.interpolate || reNoMatch,
9565 source = "__p += '";
9566
9567 // Compile the regexp to match each delimiter.
9568 var reDelimiters = RegExp(
9569 (options.escape || reNoMatch).source + '|' +
9570 interpolate.source + '|' +
9571 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
9572 (options.evaluate || reNoMatch).source + '|$'
9573 , 'g');
9574
9575 // Use a sourceURL for easier debugging.
9576 var sourceURL = '//# sourceURL=' +
9577 ('sourceURL' in options
9578 ? options.sourceURL
9579 : ('lodash.templateSources[' + (++templateCounter) + ']')
9580 ) + '\n';
9581
9582 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
9583 interpolateValue || (interpolateValue = esTemplateValue);
9584
9585 // Escape characters that can't be included in string literals.
9586 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
9587
9588 // Replace delimiters with snippets.
9589 if (escapeValue) {
9590 isEscaping = true;
9591 source += "' +\n__e(" + escapeValue + ") +\n'";
9592 }
9593 if (evaluateValue) {
9594 isEvaluating = true;
9595 source += "';\n" + evaluateValue + ";\n__p += '";
9596 }
9597 if (interpolateValue) {
9598 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
9599 }
9600 index = offset + match.length;
9601
9602 // The JS engine embedded in Adobe products requires returning the `match`
9603 // string in order to produce the correct `offset` value.
9604 return match;
9605 });
9606
9607 source += "';\n";
9608
9609 // If `variable` is not specified wrap a with-statement around the generated
9610 // code to add the data object to the top of the scope chain.
9611 var variable = options.variable;
9612 if (!variable) {
9613 source = 'with (obj) {\n' + source + '\n}\n';
9614 }
9615 // Cleanup code by stripping empty strings.
9616 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
9617 .replace(reEmptyStringMiddle, '$1')
9618 .replace(reEmptyStringTrailing, '$1;');
9619
9620 // Frame code as the function body.
9621 source = 'function(' + (variable || 'obj') + ') {\n' +
9622 (variable
9623 ? ''
9624 : 'obj || (obj = {});\n'
9625 ) +
9626 "var __t, __p = ''" +
9627 (isEscaping
9628 ? ', __e = _.escape'
9629 : ''
9630 ) +
9631 (isEvaluating
9632 ? ', __j = Array.prototype.join;\n' +
9633 "function print() { __p += __j.call(arguments, '') }\n"
9634 : ';\n'
9635 ) +
9636 source +
9637 'return __p\n}';
9638
9639 var result = attempt(function() {
9640 return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
9641 });
9642
9643 // Provide the compiled function's source by its `toString` method or
9644 // the `source` property as a convenience for inlining compiled templates.
9645 result.source = source;
9646 if (isError(result)) {
9647 throw result;
9648 }
9649 return result;
9650 }
9651
9652 /**
9653 * Removes leading and trailing whitespace or specified characters from `string`.
9654 *
9655 * @static
9656 * @memberOf _
9657 * @category String
9658 * @param {string} [string=''] The string to trim.
9659 * @param {string} [chars=whitespace] The characters to trim.
9660 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9661 * @returns {string} Returns the trimmed string.
9662 * @example
9663 *
9664 * _.trim(' abc ');
9665 * // => 'abc'
9666 *
9667 * _.trim('-_-abc-_-', '_-');
9668 * // => 'abc'
9669 *
9670 * _.map([' foo ', ' bar '], _.trim);
9671 * // => ['foo', 'bar]
9672 */
9673 function trim(string, chars, guard) {
9674 var value = string;
9675 string = baseToString(string);
9676 if (!string) {
9677 return string;
9678 }
9679 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
9680 return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
9681 }
9682 chars = baseToString(chars);
9683 return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
9684 }
9685
9686 /**
9687 * Removes leading whitespace or specified characters from `string`.
9688 *
9689 * @static
9690 * @memberOf _
9691 * @category String
9692 * @param {string} [string=''] The string to trim.
9693 * @param {string} [chars=whitespace] The characters to trim.
9694 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9695 * @returns {string} Returns the trimmed string.
9696 * @example
9697 *
9698 * _.trimLeft(' abc ');
9699 * // => 'abc '
9700 *
9701 * _.trimLeft('-_-abc-_-', '_-');
9702 * // => 'abc-_-'
9703 */
9704 function trimLeft(string, chars, guard) {
9705 var value = string;
9706 string = baseToString(string);
9707 if (!string) {
9708 return string;
9709 }
9710 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
9711 return string.slice(trimmedLeftIndex(string))
9712 }
9713 return string.slice(charsLeftIndex(string, baseToString(chars)));
9714 }
9715
9716 /**
9717 * Removes trailing whitespace or specified characters from `string`.
9718 *
9719 * @static
9720 * @memberOf _
9721 * @category String
9722 * @param {string} [string=''] The string to trim.
9723 * @param {string} [chars=whitespace] The characters to trim.
9724 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9725 * @returns {string} Returns the trimmed string.
9726 * @example
9727 *
9728 * _.trimRight(' abc ');
9729 * // => ' abc'
9730 *
9731 * _.trimRight('-_-abc-_-', '_-');
9732 * // => '-_-abc'
9733 */
9734 function trimRight(string, chars, guard) {
9735 var value = string;
9736 string = baseToString(string);
9737 if (!string) {
9738 return string;
9739 }
9740 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
9741 return string.slice(0, trimmedRightIndex(string) + 1)
9742 }
9743 return string.slice(0, charsRightIndex(string, baseToString(chars)) + 1);
9744 }
9745
9746 /**
9747 * Truncates `string` if it is longer than the given maximum string length.
9748 * The last characters of the truncated string are replaced with the omission
9749 * string which defaults to "...".
9750 *
9751 * @static
9752 * @memberOf _
9753 * @category String
9754 * @param {string} [string=''] The string to truncate.
9755 * @param {Object|number} [options] The options object or maximum string length.
9756 * @param {number} [options.length=30] The maximum string length.
9757 * @param {string} [options.omission='...'] The string to indicate text is omitted.
9758 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
9759 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9760 * @returns {string} Returns the truncated string.
9761 * @example
9762 *
9763 * _.trunc('hi-diddly-ho there, neighborino');
9764 * // => 'hi-diddly-ho there, neighbo...'
9765 *
9766 * _.trunc('hi-diddly-ho there, neighborino', 24);
9767 * // => 'hi-diddly-ho there, n...'
9768 *
9769 * _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' });
9770 * // => 'hi-diddly-ho there,...'
9771 *
9772 * _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ });
9773 * //=> 'hi-diddly-ho there...'
9774 *
9775 * _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' });
9776 * // => 'hi-diddly-ho there, neig [...]'
9777 */
9778 function trunc(string, options, guard) {
9779 if (guard && isIterateeCall(string, options, guard)) {
9780 options = null;
9781 }
9782 var length = DEFAULT_TRUNC_LENGTH,
9783 omission = DEFAULT_TRUNC_OMISSION;
9784
9785 if (options != null) {
9786 if (isObject(options)) {
9787 var separator = 'separator' in options ? options.separator : separator;
9788 length = 'length' in options ? +options.length || 0 : length;
9789 omission = 'omission' in options ? baseToString(options.omission) : omission;
9790 } else {
9791 length = +options || 0;
9792 }
9793 }
9794 string = baseToString(string);
9795 if (length >= string.length) {
9796 return string;
9797 }
9798 var end = length - omission.length;
9799 if (end < 1) {
9800 return omission;
9801 }
9802 var result = string.slice(0, end);
9803 if (separator == null) {
9804 return result + omission;
9805 }
9806 if (isRegExp(separator)) {
9807 if (string.slice(end).search(separator)) {
9808 var match,
9809 newEnd,
9810 substring = string.slice(0, end);
9811
9812 if (!separator.global) {
9813 separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
9814 }
9815 separator.lastIndex = 0;
9816 while ((match = separator.exec(substring))) {
9817 newEnd = match.index;
9818 }
9819 result = result.slice(0, newEnd == null ? end : newEnd);
9820 }
9821 } else if (string.indexOf(separator, end) != end) {
9822 var index = result.lastIndexOf(separator);
9823 if (index > -1) {
9824 result = result.slice(0, index);
9825 }
9826 }
9827 return result + omission;
9828 }
9829
9830 /**
9831 * The inverse of `_.escape`; this method converts the HTML entities
9832 * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
9833 * corresponding characters.
9834 *
9835 * **Note:** No other HTML entities are unescaped. To unescape additional HTML
9836 * entities use a third-party library like [_he_](https://mths.be/he).
9837 *
9838 * @static
9839 * @memberOf _
9840 * @category String
9841 * @param {string} [string=''] The string to unescape.
9842 * @returns {string} Returns the unescaped string.
9843 * @example
9844 *
9845 * _.unescape('fred, barney, &amp; pebbles');
9846 * // => 'fred, barney, & pebbles'
9847 */
9848 function unescape(string) {
9849 string = baseToString(string);
9850 return (string && reHasEscapedHtml.test(string))
9851 ? string.replace(reEscapedHtml, unescapeHtmlChar)
9852 : string;
9853 }
9854
9855 /**
9856 * Splits `string` into an array of its words.
9857 *
9858 * @static
9859 * @memberOf _
9860 * @category String
9861 * @param {string} [string=''] The string to inspect.
9862 * @param {RegExp|string} [pattern] The pattern to match words.
9863 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9864 * @returns {Array} Returns the words of `string`.
9865 * @example
9866 *
9867 * _.words('fred, barney, & pebbles');
9868 * // => ['fred', 'barney', 'pebbles']
9869 *
9870 * _.words('fred, barney, & pebbles', /[^, ]+/g);
9871 * // => ['fred', 'barney', '&', 'pebbles']
9872 */
9873 function words(string, pattern, guard) {
9874 if (guard && isIterateeCall(string, pattern, guard)) {
9875 pattern = null;
9876 }
9877 string = baseToString(string);
9878 return string.match(pattern || reWords) || [];
9879 }
9880
9881 /*------------------------------------------------------------------------*/
9882
9883 /**
9884 * Attempts to invoke `func`, returning either the result or the caught
9885 * error object.
9886 *
9887 * @static
9888 * @memberOf _
9889 * @category Utility
9890 * @param {*} func The function to attempt.
9891 * @returns {*} Returns the `func` result or error object.
9892 * @example
9893 *
9894 * // avoid throwing errors for invalid selectors
9895 * var elements = _.attempt(function() {
9896 * return document.querySelectorAll(selector);
9897 * });
9898 *
9899 * if (_.isError(elements)) {
9900 * elements = [];
9901 * }
9902 */
9903 function attempt(func) {
9904 try {
9905 return func();
9906 } catch(e) {
9907 return isError(e) ? e : Error(e);
9908 }
9909 }
9910
9911 /**
9912 * Creates a function bound to an optional `thisArg`. If `func` is a property
9913 * name the created callback returns the property value for a given element.
9914 * If `func` is an object the created callback returns `true` for elements
9915 * that contain the equivalent object properties, otherwise it returns `false`.
9916 *
9917 * @static
9918 * @memberOf _
9919 * @alias iteratee
9920 * @category Utility
9921 * @param {*} [func=_.identity] The value to convert to a callback.
9922 * @param {*} [thisArg] The `this` binding of `func`.
9923 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9924 * @returns {Function} Returns the callback.
9925 * @example
9926 *
9927 * var users = [
9928 * { 'user': 'barney', 'age': 36 },
9929 * { 'user': 'fred', 'age': 40 }
9930 * ];
9931 *
9932 * // wrap to create custom callback shorthands
9933 * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
9934 * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
9935 * if (!match) {
9936 * return callback(func, thisArg);
9937 * }
9938 * return function(object) {
9939 * return match[2] == 'gt' ? object[match[1]] > match[3] : object[match[1]] < match[3];
9940 * };
9941 * });
9942 *
9943 * _.filter(users, 'age__gt36');
9944 * // => [{ 'user': 'fred', 'age': 40 }]
9945 */
9946 function callback(func, thisArg, guard) {
9947 if (guard && isIterateeCall(func, thisArg, guard)) {
9948 thisArg = null;
9949 }
9950 return baseCallback(func, thisArg);
9951 }
9952
9953 /**
9954 * Creates a function that returns `value`.
9955 *
9956 * @static
9957 * @memberOf _
9958 * @category Utility
9959 * @param {*} value The value to return from the new function.
9960 * @returns {Function} Returns the new function.
9961 * @example
9962 *
9963 * var object = { 'user': 'fred' };
9964 * var getter = _.constant(object);
9965 * getter() === object;
9966 * // => true
9967 */
9968 function constant(value) {
9969 return function() {
9970 return value;
9971 };
9972 }
9973
9974 /**
9975 * This method returns the first argument provided to it.
9976 *
9977 * @static
9978 * @memberOf _
9979 * @category Utility
9980 * @param {*} value Any value.
9981 * @returns {*} Returns `value`.
9982 * @example
9983 *
9984 * var object = { 'user': 'fred' };
9985 * _.identity(object) === object;
9986 * // => true
9987 */
9988 function identity(value) {
9989 return value;
9990 }
9991
9992 /**
9993 * Creates a function which performs a deep comparison between a given object
9994 * and `source`, returning `true` if the given object has equivalent property
9995 * values, else `false`.
9996 *
9997 * @static
9998 * @memberOf _
9999 * @category Utility
10000 * @param {Object} source The object of property values to match.
10001 * @returns {Function} Returns the new function.
10002 * @example
10003 *
10004 * var users = [
10005 * { 'user': 'fred', 'age': 40 },
10006 * { 'user': 'barney', 'age': 36 }
10007 * ];
10008 *
10009 * var matchesAge = _.matches({ 'age': 36 });
10010 *
10011 * _.filter(users, matchesAge);
10012 * // => [{ 'user': 'barney', 'age': 36 }]
10013 *
10014 * _.find(users, matchesAge);
10015 * // => { 'user': 'barney', 'age': 36 }
10016 */
10017 function matches(source) {
10018 return baseMatches(source, true);
10019 }
10020
10021 /**
10022 * Adds all own enumerable function properties of a source object to the
10023 * destination object. If `object` is a function then methods are added to
10024 * its prototype as well.
10025 *
10026 * @static
10027 * @memberOf _
10028 * @category Utility
10029 * @param {Function|Object} [object=this] object The destination object.
10030 * @param {Object} source The object of functions to add.
10031 * @param {Object} [options] The options object.
10032 * @param {boolean} [options.chain=true] Specify whether the functions added
10033 * are chainable.
10034 * @returns {Function|Object} Returns `object`.
10035 * @example
10036 *
10037 * function vowels(string) {
10038 * return _.filter(string, function(v) {
10039 * return /[aeiou]/i.test(v);
10040 * });
10041 * }
10042 *
10043 * _.mixin({ 'vowels': vowels });
10044 * _.vowels('fred');
10045 * // => ['e']
10046 *
10047 * _('fred').vowels().value();
10048 * // => ['e']
10049 *
10050 * _.mixin({ 'vowels': vowels }, { 'chain': false });
10051 * _('fred').vowels();
10052 * // => ['e']
10053 */
10054 function mixin(object, source, options) {
10055 if (options == null) {
10056 var isObj = isObject(source),
10057 props = isObj && keys(source),
10058 methodNames = props && props.length && baseFunctions(source, props);
10059
10060 if (!(methodNames ? methodNames.length : isObj)) {
10061 methodNames = false;
10062 options = source;
10063 source = object;
10064 object = this;
10065 }
10066 }
10067 if (!methodNames) {
10068 methodNames = baseFunctions(source, keys(source));
10069 }
10070 var chain = true,
10071 index = -1,
10072 isFunc = isFunction(object),
10073 length = methodNames.length;
10074
10075 if (options === false) {
10076 chain = false;
10077 } else if (isObject(options) && 'chain' in options) {
10078 chain = options.chain;
10079 }
10080 while (++index < length) {
10081 var methodName = methodNames[index],
10082 func = source[methodName];
10083
10084 object[methodName] = func;
10085 if (isFunc) {
10086 object.prototype[methodName] = (function(func) {
10087 return function() {
10088 var chainAll = this.__chain__;
10089 if (chain || chainAll) {
10090 var result = object(this.__wrapped__);
10091 (result.__actions__ = arrayCopy(this.__actions__)).push({ 'func': func, 'args': arguments, 'thisArg': object });
10092 result.__chain__ = chainAll;
10093 return result;
10094 }
10095 var args = [this.value()];
10096 push.apply(args, arguments);
10097 return func.apply(object, args);
10098 };
10099 }(func));
10100 }
10101 }
10102 return object;
10103 }
10104
10105 /**
10106 * Reverts the `_` variable to its previous value and returns a reference to
10107 * the `lodash` function.
10108 *
10109 * @static
10110 * @memberOf _
10111 * @category Utility
10112 * @returns {Function} Returns the `lodash` function.
10113 * @example
10114 *
10115 * var lodash = _.noConflict();
10116 */
10117 function noConflict() {
10118 context._ = oldDash;
10119 return this;
10120 }
10121
10122 /**
10123 * A no-operation function.
10124 *
10125 * @static
10126 * @memberOf _
10127 * @category Utility
10128 * @example
10129 *
10130 * var object = { 'user': 'fred' };
10131 * _.noop(object) === undefined;
10132 * // => true
10133 */
10134 function noop() {
10135 // No operation performed.
10136 }
10137
10138 /**
10139 * Creates a function which returns the property value of `key` on a given object.
10140 *
10141 * @static
10142 * @memberOf _
10143 * @category Utility
10144 * @param {string} key The key of the property to get.
10145 * @returns {Function} Returns the new function.
10146 * @example
10147 *
10148 * var users = [
10149 * { 'user': 'fred' },
10150 * { 'user': 'barney' }
10151 * ];
10152 *
10153 * var getName = _.property('user');
10154 *
10155 * _.map(users, getName);
10156 * // => ['fred', barney']
10157 *
10158 * _.pluck(_.sortBy(users, getName), 'user');
10159 * // => ['barney', 'fred']
10160 */
10161 function property(key) {
10162 return baseProperty(key + '');
10163 }
10164
10165 /**
10166 * The inverse of `_.property`; this method creates a function which returns
10167 * the property value of a given key on `object`.
10168 *
10169 * @static
10170 * @memberOf _
10171 * @category Utility
10172 * @param {Object} object The object to inspect.
10173 * @returns {Function} Returns the new function.
10174 * @example
10175 *
10176 * var object = { 'user': 'fred', 'age': 40, 'active': true };
10177 * _.map(['active', 'user'], _.propertyOf(object));
10178 * // => [true, 'fred']
10179 *
10180 * var object = { 'a': 3, 'b': 1, 'c': 2 };
10181 * _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
10182 * // => ['b', 'c', 'a']
10183 */
10184 function propertyOf(object) {
10185 return function(key) {
10186 return object == null ? undefined : object[key];
10187 };
10188 }
10189
10190 /**
10191 * Creates an array of numbers (positive and/or negative) progressing from
10192 * `start` up to, but not including, `end`. If `start` is less than `end` a
10193 * zero-length range is created unless a negative `step` is specified.
10194 *
10195 * @static
10196 * @memberOf _
10197 * @category Utility
10198 * @param {number} [start=0] The start of the range.
10199 * @param {number} end The end of the range.
10200 * @param {number} [step=1] The value to increment or decrement by.
10201 * @returns {Array} Returns the new array of numbers.
10202 * @example
10203 *
10204 * _.range(4);
10205 * // => [0, 1, 2, 3]
10206 *
10207 * _.range(1, 5);
10208 * // => [1, 2, 3, 4]
10209 *
10210 * _.range(0, 20, 5);
10211 * // => [0, 5, 10, 15]
10212 *
10213 * _.range(0, -4, -1);
10214 * // => [0, -1, -2, -3]
10215 *
10216 * _.range(1, 4, 0);
10217 * // => [1, 1, 1]
10218 *
10219 * _.range(0);
10220 * // => []
10221 */
10222 function range(start, end, step) {
10223 if (step && isIterateeCall(start, end, step)) {
10224 end = step = null;
10225 }
10226 start = +start || 0;
10227 step = step == null ? 1 : (+step || 0);
10228
10229 if (end == null) {
10230 end = start;
10231 start = 0;
10232 } else {
10233 end = +end || 0;
10234 }
10235 // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
10236 // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
10237 var index = -1,
10238 length = nativeMax(ceil((end - start) / (step || 1)), 0),
10239 result = Array(length);
10240
10241 while (++index < length) {
10242 result[index] = start;
10243 start += step;
10244 }
10245 return result;
10246 }
10247
10248 /**
10249 * Invokes the iteratee function `n` times, returning an array of the results
10250 * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
10251 * one argument; (index).
10252 *
10253 * @static
10254 * @memberOf _
10255 * @category Utility
10256 * @param {number} n The number of times to invoke `iteratee`.
10257 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10258 * @param {*} [thisArg] The `this` binding of `iteratee`.
10259 * @returns {Array} Returns the array of results.
10260 * @example
10261 *
10262 * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
10263 * // => [3, 6, 4]
10264 *
10265 * _.times(3, function(n) { mage.castSpell(n); });
10266 * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively
10267 *
10268 * _.times(3, function(n) { this.cast(n); }, mage);
10269 * // => also invokes `mage.castSpell(n)` three times
10270 */
10271 function times(n, iteratee, thisArg) {
10272 n = +n;
10273
10274 // Exit early to avoid a JSC JIT bug in Safari 8
10275 // where `Array(0)` is treated as `Array(1)`.
10276 if (n < 1 || !nativeIsFinite(n)) {
10277 return [];
10278 }
10279 var index = -1,
10280 result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
10281
10282 iteratee = bindCallback(iteratee, thisArg, 1);
10283 while (++index < n) {
10284 if (index < MAX_ARRAY_LENGTH) {
10285 result[index] = iteratee(index);
10286 } else {
10287 iteratee(index);
10288 }
10289 }
10290 return result;
10291 }
10292
10293 /**
10294 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
10295 *
10296 * @static
10297 * @memberOf _
10298 * @category Utility
10299 * @param {string} [prefix] The value to prefix the ID with.
10300 * @returns {string} Returns the unique ID.
10301 * @example
10302 *
10303 * _.uniqueId('contact_');
10304 * // => 'contact_104'
10305 *
10306 * _.uniqueId();
10307 * // => '105'
10308 */
10309 function uniqueId(prefix) {
10310 var id = ++idCounter;
10311 return baseToString(prefix) + id;
10312 }
10313
10314 /*------------------------------------------------------------------------*/
10315
10316 // Ensure `new LodashWrapper` is an instance of `lodash`.
10317 LodashWrapper.prototype = lodash.prototype;
10318
10319 // Add functions to the `Map` cache.
10320 MapCache.prototype['delete'] = mapDelete;
10321 MapCache.prototype.get = mapGet;
10322 MapCache.prototype.has = mapHas;
10323 MapCache.prototype.set = mapSet;
10324
10325 // Add functions to the `Set` cache.
10326 SetCache.prototype.push = cachePush;
10327
10328 // Assign cache to `_.memoize`.
10329 memoize.Cache = MapCache;
10330
10331 // Add functions that return wrapped values when chaining.
10332 lodash.after = after;
10333 lodash.ary = ary;
10334 lodash.assign = assign;
10335 lodash.at = at;
10336 lodash.before = before;
10337 lodash.bind = bind;
10338 lodash.bindAll = bindAll;
10339 lodash.bindKey = bindKey;
10340 lodash.callback = callback;
10341 lodash.chain = chain;
10342 lodash.chunk = chunk;
10343 lodash.compact = compact;
10344 lodash.constant = constant;
10345 lodash.countBy = countBy;
10346 lodash.create = create;
10347 lodash.curry = curry;
10348 lodash.curryRight = curryRight;
10349 lodash.debounce = debounce;
10350 lodash.defaults = defaults;
10351 lodash.defer = defer;
10352 lodash.delay = delay;
10353 lodash.difference = difference;
10354 lodash.drop = drop;
10355 lodash.dropRight = dropRight;
10356 lodash.dropRightWhile = dropRightWhile;
10357 lodash.dropWhile = dropWhile;
10358 lodash.filter = filter;
10359 lodash.flatten = flatten;
10360 lodash.flattenDeep = flattenDeep;
10361 lodash.flow = flow;
10362 lodash.flowRight = flowRight;
10363 lodash.forEach = forEach;
10364 lodash.forEachRight = forEachRight;
10365 lodash.forIn = forIn;
10366 lodash.forInRight = forInRight;
10367 lodash.forOwn = forOwn;
10368 lodash.forOwnRight = forOwnRight;
10369 lodash.functions = functions;
10370 lodash.groupBy = groupBy;
10371 lodash.indexBy = indexBy;
10372 lodash.initial = initial;
10373 lodash.intersection = intersection;
10374 lodash.invert = invert;
10375 lodash.invoke = invoke;
10376 lodash.keys = keys;
10377 lodash.keysIn = keysIn;
10378 lodash.map = map;
10379 lodash.mapValues = mapValues;
10380 lodash.matches = matches;
10381 lodash.memoize = memoize;
10382 lodash.merge = merge;
10383 lodash.mixin = mixin;
10384 lodash.negate = negate;
10385 lodash.omit = omit;
10386 lodash.once = once;
10387 lodash.pairs = pairs;
10388 lodash.partial = partial;
10389 lodash.partialRight = partialRight;
10390 lodash.partition = partition;
10391 lodash.pick = pick;
10392 lodash.pluck = pluck;
10393 lodash.property = property;
10394 lodash.propertyOf = propertyOf;
10395 lodash.pull = pull;
10396 lodash.pullAt = pullAt;
10397 lodash.range = range;
10398 lodash.rearg = rearg;
10399 lodash.reject = reject;
10400 lodash.remove = remove;
10401 lodash.rest = rest;
10402 lodash.shuffle = shuffle;
10403 lodash.slice = slice;
10404 lodash.sortBy = sortBy;
10405 lodash.sortByAll = sortByAll;
10406 lodash.take = take;
10407 lodash.takeRight = takeRight;
10408 lodash.takeRightWhile = takeRightWhile;
10409 lodash.takeWhile = takeWhile;
10410 lodash.tap = tap;
10411 lodash.throttle = throttle;
10412 lodash.thru = thru;
10413 lodash.times = times;
10414 lodash.toArray = toArray;
10415 lodash.toPlainObject = toPlainObject;
10416 lodash.transform = transform;
10417 lodash.union = union;
10418 lodash.uniq = uniq;
10419 lodash.unzip = unzip;
10420 lodash.values = values;
10421 lodash.valuesIn = valuesIn;
10422 lodash.where = where;
10423 lodash.without = without;
10424 lodash.wrap = wrap;
10425 lodash.xor = xor;
10426 lodash.zip = zip;
10427 lodash.zipObject = zipObject;
10428
10429 // Add aliases.
10430 lodash.backflow = flowRight;
10431 lodash.collect = map;
10432 lodash.compose = flowRight;
10433 lodash.each = forEach;
10434 lodash.eachRight = forEachRight;
10435 lodash.extend = assign;
10436 lodash.iteratee = callback;
10437 lodash.methods = functions;
10438 lodash.object = zipObject;
10439 lodash.select = filter;
10440 lodash.tail = rest;
10441 lodash.unique = uniq;
10442
10443 // Add functions to `lodash.prototype`.
10444 mixin(lodash, lodash);
10445
10446 /*------------------------------------------------------------------------*/
10447
10448 // Add functions that return unwrapped values when chaining.
10449 lodash.attempt = attempt;
10450 lodash.camelCase = camelCase;
10451 lodash.capitalize = capitalize;
10452 lodash.clone = clone;
10453 lodash.cloneDeep = cloneDeep;
10454 lodash.deburr = deburr;
10455 lodash.endsWith = endsWith;
10456 lodash.escape = escape;
10457 lodash.escapeRegExp = escapeRegExp;
10458 lodash.every = every;
10459 lodash.find = find;
10460 lodash.findIndex = findIndex;
10461 lodash.findKey = findKey;
10462 lodash.findLast = findLast;
10463 lodash.findLastIndex = findLastIndex;
10464 lodash.findLastKey = findLastKey;
10465 lodash.findWhere = findWhere;
10466 lodash.first = first;
10467 lodash.has = has;
10468 lodash.identity = identity;
10469 lodash.includes = includes;
10470 lodash.indexOf = indexOf;
10471 lodash.isArguments = isArguments;
10472 lodash.isArray = isArray;
10473 lodash.isBoolean = isBoolean;
10474 lodash.isDate = isDate;
10475 lodash.isElement = isElement;
10476 lodash.isEmpty = isEmpty;
10477 lodash.isEqual = isEqual;
10478 lodash.isError = isError;
10479 lodash.isFinite = isFinite;
10480 lodash.isFunction = isFunction;
10481 lodash.isMatch = isMatch;
10482 lodash.isNaN = isNaN;
10483 lodash.isNative = isNative;
10484 lodash.isNull = isNull;
10485 lodash.isNumber = isNumber;
10486 lodash.isObject = isObject;
10487 lodash.isPlainObject = isPlainObject;
10488 lodash.isRegExp = isRegExp;
10489 lodash.isString = isString;
10490 lodash.isTypedArray = isTypedArray;
10491 lodash.isUndefined = isUndefined;
10492 lodash.kebabCase = kebabCase;
10493 lodash.last = last;
10494 lodash.lastIndexOf = lastIndexOf;
10495 lodash.max = max;
10496 lodash.min = min;
10497 lodash.noConflict = noConflict;
10498 lodash.noop = noop;
10499 lodash.now = now;
10500 lodash.pad = pad;
10501 lodash.padLeft = padLeft;
10502 lodash.padRight = padRight;
10503 lodash.parseInt = parseInt;
10504 lodash.random = random;
10505 lodash.reduce = reduce;
10506 lodash.reduceRight = reduceRight;
10507 lodash.repeat = repeat;
10508 lodash.result = result;
10509 lodash.runInContext = runInContext;
10510 lodash.size = size;
10511 lodash.snakeCase = snakeCase;
10512 lodash.some = some;
10513 lodash.sortedIndex = sortedIndex;
10514 lodash.sortedLastIndex = sortedLastIndex;
10515 lodash.startsWith = startsWith;
10516 lodash.template = template;
10517 lodash.trim = trim;
10518 lodash.trimLeft = trimLeft;
10519 lodash.trimRight = trimRight;
10520 lodash.trunc = trunc;
10521 lodash.unescape = unescape;
10522 lodash.uniqueId = uniqueId;
10523 lodash.words = words;
10524
10525 // Add aliases.
10526 lodash.all = every;
10527 lodash.any = some;
10528 lodash.contains = includes;
10529 lodash.detect = find;
10530 lodash.foldl = reduce;
10531 lodash.foldr = reduceRight;
10532 lodash.head = first;
10533 lodash.include = includes;
10534 lodash.inject = reduce;
10535
10536 mixin(lodash, (function() {
10537 var source = {};
10538 baseForOwn(lodash, function(func, methodName) {
10539 if (!lodash.prototype[methodName]) {
10540 source[methodName] = func;
10541 }
10542 });
10543 return source;
10544 }()), false);
10545
10546 /*------------------------------------------------------------------------*/
10547
10548 // Add functions capable of returning wrapped and unwrapped values when chaining.
10549 lodash.sample = sample;
10550
10551 lodash.prototype.sample = function(n) {
10552 if (!this.__chain__ && n == null) {
10553 return sample(this.value());
10554 }
10555 return this.thru(function(value) {
10556 return sample(value, n);
10557 });
10558 };
10559
10560 /*------------------------------------------------------------------------*/
10561
10562 /**
10563 * The semantic version number.
10564 *
10565 * @static
10566 * @memberOf _
10567 * @type string
10568 */
10569 lodash.VERSION = VERSION;
10570
10571 // Assign default placeholders.
10572 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
10573 lodash[methodName].placeholder = lodash;
10574 });
10575
10576 // Add `LazyWrapper` methods that accept an `iteratee` value.
10577 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
10578 var isFilter = index == LAZY_FILTER_FLAG;
10579
10580 LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
10581 var result = this.clone(),
10582 filtered = result.filtered,
10583 iteratees = result.iteratees || (result.iteratees = []);
10584
10585 result.filtered = filtered || isFilter || (index == LAZY_WHILE_FLAG && result.dir < 0);
10586 iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 3), 'type': index });
10587 return result;
10588 };
10589 });
10590
10591 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
10592 arrayEach(['drop', 'take'], function(methodName, index) {
10593 var countName = methodName + 'Count',
10594 whileName = methodName + 'While';
10595
10596 LazyWrapper.prototype[methodName] = function(n) {
10597 n = n == null ? 1 : nativeMax(+n || 0, 0);
10598
10599 var result = this.clone();
10600 if (result.filtered) {
10601 var value = result[countName];
10602 result[countName] = index ? nativeMin(value, n) : (value + n);
10603 } else {
10604 var views = result.views || (result.views = []);
10605 views.push({ 'size': n, 'type': methodName + (result.dir < 0 ? 'Right' : '') });
10606 }
10607 return result;
10608 };
10609
10610 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
10611 return this.reverse()[methodName](n).reverse();
10612 };
10613
10614 LazyWrapper.prototype[methodName + 'RightWhile'] = function(predicate, thisArg) {
10615 return this.reverse()[whileName](predicate, thisArg).reverse();
10616 };
10617 });
10618
10619 // Add `LazyWrapper` methods for `_.first` and `_.last`.
10620 arrayEach(['first', 'last'], function(methodName, index) {
10621 var takeName = 'take' + (index ? 'Right': '');
10622
10623 LazyWrapper.prototype[methodName] = function() {
10624 return this[takeName](1).value()[0];
10625 };
10626 });
10627
10628 // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
10629 arrayEach(['initial', 'rest'], function(methodName, index) {
10630 var dropName = 'drop' + (index ? '' : 'Right');
10631
10632 LazyWrapper.prototype[methodName] = function() {
10633 return this[dropName](1);
10634 };
10635 });
10636
10637 // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
10638 arrayEach(['pluck', 'where'], function(methodName, index) {
10639 var operationName = index ? 'filter' : 'map',
10640 createCallback = index ? matches : property;
10641
10642 LazyWrapper.prototype[methodName] = function(value) {
10643 return this[operationName](createCallback(value));
10644 };
10645 });
10646
10647 LazyWrapper.prototype.dropWhile = function(iteratee, thisArg) {
10648 var done,
10649 lastIndex,
10650 isRight = this.dir < 0;
10651
10652 iteratee = getCallback(iteratee, thisArg, 3);
10653 return this.filter(function(value, index, array) {
10654 done = done && (isRight ? index < lastIndex : index > lastIndex);
10655 lastIndex = index;
10656 return done || (done = !iteratee(value, index, array));
10657 });
10658 };
10659
10660 LazyWrapper.prototype.reject = function(iteratee, thisArg) {
10661 iteratee = getCallback(iteratee, thisArg, 3);
10662 return this.filter(function(value, index, array) {
10663 return !iteratee(value, index, array);
10664 });
10665 };
10666
10667 LazyWrapper.prototype.slice = function(start, end) {
10668 start = start == null ? 0 : (+start || 0);
10669 var result = start < 0 ? this.takeRight(-start) : this.drop(start);
10670
10671 if (typeof end != 'undefined') {
10672 end = (+end || 0);
10673 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
10674 }
10675 return result;
10676 };
10677
10678 // Add `LazyWrapper` methods to `lodash.prototype`.
10679 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
10680 var retUnwrapped = /^(?:first|last)$/.test(methodName);
10681
10682 lodash.prototype[methodName] = function() {
10683 var value = this.__wrapped__,
10684 args = arguments,
10685 chainAll = this.__chain__,
10686 isHybrid = !!this.__actions__.length,
10687 isLazy = value instanceof LazyWrapper,
10688 onlyLazy = isLazy && !isHybrid;
10689
10690 if (retUnwrapped && !chainAll) {
10691 return onlyLazy
10692 ? func.call(value)
10693 : lodash[methodName](this.value());
10694 }
10695 var interceptor = function(value) {
10696 var otherArgs = [value];
10697 push.apply(otherArgs, args);
10698 return lodash[methodName].apply(lodash, otherArgs);
10699 };
10700 if (isLazy || isArray(value)) {
10701 var wrapper = onlyLazy ? value : new LazyWrapper(this),
10702 result = func.apply(wrapper, args);
10703
10704 if (!retUnwrapped && (isHybrid || result.actions)) {
10705 var actions = result.actions || (result.actions = []);
10706 actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
10707 }
10708 return new LodashWrapper(result, chainAll);
10709 }
10710 return this.thru(interceptor);
10711 };
10712 });
10713
10714 // Add `Array.prototype` functions to `lodash.prototype`.
10715 arrayEach(['concat', 'join', 'pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
10716 var func = arrayProto[methodName],
10717 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
10718 retUnwrapped = /^(?:join|pop|shift)$/.test(methodName);
10719
10720 lodash.prototype[methodName] = function() {
10721 var args = arguments;
10722 if (retUnwrapped && !this.__chain__) {
10723 return func.apply(this.value(), args);
10724 }
10725 return this[chainName](function(value) {
10726 return func.apply(value, args);
10727 });
10728 };
10729 });
10730
10731 // Add functions to the lazy wrapper.
10732 LazyWrapper.prototype.clone = lazyClone;
10733 LazyWrapper.prototype.reverse = lazyReverse;
10734 LazyWrapper.prototype.value = lazyValue;
10735
10736 // Add chaining functions to the lodash wrapper.
10737 lodash.prototype.chain = wrapperChain;
10738 lodash.prototype.reverse = wrapperReverse;
10739 lodash.prototype.toString = wrapperToString;
10740 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
10741
10742 // Add function aliases to the lodash wrapper.
10743 lodash.prototype.collect = lodash.prototype.map;
10744 lodash.prototype.head = lodash.prototype.first;
10745 lodash.prototype.select = lodash.prototype.filter;
10746 lodash.prototype.tail = lodash.prototype.rest;
10747
10748 return lodash;
10749 }
10750
10751 /*--------------------------------------------------------------------------*/
10752
10753 // Export lodash.
10754 var _ = runInContext();
10755
10756 // Some AMD build optimizers like r.js check for condition patterns like the following:
10757 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
10758 // Expose lodash to the global object when an AMD loader is present to avoid
10759 // errors in cases where lodash is loaded by a script tag and not intended
10760 // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
10761 // more details.
10762 root._ = _;
10763
10764 // Define as an anonymous module so, through path mapping, it can be
10765 // referenced as the "underscore" module.
10766 define(function() {
10767 return _;
10768 });
10769 }
10770 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
10771 else if (freeExports && freeModule) {
10772 // Export for Node.js or RingoJS.
10773 if (moduleExports) {
10774 (freeModule.exports = _)._ = _;
10775 }
10776 // Export for Narwhal or Rhino -require.
10777 else {
10778 freeExports._ = _;
10779 }
10780 }
10781 else {
10782 // Export for a browser or Rhino.
10783 root._ = _;
10784 }
10785 }.call(this));